bbbac2ae2fa4afb99ea4fb4f7b510ed2e467ba43
[reactos.git] / rostests / winetests / user32 / win.c
1 /*
2 * Unit tests for window handling
3 *
4 * Copyright 2002 Bill Medland
5 * Copyright 2002 Alexandre Julliard
6 * Copyright 2003 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 /* To get ICON_SMALL2 with the MSVC headers */
24 #define _WIN32_WINNT 0x0501
25
26 #include <assert.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35
36 #include "wine/test.h"
37
38 #ifndef SPI_GETDESKWALLPAPER
39 #define SPI_GETDESKWALLPAPER 0x0073
40 #endif
41
42 #define LONG_PTR INT_PTR
43 #define ULONG_PTR UINT_PTR
44
45 void dump_region(HRGN hrgn);
46
47 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
48 static BOOL (WINAPI *pGetWindowInfo)(HWND,WINDOWINFO*);
49 static UINT (WINAPI *pGetWindowModuleFileNameA)(HWND,LPSTR,UINT);
50 static BOOL (WINAPI *pGetLayeredWindowAttributes)(HWND,COLORREF*,BYTE*,DWORD*);
51 static BOOL (WINAPI *pSetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD);
52 static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
53 static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
54 static int (WINAPI *pGetWindowRgnBox)(HWND,LPRECT);
55
56 static BOOL test_lbuttondown_flag;
57 static HWND hwndMessage;
58 static HWND hwndMain, hwndMain2;
59 static HHOOK hhook;
60
61 static const char* szAWRClass = "Winsize";
62 static HMENU hmenu;
63 static DWORD our_pid;
64
65 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
66
67 static void dump_minmax_info( const MINMAXINFO *minmax )
68 {
69 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
70 minmax->ptReserved.x, minmax->ptReserved.y,
71 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
72 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
73 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
74 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
75 }
76
77 /* try to make sure pending X events have been processed before continuing */
78 static void flush_events( BOOL remove_messages )
79 {
80 MSG msg;
81 int diff = 200;
82 int min_timeout = 100;
83 DWORD time = GetTickCount() + diff;
84
85 while (diff > 0)
86 {
87 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
88 if (remove_messages)
89 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
90 diff = time - GetTickCount();
91 min_timeout = 50;
92 }
93 }
94
95 /* check the values returned by the various parent/owner functions on a given window */
96 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
97 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
98 {
99 HWND res;
100
101 if (pGetAncestor)
102 {
103 res = pGetAncestor( hwnd, GA_PARENT );
104 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
105 }
106 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
107 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
108 res = GetParent( hwnd );
109 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
110 res = GetWindow( hwnd, GW_OWNER );
111 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
112 if (pGetAncestor)
113 {
114 res = pGetAncestor( hwnd, GA_ROOT );
115 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
116 res = pGetAncestor( hwnd, GA_ROOTOWNER );
117 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
118 }
119 }
120
121 static BOOL ignore_message( UINT message )
122 {
123 /* these are always ignored */
124 return (message >= 0xc000 ||
125 message == WM_GETICON ||
126 message == WM_GETOBJECT ||
127 message == WM_TIMECHANGE ||
128 message == WM_DEVICECHANGE);
129 }
130
131 static BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
132 {
133 (*(LPINT)lParam)++;
134 trace("EnumChildProc on %p\n", hwndChild);
135 if (*(LPINT)lParam > 1) return FALSE;
136 return TRUE;
137 }
138
139 /* will search for the given window */
140 static BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
141 {
142 trace("EnumChildProc1 on %p\n", hwndChild);
143 if ((HWND)lParam == hwndChild) return FALSE;
144 return TRUE;
145 }
146
147 static HWND create_tool_window( LONG style, HWND parent )
148 {
149 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
150 0, 0, 100, 100, parent, 0, 0, NULL );
151 ok( ret != 0, "Creation failed\n" );
152 return ret;
153 }
154
155 /* test parent and owner values for various combinations */
156 static void test_parent_owner(void)
157 {
158 LONG style;
159 HWND test, owner, ret;
160 HWND desktop = GetDesktopWindow();
161 HWND child = create_tool_window( WS_CHILD, hwndMain );
162 INT numChildren;
163
164 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
165
166 /* child without parent, should fail */
167 SetLastError(0xdeadbeef);
168 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
169 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
170 ok( !test, "WS_CHILD without parent created\n" );
171 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD ||
172 broken(GetLastError() == 0xdeadbeef), /* win9x */
173 "CreateWindowExA error %u\n", GetLastError() );
174
175 /* desktop window */
176 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
177 style = GetWindowLongA( desktop, GWL_STYLE );
178 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
179 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
180 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
181
182 /* normal child window */
183 test = create_tool_window( WS_CHILD, hwndMain );
184 trace( "created child %p\n", test );
185 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
186 SetWindowLongA( test, GWL_STYLE, 0 );
187 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
188 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
189 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
190 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
191 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
192 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
193 DestroyWindow( test );
194
195 /* normal child window with WS_MAXIMIZE */
196 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
197 DestroyWindow( test );
198
199 /* normal child window with WS_THICKFRAME */
200 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
201 DestroyWindow( test );
202
203 /* popup window with WS_THICKFRAME */
204 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
205 DestroyWindow( test );
206
207 /* child of desktop */
208 test = create_tool_window( WS_CHILD, desktop );
209 trace( "created child of desktop %p\n", test );
210 check_parents( test, desktop, 0, desktop, 0, test, desktop );
211 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
212 check_parents( test, desktop, 0, 0, 0, test, test );
213 SetWindowLongA( test, GWL_STYLE, 0 );
214 check_parents( test, desktop, 0, 0, 0, test, test );
215 DestroyWindow( test );
216
217 /* child of desktop with WS_MAXIMIZE */
218 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
219 DestroyWindow( test );
220
221 /* child of desktop with WS_MINIMIZE */
222 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
223 DestroyWindow( test );
224
225 /* child of child */
226 test = create_tool_window( WS_CHILD, child );
227 trace( "created child of child %p\n", test );
228 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
229 SetWindowLongA( test, GWL_STYLE, 0 );
230 check_parents( test, child, child, 0, 0, hwndMain, test );
231 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
232 check_parents( test, child, child, 0, 0, hwndMain, test );
233 DestroyWindow( test );
234
235 /* child of child with WS_MAXIMIZE */
236 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
237 DestroyWindow( test );
238
239 /* child of child with WS_MINIMIZE */
240 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
241 DestroyWindow( test );
242
243 /* not owned top-level window */
244 test = create_tool_window( 0, 0 );
245 trace( "created top-level %p\n", test );
246 check_parents( test, desktop, 0, 0, 0, test, test );
247 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
248 check_parents( test, desktop, 0, 0, 0, test, test );
249 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
250 check_parents( test, desktop, 0, desktop, 0, test, desktop );
251 DestroyWindow( test );
252
253 /* not owned top-level window with WS_MAXIMIZE */
254 test = create_tool_window( WS_MAXIMIZE, 0 );
255 DestroyWindow( test );
256
257 /* owned top-level window */
258 test = create_tool_window( 0, hwndMain );
259 trace( "created owned top-level %p\n", test );
260 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
261 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
262 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
263 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
264 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
265 DestroyWindow( test );
266
267 /* owned top-level window with WS_MAXIMIZE */
268 test = create_tool_window( WS_MAXIMIZE, hwndMain );
269 DestroyWindow( test );
270
271 /* not owned popup */
272 test = create_tool_window( WS_POPUP, 0 );
273 trace( "created popup %p\n", test );
274 check_parents( test, desktop, 0, 0, 0, test, test );
275 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
276 check_parents( test, desktop, 0, desktop, 0, test, desktop );
277 SetWindowLongA( test, GWL_STYLE, 0 );
278 check_parents( test, desktop, 0, 0, 0, test, test );
279 DestroyWindow( test );
280
281 /* not owned popup with WS_MAXIMIZE */
282 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
283 DestroyWindow( test );
284
285 /* owned popup */
286 test = create_tool_window( WS_POPUP, hwndMain );
287 trace( "created owned popup %p\n", test );
288 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
289 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
290 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
291 SetWindowLongA( test, GWL_STYLE, 0 );
292 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
293 DestroyWindow( test );
294
295 /* owned popup with WS_MAXIMIZE */
296 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
297 DestroyWindow( test );
298
299 /* top-level window owned by child (same as owned by top-level) */
300 test = create_tool_window( 0, child );
301 trace( "created top-level owned by child %p\n", test );
302 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
303 DestroyWindow( test );
304
305 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
306 test = create_tool_window( WS_MAXIMIZE, child );
307 DestroyWindow( test );
308
309 /* popup owned by desktop (same as not owned) */
310 test = create_tool_window( WS_POPUP, desktop );
311 trace( "created popup owned by desktop %p\n", test );
312 check_parents( test, desktop, 0, 0, 0, test, test );
313 DestroyWindow( test );
314
315 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
316 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
317 DestroyWindow( test );
318
319 /* popup owned by child (same as owned by top-level) */
320 test = create_tool_window( WS_POPUP, child );
321 trace( "created popup owned by child %p\n", test );
322 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
323 DestroyWindow( test );
324
325 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
326 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
327 DestroyWindow( test );
328
329 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
330 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
331 trace( "created WS_CHILD popup %p\n", test );
332 check_parents( test, desktop, 0, 0, 0, test, test );
333 DestroyWindow( test );
334
335 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
336 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
337 DestroyWindow( test );
338
339 /* owned popup with WS_CHILD (same as WS_POPUP only) */
340 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
341 trace( "created owned WS_CHILD popup %p\n", test );
342 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
343 DestroyWindow( test );
344
345 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
346 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
347 DestroyWindow( test );
348
349 /******************** parent changes *************************/
350 trace( "testing parent changes\n" );
351
352 /* desktop window */
353 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
354 if (0)
355 {
356 /* this test succeeds on NT but crashes on win9x systems */
357 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
358 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
359 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
360 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
361 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
362 }
363 /* normal child window */
364 test = create_tool_window( WS_CHILD, hwndMain );
365 trace( "created child %p\n", test );
366
367 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
368 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
369 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
370
371 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
372 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
373 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
374
375 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
376 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
377 check_parents( test, desktop, 0, desktop, 0, test, desktop );
378
379 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
380 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
381 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
382 check_parents( test, desktop, child, desktop, child, test, desktop );
383
384 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
385 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
386 check_parents( test, desktop, 0, desktop, 0, test, desktop );
387 DestroyWindow( test );
388
389 /* not owned top-level window */
390 test = create_tool_window( 0, 0 );
391 trace( "created top-level %p\n", test );
392
393 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
394 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
395 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
396
397 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
398 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
399 check_parents( test, desktop, child, 0, child, test, test );
400
401 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
402 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
403 check_parents( test, desktop, 0, 0, 0, test, test );
404 DestroyWindow( test );
405
406 /* not owned popup */
407 test = create_tool_window( WS_POPUP, 0 );
408 trace( "created popup %p\n", test );
409
410 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
411 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
412 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
413
414 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
415 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
416 check_parents( test, desktop, child, child, child, test, hwndMain );
417
418 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
419 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
420 check_parents( test, desktop, 0, 0, 0, test, test );
421 DestroyWindow( test );
422
423 /* normal child window */
424 test = create_tool_window( WS_CHILD, hwndMain );
425 trace( "created child %p\n", test );
426
427 ret = SetParent( test, desktop );
428 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
429 check_parents( test, desktop, 0, desktop, 0, test, desktop );
430
431 ret = SetParent( test, child );
432 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
433 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
434
435 ret = SetParent( test, hwndMain2 );
436 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
437 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
438 DestroyWindow( test );
439
440 /* not owned top-level window */
441 test = create_tool_window( 0, 0 );
442 trace( "created top-level %p\n", test );
443
444 ret = SetParent( test, child );
445 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
446 check_parents( test, child, child, 0, 0, hwndMain, test );
447 DestroyWindow( test );
448
449 /* owned popup */
450 test = create_tool_window( WS_POPUP, hwndMain2 );
451 trace( "created owned popup %p\n", test );
452
453 ret = SetParent( test, child );
454 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
455 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
456
457 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
458 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
459 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
460 DestroyWindow( test );
461
462 /**************** test owner destruction *******************/
463
464 /* owned child popup */
465 owner = create_tool_window( 0, 0 );
466 test = create_tool_window( WS_POPUP, owner );
467 trace( "created owner %p and popup %p\n", owner, test );
468 ret = SetParent( test, child );
469 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
470 check_parents( test, child, child, owner, owner, hwndMain, owner );
471 /* window is now child of 'child' but owned by 'owner' */
472 DestroyWindow( owner );
473 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
474 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
475 * while Win95, Win2k, WinXP do.
476 */
477 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
478 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
479 DestroyWindow(test);
480
481 /* owned top-level popup */
482 owner = create_tool_window( 0, 0 );
483 test = create_tool_window( WS_POPUP, owner );
484 trace( "created owner %p and popup %p\n", owner, test );
485 check_parents( test, desktop, owner, owner, owner, test, owner );
486 DestroyWindow( owner );
487 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
488
489 /* top-level popup owned by child */
490 owner = create_tool_window( WS_CHILD, hwndMain2 );
491 test = create_tool_window( WS_POPUP, 0 );
492 trace( "created owner %p and popup %p\n", owner, test );
493 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
494 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
495 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
496 DestroyWindow( owner );
497 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
498 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
499 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
500 * while Win95, Win2k, WinXP do.
501 */
502 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
503 DestroyWindow(test);
504
505 /* final cleanup */
506 DestroyWindow(child);
507
508
509 owner = create_tool_window( WS_OVERLAPPED, 0 );
510 test = create_tool_window( WS_POPUP, desktop );
511
512 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
513 numChildren = 0;
514 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
515 "EnumChildWindows should have returned FALSE\n" );
516 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
517
518 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
519 ret = SetParent( test, owner );
520 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
521
522 numChildren = 0;
523 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
524 "EnumChildWindows should have returned TRUE\n" );
525 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
526
527 child = create_tool_window( WS_CHILD, owner );
528 numChildren = 0;
529 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
530 "EnumChildWindows should have returned FALSE\n" );
531 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
532 DestroyWindow( child );
533
534 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
535 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
536 numChildren = 0;
537 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
538 "EnumChildWindows should have returned TRUE\n" );
539 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
540
541 ret = SetParent( child, owner );
542 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
543 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
544 numChildren = 0;
545 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
546 "EnumChildWindows should have returned FALSE\n" );
547 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
548
549 ret = SetParent( child, NULL );
550 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
551 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
552 numChildren = 0;
553 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
554 "EnumChildWindows should have returned TRUE\n" );
555 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
556
557 /* even GW_OWNER == owner it's still a desktop's child */
558 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
559 "EnumChildWindows should have found %p and returned FALSE\n", child );
560
561 DestroyWindow( child );
562 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
563
564 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
565 "EnumChildWindows should have found %p and returned FALSE\n", child );
566
567 DestroyWindow( child );
568 DestroyWindow( test );
569 DestroyWindow( owner );
570 }
571
572 static BOOL CALLBACK enum_proc( HWND hwnd, LPARAM lParam)
573 {
574 (*(LPINT)lParam)++;
575 if (*(LPINT)lParam > 2) return FALSE;
576 return TRUE;
577 }
578 static DWORD CALLBACK enum_thread( void *arg )
579 {
580 INT count;
581 HWND hwnd[3];
582 BOOL ret;
583 MSG msg;
584
585 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ); /* make sure we have a message queue */
586
587 count = 0;
588 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
589 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
590 ok( count == 0, "count should be 0 got %d\n", count );
591
592 hwnd[0] = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", WS_POPUP,
593 0, 0, 100, 100, 0, 0, 0, NULL );
594 count = 0;
595 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
596 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
597 if (count != 2) /* Vista gives us two windows for the price of one */
598 {
599 ok( count == 1, "count should be 1 got %d\n", count );
600 hwnd[2] = CreateWindowExA(0, "ToolWindowClass", "Tool window 2", WS_POPUP,
601 0, 0, 100, 100, 0, 0, 0, NULL );
602 }
603 else hwnd[2] = 0;
604
605 hwnd[1] = CreateWindowExA(0, "ToolWindowClass", "Tool window 3", WS_POPUP,
606 0, 0, 100, 100, 0, 0, 0, NULL );
607 count = 0;
608 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
609 ok( !ret, "EnumThreadWindows should have returned FALSE\n" );
610 ok( count == 3, "count should be 3 got %d\n", count );
611
612 if (hwnd[2]) DestroyWindow(hwnd[2]);
613 DestroyWindow(hwnd[1]);
614 DestroyWindow(hwnd[0]);
615 return 0;
616 }
617
618 /* test EnumThreadWindows in a separate thread */
619 static void test_enum_thread_windows(void)
620 {
621 DWORD id;
622 HANDLE handle = CreateThread( NULL, 0, enum_thread, 0, 0, &id );
623 ok( !WaitForSingleObject( handle, 10000 ), "wait failed\n" );
624 CloseHandle( handle );
625 }
626
627 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
628 {
629 switch (msg)
630 {
631 case WM_GETMINMAXINFO:
632 {
633 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
634
635 trace("WM_GETMINMAXINFO: hwnd %p, %08lx, %08lx\n", hwnd, wparam, lparam);
636 dump_minmax_info( minmax );
637 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
638 break;
639 }
640 case WM_WINDOWPOSCHANGING:
641 {
642 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
643 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
644 trace("main: WM_WINDOWPOSCHANGING %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
645 winpos->hwnd, winpos->hwndInsertAfter,
646 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
647 if (!(winpos->flags & SWP_NOMOVE))
648 {
649 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
650 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
651 }
652 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
653 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
654 {
655 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
656 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
657 }
658 break;
659 }
660 case WM_WINDOWPOSCHANGED:
661 {
662 RECT rc1, rc2;
663 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
664 trace("main: WM_WINDOWPOSCHANGED %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
665 winpos->hwnd, winpos->hwndInsertAfter,
666 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
667 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
668 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
669
670 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
671 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
672
673 GetWindowRect(hwnd, &rc1);
674 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
675 /* note: winpos coordinates are relative to parent */
676 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
677 if (0)
678 {
679 /* Uncomment this once the test succeeds in all cases */
680 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
681 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
682
683 GetClientRect(hwnd, &rc2);
684 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
685 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
686 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
687 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
688 }
689 break;
690 }
691 case WM_NCCREATE:
692 {
693 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
694 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
695
696 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
697 if (got_getminmaxinfo)
698 trace("%p got WM_GETMINMAXINFO\n", hwnd);
699
700 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
701 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
702 else
703 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
704 break;
705 }
706 case WM_COMMAND:
707 if (test_lbuttondown_flag)
708 {
709 ShowWindow((HWND)wparam, SW_SHOW);
710 flush_events( FALSE );
711 }
712 break;
713 }
714
715 return DefWindowProcA(hwnd, msg, wparam, lparam);
716 }
717
718 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
719 {
720 switch (msg)
721 {
722 case WM_GETMINMAXINFO:
723 {
724 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
725
726 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
727 dump_minmax_info( minmax );
728 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
729 break;
730 }
731 case WM_NCCREATE:
732 {
733 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
734 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
735
736 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
737 if (got_getminmaxinfo)
738 trace("%p got WM_GETMINMAXINFO\n", hwnd);
739
740 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
741 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
742 else
743 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
744 break;
745 }
746 }
747
748 return DefWindowProcA(hwnd, msg, wparam, lparam);
749 }
750
751 static BOOL RegisterWindowClasses(void)
752 {
753 WNDCLASSA cls;
754
755 cls.style = CS_DBLCLKS;
756 cls.lpfnWndProc = main_window_procA;
757 cls.cbClsExtra = 0;
758 cls.cbWndExtra = 0;
759 cls.hInstance = GetModuleHandleA(0);
760 cls.hIcon = 0;
761 cls.hCursor = LoadCursorA(0, IDC_ARROW);
762 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
763 cls.lpszMenuName = NULL;
764 cls.lpszClassName = "MainWindowClass";
765
766 if(!RegisterClassA(&cls)) return FALSE;
767
768 cls.style = 0;
769 cls.lpfnWndProc = tool_window_procA;
770 cls.cbClsExtra = 0;
771 cls.cbWndExtra = 0;
772 cls.hInstance = GetModuleHandleA(0);
773 cls.hIcon = 0;
774 cls.hCursor = LoadCursorA(0, IDC_ARROW);
775 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
776 cls.lpszMenuName = NULL;
777 cls.lpszClassName = "ToolWindowClass";
778
779 if(!RegisterClassA(&cls)) return FALSE;
780
781 return TRUE;
782 }
783
784 static void verify_window_info(const char *hook, HWND hwnd, const WINDOWINFO *info)
785 {
786 RECT rcWindow, rcClient;
787 DWORD status;
788
789 ok(IsWindow(hwnd), "bad window handle %p in hook %s\n", hwnd, hook);
790
791 GetWindowRect(hwnd, &rcWindow);
792 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow for %p in hook %s\n", hwnd, hook);
793
794 GetClientRect(hwnd, &rcClient);
795 /* translate to screen coordinates */
796 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
797 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient for %p in hook %s\n", hwnd, hook);
798
799 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
800 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
801 info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE), hwnd, hook);
802 /* Windows reports some undocumented exstyles in WINDOWINFO, but
803 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
804 */
805 ok((info->dwExStyle & ~0xe0000800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
806 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
807 info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE), hwnd, hook);
808 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
809 if (GetForegroundWindow())
810 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
811 info->dwWindowStatus, status, GetActiveWindow(), GetForegroundWindow(), hook);
812
813 /* win2k and XP return broken border info in GetWindowInfo most of
814 * the time, so there is no point in testing it.
815 */
816 #if 0
817 UINT border;
818 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
819 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
820 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
821 ok(info->cyWindowBorders == border,
822 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
823 #endif
824 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType for %p in hook %s\n",
825 hwnd, hook);
826 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
827 info->wCreatorVersion == 0x0500 /* Vista */,
828 "wrong wCreatorVersion %04x for %p in hook %s\n", info->wCreatorVersion, hwnd, hook);
829 }
830
831 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
832 {
833 AdjustWindowRectEx(rc, style, menu, exstyle);
834 /* AdjustWindowRectEx does not include scroll bars */
835 if (style & WS_VSCROLL)
836 {
837 if(exstyle & WS_EX_LEFTSCROLLBAR)
838 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
839 else
840 rc->right += GetSystemMetrics(SM_CXVSCROLL);
841 }
842 if (style & WS_HSCROLL)
843 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
844 }
845
846 static void test_nonclient_area(HWND hwnd)
847 {
848 DWORD style, exstyle;
849 RECT rc_window, rc_client, rc;
850 BOOL menu;
851 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
852 LRESULT ret;
853
854 style = GetWindowLongA(hwnd, GWL_STYLE);
855 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
856 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
857
858 GetWindowRect(hwnd, &rc_window);
859 GetClientRect(hwnd, &rc_client);
860
861 /* avoid some cases when things go wrong */
862 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
863 rc_window.right > 32768 || rc_window.bottom > 32768) return;
864
865 CopyRect(&rc, &rc_client);
866 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
867 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
868
869 ok(EqualRect(&rc, &rc_window),
870 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
871 style, exstyle, menu, rc_window.left, rc_window.top, rc_window.right, rc_window.bottom,
872 rc.left, rc.top, rc.right, rc.bottom);
873
874
875 CopyRect(&rc, &rc_window);
876 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
877 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
878 ok(EqualRect(&rc, &rc_client),
879 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
880 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
881 rc.left, rc.top, rc.right, rc.bottom);
882
883 /* NULL rectangle shouldn't crash */
884 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
885 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
886
887 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
888 if (is_win9x)
889 return;
890
891 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
892 SetRect(&rc_client, 0, 0, 250, 150);
893 CopyRect(&rc_window, &rc_client);
894 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
895 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
896
897 CopyRect(&rc, &rc_window);
898 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
899 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
900 ok(EqualRect(&rc, &rc_client),
901 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
902 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
903 rc.left, rc.top, rc.right, rc.bottom);
904 }
905
906 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
907 {
908 static const char *CBT_code_name[10] = {
909 "HCBT_MOVESIZE",
910 "HCBT_MINMAX",
911 "HCBT_QS",
912 "HCBT_CREATEWND",
913 "HCBT_DESTROYWND",
914 "HCBT_ACTIVATE",
915 "HCBT_CLICKSKIPPED",
916 "HCBT_KEYSKIPPED",
917 "HCBT_SYSCOMMAND",
918 "HCBT_SETFOCUS" };
919 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
920 HWND hwnd = (HWND)wParam;
921
922 switch (nCode)
923 {
924 case HCBT_CREATEWND:
925 {
926 static const RECT rc_null;
927 RECT rc;
928 LONG style;
929 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
930 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
931 hwnd, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
932 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
933
934 if (pGetWindowInfo)
935 {
936 WINDOWINFO info;
937 info.cbSize = sizeof(WINDOWINFO);
938 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
939 verify_window_info(code_name, hwnd, &info);
940 }
941
942 /* WS_VISIBLE should be turned off yet */
943 style = createwnd->lpcs->style & ~WS_VISIBLE;
944 ok(style == GetWindowLongA(hwnd, GWL_STYLE),
945 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
946 GetWindowLongA(hwnd, GWL_STYLE), style);
947
948 if (0)
949 {
950 /* Uncomment this once the test succeeds in all cases */
951 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
952 {
953 ok(GetParent(hwnd) == hwndMessage,
954 "wrong result from GetParent %p: message window %p\n",
955 GetParent(hwnd), hwndMessage);
956 }
957 else
958 ok(!GetParent(hwnd), "GetParent should return 0 at this point\n");
959
960 ok(!GetWindow(hwnd, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
961 }
962 if (0)
963 {
964 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
965 * Win9x still has them set to 0.
966 */
967 ok(GetWindow(hwnd, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
968 ok(GetWindow(hwnd, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
969 }
970 ok(!GetWindow(hwnd, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
971 ok(!GetWindow(hwnd, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
972
973 if (0)
974 {
975 /* Uncomment this once the test succeeds in all cases */
976 if (pGetAncestor)
977 {
978 ok(pGetAncestor(hwnd, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
979 ok(pGetAncestor(hwnd, GA_ROOT) == hwnd,
980 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOT), hwnd);
981
982 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
983 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwndMessage,
984 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
985 else
986 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwnd,
987 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOTOWNER), hwnd);
988 }
989
990 ok(GetWindowRect(hwnd, &rc), "GetWindowRect failed\n");
991 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
992 ok(GetClientRect(hwnd, &rc), "GetClientRect failed\n");
993 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
994 }
995 break;
996 }
997 case HCBT_MOVESIZE:
998 case HCBT_MINMAX:
999 case HCBT_ACTIVATE:
1000 case HCBT_SETFOCUS:
1001 if (pGetWindowInfo && IsWindow(hwnd))
1002 {
1003 WINDOWINFO info;
1004
1005 /* Win98 actually does check the info.cbSize and doesn't allow
1006 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
1007 * WinXP do not check it at all.
1008 */
1009 info.cbSize = sizeof(WINDOWINFO);
1010 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
1011 verify_window_info(code_name, hwnd, &info);
1012 }
1013 break;
1014 /* on HCBT_DESTROYWND window state is undefined */
1015 case HCBT_DESTROYWND:
1016 trace( "HCBT_DESTROYWND: hwnd %p\n", hwnd );
1017 break;
1018 default:
1019 break;
1020 }
1021
1022 return CallNextHookEx(hhook, nCode, wParam, lParam);
1023 }
1024
1025 static void test_shell_window(void)
1026 {
1027 BOOL ret;
1028 DWORD error;
1029 HMODULE hinst, hUser32;
1030 BOOL (WINAPI*SetShellWindow)(HWND);
1031 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
1032 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
1033 HWND shellWindow, nextWnd;
1034
1035 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
1036 {
1037 trace("Skipping shell window test on Win9x\n");
1038 return;
1039 }
1040
1041 shellWindow = GetShellWindow();
1042 hinst = GetModuleHandle(0);
1043 hUser32 = GetModuleHandleA("user32");
1044
1045 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
1046 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
1047
1048 trace("previous shell window: %p\n", shellWindow);
1049
1050 if (shellWindow) {
1051 DWORD pid;
1052 HANDLE hProcess;
1053
1054 GetWindowThreadProcessId(shellWindow, &pid);
1055 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
1056 if (!hProcess)
1057 {
1058 skip( "cannot get access to shell process\n" );
1059 return;
1060 }
1061
1062 SetLastError(0xdeadbeef);
1063 ret = DestroyWindow(shellWindow);
1064 error = GetLastError();
1065
1066 ok(!ret, "DestroyWindow(shellWindow)\n");
1067 /* passes on Win XP, but not on Win98 */
1068 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
1069 "got %u after DestroyWindow(shellWindow)\n", error);
1070
1071 /* close old shell instance */
1072 ret = TerminateProcess(hProcess, 0);
1073 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1074 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
1075 CloseHandle(hProcess);
1076 }
1077
1078 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
1079 trace("created window 1: %p\n", hwnd1);
1080
1081 ret = SetShellWindow(hwnd1);
1082 ok(ret, "first call to SetShellWindow(hwnd1)\n");
1083 shellWindow = GetShellWindow();
1084 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
1085
1086 ret = SetShellWindow(hwnd1);
1087 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1088
1089 ret = SetShellWindow(0);
1090 error = GetLastError();
1091 /* passes on Win XP, but not on Win98
1092 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1093 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1094
1095 ret = SetShellWindow(hwnd1);
1096 /* passes on Win XP, but not on Win98
1097 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1098
1099 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1100 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
1101 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1102
1103 ret = DestroyWindow(hwnd1);
1104 ok(ret, "DestroyWindow(hwnd1)\n");
1105
1106 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1107 trace("created window 2: %p\n", hwnd2);
1108 ret = SetShellWindow(hwnd2);
1109 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1110
1111 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1112 trace("created window 3: %p\n", hwnd3);
1113
1114 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1115 trace("created window 4: %p\n", hwnd4);
1116
1117 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1118 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1119
1120 ret = SetShellWindow(hwnd4);
1121 ok(ret, "SetShellWindow(hwnd4)\n");
1122 shellWindow = GetShellWindow();
1123 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1124
1125 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1126 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1127
1128 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1129 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1130
1131 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1132 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1133
1134 ret = SetShellWindow(hwnd3);
1135 ok(!ret, "SetShellWindow(hwnd3)\n");
1136 shellWindow = GetShellWindow();
1137 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1138
1139 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1140 trace("created window 5: %p\n", hwnd5);
1141 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1142 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1143
1144 todo_wine
1145 {
1146 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1147 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1148 }
1149
1150 /* destroy test windows */
1151 DestroyWindow(hwnd2);
1152 DestroyWindow(hwnd3);
1153 DestroyWindow(hwnd4);
1154 DestroyWindow(hwnd5);
1155 }
1156
1157 /************** MDI test ****************/
1158
1159 static char mdi_lParam_test_message[] = "just a test string";
1160
1161 static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
1162 {
1163 MDICREATESTRUCTA mdi_cs;
1164 HWND mdi_child;
1165 INT_PTR id;
1166 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1167 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1168 BOOL isWin9x = FALSE;
1169
1170 mdi_cs.szClass = "MDI_child_Class_1";
1171 mdi_cs.szTitle = "MDI child";
1172 mdi_cs.hOwner = GetModuleHandle(0);
1173 mdi_cs.x = CW_USEDEFAULT;
1174 mdi_cs.y = CW_USEDEFAULT;
1175 mdi_cs.cx = CW_USEDEFAULT;
1176 mdi_cs.cy = CW_USEDEFAULT;
1177 mdi_cs.style = 0;
1178 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1179 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1180 ok(mdi_child != 0, "MDI child creation failed\n");
1181 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1182 ok(id == first_id, "wrong child id %ld\n", id);
1183 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1184 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1185
1186 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1187 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1188 ok(mdi_child != 0, "MDI child creation failed\n");
1189 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1190 ok(id == first_id, "wrong child id %ld\n", id);
1191 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1192 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1193
1194 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1195 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1196 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1197 {
1198 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1199 }
1200 else
1201 {
1202 ok(mdi_child != 0, "MDI child creation failed\n");
1203 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1204 ok(id == first_id, "wrong child id %ld\n", id);
1205 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1206 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1207 }
1208
1209 /* test MDICREATESTRUCT A<->W mapping */
1210 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1211 mdi_cs.style = 0;
1212 mdi_cs.szClass = (LPCSTR)classW;
1213 mdi_cs.szTitle = (LPCSTR)titleW;
1214 SetLastError(0xdeadbeef);
1215 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1216 if (!mdi_child)
1217 {
1218 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1219 isWin9x = TRUE;
1220 else
1221 ok(mdi_child != 0, "MDI child creation failed\n");
1222 }
1223 else
1224 {
1225 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1226 ok(id == first_id, "wrong child id %ld\n", id);
1227 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1228 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1229 }
1230
1231 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1232 0,
1233 CW_USEDEFAULT, CW_USEDEFAULT,
1234 CW_USEDEFAULT, CW_USEDEFAULT,
1235 mdi_client, GetModuleHandle(0),
1236 (LPARAM)mdi_lParam_test_message);
1237 ok(mdi_child != 0, "MDI child creation failed\n");
1238 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1239 ok(id == first_id, "wrong child id %ld\n", id);
1240 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1241 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1242
1243 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1244 0x7fffffff, /* without WS_POPUP */
1245 CW_USEDEFAULT, CW_USEDEFAULT,
1246 CW_USEDEFAULT, CW_USEDEFAULT,
1247 mdi_client, GetModuleHandle(0),
1248 (LPARAM)mdi_lParam_test_message);
1249 ok(mdi_child != 0, "MDI child creation failed\n");
1250 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1251 ok(id == first_id, "wrong child id %ld\n", id);
1252 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1253 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1254
1255 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1256 0xffffffff, /* with WS_POPUP */
1257 CW_USEDEFAULT, CW_USEDEFAULT,
1258 CW_USEDEFAULT, CW_USEDEFAULT,
1259 mdi_client, GetModuleHandle(0),
1260 (LPARAM)mdi_lParam_test_message);
1261 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1262 {
1263 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1264 }
1265 else
1266 {
1267 ok(mdi_child != 0, "MDI child creation failed\n");
1268 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1269 ok(id == first_id, "wrong child id %ld\n", id);
1270 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1271 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1272 }
1273
1274 /* test MDICREATESTRUCT A<->W mapping */
1275 SetLastError(0xdeadbeef);
1276 mdi_child = CreateMDIWindowW(classW, titleW,
1277 0,
1278 CW_USEDEFAULT, CW_USEDEFAULT,
1279 CW_USEDEFAULT, CW_USEDEFAULT,
1280 mdi_client, GetModuleHandle(0),
1281 (LPARAM)mdi_lParam_test_message);
1282 if (!mdi_child)
1283 {
1284 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1285 isWin9x = TRUE;
1286 else
1287 ok(mdi_child != 0, "MDI child creation failed\n");
1288 }
1289 else
1290 {
1291 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1292 ok(id == first_id, "wrong child id %ld\n", id);
1293 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1294 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1295 }
1296
1297 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1298 0,
1299 CW_USEDEFAULT, CW_USEDEFAULT,
1300 CW_USEDEFAULT, CW_USEDEFAULT,
1301 mdi_client, 0, GetModuleHandle(0),
1302 mdi_lParam_test_message);
1303 ok(mdi_child != 0, "MDI child creation failed\n");
1304 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1305 ok(id == first_id, "wrong child id %ld\n", id);
1306 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1307 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1308
1309 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1310 0x7fffffff, /* without WS_POPUP */
1311 CW_USEDEFAULT, CW_USEDEFAULT,
1312 CW_USEDEFAULT, CW_USEDEFAULT,
1313 mdi_client, 0, GetModuleHandle(0),
1314 mdi_lParam_test_message);
1315 ok(mdi_child != 0, "MDI child creation failed\n");
1316 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1317 ok(id == first_id, "wrong child id %ld\n", id);
1318 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1319 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1320
1321 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1322 0xffffffff, /* with WS_POPUP */
1323 CW_USEDEFAULT, CW_USEDEFAULT,
1324 CW_USEDEFAULT, CW_USEDEFAULT,
1325 mdi_client, 0, GetModuleHandle(0),
1326 mdi_lParam_test_message);
1327 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1328 {
1329 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1330 }
1331 else
1332 {
1333 ok(mdi_child != 0, "MDI child creation failed\n");
1334 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1335 ok(id == first_id, "wrong child id %ld\n", id);
1336 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1337 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1338 }
1339
1340 /* test MDICREATESTRUCT A<->W mapping */
1341 SetLastError(0xdeadbeef);
1342 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1343 0,
1344 CW_USEDEFAULT, CW_USEDEFAULT,
1345 CW_USEDEFAULT, CW_USEDEFAULT,
1346 mdi_client, 0, GetModuleHandle(0),
1347 mdi_lParam_test_message);
1348 if (!mdi_child)
1349 {
1350 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1351 isWin9x = TRUE;
1352 else
1353 ok(mdi_child != 0, "MDI child creation failed\n");
1354 }
1355 else
1356 {
1357 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1358 ok(id == first_id, "wrong child id %ld\n", id);
1359 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1360 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1361 }
1362
1363 /* This test fails on Win9x */
1364 if (!isWin9x)
1365 {
1366 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1367 WS_CHILD,
1368 CW_USEDEFAULT, CW_USEDEFAULT,
1369 CW_USEDEFAULT, CW_USEDEFAULT,
1370 parent, 0, GetModuleHandle(0),
1371 mdi_lParam_test_message);
1372 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1373 }
1374
1375 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1376 WS_CHILD, /* without WS_POPUP */
1377 CW_USEDEFAULT, CW_USEDEFAULT,
1378 CW_USEDEFAULT, CW_USEDEFAULT,
1379 mdi_client, 0, GetModuleHandle(0),
1380 mdi_lParam_test_message);
1381 ok(mdi_child != 0, "MDI child creation failed\n");
1382 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1383 ok(id == 0, "wrong child id %ld\n", id);
1384 DestroyWindow(mdi_child);
1385
1386 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1387 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1388 CW_USEDEFAULT, CW_USEDEFAULT,
1389 CW_USEDEFAULT, CW_USEDEFAULT,
1390 mdi_client, 0, GetModuleHandle(0),
1391 mdi_lParam_test_message);
1392 ok(mdi_child != 0, "MDI child creation failed\n");
1393 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1394 ok(id == 0, "wrong child id %ld\n", id);
1395 DestroyWindow(mdi_child);
1396
1397 /* maximized child */
1398 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1399 WS_CHILD | WS_MAXIMIZE,
1400 CW_USEDEFAULT, CW_USEDEFAULT,
1401 CW_USEDEFAULT, CW_USEDEFAULT,
1402 mdi_client, 0, GetModuleHandle(0),
1403 mdi_lParam_test_message);
1404 ok(mdi_child != 0, "MDI child creation failed\n");
1405 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1406 ok(id == 0, "wrong child id %ld\n", id);
1407 DestroyWindow(mdi_child);
1408
1409 trace("Creating maximized child with a caption\n");
1410 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1411 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1412 CW_USEDEFAULT, CW_USEDEFAULT,
1413 CW_USEDEFAULT, CW_USEDEFAULT,
1414 mdi_client, 0, GetModuleHandle(0),
1415 mdi_lParam_test_message);
1416 ok(mdi_child != 0, "MDI child creation failed\n");
1417 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1418 ok(id == 0, "wrong child id %ld\n", id);
1419 DestroyWindow(mdi_child);
1420
1421 trace("Creating maximized child with a caption and a thick frame\n");
1422 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1423 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1424 CW_USEDEFAULT, CW_USEDEFAULT,
1425 CW_USEDEFAULT, CW_USEDEFAULT,
1426 mdi_client, 0, GetModuleHandle(0),
1427 mdi_lParam_test_message);
1428 ok(mdi_child != 0, "MDI child creation failed\n");
1429 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1430 ok(id == 0, "wrong child id %ld\n", id);
1431 DestroyWindow(mdi_child);
1432 }
1433
1434 /**********************************************************************
1435 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1436 *
1437 * Note: The rule here is that client rect of the maximized MDI child
1438 * is equal to the client rect of the MDI client window.
1439 */
1440 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1441 {
1442 RECT rect;
1443
1444 GetClientRect( client, &rect );
1445 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1446 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1447
1448 rect.right -= rect.left;
1449 rect.bottom -= rect.top;
1450 lpMinMax->ptMaxSize.x = rect.right;
1451 lpMinMax->ptMaxSize.y = rect.bottom;
1452
1453 lpMinMax->ptMaxPosition.x = rect.left;
1454 lpMinMax->ptMaxPosition.y = rect.top;
1455
1456 trace("max rect (%d,%d - %d, %d)\n",
1457 rect.left, rect.top, rect.right, rect.bottom);
1458 }
1459
1460 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1461 {
1462 switch (msg)
1463 {
1464 case WM_NCCREATE:
1465 case WM_CREATE:
1466 {
1467 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1468 MDICREATESTRUCTA *mdi_cs = cs->lpCreateParams;
1469
1470 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1471 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1472
1473 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1474 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1475 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1476 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1477 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1478
1479 /* MDICREATESTRUCT should have original values */
1480 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1481 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1482 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1483 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1484 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1485 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1486
1487 /* CREATESTRUCT should have fixed values */
1488 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1489 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1490
1491 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1492 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1493 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1494
1495 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1496
1497 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1498 {
1499 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1500 ok(cs->style == style,
1501 "cs->style does not match (%08x)\n", cs->style);
1502 }
1503 else
1504 {
1505 LONG style = mdi_cs->style;
1506 style &= ~WS_POPUP;
1507 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1508 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1509 ok(cs->style == style,
1510 "cs->style does not match (%08x)\n", cs->style);
1511 }
1512 break;
1513 }
1514
1515 case WM_GETMINMAXINFO:
1516 {
1517 HWND client = GetParent(hwnd);
1518 RECT rc;
1519 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1520 MINMAXINFO my_minmax;
1521 LONG style, exstyle;
1522
1523 style = GetWindowLongA(hwnd, GWL_STYLE);
1524 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1525
1526 GetWindowRect(client, &rc);
1527 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1528 GetClientRect(client, &rc);
1529 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1530 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1531 GetSystemMetrics(SM_CYSCREEN));
1532
1533 GetClientRect(client, &rc);
1534 if ((style & WS_CAPTION) == WS_CAPTION)
1535 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1536 AdjustWindowRectEx(&rc, style, 0, exstyle);
1537 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1538 dump_minmax_info( minmax );
1539
1540 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1541 minmax->ptMaxSize.x, rc.right - rc.left);
1542 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1543 minmax->ptMaxSize.y, rc.bottom - rc.top);
1544
1545 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1546
1547 trace("DefMDIChildProc returned:\n");
1548 dump_minmax_info( minmax );
1549
1550 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1551 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1552 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1553 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1554 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1555
1556 return 1;
1557 }
1558
1559 case WM_MDIACTIVATE:
1560 {
1561 HWND active, client = GetParent(hwnd);
1562 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1563 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1564 if (hwnd == (HWND)lparam) /* if we are being activated */
1565 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1566 else
1567 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1568 break;
1569 }
1570 }
1571 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1572 }
1573
1574 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1575 {
1576 switch (msg)
1577 {
1578 case WM_NCCREATE:
1579 case WM_CREATE:
1580 {
1581 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1582
1583 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE",
1584 cs->x, cs->y, cs->cx, cs->cy);
1585
1586 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1587 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1588
1589 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1590 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1591
1592 /* CREATESTRUCT should have fixed values */
1593 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1594 while NT does. */
1595 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1596 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1597
1598 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1599 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1600 while Win95, Win2k, WinXP do. */
1601 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1602 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1603 break;
1604 }
1605
1606 case WM_GETMINMAXINFO:
1607 {
1608 HWND parent = GetParent(hwnd);
1609 RECT rc;
1610 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1611 LONG style, exstyle;
1612
1613 style = GetWindowLongA(hwnd, GWL_STYLE);
1614 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1615
1616 GetClientRect(parent, &rc);
1617 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1618
1619 GetClientRect(parent, &rc);
1620 if ((style & WS_CAPTION) == WS_CAPTION)
1621 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1622 AdjustWindowRectEx(&rc, style, 0, exstyle);
1623 dump_minmax_info( minmax );
1624
1625 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1626 minmax->ptMaxSize.x, rc.right - rc.left);
1627 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1628 minmax->ptMaxSize.y, rc.bottom - rc.top);
1629 break;
1630 }
1631
1632 case WM_WINDOWPOSCHANGED:
1633 {
1634 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1635 RECT rc1, rc2;
1636
1637 GetWindowRect(hwnd, &rc1);
1638 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1639 /* note: winpos coordinates are relative to parent */
1640 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1641 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) pos=(%d,%d)-(%d,%d)\n",
1642 rc1.left, rc1.top, rc1.right, rc1.bottom,
1643 rc2.left, rc2.top, rc2.right, rc2.bottom);
1644 GetWindowRect(hwnd, &rc1);
1645 GetClientRect(hwnd, &rc2);
1646 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1647 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1648 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1649 rc1.left, rc1.top, rc1.right, rc1.bottom,
1650 rc2.left, rc2.top, rc2.right, rc2.bottom);
1651 }
1652 /* fall through */
1653 case WM_WINDOWPOSCHANGING:
1654 {
1655 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1656 WINDOWPOS my_winpos = *winpos;
1657
1658 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1659 (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
1660 winpos->hwnd, winpos->hwndInsertAfter,
1661 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1662
1663 DefWindowProcA(hwnd, msg, wparam, lparam);
1664
1665 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1666 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1667 winpos->hwnd, winpos->hwndInsertAfter,
1668 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1669
1670 return 1;
1671 }
1672 }
1673 return DefWindowProcA(hwnd, msg, wparam, lparam);
1674 }
1675
1676 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1677 {
1678 static HWND mdi_client;
1679
1680 switch (msg)
1681 {
1682 case WM_CREATE:
1683 {
1684 CLIENTCREATESTRUCT client_cs;
1685 RECT rc;
1686
1687 GetClientRect(hwnd, &rc);
1688
1689 client_cs.hWindowMenu = 0;
1690 client_cs.idFirstChild = 1;
1691
1692 /* MDIClient without MDIS_ALLCHILDSTYLES */
1693 mdi_client = CreateWindowExA(0, "mdiclient",
1694 NULL,
1695 WS_CHILD /*| WS_VISIBLE*/,
1696 /* tests depend on a not zero MDIClient size */
1697 0, 0, rc.right, rc.bottom,
1698 hwnd, 0, GetModuleHandle(0),
1699 &client_cs);
1700 assert(mdi_client);
1701 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1702 DestroyWindow(mdi_client);
1703
1704 /* MDIClient with MDIS_ALLCHILDSTYLES */
1705 mdi_client = CreateWindowExA(0, "mdiclient",
1706 NULL,
1707 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1708 /* tests depend on a not zero MDIClient size */
1709 0, 0, rc.right, rc.bottom,
1710 hwnd, 0, GetModuleHandle(0),
1711 &client_cs);
1712 assert(mdi_client);
1713 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1714 DestroyWindow(mdi_client);
1715 break;
1716 }
1717
1718 case WM_WINDOWPOSCHANGED:
1719 {
1720 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1721 RECT rc1, rc2;
1722
1723 GetWindowRect(hwnd, &rc1);
1724 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1725 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1726 /* note: winpos coordinates are relative to parent */
1727 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1728 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1729 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1730
1731 GetWindowRect(hwnd, &rc1);
1732 GetClientRect(hwnd, &rc2);
1733 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1734 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1735 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1736 }
1737 /* fall through */
1738 case WM_WINDOWPOSCHANGING:
1739 {
1740 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1741 WINDOWPOS my_winpos = *winpos;
1742
1743 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1744 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1745 winpos->hwnd, winpos->hwndInsertAfter,
1746 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1747
1748 DefWindowProcA(hwnd, msg, wparam, lparam);
1749
1750 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1751 winpos->hwnd, winpos->hwndInsertAfter,
1752 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1753
1754 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1755 "DefWindowProc should not change WINDOWPOS values\n");
1756
1757 return 1;
1758 }
1759
1760 case WM_CLOSE:
1761 PostQuitMessage(0);
1762 break;
1763 }
1764 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1765 }
1766
1767 static BOOL mdi_RegisterWindowClasses(void)
1768 {
1769 WNDCLASSA cls;
1770
1771 cls.style = 0;
1772 cls.lpfnWndProc = mdi_main_wnd_procA;
1773 cls.cbClsExtra = 0;
1774 cls.cbWndExtra = 0;
1775 cls.hInstance = GetModuleHandleA(0);
1776 cls.hIcon = 0;
1777 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1778 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1779 cls.lpszMenuName = NULL;
1780 cls.lpszClassName = "MDI_parent_Class";
1781 if(!RegisterClassA(&cls)) return FALSE;
1782
1783 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1784 cls.lpszClassName = "MDI_child_Class_1";
1785 if(!RegisterClassA(&cls)) return FALSE;
1786
1787 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1788 cls.lpszClassName = "MDI_child_Class_2";
1789 if(!RegisterClassA(&cls)) return FALSE;
1790
1791 return TRUE;
1792 }
1793
1794 static void test_mdi(void)
1795 {
1796 HWND mdi_hwndMain;
1797 /*MSG msg;*/
1798
1799 if (!mdi_RegisterWindowClasses()) assert(0);
1800
1801 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1802 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1803 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1804 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1805 GetDesktopWindow(), 0,
1806 GetModuleHandle(0), NULL);
1807 assert(mdi_hwndMain);
1808 /*
1809 while(GetMessage(&msg, 0, 0, 0))
1810 {
1811 TranslateMessage(&msg);
1812 DispatchMessage(&msg);
1813 }
1814 */
1815 DestroyWindow(mdi_hwndMain);
1816 }
1817
1818 static void test_icons(void)
1819 {
1820 WNDCLASSEXA cls;
1821 HWND hwnd;
1822 HICON icon = LoadIconA(0, IDI_APPLICATION);
1823 HICON icon2 = LoadIconA(0, IDI_QUESTION);
1824 HICON small_icon = LoadImageA(0, IDI_APPLICATION, IMAGE_ICON,
1825 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1826 HICON res;
1827
1828 cls.cbSize = sizeof(cls);
1829 cls.style = 0;
1830 cls.lpfnWndProc = DefWindowProcA;
1831 cls.cbClsExtra = 0;
1832 cls.cbWndExtra = 0;
1833 cls.hInstance = 0;
1834 cls.hIcon = LoadIconA(0, IDI_HAND);
1835 cls.hIconSm = small_icon;
1836 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1837 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1838 cls.lpszMenuName = NULL;
1839 cls.lpszClassName = "IconWindowClass";
1840
1841 RegisterClassExA(&cls);
1842
1843 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1844 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1845 assert( hwnd );
1846
1847 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1848 ok( res == 0, "wrong big icon %p/0\n", res );
1849 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1850 ok( res == 0, "wrong previous big icon %p/0\n", res );
1851 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1852 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1853 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1854 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1855 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1856 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1857
1858 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1859 ok( res == 0, "wrong small icon %p/0\n", res );
1860 /* this test is XP specific */
1861 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1862 ok( res != 0, "wrong small icon %p\n", res );*/
1863 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1864 ok( res == 0, "wrong previous small icon %p/0\n", res );
1865 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1866 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1867 /* this test is XP specific */
1868 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1869 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1870 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1871 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1872 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1873 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1874 /* this test is XP specific */
1875 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1876 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1877
1878 /* make sure the big icon hasn't changed */
1879 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1880 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1881
1882 DestroyWindow( hwnd );
1883 }
1884
1885 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1886 {
1887 if (msg == WM_NCCALCSIZE)
1888 {
1889 RECT *rect = (RECT *)lparam;
1890 /* first time around increase the rectangle, next time decrease it */
1891 if (rect->left == 100) InflateRect( rect, 10, 10 );
1892 else InflateRect( rect, -10, -10 );
1893 return 0;
1894 }
1895 return DefWindowProc( hwnd, msg, wparam, lparam );
1896 }
1897
1898 static void test_SetWindowPos(HWND hwnd)
1899 {
1900 RECT orig_win_rc, rect;
1901 LONG_PTR old_proc;
1902 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1903
1904 SetRect(&rect, 111, 222, 333, 444);
1905 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1906 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1907 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1908
1909 SetRect(&rect, 111, 222, 333, 444);
1910 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1911 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1912 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1913
1914 GetWindowRect(hwnd, &orig_win_rc);
1915
1916 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1917 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1918 GetWindowRect( hwnd, &rect );
1919 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1920 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1921 GetClientRect( hwnd, &rect );
1922 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1923 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1924 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1925
1926 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1927 GetWindowRect( hwnd, &rect );
1928 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1929 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1930 GetClientRect( hwnd, &rect );
1931 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1932 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1933 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1934
1935 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1936 orig_win_rc.right, orig_win_rc.bottom, 0);
1937 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1938
1939 /* Win9x truncates coordinates to 16-bit irrespectively */
1940 if (!is_win9x)
1941 {
1942 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1943 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1944
1945 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1946 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1947 }
1948
1949 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1950 orig_win_rc.right, orig_win_rc.bottom, 0);
1951
1952 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1953 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1954 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1955 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1956 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1957 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1958 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1959 }
1960
1961 static void test_SetMenu(HWND parent)
1962 {
1963 HWND child;
1964 HMENU hMenu, ret;
1965 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1966 BOOL retok;
1967 DWORD style;
1968
1969 hMenu = CreateMenu();
1970 assert(hMenu);
1971
1972 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1973 if (0)
1974 {
1975 /* fails on (at least) Wine, NT4, XP SP2 */
1976 test_nonclient_area(parent);
1977 }
1978 ret = GetMenu(parent);
1979 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1980 /* test whether we can destroy a menu assigned to a window */
1981 retok = DestroyMenu(hMenu);
1982 ok( retok, "DestroyMenu error %d\n", GetLastError());
1983 retok = IsMenu(hMenu);
1984 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
1985 ret = GetMenu(parent);
1986 /* This test fails on Win9x */
1987 if (!is_win9x)
1988 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1989 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1990 test_nonclient_area(parent);
1991
1992 hMenu = CreateMenu();
1993 assert(hMenu);
1994
1995 /* parent */
1996 ret = GetMenu(parent);
1997 ok(ret == 0, "unexpected menu id %p\n", ret);
1998
1999 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2000 test_nonclient_area(parent);
2001 ret = GetMenu(parent);
2002 ok(ret == 0, "unexpected menu id %p\n", ret);
2003
2004 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2005 if (0)
2006 {
2007 /* fails on (at least) Wine, NT4, XP SP2 */
2008 test_nonclient_area(parent);
2009 }
2010 ret = GetMenu(parent);
2011 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2012
2013 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2014 test_nonclient_area(parent);
2015 ret = GetMenu(parent);
2016 ok(ret == 0, "unexpected menu id %p\n", ret);
2017
2018 /* child */
2019 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
2020 assert(child);
2021
2022 ret = GetMenu(child);
2023 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2024
2025 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2026 test_nonclient_area(child);
2027 ret = GetMenu(child);
2028 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2029
2030 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
2031 test_nonclient_area(child);
2032 ret = GetMenu(child);
2033 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2034
2035 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
2036 test_nonclient_area(child);
2037 ret = GetMenu(child);
2038 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2039
2040 style = GetWindowLong(child, GWL_STYLE);
2041 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
2042 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
2043 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
2044 SetWindowLong(child, GWL_STYLE, style);
2045
2046 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
2047 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
2048 SetWindowLong(child, GWL_STYLE, style);
2049
2050 DestroyWindow(child);
2051 DestroyMenu(hMenu);
2052 }
2053
2054 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
2055 {
2056 HWND child[5], hwnd;
2057 INT_PTR i;
2058
2059 assert(total <= 5);
2060
2061 hwnd = GetWindow(parent, GW_CHILD);
2062 ok(!hwnd, "have to start without children to perform the test\n");
2063
2064 for (i = 0; i < total; i++)
2065 {
2066 if (style[i] & DS_CONTROL)
2067 {
2068 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
2069 0,0,0,0, parent, (HMENU)i, 0, NULL);
2070 if (style[i] & WS_VISIBLE)
2071 ShowWindow(child[i], SW_SHOW);
2072
2073 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
2074 }
2075 else
2076 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
2077 parent, (HMENU)i, 0, NULL);
2078 trace("child[%ld] = %p\n", i, child[i]);
2079 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
2080 }
2081
2082 hwnd = GetWindow(parent, GW_CHILD);
2083 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
2084 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
2085 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
2086
2087 for (i = 0; i < total; i++)
2088 {
2089 trace("hwnd[%ld] = %p\n", i, hwnd);
2090 ok(child[order[i]] == hwnd, "Z order of child #%ld is wrong\n", i);
2091
2092 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
2093 }
2094
2095 for (i = 0; i < total; i++)
2096 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2097 }
2098
2099 static void test_children_zorder(HWND parent)
2100 {
2101 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2102 WS_CHILD };
2103 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2104
2105 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2106 WS_CHILD | WS_VISIBLE, WS_CHILD,
2107 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2108 const int complex_order_1[1] = { 0 };
2109 const int complex_order_2[2] = { 1, 0 };
2110 const int complex_order_3[3] = { 1, 0, 2 };
2111 const int complex_order_4[4] = { 1, 0, 2, 3 };
2112 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2113 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2114 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2115 WS_CHILD | WS_VISIBLE };
2116 const int complex_order_6[3] = { 0, 1, 2 };
2117
2118 /* simple WS_CHILD */
2119 test_window_tree(parent, simple_style, simple_order, 5);
2120
2121 /* complex children styles */
2122 test_window_tree(parent, complex_style, complex_order_1, 1);
2123 test_window_tree(parent, complex_style, complex_order_2, 2);
2124 test_window_tree(parent, complex_style, complex_order_3, 3);
2125 test_window_tree(parent, complex_style, complex_order_4, 4);
2126 test_window_tree(parent, complex_style, complex_order_5, 5);
2127
2128 /* another set of complex children styles */
2129 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2130 }
2131
2132 #define check_z_order(hwnd, next, prev, owner, topmost) \
2133 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2134 __FILE__, __LINE__)
2135
2136 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2137 BOOL topmost, const char *file, int line)
2138 {
2139 HWND test;
2140 DWORD ex_style;
2141
2142 test = GetWindow(hwnd, GW_HWNDNEXT);
2143 /* skip foreign windows */
2144 while (test && test != next &&
2145 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2146 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2147 GetWindow(test, GW_OWNER) == next))
2148 {
2149 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2150 test = GetWindow(test, GW_HWNDNEXT);
2151 }
2152 ok_(file, line)(next == test, "expected next %p, got %p\n", next, test);
2153
2154 test = GetWindow(hwnd, GW_HWNDPREV);
2155 /* skip foreign windows */
2156 while (test && test != prev &&
2157 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2158 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2159 GetWindow(test, GW_OWNER) == hwnd))
2160 {
2161 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2162 test = GetWindow(test, GW_HWNDPREV);
2163 }
2164 ok_(file, line)(prev == test, "expected prev %p, got %p\n", prev, test);
2165
2166 test = GetWindow(hwnd, GW_OWNER);
2167 ok_(file, line)(owner == test, "expected owner %p, got %p\n", owner, test);
2168
2169 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2170 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "expected %stopmost\n", topmost ? "" : "NOT ");
2171 }
2172
2173 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E)
2174 {
2175 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2176
2177 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2178
2179 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2180
2181 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2182 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2183
2184 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2185 WS_OVERLAPPED | WS_CAPTION,
2186 100, 100, 100, 100,
2187 0, 0, GetModuleHandle(0), NULL);
2188 trace("hwnd_F %p\n", hwnd_F);
2189 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2190
2191 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2192 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2193 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2194 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2195
2196 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2197 WS_POPUP,
2198 100, 100, 100, 100,
2199 hwnd_F, 0, GetModuleHandle(0), NULL);
2200 trace("hwnd_C %p\n", hwnd_C);
2201 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2202 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2203 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2204 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2205
2206 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2207 WS_POPUP,
2208 100, 100, 100, 100,
2209 hwnd_F, 0, GetModuleHandle(0), NULL);
2210 trace("hwnd_B %p\n", hwnd_B);
2211 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2212 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2213 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2214 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2215 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2216
2217 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2218 WS_POPUP,
2219 100, 100, 100, 100,
2220 0, 0, GetModuleHandle(0), NULL);
2221 trace("hwnd_A %p\n", hwnd_A);
2222 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2223 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2224 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2225 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2226 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2227 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2228
2229 trace("A %p B %p C %p D %p E %p F %p\n", hwnd_A, hwnd_B, hwnd_C, hwnd_D, hwnd_E, hwnd_F);
2230
2231 /* move hwnd_F and its popups up */
2232 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2233 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2234 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2235 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2236 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2237 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2238 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2239
2240 /* move hwnd_F and its popups down */
2241 #if 0 /* enable once Wine is fixed to pass this test */
2242 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2243 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2244 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2245 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2246 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2247 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2248 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2249 #endif
2250
2251 DestroyWindow(hwnd_A);
2252 DestroyWindow(hwnd_B);
2253 DestroyWindow(hwnd_C);
2254 DestroyWindow(hwnd_F);
2255 }
2256
2257 static void test_vis_rgn( HWND hwnd )
2258 {
2259 RECT win_rect, rgn_rect;
2260 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2261 HDC hdc;
2262
2263 ShowWindow(hwnd,SW_SHOW);
2264 hdc = GetDC( hwnd );
2265 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2266 GetWindowRect( hwnd, &win_rect );
2267 GetRgnBox( hrgn, &rgn_rect );
2268 if (GetVersion() & 0x80000000)
2269 {
2270 trace("win9x, mapping to screen coords\n");
2271 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2272 }
2273 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2274 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2275 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2276 rgn_rect.left, win_rect.left );
2277 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2278 rgn_rect.top, win_rect.top );
2279 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2280 rgn_rect.right, win_rect.right );
2281 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2282 rgn_rect.bottom, win_rect.bottom );
2283 ReleaseDC( hwnd, hdc );
2284 }
2285
2286 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2287 {
2288 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2289 {
2290 HWND child = GetWindow(hwnd, GW_CHILD);
2291 ok(child != 0, "couldn't find child window\n");
2292 SetFocus(child);
2293 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2294 return 0;
2295 }
2296 return DefWindowProc(hwnd, msg, wp, lp);
2297 }
2298
2299 static void test_SetFocus(HWND hwnd)
2300 {
2301 HWND child, child2;
2302 WNDPROC old_wnd_proc;
2303
2304 /* check if we can set focus to non-visible windows */
2305
2306 ShowWindow(hwnd, SW_SHOW);
2307 SetFocus(0);
2308 SetFocus(hwnd);
2309 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2310 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2311 ShowWindow(hwnd, SW_HIDE);
2312 SetFocus(0);
2313 SetFocus(hwnd);
2314 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2315 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2316 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2317 assert(child);
2318 SetFocus(child);
2319 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2320 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2321 ShowWindow(child, SW_SHOW);
2322 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2323 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2324 ShowWindow(child, SW_HIDE);
2325 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2326 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2327 ShowWindow(child, SW_SHOW);
2328 child2 = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, child, 0, 0, NULL);
2329 assert(child2);
2330 ShowWindow(child2, SW_SHOW);
2331 SetFocus(child2);
2332 ShowWindow(child, SW_HIDE);
2333 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2334 ok( GetFocus() == child2, "Focus should be on %p, not %p\n", child2, GetFocus() );
2335 ShowWindow(child, SW_SHOW);
2336 SetFocus(child);
2337 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2338 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2339 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2340
2341 ShowWindow(child, SW_HIDE);
2342 SetFocus(hwnd);
2343 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2344 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2345 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2346 ShowWindow(child, SW_HIDE);
2347 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2348
2349 ShowWindow(hwnd, SW_SHOW);
2350 ShowWindow(child, SW_SHOW);
2351 SetFocus(child);
2352 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2353 EnableWindow(hwnd, FALSE);
2354 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2355 EnableWindow(hwnd, TRUE);
2356
2357 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2358 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2359 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2360 todo_wine
2361 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2362 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2363 ShowWindow(hwnd, SW_RESTORE);
2364 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2365 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2366 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2367 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2368 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2369 todo_wine
2370 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2371 old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2372 ShowWindow(hwnd, SW_RESTORE);
2373 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2374 todo_wine
2375 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2376
2377 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2378
2379 DestroyWindow( child2 );
2380 DestroyWindow( child );
2381 }
2382
2383 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
2384 static void check_wnd_state_(const char *file, int line,
2385 HWND active, HWND foreground, HWND focus, HWND capture)
2386 {
2387 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2388 /* only check foreground if it belongs to the current thread */
2389 /* foreground can be moved to a different app pretty much at any time */
2390 if (foreground && GetForegroundWindow() &&
2391 GetWindowThreadProcessId(GetForegroundWindow(), NULL) == GetCurrentThreadId())
2392 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2393 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2394 ok_(file, line)(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2395 }
2396
2397 static void test_SetActiveWindow(HWND hwnd)
2398 {
2399 HWND hwnd2;
2400
2401 flush_events( TRUE );
2402 ShowWindow(hwnd, SW_HIDE);
2403 SetFocus(0);
2404 SetActiveWindow(0);
2405 check_wnd_state(0, 0, 0, 0);
2406
2407 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2408
2409 ShowWindow(hwnd, SW_SHOW);
2410 check_wnd_state(hwnd, hwnd, hwnd, 0);
2411
2412 hwnd2 = SetActiveWindow(0);
2413 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2414 if (!GetActiveWindow()) /* doesn't always work on vista */
2415 {
2416 check_wnd_state(0, 0, 0, 0);
2417 hwnd2 = SetActiveWindow(hwnd);
2418 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2419 }
2420 check_wnd_state(hwnd, hwnd, hwnd, 0);
2421
2422 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2423 check_wnd_state(hwnd, hwnd, hwnd, 0);
2424
2425 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2426 check_wnd_state(hwnd, hwnd, hwnd, 0);
2427
2428 ShowWindow(hwnd, SW_HIDE);
2429 check_wnd_state(0, 0, 0, 0);
2430
2431 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2432 SetActiveWindow(hwnd);
2433 check_wnd_state(hwnd, hwnd, hwnd, 0);
2434
2435 ShowWindow(hwnd, SW_SHOW);
2436 check_wnd_state(hwnd, hwnd, hwnd, 0);
2437
2438 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2439 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2440
2441 DestroyWindow(hwnd2);
2442 check_wnd_state(hwnd, hwnd, hwnd, 0);
2443
2444 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2445 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2446
2447 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2448 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2449
2450 DestroyWindow(hwnd2);
2451 check_wnd_state(hwnd, hwnd, hwnd, 0);
2452 }
2453
2454 static void test_SetForegroundWindow(HWND hwnd)
2455 {
2456 BOOL ret;
2457 HWND hwnd2;
2458
2459 flush_events( TRUE );
2460 ShowWindow(hwnd, SW_HIDE);
2461 SetFocus(0);
2462 SetActiveWindow(0);
2463 check_wnd_state(0, 0, 0, 0);
2464
2465 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2466
2467 ShowWindow(hwnd, SW_SHOW);
2468 check_wnd_state(hwnd, hwnd, hwnd, 0);
2469
2470 hwnd2 = SetActiveWindow(0);
2471 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2472 if (GetActiveWindow() == hwnd) /* doesn't always work on vista */
2473 check_wnd_state(hwnd, hwnd, hwnd, 0);
2474 else
2475 check_wnd_state(0, 0, 0, 0);
2476
2477 ret = SetForegroundWindow(hwnd);
2478 if (!ret)
2479 {
2480 skip( "SetForegroundWindow not working\n" );
2481 return;
2482 }
2483 check_wnd_state(hwnd, hwnd, hwnd, 0);
2484
2485 SetLastError(0xdeadbeef);
2486 ret = SetForegroundWindow(0);
2487 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2488 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
2489 broken(GetLastError() == 0xdeadbeef), /* win9x */
2490 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2491 check_wnd_state(hwnd, hwnd, hwnd, 0);
2492
2493 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2494 check_wnd_state(hwnd, hwnd, hwnd, 0);
2495
2496 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2497 check_wnd_state(hwnd, hwnd, hwnd, 0);
2498
2499 hwnd2 = GetForegroundWindow();
2500 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2501 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2502 hwnd2 = GetForegroundWindow();
2503 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2504
2505 ShowWindow(hwnd, SW_HIDE);
2506 check_wnd_state(0, 0, 0, 0);
2507
2508 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2509 ret = SetForegroundWindow(hwnd);
2510 ok(ret || broken(!ret), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
2511 check_wnd_state(hwnd, hwnd, hwnd, 0);
2512
2513 ShowWindow(hwnd, SW_SHOW);
2514 check_wnd_state(hwnd, hwnd, hwnd, 0);
2515
2516 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2517 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2518
2519 DestroyWindow(hwnd2);
2520 check_wnd_state(hwnd, hwnd, hwnd, 0);
2521
2522 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2523 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2524
2525 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2526 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2527
2528 DestroyWindow(hwnd2);
2529 check_wnd_state(hwnd, hwnd, hwnd, 0);
2530 }
2531
2532 static WNDPROC old_button_proc;
2533
2534 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2535 {
2536 LRESULT ret;
2537 USHORT key_state;
2538
2539 key_state = GetKeyState(VK_LBUTTON);
2540 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2541
2542 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2543
2544 if (msg == WM_LBUTTONDOWN)
2545 {
2546 HWND hwnd, capture;
2547
2548 check_wnd_state(button, button, button, button);
2549
2550 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2551 assert(hwnd);
2552 trace("hwnd %p\n", hwnd);
2553
2554 check_wnd_state(button, button, button, button);
2555
2556 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2557
2558 check_wnd_state(button, button, button, button);
2559
2560 DestroyWindow(hwnd);
2561
2562 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2563 assert(hwnd);
2564 trace("hwnd %p\n", hwnd);
2565
2566 check_wnd_state(button, button, button, button);
2567
2568 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2569 * match internal button state.
2570 */
2571 SendMessage(button, WM_KILLFOCUS, 0, 0);
2572 check_wnd_state(button, button, button, 0);
2573
2574 ShowWindow(hwnd, SW_SHOW);
2575 check_wnd_state(hwnd, hwnd, hwnd, 0);
2576
2577 capture = SetCapture(hwnd);
2578 ok(capture == 0, "SetCapture() = %p\n", capture);
2579
2580 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2581
2582 DestroyWindow(hwnd);
2583
2584 check_wnd_state(button, 0, button, 0);
2585 }
2586
2587 return ret;
2588 }
2589
2590 static void test_capture_1(void)
2591 {
2592 HWND button, capture, oldFocus, oldActive;
2593
2594 oldFocus = GetFocus();
2595 oldActive = GetActiveWindow();
2596
2597 capture = GetCapture();
2598 ok(capture == 0, "GetCapture() = %p\n", capture);
2599
2600 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2601 assert(button);
2602 trace("button %p\n", button);
2603
2604 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2605
2606 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2607
2608 capture = SetCapture(button);
2609 ok(capture == 0, "SetCapture() = %p\n", capture);
2610 check_wnd_state(button, 0, button, button);
2611
2612 DestroyWindow(button);
2613 check_wnd_state(oldActive, 0, oldFocus, 0);
2614 }
2615
2616 static void test_capture_2(void)
2617 {
2618 HWND button, hwnd, capture, oldFocus, oldActive;
2619
2620 oldFocus = GetFocus();
2621 oldActive = GetActiveWindow();
2622 check_wnd_state(oldActive, 0, oldFocus, 0);
2623
2624 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2625 assert(button);
2626 trace("button %p\n", button);
2627
2628 check_wnd_state(button, button, button, 0);
2629
2630 capture = SetCapture(button);
2631 ok(capture == 0, "SetCapture() = %p\n", capture);
2632
2633 check_wnd_state(button, button, button, button);
2634
2635 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2636 * internal button state.
2637 */
2638 SendMessage(button, WM_KILLFOCUS, 0, 0);
2639 check_wnd_state(button, button, button, button);
2640
2641 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2642 assert(hwnd);
2643 trace("hwnd %p\n", hwnd);
2644
2645 check_wnd_state(button, button, button, button);
2646
2647 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2648
2649 check_wnd_state(button, button, button, button);
2650
2651 DestroyWindow(hwnd);
2652
2653 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2654 assert(hwnd);
2655 trace("hwnd %p\n", hwnd);
2656
2657 check_wnd_state(button, button, button, button);
2658
2659 ShowWindow(hwnd, SW_SHOW);
2660
2661 check_wnd_state(hwnd, hwnd, hwnd, button);
2662
2663 capture = SetCapture(hwnd);
2664 ok(capture == button, "SetCapture() = %p\n", capture);
2665
2666 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2667
2668 DestroyWindow(hwnd);
2669 check_wnd_state(button, button, button, 0);
2670
2671 DestroyWindow(button);
2672 check_wnd_state(oldActive, 0, oldFocus, 0);
2673 }
2674
2675 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2676 {
2677 BOOL ret;
2678
2679 ShowWindow(hwnd1, SW_HIDE);
2680 ShowWindow(hwnd2, SW_HIDE);
2681
2682 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2683 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2684
2685 SetCapture(hwnd1);
2686 check_wnd_state(0, 0, 0, hwnd1);
2687
2688 SetCapture(hwnd2);
2689 check_wnd_state(0, 0, 0, hwnd2);
2690
2691 ShowWindow(hwnd1, SW_SHOW);
2692 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2693
2694 ret = ReleaseCapture();
2695 ok (ret, "releasecapture did not return TRUE.\n");
2696 ret = ReleaseCapture();
2697 ok (ret, "releasecapture did not return TRUE after second try.\n");
2698 }
2699
2700 /* PeekMessage wrapper that ignores the messages we don't care about */
2701 static BOOL peek_message( MSG *msg )
2702 {
2703 BOOL ret;
2704 do
2705 {
2706 ret = PeekMessageA(msg, 0, 0, 0, PM_REMOVE);
2707 } while (ret && (msg->message == WM_TIMER || ignore_message(msg->message)));
2708 return ret;
2709 }
2710
2711 static void test_keyboard_input(HWND hwnd)
2712 {
2713 MSG msg;
2714 BOOL ret;
2715
2716 flush_events( TRUE );
2717 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
2718 UpdateWindow(hwnd);
2719 flush_events( TRUE );
2720
2721 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2722
2723 SetFocus(hwnd);
2724 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2725
2726 flush_events( TRUE );
2727
2728 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2729 ret = peek_message(&msg);
2730 ok( ret, "no message available\n");
2731 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2732 ret = peek_message(&msg);
2733 ok( !ret, "message %04x available\n", msg.message);
2734
2735 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2736
2737 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2738 ret = peek_message(&msg);
2739 ok(ret, "no message available\n");
2740 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2741 ret = peek_message(&msg);
2742 ok( !ret, "message %04x available\n", msg.message);
2743
2744 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2745
2746 keybd_event(VK_SPACE, 0, 0, 0);
2747 if (!peek_message(&msg))
2748 {
2749 skip( "keybd_event didn't work, skipping keyboard test\n" );
2750 return;
2751 }
2752 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2753 ret = peek_message(&msg);
2754 ok( !ret, "message %04x available\n", msg.message);
2755
2756 SetFocus(0);
2757 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2758
2759 flush_events( TRUE );
2760
2761 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2762 ret = peek_message(&msg);
2763 ok(ret, "no message available\n");
2764 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2765 ret = peek_message(&msg);
2766 ok( !ret, "message %04x available\n", msg.message);
2767
2768 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2769
2770 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2771 ret = peek_message(&msg);
2772 ok(ret, "no message available\n");
2773 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2774 ret = peek_message(&msg);
2775 ok( !ret, "message %04x available\n", msg.message);
2776
2777 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2778
2779 keybd_event(VK_SPACE, 0, 0, 0);
2780 ret = peek_message(&msg);
2781 ok(ret, "no message available\n");
2782 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2783 ret = peek_message(&msg);
2784 ok( !ret, "message %04x available\n", msg.message);
2785 }
2786
2787 static BOOL wait_for_message( MSG *msg )
2788 {
2789 BOOL ret;
2790
2791 for (;;)
2792 {
2793 ret = peek_message(msg);
2794 if (ret)
2795 {
2796 if (msg->message == WM_PAINT) DispatchMessage(msg);
2797 else break;
2798 }
2799 else if (MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
2800 }
2801 if (!ret) msg->message = 0;
2802 return ret;
2803 }
2804
2805 static void test_mouse_input(HWND hwnd)
2806 {
2807 RECT rc;
2808 POINT pt;
2809 int x, y;
2810 HWND popup;
2811 MSG msg;
2812 BOOL ret;
2813 LRESULT res;
2814
2815 ShowWindow(hwnd, SW_SHOW);
2816 UpdateWindow(hwnd);
2817 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2818
2819 GetWindowRect(hwnd, &rc);
2820 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2821
2822 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2823 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2824 hwnd, 0, 0, NULL);
2825 assert(popup != 0);
2826 ShowWindow(popup, SW_SHOW);
2827 UpdateWindow(popup);
2828 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2829
2830 GetWindowRect(popup, &rc);
2831 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2832
2833 x = rc.left + (rc.right - rc.left) / 2;
2834 y = rc.top + (rc.bottom - rc.top) / 2;
2835 trace("setting cursor to (%d,%d)\n", x, y);
2836
2837 SetCursorPos(x, y);
2838 GetCursorPos(&pt);
2839 if (x != pt.x || y != pt.y)
2840 {
2841 skip( "failed to set mouse position, skipping mouse input tests\n" );
2842 goto done;
2843 }
2844
2845 flush_events( TRUE );
2846
2847 /* Check that setting the same position may generate WM_MOUSEMOVE */
2848 SetCursorPos(x, y);
2849 msg.message = 0;
2850 ret = peek_message(&msg);
2851 if (ret)
2852 {
2853 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
2854 msg.hwnd, msg.message);
2855 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
2856 x, y, msg.pt.x, msg.pt.y);
2857 }
2858
2859 /* force the system to update its internal queue mouse position,
2860 * otherwise it won't generate relative mouse movements below.
2861 */
2862 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2863 flush_events( TRUE );
2864
2865 msg.message = 0;
2866 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2867 flush_events( FALSE );
2868 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2869 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2870 {
2871 if (msg.message == WM_TIMER || ignore_message(msg.message)) continue;
2872 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
2873 "hwnd %p message %04x\n", msg.hwnd, msg.message);
2874 }
2875 ret = peek_message(&msg);
2876 ok( !ret, "message %04x available\n", msg.message);
2877
2878 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2879 ShowWindow(popup, SW_HIDE);
2880 ret = wait_for_message( &msg );
2881 if (ret)
2882 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2883 flush_events( TRUE );
2884
2885 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2886 ShowWindow(hwnd, SW_HIDE);
2887 ret = wait_for_message( &msg );
2888 ok( !ret, "message %04x available\n", msg.message);
2889 flush_events( TRUE );
2890
2891 /* test mouse clicks */
2892
2893 ShowWindow(hwnd, SW_SHOW);
2894 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2895 flush_events( TRUE );
2896 ShowWindow(popup, SW_SHOW);
2897 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2898 flush_events( TRUE );
2899
2900 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2901 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2902 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2903 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2904
2905 ret = wait_for_message( &msg );
2906 if (!ret)
2907 {
2908 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
2909 goto done;
2910 }
2911 if (msg.message == WM_MOUSEMOVE) /* win2k has an extra WM_MOUSEMOVE here */
2912 {
2913 ret = wait_for_message( &msg );
2914 ok(ret, "no message available\n");
2915 }
2916
2917 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2918 msg.hwnd, popup, msg.message);
2919
2920 ret = wait_for_message( &msg );
2921 ok(ret, "no message available\n");
2922 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2923 msg.hwnd, popup, msg.message);
2924
2925 ret = wait_for_message( &msg );
2926 ok(ret, "no message available\n");
2927 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
2928 msg.hwnd, popup, msg.message);
2929
2930 ret = wait_for_message( &msg );
2931 ok(ret, "no message available\n");
2932 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2933 msg.hwnd, popup, msg.message);
2934
2935 ret = peek_message(&msg);
2936 ok(!ret, "message %04x available\n", msg.message);
2937
2938 ShowWindow(popup, SW_HIDE);
2939 flush_events( TRUE );
2940
2941 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2942 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2943 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2944 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2945
2946 ret = wait_for_message( &msg );
2947 ok(ret, "no message available\n");
2948 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2949 msg.hwnd, hwnd, msg.message);
2950 ret = wait_for_message( &msg );
2951 ok(ret, "no message available\n");
2952 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2953 msg.hwnd, hwnd, msg.message);
2954
2955 test_lbuttondown_flag = TRUE;
2956 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
2957 test_lbuttondown_flag = FALSE;
2958
2959 ret = wait_for_message( &msg );
2960 ok(ret, "no message available\n");
2961 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2962 msg.hwnd, popup, msg.message);
2963 ok(peek_message(&msg), "no message available\n");
2964 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2965 msg.hwnd, popup, msg.message);
2966 ok(peek_message(&msg), "no message available\n");
2967
2968 /* Test WM_MOUSEACTIVATE */
2969 #define TEST_MOUSEACTIVATE(A,B) \
2970 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2971 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2972
2973 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
2974 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
2975 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
2976 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
2977 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
2978 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
2979 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
2980 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
2981 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
2982 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
2983 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
2984 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
2985 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
2986 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
2987 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
2988 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
2989 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
2990 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
2991 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
2992 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
2993 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
2994 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
2995 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
2996 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
2997
2998 done:
2999 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
3000 flush_events( TRUE );
3001
3002 DestroyWindow(popup);
3003 }
3004
3005 static void test_validatergn(HWND hwnd)
3006 {
3007 HWND child;
3008 RECT rc, rc2;
3009 HRGN rgn;
3010 int ret;
3011 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
3012 ShowWindow(hwnd, SW_SHOW);
3013 UpdateWindow( hwnd);
3014 /* test that ValidateRect validates children*/
3015 InvalidateRect( child, NULL, 1);
3016 GetWindowRect( child, &rc);
3017 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3018 ret = GetUpdateRect( child, &rc2, 0);
3019 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
3020 "Update rectangle is empty!\n");
3021 ValidateRect( hwnd, &rc);
3022 ret = GetUpdateRect( child, &rc2, 0);
3023 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3024 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3025 rc2.right, rc2.bottom);
3026
3027