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 if (GetForegroundWindow())
744 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x active %p fg %p\n",
745 info->dwWindowStatus, status, GetActiveWindow(), GetForegroundWindow());
747 /* win2k and XP return broken border info in GetWindowInfo most of
748 * the time, so there is no point in testing it.
752 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
753 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
754 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
755 ok(info->cyWindowBorders == border,
756 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
758 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType\n");
759 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
760 info->wCreatorVersion == 0x0500 /* Vista */,
761 "wrong wCreatorVersion %04x\n", info->wCreatorVersion);
764 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
766 AdjustWindowRectEx(rc, style, menu, exstyle);
767 /* AdjustWindowRectEx does not include scroll bars */
768 if (style & WS_VSCROLL)
770 if(exstyle & WS_EX_LEFTSCROLLBAR)
771 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
773 rc->right += GetSystemMetrics(SM_CXVSCROLL);
775 if (style & WS_HSCROLL)
776 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
779 static void test_nonclient_area(HWND hwnd)
781 DWORD style, exstyle;
782 RECT rc_window, rc_client, rc;
784 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
787 style = GetWindowLongA(hwnd, GWL_STYLE);
788 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
789 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
791 GetWindowRect(hwnd, &rc_window);
792 trace("window: (%d,%d)-(%d,%d)\n", rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
793 GetClientRect(hwnd, &rc_client);
794 trace("client: (%d,%d)-(%d,%d)\n", rc_client.left, rc_client.top, rc_client.right, rc_client.bottom);
796 /* avoid some cases when things go wrong */
797 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
798 rc_window.right > 32768 || rc_window.bottom > 32768) return;
800 CopyRect(&rc, &rc_client);
801 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
802 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
804 trace("calc window: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
805 ok(EqualRect(&rc, &rc_window), "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
808 CopyRect(&rc, &rc_window);
809 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
810 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
811 trace("calc client: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
812 ok(EqualRect(&rc, &rc_client), "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
814 /* NULL rectangle shouldn't crash */
815 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
816 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
818 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
822 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
823 SetRect(&rc_client, 0, 0, 250, 150);
824 CopyRect(&rc_window, &rc_client);
825 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
826 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
827 trace("calc window: (%d,%d)-(%d,%d)\n",
828 rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
830 CopyRect(&rc, &rc_window);
831 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
832 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
833 trace("calc client: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
834 ok(EqualRect(&rc, &rc_client), "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
837 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
839 static const char *CBT_code_name[10] = {
850 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
852 trace("CBT: %d (%s), %08lx, %08lx\n", nCode, code_name, wParam, lParam);
854 /* on HCBT_DESTROYWND window state is undefined */
855 if (nCode != HCBT_DESTROYWND && IsWindow((HWND)wParam))
861 /* Win98 actually does check the info.cbSize and doesn't allow
862 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
863 * WinXP do not check it at all.
865 info.cbSize = sizeof(WINDOWINFO);
866 ok(pGetWindowInfo((HWND)wParam, &info), "GetWindowInfo should not fail\n");
867 verify_window_info((HWND)wParam, &info);
875 static const RECT rc_null;
878 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
879 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
880 (HWND)wParam, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
881 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
883 /* WS_VISIBLE should be turned off yet */
884 style = createwnd->lpcs->style & ~WS_VISIBLE;
885 ok(style == GetWindowLongA((HWND)wParam, GWL_STYLE),
886 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
887 GetWindowLongA((HWND)wParam, GWL_STYLE), style);
891 /* Uncomment this once the test succeeds in all cases */
892 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
894 ok(GetParent((HWND)wParam) == hwndMessage,
895 "wrong result from GetParent %p: message window %p\n",
896 GetParent((HWND)wParam), hwndMessage);
899 ok(!GetParent((HWND)wParam), "GetParent should return 0 at this point\n");
901 ok(!GetWindow((HWND)wParam, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
905 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
906 * Win9x still has them set to 0.
908 ok(GetWindow((HWND)wParam, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
909 ok(GetWindow((HWND)wParam, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
911 ok(!GetWindow((HWND)wParam, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
912 ok(!GetWindow((HWND)wParam, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
916 /* Uncomment this once the test succeeds in all cases */
919 ok(pGetAncestor((HWND)wParam, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
920 ok(pGetAncestor((HWND)wParam, GA_ROOT) == (HWND)wParam,
921 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOT), (HWND)wParam);
923 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
924 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == hwndMessage,
925 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
927 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == (HWND)wParam,
928 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOTOWNER), (HWND)wParam);
931 ok(GetWindowRect((HWND)wParam, &rc), "GetWindowRect failed\n");
932 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
933 ok(GetClientRect((HWND)wParam, &rc), "GetClientRect failed\n");
934 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
940 return CallNextHookEx(hhook, nCode, wParam, lParam);
943 static void test_shell_window(void)
947 HMODULE hinst, hUser32;
948 BOOL (WINAPI*SetShellWindow)(HWND);
949 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
950 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
951 HWND shellWindow, nextWnd;
953 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
955 trace("Skipping shell window test on Win9x\n");
959 shellWindow = GetShellWindow();
960 hinst = GetModuleHandle(0);
961 hUser32 = GetModuleHandleA("user32");
963 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
964 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
966 trace("previous shell window: %p\n", shellWindow);
972 SetLastError(0xdeadbeef);
973 ret = DestroyWindow(shellWindow);
974 error = GetLastError();
976 ok(!ret, "DestroyWindow(shellWindow)\n");
977 /* passes on Win XP, but not on Win98 */
978 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
979 "got %u after DestroyWindow(shellWindow)\n", error);
981 /* close old shell instance */
982 GetWindowThreadProcessId(shellWindow, &pid);
983 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
984 ret = TerminateProcess(hProcess, 0);
985 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
986 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
987 CloseHandle(hProcess);
990 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
991 trace("created window 1: %p\n", hwnd1);
993 ret = SetShellWindow(hwnd1);
994 ok(ret, "first call to SetShellWindow(hwnd1)\n");
995 shellWindow = GetShellWindow();
996 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
998 ret = SetShellWindow(hwnd1);
999 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1001 ret = SetShellWindow(0);
1002 error = GetLastError();
1003 /* passes on Win XP, but not on Win98
1004 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1005 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1007 ret = SetShellWindow(hwnd1);
1008 /* passes on Win XP, but not on Win98
1009 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1011 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1012 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
1013 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1015 ret = DestroyWindow(hwnd1);
1016 ok(ret, "DestroyWindow(hwnd1)\n");
1018 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1019 trace("created window 2: %p\n", hwnd2);
1020 ret = SetShellWindow(hwnd2);
1021 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1023 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1024 trace("created window 3: %p\n", hwnd3);
1026 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1027 trace("created window 4: %p\n", hwnd4);
1029 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1030 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1032 ret = SetShellWindow(hwnd4);
1033 ok(ret, "SetShellWindow(hwnd4)\n");
1034 shellWindow = GetShellWindow();
1035 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1037 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1038 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1040 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1041 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1043 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1044 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1046 ret = SetShellWindow(hwnd3);
1047 ok(!ret, "SetShellWindow(hwnd3)\n");
1048 shellWindow = GetShellWindow();
1049 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1051 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1052 trace("created window 5: %p\n", hwnd5);
1053 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1054 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1058 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1059 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1062 /* destroy test windows */
1063 DestroyWindow(hwnd2);
1064 DestroyWindow(hwnd3);
1065 DestroyWindow(hwnd4);
1066 DestroyWindow(hwnd5);
1069 /************** MDI test ****************/
1071 static char mdi_lParam_test_message[] = "just a test string";
1073 static void test_MDI_create(HWND parent, HWND mdi_client, INT first_id)
1075 MDICREATESTRUCTA mdi_cs;
1077 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1078 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1079 BOOL isWin9x = FALSE;
1081 mdi_cs.szClass = "MDI_child_Class_1";
1082 mdi_cs.szTitle = "MDI child";
1083 mdi_cs.hOwner = GetModuleHandle(0);
1084 mdi_cs.x = CW_USEDEFAULT;
1085 mdi_cs.y = CW_USEDEFAULT;
1086 mdi_cs.cx = CW_USEDEFAULT;
1087 mdi_cs.cy = CW_USEDEFAULT;
1089 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1090 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1091 ok(mdi_child != 0, "MDI child creation failed\n");
1092 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1093 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1094 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1096 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1097 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1098 ok(mdi_child != 0, "MDI child creation failed\n");
1099 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1100 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1101 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1103 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1104 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1105 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1107 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1111 ok(mdi_child != 0, "MDI child creation failed\n");
1112 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1113 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1114 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1117 /* test MDICREATESTRUCT A<->W mapping */
1118 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1120 mdi_cs.szClass = (LPCSTR)classW;
1121 mdi_cs.szTitle = (LPCSTR)titleW;
1122 SetLastError(0xdeadbeef);
1123 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1126 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1129 ok(mdi_child != 0, "MDI child creation failed\n");
1133 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1134 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1135 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1138 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1140 CW_USEDEFAULT, CW_USEDEFAULT,
1141 CW_USEDEFAULT, CW_USEDEFAULT,
1142 mdi_client, GetModuleHandle(0),
1143 (LPARAM)mdi_lParam_test_message);
1144 ok(mdi_child != 0, "MDI child creation failed\n");
1145 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1146 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1147 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1149 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1150 0x7fffffff, /* without WS_POPUP */
1151 CW_USEDEFAULT, CW_USEDEFAULT,
1152 CW_USEDEFAULT, CW_USEDEFAULT,
1153 mdi_client, GetModuleHandle(0),
1154 (LPARAM)mdi_lParam_test_message);
1155 ok(mdi_child != 0, "MDI child creation failed\n");
1156 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1157 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1158 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1160 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1161 0xffffffff, /* with WS_POPUP */
1162 CW_USEDEFAULT, CW_USEDEFAULT,
1163 CW_USEDEFAULT, CW_USEDEFAULT,
1164 mdi_client, GetModuleHandle(0),
1165 (LPARAM)mdi_lParam_test_message);
1166 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1168 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1172 ok(mdi_child != 0, "MDI child creation failed\n");
1173 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1174 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1175 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1178 /* test MDICREATESTRUCT A<->W mapping */
1179 SetLastError(0xdeadbeef);
1180 mdi_child = CreateMDIWindowW(classW, titleW,
1182 CW_USEDEFAULT, CW_USEDEFAULT,
1183 CW_USEDEFAULT, CW_USEDEFAULT,
1184 mdi_client, GetModuleHandle(0),
1185 (LPARAM)mdi_lParam_test_message);
1188 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1191 ok(mdi_child != 0, "MDI child creation failed\n");
1195 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1196 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1197 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1200 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1202 CW_USEDEFAULT, CW_USEDEFAULT,
1203 CW_USEDEFAULT, CW_USEDEFAULT,
1204 mdi_client, 0, GetModuleHandle(0),
1205 (LPVOID)mdi_lParam_test_message);
1206 ok(mdi_child != 0, "MDI child creation failed\n");
1207 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1208 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1209 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1211 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1212 0x7fffffff, /* without WS_POPUP */
1213 CW_USEDEFAULT, CW_USEDEFAULT,
1214 CW_USEDEFAULT, CW_USEDEFAULT,
1215 mdi_client, 0, GetModuleHandle(0),
1216 (LPVOID)mdi_lParam_test_message);
1217 ok(mdi_child != 0, "MDI child creation failed\n");
1218 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1219 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1220 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1222 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1223 0xffffffff, /* with WS_POPUP */
1224 CW_USEDEFAULT, CW_USEDEFAULT,
1225 CW_USEDEFAULT, CW_USEDEFAULT,
1226 mdi_client, 0, GetModuleHandle(0),
1227 (LPVOID)mdi_lParam_test_message);
1228 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1230 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1234 ok(mdi_child != 0, "MDI child creation failed\n");
1235 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1236 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1237 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1240 /* test MDICREATESTRUCT A<->W mapping */
1241 SetLastError(0xdeadbeef);
1242 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1244 CW_USEDEFAULT, CW_USEDEFAULT,
1245 CW_USEDEFAULT, CW_USEDEFAULT,
1246 mdi_client, 0, GetModuleHandle(0),
1247 (LPVOID)mdi_lParam_test_message);
1250 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1253 ok(mdi_child != 0, "MDI child creation failed\n");
1257 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1258 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1259 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1262 /* This test fails on Win9x */
1265 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1267 CW_USEDEFAULT, CW_USEDEFAULT,
1268 CW_USEDEFAULT, CW_USEDEFAULT,
1269 parent, 0, GetModuleHandle(0),
1270 (LPVOID)mdi_lParam_test_message);
1271 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1274 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1275 WS_CHILD, /* without WS_POPUP */
1276 CW_USEDEFAULT, CW_USEDEFAULT,
1277 CW_USEDEFAULT, CW_USEDEFAULT,
1278 mdi_client, 0, GetModuleHandle(0),
1279 (LPVOID)mdi_lParam_test_message);
1280 ok(mdi_child != 0, "MDI child creation failed\n");
1281 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1282 DestroyWindow(mdi_child);
1284 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1285 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1286 CW_USEDEFAULT, CW_USEDEFAULT,
1287 CW_USEDEFAULT, CW_USEDEFAULT,
1288 mdi_client, 0, GetModuleHandle(0),
1289 (LPVOID)mdi_lParam_test_message);
1290 ok(mdi_child != 0, "MDI child creation failed\n");
1291 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1292 DestroyWindow(mdi_child);
1294 /* maximized child */
1295 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1296 WS_CHILD | WS_MAXIMIZE,
1297 CW_USEDEFAULT, CW_USEDEFAULT,
1298 CW_USEDEFAULT, CW_USEDEFAULT,
1299 mdi_client, 0, GetModuleHandle(0),
1300 (LPVOID)mdi_lParam_test_message);
1301 ok(mdi_child != 0, "MDI child creation failed\n");
1302 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1303 DestroyWindow(mdi_child);
1305 trace("Creating maximized child with a caption\n");
1306 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1307 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1308 CW_USEDEFAULT, CW_USEDEFAULT,
1309 CW_USEDEFAULT, CW_USEDEFAULT,
1310 mdi_client, 0, GetModuleHandle(0),
1311 (LPVOID)mdi_lParam_test_message);
1312 ok(mdi_child != 0, "MDI child creation failed\n");
1313 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1314 DestroyWindow(mdi_child);
1316 trace("Creating maximized child with a caption and a thick frame\n");
1317 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1318 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1319 CW_USEDEFAULT, CW_USEDEFAULT,
1320 CW_USEDEFAULT, CW_USEDEFAULT,
1321 mdi_client, 0, GetModuleHandle(0),
1322 (LPVOID)mdi_lParam_test_message);
1323 ok(mdi_child != 0, "MDI child creation failed\n");
1324 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1325 DestroyWindow(mdi_child);
1328 /**********************************************************************
1329 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1331 * Note: The rule here is that client rect of the maximized MDI child
1332 * is equal to the client rect of the MDI client window.
1334 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1338 GetClientRect( client, &rect );
1339 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1340 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1342 rect.right -= rect.left;
1343 rect.bottom -= rect.top;
1344 lpMinMax->ptMaxSize.x = rect.right;
1345 lpMinMax->ptMaxSize.y = rect.bottom;
1347 lpMinMax->ptMaxPosition.x = rect.left;
1348 lpMinMax->ptMaxPosition.y = rect.top;
1350 trace("max rect (%d,%d - %d, %d)\n",
1351 rect.left, rect.top, rect.right, rect.bottom);
1354 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1361 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1362 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs->lpCreateParams;
1364 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1365 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1367 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1368 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1369 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1370 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1371 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1373 /* MDICREATESTRUCT should have original values */
1374 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1375 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1376 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1377 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1378 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1379 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1381 /* CREATESTRUCT should have fixed values */
1382 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1383 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1385 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1386 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1387 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1389 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1391 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1393 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1394 ok(cs->style == style,
1395 "cs->style does not match (%08x)\n", cs->style);
1399 LONG style = mdi_cs->style;
1401 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1402 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1403 ok(cs->style == style,
1404 "cs->style does not match (%08x)\n", cs->style);
1409 case WM_GETMINMAXINFO:
1411 HWND client = GetParent(hwnd);
1413 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1414 MINMAXINFO my_minmax;
1415 LONG style, exstyle;
1417 style = GetWindowLongA(hwnd, GWL_STYLE);
1418 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1420 GetWindowRect(client, &rc);
1421 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1422 GetClientRect(client, &rc);
1423 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1424 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1425 GetSystemMetrics(SM_CYSCREEN));
1427 GetClientRect(client, &rc);
1428 if ((style & WS_CAPTION) == WS_CAPTION)
1429 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1430 AdjustWindowRectEx(&rc, style, 0, exstyle);
1431 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1432 dump_minmax_info( minmax );
1434 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1435 minmax->ptMaxSize.x, rc.right - rc.left);
1436 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1437 minmax->ptMaxSize.y, rc.bottom - rc.top);
1439 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1441 trace("DefMDIChildProc returned:\n");
1442 dump_minmax_info( minmax );
1444 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1445 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1446 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1447 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1448 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1453 case WM_MDIACTIVATE:
1455 HWND active, client = GetParent(hwnd);
1456 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1457 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1458 if (hwnd == (HWND)lparam) /* if we are being activated */
1459 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1461 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1465 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1468 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1475 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1477 trace("%s\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE");
1478 trace("x %d, y %d, cx %d, cy %d\n", cs->x, cs->y, cs->cx, cs->cy);
1480 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1481 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1483 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1484 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1486 /* CREATESTRUCT should have fixed values */
1487 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1489 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1490 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1492 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1493 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1494 while Win95, Win2k, WinXP do. */
1495 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1496 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1500 case WM_GETMINMAXINFO:
1502 HWND parent = GetParent(hwnd);
1504 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1505 LONG style, exstyle;
1507 trace("WM_GETMINMAXINFO\n");
1509 style = GetWindowLongA(hwnd, GWL_STYLE);
1510 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1512 GetClientRect(parent, &rc);
1513 trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1515 GetClientRect(parent, &rc);
1516 if ((style & WS_CAPTION) == WS_CAPTION)
1517 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1518 AdjustWindowRectEx(&rc, style, 0, exstyle);
1519 trace("calculated max child window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1520 dump_minmax_info( minmax );
1522 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1523 minmax->ptMaxSize.x, rc.right - rc.left);
1524 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1525 minmax->ptMaxSize.y, rc.bottom - rc.top);
1529 case WM_WINDOWPOSCHANGED:
1531 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1534 GetWindowRect(hwnd, &rc1);
1535 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1536 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1537 /* note: winpos coordinates are relative to parent */
1538 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1539 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1540 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1542 GetWindowRect(hwnd, &rc1);
1543 GetClientRect(hwnd, &rc2);
1544 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1545 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1546 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1549 case WM_WINDOWPOSCHANGING:
1551 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1552 WINDOWPOS my_winpos = *winpos;
1554 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1555 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1556 winpos->hwnd, winpos->hwndInsertAfter,
1557 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1559 DefWindowProcA(hwnd, msg, wparam, lparam);
1561 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1562 winpos->hwnd, winpos->hwndInsertAfter,
1563 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1565 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1566 "DefWindowProc should not change WINDOWPOS values\n");
1571 return DefWindowProcA(hwnd, msg, wparam, lparam);
1574 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1576 static HWND mdi_client;
1582 CLIENTCREATESTRUCT client_cs;
1585 GetClientRect(hwnd, &rc);
1587 client_cs.hWindowMenu = 0;
1588 client_cs.idFirstChild = 1;
1590 /* MDIClient without MDIS_ALLCHILDSTYLES */
1591 mdi_client = CreateWindowExA(0, "mdiclient",
1593 WS_CHILD /*| WS_VISIBLE*/,
1594 /* tests depend on a not zero MDIClient size */
1595 0, 0, rc.right, rc.bottom,
1596 hwnd, 0, GetModuleHandle(0),
1597 (LPVOID)&client_cs);
1599 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1600 DestroyWindow(mdi_client);
1602 /* MDIClient with MDIS_ALLCHILDSTYLES */
1603 mdi_client = CreateWindowExA(0, "mdiclient",
1605 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1606 /* tests depend on a not zero MDIClient size */
1607 0, 0, rc.right, rc.bottom,
1608 hwnd, 0, GetModuleHandle(0),
1609 (LPVOID)&client_cs);
1611 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1612 DestroyWindow(mdi_client);
1616 case WM_WINDOWPOSCHANGED:
1618 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1621 GetWindowRect(hwnd, &rc1);
1622 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1623 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1624 /* note: winpos coordinates are relative to parent */
1625 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1626 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1627 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1629 GetWindowRect(hwnd, &rc1);
1630 GetClientRect(hwnd, &rc2);
1631 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1632 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1633 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1636 case WM_WINDOWPOSCHANGING:
1638 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1639 WINDOWPOS my_winpos = *winpos;
1641 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1642 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1643 winpos->hwnd, winpos->hwndInsertAfter,
1644 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1646 DefWindowProcA(hwnd, msg, wparam, lparam);
1648 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1649 winpos->hwnd, winpos->hwndInsertAfter,
1650 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1652 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1653 "DefWindowProc should not change WINDOWPOS values\n");
1662 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1665 static BOOL mdi_RegisterWindowClasses(void)
1670 cls.lpfnWndProc = mdi_main_wnd_procA;
1673 cls.hInstance = GetModuleHandleA(0);
1675 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1676 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1677 cls.lpszMenuName = NULL;
1678 cls.lpszClassName = "MDI_parent_Class";
1679 if(!RegisterClassA(&cls)) return FALSE;
1681 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1682 cls.lpszClassName = "MDI_child_Class_1";
1683 if(!RegisterClassA(&cls)) return FALSE;
1685 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1686 cls.lpszClassName = "MDI_child_Class_2";
1687 if(!RegisterClassA(&cls)) return FALSE;
1692 static void test_mdi(void)
1697 if (!mdi_RegisterWindowClasses()) assert(0);
1699 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1700 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1701 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1702 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1703 GetDesktopWindow(), 0,
1704 GetModuleHandle(0), NULL);
1705 assert(mdi_hwndMain);
1707 while(GetMessage(&msg, 0, 0, 0))
1709 TranslateMessage(&msg);
1710 DispatchMessage(&msg);
1713 DestroyWindow(mdi_hwndMain);
1716 static void test_icons(void)
1720 HICON icon = LoadIconA(0, (LPSTR)IDI_APPLICATION);
1721 HICON icon2 = LoadIconA(0, (LPSTR)IDI_QUESTION);
1722 HICON small_icon = LoadImageA(0, (LPSTR)IDI_APPLICATION, IMAGE_ICON,
1723 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1726 cls.cbSize = sizeof(cls);
1728 cls.lpfnWndProc = DefWindowProcA;
1732 cls.hIcon = LoadIconA(0, (LPSTR)IDI_HAND);
1733 cls.hIconSm = small_icon;
1734 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1735 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1736 cls.lpszMenuName = NULL;
1737 cls.lpszClassName = "IconWindowClass";
1739 RegisterClassExA(&cls);
1741 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1742 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1745 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1746 ok( res == 0, "wrong big icon %p/0\n", res );
1747 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1748 ok( res == 0, "wrong previous big icon %p/0\n", res );
1749 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1750 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1751 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1752 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1753 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1754 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1756 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1757 ok( res == 0, "wrong small icon %p/0\n", res );
1758 /* this test is XP specific */
1759 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1760 ok( res != 0, "wrong small icon %p\n", res );*/
1761 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1762 ok( res == 0, "wrong previous small icon %p/0\n", res );
1763 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1764 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1765 /* this test is XP specific */
1766 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1767 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1768 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1769 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1770 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1771 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1772 /* this test is XP specific */
1773 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1774 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1776 /* make sure the big icon hasn't changed */
1777 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1778 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1780 DestroyWindow( hwnd );
1783 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1785 if (msg == WM_NCCALCSIZE)
1787 RECT *rect = (RECT *)lparam;
1788 /* first time around increase the rectangle, next time decrease it */
1789 if (rect->left == 100) InflateRect( rect, 10, 10 );
1790 else InflateRect( rect, -10, -10 );
1793 return DefWindowProc( hwnd, msg, wparam, lparam );
1796 static void test_SetWindowPos(HWND hwnd)
1798 RECT orig_win_rc, rect;
1800 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1802 SetRect(&rect, 111, 222, 333, 444);
1803 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1804 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1805 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1807 SetRect(&rect, 111, 222, 333, 444);
1808 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1809 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1810 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1812 GetWindowRect(hwnd, &orig_win_rc);
1814 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1815 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1816 GetWindowRect( hwnd, &rect );
1817 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1818 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1819 GetClientRect( hwnd, &rect );
1820 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1821 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1822 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1824 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1825 GetWindowRect( hwnd, &rect );
1826 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1827 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1828 GetClientRect( hwnd, &rect );
1829 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1830 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1831 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1833 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1834 orig_win_rc.right, orig_win_rc.bottom, 0);
1835 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1837 /* Win9x truncates coordinates to 16-bit irrespectively */
1840 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1841 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1843 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1844 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1847 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1848 orig_win_rc.right, orig_win_rc.bottom, 0);
1850 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1851 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1852 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1853 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1854 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1855 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1856 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1859 static void test_SetMenu(HWND parent)
1863 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1867 hMenu = CreateMenu();
1870 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1873 /* fails on (at least) Wine, NT4, XP SP2 */
1874 test_nonclient_area(parent);
1876 ret = GetMenu(parent);
1877 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1878 /* test whether we can destroy a menu assigned to a window */
1879 retok = DestroyMenu(hMenu);
1880 ok( retok, "DestroyMenu error %d\n", GetLastError());
1881 retok = IsMenu(hMenu);
1882 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
1883 ret = GetMenu(parent);
1884 /* This test fails on Win9x */
1886 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1887 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1888 test_nonclient_area(parent);
1890 hMenu = CreateMenu();
1894 ret = GetMenu(parent);
1895 ok(ret == 0, "unexpected menu id %p\n", ret);
1897 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1898 test_nonclient_area(parent);
1899 ret = GetMenu(parent);
1900 ok(ret == 0, "unexpected menu id %p\n", ret);
1902 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1905 /* fails on (at least) Wine, NT4, XP SP2 */
1906 test_nonclient_area(parent);
1908 ret = GetMenu(parent);
1909 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1911 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1912 test_nonclient_area(parent);
1913 ret = GetMenu(parent);
1914 ok(ret == 0, "unexpected menu id %p\n", ret);
1917 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1920 ret = GetMenu(child);
1921 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1923 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1924 test_nonclient_area(child);
1925 ret = GetMenu(child);
1926 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1928 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1929 test_nonclient_area(child);
1930 ret = GetMenu(child);
1931 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1933 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1934 test_nonclient_area(child);
1935 ret = GetMenu(child);
1936 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1938 style = GetWindowLong(child, GWL_STYLE);
1939 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
1940 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
1941 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
1942 SetWindowLong(child, GWL_STYLE, style);
1944 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
1945 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
1946 SetWindowLong(child, GWL_STYLE, style);
1948 DestroyWindow(child);
1952 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1954 HWND child[5], hwnd;
1959 hwnd = GetWindow(parent, GW_CHILD);
1960 ok(!hwnd, "have to start without children to perform the test\n");
1962 for (i = 0; i < total; i++)
1964 if (style[i] & DS_CONTROL)
1966 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
1967 0,0,0,0, parent, (HMENU)i, 0, NULL);
1968 if (style[i] & WS_VISIBLE)
1969 ShowWindow(child[i], SW_SHOW);
1971 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
1974 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
1975 parent, (HMENU)i, 0, NULL);
1976 trace("child[%d] = %p\n", i, child[i]);
1977 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
1980 hwnd = GetWindow(parent, GW_CHILD);
1981 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
1982 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
1983 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
1985 for (i = 0; i < total; i++)
1987 trace("hwnd[%d] = %p\n", i, hwnd);
1988 ok(child[order[i]] == hwnd, "Z order of child #%d is wrong\n", i);
1990 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1993 for (i = 0; i < total; i++)
1994 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
1997 static void test_children_zorder(HWND parent)
1999 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2001 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2003 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2004 WS_CHILD | WS_VISIBLE, WS_CHILD,
2005 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2006 const int complex_order_1[1] = { 0 };
2007 const int complex_order_2[2] = { 1, 0 };
2008 const int complex_order_3[3] = { 1, 0, 2 };
2009 const int complex_order_4[4] = { 1, 0, 2, 3 };
2010 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2011 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2012 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2013 WS_CHILD | WS_VISIBLE };
2014 const int complex_order_6[3] = { 0, 1, 2 };
2016 /* simple WS_CHILD */
2017 test_window_tree(parent, simple_style, simple_order, 5);
2019 /* complex children styles */
2020 test_window_tree(parent, complex_style, complex_order_1, 1);
2021 test_window_tree(parent, complex_style, complex_order_2, 2);
2022 test_window_tree(parent, complex_style, complex_order_3, 3);
2023 test_window_tree(parent, complex_style, complex_order_4, 4);
2024 test_window_tree(parent, complex_style, complex_order_5, 5);
2026 /* another set of complex children styles */
2027 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2030 #define check_z_order(hwnd, next, prev, owner, topmost) \
2031 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2034 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2035 BOOL topmost, const char *file, int line)
2040 test = GetWindow(hwnd, GW_HWNDNEXT);
2041 /* skip foreign windows */
2042 while (test && (GetWindowThreadProcessId(test, NULL) != our_pid ||
2043 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0)))
2045 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2046 test = GetWindow(test, GW_HWNDNEXT);
2048 ok_(file, line)(next == test, "expected next %p, got %p\n", next, test);
2050 test = GetWindow(hwnd, GW_HWNDPREV);
2051 /* skip foreign windows */
2052 while (test && (GetWindowThreadProcessId(test, NULL) != our_pid ||
2053 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0)))
2055 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2056 test = GetWindow(test, GW_HWNDPREV);
2058 ok_(file, line)(prev == test, "expected prev %p, got %p\n", prev, test);
2060 test = GetWindow(hwnd, GW_OWNER);
2061 ok_(file, line)(owner == test, "expected owner %p, got %p\n", owner, test);
2063 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2064 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "expected %stopmost\n", topmost ? "" : "NOT ");
2067 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E)
2069 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2071 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2073 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2075 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2076 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2078 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2079 WS_OVERLAPPED | WS_CAPTION,
2081 0, 0, GetModuleHandle(0), NULL);
2082 trace("hwnd_F %p\n", hwnd_F);
2083 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2085 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2086 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2087 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2088 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2090 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2093 hwnd_F, 0, GetModuleHandle(0), NULL);
2094 trace("hwnd_C %p\n", hwnd_C);
2095 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2096 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2097 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2098 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2100 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2103 hwnd_F, 0, GetModuleHandle(0), NULL);
2104 trace("hwnd_B %p\n", hwnd_B);
2105 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2106 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2107 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2108 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2109 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2111 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2114 0, 0, GetModuleHandle(0), NULL);
2115 trace("hwnd_A %p\n", hwnd_A);
2116 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2117 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2118 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2119 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2120 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2121 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2123 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);
2125 /* move hwnd_F and its popups up */
2126 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2127 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2128 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2129 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2130 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2131 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2132 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2134 /* move hwnd_F and its popups down */
2135 #if 0 /* enable once Wine is fixed to pass this test */
2136 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2137 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2138 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2139 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2140 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2141 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2142 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2145 DestroyWindow(hwnd_A);
2146 DestroyWindow(hwnd_B);
2147 DestroyWindow(hwnd_C);
2148 DestroyWindow(hwnd_F);
2151 static void test_vis_rgn( HWND hwnd )
2153 RECT win_rect, rgn_rect;
2154 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2157 ShowWindow(hwnd,SW_SHOW);
2158 hdc = GetDC( hwnd );
2159 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2160 GetWindowRect( hwnd, &win_rect );
2161 GetRgnBox( hrgn, &rgn_rect );
2162 if (GetVersion() & 0x80000000)
2164 trace("win9x, mapping to screen coords\n");
2165 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2167 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2168 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2169 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2170 rgn_rect.left, win_rect.left );
2171 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2172 rgn_rect.top, win_rect.top );
2173 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2174 rgn_rect.right, win_rect.right );
2175 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2176 rgn_rect.bottom, win_rect.bottom );
2177 ReleaseDC( hwnd, hdc );
2180 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2182 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2184 HWND child = GetWindow(hwnd, GW_CHILD);
2185 ok(child != 0, "couldn't find child window\n");
2187 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2190 return DefWindowProc(hwnd, msg, wp, lp);
2193 static void test_SetFocus(HWND hwnd)
2196 WNDPROC old_wnd_proc;
2198 /* check if we can set focus to non-visible windows */
2200 ShowWindow(hwnd, SW_SHOW);
2203 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2204 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2205 ShowWindow(hwnd, SW_HIDE);
2208 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2209 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2210 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2213 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2214 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2215 ShowWindow(child, SW_SHOW);
2216 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2217 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2218 ShowWindow(child, SW_HIDE);
2219 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2220 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2221 ShowWindow(child, SW_SHOW);
2223 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2224 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2225 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2227 ShowWindow(child, SW_HIDE);
2229 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2230 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2231 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2232 ShowWindow(child, SW_HIDE);
2233 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2235 ShowWindow(hwnd, SW_SHOW);
2236 ShowWindow(child, SW_SHOW);
2238 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2239 EnableWindow(hwnd, FALSE);
2240 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2241 EnableWindow(hwnd, TRUE);
2243 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2244 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2245 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2247 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2248 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2249 ShowWindow(hwnd, SW_RESTORE);
2250 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2251 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2252 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2253 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2254 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2256 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2257 old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2258 ShowWindow(hwnd, SW_RESTORE);
2259 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2261 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2263 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2265 DestroyWindow( child );
2268 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
2269 static void check_wnd_state_(const char *file, int line,
2270 HWND active, HWND foreground, HWND focus, HWND capture)
2272 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2273 if (foreground && GetForegroundWindow())
2274 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2275 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2276 ok_(file, line)(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2279 static void test_SetActiveWindow(HWND hwnd)
2283 flush_events( TRUE );
2284 ShowWindow(hwnd, SW_HIDE);
2287 check_wnd_state(0, 0, 0, 0);
2289 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2291 ShowWindow(hwnd, SW_SHOW);
2292 check_wnd_state(hwnd, hwnd, hwnd, 0);
2294 hwnd2 = SetActiveWindow(0);
2295 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2296 check_wnd_state(0, 0, 0, 0);
2298 hwnd2 = SetActiveWindow(hwnd);
2299 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2300 check_wnd_state(hwnd, hwnd, hwnd, 0);
2302 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2303 check_wnd_state(hwnd, hwnd, hwnd, 0);
2305 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2306 check_wnd_state(hwnd, hwnd, hwnd, 0);
2308 ShowWindow(hwnd, SW_HIDE);
2309 check_wnd_state(0, 0, 0, 0);
2311 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2312 SetActiveWindow(hwnd);
2313 check_wnd_state(hwnd, hwnd, hwnd, 0);
2315 ShowWindow(hwnd, SW_SHOW);
2316 check_wnd_state(hwnd, hwnd, hwnd, 0);
2318 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2319 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2321 DestroyWindow(hwnd2);
2322 check_wnd_state(hwnd, hwnd, hwnd, 0);
2324 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2325 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2327 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2328 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2330 DestroyWindow(hwnd2);
2331 check_wnd_state(hwnd, hwnd, hwnd, 0);
2334 static void test_SetForegroundWindow(HWND hwnd)
2339 flush_events( TRUE );
2340 ShowWindow(hwnd, SW_HIDE);
2343 check_wnd_state(0, 0, 0, 0);
2345 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2347 ShowWindow(hwnd, SW_SHOW);
2348 check_wnd_state(hwnd, hwnd, hwnd, 0);
2350 hwnd2 = SetActiveWindow(0);
2351 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2352 check_wnd_state(0, 0, 0, 0);
2354 ret = SetForegroundWindow(hwnd);
2355 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2356 check_wnd_state(hwnd, hwnd, hwnd, 0);
2358 SetLastError(0xdeadbeef);
2359 ret = SetForegroundWindow(0);
2360 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2361 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2362 check_wnd_state(hwnd, hwnd, hwnd, 0);
2364 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2365 check_wnd_state(hwnd, hwnd, hwnd, 0);
2367 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2368 check_wnd_state(hwnd, hwnd, hwnd, 0);
2370 hwnd2 = GetForegroundWindow();
2371 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2372 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2373 hwnd2 = GetForegroundWindow();
2374 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2376 ShowWindow(hwnd, SW_HIDE);
2377 check_wnd_state(0, 0, 0, 0);
2379 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2380 ret = SetForegroundWindow(hwnd);
2381 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2382 check_wnd_state(hwnd, hwnd, hwnd, 0);
2384 ShowWindow(hwnd, SW_SHOW);
2385 check_wnd_state(hwnd, hwnd, hwnd, 0);
2387 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2388 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2390 DestroyWindow(hwnd2);
2391 check_wnd_state(hwnd, hwnd, hwnd, 0);
2393 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2394 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2396 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2397 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2399 DestroyWindow(hwnd2);
2400 check_wnd_state(hwnd, hwnd, hwnd, 0);
2403 static WNDPROC old_button_proc;
2405 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2410 key_state = GetKeyState(VK_LBUTTON);
2411 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2413 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2415 if (msg == WM_LBUTTONDOWN)
2419 check_wnd_state(button, button, button, button);
2421 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2423 trace("hwnd %p\n", hwnd);
2425 check_wnd_state(button, button, button, button);
2427 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2429 check_wnd_state(button, button, button, button);
2431 DestroyWindow(hwnd);
2433 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2435 trace("hwnd %p\n", hwnd);
2437 check_wnd_state(button, button, button, button);
2439 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2440 * match internal button state.
2442 SendMessage(button, WM_KILLFOCUS, 0, 0);
2443 check_wnd_state(button, button, button, 0);
2445 ShowWindow(hwnd, SW_SHOW);
2446 check_wnd_state(hwnd, hwnd, hwnd, 0);
2448 capture = SetCapture(hwnd);
2449 ok(capture == 0, "SetCapture() = %p\n", capture);
2451 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2453 DestroyWindow(hwnd);
2455 check_wnd_state(button, 0, button, 0);
2461 static void test_capture_1(void)
2463 HWND button, capture, oldFocus, oldActive;
2465 oldFocus = GetFocus();
2466 oldActive = GetActiveWindow();
2468 capture = GetCapture();
2469 ok(capture == 0, "GetCapture() = %p\n", capture);
2471 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2473 trace("button %p\n", button);
2475 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2477 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2479 capture = SetCapture(button);
2480 ok(capture == 0, "SetCapture() = %p\n", capture);
2481 check_wnd_state(button, 0, button, button);
2483 DestroyWindow(button);
2484 check_wnd_state(oldActive, 0, oldFocus, 0);
2487 static void test_capture_2(void)
2489 HWND button, hwnd, capture, oldFocus, oldActive;
2491 oldFocus = GetFocus();
2492 oldActive = GetActiveWindow();
2493 check_wnd_state(oldActive, 0, oldFocus, 0);
2495 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2497 trace("button %p\n", button);
2499 check_wnd_state(button, button, button, 0);
2501 capture = SetCapture(button);
2502 ok(capture == 0, "SetCapture() = %p\n", capture);
2504 check_wnd_state(button, button, button, button);
2506 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2507 * internal button state.
2509 SendMessage(button, WM_KILLFOCUS, 0, 0);
2510 check_wnd_state(button, button, button, button);
2512 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2514 trace("hwnd %p\n", hwnd);
2516 check_wnd_state(button, button, button, button);
2518 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2520 check_wnd_state(button, button, button, button);
2522 DestroyWindow(hwnd);
2524 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2526 trace("hwnd %p\n", hwnd);
2528 check_wnd_state(button, button, button, button);
2530 ShowWindow(hwnd, SW_SHOW);
2532 check_wnd_state(hwnd, hwnd, hwnd, button);
2534 capture = SetCapture(hwnd);
2535 ok(capture == button, "SetCapture() = %p\n", capture);
2537 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2539 DestroyWindow(hwnd);
2540 check_wnd_state(button, button, button, 0);
2542 DestroyWindow(button);
2543 check_wnd_state(oldActive, 0, oldFocus, 0);
2546 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2550 ShowWindow(hwnd1, SW_HIDE);
2551 ShowWindow(hwnd2, SW_HIDE);
2553 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2554 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2557 check_wnd_state(0, 0, 0, hwnd1);
2560 check_wnd_state(0, 0, 0, hwnd2);
2562 ShowWindow(hwnd1, SW_SHOW);
2563 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2565 ret = ReleaseCapture();
2566 ok (ret, "releasecapture did not return TRUE.\n");
2567 ret = ReleaseCapture();
2568 ok (ret, "releasecapture did not return TRUE after second try.\n");
2571 static void test_keyboard_input(HWND hwnd)
2576 flush_events( TRUE );
2577 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
2579 flush_events( TRUE );
2581 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2584 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2586 flush_events( TRUE );
2588 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2589 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2590 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2591 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2592 ok( !ret, "message %04x available\n", msg.message);
2594 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2596 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2597 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2598 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2599 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2600 ok( !ret, "message %04x available\n", msg.message);
2602 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2604 keybd_event(VK_SPACE, 0, 0, 0);
2605 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2606 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2607 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2608 ok( !ret, "message %04x available\n", msg.message);
2611 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2613 flush_events( TRUE );
2615 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2616 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2617 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2618 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2619 ok( !ret, "message %04x available\n", msg.message);
2621 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2623 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2624 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2625 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2626 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2627 ok( !ret, "message %04x available\n", msg.message);
2629 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2631 keybd_event(VK_SPACE, 0, 0, 0);
2632 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2633 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2634 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2635 ok( !ret, "message %04x available\n", msg.message);
2638 static void test_mouse_input(HWND hwnd)
2648 ShowWindow(hwnd, SW_SHOW);
2651 GetWindowRect(hwnd, &rc);
2652 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2654 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2655 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2658 ShowWindow(popup, SW_SHOW);
2659 UpdateWindow(popup);
2661 GetWindowRect(popup, &rc);
2662 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2664 x = rc.left + (rc.right - rc.left) / 2;
2665 y = rc.top + (rc.bottom - rc.top) / 2;
2666 trace("setting cursor to (%d,%d)\n", x, y);
2670 ok(x == pt.x && y == pt.y, "wrong cursor pos (%d,%d), expected (%d,%d)\n", pt.x, pt.y, x, y);
2672 flush_events( TRUE );
2674 /* Check that setting the same position may generate WM_MOUSEMOVE */
2678 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2679 while (ret && msg.message >= 0xc000); /* skip registered messages */
2682 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
2683 msg.hwnd, msg.message);
2684 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
2685 x, y, msg.pt.x, msg.pt.y);
2688 /* force the system to update its internal queue mouse position,
2689 * otherwise it won't generate relative mouse movements below.
2691 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2692 flush_events( TRUE );
2695 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2696 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2697 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2699 if (msg.message >= 0xc000) continue; /* skip registered messages */
2700 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
2701 "hwnd %p message %04x\n", msg.hwnd, msg.message);
2703 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2704 ok( !ret, "message %04x available\n", msg.message);
2706 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2707 ShowWindow(popup, SW_HIDE);
2709 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2710 while (msg.message >= 0xc000); /* skip registered messages */
2711 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2712 flush_events( TRUE );
2714 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2715 ShowWindow(hwnd, SW_HIDE);
2717 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2718 while (ret && msg.message >= 0xc000); /* skip registered messages */
2719 ok( !ret, "message %04x available\n", msg.message);
2720 flush_events( TRUE );
2722 /* test mouse clicks */
2724 ShowWindow(hwnd, SW_SHOW);
2725 flush_events( TRUE );
2726 ShowWindow(popup, SW_SHOW);
2727 flush_events( TRUE );
2729 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2730 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2731 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2732 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2734 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2735 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2736 msg.hwnd, popup, msg.message);
2737 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2738 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2739 msg.hwnd, popup, msg.message);
2741 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2742 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2743 msg.hwnd, popup, msg.message);
2744 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2745 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2746 msg.hwnd, popup, msg.message);
2748 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2749 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
2750 msg.hwnd, popup, msg.message);
2751 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2752 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
2753 msg.hwnd, popup, msg.message);
2755 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2756 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2757 msg.hwnd, popup, msg.message);
2758 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2759 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2760 msg.hwnd, popup, msg.message);
2762 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2763 ok(!ret, "message %04x available\n", msg.message);
2765 ShowWindow(popup, SW_HIDE);
2766 flush_events( TRUE );
2768 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2769 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2770 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2771 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2773 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2774 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2775 msg.hwnd, hwnd, msg.message);
2776 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2777 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2778 msg.hwnd, hwnd, msg.message);
2780 test_lbuttondown_flag = TRUE;
2781 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
2782 test_lbuttondown_flag = FALSE;
2785 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2786 while (msg.message >= 0xc000); /* skip registered messages */
2787 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2788 msg.hwnd, popup, msg.message);
2789 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2790 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2791 msg.hwnd, popup, msg.message);
2792 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2794 /* Test WM_MOUSEACTIVATE */
2795 #define TEST_MOUSEACTIVATE(A,B) \
2796 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2797 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2799 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
2800 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
2801 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
2802 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
2803 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
2804 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
2805 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
2806 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
2807 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
2808 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
2809 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
2810 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
2811 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
2812 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
2813 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
2814 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
2815 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
2816 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
2817 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
2818 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
2819 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
2820 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
2821 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
2822 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
2824 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2825 flush_events( TRUE );
2827 DestroyWindow(popup);
2830 static void test_validatergn(HWND hwnd)
2836 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
2837 ShowWindow(hwnd, SW_SHOW);
2838 UpdateWindow( hwnd);
2839 /* test that ValidateRect validates children*/
2840 InvalidateRect( child, NULL, 1);
2841 GetWindowRect( child, &rc);
2842 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2843 ret = GetUpdateRect( child, &rc2, 0);
2844 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
2845 "Update rectangle is empty!\n");
2846 ValidateRect( hwnd, &rc);
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);
2852 /* now test ValidateRgn */
2853 InvalidateRect( child, NULL, 1);
2854 GetWindowRect( child, &rc);
2855 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2856 rgn = CreateRectRgnIndirect( &rc);
2857 ValidateRgn( hwnd, rgn);
2858 ret = GetUpdateRect( child, &rc2, 0);
2859 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2860 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2861 rc2.right, rc2.bottom);
2864 DestroyWindow( child );
2867 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
2869 MoveWindow( hwnd, 0, 0, x, y, 0);
2870 GetWindowRect( hwnd, prc);
2871 trace("window rect is %d,%d - %d,%d\n",
2872 prc->left,prc->top,prc->right,prc->bottom);
2873 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
2874 trace("nccalc rect is %d,%d - %d,%d\n",
2875 prc->left,prc->top,prc->right,prc->bottom);
2878 static void test_nccalcscroll(HWND parent)
2881 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
2882 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
2883 HWND hwnd = CreateWindowExA(0, "static", NULL,
2884 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
2885 10, 10, 200, 200, parent, 0, 0, NULL);
2886 ShowWindow( parent, SW_SHOW);
2887 UpdateWindow( parent);
2889 /* test window too low for a horizontal scroll bar */
2890 nccalchelper( hwnd, 100, sbheight, &rc1);
2891 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
2892 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
2894 /* test window just high enough for a horizontal scroll bar */
2895 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
2896 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
2897 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2899 /* test window too narrow for a vertical scroll bar */
2900 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
2901 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
2902 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2904 /* test window just wide enough for a vertical scroll bar */
2905 nccalchelper( hwnd, sbwidth, 100, &rc1);
2906 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
2907 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
2909 /* same test, but with client edge: not enough width */
2910 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
2911 nccalchelper( hwnd, sbwidth, 100, &rc1);
2912 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
2913 "Width should be %d size is %d,%d - %d,%d\n",
2914 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
2916 DestroyWindow( hwnd);
2919 static void test_SetParent(void)
2922 HWND desktop = GetDesktopWindow();
2924 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
2925 HWND parent, child1, child2, child3, child4, sibling;
2927 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2928 100, 100, 200, 200, 0, 0, 0, NULL);
2929 assert(parent != 0);
2930 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2931 0, 0, 50, 50, parent, 0, 0, NULL);
2932 assert(child1 != 0);
2933 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2934 0, 0, 50, 50, child1, 0, 0, NULL);
2935 assert(child2 != 0);
2936 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2937 0, 0, 50, 50, child2, 0, 0, NULL);
2938 assert(child3 != 0);
2939 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2940 0, 0, 50, 50, child3, 0, 0, NULL);
2941 assert(child4 != 0);
2943 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2944 parent, child1, child2, child3, child4);
2946 check_parents(parent, desktop, 0, 0, 0, parent, parent);
2947 check_parents(child1, parent, parent, parent, 0, parent, parent);
2948 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2949 check_parents(child3, child2, child2, child2, 0, child2, parent);
2950 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2952 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
2953 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
2954 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2955 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
2956 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2958 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
2959 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2960 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
2961 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
2962 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
2963 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
2964 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
2965 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
2966 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2968 if (!is_win9x) /* Win9x doesn't survive this test */
2970 ok(!SetParent(parent, child1), "SetParent should fail\n");
2971 ok(!SetParent(child2, child3), "SetParent should fail\n");
2972 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
2973 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
2974 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
2975 ok(!SetParent(child2, parent), "SetParent should fail\n");
2976 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
2978 check_parents(parent, child4, child4, 0, 0, child4, parent);
2979 check_parents(child1, parent, parent, parent, 0, child4, parent);
2980 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2981 check_parents(child3, child2, child2, child2, 0, child2, parent);
2982 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2985 hMenu = CreateMenu();
2986 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2987 100, 100, 200, 200, 0, hMenu, 0, NULL);
2988 assert(sibling != 0);
2990 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
2991 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
2993 ret = DestroyWindow(parent);
2994 ok( ret, "DestroyWindow() error %d\n", GetLastError());
2996 ok(!IsWindow(parent), "parent still exists\n");
2997 ok(!IsWindow(sibling), "sibling still exists\n");
2998 ok(!IsWindow(child1), "child1 still exists\n");
2999 ok(!IsWindow(child2), "child2 still exists\n");
3000 ok(!IsWindow(child3), "child3 still exists\n");
3001 ok(!IsWindow(child4), "child4 still exists\n");
3004 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3006 LPCREATESTRUCT lpcs;
3013 lpcs = (LPCREATESTRUCT)lparam;
3014 lpss = (LPSTYLESTRUCT)lpcs->lpCreateParams;
3017 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
3018 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
3019 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
3020 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
3022 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3024 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
3025 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
3026 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
3028 ok(lpss->styleNew == lpcs->style,
3029 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3030 lpss->styleNew, lpcs->style);
3034 return DefWindowProc(hwnd, msg, wparam, lparam);
3037 static ATOM atomStyleCheckClass;
3039 static void register_style_check_class(void)
3047 GetModuleHandle(NULL),
3049 LoadCursor(NULL, IDC_ARROW),
3050 (HBRUSH)(COLOR_BTNFACE+1),
3052 TEXT("WineStyleCheck"),
3055 atomStyleCheckClass = RegisterClass(&wc);
3058 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3060 DWORD dwActualStyle;
3061 DWORD dwActualExStyle;
3064 HWND hwndParent = NULL;
3066 ss.styleNew = dwStyleIn;
3067 ss.styleOld = dwExStyleIn;
3069 if (dwStyleIn & WS_CHILD)
3071 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
3072 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3075 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
3076 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3079 flush_events( TRUE );
3081 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3082 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3083 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3084 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3085 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3087 DestroyWindow(hwnd);
3088 if (hwndParent) DestroyWindow(hwndParent);
3091 /* tests what window styles the window manager automatically adds */
3092 static void test_window_styles(void)
3094 register_style_check_class();
3096 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3097 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3098 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3099 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3100 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3101 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3102 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3103 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3104 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3105 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3106 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3109 static void test_scrollvalidate( HWND parent)
3112 HRGN hrgn=CreateRectRgn(0,0,0,0);
3113 HRGN exprgn, tmprgn, clipping;
3114 RECT rc, rcu, cliprc;
3115 /* create two overlapping child windows. The visual region
3116 * of hwnd1 is clipped by the overlapping part of
3117 * hwnd2 because of the WS_CLIPSIBLING style */
3120 clipping = CreateRectRgn(0,0,0,0);
3121 tmprgn = CreateRectRgn(0,0,0,0);
3122 exprgn = CreateRectRgn(0,0,0,0);
3123 hwnd2 = CreateWindowExA(0, "static", NULL,
3124 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3125 75, 30, 100, 100, parent, 0, 0, NULL);
3126 hwnd1 = CreateWindowExA(0, "static", NULL,
3127 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3128 25, 50, 100, 100, parent, 0, 0, NULL);
3129 ShowWindow( parent, SW_SHOW);
3130 UpdateWindow( parent);
3131 GetClientRect( hwnd1, &rc);
3133 SetRectRgn( clipping, 10, 10, 90, 90);
3134 hdc = GetDC( hwnd1);
3135 /* for a visual touch */
3136 TextOut( hdc, 0,10, "0123456789", 10);
3137 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3138 if (winetest_debug > 0) dump_region(hrgn);
3139 /* create a region with what is expected */
3140 SetRectRgn( exprgn, 39,0,49,74);
3141 SetRectRgn( tmprgn, 88,79,98,93);
3142 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3143 SetRectRgn( tmprgn, 0,93,98,98);
3144 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3145 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3146 trace("update rect is %d,%d - %d,%d\n",
3147 rcu.left,rcu.top,rcu.right,rcu.bottom);
3148 /* now with clipping region */
3149 SelectClipRgn( hdc, clipping);
3150 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3151 if (winetest_debug > 0) dump_region(hrgn);
3152 /* create a region with what is expected */
3153 SetRectRgn( exprgn, 39,10,49,74);
3154 SetRectRgn( tmprgn, 80,79,90,85);
3155 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3156 SetRectRgn( tmprgn, 10,85,90,90);
3157 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3158 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3159 trace("update rect is %d,%d - %d,%d\n",
3160 rcu.left,rcu.top,rcu.right,rcu.bottom);
3161 ReleaseDC( hwnd1, hdc);
3163 /* test scrolling a window with an update region */
3164 DestroyWindow( hwnd2);
3165 ValidateRect( hwnd1, NULL);
3166 SetRect( &rc, 40,40, 50,50);
3167 InvalidateRect( hwnd1, &rc, 1);
3168 GetClientRect( hwnd1, &rc);
3170 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
3171 SW_SCROLLCHILDREN | SW_INVALIDATE);
3172 if (winetest_debug > 0) dump_region(hrgn);
3173 SetRectRgn( exprgn, 88,0,98,98);
3174 SetRectRgn( tmprgn, 30, 40, 50, 50);
3175 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3176 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3178 /* clear an update region */
3179 UpdateWindow( hwnd1 );
3181 SetRect( &rc, 0,40, 100,60);
3182 SetRect( &cliprc, 0,0, 100,100);
3183 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3184 if (winetest_debug > 0) dump_region( hrgn );
3185 SetRectRgn( exprgn, 0, 40, 98, 60 );
3186 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
3188 /* now test ScrollWindowEx with a combination of
3189 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3190 /* make hwnd2 the child of hwnd1 */
3191 hwnd2 = CreateWindowExA(0, "static", NULL,
3192 WS_CHILD| WS_VISIBLE | WS_BORDER ,
3193 50, 50, 100, 100, hwnd1, 0, 0, NULL);
3194 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
3195 GetClientRect( hwnd1, &rc);
3198 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3199 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3200 ValidateRect( hwnd1, NULL);
3201 ValidateRect( hwnd2, NULL);
3202 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
3203 SW_SCROLLCHILDREN | SW_INVALIDATE);
3204 if (winetest_debug > 0) dump_region(hrgn);
3205 SetRectRgn( exprgn, 88,0,98,88);
3206 SetRectRgn( tmprgn, 0,88,98,98);
3207 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3208 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3210 /* SW_SCROLLCHILDREN */
3211 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3212 ValidateRect( hwnd1, NULL);
3213 ValidateRect( hwnd2, NULL);
3214 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3215 if (winetest_debug > 0) dump_region(hrgn);
3216 /* expected region is the same as in previous test */
3217 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3219 /* no SW_SCROLLCHILDREN */
3220 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3221 ValidateRect( hwnd1, NULL);
3222 ValidateRect( hwnd2, NULL);
3223 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3224 if (winetest_debug > 0) dump_region(hrgn);
3225 /* expected region is the same as in previous test */
3226 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3228 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3229 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3230 ValidateRect( hwnd1, NULL);
3231 ValidateRect( hwnd2, NULL);
3232 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3233 if (winetest_debug > 0) dump_region(hrgn);
3234 SetRectRgn( exprgn, 88,0,98,20);
3235 SetRectRgn( tmprgn, 20,20,98,30);
3236 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3237 SetRectRgn( tmprgn, 20,30,30,88);
3238 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3239 SetRectRgn( tmprgn, 0,88,30,98);
3240 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3241 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3244 DeleteObject( hrgn);
3245 DeleteObject( exprgn);
3246 DeleteObject( tmprgn);
3247 DestroyWindow( hwnd1);
3248 DestroyWindow( hwnd2);
3251 /* couple of tests of return values of scrollbar functions
3252 * called on a scrollbarless window */
3253 static void test_scroll(void)
3258 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3259 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3260 100, 100, 200, 200, 0, 0, 0, NULL);
3262 ret = GetScrollRange( hwnd, SB_HORZ, &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_HORZ, &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 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3274 ok( ret, "GetScrollRange returns FALSE\n");
3275 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3276 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3277 si.cbSize = sizeof( si);
3278 si.fMask = SIF_PAGE;
3279 si.nPage = 0xdeadbeef;
3280 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3281 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3282 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3284 DestroyWindow( hwnd);
3287 static void test_scrolldc( HWND parent)
3290 HRGN exprgn, tmprgn, hrgn;
3291 RECT rc, rc2, rcu, cliprc;
3295 hrgn = CreateRectRgn(0,0,0,0);
3296 tmprgn = CreateRectRgn(0,0,0,0);
3297 exprgn = CreateRectRgn(0,0,0,0);
3299 hwnd1 = CreateWindowExA(0, "static", NULL,
3300 WS_CHILD| WS_VISIBLE,
3301 25, 50, 100, 100, parent, 0, 0, NULL);
3302 ShowWindow( parent, SW_SHOW);
3303 UpdateWindow( parent);
3304 flush_events( TRUE );
3305 GetClientRect( hwnd1, &rc);
3306 hdc = GetDC( hwnd1);
3307 /* paint the upper half of the window black */
3309 rc2.bottom = ( rc.top + rc.bottom) /2;
3310 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3311 /* clip region is the lower half */
3313 cliprc.top = (rc.top + rc.bottom) /2;
3314 /* test whether scrolled pixels are properly clipped */
3315 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3316 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3317 /* this scroll should not cause any visible changes */
3318 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3319 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3320 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3321 /* test with NULL clip rect */
3322 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3323 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3324 trace("update rect: %d,%d - %d,%d\n",
3325 rcu.left, rcu.top, rcu.right, rcu.bottom);
3326 if (winetest_debug > 0) dump_region(hrgn);
3327 SetRect(&rc2, 0, 0, 100, 100);
3328 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3329 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3331 SetRectRgn( exprgn, 0, 0, 20, 80);
3332 SetRectRgn( tmprgn, 0, 80, 100, 100);
3333 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3334 if (winetest_debug > 0) dump_region(exprgn);
3335 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3336 /* test clip rect > scroll rect */
3337 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3339 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3340 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3341 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3342 SetRectRgn( exprgn, 25, 25, 75, 35);
3343 SetRectRgn( tmprgn, 25, 35, 35, 75);
3344 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3345 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3346 colr = GetPixel( hdc, 80, 80);
3347 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3348 trace("update rect: %d,%d - %d,%d\n",
3349 rcu.left, rcu.top, rcu.right, rcu.bottom);
3350 if (winetest_debug > 0) dump_region(hrgn);
3354 DeleteObject(exprgn);
3355 DeleteObject(tmprgn);
3356 DestroyWindow(hwnd1);
3359 static void test_params(void)
3364 /* Just a param check */
3365 if (pGetMonitorInfoA)
3367 SetLastError(0xdeadbeef);
3368 rc = GetWindowText(hwndMain2, NULL, 1024);
3369 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
3373 /* Skips actually on Win95 and NT4 */
3374 win_skip("Test would crash on Win95\n");
3377 SetLastError(0xdeadbeef);
3378 hwnd=CreateWindow("LISTBOX", "TestList",
3379 (LBS_STANDARD & ~LBS_SORT),
3381 NULL, (HMENU)1, NULL, 0);
3383 ok(!hwnd, "CreateWindow with invalid menu handle should fail\n");
3384 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3385 GetLastError() == 0xdeadbeef, /* Win9x */
3386 "wrong last error value %d\n", GetLastError());
3389 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3393 hwnd = CreateWindowEx(exStyle, class, class, style,
3400 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
3403 ShowWindow(hwnd, SW_SHOW);
3405 test_nonclient_area(hwnd);
3408 DestroyWindow(hwnd);
3411 static BOOL AWR_init(void)
3415 class.style = CS_HREDRAW | CS_VREDRAW;
3416 class.lpfnWndProc = DefWindowProcA;
3417 class.cbClsExtra = 0;
3418 class.cbWndExtra = 0;
3419 class.hInstance = 0;
3420 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3421 class.hCursor = LoadCursor (0, IDC_ARROW);
3422 class.hbrBackground = 0;
3423 class.lpszMenuName = 0;
3424 class.lpszClassName = szAWRClass;
3426 if (!RegisterClass (&class)) {
3427 ok(FALSE, "RegisterClass failed\n");
3431 hmenu = CreateMenu();
3434 ok(hmenu != 0, "Failed to create menu\n");
3435 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3441 static void test_AWR_window_size(BOOL menu)
3445 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3448 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3449 WS_HSCROLL, WS_VSCROLL
3453 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3456 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3457 WS_EX_DLGMODALFRAME,
3464 /* A exhaustive check of all the styles takes too long
3465 * so just do a (hopefully representative) sample
3467 for (i = 0; i < COUNTOF(styles); ++i)
3468 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3469 for (i = 0; i < COUNTOF(exStyles); ++i) {
3470 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3471 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3476 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3478 static void test_AdjustWindowRect(void)
3483 SHOWSYSMETRIC(SM_CYCAPTION);
3484 SHOWSYSMETRIC(SM_CYSMCAPTION);
3485 SHOWSYSMETRIC(SM_CYMENU);
3486 SHOWSYSMETRIC(SM_CXEDGE);
3487 SHOWSYSMETRIC(SM_CYEDGE);
3488 SHOWSYSMETRIC(SM_CXVSCROLL);
3489 SHOWSYSMETRIC(SM_CYHSCROLL);
3490 SHOWSYSMETRIC(SM_CXFRAME);
3491 SHOWSYSMETRIC(SM_CYFRAME);
3492 SHOWSYSMETRIC(SM_CXDLGFRAME);
3493 SHOWSYSMETRIC(SM_CYDLGFRAME);
3494 SHOWSYSMETRIC(SM_CXBORDER);
3495 SHOWSYSMETRIC(SM_CYBORDER);
3497 test_AWR_window_size(FALSE);
3498 test_AWR_window_size(TRUE);
3502 #undef SHOWSYSMETRIC
3505 /* Global variables to trigger exit from loop */
3506 static int redrawComplete, WMPAINT_count;
3508 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3513 trace("doing WM_PAINT %d\n", WMPAINT_count);
3515 if (WMPAINT_count > 10 && redrawComplete == 0) {
3517 BeginPaint(hwnd, &ps);
3518 EndPaint(hwnd, &ps);
3523 return DefWindowProc(hwnd, msg, wparam, lparam);
3526 /* Ensure we exit from RedrawNow regardless of invalidated area */
3527 static void test_redrawnow(void)
3532 cls.style = CS_DBLCLKS;
3533 cls.lpfnWndProc = redraw_window_procA;
3536 cls.hInstance = GetModuleHandleA(0);
3538 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3539 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3540 cls.lpszMenuName = NULL;
3541 cls.lpszClassName = "RedrawWindowClass";
3543 if(!RegisterClassA(&cls)) {
3544 trace("Register failed %d\n", GetLastError());
3548 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3549 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3551 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3552 ShowWindow(hwndMain, SW_SHOW);
3553 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3554 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3555 ok( WMPAINT_count == 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3556 redrawComplete = TRUE;
3557 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3560 DestroyWindow( hwndMain);
3563 struct parentdc_stat {
3569 struct parentdc_test {
3570 struct parentdc_stat main, main_todo;
3571 struct parentdc_stat child1, child1_todo;
3572 struct parentdc_stat child2, child2_todo;
3575 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3580 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3585 trace("doing WM_PAINT on %p\n", hwnd);
3586 GetClientRect(hwnd, &rc);
3587 CopyRect(&t->client, &rc);
3588 trace("client rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3589 GetWindowRect(hwnd, &rc);
3590 trace("window rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3591 BeginPaint(hwnd, &ps);
3592 CopyRect(&t->paint, &ps.rcPaint);
3593 GetClipBox(ps.hdc, &rc);
3594 CopyRect(&t->clip, &rc);
3595 trace("clip rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3596 trace("paint rect (%d, %d)-(%d, %d)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3597 EndPaint(hwnd, &ps);
3600 return DefWindowProc(hwnd, msg, wparam, lparam);
3603 static void zero_parentdc_stat(struct parentdc_stat *t)
3605 SetRectEmpty(&t->client);
3606 SetRectEmpty(&t->clip);
3607 SetRectEmpty(&t->paint);
3610 static void zero_parentdc_test(struct parentdc_test *t)
3612 zero_parentdc_stat(&t->main);
3613 zero_parentdc_stat(&t->child1);
3614 zero_parentdc_stat(&t->child2);
3617 #define parentdc_field_ok(t, w, r, f, got) \
3618 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3619 ": expected %d, got %d\n", \
3622 #define parentdc_todo_field_ok(t, w, r, f, got) \
3623 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3624 else parentdc_field_ok(t, w, r, f, got)
3626 #define parentdc_rect_ok(t, w, r, got) \
3627 parentdc_todo_field_ok(t, w, r, left, got); \
3628 parentdc_todo_field_ok(t, w, r, top, got); \
3629 parentdc_todo_field_ok(t, w, r, right, got); \
3630 parentdc_todo_field_ok(t, w, r, bottom, got);
3632 #define parentdc_win_ok(t, w, got) \
3633 parentdc_rect_ok(t, w, client, got); \
3634 parentdc_rect_ok(t, w, clip, got); \
3635 parentdc_rect_ok(t, w, paint, got);
3637 #define parentdc_ok(t, got) \
3638 parentdc_win_ok(t, main, got); \
3639 parentdc_win_ok(t, child1, got); \
3640 parentdc_win_ok(t, child2, got);
3642 static void test_csparentdc(void)
3644 WNDCLASSA clsMain, cls;
3645 HWND hwndMain, hwnd1, hwnd2;
3648 struct parentdc_test test_answer;
3650 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3651 const struct parentdc_test test1 =
3653 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
3654 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3655 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3658 const struct parentdc_test test2 =
3660 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
3661 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3662 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3665 const struct parentdc_test test3 =
3667 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3668 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3669 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3672 const struct parentdc_test test4 =
3674 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
3675 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
3676 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3679 const struct parentdc_test test5 =
3681 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
3682 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3683 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3686 const struct parentdc_test test6 =
3688 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3689 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3690 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3693 const struct parentdc_test test7 =
3695 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3696 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3697 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3701 clsMain.style = CS_DBLCLKS;
3702 clsMain.lpfnWndProc = parentdc_window_procA;
3703 clsMain.cbClsExtra = 0;
3704 clsMain.cbWndExtra = 0;
3705 clsMain.hInstance = GetModuleHandleA(0);
3707 clsMain.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3708 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
3709 clsMain.lpszMenuName = NULL;
3710 clsMain.lpszClassName = "ParentDcMainWindowClass";
3712 if(!RegisterClassA(&clsMain)) {
3713 trace("Register failed %d\n", GetLastError());
3717 cls.style = CS_DBLCLKS | CS_PARENTDC;
3718 cls.lpfnWndProc = parentdc_window_procA;
3721 cls.hInstance = GetModuleHandleA(0);
3723 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3724 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3725 cls.lpszMenuName = NULL;
3726 cls.lpszClassName = "ParentDcWindowClass";
3728 if(!RegisterClassA(&cls)) {
3729 trace("Register failed %d\n", GetLastError());
3733 SetRect(&rc, 0, 0, 150, 150);
3734 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
3735 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3736 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
3737 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
3738 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
3739 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
3740 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
3741 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
3742 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
3743 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
3744 ShowWindow(hwndMain, SW_SHOW);
3745 ShowWindow(hwnd1, SW_SHOW);
3746 ShowWindow(hwnd2, SW_SHOW);
3747 flush_events( TRUE );
3749 zero_parentdc_test(&test_answer);
3750 InvalidateRect(hwndMain, NULL, TRUE);
3751 flush_events( TRUE );
3752 parentdc_ok(test1, test_answer);
3754 zero_parentdc_test(&test_answer);
3755 SetRect(&rc, 0, 0, 50, 50);
3756 InvalidateRect(hwndMain, &rc, TRUE);
3757 flush_events( TRUE );
3758 parentdc_ok(test2, test_answer);
3760 zero_parentdc_test(&test_answer);
3761 SetRect(&rc, 0, 0, 10, 10);
3762 InvalidateRect(hwndMain, &rc, TRUE);
3763 flush_events( TRUE );
3764 parentdc_ok(test3, test_answer);
3766 zero_parentdc_test(&test_answer);
3767 SetRect(&rc, 40, 40, 50, 50);
3768 InvalidateRect(hwndMain, &rc, TRUE);
3769 flush_events( TRUE );
3770 parentdc_ok(test4, test_answer);
3772 zero_parentdc_test(&test_answer);
3773 SetRect(&rc, 20, 20, 60, 60);
3774 InvalidateRect(hwndMain, &rc, TRUE);
3775 flush_events( TRUE );
3776 parentdc_ok(test5, test_answer);
3778 zero_parentdc_test(&test_answer);
3779 SetRect(&rc, 0, 0, 10, 10);
3780 InvalidateRect(hwnd1, &rc, TRUE);
3781 flush_events( TRUE );
3782 parentdc_ok(test6, test_answer);
3784 zero_parentdc_test(&test_answer);
3785 SetRect(&rc, -5, -5, 65, 65);
3786 InvalidateRect(hwnd1, &rc, TRUE);
3787 flush_events( TRUE );
3788 parentdc_ok(test7, test_answer);
3790 DestroyWindow(hwndMain);
3791 DestroyWindow(hwnd1);
3792 DestroyWindow(hwnd2);
3795 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3797 return DefWindowProcA(hwnd, msg, wparam, lparam);
3800 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3802 return DefWindowProcW(hwnd, msg, wparam, lparam);
3805 static void test_IsWindowUnicode(void)
3807 static const char ansi_class_nameA[] = "ansi class name";
3808 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3809 static const char unicode_class_nameA[] = "unicode class name";
3810 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3815 memset(&classW, 0, sizeof(classW));
3816 classW.hInstance = GetModuleHandleA(0);
3817 classW.lpfnWndProc = def_window_procW;
3818 classW.lpszClassName = unicode_class_nameW;
3819 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
3821 memset(&classA, 0, sizeof(classA));
3822 classA.hInstance = GetModuleHandleA(0);
3823 classA.lpfnWndProc = def_window_procA;
3824 classA.lpszClassName = ansi_class_nameA;
3825 assert(RegisterClassA(&classA));
3827 /* unicode class: window proc */
3828 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3829 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3832 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3833 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3834 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3835 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3836 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3838 DestroyWindow(hwnd);
3840 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3841 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3844 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3845 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3846 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3847 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3848 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3850 DestroyWindow(hwnd);
3852 /* ansi class: window proc */
3853 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3854 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3857 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3858 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3859 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3860 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3861 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3863 DestroyWindow(hwnd);
3865 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3866 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3869 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3870 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3871 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3872 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3873 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3875 DestroyWindow(hwnd);
3877 /* unicode class: class proc */
3878 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3879 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3882 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3883 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3884 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3885 /* do not restore class window proc back to unicode */
3887 DestroyWindow(hwnd);
3889 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3890 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3893 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3894 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
3895 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3897 DestroyWindow(hwnd);
3899 /* ansi class: class proc */
3900 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3901 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3904 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3905 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
3906 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3907 /* do not restore class window proc back to ansi */
3909 DestroyWindow(hwnd);
3911 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3912 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3915 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3916 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3917 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3919 DestroyWindow(hwnd);
3922 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
3926 if (msg != WM_GETMINMAXINFO)
3927 return DefWindowProc(hwnd, msg, wp, lp);
3929 minmax = (MINMAXINFO *)lp;
3931 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
3933 minmax->ptReserved.x = 0;
3934 minmax->ptReserved.y = 0;
3935 minmax->ptMaxSize.x = 400;
3936 minmax->ptMaxSize.y = 400;
3937 minmax->ptMaxPosition.x = 300;
3938 minmax->ptMaxPosition.y = 300;
3939 minmax->ptMaxTrackSize.x = 200;
3940 minmax->ptMaxTrackSize.y = 200;
3941 minmax->ptMinTrackSize.x = 100;
3942 minmax->ptMinTrackSize.y = 100;
3945 DefWindowProc(hwnd, msg, wp, lp);
3949 static int expected_cx, expected_cy;
3950 static RECT expected_rect, broken_rect;
3952 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
3956 case WM_GETMINMAXINFO:
3959 GetWindowRect( hwnd, &rect );
3960 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
3961 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
3962 return DefWindowProc(hwnd, msg, wp, lp);
3967 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
3969 GetWindowRect( hwnd, &rect );
3970 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
3971 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
3972 ok( cs->cx == expected_cx, "wrong x size %d/%d\n", cs->cx, expected_cx );
3973 ok( cs->cy == expected_cy, "wrong y size %d/%d\n", cs->cy, expected_cy );
3974 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
3975 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
3976 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
3977 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top),
3978 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
3979 rect.left, rect.top, rect.right, rect.bottom,
3980 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
3981 return DefWindowProc(hwnd, msg, wp, lp);
3985 RECT rect, *r = (RECT *)lp;
3986 GetWindowRect( hwnd, &rect );
3987 ok( !memcmp( &rect, r, sizeof(rect) ),
3988 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
3989 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
3990 return DefWindowProc(hwnd, msg, wp, lp);
3993 return DefWindowProc(hwnd, msg, wp, lp);
3997 static void test_CreateWindow(void)
4005 #define expect_menu(window, menu) \
4006 SetLastError(0xdeadbeef); \
4007 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
4009 #define expect_style(window, style)\
4010 ok(GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
4012 #define expect_ex_style(window, ex_style)\
4013 ok(GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
4015 #define expect_gle_broken_9x(gle)\
4016 ok(GetLastError() == gle ||\
4017 broken(GetLastError() == 0xdeadbeef),\
4018 "IsMenu set error %d\n", GetLastError())
4020 hmenu = CreateMenu();
4022 parent = GetDesktopWindow();
4023 assert(parent != 0);
4025 SetLastError(0xdeadbeef);
4026 ok(IsMenu(hmenu), "IsMenu error %d\n", GetLastError());
4029 SetLastError(0xdeadbeef);
4030 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
4031 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4032 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4033 expect_menu(hwnd, 1);
4034 expect_style(hwnd, WS_CHILD);
4035 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4036 DestroyWindow(hwnd);
4038 SetLastError(0xdeadbeef);
4039 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
4040 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4041 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4042 expect_menu(hwnd, 1);
4043 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4044 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4045 DestroyWindow(hwnd);
4047 SetLastError(0xdeadbeef);
4048 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
4049 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4050 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4051 expect_menu(hwnd, 1);
4052 expect_style(hwnd, WS_CHILD);
4053 expect_ex_style(hwnd, 0);
4054 DestroyWindow(hwnd);
4056 SetLastError(0xdeadbeef);
4057 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
4058 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4059 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4060 expect_menu(hwnd, 1);
4061 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4062 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4063 DestroyWindow(hwnd);
4066 SetLastError(0xdeadbeef);
4067 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4068 0, 0, 100, 100, parent, hmenu, 0, NULL);
4069 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4070 expect_menu(hwnd, hmenu);
4071 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4072 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4073 DestroyWindow(hwnd);
4074 SetLastError(0xdeadbeef);
4075 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4076 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4078 hmenu = CreateMenu();
4080 SetLastError(0xdeadbeef);
4081 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
4082 0, 0, 100, 100, parent, hmenu, 0, NULL);
4083 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4084 expect_menu(hwnd, hmenu);
4085 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4086 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4087 DestroyWindow(hwnd);
4088 SetLastError(0xdeadbeef);
4089 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4090 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4092 hmenu = CreateMenu();
4094 SetLastError(0xdeadbeef);
4095 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
4096 0, 0, 100, 100, parent, hmenu, 0, NULL);
4097 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4098 expect_menu(hwnd, hmenu);
4099 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4100 expect_ex_style(hwnd, 0);
4101 DestroyWindow(hwnd);
4102 SetLastError(0xdeadbeef);
4103 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4104 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4106 hmenu = CreateMenu();
4108 SetLastError(0xdeadbeef);
4109 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
4110 0, 0, 100, 100, parent, hmenu, 0, NULL);
4111 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4112 expect_menu(hwnd, hmenu);
4113 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4114 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4115 DestroyWindow(hwnd);
4116 SetLastError(0xdeadbeef);
4117 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4118 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4120 /* WS_CHILD | WS_POPUP */
4121 SetLastError(0xdeadbeef);
4122 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4123 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4124 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4125 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4127 DestroyWindow(hwnd);
4129 hmenu = CreateMenu();
4131 SetLastError(0xdeadbeef);
4132 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4133 0, 0, 100, 100, parent, hmenu, 0, NULL);
4134 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4135 expect_menu(hwnd, hmenu);
4136 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4137 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4138 DestroyWindow(hwnd);
4139 SetLastError(0xdeadbeef);
4140 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4141 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4143 SetLastError(0xdeadbeef);
4144 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4145 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4146 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4147 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4149 DestroyWindow(hwnd);
4151 hmenu = CreateMenu();
4153 SetLastError(0xdeadbeef);
4154 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4155 0, 0, 100, 100, parent, hmenu, 0, NULL);
4156 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4157 expect_menu(hwnd, hmenu);
4158 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4159 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4160 DestroyWindow(hwnd);
4161 SetLastError(0xdeadbeef);
4162 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4163 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4165 SetLastError(0xdeadbeef);
4166 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4167 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4168 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4169 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4171 DestroyWindow(hwnd);
4173 hmenu = CreateMenu();
4175 SetLastError(0xdeadbeef);
4176 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4177 0, 0, 100, 100, parent, hmenu, 0, NULL);
4178 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4179 expect_menu(hwnd, hmenu);
4180 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4181 expect_ex_style(hwnd, 0);
4182 DestroyWindow(hwnd);
4183 SetLastError(0xdeadbeef);
4184 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4185 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4187 SetLastError(0xdeadbeef);
4188 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4189 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4190 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4191 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4193 DestroyWindow(hwnd);
4195 hmenu = CreateMenu();
4197 SetLastError(0xdeadbeef);
4198 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4199 0, 0, 100, 100, parent, hmenu, 0, NULL);
4200 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4201 expect_menu(hwnd, hmenu);
4202 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4203 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4204 DestroyWindow(hwnd);
4205 SetLastError(0xdeadbeef);
4206 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4207 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4209 /* test child window sizing */
4211 cls.lpfnWndProc = minmax_wnd_proc;
4214 cls.hInstance = GetModuleHandle(0);
4216 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
4217 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4218 cls.lpszMenuName = NULL;
4219 cls.lpszClassName = "MinMax_WndClass";
4220 RegisterClass(&cls);
4222 SetLastError(0xdeadbeef);
4223 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4224 0, 0, 100, 100, 0, 0, 0, NULL);
4225 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4226 expect_menu(parent, 0);
4227 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
4228 expect_ex_style(parent, WS_EX_WINDOWEDGE);
4230 memset(&minmax, 0, sizeof(minmax));
4231 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4232 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
4233 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
4234 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4235 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
4237 GetWindowRect(parent, &rc);
4238 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
4239 GetClientRect(parent, &rc);
4240 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
4242 InflateRect(&rc, 200, 200);
4243 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4245 SetLastError(0xdeadbeef);
4246 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4247 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
4248 parent, (HMENU)1, 0, NULL);
4249 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4250 expect_menu(hwnd, 1);
4251 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
4252 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4254 memset(&minmax, 0, sizeof(minmax));
4255 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4256 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4258 GetWindowRect(hwnd, &rc);
4259 OffsetRect(&rc, -rc.left, -rc.top);
4260 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4261 rc.left, rc.top, rc.right, rc.bottom,
4262 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
4263 DestroyWindow(hwnd);
4265 cls.lpfnWndProc = winsizes_wnd_proc;
4266 cls.lpszClassName = "Sizes_WndClass";
4267 RegisterClass(&cls);
4269 expected_cx = expected_cy = 200000;
4270 SetRect( &expected_rect, 0, 0, 200000, 200000 );
4271 broken_rect = expected_rect;
4272 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
4273 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4274 GetClientRect( hwnd, &rc );
4275 ok( rc.right == 200000, "invalid rect right %u\n", rc.right );
4276 ok( rc.bottom == 200000, "invalid rect bottom %u\n", rc.bottom );
4277 DestroyWindow(hwnd);
4279 expected_cx = expected_cy = -10;
4280 SetRect( &expected_rect, 0, 0, 0, 0 );
4281 SetRect( &broken_rect, 0, 0, -10, -10 );
4282 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
4283 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4284 GetClientRect( hwnd, &rc );
4285 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4286 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4287 DestroyWindow(hwnd);
4289 expected_cx = expected_cy = -200000;
4290 SetRect( &expected_rect, 0, 0, 0, 0 );
4291 SetRect( &broken_rect, 0, 0, -200000, -200000 );
4292 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
4293 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4294 GetClientRect( hwnd, &rc );
4295 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4296 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4297 DestroyWindow(hwnd);
4299 /* we need a parent at 0,0 so that child coordinates match */
4300 DestroyWindow(parent);
4301 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
4302 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4305 expected_cy = 0x7fffffff;
4306 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
4307 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
4308 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
4309 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4310 GetClientRect( hwnd, &rc );
4311 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
4312 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4313 DestroyWindow(hwnd);
4315 expected_cx = 0x7fffffff;
4316 expected_cy = 0x7fffffff;
4317 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
4318 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
4319 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
4320 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4321 GetClientRect( hwnd, &rc );
4322 ok( rc.right == 0x7fffffff - 20 || broken(rc.right == 0), "invalid rect right %u\n", rc.right );
4323 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4324 DestroyWindow(hwnd);
4326 /* top level window */
4327 expected_cx = expected_cy = 200000;
4328 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
4329 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
4330 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4331 GetClientRect( hwnd, &rc );
4332 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
4333 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
4334 DestroyWindow(hwnd);
4336 DestroyWindow(parent);
4338 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4339 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4341 #undef expect_gle_broken_9x
4344 #undef expect_ex_style
4347 /* function that remembers whether the system the test is running on sets the
4348 * last error for user32 functions to make the tests stricter */
4349 static int check_error(DWORD actual, DWORD expected)
4351 static int sets_last_error = -1;
4352 if (sets_last_error == -1)
4353 sets_last_error = (actual != 0xdeadbeef);
4354 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
4357 static void test_SetWindowLong(void)
4360 WNDPROC old_window_procW;
4362 SetLastError(0xdeadbeef);
4363 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
4364 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
4365 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
4366 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4368 SetLastError(0xdeadbeef);
4369 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
4370 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
4371 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
4372 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4374 SetLastError(0xdeadbeef);
4375 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4376 ok((WNDPROC)retval == main_window_procA,
4377 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
4378 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4379 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
4380 ok((WNDPROC)retval == main_window_procA,
4381 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4382 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
4384 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
4385 SetLastError(0xdeadbeef);
4386 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
4387 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
4389 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4390 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
4391 ok((WNDPROC)retval == old_window_procW,
4392 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4393 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
4395 /* set it back to ANSI */
4396 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4400 static void test_ShowWindow(void)
4407 SetRect(&rcMain, 120, 120, 210, 210);
4409 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
4410 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4411 WS_MAXIMIZEBOX | WS_POPUP,
4412 rcMain.left, rcMain.top,
4413 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
4417 style = GetWindowLong(hwnd, GWL_STYLE);
4418 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4419 ok(!(style & WS_VISIBLE), "window should not be visible\n");
4420 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4421 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4422 GetWindowRect(hwnd, &rc);
4423 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4424 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4425 rc.left, rc.top, rc.right, rc.bottom);
4427 ret = ShowWindow(hwnd, SW_SHOW);
4428 ok(!ret, "not expected ret: %lu\n", ret);
4429 style = GetWindowLong(hwnd, GWL_STYLE);
4430 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4431 ok(style & WS_VISIBLE, "window should be visible\n");
4432 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4433 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4434 GetWindowRect(hwnd, &rc);
4435 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4436 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4437 rc.left, rc.top, rc.right, rc.bottom);
4439 ret = ShowWindow(hwnd, SW_MINIMIZE);
4440 ok(ret, "not expected ret: %lu\n", ret);
4441 style = GetWindowLong(hwnd, GWL_STYLE);
4442 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4443 ok(style & WS_VISIBLE, "window should be visible\n");
4444 ok(style & WS_MINIMIZE, "window should be minimized\n");
4445 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4446 GetWindowRect(hwnd, &rc);
4447 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4449 ShowWindow(hwnd, SW_RESTORE);
4450 ok(ret, "not expected ret: %lu\n", ret);
4451 style = GetWindowLong(hwnd, GWL_STYLE);
4452 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4453 ok(style & WS_VISIBLE, "window should be visible\n");
4454 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4455 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4456 GetWindowRect(hwnd, &rc);
4457 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4458 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4459 rc.left, rc.top, rc.right, rc.bottom);
4461 ret = EnableWindow(hwnd, FALSE);
4462 ok(!ret, "not expected ret: %lu\n", ret);
4463 style = GetWindowLong(hwnd, GWL_STYLE);
4464 ok(style & WS_DISABLED, "window should be disabled\n");
4466 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
4467 ok(!ret, "not expected ret: %lu\n", ret);
4468 style = GetWindowLong(hwnd, GWL_STYLE);
4469 ok(style & WS_DISABLED, "window should be disabled\n");
4470 ok(style & WS_VISIBLE, "window should be visible\n");
4471 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4472 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4473 GetWindowRect(hwnd, &rc);
4474 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4475 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4476 rc.left, rc.top, rc.right, rc.bottom);
4478 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
4479 ok(!ret, "not expected ret: %lu\n", ret);
4480 style = GetWindowLong(hwnd, GWL_STYLE);
4481 ok(style & WS_DISABLED, "window should be disabled\n");
4482 ok(style & WS_VISIBLE, "window should be visible\n");
4483 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4484 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4485 GetWindowRect(hwnd, &rc);
4486 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4487 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4488 rc.left, rc.top, rc.right, rc.bottom);
4490 ret = ShowWindow(hwnd, SW_MINIMIZE);
4491 ok(ret, "not expected ret: %lu\n", ret);
4492 style = GetWindowLong(hwnd, GWL_STYLE);
4493 ok(style & WS_DISABLED, "window should be disabled\n");
4494 ok(style & WS_VISIBLE, "window should be visible\n");
4495 ok(style & WS_MINIMIZE, "window should be minimized\n");
4496 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4497 GetWindowRect(hwnd, &rc);
4498 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4500 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
4501 ok(!ret, "not expected ret: %lu\n", ret);
4502 style = GetWindowLong(hwnd, GWL_STYLE);
4503 ok(style & WS_DISABLED, "window should be disabled\n");
4504 ok(style & WS_VISIBLE, "window should be visible\n");
4505 ok(style & WS_MINIMIZE, "window should be minimized\n");
4506 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4507 GetWindowRect(hwnd, &rc);
4508 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4510 ret = ShowWindow(hwnd, SW_RESTORE);
4511 ok(ret, "not expected ret: %lu\n", ret);
4512 style = GetWindowLong(hwnd, GWL_STYLE);
4513 ok(style & WS_DISABLED, "window should be disabled\n");
4514 ok(style & WS_VISIBLE, "window should be visible\n");
4515 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4516 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4517 GetWindowRect(hwnd, &rc);
4518 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4519 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4520 rc.left, rc.top, rc.right, rc.bottom);
4522 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4523 ok(!ret, "not expected ret: %lu\n", ret);
4524 ok(IsWindow(hwnd), "window should exist\n");
4526 ret = EnableWindow(hwnd, TRUE);
4527 ok(ret, "not expected ret: %lu\n", ret);
4529 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4530 ok(!ret, "not expected ret: %lu\n", ret);
4531 ok(!IsWindow(hwnd), "window should not exist\n");
4534 static void test_gettext(void)
4537 LPCSTR clsname = "gettexttest";
4541 memset( &cls, 0, sizeof cls );
4542 cls.lpfnWndProc = DefWindowProc;
4543 cls.lpszClassName = clsname;
4544 cls.hInstance = GetModuleHandle(NULL);
4546 if (!RegisterClass( &cls )) return;
4548 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
4549 ok( hwnd != NULL, "window was null\n");
4551 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
4552 ok( r == 0, "settext should return zero\n");
4554 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
4555 ok( r == 0, "settext should return zero (%ld)\n", r);
4557 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
4558 ok( r == 0, "settext should return zero (%ld)\n", r);
4560 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
4561 ok( r == 0, "settext should return zero (%ld)\n", r);
4563 DestroyWindow(hwnd);
4564 UnregisterClass( clsname, NULL );
4568 static void test_GetUpdateRect(void)
4571 BOOL ret, parent_wm_paint, grandparent_wm_paint;
4573 HWND hgrandparent, hparent, hchild;
4575 static const char classNameA[] = "GetUpdateRectClass";
4577 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
4578 0, 0, 100, 100, NULL, NULL, 0, NULL);
4580 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
4581 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4583 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
4584 10, 10, 30, 30, hparent, NULL, 0, NULL);
4586 ShowWindow(hgrandparent, SW_SHOW);
4587 UpdateWindow(hgrandparent);
4588 flush_events( TRUE );
4590 ShowWindow(hchild, SW_HIDE);
4591 SetRect(&rc2, 0, 0, 0, 0);
4592 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4593 ok(!ret, "GetUpdateRect returned not empty region\n");
4594 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4595 rc1.left, rc1.top, rc1.right, rc1.bottom,
4596 rc2.left, rc2.top, rc2.right, rc2.bottom);
4598 SetRect(&rc2, 10, 10, 40, 40);
4599 ret = GetUpdateRect(hparent, &rc1, FALSE);
4600 ok(ret, "GetUpdateRect returned empty region\n");
4601 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4602 rc1.left, rc1.top, rc1.right, rc1.bottom,
4603 rc2.left, rc2.top, rc2.right, rc2.bottom);
4605 parent_wm_paint = FALSE;
4606 grandparent_wm_paint = FALSE;
4607 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4609 if (msg.message == WM_PAINT)
4611 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4612 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4614 DispatchMessage(&msg);
4616 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4617 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4619 DestroyWindow(hgrandparent);
4622 cls.lpfnWndProc = DefWindowProcA;
4625 cls.hInstance = GetModuleHandleA(0);
4627 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
4628 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4629 cls.lpszMenuName = NULL;
4630 cls.lpszClassName = classNameA;
4632 if(!RegisterClassA(&cls)) {
4633 trace("Register failed %d\n", GetLastError());
4637 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
4638 0, 0, 100, 100, NULL, NULL, 0, NULL);
4640 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
4641 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4643 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
4644 10, 10, 30, 30, hparent, NULL, 0, NULL);
4646 ShowWindow(hgrandparent, SW_SHOW);
4647 UpdateWindow(hgrandparent);
4648 flush_events( TRUE );
4650 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4651 ok(!ret, "GetUpdateRect returned not empty region\n");
4653 ShowWindow(hchild, SW_HIDE);
4655 SetRect(&rc2, 0, 0, 0, 0);
4656 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4657 ok(!ret, "GetUpdateRect returned not empty region\n");
4658 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4659 rc1.left, rc1.top, rc1.right, rc1.bottom,
4660 rc2.left, rc2.top, rc2.right, rc2.bottom);
4662 SetRect(&rc2, 10, 10, 40, 40);
4663 ret = GetUpdateRect(hparent, &rc1, FALSE);
4664 ok(ret, "GetUpdateRect returned empty region\n");
4665 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4666 rc1.left, rc1.top, rc1.right, rc1.bottom,
4667 rc2.left, rc2.top, rc2.right, rc2.bottom);
4669 parent_wm_paint = FALSE;
4670 grandparent_wm_paint = FALSE;
4671 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4673 if (msg.message == WM_PAINT)
4675 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4676 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4678 DispatchMessage(&msg);
4680 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4681 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4683 DestroyWindow(hgrandparent);
4687 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
4695 const int waitTime = 2000;
4697 BeginPaint(hwnd, &ps);
4699 /* create and destroy window to create an exposed region on this window */
4700 win = CreateWindowA("static", "win", WS_VISIBLE,
4701 10,10,50,50, NULL, NULL, 0, NULL);
4704 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
4706 ValidateRect(hwnd, NULL);
4707 EndPaint(hwnd, &ps);
4709 if(waitResult != WAIT_TIMEOUT)
4711 GetUpdateRect(hwnd, &updateRect, FALSE);
4712 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
4717 return DefWindowProc(hwnd, msg, wParam, lParam);
4720 static void test_Expose(void)
4725 memset(&cls, 0, sizeof(WNDCLASSA));
4726 cls.lpfnWndProc = TestExposedRegion_WndProc;
4727 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4728 cls.lpszClassName = "TestExposeClass";
4729 atom = RegisterClassA(&cls);
4731 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
4732 0, 0, 200, 100, NULL, NULL, 0, NULL);
4738 static void test_GetWindowModuleFileName(void)
4743 char buf1[MAX_PATH], buf2[MAX_PATH];
4745 if (!pGetWindowModuleFileNameA)
4747 skip("GetWindowModuleFileNameA is not available\n");
4751 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
4754 hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
4755 ok(hinst == 0, "expected 0, got %p\n", hinst);
4758 SetLastError(0xdeadbeef);
4759 ret1 = GetModuleFileName(hinst, buf1, sizeof(buf1));
4760 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
4763 SetLastError(0xdeadbeef);
4764 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
4765 ok(ret2, "GetWindowModuleFileNameA error %u\n", GetLastError());
4767 ok(ret1 == ret2, "%u != %u\n", ret1, ret2);
4768 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
4770 hinst = GetModuleHandle(0);
4772 SetLastError(0xdeadbeef);
4773 ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
4774 ok(ret2 == ret1 - 2, "expected %u, got %u\n", ret1 - 2, ret2);
4775 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4776 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4777 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4779 SetLastError(0xdeadbeef);
4780 ret2 = GetModuleFileName(hinst, buf2, 0);
4781 ok(!ret2, "GetModuleFileName should return 0\n");
4782 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4783 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4784 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4786 SetLastError(0xdeadbeef);
4787 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
4788 ok(ret2 == ret1 - 2, "expected %u, got %u\n", ret1 - 2, ret2);
4789 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4790 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4791 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4793 SetLastError(0xdeadbeef);
4794 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
4795 ok(!ret2, "expected 0, got %u\n", ret2);
4796 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4797 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4798 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4800 DestroyWindow(hwnd);
4803 hwnd = (HWND)0xdeadbeef;
4804 SetLastError(0xdeadbeef);
4805 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4806 ok(!ret1, "expected 0, got %u\n", ret1);
4807 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
4809 ret1 = GetModuleFileName(0, buf1, sizeof(buf1));
4810 hwnd = GetDesktopWindow();
4811 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
4812 SetLastError(0xdeadbeef);
4813 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
4814 ok(!ret2 || ret1 == ret2 /* vista */, "expected 0, got %u\n", ret2);
4816 hwnd = FindWindow("Shell_TrayWnd", NULL);
4817 ok(IsWindow(hwnd), "got invalid tray window %p\n", hwnd);
4818 SetLastError(0xdeadbeef);
4819 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4820 ok(!ret1, "expected 0, got %u\n", ret1);
4823 static void test_hwnd_message(void)
4825 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
4826 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
4828 HWND parent = 0, hwnd, found;
4831 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
4832 on CreateWindowExA and crash later in the test.
4833 Use UNICODE here to fail on win9x */
4834 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
4835 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
4838 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
4842 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
4846 HWND root, desktop = GetDesktopWindow();
4848 parent = pGetAncestor(hwnd, GA_PARENT);
4849 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
4850 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
4851 root = pGetAncestor(hwnd, GA_ROOT);
4852 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
4853 ok( !pGetAncestor(parent, GA_PARENT), "parent shouldn't have a parent\n" );
4854 trace("parent %p root %p desktop %p\n", parent, root, desktop);
4855 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
4856 ok( !lstrcmpi( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
4857 GetWindowRect( parent, &rect );
4858 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
4859 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4861 GetWindowRect( hwnd, &rect );
4862 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
4863 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4865 /* test FindWindow behavior */
4867 found = FindWindowExA( 0, 0, 0, "message window" );
4868 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
4869 SetLastError(0xdeadbeef);
4870 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
4871 ok( found == 0, "found message window %p/%p\n", found, hwnd );
4872 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
4875 found = FindWindowExA( parent, 0, 0, "message window" );
4876 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
4879 /* test IsChild behavior */
4881 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
4883 /* test IsWindowVisible behavior */
4885 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
4886 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
4888 DestroyWindow(hwnd);
4891 static void test_layered_window(void)
4899 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes)
4901 win_skip( "layered windows not supported\n" );
4904 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
4905 100, 100, 200, 200, 0, 0, 0, NULL);
4907 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4908 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
4909 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
4910 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
4911 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
4912 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4913 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
4914 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
4915 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4916 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4917 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4918 ok( key == 0x123456, "wrong color key %x\n", key );
4919 ok( alpha == 44, "wrong alpha %u\n", alpha );
4920 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
4922 /* clearing WS_EX_LAYERED resets attributes */
4923 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
4924 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4925 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
4926 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
4927 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4928 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
4929 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
4930 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4931 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4932 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4933 ok( key == 0x654321, "wrong color key %x\n", key );
4934 ok( alpha == 22, "wrong alpha %u\n", alpha );
4935 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
4937 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
4938 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4940 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4941 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4942 ok( key == 0x888888, "wrong color key %x\n", key );
4943 /* alpha not changed on vista if LWA_ALPHA is not set */
4944 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
4945 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
4947 /* color key always changed */
4948 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
4949 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4951 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4952 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4953 ok( key == 0x999999, "wrong color key %x\n", key );
4954 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
4955 ok( flags == 0, "wrong flags %x\n", flags );
4957 /* default alpha is 0 */
4958 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
4959 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
4960 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
4961 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4962 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4963 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4964 ok( key == 0x222222, "wrong color key %x\n", key );
4965 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
4966 ok( flags == 0, "wrong flags %x\n", flags );
4968 DestroyWindow( hwnd );
4971 static MONITORINFO mi;
4973 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4979 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
4980 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs->x, cs->y, cs->cx, cs->cy);
4981 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
4982 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
4983 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
4984 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
4985 cs->x, cs->y, cs->cx, cs->cy);
4988 case WM_GETMINMAXINFO:
4990 MINMAXINFO *minmax = (MINMAXINFO *)lp;
4991 dump_minmax_info(minmax);
4992 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
4993 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
4994 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
4995 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
4999 return DefWindowProc(hwnd, msg, wp, lp);
5002 static void test_fullscreen(void)
5004 static const DWORD t_style[] = {
5005 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
5007 static const DWORD t_ex_style[] = {
5008 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
5018 if (!pGetMonitorInfoA || !pMonitorFromPoint)
5020 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
5025 SetLastError(0xdeadbeef);
5026 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
5027 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
5029 mi.cbSize = sizeof(mi);
5030 SetLastError(0xdeadbeef);
5031 ret = pGetMonitorInfoA(hmon, &mi);
5032 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
5033 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
5034 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5035 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5038 cls.lpfnWndProc = fullscreen_wnd_proc;
5041 cls.hInstance = GetModuleHandle(0);
5043 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
5044 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5045 cls.lpszMenuName = NULL;
5046 cls.lpszClassName = "fullscreen_class";
5047 RegisterClass(&cls);
5049 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
5051 DWORD style, ex_style;
5053 /* avoid a WM interaction */
5054 assert(!(t_style[i] & WS_VISIBLE));
5056 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
5061 ex_style = t_ex_style[j];
5063 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5064 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5065 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5066 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5067 GetWindowRect(hwnd, &rc);
5068 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5069 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5070 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5071 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5072 DestroyWindow(hwnd);
5074 style = t_style[i] | WS_MAXIMIZE;
5075 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5076 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5077 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5078 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5079 GetWindowRect(hwnd, &rc);
5080 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5081 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5082 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5083 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5084 DestroyWindow(hwnd);
5086 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
5087 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5088 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5089 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5090 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5091 GetWindowRect(hwnd, &rc);
5092 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5093 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5094 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5095 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5096 DestroyWindow(hwnd);
5098 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
5099 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5100 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5101 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5102 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5103 GetWindowRect(hwnd, &rc);
5104 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5105 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5106 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5107 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5108 DestroyWindow(hwnd);
5110 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
5111 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5112 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5113 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5114 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5115 GetWindowRect(hwnd, &rc);
5116 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5117 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5118 fixup = min(abs(rc.left), abs(rc.top));
5119 InflateRect(&rc, -fixup, -fixup);
5120 /* FIXME: this doesn't work correctly in Wine for child windows yet */
5121 if (style & WS_CHILD)
5123 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5124 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5125 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5127 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5128 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5129 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5130 DestroyWindow(hwnd);
5132 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
5133 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5134 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5135 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5136 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5137 GetWindowRect(hwnd, &rc);
5138 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5139 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5140 fixup = min(abs(rc.left), abs(rc.top));
5141 InflateRect(&rc, -fixup, -fixup);
5142 if (style & (WS_CHILD | WS_POPUP))
5143 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5144 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5145 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5147 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5148 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5149 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5150 DestroyWindow(hwnd);
5154 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5157 static BOOL test_thick_child_got_minmax;
5159 static int getExpectedThickChildInc(void)
5161 const int outer = 2;
5162 int resizeBorder = GetSystemMetrics(SM_CXFRAME) - GetSystemMetrics(SM_CXDLGFRAME);
5163 return (outer + resizeBorder);
5166 static LRESULT WINAPI test_thick_child_size_winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5169 int expectedMinTrack;
5170 int actualMinTrackX;
5171 int actualMinTrackY;
5172 int expectedMaxTrackX;
5173 int expectedMaxTrackY;
5174 int actualMaxTrackX;
5175 int actualMaxTrackY;
5176 int expectedMaxSizeX;
5177 int expectedMaxSizeY;
5187 case WM_GETMINMAXINFO:
5189 minmax = (MINMAXINFO *)lparam;
5190 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
5191 dump_minmax_info( minmax );
5193 test_thick_child_got_minmax = TRUE;
5195 expectedMinTrack = 2* getExpectedThickChildInc();
5196 actualMinTrackX = minmax->ptMinTrackSize.x;
5197 actualMinTrackY = minmax->ptMinTrackSize.y;
5199 ok(actualMinTrackX == expectedMinTrack && actualMinTrackY == expectedMinTrack,
5200 "expected minTrack %dx%d, actual minTrack %dx%d\n",
5201 expectedMinTrack, expectedMinTrack, actualMinTrackX, actualMinTrackY);
5203 actualMaxTrackX = minmax->ptMaxTrackSize.x;
5204 actualMaxTrackY = minmax->ptMaxTrackSize.y;
5205 expectedMaxTrackX = GetSystemMetrics(SM_CXMAXTRACK);
5206 expectedMaxTrackY = GetSystemMetrics(SM_CYMAXTRACK);
5207 ok(actualMaxTrackX == expectedMaxTrackX && actualMaxTrackY == expectedMaxTrackY,
5208 "expected maxTrack %dx%d, actual maxTrack %dx%d\n",
5209 expectedMaxTrackX, expectedMaxTrackY, actualMaxTrackX, actualMaxTrackY);
5211 GetClientRect(GetParent(hwnd), &rect);
5212 AdjustWindowRectEx(&rect, WS_CHILD | WS_VISIBLE | WS_THICKFRAME, FALSE, 0);
5213 expectedMaxSizeX = rect.right - rect.left;
5214 expectedMaxSizeY = rect.bottom - rect.top;
5215 actualMaxSizeX = minmax->ptMaxSize.x;
5216 actualMaxSizeY = minmax->ptMaxSize.y;
5217 ok(actualMaxSizeX == expectedMaxSizeX && actualMaxSizeY == expectedMaxSizeY,
5218 "expected maxTrack %dx%d, actual maxTrack %dx%d\n",
5219 expectedMaxSizeX, expectedMaxSizeY, actualMaxSizeX, actualMaxSizeY);
5221 expectedPosX = - getExpectedThickChildInc();
5222 expectedPosY = expectedPosX;
5223 actualPosX = minmax->ptMaxPosition.x;
5224 actualPosY = minmax->ptMaxPosition.y;
5226 ok(actualPosX == expectedPosX && actualPosY == expectedPosY,
5227 "expected maxPosition (%d/%d), actual maxPosition (%d/%d)\n",
5228 expectedPosX, expectedPosY, actualPosX, actualPosY);
5233 return DefWindowProcA(hwnd, msg, wparam, lparam);
5236 static void test_thick_child_size(HWND parentWindow)
5244 LPCTSTR className = "THICK_CHILD_CLASS";
5245 LONG style = WS_CHILD | WS_VISIBLE | WS_THICKFRAME;
5247 int expectedSize = 2*getExpectedThickChildInc();
5251 cls.lpfnWndProc = test_thick_child_size_winproc;
5254 cls.hInstance = GetModuleHandleA(0);
5256 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
5257 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5258 cls.lpszMenuName = NULL;
5259 cls.lpszClassName = className;
5260 SetLastError(0xdeadbeef);
5261 ok(RegisterClassA(&cls),"RegisterClassA failed, error: %u\n", GetLastError());
5263 test_thick_child_got_minmax = FALSE;
5265 SetLastError(0xdeadbeef);
5266 childWindow = CreateWindowEx( exStyle, className, "", style, 0, 0, 0, 0, parentWindow, 0, GetModuleHandleA(0), NULL );
5267 ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
5269 ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
5271 SetLastError(0xdeadbeef);
5272 success = GetWindowRect(childWindow, &childRect);
5273 ok(success,"GetWindowRect call failed, error: %u\n", GetLastError());
5274 childWidth = childRect.right - childRect.left;
5275 childHeight = childRect.bottom - childRect.top;
5278 ok( (childWidth == expectedSize) && (childHeight == expectedSize),
5279 "size of window with style WS_CHILD | WS_VISIBLE | WS_THICKFRAME is wrong: expected size %dx%d != actual size %dx%d\n",
5280 expectedSize, expectedSize, childWidth, childHeight);
5283 SetLastError(0xdeadbeef);
5284 success = DestroyWindow(childWindow);
5285 ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
5286 ok(UnregisterClass(className, GetModuleHandleA(0)),"UnregisterClass call failed\n");
5292 HMODULE user32 = GetModuleHandleA( "user32.dll" );
5293 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
5294 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
5295 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
5296 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
5297 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
5298 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
5299 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
5301 if (!RegisterWindowClasses()) assert(0);
5303 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
5306 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
5307 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5308 WS_MAXIMIZEBOX | WS_POPUP,
5310 0, 0, GetModuleHandle(0), NULL);
5311 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
5312 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5313 WS_MAXIMIZEBOX | WS_POPUP,
5315 0, 0, GetModuleHandle(0), NULL);
5317 assert( hwndMain2 );
5319 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
5321 /* Add the tests below this line */
5322 test_thick_child_size(hwndMain);
5324 test_hwnd_message();
5325 test_nonclient_area(hwndMain);
5327 test_GetWindowModuleFileName();
5330 test_capture_3(hwndMain, hwndMain2);
5332 test_CreateWindow();
5333 test_parent_owner();
5338 test_SetWindowPos(hwndMain);
5339 test_SetMenu(hwndMain);
5340 test_SetFocus(hwndMain);
5341 test_SetActiveWindow(hwndMain);
5343 test_children_zorder(hwndMain);
5344 test_popup_zorder(hwndMain2, hwndMain);
5345 test_keyboard_input(hwndMain);
5346 test_mouse_input(hwndMain);
5347 test_validatergn(hwndMain);
5348 test_nccalcscroll( hwndMain);
5349 test_scrollvalidate( hwndMain);
5350 test_scrolldc( hwndMain);
5352 test_IsWindowUnicode();
5353 test_vis_rgn(hwndMain);
5355 test_AdjustWindowRect();
5356 test_window_styles();
5359 test_SetWindowLong();
5361 if (0) test_gettext(); /* crashes on NT4 */
5362 test_GetUpdateRect();
5364 test_layered_window();
5366 test_SetForegroundWindow(hwndMain);
5367 test_shell_window();
5369 /* add the tests above this line */
5370 UnhookWindowsHookEx(hhook);