2 * Unit tests for window handling
4 * Copyright 2002 Bill Medland
5 * Copyright 2002 Alexandre Julliard
6 * Copyright 2003 Dmitry Timoshkov
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.
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.
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
23 /* To get ICON_SMALL2 with the MSVC headers */
24 #define _WIN32_WINNT 0x0501
36 #include "wine/test.h"
38 #ifndef SPI_GETDESKWALLPAPER
39 #define SPI_GETDESKWALLPAPER 0x0073
42 #define LONG_PTR INT_PTR
43 #define ULONG_PTR UINT_PTR
45 void dump_region(HRGN hrgn);
47 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
48 static BOOL (WINAPI *pGetWindowInfo)(HWND,WINDOWINFO*);
50 static BOOL test_lbuttondown_flag;
51 static HWND hwndMessage;
52 static HWND hwndMain, hwndMain2;
55 static const char* szAWRClass = "Winsize";
59 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
61 /* try to make sure pending X events have been processed before continuing */
62 static void flush_events(void)
67 DWORD time = GetTickCount() + diff;
71 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
72 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
73 diff = time - GetTickCount();
78 /* check the values returned by the various parent/owner functions on a given window */
79 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
80 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
86 res = pGetAncestor( hwnd, GA_PARENT );
87 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
89 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
90 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
91 res = GetParent( hwnd );
92 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
93 res = GetWindow( hwnd, GW_OWNER );
94 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
97 res = pGetAncestor( hwnd, GA_ROOT );
98 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
99 res = pGetAncestor( hwnd, GA_ROOTOWNER );
100 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
104 static BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
107 trace("EnumChildProc on %p\n", hwndChild);
108 if (*(LPINT)lParam > 1) return FALSE;
112 /* will search for the given window */
113 static BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
115 trace("EnumChildProc1 on %p\n", hwndChild);
116 if ((HWND)lParam == hwndChild) return FALSE;
120 static HWND create_tool_window( LONG style, HWND parent )
122 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
123 0, 0, 100, 100, parent, 0, 0, NULL );
124 ok( ret != 0, "Creation failed\n" );
128 /* test parent and owner values for various combinations */
129 static void test_parent_owner(void)
132 HWND test, owner, ret;
133 HWND desktop = GetDesktopWindow();
134 HWND child = create_tool_window( WS_CHILD, hwndMain );
137 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
139 /* child without parent, should fail */
140 SetLastError(0xdeadbeef);
141 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
142 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
143 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD, "CreateWindowExA should call SetLastError\n" );
144 ok( !test, "WS_CHILD without parent created\n" );
147 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
148 style = GetWindowLongA( desktop, GWL_STYLE );
149 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
150 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
151 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
153 /* normal child window */
154 test = create_tool_window( WS_CHILD, hwndMain );
155 trace( "created child %p\n", test );
156 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
157 SetWindowLongA( test, GWL_STYLE, 0 );
158 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
159 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
160 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
161 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
162 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
163 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
164 DestroyWindow( test );
166 /* normal child window with WS_MAXIMIZE */
167 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
168 DestroyWindow( test );
170 /* normal child window with WS_THICKFRAME */
171 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
172 DestroyWindow( test );
174 /* popup window with WS_THICKFRAME */
175 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
176 DestroyWindow( test );
178 /* child of desktop */
179 test = create_tool_window( WS_CHILD, desktop );
180 trace( "created child of desktop %p\n", test );
181 check_parents( test, desktop, 0, desktop, 0, test, desktop );
182 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
183 check_parents( test, desktop, 0, 0, 0, test, test );
184 SetWindowLongA( test, GWL_STYLE, 0 );
185 check_parents( test, desktop, 0, 0, 0, test, test );
186 DestroyWindow( test );
188 /* child of desktop with WS_MAXIMIZE */
189 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
190 DestroyWindow( test );
192 /* child of desktop with WS_MINIMIZE */
193 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
194 DestroyWindow( test );
197 test = create_tool_window( WS_CHILD, child );
198 trace( "created child of child %p\n", test );
199 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
200 SetWindowLongA( test, GWL_STYLE, 0 );
201 check_parents( test, child, child, 0, 0, hwndMain, test );
202 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
203 check_parents( test, child, child, 0, 0, hwndMain, test );
204 DestroyWindow( test );
206 /* child of child with WS_MAXIMIZE */
207 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
208 DestroyWindow( test );
210 /* child of child with WS_MINIMIZE */
211 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
212 DestroyWindow( test );
214 /* not owned top-level window */
215 test = create_tool_window( 0, 0 );
216 trace( "created top-level %p\n", test );
217 check_parents( test, desktop, 0, 0, 0, test, test );
218 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
219 check_parents( test, desktop, 0, 0, 0, test, test );
220 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
221 check_parents( test, desktop, 0, desktop, 0, test, desktop );
222 DestroyWindow( test );
224 /* not owned top-level window with WS_MAXIMIZE */
225 test = create_tool_window( WS_MAXIMIZE, 0 );
226 DestroyWindow( test );
228 /* owned top-level window */
229 test = create_tool_window( 0, hwndMain );
230 trace( "created owned top-level %p\n", test );
231 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
232 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
233 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
234 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
235 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
236 DestroyWindow( test );
238 /* owned top-level window with WS_MAXIMIZE */
239 test = create_tool_window( WS_MAXIMIZE, hwndMain );
240 DestroyWindow( test );
242 /* not owned popup */
243 test = create_tool_window( WS_POPUP, 0 );
244 trace( "created popup %p\n", test );
245 check_parents( test, desktop, 0, 0, 0, test, test );
246 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
247 check_parents( test, desktop, 0, desktop, 0, test, desktop );
248 SetWindowLongA( test, GWL_STYLE, 0 );
249 check_parents( test, desktop, 0, 0, 0, test, test );
250 DestroyWindow( test );
252 /* not owned popup with WS_MAXIMIZE */
253 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
254 DestroyWindow( test );
257 test = create_tool_window( WS_POPUP, hwndMain );
258 trace( "created owned popup %p\n", test );
259 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
260 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
261 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
262 SetWindowLongA( test, GWL_STYLE, 0 );
263 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
264 DestroyWindow( test );
266 /* owned popup with WS_MAXIMIZE */
267 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
268 DestroyWindow( test );
270 /* top-level window owned by child (same as owned by top-level) */
271 test = create_tool_window( 0, child );
272 trace( "created top-level owned by child %p\n", test );
273 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
274 DestroyWindow( test );
276 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
277 test = create_tool_window( WS_MAXIMIZE, child );
278 DestroyWindow( test );
280 /* popup owned by desktop (same as not owned) */
281 test = create_tool_window( WS_POPUP, desktop );
282 trace( "created popup owned by desktop %p\n", test );
283 check_parents( test, desktop, 0, 0, 0, test, test );
284 DestroyWindow( test );
286 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
287 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
288 DestroyWindow( test );
290 /* popup owned by child (same as owned by top-level) */
291 test = create_tool_window( WS_POPUP, child );
292 trace( "created popup owned by child %p\n", test );
293 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
294 DestroyWindow( test );
296 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
297 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
298 DestroyWindow( test );
300 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
301 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
302 trace( "created WS_CHILD popup %p\n", test );
303 check_parents( test, desktop, 0, 0, 0, test, test );
304 DestroyWindow( test );
306 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
307 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
308 DestroyWindow( test );
310 /* owned popup with WS_CHILD (same as WS_POPUP only) */
311 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
312 trace( "created owned WS_CHILD popup %p\n", test );
313 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
314 DestroyWindow( test );
316 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
317 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
318 DestroyWindow( test );
320 /******************** parent changes *************************/
321 trace( "testing parent changes\n" );
324 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
327 /* this test succeeds on NT but crashes on win9x systems */
328 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
329 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
330 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
331 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
332 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
334 /* normal child window */
335 test = create_tool_window( WS_CHILD, hwndMain );
336 trace( "created child %p\n", test );
338 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
339 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
340 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
342 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
343 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
344 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
346 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
347 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
348 check_parents( test, desktop, 0, desktop, 0, test, desktop );
350 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
351 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
352 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
353 check_parents( test, desktop, child, desktop, child, test, desktop );
355 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
356 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
357 check_parents( test, desktop, 0, desktop, 0, test, desktop );
358 DestroyWindow( test );
360 /* not owned top-level window */
361 test = create_tool_window( 0, 0 );
362 trace( "created top-level %p\n", test );
364 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
365 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
366 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
368 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
369 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
370 check_parents( test, desktop, child, 0, child, test, test );
372 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
373 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
374 check_parents( test, desktop, 0, 0, 0, test, test );
375 DestroyWindow( test );
377 /* not owned popup */
378 test = create_tool_window( WS_POPUP, 0 );
379 trace( "created popup %p\n", test );
381 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
382 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
383 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
385 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
386 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
387 check_parents( test, desktop, child, child, child, test, hwndMain );
389 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
390 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
391 check_parents( test, desktop, 0, 0, 0, test, test );
392 DestroyWindow( test );
394 /* normal child window */
395 test = create_tool_window( WS_CHILD, hwndMain );
396 trace( "created child %p\n", test );
398 ret = SetParent( test, desktop );
399 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
400 check_parents( test, desktop, 0, desktop, 0, test, desktop );
402 ret = SetParent( test, child );
403 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
404 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
406 ret = SetParent( test, hwndMain2 );
407 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
408 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
409 DestroyWindow( test );
411 /* not owned top-level window */
412 test = create_tool_window( 0, 0 );
413 trace( "created top-level %p\n", test );
415 ret = SetParent( test, child );
416 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
417 check_parents( test, child, child, 0, 0, hwndMain, test );
418 DestroyWindow( test );
421 test = create_tool_window( WS_POPUP, hwndMain2 );
422 trace( "created owned popup %p\n", test );
424 ret = SetParent( test, child );
425 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
426 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
428 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
429 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
430 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
431 DestroyWindow( test );
433 /**************** test owner destruction *******************/
435 /* owned child popup */
436 owner = create_tool_window( 0, 0 );
437 test = create_tool_window( WS_POPUP, owner );
438 trace( "created owner %p and popup %p\n", owner, test );
439 ret = SetParent( test, child );
440 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
441 check_parents( test, child, child, owner, owner, hwndMain, owner );
442 /* window is now child of 'child' but owned by 'owner' */
443 DestroyWindow( owner );
444 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
445 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
446 * while Win95, Win2k, WinXP do.
448 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
449 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
452 /* owned top-level popup */
453 owner = create_tool_window( 0, 0 );
454 test = create_tool_window( WS_POPUP, owner );
455 trace( "created owner %p and popup %p\n", owner, test );
456 check_parents( test, desktop, owner, owner, owner, test, owner );
457 DestroyWindow( owner );
458 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
460 /* top-level popup owned by child */
461 owner = create_tool_window( WS_CHILD, hwndMain2 );
462 test = create_tool_window( WS_POPUP, 0 );
463 trace( "created owner %p and popup %p\n", owner, test );
464 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
465 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
466 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
467 DestroyWindow( owner );
468 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
469 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
470 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
471 * while Win95, Win2k, WinXP do.
473 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
477 DestroyWindow(child);
480 owner = create_tool_window( WS_OVERLAPPED, 0 );
481 test = create_tool_window( WS_POPUP, desktop );
483 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
485 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
486 "EnumChildWindows should have returned FALSE\n" );
487 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
489 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
490 ret = SetParent( test, owner );
491 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
494 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
495 "EnumChildWindows should have returned TRUE\n" );
496 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
498 child = create_tool_window( WS_CHILD, owner );
500 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
501 "EnumChildWindows should have returned FALSE\n" );
502 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
503 DestroyWindow( child );
505 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
506 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
508 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
509 "EnumChildWindows should have returned TRUE\n" );
510 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
512 ret = SetParent( child, owner );
513 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
514 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
516 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
517 "EnumChildWindows should have returned FALSE\n" );
518 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
520 ret = SetParent( child, NULL );
521 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
522 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
524 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
525 "EnumChildWindows should have returned TRUE\n" );
526 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
528 /* even GW_OWNER == owner it's still a desktop's child */
529 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
530 "EnumChildWindows should have found %p and returned FALSE\n", child );
532 DestroyWindow( child );
533 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
535 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
536 "EnumChildWindows should have found %p and returned FALSE\n", child );
538 DestroyWindow( child );
539 DestroyWindow( test );
540 DestroyWindow( owner );
544 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
548 case WM_GETMINMAXINFO:
550 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
552 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
553 trace("ptReserved (%d,%d), ptMaxSize (%d,%d), ptMaxPosition (%d,%d)\n"
554 " ptMinTrackSize (%d,%d), ptMaxTrackSize (%d,%d)\n",
555 minmax->ptReserved.x, minmax->ptReserved.y,
556 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
557 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
558 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
559 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
560 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
563 case WM_WINDOWPOSCHANGING:
565 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
566 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
567 trace("main: WM_WINDOWPOSCHANGING\n");
568 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
569 winpos->hwnd, winpos->hwndInsertAfter,
570 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
571 if (!(winpos->flags & SWP_NOMOVE))
573 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
574 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
576 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
577 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
579 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
580 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
584 case WM_WINDOWPOSCHANGED:
587 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
588 trace("main: WM_WINDOWPOSCHANGED\n");
589 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
590 winpos->hwnd, winpos->hwndInsertAfter,
591 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
592 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
593 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
595 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
596 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
598 GetWindowRect(hwnd, &rc1);
599 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
600 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
601 /* note: winpos coordinates are relative to parent */
602 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
603 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
606 /* Uncomment this once the test succeeds in all cases */
607 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
610 GetClientRect(hwnd, &rc2);
611 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
612 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
613 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
614 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
619 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
620 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
622 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
623 if (got_getminmaxinfo)
624 trace("%p got WM_GETMINMAXINFO\n", hwnd);
626 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
627 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
629 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
633 if (test_lbuttondown_flag)
634 ShowWindow((HWND)wparam, SW_SHOW);
638 return DefWindowProcA(hwnd, msg, wparam, lparam);
641 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
645 case WM_GETMINMAXINFO:
647 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
649 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
650 trace("ptReserved (%d,%d), ptMaxSize (%d,%d), ptMaxPosition (%d,%d)\n"
651 " ptMinTrackSize (%d,%d), ptMaxTrackSize (%d,%d)\n",
652 minmax->ptReserved.x, minmax->ptReserved.y,
653 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
654 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
655 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
656 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
657 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
662 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
663 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
665 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
666 if (got_getminmaxinfo)
667 trace("%p got WM_GETMINMAXINFO\n", hwnd);
669 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
670 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
672 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
677 return DefWindowProcA(hwnd, msg, wparam, lparam);
680 static BOOL RegisterWindowClasses(void)
684 cls.style = CS_DBLCLKS;
685 cls.lpfnWndProc = main_window_procA;
688 cls.hInstance = GetModuleHandleA(0);
690 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
691 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
692 cls.lpszMenuName = NULL;
693 cls.lpszClassName = "MainWindowClass";
695 if(!RegisterClassA(&cls)) return FALSE;
698 cls.lpfnWndProc = tool_window_procA;
701 cls.hInstance = GetModuleHandleA(0);
703 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
704 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
705 cls.lpszMenuName = NULL;
706 cls.lpszClassName = "ToolWindowClass";
708 if(!RegisterClassA(&cls)) return FALSE;
713 static void verify_window_info(HWND hwnd, const WINDOWINFO *info)
715 RECT rcWindow, rcClient;
718 ok(IsWindow(hwnd), "bad window handle\n");
720 GetWindowRect(hwnd, &rcWindow);
721 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow\n");
723 GetClientRect(hwnd, &rcClient);
724 /* translate to screen coordinates */
725 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
726 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient\n");
728 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
729 "wrong dwStyle: %08x != %08x\n", info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE));
730 /* Windows reports a not documented exstyle 0x800 in WINDOWINFO, but
731 * doesn't return it in GetWindowLong(hwnd, GWL_EXSTYLE).
733 ok((info->dwExStyle & ~0x800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
734 "wrong dwExStyle: %08x != %08x\n", info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE));
735 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
736 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x\n",
737 info->dwWindowStatus, status);
739 trace("rcWindow: %d,%d - %d,%d\n", rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
740 trace("rcClient: %d,%d - %d,%d\n", rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
742 /* win2k and XP return broken border info in GetWindowInfo most of
743 * the time, so there is no point in testing it.
747 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
748 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
749 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
750 ok(info->cyWindowBorders == border,
751 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
753 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType\n");
754 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
755 info->wCreatorVersion == 0x0500 /* Vista */,
756 "wrong wCreatorVersion %04x\n", info->wCreatorVersion);
759 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
761 AdjustWindowRectEx(rc, style, menu, exstyle);
762 /* AdjustWindowRectEx does not include scroll bars */
763 if (style & WS_VSCROLL)
765 if(exstyle & WS_EX_LEFTSCROLLBAR)
766 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
768 rc->right += GetSystemMetrics(SM_CXVSCROLL);
770 if (style & WS_HSCROLL)
771 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
774 static void test_nonclient_area(HWND hwnd)
776 DWORD style, exstyle;
777 RECT rc_window, rc_client, rc;
779 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
781 style = GetWindowLongA(hwnd, GWL_STYLE);
782 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
783 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
785 GetWindowRect(hwnd, &rc_window);
786 trace("window: (%d,%d)-(%d,%d)\n", rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
787 GetClientRect(hwnd, &rc_client);
788 trace("client: (%d,%d)-(%d,%d)\n", rc_client.left, rc_client.top, rc_client.right, rc_client.bottom);
790 /* avoid some cases when things go wrong */
791 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
792 rc_window.right > 32768 || rc_window.bottom > 32768) return;
794 CopyRect(&rc, &rc_client);
795 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
796 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
798 trace("calc window: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
799 ok(EqualRect(&rc, &rc_window), "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
802 CopyRect(&rc, &rc_window);
803 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
804 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
805 trace("calc client: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
806 ok(EqualRect(&rc, &rc_client), "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
808 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
812 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
813 SetRect(&rc_client, 0, 0, 250, 150);
814 CopyRect(&rc_window, &rc_client);
815 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
816 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
817 trace("calc window: (%d,%d)-(%d,%d)\n",
818 rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
820 CopyRect(&rc, &rc_window);
821 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
822 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
823 trace("calc client: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
824 ok(EqualRect(&rc, &rc_client), "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
827 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
829 static const char *CBT_code_name[10] = {
840 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
842 trace("CBT: %d (%s), %08lx, %08lx\n", nCode, code_name, wParam, lParam);
844 /* on HCBT_DESTROYWND window state is undefined */
845 if (nCode != HCBT_DESTROYWND && IsWindow((HWND)wParam))
851 /* Win98 actually does check the info.cbSize and doesn't allow
852 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
853 * WinXP do not check it at all.
855 info.cbSize = sizeof(WINDOWINFO);
856 ok(pGetWindowInfo((HWND)wParam, &info), "GetWindowInfo should not fail\n");
857 verify_window_info((HWND)wParam, &info);
865 static const RECT rc_null;
868 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
869 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
870 (HWND)wParam, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
871 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
873 /* WS_VISIBLE should be turned off yet */
874 style = createwnd->lpcs->style & ~WS_VISIBLE;
875 ok(style == GetWindowLongA((HWND)wParam, GWL_STYLE),
876 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
877 GetWindowLongA((HWND)wParam, GWL_STYLE), style);
881 /* Uncomment this once the test succeeds in all cases */
882 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
884 ok(GetParent((HWND)wParam) == hwndMessage,
885 "wrong result from GetParent %p: message window %p\n",
886 GetParent((HWND)wParam), hwndMessage);
889 ok(!GetParent((HWND)wParam), "GetParent should return 0 at this point\n");
891 ok(!GetWindow((HWND)wParam, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
895 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
896 * Win9x still has them set to 0.
898 ok(GetWindow((HWND)wParam, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
899 ok(GetWindow((HWND)wParam, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
901 ok(!GetWindow((HWND)wParam, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
902 ok(!GetWindow((HWND)wParam, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
906 /* Uncomment this once the test succeeds in all cases */
909 ok(pGetAncestor((HWND)wParam, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
910 ok(pGetAncestor((HWND)wParam, GA_ROOT) == (HWND)wParam,
911 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOT), (HWND)wParam);
913 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
914 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == hwndMessage,
915 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
917 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == (HWND)wParam,
918 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOTOWNER), (HWND)wParam);
921 ok(GetWindowRect((HWND)wParam, &rc), "GetWindowRect failed\n");
922 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
923 ok(GetClientRect((HWND)wParam, &rc), "GetClientRect failed\n");
924 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
930 return CallNextHookEx(hhook, nCode, wParam, lParam);
933 static void test_shell_window(void)
937 HMODULE hinst, hUser32;
938 BOOL (WINAPI*SetShellWindow)(HWND);
939 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
940 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
941 HWND shellWindow, nextWnd;
943 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
945 trace("Skipping shell window test on Win9x\n");
949 shellWindow = GetShellWindow();
950 hinst = GetModuleHandle(0);
951 hUser32 = GetModuleHandleA("user32");
953 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
954 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
956 trace("previous shell window: %p\n", shellWindow);
962 ret = DestroyWindow(shellWindow);
963 error = GetLastError();
965 ok(!ret, "DestroyWindow(shellWindow)\n");
966 /* passes on Win XP, but not on Win98 */
967 ok(error==ERROR_ACCESS_DENIED, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n");
969 /* close old shell instance */
970 GetWindowThreadProcessId(shellWindow, &pid);
971 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
972 ret = TerminateProcess(hProcess, 0);
973 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
974 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
975 CloseHandle(hProcess);
978 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
979 trace("created window 1: %p\n", hwnd1);
981 ret = SetShellWindow(hwnd1);
982 ok(ret, "first call to SetShellWindow(hwnd1)\n");
983 shellWindow = GetShellWindow();
984 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
986 ret = SetShellWindow(hwnd1);
987 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
989 ret = SetShellWindow(0);
990 error = GetLastError();
991 /* passes on Win XP, but not on Win98
992 ok(!ret, "reset shell window by SetShellWindow(0)\n");
993 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
995 ret = SetShellWindow(hwnd1);
996 /* passes on Win XP, but not on Win98
997 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
999 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1000 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
1001 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1003 ret = DestroyWindow(hwnd1);
1004 ok(ret, "DestroyWindow(hwnd1)\n");
1006 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1007 trace("created window 2: %p\n", hwnd2);
1008 ret = SetShellWindow(hwnd2);
1009 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1011 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1012 trace("created window 3: %p\n", hwnd3);
1014 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1015 trace("created window 4: %p\n", hwnd4);
1017 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1018 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1020 ret = SetShellWindow(hwnd4);
1021 ok(ret, "SetShellWindow(hwnd4)\n");
1022 shellWindow = GetShellWindow();
1023 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1025 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1026 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1028 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1029 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1031 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1032 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1034 ret = SetShellWindow(hwnd3);
1035 ok(!ret, "SetShellWindow(hwnd3)\n");
1036 shellWindow = GetShellWindow();
1037 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1039 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1040 trace("created window 5: %p\n", hwnd5);
1041 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1042 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1046 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1047 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1050 /* destroy test windows */
1051 DestroyWindow(hwnd2);
1052 DestroyWindow(hwnd3);
1053 DestroyWindow(hwnd4);
1054 DestroyWindow(hwnd5);
1057 /************** MDI test ****************/
1059 static char mdi_lParam_test_message[] = "just a test string";
1061 static void test_MDI_create(HWND parent, HWND mdi_client, INT first_id)
1063 MDICREATESTRUCTA mdi_cs;
1065 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1066 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1067 BOOL isWin9x = FALSE;
1069 mdi_cs.szClass = "MDI_child_Class_1";
1070 mdi_cs.szTitle = "MDI child";
1071 mdi_cs.hOwner = GetModuleHandle(0);
1072 mdi_cs.x = CW_USEDEFAULT;
1073 mdi_cs.y = CW_USEDEFAULT;
1074 mdi_cs.cx = CW_USEDEFAULT;
1075 mdi_cs.cy = CW_USEDEFAULT;
1077 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1078 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1079 ok(mdi_child != 0, "MDI child creation failed\n");
1080 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1081 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1082 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1084 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1085 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1086 ok(mdi_child != 0, "MDI child creation failed\n");
1087 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1088 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1089 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1091 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1092 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1093 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1095 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1099 ok(mdi_child != 0, "MDI child creation failed\n");
1100 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1101 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1102 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1105 /* test MDICREATESTRUCT A<->W mapping */
1106 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1108 mdi_cs.szClass = (LPCSTR)classW;
1109 mdi_cs.szTitle = (LPCSTR)titleW;
1110 SetLastError(0xdeadbeef);
1111 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1114 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1117 ok(mdi_child != 0, "MDI child creation failed\n");
1121 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1122 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1123 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1126 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1128 CW_USEDEFAULT, CW_USEDEFAULT,
1129 CW_USEDEFAULT, CW_USEDEFAULT,
1130 mdi_client, GetModuleHandle(0),
1131 (LPARAM)mdi_lParam_test_message);
1132 ok(mdi_child != 0, "MDI child creation failed\n");
1133 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1134 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1135 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1137 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1138 0x7fffffff, /* without WS_POPUP */
1139 CW_USEDEFAULT, CW_USEDEFAULT,
1140 CW_USEDEFAULT, CW_USEDEFAULT,
1141 mdi_client, GetModuleHandle(0),
1142 (LPARAM)mdi_lParam_test_message);
1143 ok(mdi_child != 0, "MDI child creation failed\n");
1144 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1145 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1146 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1148 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1149 0xffffffff, /* with WS_POPUP */
1150 CW_USEDEFAULT, CW_USEDEFAULT,
1151 CW_USEDEFAULT, CW_USEDEFAULT,
1152 mdi_client, GetModuleHandle(0),
1153 (LPARAM)mdi_lParam_test_message);
1154 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1156 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1160 ok(mdi_child != 0, "MDI child creation failed\n");
1161 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1162 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1163 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1166 /* test MDICREATESTRUCT A<->W mapping */
1167 SetLastError(0xdeadbeef);
1168 mdi_child = CreateMDIWindowW(classW, titleW,
1170 CW_USEDEFAULT, CW_USEDEFAULT,
1171 CW_USEDEFAULT, CW_USEDEFAULT,
1172 mdi_client, GetModuleHandle(0),
1173 (LPARAM)mdi_lParam_test_message);
1176 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1179 ok(mdi_child != 0, "MDI child creation failed\n");
1183 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1184 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1185 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1188 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1190 CW_USEDEFAULT, CW_USEDEFAULT,
1191 CW_USEDEFAULT, CW_USEDEFAULT,
1192 mdi_client, 0, GetModuleHandle(0),
1193 (LPVOID)mdi_lParam_test_message);
1194 ok(mdi_child != 0, "MDI child creation failed\n");
1195 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1196 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1197 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1199 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1200 0x7fffffff, /* without WS_POPUP */
1201 CW_USEDEFAULT, CW_USEDEFAULT,
1202 CW_USEDEFAULT, CW_USEDEFAULT,
1203 mdi_client, 0, GetModuleHandle(0),
1204 (LPVOID)mdi_lParam_test_message);
1205 ok(mdi_child != 0, "MDI child creation failed\n");
1206 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1207 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1208 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1210 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1211 0xffffffff, /* with WS_POPUP */
1212 CW_USEDEFAULT, CW_USEDEFAULT,
1213 CW_USEDEFAULT, CW_USEDEFAULT,
1214 mdi_client, 0, GetModuleHandle(0),
1215 (LPVOID)mdi_lParam_test_message);
1216 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1218 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1222 ok(mdi_child != 0, "MDI child creation failed\n");
1223 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1224 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1225 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1228 /* test MDICREATESTRUCT A<->W mapping */
1229 SetLastError(0xdeadbeef);
1230 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1232 CW_USEDEFAULT, CW_USEDEFAULT,
1233 CW_USEDEFAULT, CW_USEDEFAULT,
1234 mdi_client, 0, GetModuleHandle(0),
1235 (LPVOID)mdi_lParam_test_message);
1238 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1241 ok(mdi_child != 0, "MDI child creation failed\n");
1245 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1246 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1247 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1250 /* This test fails on Win9x */
1253 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1255 CW_USEDEFAULT, CW_USEDEFAULT,
1256 CW_USEDEFAULT, CW_USEDEFAULT,
1257 parent, 0, GetModuleHandle(0),
1258 (LPVOID)mdi_lParam_test_message);
1259 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1262 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1263 WS_CHILD, /* without WS_POPUP */
1264 CW_USEDEFAULT, CW_USEDEFAULT,
1265 CW_USEDEFAULT, CW_USEDEFAULT,
1266 mdi_client, 0, GetModuleHandle(0),
1267 (LPVOID)mdi_lParam_test_message);
1268 ok(mdi_child != 0, "MDI child creation failed\n");
1269 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1270 DestroyWindow(mdi_child);
1272 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1273 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1274 CW_USEDEFAULT, CW_USEDEFAULT,
1275 CW_USEDEFAULT, CW_USEDEFAULT,
1276 mdi_client, 0, GetModuleHandle(0),
1277 (LPVOID)mdi_lParam_test_message);
1278 ok(mdi_child != 0, "MDI child creation failed\n");
1279 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1280 DestroyWindow(mdi_child);
1282 /* maximized child */
1283 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1284 WS_CHILD | WS_MAXIMIZE,
1285 CW_USEDEFAULT, CW_USEDEFAULT,
1286 CW_USEDEFAULT, CW_USEDEFAULT,
1287 mdi_client, 0, GetModuleHandle(0),
1288 (LPVOID)mdi_lParam_test_message);
1289 ok(mdi_child != 0, "MDI child creation failed\n");
1290 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1291 DestroyWindow(mdi_child);
1293 trace("Creating maximized child with a caption\n");
1294 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1295 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1296 CW_USEDEFAULT, CW_USEDEFAULT,
1297 CW_USEDEFAULT, CW_USEDEFAULT,
1298 mdi_client, 0, GetModuleHandle(0),
1299 (LPVOID)mdi_lParam_test_message);
1300 ok(mdi_child != 0, "MDI child creation failed\n");
1301 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1302 DestroyWindow(mdi_child);
1304 trace("Creating maximized child with a caption and a thick frame\n");
1305 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1306 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1307 CW_USEDEFAULT, CW_USEDEFAULT,
1308 CW_USEDEFAULT, CW_USEDEFAULT,
1309 mdi_client, 0, GetModuleHandle(0),
1310 (LPVOID)mdi_lParam_test_message);
1311 ok(mdi_child != 0, "MDI child creation failed\n");
1312 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1313 DestroyWindow(mdi_child);
1316 /**********************************************************************
1317 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1319 * Note: The rule here is that client rect of the maximized MDI child
1320 * is equal to the client rect of the MDI client window.
1322 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1326 GetClientRect( client, &rect );
1327 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1328 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1330 rect.right -= rect.left;
1331 rect.bottom -= rect.top;
1332 lpMinMax->ptMaxSize.x = rect.right;
1333 lpMinMax->ptMaxSize.y = rect.bottom;
1335 lpMinMax->ptMaxPosition.x = rect.left;
1336 lpMinMax->ptMaxPosition.y = rect.top;
1338 trace("max rect (%d,%d - %d, %d)\n",
1339 rect.left, rect.top, rect.right, rect.bottom);
1342 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1349 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1350 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs->lpCreateParams;
1352 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1353 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1355 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1356 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1357 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1358 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1359 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1361 /* MDICREATESTRUCT should have original values */
1362 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1363 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1364 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1365 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1366 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1367 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1369 /* CREATESTRUCT should have fixed values */
1370 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1371 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1373 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1374 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1375 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1377 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1379 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1381 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1382 ok(cs->style == style,
1383 "cs->style does not match (%08x)\n", cs->style);
1387 LONG style = mdi_cs->style;
1389 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1390 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1391 ok(cs->style == style,
1392 "cs->style does not match (%08x)\n", cs->style);
1397 case WM_GETMINMAXINFO:
1399 HWND client = GetParent(hwnd);
1401 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1402 MINMAXINFO my_minmax;
1403 LONG style, exstyle;
1405 style = GetWindowLongA(hwnd, GWL_STYLE);
1406 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1408 GetWindowRect(client, &rc);
1409 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1410 GetClientRect(client, &rc);
1411 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1412 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1413 GetSystemMetrics(SM_CYSCREEN));
1415 GetClientRect(client, &rc);
1416 if ((style & WS_CAPTION) == WS_CAPTION)
1417 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1418 AdjustWindowRectEx(&rc, style, 0, exstyle);
1419 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1421 trace("ptReserved = (%d,%d)\n"
1422 "ptMaxSize = (%d,%d)\n"
1423 "ptMaxPosition = (%d,%d)\n"
1424 "ptMinTrackSize = (%d,%d)\n"
1425 "ptMaxTrackSize = (%d,%d)\n",
1426 minmax->ptReserved.x, minmax->ptReserved.y,
1427 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1428 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1429 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1430 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1432 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1433 minmax->ptMaxSize.x, rc.right - rc.left);
1434 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1435 minmax->ptMaxSize.y, rc.bottom - rc.top);
1437 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1439 trace("DefMDIChildProc returned:\n"
1440 "ptReserved = (%d,%d)\n"
1441 "ptMaxSize = (%d,%d)\n"
1442 "ptMaxPosition = (%d,%d)\n"
1443 "ptMinTrackSize = (%d,%d)\n"
1444 "ptMaxTrackSize = (%d,%d)\n",
1445 minmax->ptReserved.x, minmax->ptReserved.y,
1446 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1447 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1448 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1449 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1451 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1452 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1453 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1454 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1455 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1460 case WM_MDIACTIVATE:
1462 HWND active, client = GetParent(hwnd);
1463 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1464 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1465 if (hwnd == (HWND)lparam) /* if we are being activated */
1466 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1468 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1472 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1475 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1482 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1484 trace("%s\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE");
1485 trace("x %d, y %d, cx %d, cy %d\n", cs->x, cs->y, cs->cx, cs->cy);
1487 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1488 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1490 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1491 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1493 /* CREATESTRUCT should have fixed values */
1494 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1496 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1497 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1499 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1500 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1501 while Win95, Win2k, WinXP do. */
1502 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1503 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1507 case WM_GETMINMAXINFO:
1509 HWND parent = GetParent(hwnd);
1511 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1512 LONG style, exstyle;
1514 trace("WM_GETMINMAXINFO\n");
1516 style = GetWindowLongA(hwnd, GWL_STYLE);
1517 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1519 GetClientRect(parent, &rc);
1520 trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1522 GetClientRect(parent, &rc);
1523 if ((style & WS_CAPTION) == WS_CAPTION)
1524 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1525 AdjustWindowRectEx(&rc, style, 0, exstyle);
1526 trace("calculated max child window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1528 trace("ptReserved = (%d,%d)\n"
1529 "ptMaxSize = (%d,%d)\n"
1530 "ptMaxPosition = (%d,%d)\n"
1531 "ptMinTrackSize = (%d,%d)\n"
1532 "ptMaxTrackSize = (%d,%d)\n",
1533 minmax->ptReserved.x, minmax->ptReserved.y,
1534 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1535 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1536 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1537 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1539 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1540 minmax->ptMaxSize.x, rc.right - rc.left);
1541 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1542 minmax->ptMaxSize.y, rc.bottom - rc.top);
1546 case WM_WINDOWPOSCHANGED:
1548 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1551 GetWindowRect(hwnd, &rc1);
1552 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1553 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1554 /* note: winpos coordinates are relative to parent */
1555 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1556 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1557 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1559 GetWindowRect(hwnd, &rc1);
1560 GetClientRect(hwnd, &rc2);
1561 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1562 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1563 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1566 case WM_WINDOWPOSCHANGING:
1568 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1569 WINDOWPOS my_winpos = *winpos;
1571 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1572 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1573 winpos->hwnd, winpos->hwndInsertAfter,
1574 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1576 DefWindowProcA(hwnd, msg, wparam, lparam);
1578 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1579 winpos->hwnd, winpos->hwndInsertAfter,
1580 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1582 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1583 "DefWindowProc should not change WINDOWPOS values\n");
1588 return DefWindowProcA(hwnd, msg, wparam, lparam);
1591 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1593 static HWND mdi_client;
1599 CLIENTCREATESTRUCT client_cs;
1602 GetClientRect(hwnd, &rc);
1604 client_cs.hWindowMenu = 0;
1605 client_cs.idFirstChild = 1;
1607 /* MDIClient without MDIS_ALLCHILDSTYLES */
1608 mdi_client = CreateWindowExA(0, "mdiclient",
1610 WS_CHILD /*| WS_VISIBLE*/,
1611 /* tests depend on a not zero MDIClient size */
1612 0, 0, rc.right, rc.bottom,
1613 hwnd, 0, GetModuleHandle(0),
1614 (LPVOID)&client_cs);
1616 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1617 DestroyWindow(mdi_client);
1619 /* MDIClient with MDIS_ALLCHILDSTYLES */
1620 mdi_client = CreateWindowExA(0, "mdiclient",
1622 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1623 /* tests depend on a not zero MDIClient size */
1624 0, 0, rc.right, rc.bottom,
1625 hwnd, 0, GetModuleHandle(0),
1626 (LPVOID)&client_cs);
1628 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1629 DestroyWindow(mdi_client);
1633 case WM_WINDOWPOSCHANGED:
1635 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1638 GetWindowRect(hwnd, &rc1);
1639 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1640 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1641 /* note: winpos coordinates are relative to parent */
1642 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1643 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1644 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1646 GetWindowRect(hwnd, &rc1);
1647 GetClientRect(hwnd, &rc2);
1648 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1649 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1650 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1653 case WM_WINDOWPOSCHANGING:
1655 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1656 WINDOWPOS my_winpos = *winpos;
1658 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1659 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1660 winpos->hwnd, winpos->hwndInsertAfter,
1661 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1663 DefWindowProcA(hwnd, msg, wparam, lparam);
1665 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1666 winpos->hwnd, winpos->hwndInsertAfter,
1667 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1669 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1670 "DefWindowProc should not change WINDOWPOS values\n");
1679 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1682 static BOOL mdi_RegisterWindowClasses(void)
1687 cls.lpfnWndProc = mdi_main_wnd_procA;
1690 cls.hInstance = GetModuleHandleA(0);
1692 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1693 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1694 cls.lpszMenuName = NULL;
1695 cls.lpszClassName = "MDI_parent_Class";
1696 if(!RegisterClassA(&cls)) return FALSE;
1698 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1699 cls.lpszClassName = "MDI_child_Class_1";
1700 if(!RegisterClassA(&cls)) return FALSE;
1702 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1703 cls.lpszClassName = "MDI_child_Class_2";
1704 if(!RegisterClassA(&cls)) return FALSE;
1709 static void test_mdi(void)
1714 if (!mdi_RegisterWindowClasses()) assert(0);
1716 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1717 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1718 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1719 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1720 GetDesktopWindow(), 0,
1721 GetModuleHandle(0), NULL);
1722 assert(mdi_hwndMain);
1724 while(GetMessage(&msg, 0, 0, 0))
1726 TranslateMessage(&msg);
1727 DispatchMessage(&msg);
1730 DestroyWindow(mdi_hwndMain);
1733 static void test_icons(void)
1737 HICON icon = LoadIconA(0, (LPSTR)IDI_APPLICATION);
1738 HICON icon2 = LoadIconA(0, (LPSTR)IDI_QUESTION);
1739 HICON small_icon = LoadImageA(0, (LPSTR)IDI_APPLICATION, IMAGE_ICON,
1740 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1743 cls.cbSize = sizeof(cls);
1745 cls.lpfnWndProc = DefWindowProcA;
1749 cls.hIcon = LoadIconA(0, (LPSTR)IDI_HAND);
1750 cls.hIconSm = small_icon;
1751 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1752 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1753 cls.lpszMenuName = NULL;
1754 cls.lpszClassName = "IconWindowClass";
1756 RegisterClassExA(&cls);
1758 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1759 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1762 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1763 ok( res == 0, "wrong big icon %p/0\n", res );
1764 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1765 ok( res == 0, "wrong previous big icon %p/0\n", res );
1766 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1767 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1768 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1769 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1770 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1771 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1773 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1774 ok( res == 0, "wrong small icon %p/0\n", res );
1775 /* this test is XP specific */
1776 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1777 ok( res != 0, "wrong small icon %p\n", res );*/
1778 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1779 ok( res == 0, "wrong previous small icon %p/0\n", res );
1780 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1781 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1782 /* this test is XP specific */
1783 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1784 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1785 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1786 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1787 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1788 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1789 /* this test is XP specific */
1790 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1791 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1793 /* make sure the big icon hasn't changed */
1794 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1795 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1797 DestroyWindow( hwnd );
1800 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1802 if (msg == WM_NCCALCSIZE)
1804 RECT *rect = (RECT *)lparam;
1805 /* first time around increase the rectangle, next time decrease it */
1806 if (rect->left == 100) InflateRect( rect, 10, 10 );
1807 else InflateRect( rect, -10, -10 );
1810 return DefWindowProc( hwnd, msg, wparam, lparam );
1813 static void test_SetWindowPos(HWND hwnd)
1815 RECT orig_win_rc, rect;
1817 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1819 SetRect(&rect, 111, 222, 333, 444);
1820 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1821 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1822 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1824 SetRect(&rect, 111, 222, 333, 444);
1825 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1826 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1827 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1829 GetWindowRect(hwnd, &orig_win_rc);
1831 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1832 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1833 GetWindowRect( hwnd, &rect );
1834 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1835 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1836 GetClientRect( hwnd, &rect );
1837 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1838 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1839 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1841 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1842 GetWindowRect( hwnd, &rect );
1843 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1844 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1845 GetClientRect( hwnd, &rect );
1846 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1847 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1848 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1850 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1851 orig_win_rc.right, orig_win_rc.bottom, 0);
1852 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1854 /* Win9x truncates coordinates to 16-bit irrespectively */
1857 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1858 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1860 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1861 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1864 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1865 orig_win_rc.right, orig_win_rc.bottom, 0);
1867 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1868 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1869 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1870 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1871 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1872 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1873 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1876 static void test_SetMenu(HWND parent)
1880 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1884 hMenu = CreateMenu();
1887 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1890 /* fails on (at least) Wine, NT4, XP SP2 */
1891 test_nonclient_area(parent);
1893 ret = GetMenu(parent);
1894 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1895 /* test whether we can destroy a menu assigned to a window */
1896 retok = DestroyMenu(hMenu);
1897 ok( retok, "DestroyMenu error %d\n", GetLastError());
1898 ok(!IsMenu(hMenu), "menu handle should be not valid after DestroyMenu\n");
1899 ret = GetMenu(parent);
1900 /* This test fails on Win9x */
1902 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1903 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1904 test_nonclient_area(parent);
1906 hMenu = CreateMenu();
1910 ret = GetMenu(parent);
1911 ok(ret == 0, "unexpected menu id %p\n", ret);
1913 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1914 test_nonclient_area(parent);
1915 ret = GetMenu(parent);
1916 ok(ret == 0, "unexpected menu id %p\n", ret);
1918 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1921 /* fails on (at least) Wine, NT4, XP SP2 */
1922 test_nonclient_area(parent);
1924 ret = GetMenu(parent);
1925 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1927 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1928 test_nonclient_area(parent);
1929 ret = GetMenu(parent);
1930 ok(ret == 0, "unexpected menu id %p\n", ret);
1933 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1936 ret = GetMenu(child);
1937 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1939 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1940 test_nonclient_area(child);
1941 ret = GetMenu(child);
1942 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1944 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1945 test_nonclient_area(child);
1946 ret = GetMenu(child);
1947 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1949 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1950 test_nonclient_area(child);
1951 ret = GetMenu(child);
1952 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1954 style = GetWindowLong(child, GWL_STYLE);
1955 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
1956 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
1957 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
1958 SetWindowLong(child, GWL_STYLE, style);
1960 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
1961 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
1962 SetWindowLong(child, GWL_STYLE, style);
1964 DestroyWindow(child);
1968 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1970 HWND child[5], hwnd;
1975 hwnd = GetWindow(parent, GW_CHILD);
1976 ok(!hwnd, "have to start without children to perform the test\n");
1978 for (i = 0; i < total; i++)
1980 if (style[i] & DS_CONTROL)
1982 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
1983 0,0,0,0, parent, (HMENU)i, 0, NULL);
1984 if (style[i] & WS_VISIBLE)
1985 ShowWindow(child[i], SW_SHOW);
1987 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
1990 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
1991 parent, (HMENU)i, 0, NULL);
1992 trace("child[%d] = %p\n", i, child[i]);
1993 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
1996 hwnd = GetWindow(parent, GW_CHILD);
1997 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
1998 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
1999 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
2001 for (i = 0; i < total; i++)
2003 trace("hwnd[%d] = %p\n", i, hwnd);
2004 ok(child[order[i]] == hwnd, "Z order of child #%d is wrong\n", i);
2006 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
2009 for (i = 0; i < total; i++)
2010 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2013 static void test_children_zorder(HWND parent)
2015 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2017 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2019 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2020 WS_CHILD | WS_VISIBLE, WS_CHILD,
2021 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2022 const int complex_order_1[1] = { 0 };
2023 const int complex_order_2[2] = { 1, 0 };
2024 const int complex_order_3[3] = { 1, 0, 2 };
2025 const int complex_order_4[4] = { 1, 0, 2, 3 };
2026 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2027 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2028 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2029 WS_CHILD | WS_VISIBLE };
2030 const int complex_order_6[3] = { 0, 1, 2 };
2032 /* simple WS_CHILD */
2033 test_window_tree(parent, simple_style, simple_order, 5);
2035 /* complex children styles */
2036 test_window_tree(parent, complex_style, complex_order_1, 1);
2037 test_window_tree(parent, complex_style, complex_order_2, 2);
2038 test_window_tree(parent, complex_style, complex_order_3, 3);
2039 test_window_tree(parent, complex_style, complex_order_4, 4);
2040 test_window_tree(parent, complex_style, complex_order_5, 5);
2042 /* another set of complex children styles */
2043 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2046 #define check_z_order(hwnd, next, prev, owner, topmost) \
2047 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2050 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2051 BOOL topmost, const char *file, int line)
2056 test = GetWindow(hwnd, GW_HWNDNEXT);
2057 /* skip foreign windows */
2058 while (test && (GetWindowThreadProcessId(test, NULL) != our_pid ||
2059 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0)))
2061 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2062 test = GetWindow(test, GW_HWNDNEXT);
2064 ok_(file, line)(next == test, "expected next %p, got %p\n", next, test);
2066 test = GetWindow(hwnd, GW_HWNDPREV);
2067 /* skip foreign windows */
2068 while (test && (GetWindowThreadProcessId(test, NULL) != our_pid ||
2069 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0)))
2071 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2072 test = GetWindow(test, GW_HWNDPREV);
2074 ok_(file, line)(prev == test, "expected prev %p, got %p\n", prev, test);
2076 test = GetWindow(hwnd, GW_OWNER);
2077 ok_(file, line)(owner == test, "expected owner %p, got %p\n", owner, test);
2079 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2080 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "expected %stopmost\n", topmost ? "" : "NOT ");
2083 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E)
2085 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2087 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2089 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2091 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2092 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2094 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2095 WS_OVERLAPPED | WS_CAPTION,
2097 0, 0, GetModuleHandle(0), NULL);
2098 trace("hwnd_F %p\n", hwnd_F);
2099 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2101 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2102 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2103 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2104 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2106 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2109 hwnd_F, 0, GetModuleHandle(0), NULL);
2110 trace("hwnd_C %p\n", hwnd_C);
2111 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2112 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2113 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2114 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2116 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2119 hwnd_F, 0, GetModuleHandle(0), NULL);
2120 trace("hwnd_B %p\n", hwnd_B);
2121 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2122 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2123 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2124 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2125 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2127 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2130 0, 0, GetModuleHandle(0), NULL);
2131 trace("hwnd_A %p\n", hwnd_A);
2132 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2133 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2134 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2135 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2136 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2137 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2139 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);
2141 /* move hwnd_F and its popups up */
2142 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2143 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2144 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2145 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2146 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2147 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2148 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2150 /* move hwnd_F and its popups down */
2151 #if 0 /* enable once Wine is fixed to pass this test */
2152 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2153 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2154 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2155 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2156 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2157 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2158 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2161 DestroyWindow(hwnd_A);
2162 DestroyWindow(hwnd_B);
2163 DestroyWindow(hwnd_C);
2164 DestroyWindow(hwnd_F);
2167 static void test_vis_rgn( HWND hwnd )
2169 RECT win_rect, rgn_rect;
2170 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2173 ShowWindow(hwnd,SW_SHOW);
2174 hdc = GetDC( hwnd );
2175 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2176 GetWindowRect( hwnd, &win_rect );
2177 GetRgnBox( hrgn, &rgn_rect );
2178 if (GetVersion() & 0x80000000)
2180 trace("win9x, mapping to screen coords\n");
2181 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2183 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2184 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2185 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2186 rgn_rect.left, win_rect.left );
2187 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2188 rgn_rect.top, win_rect.top );
2189 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2190 rgn_rect.right, win_rect.right );
2191 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2192 rgn_rect.bottom, win_rect.bottom );
2193 ReleaseDC( hwnd, hdc );
2196 static void test_SetFocus(HWND hwnd)
2200 /* check if we can set focus to non-visible windows */
2202 ShowWindow(hwnd, SW_SHOW);
2205 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2206 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2207 ShowWindow(hwnd, SW_HIDE);
2210 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2211 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2212 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2215 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2216 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2217 ShowWindow(child, SW_SHOW);
2218 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2219 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2220 ShowWindow(child, SW_HIDE);
2221 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2222 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2223 ShowWindow(child, SW_SHOW);
2225 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2226 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2227 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2229 ShowWindow(child, SW_HIDE);
2231 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2232 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2233 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2234 ShowWindow(child, SW_HIDE);
2235 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2237 ShowWindow(hwnd, SW_SHOW);
2238 ShowWindow(child, SW_SHOW);
2240 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2241 EnableWindow(hwnd, FALSE);
2242 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2243 EnableWindow(hwnd, TRUE);
2245 DestroyWindow( child );
2248 static void check_wnd_state(HWND active, HWND foreground, HWND focus, HWND capture)
2250 ok(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2252 ok(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2253 ok(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2254 ok(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2257 static void test_SetActiveWindow(HWND hwnd)
2261 ShowWindow(hwnd, SW_HIDE);
2264 check_wnd_state(0, 0, 0, 0);
2266 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2268 ShowWindow(hwnd, SW_SHOW);
2269 check_wnd_state(hwnd, hwnd, hwnd, 0);
2271 hwnd2 = SetActiveWindow(0);
2272 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2273 check_wnd_state(0, 0, 0, 0);
2275 hwnd2 = SetActiveWindow(hwnd);
2276 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2277 check_wnd_state(hwnd, hwnd, hwnd, 0);
2279 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2280 check_wnd_state(hwnd, hwnd, hwnd, 0);
2282 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2283 check_wnd_state(hwnd, hwnd, hwnd, 0);
2285 ShowWindow(hwnd, SW_HIDE);
2286 check_wnd_state(0, 0, 0, 0);
2288 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2289 SetActiveWindow(hwnd);
2290 check_wnd_state(hwnd, hwnd, hwnd, 0);
2292 ShowWindow(hwnd, SW_SHOW);
2293 check_wnd_state(hwnd, hwnd, hwnd, 0);
2295 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2296 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2298 DestroyWindow(hwnd2);
2299 check_wnd_state(hwnd, hwnd, hwnd, 0);
2301 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2302 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2304 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2305 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2307 DestroyWindow(hwnd2);
2308 check_wnd_state(hwnd, hwnd, hwnd, 0);
2311 static void test_SetForegroundWindow(HWND hwnd)
2316 ShowWindow(hwnd, SW_HIDE);
2319 check_wnd_state(0, 0, 0, 0);
2321 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2323 ShowWindow(hwnd, SW_SHOW);
2324 check_wnd_state(hwnd, hwnd, hwnd, 0);
2326 hwnd2 = SetActiveWindow(0);
2327 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2328 check_wnd_state(0, 0, 0, 0);
2330 ret = SetForegroundWindow(hwnd);
2331 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2332 check_wnd_state(hwnd, hwnd, hwnd, 0);
2334 SetLastError(0xdeadbeef);
2335 ret = SetForegroundWindow(0);
2336 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2337 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2338 check_wnd_state(hwnd, hwnd, hwnd, 0);
2340 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2341 check_wnd_state(hwnd, hwnd, hwnd, 0);
2343 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2344 check_wnd_state(hwnd, hwnd, hwnd, 0);
2346 hwnd2 = GetForegroundWindow();
2347 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2348 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2349 hwnd2 = GetForegroundWindow();
2350 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2352 ShowWindow(hwnd, SW_HIDE);
2353 check_wnd_state(0, 0, 0, 0);
2355 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2356 ret = SetForegroundWindow(hwnd);
2357 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2358 check_wnd_state(hwnd, hwnd, hwnd, 0);
2360 ShowWindow(hwnd, SW_SHOW);
2361 check_wnd_state(hwnd, hwnd, hwnd, 0);
2363 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2364 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2366 DestroyWindow(hwnd2);
2367 check_wnd_state(hwnd, hwnd, hwnd, 0);
2369 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2370 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2372 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2373 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2375 DestroyWindow(hwnd2);
2376 check_wnd_state(hwnd, hwnd, hwnd, 0);
2379 static WNDPROC old_button_proc;
2381 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2386 key_state = GetKeyState(VK_LBUTTON);
2387 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2389 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2391 if (msg == WM_LBUTTONDOWN)
2395 check_wnd_state(button, button, button, button);
2397 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2399 trace("hwnd %p\n", hwnd);
2401 check_wnd_state(button, button, button, button);
2403 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2405 check_wnd_state(button, button, button, button);
2407 DestroyWindow(hwnd);
2409 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2411 trace("hwnd %p\n", hwnd);
2413 check_wnd_state(button, button, button, button);
2415 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2416 * match internal button state.
2418 SendMessage(button, WM_KILLFOCUS, 0, 0);
2419 check_wnd_state(button, button, button, 0);
2421 ShowWindow(hwnd, SW_SHOW);
2422 check_wnd_state(hwnd, hwnd, hwnd, 0);
2424 capture = SetCapture(hwnd);
2425 ok(capture == 0, "SetCapture() = %p\n", capture);
2427 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2429 DestroyWindow(hwnd);
2431 check_wnd_state(button, 0, button, 0);
2437 static void test_capture_1(void)
2439 HWND button, capture;
2441 capture = GetCapture();
2442 ok(capture == 0, "GetCapture() = %p\n", capture);
2444 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2446 trace("button %p\n", button);
2448 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2450 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2452 capture = SetCapture(button);
2453 ok(capture == 0, "SetCapture() = %p\n", capture);
2454 check_wnd_state(button, 0, button, button);
2456 DestroyWindow(button);
2457 check_wnd_state(0, 0, 0, 0);
2460 static void test_capture_2(void)
2462 HWND button, hwnd, capture;
2464 check_wnd_state(0, 0, 0, 0);
2466 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2468 trace("button %p\n", button);
2470 check_wnd_state(button, button, button, 0);
2472 capture = SetCapture(button);
2473 ok(capture == 0, "SetCapture() = %p\n", capture);
2475 check_wnd_state(button, button, button, button);
2477 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2478 * internal button state.
2480 SendMessage(button, WM_KILLFOCUS, 0, 0);
2481 check_wnd_state(button, button, button, button);
2483 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2485 trace("hwnd %p\n", hwnd);
2487 check_wnd_state(button, button, button, button);
2489 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2491 check_wnd_state(button, button, button, button);
2493 DestroyWindow(hwnd);
2495 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2497 trace("hwnd %p\n", hwnd);
2499 check_wnd_state(button, button, button, button);
2501 ShowWindow(hwnd, SW_SHOW);
2503 check_wnd_state(hwnd, hwnd, hwnd, button);
2505 capture = SetCapture(hwnd);
2506 ok(capture == button, "SetCapture() = %p\n", capture);
2508 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2510 DestroyWindow(hwnd);
2511 check_wnd_state(button, button, button, 0);
2513 DestroyWindow(button);
2514 check_wnd_state(0, 0, 0, 0);
2517 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2521 ShowWindow(hwnd1, SW_HIDE);
2522 ShowWindow(hwnd2, SW_HIDE);
2524 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2525 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2528 check_wnd_state(0, 0, 0, hwnd1);
2531 check_wnd_state(0, 0, 0, hwnd2);
2533 ShowWindow(hwnd1, SW_SHOW);
2534 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2536 ret = ReleaseCapture();
2537 ok (ret, "releasecapture did not return TRUE.\n");
2538 ret = ReleaseCapture();
2539 ok (ret, "releasecapture did not return TRUE after second try.\n");
2542 static void test_keyboard_input(HWND hwnd)
2547 ShowWindow(hwnd, SW_SHOW);
2551 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2554 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2558 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2559 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2560 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2561 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2562 ok( !ret, "message %04x available\n", msg.message);
2564 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2566 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2567 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2568 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2569 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2570 ok( !ret, "message %04x available\n", msg.message);
2572 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2574 keybd_event(VK_SPACE, 0, 0, 0);
2575 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2576 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2577 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2578 ok( !ret, "message %04x available\n", msg.message);
2581 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2585 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2586 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2587 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2588 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2589 ok( !ret, "message %04x available\n", msg.message);
2591 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2593 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2594 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2595 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2596 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2597 ok( !ret, "message %04x available\n", msg.message);
2599 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2601 keybd_event(VK_SPACE, 0, 0, 0);
2602 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2603 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2604 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2605 ok( !ret, "message %04x available\n", msg.message);
2608 static void test_mouse_input(HWND hwnd)
2618 ShowWindow(hwnd, SW_SHOW);
2621 GetWindowRect(hwnd, &rc);
2622 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2624 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2625 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2628 ShowWindow(popup, SW_SHOW);
2629 UpdateWindow(popup);
2631 GetWindowRect(popup, &rc);
2632 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2634 x = rc.left + (rc.right - rc.left) / 2;
2635 y = rc.top + (rc.bottom - rc.top) / 2;
2636 trace("setting cursor to (%d,%d)\n", x, y);
2640 ok(x == pt.x && y == pt.y, "wrong cursor pos (%d,%d), expected (%d,%d)\n", pt.x, pt.y, x, y);
2644 /* Check that setting the same position will generate WM_MOUSEMOVE */
2647 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2648 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2649 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n", x, y, msg.pt.x, msg.pt.y);
2651 /* force the system to update its internal queue mouse position,
2652 * otherwise it won't generate relative mouse movements below.
2654 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2658 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2659 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2660 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2661 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2662 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2663 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2664 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2665 ok( !ret, "message %04x available\n", msg.message);
2667 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2668 ShowWindow(popup, SW_HIDE);
2669 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2670 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2673 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2674 ShowWindow(hwnd, SW_HIDE);
2675 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2676 ok( !ret, "message %04x available\n", msg.message);
2679 /* test mouse clicks */
2681 ShowWindow(hwnd, SW_SHOW);
2683 ShowWindow(popup, SW_SHOW);
2686 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2687 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2688 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2689 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2691 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2692 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2693 msg.hwnd, popup, msg.message);
2694 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2695 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2696 msg.hwnd, popup, msg.message);
2698 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2699 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2700 msg.hwnd, popup, msg.message);
2701 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2702 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2703 msg.hwnd, popup, msg.message);
2705 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2706 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
2707 msg.hwnd, popup, msg.message);
2708 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2709 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
2710 msg.hwnd, popup, msg.message);
2712 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2713 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2714 msg.hwnd, popup, msg.message);
2715 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2716 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2717 msg.hwnd, popup, msg.message);
2719 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2720 ok(!ret, "message %04x available\n", msg.message);
2722 ShowWindow(popup, SW_HIDE);
2725 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2726 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2727 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2728 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2730 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2731 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2732 msg.hwnd, hwnd, msg.message);
2733 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2734 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2735 msg.hwnd, hwnd, msg.message);
2737 test_lbuttondown_flag = TRUE;
2738 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
2739 test_lbuttondown_flag = FALSE;
2741 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2742 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2743 msg.hwnd, popup, msg.message);
2744 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2745 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2746 msg.hwnd, popup, msg.message);
2747 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2749 /* Test WM_MOUSEACTIVATE */
2750 #define TEST_MOUSEACTIVATE(A,B) \
2751 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2752 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2754 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
2755 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
2756 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
2757 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
2758 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
2759 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
2760 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
2761 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
2762 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
2763 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
2764 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
2765 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
2766 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
2767 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
2768 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
2769 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
2770 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
2771 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
2772 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
2773 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
2774 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
2775 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
2776 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
2777 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
2779 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2782 DestroyWindow(popup);
2785 static void test_validatergn(HWND hwnd)
2791 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
2792 ShowWindow(hwnd, SW_SHOW);
2793 UpdateWindow( hwnd);
2794 /* test that ValidateRect validates children*/
2795 InvalidateRect( child, NULL, 1);
2796 GetWindowRect( child, &rc);
2797 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2798 ret = GetUpdateRect( child, &rc2, 0);
2799 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
2800 "Update rectangle is empty!\n");
2801 ValidateRect( hwnd, &rc);
2802 ret = GetUpdateRect( child, &rc2, 0);
2803 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2804 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2805 rc2.right, rc2.bottom);
2807 /* now test ValidateRgn */
2808 InvalidateRect( child, NULL, 1);
2809 GetWindowRect( child, &rc);
2810 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2811 rgn = CreateRectRgnIndirect( &rc);
2812 ValidateRgn( hwnd, rgn);
2813 ret = GetUpdateRect( child, &rc2, 0);
2814 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2815 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2816 rc2.right, rc2.bottom);
2819 DestroyWindow( child );
2822 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
2824 MoveWindow( hwnd, 0, 0, x, y, 0);
2825 GetWindowRect( hwnd, prc);
2826 trace("window rect is %d,%d - %d,%d\n",
2827 prc->left,prc->top,prc->right,prc->bottom);
2828 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
2829 trace("nccalc rect is %d,%d - %d,%d\n",
2830 prc->left,prc->top,prc->right,prc->bottom);
2833 static void test_nccalcscroll(HWND parent)
2836 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
2837 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
2838 HWND hwnd = CreateWindowExA(0, "static", NULL,
2839 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
2840 10, 10, 200, 200, parent, 0, 0, NULL);
2841 ShowWindow( parent, SW_SHOW);
2842 UpdateWindow( parent);
2844 /* test window too low for a horizontal scroll bar */
2845 nccalchelper( hwnd, 100, sbheight, &rc1);
2846 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
2847 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
2849 /* test window just high enough for a horizontal scroll bar */
2850 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
2851 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
2852 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2854 /* test window too narrow for a vertical scroll bar */
2855 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
2856 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
2857 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2859 /* test window just wide enough for a vertical scroll bar */
2860 nccalchelper( hwnd, sbwidth, 100, &rc1);
2861 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
2862 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
2864 /* same test, but with client edge: not enough width */
2865 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
2866 nccalchelper( hwnd, sbwidth, 100, &rc1);
2867 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
2868 "Width should be %d size is %d,%d - %d,%d\n",
2869 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
2871 DestroyWindow( hwnd);
2874 static void test_SetParent(void)
2877 HWND desktop = GetDesktopWindow();
2879 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
2880 HWND parent, child1, child2, child3, child4, sibling;
2882 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2883 100, 100, 200, 200, 0, 0, 0, NULL);
2884 assert(parent != 0);
2885 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2886 0, 0, 50, 50, parent, 0, 0, NULL);
2887 assert(child1 != 0);
2888 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2889 0, 0, 50, 50, child1, 0, 0, NULL);
2890 assert(child2 != 0);
2891 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2892 0, 0, 50, 50, child2, 0, 0, NULL);
2893 assert(child3 != 0);
2894 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2895 0, 0, 50, 50, child3, 0, 0, NULL);
2896 assert(child4 != 0);
2898 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2899 parent, child1, child2, child3, child4);
2901 check_parents(parent, desktop, 0, 0, 0, parent, parent);
2902 check_parents(child1, parent, parent, parent, 0, parent, parent);
2903 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2904 check_parents(child3, child2, child2, child2, 0, child2, parent);
2905 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2907 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
2908 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
2909 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2910 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
2911 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2913 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
2914 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2915 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
2916 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
2917 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
2918 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
2919 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
2920 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
2921 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2923 if (!is_win9x) /* Win9x doesn't survive this test */
2925 ok(!SetParent(parent, child1), "SetParent should fail\n");
2926 ok(!SetParent(child2, child3), "SetParent should fail\n");
2927 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
2928 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
2929 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
2930 ok(!SetParent(child2, parent), "SetParent should fail\n");
2931 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
2933 check_parents(parent, child4, child4, 0, 0, child4, parent);
2934 check_parents(child1, parent, parent, parent, 0, child4, parent);
2935 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2936 check_parents(child3, child2, child2, child2, 0, child2, parent);
2937 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2940 hMenu = CreateMenu();
2941 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2942 100, 100, 200, 200, 0, hMenu, 0, NULL);
2943 assert(sibling != 0);
2945 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
2946 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
2948 ret = DestroyWindow(parent);
2949 ok( ret, "DestroyWindow() error %d\n", GetLastError());
2951 ok(!IsWindow(parent), "parent still exists\n");
2952 ok(!IsWindow(sibling), "sibling still exists\n");
2953 ok(!IsWindow(child1), "child1 still exists\n");
2954 ok(!IsWindow(child2), "child2 still exists\n");
2955 ok(!IsWindow(child3), "child3 still exists\n");
2956 ok(!IsWindow(child4), "child4 still exists\n");
2959 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2961 LPCREATESTRUCT lpcs;
2968 lpcs = (LPCREATESTRUCT)lparam;
2969 lpss = (LPSTYLESTRUCT)lpcs->lpCreateParams;
2972 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
2973 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
2974 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
2975 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
2977 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
2979 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
2980 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2981 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
2983 ok(lpss->styleNew == lpcs->style,
2984 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
2985 lpss->styleNew, lpcs->style);
2989 return DefWindowProc(hwnd, msg, wparam, lparam);
2992 static ATOM atomStyleCheckClass;
2994 static void register_style_check_class(void)
3002 GetModuleHandle(NULL),
3004 LoadCursor(NULL, IDC_ARROW),
3005 (HBRUSH)(COLOR_BTNFACE+1),
3007 TEXT("WineStyleCheck"),
3010 atomStyleCheckClass = RegisterClass(&wc);
3013 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3015 DWORD dwActualStyle;
3016 DWORD dwActualExStyle;
3019 HWND hwndParent = NULL;
3021 ss.styleNew = dwStyleIn;
3022 ss.styleOld = dwExStyleIn;
3024 if (dwStyleIn & WS_CHILD)
3026 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
3027 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3030 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
3031 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3036 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3037 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3038 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3039 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3040 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3042 DestroyWindow(hwnd);
3043 if (hwndParent) DestroyWindow(hwndParent);
3046 /* tests what window styles the window manager automatically adds */
3047 static void test_window_styles(void)
3049 register_style_check_class();
3051 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3052 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3053 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3054 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3055 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3056 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3057 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3058 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3059 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3060 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3061 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3064 static void test_scrollvalidate( HWND parent)
3067 HRGN hrgn=CreateRectRgn(0,0,0,0);
3068 HRGN exprgn, tmprgn, clipping;
3069 RECT rc, rcu, cliprc;
3070 /* create two overlapping child windows. The visual region
3071 * of hwnd1 is clipped by the overlapping part of
3072 * hwnd2 because of the WS_CLIPSIBLING style */
3075 clipping = CreateRectRgn(0,0,0,0);
3076 tmprgn = CreateRectRgn(0,0,0,0);
3077 exprgn = CreateRectRgn(0,0,0,0);
3078 hwnd2 = CreateWindowExA(0, "static", NULL,
3079 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3080 75, 30, 100, 100, parent, 0, 0, NULL);
3081 hwnd1 = CreateWindowExA(0, "static", NULL,
3082 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3083 25, 50, 100, 100, parent, 0, 0, NULL);
3084 ShowWindow( parent, SW_SHOW);
3085 UpdateWindow( parent);
3086 GetClientRect( hwnd1, &rc);
3088 SetRectRgn( clipping, 10, 10, 90, 90);
3089 hdc = GetDC( hwnd1);
3090 /* for a visual touch */
3091 TextOut( hdc, 0,10, "0123456789", 10);
3092 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3093 if (winetest_debug > 0) dump_region(hrgn);
3094 /* create a region with what is expected */
3095 SetRectRgn( exprgn, 39,0,49,74);
3096 SetRectRgn( tmprgn, 88,79,98,93);
3097 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3098 SetRectRgn( tmprgn, 0,93,98,98);
3099 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3100 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3101 trace("update rect is %d,%d - %d,%d\n",
3102 rcu.left,rcu.top,rcu.right,rcu.bottom);
3103 /* now with clipping region */
3104 SelectClipRgn( hdc, clipping);
3105 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3106 if (winetest_debug > 0) dump_region(hrgn);
3107 /* create a region with what is expected */
3108 SetRectRgn( exprgn, 39,10,49,74);
3109 SetRectRgn( tmprgn, 80,79,90,85);
3110 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3111 SetRectRgn( tmprgn, 10,85,90,90);
3112 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3113 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3114 trace("update rect is %d,%d - %d,%d\n",
3115 rcu.left,rcu.top,rcu.right,rcu.bottom);
3116 ReleaseDC( hwnd1, hdc);
3118 /* test scrolling a window with an update region */
3119 DestroyWindow( hwnd2);
3120 ValidateRect( hwnd1, NULL);
3121 SetRect( &rc, 40,40, 50,50);
3122 InvalidateRect( hwnd1, &rc, 1);
3123 GetClientRect( hwnd1, &rc);
3125 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
3126 SW_SCROLLCHILDREN | SW_INVALIDATE);
3127 if (winetest_debug > 0) dump_region(hrgn);
3128 SetRectRgn( exprgn, 88,0,98,98);
3129 SetRectRgn( tmprgn, 30, 40, 50, 50);
3130 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3131 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3133 /* clear an update region */
3134 UpdateWindow( hwnd1 );
3136 SetRect( &rc, 0,40, 100,60);
3137 SetRect( &cliprc, 0,0, 100,100);
3138 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3139 if (winetest_debug > 0) dump_region( hrgn );
3140 SetRectRgn( exprgn, 0, 40, 98, 60 );
3141 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
3143 /* now test ScrollWindowEx with a combination of
3144 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3145 /* make hwnd2 the child of hwnd1 */
3146 hwnd2 = CreateWindowExA(0, "static", NULL,
3147 WS_CHILD| WS_VISIBLE | WS_BORDER ,
3148 50, 50, 100, 100, hwnd1, 0, 0, NULL);
3149 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
3150 GetClientRect( hwnd1, &rc);
3153 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3154 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3155 ValidateRect( hwnd1, NULL);
3156 ValidateRect( hwnd2, NULL);
3157 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
3158 SW_SCROLLCHILDREN | SW_INVALIDATE);
3159 if (winetest_debug > 0) dump_region(hrgn);
3160 SetRectRgn( exprgn, 88,0,98,88);
3161 SetRectRgn( tmprgn, 0,88,98,98);
3162 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3163 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3165 /* SW_SCROLLCHILDREN */
3166 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3167 ValidateRect( hwnd1, NULL);
3168 ValidateRect( hwnd2, NULL);
3169 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3170 if (winetest_debug > 0) dump_region(hrgn);
3171 /* expected region is the same as in previous test */
3172 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3174 /* no SW_SCROLLCHILDREN */
3175 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3176 ValidateRect( hwnd1, NULL);
3177 ValidateRect( hwnd2, NULL);
3178 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3179 if (winetest_debug > 0) dump_region(hrgn);
3180 /* expected region is the same as in previous test */
3181 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3183 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3184 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3185 ValidateRect( hwnd1, NULL);
3186 ValidateRect( hwnd2, NULL);
3187 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3188 if (winetest_debug > 0) dump_region(hrgn);
3189 SetRectRgn( exprgn, 88,0,98,20);
3190 SetRectRgn( tmprgn, 20,20,98,30);
3191 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3192 SetRectRgn( tmprgn, 20,30,30,88);
3193 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3194 SetRectRgn( tmprgn, 0,88,30,98);
3195 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3196 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3199 DeleteObject( hrgn);
3200 DeleteObject( exprgn);
3201 DeleteObject( tmprgn);
3202 DestroyWindow( hwnd1);
3203 DestroyWindow( hwnd2);
3206 /* couple of tests of return values of scrollbar functions
3207 * called on a scrollbarless window */
3208 static void test_scroll(void)
3213 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3214 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3215 100, 100, 200, 200, 0, 0, 0, NULL);
3217 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3218 ok( ret, "GetScrollRange returns FALSE\n");
3219 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3220 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3221 si.cbSize = sizeof( si);
3222 si.fMask = SIF_PAGE;
3223 si.nPage = 0xdeadbeef;
3224 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3225 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3226 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3228 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3229 ok( ret, "GetScrollRange returns FALSE\n");
3230 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3231 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3232 si.cbSize = sizeof( si);
3233 si.fMask = SIF_PAGE;
3234 si.nPage = 0xdeadbeef;
3235 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3236 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3237 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3239 DestroyWindow( hwnd);
3242 static void test_scrolldc( HWND parent)
3245 HRGN exprgn, tmprgn, hrgn;
3246 RECT rc, rc2, rcu, cliprc;
3250 hrgn = CreateRectRgn(0,0,0,0);
3251 tmprgn = CreateRectRgn(0,0,0,0);
3252 exprgn = CreateRectRgn(0,0,0,0);
3254 hwnd1 = CreateWindowExA(0, "static", NULL,
3255 WS_CHILD| WS_VISIBLE,
3256 25, 50, 100, 100, parent, 0, 0, NULL);
3257 ShowWindow( parent, SW_SHOW);
3258 UpdateWindow( parent);
3260 GetClientRect( hwnd1, &rc);
3261 hdc = GetDC( hwnd1);
3262 /* paint the upper half of the window black */
3264 rc2.bottom = ( rc.top + rc.bottom) /2;
3265 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3266 /* clip region is the lower half */
3268 cliprc.top = (rc.top + rc.bottom) /2;
3269 /* test whether scrolled pixels are properly clipped */
3270 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3271 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3272 /* this scroll should not cause any visible changes */
3273 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3274 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3275 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3276 /* test with NULL clip rect */
3277 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3278 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3279 trace("update rect: %d,%d - %d,%d\n",
3280 rcu.left, rcu.top, rcu.right, rcu.bottom);
3281 if (winetest_debug > 0) dump_region(hrgn);
3282 SetRect(&rc2, 0, 0, 100, 100);
3283 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3284 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3286 SetRectRgn( exprgn, 0, 0, 20, 80);
3287 SetRectRgn( tmprgn, 0, 80, 100, 100);
3288 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3289 if (winetest_debug > 0) dump_region(exprgn);
3290 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3291 /* test clip rect > scroll rect */
3292 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3294 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3295 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3296 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3297 SetRectRgn( exprgn, 25, 25, 75, 35);
3298 SetRectRgn( tmprgn, 25, 35, 35, 75);
3299 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3300 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3301 colr = GetPixel( hdc, 80, 80);
3302 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3303 trace("update rect: %d,%d - %d,%d\n",
3304 rcu.left, rcu.top, rcu.right, rcu.bottom);
3305 if (winetest_debug > 0) dump_region(hrgn);
3309 DeleteObject(exprgn);
3310 DeleteObject(tmprgn);
3311 DestroyWindow(hwnd1);
3314 static void test_params(void)
3319 /* Just a param check */
3320 SetLastError(0xdeadbeef);
3321 rc = GetWindowText(hwndMain2, NULL, 1024);
3322 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
3324 SetLastError(0xdeadbeef);
3325 hwnd=CreateWindow("LISTBOX", "TestList",
3326 (LBS_STANDARD & ~LBS_SORT),
3328 NULL, (HMENU)1, NULL, 0);
3330 ok(!hwnd, "CreateWindow with invalid menu handle should fail\n");
3331 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3332 GetLastError() == 0xdeadbeef, /* Win9x */
3333 "wrong last error value %d\n", GetLastError());
3336 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3340 hwnd = CreateWindowEx(exStyle, class, class, style,
3347 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
3350 ShowWindow(hwnd, SW_SHOW);
3352 test_nonclient_area(hwnd);
3355 DestroyWindow(hwnd);
3358 static BOOL AWR_init(void)
3362 class.style = CS_HREDRAW | CS_VREDRAW;
3363 class.lpfnWndProc = DefWindowProcA;
3364 class.cbClsExtra = 0;
3365 class.cbWndExtra = 0;
3366 class.hInstance = 0;
3367 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3368 class.hCursor = LoadCursor (0, IDC_ARROW);
3369 class.hbrBackground = 0;
3370 class.lpszMenuName = 0;
3371 class.lpszClassName = szAWRClass;
3373 if (!RegisterClass (&class)) {
3374 ok(FALSE, "RegisterClass failed\n");
3378 hmenu = CreateMenu();
3381 ok(hmenu != 0, "Failed to create menu\n");
3382 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3388 static void test_AWR_window_size(BOOL menu)
3392 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3395 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3396 WS_HSCROLL, WS_VSCROLL
3400 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3403 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3404 WS_EX_DLGMODALFRAME,
3411 /* A exhaustive check of all the styles takes too long
3412 * so just do a (hopefully representative) sample
3414 for (i = 0; i < COUNTOF(styles); ++i)
3415 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3416 for (i = 0; i < COUNTOF(exStyles); ++i) {
3417 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3418 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3423 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3425 static void test_AdjustWindowRect(void)
3430 SHOWSYSMETRIC(SM_CYCAPTION);
3431 SHOWSYSMETRIC(SM_CYSMCAPTION);
3432 SHOWSYSMETRIC(SM_CYMENU);
3433 SHOWSYSMETRIC(SM_CXEDGE);
3434 SHOWSYSMETRIC(SM_CYEDGE);
3435 SHOWSYSMETRIC(SM_CXVSCROLL);
3436 SHOWSYSMETRIC(SM_CYHSCROLL);
3437 SHOWSYSMETRIC(SM_CXFRAME);
3438 SHOWSYSMETRIC(SM_CYFRAME);
3439 SHOWSYSMETRIC(SM_CXDLGFRAME);
3440 SHOWSYSMETRIC(SM_CYDLGFRAME);
3441 SHOWSYSMETRIC(SM_CXBORDER);
3442 SHOWSYSMETRIC(SM_CYBORDER);
3444 test_AWR_window_size(FALSE);
3445 test_AWR_window_size(TRUE);
3449 #undef SHOWSYSMETRIC
3452 /* Global variables to trigger exit from loop */
3453 static int redrawComplete, WMPAINT_count;
3455 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3460 trace("doing WM_PAINT %d\n", WMPAINT_count);
3462 if (WMPAINT_count > 10 && redrawComplete == 0) {
3464 BeginPaint(hwnd, &ps);
3465 EndPaint(hwnd, &ps);
3470 return DefWindowProc(hwnd, msg, wparam, lparam);
3473 /* Ensure we exit from RedrawNow regardless of invalidated area */
3474 static void test_redrawnow(void)
3479 cls.style = CS_DBLCLKS;
3480 cls.lpfnWndProc = redraw_window_procA;
3483 cls.hInstance = GetModuleHandleA(0);
3485 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3486 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3487 cls.lpszMenuName = NULL;
3488 cls.lpszClassName = "RedrawWindowClass";
3490 if(!RegisterClassA(&cls)) {
3491 trace("Register failed %d\n", GetLastError());
3495 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3496 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3498 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3499 ShowWindow(hwndMain, SW_SHOW);
3500 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3501 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3502 ok( WMPAINT_count == 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3503 redrawComplete = TRUE;
3504 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3507 DestroyWindow( hwndMain);
3510 struct parentdc_stat {
3516 struct parentdc_test {
3517 struct parentdc_stat main, main_todo;
3518 struct parentdc_stat child1, child1_todo;
3519 struct parentdc_stat child2, child2_todo;
3522 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3527 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3532 trace("doing WM_PAINT on %p\n", hwnd);
3533 GetClientRect(hwnd, &rc);
3534 CopyRect(&t->client, &rc);
3535 trace("client rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3536 GetWindowRect(hwnd, &rc);
3537 trace("window rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3538 BeginPaint(hwnd, &ps);
3539 CopyRect(&t->paint, &ps.rcPaint);
3540 GetClipBox(ps.hdc, &rc);
3541 CopyRect(&t->clip, &rc);
3542 trace("clip rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3543 trace("paint rect (%d, %d)-(%d, %d)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3544 EndPaint(hwnd, &ps);
3547 return DefWindowProc(hwnd, msg, wparam, lparam);
3550 static void zero_parentdc_stat(struct parentdc_stat *t)
3552 SetRectEmpty(&t->client);
3553 SetRectEmpty(&t->clip);
3554 SetRectEmpty(&t->paint);
3557 static void zero_parentdc_test(struct parentdc_test *t)
3559 zero_parentdc_stat(&t->main);
3560 zero_parentdc_stat(&t->child1);
3561 zero_parentdc_stat(&t->child2);
3564 #define parentdc_field_ok(t, w, r, f, got) \
3565 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3566 ": expected %d, got %d\n", \
3569 #define parentdc_todo_field_ok(t, w, r, f, got) \
3570 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3571 else parentdc_field_ok(t, w, r, f, got)
3573 #define parentdc_rect_ok(t, w, r, got) \
3574 parentdc_todo_field_ok(t, w, r, left, got); \
3575 parentdc_todo_field_ok(t, w, r, top, got); \
3576 parentdc_todo_field_ok(t, w, r, right, got); \
3577 parentdc_todo_field_ok(t, w, r, bottom, got);
3579 #define parentdc_win_ok(t, w, got) \
3580 parentdc_rect_ok(t, w, client, got); \
3581 parentdc_rect_ok(t, w, clip, got); \
3582 parentdc_rect_ok(t, w, paint, got);
3584 #define parentdc_ok(t, got) \
3585 parentdc_win_ok(t, main, got); \
3586 parentdc_win_ok(t, child1, got); \
3587 parentdc_win_ok(t, child2, got);
3589 static void test_csparentdc(void)
3591 WNDCLASSA clsMain, cls;
3592 HWND hwndMain, hwnd1, hwnd2;
3595 struct parentdc_test test_answer;
3597 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3598 const struct parentdc_test test1 =
3600 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
3601 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3602 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3605 const struct parentdc_test test2 =
3607 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
3608 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3609 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3612 const struct parentdc_test test3 =
3614 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3615 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3616 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3619 const struct parentdc_test test4 =
3621 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
3622 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
3623 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3626 const struct parentdc_test test5 =
3628 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
3629 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3630 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3633 const struct parentdc_test test6 =
3635 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3636 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3637 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3640 const struct parentdc_test test7 =
3642 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3643 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3644 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3648 clsMain.style = CS_DBLCLKS;
3649 clsMain.lpfnWndProc = parentdc_window_procA;
3650 clsMain.cbClsExtra = 0;
3651 clsMain.cbWndExtra = 0;
3652 clsMain.hInstance = GetModuleHandleA(0);
3654 clsMain.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3655 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
3656 clsMain.lpszMenuName = NULL;
3657 clsMain.lpszClassName = "ParentDcMainWindowClass";
3659 if(!RegisterClassA(&clsMain)) {
3660 trace("Register failed %d\n", GetLastError());
3664 cls.style = CS_DBLCLKS | CS_PARENTDC;
3665 cls.lpfnWndProc = parentdc_window_procA;
3668 cls.hInstance = GetModuleHandleA(0);
3670 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3671 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3672 cls.lpszMenuName = NULL;
3673 cls.lpszClassName = "ParentDcWindowClass";
3675 if(!RegisterClassA(&cls)) {
3676 trace("Register failed %d\n", GetLastError());
3680 SetRect(&rc, 0, 0, 150, 150);
3681 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
3682 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3683 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
3684 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
3685 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
3686 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
3687 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
3688 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
3689 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
3690 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
3691 ShowWindow(hwndMain, SW_SHOW);
3692 ShowWindow(hwnd1, SW_SHOW);
3693 ShowWindow(hwnd2, SW_SHOW);
3696 zero_parentdc_test(&test_answer);
3697 InvalidateRect(hwndMain, NULL, TRUE);
3699 parentdc_ok(test1, test_answer);
3701 zero_parentdc_test(&test_answer);
3702 SetRect(&rc, 0, 0, 50, 50);
3703 InvalidateRect(hwndMain, &rc, TRUE);
3705 parentdc_ok(test2, test_answer);
3707 zero_parentdc_test(&test_answer);
3708 SetRect(&rc, 0, 0, 10, 10);
3709 InvalidateRect(hwndMain, &rc, TRUE);
3711 parentdc_ok(test3, test_answer);
3713 zero_parentdc_test(&test_answer);
3714 SetRect(&rc, 40, 40, 50, 50);
3715 InvalidateRect(hwndMain, &rc, TRUE);
3717 parentdc_ok(test4, test_answer);
3719 zero_parentdc_test(&test_answer);
3720 SetRect(&rc, 20, 20, 60, 60);
3721 InvalidateRect(hwndMain, &rc, TRUE);
3723 parentdc_ok(test5, test_answer);
3725 zero_parentdc_test(&test_answer);
3726 SetRect(&rc, 0, 0, 10, 10);
3727 InvalidateRect(hwnd1, &rc, TRUE);
3729 parentdc_ok(test6, test_answer);
3731 zero_parentdc_test(&test_answer);
3732 SetRect(&rc, -5, -5, 65, 65);
3733 InvalidateRect(hwnd1, &rc, TRUE);
3735 parentdc_ok(test7, test_answer);
3737 DestroyWindow(hwndMain);
3738 DestroyWindow(hwnd1);
3739 DestroyWindow(hwnd2);
3742 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3744 return DefWindowProcA(hwnd, msg, wparam, lparam);
3747 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3749 return DefWindowProcW(hwnd, msg, wparam, lparam);
3752 static void test_IsWindowUnicode(void)
3754 static const char ansi_class_nameA[] = "ansi class name";
3755 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3756 static const char unicode_class_nameA[] = "unicode class name";
3757 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3762 memset(&classW, 0, sizeof(classW));
3763 classW.hInstance = GetModuleHandleA(0);
3764 classW.lpfnWndProc = def_window_procW;
3765 classW.lpszClassName = unicode_class_nameW;
3766 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
3768 memset(&classA, 0, sizeof(classA));
3769 classA.hInstance = GetModuleHandleA(0);
3770 classA.lpfnWndProc = def_window_procA;
3771 classA.lpszClassName = ansi_class_nameA;
3772 assert(RegisterClassA(&classA));
3774 /* unicode class: window proc */
3775 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3776 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3779 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3780 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3781 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3782 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3783 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3785 DestroyWindow(hwnd);
3787 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3788 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3791 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3792 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3793 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3794 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3795 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3797 DestroyWindow(hwnd);
3799 /* ansi class: window proc */
3800 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3801 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3804 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3805 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3806 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3807 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3808 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3810 DestroyWindow(hwnd);
3812 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3813 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3816 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3817 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3818 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3819 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3820 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3822 DestroyWindow(hwnd);
3824 /* unicode class: class proc */
3825 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3826 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3829 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3830 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3831 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3832 /* do not restore class window proc back to unicode */
3834 DestroyWindow(hwnd);
3836 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3837 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3840 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3841 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
3842 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3844 DestroyWindow(hwnd);
3846 /* ansi class: class proc */
3847 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3848 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3851 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3852 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
3853 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3854 /* do not restore class window proc back to ansi */
3856 DestroyWindow(hwnd);
3858 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3859 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3862 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3863 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3864 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3866 DestroyWindow(hwnd);
3869 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
3873 if (msg != WM_GETMINMAXINFO)
3874 return DefWindowProc(hwnd, msg, wp, lp);
3876 minmax = (MINMAXINFO *)lp;
3878 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
3880 minmax->ptReserved.x = 0;
3881 minmax->ptReserved.y = 0;
3882 minmax->ptMaxSize.x = 400;
3883 minmax->ptMaxSize.y = 400;
3884 minmax->ptMaxPosition.x = 300;
3885 minmax->ptMaxPosition.y = 300;
3886 minmax->ptMaxTrackSize.x = 200;
3887 minmax->ptMaxTrackSize.y = 200;
3888 minmax->ptMinTrackSize.x = 100;
3889 minmax->ptMinTrackSize.y = 100;
3892 DefWindowProc(hwnd, msg, wp, lp);
3896 static int expected_cx, expected_cy;
3897 static RECT expected_rect;
3899 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
3903 case WM_GETMINMAXINFO:
3906 GetWindowRect( hwnd, &rect );
3907 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
3908 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
3909 return DefWindowProc(hwnd, msg, wp, lp);
3914 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
3916 GetWindowRect( hwnd, &rect );
3917 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
3918 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
3919 ok( cs->cx == expected_cx, "wrong x size %d/%d\n", cs->cx, expected_cx );
3920 ok( cs->cy == expected_cy, "wrong y size %d/%d\n", cs->cy, expected_cy );
3921 ok( rect.right - rect.left == expected_rect.right - expected_rect.left &&
3922 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top,
3923 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
3924 rect.left, rect.top, rect.right, rect.bottom,
3925 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
3926 return DefWindowProc(hwnd, msg, wp, lp);
3929 return DefWindowProc(hwnd, msg, wp, lp);
3933 static void test_CreateWindow(void)
3941 #define expect_menu(window, menu) \
3942 SetLastError(0xdeadbeef); \
3943 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
3945 #define expect_style(window, style)\
3946 ok(GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
3948 #define expect_ex_style(window, ex_style)\
3949 ok(GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
3951 hmenu = CreateMenu();
3953 parent = GetDesktopWindow();
3954 assert(parent != 0);
3956 SetLastError(0xdeadbeef);
3957 ok(IsMenu(hmenu), "IsMenu error %d\n", GetLastError());
3960 SetLastError(0xdeadbeef);
3961 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
3962 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3963 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3964 expect_menu(hwnd, 1);
3965 expect_style(hwnd, WS_CHILD);
3966 expect_ex_style(hwnd, WS_EX_APPWINDOW);
3967 DestroyWindow(hwnd);
3969 SetLastError(0xdeadbeef);
3970 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
3971 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3972 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3973 expect_menu(hwnd, 1);
3974 expect_style(hwnd, WS_CHILD | WS_CAPTION);
3975 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
3976 DestroyWindow(hwnd);
3978 SetLastError(0xdeadbeef);
3979 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
3980 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3981 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3982 expect_menu(hwnd, 1);
3983 expect_style(hwnd, WS_CHILD);
3984 expect_ex_style(hwnd, 0);
3985 DestroyWindow(hwnd);
3987 SetLastError(0xdeadbeef);
3988 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
3989 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3990 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3991 expect_menu(hwnd, 1);
3992 expect_style(hwnd, WS_CHILD | WS_CAPTION);
3993 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
3994 DestroyWindow(hwnd);
3997 SetLastError(0xdeadbeef);
3998 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
3999 0, 0, 100, 100, parent, hmenu, 0, NULL);
4000 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4001 expect_menu(hwnd, hmenu);
4002 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4003 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4004 DestroyWindow(hwnd);
4005 SetLastError(0xdeadbeef);
4006 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4007 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4009 hmenu = CreateMenu();
4011 SetLastError(0xdeadbeef);
4012 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
4013 0, 0, 100, 100, parent, hmenu, 0, NULL);
4014 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4015 expect_menu(hwnd, hmenu);
4016 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4017 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4018 DestroyWindow(hwnd);
4019 SetLastError(0xdeadbeef);
4020 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4021 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4023 hmenu = CreateMenu();
4025 SetLastError(0xdeadbeef);
4026 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
4027 0, 0, 100, 100, parent, hmenu, 0, NULL);
4028 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4029 expect_menu(hwnd, hmenu);
4030 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4031 expect_ex_style(hwnd, 0);
4032 DestroyWindow(hwnd);
4033 SetLastError(0xdeadbeef);
4034 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4035 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4037 hmenu = CreateMenu();
4039 SetLastError(0xdeadbeef);
4040 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
4041 0, 0, 100, 100, parent, hmenu, 0, NULL);
4042 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4043 expect_menu(hwnd, hmenu);
4044 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4045 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4046 DestroyWindow(hwnd);
4047 SetLastError(0xdeadbeef);
4048 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4049 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4051 /* WS_CHILD | WS_POPUP */
4052 SetLastError(0xdeadbeef);
4053 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4054 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4055 ok(!hwnd, "CreateWindowEx should fail\n");
4056 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4058 hmenu = CreateMenu();
4060 SetLastError(0xdeadbeef);
4061 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4062 0, 0, 100, 100, parent, hmenu, 0, NULL);
4063 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4064 expect_menu(hwnd, hmenu);
4065 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4066 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4067 DestroyWindow(hwnd);
4068 SetLastError(0xdeadbeef);
4069 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4070 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4072 SetLastError(0xdeadbeef);
4073 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4074 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4075 ok(!hwnd, "CreateWindowEx should fail\n");
4076 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4078 hmenu = CreateMenu();
4080 SetLastError(0xdeadbeef);
4081 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4082 0, 0, 100, 100, parent, hmenu, 0, NULL);
4083 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4084 expect_menu(hwnd, hmenu);
4085 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4086 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4087 DestroyWindow(hwnd);
4088 SetLastError(0xdeadbeef);
4089 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4090 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4092 SetLastError(0xdeadbeef);
4093 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4094 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4095 ok(!hwnd, "CreateWindowEx should fail\n");
4096 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4098 hmenu = CreateMenu();
4100 SetLastError(0xdeadbeef);
4101 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4102 0, 0, 100, 100, parent, hmenu, 0, NULL);
4103 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4104 expect_menu(hwnd, hmenu);
4105 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4106 expect_ex_style(hwnd, 0);
4107 DestroyWindow(hwnd);
4108 SetLastError(0xdeadbeef);
4109 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4110 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4112 SetLastError(0xdeadbeef);
4113 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4114 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4115 ok(!hwnd, "CreateWindowEx should fail\n");
4116 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4118 hmenu = CreateMenu();
4120 SetLastError(0xdeadbeef);
4121 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4122 0, 0, 100, 100, parent, hmenu, 0, NULL);
4123 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4124 expect_menu(hwnd, hmenu);
4125 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4126 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4127 DestroyWindow(hwnd);
4128 SetLastError(0xdeadbeef);
4129 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4130 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4132 /* test child window sizing */
4134 cls.lpfnWndProc = minmax_wnd_proc;
4137 cls.hInstance = GetModuleHandle(0);
4139 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
4140 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4141 cls.lpszMenuName = NULL;
4142 cls.lpszClassName = "MinMax_WndClass";
4143 RegisterClass(&cls);
4145 SetLastError(0xdeadbeef);
4146 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4147 0, 0, 100, 100, 0, 0, 0, NULL);
4148 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4149 expect_menu(parent, 0);
4150 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
4151 expect_ex_style(parent, WS_EX_WINDOWEDGE);
4153 memset(&minmax, 0, sizeof(minmax));
4154 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4155 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
4156 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
4157 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4158 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
4160 GetWindowRect(parent, &rc);
4161 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
4162 GetClientRect(parent, &rc);
4163 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
4165 InflateRect(&rc, 200, 200);
4166 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4168 SetLastError(0xdeadbeef);
4169 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4170 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
4171 parent, (HMENU)1, 0, NULL);
4172 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4173 expect_menu(hwnd, 1);
4174 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
4175 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4177 memset(&minmax, 0, sizeof(minmax));
4178 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4179 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4181 GetWindowRect(hwnd, &rc);
4182 OffsetRect(&rc, -rc.left, -rc.top);
4183 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4184 rc.left, rc.top, rc.right, rc.bottom,
4185 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
4186 DestroyWindow(hwnd);
4188 cls.lpfnWndProc = winsizes_wnd_proc;
4189 cls.lpszClassName = "Sizes_WndClass";
4190 RegisterClass(&cls);
4192 expected_cx = expected_cy = 200000;
4193 SetRect( &expected_rect, 0, 0, 200000, 200000 );
4194 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
4195 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4196 GetClientRect( hwnd, &rc );
4197 ok( rc.right == 200000, "invalid rect right %u\n", rc.right );
4198 ok( rc.bottom == 200000, "invalid rect bottom %u\n", rc.bottom );
4199 DestroyWindow(hwnd);
4201 expected_cx = expected_cy = -10;
4202 SetRect( &expected_rect, 0, 0, 0, 0 );
4203 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
4204 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4205 GetClientRect( hwnd, &rc );
4206 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4207 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4208 DestroyWindow(hwnd);
4210 expected_cx = expected_cy = -200000;
4211 SetRect( &expected_rect, 0, 0, 0, 0 );
4212 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
4213 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4214 GetClientRect( hwnd, &rc );
4215 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4216 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4217 DestroyWindow(hwnd);
4219 /* top level window */
4220 expected_cx = expected_cy = 200000;
4221 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
4222 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
4223 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4224 GetClientRect( hwnd, &rc );
4225 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
4226 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
4227 DestroyWindow(hwnd);
4229 DestroyWindow(parent);
4231 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4232 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4236 #undef expect_ex_style
4239 /* function that remembers whether the system the test is running on sets the
4240 * last error for user32 functions to make the tests stricter */
4241 static int check_error(DWORD actual, DWORD expected)
4243 static int sets_last_error = -1;
4244 if (sets_last_error == -1)
4245 sets_last_error = (actual != 0xdeadbeef);
4246 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
4249 static void test_SetWindowLong(void)
4252 WNDPROC old_window_procW;
4254 SetLastError(0xdeadbeef);
4255 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
4256 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
4257 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
4258 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4260 SetLastError(0xdeadbeef);
4261 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
4262 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
4263 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
4264 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4266 SetLastError(0xdeadbeef);
4267 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4268 ok((WNDPROC)retval == main_window_procA,
4269 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
4270 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4271 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
4272 ok((WNDPROC)retval == main_window_procA,
4273 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4274 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
4276 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
4277 SetLastError(0xdeadbeef);
4278 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
4279 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
4281 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4282 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
4283 ok((WNDPROC)retval == old_window_procW,
4284 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4285 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
4287 /* set it back to ANSI */
4288 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4292 static void test_ShowWindow(void)
4299 SetRect(&rcMain, 120, 120, 210, 210);
4301 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
4302 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4303 WS_MAXIMIZEBOX | WS_POPUP,
4304 rcMain.left, rcMain.top,
4305 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
4309 style = GetWindowLong(hwnd, GWL_STYLE);
4310 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4311 ok(!(style & WS_VISIBLE), "window should not be visible\n");
4312 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4313 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4314 GetWindowRect(hwnd, &rc);
4315 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4317 ret = ShowWindow(hwnd, SW_SHOW);
4318 ok(!ret, "not expected ret: %lu\n", ret);
4319 style = GetWindowLong(hwnd, GWL_STYLE);
4320 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4321 ok(style & WS_VISIBLE, "window should be visible\n");
4322 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4323 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4324 GetWindowRect(hwnd, &rc);
4325 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4327 ret = ShowWindow(hwnd, SW_MINIMIZE);
4328 ok(ret, "not expected ret: %lu\n", ret);
4329 style = GetWindowLong(hwnd, GWL_STYLE);
4330 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4331 ok(style & WS_VISIBLE, "window should be visible\n");
4332 ok(style & WS_MINIMIZE, "window should be minimized\n");
4333 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4334 GetWindowRect(hwnd, &rc);
4335 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4337 ShowWindow(hwnd, SW_RESTORE);
4338 ok(ret, "not expected ret: %lu\n", ret);
4339 style = GetWindowLong(hwnd, GWL_STYLE);
4340 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4341 ok(style & WS_VISIBLE, "window should be visible\n");
4342 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4343 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4344 GetWindowRect(hwnd, &rc);
4345 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4347 ret = EnableWindow(hwnd, FALSE);
4348 ok(!ret, "not expected ret: %lu\n", ret);
4349 style = GetWindowLong(hwnd, GWL_STYLE);
4350 ok(style & WS_DISABLED, "window should be disabled\n");
4352 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
4353 ok(!ret, "not expected ret: %lu\n", ret);
4354 style = GetWindowLong(hwnd, GWL_STYLE);
4355 ok(style & WS_DISABLED, "window should be disabled\n");
4356 ok(style & WS_VISIBLE, "window should be visible\n");
4357 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4358 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4359 GetWindowRect(hwnd, &rc);
4360 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4362 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
4363 ok(!ret, "not expected ret: %lu\n", ret);
4364 style = GetWindowLong(hwnd, GWL_STYLE);
4365 ok(style & WS_DISABLED, "window should be disabled\n");
4366 ok(style & WS_VISIBLE, "window should be visible\n");
4367 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4368 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4369 GetWindowRect(hwnd, &rc);
4370 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4372 ret = ShowWindow(hwnd, SW_MINIMIZE);
4373 ok(ret, "not expected ret: %lu\n", ret);
4374 style = GetWindowLong(hwnd, GWL_STYLE);
4375 ok(style & WS_DISABLED, "window should be disabled\n");
4376 ok(style & WS_VISIBLE, "window should be visible\n");
4377 ok(style & WS_MINIMIZE, "window should be minimized\n");
4378 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4379 GetWindowRect(hwnd, &rc);
4380 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4382 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
4383 ok(!ret, "not expected ret: %lu\n", ret);
4384 style = GetWindowLong(hwnd, GWL_STYLE);
4385 ok(style & WS_DISABLED, "window should be disabled\n");
4386 ok(style & WS_VISIBLE, "window should be visible\n");
4387 ok(style & WS_MINIMIZE, "window should be minimized\n");
4388 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4389 GetWindowRect(hwnd, &rc);
4390 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4392 ret = ShowWindow(hwnd, SW_RESTORE);
4393 ok(ret, "not expected ret: %lu\n", ret);
4394 style = GetWindowLong(hwnd, GWL_STYLE);
4395 ok(style & WS_DISABLED, "window should be disabled\n");
4396 ok(style & WS_VISIBLE, "window should be visible\n");
4397 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4398 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4399 GetWindowRect(hwnd, &rc);
4400 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4402 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4403 ok(!ret, "not expected ret: %lu\n", ret);
4404 ok(IsWindow(hwnd), "window should exist\n");
4406 ret = EnableWindow(hwnd, TRUE);
4407 ok(ret, "not expected ret: %lu\n", ret);
4409 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4410 ok(!ret, "not expected ret: %lu\n", ret);
4411 ok(!IsWindow(hwnd), "window should not exist\n");
4414 static void test_gettext(void)
4417 LPCSTR clsname = "gettexttest";
4421 memset( &cls, 0, sizeof cls );
4422 cls.lpfnWndProc = DefWindowProc;
4423 cls.lpszClassName = clsname;
4424 cls.hInstance = GetModuleHandle(NULL);
4426 if (!RegisterClass( &cls )) return;
4428 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
4429 ok( hwnd != NULL, "window was null\n");
4431 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
4432 ok( r == 0, "settext should return zero\n");
4434 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
4435 ok( r == 0, "settext should return zero (%ld)\n", r);
4437 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
4438 ok( r == 0, "settext should return zero (%ld)\n", r);
4440 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
4441 ok( r == 0, "settext should return zero (%ld)\n", r);
4443 DestroyWindow(hwnd);
4444 UnregisterClass( clsname, NULL );
4448 static void test_GetUpdateRect(void)
4451 BOOL ret, parent_wm_paint, grandparent_wm_paint;
4453 HWND hgrandparent, hparent, hchild;
4455 static const char classNameA[] = "GetUpdateRectClass";
4457 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
4458 0, 0, 100, 100, NULL, NULL, 0, NULL);
4460 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
4461 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4463 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
4464 10, 10, 30, 30, hparent, NULL, 0, NULL);
4466 ShowWindow(hgrandparent, SW_SHOW);
4467 UpdateWindow(hgrandparent);
4470 ShowWindow(hchild, SW_HIDE);
4471 SetRect(&rc2, 0, 0, 0, 0);
4472 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4473 ok(!ret, "GetUpdateRect returned not empty region\n");
4474 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4475 rc1.left, rc1.top, rc1.right, rc1.bottom,
4476 rc2.left, rc2.top, rc2.right, rc2.bottom);
4478 SetRect(&rc2, 10, 10, 40, 40);
4479 ret = GetUpdateRect(hparent, &rc1, FALSE);
4480 ok(ret, "GetUpdateRect returned empty region\n");
4481 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4482 rc1.left, rc1.top, rc1.right, rc1.bottom,
4483 rc2.left, rc2.top, rc2.right, rc2.bottom);
4485 parent_wm_paint = FALSE;
4486 grandparent_wm_paint = FALSE;
4487 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4489 if (msg.message == WM_PAINT)
4491 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4492 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4494 DispatchMessage(&msg);
4496 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4497 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4499 DestroyWindow(hgrandparent);
4502 cls.lpfnWndProc = DefWindowProcA;
4505 cls.hInstance = GetModuleHandleA(0);
4507 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
4508 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4509 cls.lpszMenuName = NULL;
4510 cls.lpszClassName = classNameA;
4512 if(!RegisterClassA(&cls)) {
4513 trace("Register failed %d\n", GetLastError());
4517 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
4518 0, 0, 100, 100, NULL, NULL, 0, NULL);
4520 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
4521 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4523 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
4524 10, 10, 30, 30, hparent, NULL, 0, NULL);
4526 ShowWindow(hgrandparent, SW_SHOW);
4527 UpdateWindow(hgrandparent);
4530 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4531 ok(!ret, "GetUpdateRect returned not empty region\n");
4533 ShowWindow(hchild, SW_HIDE);
4535 SetRect(&rc2, 0, 0, 0, 0);
4536 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4537 ok(!ret, "GetUpdateRect returned not empty region\n");
4538 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4539 rc1.left, rc1.top, rc1.right, rc1.bottom,
4540 rc2.left, rc2.top, rc2.right, rc2.bottom);
4542 SetRect(&rc2, 10, 10, 40, 40);
4543 ret = GetUpdateRect(hparent, &rc1, FALSE);
4544 ok(ret, "GetUpdateRect returned empty region\n");
4545 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4546 rc1.left, rc1.top, rc1.right, rc1.bottom,
4547 rc2.left, rc2.top, rc2.right, rc2.bottom);
4549 parent_wm_paint = FALSE;
4550 grandparent_wm_paint = FALSE;
4551 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4553 if (msg.message == WM_PAINT)
4555 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4556 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4558 DispatchMessage(&msg);
4560 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4561 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4563 DestroyWindow(hgrandparent);
4567 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
4575 const int waitTime = 2000;
4577 BeginPaint(hwnd, &ps);
4579 /* create and destroy window to create an exposed region on this window */
4580 win = CreateWindowA("static", "win", WS_VISIBLE,
4581 10,10,50,50, NULL, NULL, 0, NULL);
4584 waitResult = MsgWaitForMultipleObjectsEx( 0, NULL, waitTime, QS_PAINT, 0 );
4586 ValidateRect(hwnd, NULL);
4587 EndPaint(hwnd, &ps);
4589 if(waitResult != WAIT_TIMEOUT)
4591 GetUpdateRect(hwnd, &updateRect, FALSE);
4594 ok(!IsRectEmpty(&updateRect), "Exposed rect should not be empty\n");
4600 return DefWindowProc(hwnd, msg, wParam, lParam);
4603 static void test_Expose(void)
4608 memset(&cls, 0, sizeof(WNDCLASSA));
4609 cls.lpfnWndProc = TestExposedRegion_WndProc;
4610 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4611 cls.lpszClassName = "TestExposeClass";
4612 atom = RegisterClassA(&cls);
4614 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
4615 0, 0, 200, 100, NULL, NULL, 0, NULL);
4623 pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
4624 pGetWindowInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
4626 hwndMain = CreateWindowExA(0, "static", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, NULL);
4629 ok(!GetParent(hwndMain), "GetParent should return 0 for message only windows\n");
4632 hwndMessage = pGetAncestor(hwndMain, GA_PARENT);
4633 ok(hwndMessage != 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
4634 trace("hwndMessage %p\n", hwndMessage);
4636 DestroyWindow(hwndMain);
4639 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
4641 if (!RegisterWindowClasses()) assert(0);
4643 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
4646 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
4647 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4648 WS_MAXIMIZEBOX | WS_POPUP,
4650 0, 0, GetModuleHandle(0), NULL);
4651 test_nonclient_area(hwndMain);
4653 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
4654 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4655 WS_MAXIMIZEBOX | WS_POPUP,
4657 0, 0, GetModuleHandle(0), NULL);
4659 assert( hwndMain2 );
4661 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
4663 /* Add the tests below this line */
4668 test_capture_3(hwndMain, hwndMain2);
4670 test_CreateWindow();
4671 test_parent_owner();
4673 test_shell_window();
4677 test_SetWindowPos(hwndMain);
4678 test_SetMenu(hwndMain);
4679 test_SetFocus(hwndMain);
4680 test_SetActiveWindow(hwndMain);
4681 test_SetForegroundWindow(hwndMain);
4683 test_children_zorder(hwndMain);
4684 test_popup_zorder(hwndMain2, hwndMain);
4685 test_keyboard_input(hwndMain);
4686 test_mouse_input(hwndMain);
4687 test_validatergn(hwndMain);
4688 test_nccalcscroll( hwndMain);
4689 test_scrollvalidate( hwndMain);
4690 test_scrolldc( hwndMain);
4692 test_IsWindowUnicode();
4693 test_vis_rgn(hwndMain);
4695 test_AdjustWindowRect();
4696 test_window_styles();
4699 test_SetWindowLong();
4702 test_GetUpdateRect();
4705 /* add the tests above this line */
4706 UnhookWindowsHookEx(hhook);