- Sync winetests with Wine head (comcat, crypt32, gdiplus, lz32, mapi32, mlang, msacm...
[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_PAINT, sent|optional },
184 { WM_NCPAINT, sent|beginpaint|optional },
185 { WM_GETTEXT, sent|defwinproc|optional },
186 { WM_ERASEBKGND, sent|beginpaint|optional },
187 { 0 }
188 };
189 /* SetWindowPos(SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE)
190 * for a visible overlapped window.
191 */
192 static const struct message WmSWP_HideOverlappedSeq[] = {
193 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
194 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
195 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
196 { 0 }
197 };
198
199 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
200 * for a visible overlapped window.
201 */
202 static const struct message WmSWP_ResizeSeq[] = {
203 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
204 { WM_GETMINMAXINFO, sent|defwinproc },
205 { WM_NCCALCSIZE, sent|wparam, TRUE },
206 { WM_NCPAINT, sent|optional },
207 { WM_GETTEXT, sent|defwinproc|optional },
208 { WM_ERASEBKGND, sent|optional },
209 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
210 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
211 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
212 { WM_NCPAINT, sent|optional },
213 { WM_GETTEXT, sent|defwinproc|optional },
214 { WM_ERASEBKGND, sent|optional },
215 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
216 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
217 { 0 }
218 };
219
220 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
221 * for a visible popup window.
222 */
223 static const struct message WmSWP_ResizePopupSeq[] = {
224 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
225 { WM_GETMINMAXINFO, sent|defwinproc|optional }, /* Win9x */
226 { WM_NCCALCSIZE, sent|wparam, TRUE },
227 { WM_NCPAINT, sent|optional },
228 { WM_GETTEXT, sent|defwinproc|optional },
229 { WM_ERASEBKGND, sent|optional },
230 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
231 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
232 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
233 { WM_NCPAINT, sent|optional },
234 { WM_GETTEXT, sent|defwinproc|optional },
235 { WM_ERASEBKGND, sent|optional },
236 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
237 { 0 }
238 };
239
240 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE)
241 * for a visible overlapped window.
242 */
243 static const struct message WmSWP_MoveSeq[] = {
244 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE },
245 { WM_NCPAINT, sent|optional },
246 { WM_GETTEXT, sent|defwinproc|optional },
247 { WM_ERASEBKGND, sent|optional },
248 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
249 { WM_MOVE, sent|defwinproc|wparam, 0 },
250 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
251 { 0 }
252 };
253 /* Resize with SetWindowPos(SWP_NOZORDER)
254 * for a visible overlapped window
255 * SWP_NOZORDER is stripped by the logging code
256 */
257 static const struct message WmSWP_ResizeNoZOrder[] = {
258 { WM_WINDOWPOSCHANGING, sent|wparam, /*SWP_NOZORDER|*/SWP_NOACTIVATE },
259 { WM_GETMINMAXINFO, sent|defwinproc },
260 { WM_NCCALCSIZE, sent|wparam, 1 },
261 { WM_NCPAINT, sent },
262 { WM_GETTEXT, sent|defwinproc|optional },
263 { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
264 { WM_WINDOWPOSCHANGED, sent|wparam, /*SWP_NOZORDER|*/SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE },
265 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
266 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
267 { WM_NCPAINT, sent|optional }, /* Win9x doesn't send it */
268 { WM_GETTEXT, sent|defwinproc|optional }, /* Win9x doesn't send it */
269 { WM_ERASEBKGND, sent|optional }, /* Win9x doesn't send it */
270 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
271 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
272 { 0 }
273 };
274
275 /* Switch visible mdi children */
276 static const struct message WmSwitchChild[] = {
277 /* Switch MDI child */
278 { WM_MDIACTIVATE, sent },/* in the MDI client */
279 { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 1st MDI child */
280 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
281 { WM_CHILDACTIVATE, sent },/* in the 1st MDI child */
282 /* Deactivate 2nd MDI child */
283 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
284 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
285 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
286 /* Preparing for maximize and maximaze the 1st MDI child */
287 { WM_GETMINMAXINFO, sent|defwinproc }, /* in the 1st MDI child */
288 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED }, /* in the 1st MDI child */
289 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
290 { WM_CHILDACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
291 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 1st MDI child */
292 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED }, /* in the 1st MDI child */
293 /* Lock redraw 2nd MDI child */
294 { WM_SETREDRAW, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
295 { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
296 /* Restore 2nd MDI child */
297 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },/* in the 2nd MDI child */
298 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
299 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
300 { 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 */
301 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED }, /* in the 2nd MDI child */
302 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
303 /* Redraw 2nd MDI child */
304 { WM_SETREDRAW, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
305 /* Redraw MDI frame */
306 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },/* in MDI frame */
307 { WM_NCCALCSIZE, sent|wparam, 1 },/* in MDI frame */
308 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in MDI frame */
309 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in MDI frame */
310 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
311 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
312 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
313 { HCBT_SETFOCUS, hook },
314 { WM_KILLFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
315 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },/* in the 1st MDI child */
316 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
317 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
318 { WM_SETFOCUS, sent },/* in the MDI client */
319 { HCBT_SETFOCUS, hook },
320 { WM_KILLFOCUS, sent },/* in the MDI client */
321 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
322 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 }, /* in the 1st MDI child */
323 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
324 { WM_SETFOCUS, sent|defwinproc }, /* in the 1st MDI child */
325 { WM_MDIACTIVATE, sent|defwinproc },/* in the 1st MDI child */
326 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE }, /* in the 1st MDI child */
327 { 0 }
328 };
329
330 /* Switch visible not maximized mdi children */
331 static const struct message WmSwitchNotMaximizedChild[] = {
332 /* Switch not maximized MDI child */
333 { WM_MDIACTIVATE, sent },/* in the MDI client */
334 { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 2nd MDI child */
335 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
336 { WM_CHILDACTIVATE, sent },/* in the 2nd MDI child */
337 /* Deactivate 1st MDI child */
338 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
339 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
340 /* Activate 2nd MDI child */
341 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE}, /* in the 2nd MDI child */
342 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 2nd MDI child */
343 { HCBT_SETFOCUS, hook }, /* in the 1st MDI child */
344 { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
345 { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
346 { WM_IME_SETCONTEXT, sent|optional }, /* in the MDI client */
347 { WM_SETFOCUS, sent, 0 }, /* in the MDI client */
348 { HCBT_SETFOCUS, hook },
349 { WM_KILLFOCUS, sent }, /* in the MDI client */
350 { WM_IME_SETCONTEXT, sent|optional }, /* in the MDI client */
351 { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
352 { WM_SETFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
353 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
354 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in the 2nd MDI child */
355 { 0 }
356 };
357
358
359 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
360 SWP_NOZORDER|SWP_FRAMECHANGED)
361 * for a visible overlapped window with WS_CLIPCHILDREN style set.
362 */
363 static const struct message WmSWP_FrameChanged_clip[] = {
364 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
365 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
366 { WM_NCPAINT, sent|parent }, /* wparam != 1 */
367 { WM_GETTEXT, sent|parent|defwinproc|optional },
368 { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
369 { WM_NCPAINT, sent }, /* wparam != 1 */
370 { WM_ERASEBKGND, sent },
371 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
372 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
373 { WM_PAINT, sent },
374 { 0 }
375 };
376 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|
377 SWP_NOZORDER|SWP_FRAMECHANGED)
378 * for a visible overlapped window.
379 */
380 static const struct message WmSWP_FrameChangedDeferErase[] = {
381 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
382 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
383 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
384 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
385 { WM_PAINT, sent|parent },
386 { WM_NCPAINT, sent|beginpaint|parent }, /* wparam != 1 */
387 { WM_GETTEXT, sent|beginpaint|parent|defwinproc|optional },
388 { WM_PAINT, sent },
389 { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
390 { WM_ERASEBKGND, sent|beginpaint },
391 { 0 }
392 };
393
394 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
395 SWP_NOZORDER|SWP_FRAMECHANGED)
396 * for a visible overlapped window without WS_CLIPCHILDREN style set.
397 */
398 static const struct message WmSWP_FrameChanged_noclip[] = {
399 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
400 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
401 { WM_NCPAINT, sent|parent }, /* wparam != 1 */
402 { WM_GETTEXT, sent|parent|defwinproc|optional },
403 { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
404 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
405 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
406 { WM_PAINT, sent },
407 { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
408 { WM_ERASEBKGND, sent|beginpaint },
409 { 0 }
410 };
411
412 /* ShowWindow(SW_SHOW) for a not visible overlapped window */
413 static const struct message WmShowOverlappedSeq[] = {
414 { WM_SHOWWINDOW, sent|wparam, 1 },
415 { WM_NCPAINT, sent|wparam|optional, 1 },
416 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
417 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
418 { WM_NCPAINT, sent|wparam|optional, 1 },
419 { WM_GETTEXT, sent|defwinproc|optional },
420 { WM_ERASEBKGND, sent|optional },
421 { HCBT_ACTIVATE, hook },
422 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
423 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
424 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
425 { WM_NCPAINT, sent|wparam|optional, 1 },
426 { WM_ACTIVATEAPP, sent|wparam, 1 },
427 { WM_NCACTIVATE, sent|wparam, 1 },
428 { WM_GETTEXT, sent|defwinproc|optional },
429 { WM_ACTIVATE, sent|wparam, 1 },
430 { HCBT_SETFOCUS, hook },
431 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
432 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
433 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
434 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
435 { WM_GETTEXT, sent|optional },
436 { WM_NCPAINT, sent|wparam|optional, 1 },
437 { WM_GETTEXT, sent|defwinproc|optional },
438 { WM_ERASEBKGND, sent|optional },
439 /* Win9x adds SWP_NOZORDER below */
440 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
441 { WM_NCCALCSIZE, sent|optional },
442 { WM_GETTEXT, sent|optional },
443 { WM_NCPAINT, sent|optional },
444 { WM_ERASEBKGND, sent|optional },
445 #if 0 /* CreateWindow/ShowWindow(SW_SHOW) also generates WM_SIZE/WM_MOVE
446 * messages. Does that mean that CreateWindow doesn't set initial
447 * window dimensions for overlapped windows?
448 */
449 { WM_SIZE, sent },
450 { WM_MOVE, sent },
451 #endif
452 { WM_PAINT, sent|optional },
453 { WM_NCPAINT, sent|beginpaint|optional },
454 { 0 }
455 };
456 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible overlapped window */
457 static const struct message WmShowMaxOverlappedSeq[] = {
458 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
459 { WM_GETMINMAXINFO, sent },
460 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
461 { WM_GETMINMAXINFO, sent|defwinproc },
462 { WM_NCCALCSIZE, sent|wparam, TRUE },
463 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
464 { HCBT_ACTIVATE, hook },
465 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
466 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
467 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
468 { WM_ACTIVATEAPP, sent|wparam, 1 },
469 { WM_NCACTIVATE, sent|wparam, 1 },
470 { WM_GETTEXT, sent|defwinproc|optional },
471 { WM_ACTIVATE, sent|wparam, 1 },
472 { HCBT_SETFOCUS, hook },
473 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
474 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
475 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
476 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
477 { WM_GETTEXT, sent|optional },
478 { WM_NCPAINT, sent|wparam|optional, 1 },
479 { WM_GETTEXT, sent|defwinproc|optional },
480 { WM_ERASEBKGND, sent|optional },
481 /* Win9x adds SWP_NOZORDER below */
482 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
483 { WM_MOVE, sent|defwinproc },
484 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
485 { WM_GETTEXT, sent|optional },
486 { WM_NCCALCSIZE, sent|optional },
487 { WM_NCPAINT, sent|optional },
488 { WM_ERASEBKGND, sent|optional },
489 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
490 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
491 { WM_PAINT, sent|optional },
492 { WM_NCPAINT, sent|beginpaint|optional },
493 { WM_ERASEBKGND, sent|beginpaint|optional },
494 { 0 }
495 };
496 /* ShowWindow(SW_RESTORE) for a not visible maximized overlapped window */
497 static const struct message WmShowRestoreMaxOverlappedSeq[] = {
498 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
499 { WM_GETTEXT, sent|optional },
500 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
501 { WM_GETMINMAXINFO, sent|defwinproc },
502 { WM_NCCALCSIZE, sent|wparam, TRUE },
503 { WM_NCPAINT, sent|optional },
504 { WM_GETTEXT, sent|defwinproc|optional },
505 { WM_ERASEBKGND, sent|optional },
506 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
507 { WM_MOVE, sent|defwinproc|optional },
508 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
509 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
510 { WM_NCPAINT, sent|optional },
511 { WM_ERASEBKGND, sent|optional },
512 { WM_PAINT, sent|optional },
513 { WM_NCPAINT, sent|beginpaint|optional },
514 { WM_ERASEBKGND, sent|beginpaint|optional },
515 { 0 }
516 };
517 /* ShowWindow(SW_RESTORE) for a not visible minimized overlapped window */
518 static const struct message WmShowRestoreMinOverlappedSeq[] = {
519 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
520 { WM_QUERYOPEN, sent|optional },
521 { WM_GETTEXT, sent|optional },
522 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED|SWP_NOCOPYBITS },
523 { WM_GETMINMAXINFO, sent|defwinproc },
524 { WM_NCCALCSIZE, sent|wparam, TRUE },
525 { HCBT_ACTIVATE, hook },
526 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
527 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
528 { WM_ACTIVATEAPP, sent|wparam, 1 },
529 { WM_NCACTIVATE, sent|wparam, 1 },
530 { WM_GETTEXT, sent|defwinproc|optional },
531 { WM_ACTIVATE, sent|wparam, 1 },
532 { HCBT_SETFOCUS, hook },
533 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
534 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
535 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
536 { WM_GETTEXT, sent|optional },
537 { WM_NCPAINT, sent|wparam|optional, 1 },
538 { WM_GETTEXT, sent|defwinproc|optional },
539 { WM_ERASEBKGND, sent },
540 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_STATECHANGED|SWP_FRAMECHANGED|SWP_NOCOPYBITS },
541 { WM_MOVE, sent|defwinproc },
542 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
543 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
544 { WM_NCPAINT, sent|wparam|optional, 1 },
545 { WM_ERASEBKGND, sent|optional },
546 { WM_ACTIVATE, sent|wparam, 1 },
547 { WM_GETTEXT, sent|optional },
548 { WM_PAINT, sent|optional },
549 { WM_NCPAINT, sent|beginpaint|optional },
550 { WM_ERASEBKGND, sent|beginpaint|optional },
551 { 0 }
552 };
553 /* ShowWindow(SW_SHOWMINIMIZED) for a not visible overlapped window */
554 static const struct message WmShowMinOverlappedSeq[] = {
555 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
556 { HCBT_SETFOCUS, hook },
557 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
558 { WM_KILLFOCUS, sent },
559 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
560 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
561 { WM_GETTEXT, sent|optional },
562 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCOPYBITS|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
563 { WM_GETMINMAXINFO, sent|defwinproc },
564 { WM_NCCALCSIZE, sent|wparam, TRUE },
565 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
566 { WM_NCPAINT, sent|optional },
567 { WM_GETTEXT, sent|defwinproc|optional },
568 { WM_WINDOWPOSCHANGED, sent },
569 { WM_MOVE, sent|defwinproc },
570 { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
571 { WM_NCCALCSIZE, sent|optional },
572 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
573 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
574 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
575 { WM_NCACTIVATE, sent|wparam, 0 },
576 { WM_GETTEXT, sent|defwinproc|optional },
577 { WM_ACTIVATE, sent },
578 { WM_ACTIVATEAPP, sent|wparam, 0 },
579 /* Vista sometimes restores the window right away... */
580 { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
581 { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
582 { HCBT_MINMAX, hook|optional|lparam, 0, SW_RESTORE },
583 { WM_PAINT, sent|optional },
584 { WM_NCPAINT, sent|beginpaint|optional },
585 { WM_ERASEBKGND, sent|beginpaint|optional },
586 { 0 }
587 };
588 /* ShowWindow(SW_HIDE) for a visible overlapped window */
589 static const struct message WmHideOverlappedSeq[] = {
590 { WM_SHOWWINDOW, sent|wparam, 0 },
591 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
592 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
593 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
594 { WM_SIZE, sent|optional }, /* XP doesn't send it */
595 { WM_MOVE, sent|optional }, /* XP doesn't send it */
596 { WM_NCACTIVATE, sent|wparam, 0 },
597 { WM_ACTIVATE, sent|wparam, 0 },
598 { WM_ACTIVATEAPP, sent|wparam, 0 },
599 { WM_KILLFOCUS, sent|wparam, 0 },
600 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
601 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
602 { 0 }
603 };
604 /* DestroyWindow for a visible overlapped window */
605 static const struct message WmDestroyOverlappedSeq[] = {
606 { HCBT_DESTROYWND, hook },
607 { 0x0090, sent|optional },
608 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
609 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
610 { 0x0090, sent|optional },
611 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
612 { WM_NCACTIVATE, sent|optional|wparam, 0 },
613 { WM_ACTIVATE, sent|optional|wparam, 0 },
614 { WM_ACTIVATEAPP, sent|optional|wparam, 0 },
615 { WM_KILLFOCUS, sent|optional|wparam, 0 },
616 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
617 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
618 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
619 { WM_DESTROY, sent },
620 { WM_NCDESTROY, sent },
621 { 0 }
622 };
623 /* CreateWindow(WS_MAXIMIZE|WS_VISIBLE) for popup window */
624 static const struct message WmCreateMaxPopupSeq[] = {
625 { HCBT_CREATEWND, hook },
626 { WM_NCCREATE, sent },
627 { WM_NCCALCSIZE, sent|wparam, 0 },
628 { WM_CREATE, sent },
629 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
630 { WM_SIZE, sent|wparam, SIZE_RESTORED },
631 { WM_MOVE, sent },
632 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
633 { WM_GETMINMAXINFO, sent },
634 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
635 { WM_NCCALCSIZE, sent|wparam, TRUE },
636 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
637 { WM_MOVE, sent|defwinproc },
638 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
639 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
640 { WM_SHOWWINDOW, sent|wparam, 1 },
641 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
642 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
643 { HCBT_ACTIVATE, hook },
644 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
645 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
646 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
647 { WM_NCPAINT, sent|wparam|optional, 1 },
648 { WM_ERASEBKGND, sent|optional },
649 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_NOMOVE|SWP_NOSIZE },
650 { WM_ACTIVATEAPP, sent|wparam, 1 },
651 { WM_NCACTIVATE, sent|wparam, 1 },
652 { WM_ACTIVATE, sent|wparam, 1 },
653 { HCBT_SETFOCUS, hook },
654 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
655 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
656 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
657 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
658 { WM_GETTEXT, sent|optional },
659 { WM_SYNCPAINT, sent|wparam|optional, 4 },
660 { WM_NCPAINT, sent|wparam|optional, 1 },
661 { WM_ERASEBKGND, sent|optional },
662 { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
663 { WM_ERASEBKGND, sent|defwinproc|optional },
664 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
665 { 0 }
666 };
667 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
668 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
669 { HCBT_CREATEWND, hook },
670 { WM_NCCREATE, sent },
671 { WM_NCCALCSIZE, sent|wparam, 0 },
672 { WM_CREATE, sent },
673 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
674 { WM_SIZE, sent|wparam, SIZE_RESTORED },
675 { WM_MOVE, sent },
676 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
677 { WM_GETMINMAXINFO, sent },
678 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
679 { WM_NCCALCSIZE, sent|wparam, TRUE },
680 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
681 { WM_MOVE, sent|defwinproc },
682 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
683 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
684 { 0 }
685 };
686 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
687 static const struct message WmShowMaxPopupResizedSeq[] = {
688 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
689 { WM_GETMINMAXINFO, sent },
690 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
691 { WM_NCCALCSIZE, sent|wparam, TRUE },
692 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
693 { HCBT_ACTIVATE, hook },
694 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
695 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
696 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
697 { WM_NCPAINT, sent|wparam|optional, 1 },
698 { WM_ERASEBKGND, sent|optional },
699 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
700 { WM_ACTIVATEAPP, sent|wparam, 1 },
701 { WM_NCACTIVATE, sent|wparam, 1 },
702 { WM_ACTIVATE, sent|wparam, 1 },
703 { HCBT_SETFOCUS, hook },
704 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
705 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
706 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
707 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
708 { WM_GETTEXT, sent|optional },
709 { WM_NCPAINT, sent|wparam|optional, 1 },
710 { WM_ERASEBKGND, sent|optional },
711 { WM_WINDOWPOSCHANGED, sent },
712 /* WinNT4.0 sends WM_MOVE */
713 { WM_MOVE, sent|defwinproc|optional },
714 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
715 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
716 { 0 }
717 };
718 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
719 static const struct message WmShowMaxPopupSeq[] = {
720 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
721 { WM_GETMINMAXINFO, sent },
722 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
723 { WM_NCCALCSIZE, sent|wparam, TRUE },
724 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
725 { HCBT_ACTIVATE, hook },
726 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
727 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
728 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
729 { WM_ACTIVATEAPP, sent|wparam, 1 },
730 { WM_NCACTIVATE, sent|wparam, 1 },
731 { WM_ACTIVATE, sent|wparam, 1 },
732 { HCBT_SETFOCUS, hook },
733 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
734 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
735 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
736 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
737 { WM_GETTEXT, sent|optional },
738 { WM_SYNCPAINT, sent|wparam|optional, 4 },
739 { WM_NCPAINT, sent|wparam|optional, 1 },
740 { WM_ERASEBKGND, sent|optional },
741 { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
742 { WM_ERASEBKGND, sent|defwinproc|optional },
743 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
744 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
745 { 0 }
746 };
747 /* CreateWindow(WS_VISIBLE) for popup window */
748 static const struct message WmCreatePopupSeq[] = {
749 { HCBT_CREATEWND, hook },
750 { WM_NCCREATE, sent },
751 { WM_NCCALCSIZE, sent|wparam, 0 },
752 { WM_CREATE, sent },
753 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
754 { WM_SIZE, sent|wparam, SIZE_RESTORED },
755 { WM_MOVE, sent },
756 { WM_SHOWWINDOW, sent|wparam, 1 },
757 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
758 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
759 { HCBT_ACTIVATE, hook },
760 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
761 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
762 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
763 { WM_NCPAINT, sent|wparam|optional, 1 },
764 { WM_ERASEBKGND, sent|optional },
765 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
766 { WM_ACTIVATEAPP, sent|wparam, 1 },
767 { WM_NCACTIVATE, sent|wparam, 1 },
768 { WM_ACTIVATE, sent|wparam, 1 },
769 { HCBT_SETFOCUS, hook },
770 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
771 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
772 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
773 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
774 { WM_GETTEXT, sent|optional },
775 { WM_SYNCPAINT, sent|wparam|optional, 4 },
776 { WM_NCPAINT, sent|wparam|optional, 1 },
777 { WM_ERASEBKGND, sent|optional },
778 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
779 { 0 }
780 };
781 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
782 static const struct message WmShowVisMaxPopupSeq[] = {
783 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
784 { WM_GETMINMAXINFO, sent },
785 { WM_GETTEXT, sent|optional },
786 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
787 { WM_GETTEXT, sent|optional },
788 { WM_NCCALCSIZE, sent|wparam, TRUE },
789 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
790 { WM_NCPAINT, sent|wparam|optional, 1 },
791 { WM_ERASEBKGND, sent|optional },
792 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
793 { WM_MOVE, sent|defwinproc },
794 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
795 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
796 { 0 }
797 };
798 /* CreateWindow (for a child popup window, not initially visible) */
799 static const struct message WmCreateChildPopupSeq[] = {
800 { HCBT_CREATEWND, hook },
801 { WM_NCCREATE, sent },
802 { WM_NCCALCSIZE, sent|wparam, 0 },
803 { WM_CREATE, sent },
804 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
805 { WM_SIZE, sent|wparam, SIZE_RESTORED },
806 { WM_MOVE, sent },
807 { 0 }
808 };
809 /* CreateWindow (for a popup window, not initially visible,
810 * which sets WS_VISIBLE in WM_CREATE handler)
811 */
812 static const struct message WmCreateInvisiblePopupSeq[] = {
813 { HCBT_CREATEWND, hook },
814 { WM_NCCREATE, sent },
815 { WM_NCCALCSIZE, sent|wparam, 0 },
816 { WM_CREATE, sent },
817 { WM_STYLECHANGING, sent },
818 { WM_STYLECHANGED, sent },
819 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
820 { WM_SIZE, sent|wparam, SIZE_RESTORED },
821 { WM_MOVE, sent },
822 { 0 }
823 };
824 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
825 * for a popup window with WS_VISIBLE style set
826 */
827 static const struct message WmShowVisiblePopupSeq_2[] = {
828 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
829 { 0 }
830 };
831 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
832 * for a popup window with WS_VISIBLE style set
833 */
834 static const struct message WmShowVisiblePopupSeq_3[] = {
835 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
836 { HCBT_ACTIVATE, hook },
837 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
838 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
839 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
840 { WM_NCACTIVATE, sent|wparam, 1 },
841 { WM_ACTIVATE, sent|wparam, 1 },
842 { HCBT_SETFOCUS, hook },
843 { WM_KILLFOCUS, sent|parent },
844 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
845 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
846 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
847 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
848 { WM_SETFOCUS, sent|defwinproc },
849 { WM_GETTEXT, sent|optional },
850 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
851 { 0 }
852 };
853 /* CreateWindow (for child window, not initially visible) */
854 static const struct message WmCreateChildSeq[] = {
855 { HCBT_CREATEWND, hook },
856 { WM_NCCREATE, sent },
857 /* child is inserted into parent's child list after WM_NCCREATE returns */
858 { WM_NCCALCSIZE, sent|wparam, 0 },
859 { WM_CREATE, sent },
860 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
861 { WM_SIZE, sent|wparam, SIZE_RESTORED },
862 { WM_MOVE, sent },
863 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
864 { 0 }
865 };
866 /* CreateWindow (for maximized child window, not initially visible) */
867 static const struct message WmCreateMaximizedChildSeq[] = {
868 { HCBT_CREATEWND, hook },
869 { WM_NCCREATE, sent },
870 { WM_NCCALCSIZE, sent|wparam, 0 },
871 { WM_CREATE, sent },
872 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
873 { WM_SIZE, sent|wparam, SIZE_RESTORED },
874 { WM_MOVE, sent },
875 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
876 { WM_GETMINMAXINFO, sent },
877 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
878 { WM_NCCALCSIZE, sent|wparam, 1 },
879 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
880 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
881 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
882 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
883 { 0 }
884 };
885 /* CreateWindow (for a child window, initially visible) */
886 static const struct message WmCreateVisibleChildSeq[] = {
887 { HCBT_CREATEWND, hook },
888 { WM_NCCREATE, sent },
889 /* child is inserted into parent's child list after WM_NCCREATE returns */
890 { WM_NCCALCSIZE, sent|wparam, 0 },
891 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
892 { WM_CREATE, sent },
893 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
894 { WM_SIZE, sent|wparam, SIZE_RESTORED },
895 { WM_MOVE, sent },
896 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
897 { WM_SHOWWINDOW, sent|wparam, 1 },
898 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
899 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
900 { WM_ERASEBKGND, sent|parent|optional },
901 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
902 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
903 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
904 { 0 }
905 };
906 /* ShowWindow(SW_SHOW) for a not visible child window */
907 static const struct message WmShowChildSeq[] = {
908 { WM_SHOWWINDOW, sent|wparam, 1 },
909 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
910 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
911 { WM_ERASEBKGND, sent|parent|optional },
912 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
913 { 0 }
914 };
915 /* ShowWindow(SW_HIDE) for a visible child window */
916 static const struct message WmHideChildSeq[] = {
917 { WM_SHOWWINDOW, sent|wparam, 0 },
918 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
919 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
920 { WM_ERASEBKGND, sent|parent|optional },
921 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
922 { 0 }
923 };
924 /* ShowWindow(SW_HIDE) for a visible child window checking all parent events*/
925 static const struct message WmHideChildSeq2[] = {
926 { WM_SHOWWINDOW, sent|wparam, 0 },
927 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
928 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
929 { WM_ERASEBKGND, sent|parent|optional },
930 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
931 { 0 }
932 };
933 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
934 * for a not visible child window
935 */
936 static const struct message WmShowChildSeq_2[] = {
937 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
938 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
939 { WM_CHILDACTIVATE, sent },
940 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
941 { 0 }
942 };
943 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
944 * for a not visible child window
945 */
946 static const struct message WmShowChildSeq_3[] = {
947 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
948 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
949 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
950 { 0 }
951 };
952 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
953 * for a visible child window with a caption
954 */
955 static const struct message WmShowChildSeq_4[] = {
956 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
957 { WM_CHILDACTIVATE, sent },
958 { 0 }
959 };
960 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
961 static const struct message WmShowChildInvisibleParentSeq_1[] = {
962 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
963 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
964 { WM_NCCALCSIZE, sent|wparam, 1 },
965 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
966 { WM_CHILDACTIVATE, sent|optional },
967 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
968 { WM_MOVE, sent|defwinproc },
969 { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
970 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
971 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
972 /* FIXME: Wine creates an icon/title window while Windows doesn't */
973 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
974 { WM_GETTEXT, sent|optional },
975 { 0 }
976 };
977 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
978 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
979 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
980 { 0 }
981 };
982 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
983 static const struct message WmShowChildInvisibleParentSeq_2[] = {
984 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
985 { WM_GETMINMAXINFO, sent },
986 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
987 { WM_NCCALCSIZE, sent|wparam, 1 },
988 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
989 { WM_CHILDACTIVATE, sent },
990 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
991 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
992 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
993 { 0 }
994 };
995 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
996 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
997 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
998 { 0 }
999 };
1000 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1001 static const struct message WmShowChildInvisibleParentSeq_3[] = {
1002 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1003 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
1004 { WM_NCCALCSIZE, sent|wparam, 1 },
1005 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1006 { WM_CHILDACTIVATE, sent },
1007 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1008 { WM_MOVE, sent|defwinproc },
1009 { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
1010 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1011 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1012 /* FIXME: Wine creates an icon/title window while Windows doesn't */
1013 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1014 { WM_GETTEXT, sent|optional },
1015 { 0 }
1016 };
1017 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1018 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
1019 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1020 { 0 }
1021 };
1022 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1023 static const struct message WmShowChildInvisibleParentSeq_4[] = {
1024 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1025 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
1026 { WM_NCCALCSIZE, sent|wparam, 1 },
1027 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1028 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1029 { WM_MOVE, sent|defwinproc },
1030 { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
1031 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1032 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1033 /* FIXME: Wine creates an icon/title window while Windows doesn't */
1034 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1035 { WM_GETTEXT, sent|optional },
1036 { 0 }
1037 };
1038 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1039 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
1040 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1041 { 0 }
1042 };
1043 /* ShowWindow(SW_SHOW) for child with invisible parent */
1044 static const struct message WmShowChildInvisibleParentSeq_5[] = {
1045 { WM_SHOWWINDOW, sent|wparam, 1 },
1046 { 0 }
1047 };
1048 /* ShowWindow(SW_HIDE) for child with invisible parent */
1049 static const struct message WmHideChildInvisibleParentSeq[] = {
1050 { WM_SHOWWINDOW, sent|wparam, 0 },
1051 { 0 }
1052 };
1053 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
1054 static const struct message WmShowChildInvisibleParentSeq_6[] = {
1055 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1056 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1057 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1058 { 0 }
1059 };
1060 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
1061 static const struct message WmHideChildInvisibleParentSeq_2[] = {
1062 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1063 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1064 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1065 { 0 }
1066 };
1067 /* DestroyWindow for a visible child window */
1068 static const struct message WmDestroyChildSeq[] = {
1069 { HCBT_DESTROYWND, hook },
1070 { 0x0090, sent|optional },
1071 { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1072 { WM_SHOWWINDOW, sent|wparam, 0 },
1073 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1074 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1075 { WM_ERASEBKGND, sent|parent|optional },
1076 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1077 { HCBT_SETFOCUS, hook }, /* set focus to a parent */
1078 { WM_KILLFOCUS, sent },
1079 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1080 { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
1081 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1082 { WM_SETFOCUS, sent|parent },
1083 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1084 { WM_DESTROY, sent },
1085 { WM_DESTROY, sent|optional }, /* some other (IME?) window */
1086 { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
1087 { WM_NCDESTROY, sent },
1088 { 0 }
1089 };
1090 /* DestroyWindow for a visible child window with invisible parent */
1091 static const struct message WmDestroyInvisibleChildSeq[] = {
1092 { HCBT_DESTROYWND, hook },
1093 { 0x0090, sent|optional },
1094 { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1095 { WM_SHOWWINDOW, sent|wparam, 0 },
1096 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1097 { WM_DESTROY, sent },
1098 { WM_NCDESTROY, sent },
1099 { 0 }
1100 };
1101 /* Moving the mouse in nonclient area */
1102 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
1103 { WM_NCHITTEST, sent },
1104 { WM_SETCURSOR, sent },
1105 { WM_NCMOUSEMOVE, posted },
1106 { 0 }
1107 };
1108 /* Moving the mouse in client area */
1109 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
1110 { WM_NCHITTEST, sent },
1111 { WM_SETCURSOR, sent },
1112 { WM_MOUSEMOVE, posted },
1113 { 0 }
1114 };
1115 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1116 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
1117 { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
1118 { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
1119 { WM_GETMINMAXINFO, sent|defwinproc },
1120 { WM_ENTERSIZEMOVE, sent|defwinproc },
1121 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1122 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1123 { WM_MOVE, sent|defwinproc },
1124 { WM_EXITSIZEMOVE, sent|defwinproc },
1125 { 0 }
1126 };
1127 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1128 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
1129 { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
1130 { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
1131 { WM_GETMINMAXINFO, sent|defwinproc },
1132 { WM_ENTERSIZEMOVE, sent|defwinproc },
1133 { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
1134 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1135 { WM_GETMINMAXINFO, sent|defwinproc },
1136 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1137 { WM_NCPAINT, sent|defwinproc|wparam, 1 },
1138 { WM_GETTEXT, sent|defwinproc },
1139 { WM_ERASEBKGND, sent|defwinproc },
1140 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1141 { WM_MOVE, sent|defwinproc },
1142 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1143 { WM_EXITSIZEMOVE, sent|defwinproc },
1144 { 0 }
1145 };
1146 /* Resizing child window with MoveWindow (32) */
1147 static const struct message WmResizingChildWithMoveWindowSeq[] = {
1148 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
1149 { WM_NCCALCSIZE, sent|wparam, 1 },
1150 { WM_ERASEBKGND, sent|parent|optional },
1151 { WM_ERASEBKGND, sent|optional },
1152 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
1153 { WM_MOVE, sent|defwinproc },
1154 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1155 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1156 { 0 }
1157 };
1158 /* Clicking on inactive button */
1159 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
1160 { WM_NCHITTEST, sent },
1161 { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
1162 { WM_MOUSEACTIVATE, sent },
1163 { WM_MOUSEACTIVATE, sent|parent|defwinproc },
1164 { WM_SETCURSOR, sent },
1165 { WM_SETCURSOR, sent|parent|defwinproc },
1166 { WM_LBUTTONDOWN, posted },
1167 { WM_KILLFOCUS, posted|parent },
1168 { WM_SETFOCUS, posted },
1169 { WM_CTLCOLORBTN, posted|parent },
1170 { BM_SETSTATE, posted },
1171 { WM_CTLCOLORBTN, posted|parent },
1172 { WM_LBUTTONUP, posted },
1173 { BM_SETSTATE, posted },
1174 { WM_CTLCOLORBTN, posted|parent },
1175 { WM_COMMAND, posted|parent },
1176 { 0 }
1177 };
1178 /* Reparenting a button (16/32) */
1179 /* The last child (button) reparented gets topmost for its new parent. */
1180 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
1181 { WM_SHOWWINDOW, sent|wparam, 0 },
1182 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1183 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1184 { WM_ERASEBKGND, sent|parent },
1185 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1186 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
1187 { WM_CHILDACTIVATE, sent },
1188 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW },
1189 { WM_MOVE, sent|defwinproc },
1190 { WM_SHOWWINDOW, sent|wparam, 1 },
1191 { 0 }
1192 };
1193 /* Creation of a custom dialog (32) */
1194 static const struct message WmCreateCustomDialogSeq[] = {
1195 { HCBT_CREATEWND, hook },
1196 { WM_GETMINMAXINFO, sent },
1197 { WM_NCCREATE, sent },
1198 { WM_NCCALCSIZE, sent|wparam, 0 },
1199 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1200 { WM_CREATE, sent },
1201 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1202 { WM_NOTIFYFORMAT, sent|optional },
1203 { WM_QUERYUISTATE, sent|optional },
1204 { WM_WINDOWPOSCHANGING, sent|optional },
1205 { WM_GETMINMAXINFO, sent|optional },
1206 { WM_NCCALCSIZE, sent|optional },
1207 { WM_WINDOWPOSCHANGED, sent|optional },
1208 { WM_SHOWWINDOW, sent|wparam, 1 },
1209 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1210 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1211 { HCBT_ACTIVATE, hook },
1212 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1213
1214
1215 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1216
1217 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1218
1219 { WM_NCACTIVATE, sent|wparam, 1 },
1220 { WM_GETTEXT, sent|optional|defwinproc },
1221 { WM_GETTEXT, sent|optional|defwinproc },
1222 { WM_GETTEXT, sent|optional|defwinproc },
1223 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1224 { WM_ACTIVATE, sent|wparam, 1 },
1225 { WM_GETTEXT, sent|optional },
1226 { WM_KILLFOCUS, sent|parent },
1227 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1228 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1229 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1230 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1231 { WM_SETFOCUS, sent },
1232 { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1233 { WM_NCPAINT, sent|wparam, 1 },
1234 { WM_GETTEXT, sent|optional|defwinproc },
1235 { WM_GETTEXT, sent|optional|defwinproc },
1236 { WM_ERASEBKGND, sent },
1237 { WM_CTLCOLORDLG, sent|defwinproc },
1238 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1239 { WM_GETTEXT, sent|optional },
1240 { WM_GETTEXT, sent|optional },
1241 { WM_NCCALCSIZE, sent|optional },
1242 { WM_NCPAINT, sent|optional },
1243 { WM_GETTEXT, sent|optional|defwinproc },
1244 { WM_GETTEXT, sent|optional|defwinproc },
1245 { WM_ERASEBKGND, sent|optional },
1246 { WM_CTLCOLORDLG, sent|optional|defwinproc },
1247 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1248 { WM_SIZE, sent|wparam, SIZE_RESTORED },
1249 { WM_MOVE, sent },
1250 { 0 }
1251 };
1252 /* Calling EndDialog for a custom dialog (32) */
1253 static const struct message WmEndCustomDialogSeq[] = {
1254 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1255 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1256 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1257 { WM_GETTEXT, sent|optional },
1258 { HCBT_ACTIVATE, hook },
1259 { WM_NCACTIVATE, sent|wparam, 0 },
1260 { WM_GETTEXT, sent|optional|defwinproc },
1261 { WM_GETTEXT, sent|optional|defwinproc },
1262 { WM_ACTIVATE, sent|wparam, 0 },
1263 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1264 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1265 { HCBT_SETFOCUS, hook },
1266 { WM_KILLFOCUS, sent },
1267 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1268 { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1269 { WM_IME_NOTIFY, sent|wparam|optional, 1 },
1270 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1271 { WM_SETFOCUS, sent|parent|defwinproc },
1272 { 0 }
1273 };
1274 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
1275 static const struct message WmShowCustomDialogSeq[] = {
1276 { WM_SHOWWINDOW, sent|wparam, 1 },
1277 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1278 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1279 { HCBT_ACTIVATE, hook },
1280 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1281
1282 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1283
1284 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1285 { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
1286 { WM_NCACTIVATE, sent|wparam, 1 },
1287 { WM_ACTIVATE, sent|wparam, 1 },
1288 { WM_GETTEXT, sent|optional },
1289
1290 { WM_KILLFOCUS, sent|parent },
1291 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1292 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1293 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1294 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1295 { WM_SETFOCUS, sent },
1296 { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1297 { WM_NCPAINT, sent|wparam, 1 },
1298 { WM_ERASEBKGND, sent },
1299 { WM_CTLCOLORDLG, sent|defwinproc },
1300 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1301 { 0 }
1302 };
1303 /* Creation and destruction of a modal dialog (32) */
1304 static const struct message WmModalDialogSeq[] = {
1305 { WM_CANCELMODE, sent|parent },
1306 { HCBT_SETFOCUS, hook },
1307 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1308 { WM_KILLFOCUS, sent|parent },
1309 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1310 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1311 { WM_ENABLE, sent|parent|wparam, 0 },
1312 { HCBT_CREATEWND, hook },
1313 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1314 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1315 { WM_SETFONT, sent },
1316 { WM_INITDIALOG, sent },
1317 { WM_CHANGEUISTATE, sent|optional },
1318 { WM_UPDATEUISTATE, sent|optional },
1319 { WM_SHOWWINDOW, sent },
1320 { HCBT_ACTIVATE, hook },
1321 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1322 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1323 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1324 { WM_NCACTIVATE, sent|wparam, 1 },
1325 { WM_GETTEXT, sent|optional },
1326 { WM_ACTIVATE, sent|wparam, 1 },
1327 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1328 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1329 { WM_NCPAINT, sent },
1330 { WM_GETTEXT, sent|optional },
1331 { WM_ERASEBKGND, sent },
1332 { WM_CTLCOLORDLG, sent },
1333 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1334 { WM_GETTEXT, sent|optional },
1335 { WM_NCCALCSIZE, sent|optional },
1336 { WM_NCPAINT, sent|optional },
1337 { WM_GETTEXT, sent|optional },
1338 { WM_ERASEBKGND, sent|optional },
1339 { WM_CTLCOLORDLG, sent|optional },
1340 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1341 { WM_PAINT, sent|optional },
1342 { WM_CTLCOLORBTN, sent },
1343 { WM_ENTERIDLE, sent|parent|optional },
1344 { WM_ENTERIDLE, sent|parent|optional },
1345 { WM_ENTERIDLE, sent|parent|optional },
1346 { WM_ENTERIDLE, sent|parent|optional },
1347 { WM_ENTERIDLE, sent|parent|optional },
1348 { WM_ENTERIDLE, sent|parent|optional },
1349 { WM_ENTERIDLE, sent|parent|optional },
1350 { WM_ENTERIDLE, sent|parent|optional },
1351 { WM_ENTERIDLE, sent|parent|optional },
1352 { WM_ENTERIDLE, sent|parent|optional },
1353 { WM_ENTERIDLE, sent|parent|optional },
1354 { WM_ENTERIDLE, sent|parent|optional },
1355 { WM_ENTERIDLE, sent|parent|optional },
1356 { WM_ENTERIDLE, sent|parent|optional },
1357 { WM_ENTERIDLE, sent|parent|optional },
1358 { WM_ENTERIDLE, sent|parent|optional },
1359 { WM_ENTERIDLE, sent|parent|optional },
1360 { WM_ENTERIDLE, sent|parent|optional },
1361 { WM_ENTERIDLE, sent|parent|optional },
1362 { WM_ENTERIDLE, sent|parent|optional },
1363 { WM_TIMER, sent },
1364 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1365 { WM_ENABLE, sent|parent|wparam, 1 },
1366 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1367 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1368 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1369 { WM_GETTEXT, sent|optional },
1370 { HCBT_ACTIVATE, hook },
1371 { WM_NCACTIVATE, sent|wparam, 0 },
1372 { WM_GETTEXT, sent|optional },
1373 { WM_ACTIVATE, sent|wparam, 0 },
1374 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1375 { WM_WINDOWPOSCHANGING, sent|optional },
1376 { WM_WINDOWPOSCHANGED, sent|optional },
1377 { HCBT_SETFOCUS, hook },
1378 { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1379 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1380 { WM_SETFOCUS, sent|parent|defwinproc },
1381 { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1382 { HCBT_DESTROYWND, hook },
1383 { 0x0090, sent|optional },
1384 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1385 { WM_DESTROY, sent },
1386 { WM_NCDESTROY, sent },
1387 { 0 }
1388 };
1389 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
1390 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
1391 /* (inside dialog proc, handling WM_INITDIALOG) */
1392 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1393 { WM_NCCALCSIZE, sent },
1394 { WM_NCACTIVATE, sent|parent|wparam, 0 },
1395 { WM_GETTEXT, sent|defwinproc },
1396 { WM_ACTIVATE, sent|parent|wparam, 0 },
1397 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1398 { WM_WINDOWPOSCHANGING, sent|parent },
1399 { WM_NCACTIVATE, sent|wparam, 1 },
1400 { WM_ACTIVATE, sent|wparam, 1 },
1401 { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1402 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1403 /* (setting focus) */
1404 { WM_SHOWWINDOW, sent|wparam, 1 },
1405 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1406 { WM_NCPAINT, sent },
1407 { WM_GETTEXT, sent|defwinproc },
1408 { WM_ERASEBKGND, sent },
1409 { WM_CTLCOLORDLG, sent|defwinproc },
1410 { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1411 { WM_PAINT, sent },
1412 /* (bunch of WM_CTLCOLOR* for each control) */
1413 { WM_PAINT, sent|parent },
1414 { WM_ENTERIDLE, sent|parent|wparam, 0 },
1415 { WM_SETCURSOR, sent|parent },
1416 { 0 }
1417 };
1418 /* SetMenu for NonVisible windows with size change*/
1419 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1420 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1421 { WM_NCCALCSIZE, sent|wparam, 1 },
1422 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1423 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1424 { WM_MOVE, sent|defwinproc },
1425 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1426 { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1427 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1428 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1429 { WM_GETTEXT, sent|optional },
1430 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1431 { 0 }
1432 };
1433 /* SetMenu for NonVisible windows with no size change */
1434 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1435 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1436 { WM_NCCALCSIZE, sent|wparam, 1 },
1437 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1438 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1439 { 0 }
1440 };
1441 /* SetMenu for Visible windows with size change */
1442 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1443 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1444 { WM_NCCALCSIZE, sent|wparam, 1 },
1445 { 0x0093, sent|defwinproc|optional },
1446 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1447 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1448 { 0x0093, sent|defwinproc|optional },
1449 { 0x0093, sent|defwinproc|optional },
1450 { 0x0091, sent|defwinproc|optional },
1451 { 0x0092, sent|defwinproc|optional },
1452 { WM_GETTEXT, sent|defwinproc|optional },
1453 { WM_ERASEBKGND, sent|optional },
1454 { WM_ACTIVATE, sent|optional },
1455 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1456 { WM_MOVE, sent|defwinproc },
1457 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1458 { 0x0093, sent|optional },
1459 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1460 { 0x0093, sent|defwinproc|optional },
1461 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1462 { 0x0093, sent|defwinproc|optional },
1463 { 0x0093, sent|defwinproc|optional },
1464 { 0x0091, sent|defwinproc|optional },
1465 { 0x0092, sent|defwinproc|optional },
1466 { WM_ERASEBKGND, sent|optional },
1467 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1468 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1469 { 0 }
1470 };
1471 /* SetMenu for Visible windows with no size change */
1472 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1473 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1474 { WM_NCCALCSIZE, sent|wparam, 1 },
1475 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1476 { WM_GETTEXT, sent|defwinproc|optional },
1477 { WM_ERASEBKGND, sent|optional },
1478 { WM_ACTIVATE, sent|optional },
1479 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1480 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1481 { 0 }
1482 };
1483 /* DrawMenuBar for a visible window */
1484 static const struct message WmDrawMenuBarSeq[] =
1485 {
1486 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1487 { WM_NCCALCSIZE, sent|wparam, 1 },
1488 { 0x0093, sent|defwinproc|optional },
1489 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1490 { 0x0093, sent|defwinproc|optional },
1491 { 0x0093, sent|defwinproc|optional },
1492 { 0x0091, sent|defwinproc|optional },
1493 { 0x0092, sent|defwinproc|optional },
1494 { WM_GETTEXT, sent|defwinproc|optional },
1495 { WM_ERASEBKGND, sent|optional },
1496 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1497 { 0x0093, sent|optional },
1498 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1499 { 0 }
1500 };
1501
1502 static const struct message WmSetRedrawFalseSeq[] =
1503 {
1504 { WM_SETREDRAW, sent|wparam, 0 },
1505 { 0 }
1506 };
1507
1508 static const struct message WmSetRedrawTrueSeq[] =
1509 {
1510 { WM_SETREDRAW, sent|wparam, 1 },
1511 { 0 }
1512 };
1513
1514 static const struct message WmEnableWindowSeq_1[] =
1515 {
1516 { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1517 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1518 { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1519 { 0 }
1520 };
1521
1522 static const struct message WmEnableWindowSeq_2[] =
1523 {
1524 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1525 { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1526 { 0 }
1527 };
1528
1529 static const struct message WmGetScrollRangeSeq[] =
1530 {
1531 { SBM_GETRANGE, sent },
1532 { 0 }
1533 };
1534 static const struct message WmGetScrollInfoSeq[] =
1535 {
1536 { SBM_GETSCROLLINFO, sent },
1537 { 0 }
1538 };
1539 static const struct message WmSetScrollRangeSeq[] =
1540 {
1541 /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1542 sends SBM_SETSCROLLINFO.
1543 */
1544 { SBM_SETSCROLLINFO, sent },
1545 { 0 }
1546 };
1547 /* SetScrollRange for a window without a non-client area */
1548 static const struct message WmSetScrollRangeHSeq_empty[] =
1549 {
1550 { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1551 { 0 }
1552 };
1553 static const struct message WmSetScrollRangeVSeq_empty[] =
1554 {
1555 { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1556 { 0 }
1557 };
1558 static const struct message WmSetScrollRangeHVSeq[] =
1559 {
1560 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1561 { WM_NCCALCSIZE, sent|wparam, 1 },
1562 { WM_GETTEXT, sent|defwinproc|optional },
1563 { WM_ERASEBKGND, sent|optional },
1564 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1565 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1566 { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1567 { 0 }
1568 };
1569 /* SetScrollRange for a window with a non-client area */
1570 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1571 {
1572 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1573 { WM_NCCALCSIZE, sent|wparam, 1 },
1574 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1575 { WM_NCPAINT, sent|optional },
1576 { WM_STYLECHANGING, sent|defwinproc|optional },
1577 { WM_STYLECHANGED, sent|defwinproc|optional },
1578 { WM_STYLECHANGING, sent|defwinproc|optional },
1579 { WM_STYLECHANGED, sent|defwinproc|optional },
1580 { WM_STYLECHANGING, sent|defwinproc|optional },
1581 { WM_STYLECHANGED, sent|defwinproc|optional },
1582 { WM_STYLECHANGING, sent|defwinproc|optional },
1583 { WM_STYLECHANGED, sent|defwinproc|optional },
1584 { WM_GETTEXT, sent|defwinproc|optional },
1585 { WM_GETTEXT, sent|defwinproc|optional },
1586 { WM_ERASEBKGND, sent|optional },
1587 { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1588 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOCLIENTSIZE },
1589 { WM_SIZE, sent|defwinproc|wparam|optional, SIZE_RESTORED },
1590 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1591 { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1592 { WM_GETTEXT, sent|optional },
1593 { WM_GETTEXT, sent|optional },
1594 { WM_GETTEXT, sent|optional },
1595 { WM_GETTEXT, sent|optional },
1596 { 0 }
1597 };
1598 /* test if we receive the right sequence of messages */
1599 /* after calling ShowWindow( SW_SHOWNA) */
1600 static const struct message WmSHOWNAChildInvisParInvis[] = {
1601 { WM_SHOWWINDOW, sent|wparam, 1 },
1602 { 0 }
1603 };
1604 static const struct message WmSHOWNAChildVisParInvis[] = {
1605 { WM_SHOWWINDOW, sent|wparam, 1 },
1606 { 0 }
1607 };
1608 static const struct message WmSHOWNAChildVisParVis[] = {
1609 { WM_SHOWWINDOW, sent|wparam, 1 },
1610 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1611 { 0 }
1612 };
1613 static const struct message WmSHOWNAChildInvisParVis[] = {
1614 { WM_SHOWWINDOW, sent|wparam, 1 },
1615 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1616 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1617 { WM_ERASEBKGND, sent|optional },
1618 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1619 { 0 }
1620 };
1621 static const struct message WmSHOWNATopVisible[] = {
1622 { WM_SHOWWINDOW, sent|wparam, 1 },
1623 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1624 { WM_NCPAINT, sent|wparam|optional, 1 },
1625 { WM_GETTEXT, sent|defwinproc|optional },
1626 { WM_ERASEBKGND, sent|optional },
1627 { WM_WINDOWPOSCHANGED, sent|optional },
1628 { 0 }
1629 };
1630 static const struct message WmSHOWNATopInvisible[] = {
1631 { WM_NOTIFYFORMAT, sent|optional },
1632 { WM_QUERYUISTATE, sent|optional },
1633 { WM_WINDOWPOSCHANGING, sent|optional },
1634 { WM_GETMINMAXINFO, sent|optional },
1635 { WM_NCCALCSIZE, sent|optional },
1636 { WM_WINDOWPOSCHANGED, sent|optional },
1637 { WM_SHOWWINDOW, sent|wparam, 1 },
1638 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1639 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1640 { WM_NCPAINT, sent|wparam, 1 },
1641 { WM_GETTEXT, sent|defwinproc|optional },
1642 { WM_ERASEBKGND, sent|optional },
1643 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1644 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1645 { WM_NCPAINT, sent|wparam|optional, 1 },
1646 { WM_ERASEBKGND, sent|optional },
1647 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1648 { WM_SIZE, sent|wparam, SIZE_RESTORED },
1649 { WM_MOVE, sent },
1650 { 0 }
1651 };
1652
1653 static int after_end_dialog, test_def_id;
1654 static int sequence_cnt, sequence_size;
1655 static struct recvd_message* sequence;
1656 static int log_all_parent_messages;
1657 static int paint_loop_done;
1658
1659 /* user32 functions */
1660 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
1661 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
1662 static void (WINAPI *pNotifyWinEvent)(DWORD, HWND, LONG, LONG);
1663 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
1664 static HWINEVENTHOOK (WINAPI *pSetWinEventHook)(DWORD, DWORD, HMODULE, WINEVENTPROC, DWORD, DWORD, DWORD);
1665 static BOOL (WINAPI *pTrackMouseEvent)(TRACKMOUSEEVENT*);
1666 static BOOL (WINAPI *pUnhookWinEvent)(HWINEVENTHOOK);
1667 /* kernel32 functions */
1668 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
1669
1670 static void init_procs(void)
1671 {
1672 HMODULE user32 = GetModuleHandleA("user32.dll");
1673 HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
1674
1675 #define GET_PROC(dll, func) \
1676 p ## func = (void*)GetProcAddress(dll, #func); \
1677 if(!p ## func) { \
1678 trace("GetProcAddress(%s) failed\n", #func); \
1679 }
1680
1681 GET_PROC(user32, GetAncestor)
1682 GET_PROC(user32, GetMenuInfo)
1683 GET_PROC(user32, NotifyWinEvent)
1684 GET_PROC(user32, SetMenuInfo)
1685 GET_PROC(user32, SetWinEventHook)
1686 GET_PROC(user32, TrackMouseEvent)
1687 GET_PROC(user32, UnhookWinEvent)
1688
1689 GET_PROC(kernel32, GetCPInfoExA)
1690
1691 #undef GET_PROC
1692 }
1693
1694 static const char *get_winpos_flags(UINT flags)
1695 {
1696 static char buffer[300];
1697
1698 buffer[0] = 0;
1699 #define DUMP(flag) do { if (flags & flag) { strcat( buffer, "|" #flag ); flags &= ~flag; } } while(0)
1700 DUMP( SWP_SHOWWINDOW );
1701 DUMP( SWP_HIDEWINDOW );
1702 DUMP( SWP_NOACTIVATE );
1703 DUMP( SWP_FRAMECHANGED );
1704 DUMP( SWP_NOCOPYBITS );
1705 DUMP( SWP_NOOWNERZORDER );
1706 DUMP( SWP_NOSENDCHANGING );
1707 DUMP( SWP_DEFERERASE );
1708 DUMP( SWP_ASYNCWINDOWPOS );
1709 DUMP( SWP_NOZORDER );
1710 DUMP( SWP_NOREDRAW );
1711 DUMP( SWP_NOSIZE );
1712 DUMP( SWP_NOMOVE );
1713 DUMP( SWP_NOCLIENTSIZE );
1714 DUMP( SWP_NOCLIENTMOVE );
1715 if (flags) sprintf(buffer + strlen(buffer),"|0x%04x", flags);
1716 return buffer + 1;
1717 #undef DUMP
1718 }
1719
1720
1721 #define add_message(msg) add_message_(__LINE__,msg);
1722 static void add_message_(int line, const struct recvd_message *msg)
1723 {
1724 struct recvd_message *seq;
1725
1726 if (!sequence)
1727 {
1728 sequence_size = 10;
1729 sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof(*sequence) );
1730 }
1731 if (sequence_cnt == sequence_size)
1732 {
1733 sequence_size *= 2;
1734 sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof(*sequence) );
1735 }
1736 assert(sequence);
1737
1738 seq = &sequence[sequence_cnt];
1739 seq->hwnd = msg->hwnd;
1740 seq->message = msg->message;
1741 seq->flags = msg->flags;
1742 seq->wParam = msg->wParam;
1743 seq->lParam = msg->lParam;
1744 seq->line = line;
1745 seq->descr = msg->descr;
1746 seq->output[0] = 0;
1747
1748 if (msg->descr)
1749 {
1750 if (msg->flags & hook)
1751 {
1752 static const char * const CBT_code_name[10] =
1753 {
1754 "HCBT_MOVESIZE",
1755 "HCBT_MINMAX",
1756 "HCBT_QS",
1757 "HCBT_CREATEWND",
1758 "HCBT_DESTROYWND",
1759 "HCBT_ACTIVATE",
1760 "HCBT_CLICKSKIPPED",
1761 "HCBT_KEYSKIPPED",
1762 "HCBT_SYSCOMMAND",
1763 "HCBT_SETFOCUS"
1764 };
1765 const char *code_name = (msg->message <= HCBT_SETFOCUS) ? CBT_code_name[msg->message] : "Unknown";
1766
1767 snprintf( seq->output, sizeof(seq->output), "%s: hook %d (%s) wp %08lx lp %08lx",
1768 msg->descr, msg->message, code_name, msg->wParam, msg->lParam );
1769 }
1770 else if (msg->flags & winevent_hook)
1771 {
1772 snprintf( seq->output, sizeof(seq->output), "%s: winevent %p %08x %08lx %08lx",
1773 msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1774 }
1775 else
1776 {
1777 switch (msg->message)
1778 {
1779 case WM_WINDOWPOSCHANGING:
1780 case WM_WINDOWPOSCHANGED:
1781 {
1782 WINDOWPOS *winpos = (WINDOWPOS *)msg->lParam;
1783
1784 snprintf( seq->output, sizeof(seq->output),
1785 "%s: %p WM_WINDOWPOS%s wp %08lx lp %08lx after %p x %d y %d cx %d cy %d flags %s",
1786 msg->descr, msg->hwnd,
1787 (msg->message == WM_WINDOWPOSCHANGING) ? "CHANGING" : "CHANGED",
1788 msg->wParam, msg->lParam, winpos->hwndInsertAfter,
1789 winpos->x, winpos->y, winpos->cx, winpos->cy,
1790 get_winpos_flags(winpos->flags) );
1791
1792 /* Log only documented flags, win2k uses 0x1000 and 0x2000
1793 * in the high word for internal purposes
1794 */
1795 seq->wParam = winpos->flags & 0xffff;
1796 /* We are not interested in the flags that don't match under XP and Win9x */
1797 seq->wParam &= ~SWP_NOZORDER;
1798 break;
1799 }
1800
1801 case WM_DRAWITEM:
1802 {
1803 DRAW_ITEM_STRUCT di;
1804 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)msg->lParam;
1805
1806 snprintf( seq->output, sizeof(seq->output),
1807 "%s: %p WM_DRAWITEM: type %x, ctl_id %x, item_id %x, action %x, state %x",
1808 msg->descr, msg->hwnd, dis->CtlType, dis->CtlID,
1809 dis->itemID, dis->itemAction, dis->itemState);
1810
1811 di.u.item.type = dis->CtlType;
1812 di.u.item.ctl_id = dis->CtlID;
1813 di.u.item.item_id = dis->itemID;
1814 di.u.item.action = dis->itemAction;
1815 di.u.item.state = dis->itemState;
1816
1817 seq->lParam = di.u.lp;
1818 break;
1819 }
1820 default:
1821 if (msg->message >= 0xc000) return; /* ignore registered messages */
1822 snprintf( seq->output, sizeof(seq->output), "%s: %p %04x wp %08lx lp %08lx",
1823 msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1824 }
1825 }
1826 }
1827
1828 sequence_cnt++;
1829 }
1830
1831 /* try to make sure pending X events have been processed before continuing */
1832 static void flush_events(void)
1833 {
1834 MSG msg;
1835 int diff = 200;
1836 int min_timeout = 100;
1837 DWORD time = GetTickCount() + diff;
1838
1839 while (diff > 0)
1840 {
1841 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
1842 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
1843 diff = time - GetTickCount();
1844 }
1845 }
1846
1847 static void flush_sequence(void)
1848 {
1849 HeapFree(GetProcessHeap(), 0, sequence);
1850 sequence = 0;
1851 sequence_cnt = sequence_size = 0;
1852 }
1853
1854 static void dump_sequence(const struct message *expected, const char *context, const char *file, int line)
1855 {
1856 const struct recvd_message *actual = sequence;
1857 unsigned int count = 0;
1858
1859 trace_(file, line)("Failed sequence %s:\n", context );
1860 while (expected->message && actual->message)
1861 {
1862 if (actual->output[0])
1863 {
1864 if (expected->flags & hook)
1865 {
1866 trace_(file, line)( " %u: expected: hook %04x - actual: %s\n",
1867 count, expected->message, actual->output );
1868 }
1869 else if (expected->flags & winevent_hook)
1870 {
1871 trace_(file, line)( " %u: expected: winevent %04x - actual: %s\n",
1872 count, expected->message, actual->output );
1873 }
1874 else
1875 {
1876 trace_(file, line)( " %u: expected: msg %04x - actual: %s\n",
1877 count, expected->message, actual->output );
1878 }
1879 }
1880
1881 if (expected->message == actual->message)
1882 {
1883 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) &&
1884 (expected->flags & optional))
1885 {
1886 /* don't match messages if their defwinproc status differs */
1887 expected++;
1888 }
1889 else
1890 {
1891 expected++;
1892 actual++;
1893 }
1894 }
1895 /* silently drop winevent messages if there is no support for them */
1896 else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1897 expected++;
1898 else
1899 {
1900 expected++;
1901 actual++;
1902 }
1903 count++;
1904 }
1905
1906 /* optional trailing messages */
1907 while (expected->message && ((expected->flags & optional) ||
1908 ((expected->flags & winevent_hook) && !hEvent_hook)))
1909 {
1910 trace_(file, line)( " %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1911 expected++;
1912 count++;
1913 }
1914
1915 if (expected->message)
1916 {
1917 trace_(file, line)( " %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1918 return;
1919 }
1920
1921 while (actual->message && actual->output[0])
1922 {
1923 trace_(file, line)( " %u: expected: nothing - actual: %s\n", count, actual->output );
1924 actual++;
1925 count++;
1926 }
1927 }
1928
1929 #define ok_sequence( exp, contx, todo) \
1930 ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
1931
1932
1933 static void ok_sequence_(const struct message *expected_list, const char *context, int todo,
1934 const char *file, int line)
1935 {
1936 static const struct recvd_message end_of_sequence;
1937 const struct message *expected = expected_list;
1938 const struct recvd_message *actual;
1939 int failcount = 0, dump = 0;
1940 unsigned int count = 0;
1941
1942 add_message(&end_of_sequence);
1943
1944 actual = sequence;
1945
1946 while (expected->message && actual->message)
1947 {
1948 if (expected->message == actual->message)
1949 {
1950 if (expected->flags & wparam)
1951 {
1952 if (((expected->wParam ^ actual->wParam) & ~expected->wp_mask) && todo)
1953 {
1954 todo_wine {
1955 failcount ++;
1956 if (strcmp(winetest_platform, "wine")) dump++;
1957 ok_( file, line) (FALSE,
1958 "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1959 context, count, expected->message, expected->wParam, actual->wParam);
1960 }
1961 }
1962 else
1963 {
1964 ok_( file, line)( ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) == 0,
1965 "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1966 context, count, expected->message, expected->wParam, actual->wParam);
1967 if ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) dump++;
1968 }
1969
1970 }
1971 if (expected->flags & lparam)
1972 {
1973 if (((expected->lParam ^ actual->lParam) & ~expected->lp_mask) && todo)
1974 {
1975 todo_wine {
1976 failcount ++;
1977 if (strcmp(winetest_platform, "wine")) dump++;
1978 ok_( file, line) (FALSE,
1979 "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1980 context, count, expected->message, expected->lParam, actual->lParam);
1981 }
1982 }
1983 else
1984 {
1985 ok_( file, line)(((expected->lParam ^ actual->lParam) & ~expected->lp_mask) == 0,
1986 "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1987 context, count, expected->message, expected->lParam, actual->lParam);
1988 if ((expected->lParam ^ actual->lParam) & ~expected->lp_mask) dump++;
1989 }
1990 }
1991 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) &&
1992 (expected->flags & optional))
1993 {
1994 /* don't match messages if their defwinproc status differs */
1995 expected++;
1996 count++;
1997 continue;
1998 }
1999 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
2000 {
2001 todo_wine {
2002 failcount ++;
2003 if (strcmp(winetest_platform, "wine")) dump++;
2004 ok_( file, line) (FALSE,
2005 "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2006 context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2007 }
2008 }
2009 else
2010 {
2011 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
2012 "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2013 context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2014 if ((expected->flags & defwinproc) != (actual->flags & defwinproc)) dump++;
2015 }
2016
2017 ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
2018 "%s: %u: the msg 0x%04x should %shave been sent by BeginPaint\n",
2019 context, count, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
2020 if ((expected->flags & beginpaint) != (actual->flags & beginpaint)) dump++;
2021
2022 ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
2023 "%s: %u: the msg 0x%04x should have been %s\n",
2024 context, count, expected->message, (expected->flags & posted) ? "posted" : "sent");
2025 if ((expected->flags & (sent|posted)) != (actual->flags & (sent|posted))) dump++;
2026
2027 ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
2028 "%s: %u: the msg 0x%04x was expected in %s\n",
2029 context, count, expected->message, (expected->flags & parent) ? "parent" : "child");
2030 if ((expected->flags & parent) != (actual->flags & parent)) dump++;
2031
2032 ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
2033 "%s: %u: the msg 0x%04x should have been sent by a hook\n",
2034 context, count, expected->message);
2035 if ((expected->flags & hook) != (actual->flags & hook)) dump++;
2036
2037 ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
2038 "%s: %u: the msg 0x%04x should have been sent by a winevent hook\n",
2039 context, count, expected->message);
2040 if ((expected->flags & winevent_hook) != (actual->flags & winevent_hook)) dump++;
2041
2042 expected++;
2043 actual++;
2044 }
2045 /* silently drop hook messages if there is no support for them */
2046 else if ((expected->flags & optional) ||
2047 ((expected->flags & hook) && !hCBT_hook) ||
2048 ((expected->flags & winevent_hook) && !hEvent_hook))
2049 expected++;
2050 else if (todo)
2051 {
2052 failcount++;
2053 todo_wine {
2054 if (strcmp(winetest_platform, "wine")) dump++;
2055 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2056 context, count, expected->message, actual->message);
2057 }
2058 goto done;
2059 }
2060 else
2061 {
2062 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2063 context, count, expected->message, actual->message);
2064 dump++;
2065 expected++;
2066 actual++;
2067 }
2068 count++;
2069 }
2070
2071 /* skip all optional trailing messages */
2072 while (expected->message && ((expected->flags & optional) ||
2073 ((expected->flags & hook) && !hCBT_hook) ||
2074 ((expected->flags & winevent_hook) && !hEvent_hook)))
2075 expected++;
2076
2077 if (todo)
2078 {
2079 todo_wine {
2080 if (expected->message || actual->message) {
2081 failcount++;
2082 if (strcmp(winetest_platform, "wine")) dump++;
2083 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2084 context, count, expected->message, actual->message);
2085 }
2086 }
2087 }
2088 else
2089 {
2090 if (expected->message || actual->message)
2091 {
2092 dump++;
2093 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2094 context, count, expected->message, actual->message);
2095 }
2096 }
2097 if( todo && !failcount) /* succeeded yet marked todo */
2098 todo_wine {
2099 if (!strcmp(winetest_platform, "wine")) dump++;
2100 ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
2101 }
2102
2103 done:
2104 if (dump) dump_sequence(expected_list, context, file, line);
2105 flush_sequence();
2106 }
2107
2108 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
2109
2110 /******************************** MDI test **********************************/
2111
2112 /* CreateWindow for MDI frame window, initially visible */
2113 static const struct message WmCreateMDIframeSeq[] = {
2114 { HCBT_CREATEWND, hook },
2115 { WM_GETMINMAXINFO, sent },
2116 { WM_NCCREATE, sent },
2117 { WM_NCCALCSIZE, sent|wparam, 0 },
2118 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2119 { WM_CREATE, sent },
2120 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2121 { WM_NOTIFYFORMAT, sent|optional },
2122 { WM_QUERYUISTATE, sent|optional },
2123 { WM_WINDOWPOSCHANGING, sent|optional },
2124 { WM_GETMINMAXINFO, sent|optional },
2125 { WM_NCCALCSIZE, sent|optional },
2126 { WM_WINDOWPOSCHANGED, sent|optional },
2127 { WM_SHOWWINDOW, sent|wparam, 1 },
2128 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2129 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2130 { HCBT_ACTIVATE, hook },
2131 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
2132 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
2133 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
2134 { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
2135 { WM_NCACTIVATE, sent },
2136 { WM_GETTEXT, sent|defwinproc|optional },
2137 { WM_ACTIVATE, sent|wparam, 1 },
2138 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
2139 { HCBT_SETFOCUS, hook },
2140 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2141 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2142 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2143 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
2144 /* Win9x adds SWP_NOZORDER below */
2145 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2146 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2147 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2148 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2149 { WM_MOVE, sent },
2150 { 0 }
2151 };
2152 /* DestroyWindow for MDI frame window, initially visible */
2153 static const struct message WmDestroyMDIframeSeq[] = {
2154 { HCBT_DESTROYWND, hook },
2155 { 0x0090, sent|optional },
2156 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2157 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2158 { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2159 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2160 { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
2161 { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2162 { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
2163 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
2164 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2165 { WM_DESTROY, sent },
2166 { WM_NCDESTROY, sent },
2167 { 0 }
2168 };
2169 /* CreateWindow for MDI client window, initially visible */
2170 static const struct message WmCreateMDIclientSeq[] = {
2171 { HCBT_CREATEWND, hook },
2172 { WM_NCCREATE, sent },
2173 { WM_NCCALCSIZE, sent|wparam, 0 },
2174 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2175 { WM_CREATE, sent },
2176 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2177 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2178 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2179 { WM_MOVE, sent },
2180 { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
2181 { WM_SHOWWINDOW, sent|wparam, 1 },
2182 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2183 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2184 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2185 { 0 }
2186 };
2187 /* ShowWindow(SW_SHOW) for MDI client window */
2188 static const struct message WmShowMDIclientSeq[] = {
2189 { WM_SHOWWINDOW, sent|wparam, 1 },
2190 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2191 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2192 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2193 { 0 }
2194 };
2195 /* ShowWindow(SW_HIDE) for MDI client window */
2196 static const struct message WmHideMDIclientSeq[] = {
2197 { WM_SHOWWINDOW, sent|wparam, 0 },
2198 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2199 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
2200 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
2201 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2202 { 0 }
2203 };
2204 /* DestroyWindow for MDI client window, initially visible */
2205 static const struct message WmDestroyMDIclientSeq[] = {
2206 { HCBT_DESTROYWND, hook },
2207 { 0x0090, sent|optional },
2208 { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
2209 { WM_SHOWWINDOW, sent|wparam, 0 },
2210 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2211 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2212 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2213 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2214 { WM_DESTROY, sent },
2215 { WM_NCDESTROY, sent },
2216 { 0 }
2217 };
2218 /* CreateWindow for MDI child window, initially visible */
2219 static const struct message WmCreateMDIchildVisibleSeq[] = {
2220 { HCBT_CREATEWND, hook },
2221 { WM_NCCREATE, sent },
2222 { WM_NCCALCSIZE, sent|wparam, 0 },
2223 { WM_CREATE, sent },
2224 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2225 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2226 { WM_MOVE, sent },
2227 /* Win2k sends wparam set to
2228 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2229 * while Win9x doesn't bother to set child window id according to
2230 * CLIENTCREATESTRUCT.idFirstChild
2231 */
2232 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2233 { WM_SHOWWINDOW, sent|wparam, 1 },
2234 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2235 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2236 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2237 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2238 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2239 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2240 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2241
2242 /* Win9x: message sequence terminates here. */
2243
2244 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2245 { HCBT_SETFOCUS, hook }, /* in MDI client */
2246 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2247 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2248 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2249 { WM_SETFOCUS, sent }, /* in MDI client */
2250 { HCBT_SETFOCUS, hook },
2251 { WM_KILLFOCUS, sent }, /* in MDI client */
2252 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2253 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2254 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2255 { WM_SETFOCUS, sent|defwinproc },
2256 { WM_MDIACTIVATE, sent|defwinproc },
2257 { 0 }
2258 };
2259 /* CreateWindow for MDI child window with invisible parent */
2260 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
2261 { HCBT_CREATEWND, hook },
2262 { WM_GETMINMAXINFO, sent },
2263 { WM_NCCREATE, sent },
2264 { WM_NCCALCSIZE, sent|wparam, 0 },
2265 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2266 { WM_CREATE, sent },
2267 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2268 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2269 { WM_MOVE, sent },
2270 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2271 { WM_SHOWWINDOW, sent|wparam, 1 },
2272 { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2273 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2274 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2275 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2276
2277 /* Win9x: message sequence terminates here. */
2278
2279 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2280 { HCBT_SETFOCUS, hook }, /* in MDI client */
2281 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2282 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2283 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2284 { WM_SETFOCUS, sent }, /* in MDI client */
2285 { HCBT_SETFOCUS, hook },
2286 { WM_KILLFOCUS, sent }, /* in MDI client */
2287 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2288 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2289 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2290 { WM_SETFOCUS, sent|defwinproc },
2291 { WM_MDIACTIVATE, sent|defwinproc },
2292 { 0 }
2293 };
2294 /* DestroyWindow for MDI child window, initially visible */
2295 static const struct message WmDestroyMDIchildVisibleSeq[] = {
2296 { HCBT_DESTROYWND, hook },
2297 /* Win2k sends wparam set to
2298 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2299 * while Win9x doesn't bother to set child window id according to
2300 * CLIENTCREATESTRUCT.idFirstChild
2301 */
2302 { 0x0090, sent|optional },
2303 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2304 { WM_SHOWWINDOW, sent|wparam, 0 },
2305 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2306 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2307 { WM_ERASEBKGND, sent|parent|optional },
2308 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2309
2310 /* { WM_DESTROY, sent }
2311 * Win9x: message sequence terminates here.
2312 */
2313
2314 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2315 { WM_KILLFOCUS, sent },
2316 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2317 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2318 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2319 { WM_SETFOCUS, sent }, /* in MDI client */
2320
2321 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2322 { WM_KILLFOCUS, sent }, /* in MDI client */
2323 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2324 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2325 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2326 { WM_SETFOCUS, sent }, /* in MDI client */
2327
2328 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2329
2330 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2331 { WM_KILLFOCUS, sent },
2332 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2333 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2334 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2335 { WM_SETFOCUS, sent }, /* in MDI client */
2336
2337 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2338 { WM_KILLFOCUS, sent }, /* in MDI client */
2339 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2340 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2341 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2342 { WM_SETFOCUS, sent }, /* in MDI client */
2343
2344 { WM_DESTROY, sent },
2345
2346 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2347 { WM_KILLFOCUS, sent },
2348 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2349 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2350 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2351 { WM_SETFOCUS, sent }, /* in MDI client */
2352
2353 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2354 { WM_KILLFOCUS, sent }, /* in MDI client */
2355 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2356 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2357 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2358 { WM_SETFOCUS, sent }, /* in MDI client */
2359
2360 { WM_NCDESTROY, sent },
2361 { 0 }
2362 };
2363 /* CreateWindow for MDI child window, initially invisible */
2364 static const struct message WmCreateMDIchildInvisibleSeq[] = {
2365 { HCBT_CREATEWND, hook },
2366 { WM_NCCREATE, sent },
2367 { WM_NCCALCSIZE, sent|wparam, 0 },
2368 { WM_CREATE, sent },
2369 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2370 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2371 { WM_MOVE, sent },
2372 /* Win2k sends wparam set to
2373 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2374 * while Win9x doesn't bother to set child window id according to
2375 * CLIENTCREATESTRUCT.idFirstChild
2376 */
2377 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2378 { 0 }
2379 };
2380 /* DestroyWindow for MDI child window, initially invisible */
2381 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
2382 { HCBT_DESTROYWND, hook },
2383 /* Win2k sends wparam set to
2384 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2385 * while Win9x doesn't bother to set child window id according to
2386 * CLIENTCREATESTRUCT.idFirstChild
2387 */
2388 { 0x0090, sent|optional },
2389 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2390 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2391 { WM_DESTROY, sent },
2392 { WM_NCDESTROY, sent },
2393 /* FIXME: Wine destroys an icon/title window while Windows doesn't */
2394 { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
2395 { 0 }
2396 };
2397 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
2398 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
2399 { HCBT_CREATEWND, hook },
2400 { WM_NCCREATE, sent },
2401 { WM_NCCALCSIZE, sent|wparam, 0 },
2402 { WM_CREATE, sent },
2403 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2404 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2405 { WM_MOVE, sent },
2406 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2407 { WM_GETMINMAXINFO, sent },
2408 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2409 { WM_NCCALCSIZE, sent|wparam, 1 },
2410 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2411 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2412 /* in MDI frame */
2413 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2414 { WM_NCCALCSIZE, sent|wparam, 1 },
2415 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2416 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2417 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2418 /* Win2k sends wparam set to
2419 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2420 * while Win9x doesn't bother to set child window id according to
2421 * CLIENTCREATESTRUCT.idFirstChild
2422 */
2423 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2424 { WM_SHOWWINDOW, sent|wparam, 1 },
2425 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2426 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2427 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2428 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2429 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2430 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2431 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2432
2433 /* Win9x: message sequence terminates here. */
2434
2435 { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2436 { HCBT_SETFOCUS, hook|optional }, /* in MDI client */
2437 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2438 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2439 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2440 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2441 { HCBT_SETFOCUS, hook|optional },
2442 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2443 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2444 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2445 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2446 { WM_SETFOCUS, sent|defwinproc|optional },
2447 { WM_MDIACTIVATE, sent|defwinproc|optional },
2448 /* in MDI frame */
2449 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2450 { WM_NCCALCSIZE, sent|wparam, 1 },
2451 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2452 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2453 { 0 }
2454 };
2455 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
2456 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
2457 /* restore the 1st MDI child */
2458 { WM_SETREDRAW, sent|wparam, 0 },
2459 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2460 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2461 { WM_NCCALCSIZE, sent|wparam, 1 },
2462 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2463 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2464 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2465 /* in MDI frame */
2466 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2467 { WM_NCCALCSIZE, sent|wparam, 1 },
2468 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2469 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2470 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2471 { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
2472 /* create the 2nd MDI child */
2473 { HCBT_CREATEWND, hook },
2474 { WM_NCCREATE, sent },
2475 { WM_NCCALCSIZE, sent|wparam, 0 },
2476 { WM_CREATE, sent },
2477 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2478 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2479 { WM_MOVE, sent },
2480 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2481 { WM_GETMINMAXINFO, sent },
2482 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2483 { WM_NCCALCSIZE, sent|wparam, 1 },
2484 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2485 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2486 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2487 /* in MDI frame */
2488 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2489 { WM_NCCALCSIZE, sent|wparam, 1 },
2490 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2491 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2492 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2493 /* Win2k sends wparam set to
2494 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2495 * while Win9x doesn't bother to set child window id according to
2496 * CLIENTCREATESTRUCT.idFirstChild
2497 */
2498 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2499 { WM_SHOWWINDOW, sent|wparam, 1 },
2500 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2501 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2502 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2503 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2504 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2505 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2506
2507 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2508 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2509
2510 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2511
2512 /* Win9x: message sequence terminates here. */
2513
2514 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2515 { HCBT_SETFOCUS, hook },
2516 { WM_KILLFOCUS, sent|defwinproc|optional }, /* in the 1st MDI child */
2517 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2518 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2519 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2520 { WM_SETFOCUS, sent }, /* in MDI client */
2521 { HCBT_SETFOCUS, hook },
2522 { WM_KILLFOCUS, sent }, /* in MDI client */
2523 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2524 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2525 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2526 { WM_SETFOCUS, sent|defwinproc },
2527
2528 { WM_MDIACTIVATE, sent|defwinproc },
2529 /* in MDI frame */
2530 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2531 { WM_NCCALCSIZE, sent|wparam, 1 },
2532 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2533 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2534 { 0 }
2535 };
2536 /* WM_MDICREATE MDI child window, initially visible and maximized */
2537 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2538 { WM_MDICREATE, sent },
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 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2551 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2552
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
2560 /* Win2k sends wparam set to
2561 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2562 * while Win9x doesn't bother to set child window id according to
2563 * CLIENTCREATESTRUCT.idFirstChild
2564 */
2565 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2566 { WM_SHOWWINDOW, sent|wparam, 1 },
2567 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2568
2569 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2570
2571 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2572 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2573 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2574
2575 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
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 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2582 { HCBT_SETFOCUS, hook }, /* in MDI client */
2583 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2584 { WM_IME_NOTIFY, sent|wparam|optional, 2 },
2585 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2586 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2587 { HCBT_SETFOCUS, hook|optional },
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
2596 /* in MDI child */
2597 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2598 { WM_NCCALCSIZE, sent|wparam, 1 },
2599 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2600 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2601
2602 /* in MDI frame */
2603 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2604 { WM_NCCALCSIZE, sent|wparam, 1 },
2605 { 0x0093, sent|defwinproc|optional },
2606 { 0x0093, sent|defwinproc|optional },
2607 { 0x0093, sent|defwinproc|optional },
2608 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2609 { WM_MOVE, sent|defwinproc },
2610 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2611
2612 /* in MDI client */
2613 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2614 { WM_NCCALCSIZE, sent|wparam, 1 },
2615 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2616 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2617
2618 /* in MDI child */
2619 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2620 { WM_NCCALCSIZE, sent|wparam, 1 },
2621 { 0x0093, sent|optional },
2622 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2623 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2624
2625 { 0x0093, sent|optional },
2626 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2627 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2628 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2629 { 0x0093, sent|defwinproc|optional },
2630 { 0x0093, sent|defwinproc|optional },
2631 { 0x0093, sent|defwinproc|optional },
2632 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2633 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2634
2635 { 0 }
2636 };
2637 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2638 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2639 { HCBT_CREATEWND, hook },
2640 { WM_GETMINMAXINFO, sent },
2641 { WM_NCCREATE, sent },
2642 { WM_NCCALCSIZE, sent|wparam, 0 },
2643 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2644 { WM_CREATE, sent },
2645 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2646 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2647 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2648 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI frame */
2649 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2650 { WM_MOVE, sent },
2651 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2652 { WM_GETMINMAXINFO, sent },
2653 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2654 { WM_GETMINMAXINFO, sent|defwinproc },
2655 { WM_NCCALCSIZE, sent|wparam, 1 },
2656 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
2657 { WM_MOVE, sent|defwinproc },
2658 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2659 /* in MDI frame */
2660 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2661 { WM_NCCALCSIZE, sent|wparam, 1 },
2662 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2663 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2664 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2665 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2666 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2667 /* Win2k sends wparam set to
2668 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2669 * while Win9x doesn't bother to set child window id according to
2670 * CLIENTCREATESTRUCT.idFirstChild
2671 */
2672 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2673 { 0 }
2674 };
2675 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2676 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2677 { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2678 { HCBT_SYSCOMMAND, hook },
2679 { WM_CLOSE, sent|defwinproc },
2680 { WM_MDIDESTROY, sent }, /* in MDI client */
2681
2682 /* bring the 1st MDI child to top */
2683 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2684 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2685
2686 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2687
2688 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2689 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2690 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2691
2692 /* maximize the 1st MDI child */
2693 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2694 { WM_GETMINMAXINFO, sent|defwinproc },
2695 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED },
2696 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2697 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2698 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2699 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2700
2701 /* restore the 2nd MDI child */
2702 { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2703 { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2704 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2705 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2706
2707 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2708
2709 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2710 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2711
2712 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2713
2714 { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2715 /* in MDI frame */
2716 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2717 { WM_NCCALCSIZE, sent|wparam, 1 },
2718 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2719 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2720 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2721
2722 /* bring the 1st MDI child to top */
2723 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2724 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2725 { HCBT_SETFOCUS, hook },
2726 { WM_KILLFOCUS, sent|defwinproc },
2727 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2728 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2729 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2730 { WM_SETFOCUS, sent }, /* in MDI client */
2731 { HCBT_SETFOCUS, hook },
2732 { WM_KILLFOCUS, sent }, /* in MDI client */
2733 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2734 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2735 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2736 { WM_SETFOCUS, sent|defwinproc },
2737 { WM_MDIACTIVATE, sent|defwinproc },
2738 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2739
2740 /* apparently ShowWindow(SW_SHOW) on an MDI client */
2741 { WM_SHOWWINDOW, sent|wparam, 1 },
2742 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2743 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2744 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2745 { WM_MDIREFRESHMENU, sent },
2746
2747 { HCBT_DESTROYWND, hook },
2748 /* Win2k sends wparam set to
2749 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2750 * while Win9x doesn't bother to set child window id according to
2751 * CLIENTCREATESTRUCT.idFirstChild
2752 */
2753 { 0x0090, sent|defwinproc|optional },
2754 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2755 { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2756 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2757 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2758 { WM_ERASEBKGND, sent|parent|optional },
2759 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2760
2761 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2762 { WM_DESTROY, sent|defwinproc },
2763 { WM_NCDESTROY, sent|defwinproc },
2764 { 0 }
2765 };
2766 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2767 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2768 { WM_MDIDESTROY, sent }, /* in MDI client */
2769 { WM_SHOWWINDOW, sent|wparam, 0 },
2770 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2771 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2772 { WM_ERASEBKGND, sent|parent|optional },
2773 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2774
2775 { HCBT_SETFOCUS, hook },
2776 { WM_KILLFOCUS, sent },
2777 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2778 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2779 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2780 { WM_SETFOCUS, sent }, /* in MDI client */
2781 { HCBT_SETFOCUS, hook },
2782 { WM_KILLFOCUS, sent }, /* in MDI client */
2783 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2784 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2785 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2786 { WM_SETFOCUS, sent },
2787
2788 /* in MDI child */
2789 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2790 { WM_NCCALCSIZE, sent|wparam, 1 },
2791 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2792 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2793
2794 /* in MDI frame */
2795 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2796 { WM_NCCALCSIZE, sent|wparam, 1 },
2797 { 0x0093, sent|defwinproc|optional },
2798 { 0x0093, sent|defwinproc|optional },
2799 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2800 { WM_MOVE, sent|defwinproc },
2801 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2802
2803 /* in MDI client */
2804 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2805 { WM_NCCALCSIZE, sent|wparam, 1 },
2806 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2807 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2808
2809 /* in MDI child */
2810 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2811 { WM_NCCALCSIZE, sent|wparam, 1 },
2812 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2813 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2814
2815 /* in MDI child */
2816 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2817 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2818 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2819 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2820
2821 /* in MDI frame */
2822 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2823 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2824 { 0x0093, sent|defwinproc|optional },
2825 { 0x0093, sent|defwinproc|optional },
2826 { 0x0093, sent|defwinproc|optional },
2827 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2828 { WM_MOVE, sent|defwinproc },
2829 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2830
2831 /* in MDI client */
2832 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2833 { WM_NCCALCSIZE, sent|wparam, 1 },
2834 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2835 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2836
2837 /* in MDI child */
2838 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2839 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2840 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2841 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2842 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2843 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2844
2845 { 0x0093, sent|defwinproc|optional },
2846 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2847 { 0x0093, sent|defwinproc|optional },
2848 { 0x0093, sent|defwinproc|optional },
2849 { 0x0093, sent|defwinproc|optional },
2850 { 0x0093, sent|optional },
2851
2852 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2853 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2854 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2855 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2856 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2857
2858 /* in MDI frame */
2859 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2860 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2861 { 0x0093, sent|defwinproc|optional },
2862 { 0x0093, sent|defwinproc|optional },
2863 { 0x0093, sent|defwinproc|optional },
2864 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2865 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2866 { 0x0093, sent|optional },
2867
2868 { WM_NCACTIVATE, sent|wparam, 0 },
2869 { WM_MDIACTIVATE, sent },
2870
2871 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2872 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2873 { WM_NCCALCSIZE, sent|wparam, 1 },
2874
2875 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2876
2877 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2878 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2879 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
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_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2885 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2886
2887 /* in MDI frame */
2888 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2889 { WM_NCCALCSIZE, sent|wparam, 1 },
2890 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2891 { WM_MOVE, sent|defwinproc },
2892 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2893
2894 /* in MDI client */
2895 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2896 { WM_NCCALCSIZE, sent|wparam, 1 },
2897 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2898 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2899 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2900 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2901 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2902 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2903 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2904
2905 { HCBT_SETFOCUS, hook },
2906 { WM_KILLFOCUS, sent },
2907 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2908 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2909 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2910 { WM_SETFOCUS, sent }, /* in MDI client */
2911
2912 { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2913
2914 { HCBT_DESTROYWND, hook },
2915 /* Win2k sends wparam set to
2916 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2917 * while Win9x doesn't bother to set child window id according to
2918 * CLIENTCREATESTRUCT.idFirstChild
2919 */
2920 { 0x0090, sent|optional },
2921 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2922
2923 { WM_SHOWWINDOW, sent|wparam, 0 },
2924 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2925 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2926 { WM_ERASEBKGND, sent|parent|optional },
2927 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2928
2929 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2930 { WM_DESTROY, sent },
2931 { WM_NCDESTROY, sent },
2932 { 0 }
2933 };
2934 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
2935 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
2936 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2937 { WM_GETMINMAXINFO, sent },
2938 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
2939 { WM_NCCALCSIZE, sent|wparam, 1 },
2940 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2941 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2942
2943 { WM_WINDOWPOSCHANGING, sent|wparam|optional|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2944 { WM_NCACTIVATE, sent|wparam|optional|defwinproc, 1 },
2945 { HCBT_SETFOCUS, hook|optional },
2946 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2947 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2948 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2949 { HCBT_SETFOCUS, hook|optional },
2950 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2951 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2952 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2953 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2954 { WM_SETFOCUS, sent|optional|defwinproc },
2955 { WM_MDIACTIVATE, sent|optional|defwinproc },
2956 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2957 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2958 /* in MDI frame */
2959 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2960 { WM_NCCALCSIZE, sent|wparam, 1 },
2961 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2962 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2963 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2964 { 0 }
2965 };
2966 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
2967 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
2968 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2969 { WM_GETMINMAXINFO, sent },
2970 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
2971 { WM_GETMINMAXINFO, sent|defwinproc },
2972 { WM_NCCALCSIZE, sent|wparam, 1 },
2973 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2974 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2975
2976 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2977 { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2978 { HCBT_SETFOCUS, hook|optional },
2979 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2980 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2981 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2982 { HCBT_SETFOCUS, hook|optional },
2983 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2984 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2985 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2986 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2987 { WM_SETFOCUS, sent|defwinproc|optional },
2988 { WM_MDIACTIVATE, sent|defwinproc|optional },
2989 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2990 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2991 { 0 }
2992 };
2993 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
2994 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
2995 { WM_MDIMAXIMIZE, sent }, /* in MDI client */
2996 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2997 { WM_GETMINMAXINFO, sent },
2998 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2999 { WM_GETMINMAXINFO, sent|defwinproc },
3000 { WM_NCCALCSIZE, sent|wparam, 1 },
3001 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
3002 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3003 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
3004 { WM_MOVE, sent|defwinproc },
3005 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3006
3007 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3008 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3009 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3010 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3011 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3012 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3013 /* in MDI frame */
3014 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3015 { WM_NCCALCSIZE, sent|wparam, 1 },
3016 { 0x0093, sent|defwinproc|optional },
3017 { 0x0094, sent|defwinproc|optional },
3018 { 0x0094, sent|defwinproc|optional },
3019 { 0x0094, sent|defwinproc|optional },
3020 { 0x0094, sent|defwinproc|optional },
3021 { 0x0093, sent|defwinproc|optional },
3022 { 0x0093, sent|defwinproc|optional },
3023 { 0x0091, sent|defwinproc|optional },
3024 { 0x0092, sent|defwinproc|optional },
3025 { 0x0092, sent|defwinproc|optional },
3026 { 0x0092, sent|defwinproc|optional },
3027 { 0x0092, sent|defwinproc|optional },
3028 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3029 { WM_MOVE, sent|defwinproc },
3030 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3031 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
3032 /* in MDI client */
3033 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
3034 { WM_NCCALCSIZE, sent|wparam, 1 },
3035 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3036 { WM_SIZE, sent|wparam, SIZE_RESTORED },
3037 /* in MDI child */
3038 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
3039 { WM_GETMINMAXINFO, sent|defwinproc },
3040 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3041 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3042 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3043 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
3044 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3045 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3046 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3047 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3048 /* in MDI frame */
3049 { 0x0093, sent|optional },
3050 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
3051 { 0x0093, sent|defwinproc|optional },
3052 { 0x0093, sent|defwinproc|optional },
3053 { 0x0093, sent|defwinproc|optional },
3054 { 0x0091, sent|defwinproc|optional },
3055 { 0x0092, sent|defwinproc|optional },
3056 { 0x0092, sent|defwinproc|optional },
3057 { 0x0092, sent|defwinproc|optional },
3058 { 0x0092, sent|defwinproc|optional },
3059 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3060 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3061 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3062 { 0 }
3063 };
3064 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
3065 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
3066 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3067 { WM_GETMINMAXINFO, sent },
3068 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3069 { WM_NCCALCSIZE, sent|wparam, 1 },
3070 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3071 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3072 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3073 /* in MDI frame */
3074 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3075 { WM_NCCALCSIZE, sent|wparam, 1 },
3076 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3077 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3078 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3079 { 0 }
3080 };
3081 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
3082 static const struct message WmRestoreMDIchildVisibleSeq[] = {
3083 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3084 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3085 { WM_NCCALCSIZE, sent|wparam, 1 },
3086 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3087 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3088 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3089 /* in MDI frame */
3090 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3091 { WM_NCCALCSIZE, sent|wparam, 1 },
3092 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3093 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3094 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3095 { 0 }
3096 };
3097 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
3098 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
3099 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3100 { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
3101 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3102 { WM_NCCALCSIZE, sent|wparam, 1 },
3103 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3104 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
3105 { WM_MOVE, sent|defwinproc },
3106 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3107 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3108 { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3109 { HCBT_SETFOCUS, hook },
3110 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3111 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
3112 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3113 { WM_SETFOCUS, sent },
3114 { 0 }
3115 };
3116 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
3117 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
3118 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
3119 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3120 { WM_NCCALCSIZE, sent|wparam, 1 },
3121 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
3122 { WM_MOVE, sent|defwinproc },
3123 { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
3124 { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
3125 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3126 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3127 /* FIXME: Wine creates an icon/title window while Windows doesn't */
3128 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
3129 { 0 }
3130 };
3131 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
3132 static const struct message WmRestoreMDIchildInisibleSeq[] = {
3133 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3134 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
3135 { WM_NCCALCSIZE, sent|wparam, 1 },
3136 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3137 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3138 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3139 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3140 /* in MDI frame */
3141 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3142 { WM_NCCALCSIZE, sent|wparam, 1 },
3143 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3144 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3145 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3146 { 0 }
3147 };
3148
3149 static HWND mdi_client;
3150 static WNDPROC old_mdi_client_proc;
3151
3152 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3153 {
3154 struct recvd_message msg;
3155
3156 /* do not log painting messages */
3157 if (message != WM_PAINT &&
3158 message != WM_NCPAINT &&
3159 message != WM_SYNCPAINT &&
3160 message != WM_ERASEBKGND &&
3161 message != WM_NCHITTEST &&
3162 message != WM_GETTEXT &&
3163 message != WM_MDIGETACTIVE &&
3164 message != WM_GETICON &&
3165 message != WM_GETOBJECT &&
3166 message != WM_DEVICECHANGE)
3167 {
3168 msg.hwnd = hwnd;
3169 msg.message = message;
3170 msg.flags = sent|wparam|lparam;
3171 msg.wParam = wParam;
3172 msg.lParam = lParam;
3173 msg.descr = "mdi client";
3174 add_message(&msg);
3175 }
3176
3177 return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
3178 }
3179
3180 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3181 {
3182 static long defwndproc_counter = 0;
3183 LRESULT ret;
3184 struct recvd_message msg;
3185
3186 /* do not log painting messages */
3187 if (message != WM_PAINT &&
3188 message != WM_NCPAINT &&
3189 message != WM_SYNCPAINT &&
3190 message != WM_ERASEBKGND &&
3191 message != WM_NCHITTEST &&
3192 message != WM_GETTEXT &&
3193 message != WM_GETICON &&
3194 message != WM_GETOBJECT &&
3195 message != WM_DEVICECHANGE)
3196 {
3197 switch (message)
3198 {
3199 case WM_MDIACTIVATE:
3200 {
3201 HWND active, client = GetParent(hwnd);
3202
3203 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
3204
3205 if (hwnd == (HWND)lParam) /* if we are being activated */
3206 ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
3207 else
3208 ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
3209 break;
3210 }
3211 }
3212
3213 msg.hwnd = hwnd;
3214 msg.message = message;
3215 msg.flags = sent|wparam|lparam;
3216 if (defwndproc_counter) msg.flags |= defwinproc;
3217 msg.wParam = wParam;
3218 msg.lParam = lParam;
3219 msg.descr = "mdi child";
3220 add_message(&msg);
3221 }
3222
3223 defwndproc_counter++;
3224 ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
3225 defwndproc_counter--;
3226
3227 return ret;
3228 }
3229
3230 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3231 {
3232 static long defwndproc_counter = 0;
3233 LRESULT ret;
3234 struct recvd_message msg;
3235
3236 /* do not log painting messages */
3237 if (message != WM_PAINT &&
3238 message != WM_NCPAINT &&
3239 message != WM_SYNCPAINT &&
3240 message != WM_ERASEBKGND &&
3241 message != WM_NCHITTEST &&
3242 message != WM_GETTEXT &&
3243 message != WM_GETICON &&
3244 message != WM_GETOBJECT &&
3245 message != WM_DEVICECHANGE)
3246 {
3247 msg.hwnd = hwnd;
3248 msg.message = message;
3249 msg.flags = sent|wparam|lparam;
3250 if (defwndproc_counter) msg.flags |= defwinproc;
3251 msg.wParam = wParam;
3252 msg.lParam = lParam;
3253 msg.descr = "mdi frame";
3254 add_message(&msg);
3255 }
3256
3257 defwndproc_counter++;
3258 ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
3259 defwndproc_counter--;
3260
3261 return ret;
3262 }
3263
3264 static BOOL mdi_RegisterWindowClasses(void)
3265 {
3266 WNDCLASSA cls;
3267
3268 cls.style = 0;
3269 cls.lpfnWndProc = mdi_frame_wnd_proc;
3270 cls.cbClsExtra = 0;
3271 cls.cbWndExtra = 0;
3272 cls.hInstance = GetModuleHandleA(0);
3273 cls.hIcon = 0;
3274 cls.hCursor = LoadCursorA(0, IDC_ARROW);
3275 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3276 cls.lpszMenuName = NULL;
3277 cls.lpszClassName = "MDI_frame_class";
3278 if (!RegisterClassA(&cls)) return FALSE;
3279
3280 cls.lpfnWndProc = mdi_child_wnd_proc;
3281 cls.lpszClassName = "MDI_child_class";
3282 if (!RegisterClassA(&cls)) return FALSE;
3283
3284 if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
3285 old_mdi_client_proc = cls.lpfnWndProc;
3286 cls.hInstance = GetModuleHandleA(0);
3287 cls.lpfnWndProc = mdi_client_hook_proc;
3288 cls.lpszClassName = "MDI_client_class";
3289 if (!RegisterClassA(&cls)) assert(0);
3290
3291 return TRUE;
3292 }
3293
3294 static void test_mdi_messages(void)
3295 {
3296 MDICREATESTRUCTA mdi_cs;
3297 CLIENTCREATESTRUCT client_cs;
3298 HWND mdi_frame, mdi_child, mdi_child2, active_child;
3299 BOOL zoomed;
3300 HMENU hMenu = CreateMenu();
3301
3302 assert(mdi_RegisterWindowClasses());
3303
3304 flush_sequence();
3305
3306 trace("creating MDI frame window\n");
3307 mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
3308 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3309 WS_MAXIMIZEBOX | WS_VISIBLE,
3310 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
3311 GetDesktopWindow(), hMenu,
3312 GetModuleHandleA(0), NULL);
3313 assert(mdi_frame);
3314 ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
3315
3316 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3317 ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
3318
3319 trace("creating MDI client window\n");
3320 client_cs.hWindowMenu = 0;
3321 client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
3322 mdi_client = CreateWindowExA(0, "MDI_client_class",
3323 NULL,
3324 WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
3325 0, 0, 0, 0,
3326 mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3327 assert(mdi_client);
3328 ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
3329
3330 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3331 ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
3332
3333 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3334 ok(!active_child, "wrong active MDI child %p\n", active_child);
3335 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3336
3337 SetFocus(0);
3338 flush_sequence();
3339
3340 trace("creating invisible MDI child window\n");
3341 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3342 WS_CHILD,
3343 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3344 mdi_client, 0, GetModuleHandleA(0), NULL);
3345 assert(mdi_child);
3346
3347 flush_sequence();
3348 ShowWindow(mdi_child, SW_SHOWNORMAL);
3349 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
3350
3351 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3352 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3353
3354 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3355 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3356
3357 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3358 ok(!active_child, "wrong active MDI child %p\n", active_child);
3359 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3360
3361 ShowWindow(mdi_child, SW_HIDE);
3362 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
3363 flush_sequence();
3364
3365 ShowWindow(mdi_child, SW_SHOW);
3366 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
3367
3368 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3369 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3370
3371 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3372 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3373
3374 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3375 ok(!active_child, "wrong active MDI child %p\n", active_child);
3376 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3377
3378 DestroyWindow(mdi_child);
3379 flush_sequence();
3380
3381 trace("creating visible MDI child window\n");
3382 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3383 WS_CHILD | WS_VISIBLE,
3384 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3385 mdi_client, 0, GetModuleHandleA(0), NULL);
3386 assert(mdi_child);
3387 ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
3388
3389 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3390 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3391
3392 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3393 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3394
3395 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3396 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3397 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3398 flush_sequence();
3399
3400 DestroyWindow(mdi_child);
3401 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3402
3403 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3404 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3405
3406 /* Win2k: MDI client still returns a just destroyed child as active
3407 * Win9x: MDI client returns 0
3408 */
3409 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3410 ok(active_child == mdi_child || /* win2k */
3411 !active_child, /* win9x */
3412 "wrong active MDI child %p\n", active_child);
3413 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3414
3415 flush_sequence();
3416
3417 trace("creating invisible MDI child window\n");
3418 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3419 WS_CHILD,
3420 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3421 mdi_client, 0, GetModuleHandleA(0), NULL);
3422 assert(mdi_child2);
3423 ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
3424
3425 ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
3426 ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
3427
3428 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3429 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3430
3431 /* Win2k: MDI client still returns a just destroyed child as active
3432 * Win9x: MDI client returns mdi_child2
3433 */
3434 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3435 ok(active_child == mdi_child || /* win2k */
3436 active_child == mdi_child2, /* win9x */
3437 "wrong active MDI child %p\n", active_child);
3438 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3439 flush_sequence();
3440
3441 ShowWindow(mdi_child2, SW_MAXIMIZE);
3442 ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
3443
3444 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3445 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3446
3447 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3448 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3449 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3450 flush_sequence();
3451
3452 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3453 ok(GetFocus() == mdi_child2 || /* win2k */
3454 GetFocus() == 0, /* win9x */
3455 "wrong focus window %p\n", GetFocus());
3456
3457 SetFocus(0);
3458 flush_sequence();
3459
3460 ShowWindow(mdi_child2, SW_HIDE);
3461 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3462
3463 ShowWindow(mdi_child2, SW_RESTORE);
3464 ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
3465 flush_sequence();
3466
3467 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3468 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3469
3470 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3471 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3472 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3473 flush_sequence();
3474
3475 SetFocus(0);
3476 flush_sequence();
3477
3478 ShowWindow(mdi_child2, SW_HIDE);
3479 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3480
3481 ShowWindow(mdi_child2, SW_SHOW);
3482 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
3483
3484 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3485 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3486
3487 ShowWindow(mdi_child2, SW_MAXIMIZE);
3488 ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3489
3490 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3491 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3492
3493 ShowWindow(mdi_child2, SW_RESTORE);
3494 ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3495
3496 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3497 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3498
3499 ShowWindow(mdi_child2, SW_MINIMIZE);
3500 ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3501
3502 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3503 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3504
3505 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3506 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3507 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3508 flush_sequence();
3509
3510 ShowWindow(mdi_child2, SW_RESTORE);
3511 ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", TRUE);
3512
3513 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3514 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3515
3516 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3517 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3518 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3519 flush_sequence();
3520
3521 SetFocus(0);
3522 flush_sequence();
3523
3524 ShowWindow(mdi_child2, SW_HIDE);
3525 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3526
3527 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3528 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3529
3530 DestroyWindow(mdi_child2);
3531 ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3532
3533 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3534 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3535
3536 /* test for maximized MDI children */
3537 trace("creating maximized visible MDI child window 1\n");
3538 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3539 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3540 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3541 mdi_client, 0, GetModuleHandleA(0), NULL);
3542 assert(mdi_child);
3543 ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3544 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3545
3546 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3547 ok(GetFocus() == mdi_child || /* win2k */
3548 GetFocus() == 0, /* win9x */
3549 "wrong focus window %p\n", GetFocus());
3550
3551 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3552 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3553 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3554 flush_sequence();
3555
3556 trace("creating maximized visible MDI child window 2\n");
3557 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3558 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3559 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3560 mdi_client, 0, GetModuleHandleA(0), NULL);
3561 assert(mdi_child2);
3562 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3563 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3564 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3565
3566 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3567 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3568
3569 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3570 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3571 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3572 flush_sequence();
3573
3574 trace("destroying maximized visible MDI child window 2\n");
3575 DestroyWindow(mdi_child2);
3576 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3577
3578 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3579
3580 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3581 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3582
3583 /* Win2k: MDI client still returns a just destroyed child as active
3584 * Win9x: MDI client returns 0
3585 */
3586 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3587 ok(active_child == mdi_child2 || /* win2k */
3588 !active_child, /* win9x */
3589 "wrong active MDI child %p\n", active_child);
3590 flush_sequence();
3591
3592 ShowWindow(mdi_child, SW_MAXIMIZE);
3593 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3594 flush_sequence();
3595
3596 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3597 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3598
3599 trace("re-creating maximized visible MDI child window 2\n");
3600 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3601 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3602 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3603 mdi_client, 0, GetModuleHandleA(0), NULL);
3604 assert(mdi_child2);
3605 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3606 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3607 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3608
3609 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3610 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3611
3612 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3613 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3614 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3615 flush_sequence();
3616
3617 SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3618 ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3619 ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3620
3621 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3622 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3623 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3624
3625 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3626 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3627 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3628 flush_sequence();
3629
3630 DestroyWindow(mdi_child);
3631 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3632
3633 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3634 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3635
3636 /* Win2k: MDI client still returns a just destroyed child as active
3637 * Win9x: MDI client returns 0
3638 */
3639 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3640 ok(active_child == mdi_child || /* win2k */
3641 !active_child, /* win9x */
3642 "wrong active MDI child %p\n", active_child);
3643 flush_sequence();
3644
3645 trace("creating maximized invisible MDI child window\n");
3646 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3647 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3648 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3649 mdi_client, 0, GetModuleHandleA(0), NULL);
3650 assert(mdi_child2);
3651 ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", FALSE);
3652 ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3653 ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3654 ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3655
3656 /* Win2k: MDI client still returns a just destroyed child as active
3657 * Win9x: MDI client returns 0
3658 */
3659 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3660 ok(active_child == mdi_child || /* win2k */
3661 !active_child, /* win9x */
3662 "wrong active MDI child %p\n", active_child);
3663 flush_sequence();
3664
3665 trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3666 ShowWindow(mdi_child2, SW_MAXIMIZE);
3667 ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3668 ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3669 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3670 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
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_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3678 flush_sequence();
3679
3680 /* end of test for maximized MDI children */
3681 SetFocus(0);
3682 flush_sequence();
3683 trace("creating maximized visible MDI child window 1(Switch test)\n");
3684 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3685 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3686 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3687 mdi_client, 0, GetModuleHandleA(0), NULL);
3688 assert(mdi_child);
3689 ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3690 ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3691
3692 ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3693 ok(GetFocus() == mdi_child || /* win2k */
3694 GetFocus() == 0, /* win9x */
3695 "wrong focus window %p(Switch test)\n", GetFocus());
3696
3697 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3698 ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3699 ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3700 flush_sequence();
3701
3702 trace("creating maximized visible MDI child window 2(Switch test)\n");
3703 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3704 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3705 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3706 mdi_client, 0, GetModuleHandleA(0), NULL);
3707 assert(mdi_child2);
3708 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child window (Switch test)", TRUE);
3709
3710 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3711 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3712
3713 ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3714 ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3715
3716 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3717 ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3718 ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3719 flush_sequence();
3720
3721 trace("Switch child window.\n");
3722 SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3723 ok_sequence(WmSwitchChild, "Child did not switch correctly", TRUE);
3724 trace("end of test for switch maximized MDI children\n");
3725 flush_sequence();
3726
3727 /* Prepare for switching test of not maximized MDI children */
3728 ShowWindow( mdi_child, SW_NORMAL );
3729 ok(!IsZoomed(mdi_child), "wrong zoomed state for %p(Switch test)\n", mdi_child);
3730 ok(!IsZoomed(mdi_child2), "wrong zoomed state for %p(Switch test)\n", mdi_child2);
3731 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
3732 ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3733 flush_sequence();
3734
3735 SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child2, 0);
3736 ok_sequence(WmSwitchNotMaximizedChild, "Not maximized child did not switch correctly", FALSE);
3737 trace("end of test for switch not maximized MDI children\n");
3738 flush_sequence();
3739
3740 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3741 flush_sequence();
3742
3743 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3744 flush_sequence();
3745
3746 SetFocus(0);
3747 flush_sequence();
3748 /* end of tests for switch maximized/not maximized MDI children */
3749
3750 mdi_cs.szClass = "MDI_child_Class";
3751 mdi_cs.szTitle = "MDI child";
3752 mdi_cs.hOwner = GetModuleHandleA(0);
3753 mdi_cs.x = 0;
3754 mdi_cs.y = 0;
3755 mdi_cs.cx = CW_USEDEFAULT;
3756 mdi_cs.cy = CW_USEDEFAULT;
3757 mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3758 mdi_cs.lParam = 0;
3759 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3760 ok(mdi_child != 0, "MDI child creation failed\n");
3761 ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3762
3763 ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3764
3765 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3766 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3767
3768 ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3769 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3770 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3771
3772 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3773 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3774 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3775 flush_sequence();
3776
3777 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3778 ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3779
3780 ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3781 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3782 ok(!active_child, "wrong active MDI child %p\n", active_child);
3783
3784 SetFocus(0);
3785 flush_sequence();
3786
3787 DestroyWindow(mdi_client);
3788 ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3789
3790 /* test maximization of MDI child with invisible parent */
3791 client_cs.hWindowMenu = 0;
3792 mdi_client = CreateWindow("MDI_client_class",
3793 NULL,
3794 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3795 0, 0, 660, 430,
3796 mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3797 ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3798
3799 ShowWindow(mdi_client, SW_HIDE);
3800 ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3801
3802 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3803 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3804 0, 0, 650, 440,
3805 mdi_client, 0, GetModuleHandleA(0), NULL);
3806 ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3807
3808 SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3809 ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3810 zoomed = IsZoomed(mdi_child);
3811 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3812
3813 ShowWindow(mdi_client, SW_SHOW);
3814 ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3815
3816 DestroyWindow(mdi_child);
3817 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3818
3819 /* end of test for maximization of MDI child with invisible parent */
3820
3821 DestroyWindow(mdi_client);
3822 ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3823
3824 DestroyWindow(mdi_frame);
3825 ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3826 }
3827 /************************* End of MDI test **********************************/
3828
3829 static void test_WM_SETREDRAW(HWND hwnd)
3830 {
3831 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3832
3833 flush_events();
3834 flush_sequence();
3835
3836 SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3837 ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3838
3839 ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3840 ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3841
3842 flush_sequence();
3843 SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3844 ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3845
3846 ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3847 ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3848
3849 /* restore original WS_VISIBLE state */
3850 SetWindowLongA(hwnd, GWL_STYLE, style);
3851
3852 flush_events();
3853 flush_sequence();
3854 }
3855
3856 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3857 {
3858 struct recvd_message msg;
3859
3860 switch (message)
3861 {
3862 /* ignore */
3863 case WM_GETICON:
3864 case WM_GETOBJECT:
3865 case WM_MOUSEMOVE:
3866 case WM_NCMOUSEMOVE:
3867 case WM_NCMOUSELEAVE:
3868 case WM_SETCURSOR:
3869 case WM_DEVICECHANGE:
3870 return 0;
3871 case WM_NCHITTEST:
3872 return HTCLIENT;
3873 }
3874
3875 msg.hwnd = hwnd;
3876 msg.message = message;
3877 msg.flags = sent|wparam|lparam;
3878 msg.wParam = wParam;
3879 msg.lParam = lParam;
3880 msg.descr = "dialog";
3881 add_message(&msg);
3882
3883 if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3884 if (message == WM_TIMER) EndDialog( hwnd, 0 );
3885 return 0;
3886 }
3887
3888 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3889 {
3890 DWORD style, exstyle;
3891 INT xmin, xmax;
3892 BOOL ret;
3893
3894 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3895 style = GetWindowLongA(hwnd, GWL_STYLE);
3896 /* do not be confused by WS_DLGFRAME set */
3897 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3898
3899 if (clear) ok(style & clear, "style %08x should be set\n", clear);
3900 if (set) ok(!(style & set), "style %08x should not be set\n", set);
3901
3902 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3903 ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3904 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3905 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3906 else
3907 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3908
3909 style = GetWindowLongA(hwnd, GWL_STYLE);
3910 if (set) ok(style & set, "style %08x should be set\n", set);
3911 if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3912
3913 /* a subsequent call should do nothing */
3914 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3915 ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3916 ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3917
3918 xmin = 0xdeadbeef;
3919 xmax = 0xdeadbeef;
3920 trace("Ignore GetScrollRange error below if you are on Win9x\n");
3921 ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
3922 ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
3923 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3924 ok(xmin == min, "unexpected min scroll value %d\n", xmin);
3925 ok(xmax == max, "unexpected max scroll value %d\n", xmax);
3926 }
3927
3928 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3929 {
3930 DWORD style, exstyle;
3931 SCROLLINFO si;
3932 BOOL ret;
3933
3934 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3935 style = GetWindowLongA(hwnd, GWL_STYLE);
3936 /* do not be confused by WS_DLGFRAME set */
3937 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3938
3939 if (clear) ok(style & clear, "style %08x should be set\n", clear);
3940 if (set) ok(!(style & set), "style %08x should not be set\n", set);
3941
3942 si.cbSize = sizeof(si);
3943 si.fMask = SIF_RANGE;
3944 si.nMin = min;
3945 si.nMax = max;
3946 SetScrollInfo(hwnd, ctl, &si, TRUE);
3947 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3948 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
3949 else
3950 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
3951
3952 style = GetWindowLongA(hwnd, GWL_STYLE);
3953 if (set) ok(style & set, "style %08x should be set\n", set);
3954 if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3955
3956 /* a subsequent call should do nothing */
3957 SetScrollInfo(hwnd, ctl, &si, TRUE);
3958 if (style & WS_HSCROLL)
3959 ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3960 else if (style & WS_VSCROLL)
3961 ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3962 else
3963 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3964
3965 si.fMask = SIF_PAGE;
3966 si.nPage = 5;
3967 SetScrollInfo(hwnd, ctl, &si, FALSE);
3968 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3969
3970 si.fMask = SIF_POS;
3971 si.nPos = max - 1;
3972 SetScrollInfo(hwnd, ctl, &si, FALSE);
3973 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3974
3975 si.fMask = SIF_RANGE;
3976 si.nMin = 0xdeadbeef;
3977 si.nMax = 0xdeadbeef;
3978 ret = GetScrollInfo(hwnd, ctl, &si);
3979 ok( ret, "GetScrollInfo error %d\n", GetLastError());
3980 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3981 ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
3982 ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
3983 }
3984
3985 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
3986 static void test_scroll_messages(HWND hwnd)
3987 {
3988 SCROLLINFO si;
3989 INT min, max;
3990 BOOL ret;
3991
3992 flush_events();
3993 flush_sequence();
3994
3995 min = 0xdeadbeef;
3996 max = 0xdeadbeef;
3997 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3998 ok( ret, "GetScrollRange error %d\n", GetLastError());
3999 if (sequence->message != WmGetScrollRangeSeq[0].message)
4000 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4001 /* values of min and max are undefined */
4002 flush_sequence();
4003
4004 ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
4005 ok( ret, "SetScrollRange error %d\n", GetLastError());
4006 if (sequence->message != WmSetScrollRangeSeq[0].message)
4007 trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4008 flush_sequence();
4009
4010 min = 0xdeadbeef;
4011 max = 0xdeadbeef;
4012 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4013 ok( ret, "GetScrollRange error %d\n", GetLastError());
4014 if (sequence->message != WmGetScrollRangeSeq[0].message)
4015 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4016 /* values of min and max are undefined */
4017 flush_sequence();
4018
4019 si.cbSize = sizeof(si);
4020 si.fMask = SIF_RANGE;
4021 si.nMin = 20;
4022 si.nMax = 160;
4023 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4024 if (sequence->message != WmSetScrollRangeSeq[0].message)
4025 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4026 flush_sequence();
4027
4028 si.fMask = SIF_PAGE;
4029 si.nPage = 10;
4030 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4031 if (sequence->message != WmSetScrollRangeSeq[0].message)
4032 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4033 flush_sequence();
4034
4035 si.fMask = SIF_POS;
4036 si.nPos = 20;
4037 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4038 if (sequence->message != WmSetScrollRangeSeq[0].message)
4039 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4040 flush_sequence();
4041
4042 si.fMask = SIF_RANGE;
4043 si.nMin = 0xdeadbeef;
4044 si.nMax = 0xdeadbeef;
4045 ret = GetScrollInfo(hwnd, SB_CTL, &si);
4046 ok( ret, "GetScrollInfo error %d\n", GetLastError());
4047 if (sequence->message != WmGetScrollInfoSeq[0].message)
4048 trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4049 /* values of min and max are undefined */
4050 flush_sequence();
4051
4052 /* set WS_HSCROLL */
4053 test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4054 /* clear WS_HSCROLL */
4055 test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4056
4057 /* set WS_HSCROLL */
4058 test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4059 /* clear WS_HSCROLL */
4060 test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4061
4062 /* set WS_VSCROLL */
4063 test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4064 /* clear WS_VSCROLL */
4065 test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4066
4067 /* set WS_VSCROLL */
4068 test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4069 /* clear WS_VSCROLL */
4070 test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4071 }
4072
4073 static void test_showwindow(void)
4074 {
4075 HWND hwnd, hchild;
4076 RECT rc;
4077
4078 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4079 100, 100, 200, 200, 0, 0, 0, NULL);
4080 ok (hwnd != 0, "Failed to create overlapped window\n");
4081 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4082 0, 0, 10, 10, hwnd, 0, 0, NULL);
4083 ok (hchild != 0, "Failed to create child\n");
4084 flush_sequence();
4085
4086 /* ShowWindow( SW_SHOWNA) for invisible top level window */
4087 trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
4088 ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4089 ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", TRUE);
4090
4091 /* ShowWindow( SW_SHOWNA) for now visible top level window */
4092 trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
4093 ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4094 ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
4095 /* back to invisible */
4096 ShowWindow(hchild, SW_HIDE);
4097 ShowWindow(hwnd, SW_HIDE);
4098 flush_sequence();
4099 /* ShowWindow(SW_SHOWNA) with child and parent invisible */
4100 trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
4101 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4102 ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
4103 /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */
4104 ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
4105 flush_sequence();
4106 trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
4107 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4108 ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
4109 /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
4110 ShowWindow( hwnd, SW_SHOW);
4111 flush_sequence();
4112 trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
4113 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4114 ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
4115
4116 /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
4117 ShowWindow( hchild, SW_HIDE);
4118 flush_sequence();
4119 trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
4120 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4121 ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
4122
4123 SetCapture(hchild);
4124 ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
4125 DestroyWindow(hchild);
4126 ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
4127
4128 DestroyWindow(hwnd);
4129 flush_sequence();
4130
4131 /* Popup windows */
4132 /* Test 1:
4133 * 1. Create invisible maximized popup window.
4134 * 2. Move and resize it.
4135 * 3. Show it maximized.
4136 */
4137 trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4138 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4139 100, 100, 200, 200, 0, 0, 0, NULL);
4140 ok (hwnd != 0, "Failed to create popup window\n");
4141 ok(IsZoomed(hwnd), "window should be maximized\n");
4142 ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4143
4144 GetWindowRect(hwnd, &rc);
4145 ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4146 rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4147 "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
4148 rc.left, rc.top, rc.right, rc.bottom);
4149 /* Reset window's size & position */
4150 SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
4151 ok(IsZoomed(hwnd), "window should be maximized\n");
4152 flush_sequence();
4153
4154 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4155 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4156 ok(IsZoomed(hwnd), "window should be maximized\n");
4157 ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
4158
4159 GetWindowRect(hwnd, &rc);
4160 ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4161 rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4162 "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
4163 rc.left, rc.top, rc.right, rc.bottom);
4164 DestroyWindow(hwnd);
4165 flush_sequence();
4166
4167 /* Test 2:
4168 * 1. Create invisible maximized popup window.
4169 * 2. Show it maximized.
4170 */
4171 trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4172 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4173 100, 100, 200, 200, 0, 0, 0, NULL);
4174 ok (hwnd != 0, "Failed to create popup window\n");
4175 ok(IsZoomed(hwnd), "window should be maximized\n");
4176 ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4177
4178 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4179 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4180 ok(IsZoomed(hwnd), "window should be maximized\n");
4181 ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
4182 DestroyWindow(hwnd);
4183 flush_sequence();
4184
4185 /* Test 3:
4186 * 1. Create visible maximized popup window.
4187 */
4188 trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
4189 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4190 100, 100, 200, 200, 0, 0, 0, NULL);
4191 ok (hwnd != 0, "Failed to create popup window\n");
4192 ok(IsZoomed(hwnd), "window should be maximized\n");
4193 ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4194 DestroyWindow(hwnd);
4195 flush_sequence();
4196
4197 /* Test 4:
4198 * 1. Create visible popup window.
4199 * 2. Maximize it.
4200 */
4201 trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
4202 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
4203 100, 100, 200, 200, 0, 0, 0, NULL);
4204 ok (hwnd != 0, "Failed to create popup window\n");
4205 ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
4206 ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
4207
4208 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
4209 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4210 ok(IsZoomed(hwnd), "window should be maximized\n");
4211 ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
4212 DestroyWindow(hwnd);
4213 flush_sequence();
4214 }
4215
4216 static void test_sys_menu(void)
4217 {
4218 HWND hwnd;
4219 HMENU hmenu;
4220 UINT state;
4221
4222 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4223 100, 100, 200, 200, 0, 0, 0, NULL);
4224 ok (hwnd != 0, "Failed to create overlapped window\n");
4225
4226 flush_sequence();
4227
4228 /* test existing window without CS_NOCLOSE style */
4229 hmenu = GetSystemMenu(hwnd, FALSE);
4230 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4231
4232 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4233 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4234 ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4235
4236 EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
4237 ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4238
4239 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4240 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4241 ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
4242
4243 EnableMenuItem(hmenu, SC_CLOSE, 0);
4244 ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4245
4246 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4247 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4248 ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4249
4250 /* test whether removing WS_SYSMENU destroys a system menu */
4251 SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
4252 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4253 flush_sequence();
4254 hmenu = GetSystemMenu(hwnd, FALSE);
4255 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4256
4257 DestroyWindow(hwnd);
4258
4259 /* test new window with CS_NOCLOSE style */
4260 hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4261 100, 100, 200, 200, 0, 0, 0, NULL);
4262 ok (hwnd != 0, "Failed to create overlapped window\n");
4263
4264 hmenu = GetSystemMenu(hwnd, FALSE);
4265 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4266
4267 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4268 ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4269
4270 DestroyWindow(hwnd);
4271
4272 /* test new window without WS_SYSMENU style */
4273 hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
4274 100, 100, 200, 200, 0, 0, 0, NULL);
4275 ok(hwnd != 0, "Failed to create overlapped window\n");
4276
4277 hmenu = GetSystemMenu(hwnd, FALSE);
4278 ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
4279
4280 DestroyWindow(hwnd);
4281 }
4282
4283 /* For shown WS_OVERLAPPEDWINDOW */
4284 static const struct message WmSetIcon_1[] = {
4285 { WM_SETICON, sent },
4286 { 0x00AE, sent|defwinproc|optional }, /* XP */
4287 { WM_GETTEXT, sent|defwinproc|optional },
4288 { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
4289 { 0 }
4290 };
4291
4292 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
4293 static const struct message WmSetIcon_2[] = {
4294 { WM_SETICON, sent },
4295 { 0 }
4296 };
4297
4298 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
4299 static const struct message WmInitEndSession[] = {
4300 { 0x003B, sent },
4301 { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4302 { 0 }
4303 };
4304
4305 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
4306 static const struct message WmInitEndSession_2[] = {
4307 { 0x003B, sent },
4308 { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4309 { 0 }
4310 };
4311
4312 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
4313 static const struct message WmInitEndSession_3[] = {
4314 { 0x003B, sent },
4315 { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4316 { 0 }
4317 };
4318
4319 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
4320 static const struct message WmInitEndSession_4[] = {
4321 { 0x003B, sent },
4322 { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4323 { 0 }
4324 };
4325
4326 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
4327 static const struct message WmInitEndSession_5[] = {
4328 { 0x003B, sent },
4329 { WM_ENDSESSION, sent|defwinproc/*|wparam*/|lparam, 1, ENDSESSION_LOGOFF },
4330 { 0 }
4331 };
4332
4333 static const struct message WmOptionalPaint[] = {
4334 { WM_PAINT, sent|optional },
4335 { WM_NCPAINT, sent|beginpaint|optional },
4336 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4337 { WM_ERASEBKGND, sent|beginpaint|optional },
4338 { 0 }
4339 };
4340
4341 static const struct message WmZOrder[] = {
4342 { WM_WINDOWPOSCHANGING, sent|wparam, 0, 0 },
4343 { WM_GETMINMAXINFO, sent|defwinproc|wparam, 0, 0 },
4344 { HCBT_ACTIVATE, hook },
4345 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
4346 { WM_WINDOWPOSCHANGING, sent|wparam, 3, 0 },
4347 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0 },
4348 { WM_GETTEXT, sent|optional },
4349 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
4350 { WM_ACTIVATEAPP, sent|wparam, 1, 0 },
4351 { WM_NCACTIVATE, sent|wparam|lparam, 1, 0 },
4352 { WM_GETTEXT, sent|defwinproc|optional },
4353 { WM_GETTEXT, sent|defwinproc|optional },
4354 { WM_ACTIVATE, sent|wparam|lparam, 1, 0 },
4355 { HCBT_SETFOCUS, hook },
4356 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4357 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4358 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4359 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
4360 { WM_GETTEXT, sent|optional },
4361 { WM_NCCALCSIZE, sent|optional },
4362 { 0 }
4363 };
4364
4365 static void test_MsgWaitForMultipleObjects(HWND hwnd)
4366 {
4367 DWORD ret;
4368 MSG msg;
4369
4370 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4371 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4372
4373 PostMessageA(hwnd, WM_USER, 0, 0);
4374
4375 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4376 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4377
4378 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4379 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4380
4381 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4382 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4383
4384 PostMessageA(hwnd, WM_USER, 0, 0);
4385
4386 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4387 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4388
4389 ok(PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
4390 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4391
4392 /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
4393 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4394 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4395
4396 PostMessageA(hwnd, WM_USER, 0, 0);
4397
4398 /* new incoming message causes it to become signaled again */
4399 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4400 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4401
4402 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4403 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4404 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4405 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4406 }
4407
4408 /* test if we receive the right sequence of messages */
4409 static void test_messages(void)
4410 {
4411 HWND hwnd, hparent, hchild;
4412 HWND hchild2, hbutton;
4413 HMENU hmenu;
4414 MSG msg;
4415 LRESULT res;
4416
4417 flush_sequence();
4418
4419 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4420 100, 100, 200, 200, 0, 0, 0, NULL);
4421 ok (hwnd != 0, "Failed to create overlapped window\n");
4422 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4423
4424 /* test ShowWindow(SW_HIDE) on a newly created invisible window */
4425 ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
4426 ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
4427
4428 /* test WM_SETREDRAW on a not visible top level window */
4429 test_WM_SETREDRAW(hwnd);
4430
4431 SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4432 flush_events();
4433 ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
4434 ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
4435
4436 ok(GetActiveWindow() == hwnd, "window should be active\n");
4437 ok(GetFocus() == hwnd, "window should have input focus\n");
4438 ShowWindow(hwnd, SW_HIDE);
4439 flush_events();
4440 ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4441
4442 ShowWindow(hwnd, SW_SHOW);
4443 flush_events();
4444 ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
4445
4446 ShowWindow(hwnd, SW_HIDE);
4447 flush_events();
4448 ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4449
4450 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4451 flush_events();
4452 ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
4453 flush_sequence();
4454
4455 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MAXIMIZE)
4456 {
4457 ShowWindow(hwnd, SW_RESTORE);
4458 flush_events();
4459 ok_sequence(WmShowRestoreMaxOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4460 flush_sequence();
4461 }
4462
4463 ShowWindow(hwnd, SW_MINIMIZE);
4464 flush_events();
4465 ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4466 flush_sequence();
4467
4468 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MINIMIZE)
4469 {
4470 ShowWindow(hwnd, SW_RESTORE);
4471 flush_events();
4472 ok_sequence(WmShowRestoreMinOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4473 flush_sequence();
4474 }
4475
4476 ShowWindow(hwnd, SW_SHOW);
4477 flush_events();
4478 ok_sequence(WmOptionalPaint, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4479
4480 ok(GetActiveWindow() == hwnd, "window should be active\n");
4481 ok(GetFocus() == hwnd, "window should have input focus\n");
4482 SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4483 ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4484 ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4485 ok(GetActiveWindow() == hwnd, "window should still be active\n");
4486
4487 /* test WM_SETREDRAW on a visible top level window */
4488 ShowWindow(hwnd, SW_SHOW);
4489 flush_events();
4490 test_WM_SETREDRAW(hwnd);
4491
4492 trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4493 test_scroll_messages(hwnd);
4494
4495 /* test resizing and moving */
4496 SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4497 ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4498 flush_events();
4499 flush_sequence();
4500 SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4501 ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4502 flush_events();
4503 flush_sequence();
4504 SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER|SWP_NOACTIVATE );
4505 ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4506 flush_events();
4507 flush_sequence();
4508
4509 /* popups don't get WM_GETMINMAXINFO */
4510 SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4511 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4512 flush_sequence();
4513 SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4514 ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4515
4516 DestroyWindow(hwnd);
4517 ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4518
4519 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4520 100, 100, 200, 200, 0, 0, 0, NULL);
4521 ok (hparent != 0, "Failed to create parent window\n");
4522 flush_sequence();
4523
4524 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4525 0, 0, 10, 10, hparent, 0, 0, NULL);
4526 ok (hchild != 0, "Failed to create child window\n");
4527 ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4528 DestroyWindow(hchild);
4529 flush_sequence();
4530
4531 /* visible child window with a caption */
4532 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4533 WS_CHILD | WS_VISIBLE | WS_CAPTION,
4534 0, 0, 10, 10, hparent, 0, 0, NULL);
4535 ok (hchild != 0, "Failed to create child window\n");
4536 ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4537
4538 trace("testing scroll APIs on a visible child window %p\n", hchild);
4539 test_scroll_messages(hchild);
4540
4541 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4542 ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4543
4544 DestroyWindow(hchild);
4545 flush_sequence();
4546
4547 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4548 0, 0, 10, 10, hparent, 0, 0, NULL);
4549 ok (hchild != 0, "Failed to create child window\n");
4550 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4551
4552 hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4553 100, 100, 50, 50, hparent, 0, 0, NULL);
4554 ok (hchild2 != 0, "Failed to create child2 window\n");
4555 flush_sequence();
4556
4557 hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4558 0, 100, 50, 50, hchild, 0, 0, NULL);
4559 ok (hbutton != 0, "Failed to create button window\n");
4560
4561 /* test WM_SETREDRAW on a not visible child window */
4562 test_WM_SETREDRAW(hchild);
4563
4564 ShowWindow(hchild, SW_SHOW);
4565 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4566
4567 /* check parent messages too */
4568 log_all_parent_messages++;
4569 ShowWindow(hchild, SW_HIDE);
4570 ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4571 log_all_parent_messages--;
4572
4573 ShowWindow(hchild, SW_SHOW);
4574 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4575
4576 ShowWindow(hchild, SW_HIDE);
4577 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4578
4579 ShowWindow(hchild, SW_SHOW);
4580 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4581
4582 /* test WM_SETREDRAW on a visible child window */
4583 test_WM_SETREDRAW(hchild);
4584
4585 log_all_parent_messages++;
4586 MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4587 ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4588 log_all_parent_messages--;
4589
4590 ShowWindow(hchild, SW_HIDE);
4591 flush_sequence();
4592 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4593 ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4594
4595 ShowWindow(hchild, SW_HIDE);
4596 flush_sequence();
4597 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4598 ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4599
4600 /* DestroyWindow sequence below expects that a child has focus */
4601 SetFocus(hchild);
4602 flush_sequence();
4603
4604 DestroyWindow(hchild);
4605 ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4606 DestroyWindow(hchild2);
4607 DestroyWindow(hbutton);
4608
4609 flush_sequence();
4610 hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4611 0, 0, 100, 100, hparent, 0, 0, NULL);
4612 ok (hchild != 0, "Failed to create child popup window\n");
4613 ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4614 DestroyWindow(hchild);
4615
4616 /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4617 flush_sequence();
4618 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4619 0, 0, 100, 100, hparent, 0, 0, NULL);
4620 ok (hchild != 0, "Failed to create popup window\n");
4621 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4622 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4623 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4624 flush_sequence();
4625 ShowWindow(hchild, SW_SHOW);
4626 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4627 flush_sequence();
4628 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4629 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4630 flush_sequence();
4631 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4632 ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
4633 DestroyWindow(hchild);
4634
4635 /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4636 * changes nothing in message sequences.
4637 */
4638 flush_sequence();
4639 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4640 0, 0, 100, 100, hparent, 0, 0, NULL);
4641 ok (hchild != 0, "Failed to create popup window\n");
4642 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4643 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4644 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4645 flush_sequence();
4646 ShowWindow(hchild, SW_SHOW);
4647 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4648 flush_sequence();
4649 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4650 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4651 DestroyWindow(hchild);
4652
4653 flush_sequence();
4654 hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4655 0, 0, 100, 100, hparent, 0, 0, NULL);
4656 ok(hwnd != 0, "Failed to create custom dialog window\n");
4657 ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4658
4659 /*
4660 trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4661 test_scroll_messages(hwnd);
4662 */
4663
4664 flush_sequence();
4665
4666 test_def_id = 1;
4667 SendMessage(hwnd, WM_NULL, 0, 0);
4668
4669 flush_sequence();
4670 after_end_dialog = 1;
4671 EndDialog( hwnd, 0 );
4672 ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4673
4674 DestroyWindow(hwnd);
4675 after_end_dialog = 0;
4676 test_def_id = 0;
4677
4678 hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4679 0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4680 ok(hwnd != 0, "Failed to create custom dialog window\n");
4681 flush_sequence();
4682 trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4683 ShowWindow(hwnd, SW_SHOW);
4684 ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4685 DestroyWindow(hwnd);
4686
4687 flush_sequence();
4688 DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4689 ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4690
4691 DestroyWindow(hparent);
4692 flush_sequence();
4693
4694 /* Message sequence for SetMenu */
4695 ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4696 ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4697
4698 hmenu = CreateMenu();
4699 ok (hmenu != 0, "Failed to create menu\n");
4700 ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4701 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4702 100, 100, 200, 200, 0, hmenu, 0, NULL);
4703 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4704 ok (SetMenu(hwnd, 0), "SetMenu\n");
4705 ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4706 ok (SetMenu(hwnd, 0), "SetMenu\n");
4707 ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4708 ShowWindow(hwnd, SW_SHOW);
4709 UpdateWindow( hwnd );
4710 flush_events();
4711 flush_sequence();
4712 ok (SetMenu(hwnd, 0), "SetMenu\n");
4713 ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4714 ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4715 ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4716
4717 UpdateWindow( hwnd );
4718 flush_events();
4719 flush_sequence();
4720 ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4721 flush_events();
4722 ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4723
4724 DestroyWindow(hwnd);
4725 flush_sequence();
4726
4727 /* Message sequence for EnableWindow */
4728 hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4729 100, 100, 200, 200, 0, 0, 0, NULL);
4730 ok (hparent != 0, "Failed to create parent window\n");
4731 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4732 0, 0, 10, 10, hparent, 0, 0, NULL);
4733 ok (hchild != 0, "Failed to create child window\n");
4734
4735 SetFocus(hchild);
4736 flush_events();
4737 flush_sequence();
4738
4739 EnableWindow(hparent, FALSE);
4740 ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4741
4742 EnableWindow(hparent, TRUE);
4743 ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4744
4745 flush_events();
4746 flush_sequence();
4747
4748 test_MsgWaitForMultipleObjects(hparent);
4749
4750 /* the following test causes an exception in user.exe under win9x */
4751 if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4752 {
4753 DestroyWindow(hparent);
4754 flush_sequence();
4755 return;
4756 }
4757 PostMessageW( hparent, WM_USER+1, 0, 0 );
4758 /* PeekMessage(NULL) fails, but still removes the message */
4759 SetLastError(0xdeadbeef);
4760 ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4761 ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4762 GetLastError() == 0xdeadbeef, /* NT4 */
4763 "last error is %d\n", GetLastError() );
4764 ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4765 ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4766
4767 DestroyWindow(hchild);
4768 DestroyWindow(hparent);
4769 flush_sequence();
4770
4771 /* Message sequences for WM_SETICON */
4772 trace("testing WM_SETICON\n");
4773 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4774 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4775 NULL, NULL, 0);
4776 ShowWindow(hwnd, SW_SHOW);
4777 UpdateWindow(hwnd);
4778 flush_events();
4779 flush_sequence();
4780 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4781 ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4782
4783 ShowWindow(hwnd, SW_HIDE);
4784 flush_events();
4785 flush_sequence();
4786 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4787 ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4788 DestroyWindow(hwnd);
4789 flush_sequence();
4790
4791 hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4792 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4793 NULL, NULL, 0);
4794 ShowWindow(hwnd, SW_SHOW);
4795 UpdateWindow(hwnd);
4796 flush_events();
4797 flush_sequence();
4798 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4799 ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4800
4801 ShowWindow(hwnd, SW_HIDE);
4802 flush_events();
4803 flush_sequence();
4804 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4805 ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4806
4807 flush_sequence();
4808 res = SendMessage(hwnd, 0x3B, 0x8000000b, 0);
4809 if (!res)
4810 {
4811 todo_wine win_skip( "Message 0x3b not supported\n" );
4812 goto done;
4813 }
4814 ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4815 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4816 res = SendMessage(hwnd, 0x3B, 0x0000000b, 0);
4817 ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4818 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4819 res = SendMessage(hwnd, 0x3B, 0x0000000f, 0);
4820 ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4821 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4822
4823 flush_sequence();
4824 res = SendMessage(hwnd, 0x3B, 0x80000008, 0);
4825 ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4826 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4827 res = SendMessage(hwnd, 0x3B, 0x00000008, 0);
4828 ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4829 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4830
4831 res = SendMessage(hwnd, 0x3B, 0x80000004, 0);
4832 ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4833 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4834
4835 res = SendMessage(hwnd, 0x3B, 0x80000001, 0);
4836 ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4837 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4838
4839 done:
4840 DestroyWindow(hwnd);
4841 flush_sequence();
4842 }
4843
4844 static void test_setwindowpos(void)
4845 {
4846 HWND hwnd;
4847 RECT rc;
4848 LRESULT res;
4849 const INT winX = 100;
4850 const INT winY = 100;
4851 const INT sysX = GetSystemMetrics(SM_CXMINTRACK);
4852
4853 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, 0,
4854 0, 0, winX, winY, 0,
4855 NULL, NULL, 0);
4856
4857 GetWindowRect(hwnd, &rc);
4858 expect(sysX, rc.right);
4859 expect(winY, rc.bottom);
4860
4861 flush_events();
4862 flush_sequence();
4863 res = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, winX, winY, 0);
4864 ok_sequence(WmZOrder, "Z-Order", TRUE);
4865 ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
4866
4867 GetWindowRect(hwnd, &rc);
4868 expect(sysX, rc.right);
4869 expect(winY, rc.bottom);
4870 DestroyWindow(hwnd);
4871 }
4872
4873 static void invisible_parent_tests(void)
4874 {
4875 HWND hparent, hchild;
4876
4877 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4878 100, 100, 200, 200, 0, 0, 0, NULL);
4879 ok (hparent != 0, "Failed to create parent window\n");
4880 flush_sequence();
4881
4882 /* test showing child with hidden parent */
4883
4884 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4885 0, 0, 10, 10, hparent, 0, 0, NULL);
4886 ok (hchild != 0, "Failed to create child window\n");
4887 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4888
4889 ShowWindow( hchild, SW_MINIMIZE );
4890 ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4891 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4892 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4893
4894 /* repeat */
4895 flush_events();
4896 flush_sequence();
4897 ShowWindow( hchild, SW_MINIMIZE );
4898 ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4899
4900 DestroyWindow(hchild);
4901 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4902 0, 0, 10, 10, hparent, 0, 0, NULL);
4903 flush_sequence();
4904
4905 ShowWindow( hchild, SW_MAXIMIZE );
4906 ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4907 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4908 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4909
4910 /* repeat */
4911 flush_events();
4912 flush_sequence();
4913 ShowWindow( hchild, SW_MAXIMIZE );
4914 ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4915
4916 DestroyWindow(hchild);
4917 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4918 0, 0, 10, 10, hparent, 0, 0, NULL);
4919 flush_sequence();
4920
4921 ShowWindow( hchild, SW_RESTORE );
4922 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
4923 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4924 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4925
4926 DestroyWindow(hchild);
4927 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4928 0, 0, 10, 10, hparent, 0, 0, NULL);
4929 flush_sequence();
4930
4931 ShowWindow( hchild, SW_SHOWMINIMIZED );
4932 ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4933 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4934 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4935
4936 /* repeat */
4937 flush_events();
4938 flush_sequence();
4939 ShowWindow( hchild, SW_SHOWMINIMIZED );
4940 ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4941
4942 DestroyWindow(hchild);
4943 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4944 0, 0, 10, 10, hparent, 0, 0, NULL);
4945 flush_sequence();
4946
4947 /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
4948 ShowWindow( hchild, SW_SHOWMAXIMIZED );
4949 ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
4950 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4951 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4952
4953 DestroyWindow(hchild);
4954 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4955 0, 0, 10, 10, hparent, 0, 0, NULL);
4956 flush_sequence();
4957
4958 ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4959 ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4960 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4961 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4962
4963 /* repeat */
4964 flush_events();
4965 flush_sequence();
4966 ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4967 ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4968
4969 DestroyWindow(hchild);
4970 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4971 0, 0, 10, 10, hparent, 0, 0, NULL);
4972 flush_sequence();
4973
4974 /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
4975 ShowWindow( hchild, SW_FORCEMINIMIZE );
4976 ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
4977 todo_wine {
4978 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4979 }
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_SHOWNA );
4988 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) 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_SHOWNA );
4996 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) 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 ShowWindow( hchild, SW_SHOW );
5004 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5005 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5006 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5007
5008 /* repeat */
5009 flush_events();
5010 flush_sequence();
5011 ShowWindow( hchild, SW_SHOW );
5012 ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5013
5014 ShowWindow( hchild, SW_HIDE );
5015 ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
5016 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5017 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5018
5019 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5020 ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
5021 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5022 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5023
5024 SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5025 ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
5026 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
5027 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5028
5029 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5030 flush_sequence();
5031 DestroyWindow(hchild);
5032 ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
5033
5034 DestroyWindow(hparent);
5035 flush_sequence();
5036 }
5037
5038 /****************** button message test *************************/
5039 static const struct message WmSetFocusButtonSeq[] =
5040 {
5041 { HCBT_SETFOCUS, hook },
5042 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5043 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5044 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5045 { WM_SETFOCUS, sent|wparam, 0 },
5046 { WM_CTLCOLORBTN, sent|defwinproc },
5047 { 0 }
5048 };
5049 static const struct message WmKillFocusButtonSeq[] =
5050 {
5051 { HCBT_SETFOCUS, hook },
5052 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5053 { WM_KILLFOCUS, sent|wparam, 0 },
5054 { WM_CTLCOLORBTN, sent|defwinproc },
5055 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5056 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5057 { 0 }
5058 };
5059 static const struct message WmSetFocusStaticSeq[] =
5060 {
5061 { HCBT_SETFOCUS, hook },
5062 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5063 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5064 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5065 { WM_SETFOCUS, sent|wparam, 0 },
5066 { WM_CTLCOLORSTATIC, sent|defwinproc },
5067 { 0 }
5068 };
5069 static const struct message WmKillFocusStaticSeq[] =
5070 {
5071 { HCBT_SETFOCUS, hook },
5072 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5073 { WM_KILLFOCUS, sent|wparam, 0 },
5074 { WM_CTLCOLORSTATIC, sent|defwinproc },
5075 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5076 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5077 { 0 }
5078 };
5079 static const struct message WmLButtonDownSeq[] =
5080 {
5081 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
5082 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5083 { HCBT_SETFOCUS, hook },
5084 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
5085 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5086 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5087 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
5088 { WM_CTLCOLORBTN, sent|defwinproc },
5089 { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
5090 { WM_CTLCOLORBTN, sent|defwinproc },
5091 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5092 { 0 }
5093 };
5094 static const struct message WmLButtonUpSeq[] =
5095 {
5096 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
5097 { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
5098 { WM_CTLCOLORBTN, sent|defwinproc },
5099 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5100 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5101 { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
5102 { 0 }
5103 };
5104 static const struct message WmSetFontButtonSeq[] =
5105 {
5106 { WM_SETFONT, sent },
5107 { WM_PAINT, sent },
5108 { WM_ERASEBKGND, sent|defwinproc|optional },
5109 { WM_CTLCOLORBTN, sent|defwinproc },
5110 { 0 }
5111 };
5112
5113 static WNDPROC old_button_proc;
5114
5115 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5116 {
5117 static long defwndproc_counter = 0;
5118 LRESULT ret;
5119 struct recvd_message msg;
5120
5121 switch (message)
5122 {
5123 case WM_GETICON:
5124 case WM_GETOBJECT:
5125 return 0; /* ignore them */
5126 case WM_SYNCPAINT:
5127 break;
5128 case BM_SETSTATE:
5129 ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
5130 /* fall through */
5131 default:
5132 msg.hwnd = hwnd;
5133 msg.message = message;
5134 msg.flags = sent|wparam|lparam;
5135 if (defwndproc_counter) msg.flags |= defwinproc;
5136 msg.wParam = wParam;
5137 msg.lParam = lParam;
5138 msg.descr = "button";
5139 add_message(&msg);
5140 }
5141
5142 defwndproc_counter++;
5143 ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
5144 defwndproc_counter--;
5145
5146 return ret;
5147 }
5148
5149 static void subclass_button(void)
5150 {
5151 WNDCLASSA cls;
5152
5153 if (!GetClassInfoA(0, "button", &cls)) assert(0);
5154
5155 old_button_proc = cls.lpfnWndProc;
5156
5157 cls.hInstance = GetModuleHandle(0);
5158 cls.lpfnWndProc = button_hook_proc;
5159 cls.lpszClassName = "my_button_class";
5160 UnregisterClass(cls.lpszClassName, cls.hInstance);
5161 if (!RegisterClassA(&cls)) assert(0);
5162 }
5163
5164 static void test_button_messages(void)
5165 {
5166 static const struct
5167 {
5168 DWORD style;
5169 DWORD dlg_code;
5170 const struct message *setfocus;
5171 const struct message *killfocus;
5172 } button[] = {
5173 { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5174 WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5175 { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
5176 WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5177 { BS_CHECKBOX, DLGC_BUTTON,
5178 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5179 { BS_AUTOCHECKBOX, DLGC_BUTTON,
5180 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5181 { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5182 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5183 { BS_3STATE, DLGC_BUTTON,
5184 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5185 { BS_AUTO3STATE, DLGC_BUTTON,
5186 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5187 { BS_GROUPBOX, DLGC_STATIC,
5188 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5189 { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5190 WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5191 { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5192 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5193 { BS_OWNERDRAW, DLGC_BUTTON,
5194 WmSetFocusButtonSeq, WmKillFocusButtonSeq }
5195 };
5196 unsigned int i;
5197 HWND hwnd;
5198 DWORD dlg_code;
5199 HFONT zfont;
5200
5201 subclass_button();
5202
5203 for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
5204 {
5205 hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_POPUP,
5206 0, 0, 50, 14, 0, 0, 0, NULL);
5207 ok(hwnd != 0, "Failed to create button window\n");
5208
5209 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5210 ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5211
5212 ShowWindow(hwnd, SW_SHOW);
5213 UpdateWindow(hwnd);
5214 SetFocus(0);
5215 flush_sequence();
5216
5217 trace("button style %08x\n", button[i].style);
5218 SetFocus(hwnd);
5219 ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
5220
5221 SetFocus(0);
5222 ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
5223
5224 DestroyWindow(hwnd);
5225 }
5226
5227 hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
5228 0, 0, 50, 14, 0, 0, 0, NULL);
5229 ok(hwnd != 0, "Failed to create button window\n");
5230
5231 SetForegroundWindow(hwnd);
5232 flush_events();
5233
5234 SetActiveWindow(hwnd);
5235 SetFocus(0);
5236 flush_sequence();
5237
5238 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
5239 ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
5240
5241 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
5242 ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
5243
5244 flush_sequence();
5245 zfont = GetStockObject(SYSTEM_FONT);
5246 SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
5247 UpdateWindow(hwnd);
5248 ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
5249
5250 DestroyWindow(hwnd);
5251 }
5252
5253 /****************** static message test *************************/
5254 static const struct message WmSetFontStaticSeq[] =
5255 {
5256 { WM_SETFONT, sent },
5257 { WM_PAINT, sent|defwinproc|optional },
5258 { WM_ERASEBKGND, sent|defwinproc|optional },
5259 { WM_CTLCOLORSTATIC, sent|defwinproc|optional },
5260 { 0 }
5261 };
5262
5263 static WNDPROC old_static_proc;
5264
5265 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5266 {
5267 static long defwndproc_counter = 0;
5268 LRESULT ret;
5269 struct recvd_message msg;
5270
5271 if (message == WM_GETICON || message == WM_GETOBJECT) return 0; /* ignore them */
5272
5273 msg.hwnd = hwnd;
5274 msg.message = message;
5275 msg.flags = sent|wparam|lparam;
5276 if (defwndproc_counter) msg.flags |= defwinproc;
5277 msg.wParam = wParam;
5278 msg.lParam = lParam;
5279 msg.descr = "static";
5280 add_message(&msg);
5281
5282 defwndproc_counter++;
5283 ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
5284 defwndproc_counter--;
5285
5286 return ret;
5287 }
5288
5289 static void subclass_static(void)
5290 {
5291 WNDCLASSA cls;
5292
5293 if (!GetClassInfoA(0, "static", &cls)) assert(0);
5294
5295 old_static_proc = cls.lpfnWndProc;
5296
5297 cls.hInstance = GetModuleHandle(0);
5298 cls.lpfnWndProc = static_hook_proc;
5299 cls.lpszClassName = "my_static_class";
5300 UnregisterClass(cls.lpszClassName, cls.hInstance);
5301 if (!RegisterClassA(&cls)) assert(0);
5302 }
5303
5304 static void test_static_messages(void)
5305 {
5306 /* FIXME: make as comprehensive as the button message test */
5307 static const struct
5308 {
5309 DWORD style;
5310 DWORD dlg_code;
5311 const struct message *setfont;
5312 } static_ctrl[] = {
5313 { SS_LEFT, DLGC_STATIC,
5314 WmSetFontStaticSeq }
5315 };
5316 unsigned int i;
5317 HWND hwnd;
5318 DWORD dlg_code;
5319
5320 subclass_static();
5321
5322 for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
5323 {
5324 hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
5325 0, 0, 50, 14, 0, 0, 0, NULL);
5326 ok(hwnd != 0, "Failed to create static window\n");
5327
5328 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5329 ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5330
5331 ShowWindow(hwnd, SW_SHOW);
5332 UpdateWindow(hwnd);
5333 SetFocus(0);
5334 flush_sequence();
5335
5336 trace("static style %08x\n", static_ctrl[i].style);
5337 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
5338 ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
5339
5340 DestroyWindow(hwnd);
5341 }
5342 }
5343
5344 /****************** ComboBox message test *************************/
5345 #define ID_COMBOBOX 0x000f
5346
5347 static const struct message WmKeyDownComboSeq[] =
5348 {
5349 { WM_KEYDOWN, sent|wparam|lparam, VK_DOWN, 0 },
5350 { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(1000, LBN_SELCHANGE) },
5351 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELENDOK) },
5352 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELCHANGE) },
5353 { WM_CTLCOLOREDIT, sent|parent },
5354 { WM_KEYUP, sent|wparam|lparam, VK_DOWN, 0 },
5355 { 0 }
5356 };
5357
5358 static WNDPROC old_combobox_proc;
5359
5360 static LRESULT CALLBACK combobox_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5361 {
5362 static long defwndproc_counter = 0;
5363 LRESULT ret;
5364 struct recvd_message msg;
5365
5366 /* do not log painting messages */
5367 if (message != WM_PAINT &&
5368 message != WM_NCPAINT &&
5369 message != WM_SYNCPAINT &&
5370 message != WM_ERASEBKGND &&
5371 message != WM_NCHITTEST &&
5372 message != WM_GETTEXT &&
5373 message != WM_GETICON &&
5374 message != WM_GETOBJECT &&
5375 message != WM_DEVICECHANGE)
5376 {
5377 msg.hwnd = hwnd;
5378 msg.message = message;
5379 msg.flags = sent|wparam|lparam;
5380 if (defwndproc_counter) msg.flags |= defwinproc;
5381 msg.wParam = wParam;
5382 msg.lParam = lParam;
5383 msg.descr = "combo";
5384 add_message(&msg);
5385 }
5386
5387 defwndproc_counter++;
5388 ret = CallWindowProcA(old_combobox_proc, hwnd, message, wParam, lParam);
5389 defwndproc_counter--;
5390
5391 return ret;
5392 }
5393
5394 static void subclass_combobox(void)
5395 {
5396 WNDCLASSA cls;
5397
5398 if (!GetClassInfoA(0, "ComboBox", &cls)) assert(0);
5399
5400 old_combobox_proc = cls.lpfnWndProc;
5401
5402 cls.hInstance = GetModuleHandle(0);
5403 cls.lpfnWndProc = combobox_hook_proc;
5404 cls.lpszClassName = "my_combobox_class";
5405 UnregisterClass(cls.lpszClassName, cls.hInstance);
5406 if (!RegisterClassA(&cls)) assert(0);
5407 }
5408
5409 static void test_combobox_messages(void)
5410 {
5411 HWND parent, combo;
5412 LRESULT ret;
5413
5414 subclass_combobox();
5415
5416 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5417 100, 100, 200, 200, 0, 0, 0, NULL);
5418 ok(parent != 0, "Failed to create parent window\n");
5419 flush_sequence();
5420
5421 combo = CreateWindowEx(0, "my_combobox_class", "test", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
5422 0, 0, 100, 150, parent, (HMENU)ID_COMBOBOX, 0, NULL);
5423 ok(combo != 0, "Failed to create combobox window\n");
5424
5425 UpdateWindow(combo);
5426
5427 ret = SendMessage(combo, WM_GETDLGCODE, 0, 0);
5428 ok(ret == (DLGC_WANTCHARS | DLGC_WANTARROWS), "wrong dlg_code %08lx\n", ret);
5429
5430 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 0");
5431 ok(ret == 0, "expected 0, got %ld\n", ret);
5432 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 1");
5433 ok(ret == 1, "expected 1, got %ld\n", ret);
5434 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 2");
5435 ok(ret == 2, "expected 2, got %ld\n", ret);
5436
5437 SendMessage(combo, CB_SETCURSEL, 0, 0);
5438 SetFocus(combo);
5439 flush_sequence();
5440
5441 log_all_parent_messages++;
5442 SendMessage(combo, WM_KEYDOWN, VK_DOWN, 0);
5443 SendMessage(combo, WM_KEYUP, VK_DOWN, 0);
5444 log_all_parent_messages--;
5445 ok_sequence(WmKeyDownComboSeq, "WM_KEYDOWN/VK_DOWN on a ComboBox", FALSE);
5446
5447 DestroyWindow(combo);
5448 DestroyWindow(parent);
5449 }
5450
5451 /****************** WM_IME_KEYDOWN message test *******************/
5452
5453 static const struct message WmImeKeydownMsgSeq_0[] =
5454 {
5455 { WM_IME_KEYDOWN, wparam, VK_RETURN },
5456 { WM_CHAR, wparam, 'A' },
5457 { 0 }
5458 };
5459
5460 static const struct message WmImeKeydownMsgSeq_1[] =
5461 {
5462 { WM_KEYDOWN, optional|wparam, VK_RETURN },
5463 { WM_CHAR, optional|wparam, VK_RETURN },
5464 { 0 }
5465 };
5466
5467 static LRESULT WINAPI wmime_keydown_procA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5468 {
5469 struct recvd_message msg;
5470
5471 msg.hwnd = hwnd;
5472 msg.message = message;
5473 msg.flags = wparam|lparam;
5474 msg.wParam = wParam;
5475 msg.lParam = lParam;
5476 msg.descr = "wmime_keydown";
5477 add_message(&msg);
5478
5479 return DefWindowProcA(hwnd, message, wParam, lParam);
5480 }
5481
5482 static void register_wmime_keydown_class(void)
5483 {
5484 WNDCLASSA cls;
5485
5486 ZeroMemory(&cls, sizeof(WNDCLASSA));
5487 cls.lpfnWndProc = wmime_keydown_procA;
5488 cls.hInstance = GetModuleHandleA(0);
5489 cls.lpszClassName = "wmime_keydown_class";
5490 if (!RegisterClassA(&cls)) assert(0);
5491 }
5492
5493 static void test_wmime_keydown_message(void)
5494 {
5495 HWND hwnd;
5496 MSG msg;
5497
5498 trace("Message sequences by WM_IME_KEYDOWN\n");
5499
5500 register_wmime_keydown_class();
5501 hwnd = CreateWindowExA(0, "wmime_keydown_class", NULL, WS_OVERLAPPEDWINDOW,
5502 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5503 NULL, NULL, 0);
5504 flush_events();
5505 flush_sequence();
5506
5507 SendMessage(hwnd, WM_IME_KEYDOWN, VK_RETURN, 0x1c0001);
5508 SendMessage(hwnd, WM_CHAR, 'A', 1);
5509 ok_sequence(WmImeKeydownMsgSeq_0, "WM_IME_KEYDOWN 0", FALSE);
5510
5511 while ( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) )
5512 {
5513 TranslateMessage(&msg);
5514 DispatchMessage(&msg);
5515 }
5516 ok_sequence(WmImeKeydownMsgSeq_1, "WM_IME_KEYDOWN 1", FALSE);
5517
5518 DestroyWindow(hwnd);
5519 }
5520
5521 /************* painting message test ********************/
5522
5523 void dump_region(HRGN hrgn)
5524 {
5525 DWORD i, size;
5526 RGNDATA *data = NULL;
5527 RECT *rect;
5528
5529 if (!hrgn)
5530 {
5531 printf( "null region\n" );
5532 return;
5533 }
5534 if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
5535 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
5536 GetRegionData( hrgn, size, data );
5537 printf("%d rects:", data->rdh.nCount );
5538 for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
5539 printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
5540 printf("\n");
5541 HeapFree( GetProcessHeap(), 0, data );
5542 }
5543
5544 static void check_update_rgn( HWND hwnd, HRGN hrgn )
5545 {
5546 INT ret;
5547 RECT r1, r2;
5548 HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
5549 HRGN update = CreateRectRgn( 0, 0, 0, 0 );
5550
5551 ret = GetUpdateRgn( hwnd, update, FALSE );
5552 ok( ret != ERROR, "GetUpdateRgn failed\n" );
5553 if (ret == NULLREGION)
5554 {
5555 ok( !hrgn, "Update region shouldn't be empty\n" );
5556 }
5557 else
5558 {
5559 if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
5560 {
5561 ok( 0, "Regions are different\n" );
5562 if (winetest_debug > 0)
5563 {
5564 printf( "Update region: " );
5565 dump_region( update );
5566 printf( "Wanted region: " );
5567 dump_region( hrgn );
5568 }
5569 }
5570 }
5571 GetRgnBox( update, &r1 );
5572 GetUpdateRect( hwnd, &r2, FALSE );
5573 ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
5574 "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
5575 r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
5576
5577 DeleteObject( tmp );
5578 DeleteObject( update );
5579 }
5580
5581 static const struct message WmInvalidateRgn[] = {
5582 { WM_NCPAINT, sent },
5583 { WM_GETTEXT, sent|defwinproc|optional },
5584 { 0 }
5585 };
5586
5587 static const struct message WmGetUpdateRect[] = {
5588 { WM_NCPAINT, sent },
5589 { WM_GETTEXT, sent|defwinproc|optional },
5590 { WM_PAINT, sent },
5591 { 0 }
5592 };
5593
5594 static const struct message WmInvalidateFull[] = {
5595 { WM_NCPAINT, sent|wparam, 1 },
5596 { WM_GETTEXT, sent|defwinproc|optional },
5597 { 0 }
5598 };
5599
5600 static const struct message WmInvalidateErase[] = {
5601 { WM_NCPAINT, sent|wparam, 1 },
5602 { WM_GETTEXT, sent|defwinproc|optional },
5603 { WM_ERASEBKGND, sent },
5604 { 0 }
5605 };
5606
5607 static const struct message WmInvalidatePaint[] = {
5608 { WM_PAINT, sent },
5609 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5610 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5611 { 0 }
5612 };
5613
5614 static const struct message WmInvalidateErasePaint[] = {
5615 { WM_PAINT, sent },
5616 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5617 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5618 { WM_ERASEBKGND, sent|beginpaint },
5619 { 0 }
5620 };
5621
5622 static const struct message WmInvalidateErasePaint2[] = {
5623 { WM_PAINT, sent },
5624 { WM_NCPAINT, sent|beginpaint },
5625 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5626 { WM_ERASEBKGND, sent|beginpaint|optional },
5627 { 0 }
5628 };
5629
5630 static const struct message WmErase[] = {
5631 { WM_ERASEBKGND, sent },
5632 { 0 }
5633 };
5634
5635 static const struct message WmPaint[] = {
5636 { WM_PAINT, sent },
5637 { 0 }
5638 };
5639
5640 static const struct message WmParentOnlyPaint[] = {
5641 { WM_PAINT, sent|parent },
5642 { 0 }
5643 };
5644
5645 static const struct message WmInvalidateParent[] = {
5646 { WM_NCPAINT, sent|parent },
5647 { WM_GETTEXT, sent|defwinproc|parent|optional },
5648 { WM_ERASEBKGND, sent|parent },
5649 { 0 }
5650 };
5651
5652 static const struct message WmInvalidateParentChild[] = {
5653 { WM_NCPAINT, sent|parent },
5654 { WM_GETTEXT, sent|defwinproc|parent|optional },
5655 { WM_ERASEBKGND, sent|parent },
5656 { WM_NCPAINT, sent },
5657 { WM_GETTEXT, sent|defwinproc|optional },
5658 { WM_ERASEBKGND, sent },
5659 { 0 }
5660 };
5661
5662 static const struct message WmInvalidateParentChild2[] = {
5663 { WM_ERASEBKGND, sent|parent },
5664 { WM_NCPAINT, sent },
5665 { WM_GETTEXT, sent|defwinproc|optional },
5666 { WM_ERASEBKGND, sent },
5667 { 0 }
5668 };
5669
5670 static const struct message WmParentPaint[] = {
5671 { WM_PAINT, sent|parent },
5672 { WM_PAINT, sent },
5673 { 0 }
5674 };
5675
5676 static const struct message WmParentPaintNc[] = {
5677 { WM_PAINT, sent|parent },
5678 { WM_PAINT, sent },
5679 { WM_NCPAINT, sent|beginpaint },
5680 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5681 { WM_ERASEBKGND, sent|beginpaint|optional },
5682 { 0 }
5683 };
5684
5685 static const struct message WmChildPaintNc[] = {
5686 { WM_PAINT, sent },
5687 { WM_NCPAINT, sent|beginpaint },
5688 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5689 { WM_ERASEBKGND, sent|beginpaint },
5690 { 0 }
5691 };
5692
5693 static const struct message WmParentErasePaint[] = {
5694 { WM_PAINT, sent|parent },
5695 { WM_NCPAINT, sent|parent|beginpaint },
5696 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5697 { WM_ERASEBKGND, sent|parent|beginpaint|optional },
5698 { WM_PAINT, sent },
5699 { WM_NCPAINT, sent|beginpaint },
5700 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5701 { WM_ERASEBKGND, sent|beginpaint|optional },
5702 { 0 }
5703 };
5704
5705 static const struct message WmParentOnlyNcPaint[] = {
5706 { WM_PAINT, sent|parent },
5707 { WM_NCPAINT, sent|parent|beginpaint },
5708 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5709 { 0 }
5710 };
5711
5712 static const struct message WmSetParentStyle[] = {
5713 { WM_STYLECHANGING, sent|parent },
5714 { WM_STYLECHANGED, sent|parent },
5715 { 0 }
5716 };
5717
5718 static void test_paint_messages(void)
5719 {
5720 BOOL ret;
5721 RECT rect;
5722 POINT pt;
5723 MSG msg;
5724 HWND hparent, hchild;
5725 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
5726 HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
5727 HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
5728 100, 100, 200, 200, 0, 0, 0, NULL);
5729 ok (hwnd != 0, "Failed to create overlapped window\n");
5730
5731 ShowWindow( hwnd, SW_SHOW );
5732 UpdateWindow( hwnd );
5733 flush_events();
5734 flush_sequence();
5735
5736 check_update_rgn( hwnd, 0 );
5737 SetRectRgn( hrgn, 10, 10, 20, 20 );
5738 ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5739 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5740 check_update_rgn( hwnd, hrgn );
5741 SetRectRgn( hrgn2, 20, 20, 30, 30 );
5742 ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
5743 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5744 CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
5745 check_update_rgn( hwnd, hrgn );
5746 /* validate everything */
5747 ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5748 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5749 check_update_rgn( hwnd, 0 );
5750
5751 /* test empty region */
5752 SetRectRgn( hrgn, 10, 10, 10, 15 );
5753 ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5754 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5755 check_update_rgn( hwnd, 0 );
5756 /* test empty rect */
5757 SetRect( &rect, 10, 10, 10, 15 );
5758 ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
5759 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5760 check_update_rgn( hwnd, 0 );
5761
5762 /* flush pending messages */
5763 flush_events();
5764 flush_sequence();
5765
5766 GetClientRect( hwnd, &rect );
5767 SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
5768 /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
5769 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5770 */
5771 trace("testing InvalidateRect(0, NULL, FALSE)\n");
5772 SetRectEmpty( &rect );
5773 ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
5774 check_update_rgn( hwnd, hrgn );
5775 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5776 flush_events();
5777 ok_sequence( WmPaint, "Paint", FALSE );
5778 RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5779 check_update_rgn( hwnd, 0 );
5780
5781 /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
5782 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5783 */
5784 trace("testing ValidateRect(0, NULL)\n");
5785 SetRectEmpty( &rect );
5786 if (ValidateRect(0, &rect)) /* not supported on Win9x */
5787 {
5788 check_update_rgn( hwnd, hrgn );
5789 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5790 flush_events();
5791 ok_sequence( WmPaint, "Paint", FALSE );
5792 RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5793 check_update_rgn( hwnd, 0 );
5794 }
5795
5796 trace("testing InvalidateRgn(0, NULL, FALSE)\n");
5797 SetLastError(0xdeadbeef);
5798 ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
5799 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || GetLastError() == 0xdeadbeef,
5800 "wrong error code %d\n", GetLastError());
5801 check_update_rgn( hwnd, 0 );
5802 flush_events();
5803 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5804
5805 trace("testing ValidateRgn(0, NULL)\n");
5806 SetLastError(0xdeadbeef);
5807 ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
5808 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
5809 broken( GetLastError() == 0xdeadbeef ) /* win9x */,
5810 "wrong error code %d\n", GetLastError());
5811 check_update_rgn( hwnd, 0 );
5812 flush_events();
5813 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5814
5815 /* now with frame */
5816 SetRectRgn( hrgn, -5, -5, 20, 20 );
5817
5818 /* flush pending messages */
5819 flush_events();
5820 flush_sequence();
5821 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5822 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5823
5824 SetRectRgn( hrgn, 0, 0, 20, 20 ); /* GetUpdateRgn clips to client area */
5825 check_update_rgn( hwnd, hrgn );
5826
5827 flush_sequence();
5828 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5829 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5830
5831 flush_sequence();
5832 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5833 ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
5834
5835 GetClientRect( hwnd, &rect );
5836 SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
5837 check_update_rgn( hwnd, hrgn );
5838
5839 flush_sequence();
5840 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
5841 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5842
5843 flush_sequence();
5844 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
5845 ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
5846 check_update_rgn( hwnd, 0 );
5847
5848 flush_sequence();
5849 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
5850 ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
5851 check_update_rgn( hwnd, 0 );
5852
5853 flush_sequence();
5854 SetRectRgn( hrgn, 0, 0, 100, 100 );
5855 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5856 SetRectRgn( hrgn, 0, 0, 50, 100 );
5857 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
5858 SetRectRgn( hrgn, 50, 0, 100, 100 );
5859 check_update_rgn( hwnd, hrgn );
5860 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5861 ok_sequence( WmEmptySeq, "EmptySeq", FALSE ); /* must not generate messages, everything is valid */
5862 check_update_rgn( hwnd, 0 );
5863
5864 flush_sequence();
5865 SetRectRgn( hrgn, 0, 0, 100, 100 );
5866 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5867 SetRectRgn( hrgn, 0, 0, 100, 50 );
5868 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5869 ok_sequence( WmErase, "Erase", FALSE );
5870 SetRectRgn( hrgn, 0, 50, 100, 100 );
5871 check_update_rgn( hwnd, hrgn );
5872
5873 flush_sequence();
5874 SetRectRgn( hrgn, 0, 0, 100, 100 );
5875 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5876 SetRectRgn( hrgn, 0, 0, 50, 50 );
5877 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
5878 ok_sequence( WmPaint, "Paint", FALSE );
5879
5880 flush_sequence();
5881 SetRectRgn( hrgn, -4, -4, -2, -2 );
5882 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5883 SetRectRgn( hrgn, -200, -200, -198, -198 );
5884 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
5885 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5886
5887 flush_sequence();
5888 SetRectRgn( hrgn, -4, -4, -2, -2 );
5889 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5890 SetRectRgn( hrgn, -4, -4, -3, -3 );
5891 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
5892 SetRectRgn( hrgn, 0, 0, 1, 1 );
5893 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
5894 ok_sequence( WmPaint, "Paint", FALSE );
5895
5896 flush_sequence();
5897 SetRectRgn( hrgn, -4, -4, -1, -1 );
5898 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5899 RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
5900 /* make sure no WM_PAINT was generated */
5901 flush_events();
5902 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5903
5904 flush_sequence();
5905 SetRectRgn( hrgn, -4, -4, -1, -1 );
5906 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5907 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
5908 {
5909 if (msg.hwnd == hwnd && msg.message == WM_PAINT)
5910 {
5911 /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
5912 INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
5913 ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
5914 ret = GetUpdateRect( hwnd, &rect, FALSE );
5915 ok( ret, "Invalid GetUpdateRect result %d\n", ret );
5916 /* this will send WM_NCPAINT and validate the non client area */
5917 ret = GetUpdateRect( hwnd, &rect, TRUE );
5918 ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
5919 }
5920 DispatchMessage( &msg );
5921 }
5922 ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
5923
5924 DestroyWindow( hwnd );
5925
5926 /* now test with a child window */
5927
5928 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
5929 100, 100, 200, 200, 0, 0, 0, NULL);
5930 ok (hparent != 0, "Failed to create parent window\n");
5931
5932 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
5933 10, 10, 100, 100, hparent, 0, 0, NULL);
5934 ok (hchild != 0, "Failed to create child window\n");
5935
5936 ShowWindow( hparent, SW_SHOW );
5937 UpdateWindow( hparent );
5938 UpdateWindow( hchild );
5939 flush_events();
5940 flush_sequence();
5941 log_all_parent_messages++;
5942
5943 SetRect( &rect, 0, 0, 50, 50 );
5944 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5945 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5946 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
5947
5948 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5949 pt.x = pt.y = 0;
5950 MapWindowPoints( hchild, hparent, &pt, 1 );
5951 SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
5952 check_update_rgn( hchild, hrgn );
5953 SetRectRgn( hrgn, 0, 0, 50, 50 );
5954 check_update_rgn( hparent, hrgn );
5955 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5956 ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
5957 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5958 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5959
5960 flush_events();
5961 ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
5962
5963 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5964 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5965 ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
5966 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5967 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5968
5969 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
5970 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5971 ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
5972
5973 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
5974 flush_sequence();
5975 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5976 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5977 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
5978
5979 /* flush all paint messages */
5980 flush_events();
5981 flush_sequence();
5982
5983 /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
5984 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5985 SetRectRgn( hrgn, 0, 0, 50, 50 );
5986 check_update_rgn( hparent, hrgn );
5987 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5988 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5989 SetRectRgn( hrgn, 0, 0, 50, 50 );
5990 check_update_rgn( hparent, hrgn );
5991
5992 /* flush all paint messages */
5993 flush_events();
5994 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
5995 flush_sequence();
5996
5997 /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
5998 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5999 SetRectRgn( hrgn, 0, 0, 50, 50 );
6000 check_update_rgn( hparent, hrgn );
6001 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6002 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6003 SetRectRgn( hrgn2, 10, 10, 50, 50 );
6004 CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
6005 check_update_rgn( hparent, hrgn );
6006 /* flush all paint messages */
6007 flush_events();
6008 flush_sequence();
6009
6010 /* same as above but parent gets completely validated */
6011 SetRect( &rect, 20, 20, 30, 30 );
6012 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6013 SetRectRgn( hrgn, 20, 20, 30, 30 );
6014 check_update_rgn( hparent, hrgn );
6015 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6016 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6017 check_update_rgn( hparent, 0 ); /* no update region */
6018 flush_events();
6019 ok_sequence( WmEmptySeq, "WmEmpty", FALSE ); /* and no paint messages */
6020
6021 /* make sure RDW_VALIDATE on child doesn't have the same effect */
6022 flush_sequence();
6023 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6024 SetRectRgn( hrgn, 20, 20, 30, 30 );
6025 check_update_rgn( hparent, hrgn );
6026 RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
6027 SetRectRgn( hrgn, 20, 20, 30, 30 );
6028 check_update_rgn( hparent, hrgn );
6029
6030 /* same as above but normal WM_PAINT doesn't validate parent */
6031 flush_sequence();
6032 SetRect( &rect, 20, 20, 30, 30 );
6033 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6034 SetRectRgn( hrgn, 20, 20, 30, 30 );
6035 check_update_rgn( hparent, hrgn );
6036 /* no WM_PAINT in child while parent still pending */
6037 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6038 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6039 while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6040 ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
6041
6042 flush_sequence();
6043 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6044 /* no WM_PAINT in child while parent still pending */
6045 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6046 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6047 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
6048 /* now that parent is valid child should get WM_PAINT */
6049 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6050 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6051 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6052 ok_sequence( WmEmptySeq, "No other message", FALSE );
6053
6054 /* same thing with WS_CLIPCHILDREN in parent */
6055 flush_sequence();
6056 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6057 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6058 /* changing style invalidates non client area, but we need to invalidate something else to see it */
6059 RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
6060 ok_sequence( WmEmptySeq, "No message", FALSE );
6061 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
6062 ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
6063
6064 flush_sequence();
6065 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
6066 SetRectRgn( hrgn, 20, 20, 30, 30 );
6067 check_update_rgn( hparent, hrgn );
6068 /* no WM_PAINT in child while parent still pending */
6069 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6070 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6071 /* WM_PAINT in parent first */
6072 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6073 ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
6074
6075 /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
6076 flush_sequence();
6077 SetRect( &rect, 0, 0, 30, 30 );
6078 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
6079 SetRectRgn( hrgn, 0, 0, 30, 30 );
6080 check_update_rgn( hparent, hrgn );
6081 flush_events();
6082 ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
6083
6084 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6085 flush_sequence();
6086 SetRect( &rect, -10, 0, 30, 30 );
6087 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6088 SetRect( &rect, 0, 0, 20, 20 );
6089 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6090 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6091 ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
6092
6093 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6094 flush_sequence();
6095 SetRect( &rect, -10, 0, 30, 30 );
6096 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6097 SetRect( &rect, 0, 0, 100, 100 );
6098 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6099 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6100 ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
6101 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6102 ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
6103
6104 /* test RDW_INTERNALPAINT behavior */
6105
6106 flush_sequence();
6107 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
6108 flush_events();
6109 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6110
6111 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
6112 flush_events();
6113 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6114
6115 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6116 flush_events();
6117 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6118
6119 assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
6120 UpdateWindow( hparent );
6121 flush_events();
6122 flush_sequence();
6123 trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
6124 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6125 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6126 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6127 flush_events();
6128 ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
6129
6130 UpdateWindow( hparent );
6131 flush_events();
6132 flush_sequence();
6133 trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
6134 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6135 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6136 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6137 flush_events();
6138 ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6139
6140 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6141 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6142 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6143 flush_events();
6144 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6145
6146 assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
6147 UpdateWindow( hparent );
6148 flush_events();
6149 flush_sequence();
6150 trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
6151 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6152 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6153 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6154 flush_events();
6155 ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
6156
6157 UpdateWindow( hparent );
6158 flush_events();
6159 flush_sequence();
6160 trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
6161 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6162 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6163 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6164 flush_events();
6165 ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6166
6167 ok(GetWindowLong( hparent, GWL_STYLE ) & WS_VISIBLE, "parent should be visible\n");
6168 ok(GetWindowLong( hchild, GWL_STYLE ) & WS_VISIBLE, "child should be visible\n");
6169
6170 UpdateWindow( hparent );
6171 flush_events();
6172 flush_sequence();
6173 trace("testing SetWindowPos(-10000, -10000) on child\n");
6174 SetWindowPos( hchild, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6175 check_update_rgn( hchild, 0 );
6176 flush_events();
6177
6178 #if 0 /* this one doesn't pass under Wine yet */
6179 UpdateWindow( hparent );
6180 flush_events();
6181 flush_sequence();
6182 trace("testing ShowWindow(SW_MINIMIZE) on child\n");
6183 ShowWindow( hchild, SW_MINIMIZE );
6184 check_update_rgn( hchild, 0 );
6185 flush_events();
6186 #endif
6187
6188 UpdateWindow( hparent );
6189 flush_events();
6190 flush_sequence();
6191 trace("testing SetWindowPos(-10000, -10000) on parent\n");
6192 SetWindowPos( hparent, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6193 check_update_rgn( hparent, 0 );
6194 flush_events();
6195
6196 log_all_parent_messages--;
6197 DestroyWindow( hparent );
6198 ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6199
6200 /* tests for moving windows off-screen (needs simple WS_POPUP windows) */
6201
6202 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_POPUP | WS_VISIBLE,
6203 100, 100, 200, 200, 0, 0, 0, NULL);
6204 ok (hparent != 0, "Failed to create parent window\n");
6205
6206 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
6207 10, 10, 100, 100, hparent, 0, 0, NULL);
6208 ok (hchild != 0, "Failed to create child window\n");
6209
6210 ShowWindow( hparent, SW_SHOW );
6211 UpdateWindow( hparent );
6212 UpdateWindow( hchild );
6213 flush_events();
6214 flush_sequence();
6215
6216 /* moving child outside of parent boundaries changes update region */
6217 SetRect( &rect, 0, 0, 40, 40 );
6218 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6219 SetRectRgn( hrgn, 0, 0, 40, 40 );
6220 check_update_rgn( hchild, hrgn );
6221 MoveWindow( hchild, -10, 10, 100, 100, FALSE );
6222 SetRectRgn( hrgn, 10, 0, 40, 40 );
6223 check_update_rgn( hchild, hrgn );
6224 MoveWindow( hchild, -10, -10, 100, 100, FALSE );
6225 SetRectRgn( hrgn, 10, 10, 40, 40 );
6226 check_update_rgn( hchild, hrgn );
6227
6228 /* moving parent off-screen does too */
6229 SetRect( &rect, 0, 0, 100, 100 );
6230 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
6231 SetRectRgn( hrgn, 0, 0, 100, 100 );
6232 check_update_rgn( hparent, hrgn );
6233 SetRectRgn( hrgn, 10, 10, 40, 40 );
6234 check_update_rgn( hchild, hrgn );
6235 MoveWindow( hparent, -20, -20, 200, 200, FALSE );
6236 SetRectRgn( hrgn, 20, 20, 100, 100 );
6237 check_update_rgn( hparent, hrgn );
6238 SetRectRgn( hrgn, 30, 30, 40, 40 );
6239 check_update_rgn( hchild, hrgn );
6240
6241 /* invalidated region is cropped by the parent rects */
6242 SetRect( &rect, 0, 0, 50, 50 );
6243 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6244 SetRectRgn( hrgn, 30, 30, 50, 50 );
6245 check_update_rgn( hchild, hrgn );
6246
6247 DestroyWindow( hparent );
6248 ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6249 flush_sequence();
6250
6251 DeleteObject( hrgn );
6252 DeleteObject( hrgn2 );
6253 }
6254
6255 struct wnd_event
6256 {
6257 HWND hwnd;
6258 HANDLE event;
6259 };
6260
6261 static DWORD WINAPI thread_proc(void *param)
6262 {
6263 MSG msg;
6264 struct wnd_event *wnd_event = param;
6265
6266 wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
6267 100, 100, 200, 200, 0, 0, 0, NULL);
6268 ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
6269
6270 SetEvent(wnd_event->event);
6271
6272 while (GetMessage(&msg, 0, 0, 0))
6273 {
6274 TranslateMessage(&msg);
6275 DispatchMessage(&msg);
6276 }
6277
6278 ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
6279
6280 return 0;
6281 }
6282
6283 static void test_interthread_messages(void)
6284 {
6285 HANDLE hThread;
6286 DWORD tid;
6287 WNDPROC proc;
6288 MSG msg;
6289 char buf[256];
6290 int len, expected_len;
6291 struct wnd_event wnd_event;
6292 BOOL ret;
6293
6294 wnd_event.event = CreateEventW(NULL, 0, 0, NULL);
6295 if (!wnd_event.event)
6296 {
6297 win_skip("skipping interthread message test under win9x\n");
6298 return;
6299 }
6300
6301 hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
6302 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
6303
6304 ok(WaitForSingleObject(wnd_event.event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6305
6306 CloseHandle(wnd_event.event);
6307
6308 SetLastError(0xdeadbeef);
6309 ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
6310 ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
6311 "wrong error code %d\n", GetLastError());
6312
6313 proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6314 ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
6315
6316 expected_len = lstrlenA("window caption text");
6317 memset(buf, 0, sizeof(buf));
6318 SetLastError(0xdeadbeef);
6319 len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
6320 ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
6321 ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
6322
6323 msg.hwnd = wnd_event.hwnd;
6324 msg.message = WM_GETTEXT;
6325 msg.wParam = sizeof(buf);
6326 msg.lParam = (LPARAM)buf;
6327 memset(buf, 0, sizeof(buf));
6328 SetLastError(0xdeadbeef);
6329 len = DispatchMessageA(&msg);
6330 ok((!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY) || broken(len), /* nt4 */
6331 "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %d\n", len, GetLastError());
6332
6333 /* the following test causes an exception in user.exe under win9x */
6334 msg.hwnd = wnd_event.hwnd;
6335 msg.message = WM_TIMER;
6336 msg.wParam = 0;
6337 msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6338 SetLastError(0xdeadbeef);
6339 len = DispatchMessageA(&msg);
6340 ok(!len && GetLastError() == 0xdeadbeef,
6341 "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
6342
6343 ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
6344 ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
6345
6346 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6347 CloseHandle(hThread);
6348
6349 ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
6350 }
6351
6352
6353 static const struct message WmVkN[] = {
6354 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6355 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6356 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6357 { WM_CHAR, wparam|lparam, 'n', 1 },
6358 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
6359 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6360 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6361 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6362 { 0 }
6363 };
6364 static const struct message WmShiftVkN[] = {
6365 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6366 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6367 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6368 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6369 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6370 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6371 { WM_CHAR, wparam|lparam, 'N', 1 },
6372 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
6373 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6374 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6375 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6376 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6377 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6378 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6379 { 0 }
6380 };
6381 static const struct message WmCtrlVkN[] = {
6382 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6383 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6384 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6385 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6386 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6387 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6388 { WM_CHAR, wparam|lparam, 0x000e, 1 },
6389 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6390 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6391 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6392 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6393 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6394 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6395 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6396 { 0 }
6397 };
6398 static const struct message WmCtrlVkN_2[] = {
6399 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6400 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6401 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6402 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6403 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6404 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6405 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6406 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6407 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6408 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6409 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6410 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6411 { 0 }
6412 };
6413 static const struct message WmAltVkN[] = {
6414 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6415 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6416 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6417 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6418 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6419 { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6420 { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
6421 { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
6422 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
6423 { HCBT_SYSCOMMAND, hook },
6424 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6425 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6426 { 0x00AE, sent|defwinproc|optional }, /* XP */
6427 { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
6428 { WM_INITMENU, sent|defwinproc },
6429 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6430 { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
6431 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
6432 { WM_CAPTURECHANGED, sent|defwinproc },
6433 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
6434 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6435 { WM_EXITMENULOOP, sent|defwinproc },
6436 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
6437 { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
6438 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6439 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6440 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6441 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6442 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6443 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6444 { 0 }
6445 };
6446 static const struct message WmAltVkN_2[] = {
6447 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6448 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6449 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6450 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6451 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6452 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
6453 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6454 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6455 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6456 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6457 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6458 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6459 { 0 }
6460 };
6461 static const struct message WmCtrlAltVkN[] = {
6462 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6463 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6464 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6465 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6466 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6467 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6468 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6469 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6470 { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6471 { WM_CHAR, optional },
6472 { WM_CHAR, sent|optional },
6473 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6474 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6475 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6476 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6477 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6478 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6479 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6480 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6481 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6482 { 0 }
6483 };
6484 static const struct message WmCtrlShiftVkN[] = {
6485 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6486 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6487 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6488 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6489 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6490 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6491 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6492 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6493 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
6494 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6495 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6496 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6497 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6498 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6499 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6500 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6501 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6502 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6503 { 0 }
6504 };
6505 static const struct message WmCtrlAltShiftVkN[] = {
6506 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6507 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6508 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6509 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6510 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6511 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6512 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
6513 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
6514 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
6515 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6516 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6517 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
6518 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6519 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6520 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6521 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
6522 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
6523 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
6524 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6525 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6526 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6527 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6528 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6529 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6530 { 0 }
6531 };
6532 static const struct message WmAltPressRelease[] = {
6533 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6534 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6535 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6536 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6537 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6538 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6539 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
6540 { HCBT_SYSCOMMAND, hook },
6541 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6542 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6543 { WM_INITMENU, sent|defwinproc },
6544 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6545 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6546 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6547
6548 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
6549
6550 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6551 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
6552 { WM_CAPTURECHANGED, sent|defwinproc },
6553 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
6554 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6555 { WM_EXITMENULOOP, sent|defwinproc },
6556 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6557 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6558 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6559 { 0 }
6560 };
6561 static const struct message WmShiftMouseButton[] = {
6562 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6563 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6564 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6565 { WM_MOUSEMOVE, wparam|optional, 0, 0 },
6566 { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
6567 { WM_LBUTTONDOWN, wparam, MK_LBUTTON|MK_SHIFT, 0 },
6568 { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON|MK_SHIFT, 0 },
6569 { WM_LBUTTONUP, wparam, MK_SHIFT, 0 },
6570 { WM_LBUTTONUP, sent|wparam, MK_SHIFT, 0 },
6571 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6572 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6573 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6574 { 0 }
6575 };
6576 static const struct message WmF1Seq[] = {
6577 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
6578 { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
6579 { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
6580 { WM_KEYF1, wparam|lparam, 0, 0 },
6581 { WM_KEYF1, sent|wparam|lparam, 0, 0 },
6582 { WM_HELP, sent|defwinproc },
6583 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
6584 { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
6585 { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
6586 { 0 }
6587 };
6588 static const struct message WmVkAppsSeq[] = {
6589 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
6590 { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
6591 { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
6592 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
6593 { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
6594 { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
6595 { WM_CONTEXTMENU, lparam, /*hwnd*/0, (LPARAM)-1 },
6596 { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, (LPARAM)-1 },
6597 { 0 }
6598 };
6599
6600 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
6601 {
6602 MSG msg;
6603
6604 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
6605 {
6606 struct recvd_message log_msg;
6607
6608 /* ignore some unwanted messages */
6609 if (msg.message == WM_MOUSEMOVE ||
6610 msg.message == WM_GETICON ||
6611 msg.message == WM_GETOBJECT ||
6612 msg.message == WM_TIMER ||
6613 msg.message == WM_DEVICECHANGE)
6614 continue;
6615
6616 log_msg.hwnd = msg.hwnd;
6617 log_msg.message = msg.message;
6618 log_msg.flags = wparam|lparam;
6619 log_msg.wParam = msg.wParam;
6620 log_msg.lParam = msg.lParam;
6621 log_msg.descr = "accel";
6622 add_message(&log_msg);
6623
6624 if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
6625 {
6626 TranslateMessage(&msg);
6627 DispatchMessage(&msg);
6628 }
6629 }
6630 }
6631
6632 static void test_accelerators(void)
6633 {
6634 RECT rc;
6635 POINT pt;
6636 SHORT state;
6637 HACCEL hAccel;
6638 HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6639 100, 100, 200, 200, 0, 0, 0, NULL);
6640 BOOL ret;
6641
6642 assert(hwnd != 0);
6643 UpdateWindow(hwnd);
6644 flush_events();
6645 flush_sequence();
6646
6647 SetFocus(hwnd);
6648 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
6649
6650 state = GetKeyState(VK_SHIFT);
6651 ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
6652 state = GetKeyState(VK_CAPITAL);
6653 ok(state == 0, "wrong CapsLock state %04x\n", state);
6654
6655 hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
6656 assert(hAccel != 0);
6657
6658 flush_events();
6659 pump_msg_loop(hwnd, 0);
6660 flush_sequence();
6661
6662 trace("testing VK_N press/release\n");
6663 flush_sequence();
6664 keybd_event('N', 0, 0, 0);
6665 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6666 pump_msg_loop(hwnd, hAccel);
6667 if (!sequence_cnt) /* we didn't get any message */
6668 {
6669 skip( "queuing key events not supported\n" );
6670 goto done;
6671 }
6672 ok_sequence(WmVkN, "VK_N press/release", FALSE);
6673
6674 trace("testing Shift+VK_N press/release\n");
6675 flush_sequence();
6676 keybd_event(VK_SHIFT, 0, 0, 0);
6677 keybd_event('N', 0, 0, 0);
6678 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6679 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6680 pump_msg_loop(hwnd, hAccel);
6681 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6682
6683 trace("testing Ctrl+VK_N press/release\n");
6684 flush_sequence();
6685 keybd_event(VK_CONTROL, 0, 0, 0);
6686 keybd_event('N', 0, 0, 0);
6687 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6688 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6689 pump_msg_loop(hwnd, hAccel);
6690 ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
6691
6692 trace("testing Alt+VK_N press/release\n");
6693 flush_sequence();
6694 keybd_event(VK_MENU, 0, 0, 0);
6695 keybd_event('N', 0, 0, 0);
6696 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6697 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6698 pump_msg_loop(hwnd, hAccel);
6699 ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
6700
6701 trace("testing Ctrl+Alt+VK_N press/release 1\n");
6702 flush_sequence();
6703 keybd_event(VK_CONTROL, 0, 0, 0);
6704 keybd_event(VK_MENU, 0, 0, 0);
6705 keybd_event('N', 0, 0, 0);
6706 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6707 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6708 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6709 pump_msg_loop(hwnd, hAccel);
6710 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
6711
6712 ret = DestroyAcceleratorTable(hAccel);
6713 ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6714
6715 hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
6716 assert(hAccel != 0);
6717
6718 trace("testing VK_N press/release\n");
6719 flush_sequence();
6720 keybd_event('N', 0, 0, 0);
6721 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6722 pump_msg_loop(hwnd, hAccel);
6723 ok_sequence(WmVkN, "VK_N press/release", FALSE);
6724
6725 trace("testing Shift+VK_N press/release\n");
6726 flush_sequence();
6727 keybd_event(VK_SHIFT, 0, 0, 0);
6728 keybd_event('N', 0, 0, 0);
6729 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6730 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6731 pump_msg_loop(hwnd, hAccel);
6732 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6733
6734 trace("testing Ctrl+VK_N press/release 2\n");
6735 flush_sequence();
6736 keybd_event(VK_CONTROL, 0, 0, 0);
6737 keybd_event('N', 0, 0, 0);
6738 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6739 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6740 pump_msg_loop(hwnd, hAccel);
6741 ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
6742
6743 trace("testing Alt+VK_N press/release 2\n");
6744 flush_sequence();
6745 keybd_event(VK_MENU, 0, 0, 0);
6746 keybd_event('N', 0, 0, 0);
6747 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6748 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6749 pump_msg_loop(hwnd, hAccel);
6750 ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
6751
6752 trace("testing Ctrl+Alt+VK_N press/release 2\n");
6753 flush_sequence();
6754 keybd_event(VK_CONTROL, 0, 0, 0);
6755 keybd_event(VK_MENU, 0, 0, 0);
6756 keybd_event('N', 0, 0, 0);
6757 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6758 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6759 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6760 pump_msg_loop(hwnd, hAccel);
6761 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
6762
6763 trace("testing Ctrl+Shift+VK_N press/release\n");
6764 flush_sequence();
6765 keybd_event(VK_CONTROL, 0, 0, 0);
6766 keybd_event(VK_SHIFT, 0, 0, 0);
6767 keybd_event('N', 0, 0, 0);
6768 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6769 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6770 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6771 pump_msg_loop(hwnd, hAccel);
6772 ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
6773
6774 trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
6775 flush_sequence();
6776 keybd_event(VK_CONTROL, 0, 0, 0);
6777 keybd_event(VK_MENU, 0, 0, 0);
6778 keybd_event(VK_SHIFT, 0, 0, 0);
6779 keybd_event('N', 0, 0, 0);
6780 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6781 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6782 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6783 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6784 pump_msg_loop(hwnd, hAccel);
6785 ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
6786
6787 ret = DestroyAcceleratorTable(hAccel);
6788 ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6789 hAccel = 0;
6790
6791 trace("testing Alt press/release\n");
6792 flush_sequence();
6793 keybd_event(VK_MENU, 0, 0, 0);
6794 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6795 keybd_event(VK_MENU, 0, 0, 0);
6796 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6797 pump_msg_loop(hwnd, 0);
6798 /* this test doesn't pass in Wine for managed windows */
6799 ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
6800
6801 trace("testing VK_F1 press/release\n");
6802 keybd_event(VK_F1, 0, 0, 0);
6803 keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
6804 pump_msg_loop(hwnd, 0);
6805 ok_sequence(WmF1Seq, "F1 press/release", FALSE);
6806
6807 trace("testing VK_APPS press/release\n");
6808 keybd_event(VK_APPS, 0, 0, 0);
6809 keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
6810 pump_msg_loop(hwnd, 0);
6811 ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
6812
6813 trace("testing Shift+MouseButton press/release\n");
6814 /* first, move mouse pointer inside of the window client area */
6815 GetClientRect(hwnd, &rc);
6816 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
6817 rc.left += (rc.right - rc.left)/2;
6818 rc.top += (rc.bottom - rc.top)/2;
6819 SetCursorPos(rc.left, rc.top);
6820 SetActiveWindow(hwnd);
6821
6822 flush_events();
6823 flush_sequence();
6824 GetCursorPos(&pt);
6825 if (pt.x == rc.left && pt.y == rc.top)
6826 {
6827 keybd_event(VK_SHIFT, 0, 0, 0);
6828 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
6829 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
6830 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6831 pump_msg_loop(hwnd, 0);
6832 ok_sequence(WmShiftMouseButton, "Shift+MouseButton press/release", FALSE);
6833 }
6834
6835 done:
6836 if (hAccel) DestroyAcceleratorTable(hAccel);
6837 DestroyWindow(hwnd);
6838 }
6839
6840 /************* window procedures ********************/
6841
6842 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message,
6843 WPARAM wParam, LPARAM lParam)
6844 {
6845 static long defwndproc_counter = 0;
6846 static long beginpaint_counter = 0;
6847 LRESULT ret;
6848 struct recvd_message msg;
6849
6850 /* ignore registered messages */
6851 if (message >= 0xc000) return 0;
6852
6853 switch (message)
6854 {
6855 case WM_ENABLE:
6856 {
6857 LONG style = GetWindowLongA(hwnd, GWL_STYLE);
6858 ok((BOOL)wParam == !(style & WS_DISABLED),
6859 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
6860 break;
6861 }
6862
6863 case WM_CAPTURECHANGED:
6864 if (test_DestroyWindow_flag)
6865 {
6866 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6867 if (style & WS_CHILD)
6868 lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6869 else if (style & WS_POPUP)
6870 lParam = WND_POPUP_ID;
6871 else
6872 lParam = WND_PARENT_ID;
6873 }
6874 break;
6875
6876 case WM_NCDESTROY:
6877 {
6878 HWND capture;
6879
6880 ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
6881 capture = GetCapture();
6882 if (capture)
6883 {
6884 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
6885 trace("current capture %p, releasing...\n", capture);
6886 ReleaseCapture();
6887 }
6888 }
6889 /* fall through */
6890 case WM_DESTROY:
6891 if (pGetAncestor)
6892 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
6893 if (test_DestroyWindow_flag)
6894 {
6895 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6896 if (style & WS_CHILD)
6897 lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6898 else if (style & WS_POPUP)
6899 lParam = WND_POPUP_ID;
6900 else
6901 lParam = WND_PARENT_ID;
6902 }
6903 break;
6904
6905 /* test_accelerators() depends on this */
6906 case WM_NCHITTEST:
6907 return HTCLIENT;
6908
6909 /* ignore */
6910 case WM_MOUSEMOVE:
6911 case WM_MOUSEACTIVATE:
6912 case WM_NCMOUSEMOVE:
6913 case WM_SETCURSOR:
6914 case WM_GETICON:
6915 case WM_GETOBJECT:
6916 case WM_DEVICECHANGE:
6917 case WM_IME_SELECT:
6918 return 0;
6919 }
6920
6921 msg.hwnd = hwnd;
6922 msg.message = message;
6923 msg.flags = sent|wparam|lparam;
6924 if (defwndproc_counter) msg.flags |= defwinproc;
6925 if (beginpaint_counter) msg.flags |= beginpaint;
6926 msg.wParam = wParam;
6927 msg.lParam = lParam;
6928 msg.descr = "MsgCheckProc";
6929 add_message(&msg);
6930
6931 if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
6932 {
6933 HWND parent = GetParent(hwnd);
6934 RECT rc;
6935 MINMAXINFO *minmax = (MINMAXINFO *)lParam;
6936
6937 GetClientRect(parent, &rc);
6938 trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
6939 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
6940 minmax->ptReserved.x, minmax->ptReserved.y,
6941 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
6942 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
6943 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
6944 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
6945
6946 ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
6947 minmax->ptMaxSize.x, rc.right);
6948 ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
6949 minmax->ptMaxSize.y, rc.bottom);
6950 }
6951
6952 if (message == WM_PAINT)
6953 {
6954 PAINTSTRUCT ps;
6955 beginpaint_counter++;
6956 BeginPaint( hwnd, &ps );
6957 beginpaint_counter--;
6958 EndPaint( hwnd, &ps );
6959 return 0;
6960 }
6961
6962 defwndproc_counter++;
6963 ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam)
6964 : DefWindowProcA(hwnd, message, wParam, lParam);
6965 defwndproc_counter--;
6966
6967 return ret;
6968 }
6969
6970 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6971 {
6972 return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
6973 }
6974
6975 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6976 {
6977 return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
6978 }
6979
6980 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6981 {
6982 static long defwndproc_counter = 0;
6983 LRESULT ret;
6984 struct recvd_message msg;
6985
6986 switch (message)
6987 {
6988 case WM_GETICON:
6989 case WM_GETOBJECT:
6990 return 0; /* ignore them */
6991 case WM_QUERYENDSESSION:
6992 case WM_ENDSESSION:
6993 lParam &= ~0x01; /* Vista adds a 0x01 flag */
6994 break;
6995 }
6996
6997 msg.hwnd = hwnd;
6998 msg.message = message;
6999 msg.flags = sent|wparam|lparam;
7000 if (defwndproc_counter) msg.flags |= defwinproc;
7001 msg.wParam = wParam;
7002 msg.lParam = lParam;
7003 msg.descr = "popup";
7004 add_message(&msg);
7005
7006 if (message == WM_CREATE)
7007 {
7008 DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
7009 SetWindowLongA(hwnd, GWL_STYLE, style);
7010 }
7011
7012 defwndproc_counter++;
7013 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7014 defwndproc_counter--;
7015
7016 return ret;
7017 }
7018
7019 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7020 {
7021 static long defwndproc_counter = 0;
7022 static long beginpaint_counter = 0;
7023 LRESULT ret;
7024 struct recvd_message msg;
7025
7026 if (message == WM_GETICON || message == WM_GETOBJECT) return 0; /* ignore them */
7027
7028 /* ignore registered messages */
7029 if (message >= 0xc000) return 0;
7030
7031 if (log_all_parent_messages ||
7032 message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
7033 message == WM_SETFOCUS || message == WM_KILLFOCUS ||
7034 message == WM_ENABLE || message == WM_ENTERIDLE ||
7035 message == WM_DRAWITEM ||
7036 message == WM_IME_SETCONTEXT)
7037 {
7038 switch (message)
7039 {
7040 /* ignore */
7041 case WM_NCHITTEST:
7042 return HTCLIENT;
7043 case WM_SETCURSOR:
7044 case WM_MOUSEMOVE:
7045 case WM_NCMOUSEMOVE:
7046 return 0;
7047
7048 case WM_ERASEBKGND:
7049 {
7050 RECT rc;
7051 INT ret = GetClipBox((HDC)wParam, &rc);
7052
7053 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
7054 ret, rc.left, rc.top, rc.right, rc.bottom);
7055 break;
7056 }
7057 }
7058
7059 msg.hwnd = hwnd;
7060 msg.message = message;
7061 msg.flags = sent|parent|wparam|lparam;
7062 if (defwndproc_counter) msg.flags |= defwinproc;
7063 if (beginpaint_counter) msg.flags |= beginpaint;
7064 msg.wParam = wParam;
7065 msg.lParam = lParam;
7066 msg.descr = "parent";
7067 add_message(&msg);
7068 }
7069
7070 if (message == WM_PAINT)
7071 {
7072 PAINTSTRUCT ps;
7073 beginpaint_counter++;
7074 BeginPaint( hwnd, &ps );
7075 beginpaint_counter--;
7076 EndPaint( hwnd, &ps );
7077 return 0;
7078 }
7079
7080 defwndproc_counter++;
7081 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7082 defwndproc_counter--;
7083
7084 return ret;
7085 }
7086
7087 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7088 {
7089 static long defwndproc_counter = 0;
7090 LRESULT ret;
7091 struct recvd_message msg;
7092
7093 if (message == WM_GETICON || message == WM_GETOBJECT) return 0; /* ignore them */
7094
7095 if (test_def_id)
7096 {
7097 DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
7098 ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
7099 if (after_end_dialog)
7100 ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
7101 else
7102 ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
7103 }
7104
7105 msg.hwnd = hwnd;
7106 msg.message = message;
7107 msg.flags = sent|wparam|lparam;
7108 if (defwndproc_counter) msg.flags |= defwinproc;
7109 msg.wParam = wParam;
7110 msg.lParam = lParam;
7111 msg.descr = "dialog";
7112 add_message(&msg);
7113
7114 defwndproc_counter++;
7115 ret = DefDlgProcA(hwnd, message, wParam, lParam);
7116 defwndproc_counter--;
7117
7118 return ret;
7119 }
7120
7121 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7122 {
7123 static long defwndproc_counter = 0;
7124 LRESULT ret;
7125 struct recvd_message msg;
7126
7127 /* log only specific messages we are interested in */
7128 switch (message)
7129 {
7130 #if 0 /* probably log these as well */
7131 case WM_ACTIVATE:
7132 case WM_SETFOCUS:
7133 case WM_KILLFOCUS:
7134 #endif
7135 case WM_SHOWWINDOW:
7136 case WM_SIZE:
7137 case WM_MOVE:
7138 case WM_GETMINMAXINFO:
7139 case WM_WINDOWPOSCHANGING:
7140 case WM_WINDOWPOSCHANGED:
7141 break;
7142
7143 default: /* ignore */
7144 /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
7145 return DefWindowProcA(hwnd, message, wParam, lParam);
7146 }
7147
7148 msg.hwnd = hwnd;
7149 msg.message = message;
7150 msg.flags = sent|wparam|lparam;
7151 if (defwndproc_counter) msg.flags |= defwinproc;
7152 msg.wParam = wParam;
7153 msg.lParam = lParam;
7154 msg.descr = "show";
7155 add_message(&msg);
7156
7157 defwndproc_counter++;
7158 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7159 defwndproc_counter--;
7160
7161 return ret;
7162 }
7163
7164 static LRESULT WINAPI PaintLoopProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
7165 {
7166 switch (msg)
7167 {
7168 case WM_CREATE: return 0;
7169 case WM_PAINT:
7170 {
7171 MSG msg2;
7172 static int i = 0;
7173
7174 if (i < 256)
7175 {
7176 i++;
7177 if (PeekMessageA(&msg2, 0, 0, 0, 1))
7178 {
7179 TranslateMessage(&msg2);
7180 DispatchMessage(&msg2);
7181 }
7182 i--;
7183 }
7184 else ok(broken(1), "infinite loop\n");
7185 if ( i == 0)
7186 paint_loop_done = 1;
7187 return DefWindowProcA(hWnd,msg,wParam,lParam);
7188 }
7189 }
7190 return DefWindowProcA(hWnd,msg,wParam,lParam);
7191 }
7192
7193 static BOOL RegisterWindowClasses(void)
7194 {
7195 WNDCLASSA cls;
7196 WNDCLASSW clsW;
7197
7198 cls.style = 0;
7199 cls.lpfnWndProc = MsgCheckProcA;
7200 cls.cbClsExtra = 0;
7201 cls.cbWndExtra = 0;
7202 cls.hInstance = GetModuleHandleA(0);
7203 cls.hIcon = 0;
7204 cls.hCursor = LoadCursorA(0, IDC_ARROW);
7205 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7206 cls.lpszMenuName = NULL;
7207 cls.lpszClassName = "TestWindowClass";
7208 if(!RegisterClassA(&cls)) return FALSE;
7209
7210 cls.lpfnWndProc = ShowWindowProcA;
7211 cls.lpszClassName = "ShowWindowClass";
7212 if(!RegisterClassA(&cls)) return FALSE;
7213
7214 cls.lpfnWndProc = PopupMsgCheckProcA;
7215 cls.lpszClassName = "TestPopupClass";
7216 if(!RegisterClassA(&cls)) return FALSE;
7217
7218 cls.lpfnWndProc = ParentMsgCheckProcA;
7219 cls.lpszClassName = "TestParentClass";
7220 if(!RegisterClassA(&cls)) return FALSE;
7221
7222 cls.lpfnWndProc = DefWindowProcA;
7223 cls.lpszClassName = "SimpleWindowClass";
7224 if(!RegisterClassA(&cls)) return FALSE;
7225
7226 cls.lpfnWndProc = PaintLoopProcA;
7227 cls.lpszClassName = "PaintLoopWindowClass";
7228 if(!RegisterClassA(&cls)) return FALSE;
7229
7230 cls.style = CS_NOCLOSE;
7231 cls.lpszClassName = "NoCloseWindowClass";
7232 if(!RegisterClassA(&cls)) return FALSE;
7233
7234 ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
7235 cls.style = 0;
7236 cls.hInstance = GetModuleHandleA(0);
7237 cls.hbrBackground = 0;
7238 cls.lpfnWndProc = TestDlgProcA;
7239 cls.lpszClassName = "TestDialogClass";
7240 if(!RegisterClassA(&cls)) return FALSE;
7241
7242 clsW.style = 0;
7243 clsW.lpfnWndProc = MsgCheckProcW;
7244 clsW.cbClsExtra = 0;
7245 clsW.cbWndExtra = 0;
7246 clsW.hInstance = GetModuleHandleW(0);
7247 clsW.hIcon = 0;
7248 clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
7249 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
7250 clsW.lpszMenuName = NULL;
7251 clsW.lpszClassName = testWindowClassW;
7252 RegisterClassW(&clsW); /* ignore error, this fails on Win9x */
7253
7254 return TRUE;
7255 }
7256
7257 static BOOL is_our_logged_class(HWND hwnd)
7258 {
7259 char buf[256];
7260
7261 if (GetClassNameA(hwnd, buf, sizeof(buf)))
7262 {
7263 if (!lstrcmpiA(buf, "TestWindowClass") ||
7264 !lstrcmpiA(buf, "ShowWindowClass") ||
7265 !lstrcmpiA(buf, "TestParentClass") ||
7266 !lstrcmpiA(buf, "TestPopupClass") ||
7267 !lstrcmpiA(buf, "SimpleWindowClass") ||
7268 !lstrcmpiA(buf, "TestDialogClass") ||
7269 !lstrcmpiA(buf, "MDI_frame_class") ||
7270 !lstrcmpiA(buf, "MDI_client_class") ||
7271 !lstrcmpiA(buf, "MDI_child_class") ||
7272 !lstrcmpiA(buf, "my_button_class") ||
7273 !lstrcmpiA(buf, "my_edit_class") ||
7274 !lstrcmpiA(buf, "static") ||
7275 !lstrcmpiA(buf, "ListBox") ||
7276 !lstrcmpiA(buf, "ComboBox") ||
7277 !lstrcmpiA(buf, "MyDialogClass") ||
7278 !lstrcmpiA(buf, "#32770") ||
7279 !lstrcmpiA(buf, "#32768"))
7280 return TRUE;
7281 }
7282 return FALSE;
7283 }
7284
7285 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
7286 {
7287 HWND hwnd;
7288
7289 ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7290
7291 if (nCode == HCBT_CLICKSKIPPED)
7292 {
7293 /* ignore this event, XP sends it a lot when switching focus between windows */
7294 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7295 }
7296
7297 if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
7298 {
7299 struct recvd_message msg;
7300
7301 msg.hwnd = 0;
7302 msg.message = nCode;
7303 msg.flags = hook|wparam|lparam;
7304 msg.wParam = wParam;
7305 msg.lParam = lParam;
7306 msg.descr = "CBT";
7307 add_message(&msg);
7308
7309 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7310 }
7311
7312 if (nCode == HCBT_DESTROYWND)
7313 {
7314 if (test_DestroyWindow_flag)
7315 {
7316 DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
7317 if (style & WS_CHILD)
7318 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
7319 else if (style & WS_POPUP)
7320 lParam = WND_POPUP_ID;
7321 else
7322 lParam = WND_PARENT_ID;
7323 }
7324 }
7325
7326 /* Log also SetFocus(0) calls */
7327 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7328
7329 if (is_our_logged_class(hwnd))
7330 {
7331 struct recvd_message msg;
7332
7333 msg.hwnd = hwnd;
7334 msg.message = nCode;
7335 msg.flags = hook|wparam|lparam;
7336 msg.wParam = wParam;
7337 msg.lParam = lParam;
7338 msg.descr = "CBT";
7339 add_message(&msg);
7340 }
7341 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7342 }
7343
7344 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
7345 DWORD event,
7346 HWND hwnd,
7347 LONG object_id,
7348 LONG child_id,
7349 DWORD thread_id,
7350 DWORD event_time)
7351 {
7352 ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7353
7354 /* ignore mouse cursor events */
7355 if (object_id == OBJID_CURSOR) return;
7356
7357 if (!hwnd || is_our_logged_class(hwnd))
7358 {
7359 struct recvd_message msg;
7360
7361 msg.hwnd = hwnd;
7362 msg.message = event;
7363 msg.flags = winevent_hook|wparam|lparam;
7364 msg.wParam = object_id;
7365 msg.lParam = child_id;
7366 msg.descr = "WEH";
7367 add_message(&msg);
7368 }
7369 }
7370
7371 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
7372 static const WCHAR wszAnsi[] = {'U',0};
7373
7374 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
7375 {
7376 switch (uMsg)
7377 {
7378 case CB_FINDSTRINGEXACT:
7379 trace("String: %p\n", (LPCWSTR)lParam);
7380 if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
7381 return 1;
7382 if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
7383 return 0;
7384 return -1;
7385 }
7386 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
7387 }
7388
7389 static const struct message WmGetTextLengthAfromW[] = {
7390 { WM_GETTEXTLENGTH, sent },
7391 { WM_GETTEXT, sent|optional },
7392 { 0 }
7393 };
7394
7395 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
7396
7397 /* dummy window proc for WM_GETTEXTLENGTH test */
7398 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
7399 {
7400 switch(msg)
7401 {
7402 case WM_GETTEXTLENGTH:
7403 return lstrlenW(dummy_window_text) + 37; /* some random length */
7404 case WM_GETTEXT:
7405 lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
7406 return lstrlenW( (LPWSTR)lp );
7407 default:
7408 return DefWindowProcW( hwnd, msg, wp, lp );
7409 }
7410 }
7411
7412 static void test_message_conversion(void)
7413 {
7414 static const WCHAR wszMsgConversionClass[] =
7415 {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
7416 WNDCLASSW cls;
7417 LRESULT lRes;
7418 HWND hwnd;
7419 WNDPROC wndproc, newproc;
7420 BOOL ret;
7421
7422 cls.style = 0;
7423 cls.lpfnWndProc = MsgConversionProcW;
7424 cls.cbClsExtra = 0;
7425 cls.cbWndExtra = 0;
7426 cls.hInstance = GetModuleHandleW(NULL);
7427 cls.hIcon = NULL;
7428 cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
7429 cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
7430 cls.lpszMenuName = NULL;
7431 cls.lpszClassName = wszMsgConversionClass;
7432 /* this call will fail on Win9x, but that doesn't matter as this test is
7433 * meaningless on those platforms */
7434 if(!RegisterClassW(&cls)) return;
7435
7436 hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
7437 100, 100, 200, 200, 0, 0, 0, NULL);
7438 ok(hwnd != NULL, "Window creation failed\n");
7439
7440 /* {W, A} -> A */
7441
7442 wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
7443 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7444 ok(lRes == 0, "String should have been converted\n");
7445 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7446 ok(lRes == 1, "String shouldn't have been converted\n");
7447
7448 /* {W, A} -> W */
7449
7450 wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
7451 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7452 ok(lRes == 1, "String shouldn't have been converted\n");
7453 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7454 ok(lRes == 1, "String shouldn't have been converted\n");
7455
7456 /* Synchronous messages */
7457
7458 lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7459 ok(lRes == 0, "String should have been converted\n");
7460 lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7461 ok(lRes == 1, "String shouldn't have been converted\n");
7462
7463 /* Asynchronous messages */
7464
7465 SetLastError(0);
7466 lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7467 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7468 "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7469 SetLastError(0);
7470 lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7471 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7472 "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7473 SetLastError(0);
7474 lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7475 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7476 "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7477 SetLastError(0);
7478 lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7479 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7480 "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7481 SetLastError(0);
7482 lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7483 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7484 "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7485 SetLastError(0);
7486 lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7487 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7488 "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7489 SetLastError(0);
7490 lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7491 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7492 "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7493 SetLastError(0);
7494 lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7495 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7496 "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7497
7498 /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
7499
7500 hwnd = CreateWindowW (testWindowClassW, wszUnicode,
7501 WS_OVERLAPPEDWINDOW,
7502 100, 100, 200, 200, 0, 0, 0, NULL);
7503 assert(hwnd);
7504 flush_sequence();
7505 lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
7506 ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7507 ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7508 "got bad length %ld\n", lRes );
7509
7510 flush_sequence();
7511 lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
7512 hwnd, WM_GETTEXTLENGTH, 0, 0);
7513 ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7514 ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7515 "got bad length %ld\n", lRes );
7516
7517 wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
7518 newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
7519 lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7520 ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7521 NULL, 0, NULL, NULL ) ||
7522 broken(lRes == lstrlenW(dummy_window_text) + 37),
7523 "got bad length %ld\n", lRes );
7524
7525 SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc ); /* restore old wnd proc */
7526 lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7527 ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7528 NULL, 0, NULL, NULL ) ||
7529 broken(lRes == lstrlenW(dummy_window_text) + 37),
7530 "got bad length %ld\n", lRes );
7531
7532 ret = DestroyWindow(hwnd);
7533 ok( ret, "DestroyWindow() error %d\n", GetLastError());
7534 }
7535
7536 struct timer_info
7537 {
7538 HWND hWnd;
7539 HANDLE handles[2];
7540 DWORD id;
7541 };
7542
7543 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
7544 {
7545 }
7546
7547 #define TIMER_ID 0x19
7548
7549 static DWORD WINAPI timer_thread_proc(LPVOID x)
7550 {
7551 struct timer_info *info = x;
7552 DWORD r;
7553
7554 r = KillTimer(info->hWnd, 0x19);
7555 ok(r,"KillTimer failed in thread\n");
7556 r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
7557 ok(r,"SetTimer failed in thread\n");
7558 ok(r==TIMER_ID,"SetTimer id different\n");
7559 r = SetEvent(info->handles[0]);
7560 ok(r,"SetEvent failed in thread\n");
7561 return 0;
7562 }
7563
7564 static void test_timers(void)
7565 {
7566 struct timer_info info;
7567 DWORD id;
7568
7569 info.hWnd = CreateWindow ("TestWindowClass", NULL,
7570 WS_OVERLAPPEDWINDOW ,
7571 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7572 NULL, NULL, 0);
7573
7574 info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
7575 ok(info.id, "SetTimer failed\n");
7576 ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
7577 info.handles[0] = CreateEvent(NULL,0,0,NULL);
7578 info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
7579
7580 WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
7581
7582 WaitForSingleObject(info.handles[1], INFINITE);
7583
7584 CloseHandle(info.handles[0]);
7585 CloseHandle(info.handles[1]);
7586
7587 ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
7588
7589 ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
7590 }
7591
7592 static int count = 0;
7593 static VOID CALLBACK callback_count(
7594 HWND hwnd,
7595 UINT uMsg,
7596 UINT_PTR idEvent,
7597 DWORD dwTime
7598 )
7599 {
7600 count++;
7601 }
7602
7603 static void test_timers_no_wnd(void)
7604 {
7605 UINT_PTR id, id2;
7606 MSG msg;
7607
7608 count = 0;
7609 id = SetTimer(NULL, 0, 100, callback_count);
7610 ok(id != 0, "did not get id from SetTimer.\n");
7611 id2 = SetTimer(NULL, id, 200, callback_count);
7612 ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
7613 Sleep(150);
7614 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7615 ok(count == 0, "did not get zero count as expected (%i).\n", count);
7616 Sleep(150);
7617 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7618 ok(count == 1, "did not get one count as expected (%i).\n", count);
7619 KillTimer(NULL, id);
7620 Sleep(250);
7621 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7622 ok(count == 1, "killing replaced timer did not work (%i).\n", count);
7623 }
7624
7625 /* Various win events with arbitrary parameters */
7626 static const struct message WmWinEventsSeq[] = {
7627 { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7628 { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7629 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7630 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7631 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7632 { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7633 { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7634 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7635 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7636 /* our win event hook ignores OBJID_CURSOR events */
7637 /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
7638 { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
7639 { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
7640 { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
7641 { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
7642 { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7643 { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7644 { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7645 { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7646 { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7647 { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7648 { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7649 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7650 { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7651 { 0 }
7652 };
7653 static const struct message WmWinEventCaretSeq[] = {
7654 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7655 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7656 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
7657 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7658 { 0 }
7659 };
7660 static const struct message WmWinEventCaretSeq_2[] = {
7661 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7662 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7663 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7664 { 0 }
7665 };
7666 static const struct message WmWinEventAlertSeq[] = {
7667 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
7668 { 0 }
7669 };
7670 static const struct message WmWinEventAlertSeq_2[] = {
7671 /* create window in the thread proc */
7672 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
7673 /* our test event */
7674 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
7675 { 0 }
7676 };
7677 static const struct message WmGlobalHookSeq_1[] = {
7678 /* create window in the thread proc */
7679 { HCBT_CREATEWND, hook|lparam, 0, 2 },
7680 /* our test events */
7681 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
7682 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
7683 { 0 }
7684 };
7685 static const struct message WmGlobalHookSeq_2[] = {
7686 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
7687 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
7688 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
7689 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
7690 { 0 }
7691 };
7692
7693 static const struct message WmMouseLLHookSeq[] = {
7694 { WM_MOUSEMOVE, hook },
7695 { WM_LBUTTONUP, hook },
7696 { WM_MOUSEMOVE, hook },
7697 { 0 }
7698 };
7699
7700 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
7701 DWORD event,
7702 HWND hwnd,
7703 LONG object_id,
7704 LONG child_id,
7705 DWORD thread_id,
7706 DWORD event_time)
7707 {
7708 char buf[256];
7709
7710 if (GetClassNameA(hwnd, buf, sizeof(buf)))
7711 {
7712 if (!lstrcmpiA(buf, "TestWindowClass") ||
7713 !lstrcmpiA(buf, "static"))
7714 {
7715 struct recvd_message msg;
7716
7717 msg.hwnd = hwnd;
7718 msg.message = event;
7719 msg.flags = winevent_hook|wparam|lparam;
7720 msg.wParam = object_id;
7721 msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
7722 msg.descr = "WEH_2";
7723 add_message(&msg);
7724 }
7725 }
7726 }
7727
7728 static HHOOK hCBT_global_hook;
7729 static DWORD cbt_global_hook_thread_id;
7730
7731 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
7732 {
7733 HWND hwnd;
7734 char buf[256];
7735
7736 if (nCode == HCBT_SYSCOMMAND)
7737 {
7738 struct recvd_message msg;
7739
7740 msg.hwnd = 0;
7741 msg.message = nCode;
7742 msg.flags = hook|wparam|lparam;
7743 msg.wParam = wParam;
7744 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7745 msg.descr = "CBT_2";
7746 add_message(&msg);
7747
7748 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7749 }
7750 /* WH_MOUSE_LL hook */
7751 if (nCode == HC_ACTION)
7752 {
7753 MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
7754
7755 /* we can't test for real mouse events */
7756 if (mhll->flags & LLMHF_INJECTED)
7757 {
7758 struct recvd_message msg;
7759
7760 memset (&msg, 0, sizeof (msg));
7761 msg.message = wParam;
7762 msg.flags = hook;
7763 msg.descr = "CBT_2";
7764 add_message(&msg);
7765 }
7766 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7767 }
7768
7769 /* Log also SetFocus(0) calls */
7770 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7771
7772 if (GetClassNameA(hwnd, buf, sizeof(buf)))
7773 {
7774 if (!lstrcmpiA(buf, "TestWindowClass") ||
7775 !lstrcmpiA(buf, "static"))
7776 {
7777 struct recvd_message msg;
7778
7779 msg.hwnd = hwnd;
7780 msg.message = nCode;
7781 msg.flags = hook|wparam|lparam;
7782 msg.wParam = wParam;
7783 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7784 msg.descr = "CBT_2";
7785 add_message(&msg);
7786 }
7787 }
7788 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7789 }
7790
7791 static DWORD WINAPI win_event_global_thread_proc(void *param)
7792 {
7793 HWND hwnd;
7794 MSG msg;
7795 HANDLE hevent = *(HANDLE *)param;
7796
7797 assert(pNotifyWinEvent);
7798
7799 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7800 assert(hwnd);
7801 trace("created thread window %p\n", hwnd);
7802
7803 *(HWND *)param = hwnd;
7804
7805 flush_sequence();
7806 /* this event should be received only by our new hook proc,
7807 * an old one does not expect an event from another thread.
7808 */
7809 pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
7810 SetEvent(hevent);
7811
7812 while (GetMessage(&msg, 0, 0, 0))
7813 {
7814 TranslateMessage(&msg);
7815 DispatchMessage(&msg);
7816 }
7817 return 0;
7818 }
7819
7820 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
7821 {
7822 HWND hwnd;
7823 MSG msg;
7824 HANDLE hevent = *(HANDLE *)param;
7825
7826 flush_sequence();
7827 /* these events should be received only by our new hook proc,
7828 * an old one does not expect an event from another thread.
7829 */
7830
7831 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7832 assert(hwnd);
7833 trace("created thread window %p\n", hwnd);
7834
7835 *(HWND *)param = hwnd;
7836
7837 /* Windows doesn't like when a thread plays games with the focus,
7838 that leads to all kinds of misbehaviours and failures to activate
7839 a window. So, better keep next lines commented out.
7840 SetFocus(0);
7841 SetFocus(hwnd);*/
7842
7843 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7844 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7845
7846 SetEvent(hevent);
7847
7848 while (GetMessage(&msg, 0, 0, 0))
7849 {
7850 TranslateMessage(&msg);
7851 DispatchMessage(&msg);
7852 }
7853 return 0;
7854 }
7855
7856 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
7857 {
7858 HWND hwnd;
7859 MSG msg;
7860 HANDLE hevent = *(HANDLE *)param;
7861
7862 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7863 assert(hwnd);
7864 trace("created thread window %p\n", hwnd);
7865
7866 *(HWND *)param = hwnd;
7867
7868 flush_sequence();
7869
7870 /* Windows doesn't like when a thread plays games with the focus,
7871 * that leads to all kinds of misbehaviours and failures to activate
7872 * a window. So, better don't generate a mouse click message below.
7873 */
7874 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
7875 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7876 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
7877
7878 SetEvent(hevent);
7879 while (GetMessage(&msg, 0, 0, 0))
7880 {
7881 TranslateMessage(&msg);
7882 DispatchMessage(&msg);
7883 }
7884 return 0;
7885 }
7886
7887 static void test_winevents(void)
7888 {
7889 BOOL ret;
7890 MSG msg;
7891 HWND hwnd, hwnd2;
7892 UINT i;
7893 HANDLE hthread, hevent;
7894 DWORD tid;
7895 HWINEVENTHOOK hhook;
7896 const struct message *events = WmWinEventsSeq;
7897
7898 hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
7899 WS_OVERLAPPEDWINDOW,
7900 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7901 NULL, NULL, 0);
7902 assert(hwnd);
7903
7904 /****** start of global hook test *************/
7905 hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7906 if (!hCBT_global_hook)
7907 {
7908 ok(DestroyWindow(hwnd), "failed to destroy window\n");
7909 skip( "cannot set global hook\n" );
7910 return;
7911 }
7912
7913 hevent = CreateEventA(NULL, 0, 0, NULL);
7914 assert(hevent);
7915 hwnd2 = hevent;
7916
7917 hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
7918 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7919
7920 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7921
7922 ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
7923
7924 flush_sequence();
7925 /* this one should be received only by old hook proc */
7926 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7927 /* this one should be received only by old hook proc */
7928 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7929
7930 ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
7931
7932 ret = UnhookWindowsHookEx(hCBT_global_hook);
7933 ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
7934
7935 PostThreadMessageA(tid, WM_QUIT, 0, 0);
7936 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7937 CloseHandle(hthread);
7938 CloseHandle(hevent);
7939 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7940 /****** end of global hook test *************/
7941
7942 if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
7943 {
7944 ok(DestroyWindow(hwnd), "failed to destroy window\n");
7945 return;
7946 }
7947
7948 flush_sequence();
7949
7950 if (0)
7951 {
7952 /* this test doesn't pass under Win9x */
7953 /* win2k ignores events with hwnd == 0 */
7954 SetLastError(0xdeadbeef);
7955 pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
7956 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
7957 GetLastError() == 0xdeadbeef, /* Win9x */
7958 "unexpected error %d\n", GetLastError());
7959 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7960 }
7961
7962 for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
7963 pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
7964
7965 ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
7966
7967 /****** start of event filtering test *************/
7968 hhook = pSetWinEventHook(
7969 EVENT_OBJECT_SHOW, /* 0x8002 */
7970 EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
7971 GetModuleHandleA(0), win_event_global_hook_proc,
7972 GetCurrentProcessId(), 0,
7973 WINEVENT_INCONTEXT);
7974 ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7975
7976 hevent = CreateEventA(NULL, 0, 0, NULL);
7977 assert(hevent);
7978 hwnd2 = hevent;
7979
7980 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7981 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7982
7983 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7984
7985 ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
7986
7987 flush_sequence();
7988 /* this one should be received only by old hook proc */
7989 pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7990 pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7991 /* this one should be received only by old hook proc */
7992 pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7993
7994 ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
7995
7996 ret = pUnhookWinEvent(hhook);
7997 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7998
7999 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8000 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8001 CloseHandle(hthread);
8002 CloseHandle(hevent);
8003 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8004 /****** end of event filtering test *************/
8005
8006 /****** start of out of context event test *************/
8007 hhook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0,
8008 win_event_global_hook_proc, GetCurrentProcessId(), 0,
8009 WINEVENT_OUTOFCONTEXT);
8010 ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8011
8012 hevent = CreateEventA(NULL, 0, 0, NULL);
8013 assert(hevent);
8014 hwnd2 = hevent;
8015
8016 flush_sequence();
8017
8018 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8019 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8020
8021 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8022
8023 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8024 /* process pending winevent messages */
8025 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8026 ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
8027
8028 flush_sequence();
8029 /* this one should be received only by old hook proc */
8030 pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8031 pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8032 /* this one should be received only by old hook proc */
8033 pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8034
8035 ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
8036 /* process pending winevent messages */
8037 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8038 ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
8039
8040 ret = pUnhookWinEvent(hhook);
8041 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8042
8043 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8044 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8045 CloseHandle(hthread);
8046 CloseHandle(hevent);
8047 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8048 /****** end of out of context event test *************/
8049
8050 /****** start of MOUSE_LL hook test *************/
8051 hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8052 /* WH_MOUSE_LL is not supported on Win9x platforms */
8053 if (!hCBT_global_hook)
8054 {
8055 win_skip("Skipping WH_MOUSE_LL test on this platform\n");
8056 goto skip_mouse_ll_hook_test;
8057 }
8058
8059 hevent = CreateEventA(NULL, 0, 0, NULL);
8060 assert(hevent);
8061 hwnd2 = hevent;
8062
8063 hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
8064 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8065
8066 while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
8067 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
8068
8069 ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
8070 flush_sequence();
8071
8072 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8073 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8074 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8075
8076 ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
8077
8078 ret = UnhookWindowsHookEx(hCBT_global_hook);
8079 ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8080
8081 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8082 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8083 CloseHandle(hthread);
8084 CloseHandle(hevent);
8085 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8086 /****** end of MOUSE_LL hook test *************/
8087 skip_mouse_ll_hook_test:
8088
8089 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8090 }
8091
8092 static void test_set_hook(void)
8093 {
8094 BOOL ret;
8095 HHOOK hhook;
8096 HWINEVENTHOOK hwinevent_hook;
8097
8098 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
8099 ok(hhook != 0, "local hook does not require hModule set to 0\n");
8100 UnhookWindowsHookEx(hhook);
8101
8102 if (0)
8103 {
8104 /* this test doesn't pass under Win9x: BUG! */
8105 SetLastError(0xdeadbeef);
8106 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
8107 ok(!hhook, "global hook requires hModule != 0\n");
8108 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
8109 }
8110
8111 SetLastError(0xdeadbeef);
8112 hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
8113 ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
8114 ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
8115 GetLastError() == 0xdeadbeef, /* Win9x */
8116 "unexpected error %d\n", GetLastError());
8117
8118 SetLastError(0xdeadbeef);
8119 ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
8120 ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
8121 GetLastError() == 0xdeadbeef, /* Win9x */
8122 "unexpected error %d\n", GetLastError());
8123
8124 if (!pSetWinEventHook || !pUnhookWinEvent) return;
8125
8126 /* even process local incontext hooks require hmodule */
8127 SetLastError(0xdeadbeef);
8128 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8129 GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
8130 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8131 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8132 GetLastError() == 0xdeadbeef, /* Win9x */
8133 "unexpected error %d\n", GetLastError());
8134
8135 /* even thread local incontext hooks require hmodule */
8136 SetLastError(0xdeadbeef);
8137 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8138 GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
8139 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8140 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8141 GetLastError() == 0xdeadbeef, /* Win9x */
8142 "unexpected error %d\n", GetLastError());
8143
8144 if (0)
8145 {
8146 /* these 3 tests don't pass under Win9x */
8147 SetLastError(0xdeadbeef);
8148 hwinevent_hook = pSetWinEventHook(1, 0, 0, win_event_proc,
8149 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8150 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8151 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8152
8153 SetLastError(0xdeadbeef);
8154 hwinevent_hook = pSetWinEventHook(-1, 1, 0, win_event_proc,
8155 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8156 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8157 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8158
8159 SetLastError(0xdeadbeef);
8160 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8161 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
8162 ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
8163 ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
8164 }
8165
8166 SetLastError(0xdeadbeef);
8167 hwinevent_hook = pSetWinEventHook(0, 0, 0, win_event_proc,
8168 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8169 ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8170 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8171 ret = pUnhookWinEvent(hwinevent_hook);
8172 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8173
8174 todo_wine {
8175 /* This call succeeds under win2k SP4, but fails under Wine.
8176 Does win2k test/use passed process id? */
8177 SetLastError(0xdeadbeef);
8178 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8179 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
8180 ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8181 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8182 ret = pUnhookWinEvent(hwinevent_hook);
8183 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8184 }
8185
8186 SetLastError(0xdeadbeef);
8187 ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
8188 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
8189 GetLastError() == 0xdeadbeef, /* Win9x */
8190 "unexpected error %d\n", GetLastError());
8191 }
8192
8193 static const struct message ScrollWindowPaint1[] = {
8194 { WM_PAINT, sent },
8195 { WM_ERASEBKGND, sent|beginpaint },
8196 { WM_GETTEXTLENGTH, sent|optional },
8197 { 0 }
8198 };
8199
8200 static const struct message ScrollWindowPaint2[] = {
8201 { WM_PAINT, sent },
8202 { 0 }
8203 };
8204
8205 static void test_scrollwindowex(void)
8206 {
8207 HWND hwnd, hchild;
8208 RECT rect={0,0,130,130};
8209
8210 hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
8211 WS_VISIBLE|WS_OVERLAPPEDWINDOW,
8212 100, 100, 200, 200, 0, 0, 0, NULL);
8213 ok (hwnd != 0, "Failed to create overlapped window\n");
8214 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
8215 WS_VISIBLE|WS_CAPTION|WS_CHILD,
8216 10, 10, 150, 150, hwnd, 0, 0, NULL);
8217 ok (hchild != 0, "Failed to create child\n");
8218 UpdateWindow(hwnd);
8219 flush_events();
8220 flush_sequence();
8221
8222 /* scroll without the child window */
8223 trace("start scroll\n");
8224 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8225 SW_ERASE|SW_INVALIDATE);
8226 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8227 trace("end scroll\n");
8228 flush_sequence();
8229 flush_events();
8230 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8231 flush_events();
8232 flush_sequence();
8233
8234 /* Now without the SW_ERASE flag */
8235 trace("start scroll\n");
8236 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
8237 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8238 trace("end scroll\n");
8239 flush_sequence();
8240 flush_events();
8241 ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
8242 flush_events();
8243 flush_sequence();
8244
8245 /* now scroll the child window as well */
8246 trace("start scroll\n");
8247 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8248 SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
8249 /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
8250 /* windows sometimes a WM_MOVE */
8251 ok_sequence(WmEmptySeq, "ScrollWindowEx", TRUE);
8252 trace("end scroll\n");
8253 flush_sequence();
8254 flush_events();
8255 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8256 flush_events();
8257 flush_sequence();
8258
8259 /* now scroll with ScrollWindow() */
8260 trace("start scroll with ScrollWindow\n");
8261 ScrollWindow( hwnd, 5, 5, NULL, NULL);
8262 trace("end scroll\n");
8263 flush_sequence();
8264 flush_events();
8265 ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
8266
8267 ok(DestroyWindow(hchild), "failed to destroy window\n");
8268 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8269 flush_sequence();
8270 }
8271
8272 static const struct message destroy_window_with_children[] = {
8273 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8274 { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
8275 { 0x0090, sent|optional },
8276 { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
8277 { 0x0090, sent|optional },
8278 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8279 { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8280 { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8281 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8282 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
8283 { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8284 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8285 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8286 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8287 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8288 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8289 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8290 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8291 { 0 }
8292 };
8293
8294 static void test_DestroyWindow(void)
8295 {
8296 BOOL ret;
8297 HWND parent, child1, child2, child3, child4, test;
8298 UINT_PTR child_id = WND_CHILD_ID + 1;
8299
8300 parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8301 100, 100, 200, 200, 0, 0, 0, NULL);
8302 assert(parent != 0);
8303 child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8304 0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
8305 assert(child1 != 0);
8306 child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8307 0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
8308 assert(child2 != 0);
8309 child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8310 0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
8311 assert(child3 != 0);
8312 child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
8313 0, 0, 50, 50, parent, 0, 0, NULL);
8314 assert(child4 != 0);
8315
8316 /* test owner/parent of child2 */
8317 test = GetParent(child2);
8318 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8319 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8320 if(pGetAncestor) {
8321 test = pGetAncestor(child2, GA_PARENT);
8322 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8323 }
8324 test = GetWindow(child2, GW_OWNER);
8325 ok(!test, "wrong owner %p\n", test);
8326
8327 test = SetParent(child2, parent);
8328 ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
8329
8330 /* test owner/parent of the parent */
8331 test = GetParent(parent);
8332 ok(!test, "wrong parent %p\n", test);
8333 ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
8334 if(pGetAncestor) {
8335 test = pGetAncestor(parent, GA_PARENT);
8336 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8337 }
8338 test = GetWindow(parent, GW_OWNER);
8339 ok(!test, "wrong owner %p\n", test);
8340
8341 /* test owner/parent of child1 */
8342 test = GetParent(child1);
8343 ok(test == parent, "wrong parent %p\n", test);
8344 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
8345 if(pGetAncestor) {
8346 test = pGetAncestor(child1, GA_PARENT);
8347 ok(test == parent, "wrong parent %p\n", test);
8348 }
8349 test = GetWindow(child1, GW_OWNER);
8350 ok(!test, "wrong owner %p\n", test);
8351
8352 /* test owner/parent of child2 */
8353 test = GetParent(child2);
8354 ok(test == parent, "wrong parent %p\n", test);
8355 ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8356 if(pGetAncestor) {
8357 test = pGetAncestor(child2, GA_PARENT);
8358 ok(test == parent, "wrong parent %p\n", test);
8359 }
8360 test = GetWindow(child2, GW_OWNER);
8361 ok(!test, "wrong owner %p\n", test);
8362
8363 /* test owner/parent of child3 */
8364 test = GetParent(child3);
8365 ok(test == child1, "wrong parent %p\n", test);
8366 ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
8367 if(pGetAncestor) {
8368 test = pGetAncestor(child3, GA_PARENT);
8369 ok(test == child1, "wrong parent %p\n", test);
8370 }
8371 test = GetWindow(child3, GW_OWNER);
8372 ok(!test, "wrong owner %p\n", test);
8373
8374 /* test owner/parent of child4 */
8375 test = GetParent(child4);
8376 ok(test == parent, "wrong parent %p\n", test);
8377 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
8378 if(pGetAncestor) {
8379 test = pGetAncestor(child4, GA_PARENT);
8380 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8381 }
8382 test = GetWindow(child4, GW_OWNER);
8383 ok(test == parent, "wrong owner %p\n", test);
8384
8385 flush_sequence();
8386
8387 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
8388 parent, child1, child2, child3, child4);
8389
8390 SetCapture(child4);
8391 test = GetCapture();
8392 ok(test == child4, "wrong capture window %p\n", test);
8393
8394 test_DestroyWindow_flag = TRUE;
8395 ret = DestroyWindow(parent);
8396 ok( ret, "DestroyWindow() error %d\n", GetLastError());
8397 test_DestroyWindow_flag = FALSE;
8398 ok_sequence(destroy_window_with_children, "destroy window with children", 0);
8399
8400 ok(!IsWindow(parent), "parent still exists\n");
8401 ok(!IsWindow(child1), "child1 still exists\n");
8402 ok(!IsWindow(child2), "child2 still exists\n");
8403 ok(!IsWindow(child3), "child3 still exists\n");
8404 ok(!IsWindow(child4), "child4 still exists\n");
8405
8406 test = GetCapture();
8407 ok(!test, "wrong capture window %p\n", test);
8408 }
8409
8410
8411 static const struct message WmDispatchPaint[] = {
8412 { WM_NCPAINT, sent },
8413 { WM_GETTEXT, sent|defwinproc|optional },
8414 { WM_GETTEXT, sent|defwinproc|optional },
8415 { WM_ERASEBKGND, sent },
8416 { 0 }
8417 };
8418
8419 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8420 {
8421 if (message == WM_PAINT) return 0;
8422 return MsgCheckProcA( hwnd, message, wParam, lParam );
8423 }
8424
8425 static void test_DispatchMessage(void)
8426 {
8427 RECT rect;
8428 MSG msg;
8429 int count;
8430 HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8431 100, 100, 200, 200, 0, 0, 0, NULL);
8432 ShowWindow( hwnd, SW_SHOW );
8433 UpdateWindow( hwnd );
8434 flush_events();
8435 flush_sequence();
8436 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
8437
8438 SetRect( &rect, -5, -5, 5, 5 );
8439 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8440 count = 0;
8441 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8442 {
8443 if (msg.message != WM_PAINT) DispatchMessage( &msg );
8444 else
8445 {
8446 flush_sequence();
8447 DispatchMessage( &msg );
8448 /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
8449 if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8450 else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
8451 if (++count > 10) break;
8452 }
8453 }
8454 ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
8455
8456 trace("now without DispatchMessage\n");
8457 flush_sequence();
8458 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8459 count = 0;
8460 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8461 {
8462 if (msg.message != WM_PAINT) DispatchMessage( &msg );
8463 else
8464 {
8465 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
8466 flush_sequence();
8467 /* this will send WM_NCCPAINT just like DispatchMessage does */
8468 GetUpdateRgn( hwnd, hrgn, TRUE );
8469 ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8470 DeleteObject( hrgn );
8471 GetClientRect( hwnd, &rect );
8472 ValidateRect( hwnd, &rect ); /* this will stop WM_PAINTs */
8473 ok( !count, "Got multiple WM_PAINTs\n" );
8474 if (++count > 10) break;
8475 }
8476 }
8477 DestroyWindow(hwnd);
8478 }
8479
8480
8481 static const struct message WmUser[] = {
8482 { WM_USER, sent },
8483 { 0 }
8484 };
8485
8486 struct sendmsg_info
8487 {
8488 HWND hwnd;
8489 DWORD timeout;
8490 DWORD ret;
8491 };
8492
8493 static DWORD CALLBACK send_msg_thread( LPVOID arg )
8494 {
8495 struct sendmsg_info *info = arg;
8496 SetLastError( 0xdeadbeef );
8497 info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
8498 if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT ||
8499 broken(GetLastError() == 0), /* win9x */
8500 "unexpected error %d\n", GetLastError());
8501 return 0;
8502 }
8503
8504 static void wait_for_thread( HANDLE thread )
8505 {
8506 while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
8507 {
8508 MSG msg;
8509 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
8510 }
8511 }
8512
8513 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8514 {
8515 if (message == WM_USER) Sleep(200);
8516 return MsgCheckProcA( hwnd, message, wParam, lParam );
8517 }
8518
8519 static void test_SendMessageTimeout(void)
8520 {
8521 HANDLE thread;
8522 struct sendmsg_info info;
8523 DWORD tid;
8524 BOOL is_win9x;
8525
8526 info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8527 100, 100, 200, 200, 0, 0, 0, NULL);
8528 flush_events();
8529 flush_sequence();
8530
8531 info.timeout = 1000;
8532 info.ret = 0xdeadbeef;
8533 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8534 wait_for_thread( thread );
8535 CloseHandle( thread );
8536 ok( info.ret == 1, "SendMessageTimeout failed\n" );
8537 ok_sequence( WmUser, "WmUser", FALSE );
8538
8539 info.timeout = 1;
8540 info.ret = 0xdeadbeef;
8541 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8542 Sleep(100); /* SendMessageTimeout should time out here */
8543 wait_for_thread( thread );
8544 CloseHandle( thread );
8545 ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8546 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8547
8548 /* 0 means infinite timeout (but not on win9x) */
8549 info.timeout = 0;
8550 info.ret = 0xdeadbeef;
8551 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8552 Sleep(100);
8553 wait_for_thread( thread );
8554 CloseHandle( thread );
8555 is_win9x = !info.ret;
8556 if (is_win9x) ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8557 else ok_sequence( WmUser, "WmUser", FALSE );
8558
8559 /* timeout is treated as signed despite the prototype (but not on win9x) */
8560 info.timeout = 0x7fffffff;
8561 info.ret = 0xdeadbeef;
8562 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8563 Sleep(100);
8564 wait_for_thread( thread );
8565 CloseHandle( thread );
8566 ok( info.ret == 1, "SendMessageTimeout failed\n" );
8567 ok_sequence( WmUser, "WmUser", FALSE );
8568
8569 info.timeout = 0x80000000;
8570 info.ret = 0xdeadbeef;
8571 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8572 Sleep(100);
8573 wait_for_thread( thread );
8574 CloseHandle( thread );
8575 if (is_win9x)
8576 {
8577 ok( info.ret == 1, "SendMessageTimeout failed\n" );
8578 ok_sequence( WmUser, "WmUser", FALSE );
8579 }
8580 else
8581 {
8582 ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8583 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8584 }
8585
8586 /* now check for timeout during message processing */
8587 SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
8588 info.timeout = 100;
8589 info.ret = 0xdeadbeef;
8590 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8591 wait_for_thread( thread );
8592 CloseHandle( thread );
8593 /* we should time out but still get the message */
8594 ok( info.ret == 0, "SendMessageTimeout failed\n" );
8595 ok_sequence( WmUser, "WmUser", FALSE );
8596
8597 DestroyWindow( info.hwnd );
8598 }
8599
8600
8601 /****************** edit message test *************************/
8602 #define ID_EDIT 0x1234
8603 static const struct message sl_edit_setfocus[] =
8604 {
8605 { HCBT_SETFOCUS, hook },
8606 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8607 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8608 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8609 { WM_SETFOCUS, sent|wparam, 0 },
8610 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8611 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
8612 { WM_CTLCOLOREDIT, sent|parent },
8613 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8614 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8615 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8616 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8617 { 0 }
8618 };
8619 static const struct message ml_edit_setfocus[] =
8620 {
8621 { HCBT_SETFOCUS, hook },
8622 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8623 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8624 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8625 { WM_SETFOCUS, sent|wparam, 0 },
8626 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8627 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8628 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8629 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8630 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8631 { 0 }
8632 };
8633 static const struct message sl_edit_killfocus[] =
8634 {
8635 { HCBT_SETFOCUS, hook },
8636 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8637 { WM_KILLFOCUS, sent|wparam, 0 },
8638 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8639 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8640 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
8641 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
8642 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
8643 { 0 }
8644 };
8645 static const struct message sl_edit_lbutton_dblclk[] =
8646 {
8647 { WM_LBUTTONDBLCLK, sent },
8648 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8649 { 0 }
8650 };
8651 static const struct message sl_edit_lbutton_down[] =
8652 {
8653 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8654 { HCBT_SETFOCUS, hook },
8655 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8656 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8657 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8658 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8659 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8660 { WM_CTLCOLOREDIT, sent|parent },
8661 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8662 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8663 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8664 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8665 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8666 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8667 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8668 { WM_CTLCOLOREDIT, sent|parent|optional },
8669 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8670 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8671 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8672 { 0 }
8673 };
8674 static const struct message ml_edit_lbutton_down[] =
8675 {
8676 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8677 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8678 { HCBT_SETFOCUS, hook },
8679 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8680 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8681 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8682 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8683 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8684 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8685 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8686 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8687 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8688 { 0 }
8689 };
8690 static const struct message sl_edit_lbutton_up[] =
8691 {
8692 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8693 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8694 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8695 { WM_CAPTURECHANGED, sent|defwinproc },
8696 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8697 { 0 }
8698 };
8699 static const struct message ml_edit_lbutton_up[] =
8700 {
8701 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8702 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8703 { WM_CAPTURECHANGED, sent|defwinproc },
8704 { 0 }
8705 };
8706
8707 static WNDPROC old_edit_proc;
8708
8709 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8710 {
8711 static long defwndproc_counter = 0;
8712 LRESULT ret;
8713 struct recvd_message msg;
8714
8715 if (message == WM_GETICON || message == WM_GETOBJECT) return 0; /* ignore them */
8716
8717 msg.hwnd = hwnd;
8718 msg.message = message;
8719 msg.flags = sent|wparam|lparam;
8720 if (defwndproc_counter) msg.flags |= defwinproc;
8721 msg.wParam = wParam;
8722 msg.lParam = lParam;
8723 msg.descr = "edit";
8724 add_message(&msg);
8725
8726 defwndproc_counter++;
8727 ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
8728 defwndproc_counter--;
8729
8730 return ret;
8731 }
8732
8733 static void subclass_edit(void)
8734 {
8735 WNDCLASSA cls;
8736
8737 if (!GetClassInfoA(0, "edit", &cls)) assert(0);
8738
8739 old_edit_proc = cls.lpfnWndProc;
8740
8741 cls.hInstance = GetModuleHandle(0);
8742 cls.lpfnWndProc = edit_hook_proc;
8743 cls.lpszClassName = "my_edit_class";
8744 UnregisterClass(cls.lpszClassName, cls.hInstance);
8745 if (!RegisterClassA(&cls)) assert(0);
8746 }
8747
8748 static void test_edit_messages(void)
8749 {
8750 HWND hwnd, parent;
8751 DWORD dlg_code;
8752
8753 subclass_edit();
8754 log_all_parent_messages++;
8755
8756 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8757 100, 100, 200, 200, 0, 0, 0, NULL);
8758 ok (parent != 0, "Failed to create parent window\n");
8759
8760 /* test single line edit */
8761 hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
8762 0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8763 ok(hwnd != 0, "Failed to create edit window\n");
8764
8765 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8766 ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
8767
8768 ShowWindow(hwnd, SW_SHOW);
8769 UpdateWindow(hwnd);
8770 SetFocus(0);
8771 flush_sequence();
8772
8773 SetFocus(hwnd);
8774 ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
8775
8776 SetFocus(0);
8777 ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
8778
8779 SetFocus(0);
8780 ReleaseCapture();
8781 flush_sequence();
8782
8783 SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8784 ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
8785
8786 SetFocus(0);
8787 ReleaseCapture();
8788 flush_sequence();
8789
8790 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8791 ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
8792
8793 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8794 ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
8795
8796 DestroyWindow(hwnd);
8797
8798 /* test multiline edit */
8799 hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
8800 0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8801 ok(hwnd != 0, "Failed to create edit window\n");
8802
8803 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8804 ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
8805 "wrong dlg_code %08x\n", dlg_code);
8806
8807 ShowWindow(hwnd, SW_SHOW);
8808 UpdateWindow(hwnd);
8809 SetFocus(0);
8810 flush_sequence();
8811
8812 SetFocus(hwnd);
8813 ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
8814
8815 SetFocus(0);
8816 ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
8817
8818 SetFocus(0);
8819 ReleaseCapture();
8820 flush_sequence();
8821
8822 SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8823 ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
8824
8825 SetFocus(0);
8826 ReleaseCapture();
8827 flush_sequence();
8828
8829 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8830 ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
8831
8832 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8833 ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
8834
8835 DestroyWindow(hwnd);
8836 DestroyWindow(parent);
8837
8838 log_all_parent_messages--;
8839 }
8840
8841 /**************************** End of Edit test ******************************/
8842
8843 static const struct message WmKeyDownSkippedSeq[] =
8844 {
8845 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
8846 { 0 }
8847 };
8848 static const struct message WmKeyDownWasDownSkippedSeq[] =
8849 {
8850 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x40000001 }, /* XP */
8851 { 0 }
8852 };
8853 static const struct message WmKeyUpSkippedSeq[] =
8854 {
8855 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8856 { 0 }
8857 };
8858 static const struct message WmUserKeyUpSkippedSeq[] =
8859 {
8860 { WM_USER, sent },
8861 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8862 { 0 }
8863 };
8864
8865 #define EV_STOP 0
8866 #define EV_SENDMSG 1
8867 #define EV_ACK 2
8868
8869 struct peekmsg_info
8870 {
8871 HWND hwnd;
8872 HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
8873 };
8874
8875 static DWORD CALLBACK send_msg_thread_2(void *param)
8876 {
8877 DWORD ret;
8878 struct peekmsg_info *info = param;
8879
8880 trace("thread: looping\n");
8881 SetEvent(info->hevent[EV_ACK]);
8882
8883 while (1)
8884 {
8885 ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
8886
8887 switch (ret)
8888 {
8889 case WAIT_OBJECT_0 + EV_STOP:
8890 trace("thread: exiting\n");
8891 return 0;
8892
8893 case WAIT_OBJECT_0 + EV_SENDMSG:
8894 trace("thread: sending message\n");
8895 ok( SendNotifyMessageA(info->hwnd, WM_USER, 0, 0),
8896 "SendNotifyMessageA failed error %u\n", GetLastError());
8897 SetEvent(info->hevent[EV_ACK]);
8898 break;
8899
8900 default:
8901 trace("unexpected return: %04x\n", ret);
8902 assert(0);
8903 break;
8904 }
8905 }
8906 return 0;
8907 }
8908
8909 static void test_PeekMessage(void)
8910 {
8911 MSG msg;
8912 HANDLE hthread;
8913 DWORD tid, qstatus;
8914 UINT qs_all_input = QS_ALLINPUT;
8915 UINT qs_input = QS_INPUT;
8916 BOOL ret;
8917 struct peekmsg_info info;
8918
8919 info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8920 100, 100, 200, 200, 0, 0, 0, NULL);
8921 assert(info.hwnd);
8922 ShowWindow(info.hwnd, SW_SHOW);
8923 UpdateWindow(info.hwnd);
8924 SetFocus(info.hwnd);
8925
8926 info.hevent[EV_STOP] = CreateEventA(NULL, 0, 0, NULL);
8927 info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
8928 info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
8929
8930 hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
8931 WaitForSingleObject(info.hevent[EV_ACK], 10000);
8932
8933 flush_events();
8934 flush_sequence();
8935
8936 SetLastError(0xdeadbeef);
8937 qstatus = GetQueueStatus(qs_all_input);
8938 if (GetLastError() == ERROR_INVALID_FLAGS)
8939 {
8940 trace("QS_RAWINPUT not supported on this platform\n");
8941 qs_all_input &= ~QS_RAWINPUT;
8942 qs_input &= ~QS_RAWINPUT;
8943 }
8944 if (qstatus & QS_POSTMESSAGE)
8945 {
8946 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) /* nothing */ ;
8947 qstatus = GetQueueStatus(qs_all_input);
8948 }
8949 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8950
8951 trace("signalling to send message\n");
8952 SetEvent(info.hevent[EV_SENDMSG]);
8953 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8954
8955 /* pass invalid QS_xxxx flags */
8956 SetLastError(0xdeadbeef);
8957 qstatus = GetQueueStatus(0xffffffff);
8958 ok(qstatus == 0 || broken(qstatus) /* win9x */, "GetQueueStatus should fail: %08x\n", qstatus);
8959 if (!qstatus)
8960 {
8961 ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
8962 qstatus = GetQueueStatus(qs_all_input);
8963 }
8964 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
8965 "wrong qstatus %08x\n", qstatus);
8966
8967 msg.message = 0;
8968 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8969 ok(!ret,
8970 "PeekMessageA should have returned FALSE instead of msg %04x\n",
8971 msg.message);
8972 ok_sequence(WmUser, "WmUser", FALSE);
8973
8974 qstatus = GetQueueStatus(qs_all_input);
8975 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8976
8977 keybd_event('N', 0, 0, 0);
8978 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
8979 qstatus = GetQueueStatus(qs_all_input);
8980 if (!(qstatus & MAKELONG(QS_KEY, QS_KEY)))
8981 {
8982 skip( "queuing key events not supported\n" );
8983 goto done;
8984 }
8985 ok(qstatus == MAKELONG(QS_KEY, QS_KEY),
8986 "wrong qstatus %08x\n", qstatus);
8987
8988 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8989 qstatus = GetQueueStatus(qs_all_input);
8990 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
8991 "wrong qstatus %08x\n", qstatus);
8992
8993 InvalidateRect(info.hwnd, NULL, FALSE);
8994 qstatus = GetQueueStatus(qs_all_input);
8995 ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8996 "wrong qstatus %08x\n", qstatus);
8997
8998 trace("signalling to send message\n");
8999 SetEvent(info.hevent[EV_SENDMSG]);
9000 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9001
9002 qstatus = GetQueueStatus(qs_all_input);
9003 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9004 "wrong qstatus %08x\n", qstatus);
9005
9006 msg.message = 0;
9007 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
9008 if (ret && msg.message == WM_CHAR)
9009 {
9010 win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9011 goto done;
9012 }
9013 ok(!ret,
9014 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9015 msg.message);
9016 if (!sequence_cnt) /* nt4 doesn't fetch anything with PM_QS_* flags */
9017 {
9018 win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9019 goto done;
9020 }
9021 ok_sequence(WmUser, "WmUser", FALSE);
9022
9023 qstatus = GetQueueStatus(qs_all_input);
9024 ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9025 "wrong qstatus %08x\n", qstatus);
9026
9027 trace("signalling to send message\n");
9028 SetEvent(info.hevent[EV_SENDMSG]);
9029 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9030
9031 qstatus = GetQueueStatus(qs_all_input);
9032 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9033 "wrong qstatus %08x\n", qstatus);
9034
9035 msg.message = 0;
9036 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE );
9037 ok(!ret,
9038 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9039 msg.message);
9040 ok_sequence(WmUser, "WmUser", FALSE);
9041
9042 qstatus = GetQueueStatus(qs_all_input);
9043 ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9044 "wrong qstatus %08x\n", qstatus);
9045
9046 msg.message = 0;
9047 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9048 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9049 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9050 ret, msg.message, msg.wParam);
9051 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9052
9053 qstatus = GetQueueStatus(qs_all_input);
9054 ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9055 "wrong qstatus %08x\n", qstatus);
9056
9057 msg.message = 0;
9058 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9059 ok(!ret,
9060 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9061 msg.message);
9062 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9063
9064 qstatus = GetQueueStatus(qs_all_input);
9065 ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9066 "wrong qstatus %08x\n", qstatus);
9067
9068 msg.message = 0;
9069 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9070 ok(ret && msg.message == WM_PAINT,
9071 "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
9072 DispatchMessageA(&msg);
9073 ok_sequence(WmPaint, "WmPaint", FALSE);
9074
9075 qstatus = GetQueueStatus(qs_all_input);
9076 ok(qstatus == MAKELONG(0, QS_KEY),
9077 "wrong qstatus %08x\n", qstatus);
9078
9079 msg.message = 0;
9080 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9081 ok(!ret,
9082 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9083 msg.message);
9084 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9085
9086 qstatus = GetQueueStatus(qs_all_input);
9087 ok(qstatus == MAKELONG(0, QS_KEY),
9088 "wrong qstatus %08x\n", qstatus);
9089
9090 trace("signalling to send message\n");
9091 SetEvent(info.hevent[EV_SENDMSG]);
9092 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9093
9094 qstatus = GetQueueStatus(qs_all_input);
9095 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
9096 "wrong qstatus %08x\n", qstatus);
9097
9098 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9099
9100 qstatus = GetQueueStatus(qs_all_input);
9101 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9102 "wrong qstatus %08x\n", qstatus);
9103
9104 msg.message = 0;
9105 ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9106 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9107 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9108 ret, msg.message, msg.wParam);
9109 ok_sequence(WmUser, "WmUser", FALSE);
9110
9111 qstatus = GetQueueStatus(qs_all_input);
9112 ok(qstatus == MAKELONG(0, QS_KEY),
9113 "wrong qstatus %08x\n", qstatus);
9114
9115 msg.message = 0;
9116 ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9117 ok(!ret,
9118 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9119 msg.message);
9120 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9121
9122 qstatus = GetQueueStatus(qs_all_input);
9123 ok(qstatus == MAKELONG(0, QS_KEY),
9124 "wrong qstatus %08x\n", qstatus);
9125
9126 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9127
9128 qstatus = GetQueueStatus(qs_all_input);
9129 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9130 "wrong qstatus %08x\n", qstatus);
9131
9132 trace("signalling to send message\n");
9133 SetEvent(info.hevent[EV_SENDMSG]);
9134 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9135
9136 qstatus = GetQueueStatus(qs_all_input);
9137 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9138 "wrong qstatus %08x\n", qstatus);
9139
9140 msg.message = 0;
9141 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
9142 ok(!ret,
9143 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9144 msg.message);
9145 ok_sequence(WmUser, "WmUser", FALSE);
9146
9147 qstatus = GetQueueStatus(qs_all_input);
9148 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9149 "wrong qstatus %08x\n", qstatus);
9150
9151 msg.message = 0;
9152 if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9153 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9154 else /* workaround for a missing QS_RAWINPUT support */
9155 ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
9156 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9157 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9158 ret, msg.message, msg.wParam);
9159 ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9160
9161 qstatus = GetQueueStatus(qs_all_input);
9162 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9163 "wrong qstatus %08x\n", qstatus);
9164
9165 msg.message = 0;
9166 if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9167 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9168 else /* workaround for a missing QS_RAWINPUT support */
9169 ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
9170 ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9171 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
9172 ret, msg.message, msg.wParam);
9173 ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
9174
9175 qstatus = GetQueueStatus(qs_all_input);
9176 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9177 "wrong qstatus %08x\n", qstatus);
9178
9179 msg.message = 0;
9180 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
9181 ok(!ret,
9182 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9183 msg.message);
9184 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9185
9186 qstatus = GetQueueStatus(qs_all_input);
9187 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9188 "wrong qstatus %08x\n", qstatus);
9189
9190 msg.message = 0;
9191 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9192 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9193 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9194 ret, msg.message, msg.wParam);
9195 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9196
9197 qstatus = GetQueueStatus(qs_all_input);
9198 ok(qstatus == 0,
9199 "wrong qstatus %08x\n", qstatus);
9200
9201 msg.message = 0;
9202 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9203 ok(!ret,
9204 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9205 msg.message);
9206 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9207
9208 qstatus = GetQueueStatus(qs_all_input);
9209 ok(qstatus == 0,
9210 "wrong qstatus %08x\n", qstatus);
9211
9212 /* test whether presence of the quit flag in the queue affects
9213 * the queue state
9214 */
9215 PostQuitMessage(0x1234abcd);
9216
9217 qstatus = GetQueueStatus(qs_all_input);
9218 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9219 "wrong qstatus %08x\n", qstatus);
9220
9221 PostMessageA(info.hwnd, WM_USER, 0, 0);
9222
9223 qstatus = GetQueueStatus(qs_all_input);
9224 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9225 "wrong qstatus %08x\n", qstatus);
9226
9227 msg.message = 0;
9228 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9229 ok(ret && msg.message == WM_USER,
9230 "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
9231 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9232
9233 qstatus = GetQueueStatus(qs_all_input);
9234 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9235 "wrong qstatus %08x\n", qstatus);
9236
9237 msg.message = 0;
9238 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9239 ok(ret && msg.message == WM_QUIT,
9240 "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
9241 ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
9242 ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
9243 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9244
9245 qstatus = GetQueueStatus(qs_all_input);
9246 todo_wine {
9247 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9248 "wrong qstatus %08x\n", qstatus);
9249 }
9250
9251 msg.message = 0;
9252 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9253 ok(!ret,
9254 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9255 msg.message);
9256 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9257
9258 qstatus = GetQueueStatus(qs_all_input);
9259 ok(qstatus == 0,
9260 "wrong qstatus %08x\n", qstatus);
9261
9262 /* some GetMessage tests */
9263
9264 keybd_event('N', 0, 0, 0);
9265 qstatus = GetQueueStatus(qs_all_input);
9266 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9267
9268 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9269 qstatus = GetQueueStatus(qs_all_input);
9270 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9271
9272 if (qstatus)
9273 {
9274 ret = GetMessageA( &msg, 0, 0, 0 );
9275 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9276 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9277 ret, msg.message, msg.wParam);
9278 qstatus = GetQueueStatus(qs_all_input);
9279 ok(qstatus == MAKELONG(0, QS_KEY), "wrong qstatus %08x\n", qstatus);
9280 }
9281
9282 if (qstatus)
9283 {
9284 ret = GetMessageA( &msg, 0, 0, 0 );
9285 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9286 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9287 ret, msg.message, msg.wParam);
9288 ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9289 qstatus = GetQueueStatus(qs_all_input);
9290 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9291 }
9292
9293 keybd_event('N', 0, 0, 0);
9294 qstatus = GetQueueStatus(qs_all_input);
9295 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9296
9297 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9298 qstatus = GetQueueStatus(qs_all_input);
9299 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9300
9301 if (qstatus & (QS_KEY << 16))
9302 {
9303 ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9304 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9305 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9306 ret, msg.message, msg.wParam);
9307 ok_sequence(WmKeyDownWasDownSkippedSeq, "WmKeyDownWasDownSkippedSeq", FALSE);
9308 qstatus = GetQueueStatus(qs_all_input);
9309 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9310 }
9311
9312 if (qstatus)
9313 {
9314 ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9315 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9316 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9317 ret, msg.message, msg.wParam);
9318 qstatus = GetQueueStatus(qs_all_input);
9319 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9320 }
9321
9322 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9323 qstatus = GetQueueStatus(qs_all_input);
9324 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9325
9326 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9327 qstatus = GetQueueStatus(qs_all_input);
9328 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9329
9330 trace("signalling to send message\n");
9331 SetEvent(info.hevent[EV_SENDMSG]);
9332 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9333 qstatus = GetQueueStatus(qs_all_input);
9334 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9335 "wrong qstatus %08x\n", qstatus);
9336
9337 if (qstatus & (QS_KEY << 16))
9338 {
9339 ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9340 ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9341 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9342 ret, msg.message, msg.wParam);
9343 ok_sequence(WmUserKeyUpSkippedSeq, "WmUserKeyUpSkippedSeq", FALSE);
9344 qstatus = GetQueueStatus(qs_all_input);
9345 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9346 }
9347
9348 if (qstatus)
9349 {
9350 ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9351 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9352 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9353 ret, msg.message, msg.wParam);
9354 qstatus = GetQueueStatus(qs_all_input);
9355 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9356 }
9357 done:
9358 trace("signalling to exit\n");
9359 SetEvent(info.hevent[EV_STOP]);
9360
9361 WaitForSingleObject(hthread, INFINITE);
9362
9363 CloseHandle(hthread);
9364 CloseHandle(info.hevent[0]);
9365 CloseHandle(info.hevent[1]);
9366 CloseHandle(info.hevent[2]);
9367
9368 DestroyWindow(info.hwnd);
9369 }
9370
9371 static void wait_move_event(HWND hwnd, int x, int y)
9372 {
9373 MSG msg;
9374 DWORD time;
9375 BOOL ret;
9376 int go = 0;
9377
9378 time = GetTickCount();
9379 while (GetTickCount() - time < 200 && !go) {
9380 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9381 go = ret && msg.pt.x > x && msg.pt.y > y;
9382 if (!ret) MsgWaitForMultipleObjects( 0, NULL, FALSE, GetTickCount() - time, QS_ALLINPUT );
9383 }
9384 }
9385
9386 #define STEP 5
9387 static void test_PeekMessage2(void)
9388 {
9389 HWND hwnd;
9390 BOOL ret;
9391 MSG msg;
9392 UINT message;
9393 DWORD time1, time2, time3;
9394 int x1, y1, x2, y2, x3, y3;
9395 POINT pos;
9396
9397 time1 = time2 = time3 = 0;
9398 x1 = y1 = x2 = y2 = x3 = y3 = 0;
9399
9400 /* Initialise window and make sure it is ready for events */
9401 hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
9402 10, 10, 800, 800, NULL, NULL, NULL, NULL);
9403 assert(hwnd);
9404 trace("Window for test_PeekMessage2 %p\n", hwnd);
9405 ShowWindow(hwnd, SW_SHOW);
9406 UpdateWindow(hwnd);
9407 SetFocus(hwnd);
9408 GetCursorPos(&pos);
9409 SetCursorPos(100, 100);
9410 mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
9411 flush_events();
9412
9413 /* Do initial mousemove, wait until we can see it
9414 and then do our test peek with PM_NOREMOVE. */
9415 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9416 wait_move_event(hwnd, 100-STEP, 100-STEP);
9417
9418 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9419 if (!ret)
9420 {
9421 skip( "queuing mouse events not supported\n" );
9422 goto done;
9423 }
9424 else
9425 {
9426 trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9427 message = msg.message;
9428 time1 = msg.time;
9429 x1 = msg.pt.x;
9430 y1 = msg.pt.y;
9431 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9432 }
9433
9434 /* Allow time to advance a bit, and then simulate the user moving their
9435 * mouse around. After that we peek again with PM_NOREMOVE.
9436 * Although the previous mousemove message was never removed, the
9437 * mousemove we now peek should reflect the recent mouse movements
9438 * because the input queue will merge the move events. */
9439 Sleep(100);
9440 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9441 wait_move_event(hwnd, x1, y1);
9442
9443 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9444 ok(ret, "no message available\n");
9445 if (ret) {
9446 trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9447 message = msg.message;
9448 time2 = msg.time;
9449 x2 = msg.pt.x;
9450 y2 = msg.pt.y;
9451 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9452 ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
9453 ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
9454 }
9455
9456 /* Have another go, to drive the point home */
9457 Sleep(100);
9458 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9459 wait_move_event(hwnd, x2, y2);
9460
9461 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9462 ok(ret, "no message available\n");
9463 if (ret) {
9464 trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9465 message = msg.message;
9466 time3 = msg.time;
9467 x3 = msg.pt.x;
9468 y3 = msg.pt.y;
9469 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9470 ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
9471 ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
9472 }
9473
9474 done:
9475 DestroyWindow(hwnd);
9476 SetCursorPos(pos.x, pos.y);
9477 flush_events();
9478 }
9479
9480 static void test_quit_message(void)
9481 {
9482 MSG msg;
9483 BOOL ret;
9484
9485 /* test using PostQuitMessage */
9486 flush_events();
9487 PostQuitMessage(0xbeef);
9488
9489 ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9490 ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9491 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9492 ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9493
9494 ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9495 ok(ret, "PostMessage failed with error %d\n", GetLastError());
9496
9497 ret = GetMessage(&msg, NULL, 0, 0);
9498 ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9499 ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9500
9501 /* note: WM_QUIT message received after WM_USER message */
9502 ret = GetMessage(&msg, NULL, 0, 0);
9503 ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9504 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9505 ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9506
9507 ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
9508 ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
9509
9510 /* now test with PostThreadMessage - different behaviour! */
9511 PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
9512
9513 ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9514 ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9515 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9516 ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9517
9518 ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9519 ok(ret, "PostMessage failed with error %d\n", GetLastError());
9520
9521 /* note: we receive the WM_QUIT message first this time */
9522 ret = GetMessage(&msg, NULL, 0, 0);
9523 ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9524 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9525 ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9526
9527 ret = GetMessage(&msg, NULL, 0, 0);
9528 ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9529 ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9530 }
9531
9532 static const struct message WmMouseHoverSeq[] = {
9533 { WM_MOUSEACTIVATE, sent|optional }, /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
9534 { WM_MOUSEACTIVATE, sent|optional },
9535 { WM_TIMER, sent|optional }, /* XP sends it */
9536 { WM_SYSTIMER, sent },
9537 { WM_MOUSEHOVER, sent|wparam, 0 },
9538 { 0 }
9539 };
9540
9541 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
9542 {
9543 MSG msg;
9544 DWORD start_ticks, end_ticks;
9545
9546 start_ticks = GetTickCount();
9547 /* add some deviation (50%) to cover not expected delays */
9548 start_ticks += timeout / 2;
9549
9550 do
9551 {
9552 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
9553 {
9554 /* Timer proc messages are not dispatched to the window proc,
9555 * and therefore not logged.
9556 */
9557 if (msg.message == WM_TIMER || msg.message == WM_SYSTIMER)
9558 {
9559 struct recvd_message s_msg;
9560
9561 s_msg.hwnd = msg.hwnd;
9562 s_msg.message = msg.message;
9563 s_msg.flags = sent|wparam|lparam;
9564 s_msg.wParam = msg.wParam;
9565 s_msg.lParam = msg.lParam;
9566 s_msg.descr = "msg_loop";
9567 add_message(&s_msg);
9568 }
9569 DispatchMessage(&msg);
9570 }
9571
9572 end_ticks = GetTickCount();
9573
9574 /* inject WM_MOUSEMOVE to see how it changes tracking */
9575 if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
9576 {
9577 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9578 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9579
9580 inject_mouse_move = FALSE;
9581 }
9582 } while (start_ticks + timeout >= end_ticks);
9583 }
9584
9585 static void test_TrackMouseEvent(void)
9586 {
9587 TRACKMOUSEEVENT tme;
9588 BOOL ret;
9589 HWND hwnd, hchild;
9590 RECT rc_parent, rc_child;
9591 UINT default_hover_time, hover_width = 0, hover_height = 0;
9592
9593 #define track_hover(track_hwnd, track_hover_time) \
9594 tme.cbSize = sizeof(tme); \
9595 tme.dwFlags = TME_HOVER; \
9596 tme.hwndTrack = track_hwnd; \
9597 tme.dwHoverTime = track_hover_time; \
9598 SetLastError(0xdeadbeef); \
9599 ret = pTrackMouseEvent(&tme); \
9600 ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
9601
9602 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
9603 tme.cbSize = sizeof(tme); \
9604 tme.dwFlags = TME_QUERY; \
9605 tme.hwndTrack = (HWND)0xdeadbeef; \
9606 tme.dwHoverTime = 0xdeadbeef; \
9607 SetLastError(0xdeadbeef); \
9608 ret = pTrackMouseEvent(&tme); \
9609 ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
9610 ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
9611 ok(tme.dwFlags == (expected_track_flags), \
9612 "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
9613 ok(tme.hwndTrack == (expected_track_hwnd), \
9614 "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
9615 ok(tme.dwHoverTime == (expected_hover_time), \
9616 "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
9617
9618 #define track_hover_cancel(track_hwnd) \
9619 tme.cbSize = sizeof(tme); \
9620 tme.dwFlags = TME_HOVER | TME_CANCEL; \
9621 tme.hwndTrack = track_hwnd; \
9622 tme.dwHoverTime = 0xdeadbeef; \
9623 SetLastError(0xdeadbeef); \
9624 ret = pTrackMouseEvent(&tme); \
9625 ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
9626
9627 default_hover_time = 0xdeadbeef;
9628 SetLastError(0xdeadbeef);
9629 ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
9630 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
9631 "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
9632 if (!ret) default_hover_time = 400;
9633 trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
9634
9635 SetLastError(0xdeadbeef);
9636 ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
9637 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
9638 "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
9639 if (!ret) hover_width = 4;
9640 SetLastError(0xdeadbeef);
9641 ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
9642 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
9643 "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
9644 if (!ret) hover_height = 4;
9645 trace("hover rect is %u x %d\n", hover_width, hover_height);
9646
9647 hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
9648 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9649 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
9650 NULL, NULL, 0);
9651 assert(hwnd);
9652
9653 hchild = CreateWindowEx(0, "TestWindowClass", NULL,
9654 WS_CHILD | WS_BORDER | WS_VISIBLE,
9655 50, 50, 200, 200, hwnd,
9656 NULL, NULL, 0);
9657 assert(hchild);
9658
9659 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
9660 flush_events();
9661 flush_sequence();
9662
9663 tme.cbSize = 0;
9664 tme.dwFlags = TME_QUERY;
9665 tme.hwndTrack = (HWND)0xdeadbeef;
9666 tme.dwHoverTime = 0xdeadbeef;
9667 SetLastError(0xdeadbeef);
9668 ret = pTrackMouseEvent(&tme);
9669 ok(!ret, "TrackMouseEvent should fail\n");
9670 ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef),
9671 "not expected error %u\n", GetLastError());
9672
9673 tme.cbSize = sizeof(tme);
9674 tme.dwFlags = TME_HOVER;
9675 tme.hwndTrack = (HWND)0xdeadbeef;
9676 tme.dwHoverTime = 0xdeadbeef;
9677 SetLastError(0xdeadbeef);
9678 ret = pTrackMouseEvent(&tme);
9679 ok(!ret, "TrackMouseEvent should fail\n");
9680 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
9681 "not expected error %u\n", GetLastError());
9682
9683 tme.cbSize = sizeof(tme);
9684 tme.dwFlags = TME_HOVER | TME_CANCEL;
9685 tme.hwndTrack = (HWND)0xdeadbeef;
9686 tme.dwHoverTime = 0xdeadbeef;
9687 SetLastError(0xdeadbeef);
9688 ret = pTrackMouseEvent(&tme);
9689 ok(!ret, "TrackMouseEvent should fail\n");
9690 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
9691 "not expected error %u\n", GetLastError());
9692
9693 GetWindowRect(hwnd, &rc_parent);
9694 GetWindowRect(hchild, &rc_child);
9695 SetCursorPos(rc_child.left - 10, rc_child.top - 10);
9696
9697 /* Process messages so that the system updates its internal current
9698 * window and hittest, otherwise TrackMouseEvent calls don't have any
9699 * effect.
9700 */
9701 flush_events();
9702 flush_sequence();
9703
9704 track_query(0, NULL, 0);
9705 track_hover(hchild, 0);
9706 track_query(0, NULL, 0);
9707
9708 flush_events();
9709 flush_sequence();
9710
9711 track_hover(hwnd, 0);
9712 tme.cbSize = sizeof(tme);
9713 tme.dwFlags = TME_QUERY;
9714 tme.hwndTrack = (HWND)0xdeadbeef;
9715 tme.dwHoverTime = 0xdeadbeef;
9716 SetLastError(0xdeadbeef);
9717 ret = pTrackMouseEvent(&tme);
9718 ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());
9719 ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize);
9720 if (!tme.dwFlags)
9721 {
9722 skip( "Cursor not inside window, skipping TrackMouseEvent tests\n" );
9723 DestroyWindow( hwnd );
9724 return;
9725 }
9726 ok(tme.dwFlags == TME_HOVER, "wrong tme.dwFlags %08x, expected TME_HOVER\n", tme.dwFlags);
9727 ok(tme.hwndTrack == hwnd, "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, hwnd);
9728 ok(tme.dwHoverTime == default_hover_time, "wrong tme.dwHoverTime %u, expected %u\n",
9729 tme.dwHoverTime, default_hover_time);
9730
9731 pump_msg_loop_timeout(default_hover_time, FALSE);
9732 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9733
9734 track_query(0, NULL, 0);
9735
9736 track_hover(hwnd, HOVER_DEFAULT);
9737 track_query(TME_HOVER, hwnd, default_hover_time);
9738
9739 Sleep(default_hover_time / 2);
9740 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9741 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9742
9743 track_query(TME_HOVER, hwnd, default_hover_time);
9744
9745 pump_msg_loop_timeout(default_hover_time, FALSE);
9746 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9747
9748 track_query(0, NULL, 0);
9749
9750 track_hover(hwnd, HOVER_DEFAULT);
9751 track_query(TME_HOVER, hwnd, default_hover_time);
9752
9753 pump_msg_loop_timeout(default_hover_time, TRUE);
9754 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9755
9756 track_query(0, NULL, 0);
9757
9758 track_hover(hwnd, HOVER_DEFAULT);
9759 track_query(TME_HOVER, hwnd, default_hover_time);
9760 track_hover_cancel(hwnd);
9761
9762 DestroyWindow(hwnd);
9763
9764 #undef track_hover
9765 #undef track_query
9766 #undef track_hover_cancel
9767 }
9768
9769
9770 static const struct message WmSetWindowRgn[] = {
9771 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9772 { WM_NCCALCSIZE, sent|wparam, 1 },
9773 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
9774 { WM_GETTEXT, sent|defwinproc|optional },
9775 { WM_ERASEBKGND, sent|optional },
9776 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9777 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9778 { 0 }
9779 };
9780
9781 static const struct message WmSetWindowRgn_no_redraw[] = {
9782 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9783 { WM_NCCALCSIZE, sent|wparam, 1 },
9784 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9785 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9786 { 0 }
9787 };
9788
9789 static const struct message WmSetWindowRgn_clear[] = {
9790 { WM_WINDOWPOSCHANGING, sent/*|wparam*/, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE/*|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE only on some Windows versions */ },
9791 { WM_NCCALCSIZE, sent|wparam, 1 },
9792 { WM_NCPAINT, sent|optional },
9793 { WM_GETTEXT, sent|defwinproc|optional },
9794 { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
9795 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9796 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
9797 { WM_NCPAINT, sent|optional },
9798 { WM_GETTEXT, sent|defwinproc|optional },
9799 { WM_ERASEBKGND, sent|optional },
9800 { WM_WINDOWPOSCHANGING, sent|optional },
9801 { WM_NCCALCSIZE, sent|optional|wparam, 1 },
9802 { WM_NCPAINT, sent|optional },
9803 { WM_GETTEXT, sent|defwinproc|optional },
9804 { WM_ERASEBKGND, sent|optional },
9805 { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9806 { WM_NCCALCSIZE, sent|optional|wparam, 1 },
9807 { WM_NCPAINT, sent|optional },
9808 { WM_GETTEXT, sent|defwinproc|optional },
9809 { WM_ERASEBKGND, sent|optional },
9810 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9811 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9812 { 0 }
9813 };
9814
9815 static void test_SetWindowRgn(void)
9816 {
9817 HRGN hrgn;
9818 HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
9819 100, 100, 200, 200, 0, 0, 0, NULL);
9820 ok( hwnd != 0, "Failed to create overlapped window\n" );
9821
9822 ShowWindow( hwnd, SW_SHOW );
9823 UpdateWindow( hwnd );
9824 flush_events();
9825 flush_sequence();
9826
9827 trace("testing SetWindowRgn\n");
9828 hrgn = CreateRectRgn( 0, 0, 150, 150 );
9829 SetWindowRgn( hwnd, hrgn, TRUE );
9830 ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
9831
9832 hrgn = CreateRectRgn( 30, 30, 160, 160 );
9833 SetWindowRgn( hwnd, hrgn, FALSE );
9834 ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
9835
9836 hrgn = CreateRectRgn( 0, 0, 180, 180 );
9837 SetWindowRgn( hwnd, hrgn, TRUE );
9838 ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
9839
9840 SetWindowRgn( hwnd, 0, TRUE );
9841 ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
9842
9843 DestroyWindow( hwnd );
9844 }
9845
9846 /*************************** ShowWindow() test ******************************/
9847 static const struct message WmShowNormal[] = {
9848 { WM_SHOWWINDOW, sent|wparam, 1 },
9849 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9850 { HCBT_ACTIVATE, hook },
9851 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9852 { HCBT_SETFOCUS, hook },
9853 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9854 { 0 }
9855 };
9856 static const struct message WmShow[] = {
9857 { WM_SHOWWINDOW, sent|wparam, 1 },
9858 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9859 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9860 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9861 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9862 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9863 { 0 }
9864 };
9865 static const struct message WmShowNoActivate_1[] = {
9866 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9867 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9868 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9869 { WM_MOVE, sent|defwinproc|optional },
9870 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9871 { 0 }
9872 };
9873 static const struct message WmShowNoActivate_2[] = {
9874 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9875 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9876 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9877 { WM_MOVE, sent|defwinproc },
9878 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9879 { HCBT_SETFOCUS, hook|optional },
9880 { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9881 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9882 { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9883 { 0 }
9884 };
9885 static const struct message WmShowNA_1[] = {
9886 { WM_SHOWWINDOW, sent|wparam, 1 },
9887 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9888 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9889 { 0 }
9890 };
9891 static const struct message WmShowNA_2[] = {
9892 { WM_SHOWWINDOW, sent|wparam, 1 },
9893 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9894 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9895 { 0 }
9896 };
9897 static const struct message WmRestore_1[] = {
9898 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9899 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9900 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9901 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9902 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9903 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9904 { WM_MOVE, sent|defwinproc },
9905 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9906 { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9907 { 0 }
9908 };
9909 static const struct message WmRestore_2[] = {
9910 { WM_SHOWWINDOW, sent|wparam, 1 },
9911 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9912 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9913 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9914 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9915 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9916 { 0 }
9917 };
9918 static const struct message WmRestore_3[] = {
9919 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9920 { WM_GETMINMAXINFO, sent },
9921 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9922 { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9923 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9924 { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9925 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9926 { WM_MOVE, sent|defwinproc },
9927 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9928 { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9929 { 0 }
9930 };
9931 static const struct message WmRestore_4[] = {
9932 { HCBT_MINMAX, hook|lparam|optional, 0, SW_RESTORE },
9933 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9934 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9935 { WM_MOVE, sent|defwinproc|optional },
9936 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
9937 { 0 }
9938 };
9939 static const struct message WmRestore_5[] = {
9940 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
9941 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9942 { HCBT_ACTIVATE, hook|optional },
9943 { HCBT_SETFOCUS, hook|optional },
9944 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9945 { WM_MOVE, sent|defwinproc|optional },
9946 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9947 { 0 }
9948 };
9949 static const struct message WmHide_1[] = {
9950 { WM_SHOWWINDOW, sent|wparam, 0 },
9951 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9952 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9953 { HCBT_ACTIVATE, hook|optional },
9954 { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9955 { 0 }
9956 };
9957 static const struct message WmHide_2[] = {
9958 { WM_SHOWWINDOW, sent|wparam, 0 },
9959 { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9960 { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9961 { HCBT_ACTIVATE, hook|optional },
9962 { 0 }
9963 };
9964 static const struct message WmHide_3[] = {
9965 { WM_SHOWWINDOW, sent|wparam, 0 },
9966 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9967 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9968 { HCBT_SETFOCUS, hook|optional },
9969 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9970 { 0 }
9971 };
9972 static const struct message WmShowMinimized_1[] = {
9973 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9974 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9975 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9976 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9977 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9978 { WM_MOVE, sent|defwinproc },
9979 { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9980 { 0 }
9981 };
9982 static const struct message WmMinimize_1[] = {
9983 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9984 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9985 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9986 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9987 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9988 { WM_MOVE, sent|defwinproc },
9989 { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9990 { 0 }
9991 };
9992 static const struct message WmMinimize_2[] = {
9993 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9994 { HCBT_SETFOCUS, hook|optional },
9995 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9996 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9997 { WM_MOVE, sent|defwinproc },
9998 { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9999 { 0 }
10000 };
10001 static const struct message WmMinimize_3[] = {
10002 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10003 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10004 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10005 { WM_MOVE, sent|defwinproc },
10006 { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
10007 { 0 }
10008 };
10009 static const struct message WmShowMinNoActivate[] = {
10010 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10011 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10012 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10013 { 0 }
10014 };
10015 static const struct message WmMinMax_1[] = {
10016 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10017 { 0 }
10018 };
10019 static const struct message WmMinMax_2[] = {
10020 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10021 { WM_GETMINMAXINFO, sent|optional },
10022 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED },
10023 { HCBT_ACTIVATE, hook|optional },
10024 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10025 { HCBT_SETFOCUS, hook|optional },
10026 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10027 { WM_MOVE, sent|defwinproc|optional },
10028 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MAXIMIZED },
10029 { HCBT_SETFOCUS, hook|optional },
10030 { 0 }
10031 };
10032 static const struct message WmMinMax_3[] = {
10033 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10034 { HCBT_SETFOCUS, hook|optional },
10035 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10036 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10037 { WM_MOVE, sent|defwinproc|optional },
10038 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10039 { 0 }
10040 };
10041 static const struct message WmMinMax_4[] = {
10042 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10043 { 0 }
10044 };
10045 static const struct message WmShowMaximized_1[] = {
10046 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10047 { WM_GETMINMAXINFO, sent },
10048 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10049 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10050 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10051 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10052 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10053 { WM_MOVE, sent|defwinproc },
10054 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10055 { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10056 { 0 }
10057 };
10058 static const struct message WmShowMaximized_2[] = {
10059 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10060 { WM_GETMINMAXINFO, sent },
10061 { WM_WINDOWPOSCHANGING, sent|optional },
10062 { HCBT_ACTIVATE, hook|optional },
10063 { WM_WINDOWPOSCHANGED, sent|optional },
10064 { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
10065 { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
10066 { WM_WINDOWPOSCHANGING, sent|optional },
10067 { HCBT_SETFOCUS, hook|optional },
10068 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10069 { WM_MOVE, sent|defwinproc },
10070 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10071 { HCBT_SETFOCUS, hook|optional },
10072 { 0 }
10073 };
10074 static const struct message WmShowMaximized_3[] = {
10075 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10076 { WM_GETMINMAXINFO, sent },
10077 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10078 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10079 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10080 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10081 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10082 { WM_MOVE, sent|defwinproc|optional },
10083 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10084 { 0 }
10085 };
10086
10087 static void test_ShowWindow(void)
10088 {
10089 /* ShowWindow commands in random order */
10090 static const struct
10091 {
10092 INT cmd; /* ShowWindow command */
10093 LPARAM ret; /* ShowWindow return value */
10094 DWORD style; /* window style after the command */
10095 const struct message *msg; /* message sequence the command produces */
10096 BOOL todo_msg; /* message sequence doesn't match what Wine does */
10097 } sw[] =
10098 {
10099 /* 1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
10100 /* 2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10101 /* 3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10102 /* 4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10103 /* 5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
10104 /* 6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
10105 /* 7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
10106 /* 8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10107 /* 9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
10108 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10109 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
10110 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
10111 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
10112 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10113 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
10114 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10115 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
10116 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10117 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10118 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10119 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10120 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
10121 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
10122 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10123 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10124 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
10125 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
10126 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10127 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10128 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
10129 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10130 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, FALSE },
10131 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10132 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE }, /* what does this mean?! */
10133 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE },
10134 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10135 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
10136 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10137 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10138 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, FALSE },
10139 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10140 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, FALSE },
10141 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10142 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10143 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10144 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
10145 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
10146 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
10147 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
10148 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
10149 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10150 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10151 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10152 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, FALSE },
10153 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10154 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
10155 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
10156 };
10157 HWND hwnd;
10158 DWORD style;
10159 LPARAM ret;
10160 INT i;
10161
10162 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
10163 hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
10164 120, 120, 90, 90,
10165 0, 0, 0, NULL);
10166 assert(hwnd);
10167
10168 style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10169 ok(style == 0, "expected style 0, got %08x\n", style);
10170
10171 flush_events();
10172 flush_sequence();
10173
10174 for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
10175 {
10176 static const char * const sw_cmd_name[13] =
10177 {
10178 "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
10179 "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
10180 "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
10181 "SW_NORMALNA" /* 0xCC */
10182 };
10183 char comment[64];
10184 INT idx; /* index into the above array of names */
10185
10186 idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
10187
10188 style = GetWindowLong(hwnd, GWL_STYLE);
10189 trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
10190 ret = ShowWindow(hwnd, sw[i].cmd);
10191 ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
10192 style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10193 ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
10194
10195 sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
10196 ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
10197
10198 flush_events();
10199 flush_sequence();
10200 }
10201
10202 DestroyWindow(hwnd);
10203 }
10204
10205 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
10206 {
10207 struct recvd_message msg;
10208
10209 switch (message)
10210 {
10211 case WM_GETICON:
10212 case WM_GETOBJECT:
10213 return 0; /* ignore them */
10214 }
10215
10216 msg.hwnd = hwnd;
10217 msg.message = message;
10218 msg.flags = sent|wparam|lparam;
10219 msg.wParam = wParam;
10220 msg.lParam = lParam;
10221 msg.descr = "dialog";
10222 add_message(&msg);
10223
10224 /* calling DefDlgProc leads to a recursion under XP */
10225
10226 switch (message)
10227 {
10228 case WM_INITDIALOG:
10229 case WM_GETDLGCODE:
10230 return 0;
10231 }
10232 return 1;
10233 }
10234
10235 static const struct message WmDefDlgSetFocus_1[] = {
10236 { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10237 { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10238 { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10239 { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10240 { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10241 { HCBT_SETFOCUS, hook },
10242 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
10243 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10244 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10245 { WM_SETFOCUS, sent|wparam, 0 },
10246 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
10247 { WM_CTLCOLOREDIT, sent },
10248 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
10249 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10250 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10251 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10252 { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
10253 { 0 }
10254 };
10255 static const struct message WmDefDlgSetFocus_2[] = {
10256 { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10257 { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10258 { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10259 { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10260 { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10261 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10262 { WM_CTLCOLOREDIT, sent|optional }, /* XP */
10263 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10264 { 0 }
10265 };
10266 /* Creation of a dialog */
10267 static const struct message WmCreateDialogParamSeq_1[] = {
10268 { HCBT_CREATEWND, hook },
10269 { WM_NCCREATE, sent },
10270 { WM_NCCALCSIZE, sent|wparam, 0 },
10271 { WM_CREATE, sent },
10272 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10273 { WM_SIZE, sent|wparam, SIZE_RESTORED },
10274 { WM_MOVE, sent },
10275 { WM_SETFONT, sent },
10276 { WM_INITDIALOG, sent },
10277 { WM_CHANGEUISTATE, sent|optional },
10278 { 0 }
10279 };
10280 /* Creation of a dialog */
10281 static const struct message WmCreateDialogParamSeq_2[] = {
10282 { HCBT_CREATEWND, hook },
10283 { WM_NCCREATE, sent },
10284 { WM_NCCALCSIZE, sent|wparam, 0 },
10285 { WM_CREATE, sent },
10286 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10287 { WM_SIZE, sent|wparam, SIZE_RESTORED },
10288 { WM_MOVE, sent },
10289 { WM_CHANGEUISTATE, sent|optional },
10290 { 0 }
10291 };
10292
10293 static void test_dialog_messages(void)
10294 {
10295 WNDCLASS cls;
10296 HWND hdlg, hedit1, hedit2, hfocus;
10297 LRESULT ret;
10298
10299 #define set_selection(hctl, start, end) \
10300 ret = SendMessage(hctl, EM_SETSEL, start, end); \
10301 ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
10302
10303 #define check_selection(hctl, start, end) \
10304 ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
10305 ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
10306
10307 subclass_edit();
10308
10309 hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
10310 WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
10311 0, 0, 100, 100, 0, 0, 0, NULL);
10312 ok(hdlg != 0, "Failed to create custom dialog window\n");
10313
10314 hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
10315 WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10316 0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
10317 ok(hedit1 != 0, "Failed to create edit control\n");
10318 hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
10319 WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10320 0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
10321 ok(hedit2 != 0, "Failed to create edit control\n");
10322
10323 SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
10324 SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
10325
10326 hfocus = GetFocus();
10327 ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
10328
10329 SetFocus(hedit2);
10330 hfocus = GetFocus();
10331 ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
10332
10333 check_selection(hedit1, 0, 0);
10334 check_selection(hedit2, 0, 0);
10335
10336 set_selection(hedit2, 0, -1);
10337 check_selection(hedit2, 0, 3);
10338
10339 SetFocus(0);
10340 hfocus = GetFocus();
10341 ok(hfocus == 0, "wrong focus %p\n", hfocus);
10342
10343 flush_sequence();
10344 ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10345 ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10346 ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
10347
10348 hfocus = GetFocus();
10349 ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10350
10351 check_selection(hedit1, 0, 5);
10352 check_selection(hedit2, 0, 3);
10353
10354 flush_sequence();
10355 ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10356 ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10357 ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
10358
10359 hfocus = GetFocus();
10360 ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10361
10362 check_selection(hedit1, 0, 5);
10363 check_selection(hedit2, 0, 3);
10364
10365 EndDialog(hdlg, 0);
10366 DestroyWindow(hedit1);
10367 DestroyWindow(hedit2);
10368 DestroyWindow(hdlg);
10369 flush_sequence();
10370
10371 #undef set_selection
10372 #undef check_selection
10373
10374 ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
10375 cls.lpszClassName = "MyDialogClass";
10376 cls.hInstance = GetModuleHandle(0);
10377 /* need a cast since a dlgproc is used as a wndproc */
10378 cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
10379 if (!RegisterClass(&cls)) assert(0);
10380
10381 hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
10382 ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10383 ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
10384 EndDialog(hdlg, 0);
10385 DestroyWindow(hdlg);
10386 flush_sequence();
10387
10388 hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
10389 ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10390 ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
10391 EndDialog(hdlg, 0);
10392 DestroyWindow(hdlg);
10393 flush_sequence();
10394
10395 UnregisterClass(cls.lpszClassName, cls.hInstance);
10396 }
10397
10398 static void test_nullCallback(void)
10399 {
10400 HWND hwnd;
10401
10402 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10403 100, 100, 200, 200, 0, 0, 0, NULL);
10404 ok (hwnd != 0, "Failed to create overlapped window\n");
10405
10406 SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
10407 flush_events();
10408 DestroyWindow(hwnd);
10409 }
10410
10411 /* SetActiveWindow( 0 ) hwnd visible */
10412 static const struct message SetActiveWindowSeq0[] =
10413 {
10414 { HCBT_ACTIVATE, hook|optional },
10415 { WM_NCACTIVATE, sent|wparam, 0 },
10416 { WM_GETTEXT, sent|defwinproc|optional },
10417 { WM_ACTIVATE, sent|wparam, 0 },
10418 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
10419 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
10420 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10421 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10422 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10423 { WM_NCACTIVATE, sent|wparam|optional, 1 },
10424 { WM_GETTEXT, sent|defwinproc|optional },
10425 { WM_ACTIVATE, sent|wparam|optional, 1 },
10426 { HCBT_SETFOCUS, hook|optional },
10427 { WM_KILLFOCUS, sent|defwinproc },
10428 { WM_IME_SETCONTEXT, sent|defwinproc|optional },
10429 { WM_IME_SETCONTEXT, sent|defwinproc|optional },
10430 { WM_IME_SETCONTEXT, sent|defwinproc|optional },
10431 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10432 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10433 { WM_SETFOCUS, sent|defwinproc|optional },
10434 { WM_GETTEXT, sent|optional },
10435 { 0 }
10436 };
10437 /* SetActiveWindow( hwnd ) hwnd visible */
10438 static const struct message SetActiveWindowSeq1[] =
10439 {
10440 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10441 { 0 }
10442 };
10443 /* SetActiveWindow( popup ) hwnd visible, popup visible */
10444 static const struct message SetActiveWindowSeq2[] =
10445 {
10446 { HCBT_ACTIVATE, hook },
10447 { WM_NCACTIVATE, sent|wparam, 0 },
10448 { WM_GETTEXT, sent|defwinproc|optional },
10449 { WM_ACTIVATE, sent|wparam, 0 },
10450 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10451 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10452 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10453 { WM_NCPAINT, sent|optional },
10454 { WM_GETTEXT, sent|defwinproc|optional },
10455 { WM_ERASEBKGND, sent|optional },
10456 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10457 { WM_NCACTIVATE, sent|wparam, 1 },
10458 { WM_GETTEXT, sent|defwinproc|optional },
10459 { WM_ACTIVATE, sent|wparam, 1 },
10460 { HCBT_SETFOCUS, hook },
10461 { WM_KILLFOCUS, sent|defwinproc },
10462 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10463 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10464 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10465 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10466 { WM_SETFOCUS, sent|defwinproc },
10467 { WM_GETTEXT, sent|optional },
10468 { 0 }
10469 };
10470
10471 /* SetActiveWindow( hwnd ) hwnd not visible */
10472 static const struct message SetActiveWindowSeq3[] =
10473 {
10474 { HCBT_ACTIVATE, hook },
10475 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10476 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10477 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10478 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10479 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10480 { WM_ACTIVATEAPP, sent|wparam, 1 },
10481 { WM_ACTIVATEAPP, sent|wparam, 1 },
10482 { WM_NCACTIVATE, sent|wparam, 1 },
10483 { WM_ACTIVATE, sent|wparam, 1 },
10484 { HCBT_SETFOCUS, hook },
10485 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10486 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10487 { WM_SETFOCUS, sent|defwinproc },
10488 { 0 }
10489 };
10490 /* SetActiveWindow( popup ) hwnd not visible, popup not visible */
10491 static const struct message SetActiveWindowSeq4[] =
10492 {
10493 { HCBT_ACTIVATE, hook },
10494 { WM_NCACTIVATE, sent|wparam, 0 },
10495 { WM_GETTEXT, sent|defwinproc|optional },
10496 { WM_ACTIVATE, sent|wparam, 0 },
10497 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10498 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10499 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10500 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10501 { WM_NCACTIVATE, sent|wparam, 1 },
10502 { WM_GETTEXT, sent|defwinproc|optional },
10503 { WM_ACTIVATE, sent|wparam, 1 },
10504 { HCBT_SETFOCUS, hook },
10505 { WM_KILLFOCUS, sent|defwinproc },
10506 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10507 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10508 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10509 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10510 { WM_SETFOCUS, sent|defwinproc },
10511 { 0 }
10512 };
10513
10514
10515 static void test_SetActiveWindow(void)
10516 {
10517 HWND hwnd, popup, ret;
10518
10519 hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10520 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10521 100, 100, 200, 200, 0, 0, 0, NULL);
10522
10523 popup = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10524 WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_POPUP,
10525 100, 100, 200, 200, hwnd, 0, 0, NULL);
10526
10527 ok(hwnd != 0, "Failed to create overlapped window\n");
10528 ok(popup != 0, "Failed to create popup window\n");
10529 SetForegroundWindow( popup );
10530 flush_sequence();
10531
10532 trace("SetActiveWindow(0)\n");
10533 ret = SetActiveWindow(0);
10534 ok( ret == popup, "Failed to SetActiveWindow(0)\n");
10535 ok_sequence(SetActiveWindowSeq0, "SetActiveWindow(0)", TRUE);
10536 flush_sequence();
10537
10538 trace("SetActiveWindow(hwnd), hwnd visible\n");
10539 ret = SetActiveWindow(hwnd);
10540 if (ret == hwnd) ok_sequence(SetActiveWindowSeq1, "SetActiveWindow(hwnd), hwnd visible", TRUE);
10541 flush_sequence();
10542
10543 trace("SetActiveWindow(popup), hwnd visible, popup visible\n");
10544 ret = SetActiveWindow(popup);
10545 ok( ret == hwnd, "Failed to SetActiveWindow(popup), popup visible\n");
10546 ok_sequence(SetActiveWindowSeq2, "SetActiveWindow(popup), hwnd visible, popup visible", FALSE);
10547 flush_sequence();
10548
10549 ShowWindow(hwnd, SW_HIDE);
10550 ShowWindow(popup, SW_HIDE);
10551 flush_sequence();
10552
10553 trace("SetActiveWindow(hwnd), hwnd not visible\n");
10554 ret = SetActiveWindow(hwnd);
10555 ok( ret == NULL, "SetActiveWindow(hwnd), hwnd not visible, previous is %p\n", ret );
10556 ok_sequence(SetActiveWindowSeq3, "SetActiveWindow(hwnd), hwnd not visible", TRUE);
10557 flush_sequence();
10558
10559 trace("SetActiveWindow(popup), hwnd not visible, popup not visible\n");
10560 ret = SetActiveWindow(popup);
10561 ok( ret == hwnd, "Failed to SetActiveWindow(popup)\n");
10562 ok_sequence(SetActiveWindowSeq4, "SetActiveWindow(popup), hwnd not visible, popup not visible", TRUE);
10563 flush_sequence();
10564
10565 trace("done\n");
10566
10567 DestroyWindow(hwnd);
10568 }
10569
10570 static const struct message SetForegroundWindowSeq[] =
10571 {
10572 { WM_NCACTIVATE, sent|wparam, 0 },
10573 { WM_GETTEXT, sent|defwinproc|optional },
10574 { WM_ACTIVATE, sent|wparam, 0 },
10575 { WM_ACTIVATEAPP, sent|wparam, 0 },
10576 { WM_KILLFOCUS, sent },
10577 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
10578 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
10579 { 0 }
10580 };
10581
10582 static void test_SetForegroundWindow(void)
10583 {
10584 HWND hwnd;
10585
10586 hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
10587 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10588 100, 100, 200, 200, 0, 0, 0, NULL);
10589 ok (hwnd != 0, "Failed to create overlapped window\n");
10590 SetForegroundWindow( hwnd );
10591 flush_sequence();
10592
10593 trace("SetForegroundWindow( 0 )\n");
10594 SetForegroundWindow( 0 );
10595 ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
10596 trace("SetForegroundWindow( GetDesktopWindow() )\n");
10597 SetForegroundWindow( GetDesktopWindow() );
10598 ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
10599 "foreground top level window", FALSE);
10600 trace("done\n");
10601
10602 DestroyWindow(hwnd);
10603 }
10604
10605 static void test_dbcs_wm_char(void)
10606 {
10607 BYTE dbch[2];
10608 WCHAR wch, bad_wch;
10609 HWND hwnd, hwnd2;
10610 MSG msg;
10611 DWORD time;
10612 POINT pt;
10613 DWORD_PTR res;
10614 CPINFOEXA cpinfo;
10615 UINT i, j, k;
10616 struct message wmCharSeq[2];
10617
10618 if (!pGetCPInfoExA)
10619 {
10620 win_skip("GetCPInfoExA is not available\n");
10621 return;
10622 }
10623
10624 pGetCPInfoExA( CP_ACP, 0, &cpinfo );
10625 if (cpinfo.MaxCharSize != 2)
10626 {
10627 skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
10628 return;
10629 }
10630
10631 dbch[0] = dbch[1] = 0;
10632 wch = 0;
10633 bad_wch = cpinfo.UnicodeDefaultChar;
10634 for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
10635 for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
10636 for (k = 128; k <= 255; k++)
10637 {
10638 char str[2];
10639 WCHAR wstr[2];
10640 str[0] = j;
10641 str[1] = k;
10642 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
10643 WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
10644 (BYTE)str[0] == j && (BYTE)str[1] == k &&
10645 HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
10646 {
10647 dbch[0] = j;
10648 dbch[1] = k;
10649 wch = wstr[0];
10650 break;
10651 }
10652 }
10653
10654 if (!wch)
10655 {
10656 skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
10657 return;
10658 }
10659 trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
10660 dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
10661
10662 hwnd = CreateWindowExW(0, testWindowClassW, NULL,
10663 WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
10664 hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
10665 WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
10666 ok (hwnd != 0, "Failed to create overlapped window\n");
10667 ok (hwnd2 != 0, "Failed to create overlapped window\n");
10668 flush_sequence();
10669
10670 memset( wmCharSeq, 0, sizeof(wmCharSeq) );
10671 wmCharSeq[0].message = WM_CHAR;
10672 wmCharSeq[0].flags = sent|wparam;
10673 wmCharSeq[0].wParam = wch;
10674
10675 /* posted message */
10676 PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10677 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10678 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10679 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10680 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10681 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10682 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10683
10684 /* posted thread message */
10685 PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
10686 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10687 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10688 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10689 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10690 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10691 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10692
10693 /* sent message */
10694 flush_sequence();
10695 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10696 ok_sequence( WmEmptySeq, "no messages", FALSE );
10697 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10698 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10699 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10700
10701 /* sent message with timeout */
10702 flush_sequence();
10703 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10704 ok_sequence( WmEmptySeq, "no messages", FALSE );
10705 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10706 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10707 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10708
10709 /* sent message with timeout and callback */
10710 flush_sequence();
10711 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10712 ok_sequence( WmEmptySeq, "no messages", FALSE );
10713 SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10714 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10715 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10716
10717 /* sent message with callback */
10718 flush_sequence();
10719 SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10720 ok_sequence( WmEmptySeq, "no messages", FALSE );
10721 SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10722 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10723 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10724
10725 /* direct window proc call */
10726 flush_sequence();
10727 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10728 ok_sequence( WmEmptySeq, "no messages", FALSE );
10729 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10730 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10731
10732 /* dispatch message */
10733 msg.hwnd = hwnd;
10734 msg.message = WM_CHAR;
10735 msg.wParam = dbch[0];
10736 msg.lParam = 0;
10737 DispatchMessageA( &msg );
10738 ok_sequence( WmEmptySeq, "no messages", FALSE );
10739 msg.wParam = dbch[1];
10740 DispatchMessageA( &msg );
10741 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10742
10743 /* window handle is irrelevant */
10744 flush_sequence();
10745 SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10746 ok_sequence( WmEmptySeq, "no messages", FALSE );
10747 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10748 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10749 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10750
10751 /* interleaved post and send */
10752 flush_sequence();
10753 PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10754 SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10755 ok_sequence( WmEmptySeq, "no messages", FALSE );
10756 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10757 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10758 ok_sequence( WmEmptySeq, "no messages", FALSE );
10759 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10760 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10761 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10762 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10763 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10764 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10765 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10766
10767 /* interleaved sent message and winproc */
10768 flush_sequence();
10769 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10770 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10771 ok_sequence( WmEmptySeq, "no messages", FALSE );
10772 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10773 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10774 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10775 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10776
10777 /* interleaved winproc and dispatch */
10778 msg.hwnd = hwnd;
10779 msg.message = WM_CHAR;
10780 msg.wParam = dbch[0];
10781 msg.lParam = 0;
10782 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10783 DispatchMessageA( &msg );
10784 ok_sequence( WmEmptySeq, "no messages", FALSE );
10785 msg.wParam = dbch[1];
10786 DispatchMessageA( &msg );
10787 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10788 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10789 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10790
10791 /* interleaved sends */
10792 flush_sequence();
10793 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10794 SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
10795 ok_sequence( WmEmptySeq, "no messages", FALSE );
10796 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10797 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10798 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10799 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10800
10801 /* dbcs WM_CHAR */
10802 flush_sequence();
10803 SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
10804 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10805 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10806
10807 /* other char messages are not magic */
10808 PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
10809 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10810 ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
10811 ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10812 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10813 PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
10814 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10815 ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
10816 ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10817 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10818
10819 /* test retrieving messages */
10820
10821 PostMessageW( hwnd, WM_CHAR, wch, 0 );
10822 ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10823 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10824 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10825 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10826 ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10827 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10828 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10829 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10830 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10831
10832 /* message filters */
10833 PostMessageW( hwnd, WM_CHAR, wch, 0 );
10834 ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10835 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10836 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10837 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10838 /* message id is filtered, hwnd is not */
10839 ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
10840 ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
10841 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10842 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10843 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10844 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10845
10846 /* mixing GetMessage and PostMessage */
10847 PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
10848 ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
10849 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10850 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10851 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10852 ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10853 time = msg.time;
10854 pt = msg.pt;
10855 ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
10856 ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10857 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10858 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10859 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10860 ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10861 ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
10862 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 );
10863 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10864
10865 /* without PM_REMOVE */
10866 PostMessageW( hwnd, WM_CHAR, wch, 0 );
10867 ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10868 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10869 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10870 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10871 ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10872 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10873 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10874 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10875 ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10876 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10877 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10878 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10879 ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10880 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10881 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10882 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10883 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10884
10885 DestroyWindow(hwnd);
10886 }
10887
10888 #define ID_LISTBOX 0x000f
10889
10890 static const struct message wm_lb_setcursel_0[] =
10891 {
10892 { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
10893 { WM_CTLCOLORLISTBOX, sent|parent },
10894 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10895 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10896 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10897 { 0 }
10898 };
10899 static const struct message wm_lb_setcursel_1[] =
10900 {
10901 { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
10902 { WM_CTLCOLORLISTBOX, sent|parent },
10903 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
10904 { WM_CTLCOLORLISTBOX, sent|parent },
10905 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
10906 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10907 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10908 { 0 }
10909 };
10910 static const struct message wm_lb_setcursel_2[] =
10911 {
10912 { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
10913 { WM_CTLCOLORLISTBOX, sent|parent },
10914 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
10915 { WM_CTLCOLORLISTBOX, sent|parent },
10916 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
10917 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10918 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10919 { 0 }
10920 };
10921 static const struct message wm_lb_click_0[] =
10922 {
10923 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
10924 { HCBT_SETFOCUS, hook },
10925 { WM_KILLFOCUS, sent|parent },
10926 { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
10927 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10928 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10929 { WM_SETFOCUS, sent|defwinproc },
10930
10931 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
10932 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
10933 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10934 { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
10935 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
10936
10937 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
10938 { WM_CTLCOLORLISTBOX, sent|parent },
10939 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
10940 { WM_CTLCOLORLISTBOX, sent|parent },
10941 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10942 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
10943
10944 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10945 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10946
10947 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
10948 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
10949 { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
10950 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
10951 { 0 }
10952 };
10953
10954 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
10955
10956 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
10957
10958 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
10959 {
10960 static long defwndproc_counter = 0;
10961 LRESULT ret;
10962 struct recvd_message msg;
10963
10964 /* do not log painting messages */
10965 if (message != WM_PAINT &&
10966 message != WM_NCPAINT &&
10967 message != WM_SYNCPAINT &&
10968 message != WM_ERASEBKGND &&
10969 message != WM_NCHITTEST &&
10970 message != WM_GETTEXT &&
10971 message != WM_GETOBJECT &&
10972 message != WM_GETICON &&
10973 message != WM_DEVICECHANGE)
10974 {
10975 msg.hwnd = hwnd;
10976 msg.message = message;
10977 msg.flags = sent|wparam|lparam;
10978 if (defwndproc_counter) msg.flags |= defwinproc;
10979 msg.wParam = wp;
10980 msg.lParam = lp;
10981 msg.descr = "listbox";
10982 add_message(&msg);
10983 }
10984
10985 defwndproc_counter++;
10986 ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
10987 defwndproc_counter--;
10988
10989 return ret;
10990 }
10991
10992 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
10993 int caret_index, int top_index, int line)
10994 {
10995 LRESULT ret;
10996
10997 /* calling an orig proc helps to avoid unnecessary message logging */
10998 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
10999 ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
11000 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
11001 ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
11002 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
11003 ok_(__FILE__, line)(ret == caret_index, "expected caret index %d, got %ld\n", caret_index, ret);
11004 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
11005 ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
11006 }
11007
11008 static void test_listbox_messages(void)
11009 {
11010 HWND parent, listbox;
11011 LRESULT ret;
11012
11013 parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11014 100, 100, 200, 200, 0, 0, 0, NULL);
11015 listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
11016 WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
11017 10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
11018 listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
11019
11020 check_lb_state(listbox, 0, LB_ERR, 0, 0);
11021
11022 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
11023 ok(ret == 0, "expected 0, got %ld\n", ret);
11024 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
11025 ok(ret == 1, "expected 1, got %ld\n", ret);
11026 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
11027 ok(ret == 2, "expected 2, got %ld\n", ret);
11028
11029 check_lb_state(listbox, 3, LB_ERR, 0, 0);
11030
11031 flush_sequence();
11032
11033 log_all_parent_messages++;
11034
11035 trace("selecting item 0\n");
11036 ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
11037 ok(ret == 0, "expected 0, got %ld\n", ret);
11038 ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
11039 check_lb_state(listbox, 3, 0, 0, 0);
11040 flush_sequence();
11041
11042 trace("selecting item 1\n");
11043 ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
11044 ok(ret == 1, "expected 1, got %ld\n", ret);
11045 ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
11046 check_lb_state(listbox, 3, 1, 1, 0);
11047
11048 trace("selecting item 2\n");
11049 ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
11050 ok(ret == 2, "expected 2, got %ld\n", ret);
11051 ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
11052 check_lb_state(listbox, 3, 2, 2, 0);
11053
11054 trace("clicking on item 0\n");
11055 ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
11056 ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11057 ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
11058 ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11059 ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
11060 check_lb_state(listbox, 3, 0, 0, 0);
11061 flush_sequence();
11062
11063 log_all_parent_messages--;
11064
11065 DestroyWindow(listbox);
11066 DestroyWindow(parent);
11067 }
11068
11069 /*************************** Menu test ******************************/
11070 static const struct message wm_popup_menu_1[] =
11071 {
11072 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11073 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11074 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0x20000001 },
11075 { WM_SYSKEYDOWN, sent|wparam|lparam, 'E', 0x20000001 },
11076 { WM_SYSCHAR, sent|wparam|lparam, 'e', 0x20000001 },
11077 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'e' },
11078 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11079 { WM_INITMENU, sent|lparam, 0, 0 },
11080 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(1,MF_HILITE|MF_POPUP) },
11081 { WM_INITMENUPOPUP, sent|lparam, 0, 1 },
11082 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't create a window */
11083 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(200,MF_HILITE) },
11084 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0xf0000001 },
11085 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11086 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11087 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't create a window */
11088 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11089 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11090 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11091 { WM_MENUCOMMAND, sent }, /* |wparam, 200 - Win9x */
11092 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11093 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11094 { 0 }
11095 };
11096 static const struct message wm_popup_menu_2[] =
11097 {
11098 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11099 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11100 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11101 { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11102 { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11103 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11104 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11105 { WM_INITMENU, sent|lparam, 0, 0 },
11106 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11107 { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11108 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11109 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11110 { HCBT_CREATEWND, hook },
11111 { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11112 |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11113 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11114 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11115 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11116 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11117 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11118 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11119 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11120 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11121 { HCBT_DESTROYWND, hook },
11122 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11123 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11124 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11125 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11126 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11127 { WM_MENUCOMMAND, sent }, /* |wparam, 100 - Win9x */
11128 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11129 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11130 { 0 }
11131 };
11132 static const struct message wm_popup_menu_3[] =
11133 {
11134 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11135 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11136 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11137 { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11138 { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11139 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11140 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11141 { WM_INITMENU, sent|lparam, 0, 0 },
11142 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11143 { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11144 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11145 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11146 { HCBT_CREATEWND, hook },
11147 { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11148 |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11149 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11150 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11151 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11152 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11153 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11154 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11155 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11156 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11157 { HCBT_DESTROYWND, hook },
11158 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11159 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11160 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11161 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11162 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11163 { WM_COMMAND, sent|wparam|lparam, 100, 0 },
11164 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11165 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11166 { 0 }
11167 };
11168
11169 static LRESULT WINAPI parent_menu_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11170 {
11171 if (message == WM_ENTERIDLE ||
11172 message == WM_INITMENU ||
11173 message == WM_INITMENUPOPUP ||
11174 message == WM_MENUSELECT ||
11175 message == WM_PARENTNOTIFY ||
11176 message == WM_ENTERMENULOOP ||
11177 message == WM_EXITMENULOOP ||
11178 message == WM_UNINITMENUPOPUP ||
11179 message == WM_KEYDOWN ||
11180 message == WM_KEYUP ||
11181 message == WM_CHAR ||
11182 message == WM_SYSKEYDOWN ||
11183 message == WM_SYSKEYUP ||
11184 message == WM_SYSCHAR ||
11185 message == WM_COMMAND ||
11186 message == WM_MENUCOMMAND)
11187 {
11188 struct recvd_message msg;
11189
11190 msg.hwnd = hwnd;
11191 msg.message = message;
11192 msg.flags = sent|wparam|lparam;
11193 msg.wParam = wp;
11194 msg.lParam = lp;
11195 msg.descr = "parent_menu_proc";
11196 add_message(&msg);
11197 }
11198
11199 return DefWindowProcA(hwnd, message, wp, lp);
11200 }
11201
11202 static void set_menu_style(HMENU hmenu, DWORD style)
11203 {
11204 MENUINFO mi;
11205 BOOL ret;
11206
11207 mi.cbSize = sizeof(mi);
11208 mi.fMask = MIM_STYLE;
11209 mi.dwStyle = style;
11210 SetLastError(0xdeadbeef);
11211 ret = pSetMenuInfo(hmenu, &mi);
11212 ok(ret, "SetMenuInfo error %u\n", GetLastError());
11213 }
11214
11215 static DWORD get_menu_style(HMENU hmenu)
11216 {
11217 MENUINFO mi;
11218 BOOL ret;
11219
11220 mi.cbSize = sizeof(mi);
11221 mi.fMask = MIM_STYLE;
11222 mi.dwStyle = 0;
11223 SetLastError(0xdeadbeef);
11224 ret = pGetMenuInfo(hmenu, &mi);
11225 ok(ret, "GetMenuInfo error %u\n", GetLastError());
11226
11227 return mi.dwStyle;
11228 }
11229
11230 static void test_menu_messages(void)
11231 {
11232 MSG msg;
11233 WNDCLASSA cls;
11234 HMENU hmenu, hmenu_popup;
11235 HWND hwnd;
11236 DWORD style;
11237
11238 if (!pGetMenuInfo || !pSetMenuInfo)
11239 {
11240 win_skip("GetMenuInfo and/or SetMenuInfo are not available\n");
11241 return;
11242 }
11243 cls.style = 0;
11244 cls.lpfnWndProc = parent_menu_proc;
11245 cls.cbClsExtra = 0;
11246 cls.cbWndExtra = 0;
11247 cls.hInstance = GetModuleHandleA(0);
11248 cls.hIcon = 0;
11249 cls.hCursor = LoadCursorA(0, IDC_ARROW);
11250 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
11251 cls.lpszMenuName = NULL;
11252 cls.lpszClassName = "TestMenuClass";
11253 UnregisterClass(cls.lpszClassName, cls.hInstance);
11254 if (!RegisterClassA(&cls)) assert(0);
11255
11256 SetLastError(0xdeadbeef);
11257 hwnd = CreateWindowExA(0, "TestMenuClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11258 100, 100, 200, 200, 0, 0, 0, NULL);
11259 ok(hwnd != 0, "LoadMenuA error %u\n", GetLastError());
11260
11261 SetLastError(0xdeadbeef);
11262 hmenu = LoadMenuA(GetModuleHandle(0), MAKEINTRESOURCE(1));
11263 ok(hmenu != 0, "LoadMenuA error %u\n", GetLastError());
11264
11265 SetMenu(hwnd, hmenu);
11266 SetForegroundWindow( hwnd );
11267
11268 set_menu_style(hmenu, MNS_NOTIFYBYPOS);
11269 style = get_menu_style(hmenu);
11270 ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11271
11272 hmenu_popup = GetSubMenu(hmenu, 0);
11273 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11274 style = get_menu_style(hmenu_popup);
11275 ok(style == 0, "expected 0, got %u\n", style);
11276
11277 hmenu_popup = GetSubMenu(hmenu_popup, 0);
11278 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11279 style = get_menu_style(hmenu_popup);
11280 ok(style == 0, "expected 0, got %u\n", style);
11281
11282 /* Alt+E, Enter */
11283 trace("testing a popup menu command\n");
11284 flush_sequence();
11285 keybd_event(VK_MENU, 0, 0, 0);
11286 keybd_event('E', 0, 0, 0);
11287 keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
11288 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11289 keybd_event(VK_RETURN, 0, 0, 0);
11290 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11291 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11292 {
11293 TranslateMessage(&msg);
11294 DispatchMessage(&msg);
11295 }
11296 if (!sequence_cnt) /* we didn't get any message */
11297 {
11298 skip( "queuing key events not supported\n" );
11299 goto done;
11300 }
11301 ok_sequence(wm_popup_menu_1, "popup menu command", FALSE);
11302
11303 /* Alt+F, Right, Enter */
11304 trace("testing submenu of a popup menu command\n");
11305 flush_sequence();
11306 keybd_event(VK_MENU, 0, 0, 0);
11307 keybd_event('F', 0, 0, 0);
11308 keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11309 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11310 keybd_event(VK_RIGHT, 0, 0, 0);
11311 keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11312 keybd_event(VK_RETURN, 0, 0, 0);
11313 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11314 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11315 {
11316 TranslateMessage(&msg);
11317 DispatchMessage(&msg);
11318 }
11319 ok_sequence(wm_popup_menu_2, "submenu of a popup menu command", FALSE);
11320
11321 set_menu_style(hmenu, 0);
11322 style = get_menu_style(hmenu);
11323 ok(style == 0, "expected 0, got %u\n", style);
11324
11325 hmenu_popup = GetSubMenu(hmenu, 0);
11326 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11327 set_menu_style(hmenu_popup, MNS_NOTIFYBYPOS);
11328 style = get_menu_style(hmenu_popup);
11329 ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11330
11331 hmenu_popup = GetSubMenu(hmenu_popup, 0);
11332 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11333 style = get_menu_style(hmenu_popup);
11334 ok(style == 0, "expected 0, got %u\n", style);
11335
11336 /* Alt+F, Right, Enter */
11337 trace("testing submenu of a popup menu command\n");
11338 flush_sequence();
11339 keybd_event(VK_MENU, 0, 0, 0);
11340 keybd_event('F', 0, 0, 0);
11341 keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11342 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11343 keybd_event(VK_RIGHT, 0, 0, 0);
11344 keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11345 keybd_event(VK_RETURN, 0, 0, 0);
11346 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11347 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11348 {
11349 TranslateMessage(&msg);
11350 DispatchMessage(&msg);
11351 }
11352 ok_sequence(wm_popup_menu_3, "submenu of a popup menu command", FALSE);
11353
11354 done:
11355 DestroyWindow(hwnd);
11356 DestroyMenu(hmenu);
11357 }
11358
11359
11360 static void test_paintingloop(void)
11361 {
11362 HWND hwnd;
11363
11364 paint_loop_done = 0;
11365 hwnd = CreateWindowExA(0x0,"PaintLoopWindowClass",
11366 "PaintLoopWindowClass",WS_OVERLAPPEDWINDOW,
11367 100, 100, 100, 100, 0, 0, 0, NULL );
11368 ok(hwnd != 0, "PaintLoop window error %u\n", GetLastError());
11369 ShowWindow(hwnd,SW_NORMAL);
11370 SetFocus(hwnd);
11371
11372 while (!paint_loop_done)
11373 {
11374 MSG msg;
11375 if (PeekMessageA(&msg, 0, 0, 0, 1))
11376 {
11377 TranslateMessage(&msg);
11378 DispatchMessage(&msg);
11379 }
11380 }
11381 DestroyWindow(hwnd);
11382 }
11383
11384 static void test_defwinproc(void)
11385 {
11386 HWND hwnd;
11387 MSG msg;
11388 int gotwmquit = FALSE;
11389 hwnd = CreateWindowExA(0, "static", "test_defwndproc", WS_POPUP, 0,0,0,0,0,0,0, NULL);
11390 assert(hwnd);
11391 DefWindowProcA( hwnd, WM_ENDSESSION, 1, 0);
11392 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) {
11393 if( msg.message == WM_QUIT) gotwmquit = TRUE;
11394 DispatchMessageA( &msg );
11395 }
11396 ok( gotwmquit == FALSE, "Unexpected WM_QUIT message!\n");
11397 DestroyWindow( hwnd);
11398 }
11399
11400 START_TEST(msg)
11401 {
11402 BOOL ret;
11403 FARPROC pIsWinEventHookInstalled = 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
11404
11405 init_procs();
11406
11407 if (!RegisterWindowClasses()) assert(0);
11408
11409 if (pSetWinEventHook)
11410 {
11411 hEvent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX,
11412 GetModuleHandleA(0), win_event_proc,
11413 0, GetCurrentThreadId(),
11414 WINEVENT_INCONTEXT);
11415 if (pIsWinEventHookInstalled && hEvent_hook)
11416 {
11417 UINT event;
11418 for (event = EVENT_MIN; event <= EVENT_MAX; event++)
11419 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
11420 }
11421 }
11422 if (!hEvent_hook) win_skip( "no win event hook support\n" );
11423
11424 cbt_hook_thread_id = GetCurrentThreadId();
11425 hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
11426 if (!hCBT_hook) win_skip( "cannot set global hook, will skip hook tests\n" );
11427
11428 test_winevents();
11429
11430 /* Fix message sequences before removing 4 lines below */
11431 #if 1
11432 if (pUnhookWinEvent && hEvent_hook)
11433 {
11434 ret = pUnhookWinEvent(hEvent_hook);
11435 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
11436 pUnhookWinEvent = 0;
11437 }
11438 hEvent_hook = 0;
11439 #endif
11440
11441 test_ShowWindow();
11442 test_PeekMessage();
11443 test_PeekMessage2();
11444 test_scrollwindowex();
11445 test_messages();
11446 test_setwindowpos();
11447 test_showwindow();
11448 invisible_parent_tests();
11449 test_mdi_messages();
11450 test_button_messages();
11451 test_static_messages();
11452 test_listbox_messages();
11453 test_combobox_messages();
11454 test_wmime_keydown_message();
11455 test_paint_messages();
11456 test_interthread_messages();
11457 test_message_conversion();
11458 test_accelerators();
11459 test_timers();
11460 test_timers_no_wnd();
11461 if (hCBT_hook) test_set_hook();
11462 test_DestroyWindow();
11463 test_DispatchMessage();
11464 test_SendMessageTimeout();
11465 test_edit_messages();
11466 test_quit_message();
11467 test_SetActiveWindow();
11468
11469 if (!pTrackMouseEvent)
11470 win_skip("TrackMouseEvent is not available\n");
11471 else
11472 test_TrackMouseEvent();
11473
11474 test_SetWindowRgn();
11475 test_sys_menu();
11476 test_dialog_messages();
11477 test_nullCallback();
11478 test_dbcs_wm_char();
11479 test_menu_messages();
11480 test_paintingloop();
11481 test_defwinproc();
11482 /* keep it the last test, under Windows it tends to break the tests
11483 * which rely on active/foreground windows being correct.
11484 */
11485 test_SetForegroundWindow();
11486
11487 UnhookWindowsHookEx(hCBT_hook);
11488 if (pUnhookWinEvent && hEvent_hook)
11489 {
11490 ret = pUnhookWinEvent(hEvent_hook);
11491 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
11492 SetLastError(0xdeadbeef);
11493 ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
11494 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
11495 GetLastError() == 0xdeadbeef, /* Win9x */
11496 "unexpected error %d\n", GetLastError());
11497 }
11498 }