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);
50 static BOOL (WINAPI *pGetLayeredWindowAttributes)(HWND,COLORREF*,BYTE*,DWORD*);
51 static BOOL (WINAPI *pSetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD);
52 static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
53 static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
55 static BOOL test_lbuttondown_flag;
56 static HWND hwndMessage;
57 static HWND hwndMain, hwndMain2;
60 static const char* szAWRClass = "Winsize";
64 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
66 static void dump_minmax_info( const MINMAXINFO *minmax )
68 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
69 minmax->ptReserved.x, minmax->ptReserved.y,
70 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
71 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
72 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
73 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
76 /* try to make sure pending X events have been processed before continuing */
77 static void flush_events( BOOL remove_messages )
82 DWORD time = GetTickCount() + diff;
86 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
88 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
89 diff = time - GetTickCount();
94 /* check the values returned by the various parent/owner functions on a given window */
95 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
96 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
102 res = pGetAncestor( hwnd, GA_PARENT );
103 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
105 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
106 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
107 res = GetParent( hwnd );
108 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
109 res = GetWindow( hwnd, GW_OWNER );
110 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
113 res = pGetAncestor( hwnd, GA_ROOT );
114 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
115 res = pGetAncestor( hwnd, GA_ROOTOWNER );
116 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
120 static BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
123 trace("EnumChildProc on %p\n", hwndChild);
124 if (*(LPINT)lParam > 1) return FALSE;
128 /* will search for the given window */
129 static BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
131 trace("EnumChildProc1 on %p\n", hwndChild);
132 if ((HWND)lParam == hwndChild) return FALSE;
136 static HWND create_tool_window( LONG style, HWND parent )
138 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
139 0, 0, 100, 100, parent, 0, 0, NULL );
140 ok( ret != 0, "Creation failed\n" );
144 /* test parent and owner values for various combinations */
145 static void test_parent_owner(void)
148 HWND test, owner, ret;
149 HWND desktop = GetDesktopWindow();
150 HWND child = create_tool_window( WS_CHILD, hwndMain );
153 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
155 /* child without parent, should fail */
156 SetLastError(0xdeadbeef);
157 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
158 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
159 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD, "CreateWindowExA should call SetLastError\n" );
160 ok( !test, "WS_CHILD without parent created\n" );
163 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
164 style = GetWindowLongA( desktop, GWL_STYLE );
165 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
166 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
167 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
169 /* normal child window */
170 test = create_tool_window( WS_CHILD, hwndMain );
171 trace( "created child %p\n", test );
172 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
173 SetWindowLongA( test, GWL_STYLE, 0 );
174 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
175 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
176 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
177 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
178 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
179 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
180 DestroyWindow( test );
182 /* normal child window with WS_MAXIMIZE */
183 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
184 DestroyWindow( test );
186 /* normal child window with WS_THICKFRAME */
187 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
188 DestroyWindow( test );
190 /* popup window with WS_THICKFRAME */
191 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
192 DestroyWindow( test );
194 /* child of desktop */
195 test = create_tool_window( WS_CHILD, desktop );
196 trace( "created child of desktop %p\n", test );
197 check_parents( test, desktop, 0, desktop, 0, test, desktop );
198 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
199 check_parents( test, desktop, 0, 0, 0, test, test );
200 SetWindowLongA( test, GWL_STYLE, 0 );
201 check_parents( test, desktop, 0, 0, 0, test, test );
202 DestroyWindow( test );
204 /* child of desktop with WS_MAXIMIZE */
205 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
206 DestroyWindow( test );
208 /* child of desktop with WS_MINIMIZE */
209 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
210 DestroyWindow( test );
213 test = create_tool_window( WS_CHILD, child );
214 trace( "created child of child %p\n", test );
215 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
216 SetWindowLongA( test, GWL_STYLE, 0 );
217 check_parents( test, child, child, 0, 0, hwndMain, test );
218 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
219 check_parents( test, child, child, 0, 0, hwndMain, test );
220 DestroyWindow( test );
222 /* child of child with WS_MAXIMIZE */
223 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
224 DestroyWindow( test );
226 /* child of child with WS_MINIMIZE */
227 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
228 DestroyWindow( test );
230 /* not owned top-level window */
231 test = create_tool_window( 0, 0 );
232 trace( "created top-level %p\n", test );
233 check_parents( test, desktop, 0, 0, 0, test, test );
234 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
235 check_parents( test, desktop, 0, 0, 0, test, test );
236 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
237 check_parents( test, desktop, 0, desktop, 0, test, desktop );
238 DestroyWindow( test );
240 /* not owned top-level window with WS_MAXIMIZE */
241 test = create_tool_window( WS_MAXIMIZE, 0 );
242 DestroyWindow( test );
244 /* owned top-level window */
245 test = create_tool_window( 0, hwndMain );
246 trace( "created owned top-level %p\n", test );
247 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
248 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
249 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
250 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
251 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
252 DestroyWindow( test );
254 /* owned top-level window with WS_MAXIMIZE */
255 test = create_tool_window( WS_MAXIMIZE, hwndMain );
256 DestroyWindow( test );
258 /* not owned popup */
259 test = create_tool_window( WS_POPUP, 0 );
260 trace( "created popup %p\n", test );
261 check_parents( test, desktop, 0, 0, 0, test, test );
262 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
263 check_parents( test, desktop, 0, desktop, 0, test, desktop );
264 SetWindowLongA( test, GWL_STYLE, 0 );
265 check_parents( test, desktop, 0, 0, 0, test, test );
266 DestroyWindow( test );
268 /* not owned popup with WS_MAXIMIZE */
269 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
270 DestroyWindow( test );
273 test = create_tool_window( WS_POPUP, hwndMain );
274 trace( "created owned popup %p\n", test );
275 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
276 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
277 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
278 SetWindowLongA( test, GWL_STYLE, 0 );
279 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
280 DestroyWindow( test );
282 /* owned popup with WS_MAXIMIZE */
283 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
284 DestroyWindow( test );
286 /* top-level window owned by child (same as owned by top-level) */
287 test = create_tool_window( 0, child );
288 trace( "created top-level owned by child %p\n", test );
289 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
290 DestroyWindow( test );
292 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
293 test = create_tool_window( WS_MAXIMIZE, child );
294 DestroyWindow( test );
296 /* popup owned by desktop (same as not owned) */
297 test = create_tool_window( WS_POPUP, desktop );
298 trace( "created popup owned by desktop %p\n", test );
299 check_parents( test, desktop, 0, 0, 0, test, test );
300 DestroyWindow( test );
302 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
303 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
304 DestroyWindow( test );
306 /* popup owned by child (same as owned by top-level) */
307 test = create_tool_window( WS_POPUP, child );
308 trace( "created popup owned by child %p\n", test );
309 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
310 DestroyWindow( test );
312 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
313 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
314 DestroyWindow( test );
316 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
317 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
318 trace( "created WS_CHILD popup %p\n", test );
319 check_parents( test, desktop, 0, 0, 0, test, test );
320 DestroyWindow( test );
322 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
323 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
324 DestroyWindow( test );
326 /* owned popup with WS_CHILD (same as WS_POPUP only) */
327 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
328 trace( "created owned WS_CHILD popup %p\n", test );
329 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
330 DestroyWindow( test );
332 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
333 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
334 DestroyWindow( test );
336 /******************** parent changes *************************/
337 trace( "testing parent changes\n" );
340 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
343 /* this test succeeds on NT but crashes on win9x systems */
344 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
345 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
346 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
347 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
348 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
350 /* normal child window */
351 test = create_tool_window( WS_CHILD, hwndMain );
352 trace( "created child %p\n", test );
354 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
355 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
356 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
358 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
359 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
360 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
362 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
363 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
364 check_parents( test, desktop, 0, desktop, 0, test, desktop );
366 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
367 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
368 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
369 check_parents( test, desktop, child, desktop, child, test, desktop );
371 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
372 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
373 check_parents( test, desktop, 0, desktop, 0, test, desktop );
374 DestroyWindow( test );
376 /* not owned top-level window */
377 test = create_tool_window( 0, 0 );
378 trace( "created top-level %p\n", test );
380 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
381 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
382 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
384 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
385 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
386 check_parents( test, desktop, child, 0, child, test, test );
388 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
389 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
390 check_parents( test, desktop, 0, 0, 0, test, test );
391 DestroyWindow( test );
393 /* not owned popup */
394 test = create_tool_window( WS_POPUP, 0 );
395 trace( "created popup %p\n", test );
397 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
398 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
399 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
401 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
402 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
403 check_parents( test, desktop, child, child, child, test, hwndMain );
405 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
406 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
407 check_parents( test, desktop, 0, 0, 0, test, test );
408 DestroyWindow( test );
410 /* normal child window */
411 test = create_tool_window( WS_CHILD, hwndMain );
412 trace( "created child %p\n", test );
414 ret = SetParent( test, desktop );
415 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
416 check_parents( test, desktop, 0, desktop, 0, test, desktop );
418 ret = SetParent( test, child );
419 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
420 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
422 ret = SetParent( test, hwndMain2 );
423 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
424 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
425 DestroyWindow( test );
427 /* not owned top-level window */
428 test = create_tool_window( 0, 0 );
429 trace( "created top-level %p\n", test );
431 ret = SetParent( test, child );
432 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
433 check_parents( test, child, child, 0, 0, hwndMain, test );
434 DestroyWindow( test );
437 test = create_tool_window( WS_POPUP, hwndMain2 );
438 trace( "created owned popup %p\n", test );
440 ret = SetParent( test, child );
441 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
442 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
444 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
445 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
446 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
447 DestroyWindow( test );
449 /**************** test owner destruction *******************/
451 /* owned child popup */
452 owner = create_tool_window( 0, 0 );
453 test = create_tool_window( WS_POPUP, owner );
454 trace( "created owner %p and popup %p\n", owner, test );
455 ret = SetParent( test, child );
456 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
457 check_parents( test, child, child, owner, owner, hwndMain, owner );
458 /* window is now child of 'child' but owned by 'owner' */
459 DestroyWindow( owner );
460 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
461 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
462 * while Win95, Win2k, WinXP do.
464 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
465 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
468 /* owned top-level popup */
469 owner = create_tool_window( 0, 0 );
470 test = create_tool_window( WS_POPUP, owner );
471 trace( "created owner %p and popup %p\n", owner, test );
472 check_parents( test, desktop, owner, owner, owner, test, owner );
473 DestroyWindow( owner );
474 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
476 /* top-level popup owned by child */
477 owner = create_tool_window( WS_CHILD, hwndMain2 );
478 test = create_tool_window( WS_POPUP, 0 );
479 trace( "created owner %p and popup %p\n", owner, test );
480 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
481 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
482 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
483 DestroyWindow( owner );
484 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
485 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
486 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
487 * while Win95, Win2k, WinXP do.
489 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
493 DestroyWindow(child);
496 owner = create_tool_window( WS_OVERLAPPED, 0 );
497 test = create_tool_window( WS_POPUP, desktop );
499 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
501 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
502 "EnumChildWindows should have returned FALSE\n" );
503 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
505 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
506 ret = SetParent( test, owner );
507 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
510 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
511 "EnumChildWindows should have returned TRUE\n" );
512 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
514 child = create_tool_window( WS_CHILD, owner );
516 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
517 "EnumChildWindows should have returned FALSE\n" );
518 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
519 DestroyWindow( child );
521 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
522 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
524 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
525 "EnumChildWindows should have returned TRUE\n" );
526 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
528 ret = SetParent( child, owner );
529 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
530 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
532 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
533 "EnumChildWindows should have returned FALSE\n" );
534 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
536 ret = SetParent( child, NULL );
537 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
538 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
540 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
541 "EnumChildWindows should have returned TRUE\n" );
542 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
544 /* even GW_OWNER == owner it's still a desktop's child */
545 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
546 "EnumChildWindows should have found %p and returned FALSE\n", child );
548 DestroyWindow( child );
549 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
551 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
552 "EnumChildWindows should have found %p and returned FALSE\n", child );
554 DestroyWindow( child );
555 DestroyWindow( test );
556 DestroyWindow( owner );
560 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
564 case WM_GETMINMAXINFO:
566 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
568 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
569 dump_minmax_info( minmax );
570 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
573 case WM_WINDOWPOSCHANGING:
575 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
576 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
577 trace("main: WM_WINDOWPOSCHANGING\n");
578 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
579 winpos->hwnd, winpos->hwndInsertAfter,
580 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
581 if (!(winpos->flags & SWP_NOMOVE))
583 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
584 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
586 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
587 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
589 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
590 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
594 case WM_WINDOWPOSCHANGED:
597 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
598 trace("main: WM_WINDOWPOSCHANGED\n");
599 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
600 winpos->hwnd, winpos->hwndInsertAfter,
601 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
602 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
603 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
605 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
606 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
608 GetWindowRect(hwnd, &rc1);
609 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
610 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
611 /* note: winpos coordinates are relative to parent */
612 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
613 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
616 /* Uncomment this once the test succeeds in all cases */
617 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
620 GetClientRect(hwnd, &rc2);
621 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
622 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
623 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
624 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
629 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
630 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
632 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
633 if (got_getminmaxinfo)
634 trace("%p got WM_GETMINMAXINFO\n", hwnd);
636 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
637 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
639 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
643 if (test_lbuttondown_flag)
645 ShowWindow((HWND)wparam, SW_SHOW);
646 flush_events( FALSE );
651 return DefWindowProcA(hwnd, msg, wparam, lparam);
654 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
658 case WM_GETMINMAXINFO:
660 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
662 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
663 dump_minmax_info( minmax );
664 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
669 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
670 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
672 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
673 if (got_getminmaxinfo)
674 trace("%p got WM_GETMINMAXINFO\n", hwnd);
676 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
677 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
679 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
684 return DefWindowProcA(hwnd, msg, wparam, lparam);
687 static BOOL RegisterWindowClasses(void)
691 cls.style = CS_DBLCLKS;
692 cls.lpfnWndProc = main_window_procA;
695 cls.hInstance = GetModuleHandleA(0);
697 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
698 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
699 cls.lpszMenuName = NULL;
700 cls.lpszClassName = "MainWindowClass";
702 if(!RegisterClassA(&cls)) return FALSE;
705 cls.lpfnWndProc = tool_window_procA;
708 cls.hInstance = GetModuleHandleA(0);
710 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
711 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
712 cls.lpszMenuName = NULL;
713 cls.lpszClassName = "ToolWindowClass";
715 if(!RegisterClassA(&cls)) return FALSE;
720 static void verify_window_info(HWND hwnd, const WINDOWINFO *info)
722 RECT rcWindow, rcClient;
725 ok(IsWindow(hwnd), "bad window handle\n");
727 GetWindowRect(hwnd, &rcWindow);
728 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow\n");
730 GetClientRect(hwnd, &rcClient);
731 /* translate to screen coordinates */
732 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
733 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient\n");
735 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
736 "wrong dwStyle: %08x != %08x\n", info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE));
737 /* Windows reports some undocumented exstyles in WINDOWINFO, but
738 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
740 ok((info->dwExStyle & ~0xe0000800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
741 "wrong dwExStyle: %08x != %08x\n", info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE));
742 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
743 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x\n",
744 info->dwWindowStatus, status);
746 /* win2k and XP return broken border info in GetWindowInfo most of
747 * the time, so there is no point in testing it.
751 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
752 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
753 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
754 ok(info->cyWindowBorders == border,
755 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
757 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType\n");
758 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
759 info->wCreatorVersion == 0x0500 /* Vista */,
760 "wrong wCreatorVersion %04x\n", info->wCreatorVersion);
763 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
765 AdjustWindowRectEx(rc, style, menu, exstyle);
766 /* AdjustWindowRectEx does not include scroll bars */
767 if (style & WS_VSCROLL)
769 if(exstyle & WS_EX_LEFTSCROLLBAR)
770 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
772 rc->right += GetSystemMetrics(SM_CXVSCROLL);
774 if (style & WS_HSCROLL)
775 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
778 static void test_nonclient_area(HWND hwnd)
780 DWORD style, exstyle;
781 RECT rc_window, rc_client, rc;
783 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
786 style = GetWindowLongA(hwnd, GWL_STYLE);
787 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
788 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
790 GetWindowRect(hwnd, &rc_window);
791 trace("window: (%d,%d)-(%d,%d)\n", rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
792 GetClientRect(hwnd, &rc_client);
793 trace("client: (%d,%d)-(%d,%d)\n", rc_client.left, rc_client.top, rc_client.right, rc_client.bottom);
795 /* avoid some cases when things go wrong */
796 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
797 rc_window.right > 32768 || rc_window.bottom > 32768) return;
799 CopyRect(&rc, &rc_client);
800 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
801 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
803 trace("calc window: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
804 ok(EqualRect(&rc, &rc_window), "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
807 CopyRect(&rc, &rc_window);
808 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
809 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
810 trace("calc client: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
811 ok(EqualRect(&rc, &rc_client), "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
813 /* NULL rectangle shouldn't crash */
814 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
815 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
817 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
821 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
822 SetRect(&rc_client, 0, 0, 250, 150);
823 CopyRect(&rc_window, &rc_client);
824 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
825 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
826 trace("calc window: (%d,%d)-(%d,%d)\n",
827 rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
829 CopyRect(&rc, &rc_window);
830 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
831 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
832 trace("calc client: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
833 ok(EqualRect(&rc, &rc_client), "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
836 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
838 static const char *CBT_code_name[10] = {
849 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
851 trace("CBT: %d (%s), %08lx, %08lx\n", nCode, code_name, wParam, lParam);
853 /* on HCBT_DESTROYWND window state is undefined */
854 if (nCode != HCBT_DESTROYWND && IsWindow((HWND)wParam))
860 /* Win98 actually does check the info.cbSize and doesn't allow
861 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
862 * WinXP do not check it at all.
864 info.cbSize = sizeof(WINDOWINFO);
865 ok(pGetWindowInfo((HWND)wParam, &info), "GetWindowInfo should not fail\n");
866 verify_window_info((HWND)wParam, &info);
874 static const RECT rc_null;
877 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
878 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
879 (HWND)wParam, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
880 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
882 /* WS_VISIBLE should be turned off yet */
883 style = createwnd->lpcs->style & ~WS_VISIBLE;
884 ok(style == GetWindowLongA((HWND)wParam, GWL_STYLE),
885 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
886 GetWindowLongA((HWND)wParam, GWL_STYLE), style);
890 /* Uncomment this once the test succeeds in all cases */
891 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
893 ok(GetParent((HWND)wParam) == hwndMessage,
894 "wrong result from GetParent %p: message window %p\n",
895 GetParent((HWND)wParam), hwndMessage);
898 ok(!GetParent((HWND)wParam), "GetParent should return 0 at this point\n");
900 ok(!GetWindow((HWND)wParam, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
904 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
905 * Win9x still has them set to 0.
907 ok(GetWindow((HWND)wParam, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
908 ok(GetWindow((HWND)wParam, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
910 ok(!GetWindow((HWND)wParam, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
911 ok(!GetWindow((HWND)wParam, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
915 /* Uncomment this once the test succeeds in all cases */
918 ok(pGetAncestor((HWND)wParam, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
919 ok(pGetAncestor((HWND)wParam, GA_ROOT) == (HWND)wParam,
920 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOT), (HWND)wParam);
922 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
923 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == hwndMessage,
924 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
926 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == (HWND)wParam,
927 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOTOWNER), (HWND)wParam);
930 ok(GetWindowRect((HWND)wParam, &rc), "GetWindowRect failed\n");
931 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
932 ok(GetClientRect((HWND)wParam, &rc), "GetClientRect failed\n");
933 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
939 return CallNextHookEx(hhook, nCode, wParam, lParam);
942 static void test_shell_window(void)
946 HMODULE hinst, hUser32;
947 BOOL (WINAPI*SetShellWindow)(HWND);
948 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
949 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
950 HWND shellWindow, nextWnd;
952 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
954 trace("Skipping shell window test on Win9x\n");
958 shellWindow = GetShellWindow();
959 hinst = GetModuleHandle(0);
960 hUser32 = GetModuleHandleA("user32");
962 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
963 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
965 trace("previous shell window: %p\n", shellWindow);
971 SetLastError(0xdeadbeef);
972 ret = DestroyWindow(shellWindow);
973 error = GetLastError();
975 ok(!ret, "DestroyWindow(shellWindow)\n");
976 /* passes on Win XP, but not on Win98 */
977 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
978 "got %u after DestroyWindow(shellWindow)\n", error);
980 /* close old shell instance */
981 GetWindowThreadProcessId(shellWindow, &pid);
982 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
983 ret = TerminateProcess(hProcess, 0);
984 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
985 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
986 CloseHandle(hProcess);
989 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
990 trace("created window 1: %p\n", hwnd1);
992 ret = SetShellWindow(hwnd1);
993 ok(ret, "first call to SetShellWindow(hwnd1)\n");
994 shellWindow = GetShellWindow();
995 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
997 ret = SetShellWindow(hwnd1);
998 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1000 ret = SetShellWindow(0);
1001 error = GetLastError();
1002 /* passes on Win XP, but not on Win98
1003 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1004 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1006 ret = SetShellWindow(hwnd1);
1007 /* passes on Win XP, but not on Win98
1008 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1010 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1011 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
1012 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1014 ret = DestroyWindow(hwnd1);
1015 ok(ret, "DestroyWindow(hwnd1)\n");
1017 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1018 trace("created window 2: %p\n", hwnd2);
1019 ret = SetShellWindow(hwnd2);
1020 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1022 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1023 trace("created window 3: %p\n", hwnd3);
1025 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1026 trace("created window 4: %p\n", hwnd4);
1028 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1029 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1031 ret = SetShellWindow(hwnd4);
1032 ok(ret, "SetShellWindow(hwnd4)\n");
1033 shellWindow = GetShellWindow();
1034 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1036 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1037 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1039 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1040 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1042 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1043 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1045 ret = SetShellWindow(hwnd3);
1046 ok(!ret, "SetShellWindow(hwnd3)\n");
1047 shellWindow = GetShellWindow();
1048 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1050 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1051 trace("created window 5: %p\n", hwnd5);
1052 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1053 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1057 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1058 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1061 /* destroy test windows */
1062 DestroyWindow(hwnd2);
1063 DestroyWindow(hwnd3);
1064 DestroyWindow(hwnd4);
1065 DestroyWindow(hwnd5);
1068 /************** MDI test ****************/
1070 static char mdi_lParam_test_message[] = "just a test string";
1072 static void test_MDI_create(HWND parent, HWND mdi_client, INT first_id)
1074 MDICREATESTRUCTA mdi_cs;
1076 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1077 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1078 BOOL isWin9x = FALSE;
1080 mdi_cs.szClass = "MDI_child_Class_1";
1081 mdi_cs.szTitle = "MDI child";
1082 mdi_cs.hOwner = GetModuleHandle(0);
1083 mdi_cs.x = CW_USEDEFAULT;
1084 mdi_cs.y = CW_USEDEFAULT;
1085 mdi_cs.cx = CW_USEDEFAULT;
1086 mdi_cs.cy = CW_USEDEFAULT;
1088 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1089 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1090 ok(mdi_child != 0, "MDI child creation failed\n");
1091 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1092 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1093 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1095 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1096 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1097 ok(mdi_child != 0, "MDI child creation failed\n");
1098 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1099 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1100 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1102 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1103 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1104 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1106 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1110 ok(mdi_child != 0, "MDI child creation failed\n");
1111 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1112 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1113 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1116 /* test MDICREATESTRUCT A<->W mapping */
1117 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1119 mdi_cs.szClass = (LPCSTR)classW;
1120 mdi_cs.szTitle = (LPCSTR)titleW;
1121 SetLastError(0xdeadbeef);
1122 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1125 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1128 ok(mdi_child != 0, "MDI child creation failed\n");
1132 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1133 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1134 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1137 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
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 0x7fffffff, /* without WS_POPUP */
1150 CW_USEDEFAULT, CW_USEDEFAULT,
1151 CW_USEDEFAULT, CW_USEDEFAULT,
1152 mdi_client, GetModuleHandle(0),
1153 (LPARAM)mdi_lParam_test_message);
1154 ok(mdi_child != 0, "MDI child creation failed\n");
1155 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1156 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1157 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1159 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1160 0xffffffff, /* with WS_POPUP */
1161 CW_USEDEFAULT, CW_USEDEFAULT,
1162 CW_USEDEFAULT, CW_USEDEFAULT,
1163 mdi_client, GetModuleHandle(0),
1164 (LPARAM)mdi_lParam_test_message);
1165 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1167 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1171 ok(mdi_child != 0, "MDI child creation failed\n");
1172 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1173 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1174 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1177 /* test MDICREATESTRUCT A<->W mapping */
1178 SetLastError(0xdeadbeef);
1179 mdi_child = CreateMDIWindowW(classW, titleW,
1181 CW_USEDEFAULT, CW_USEDEFAULT,
1182 CW_USEDEFAULT, CW_USEDEFAULT,
1183 mdi_client, GetModuleHandle(0),
1184 (LPARAM)mdi_lParam_test_message);
1187 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1190 ok(mdi_child != 0, "MDI child creation failed\n");
1194 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1195 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1196 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1199 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
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 0x7fffffff, /* without 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 ok(mdi_child != 0, "MDI child creation failed\n");
1217 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1218 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1219 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1221 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1222 0xffffffff, /* with WS_POPUP */
1223 CW_USEDEFAULT, CW_USEDEFAULT,
1224 CW_USEDEFAULT, CW_USEDEFAULT,
1225 mdi_client, 0, GetModuleHandle(0),
1226 (LPVOID)mdi_lParam_test_message);
1227 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1229 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1233 ok(mdi_child != 0, "MDI child creation failed\n");
1234 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1235 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1236 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1239 /* test MDICREATESTRUCT A<->W mapping */
1240 SetLastError(0xdeadbeef);
1241 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1243 CW_USEDEFAULT, CW_USEDEFAULT,
1244 CW_USEDEFAULT, CW_USEDEFAULT,
1245 mdi_client, 0, GetModuleHandle(0),
1246 (LPVOID)mdi_lParam_test_message);
1249 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1252 ok(mdi_child != 0, "MDI child creation failed\n");
1256 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1257 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1258 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1261 /* This test fails on Win9x */
1264 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1266 CW_USEDEFAULT, CW_USEDEFAULT,
1267 CW_USEDEFAULT, CW_USEDEFAULT,
1268 parent, 0, GetModuleHandle(0),
1269 (LPVOID)mdi_lParam_test_message);
1270 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1273 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1274 WS_CHILD, /* without WS_POPUP */
1275 CW_USEDEFAULT, CW_USEDEFAULT,
1276 CW_USEDEFAULT, CW_USEDEFAULT,
1277 mdi_client, 0, GetModuleHandle(0),
1278 (LPVOID)mdi_lParam_test_message);
1279 ok(mdi_child != 0, "MDI child creation failed\n");
1280 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1281 DestroyWindow(mdi_child);
1283 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1284 WS_CHILD | WS_POPUP, /* with WS_POPUP */
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 /* maximized child */
1294 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1295 WS_CHILD | WS_MAXIMIZE,
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\n");
1305 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1306 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
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);
1315 trace("Creating maximized child with a caption and a thick frame\n");
1316 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1317 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1318 CW_USEDEFAULT, CW_USEDEFAULT,
1319 CW_USEDEFAULT, CW_USEDEFAULT,
1320 mdi_client, 0, GetModuleHandle(0),
1321 (LPVOID)mdi_lParam_test_message);
1322 ok(mdi_child != 0, "MDI child creation failed\n");
1323 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1324 DestroyWindow(mdi_child);
1327 /**********************************************************************
1328 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1330 * Note: The rule here is that client rect of the maximized MDI child
1331 * is equal to the client rect of the MDI client window.
1333 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1337 GetClientRect( client, &rect );
1338 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1339 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1341 rect.right -= rect.left;
1342 rect.bottom -= rect.top;
1343 lpMinMax->ptMaxSize.x = rect.right;
1344 lpMinMax->ptMaxSize.y = rect.bottom;
1346 lpMinMax->ptMaxPosition.x = rect.left;
1347 lpMinMax->ptMaxPosition.y = rect.top;
1349 trace("max rect (%d,%d - %d, %d)\n",
1350 rect.left, rect.top, rect.right, rect.bottom);
1353 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1360 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1361 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs->lpCreateParams;
1363 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1364 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1366 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1367 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1368 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1369 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1370 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1372 /* MDICREATESTRUCT should have original values */
1373 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1374 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1375 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1376 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1377 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1378 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1380 /* CREATESTRUCT should have fixed values */
1381 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1382 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1384 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1385 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1386 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1388 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1390 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1392 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1393 ok(cs->style == style,
1394 "cs->style does not match (%08x)\n", cs->style);
1398 LONG style = mdi_cs->style;
1400 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1401 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1402 ok(cs->style == style,
1403 "cs->style does not match (%08x)\n", cs->style);
1408 case WM_GETMINMAXINFO:
1410 HWND client = GetParent(hwnd);
1412 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1413 MINMAXINFO my_minmax;
1414 LONG style, exstyle;
1416 style = GetWindowLongA(hwnd, GWL_STYLE);
1417 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1419 GetWindowRect(client, &rc);
1420 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1421 GetClientRect(client, &rc);
1422 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1423 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1424 GetSystemMetrics(SM_CYSCREEN));
1426 GetClientRect(client, &rc);
1427 if ((style & WS_CAPTION) == WS_CAPTION)
1428 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1429 AdjustWindowRectEx(&rc, style, 0, exstyle);
1430 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1431 dump_minmax_info( minmax );
1433 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1434 minmax->ptMaxSize.x, rc.right - rc.left);
1435 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1436 minmax->ptMaxSize.y, rc.bottom - rc.top);
1438 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1440 trace("DefMDIChildProc returned:\n");
1441 dump_minmax_info( minmax );
1443 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1444 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1445 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1446 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1447 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1452 case WM_MDIACTIVATE:
1454 HWND active, client = GetParent(hwnd);
1455 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1456 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1457 if (hwnd == (HWND)lparam) /* if we are being activated */
1458 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1460 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1464 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1467 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1474 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1476 trace("%s\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE");
1477 trace("x %d, y %d, cx %d, cy %d\n", cs->x, cs->y, cs->cx, cs->cy);
1479 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1480 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1482 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1483 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1485 /* CREATESTRUCT should have fixed values */
1486 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1488 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1489 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1491 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1492 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1493 while Win95, Win2k, WinXP do. */
1494 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1495 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1499 case WM_GETMINMAXINFO:
1501 HWND parent = GetParent(hwnd);
1503 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1504 LONG style, exstyle;
1506 trace("WM_GETMINMAXINFO\n");
1508 style = GetWindowLongA(hwnd, GWL_STYLE);
1509 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1511 GetClientRect(parent, &rc);
1512 trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1514 GetClientRect(parent, &rc);
1515 if ((style & WS_CAPTION) == WS_CAPTION)
1516 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1517 AdjustWindowRectEx(&rc, style, 0, exstyle);
1518 trace("calculated max child window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1519 dump_minmax_info( minmax );
1521 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1522 minmax->ptMaxSize.x, rc.right - rc.left);
1523 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1524 minmax->ptMaxSize.y, rc.bottom - rc.top);
1528 case WM_WINDOWPOSCHANGED:
1530 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1533 GetWindowRect(hwnd, &rc1);
1534 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1535 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1536 /* note: winpos coordinates are relative to parent */
1537 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1538 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1539 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1541 GetWindowRect(hwnd, &rc1);
1542 GetClientRect(hwnd, &rc2);
1543 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1544 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1545 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1548 case WM_WINDOWPOSCHANGING:
1550 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1551 WINDOWPOS my_winpos = *winpos;
1553 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1554 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1555 winpos->hwnd, winpos->hwndInsertAfter,
1556 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1558 DefWindowProcA(hwnd, msg, wparam, lparam);
1560 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1561 winpos->hwnd, winpos->hwndInsertAfter,
1562 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1564 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1565 "DefWindowProc should not change WINDOWPOS values\n");
1570 return DefWindowProcA(hwnd, msg, wparam, lparam);
1573 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1575 static HWND mdi_client;
1581 CLIENTCREATESTRUCT client_cs;
1584 GetClientRect(hwnd, &rc);
1586 client_cs.hWindowMenu = 0;
1587 client_cs.idFirstChild = 1;
1589 /* MDIClient without MDIS_ALLCHILDSTYLES */
1590 mdi_client = CreateWindowExA(0, "mdiclient",
1592 WS_CHILD /*| WS_VISIBLE*/,
1593 /* tests depend on a not zero MDIClient size */
1594 0, 0, rc.right, rc.bottom,
1595 hwnd, 0, GetModuleHandle(0),
1596 (LPVOID)&client_cs);
1598 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1599 DestroyWindow(mdi_client);
1601 /* MDIClient with MDIS_ALLCHILDSTYLES */
1602 mdi_client = CreateWindowExA(0, "mdiclient",
1604 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1605 /* tests depend on a not zero MDIClient size */
1606 0, 0, rc.right, rc.bottom,
1607 hwnd, 0, GetModuleHandle(0),
1608 (LPVOID)&client_cs);
1610 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1611 DestroyWindow(mdi_client);
1615 case WM_WINDOWPOSCHANGED:
1617 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1620 GetWindowRect(hwnd, &rc1);
1621 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1622 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1623 /* note: winpos coordinates are relative to parent */
1624 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1625 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1626 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1628 GetWindowRect(hwnd, &rc1);
1629 GetClientRect(hwnd, &rc2);
1630 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1631 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1632 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1635 case WM_WINDOWPOSCHANGING:
1637 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1638 WINDOWPOS my_winpos = *winpos;
1640 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1641 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1642 winpos->hwnd, winpos->hwndInsertAfter,
1643 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1645 DefWindowProcA(hwnd, msg, wparam, lparam);
1647 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1648 winpos->hwnd, winpos->hwndInsertAfter,
1649 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1651 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1652 "DefWindowProc should not change WINDOWPOS values\n");
1661 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1664 static BOOL mdi_RegisterWindowClasses(void)
1669 cls.lpfnWndProc = mdi_main_wnd_procA;
1672 cls.hInstance = GetModuleHandleA(0);
1674 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1675 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1676 cls.lpszMenuName = NULL;
1677 cls.lpszClassName = "MDI_parent_Class";
1678 if(!RegisterClassA(&cls)) return FALSE;
1680 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1681 cls.lpszClassName = "MDI_child_Class_1";
1682 if(!RegisterClassA(&cls)) return FALSE;
1684 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1685 cls.lpszClassName = "MDI_child_Class_2";
1686 if(!RegisterClassA(&cls)) return FALSE;
1691 static void test_mdi(void)
1696 if (!mdi_RegisterWindowClasses()) assert(0);
1698 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1699 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1700 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1701 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1702 GetDesktopWindow(), 0,
1703 GetModuleHandle(0), NULL);
1704 assert(mdi_hwndMain);
1706 while(GetMessage(&msg, 0, 0, 0))
1708 TranslateMessage(&msg);
1709 DispatchMessage(&msg);
1712 DestroyWindow(mdi_hwndMain);
1715 static void test_icons(void)
1719 HICON icon = LoadIconA(0, (LPSTR)IDI_APPLICATION);
1720 HICON icon2 = LoadIconA(0, (LPSTR)IDI_QUESTION);
1721 HICON small_icon = LoadImageA(0, (LPSTR)IDI_APPLICATION, IMAGE_ICON,
1722 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1725 cls.cbSize = sizeof(cls);
1727 cls.lpfnWndProc = DefWindowProcA;
1731 cls.hIcon = LoadIconA(0, (LPSTR)IDI_HAND);
1732 cls.hIconSm = small_icon;
1733 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1734 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1735 cls.lpszMenuName = NULL;
1736 cls.lpszClassName = "IconWindowClass";
1738 RegisterClassExA(&cls);
1740 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1741 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1744 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1745 ok( res == 0, "wrong big icon %p/0\n", res );
1746 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1747 ok( res == 0, "wrong previous big icon %p/0\n", res );
1748 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1749 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1750 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1751 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1752 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1753 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1755 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1756 ok( res == 0, "wrong small icon %p/0\n", res );
1757 /* this test is XP specific */
1758 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1759 ok( res != 0, "wrong small icon %p\n", res );*/
1760 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1761 ok( res == 0, "wrong previous small icon %p/0\n", res );
1762 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1763 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1764 /* this test is XP specific */
1765 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1766 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1767 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1768 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1769 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1770 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1771 /* this test is XP specific */
1772 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1773 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1775 /* make sure the big icon hasn't changed */
1776 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1777 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1779 DestroyWindow( hwnd );
1782 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1784 if (msg == WM_NCCALCSIZE)
1786 RECT *rect = (RECT *)lparam;
1787 /* first time around increase the rectangle, next time decrease it */
1788 if (rect->left == 100) InflateRect( rect, 10, 10 );
1789 else InflateRect( rect, -10, -10 );
1792 return DefWindowProc( hwnd, msg, wparam, lparam );
1795 static void test_SetWindowPos(HWND hwnd)
1797 RECT orig_win_rc, rect;
1799 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1801 SetRect(&rect, 111, 222, 333, 444);
1802 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1803 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1804 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1806 SetRect(&rect, 111, 222, 333, 444);
1807 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1808 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1809 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1811 GetWindowRect(hwnd, &orig_win_rc);
1813 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1814 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1815 GetWindowRect( hwnd, &rect );
1816 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1817 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1818 GetClientRect( hwnd, &rect );
1819 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1820 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1821 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1823 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1824 GetWindowRect( hwnd, &rect );
1825 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1826 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1827 GetClientRect( hwnd, &rect );
1828 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1829 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1830 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1832 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1833 orig_win_rc.right, orig_win_rc.bottom, 0);
1834 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1836 /* Win9x truncates coordinates to 16-bit irrespectively */
1839 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1840 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1842 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1843 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1846 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1847 orig_win_rc.right, orig_win_rc.bottom, 0);
1849 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1850 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1851 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1852 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1853 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1854 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1855 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1858 static void test_SetMenu(HWND parent)
1862 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1866 hMenu = CreateMenu();
1869 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1872 /* fails on (at least) Wine, NT4, XP SP2 */
1873 test_nonclient_area(parent);
1875 ret = GetMenu(parent);
1876 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1877 /* test whether we can destroy a menu assigned to a window */
1878 retok = DestroyMenu(hMenu);
1879 ok( retok, "DestroyMenu error %d\n", GetLastError());
1880 ok(!IsMenu(hMenu), "menu handle should be not valid after DestroyMenu\n");
1881 ret = GetMenu(parent);
1882 /* This test fails on Win9x */
1884 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1885 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1886 test_nonclient_area(parent);
1888 hMenu = CreateMenu();
1892 ret = GetMenu(parent);
1893 ok(ret == 0, "unexpected menu id %p\n", ret);
1895 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1896 test_nonclient_area(parent);
1897 ret = GetMenu(parent);
1898 ok(ret == 0, "unexpected menu id %p\n", ret);
1900 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1903 /* fails on (at least) Wine, NT4, XP SP2 */
1904 test_nonclient_area(parent);
1906 ret = GetMenu(parent);
1907 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1909 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1910 test_nonclient_area(parent);
1911 ret = GetMenu(parent);
1912 ok(ret == 0, "unexpected menu id %p\n", ret);
1915 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1918 ret = GetMenu(child);
1919 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1921 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1922 test_nonclient_area(child);
1923 ret = GetMenu(child);
1924 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1926 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1927 test_nonclient_area(child);
1928 ret = GetMenu(child);
1929 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1931 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1932 test_nonclient_area(child);
1933 ret = GetMenu(child);
1934 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1936 style = GetWindowLong(child, GWL_STYLE);
1937 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
1938 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
1939 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
1940 SetWindowLong(child, GWL_STYLE, style);
1942 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
1943 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
1944 SetWindowLong(child, GWL_STYLE, style);
1946 DestroyWindow(child);
1950 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1952 HWND child[5], hwnd;
1957 hwnd = GetWindow(parent, GW_CHILD);
1958 ok(!hwnd, "have to start without children to perform the test\n");
1960 for (i = 0; i < total; i++)
1962 if (style[i] & DS_CONTROL)
1964 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
1965 0,0,0,0, parent, (HMENU)i, 0, NULL);
1966 if (style[i] & WS_VISIBLE)
1967 ShowWindow(child[i], SW_SHOW);
1969 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
1972 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
1973 parent, (HMENU)i, 0, NULL);
1974 trace("child[%d] = %p\n", i, child[i]);
1975 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
1978 hwnd = GetWindow(parent, GW_CHILD);
1979 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
1980 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
1981 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
1983 for (i = 0; i < total; i++)
1985 trace("hwnd[%d] = %p\n", i, hwnd);
1986 ok(child[order[i]] == hwnd, "Z order of child #%d is wrong\n", i);
1988 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1991 for (i = 0; i < total; i++)
1992 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
1995 static void test_children_zorder(HWND parent)
1997 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
1999 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2001 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2002 WS_CHILD | WS_VISIBLE, WS_CHILD,
2003 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2004 const int complex_order_1[1] = { 0 };
2005 const int complex_order_2[2] = { 1, 0 };
2006 const int complex_order_3[3] = { 1, 0, 2 };
2007 const int complex_order_4[4] = { 1, 0, 2, 3 };
2008 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2009 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2010 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2011 WS_CHILD | WS_VISIBLE };
2012 const int complex_order_6[3] = { 0, 1, 2 };
2014 /* simple WS_CHILD */
2015 test_window_tree(parent, simple_style, simple_order, 5);
2017 /* complex children styles */
2018 test_window_tree(parent, complex_style, complex_order_1, 1);
2019 test_window_tree(parent, complex_style, complex_order_2, 2);
2020 test_window_tree(parent, complex_style, complex_order_3, 3);
2021 test_window_tree(parent, complex_style, complex_order_4, 4);
2022 test_window_tree(parent, complex_style, complex_order_5, 5);
2024 /* another set of complex children styles */
2025 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2028 #define check_z_order(hwnd, next, prev, owner, topmost) \
2029 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2032 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2033 BOOL topmost, const char *file, int line)
2038 test = GetWindow(hwnd, GW_HWNDNEXT);
2039 /* skip foreign windows */
2040 while (test && (GetWindowThreadProcessId(test, NULL) != our_pid ||
2041 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0)))
2043 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2044 test = GetWindow(test, GW_HWNDNEXT);
2046 ok_(file, line)(next == test, "expected next %p, got %p\n", next, test);
2048 test = GetWindow(hwnd, GW_HWNDPREV);
2049 /* skip foreign windows */
2050 while (test && (GetWindowThreadProcessId(test, NULL) != our_pid ||
2051 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0)))
2053 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2054 test = GetWindow(test, GW_HWNDPREV);
2056 ok_(file, line)(prev == test, "expected prev %p, got %p\n", prev, test);
2058 test = GetWindow(hwnd, GW_OWNER);
2059 ok_(file, line)(owner == test, "expected owner %p, got %p\n", owner, test);
2061 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2062 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "expected %stopmost\n", topmost ? "" : "NOT ");
2065 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E)
2067 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2069 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2071 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2073 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2074 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2076 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2077 WS_OVERLAPPED | WS_CAPTION,
2079 0, 0, GetModuleHandle(0), NULL);
2080 trace("hwnd_F %p\n", hwnd_F);
2081 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2083 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2084 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2085 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2086 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2088 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2091 hwnd_F, 0, GetModuleHandle(0), NULL);
2092 trace("hwnd_C %p\n", hwnd_C);
2093 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2094 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2095 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2096 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2098 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2101 hwnd_F, 0, GetModuleHandle(0), NULL);
2102 trace("hwnd_B %p\n", hwnd_B);
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, 0, hwnd_F, TRUE);
2109 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2112 0, 0, GetModuleHandle(0), NULL);
2113 trace("hwnd_A %p\n", hwnd_A);
2114 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2115 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2116 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2117 check_z_order(hwnd_C, hwnd_D, 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 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);
2123 /* move hwnd_F and its popups up */
2124 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2125 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2126 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2127 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2128 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2129 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2130 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2132 /* move hwnd_F and its popups down */
2133 #if 0 /* enable once Wine is fixed to pass this test */
2134 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2135 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2136 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2137 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2138 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2139 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2140 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2143 DestroyWindow(hwnd_A);
2144 DestroyWindow(hwnd_B);
2145 DestroyWindow(hwnd_C);
2146 DestroyWindow(hwnd_F);
2149 static void test_vis_rgn( HWND hwnd )
2151 RECT win_rect, rgn_rect;
2152 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2155 ShowWindow(hwnd,SW_SHOW);
2156 hdc = GetDC( hwnd );
2157 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2158 GetWindowRect( hwnd, &win_rect );
2159 GetRgnBox( hrgn, &rgn_rect );
2160 if (GetVersion() & 0x80000000)
2162 trace("win9x, mapping to screen coords\n");
2163 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2165 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2166 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2167 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2168 rgn_rect.left, win_rect.left );
2169 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2170 rgn_rect.top, win_rect.top );
2171 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2172 rgn_rect.right, win_rect.right );
2173 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2174 rgn_rect.bottom, win_rect.bottom );
2175 ReleaseDC( hwnd, hdc );
2178 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2180 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2182 HWND child = GetWindow(hwnd, GW_CHILD);
2183 ok(child != 0, "couldn't find child window\n");
2185 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2188 return DefWindowProc(hwnd, msg, wp, lp);
2191 static void test_SetFocus(HWND hwnd)
2194 WNDPROC old_wnd_proc;
2196 /* check if we can set focus to non-visible windows */
2198 ShowWindow(hwnd, SW_SHOW);
2201 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2202 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2203 ShowWindow(hwnd, SW_HIDE);
2206 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2207 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2208 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2211 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2212 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2213 ShowWindow(child, SW_SHOW);
2214 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2215 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2216 ShowWindow(child, SW_HIDE);
2217 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2218 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2219 ShowWindow(child, SW_SHOW);
2221 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2222 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2223 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2225 ShowWindow(child, SW_HIDE);
2227 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2228 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2229 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2230 ShowWindow(child, SW_HIDE);
2231 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2233 ShowWindow(hwnd, SW_SHOW);
2234 ShowWindow(child, SW_SHOW);
2236 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2237 EnableWindow(hwnd, FALSE);
2238 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2239 EnableWindow(hwnd, TRUE);
2241 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2242 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2243 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2245 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2246 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2247 ShowWindow(hwnd, SW_RESTORE);
2248 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2249 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2250 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2251 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2252 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2254 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2255 old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2256 ShowWindow(hwnd, SW_RESTORE);
2257 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2259 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2261 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2263 DestroyWindow( child );
2266 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
2267 static void check_wnd_state_(const char *file, int line,
2268 HWND active, HWND foreground, HWND focus, HWND capture)
2270 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2272 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2273 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2274 ok_(file, line)(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2277 static void test_SetActiveWindow(HWND hwnd)
2281 flush_events( TRUE );
2282 ShowWindow(hwnd, SW_HIDE);
2285 check_wnd_state(0, 0, 0, 0);
2287 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2289 ShowWindow(hwnd, SW_SHOW);
2290 check_wnd_state(hwnd, hwnd, hwnd, 0);
2292 hwnd2 = SetActiveWindow(0);
2293 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2294 check_wnd_state(0, 0, 0, 0);
2296 hwnd2 = SetActiveWindow(hwnd);
2297 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2298 check_wnd_state(hwnd, hwnd, hwnd, 0);
2300 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2301 check_wnd_state(hwnd, hwnd, hwnd, 0);
2303 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2304 check_wnd_state(hwnd, hwnd, hwnd, 0);
2306 ShowWindow(hwnd, SW_HIDE);
2307 check_wnd_state(0, 0, 0, 0);
2309 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2310 SetActiveWindow(hwnd);
2311 check_wnd_state(hwnd, hwnd, hwnd, 0);
2313 ShowWindow(hwnd, SW_SHOW);
2314 check_wnd_state(hwnd, hwnd, hwnd, 0);
2316 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2317 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2319 DestroyWindow(hwnd2);
2320 check_wnd_state(hwnd, hwnd, hwnd, 0);
2322 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2323 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2325 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2326 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2328 DestroyWindow(hwnd2);
2329 check_wnd_state(hwnd, hwnd, hwnd, 0);
2332 static void test_SetForegroundWindow(HWND hwnd)
2337 flush_events( TRUE );
2338 ShowWindow(hwnd, SW_HIDE);
2341 check_wnd_state(0, 0, 0, 0);
2343 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2345 ShowWindow(hwnd, SW_SHOW);
2346 check_wnd_state(hwnd, hwnd, hwnd, 0);
2348 hwnd2 = SetActiveWindow(0);
2349 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2350 check_wnd_state(0, 0, 0, 0);
2352 ret = SetForegroundWindow(hwnd);
2353 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2354 check_wnd_state(hwnd, hwnd, hwnd, 0);
2356 SetLastError(0xdeadbeef);
2357 ret = SetForegroundWindow(0);
2358 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2359 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2360 check_wnd_state(hwnd, hwnd, hwnd, 0);
2362 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2363 check_wnd_state(hwnd, hwnd, hwnd, 0);
2365 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2366 check_wnd_state(hwnd, hwnd, hwnd, 0);
2368 hwnd2 = GetForegroundWindow();
2369 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2370 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2371 hwnd2 = GetForegroundWindow();
2372 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2374 ShowWindow(hwnd, SW_HIDE);
2375 check_wnd_state(0, 0, 0, 0);
2377 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2378 ret = SetForegroundWindow(hwnd);
2379 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2380 check_wnd_state(hwnd, hwnd, hwnd, 0);
2382 ShowWindow(hwnd, SW_SHOW);
2383 check_wnd_state(hwnd, hwnd, hwnd, 0);
2385 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2386 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2388 DestroyWindow(hwnd2);
2389 check_wnd_state(hwnd, hwnd, hwnd, 0);
2391 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2392 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2394 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2395 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2397 DestroyWindow(hwnd2);
2398 check_wnd_state(hwnd, hwnd, hwnd, 0);
2401 static WNDPROC old_button_proc;
2403 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2408 key_state = GetKeyState(VK_LBUTTON);
2409 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2411 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2413 if (msg == WM_LBUTTONDOWN)
2417 check_wnd_state(button, button, button, button);
2419 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2421 trace("hwnd %p\n", hwnd);
2423 check_wnd_state(button, button, button, button);
2425 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2427 check_wnd_state(button, button, button, button);
2429 DestroyWindow(hwnd);
2431 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2433 trace("hwnd %p\n", hwnd);
2435 check_wnd_state(button, button, button, button);
2437 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2438 * match internal button state.
2440 SendMessage(button, WM_KILLFOCUS, 0, 0);
2441 check_wnd_state(button, button, button, 0);
2443 ShowWindow(hwnd, SW_SHOW);
2444 check_wnd_state(hwnd, hwnd, hwnd, 0);
2446 capture = SetCapture(hwnd);
2447 ok(capture == 0, "SetCapture() = %p\n", capture);
2449 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2451 DestroyWindow(hwnd);
2453 check_wnd_state(button, 0, button, 0);
2459 static void test_capture_1(void)
2461 HWND button, capture, oldFocus, oldActive;
2463 oldFocus = GetFocus();
2464 oldActive = GetActiveWindow();
2466 capture = GetCapture();
2467 ok(capture == 0, "GetCapture() = %p\n", capture);
2469 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2471 trace("button %p\n", button);
2473 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2475 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2477 capture = SetCapture(button);
2478 ok(capture == 0, "SetCapture() = %p\n", capture);
2479 check_wnd_state(button, 0, button, button);
2481 DestroyWindow(button);
2482 check_wnd_state(oldActive, 0, oldFocus, 0);
2485 static void test_capture_2(void)
2487 HWND button, hwnd, capture, oldFocus, oldActive;
2489 oldFocus = GetFocus();
2490 oldActive = GetActiveWindow();
2491 check_wnd_state(oldActive, 0, oldFocus, 0);
2493 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2495 trace("button %p\n", button);
2497 check_wnd_state(button, button, button, 0);
2499 capture = SetCapture(button);
2500 ok(capture == 0, "SetCapture() = %p\n", capture);
2502 check_wnd_state(button, button, button, button);
2504 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2505 * internal button state.
2507 SendMessage(button, WM_KILLFOCUS, 0, 0);
2508 check_wnd_state(button, button, button, button);
2510 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2512 trace("hwnd %p\n", hwnd);
2514 check_wnd_state(button, button, button, button);
2516 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2518 check_wnd_state(button, button, button, button);
2520 DestroyWindow(hwnd);
2522 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2524 trace("hwnd %p\n", hwnd);
2526 check_wnd_state(button, button, button, button);
2528 ShowWindow(hwnd, SW_SHOW);
2530 check_wnd_state(hwnd, hwnd, hwnd, button);
2532 capture = SetCapture(hwnd);
2533 ok(capture == button, "SetCapture() = %p\n", capture);
2535 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2537 DestroyWindow(hwnd);
2538 check_wnd_state(button, button, button, 0);
2540 DestroyWindow(button);
2541 check_wnd_state(oldActive, 0, oldFocus, 0);
2544 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2548 ShowWindow(hwnd1, SW_HIDE);
2549 ShowWindow(hwnd2, SW_HIDE);
2551 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2552 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2555 check_wnd_state(0, 0, 0, hwnd1);
2558 check_wnd_state(0, 0, 0, hwnd2);
2560 ShowWindow(hwnd1, SW_SHOW);
2561 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2563 ret = ReleaseCapture();
2564 ok (ret, "releasecapture did not return TRUE.\n");
2565 ret = ReleaseCapture();
2566 ok (ret, "releasecapture did not return TRUE after second try.\n");
2569 static void test_keyboard_input(HWND hwnd)
2574 flush_events( TRUE );
2575 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
2577 flush_events( TRUE );
2579 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2582 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2584 flush_events( TRUE );
2586 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2587 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2588 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2589 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2590 ok( !ret, "message %04x available\n", msg.message);
2592 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2594 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2595 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2596 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2597 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2598 ok( !ret, "message %04x available\n", msg.message);
2600 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2602 keybd_event(VK_SPACE, 0, 0, 0);
2603 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2604 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2605 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2606 ok( !ret, "message %04x available\n", msg.message);
2609 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2611 flush_events( TRUE );
2613 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2614 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2615 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2616 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2617 ok( !ret, "message %04x available\n", msg.message);
2619 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2621 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2622 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2623 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2624 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2625 ok( !ret, "message %04x available\n", msg.message);
2627 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2629 keybd_event(VK_SPACE, 0, 0, 0);
2630 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2631 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2632 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2633 ok( !ret, "message %04x available\n", msg.message);
2636 static void test_mouse_input(HWND hwnd)
2646 ShowWindow(hwnd, SW_SHOW);
2649 GetWindowRect(hwnd, &rc);
2650 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2652 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2653 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2656 ShowWindow(popup, SW_SHOW);
2657 UpdateWindow(popup);
2659 GetWindowRect(popup, &rc);
2660 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2662 x = rc.left + (rc.right - rc.left) / 2;
2663 y = rc.top + (rc.bottom - rc.top) / 2;
2664 trace("setting cursor to (%d,%d)\n", x, y);
2668 ok(x == pt.x && y == pt.y, "wrong cursor pos (%d,%d), expected (%d,%d)\n", pt.x, pt.y, x, y);
2670 flush_events( TRUE );
2672 /* Check that setting the same position will generate WM_MOUSEMOVE */
2675 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2676 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2677 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);
2679 /* force the system to update its internal queue mouse position,
2680 * otherwise it won't generate relative mouse movements below.
2682 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2683 flush_events( TRUE );
2686 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2687 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2688 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2689 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2690 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2691 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2692 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2693 ok( !ret, "message %04x available\n", msg.message);
2695 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2696 ShowWindow(popup, SW_HIDE);
2698 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2699 while (msg.message >= 0xc000); /* skip registered messages */
2700 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2701 flush_events( TRUE );
2703 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2704 ShowWindow(hwnd, SW_HIDE);
2706 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2707 while (ret && msg.message >= 0xc000); /* skip registered messages */
2708 ok( !ret, "message %04x available\n", msg.message);
2709 flush_events( TRUE );
2711 /* test mouse clicks */
2713 ShowWindow(hwnd, SW_SHOW);
2714 flush_events( TRUE );
2715 ShowWindow(popup, SW_SHOW);
2716 flush_events( TRUE );
2718 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2719 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2720 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2721 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2723 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2724 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2725 msg.hwnd, popup, msg.message);
2726 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2727 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2728 msg.hwnd, popup, msg.message);
2730 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2731 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2732 msg.hwnd, popup, msg.message);
2733 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2734 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2735 msg.hwnd, popup, msg.message);
2737 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2738 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
2739 msg.hwnd, popup, msg.message);
2740 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2741 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
2742 msg.hwnd, popup, msg.message);
2744 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2745 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2746 msg.hwnd, popup, msg.message);
2747 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2748 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2749 msg.hwnd, popup, msg.message);
2751 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2752 ok(!ret, "message %04x available\n", msg.message);
2754 ShowWindow(popup, SW_HIDE);
2755 flush_events( TRUE );
2757 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2758 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2759 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2760 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2762 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2763 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2764 msg.hwnd, hwnd, msg.message);
2765 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2766 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2767 msg.hwnd, hwnd, msg.message);
2769 test_lbuttondown_flag = TRUE;
2770 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
2771 test_lbuttondown_flag = FALSE;
2774 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2775 while (msg.message >= 0xc000); /* skip registered messages */
2776 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2777 msg.hwnd, popup, msg.message);
2778 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2779 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2780 msg.hwnd, popup, msg.message);
2781 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2783 /* Test WM_MOUSEACTIVATE */
2784 #define TEST_MOUSEACTIVATE(A,B) \
2785 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2786 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2788 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
2789 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
2790 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
2791 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
2792 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
2793 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
2794 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
2795 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
2796 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
2797 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
2798 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
2799 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
2800 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
2801 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
2802 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
2803 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
2804 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
2805 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
2806 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
2807 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
2808 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
2809 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
2810 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
2811 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
2813 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2814 flush_events( TRUE );
2816 DestroyWindow(popup);
2819 static void test_validatergn(HWND hwnd)
2825 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
2826 ShowWindow(hwnd, SW_SHOW);
2827 UpdateWindow( hwnd);
2828 /* test that ValidateRect validates children*/
2829 InvalidateRect( child, NULL, 1);
2830 GetWindowRect( child, &rc);
2831 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2832 ret = GetUpdateRect( child, &rc2, 0);
2833 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
2834 "Update rectangle is empty!\n");
2835 ValidateRect( hwnd, &rc);
2836 ret = GetUpdateRect( child, &rc2, 0);
2837 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2838 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2839 rc2.right, rc2.bottom);
2841 /* now test ValidateRgn */
2842 InvalidateRect( child, NULL, 1);
2843 GetWindowRect( child, &rc);
2844 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2845 rgn = CreateRectRgnIndirect( &rc);
2846 ValidateRgn( hwnd, rgn);
2847 ret = GetUpdateRect( child, &rc2, 0);
2848 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2849 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2850 rc2.right, rc2.bottom);
2853 DestroyWindow( child );
2856 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
2858 MoveWindow( hwnd, 0, 0, x, y, 0);
2859 GetWindowRect( hwnd, prc);
2860 trace("window rect is %d,%d - %d,%d\n",
2861 prc->left,prc->top,prc->right,prc->bottom);
2862 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
2863 trace("nccalc rect is %d,%d - %d,%d\n",
2864 prc->left,prc->top,prc->right,prc->bottom);
2867 static void test_nccalcscroll(HWND parent)
2870 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
2871 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
2872 HWND hwnd = CreateWindowExA(0, "static", NULL,
2873 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
2874 10, 10, 200, 200, parent, 0, 0, NULL);
2875 ShowWindow( parent, SW_SHOW);
2876 UpdateWindow( parent);
2878 /* test window too low for a horizontal scroll bar */
2879 nccalchelper( hwnd, 100, sbheight, &rc1);
2880 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
2881 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
2883 /* test window just high enough for a horizontal scroll bar */
2884 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
2885 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
2886 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2888 /* test window too narrow for a vertical scroll bar */
2889 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
2890 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
2891 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2893 /* test window just wide enough for a vertical scroll bar */
2894 nccalchelper( hwnd, sbwidth, 100, &rc1);
2895 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
2896 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
2898 /* same test, but with client edge: not enough width */
2899 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
2900 nccalchelper( hwnd, sbwidth, 100, &rc1);
2901 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
2902 "Width should be %d size is %d,%d - %d,%d\n",
2903 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
2905 DestroyWindow( hwnd);
2908 static void test_SetParent(void)
2911 HWND desktop = GetDesktopWindow();
2913 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
2914 HWND parent, child1, child2, child3, child4, sibling;
2916 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2917 100, 100, 200, 200, 0, 0, 0, NULL);
2918 assert(parent != 0);
2919 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2920 0, 0, 50, 50, parent, 0, 0, NULL);
2921 assert(child1 != 0);
2922 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2923 0, 0, 50, 50, child1, 0, 0, NULL);
2924 assert(child2 != 0);
2925 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2926 0, 0, 50, 50, child2, 0, 0, NULL);
2927 assert(child3 != 0);
2928 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2929 0, 0, 50, 50, child3, 0, 0, NULL);
2930 assert(child4 != 0);
2932 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2933 parent, child1, child2, child3, child4);
2935 check_parents(parent, desktop, 0, 0, 0, parent, parent);
2936 check_parents(child1, parent, parent, parent, 0, parent, parent);
2937 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2938 check_parents(child3, child2, child2, child2, 0, child2, parent);
2939 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2941 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
2942 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
2943 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2944 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
2945 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2947 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
2948 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2949 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
2950 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
2951 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
2952 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
2953 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
2954 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
2955 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2957 if (!is_win9x) /* Win9x doesn't survive this test */
2959 ok(!SetParent(parent, child1), "SetParent should fail\n");
2960 ok(!SetParent(child2, child3), "SetParent should fail\n");
2961 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
2962 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
2963 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
2964 ok(!SetParent(child2, parent), "SetParent should fail\n");
2965 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
2967 check_parents(parent, child4, child4, 0, 0, child4, parent);
2968 check_parents(child1, parent, parent, parent, 0, child4, parent);
2969 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2970 check_parents(child3, child2, child2, child2, 0, child2, parent);
2971 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2974 hMenu = CreateMenu();
2975 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2976 100, 100, 200, 200, 0, hMenu, 0, NULL);
2977 assert(sibling != 0);
2979 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
2980 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
2982 ret = DestroyWindow(parent);
2983 ok( ret, "DestroyWindow() error %d\n", GetLastError());
2985 ok(!IsWindow(parent), "parent still exists\n");
2986 ok(!IsWindow(sibling), "sibling still exists\n");
2987 ok(!IsWindow(child1), "child1 still exists\n");
2988 ok(!IsWindow(child2), "child2 still exists\n");
2989 ok(!IsWindow(child3), "child3 still exists\n");
2990 ok(!IsWindow(child4), "child4 still exists\n");
2993 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2995 LPCREATESTRUCT lpcs;
3002 lpcs = (LPCREATESTRUCT)lparam;
3003 lpss = (LPSTYLESTRUCT)lpcs->lpCreateParams;
3006 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
3007 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
3008 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
3009 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
3011 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3013 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
3014 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
3015 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
3017 ok(lpss->styleNew == lpcs->style,
3018 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3019 lpss->styleNew, lpcs->style);
3023 return DefWindowProc(hwnd, msg, wparam, lparam);
3026 static ATOM atomStyleCheckClass;
3028 static void register_style_check_class(void)
3036 GetModuleHandle(NULL),
3038 LoadCursor(NULL, IDC_ARROW),
3039 (HBRUSH)(COLOR_BTNFACE+1),
3041 TEXT("WineStyleCheck"),
3044 atomStyleCheckClass = RegisterClass(&wc);
3047 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3049 DWORD dwActualStyle;
3050 DWORD dwActualExStyle;
3053 HWND hwndParent = NULL;
3055 ss.styleNew = dwStyleIn;
3056 ss.styleOld = dwExStyleIn;
3058 if (dwStyleIn & WS_CHILD)
3060 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
3061 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3064 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
3065 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3068 flush_events( TRUE );
3070 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3071 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3072 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3073 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3074 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3076 DestroyWindow(hwnd);
3077 if (hwndParent) DestroyWindow(hwndParent);
3080 /* tests what window styles the window manager automatically adds */
3081 static void test_window_styles(void)
3083 register_style_check_class();
3085 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3086 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3087 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3088 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3089 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3090 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3091 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3092 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3093 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3094 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3095 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3098 static void test_scrollvalidate( HWND parent)
3101 HRGN hrgn=CreateRectRgn(0,0,0,0);
3102 HRGN exprgn, tmprgn, clipping;
3103 RECT rc, rcu, cliprc;
3104 /* create two overlapping child windows. The visual region
3105 * of hwnd1 is clipped by the overlapping part of
3106 * hwnd2 because of the WS_CLIPSIBLING style */
3109 clipping = CreateRectRgn(0,0,0,0);
3110 tmprgn = CreateRectRgn(0,0,0,0);
3111 exprgn = CreateRectRgn(0,0,0,0);
3112 hwnd2 = CreateWindowExA(0, "static", NULL,
3113 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3114 75, 30, 100, 100, parent, 0, 0, NULL);
3115 hwnd1 = CreateWindowExA(0, "static", NULL,
3116 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3117 25, 50, 100, 100, parent, 0, 0, NULL);
3118 ShowWindow( parent, SW_SHOW);
3119 UpdateWindow( parent);
3120 GetClientRect( hwnd1, &rc);
3122 SetRectRgn( clipping, 10, 10, 90, 90);
3123 hdc = GetDC( hwnd1);
3124 /* for a visual touch */
3125 TextOut( hdc, 0,10, "0123456789", 10);
3126 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3127 if (winetest_debug > 0) dump_region(hrgn);
3128 /* create a region with what is expected */
3129 SetRectRgn( exprgn, 39,0,49,74);
3130 SetRectRgn( tmprgn, 88,79,98,93);
3131 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3132 SetRectRgn( tmprgn, 0,93,98,98);
3133 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3134 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3135 trace("update rect is %d,%d - %d,%d\n",
3136 rcu.left,rcu.top,rcu.right,rcu.bottom);
3137 /* now with clipping region */
3138 SelectClipRgn( hdc, clipping);
3139 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3140 if (winetest_debug > 0) dump_region(hrgn);
3141 /* create a region with what is expected */
3142 SetRectRgn( exprgn, 39,10,49,74);
3143 SetRectRgn( tmprgn, 80,79,90,85);
3144 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3145 SetRectRgn( tmprgn, 10,85,90,90);
3146 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3147 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3148 trace("update rect is %d,%d - %d,%d\n",
3149 rcu.left,rcu.top,rcu.right,rcu.bottom);
3150 ReleaseDC( hwnd1, hdc);
3152 /* test scrolling a window with an update region */
3153 DestroyWindow( hwnd2);
3154 ValidateRect( hwnd1, NULL);
3155 SetRect( &rc, 40,40, 50,50);
3156 InvalidateRect( hwnd1, &rc, 1);
3157 GetClientRect( hwnd1, &rc);
3159 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
3160 SW_SCROLLCHILDREN | SW_INVALIDATE);
3161 if (winetest_debug > 0) dump_region(hrgn);
3162 SetRectRgn( exprgn, 88,0,98,98);
3163 SetRectRgn( tmprgn, 30, 40, 50, 50);
3164 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3165 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3167 /* clear an update region */
3168 UpdateWindow( hwnd1 );
3170 SetRect( &rc, 0,40, 100,60);
3171 SetRect( &cliprc, 0,0, 100,100);
3172 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3173 if (winetest_debug > 0) dump_region( hrgn );
3174 SetRectRgn( exprgn, 0, 40, 98, 60 );
3175 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
3177 /* now test ScrollWindowEx with a combination of
3178 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3179 /* make hwnd2 the child of hwnd1 */
3180 hwnd2 = CreateWindowExA(0, "static", NULL,
3181 WS_CHILD| WS_VISIBLE | WS_BORDER ,
3182 50, 50, 100, 100, hwnd1, 0, 0, NULL);
3183 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
3184 GetClientRect( hwnd1, &rc);
3187 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3188 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3189 ValidateRect( hwnd1, NULL);
3190 ValidateRect( hwnd2, NULL);
3191 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
3192 SW_SCROLLCHILDREN | SW_INVALIDATE);
3193 if (winetest_debug > 0) dump_region(hrgn);
3194 SetRectRgn( exprgn, 88,0,98,88);
3195 SetRectRgn( tmprgn, 0,88,98,98);
3196 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3197 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3199 /* SW_SCROLLCHILDREN */
3200 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3201 ValidateRect( hwnd1, NULL);
3202 ValidateRect( hwnd2, NULL);
3203 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3204 if (winetest_debug > 0) dump_region(hrgn);
3205 /* expected region is the same as in previous test */
3206 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3208 /* no SW_SCROLLCHILDREN */
3209 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3210 ValidateRect( hwnd1, NULL);
3211 ValidateRect( hwnd2, NULL);
3212 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3213 if (winetest_debug > 0) dump_region(hrgn);
3214 /* expected region is the same as in previous test */
3215 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3217 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3218 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3219 ValidateRect( hwnd1, NULL);
3220 ValidateRect( hwnd2, NULL);
3221 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3222 if (winetest_debug > 0) dump_region(hrgn);
3223 SetRectRgn( exprgn, 88,0,98,20);
3224 SetRectRgn( tmprgn, 20,20,98,30);
3225 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3226 SetRectRgn( tmprgn, 20,30,30,88);
3227 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3228 SetRectRgn( tmprgn, 0,88,30,98);
3229 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3230 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3233 DeleteObject( hrgn);
3234 DeleteObject( exprgn);
3235 DeleteObject( tmprgn);
3236 DestroyWindow( hwnd1);
3237 DestroyWindow( hwnd2);
3240 /* couple of tests of return values of scrollbar functions
3241 * called on a scrollbarless window */
3242 static void test_scroll(void)
3247 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3248 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3249 100, 100, 200, 200, 0, 0, 0, NULL);
3251 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3252 ok( ret, "GetScrollRange returns FALSE\n");
3253 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3254 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3255 si.cbSize = sizeof( si);
3256 si.fMask = SIF_PAGE;
3257 si.nPage = 0xdeadbeef;
3258 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3259 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3260 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3262 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3263 ok( ret, "GetScrollRange returns FALSE\n");
3264 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3265 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3266 si.cbSize = sizeof( si);
3267 si.fMask = SIF_PAGE;
3268 si.nPage = 0xdeadbeef;
3269 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3270 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3271 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3273 DestroyWindow( hwnd);
3276 static void test_scrolldc( HWND parent)
3279 HRGN exprgn, tmprgn, hrgn;
3280 RECT rc, rc2, rcu, cliprc;
3284 hrgn = CreateRectRgn(0,0,0,0);
3285 tmprgn = CreateRectRgn(0,0,0,0);
3286 exprgn = CreateRectRgn(0,0,0,0);
3288 hwnd1 = CreateWindowExA(0, "static", NULL,
3289 WS_CHILD| WS_VISIBLE,
3290 25, 50, 100, 100, parent, 0, 0, NULL);
3291 ShowWindow( parent, SW_SHOW);
3292 UpdateWindow( parent);
3293 flush_events( TRUE );
3294 GetClientRect( hwnd1, &rc);
3295 hdc = GetDC( hwnd1);
3296 /* paint the upper half of the window black */
3298 rc2.bottom = ( rc.top + rc.bottom) /2;
3299 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3300 /* clip region is the lower half */
3302 cliprc.top = (rc.top + rc.bottom) /2;
3303 /* test whether scrolled pixels are properly clipped */
3304 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3305 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3306 /* this scroll should not cause any visible changes */
3307 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3308 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3309 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3310 /* test with NULL clip rect */
3311 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3312 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3313 trace("update rect: %d,%d - %d,%d\n",
3314 rcu.left, rcu.top, rcu.right, rcu.bottom);
3315 if (winetest_debug > 0) dump_region(hrgn);
3316 SetRect(&rc2, 0, 0, 100, 100);
3317 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3318 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3320 SetRectRgn( exprgn, 0, 0, 20, 80);
3321 SetRectRgn( tmprgn, 0, 80, 100, 100);
3322 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3323 if (winetest_debug > 0) dump_region(exprgn);
3324 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3325 /* test clip rect > scroll rect */
3326 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3328 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3329 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3330 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3331 SetRectRgn( exprgn, 25, 25, 75, 35);
3332 SetRectRgn( tmprgn, 25, 35, 35, 75);
3333 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3334 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3335 colr = GetPixel( hdc, 80, 80);
3336 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3337 trace("update rect: %d,%d - %d,%d\n",
3338 rcu.left, rcu.top, rcu.right, rcu.bottom);
3339 if (winetest_debug > 0) dump_region(hrgn);
3343 DeleteObject(exprgn);
3344 DeleteObject(tmprgn);
3345 DestroyWindow(hwnd1);
3348 static void test_params(void)
3353 /* Just a param check */
3354 SetLastError(0xdeadbeef);
3355 rc = GetWindowText(hwndMain2, NULL, 1024);
3356 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
3358 SetLastError(0xdeadbeef);
3359 hwnd=CreateWindow("LISTBOX", "TestList",
3360 (LBS_STANDARD & ~LBS_SORT),
3362 NULL, (HMENU)1, NULL, 0);
3364 ok(!hwnd, "CreateWindow with invalid menu handle should fail\n");
3365 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3366 GetLastError() == 0xdeadbeef, /* Win9x */
3367 "wrong last error value %d\n", GetLastError());
3370 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3374 hwnd = CreateWindowEx(exStyle, class, class, style,
3381 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
3384 ShowWindow(hwnd, SW_SHOW);
3386 test_nonclient_area(hwnd);
3389 DestroyWindow(hwnd);
3392 static BOOL AWR_init(void)
3396 class.style = CS_HREDRAW | CS_VREDRAW;
3397 class.lpfnWndProc = DefWindowProcA;
3398 class.cbClsExtra = 0;
3399 class.cbWndExtra = 0;
3400 class.hInstance = 0;
3401 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3402 class.hCursor = LoadCursor (0, IDC_ARROW);
3403 class.hbrBackground = 0;
3404 class.lpszMenuName = 0;
3405 class.lpszClassName = szAWRClass;
3407 if (!RegisterClass (&class)) {
3408 ok(FALSE, "RegisterClass failed\n");
3412 hmenu = CreateMenu();
3415 ok(hmenu != 0, "Failed to create menu\n");
3416 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3422 static void test_AWR_window_size(BOOL menu)
3426 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3429 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3430 WS_HSCROLL, WS_VSCROLL
3434 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3437 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3438 WS_EX_DLGMODALFRAME,
3445 /* A exhaustive check of all the styles takes too long
3446 * so just do a (hopefully representative) sample
3448 for (i = 0; i < COUNTOF(styles); ++i)
3449 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3450 for (i = 0; i < COUNTOF(exStyles); ++i) {
3451 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3452 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3457 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3459 static void test_AdjustWindowRect(void)
3464 SHOWSYSMETRIC(SM_CYCAPTION);
3465 SHOWSYSMETRIC(SM_CYSMCAPTION);
3466 SHOWSYSMETRIC(SM_CYMENU);
3467 SHOWSYSMETRIC(SM_CXEDGE);
3468 SHOWSYSMETRIC(SM_CYEDGE);
3469 SHOWSYSMETRIC(SM_CXVSCROLL);
3470 SHOWSYSMETRIC(SM_CYHSCROLL);
3471 SHOWSYSMETRIC(SM_CXFRAME);
3472 SHOWSYSMETRIC(SM_CYFRAME);
3473 SHOWSYSMETRIC(SM_CXDLGFRAME);
3474 SHOWSYSMETRIC(SM_CYDLGFRAME);
3475 SHOWSYSMETRIC(SM_CXBORDER);
3476 SHOWSYSMETRIC(SM_CYBORDER);
3478 test_AWR_window_size(FALSE);
3479 test_AWR_window_size(TRUE);
3483 #undef SHOWSYSMETRIC
3486 /* Global variables to trigger exit from loop */
3487 static int redrawComplete, WMPAINT_count;
3489 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3494 trace("doing WM_PAINT %d\n", WMPAINT_count);
3496 if (WMPAINT_count > 10 && redrawComplete == 0) {
3498 BeginPaint(hwnd, &ps);
3499 EndPaint(hwnd, &ps);
3504 return DefWindowProc(hwnd, msg, wparam, lparam);
3507 /* Ensure we exit from RedrawNow regardless of invalidated area */
3508 static void test_redrawnow(void)
3513 cls.style = CS_DBLCLKS;
3514 cls.lpfnWndProc = redraw_window_procA;
3517 cls.hInstance = GetModuleHandleA(0);
3519 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3520 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3521 cls.lpszMenuName = NULL;
3522 cls.lpszClassName = "RedrawWindowClass";
3524 if(!RegisterClassA(&cls)) {
3525 trace("Register failed %d\n", GetLastError());
3529 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3530 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3532 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3533 ShowWindow(hwndMain, SW_SHOW);
3534 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3535 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3536 ok( WMPAINT_count == 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3537 redrawComplete = TRUE;
3538 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3541 DestroyWindow( hwndMain);
3544 struct parentdc_stat {
3550 struct parentdc_test {
3551 struct parentdc_stat main, main_todo;
3552 struct parentdc_stat child1, child1_todo;
3553 struct parentdc_stat child2, child2_todo;
3556 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3561 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3566 trace("doing WM_PAINT on %p\n", hwnd);
3567 GetClientRect(hwnd, &rc);
3568 CopyRect(&t->client, &rc);
3569 trace("client rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3570 GetWindowRect(hwnd, &rc);
3571 trace("window rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3572 BeginPaint(hwnd, &ps);
3573 CopyRect(&t->paint, &ps.rcPaint);
3574 GetClipBox(ps.hdc, &rc);
3575 CopyRect(&t->clip, &rc);
3576 trace("clip rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3577 trace("paint rect (%d, %d)-(%d, %d)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3578 EndPaint(hwnd, &ps);
3581 return DefWindowProc(hwnd, msg, wparam, lparam);
3584 static void zero_parentdc_stat(struct parentdc_stat *t)
3586 SetRectEmpty(&t->client);
3587 SetRectEmpty(&t->clip);
3588 SetRectEmpty(&t->paint);
3591 static void zero_parentdc_test(struct parentdc_test *t)
3593 zero_parentdc_stat(&t->main);
3594 zero_parentdc_stat(&t->child1);
3595 zero_parentdc_stat(&t->child2);
3598 #define parentdc_field_ok(t, w, r, f, got) \
3599 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3600 ": expected %d, got %d\n", \
3603 #define parentdc_todo_field_ok(t, w, r, f, got) \
3604 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3605 else parentdc_field_ok(t, w, r, f, got)
3607 #define parentdc_rect_ok(t, w, r, got) \
3608 parentdc_todo_field_ok(t, w, r, left, got); \
3609 parentdc_todo_field_ok(t, w, r, top, got); \
3610 parentdc_todo_field_ok(t, w, r, right, got); \
3611 parentdc_todo_field_ok(t, w, r, bottom, got);
3613 #define parentdc_win_ok(t, w, got) \
3614 parentdc_rect_ok(t, w, client, got); \
3615 parentdc_rect_ok(t, w, clip, got); \
3616 parentdc_rect_ok(t, w, paint, got);
3618 #define parentdc_ok(t, got) \
3619 parentdc_win_ok(t, main, got); \
3620 parentdc_win_ok(t, child1, got); \
3621 parentdc_win_ok(t, child2, got);
3623 static void test_csparentdc(void)
3625 WNDCLASSA clsMain, cls;
3626 HWND hwndMain, hwnd1, hwnd2;
3629 struct parentdc_test test_answer;
3631 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3632 const struct parentdc_test test1 =
3634 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
3635 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3636 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3639 const struct parentdc_test test2 =
3641 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
3642 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3643 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3646 const struct parentdc_test test3 =
3648 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3649 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3650 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3653 const struct parentdc_test test4 =
3655 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
3656 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
3657 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3660 const struct parentdc_test test5 =
3662 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
3663 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3664 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3667 const struct parentdc_test test6 =
3669 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3670 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3671 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3674 const struct parentdc_test test7 =
3676 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3677 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3678 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3682 clsMain.style = CS_DBLCLKS;
3683 clsMain.lpfnWndProc = parentdc_window_procA;
3684 clsMain.cbClsExtra = 0;
3685 clsMain.cbWndExtra = 0;
3686 clsMain.hInstance = GetModuleHandleA(0);
3688 clsMain.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3689 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
3690 clsMain.lpszMenuName = NULL;
3691 clsMain.lpszClassName = "ParentDcMainWindowClass";
3693 if(!RegisterClassA(&clsMain)) {
3694 trace("Register failed %d\n", GetLastError());
3698 cls.style = CS_DBLCLKS | CS_PARENTDC;
3699 cls.lpfnWndProc = parentdc_window_procA;
3702 cls.hInstance = GetModuleHandleA(0);
3704 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3705 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3706 cls.lpszMenuName = NULL;
3707 cls.lpszClassName = "ParentDcWindowClass";
3709 if(!RegisterClassA(&cls)) {
3710 trace("Register failed %d\n", GetLastError());
3714 SetRect(&rc, 0, 0, 150, 150);
3715 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
3716 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3717 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
3718 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
3719 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
3720 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
3721 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
3722 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
3723 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
3724 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
3725 ShowWindow(hwndMain, SW_SHOW);
3726 ShowWindow(hwnd1, SW_SHOW);
3727 ShowWindow(hwnd2, SW_SHOW);
3728 flush_events( TRUE );
3730 zero_parentdc_test(&test_answer);
3731 InvalidateRect(hwndMain, NULL, TRUE);
3732 flush_events( TRUE );
3733 parentdc_ok(test1, test_answer);
3735 zero_parentdc_test(&test_answer);
3736 SetRect(&rc, 0, 0, 50, 50);
3737 InvalidateRect(hwndMain, &rc, TRUE);
3738 flush_events( TRUE );
3739 parentdc_ok(test2, test_answer);
3741 zero_parentdc_test(&test_answer);
3742 SetRect(&rc, 0, 0, 10, 10);
3743 InvalidateRect(hwndMain, &rc, TRUE);
3744 flush_events( TRUE );
3745 parentdc_ok(test3, test_answer);
3747 zero_parentdc_test(&test_answer);
3748 SetRect(&rc, 40, 40, 50, 50);
3749 InvalidateRect(hwndMain, &rc, TRUE);
3750 flush_events( TRUE );
3751 parentdc_ok(test4, test_answer);
3753 zero_parentdc_test(&test_answer);
3754 SetRect(&rc, 20, 20, 60, 60);
3755 InvalidateRect(hwndMain, &rc, TRUE);
3756 flush_events( TRUE );
3757 parentdc_ok(test5, test_answer);
3759 zero_parentdc_test(&test_answer);
3760 SetRect(&rc, 0, 0, 10, 10);
3761 InvalidateRect(hwnd1, &rc, TRUE);
3762 flush_events( TRUE );
3763 parentdc_ok(test6, test_answer);
3765 zero_parentdc_test(&test_answer);
3766 SetRect(&rc, -5, -5, 65, 65);
3767 InvalidateRect(hwnd1, &rc, TRUE);
3768 flush_events( TRUE );
3769 parentdc_ok(test7, test_answer);
3771 DestroyWindow(hwndMain);
3772 DestroyWindow(hwnd1);
3773 DestroyWindow(hwnd2);
3776 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3778 return DefWindowProcA(hwnd, msg, wparam, lparam);
3781 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3783 return DefWindowProcW(hwnd, msg, wparam, lparam);
3786 static void test_IsWindowUnicode(void)
3788 static const char ansi_class_nameA[] = "ansi class name";
3789 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3790 static const char unicode_class_nameA[] = "unicode class name";
3791 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3796 memset(&classW, 0, sizeof(classW));
3797 classW.hInstance = GetModuleHandleA(0);
3798 classW.lpfnWndProc = def_window_procW;
3799 classW.lpszClassName = unicode_class_nameW;
3800 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
3802 memset(&classA, 0, sizeof(classA));
3803 classA.hInstance = GetModuleHandleA(0);
3804 classA.lpfnWndProc = def_window_procA;
3805 classA.lpszClassName = ansi_class_nameA;
3806 assert(RegisterClassA(&classA));
3808 /* unicode class: window proc */
3809 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3810 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3813 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3814 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3815 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3816 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3817 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3819 DestroyWindow(hwnd);
3821 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3822 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3825 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3826 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3827 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3828 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3829 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3831 DestroyWindow(hwnd);
3833 /* ansi class: window proc */
3834 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3835 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3838 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3839 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3840 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3841 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3842 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3844 DestroyWindow(hwnd);
3846 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3847 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3850 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3851 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3852 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3853 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3854 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3856 DestroyWindow(hwnd);
3858 /* unicode class: class proc */
3859 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3860 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3863 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3864 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3865 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3866 /* do not restore class window proc back to unicode */
3868 DestroyWindow(hwnd);
3870 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3871 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3874 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3875 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
3876 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3878 DestroyWindow(hwnd);
3880 /* ansi class: class proc */
3881 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3882 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3885 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3886 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
3887 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3888 /* do not restore class window proc back to ansi */
3890 DestroyWindow(hwnd);
3892 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3893 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3896 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3897 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3898 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3900 DestroyWindow(hwnd);
3903 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
3907 if (msg != WM_GETMINMAXINFO)
3908 return DefWindowProc(hwnd, msg, wp, lp);
3910 minmax = (MINMAXINFO *)lp;
3912 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
3914 minmax->ptReserved.x = 0;
3915 minmax->ptReserved.y = 0;
3916 minmax->ptMaxSize.x = 400;
3917 minmax->ptMaxSize.y = 400;
3918 minmax->ptMaxPosition.x = 300;
3919 minmax->ptMaxPosition.y = 300;
3920 minmax->ptMaxTrackSize.x = 200;
3921 minmax->ptMaxTrackSize.y = 200;
3922 minmax->ptMinTrackSize.x = 100;
3923 minmax->ptMinTrackSize.y = 100;
3926 DefWindowProc(hwnd, msg, wp, lp);
3930 static int expected_cx, expected_cy;
3931 static RECT expected_rect, broken_rect;
3933 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
3937 case WM_GETMINMAXINFO:
3940 GetWindowRect( hwnd, &rect );
3941 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
3942 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
3943 return DefWindowProc(hwnd, msg, wp, lp);
3948 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
3950 GetWindowRect( hwnd, &rect );
3951 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
3952 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
3953 ok( cs->cx == expected_cx, "wrong x size %d/%d\n", cs->cx, expected_cx );
3954 ok( cs->cy == expected_cy, "wrong y size %d/%d\n", cs->cy, expected_cy );
3955 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
3956 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
3957 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
3958 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top),
3959 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
3960 rect.left, rect.top, rect.right, rect.bottom,
3961 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
3962 return DefWindowProc(hwnd, msg, wp, lp);
3966 RECT rect, *r = (RECT *)lp;
3967 GetWindowRect( hwnd, &rect );
3968 ok( !memcmp( &rect, r, sizeof(rect) ),
3969 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
3970 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
3971 return DefWindowProc(hwnd, msg, wp, lp);
3974 return DefWindowProc(hwnd, msg, wp, lp);
3978 static void test_CreateWindow(void)
3986 #define expect_menu(window, menu) \
3987 SetLastError(0xdeadbeef); \
3988 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
3990 #define expect_style(window, style)\
3991 ok(GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
3993 #define expect_ex_style(window, ex_style)\
3994 ok(GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
3996 hmenu = CreateMenu();
3998 parent = GetDesktopWindow();
3999 assert(parent != 0);
4001 SetLastError(0xdeadbeef);
4002 ok(IsMenu(hmenu), "IsMenu error %d\n", GetLastError());
4005 SetLastError(0xdeadbeef);
4006 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
4007 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4008 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4009 expect_menu(hwnd, 1);
4010 expect_style(hwnd, WS_CHILD);
4011 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4012 DestroyWindow(hwnd);
4014 SetLastError(0xdeadbeef);
4015 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
4016 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4017 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4018 expect_menu(hwnd, 1);
4019 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4020 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4021 DestroyWindow(hwnd);
4023 SetLastError(0xdeadbeef);
4024 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
4025 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4026 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4027 expect_menu(hwnd, 1);
4028 expect_style(hwnd, WS_CHILD);
4029 expect_ex_style(hwnd, 0);
4030 DestroyWindow(hwnd);
4032 SetLastError(0xdeadbeef);
4033 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
4034 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4035 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4036 expect_menu(hwnd, 1);
4037 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4038 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4039 DestroyWindow(hwnd);
4042 SetLastError(0xdeadbeef);
4043 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4044 0, 0, 100, 100, parent, hmenu, 0, NULL);
4045 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4046 expect_menu(hwnd, hmenu);
4047 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4048 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4049 DestroyWindow(hwnd);
4050 SetLastError(0xdeadbeef);
4051 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4052 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4054 hmenu = CreateMenu();
4056 SetLastError(0xdeadbeef);
4057 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
4058 0, 0, 100, 100, parent, hmenu, 0, NULL);
4059 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4060 expect_menu(hwnd, hmenu);
4061 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4062 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4063 DestroyWindow(hwnd);
4064 SetLastError(0xdeadbeef);
4065 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4066 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4068 hmenu = CreateMenu();
4070 SetLastError(0xdeadbeef);
4071 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
4072 0, 0, 100, 100, parent, hmenu, 0, NULL);
4073 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4074 expect_menu(hwnd, hmenu);
4075 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4076 expect_ex_style(hwnd, 0);
4077 DestroyWindow(hwnd);
4078 SetLastError(0xdeadbeef);
4079 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4080 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4082 hmenu = CreateMenu();
4084 SetLastError(0xdeadbeef);
4085 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
4086 0, 0, 100, 100, parent, hmenu, 0, NULL);
4087 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4088 expect_menu(hwnd, hmenu);
4089 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4090 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4091 DestroyWindow(hwnd);
4092 SetLastError(0xdeadbeef);
4093 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4094 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4096 /* WS_CHILD | WS_POPUP */
4097 SetLastError(0xdeadbeef);
4098 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4099 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4100 ok(!hwnd, "CreateWindowEx should fail\n");
4101 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4103 hmenu = CreateMenu();
4105 SetLastError(0xdeadbeef);
4106 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4107 0, 0, 100, 100, parent, hmenu, 0, NULL);
4108 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4109 expect_menu(hwnd, hmenu);
4110 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4111 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4112 DestroyWindow(hwnd);
4113 SetLastError(0xdeadbeef);
4114 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4115 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4117 SetLastError(0xdeadbeef);
4118 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4119 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4120 ok(!hwnd, "CreateWindowEx should fail\n");
4121 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4123 hmenu = CreateMenu();
4125 SetLastError(0xdeadbeef);
4126 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4127 0, 0, 100, 100, parent, hmenu, 0, NULL);
4128 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4129 expect_menu(hwnd, hmenu);
4130 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4131 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4132 DestroyWindow(hwnd);
4133 SetLastError(0xdeadbeef);
4134 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4135 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4137 SetLastError(0xdeadbeef);
4138 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4139 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4140 ok(!hwnd, "CreateWindowEx should fail\n");
4141 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4143 hmenu = CreateMenu();
4145 SetLastError(0xdeadbeef);
4146 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4147 0, 0, 100, 100, parent, hmenu, 0, NULL);
4148 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4149 expect_menu(hwnd, hmenu);
4150 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4151 expect_ex_style(hwnd, 0);
4152 DestroyWindow(hwnd);
4153 SetLastError(0xdeadbeef);
4154 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4155 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4157 SetLastError(0xdeadbeef);
4158 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4159 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4160 ok(!hwnd, "CreateWindowEx should fail\n");
4161 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4163 hmenu = CreateMenu();
4165 SetLastError(0xdeadbeef);
4166 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4167 0, 0, 100, 100, parent, hmenu, 0, NULL);
4168 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4169 expect_menu(hwnd, hmenu);
4170 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4171 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4172 DestroyWindow(hwnd);
4173 SetLastError(0xdeadbeef);
4174 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4175 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4177 /* test child window sizing */
4179 cls.lpfnWndProc = minmax_wnd_proc;
4182 cls.hInstance = GetModuleHandle(0);
4184 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
4185 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4186 cls.lpszMenuName = NULL;
4187 cls.lpszClassName = "MinMax_WndClass";
4188 RegisterClass(&cls);
4190 SetLastError(0xdeadbeef);
4191 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4192 0, 0, 100, 100, 0, 0, 0, NULL);
4193 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4194 expect_menu(parent, 0);
4195 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
4196 expect_ex_style(parent, WS_EX_WINDOWEDGE);
4198 memset(&minmax, 0, sizeof(minmax));
4199 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4200 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
4201 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
4202 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4203 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
4205 GetWindowRect(parent, &rc);
4206 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
4207 GetClientRect(parent, &rc);
4208 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
4210 InflateRect(&rc, 200, 200);
4211 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4213 SetLastError(0xdeadbeef);
4214 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4215 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
4216 parent, (HMENU)1, 0, NULL);
4217 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4218 expect_menu(hwnd, 1);
4219 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
4220 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4222 memset(&minmax, 0, sizeof(minmax));
4223 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4224 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4226 GetWindowRect(hwnd, &rc);
4227 OffsetRect(&rc, -rc.left, -rc.top);
4228 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4229 rc.left, rc.top, rc.right, rc.bottom,
4230 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
4231 DestroyWindow(hwnd);
4233 cls.lpfnWndProc = winsizes_wnd_proc;
4234 cls.lpszClassName = "Sizes_WndClass";
4235 RegisterClass(&cls);
4237 expected_cx = expected_cy = 200000;
4238 SetRect( &expected_rect, 0, 0, 200000, 200000 );
4239 broken_rect = expected_rect;
4240 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
4241 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4242 GetClientRect( hwnd, &rc );
4243 ok( rc.right == 200000, "invalid rect right %u\n", rc.right );
4244 ok( rc.bottom == 200000, "invalid rect bottom %u\n", rc.bottom );
4245 DestroyWindow(hwnd);
4247 expected_cx = expected_cy = -10;
4248 SetRect( &expected_rect, 0, 0, 0, 0 );
4249 broken_rect = expected_rect;
4250 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
4251 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4252 GetClientRect( hwnd, &rc );
4253 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4254 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4255 DestroyWindow(hwnd);
4257 expected_cx = expected_cy = -200000;
4258 SetRect( &expected_rect, 0, 0, 0, 0 );
4259 broken_rect = expected_rect;
4260 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
4261 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4262 GetClientRect( hwnd, &rc );
4263 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4264 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4265 DestroyWindow(hwnd);
4267 /* we need a parent at 0,0 so that child coordinates match */
4268 DestroyWindow(parent);
4269 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
4270 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4273 expected_cy = 0x7fffffff;
4274 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
4275 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
4276 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
4277 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4278 GetClientRect( hwnd, &rc );
4279 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
4280 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4281 DestroyWindow(hwnd);
4283 expected_cx = 0x7fffffff;
4284 expected_cy = 0x7fffffff;
4285 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
4286 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
4287 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
4288 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4289 GetClientRect( hwnd, &rc );
4290 ok( rc.right == 0x7fffffff - 20 || broken(rc.right == 0), "invalid rect right %u\n", rc.right );
4291 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4292 DestroyWindow(hwnd);
4294 /* top level window */
4295 expected_cx = expected_cy = 200000;
4296 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
4297 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
4298 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4299 GetClientRect( hwnd, &rc );
4300 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
4301 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
4302 DestroyWindow(hwnd);
4304 DestroyWindow(parent);
4306 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4307 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4311 #undef expect_ex_style
4314 /* function that remembers whether the system the test is running on sets the
4315 * last error for user32 functions to make the tests stricter */
4316 static int check_error(DWORD actual, DWORD expected)
4318 static int sets_last_error = -1;
4319 if (sets_last_error == -1)
4320 sets_last_error = (actual != 0xdeadbeef);
4321 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
4324 static void test_SetWindowLong(void)
4327 WNDPROC old_window_procW;
4329 SetLastError(0xdeadbeef);
4330 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
4331 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
4332 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
4333 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4335 SetLastError(0xdeadbeef);
4336 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
4337 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
4338 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
4339 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4341 SetLastError(0xdeadbeef);
4342 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4343 ok((WNDPROC)retval == main_window_procA,
4344 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
4345 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4346 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
4347 ok((WNDPROC)retval == main_window_procA,
4348 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4349 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
4351 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
4352 SetLastError(0xdeadbeef);
4353 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
4354 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
4356 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4357 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
4358 ok((WNDPROC)retval == old_window_procW,
4359 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4360 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
4362 /* set it back to ANSI */
4363 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4367 static void test_ShowWindow(void)
4374 SetRect(&rcMain, 120, 120, 210, 210);
4376 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
4377 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4378 WS_MAXIMIZEBOX | WS_POPUP,
4379 rcMain.left, rcMain.top,
4380 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
4384 style = GetWindowLong(hwnd, GWL_STYLE);
4385 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4386 ok(!(style & WS_VISIBLE), "window should not be visible\n");
4387 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4388 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4389 GetWindowRect(hwnd, &rc);
4390 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4391 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4392 rc.left, rc.top, rc.right, rc.bottom);
4394 ret = ShowWindow(hwnd, SW_SHOW);
4395 ok(!ret, "not expected ret: %lu\n", ret);
4396 style = GetWindowLong(hwnd, GWL_STYLE);
4397 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4398 ok(style & WS_VISIBLE, "window should be visible\n");
4399 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4400 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4401 GetWindowRect(hwnd, &rc);
4402 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4403 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4404 rc.left, rc.top, rc.right, rc.bottom);
4406 ret = ShowWindow(hwnd, SW_MINIMIZE);
4407 ok(ret, "not expected ret: %lu\n", ret);
4408 style = GetWindowLong(hwnd, GWL_STYLE);
4409 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4410 ok(style & WS_VISIBLE, "window should be visible\n");
4411 ok(style & WS_MINIMIZE, "window should be minimized\n");
4412 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4413 GetWindowRect(hwnd, &rc);
4414 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4416 ShowWindow(hwnd, SW_RESTORE);
4417 ok(ret, "not expected ret: %lu\n", ret);
4418 style = GetWindowLong(hwnd, GWL_STYLE);
4419 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4420 ok(style & WS_VISIBLE, "window should be visible\n");
4421 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4422 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4423 GetWindowRect(hwnd, &rc);
4424 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4425 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4426 rc.left, rc.top, rc.right, rc.bottom);
4428 ret = EnableWindow(hwnd, FALSE);
4429 ok(!ret, "not expected ret: %lu\n", ret);
4430 style = GetWindowLong(hwnd, GWL_STYLE);
4431 ok(style & WS_DISABLED, "window should be disabled\n");
4433 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
4434 ok(!ret, "not expected ret: %lu\n", ret);
4435 style = GetWindowLong(hwnd, GWL_STYLE);
4436 ok(style & WS_DISABLED, "window should be disabled\n");
4437 ok(style & WS_VISIBLE, "window should be visible\n");
4438 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4439 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4440 GetWindowRect(hwnd, &rc);
4441 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4442 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4443 rc.left, rc.top, rc.right, rc.bottom);
4445 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
4446 ok(!ret, "not expected ret: %lu\n", ret);
4447 style = GetWindowLong(hwnd, GWL_STYLE);
4448 ok(style & WS_DISABLED, "window should be disabled\n");
4449 ok(style & WS_VISIBLE, "window should be visible\n");
4450 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4451 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4452 GetWindowRect(hwnd, &rc);
4453 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4454 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4455 rc.left, rc.top, rc.right, rc.bottom);
4457 ret = ShowWindow(hwnd, SW_MINIMIZE);
4458 ok(ret, "not expected ret: %lu\n", ret);
4459 style = GetWindowLong(hwnd, GWL_STYLE);
4460 ok(style & WS_DISABLED, "window should be disabled\n");
4461 ok(style & WS_VISIBLE, "window should be visible\n");
4462 ok(style & WS_MINIMIZE, "window should be minimized\n");
4463 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4464 GetWindowRect(hwnd, &rc);
4465 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4467 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
4468 ok(!ret, "not expected ret: %lu\n", ret);
4469 style = GetWindowLong(hwnd, GWL_STYLE);
4470 ok(style & WS_DISABLED, "window should be disabled\n");
4471 ok(style & WS_VISIBLE, "window should be visible\n");
4472 ok(style & WS_MINIMIZE, "window should be minimized\n");
4473 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4474 GetWindowRect(hwnd, &rc);
4475 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4477 ret = ShowWindow(hwnd, SW_RESTORE);
4478 ok(ret, "not expected ret: %lu\n", ret);
4479 style = GetWindowLong(hwnd, GWL_STYLE);
4480 ok(style & WS_DISABLED, "window should be disabled\n");
4481 ok(style & WS_VISIBLE, "window should be visible\n");
4482 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4483 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4484 GetWindowRect(hwnd, &rc);
4485 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4486 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4487 rc.left, rc.top, rc.right, rc.bottom);
4489 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4490 ok(!ret, "not expected ret: %lu\n", ret);
4491 ok(IsWindow(hwnd), "window should exist\n");
4493 ret = EnableWindow(hwnd, TRUE);
4494 ok(ret, "not expected ret: %lu\n", ret);
4496 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4497 ok(!ret, "not expected ret: %lu\n", ret);
4498 ok(!IsWindow(hwnd), "window should not exist\n");
4501 static void test_gettext(void)
4504 LPCSTR clsname = "gettexttest";
4508 memset( &cls, 0, sizeof cls );
4509 cls.lpfnWndProc = DefWindowProc;
4510 cls.lpszClassName = clsname;
4511 cls.hInstance = GetModuleHandle(NULL);
4513 if (!RegisterClass( &cls )) return;
4515 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
4516 ok( hwnd != NULL, "window was null\n");
4518 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
4519 ok( r == 0, "settext should return zero\n");
4521 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
4522 ok( r == 0, "settext should return zero (%ld)\n", r);
4524 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
4525 ok( r == 0, "settext should return zero (%ld)\n", r);
4527 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
4528 ok( r == 0, "settext should return zero (%ld)\n", r);
4530 DestroyWindow(hwnd);
4531 UnregisterClass( clsname, NULL );
4535 static void test_GetUpdateRect(void)
4538 BOOL ret, parent_wm_paint, grandparent_wm_paint;
4540 HWND hgrandparent, hparent, hchild;
4542 static const char classNameA[] = "GetUpdateRectClass";
4544 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
4545 0, 0, 100, 100, NULL, NULL, 0, NULL);
4547 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
4548 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4550 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
4551 10, 10, 30, 30, hparent, NULL, 0, NULL);
4553 ShowWindow(hgrandparent, SW_SHOW);
4554 UpdateWindow(hgrandparent);
4555 flush_events( TRUE );
4557 ShowWindow(hchild, SW_HIDE);
4558 SetRect(&rc2, 0, 0, 0, 0);
4559 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4560 ok(!ret, "GetUpdateRect returned not empty region\n");
4561 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4562 rc1.left, rc1.top, rc1.right, rc1.bottom,
4563 rc2.left, rc2.top, rc2.right, rc2.bottom);
4565 SetRect(&rc2, 10, 10, 40, 40);
4566 ret = GetUpdateRect(hparent, &rc1, FALSE);
4567 ok(ret, "GetUpdateRect returned empty region\n");
4568 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4569 rc1.left, rc1.top, rc1.right, rc1.bottom,
4570 rc2.left, rc2.top, rc2.right, rc2.bottom);
4572 parent_wm_paint = FALSE;
4573 grandparent_wm_paint = FALSE;
4574 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4576 if (msg.message == WM_PAINT)
4578 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4579 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4581 DispatchMessage(&msg);
4583 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4584 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4586 DestroyWindow(hgrandparent);
4589 cls.lpfnWndProc = DefWindowProcA;
4592 cls.hInstance = GetModuleHandleA(0);
4594 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
4595 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4596 cls.lpszMenuName = NULL;
4597 cls.lpszClassName = classNameA;
4599 if(!RegisterClassA(&cls)) {
4600 trace("Register failed %d\n", GetLastError());
4604 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
4605 0, 0, 100, 100, NULL, NULL, 0, NULL);
4607 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
4608 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4610 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
4611 10, 10, 30, 30, hparent, NULL, 0, NULL);
4613 ShowWindow(hgrandparent, SW_SHOW);
4614 UpdateWindow(hgrandparent);
4615 flush_events( TRUE );
4617 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4618 ok(!ret, "GetUpdateRect returned not empty region\n");
4620 ShowWindow(hchild, SW_HIDE);
4622 SetRect(&rc2, 0, 0, 0, 0);
4623 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4624 ok(!ret, "GetUpdateRect returned not empty region\n");
4625 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4626 rc1.left, rc1.top, rc1.right, rc1.bottom,
4627 rc2.left, rc2.top, rc2.right, rc2.bottom);
4629 SetRect(&rc2, 10, 10, 40, 40);
4630 ret = GetUpdateRect(hparent, &rc1, FALSE);
4631 ok(ret, "GetUpdateRect returned empty region\n");
4632 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4633 rc1.left, rc1.top, rc1.right, rc1.bottom,
4634 rc2.left, rc2.top, rc2.right, rc2.bottom);
4636 parent_wm_paint = FALSE;
4637 grandparent_wm_paint = FALSE;
4638 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4640 if (msg.message == WM_PAINT)
4642 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4643 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4645 DispatchMessage(&msg);
4647 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4648 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4650 DestroyWindow(hgrandparent);
4654 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
4662 const int waitTime = 2000;
4664 BeginPaint(hwnd, &ps);
4666 /* create and destroy window to create an exposed region on this window */
4667 win = CreateWindowA("static", "win", WS_VISIBLE,
4668 10,10,50,50, NULL, NULL, 0, NULL);
4671 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
4673 ValidateRect(hwnd, NULL);
4674 EndPaint(hwnd, &ps);
4676 if(waitResult != WAIT_TIMEOUT)
4678 GetUpdateRect(hwnd, &updateRect, FALSE);
4679 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
4684 return DefWindowProc(hwnd, msg, wParam, lParam);
4687 static void test_Expose(void)
4692 memset(&cls, 0, sizeof(WNDCLASSA));
4693 cls.lpfnWndProc = TestExposedRegion_WndProc;
4694 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4695 cls.lpszClassName = "TestExposeClass";
4696 atom = RegisterClassA(&cls);
4698 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
4699 0, 0, 200, 100, NULL, NULL, 0, NULL);
4705 static void test_GetWindowModuleFileName(void)
4710 char buf1[MAX_PATH], buf2[MAX_PATH];
4712 if (!pGetWindowModuleFileNameA)
4714 skip("GetWindowModuleFileNameA is not available\n");
4718 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
4721 hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
4722 ok(hinst == 0, "expected 0, got %p\n", hinst);
4725 SetLastError(0xdeadbeef);
4726 ret1 = GetModuleFileName(hinst, buf1, sizeof(buf1));
4727 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
4730 SetLastError(0xdeadbeef);
4731 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
4732 ok(ret2, "GetWindowModuleFileNameA error %u\n", GetLastError());
4734 ok(ret1 == ret2, "%u != %u\n", ret1, ret2);
4735 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
4737 hinst = GetModuleHandle(0);
4739 SetLastError(0xdeadbeef);
4740 ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
4741 ok(ret2 == ret1 - 2, "expected %u, got %u\n", ret1 - 2, ret2);
4742 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4743 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4744 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4746 SetLastError(0xdeadbeef);
4747 ret2 = GetModuleFileName(hinst, buf2, 0);
4748 ok(!ret2, "GetModuleFileName should return 0\n");
4749 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4750 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4751 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4753 SetLastError(0xdeadbeef);
4754 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
4755 ok(ret2 == ret1 - 2, "expected %u, got %u\n", ret1 - 2, ret2);
4756 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4757 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4758 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4760 SetLastError(0xdeadbeef);
4761 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
4762 ok(!ret2, "expected 0, got %u\n", ret2);
4763 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4764 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4765 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4767 DestroyWindow(hwnd);
4770 hwnd = (HWND)0xdeadbeef;
4771 SetLastError(0xdeadbeef);
4772 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4773 ok(!ret1, "expected 0, got %u\n", ret1);
4774 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
4776 ret1 = GetModuleFileName(0, buf1, sizeof(buf1));
4777 hwnd = GetDesktopWindow();
4778 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
4779 SetLastError(0xdeadbeef);
4780 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
4781 ok(!ret2 || ret1 == ret2 /* vista */, "expected 0, got %u\n", ret2);
4783 hwnd = FindWindow("Shell_TrayWnd", NULL);
4784 ok(IsWindow(hwnd), "got invalid tray window %p\n", hwnd);
4785 SetLastError(0xdeadbeef);
4786 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4787 ok(!ret1, "expected 0, got %u\n", ret1);
4790 static void test_hwnd_message(void)
4792 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
4793 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
4795 HWND parent = 0, hwnd, found;
4798 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
4799 on CreateWindowExA and crash later in the test.
4800 Use UNICODE here to fail on win9x */
4801 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
4802 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
4805 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
4809 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
4813 HWND root, desktop = GetDesktopWindow();
4815 parent = pGetAncestor(hwnd, GA_PARENT);
4816 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
4817 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
4818 root = pGetAncestor(hwnd, GA_ROOT);
4819 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
4820 ok( !pGetAncestor(parent, GA_PARENT), "parent shouldn't have a parent\n" );
4821 trace("parent %p root %p desktop %p\n", parent, root, desktop);
4822 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
4823 ok( !lstrcmpi( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
4824 GetWindowRect( parent, &rect );
4825 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
4826 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4828 GetWindowRect( hwnd, &rect );
4829 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
4830 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4832 /* test FindWindow behavior */
4834 found = FindWindowExA( 0, 0, 0, "message window" );
4835 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
4836 SetLastError(0xdeadbeef);
4837 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
4838 ok( found == 0, "found message window %p/%p\n", found, hwnd );
4839 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
4842 found = FindWindowExA( parent, 0, 0, "message window" );
4843 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
4846 /* test IsChild behavior */
4848 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
4850 /* test IsWindowVisible behavior */
4852 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
4853 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
4855 DestroyWindow(hwnd);
4858 static void test_layered_window(void)
4866 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes)
4868 win_skip( "layered windows not supported\n" );
4871 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
4872 100, 100, 200, 200, 0, 0, 0, NULL);
4874 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4875 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
4876 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
4877 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
4878 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
4879 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4880 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
4881 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
4882 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4883 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4884 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4885 ok( key == 0x123456, "wrong color key %x\n", key );
4886 ok( alpha == 44, "wrong alpha %u\n", alpha );
4887 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
4889 /* clearing WS_EX_LAYERED resets attributes */
4890 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
4891 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4892 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
4893 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
4894 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4895 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
4896 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
4897 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4898 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4899 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4900 ok( key == 0x654321, "wrong color key %x\n", key );
4901 ok( alpha == 22, "wrong alpha %u\n", alpha );
4902 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
4904 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
4905 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4907 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4908 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4909 ok( key == 0x888888, "wrong color key %x\n", key );
4910 /* alpha not changed on vista if LWA_ALPHA is not set */
4911 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
4912 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
4914 /* color key always changed */
4915 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
4916 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4918 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4919 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4920 ok( key == 0x999999, "wrong color key %x\n", key );
4921 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
4922 ok( flags == 0, "wrong flags %x\n", flags );
4924 /* default alpha is 0 */
4925 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
4926 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
4927 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
4928 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4929 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4930 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4931 ok( key == 0x222222, "wrong color key %x\n", key );
4932 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
4933 ok( flags == 0, "wrong flags %x\n", flags );
4935 DestroyWindow( hwnd );
4938 static MONITORINFO mi;
4940 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4946 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
4947 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs->x, cs->y, cs->cx, cs->cy);
4948 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
4949 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
4950 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
4951 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
4952 cs->x, cs->y, cs->cx, cs->cy);
4955 case WM_GETMINMAXINFO:
4957 MINMAXINFO *minmax = (MINMAXINFO *)lp;
4958 dump_minmax_info(minmax);
4959 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
4960 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
4961 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
4962 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
4966 return DefWindowProc(hwnd, msg, wp, lp);
4969 static void test_fullscreen(void)
4971 static const DWORD t_style[] = {
4972 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
4974 static const DWORD t_ex_style[] = {
4975 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
4985 if (!pGetMonitorInfoA || !pMonitorFromPoint)
4987 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
4992 SetLastError(0xdeadbeef);
4993 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
4994 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
4996 mi.cbSize = sizeof(mi);
4997 SetLastError(0xdeadbeef);
4998 ret = pGetMonitorInfoA(hmon, &mi);
4999 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
5000 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
5001 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5002 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5005 cls.lpfnWndProc = fullscreen_wnd_proc;
5008 cls.hInstance = GetModuleHandle(0);
5010 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
5011 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5012 cls.lpszMenuName = NULL;
5013 cls.lpszClassName = "fullscreen_class";
5014 RegisterClass(&cls);
5016 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
5018 DWORD style, ex_style;
5020 /* avoid a WM interaction */
5021 assert(!(t_style[i] & WS_VISIBLE));
5023 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
5028 ex_style = t_ex_style[j];
5030 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5031 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5032 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5033 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5034 GetWindowRect(hwnd, &rc);
5035 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5036 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5037 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5038 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5039 DestroyWindow(hwnd);
5041 style = t_style[i] | WS_MAXIMIZE;
5042 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5043 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5044 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5045 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5046 GetWindowRect(hwnd, &rc);
5047 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5048 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5049 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5050 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5051 DestroyWindow(hwnd);
5053 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
5054 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5055 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5056 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5057 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5058 GetWindowRect(hwnd, &rc);
5059 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5060 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5061 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5062 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5063 DestroyWindow(hwnd);
5065 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
5066 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5067 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5068 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5069 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5070 GetWindowRect(hwnd, &rc);
5071 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5072 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5073 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5074 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5075 DestroyWindow(hwnd);
5077 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
5078 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5079 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5080 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5081 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5082 GetWindowRect(hwnd, &rc);
5083 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5084 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5085 fixup = min(abs(rc.left), abs(rc.top));
5086 InflateRect(&rc, -fixup, -fixup);
5087 /* FIXME: this doesn't work correctly in Wine for child windows yet */
5088 if (style & WS_CHILD)
5090 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5091 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5092 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5094 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5095 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5096 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5097 DestroyWindow(hwnd);
5099 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
5100 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5101 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5102 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5103 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5104 GetWindowRect(hwnd, &rc);
5105 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5106 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5107 fixup = min(abs(rc.left), abs(rc.top));
5108 InflateRect(&rc, -fixup, -fixup);
5109 if (style & (WS_CHILD | WS_POPUP))
5110 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5111 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5112 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5114 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5115 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5116 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5117 DestroyWindow(hwnd);
5121 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5126 HMODULE user32 = GetModuleHandleA( "user32.dll" );
5127 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
5128 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
5129 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
5130 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
5131 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
5132 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
5133 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
5135 if (!RegisterWindowClasses()) assert(0);
5137 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
5140 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
5141 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5142 WS_MAXIMIZEBOX | WS_POPUP,
5144 0, 0, GetModuleHandle(0), NULL);
5145 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
5146 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5147 WS_MAXIMIZEBOX | WS_POPUP,
5149 0, 0, GetModuleHandle(0), NULL);
5151 assert( hwndMain2 );
5153 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
5155 /* Add the tests below this line */
5157 test_hwnd_message();
5158 test_nonclient_area(hwndMain);
5160 test_GetWindowModuleFileName();
5163 test_capture_3(hwndMain, hwndMain2);
5165 test_CreateWindow();
5166 test_parent_owner();
5171 test_SetWindowPos(hwndMain);
5172 test_SetMenu(hwndMain);
5173 test_SetFocus(hwndMain);
5174 test_SetActiveWindow(hwndMain);
5176 test_children_zorder(hwndMain);
5177 test_popup_zorder(hwndMain2, hwndMain);
5178 test_keyboard_input(hwndMain);
5179 test_mouse_input(hwndMain);
5180 test_validatergn(hwndMain);
5181 test_nccalcscroll( hwndMain);
5182 test_scrollvalidate( hwndMain);
5183 test_scrolldc( hwndMain);
5185 test_IsWindowUnicode();
5186 test_vis_rgn(hwndMain);
5188 test_AdjustWindowRect();
5189 test_window_styles();
5192 test_SetWindowLong();
5194 if (0) test_gettext(); /* crashes on NT4 */
5195 test_GetUpdateRect();
5197 test_layered_window();
5199 test_SetForegroundWindow(hwndMain);
5200 test_shell_window();
5202 /* add the tests above this line */
5203 UnhookWindowsHookEx(hhook);