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*);
49 static UINT (WINAPI *pGetWindowModuleFileNameA)(HWND,LPSTR,UINT);
51 static BOOL test_lbuttondown_flag;
52 static HWND hwndMessage;
53 static HWND hwndMain, hwndMain2;
56 static const char* szAWRClass = "Winsize";
60 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
62 static void dump_minmax_info( const MINMAXINFO *minmax )
64 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
65 minmax->ptReserved.x, minmax->ptReserved.y,
66 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
67 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
68 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
69 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
72 /* try to make sure pending X events have been processed before continuing */
73 static void flush_events( BOOL remove_messages )
78 DWORD time = GetTickCount() + diff;
82 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
84 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
85 diff = time - GetTickCount();
90 /* check the values returned by the various parent/owner functions on a given window */
91 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
92 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
98 res = pGetAncestor( hwnd, GA_PARENT );
99 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
101 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
102 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
103 res = GetParent( hwnd );
104 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
105 res = GetWindow( hwnd, GW_OWNER );
106 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
109 res = pGetAncestor( hwnd, GA_ROOT );
110 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
111 res = pGetAncestor( hwnd, GA_ROOTOWNER );
112 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
116 static BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
119 trace("EnumChildProc on %p\n", hwndChild);
120 if (*(LPINT)lParam > 1) return FALSE;
124 /* will search for the given window */
125 static BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
127 trace("EnumChildProc1 on %p\n", hwndChild);
128 if ((HWND)lParam == hwndChild) return FALSE;
132 static HWND create_tool_window( LONG style, HWND parent )
134 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
135 0, 0, 100, 100, parent, 0, 0, NULL );
136 ok( ret != 0, "Creation failed\n" );
140 /* test parent and owner values for various combinations */
141 static void test_parent_owner(void)
144 HWND test, owner, ret;
145 HWND desktop = GetDesktopWindow();
146 HWND child = create_tool_window( WS_CHILD, hwndMain );
149 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
151 /* child without parent, should fail */
152 SetLastError(0xdeadbeef);
153 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
154 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
155 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD, "CreateWindowExA should call SetLastError\n" );
156 ok( !test, "WS_CHILD without parent created\n" );
159 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
160 style = GetWindowLongA( desktop, GWL_STYLE );
161 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
162 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
163 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
165 /* normal child window */
166 test = create_tool_window( WS_CHILD, hwndMain );
167 trace( "created child %p\n", test );
168 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
169 SetWindowLongA( test, GWL_STYLE, 0 );
170 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
171 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
172 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
173 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
174 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
175 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
176 DestroyWindow( test );
178 /* normal child window with WS_MAXIMIZE */
179 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
180 DestroyWindow( test );
182 /* normal child window with WS_THICKFRAME */
183 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
184 DestroyWindow( test );
186 /* popup window with WS_THICKFRAME */
187 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
188 DestroyWindow( test );
190 /* child of desktop */
191 test = create_tool_window( WS_CHILD, desktop );
192 trace( "created child of desktop %p\n", test );
193 check_parents( test, desktop, 0, desktop, 0, test, desktop );
194 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
195 check_parents( test, desktop, 0, 0, 0, test, test );
196 SetWindowLongA( test, GWL_STYLE, 0 );
197 check_parents( test, desktop, 0, 0, 0, test, test );
198 DestroyWindow( test );
200 /* child of desktop with WS_MAXIMIZE */
201 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
202 DestroyWindow( test );
204 /* child of desktop with WS_MINIMIZE */
205 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
206 DestroyWindow( test );
209 test = create_tool_window( WS_CHILD, child );
210 trace( "created child of child %p\n", test );
211 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
212 SetWindowLongA( test, GWL_STYLE, 0 );
213 check_parents( test, child, child, 0, 0, hwndMain, test );
214 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
215 check_parents( test, child, child, 0, 0, hwndMain, test );
216 DestroyWindow( test );
218 /* child of child with WS_MAXIMIZE */
219 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
220 DestroyWindow( test );
222 /* child of child with WS_MINIMIZE */
223 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
224 DestroyWindow( test );
226 /* not owned top-level window */
227 test = create_tool_window( 0, 0 );
228 trace( "created top-level %p\n", test );
229 check_parents( test, desktop, 0, 0, 0, test, test );
230 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
231 check_parents( test, desktop, 0, 0, 0, test, test );
232 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
233 check_parents( test, desktop, 0, desktop, 0, test, desktop );
234 DestroyWindow( test );
236 /* not owned top-level window with WS_MAXIMIZE */
237 test = create_tool_window( WS_MAXIMIZE, 0 );
238 DestroyWindow( test );
240 /* owned top-level window */
241 test = create_tool_window( 0, hwndMain );
242 trace( "created owned top-level %p\n", test );
243 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
244 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
245 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
246 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
247 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
248 DestroyWindow( test );
250 /* owned top-level window with WS_MAXIMIZE */
251 test = create_tool_window( WS_MAXIMIZE, hwndMain );
252 DestroyWindow( test );
254 /* not owned popup */
255 test = create_tool_window( WS_POPUP, 0 );
256 trace( "created popup %p\n", test );
257 check_parents( test, desktop, 0, 0, 0, test, test );
258 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
259 check_parents( test, desktop, 0, desktop, 0, test, desktop );
260 SetWindowLongA( test, GWL_STYLE, 0 );
261 check_parents( test, desktop, 0, 0, 0, test, test );
262 DestroyWindow( test );
264 /* not owned popup with WS_MAXIMIZE */
265 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
266 DestroyWindow( test );
269 test = create_tool_window( WS_POPUP, hwndMain );
270 trace( "created owned popup %p\n", test );
271 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
272 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
273 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
274 SetWindowLongA( test, GWL_STYLE, 0 );
275 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
276 DestroyWindow( test );
278 /* owned popup with WS_MAXIMIZE */
279 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
280 DestroyWindow( test );
282 /* top-level window owned by child (same as owned by top-level) */
283 test = create_tool_window( 0, child );
284 trace( "created top-level owned by child %p\n", test );
285 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
286 DestroyWindow( test );
288 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
289 test = create_tool_window( WS_MAXIMIZE, child );
290 DestroyWindow( test );
292 /* popup owned by desktop (same as not owned) */
293 test = create_tool_window( WS_POPUP, desktop );
294 trace( "created popup owned by desktop %p\n", test );
295 check_parents( test, desktop, 0, 0, 0, test, test );
296 DestroyWindow( test );
298 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
299 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
300 DestroyWindow( test );
302 /* popup owned by child (same as owned by top-level) */
303 test = create_tool_window( WS_POPUP, child );
304 trace( "created popup owned by child %p\n", test );
305 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
306 DestroyWindow( test );
308 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
309 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
310 DestroyWindow( test );
312 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
313 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
314 trace( "created WS_CHILD popup %p\n", test );
315 check_parents( test, desktop, 0, 0, 0, test, test );
316 DestroyWindow( test );
318 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
319 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
320 DestroyWindow( test );
322 /* owned popup with WS_CHILD (same as WS_POPUP only) */
323 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
324 trace( "created owned WS_CHILD popup %p\n", test );
325 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
326 DestroyWindow( test );
328 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
329 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
330 DestroyWindow( test );
332 /******************** parent changes *************************/
333 trace( "testing parent changes\n" );
336 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
339 /* this test succeeds on NT but crashes on win9x systems */
340 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
341 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
342 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
343 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
344 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
346 /* normal child window */
347 test = create_tool_window( WS_CHILD, hwndMain );
348 trace( "created child %p\n", test );
350 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
351 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
352 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
354 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
355 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
356 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
358 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
359 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
360 check_parents( test, desktop, 0, desktop, 0, test, desktop );
362 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
363 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
364 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
365 check_parents( test, desktop, child, desktop, child, test, desktop );
367 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
368 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
369 check_parents( test, desktop, 0, desktop, 0, test, desktop );
370 DestroyWindow( test );
372 /* not owned top-level window */
373 test = create_tool_window( 0, 0 );
374 trace( "created top-level %p\n", test );
376 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
377 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
378 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
380 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
381 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
382 check_parents( test, desktop, child, 0, child, test, test );
384 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
385 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
386 check_parents( test, desktop, 0, 0, 0, test, test );
387 DestroyWindow( test );
389 /* not owned popup */
390 test = create_tool_window( WS_POPUP, 0 );
391 trace( "created popup %p\n", test );
393 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
394 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
395 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
397 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
398 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
399 check_parents( test, desktop, child, child, child, test, hwndMain );
401 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
402 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
403 check_parents( test, desktop, 0, 0, 0, test, test );
404 DestroyWindow( test );
406 /* normal child window */
407 test = create_tool_window( WS_CHILD, hwndMain );
408 trace( "created child %p\n", test );
410 ret = SetParent( test, desktop );
411 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
412 check_parents( test, desktop, 0, desktop, 0, test, desktop );
414 ret = SetParent( test, child );
415 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
416 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
418 ret = SetParent( test, hwndMain2 );
419 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
420 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
421 DestroyWindow( test );
423 /* not owned top-level window */
424 test = create_tool_window( 0, 0 );
425 trace( "created top-level %p\n", test );
427 ret = SetParent( test, child );
428 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
429 check_parents( test, child, child, 0, 0, hwndMain, test );
430 DestroyWindow( test );
433 test = create_tool_window( WS_POPUP, hwndMain2 );
434 trace( "created owned popup %p\n", test );
436 ret = SetParent( test, child );
437 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
438 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
440 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
441 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
442 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
443 DestroyWindow( test );
445 /**************** test owner destruction *******************/
447 /* owned child popup */
448 owner = create_tool_window( 0, 0 );
449 test = create_tool_window( WS_POPUP, owner );
450 trace( "created owner %p and popup %p\n", owner, test );
451 ret = SetParent( test, child );
452 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
453 check_parents( test, child, child, owner, owner, hwndMain, owner );
454 /* window is now child of 'child' but owned by 'owner' */
455 DestroyWindow( owner );
456 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
457 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
458 * while Win95, Win2k, WinXP do.
460 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
461 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
464 /* owned top-level popup */
465 owner = create_tool_window( 0, 0 );
466 test = create_tool_window( WS_POPUP, owner );
467 trace( "created owner %p and popup %p\n", owner, test );
468 check_parents( test, desktop, owner, owner, owner, test, owner );
469 DestroyWindow( owner );
470 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
472 /* top-level popup owned by child */
473 owner = create_tool_window( WS_CHILD, hwndMain2 );
474 test = create_tool_window( WS_POPUP, 0 );
475 trace( "created owner %p and popup %p\n", owner, test );
476 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
477 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
478 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
479 DestroyWindow( owner );
480 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
481 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
482 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
483 * while Win95, Win2k, WinXP do.
485 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
489 DestroyWindow(child);
492 owner = create_tool_window( WS_OVERLAPPED, 0 );
493 test = create_tool_window( WS_POPUP, desktop );
495 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
497 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
498 "EnumChildWindows should have returned FALSE\n" );
499 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
501 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
502 ret = SetParent( test, owner );
503 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
506 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
507 "EnumChildWindows should have returned TRUE\n" );
508 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
510 child = create_tool_window( WS_CHILD, owner );
512 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
513 "EnumChildWindows should have returned FALSE\n" );
514 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
515 DestroyWindow( child );
517 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
518 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
520 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
521 "EnumChildWindows should have returned TRUE\n" );
522 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
524 ret = SetParent( child, owner );
525 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
526 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
528 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
529 "EnumChildWindows should have returned FALSE\n" );
530 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
532 ret = SetParent( child, NULL );
533 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
534 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
536 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
537 "EnumChildWindows should have returned TRUE\n" );
538 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
540 /* even GW_OWNER == owner it's still a desktop's child */
541 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
542 "EnumChildWindows should have found %p and returned FALSE\n", child );
544 DestroyWindow( child );
545 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
547 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
548 "EnumChildWindows should have found %p and returned FALSE\n", child );
550 DestroyWindow( child );
551 DestroyWindow( test );
552 DestroyWindow( owner );
556 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
560 case WM_GETMINMAXINFO:
562 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
564 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
565 dump_minmax_info( minmax );
566 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
569 case WM_WINDOWPOSCHANGING:
571 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
572 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
573 trace("main: WM_WINDOWPOSCHANGING\n");
574 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
575 winpos->hwnd, winpos->hwndInsertAfter,
576 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
577 if (!(winpos->flags & SWP_NOMOVE))
579 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
580 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
582 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
583 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
585 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
586 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
590 case WM_WINDOWPOSCHANGED:
593 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
594 trace("main: WM_WINDOWPOSCHANGED\n");
595 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
596 winpos->hwnd, winpos->hwndInsertAfter,
597 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
598 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
599 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
601 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
602 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
604 GetWindowRect(hwnd, &rc1);
605 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
606 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
607 /* note: winpos coordinates are relative to parent */
608 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
609 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
612 /* Uncomment this once the test succeeds in all cases */
613 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
616 GetClientRect(hwnd, &rc2);
617 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
618 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
619 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
620 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
625 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
626 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
628 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
629 if (got_getminmaxinfo)
630 trace("%p got WM_GETMINMAXINFO\n", hwnd);
632 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
633 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
635 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
639 if (test_lbuttondown_flag)
641 ShowWindow((HWND)wparam, SW_SHOW);
642 flush_events( FALSE );
647 return DefWindowProcA(hwnd, msg, wparam, lparam);
650 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
654 case WM_GETMINMAXINFO:
656 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
658 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
659 dump_minmax_info( minmax );
660 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
665 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
666 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
668 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
669 if (got_getminmaxinfo)
670 trace("%p got WM_GETMINMAXINFO\n", hwnd);
672 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
673 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
675 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
680 return DefWindowProcA(hwnd, msg, wparam, lparam);
683 static BOOL RegisterWindowClasses(void)
687 cls.style = CS_DBLCLKS;
688 cls.lpfnWndProc = main_window_procA;
691 cls.hInstance = GetModuleHandleA(0);
693 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
694 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
695 cls.lpszMenuName = NULL;
696 cls.lpszClassName = "MainWindowClass";
698 if(!RegisterClassA(&cls)) return FALSE;
701 cls.lpfnWndProc = tool_window_procA;
704 cls.hInstance = GetModuleHandleA(0);
706 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
707 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
708 cls.lpszMenuName = NULL;
709 cls.lpszClassName = "ToolWindowClass";
711 if(!RegisterClassA(&cls)) return FALSE;
716 static void verify_window_info(HWND hwnd, const WINDOWINFO *info)
718 RECT rcWindow, rcClient;
721 ok(IsWindow(hwnd), "bad window handle\n");
723 GetWindowRect(hwnd, &rcWindow);
724 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow\n");
726 GetClientRect(hwnd, &rcClient);
727 /* translate to screen coordinates */
728 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
729 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient\n");
731 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
732 "wrong dwStyle: %08x != %08x\n", info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE));
733 /* Windows reports a not documented exstyle 0x800 in WINDOWINFO, but
734 * doesn't return it in GetWindowLong(hwnd, GWL_EXSTYLE).
736 ok((info->dwExStyle & ~0x800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
737 "wrong dwExStyle: %08x != %08x\n", info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE));
738 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
739 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x\n",
740 info->dwWindowStatus, status);
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);
1420 dump_minmax_info( minmax );
1422 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1423 minmax->ptMaxSize.x, rc.right - rc.left);
1424 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1425 minmax->ptMaxSize.y, rc.bottom - rc.top);
1427 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1429 trace("DefMDIChildProc returned:\n");
1430 dump_minmax_info( minmax );
1432 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1433 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1434 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1435 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1436 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1441 case WM_MDIACTIVATE:
1443 HWND active, client = GetParent(hwnd);
1444 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1445 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1446 if (hwnd == (HWND)lparam) /* if we are being activated */
1447 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1449 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1453 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1456 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1463 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1465 trace("%s\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE");
1466 trace("x %d, y %d, cx %d, cy %d\n", cs->x, cs->y, cs->cx, cs->cy);
1468 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1469 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1471 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1472 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1474 /* CREATESTRUCT should have fixed values */
1475 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1477 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1478 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1480 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1481 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1482 while Win95, Win2k, WinXP do. */
1483 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1484 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1488 case WM_GETMINMAXINFO:
1490 HWND parent = GetParent(hwnd);
1492 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1493 LONG style, exstyle;
1495 trace("WM_GETMINMAXINFO\n");
1497 style = GetWindowLongA(hwnd, GWL_STYLE);
1498 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1500 GetClientRect(parent, &rc);
1501 trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1503 GetClientRect(parent, &rc);
1504 if ((style & WS_CAPTION) == WS_CAPTION)
1505 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1506 AdjustWindowRectEx(&rc, style, 0, exstyle);
1507 trace("calculated max child window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1508 dump_minmax_info( minmax );
1510 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1511 minmax->ptMaxSize.x, rc.right - rc.left);
1512 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1513 minmax->ptMaxSize.y, rc.bottom - rc.top);
1517 case WM_WINDOWPOSCHANGED:
1519 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1522 GetWindowRect(hwnd, &rc1);
1523 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1524 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1525 /* note: winpos coordinates are relative to parent */
1526 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1527 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1528 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1530 GetWindowRect(hwnd, &rc1);
1531 GetClientRect(hwnd, &rc2);
1532 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1533 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1534 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1537 case WM_WINDOWPOSCHANGING:
1539 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1540 WINDOWPOS my_winpos = *winpos;
1542 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1543 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1544 winpos->hwnd, winpos->hwndInsertAfter,
1545 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1547 DefWindowProcA(hwnd, msg, wparam, lparam);
1549 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1550 winpos->hwnd, winpos->hwndInsertAfter,
1551 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1553 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1554 "DefWindowProc should not change WINDOWPOS values\n");
1559 return DefWindowProcA(hwnd, msg, wparam, lparam);
1562 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1564 static HWND mdi_client;
1570 CLIENTCREATESTRUCT client_cs;
1573 GetClientRect(hwnd, &rc);
1575 client_cs.hWindowMenu = 0;
1576 client_cs.idFirstChild = 1;
1578 /* MDIClient without MDIS_ALLCHILDSTYLES */
1579 mdi_client = CreateWindowExA(0, "mdiclient",
1581 WS_CHILD /*| WS_VISIBLE*/,
1582 /* tests depend on a not zero MDIClient size */
1583 0, 0, rc.right, rc.bottom,
1584 hwnd, 0, GetModuleHandle(0),
1585 (LPVOID)&client_cs);
1587 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1588 DestroyWindow(mdi_client);
1590 /* MDIClient with MDIS_ALLCHILDSTYLES */
1591 mdi_client = CreateWindowExA(0, "mdiclient",
1593 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1594 /* tests depend on a not zero MDIClient size */
1595 0, 0, rc.right, rc.bottom,
1596 hwnd, 0, GetModuleHandle(0),
1597 (LPVOID)&client_cs);
1599 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1600 DestroyWindow(mdi_client);
1604 case WM_WINDOWPOSCHANGED:
1606 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1609 GetWindowRect(hwnd, &rc1);
1610 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1611 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1612 /* note: winpos coordinates are relative to parent */
1613 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1614 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1615 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1617 GetWindowRect(hwnd, &rc1);
1618 GetClientRect(hwnd, &rc2);
1619 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1620 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1621 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1624 case WM_WINDOWPOSCHANGING:
1626 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1627 WINDOWPOS my_winpos = *winpos;
1629 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1630 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1631 winpos->hwnd, winpos->hwndInsertAfter,
1632 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1634 DefWindowProcA(hwnd, msg, wparam, lparam);
1636 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1637 winpos->hwnd, winpos->hwndInsertAfter,
1638 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1640 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1641 "DefWindowProc should not change WINDOWPOS values\n");
1650 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1653 static BOOL mdi_RegisterWindowClasses(void)
1658 cls.lpfnWndProc = mdi_main_wnd_procA;
1661 cls.hInstance = GetModuleHandleA(0);
1663 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1664 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1665 cls.lpszMenuName = NULL;
1666 cls.lpszClassName = "MDI_parent_Class";
1667 if(!RegisterClassA(&cls)) return FALSE;
1669 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1670 cls.lpszClassName = "MDI_child_Class_1";
1671 if(!RegisterClassA(&cls)) return FALSE;
1673 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1674 cls.lpszClassName = "MDI_child_Class_2";
1675 if(!RegisterClassA(&cls)) return FALSE;
1680 static void test_mdi(void)
1685 if (!mdi_RegisterWindowClasses()) assert(0);
1687 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1688 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1689 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1690 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1691 GetDesktopWindow(), 0,
1692 GetModuleHandle(0), NULL);
1693 assert(mdi_hwndMain);
1695 while(GetMessage(&msg, 0, 0, 0))
1697 TranslateMessage(&msg);
1698 DispatchMessage(&msg);
1701 DestroyWindow(mdi_hwndMain);
1704 static void test_icons(void)
1708 HICON icon = LoadIconA(0, (LPSTR)IDI_APPLICATION);
1709 HICON icon2 = LoadIconA(0, (LPSTR)IDI_QUESTION);
1710 HICON small_icon = LoadImageA(0, (LPSTR)IDI_APPLICATION, IMAGE_ICON,
1711 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1714 cls.cbSize = sizeof(cls);
1716 cls.lpfnWndProc = DefWindowProcA;
1720 cls.hIcon = LoadIconA(0, (LPSTR)IDI_HAND);
1721 cls.hIconSm = small_icon;
1722 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1723 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1724 cls.lpszMenuName = NULL;
1725 cls.lpszClassName = "IconWindowClass";
1727 RegisterClassExA(&cls);
1729 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1730 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1733 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1734 ok( res == 0, "wrong big icon %p/0\n", res );
1735 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1736 ok( res == 0, "wrong previous big icon %p/0\n", res );
1737 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1738 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1739 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1740 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1741 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1742 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1744 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1745 ok( res == 0, "wrong small icon %p/0\n", res );
1746 /* this test is XP specific */
1747 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1748 ok( res != 0, "wrong small icon %p\n", res );*/
1749 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1750 ok( res == 0, "wrong previous small icon %p/0\n", res );
1751 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1752 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1753 /* this test is XP specific */
1754 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1755 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1756 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1757 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1758 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1759 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1760 /* this test is XP specific */
1761 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1762 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1764 /* make sure the big icon hasn't changed */
1765 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1766 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1768 DestroyWindow( hwnd );
1771 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1773 if (msg == WM_NCCALCSIZE)
1775 RECT *rect = (RECT *)lparam;
1776 /* first time around increase the rectangle, next time decrease it */
1777 if (rect->left == 100) InflateRect( rect, 10, 10 );
1778 else InflateRect( rect, -10, -10 );
1781 return DefWindowProc( hwnd, msg, wparam, lparam );
1784 static void test_SetWindowPos(HWND hwnd)
1786 RECT orig_win_rc, rect;
1788 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1790 SetRect(&rect, 111, 222, 333, 444);
1791 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1792 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1793 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1795 SetRect(&rect, 111, 222, 333, 444);
1796 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1797 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1798 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1800 GetWindowRect(hwnd, &orig_win_rc);
1802 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1803 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1804 GetWindowRect( hwnd, &rect );
1805 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1806 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1807 GetClientRect( hwnd, &rect );
1808 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1809 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1810 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1812 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1813 GetWindowRect( hwnd, &rect );
1814 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1815 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1816 GetClientRect( hwnd, &rect );
1817 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1818 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1819 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1821 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1822 orig_win_rc.right, orig_win_rc.bottom, 0);
1823 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1825 /* Win9x truncates coordinates to 16-bit irrespectively */
1828 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1829 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1831 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1832 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1835 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1836 orig_win_rc.right, orig_win_rc.bottom, 0);
1838 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1839 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1840 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1841 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1842 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1843 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1844 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1847 static void test_SetMenu(HWND parent)
1851 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1855 hMenu = CreateMenu();
1858 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1861 /* fails on (at least) Wine, NT4, XP SP2 */
1862 test_nonclient_area(parent);
1864 ret = GetMenu(parent);
1865 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1866 /* test whether we can destroy a menu assigned to a window */
1867 retok = DestroyMenu(hMenu);
1868 ok( retok, "DestroyMenu error %d\n", GetLastError());
1869 ok(!IsMenu(hMenu), "menu handle should be not valid after DestroyMenu\n");
1870 ret = GetMenu(parent);
1871 /* This test fails on Win9x */
1873 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1874 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1875 test_nonclient_area(parent);
1877 hMenu = CreateMenu();
1881 ret = GetMenu(parent);
1882 ok(ret == 0, "unexpected menu id %p\n", ret);
1884 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1885 test_nonclient_area(parent);
1886 ret = GetMenu(parent);
1887 ok(ret == 0, "unexpected menu id %p\n", ret);
1889 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1892 /* fails on (at least) Wine, NT4, XP SP2 */
1893 test_nonclient_area(parent);
1895 ret = GetMenu(parent);
1896 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1898 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1899 test_nonclient_area(parent);
1900 ret = GetMenu(parent);
1901 ok(ret == 0, "unexpected menu id %p\n", ret);
1904 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1907 ret = GetMenu(child);
1908 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1910 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1911 test_nonclient_area(child);
1912 ret = GetMenu(child);
1913 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1915 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1916 test_nonclient_area(child);
1917 ret = GetMenu(child);
1918 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1920 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1921 test_nonclient_area(child);
1922 ret = GetMenu(child);
1923 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1925 style = GetWindowLong(child, GWL_STYLE);
1926 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
1927 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
1928 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
1929 SetWindowLong(child, GWL_STYLE, style);
1931 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
1932 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
1933 SetWindowLong(child, GWL_STYLE, style);
1935 DestroyWindow(child);
1939 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1941 HWND child[5], hwnd;
1946 hwnd = GetWindow(parent, GW_CHILD);
1947 ok(!hwnd, "have to start without children to perform the test\n");
1949 for (i = 0; i < total; i++)
1951 if (style[i] & DS_CONTROL)
1953 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
1954 0,0,0,0, parent, (HMENU)i, 0, NULL);
1955 if (style[i] & WS_VISIBLE)
1956 ShowWindow(child[i], SW_SHOW);
1958 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
1961 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
1962 parent, (HMENU)i, 0, NULL);
1963 trace("child[%d] = %p\n", i, child[i]);
1964 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
1967 hwnd = GetWindow(parent, GW_CHILD);
1968 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
1969 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
1970 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
1972 for (i = 0; i < total; i++)
1974 trace("hwnd[%d] = %p\n", i, hwnd);
1975 ok(child[order[i]] == hwnd, "Z order of child #%d is wrong\n", i);
1977 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1980 for (i = 0; i < total; i++)
1981 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
1984 static void test_children_zorder(HWND parent)
1986 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
1988 const int simple_order[5] = { 0, 1, 2, 3, 4 };
1990 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
1991 WS_CHILD | WS_VISIBLE, WS_CHILD,
1992 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
1993 const int complex_order_1[1] = { 0 };
1994 const int complex_order_2[2] = { 1, 0 };
1995 const int complex_order_3[3] = { 1, 0, 2 };
1996 const int complex_order_4[4] = { 1, 0, 2, 3 };
1997 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
1998 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
1999 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2000 WS_CHILD | WS_VISIBLE };
2001 const int complex_order_6[3] = { 0, 1, 2 };
2003 /* simple WS_CHILD */
2004 test_window_tree(parent, simple_style, simple_order, 5);
2006 /* complex children styles */
2007 test_window_tree(parent, complex_style, complex_order_1, 1);
2008 test_window_tree(parent, complex_style, complex_order_2, 2);
2009 test_window_tree(parent, complex_style, complex_order_3, 3);
2010 test_window_tree(parent, complex_style, complex_order_4, 4);
2011 test_window_tree(parent, complex_style, complex_order_5, 5);
2013 /* another set of complex children styles */
2014 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2017 #define check_z_order(hwnd, next, prev, owner, topmost) \
2018 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2021 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2022 BOOL topmost, const char *file, int line)
2027 test = GetWindow(hwnd, GW_HWNDNEXT);
2028 /* skip foreign windows */
2029 while (test && (GetWindowThreadProcessId(test, NULL) != our_pid ||
2030 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0)))
2032 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2033 test = GetWindow(test, GW_HWNDNEXT);
2035 ok_(file, line)(next == test, "expected next %p, got %p\n", next, test);
2037 test = GetWindow(hwnd, GW_HWNDPREV);
2038 /* skip foreign windows */
2039 while (test && (GetWindowThreadProcessId(test, NULL) != our_pid ||
2040 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0)))
2042 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2043 test = GetWindow(test, GW_HWNDPREV);
2045 ok_(file, line)(prev == test, "expected prev %p, got %p\n", prev, test);
2047 test = GetWindow(hwnd, GW_OWNER);
2048 ok_(file, line)(owner == test, "expected owner %p, got %p\n", owner, test);
2050 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2051 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "expected %stopmost\n", topmost ? "" : "NOT ");
2054 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E)
2056 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2058 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2060 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2062 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2063 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2065 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2066 WS_OVERLAPPED | WS_CAPTION,
2068 0, 0, GetModuleHandle(0), NULL);
2069 trace("hwnd_F %p\n", hwnd_F);
2070 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2072 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2073 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2074 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2075 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2077 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2080 hwnd_F, 0, GetModuleHandle(0), NULL);
2081 trace("hwnd_C %p\n", hwnd_C);
2082 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2083 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2084 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2085 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2087 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2090 hwnd_F, 0, GetModuleHandle(0), NULL);
2091 trace("hwnd_B %p\n", hwnd_B);
2092 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2093 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2094 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2095 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2096 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2098 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2101 0, 0, GetModuleHandle(0), NULL);
2102 trace("hwnd_A %p\n", hwnd_A);
2103 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2104 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2105 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2106 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2107 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2108 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2110 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);
2112 /* move hwnd_F and its popups up */
2113 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2114 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2115 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2116 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2117 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2118 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2119 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2121 /* move hwnd_F and its popups down */
2122 #if 0 /* enable once Wine is fixed to pass this test */
2123 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2124 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2125 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2126 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2127 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2128 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2129 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2132 DestroyWindow(hwnd_A);
2133 DestroyWindow(hwnd_B);
2134 DestroyWindow(hwnd_C);
2135 DestroyWindow(hwnd_F);
2138 static void test_vis_rgn( HWND hwnd )
2140 RECT win_rect, rgn_rect;
2141 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2144 ShowWindow(hwnd,SW_SHOW);
2145 hdc = GetDC( hwnd );
2146 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2147 GetWindowRect( hwnd, &win_rect );
2148 GetRgnBox( hrgn, &rgn_rect );
2149 if (GetVersion() & 0x80000000)
2151 trace("win9x, mapping to screen coords\n");
2152 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2154 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2155 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2156 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2157 rgn_rect.left, win_rect.left );
2158 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2159 rgn_rect.top, win_rect.top );
2160 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2161 rgn_rect.right, win_rect.right );
2162 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2163 rgn_rect.bottom, win_rect.bottom );
2164 ReleaseDC( hwnd, hdc );
2167 static void test_SetFocus(HWND hwnd)
2171 /* check if we can set focus to non-visible windows */
2173 ShowWindow(hwnd, SW_SHOW);
2176 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2177 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2178 ShowWindow(hwnd, SW_HIDE);
2181 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2182 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2183 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2186 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2187 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2188 ShowWindow(child, SW_SHOW);
2189 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2190 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2191 ShowWindow(child, SW_HIDE);
2192 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2193 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2194 ShowWindow(child, SW_SHOW);
2196 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2197 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2198 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2200 ShowWindow(child, SW_HIDE);
2202 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2203 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2204 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2205 ShowWindow(child, SW_HIDE);
2206 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2208 ShowWindow(hwnd, SW_SHOW);
2209 ShowWindow(child, SW_SHOW);
2211 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2212 EnableWindow(hwnd, FALSE);
2213 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2214 EnableWindow(hwnd, TRUE);
2216 DestroyWindow( child );
2219 static void check_wnd_state(HWND active, HWND foreground, HWND focus, HWND capture)
2221 ok(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2223 ok(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2224 ok(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2225 ok(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2228 static void test_SetActiveWindow(HWND hwnd)
2232 ShowWindow(hwnd, SW_HIDE);
2235 check_wnd_state(0, 0, 0, 0);
2237 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2239 ShowWindow(hwnd, SW_SHOW);
2240 check_wnd_state(hwnd, hwnd, hwnd, 0);
2242 hwnd2 = SetActiveWindow(0);
2243 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2244 check_wnd_state(0, 0, 0, 0);
2246 hwnd2 = SetActiveWindow(hwnd);
2247 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2248 check_wnd_state(hwnd, hwnd, hwnd, 0);
2250 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2251 check_wnd_state(hwnd, hwnd, hwnd, 0);
2253 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2254 check_wnd_state(hwnd, hwnd, hwnd, 0);
2256 ShowWindow(hwnd, SW_HIDE);
2257 check_wnd_state(0, 0, 0, 0);
2259 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2260 SetActiveWindow(hwnd);
2261 check_wnd_state(hwnd, hwnd, hwnd, 0);
2263 ShowWindow(hwnd, SW_SHOW);
2264 check_wnd_state(hwnd, hwnd, hwnd, 0);
2266 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2267 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2269 DestroyWindow(hwnd2);
2270 check_wnd_state(hwnd, hwnd, hwnd, 0);
2272 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2273 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2275 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2276 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2278 DestroyWindow(hwnd2);
2279 check_wnd_state(hwnd, hwnd, hwnd, 0);
2282 static void test_SetForegroundWindow(HWND hwnd)
2287 ShowWindow(hwnd, SW_HIDE);
2290 check_wnd_state(0, 0, 0, 0);
2292 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2294 ShowWindow(hwnd, SW_SHOW);
2295 check_wnd_state(hwnd, hwnd, hwnd, 0);
2297 hwnd2 = SetActiveWindow(0);
2298 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2299 check_wnd_state(0, 0, 0, 0);
2301 ret = SetForegroundWindow(hwnd);
2302 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2303 check_wnd_state(hwnd, hwnd, hwnd, 0);
2305 SetLastError(0xdeadbeef);
2306 ret = SetForegroundWindow(0);
2307 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2308 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2309 check_wnd_state(hwnd, hwnd, hwnd, 0);
2311 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2312 check_wnd_state(hwnd, hwnd, hwnd, 0);
2314 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2315 check_wnd_state(hwnd, hwnd, hwnd, 0);
2317 hwnd2 = GetForegroundWindow();
2318 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2319 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2320 hwnd2 = GetForegroundWindow();
2321 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2323 ShowWindow(hwnd, SW_HIDE);
2324 check_wnd_state(0, 0, 0, 0);
2326 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2327 ret = SetForegroundWindow(hwnd);
2328 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2329 check_wnd_state(hwnd, hwnd, hwnd, 0);
2331 ShowWindow(hwnd, SW_SHOW);
2332 check_wnd_state(hwnd, hwnd, hwnd, 0);
2334 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2335 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2337 DestroyWindow(hwnd2);
2338 check_wnd_state(hwnd, hwnd, hwnd, 0);
2340 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2341 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2343 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2344 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2346 DestroyWindow(hwnd2);
2347 check_wnd_state(hwnd, hwnd, hwnd, 0);
2350 static WNDPROC old_button_proc;
2352 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2357 key_state = GetKeyState(VK_LBUTTON);
2358 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2360 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2362 if (msg == WM_LBUTTONDOWN)
2366 check_wnd_state(button, button, button, button);
2368 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2370 trace("hwnd %p\n", hwnd);
2372 check_wnd_state(button, button, button, button);
2374 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2376 check_wnd_state(button, button, button, button);
2378 DestroyWindow(hwnd);
2380 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2382 trace("hwnd %p\n", hwnd);
2384 check_wnd_state(button, button, button, button);
2386 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2387 * match internal button state.
2389 SendMessage(button, WM_KILLFOCUS, 0, 0);
2390 check_wnd_state(button, button, button, 0);
2392 ShowWindow(hwnd, SW_SHOW);
2393 check_wnd_state(hwnd, hwnd, hwnd, 0);
2395 capture = SetCapture(hwnd);
2396 ok(capture == 0, "SetCapture() = %p\n", capture);
2398 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2400 DestroyWindow(hwnd);
2402 check_wnd_state(button, 0, button, 0);
2408 static void test_capture_1(void)
2410 HWND button, capture;
2412 capture = GetCapture();
2413 ok(capture == 0, "GetCapture() = %p\n", capture);
2415 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2417 trace("button %p\n", button);
2419 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2421 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2423 capture = SetCapture(button);
2424 ok(capture == 0, "SetCapture() = %p\n", capture);
2425 check_wnd_state(button, 0, button, button);
2427 DestroyWindow(button);
2428 check_wnd_state(0, 0, 0, 0);
2431 static void test_capture_2(void)
2433 HWND button, hwnd, capture;
2435 check_wnd_state(0, 0, 0, 0);
2437 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2439 trace("button %p\n", button);
2441 check_wnd_state(button, button, button, 0);
2443 capture = SetCapture(button);
2444 ok(capture == 0, "SetCapture() = %p\n", capture);
2446 check_wnd_state(button, button, button, button);
2448 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2449 * internal button state.
2451 SendMessage(button, WM_KILLFOCUS, 0, 0);
2452 check_wnd_state(button, button, button, button);
2454 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2456 trace("hwnd %p\n", hwnd);
2458 check_wnd_state(button, button, button, button);
2460 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2462 check_wnd_state(button, button, button, button);
2464 DestroyWindow(hwnd);
2466 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2468 trace("hwnd %p\n", hwnd);
2470 check_wnd_state(button, button, button, button);
2472 ShowWindow(hwnd, SW_SHOW);
2474 check_wnd_state(hwnd, hwnd, hwnd, button);
2476 capture = SetCapture(hwnd);
2477 ok(capture == button, "SetCapture() = %p\n", capture);
2479 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2481 DestroyWindow(hwnd);
2482 check_wnd_state(button, button, button, 0);
2484 DestroyWindow(button);
2485 check_wnd_state(0, 0, 0, 0);
2488 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2492 ShowWindow(hwnd1, SW_HIDE);
2493 ShowWindow(hwnd2, SW_HIDE);
2495 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2496 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2499 check_wnd_state(0, 0, 0, hwnd1);
2502 check_wnd_state(0, 0, 0, hwnd2);
2504 ShowWindow(hwnd1, SW_SHOW);
2505 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2507 ret = ReleaseCapture();
2508 ok (ret, "releasecapture did not return TRUE.\n");
2509 ret = ReleaseCapture();
2510 ok (ret, "releasecapture did not return TRUE after second try.\n");
2513 static void test_keyboard_input(HWND hwnd)
2518 ShowWindow(hwnd, SW_SHOW);
2520 flush_events( TRUE );
2522 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2525 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2527 flush_events( TRUE );
2529 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2530 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2531 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2532 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2533 ok( !ret, "message %04x available\n", msg.message);
2535 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2537 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2538 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2539 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2540 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2541 ok( !ret, "message %04x available\n", msg.message);
2543 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2545 keybd_event(VK_SPACE, 0, 0, 0);
2546 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2547 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2548 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2549 ok( !ret, "message %04x available\n", msg.message);
2552 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2554 flush_events( TRUE );
2556 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2557 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2558 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2559 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2560 ok( !ret, "message %04x available\n", msg.message);
2562 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2564 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2565 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2566 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2567 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2568 ok( !ret, "message %04x available\n", msg.message);
2570 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2572 keybd_event(VK_SPACE, 0, 0, 0);
2573 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2574 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2575 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2576 ok( !ret, "message %04x available\n", msg.message);
2579 static void test_mouse_input(HWND hwnd)
2589 ShowWindow(hwnd, SW_SHOW);
2592 GetWindowRect(hwnd, &rc);
2593 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2595 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2596 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2599 ShowWindow(popup, SW_SHOW);
2600 UpdateWindow(popup);
2602 GetWindowRect(popup, &rc);
2603 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2605 x = rc.left + (rc.right - rc.left) / 2;
2606 y = rc.top + (rc.bottom - rc.top) / 2;
2607 trace("setting cursor to (%d,%d)\n", x, y);
2611 ok(x == pt.x && y == pt.y, "wrong cursor pos (%d,%d), expected (%d,%d)\n", pt.x, pt.y, x, y);
2613 flush_events( TRUE );
2615 /* Check that setting the same position will generate WM_MOUSEMOVE */
2618 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2619 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2620 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);
2622 /* force the system to update its internal queue mouse position,
2623 * otherwise it won't generate relative mouse movements below.
2625 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2626 flush_events( TRUE );
2629 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2630 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2631 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2632 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2633 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2634 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2635 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2636 ok( !ret, "message %04x available\n", msg.message);
2638 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2639 ShowWindow(popup, SW_HIDE);
2640 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2641 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2642 flush_events( TRUE );
2644 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2645 ShowWindow(hwnd, SW_HIDE);
2646 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2647 ok( !ret, "message %04x available\n", msg.message);
2648 flush_events( TRUE );
2650 /* test mouse clicks */
2652 ShowWindow(hwnd, SW_SHOW);
2653 flush_events( TRUE );
2654 ShowWindow(popup, SW_SHOW);
2655 flush_events( TRUE );
2657 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2658 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2659 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2660 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2662 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2663 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2664 msg.hwnd, popup, msg.message);
2665 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2666 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2667 msg.hwnd, popup, msg.message);
2669 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2670 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2671 msg.hwnd, popup, msg.message);
2672 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2673 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2674 msg.hwnd, popup, msg.message);
2676 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2677 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
2678 msg.hwnd, popup, msg.message);
2679 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2680 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
2681 msg.hwnd, popup, msg.message);
2683 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2684 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2685 msg.hwnd, popup, msg.message);
2686 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2687 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2688 msg.hwnd, popup, msg.message);
2690 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2691 ok(!ret, "message %04x available\n", msg.message);
2693 ShowWindow(popup, SW_HIDE);
2694 flush_events( TRUE );
2696 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2697 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2698 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2699 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2701 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2702 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2703 msg.hwnd, hwnd, msg.message);
2704 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2705 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2706 msg.hwnd, hwnd, msg.message);
2708 test_lbuttondown_flag = TRUE;
2709 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
2710 test_lbuttondown_flag = FALSE;
2712 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2713 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "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);
2718 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2720 /* Test WM_MOUSEACTIVATE */
2721 #define TEST_MOUSEACTIVATE(A,B) \
2722 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2723 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2725 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
2726 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
2727 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
2728 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
2729 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
2730 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
2731 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
2732 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
2733 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
2734 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
2735 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
2736 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
2737 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
2738 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
2739 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
2740 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
2741 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
2742 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
2743 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
2744 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
2745 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
2746 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
2747 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
2748 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
2750 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2751 flush_events( TRUE );
2753 DestroyWindow(popup);
2756 static void test_validatergn(HWND hwnd)
2762 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
2763 ShowWindow(hwnd, SW_SHOW);
2764 UpdateWindow( hwnd);
2765 /* test that ValidateRect validates children*/
2766 InvalidateRect( child, NULL, 1);
2767 GetWindowRect( child, &rc);
2768 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2769 ret = GetUpdateRect( child, &rc2, 0);
2770 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
2771 "Update rectangle is empty!\n");
2772 ValidateRect( hwnd, &rc);
2773 ret = GetUpdateRect( child, &rc2, 0);
2774 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2775 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2776 rc2.right, rc2.bottom);
2778 /* now test ValidateRgn */
2779 InvalidateRect( child, NULL, 1);
2780 GetWindowRect( child, &rc);
2781 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2782 rgn = CreateRectRgnIndirect( &rc);
2783 ValidateRgn( hwnd, rgn);
2784 ret = GetUpdateRect( child, &rc2, 0);
2785 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2786 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2787 rc2.right, rc2.bottom);
2790 DestroyWindow( child );
2793 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
2795 MoveWindow( hwnd, 0, 0, x, y, 0);
2796 GetWindowRect( hwnd, prc);
2797 trace("window rect is %d,%d - %d,%d\n",
2798 prc->left,prc->top,prc->right,prc->bottom);
2799 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
2800 trace("nccalc rect is %d,%d - %d,%d\n",
2801 prc->left,prc->top,prc->right,prc->bottom);
2804 static void test_nccalcscroll(HWND parent)
2807 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
2808 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
2809 HWND hwnd = CreateWindowExA(0, "static", NULL,
2810 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
2811 10, 10, 200, 200, parent, 0, 0, NULL);
2812 ShowWindow( parent, SW_SHOW);
2813 UpdateWindow( parent);
2815 /* test window too low for a horizontal scroll bar */
2816 nccalchelper( hwnd, 100, sbheight, &rc1);
2817 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
2818 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
2820 /* test window just high enough for a horizontal scroll bar */
2821 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
2822 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
2823 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2825 /* test window too narrow for a vertical scroll bar */
2826 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
2827 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
2828 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2830 /* test window just wide enough for a vertical scroll bar */
2831 nccalchelper( hwnd, sbwidth, 100, &rc1);
2832 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
2833 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
2835 /* same test, but with client edge: not enough width */
2836 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
2837 nccalchelper( hwnd, sbwidth, 100, &rc1);
2838 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
2839 "Width should be %d size is %d,%d - %d,%d\n",
2840 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
2842 DestroyWindow( hwnd);
2845 static void test_SetParent(void)
2848 HWND desktop = GetDesktopWindow();
2850 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
2851 HWND parent, child1, child2, child3, child4, sibling;
2853 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2854 100, 100, 200, 200, 0, 0, 0, NULL);
2855 assert(parent != 0);
2856 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2857 0, 0, 50, 50, parent, 0, 0, NULL);
2858 assert(child1 != 0);
2859 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2860 0, 0, 50, 50, child1, 0, 0, NULL);
2861 assert(child2 != 0);
2862 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2863 0, 0, 50, 50, child2, 0, 0, NULL);
2864 assert(child3 != 0);
2865 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2866 0, 0, 50, 50, child3, 0, 0, NULL);
2867 assert(child4 != 0);
2869 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2870 parent, child1, child2, child3, child4);
2872 check_parents(parent, desktop, 0, 0, 0, parent, parent);
2873 check_parents(child1, parent, parent, parent, 0, parent, parent);
2874 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2875 check_parents(child3, child2, child2, child2, 0, child2, parent);
2876 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2878 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
2879 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
2880 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2881 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
2882 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2884 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
2885 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2886 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
2887 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
2888 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
2889 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
2890 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
2891 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
2892 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2894 if (!is_win9x) /* Win9x doesn't survive this test */
2896 ok(!SetParent(parent, child1), "SetParent should fail\n");
2897 ok(!SetParent(child2, child3), "SetParent should fail\n");
2898 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
2899 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
2900 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
2901 ok(!SetParent(child2, parent), "SetParent should fail\n");
2902 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
2904 check_parents(parent, child4, child4, 0, 0, child4, parent);
2905 check_parents(child1, parent, parent, parent, 0, child4, parent);
2906 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2907 check_parents(child3, child2, child2, child2, 0, child2, parent);
2908 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2911 hMenu = CreateMenu();
2912 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2913 100, 100, 200, 200, 0, hMenu, 0, NULL);
2914 assert(sibling != 0);
2916 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
2917 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
2919 ret = DestroyWindow(parent);
2920 ok( ret, "DestroyWindow() error %d\n", GetLastError());
2922 ok(!IsWindow(parent), "parent still exists\n");
2923 ok(!IsWindow(sibling), "sibling still exists\n");
2924 ok(!IsWindow(child1), "child1 still exists\n");
2925 ok(!IsWindow(child2), "child2 still exists\n");
2926 ok(!IsWindow(child3), "child3 still exists\n");
2927 ok(!IsWindow(child4), "child4 still exists\n");
2930 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2932 LPCREATESTRUCT lpcs;
2939 lpcs = (LPCREATESTRUCT)lparam;
2940 lpss = (LPSTYLESTRUCT)lpcs->lpCreateParams;
2943 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
2944 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
2945 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
2946 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
2948 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
2950 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
2951 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2952 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
2954 ok(lpss->styleNew == lpcs->style,
2955 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
2956 lpss->styleNew, lpcs->style);
2960 return DefWindowProc(hwnd, msg, wparam, lparam);
2963 static ATOM atomStyleCheckClass;
2965 static void register_style_check_class(void)
2973 GetModuleHandle(NULL),
2975 LoadCursor(NULL, IDC_ARROW),
2976 (HBRUSH)(COLOR_BTNFACE+1),
2978 TEXT("WineStyleCheck"),
2981 atomStyleCheckClass = RegisterClass(&wc);
2984 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
2986 DWORD dwActualStyle;
2987 DWORD dwActualExStyle;
2990 HWND hwndParent = NULL;
2992 ss.styleNew = dwStyleIn;
2993 ss.styleOld = dwExStyleIn;
2995 if (dwStyleIn & WS_CHILD)
2997 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
2998 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3001 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
3002 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3005 flush_events( TRUE );
3007 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3008 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3009 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3010 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3011 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3013 DestroyWindow(hwnd);
3014 if (hwndParent) DestroyWindow(hwndParent);
3017 /* tests what window styles the window manager automatically adds */
3018 static void test_window_styles(void)
3020 register_style_check_class();
3022 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3023 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3024 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3025 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3026 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3027 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3028 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3029 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3030 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3031 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3032 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3035 static void test_scrollvalidate( HWND parent)
3038 HRGN hrgn=CreateRectRgn(0,0,0,0);
3039 HRGN exprgn, tmprgn, clipping;
3040 RECT rc, rcu, cliprc;
3041 /* create two overlapping child windows. The visual region
3042 * of hwnd1 is clipped by the overlapping part of
3043 * hwnd2 because of the WS_CLIPSIBLING style */
3046 clipping = CreateRectRgn(0,0,0,0);
3047 tmprgn = CreateRectRgn(0,0,0,0);
3048 exprgn = CreateRectRgn(0,0,0,0);
3049 hwnd2 = CreateWindowExA(0, "static", NULL,
3050 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3051 75, 30, 100, 100, parent, 0, 0, NULL);
3052 hwnd1 = CreateWindowExA(0, "static", NULL,
3053 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3054 25, 50, 100, 100, parent, 0, 0, NULL);
3055 ShowWindow( parent, SW_SHOW);
3056 UpdateWindow( parent);
3057 GetClientRect( hwnd1, &rc);
3059 SetRectRgn( clipping, 10, 10, 90, 90);
3060 hdc = GetDC( hwnd1);
3061 /* for a visual touch */
3062 TextOut( hdc, 0,10, "0123456789", 10);
3063 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3064 if (winetest_debug > 0) dump_region(hrgn);
3065 /* create a region with what is expected */
3066 SetRectRgn( exprgn, 39,0,49,74);
3067 SetRectRgn( tmprgn, 88,79,98,93);
3068 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3069 SetRectRgn( tmprgn, 0,93,98,98);
3070 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3071 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3072 trace("update rect is %d,%d - %d,%d\n",
3073 rcu.left,rcu.top,rcu.right,rcu.bottom);
3074 /* now with clipping region */
3075 SelectClipRgn( hdc, clipping);
3076 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3077 if (winetest_debug > 0) dump_region(hrgn);
3078 /* create a region with what is expected */
3079 SetRectRgn( exprgn, 39,10,49,74);
3080 SetRectRgn( tmprgn, 80,79,90,85);
3081 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3082 SetRectRgn( tmprgn, 10,85,90,90);
3083 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3084 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3085 trace("update rect is %d,%d - %d,%d\n",
3086 rcu.left,rcu.top,rcu.right,rcu.bottom);
3087 ReleaseDC( hwnd1, hdc);
3089 /* test scrolling a window with an update region */
3090 DestroyWindow( hwnd2);
3091 ValidateRect( hwnd1, NULL);
3092 SetRect( &rc, 40,40, 50,50);
3093 InvalidateRect( hwnd1, &rc, 1);
3094 GetClientRect( hwnd1, &rc);
3096 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
3097 SW_SCROLLCHILDREN | SW_INVALIDATE);
3098 if (winetest_debug > 0) dump_region(hrgn);
3099 SetRectRgn( exprgn, 88,0,98,98);
3100 SetRectRgn( tmprgn, 30, 40, 50, 50);
3101 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3102 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3104 /* clear an update region */
3105 UpdateWindow( hwnd1 );
3107 SetRect( &rc, 0,40, 100,60);
3108 SetRect( &cliprc, 0,0, 100,100);
3109 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3110 if (winetest_debug > 0) dump_region( hrgn );
3111 SetRectRgn( exprgn, 0, 40, 98, 60 );
3112 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
3114 /* now test ScrollWindowEx with a combination of
3115 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3116 /* make hwnd2 the child of hwnd1 */
3117 hwnd2 = CreateWindowExA(0, "static", NULL,
3118 WS_CHILD| WS_VISIBLE | WS_BORDER ,
3119 50, 50, 100, 100, hwnd1, 0, 0, NULL);
3120 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
3121 GetClientRect( hwnd1, &rc);
3124 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3125 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3126 ValidateRect( hwnd1, NULL);
3127 ValidateRect( hwnd2, NULL);
3128 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
3129 SW_SCROLLCHILDREN | SW_INVALIDATE);
3130 if (winetest_debug > 0) dump_region(hrgn);
3131 SetRectRgn( exprgn, 88,0,98,88);
3132 SetRectRgn( tmprgn, 0,88,98,98);
3133 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3134 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3136 /* SW_SCROLLCHILDREN */
3137 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3138 ValidateRect( hwnd1, NULL);
3139 ValidateRect( hwnd2, NULL);
3140 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3141 if (winetest_debug > 0) dump_region(hrgn);
3142 /* expected region is the same as in previous test */
3143 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3145 /* no SW_SCROLLCHILDREN */
3146 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3147 ValidateRect( hwnd1, NULL);
3148 ValidateRect( hwnd2, NULL);
3149 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3150 if (winetest_debug > 0) dump_region(hrgn);
3151 /* expected region is the same as in previous test */
3152 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3154 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3155 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3156 ValidateRect( hwnd1, NULL);
3157 ValidateRect( hwnd2, NULL);
3158 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3159 if (winetest_debug > 0) dump_region(hrgn);
3160 SetRectRgn( exprgn, 88,0,98,20);
3161 SetRectRgn( tmprgn, 20,20,98,30);
3162 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3163 SetRectRgn( tmprgn, 20,30,30,88);
3164 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3165 SetRectRgn( tmprgn, 0,88,30,98);
3166 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3167 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3170 DeleteObject( hrgn);
3171 DeleteObject( exprgn);
3172 DeleteObject( tmprgn);
3173 DestroyWindow( hwnd1);
3174 DestroyWindow( hwnd2);
3177 /* couple of tests of return values of scrollbar functions
3178 * called on a scrollbarless window */
3179 static void test_scroll(void)
3184 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3185 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3186 100, 100, 200, 200, 0, 0, 0, NULL);
3188 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3189 ok( ret, "GetScrollRange returns FALSE\n");
3190 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3191 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3192 si.cbSize = sizeof( si);
3193 si.fMask = SIF_PAGE;
3194 si.nPage = 0xdeadbeef;
3195 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3196 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3197 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3199 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3200 ok( ret, "GetScrollRange returns FALSE\n");
3201 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3202 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3203 si.cbSize = sizeof( si);
3204 si.fMask = SIF_PAGE;
3205 si.nPage = 0xdeadbeef;
3206 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3207 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3208 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3210 DestroyWindow( hwnd);
3213 static void test_scrolldc( HWND parent)
3216 HRGN exprgn, tmprgn, hrgn;
3217 RECT rc, rc2, rcu, cliprc;
3221 hrgn = CreateRectRgn(0,0,0,0);
3222 tmprgn = CreateRectRgn(0,0,0,0);
3223 exprgn = CreateRectRgn(0,0,0,0);
3225 hwnd1 = CreateWindowExA(0, "static", NULL,
3226 WS_CHILD| WS_VISIBLE,
3227 25, 50, 100, 100, parent, 0, 0, NULL);
3228 ShowWindow( parent, SW_SHOW);
3229 UpdateWindow( parent);
3230 flush_events( TRUE );
3231 GetClientRect( hwnd1, &rc);
3232 hdc = GetDC( hwnd1);
3233 /* paint the upper half of the window black */
3235 rc2.bottom = ( rc.top + rc.bottom) /2;
3236 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3237 /* clip region is the lower half */
3239 cliprc.top = (rc.top + rc.bottom) /2;
3240 /* test whether scrolled pixels are properly clipped */
3241 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3242 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3243 /* this scroll should not cause any visible changes */
3244 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3245 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3246 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3247 /* test with NULL clip rect */
3248 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3249 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3250 trace("update rect: %d,%d - %d,%d\n",
3251 rcu.left, rcu.top, rcu.right, rcu.bottom);
3252 if (winetest_debug > 0) dump_region(hrgn);
3253 SetRect(&rc2, 0, 0, 100, 100);
3254 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3255 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3257 SetRectRgn( exprgn, 0, 0, 20, 80);
3258 SetRectRgn( tmprgn, 0, 80, 100, 100);
3259 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3260 if (winetest_debug > 0) dump_region(exprgn);
3261 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3262 /* test clip rect > scroll rect */
3263 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3265 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3266 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3267 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3268 SetRectRgn( exprgn, 25, 25, 75, 35);
3269 SetRectRgn( tmprgn, 25, 35, 35, 75);
3270 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3271 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3272 colr = GetPixel( hdc, 80, 80);
3273 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3274 trace("update rect: %d,%d - %d,%d\n",
3275 rcu.left, rcu.top, rcu.right, rcu.bottom);
3276 if (winetest_debug > 0) dump_region(hrgn);
3280 DeleteObject(exprgn);
3281 DeleteObject(tmprgn);
3282 DestroyWindow(hwnd1);
3285 static void test_params(void)
3290 /* Just a param check */
3291 SetLastError(0xdeadbeef);
3292 rc = GetWindowText(hwndMain2, NULL, 1024);
3293 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
3295 SetLastError(0xdeadbeef);
3296 hwnd=CreateWindow("LISTBOX", "TestList",
3297 (LBS_STANDARD & ~LBS_SORT),
3299 NULL, (HMENU)1, NULL, 0);
3301 ok(!hwnd, "CreateWindow with invalid menu handle should fail\n");
3302 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3303 GetLastError() == 0xdeadbeef, /* Win9x */
3304 "wrong last error value %d\n", GetLastError());
3307 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3311 hwnd = CreateWindowEx(exStyle, class, class, style,
3318 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
3321 ShowWindow(hwnd, SW_SHOW);
3323 test_nonclient_area(hwnd);
3326 DestroyWindow(hwnd);
3329 static BOOL AWR_init(void)
3333 class.style = CS_HREDRAW | CS_VREDRAW;
3334 class.lpfnWndProc = DefWindowProcA;
3335 class.cbClsExtra = 0;
3336 class.cbWndExtra = 0;
3337 class.hInstance = 0;
3338 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3339 class.hCursor = LoadCursor (0, IDC_ARROW);
3340 class.hbrBackground = 0;
3341 class.lpszMenuName = 0;
3342 class.lpszClassName = szAWRClass;
3344 if (!RegisterClass (&class)) {
3345 ok(FALSE, "RegisterClass failed\n");
3349 hmenu = CreateMenu();
3352 ok(hmenu != 0, "Failed to create menu\n");
3353 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3359 static void test_AWR_window_size(BOOL menu)
3363 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3366 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3367 WS_HSCROLL, WS_VSCROLL
3371 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3374 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3375 WS_EX_DLGMODALFRAME,
3382 /* A exhaustive check of all the styles takes too long
3383 * so just do a (hopefully representative) sample
3385 for (i = 0; i < COUNTOF(styles); ++i)
3386 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3387 for (i = 0; i < COUNTOF(exStyles); ++i) {
3388 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3389 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3394 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3396 static void test_AdjustWindowRect(void)
3401 SHOWSYSMETRIC(SM_CYCAPTION);
3402 SHOWSYSMETRIC(SM_CYSMCAPTION);
3403 SHOWSYSMETRIC(SM_CYMENU);
3404 SHOWSYSMETRIC(SM_CXEDGE);
3405 SHOWSYSMETRIC(SM_CYEDGE);
3406 SHOWSYSMETRIC(SM_CXVSCROLL);
3407 SHOWSYSMETRIC(SM_CYHSCROLL);
3408 SHOWSYSMETRIC(SM_CXFRAME);
3409 SHOWSYSMETRIC(SM_CYFRAME);
3410 SHOWSYSMETRIC(SM_CXDLGFRAME);
3411 SHOWSYSMETRIC(SM_CYDLGFRAME);
3412 SHOWSYSMETRIC(SM_CXBORDER);
3413 SHOWSYSMETRIC(SM_CYBORDER);
3415 test_AWR_window_size(FALSE);
3416 test_AWR_window_size(TRUE);
3420 #undef SHOWSYSMETRIC
3423 /* Global variables to trigger exit from loop */
3424 static int redrawComplete, WMPAINT_count;
3426 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3431 trace("doing WM_PAINT %d\n", WMPAINT_count);
3433 if (WMPAINT_count > 10 && redrawComplete == 0) {
3435 BeginPaint(hwnd, &ps);
3436 EndPaint(hwnd, &ps);
3441 return DefWindowProc(hwnd, msg, wparam, lparam);
3444 /* Ensure we exit from RedrawNow regardless of invalidated area */
3445 static void test_redrawnow(void)
3450 cls.style = CS_DBLCLKS;
3451 cls.lpfnWndProc = redraw_window_procA;
3454 cls.hInstance = GetModuleHandleA(0);
3456 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3457 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3458 cls.lpszMenuName = NULL;
3459 cls.lpszClassName = "RedrawWindowClass";
3461 if(!RegisterClassA(&cls)) {
3462 trace("Register failed %d\n", GetLastError());
3466 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3467 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3469 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3470 ShowWindow(hwndMain, SW_SHOW);
3471 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3472 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3473 ok( WMPAINT_count == 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3474 redrawComplete = TRUE;
3475 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3478 DestroyWindow( hwndMain);
3481 struct parentdc_stat {
3487 struct parentdc_test {
3488 struct parentdc_stat main, main_todo;
3489 struct parentdc_stat child1, child1_todo;
3490 struct parentdc_stat child2, child2_todo;
3493 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3498 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3503 trace("doing WM_PAINT on %p\n", hwnd);
3504 GetClientRect(hwnd, &rc);
3505 CopyRect(&t->client, &rc);
3506 trace("client rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3507 GetWindowRect(hwnd, &rc);
3508 trace("window rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3509 BeginPaint(hwnd, &ps);
3510 CopyRect(&t->paint, &ps.rcPaint);
3511 GetClipBox(ps.hdc, &rc);
3512 CopyRect(&t->clip, &rc);
3513 trace("clip rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3514 trace("paint rect (%d, %d)-(%d, %d)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3515 EndPaint(hwnd, &ps);
3518 return DefWindowProc(hwnd, msg, wparam, lparam);
3521 static void zero_parentdc_stat(struct parentdc_stat *t)
3523 SetRectEmpty(&t->client);
3524 SetRectEmpty(&t->clip);
3525 SetRectEmpty(&t->paint);
3528 static void zero_parentdc_test(struct parentdc_test *t)
3530 zero_parentdc_stat(&t->main);
3531 zero_parentdc_stat(&t->child1);
3532 zero_parentdc_stat(&t->child2);
3535 #define parentdc_field_ok(t, w, r, f, got) \
3536 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3537 ": expected %d, got %d\n", \
3540 #define parentdc_todo_field_ok(t, w, r, f, got) \
3541 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3542 else parentdc_field_ok(t, w, r, f, got)
3544 #define parentdc_rect_ok(t, w, r, got) \
3545 parentdc_todo_field_ok(t, w, r, left, got); \
3546 parentdc_todo_field_ok(t, w, r, top, got); \
3547 parentdc_todo_field_ok(t, w, r, right, got); \
3548 parentdc_todo_field_ok(t, w, r, bottom, got);
3550 #define parentdc_win_ok(t, w, got) \
3551 parentdc_rect_ok(t, w, client, got); \
3552 parentdc_rect_ok(t, w, clip, got); \
3553 parentdc_rect_ok(t, w, paint, got);
3555 #define parentdc_ok(t, got) \
3556 parentdc_win_ok(t, main, got); \
3557 parentdc_win_ok(t, child1, got); \
3558 parentdc_win_ok(t, child2, got);
3560 static void test_csparentdc(void)
3562 WNDCLASSA clsMain, cls;
3563 HWND hwndMain, hwnd1, hwnd2;
3566 struct parentdc_test test_answer;
3568 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3569 const struct parentdc_test test1 =
3571 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
3572 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3573 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3576 const struct parentdc_test test2 =
3578 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
3579 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3580 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3583 const struct parentdc_test test3 =
3585 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3586 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3587 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3590 const struct parentdc_test test4 =
3592 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
3593 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
3594 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3597 const struct parentdc_test test5 =
3599 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
3600 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3601 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3604 const struct parentdc_test test6 =
3606 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3607 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3608 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3611 const struct parentdc_test test7 =
3613 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3614 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3615 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3619 clsMain.style = CS_DBLCLKS;
3620 clsMain.lpfnWndProc = parentdc_window_procA;
3621 clsMain.cbClsExtra = 0;
3622 clsMain.cbWndExtra = 0;
3623 clsMain.hInstance = GetModuleHandleA(0);
3625 clsMain.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3626 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
3627 clsMain.lpszMenuName = NULL;
3628 clsMain.lpszClassName = "ParentDcMainWindowClass";
3630 if(!RegisterClassA(&clsMain)) {
3631 trace("Register failed %d\n", GetLastError());
3635 cls.style = CS_DBLCLKS | CS_PARENTDC;
3636 cls.lpfnWndProc = parentdc_window_procA;
3639 cls.hInstance = GetModuleHandleA(0);
3641 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3642 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3643 cls.lpszMenuName = NULL;
3644 cls.lpszClassName = "ParentDcWindowClass";
3646 if(!RegisterClassA(&cls)) {
3647 trace("Register failed %d\n", GetLastError());
3651 SetRect(&rc, 0, 0, 150, 150);
3652 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
3653 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3654 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
3655 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
3656 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
3657 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
3658 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
3659 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
3660 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
3661 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
3662 ShowWindow(hwndMain, SW_SHOW);
3663 ShowWindow(hwnd1, SW_SHOW);
3664 ShowWindow(hwnd2, SW_SHOW);
3665 flush_events( TRUE );
3667 zero_parentdc_test(&test_answer);
3668 InvalidateRect(hwndMain, NULL, TRUE);
3669 flush_events( TRUE );
3670 parentdc_ok(test1, test_answer);
3672 zero_parentdc_test(&test_answer);
3673 SetRect(&rc, 0, 0, 50, 50);
3674 InvalidateRect(hwndMain, &rc, TRUE);
3675 flush_events( TRUE );
3676 parentdc_ok(test2, test_answer);
3678 zero_parentdc_test(&test_answer);
3679 SetRect(&rc, 0, 0, 10, 10);
3680 InvalidateRect(hwndMain, &rc, TRUE);
3681 flush_events( TRUE );
3682 parentdc_ok(test3, test_answer);
3684 zero_parentdc_test(&test_answer);
3685 SetRect(&rc, 40, 40, 50, 50);
3686 InvalidateRect(hwndMain, &rc, TRUE);
3687 flush_events( TRUE );
3688 parentdc_ok(test4, test_answer);
3690 zero_parentdc_test(&test_answer);
3691 SetRect(&rc, 20, 20, 60, 60);
3692 InvalidateRect(hwndMain, &rc, TRUE);
3693 flush_events( TRUE );
3694 parentdc_ok(test5, test_answer);
3696 zero_parentdc_test(&test_answer);
3697 SetRect(&rc, 0, 0, 10, 10);
3698 InvalidateRect(hwnd1, &rc, TRUE);
3699 flush_events( TRUE );
3700 parentdc_ok(test6, test_answer);
3702 zero_parentdc_test(&test_answer);
3703 SetRect(&rc, -5, -5, 65, 65);
3704 InvalidateRect(hwnd1, &rc, TRUE);
3705 flush_events( TRUE );
3706 parentdc_ok(test7, test_answer);
3708 DestroyWindow(hwndMain);
3709 DestroyWindow(hwnd1);
3710 DestroyWindow(hwnd2);
3713 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3715 return DefWindowProcA(hwnd, msg, wparam, lparam);
3718 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3720 return DefWindowProcW(hwnd, msg, wparam, lparam);
3723 static void test_IsWindowUnicode(void)
3725 static const char ansi_class_nameA[] = "ansi class name";
3726 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3727 static const char unicode_class_nameA[] = "unicode class name";
3728 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3733 memset(&classW, 0, sizeof(classW));
3734 classW.hInstance = GetModuleHandleA(0);
3735 classW.lpfnWndProc = def_window_procW;
3736 classW.lpszClassName = unicode_class_nameW;
3737 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
3739 memset(&classA, 0, sizeof(classA));
3740 classA.hInstance = GetModuleHandleA(0);
3741 classA.lpfnWndProc = def_window_procA;
3742 classA.lpszClassName = ansi_class_nameA;
3743 assert(RegisterClassA(&classA));
3745 /* unicode class: window proc */
3746 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3747 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3750 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3751 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3752 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3753 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3754 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3756 DestroyWindow(hwnd);
3758 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3759 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3762 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3763 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3764 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3765 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3766 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3768 DestroyWindow(hwnd);
3770 /* ansi class: window proc */
3771 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3772 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3775 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3776 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3777 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3778 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3779 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3781 DestroyWindow(hwnd);
3783 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3784 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3787 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3788 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3789 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3790 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3791 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3793 DestroyWindow(hwnd);
3795 /* unicode class: class proc */
3796 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3797 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3800 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3801 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3802 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3803 /* do not restore class window proc back to unicode */
3805 DestroyWindow(hwnd);
3807 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3808 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3811 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3812 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
3813 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3815 DestroyWindow(hwnd);
3817 /* ansi class: class proc */
3818 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3819 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3822 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3823 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
3824 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3825 /* do not restore class window proc back to ansi */
3827 DestroyWindow(hwnd);
3829 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3830 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3833 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3834 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3835 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3837 DestroyWindow(hwnd);
3840 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
3844 if (msg != WM_GETMINMAXINFO)
3845 return DefWindowProc(hwnd, msg, wp, lp);
3847 minmax = (MINMAXINFO *)lp;
3849 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
3851 minmax->ptReserved.x = 0;
3852 minmax->ptReserved.y = 0;
3853 minmax->ptMaxSize.x = 400;
3854 minmax->ptMaxSize.y = 400;
3855 minmax->ptMaxPosition.x = 300;
3856 minmax->ptMaxPosition.y = 300;
3857 minmax->ptMaxTrackSize.x = 200;
3858 minmax->ptMaxTrackSize.y = 200;
3859 minmax->ptMinTrackSize.x = 100;
3860 minmax->ptMinTrackSize.y = 100;
3863 DefWindowProc(hwnd, msg, wp, lp);
3867 static int expected_cx, expected_cy;
3868 static RECT expected_rect;
3870 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
3874 case WM_GETMINMAXINFO:
3877 GetWindowRect( hwnd, &rect );
3878 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
3879 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
3880 return DefWindowProc(hwnd, msg, wp, lp);
3885 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
3887 GetWindowRect( hwnd, &rect );
3888 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
3889 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
3890 ok( cs->cx == expected_cx, "wrong x size %d/%d\n", cs->cx, expected_cx );
3891 ok( cs->cy == expected_cy, "wrong y size %d/%d\n", cs->cy, expected_cy );
3892 ok( rect.right - rect.left == expected_rect.right - expected_rect.left &&
3893 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top,
3894 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
3895 rect.left, rect.top, rect.right, rect.bottom,
3896 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
3897 return DefWindowProc(hwnd, msg, wp, lp);
3901 RECT rect, *r = (RECT *)lp;
3902 GetWindowRect( hwnd, &rect );
3903 ok( !memcmp( &rect, r, sizeof(rect) ),
3904 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
3905 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
3906 return DefWindowProc(hwnd, msg, wp, lp);
3909 return DefWindowProc(hwnd, msg, wp, lp);
3913 static void test_CreateWindow(void)
3921 #define expect_menu(window, menu) \
3922 SetLastError(0xdeadbeef); \
3923 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
3925 #define expect_style(window, style)\
3926 ok(GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
3928 #define expect_ex_style(window, ex_style)\
3929 ok(GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
3931 hmenu = CreateMenu();
3933 parent = GetDesktopWindow();
3934 assert(parent != 0);
3936 SetLastError(0xdeadbeef);
3937 ok(IsMenu(hmenu), "IsMenu error %d\n", GetLastError());
3940 SetLastError(0xdeadbeef);
3941 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
3942 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3943 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3944 expect_menu(hwnd, 1);
3945 expect_style(hwnd, WS_CHILD);
3946 expect_ex_style(hwnd, WS_EX_APPWINDOW);
3947 DestroyWindow(hwnd);
3949 SetLastError(0xdeadbeef);
3950 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
3951 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3952 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3953 expect_menu(hwnd, 1);
3954 expect_style(hwnd, WS_CHILD | WS_CAPTION);
3955 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
3956 DestroyWindow(hwnd);
3958 SetLastError(0xdeadbeef);
3959 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
3960 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3961 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3962 expect_menu(hwnd, 1);
3963 expect_style(hwnd, WS_CHILD);
3964 expect_ex_style(hwnd, 0);
3965 DestroyWindow(hwnd);
3967 SetLastError(0xdeadbeef);
3968 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
3969 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3970 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3971 expect_menu(hwnd, 1);
3972 expect_style(hwnd, WS_CHILD | WS_CAPTION);
3973 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
3974 DestroyWindow(hwnd);
3977 SetLastError(0xdeadbeef);
3978 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
3979 0, 0, 100, 100, parent, hmenu, 0, NULL);
3980 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3981 expect_menu(hwnd, hmenu);
3982 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
3983 expect_ex_style(hwnd, WS_EX_APPWINDOW);
3984 DestroyWindow(hwnd);
3985 SetLastError(0xdeadbeef);
3986 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3987 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3989 hmenu = CreateMenu();
3991 SetLastError(0xdeadbeef);
3992 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
3993 0, 0, 100, 100, parent, hmenu, 0, NULL);
3994 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3995 expect_menu(hwnd, hmenu);
3996 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
3997 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
3998 DestroyWindow(hwnd);
3999 SetLastError(0xdeadbeef);
4000 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4001 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4003 hmenu = CreateMenu();
4005 SetLastError(0xdeadbeef);
4006 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
4007 0, 0, 100, 100, parent, hmenu, 0, NULL);
4008 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4009 expect_menu(hwnd, hmenu);
4010 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4011 expect_ex_style(hwnd, 0);
4012 DestroyWindow(hwnd);
4013 SetLastError(0xdeadbeef);
4014 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4015 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4017 hmenu = CreateMenu();
4019 SetLastError(0xdeadbeef);
4020 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
4021 0, 0, 100, 100, parent, hmenu, 0, NULL);
4022 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4023 expect_menu(hwnd, hmenu);
4024 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4025 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4026 DestroyWindow(hwnd);
4027 SetLastError(0xdeadbeef);
4028 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4029 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4031 /* WS_CHILD | WS_POPUP */
4032 SetLastError(0xdeadbeef);
4033 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4034 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4035 ok(!hwnd, "CreateWindowEx should fail\n");
4036 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4038 hmenu = CreateMenu();
4040 SetLastError(0xdeadbeef);
4041 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4042 0, 0, 100, 100, parent, hmenu, 0, NULL);
4043 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4044 expect_menu(hwnd, hmenu);
4045 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4046 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4047 DestroyWindow(hwnd);
4048 SetLastError(0xdeadbeef);
4049 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4050 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4052 SetLastError(0xdeadbeef);
4053 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
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 | WS_CAPTION,
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_CAPTION | WS_CLIPSIBLINGS);
4066 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
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(0, "static", NULL, WS_CHILD | WS_POPUP,
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(0, "static", NULL, WS_CHILD | WS_POPUP,
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_CLIPSIBLINGS);
4086 expect_ex_style(hwnd, 0);
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 | WS_CAPTION,
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 | WS_CAPTION,
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_CAPTION | WS_CLIPSIBLINGS);
4106 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
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 /* test child window sizing */
4114 cls.lpfnWndProc = minmax_wnd_proc;
4117 cls.hInstance = GetModuleHandle(0);
4119 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
4120 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4121 cls.lpszMenuName = NULL;
4122 cls.lpszClassName = "MinMax_WndClass";
4123 RegisterClass(&cls);
4125 SetLastError(0xdeadbeef);
4126 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4127 0, 0, 100, 100, 0, 0, 0, NULL);
4128 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4129 expect_menu(parent, 0);
4130 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
4131 expect_ex_style(parent, WS_EX_WINDOWEDGE);
4133 memset(&minmax, 0, sizeof(minmax));
4134 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4135 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
4136 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
4137 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4138 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
4140 GetWindowRect(parent, &rc);
4141 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
4142 GetClientRect(parent, &rc);
4143 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
4145 InflateRect(&rc, 200, 200);
4146 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4148 SetLastError(0xdeadbeef);
4149 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4150 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
4151 parent, (HMENU)1, 0, NULL);
4152 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4153 expect_menu(hwnd, 1);
4154 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
4155 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4157 memset(&minmax, 0, sizeof(minmax));
4158 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4159 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4161 GetWindowRect(hwnd, &rc);
4162 OffsetRect(&rc, -rc.left, -rc.top);
4163 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4164 rc.left, rc.top, rc.right, rc.bottom,
4165 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
4166 DestroyWindow(hwnd);
4168 cls.lpfnWndProc = winsizes_wnd_proc;
4169 cls.lpszClassName = "Sizes_WndClass";
4170 RegisterClass(&cls);
4172 expected_cx = expected_cy = 200000;
4173 SetRect( &expected_rect, 0, 0, 200000, 200000 );
4174 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
4175 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4176 GetClientRect( hwnd, &rc );
4177 ok( rc.right == 200000, "invalid rect right %u\n", rc.right );
4178 ok( rc.bottom == 200000, "invalid rect bottom %u\n", rc.bottom );
4179 DestroyWindow(hwnd);
4181 expected_cx = expected_cy = -10;
4182 SetRect( &expected_rect, 0, 0, 0, 0 );
4183 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
4184 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4185 GetClientRect( hwnd, &rc );
4186 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4187 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4188 DestroyWindow(hwnd);
4190 expected_cx = expected_cy = -200000;
4191 SetRect( &expected_rect, 0, 0, 0, 0 );
4192 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
4193 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4194 GetClientRect( hwnd, &rc );
4195 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4196 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4197 DestroyWindow(hwnd);
4199 /* we need a parent at 0,0 so that child coordinates match */
4200 DestroyWindow(parent);
4201 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
4202 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4205 expected_cy = 0x7fffffff;
4206 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
4207 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
4208 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4209 GetClientRect( hwnd, &rc );
4210 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
4211 ok( rc.bottom == 0x7fffffff - 10, "invalid rect bottom %u\n", rc.bottom );
4212 DestroyWindow(hwnd);
4214 expected_cx = 0x7fffffff;
4215 expected_cy = 0x7fffffff;
4216 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
4217 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
4218 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4219 GetClientRect( hwnd, &rc );
4220 ok( rc.right == 0x7fffffff - 20, "invalid rect right %u\n", rc.right );
4221 ok( rc.bottom == 0x7fffffff - 10, "invalid rect bottom %u\n", rc.bottom );
4222 DestroyWindow(hwnd);
4224 /* top level window */
4225 expected_cx = expected_cy = 200000;
4226 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
4227 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
4228 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4229 GetClientRect( hwnd, &rc );
4230 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
4231 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
4232 DestroyWindow(hwnd);
4234 DestroyWindow(parent);
4236 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4237 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4241 #undef expect_ex_style
4244 /* function that remembers whether the system the test is running on sets the
4245 * last error for user32 functions to make the tests stricter */
4246 static int check_error(DWORD actual, DWORD expected)
4248 static int sets_last_error = -1;
4249 if (sets_last_error == -1)
4250 sets_last_error = (actual != 0xdeadbeef);
4251 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
4254 static void test_SetWindowLong(void)
4257 WNDPROC old_window_procW;
4259 SetLastError(0xdeadbeef);
4260 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
4261 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
4262 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
4263 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4265 SetLastError(0xdeadbeef);
4266 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
4267 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
4268 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
4269 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4271 SetLastError(0xdeadbeef);
4272 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4273 ok((WNDPROC)retval == main_window_procA,
4274 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
4275 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4276 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
4277 ok((WNDPROC)retval == main_window_procA,
4278 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4279 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
4281 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
4282 SetLastError(0xdeadbeef);
4283 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
4284 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
4286 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4287 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
4288 ok((WNDPROC)retval == old_window_procW,
4289 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4290 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
4292 /* set it back to ANSI */
4293 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4297 static void test_ShowWindow(void)
4304 SetRect(&rcMain, 120, 120, 210, 210);
4306 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
4307 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4308 WS_MAXIMIZEBOX | WS_POPUP,
4309 rcMain.left, rcMain.top,
4310 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
4314 style = GetWindowLong(hwnd, GWL_STYLE);
4315 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4316 ok(!(style & WS_VISIBLE), "window should not be visible\n");
4317 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4318 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4319 GetWindowRect(hwnd, &rc);
4320 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4322 ret = ShowWindow(hwnd, SW_SHOW);
4323 ok(!ret, "not expected ret: %lu\n", ret);
4324 style = GetWindowLong(hwnd, GWL_STYLE);
4325 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4326 ok(style & WS_VISIBLE, "window should be visible\n");
4327 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4328 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4329 GetWindowRect(hwnd, &rc);
4330 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4332 ret = ShowWindow(hwnd, SW_MINIMIZE);
4333 ok(ret, "not expected ret: %lu\n", ret);
4334 style = GetWindowLong(hwnd, GWL_STYLE);
4335 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4336 ok(style & WS_VISIBLE, "window should be visible\n");
4337 ok(style & WS_MINIMIZE, "window should be minimized\n");
4338 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4339 GetWindowRect(hwnd, &rc);
4340 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4342 ShowWindow(hwnd, SW_RESTORE);
4343 ok(ret, "not expected ret: %lu\n", ret);
4344 style = GetWindowLong(hwnd, GWL_STYLE);
4345 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4346 ok(style & WS_VISIBLE, "window should be visible\n");
4347 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4348 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4349 GetWindowRect(hwnd, &rc);
4350 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4352 ret = EnableWindow(hwnd, FALSE);
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");
4357 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
4358 ok(!ret, "not expected ret: %lu\n", ret);
4359 style = GetWindowLong(hwnd, GWL_STYLE);
4360 ok(style & WS_DISABLED, "window should be disabled\n");
4361 ok(style & WS_VISIBLE, "window should be visible\n");
4362 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4363 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4364 GetWindowRect(hwnd, &rc);
4365 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4367 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
4368 ok(!ret, "not expected ret: %lu\n", ret);
4369 style = GetWindowLong(hwnd, GWL_STYLE);
4370 ok(style & WS_DISABLED, "window should be disabled\n");
4371 ok(style & WS_VISIBLE, "window should be visible\n");
4372 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4373 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4374 GetWindowRect(hwnd, &rc);
4375 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4377 ret = ShowWindow(hwnd, SW_MINIMIZE);
4378 ok(ret, "not expected ret: %lu\n", ret);
4379 style = GetWindowLong(hwnd, GWL_STYLE);
4380 ok(style & WS_DISABLED, "window should be disabled\n");
4381 ok(style & WS_VISIBLE, "window should be visible\n");
4382 ok(style & WS_MINIMIZE, "window should be minimized\n");
4383 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4384 GetWindowRect(hwnd, &rc);
4385 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4387 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
4388 ok(!ret, "not expected ret: %lu\n", ret);
4389 style = GetWindowLong(hwnd, GWL_STYLE);
4390 ok(style & WS_DISABLED, "window should be disabled\n");
4391 ok(style & WS_VISIBLE, "window should be visible\n");
4392 ok(style & WS_MINIMIZE, "window should be minimized\n");
4393 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4394 GetWindowRect(hwnd, &rc);
4395 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4397 ret = ShowWindow(hwnd, SW_RESTORE);
4398 ok(ret, "not expected ret: %lu\n", ret);
4399 style = GetWindowLong(hwnd, GWL_STYLE);
4400 ok(style & WS_DISABLED, "window should be disabled\n");
4401 ok(style & WS_VISIBLE, "window should be visible\n");
4402 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4403 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4404 GetWindowRect(hwnd, &rc);
4405 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4407 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4408 ok(!ret, "not expected ret: %lu\n", ret);
4409 ok(IsWindow(hwnd), "window should exist\n");
4411 ret = EnableWindow(hwnd, TRUE);
4412 ok(ret, "not expected ret: %lu\n", ret);
4414 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4415 ok(!ret, "not expected ret: %lu\n", ret);
4416 ok(!IsWindow(hwnd), "window should not exist\n");
4419 static void test_gettext(void)
4422 LPCSTR clsname = "gettexttest";
4426 memset( &cls, 0, sizeof cls );
4427 cls.lpfnWndProc = DefWindowProc;
4428 cls.lpszClassName = clsname;
4429 cls.hInstance = GetModuleHandle(NULL);
4431 if (!RegisterClass( &cls )) return;
4433 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
4434 ok( hwnd != NULL, "window was null\n");
4436 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
4437 ok( r == 0, "settext should return zero\n");
4439 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
4440 ok( r == 0, "settext should return zero (%ld)\n", r);
4442 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
4443 ok( r == 0, "settext should return zero (%ld)\n", r);
4445 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
4446 ok( r == 0, "settext should return zero (%ld)\n", r);
4448 DestroyWindow(hwnd);
4449 UnregisterClass( clsname, NULL );
4453 static void test_GetUpdateRect(void)
4456 BOOL ret, parent_wm_paint, grandparent_wm_paint;
4458 HWND hgrandparent, hparent, hchild;
4460 static const char classNameA[] = "GetUpdateRectClass";
4462 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
4463 0, 0, 100, 100, NULL, NULL, 0, NULL);
4465 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
4466 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4468 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
4469 10, 10, 30, 30, hparent, NULL, 0, NULL);
4471 ShowWindow(hgrandparent, SW_SHOW);
4472 UpdateWindow(hgrandparent);
4473 flush_events( TRUE );
4475 ShowWindow(hchild, SW_HIDE);
4476 SetRect(&rc2, 0, 0, 0, 0);
4477 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4478 ok(!ret, "GetUpdateRect returned not empty region\n");
4479 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4480 rc1.left, rc1.top, rc1.right, rc1.bottom,
4481 rc2.left, rc2.top, rc2.right, rc2.bottom);
4483 SetRect(&rc2, 10, 10, 40, 40);
4484 ret = GetUpdateRect(hparent, &rc1, FALSE);
4485 ok(ret, "GetUpdateRect returned empty region\n");
4486 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4487 rc1.left, rc1.top, rc1.right, rc1.bottom,
4488 rc2.left, rc2.top, rc2.right, rc2.bottom);
4490 parent_wm_paint = FALSE;
4491 grandparent_wm_paint = FALSE;
4492 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4494 if (msg.message == WM_PAINT)
4496 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4497 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4499 DispatchMessage(&msg);
4501 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4502 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4504 DestroyWindow(hgrandparent);
4507 cls.lpfnWndProc = DefWindowProcA;
4510 cls.hInstance = GetModuleHandleA(0);
4512 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
4513 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4514 cls.lpszMenuName = NULL;
4515 cls.lpszClassName = classNameA;
4517 if(!RegisterClassA(&cls)) {
4518 trace("Register failed %d\n", GetLastError());
4522 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
4523 0, 0, 100, 100, NULL, NULL, 0, NULL);
4525 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
4526 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4528 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
4529 10, 10, 30, 30, hparent, NULL, 0, NULL);
4531 ShowWindow(hgrandparent, SW_SHOW);
4532 UpdateWindow(hgrandparent);
4533 flush_events( TRUE );
4535 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4536 ok(!ret, "GetUpdateRect returned not empty region\n");
4538 ShowWindow(hchild, SW_HIDE);
4540 SetRect(&rc2, 0, 0, 0, 0);
4541 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4542 ok(!ret, "GetUpdateRect returned not empty region\n");
4543 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4544 rc1.left, rc1.top, rc1.right, rc1.bottom,
4545 rc2.left, rc2.top, rc2.right, rc2.bottom);
4547 SetRect(&rc2, 10, 10, 40, 40);
4548 ret = GetUpdateRect(hparent, &rc1, FALSE);
4549 ok(ret, "GetUpdateRect returned empty region\n");
4550 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4551 rc1.left, rc1.top, rc1.right, rc1.bottom,
4552 rc2.left, rc2.top, rc2.right, rc2.bottom);
4554 parent_wm_paint = FALSE;
4555 grandparent_wm_paint = FALSE;
4556 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4558 if (msg.message == WM_PAINT)
4560 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4561 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4563 DispatchMessage(&msg);
4565 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4566 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4568 DestroyWindow(hgrandparent);
4572 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
4580 const int waitTime = 2000;
4582 BeginPaint(hwnd, &ps);
4584 /* create and destroy window to create an exposed region on this window */
4585 win = CreateWindowA("static", "win", WS_VISIBLE,
4586 10,10,50,50, NULL, NULL, 0, NULL);
4589 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
4591 ValidateRect(hwnd, NULL);
4592 EndPaint(hwnd, &ps);
4594 if(waitResult != WAIT_TIMEOUT)
4596 GetUpdateRect(hwnd, &updateRect, FALSE);
4599 ok(!IsRectEmpty(&updateRect), "Exposed rect should not be empty\n");
4605 return DefWindowProc(hwnd, msg, wParam, lParam);
4608 static void test_Expose(void)
4613 memset(&cls, 0, sizeof(WNDCLASSA));
4614 cls.lpfnWndProc = TestExposedRegion_WndProc;
4615 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4616 cls.lpszClassName = "TestExposeClass";
4617 atom = RegisterClassA(&cls);
4619 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
4620 0, 0, 200, 100, NULL, NULL, 0, NULL);
4626 static void test_GetWindowModuleFileName(void)
4631 char buf1[MAX_PATH], buf2[MAX_PATH];
4633 if (!pGetWindowModuleFileNameA)
4635 skip("GetWindowModuleFileNameA is not available\n");
4639 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
4642 hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
4643 ok(hinst == 0, "expected 0, got %p\n", hinst);
4646 SetLastError(0xdeadbeef);
4647 ret1 = GetModuleFileName(hinst, buf1, sizeof(buf1));
4648 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
4651 SetLastError(0xdeadbeef);
4652 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
4653 ok(ret2, "GetWindowModuleFileNameA error %u\n", GetLastError());
4655 ok(ret1 == ret2, "%u != %u\n", ret1, ret2);
4656 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
4658 hinst = GetModuleHandle(0);
4660 /* MSDN mentions ERROR_INSUFFICIENT_BUFFER, but XP doesn't do it */
4661 SetLastError(0xdeadbeef);
4662 ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
4663 ok(ret2 == ret1 - 2, "expected %u, got %u\n", ret1 - 2, ret2);
4664 ok(GetLastError() == 0xdeadbeef ||
4665 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3 */
4666 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4668 SetLastError(0xdeadbeef);
4669 ret2 = GetModuleFileName(hinst, buf2, 0);
4670 ok(!ret2, "GetModuleFileName should return 0\n");
4671 ok(GetLastError() == 0xdeadbeef ||
4672 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3 */
4673 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4675 SetLastError(0xdeadbeef);
4676 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
4677 ok(ret2 == ret1 - 2, "expected %u, got %u\n", ret1 - 2, ret2);
4678 ok(GetLastError() == 0xdeadbeef ||
4679 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3 */
4680 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4682 SetLastError(0xdeadbeef);
4683 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
4684 ok(!ret2, "expected 0, got %u\n", ret2);
4685 ok(GetLastError() == 0xdeadbeef ||
4686 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3 */
4687 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4689 DestroyWindow(hwnd);
4692 hwnd = (HWND)0xdeadbeef;
4693 SetLastError(0xdeadbeef);
4694 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4695 ok(!ret1, "expected 0, got %u\n", ret1);
4696 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
4698 hwnd = GetDesktopWindow();
4699 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
4700 SetLastError(0xdeadbeef);
4701 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4702 ok(!ret1, "expected 0, got %u\n", ret1);
4704 hwnd = FindWindow("Shell_TrayWnd", NULL);
4705 ok(IsWindow(hwnd), "got invalid tray window %p\n", hwnd);
4706 SetLastError(0xdeadbeef);
4707 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4708 ok(!ret1, "expected 0, got %u\n", ret1);
4713 pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
4714 pGetWindowInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
4715 pGetWindowModuleFileNameA = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowModuleFileNameA" );
4717 hwndMain = CreateWindowExA(0, "static", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, NULL);
4720 ok(!GetParent(hwndMain), "GetParent should return 0 for message only windows\n");
4723 hwndMessage = pGetAncestor(hwndMain, GA_PARENT);
4724 ok(hwndMessage != 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
4725 trace("hwndMessage %p\n", hwndMessage);
4727 DestroyWindow(hwndMain);
4730 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
4732 if (!RegisterWindowClasses()) assert(0);
4734 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
4737 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
4738 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4739 WS_MAXIMIZEBOX | WS_POPUP,
4741 0, 0, GetModuleHandle(0), NULL);
4742 test_nonclient_area(hwndMain);
4744 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
4745 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4746 WS_MAXIMIZEBOX | WS_POPUP,
4748 0, 0, GetModuleHandle(0), NULL);
4750 assert( hwndMain2 );
4752 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
4754 /* Add the tests below this line */
4756 test_GetWindowModuleFileName();
4759 test_capture_3(hwndMain, hwndMain2);
4761 test_CreateWindow();
4762 test_parent_owner();
4764 test_shell_window();
4768 test_SetWindowPos(hwndMain);
4769 test_SetMenu(hwndMain);
4770 test_SetFocus(hwndMain);
4771 test_SetActiveWindow(hwndMain);
4772 test_SetForegroundWindow(hwndMain);
4774 test_children_zorder(hwndMain);
4775 test_popup_zorder(hwndMain2, hwndMain);
4776 test_keyboard_input(hwndMain);
4777 test_mouse_input(hwndMain);
4778 test_validatergn(hwndMain);
4779 test_nccalcscroll( hwndMain);
4780 test_scrollvalidate( hwndMain);
4781 test_scrolldc( hwndMain);
4783 test_IsWindowUnicode();
4784 test_vis_rgn(hwndMain);
4786 test_AdjustWindowRect();
4787 test_window_styles();
4790 test_SetWindowLong();
4793 test_GetUpdateRect();
4796 /* add the tests above this line */
4797 UnhookWindowsHookEx(hhook);