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 )
81 int min_timeout = 100;
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( !test, "WS_CHILD without parent created\n" );
160 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD ||
161 broken(GetLastError() == 0xdeadbeef), /* win9x */
162 "CreateWindowExA error %u\n", GetLastError() );
165 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
166 style = GetWindowLongA( desktop, GWL_STYLE );
167 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
168 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
169 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
171 /* normal child window */
172 test = create_tool_window( WS_CHILD, hwndMain );
173 trace( "created child %p\n", test );
174 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
175 SetWindowLongA( test, GWL_STYLE, 0 );
176 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
177 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
178 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
179 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
180 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
181 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
182 DestroyWindow( test );
184 /* normal child window with WS_MAXIMIZE */
185 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
186 DestroyWindow( test );
188 /* normal child window with WS_THICKFRAME */
189 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
190 DestroyWindow( test );
192 /* popup window with WS_THICKFRAME */
193 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
194 DestroyWindow( test );
196 /* child of desktop */
197 test = create_tool_window( WS_CHILD, desktop );
198 trace( "created child of desktop %p\n", test );
199 check_parents( test, desktop, 0, desktop, 0, test, desktop );
200 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
201 check_parents( test, desktop, 0, 0, 0, test, test );
202 SetWindowLongA( test, GWL_STYLE, 0 );
203 check_parents( test, desktop, 0, 0, 0, test, test );
204 DestroyWindow( test );
206 /* child of desktop with WS_MAXIMIZE */
207 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
208 DestroyWindow( test );
210 /* child of desktop with WS_MINIMIZE */
211 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
212 DestroyWindow( test );
215 test = create_tool_window( WS_CHILD, child );
216 trace( "created child of child %p\n", test );
217 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
218 SetWindowLongA( test, GWL_STYLE, 0 );
219 check_parents( test, child, child, 0, 0, hwndMain, test );
220 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
221 check_parents( test, child, child, 0, 0, hwndMain, test );
222 DestroyWindow( test );
224 /* child of child with WS_MAXIMIZE */
225 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
226 DestroyWindow( test );
228 /* child of child with WS_MINIMIZE */
229 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
230 DestroyWindow( test );
232 /* not owned top-level window */
233 test = create_tool_window( 0, 0 );
234 trace( "created top-level %p\n", test );
235 check_parents( test, desktop, 0, 0, 0, test, test );
236 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
237 check_parents( test, desktop, 0, 0, 0, test, test );
238 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
239 check_parents( test, desktop, 0, desktop, 0, test, desktop );
240 DestroyWindow( test );
242 /* not owned top-level window with WS_MAXIMIZE */
243 test = create_tool_window( WS_MAXIMIZE, 0 );
244 DestroyWindow( test );
246 /* owned top-level window */
247 test = create_tool_window( 0, hwndMain );
248 trace( "created owned top-level %p\n", test );
249 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
250 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
251 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
252 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
253 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
254 DestroyWindow( test );
256 /* owned top-level window with WS_MAXIMIZE */
257 test = create_tool_window( WS_MAXIMIZE, hwndMain );
258 DestroyWindow( test );
260 /* not owned popup */
261 test = create_tool_window( WS_POPUP, 0 );
262 trace( "created popup %p\n", test );
263 check_parents( test, desktop, 0, 0, 0, test, test );
264 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
265 check_parents( test, desktop, 0, desktop, 0, test, desktop );
266 SetWindowLongA( test, GWL_STYLE, 0 );
267 check_parents( test, desktop, 0, 0, 0, test, test );
268 DestroyWindow( test );
270 /* not owned popup with WS_MAXIMIZE */
271 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
272 DestroyWindow( test );
275 test = create_tool_window( WS_POPUP, hwndMain );
276 trace( "created owned popup %p\n", test );
277 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
278 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
279 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
280 SetWindowLongA( test, GWL_STYLE, 0 );
281 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
282 DestroyWindow( test );
284 /* owned popup with WS_MAXIMIZE */
285 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
286 DestroyWindow( test );
288 /* top-level window owned by child (same as owned by top-level) */
289 test = create_tool_window( 0, child );
290 trace( "created top-level owned by child %p\n", test );
291 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
292 DestroyWindow( test );
294 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
295 test = create_tool_window( WS_MAXIMIZE, child );
296 DestroyWindow( test );
298 /* popup owned by desktop (same as not owned) */
299 test = create_tool_window( WS_POPUP, desktop );
300 trace( "created popup owned by desktop %p\n", test );
301 check_parents( test, desktop, 0, 0, 0, test, test );
302 DestroyWindow( test );
304 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
305 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
306 DestroyWindow( test );
308 /* popup owned by child (same as owned by top-level) */
309 test = create_tool_window( WS_POPUP, child );
310 trace( "created popup owned by child %p\n", test );
311 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
312 DestroyWindow( test );
314 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
315 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
316 DestroyWindow( test );
318 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
319 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
320 trace( "created WS_CHILD popup %p\n", test );
321 check_parents( test, desktop, 0, 0, 0, test, test );
322 DestroyWindow( test );
324 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
325 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
326 DestroyWindow( test );
328 /* owned popup with WS_CHILD (same as WS_POPUP only) */
329 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
330 trace( "created owned WS_CHILD popup %p\n", test );
331 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
332 DestroyWindow( test );
334 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
335 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
336 DestroyWindow( test );
338 /******************** parent changes *************************/
339 trace( "testing parent changes\n" );
342 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
345 /* this test succeeds on NT but crashes on win9x systems */
346 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
347 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
348 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
349 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
350 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
352 /* normal child window */
353 test = create_tool_window( WS_CHILD, hwndMain );
354 trace( "created child %p\n", test );
356 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
357 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
358 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
360 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
361 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
362 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
364 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
365 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
366 check_parents( test, desktop, 0, desktop, 0, test, desktop );
368 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
369 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
370 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
371 check_parents( test, desktop, child, desktop, child, test, desktop );
373 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
374 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
375 check_parents( test, desktop, 0, desktop, 0, test, desktop );
376 DestroyWindow( test );
378 /* not owned top-level window */
379 test = create_tool_window( 0, 0 );
380 trace( "created top-level %p\n", test );
382 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
383 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
384 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
386 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
387 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
388 check_parents( test, desktop, child, 0, child, test, test );
390 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
391 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
392 check_parents( test, desktop, 0, 0, 0, test, test );
393 DestroyWindow( test );
395 /* not owned popup */
396 test = create_tool_window( WS_POPUP, 0 );
397 trace( "created popup %p\n", test );
399 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
400 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
401 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
403 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
404 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
405 check_parents( test, desktop, child, child, child, test, hwndMain );
407 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
408 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
409 check_parents( test, desktop, 0, 0, 0, test, test );
410 DestroyWindow( test );
412 /* normal child window */
413 test = create_tool_window( WS_CHILD, hwndMain );
414 trace( "created child %p\n", test );
416 ret = SetParent( test, desktop );
417 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
418 check_parents( test, desktop, 0, desktop, 0, test, desktop );
420 ret = SetParent( test, child );
421 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
422 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
424 ret = SetParent( test, hwndMain2 );
425 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
426 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
427 DestroyWindow( test );
429 /* not owned top-level window */
430 test = create_tool_window( 0, 0 );
431 trace( "created top-level %p\n", test );
433 ret = SetParent( test, child );
434 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
435 check_parents( test, child, child, 0, 0, hwndMain, test );
436 DestroyWindow( test );
439 test = create_tool_window( WS_POPUP, hwndMain2 );
440 trace( "created owned popup %p\n", test );
442 ret = SetParent( test, child );
443 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
444 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
446 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
447 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
448 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
449 DestroyWindow( test );
451 /**************** test owner destruction *******************/
453 /* owned child popup */
454 owner = create_tool_window( 0, 0 );
455 test = create_tool_window( WS_POPUP, owner );
456 trace( "created owner %p and popup %p\n", owner, test );
457 ret = SetParent( test, child );
458 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
459 check_parents( test, child, child, owner, owner, hwndMain, owner );
460 /* window is now child of 'child' but owned by 'owner' */
461 DestroyWindow( owner );
462 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
463 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
464 * while Win95, Win2k, WinXP do.
466 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
467 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
470 /* owned top-level popup */
471 owner = create_tool_window( 0, 0 );
472 test = create_tool_window( WS_POPUP, owner );
473 trace( "created owner %p and popup %p\n", owner, test );
474 check_parents( test, desktop, owner, owner, owner, test, owner );
475 DestroyWindow( owner );
476 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
478 /* top-level popup owned by child */
479 owner = create_tool_window( WS_CHILD, hwndMain2 );
480 test = create_tool_window( WS_POPUP, 0 );
481 trace( "created owner %p and popup %p\n", owner, test );
482 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
483 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
484 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
485 DestroyWindow( owner );
486 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
487 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
488 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
489 * while Win95, Win2k, WinXP do.
491 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
495 DestroyWindow(child);
498 owner = create_tool_window( WS_OVERLAPPED, 0 );
499 test = create_tool_window( WS_POPUP, desktop );
501 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
503 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
504 "EnumChildWindows should have returned FALSE\n" );
505 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
507 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
508 ret = SetParent( test, owner );
509 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
512 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
513 "EnumChildWindows should have returned TRUE\n" );
514 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
516 child = create_tool_window( WS_CHILD, owner );
518 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
519 "EnumChildWindows should have returned FALSE\n" );
520 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
521 DestroyWindow( child );
523 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
524 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
526 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
527 "EnumChildWindows should have returned TRUE\n" );
528 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
530 ret = SetParent( child, owner );
531 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
532 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
534 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
535 "EnumChildWindows should have returned FALSE\n" );
536 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
538 ret = SetParent( child, NULL );
539 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
540 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
542 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
543 "EnumChildWindows should have returned TRUE\n" );
544 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
546 /* even GW_OWNER == owner it's still a desktop's child */
547 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
548 "EnumChildWindows should have found %p and returned FALSE\n", child );
550 DestroyWindow( child );
551 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
553 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
554 "EnumChildWindows should have found %p and returned FALSE\n", child );
556 DestroyWindow( child );
557 DestroyWindow( test );
558 DestroyWindow( owner );
562 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
566 case WM_GETMINMAXINFO:
568 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
570 trace("WM_GETMINMAXINFO: hwnd %p, %08lx, %08lx\n", hwnd, wparam, lparam);
571 dump_minmax_info( minmax );
572 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
575 case WM_WINDOWPOSCHANGING:
577 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
578 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
579 trace("main: WM_WINDOWPOSCHANGING %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
580 winpos->hwnd, winpos->hwndInsertAfter,
581 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
582 if (!(winpos->flags & SWP_NOMOVE))
584 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
585 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
587 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
588 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
590 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
591 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
595 case WM_WINDOWPOSCHANGED:
598 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
599 trace("main: WM_WINDOWPOSCHANGED %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 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
610 /* note: winpos coordinates are relative to parent */
611 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
614 /* Uncomment this once the test succeeds in all cases */
615 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
616 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
619 GetClientRect(hwnd, &rc2);
620 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
621 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
622 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
623 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
628 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
629 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
631 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
632 if (got_getminmaxinfo)
633 trace("%p got WM_GETMINMAXINFO\n", hwnd);
635 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
636 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
638 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
642 if (test_lbuttondown_flag)
644 ShowWindow((HWND)wparam, SW_SHOW);
645 flush_events( FALSE );
650 return DefWindowProcA(hwnd, msg, wparam, lparam);
653 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
657 case WM_GETMINMAXINFO:
659 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
661 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
662 dump_minmax_info( minmax );
663 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
668 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
669 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
671 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
672 if (got_getminmaxinfo)
673 trace("%p got WM_GETMINMAXINFO\n", hwnd);
675 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
676 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
678 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
683 return DefWindowProcA(hwnd, msg, wparam, lparam);
686 static BOOL RegisterWindowClasses(void)
690 cls.style = CS_DBLCLKS;
691 cls.lpfnWndProc = main_window_procA;
694 cls.hInstance = GetModuleHandleA(0);
696 cls.hCursor = LoadCursorA(0, IDC_ARROW);
697 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
698 cls.lpszMenuName = NULL;
699 cls.lpszClassName = "MainWindowClass";
701 if(!RegisterClassA(&cls)) return FALSE;
704 cls.lpfnWndProc = tool_window_procA;
707 cls.hInstance = GetModuleHandleA(0);
709 cls.hCursor = LoadCursorA(0, IDC_ARROW);
710 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
711 cls.lpszMenuName = NULL;
712 cls.lpszClassName = "ToolWindowClass";
714 if(!RegisterClassA(&cls)) return FALSE;
719 static void verify_window_info(const char *hook, HWND hwnd, const WINDOWINFO *info)
721 RECT rcWindow, rcClient;
724 ok(IsWindow(hwnd), "bad window handle %p in hook %s\n", hwnd, hook);
726 GetWindowRect(hwnd, &rcWindow);
727 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow for %p in hook %s\n", hwnd, hook);
729 GetClientRect(hwnd, &rcClient);
730 /* translate to screen coordinates */
731 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
732 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient for %p in hook %s\n", hwnd, hook);
734 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
735 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
736 info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE), hwnd, hook);
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 for %p in hook %s\n",
742 info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE), hwnd, hook);
743 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
744 if (GetForegroundWindow())
745 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
746 info->dwWindowStatus, status, GetActiveWindow(), GetForegroundWindow(), hook);
748 /* win2k and XP return broken border info in GetWindowInfo most of
749 * the time, so there is no point in testing it.
753 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
754 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
755 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
756 ok(info->cyWindowBorders == border,
757 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
759 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType for %p in hook %s\n",
761 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
762 info->wCreatorVersion == 0x0500 /* Vista */,
763 "wrong wCreatorVersion %04x for %p in hook %s\n", info->wCreatorVersion, hwnd, hook);
766 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
768 AdjustWindowRectEx(rc, style, menu, exstyle);
769 /* AdjustWindowRectEx does not include scroll bars */
770 if (style & WS_VSCROLL)
772 if(exstyle & WS_EX_LEFTSCROLLBAR)
773 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
775 rc->right += GetSystemMetrics(SM_CXVSCROLL);
777 if (style & WS_HSCROLL)
778 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
781 static void test_nonclient_area(HWND hwnd)
783 DWORD style, exstyle;
784 RECT rc_window, rc_client, rc;
786 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
789 style = GetWindowLongA(hwnd, GWL_STYLE);
790 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
791 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
793 GetWindowRect(hwnd, &rc_window);
794 GetClientRect(hwnd, &rc_client);
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 ok(EqualRect(&rc, &rc_window),
805 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
806 style, exstyle, menu, rc_window.left, rc_window.top, rc_window.right, rc_window.bottom,
807 rc.left, rc.top, rc.right, rc.bottom);
810 CopyRect(&rc, &rc_window);
811 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
812 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
813 ok(EqualRect(&rc, &rc_client),
814 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
815 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
816 rc.left, rc.top, rc.right, rc.bottom);
818 /* NULL rectangle shouldn't crash */
819 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
820 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
822 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
826 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
827 SetRect(&rc_client, 0, 0, 250, 150);
828 CopyRect(&rc_window, &rc_client);
829 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
830 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
832 CopyRect(&rc, &rc_window);
833 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
834 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
835 ok(EqualRect(&rc, &rc_client),
836 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
837 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
838 rc.left, rc.top, rc.right, rc.bottom);
841 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
843 static const char *CBT_code_name[10] = {
854 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
855 HWND hwnd = (HWND)wParam;
861 static const RECT rc_null;
864 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
865 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
866 hwnd, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
867 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
872 info.cbSize = sizeof(WINDOWINFO);
873 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
874 verify_window_info(code_name, hwnd, &info);
877 /* WS_VISIBLE should be turned off yet */
878 style = createwnd->lpcs->style & ~WS_VISIBLE;
879 ok(style == GetWindowLongA(hwnd, GWL_STYLE),
880 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
881 GetWindowLongA(hwnd, GWL_STYLE), style);
885 /* Uncomment this once the test succeeds in all cases */
886 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
888 ok(GetParent(hwnd) == hwndMessage,
889 "wrong result from GetParent %p: message window %p\n",
890 GetParent(hwnd), hwndMessage);
893 ok(!GetParent(hwnd), "GetParent should return 0 at this point\n");
895 ok(!GetWindow(hwnd, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
899 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
900 * Win9x still has them set to 0.
902 ok(GetWindow(hwnd, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
903 ok(GetWindow(hwnd, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
905 ok(!GetWindow(hwnd, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
906 ok(!GetWindow(hwnd, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
910 /* Uncomment this once the test succeeds in all cases */
913 ok(pGetAncestor(hwnd, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
914 ok(pGetAncestor(hwnd, GA_ROOT) == hwnd,
915 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOT), hwnd);
917 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
918 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwndMessage,
919 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
921 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwnd,
922 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOTOWNER), hwnd);
925 ok(GetWindowRect(hwnd, &rc), "GetWindowRect failed\n");
926 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
927 ok(GetClientRect(hwnd, &rc), "GetClientRect failed\n");
928 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
936 if (pGetWindowInfo && IsWindow(hwnd))
940 /* Win98 actually does check the info.cbSize and doesn't allow
941 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
942 * WinXP do not check it at all.
944 info.cbSize = sizeof(WINDOWINFO);
945 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
946 verify_window_info(code_name, hwnd, &info);
949 /* on HCBT_DESTROYWND window state is undefined */
950 case HCBT_DESTROYWND:
951 trace( "HCBT_DESTROYWND: hwnd %p\n", hwnd );
957 return CallNextHookEx(hhook, nCode, wParam, lParam);
960 static void test_shell_window(void)
964 HMODULE hinst, hUser32;
965 BOOL (WINAPI*SetShellWindow)(HWND);
966 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
967 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
968 HWND shellWindow, nextWnd;
970 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
972 trace("Skipping shell window test on Win9x\n");
976 shellWindow = GetShellWindow();
977 hinst = GetModuleHandle(0);
978 hUser32 = GetModuleHandleA("user32");
980 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
981 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
983 trace("previous shell window: %p\n", shellWindow);
989 GetWindowThreadProcessId(shellWindow, &pid);
990 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
993 skip( "cannot get access to shell process\n" );
997 SetLastError(0xdeadbeef);
998 ret = DestroyWindow(shellWindow);
999 error = GetLastError();
1001 ok(!ret, "DestroyWindow(shellWindow)\n");
1002 /* passes on Win XP, but not on Win98 */
1003 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
1004 "got %u after DestroyWindow(shellWindow)\n", error);
1006 /* close old shell instance */
1007 ret = TerminateProcess(hProcess, 0);
1008 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1009 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
1010 CloseHandle(hProcess);
1013 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
1014 trace("created window 1: %p\n", hwnd1);
1016 ret = SetShellWindow(hwnd1);
1017 ok(ret, "first call to SetShellWindow(hwnd1)\n");
1018 shellWindow = GetShellWindow();
1019 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
1021 ret = SetShellWindow(hwnd1);
1022 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1024 ret = SetShellWindow(0);
1025 error = GetLastError();
1026 /* passes on Win XP, but not on Win98
1027 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1028 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1030 ret = SetShellWindow(hwnd1);
1031 /* passes on Win XP, but not on Win98
1032 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1034 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1035 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
1036 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1038 ret = DestroyWindow(hwnd1);
1039 ok(ret, "DestroyWindow(hwnd1)\n");
1041 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1042 trace("created window 2: %p\n", hwnd2);
1043 ret = SetShellWindow(hwnd2);
1044 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1046 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1047 trace("created window 3: %p\n", hwnd3);
1049 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1050 trace("created window 4: %p\n", hwnd4);
1052 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1053 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1055 ret = SetShellWindow(hwnd4);
1056 ok(ret, "SetShellWindow(hwnd4)\n");
1057 shellWindow = GetShellWindow();
1058 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1060 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1061 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1063 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1064 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1066 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1067 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1069 ret = SetShellWindow(hwnd3);
1070 ok(!ret, "SetShellWindow(hwnd3)\n");
1071 shellWindow = GetShellWindow();
1072 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1074 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1075 trace("created window 5: %p\n", hwnd5);
1076 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1077 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1081 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1082 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1085 /* destroy test windows */
1086 DestroyWindow(hwnd2);
1087 DestroyWindow(hwnd3);
1088 DestroyWindow(hwnd4);
1089 DestroyWindow(hwnd5);
1092 /************** MDI test ****************/
1094 static char mdi_lParam_test_message[] = "just a test string";
1096 static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
1098 MDICREATESTRUCTA mdi_cs;
1101 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1102 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1103 BOOL isWin9x = FALSE;
1105 mdi_cs.szClass = "MDI_child_Class_1";
1106 mdi_cs.szTitle = "MDI child";
1107 mdi_cs.hOwner = GetModuleHandle(0);
1108 mdi_cs.x = CW_USEDEFAULT;
1109 mdi_cs.y = CW_USEDEFAULT;
1110 mdi_cs.cx = CW_USEDEFAULT;
1111 mdi_cs.cy = CW_USEDEFAULT;
1113 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1114 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1115 ok(mdi_child != 0, "MDI child creation failed\n");
1116 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1117 ok(id == first_id, "wrong child id %ld\n", id);
1118 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1119 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1121 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1122 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1123 ok(mdi_child != 0, "MDI child creation failed\n");
1124 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1125 ok(id == first_id, "wrong child id %ld\n", id);
1126 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1127 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1129 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1130 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1131 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1133 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1137 ok(mdi_child != 0, "MDI child creation failed\n");
1138 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1139 ok(id == first_id, "wrong child id %ld\n", id);
1140 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1141 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1144 /* test MDICREATESTRUCT A<->W mapping */
1145 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1147 mdi_cs.szClass = (LPCSTR)classW;
1148 mdi_cs.szTitle = (LPCSTR)titleW;
1149 SetLastError(0xdeadbeef);
1150 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1153 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1156 ok(mdi_child != 0, "MDI child creation failed\n");
1160 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1161 ok(id == first_id, "wrong child id %ld\n", id);
1162 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1163 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1166 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1168 CW_USEDEFAULT, CW_USEDEFAULT,
1169 CW_USEDEFAULT, CW_USEDEFAULT,
1170 mdi_client, GetModuleHandle(0),
1171 (LPARAM)mdi_lParam_test_message);
1172 ok(mdi_child != 0, "MDI child creation failed\n");
1173 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1174 ok(id == first_id, "wrong child id %ld\n", id);
1175 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1176 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1178 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1179 0x7fffffff, /* without WS_POPUP */
1180 CW_USEDEFAULT, CW_USEDEFAULT,
1181 CW_USEDEFAULT, CW_USEDEFAULT,
1182 mdi_client, GetModuleHandle(0),
1183 (LPARAM)mdi_lParam_test_message);
1184 ok(mdi_child != 0, "MDI child creation failed\n");
1185 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1186 ok(id == first_id, "wrong child id %ld\n", id);
1187 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1188 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1190 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1191 0xffffffff, /* with WS_POPUP */
1192 CW_USEDEFAULT, CW_USEDEFAULT,
1193 CW_USEDEFAULT, CW_USEDEFAULT,
1194 mdi_client, GetModuleHandle(0),
1195 (LPARAM)mdi_lParam_test_message);
1196 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1198 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1202 ok(mdi_child != 0, "MDI child creation failed\n");
1203 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1204 ok(id == first_id, "wrong child id %ld\n", id);
1205 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1206 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1209 /* test MDICREATESTRUCT A<->W mapping */
1210 SetLastError(0xdeadbeef);
1211 mdi_child = CreateMDIWindowW(classW, titleW,
1213 CW_USEDEFAULT, CW_USEDEFAULT,
1214 CW_USEDEFAULT, CW_USEDEFAULT,
1215 mdi_client, GetModuleHandle(0),
1216 (LPARAM)mdi_lParam_test_message);
1219 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1222 ok(mdi_child != 0, "MDI child creation failed\n");
1226 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1227 ok(id == first_id, "wrong child id %ld\n", id);
1228 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1229 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1232 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1234 CW_USEDEFAULT, CW_USEDEFAULT,
1235 CW_USEDEFAULT, CW_USEDEFAULT,
1236 mdi_client, 0, GetModuleHandle(0),
1237 mdi_lParam_test_message);
1238 ok(mdi_child != 0, "MDI child creation failed\n");
1239 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1240 ok(id == first_id, "wrong child id %ld\n", id);
1241 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1242 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1244 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1245 0x7fffffff, /* without WS_POPUP */
1246 CW_USEDEFAULT, CW_USEDEFAULT,
1247 CW_USEDEFAULT, CW_USEDEFAULT,
1248 mdi_client, 0, GetModuleHandle(0),
1249 mdi_lParam_test_message);
1250 ok(mdi_child != 0, "MDI child creation failed\n");
1251 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1252 ok(id == first_id, "wrong child id %ld\n", id);
1253 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1254 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1256 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1257 0xffffffff, /* with WS_POPUP */
1258 CW_USEDEFAULT, CW_USEDEFAULT,
1259 CW_USEDEFAULT, CW_USEDEFAULT,
1260 mdi_client, 0, GetModuleHandle(0),
1261 mdi_lParam_test_message);
1262 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1264 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1268 ok(mdi_child != 0, "MDI child creation failed\n");
1269 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1270 ok(id == first_id, "wrong child id %ld\n", id);
1271 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1272 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1275 /* test MDICREATESTRUCT A<->W mapping */
1276 SetLastError(0xdeadbeef);
1277 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1279 CW_USEDEFAULT, CW_USEDEFAULT,
1280 CW_USEDEFAULT, CW_USEDEFAULT,
1281 mdi_client, 0, GetModuleHandle(0),
1282 mdi_lParam_test_message);
1285 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1288 ok(mdi_child != 0, "MDI child creation failed\n");
1292 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1293 ok(id == first_id, "wrong child id %ld\n", id);
1294 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1295 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1298 /* This test fails on Win9x */
1301 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1303 CW_USEDEFAULT, CW_USEDEFAULT,
1304 CW_USEDEFAULT, CW_USEDEFAULT,
1305 parent, 0, GetModuleHandle(0),
1306 mdi_lParam_test_message);
1307 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1310 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1311 WS_CHILD, /* without WS_POPUP */
1312 CW_USEDEFAULT, CW_USEDEFAULT,
1313 CW_USEDEFAULT, CW_USEDEFAULT,
1314 mdi_client, 0, GetModuleHandle(0),
1315 mdi_lParam_test_message);
1316 ok(mdi_child != 0, "MDI child creation failed\n");
1317 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1318 ok(id == 0, "wrong child id %ld\n", id);
1319 DestroyWindow(mdi_child);
1321 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1322 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1323 CW_USEDEFAULT, CW_USEDEFAULT,
1324 CW_USEDEFAULT, CW_USEDEFAULT,
1325 mdi_client, 0, GetModuleHandle(0),
1326 mdi_lParam_test_message);
1327 ok(mdi_child != 0, "MDI child creation failed\n");
1328 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1329 ok(id == 0, "wrong child id %ld\n", id);
1330 DestroyWindow(mdi_child);
1332 /* maximized child */
1333 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1334 WS_CHILD | WS_MAXIMIZE,
1335 CW_USEDEFAULT, CW_USEDEFAULT,
1336 CW_USEDEFAULT, CW_USEDEFAULT,
1337 mdi_client, 0, GetModuleHandle(0),
1338 mdi_lParam_test_message);
1339 ok(mdi_child != 0, "MDI child creation failed\n");
1340 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1341 ok(id == 0, "wrong child id %ld\n", id);
1342 DestroyWindow(mdi_child);
1344 trace("Creating maximized child with a caption\n");
1345 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1346 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1347 CW_USEDEFAULT, CW_USEDEFAULT,
1348 CW_USEDEFAULT, CW_USEDEFAULT,
1349 mdi_client, 0, GetModuleHandle(0),
1350 mdi_lParam_test_message);
1351 ok(mdi_child != 0, "MDI child creation failed\n");
1352 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1353 ok(id == 0, "wrong child id %ld\n", id);
1354 DestroyWindow(mdi_child);
1356 trace("Creating maximized child with a caption and a thick frame\n");
1357 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1358 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1359 CW_USEDEFAULT, CW_USEDEFAULT,
1360 CW_USEDEFAULT, CW_USEDEFAULT,
1361 mdi_client, 0, GetModuleHandle(0),
1362 mdi_lParam_test_message);
1363 ok(mdi_child != 0, "MDI child creation failed\n");
1364 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1365 ok(id == 0, "wrong child id %ld\n", id);
1366 DestroyWindow(mdi_child);
1369 /**********************************************************************
1370 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1372 * Note: The rule here is that client rect of the maximized MDI child
1373 * is equal to the client rect of the MDI client window.
1375 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1379 GetClientRect( client, &rect );
1380 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1381 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1383 rect.right -= rect.left;
1384 rect.bottom -= rect.top;
1385 lpMinMax->ptMaxSize.x = rect.right;
1386 lpMinMax->ptMaxSize.y = rect.bottom;
1388 lpMinMax->ptMaxPosition.x = rect.left;
1389 lpMinMax->ptMaxPosition.y = rect.top;
1391 trace("max rect (%d,%d - %d, %d)\n",
1392 rect.left, rect.top, rect.right, rect.bottom);
1395 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1402 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1403 MDICREATESTRUCTA *mdi_cs = cs->lpCreateParams;
1405 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1406 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1408 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1409 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1410 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1411 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1412 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1414 /* MDICREATESTRUCT should have original values */
1415 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1416 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1417 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1418 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1419 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1420 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1422 /* CREATESTRUCT should have fixed values */
1423 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1424 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1426 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1427 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1428 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1430 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1432 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1434 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1435 ok(cs->style == style,
1436 "cs->style does not match (%08x)\n", cs->style);
1440 LONG style = mdi_cs->style;
1442 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1443 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1444 ok(cs->style == style,
1445 "cs->style does not match (%08x)\n", cs->style);
1450 case WM_GETMINMAXINFO:
1452 HWND client = GetParent(hwnd);
1454 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1455 MINMAXINFO my_minmax;
1456 LONG style, exstyle;
1458 style = GetWindowLongA(hwnd, GWL_STYLE);
1459 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1461 GetWindowRect(client, &rc);
1462 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1463 GetClientRect(client, &rc);
1464 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1465 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1466 GetSystemMetrics(SM_CYSCREEN));
1468 GetClientRect(client, &rc);
1469 if ((style & WS_CAPTION) == WS_CAPTION)
1470 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1471 AdjustWindowRectEx(&rc, style, 0, exstyle);
1472 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1473 dump_minmax_info( minmax );
1475 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1476 minmax->ptMaxSize.x, rc.right - rc.left);
1477 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1478 minmax->ptMaxSize.y, rc.bottom - rc.top);
1480 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1482 trace("DefMDIChildProc returned:\n");
1483 dump_minmax_info( minmax );
1485 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1486 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1487 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1488 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1489 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1494 case WM_MDIACTIVATE:
1496 HWND active, client = GetParent(hwnd);
1497 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1498 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1499 if (hwnd == (HWND)lparam) /* if we are being activated */
1500 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1502 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1506 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1509 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1516 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1518 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE",
1519 cs->x, cs->y, cs->cx, cs->cy);
1521 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1522 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1524 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1525 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1527 /* CREATESTRUCT should have fixed values */
1528 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1530 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1531 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1533 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1534 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1535 while Win95, Win2k, WinXP do. */
1536 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1537 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1541 case WM_GETMINMAXINFO:
1543 HWND parent = GetParent(hwnd);
1545 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1546 LONG style, exstyle;
1548 style = GetWindowLongA(hwnd, GWL_STYLE);
1549 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1551 GetClientRect(parent, &rc);
1552 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1554 GetClientRect(parent, &rc);
1555 if ((style & WS_CAPTION) == WS_CAPTION)
1556 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1557 AdjustWindowRectEx(&rc, style, 0, exstyle);
1558 dump_minmax_info( minmax );
1560 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1561 minmax->ptMaxSize.x, rc.right - rc.left);
1562 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1563 minmax->ptMaxSize.y, rc.bottom - rc.top);
1567 case WM_WINDOWPOSCHANGED:
1569 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1572 GetWindowRect(hwnd, &rc1);
1573 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1574 /* note: winpos coordinates are relative to parent */
1575 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1576 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) pos=(%d,%d)-(%d,%d)\n",
1577 rc1.left, rc1.top, rc1.right, rc1.bottom,
1578 rc2.left, rc2.top, rc2.right, rc2.bottom);
1579 GetWindowRect(hwnd, &rc1);
1580 GetClientRect(hwnd, &rc2);
1581 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1582 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1583 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1584 rc1.left, rc1.top, rc1.right, rc1.bottom,
1585 rc2.left, rc2.top, rc2.right, rc2.bottom);
1588 case WM_WINDOWPOSCHANGING:
1590 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1591 WINDOWPOS my_winpos = *winpos;
1593 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1594 (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
1595 winpos->hwnd, winpos->hwndInsertAfter,
1596 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1598 DefWindowProcA(hwnd, msg, wparam, lparam);
1600 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1601 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1602 winpos->hwnd, winpos->hwndInsertAfter,
1603 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1608 return DefWindowProcA(hwnd, msg, wparam, lparam);
1611 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1613 static HWND mdi_client;
1619 CLIENTCREATESTRUCT client_cs;
1622 GetClientRect(hwnd, &rc);
1624 client_cs.hWindowMenu = 0;
1625 client_cs.idFirstChild = 1;
1627 /* MDIClient without MDIS_ALLCHILDSTYLES */
1628 mdi_client = CreateWindowExA(0, "mdiclient",
1630 WS_CHILD /*| WS_VISIBLE*/,
1631 /* tests depend on a not zero MDIClient size */
1632 0, 0, rc.right, rc.bottom,
1633 hwnd, 0, GetModuleHandle(0),
1636 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1637 DestroyWindow(mdi_client);
1639 /* MDIClient with MDIS_ALLCHILDSTYLES */
1640 mdi_client = CreateWindowExA(0, "mdiclient",
1642 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1643 /* tests depend on a not zero MDIClient size */
1644 0, 0, rc.right, rc.bottom,
1645 hwnd, 0, GetModuleHandle(0),
1648 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1649 DestroyWindow(mdi_client);
1653 case WM_WINDOWPOSCHANGED:
1655 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1658 GetWindowRect(hwnd, &rc1);
1659 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1660 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1661 /* note: winpos coordinates are relative to parent */
1662 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1663 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1664 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1666 GetWindowRect(hwnd, &rc1);
1667 GetClientRect(hwnd, &rc2);
1668 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1669 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1670 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1673 case WM_WINDOWPOSCHANGING:
1675 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1676 WINDOWPOS my_winpos = *winpos;
1678 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1679 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1680 winpos->hwnd, winpos->hwndInsertAfter,
1681 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1683 DefWindowProcA(hwnd, msg, wparam, lparam);
1685 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1686 winpos->hwnd, winpos->hwndInsertAfter,
1687 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1689 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1690 "DefWindowProc should not change WINDOWPOS values\n");
1699 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1702 static BOOL mdi_RegisterWindowClasses(void)
1707 cls.lpfnWndProc = mdi_main_wnd_procA;
1710 cls.hInstance = GetModuleHandleA(0);
1712 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1713 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1714 cls.lpszMenuName = NULL;
1715 cls.lpszClassName = "MDI_parent_Class";
1716 if(!RegisterClassA(&cls)) return FALSE;
1718 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1719 cls.lpszClassName = "MDI_child_Class_1";
1720 if(!RegisterClassA(&cls)) return FALSE;
1722 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1723 cls.lpszClassName = "MDI_child_Class_2";
1724 if(!RegisterClassA(&cls)) return FALSE;
1729 static void test_mdi(void)
1734 if (!mdi_RegisterWindowClasses()) assert(0);
1736 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1737 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1738 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1739 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1740 GetDesktopWindow(), 0,
1741 GetModuleHandle(0), NULL);
1742 assert(mdi_hwndMain);
1744 while(GetMessage(&msg, 0, 0, 0))
1746 TranslateMessage(&msg);
1747 DispatchMessage(&msg);
1750 DestroyWindow(mdi_hwndMain);
1753 static void test_icons(void)
1757 HICON icon = LoadIconA(0, IDI_APPLICATION);
1758 HICON icon2 = LoadIconA(0, IDI_QUESTION);
1759 HICON small_icon = LoadImageA(0, IDI_APPLICATION, IMAGE_ICON,
1760 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1763 cls.cbSize = sizeof(cls);
1765 cls.lpfnWndProc = DefWindowProcA;
1769 cls.hIcon = LoadIconA(0, IDI_HAND);
1770 cls.hIconSm = small_icon;
1771 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1772 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1773 cls.lpszMenuName = NULL;
1774 cls.lpszClassName = "IconWindowClass";
1776 RegisterClassExA(&cls);
1778 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1779 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1782 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1783 ok( res == 0, "wrong big icon %p/0\n", res );
1784 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1785 ok( res == 0, "wrong previous big icon %p/0\n", res );
1786 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1787 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1788 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1789 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1790 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1791 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1793 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1794 ok( res == 0, "wrong small icon %p/0\n", res );
1795 /* this test is XP specific */
1796 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1797 ok( res != 0, "wrong small icon %p\n", res );*/
1798 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1799 ok( res == 0, "wrong previous small icon %p/0\n", res );
1800 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1801 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1802 /* this test is XP specific */
1803 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1804 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1805 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1806 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1807 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1808 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1809 /* this test is XP specific */
1810 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1811 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1813 /* make sure the big icon hasn't changed */
1814 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1815 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1817 DestroyWindow( hwnd );
1820 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1822 if (msg == WM_NCCALCSIZE)
1824 RECT *rect = (RECT *)lparam;
1825 /* first time around increase the rectangle, next time decrease it */
1826 if (rect->left == 100) InflateRect( rect, 10, 10 );
1827 else InflateRect( rect, -10, -10 );
1830 return DefWindowProc( hwnd, msg, wparam, lparam );
1833 static void test_SetWindowPos(HWND hwnd)
1835 RECT orig_win_rc, rect;
1837 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1839 SetRect(&rect, 111, 222, 333, 444);
1840 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1841 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1842 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1844 SetRect(&rect, 111, 222, 333, 444);
1845 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1846 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1847 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1849 GetWindowRect(hwnd, &orig_win_rc);
1851 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1852 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1853 GetWindowRect( hwnd, &rect );
1854 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1855 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1856 GetClientRect( hwnd, &rect );
1857 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1858 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1859 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1861 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1862 GetWindowRect( hwnd, &rect );
1863 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1864 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1865 GetClientRect( hwnd, &rect );
1866 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1867 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1868 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1870 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1871 orig_win_rc.right, orig_win_rc.bottom, 0);
1872 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1874 /* Win9x truncates coordinates to 16-bit irrespectively */
1877 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1878 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1880 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1881 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1884 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1885 orig_win_rc.right, orig_win_rc.bottom, 0);
1887 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1888 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1889 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1890 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1891 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1892 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1893 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1896 static void test_SetMenu(HWND parent)
1900 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1904 hMenu = CreateMenu();
1907 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1910 /* fails on (at least) Wine, NT4, XP SP2 */
1911 test_nonclient_area(parent);
1913 ret = GetMenu(parent);
1914 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1915 /* test whether we can destroy a menu assigned to a window */
1916 retok = DestroyMenu(hMenu);
1917 ok( retok, "DestroyMenu error %d\n", GetLastError());
1918 retok = IsMenu(hMenu);
1919 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
1920 ret = GetMenu(parent);
1921 /* This test fails on Win9x */
1923 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1924 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1925 test_nonclient_area(parent);
1927 hMenu = CreateMenu();
1931 ret = GetMenu(parent);
1932 ok(ret == 0, "unexpected menu id %p\n", ret);
1934 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1935 test_nonclient_area(parent);
1936 ret = GetMenu(parent);
1937 ok(ret == 0, "unexpected menu id %p\n", ret);
1939 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1942 /* fails on (at least) Wine, NT4, XP SP2 */
1943 test_nonclient_area(parent);
1945 ret = GetMenu(parent);
1946 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1948 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1949 test_nonclient_area(parent);
1950 ret = GetMenu(parent);
1951 ok(ret == 0, "unexpected menu id %p\n", ret);
1954 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1957 ret = GetMenu(child);
1958 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1960 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1961 test_nonclient_area(child);
1962 ret = GetMenu(child);
1963 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1965 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1966 test_nonclient_area(child);
1967 ret = GetMenu(child);
1968 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1970 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1971 test_nonclient_area(child);
1972 ret = GetMenu(child);
1973 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1975 style = GetWindowLong(child, GWL_STYLE);
1976 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
1977 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
1978 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
1979 SetWindowLong(child, GWL_STYLE, style);
1981 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
1982 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
1983 SetWindowLong(child, GWL_STYLE, style);
1985 DestroyWindow(child);
1989 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1991 HWND child[5], hwnd;
1996 hwnd = GetWindow(parent, GW_CHILD);
1997 ok(!hwnd, "have to start without children to perform the test\n");
1999 for (i = 0; i < total; i++)
2001 if (style[i] & DS_CONTROL)
2003 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
2004 0,0,0,0, parent, (HMENU)i, 0, NULL);
2005 if (style[i] & WS_VISIBLE)
2006 ShowWindow(child[i], SW_SHOW);
2008 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
2011 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
2012 parent, (HMENU)i, 0, NULL);
2013 trace("child[%ld] = %p\n", i, child[i]);
2014 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
2017 hwnd = GetWindow(parent, GW_CHILD);
2018 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
2019 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
2020 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
2022 for (i = 0; i < total; i++)
2024 trace("hwnd[%ld] = %p\n", i, hwnd);
2025 ok(child[order[i]] == hwnd, "Z order of child #%ld is wrong\n", i);
2027 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
2030 for (i = 0; i < total; i++)
2031 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2034 static void test_children_zorder(HWND parent)
2036 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2038 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2040 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2041 WS_CHILD | WS_VISIBLE, WS_CHILD,
2042 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2043 const int complex_order_1[1] = { 0 };
2044 const int complex_order_2[2] = { 1, 0 };
2045 const int complex_order_3[3] = { 1, 0, 2 };
2046 const int complex_order_4[4] = { 1, 0, 2, 3 };
2047 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2048 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2049 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2050 WS_CHILD | WS_VISIBLE };
2051 const int complex_order_6[3] = { 0, 1, 2 };
2053 /* simple WS_CHILD */
2054 test_window_tree(parent, simple_style, simple_order, 5);
2056 /* complex children styles */
2057 test_window_tree(parent, complex_style, complex_order_1, 1);
2058 test_window_tree(parent, complex_style, complex_order_2, 2);
2059 test_window_tree(parent, complex_style, complex_order_3, 3);
2060 test_window_tree(parent, complex_style, complex_order_4, 4);
2061 test_window_tree(parent, complex_style, complex_order_5, 5);
2063 /* another set of complex children styles */
2064 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2067 #define check_z_order(hwnd, next, prev, owner, topmost) \
2068 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2071 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2072 BOOL topmost, const char *file, int line)
2077 test = GetWindow(hwnd, GW_HWNDNEXT);
2078 /* skip foreign windows */
2079 while (test && (GetWindowThreadProcessId(test, NULL) != our_pid ||
2080 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0)))
2082 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2083 test = GetWindow(test, GW_HWNDNEXT);
2085 ok_(file, line)(next == test, "expected next %p, got %p\n", next, test);
2087 test = GetWindow(hwnd, GW_HWNDPREV);
2088 /* skip foreign windows */
2089 while (test && (GetWindowThreadProcessId(test, NULL) != our_pid ||
2090 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0)))
2092 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2093 test = GetWindow(test, GW_HWNDPREV);
2095 ok_(file, line)(prev == test, "expected prev %p, got %p\n", prev, test);
2097 test = GetWindow(hwnd, GW_OWNER);
2098 ok_(file, line)(owner == test, "expected owner %p, got %p\n", owner, test);
2100 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2101 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "expected %stopmost\n", topmost ? "" : "NOT ");
2104 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E)
2106 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2108 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2110 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2112 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2113 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2115 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2116 WS_OVERLAPPED | WS_CAPTION,
2118 0, 0, GetModuleHandle(0), NULL);
2119 trace("hwnd_F %p\n", hwnd_F);
2120 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2122 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2123 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2124 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2125 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2127 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2130 hwnd_F, 0, GetModuleHandle(0), NULL);
2131 trace("hwnd_C %p\n", hwnd_C);
2132 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2133 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2134 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2135 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2137 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2140 hwnd_F, 0, GetModuleHandle(0), NULL);
2141 trace("hwnd_B %p\n", hwnd_B);
2142 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2143 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2144 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2145 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2146 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2148 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2151 0, 0, GetModuleHandle(0), NULL);
2152 trace("hwnd_A %p\n", hwnd_A);
2153 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2154 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2155 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2156 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2157 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2158 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2160 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);
2162 /* move hwnd_F and its popups up */
2163 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2164 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2165 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2166 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2167 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2168 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2169 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2171 /* move hwnd_F and its popups down */
2172 #if 0 /* enable once Wine is fixed to pass this test */
2173 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2174 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2175 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2176 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2177 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2178 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2179 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2182 DestroyWindow(hwnd_A);
2183 DestroyWindow(hwnd_B);
2184 DestroyWindow(hwnd_C);
2185 DestroyWindow(hwnd_F);
2188 static void test_vis_rgn( HWND hwnd )
2190 RECT win_rect, rgn_rect;
2191 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2194 ShowWindow(hwnd,SW_SHOW);
2195 hdc = GetDC( hwnd );
2196 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2197 GetWindowRect( hwnd, &win_rect );
2198 GetRgnBox( hrgn, &rgn_rect );
2199 if (GetVersion() & 0x80000000)
2201 trace("win9x, mapping to screen coords\n");
2202 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2204 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2205 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2206 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2207 rgn_rect.left, win_rect.left );
2208 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2209 rgn_rect.top, win_rect.top );
2210 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2211 rgn_rect.right, win_rect.right );
2212 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2213 rgn_rect.bottom, win_rect.bottom );
2214 ReleaseDC( hwnd, hdc );
2217 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2219 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2221 HWND child = GetWindow(hwnd, GW_CHILD);
2222 ok(child != 0, "couldn't find child window\n");
2224 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2227 return DefWindowProc(hwnd, msg, wp, lp);
2230 static void test_SetFocus(HWND hwnd)
2233 WNDPROC old_wnd_proc;
2235 /* check if we can set focus to non-visible windows */
2237 ShowWindow(hwnd, SW_SHOW);
2240 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2241 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2242 ShowWindow(hwnd, SW_HIDE);
2245 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2246 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2247 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2250 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2251 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2252 ShowWindow(child, SW_SHOW);
2253 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2254 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2255 ShowWindow(child, SW_HIDE);
2256 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2257 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2258 ShowWindow(child, SW_SHOW);
2260 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2261 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2262 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2264 ShowWindow(child, SW_HIDE);
2266 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2267 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2268 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2269 ShowWindow(child, SW_HIDE);
2270 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2272 ShowWindow(hwnd, SW_SHOW);
2273 ShowWindow(child, SW_SHOW);
2275 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2276 EnableWindow(hwnd, FALSE);
2277 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2278 EnableWindow(hwnd, TRUE);
2280 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2281 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2282 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2284 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2285 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2286 ShowWindow(hwnd, SW_RESTORE);
2287 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2288 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2289 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2290 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2291 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2293 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2294 old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2295 ShowWindow(hwnd, SW_RESTORE);
2296 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2298 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2300 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2302 DestroyWindow( child );
2305 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
2306 static void check_wnd_state_(const char *file, int line,
2307 HWND active, HWND foreground, HWND focus, HWND capture)
2309 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2310 if (foreground && GetForegroundWindow())
2311 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2312 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2313 ok_(file, line)(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2316 static void test_SetActiveWindow(HWND hwnd)
2320 flush_events( TRUE );
2321 ShowWindow(hwnd, SW_HIDE);
2324 check_wnd_state(0, 0, 0, 0);
2326 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2328 ShowWindow(hwnd, SW_SHOW);
2329 check_wnd_state(hwnd, hwnd, hwnd, 0);
2331 hwnd2 = SetActiveWindow(0);
2332 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2333 if (!GetActiveWindow()) /* doesn't always work on vista */
2335 check_wnd_state(0, 0, 0, 0);
2336 hwnd2 = SetActiveWindow(hwnd);
2337 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2339 check_wnd_state(hwnd, hwnd, hwnd, 0);
2341 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2342 check_wnd_state(hwnd, hwnd, hwnd, 0);
2344 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2345 check_wnd_state(hwnd, hwnd, hwnd, 0);
2347 ShowWindow(hwnd, SW_HIDE);
2348 check_wnd_state(0, 0, 0, 0);
2350 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2351 SetActiveWindow(hwnd);
2352 check_wnd_state(hwnd, hwnd, hwnd, 0);
2354 ShowWindow(hwnd, SW_SHOW);
2355 check_wnd_state(hwnd, hwnd, hwnd, 0);
2357 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2358 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2360 DestroyWindow(hwnd2);
2361 check_wnd_state(hwnd, hwnd, hwnd, 0);
2363 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2364 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2366 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2367 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2369 DestroyWindow(hwnd2);
2370 check_wnd_state(hwnd, hwnd, hwnd, 0);
2373 static void test_SetForegroundWindow(HWND hwnd)
2378 flush_events( TRUE );
2379 ShowWindow(hwnd, SW_HIDE);
2382 check_wnd_state(0, 0, 0, 0);
2384 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2386 ShowWindow(hwnd, SW_SHOW);
2387 check_wnd_state(hwnd, hwnd, hwnd, 0);
2389 hwnd2 = SetActiveWindow(0);
2390 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2391 if (GetActiveWindow() == hwnd) /* doesn't always work on vista */
2392 check_wnd_state(hwnd, hwnd, hwnd, 0);
2394 check_wnd_state(0, 0, 0, 0);
2396 ret = SetForegroundWindow(hwnd);
2397 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2398 check_wnd_state(hwnd, hwnd, hwnd, 0);
2400 SetLastError(0xdeadbeef);
2401 ret = SetForegroundWindow(0);
2402 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2403 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
2404 broken(GetLastError() == 0xdeadbeef), /* win9x */
2405 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2406 check_wnd_state(hwnd, hwnd, hwnd, 0);
2408 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2409 check_wnd_state(hwnd, hwnd, hwnd, 0);
2411 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2412 check_wnd_state(hwnd, hwnd, hwnd, 0);
2414 hwnd2 = GetForegroundWindow();
2415 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2416 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2417 hwnd2 = GetForegroundWindow();
2418 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2420 ShowWindow(hwnd, SW_HIDE);
2421 check_wnd_state(0, 0, 0, 0);
2423 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2424 ret = SetForegroundWindow(hwnd);
2425 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2426 check_wnd_state(hwnd, hwnd, hwnd, 0);
2428 ShowWindow(hwnd, SW_SHOW);
2429 check_wnd_state(hwnd, hwnd, hwnd, 0);
2431 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2432 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2434 DestroyWindow(hwnd2);
2435 check_wnd_state(hwnd, hwnd, hwnd, 0);
2437 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2438 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2440 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2441 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2443 DestroyWindow(hwnd2);
2444 check_wnd_state(hwnd, hwnd, hwnd, 0);
2447 static WNDPROC old_button_proc;
2449 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2454 key_state = GetKeyState(VK_LBUTTON);
2455 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2457 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2459 if (msg == WM_LBUTTONDOWN)
2463 check_wnd_state(button, button, button, button);
2465 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2467 trace("hwnd %p\n", hwnd);
2469 check_wnd_state(button, button, button, button);
2471 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2473 check_wnd_state(button, button, button, button);
2475 DestroyWindow(hwnd);
2477 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2479 trace("hwnd %p\n", hwnd);
2481 check_wnd_state(button, button, button, button);
2483 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2484 * match internal button state.
2486 SendMessage(button, WM_KILLFOCUS, 0, 0);
2487 check_wnd_state(button, button, button, 0);
2489 ShowWindow(hwnd, SW_SHOW);
2490 check_wnd_state(hwnd, hwnd, hwnd, 0);
2492 capture = SetCapture(hwnd);
2493 ok(capture == 0, "SetCapture() = %p\n", capture);
2495 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2497 DestroyWindow(hwnd);
2499 check_wnd_state(button, 0, button, 0);
2505 static void test_capture_1(void)
2507 HWND button, capture, oldFocus, oldActive;
2509 oldFocus = GetFocus();
2510 oldActive = GetActiveWindow();
2512 capture = GetCapture();
2513 ok(capture == 0, "GetCapture() = %p\n", capture);
2515 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2517 trace("button %p\n", button);
2519 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2521 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2523 capture = SetCapture(button);
2524 ok(capture == 0, "SetCapture() = %p\n", capture);
2525 check_wnd_state(button, 0, button, button);
2527 DestroyWindow(button);
2528 check_wnd_state(oldActive, 0, oldFocus, 0);
2531 static void test_capture_2(void)
2533 HWND button, hwnd, capture, oldFocus, oldActive;
2535 oldFocus = GetFocus();
2536 oldActive = GetActiveWindow();
2537 check_wnd_state(oldActive, 0, oldFocus, 0);
2539 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2541 trace("button %p\n", button);
2543 check_wnd_state(button, button, button, 0);
2545 capture = SetCapture(button);
2546 ok(capture == 0, "SetCapture() = %p\n", capture);
2548 check_wnd_state(button, button, button, button);
2550 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2551 * internal button state.
2553 SendMessage(button, WM_KILLFOCUS, 0, 0);
2554 check_wnd_state(button, button, button, button);
2556 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2558 trace("hwnd %p\n", hwnd);
2560 check_wnd_state(button, button, button, button);
2562 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2564 check_wnd_state(button, button, button, button);
2566 DestroyWindow(hwnd);
2568 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2570 trace("hwnd %p\n", hwnd);
2572 check_wnd_state(button, button, button, button);
2574 ShowWindow(hwnd, SW_SHOW);
2576 check_wnd_state(hwnd, hwnd, hwnd, button);
2578 capture = SetCapture(hwnd);
2579 ok(capture == button, "SetCapture() = %p\n", capture);
2581 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2583 DestroyWindow(hwnd);
2584 check_wnd_state(button, button, button, 0);
2586 DestroyWindow(button);
2587 check_wnd_state(oldActive, 0, oldFocus, 0);
2590 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2594 ShowWindow(hwnd1, SW_HIDE);
2595 ShowWindow(hwnd2, SW_HIDE);
2597 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2598 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2601 check_wnd_state(0, 0, 0, hwnd1);
2604 check_wnd_state(0, 0, 0, hwnd2);
2606 ShowWindow(hwnd1, SW_SHOW);
2607 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2609 ret = ReleaseCapture();
2610 ok (ret, "releasecapture did not return TRUE.\n");
2611 ret = ReleaseCapture();
2612 ok (ret, "releasecapture did not return TRUE after second try.\n");
2615 static void test_keyboard_input(HWND hwnd)
2620 flush_events( TRUE );
2621 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
2623 flush_events( TRUE );
2625 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2628 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2630 flush_events( TRUE );
2632 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2635 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2636 ok( ret, "no message available\n");
2638 while (ret && msg.message >= 0xc000);
2639 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2641 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2642 while (ret && (msg.message == WM_TIMER || msg.message >= 0xc000));
2643 ok( !ret, "message %04x available\n", msg.message);
2645 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2647 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2648 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2649 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2650 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2651 ok( !ret, "message %04x available\n", msg.message);
2653 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2655 keybd_event(VK_SPACE, 0, 0, 0);
2656 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2657 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2658 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2659 ok( !ret, "message %04x available\n", msg.message);
2662 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2664 flush_events( TRUE );
2666 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2667 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2668 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2669 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2670 ok( !ret, "message %04x available\n", msg.message);
2672 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2674 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2675 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2676 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2677 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2678 ok( !ret, "message %04x available\n", msg.message);
2680 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2682 keybd_event(VK_SPACE, 0, 0, 0);
2683 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2684 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2685 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2686 ok( !ret, "message %04x available\n", msg.message);
2689 static BOOL wait_for_message( MSG *msg )
2695 ret = PeekMessageA(msg, 0, 0, 0, PM_REMOVE);
2698 if (msg->message == WM_PAINT) DispatchMessage(msg);
2699 else if (msg->message < 0xc000) break; /* skip registered messages */
2701 else if (MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
2703 if (!ret) msg->message = 0;
2707 static void test_mouse_input(HWND hwnd)
2717 ShowWindow(hwnd, SW_SHOW);
2719 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2721 GetWindowRect(hwnd, &rc);
2722 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2724 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2725 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2728 ShowWindow(popup, SW_SHOW);
2729 UpdateWindow(popup);
2730 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2732 GetWindowRect(popup, &rc);
2733 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2735 x = rc.left + (rc.right - rc.left) / 2;
2736 y = rc.top + (rc.bottom - rc.top) / 2;
2737 trace("setting cursor to (%d,%d)\n", x, y);
2741 ok(x == pt.x && y == pt.y, "wrong cursor pos (%d,%d), expected (%d,%d)\n", pt.x, pt.y, x, y);
2743 flush_events( TRUE );
2745 /* Check that setting the same position may generate WM_MOUSEMOVE */
2749 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2750 while (ret && msg.message >= 0xc000); /* skip registered messages */
2753 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
2754 msg.hwnd, msg.message);
2755 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
2756 x, y, msg.pt.x, msg.pt.y);
2759 /* force the system to update its internal queue mouse position,
2760 * otherwise it won't generate relative mouse movements below.
2762 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2763 flush_events( TRUE );
2766 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2767 flush_events( FALSE );
2768 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2769 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2771 if (msg.message == WM_TIMER || msg.message >= 0xc000) continue; /* skip registered messages */
2772 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
2773 "hwnd %p message %04x\n", msg.hwnd, msg.message);
2775 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2776 ok( !ret, "message %04x available\n", msg.message);
2778 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2779 ShowWindow(popup, SW_HIDE);
2780 ret = wait_for_message( &msg );
2782 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2783 flush_events( TRUE );
2785 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2786 ShowWindow(hwnd, SW_HIDE);
2787 ret = wait_for_message( &msg );
2788 ok( !ret, "message %04x available\n", msg.message);
2789 flush_events( TRUE );
2791 /* test mouse clicks */
2793 ShowWindow(hwnd, SW_SHOW);
2794 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2795 flush_events( TRUE );
2796 ShowWindow(popup, SW_SHOW);
2797 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2798 flush_events( TRUE );
2800 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2801 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2802 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2803 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2805 ret = wait_for_message( &msg );
2806 ok(ret, "no message available\n");
2807 if (msg.message == WM_MOUSEMOVE) /* win2k has an extra WM_MOUSEMOVE here */
2809 ret = wait_for_message( &msg );
2810 ok(ret, "no message available\n");
2813 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2814 msg.hwnd, popup, msg.message);
2816 ret = wait_for_message( &msg );
2817 ok(ret, "no message available\n");
2818 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2819 msg.hwnd, popup, msg.message);
2821 ret = wait_for_message( &msg );
2822 ok(ret, "no message available\n");
2823 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
2824 msg.hwnd, popup, msg.message);
2826 ret = wait_for_message( &msg );
2827 ok(ret, "no message available\n");
2828 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2829 msg.hwnd, popup, msg.message);
2831 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2832 ok(!ret, "message %04x available\n", msg.message);
2834 ShowWindow(popup, SW_HIDE);
2835 flush_events( TRUE );
2837 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2838 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2839 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2840 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2842 ret = wait_for_message( &msg );
2843 ok(ret, "no message available\n");
2844 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2845 msg.hwnd, hwnd, msg.message);
2846 ret = wait_for_message( &msg );
2847 ok(ret, "no message available\n");
2848 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2849 msg.hwnd, hwnd, msg.message);
2851 test_lbuttondown_flag = TRUE;
2852 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
2853 test_lbuttondown_flag = FALSE;
2855 ret = wait_for_message( &msg );
2856 ok(ret, "no message available\n");
2857 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2858 msg.hwnd, popup, msg.message);
2859 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2860 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2861 msg.hwnd, popup, msg.message);
2862 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2864 /* Test WM_MOUSEACTIVATE */
2865 #define TEST_MOUSEACTIVATE(A,B) \
2866 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2867 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2869 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
2870 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
2871 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
2872 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
2873 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
2874 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
2875 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
2876 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
2877 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
2878 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
2879 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
2880 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
2881 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
2882 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
2883 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
2884 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
2885 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
2886 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
2887 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
2888 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
2889 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
2890 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
2891 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
2892 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
2894 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2895 flush_events( TRUE );
2897 DestroyWindow(popup);
2900 static void test_validatergn(HWND hwnd)
2906 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
2907 ShowWindow(hwnd, SW_SHOW);
2908 UpdateWindow( hwnd);
2909 /* test that ValidateRect validates children*/
2910 InvalidateRect( child, NULL, 1);
2911 GetWindowRect( child, &rc);
2912 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2913 ret = GetUpdateRect( child, &rc2, 0);
2914 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
2915 "Update rectangle is empty!\n");
2916 ValidateRect( hwnd, &rc);
2917 ret = GetUpdateRect( child, &rc2, 0);
2918 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2919 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2920 rc2.right, rc2.bottom);
2922 /* now test ValidateRgn */
2923 InvalidateRect( child, NULL, 1);
2924 GetWindowRect( child, &rc);
2925 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2926 rgn = CreateRectRgnIndirect( &rc);
2927 ValidateRgn( hwnd, rgn);
2928 ret = GetUpdateRect( child, &rc2, 0);
2929 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2930 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2931 rc2.right, rc2.bottom);
2934 DestroyWindow( child );
2937 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
2940 MoveWindow( hwnd, 0, 0, x, y, 0);
2941 GetWindowRect( hwnd, prc);
2943 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
2944 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
2945 rc.left,rc.top,rc.right,rc.bottom, prc->left,prc->top,prc->right,prc->bottom);
2948 static void test_nccalcscroll(HWND parent)
2951 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
2952 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
2953 HWND hwnd = CreateWindowExA(0, "static", NULL,
2954 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
2955 10, 10, 200, 200, parent, 0, 0, NULL);
2956 ShowWindow( parent, SW_SHOW);
2957 UpdateWindow( parent);
2959 /* test window too low for a horizontal scroll bar */
2960 nccalchelper( hwnd, 100, sbheight, &rc1);
2961 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
2962 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
2964 /* test window just high enough for a horizontal scroll bar */
2965 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
2966 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
2967 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2969 /* test window too narrow for a vertical scroll bar */
2970 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
2971 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
2972 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2974 /* test window just wide enough for a vertical scroll bar */
2975 nccalchelper( hwnd, sbwidth, 100, &rc1);
2976 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
2977 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
2979 /* same test, but with client edge: not enough width */
2980 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
2981 nccalchelper( hwnd, sbwidth, 100, &rc1);
2982 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
2983 "Width should be %d size is %d,%d - %d,%d\n",
2984 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
2986 DestroyWindow( hwnd);
2989 static void test_SetParent(void)
2992 HWND desktop = GetDesktopWindow();
2994 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
2995 HWND parent, child1, child2, child3, child4, sibling;
2997 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2998 100, 100, 200, 200, 0, 0, 0, NULL);
2999 assert(parent != 0);
3000 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3001 0, 0, 50, 50, parent, 0, 0, NULL);
3002 assert(child1 != 0);
3003 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3004 0, 0, 50, 50, child1, 0, 0, NULL);
3005 assert(child2 != 0);
3006 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3007 0, 0, 50, 50, child2, 0, 0, NULL);
3008 assert(child3 != 0);
3009 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3010 0, 0, 50, 50, child3, 0, 0, NULL);
3011 assert(child4 != 0);
3013 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
3014 parent, child1, child2, child3, child4);
3016 check_parents(parent, desktop, 0, 0, 0, parent, parent);
3017 check_parents(child1, parent, parent, parent, 0, parent, parent);
3018 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3019 check_parents(child3, child2, child2, child2, 0, child2, parent);
3020 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3022 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
3023 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
3024 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3025 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
3026 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3028 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
3029 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3030 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
3031 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
3032 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
3033 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
3034 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
3035 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3036 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3038 if (!is_win9x) /* Win9x doesn't survive this test */
3040 ok(!SetParent(parent, child1), "SetParent should fail\n");
3041 ok(!SetParent(child2, child3), "SetParent should fail\n");
3042 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
3043 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
3044 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
3045 ok(!SetParent(child2, parent), "SetParent should fail\n");
3046 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
3048 check_parents(parent, child4, child4, 0, 0, child4, parent);
3049 check_parents(child1, parent, parent, parent, 0, child4, parent);
3050 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3051 check_parents(child3, child2, child2, child2, 0, child2, parent);
3052 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3055 hMenu = CreateMenu();
3056 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3057 100, 100, 200, 200, 0, hMenu, 0, NULL);
3058 assert(sibling != 0);
3060 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
3061 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
3063 ret = DestroyWindow(parent);
3064 ok( ret, "DestroyWindow() error %d\n", GetLastError());
3066 ok(!IsWindow(parent), "parent still exists\n");
3067 ok(!IsWindow(sibling), "sibling still exists\n");
3068 ok(!IsWindow(child1), "child1 still exists\n");
3069 ok(!IsWindow(child2), "child2 still exists\n");
3070 ok(!IsWindow(child3), "child3 still exists\n");
3071 ok(!IsWindow(child4), "child4 still exists\n");
3074 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3076 LPCREATESTRUCT lpcs;
3083 lpcs = (LPCREATESTRUCT)lparam;
3084 lpss = lpcs->lpCreateParams;
3087 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
3088 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
3089 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
3090 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
3092 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3094 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
3095 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
3096 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
3098 ok(lpss->styleNew == lpcs->style,
3099 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3100 lpss->styleNew, lpcs->style);
3104 return DefWindowProc(hwnd, msg, wparam, lparam);
3107 static ATOM atomStyleCheckClass;
3109 static void register_style_check_class(void)
3117 GetModuleHandle(NULL),
3119 LoadCursor(NULL, IDC_ARROW),
3120 (HBRUSH)(COLOR_BTNFACE+1),
3122 TEXT("WineStyleCheck"),
3125 atomStyleCheckClass = RegisterClass(&wc);
3128 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3130 DWORD dwActualStyle;
3131 DWORD dwActualExStyle;
3134 HWND hwndParent = NULL;
3136 ss.styleNew = dwStyleIn;
3137 ss.styleOld = dwExStyleIn;
3139 if (dwStyleIn & WS_CHILD)
3141 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
3142 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3145 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
3146 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3149 flush_events( TRUE );
3151 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3152 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3153 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3154 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3155 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3157 DestroyWindow(hwnd);
3158 if (hwndParent) DestroyWindow(hwndParent);
3161 /* tests what window styles the window manager automatically adds */
3162 static void test_window_styles(void)
3164 register_style_check_class();
3166 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3167 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3168 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3169 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3170 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3171 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3172 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3173 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3174 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3175 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3176 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3179 static void test_scrollvalidate( HWND parent)
3182 HRGN hrgn=CreateRectRgn(0,0,0,0);
3183 HRGN exprgn, tmprgn, clipping;
3184 RECT rc, rcu, cliprc;
3185 /* create two overlapping child windows. The visual region
3186 * of hwnd1 is clipped by the overlapping part of
3187 * hwnd2 because of the WS_CLIPSIBLING style */
3190 clipping = CreateRectRgn(0,0,0,0);
3191 tmprgn = CreateRectRgn(0,0,0,0);
3192 exprgn = CreateRectRgn(0,0,0,0);
3193 hwnd2 = CreateWindowExA(0, "static", NULL,
3194 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3195 75, 30, 100, 100, parent, 0, 0, NULL);
3196 hwnd1 = CreateWindowExA(0, "static", NULL,
3197 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3198 25, 50, 100, 100, parent, 0, 0, NULL);
3199 ShowWindow( parent, SW_SHOW);
3200 UpdateWindow( parent);
3201 GetClientRect( hwnd1, &rc);
3203 SetRectRgn( clipping, 10, 10, 90, 90);
3204 hdc = GetDC( hwnd1);
3205 /* for a visual touch */
3206 TextOut( hdc, 0,10, "0123456789", 10);
3207 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3208 if (winetest_debug > 0) dump_region(hrgn);
3209 /* create a region with what is expected */
3210 SetRectRgn( exprgn, 39,0,49,74);
3211 SetRectRgn( tmprgn, 88,79,98,93);
3212 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3213 SetRectRgn( tmprgn, 0,93,98,98);
3214 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3215 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3216 trace("update rect is %d,%d - %d,%d\n",
3217 rcu.left,rcu.top,rcu.right,rcu.bottom);
3218 /* now with clipping region */
3219 SelectClipRgn( hdc, clipping);
3220 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3221 if (winetest_debug > 0) dump_region(hrgn);
3222 /* create a region with what is expected */
3223 SetRectRgn( exprgn, 39,10,49,74);
3224 SetRectRgn( tmprgn, 80,79,90,85);
3225 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3226 SetRectRgn( tmprgn, 10,85,90,90);
3227 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3228 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3229 trace("update rect is %d,%d - %d,%d\n",
3230 rcu.left,rcu.top,rcu.right,rcu.bottom);
3231 ReleaseDC( hwnd1, hdc);
3233 /* test scrolling a window with an update region */
3234 DestroyWindow( hwnd2);
3235 ValidateRect( hwnd1, NULL);
3236 SetRect( &rc, 40,40, 50,50);
3237 InvalidateRect( hwnd1, &rc, 1);
3238 GetClientRect( hwnd1, &rc);
3240 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
3241 SW_SCROLLCHILDREN | SW_INVALIDATE);
3242 if (winetest_debug > 0) dump_region(hrgn);
3243 SetRectRgn( exprgn, 88,0,98,98);
3244 SetRectRgn( tmprgn, 30, 40, 50, 50);
3245 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3246 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3248 /* clear an update region */
3249 UpdateWindow( hwnd1 );
3251 SetRect( &rc, 0,40, 100,60);
3252 SetRect( &cliprc, 0,0, 100,100);
3253 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3254 if (winetest_debug > 0) dump_region( hrgn );
3255 SetRectRgn( exprgn, 0, 40, 98, 60 );
3256 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
3258 /* now test ScrollWindowEx with a combination of
3259 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3260 /* make hwnd2 the child of hwnd1 */
3261 hwnd2 = CreateWindowExA(0, "static", NULL,
3262 WS_CHILD| WS_VISIBLE | WS_BORDER ,
3263 50, 50, 100, 100, hwnd1, 0, 0, NULL);
3264 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
3265 GetClientRect( hwnd1, &rc);
3268 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3269 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3270 ValidateRect( hwnd1, NULL);
3271 ValidateRect( hwnd2, NULL);
3272 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
3273 SW_SCROLLCHILDREN | SW_INVALIDATE);
3274 if (winetest_debug > 0) dump_region(hrgn);
3275 SetRectRgn( exprgn, 88,0,98,88);
3276 SetRectRgn( tmprgn, 0,88,98,98);
3277 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3278 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3280 /* SW_SCROLLCHILDREN */
3281 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3282 ValidateRect( hwnd1, NULL);
3283 ValidateRect( hwnd2, NULL);
3284 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3285 if (winetest_debug > 0) dump_region(hrgn);
3286 /* expected region is the same as in previous test */
3287 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3289 /* no SW_SCROLLCHILDREN */
3290 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3291 ValidateRect( hwnd1, NULL);
3292 ValidateRect( hwnd2, NULL);
3293 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3294 if (winetest_debug > 0) dump_region(hrgn);
3295 /* expected region is the same as in previous test */
3296 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3298 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3299 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3300 ValidateRect( hwnd1, NULL);
3301 ValidateRect( hwnd2, NULL);
3302 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3303 if (winetest_debug > 0) dump_region(hrgn);
3304 SetRectRgn( exprgn, 88,0,98,20);
3305 SetRectRgn( tmprgn, 20,20,98,30);
3306 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3307 SetRectRgn( tmprgn, 20,30,30,88);
3308 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3309 SetRectRgn( tmprgn, 0,88,30,98);
3310 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3311 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3314 DeleteObject( hrgn);
3315 DeleteObject( exprgn);
3316 DeleteObject( tmprgn);
3317 DestroyWindow( hwnd1);
3318 DestroyWindow( hwnd2);
3321 /* couple of tests of return values of scrollbar functions
3322 * called on a scrollbarless window */
3323 static void test_scroll(void)
3328 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3329 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3330 100, 100, 200, 200, 0, 0, 0, NULL);
3332 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3333 if (!ret) /* win9x */
3335 win_skip( "GetScrollRange doesn't work\n" );
3336 DestroyWindow( hwnd);
3339 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3340 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3341 si.cbSize = sizeof( si);
3342 si.fMask = SIF_PAGE;
3343 si.nPage = 0xdeadbeef;
3344 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3345 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3346 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3348 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3349 ok( ret, "GetScrollRange returns FALSE\n");
3350 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3351 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3352 si.cbSize = sizeof( si);
3353 si.fMask = SIF_PAGE;
3354 si.nPage = 0xdeadbeef;
3355 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3356 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3357 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3359 DestroyWindow( hwnd);
3362 static void test_scrolldc( HWND parent)
3365 HRGN exprgn, tmprgn, hrgn;
3366 RECT rc, rc2, rcu, cliprc;
3370 hrgn = CreateRectRgn(0,0,0,0);
3371 tmprgn = CreateRectRgn(0,0,0,0);
3372 exprgn = CreateRectRgn(0,0,0,0);
3374 hwnd1 = CreateWindowExA(0, "static", NULL,
3375 WS_CHILD| WS_VISIBLE,
3376 25, 50, 100, 100, parent, 0, 0, NULL);
3377 ShowWindow( parent, SW_SHOW);
3378 UpdateWindow( parent);
3379 flush_events( TRUE );
3380 GetClientRect( hwnd1, &rc);
3381 hdc = GetDC( hwnd1);
3382 /* paint the upper half of the window black */
3384 rc2.bottom = ( rc.top + rc.bottom) /2;
3385 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3386 /* clip region is the lower half */
3388 cliprc.top = (rc.top + rc.bottom) /2;
3389 /* test whether scrolled pixels are properly clipped */
3390 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3391 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3392 /* this scroll should not cause any visible changes */
3393 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3394 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3395 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3396 /* test with NULL clip rect */
3397 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3398 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3399 trace("update rect: %d,%d - %d,%d\n",
3400 rcu.left, rcu.top, rcu.right, rcu.bottom);
3401 if (winetest_debug > 0) dump_region(hrgn);
3402 SetRect(&rc2, 0, 0, 100, 100);
3403 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3404 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3406 SetRectRgn( exprgn, 0, 0, 20, 80);
3407 SetRectRgn( tmprgn, 0, 80, 100, 100);
3408 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3409 if (winetest_debug > 0) dump_region(exprgn);
3410 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3411 /* test clip rect > scroll rect */
3412 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3414 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3415 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3416 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3417 SetRectRgn( exprgn, 25, 25, 75, 35);
3418 SetRectRgn( tmprgn, 25, 35, 35, 75);
3419 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3420 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3421 colr = GetPixel( hdc, 80, 80);
3422 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3423 trace("update rect: %d,%d - %d,%d\n",
3424 rcu.left, rcu.top, rcu.right, rcu.bottom);
3425 if (winetest_debug > 0) dump_region(hrgn);
3429 DeleteObject(exprgn);
3430 DeleteObject(tmprgn);
3431 DestroyWindow(hwnd1);
3434 static void test_params(void)
3439 /* Just a param check */
3440 if (pGetMonitorInfoA)
3442 SetLastError(0xdeadbeef);
3443 rc = GetWindowText(hwndMain2, NULL, 1024);
3444 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
3448 /* Skips actually on Win95 and NT4 */
3449 win_skip("Test would crash on Win95\n");
3452 SetLastError(0xdeadbeef);
3453 hwnd=CreateWindow("LISTBOX", "TestList",
3454 (LBS_STANDARD & ~LBS_SORT),
3456 NULL, (HMENU)1, NULL, 0);
3458 ok(!hwnd || broken(hwnd != NULL), /* w2k3 sp2 */
3459 "CreateWindow with invalid menu handle should fail\n");
3461 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3462 GetLastError() == 0xdeadbeef, /* Win9x */
3463 "wrong last error value %d\n", GetLastError());
3466 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3470 hwnd = CreateWindowEx(exStyle, class, class, style,
3477 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
3480 ShowWindow(hwnd, SW_SHOW);
3482 test_nonclient_area(hwnd);
3485 DestroyWindow(hwnd);
3488 static BOOL AWR_init(void)
3492 class.style = CS_HREDRAW | CS_VREDRAW;
3493 class.lpfnWndProc = DefWindowProcA;
3494 class.cbClsExtra = 0;
3495 class.cbWndExtra = 0;
3496 class.hInstance = 0;
3497 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3498 class.hCursor = LoadCursor (0, IDC_ARROW);
3499 class.hbrBackground = 0;
3500 class.lpszMenuName = 0;
3501 class.lpszClassName = szAWRClass;
3503 if (!RegisterClass (&class)) {
3504 ok(FALSE, "RegisterClass failed\n");
3508 hmenu = CreateMenu();
3511 ok(hmenu != 0, "Failed to create menu\n");
3512 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3518 static void test_AWR_window_size(BOOL menu)
3522 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3525 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3526 WS_HSCROLL, WS_VSCROLL
3530 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3533 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3534 WS_EX_DLGMODALFRAME,
3541 /* A exhaustive check of all the styles takes too long
3542 * so just do a (hopefully representative) sample
3544 for (i = 0; i < COUNTOF(styles); ++i)
3545 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3546 for (i = 0; i < COUNTOF(exStyles); ++i) {
3547 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3548 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3553 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3555 static void test_AdjustWindowRect(void)
3560 SHOWSYSMETRIC(SM_CYCAPTION);
3561 SHOWSYSMETRIC(SM_CYSMCAPTION);
3562 SHOWSYSMETRIC(SM_CYMENU);
3563 SHOWSYSMETRIC(SM_CXEDGE);
3564 SHOWSYSMETRIC(SM_CYEDGE);
3565 SHOWSYSMETRIC(SM_CXVSCROLL);
3566 SHOWSYSMETRIC(SM_CYHSCROLL);
3567 SHOWSYSMETRIC(SM_CXFRAME);
3568 SHOWSYSMETRIC(SM_CYFRAME);
3569 SHOWSYSMETRIC(SM_CXDLGFRAME);
3570 SHOWSYSMETRIC(SM_CYDLGFRAME);
3571 SHOWSYSMETRIC(SM_CXBORDER);
3572 SHOWSYSMETRIC(SM_CYBORDER);
3574 test_AWR_window_size(FALSE);
3575 test_AWR_window_size(TRUE);
3579 #undef SHOWSYSMETRIC
3582 /* Global variables to trigger exit from loop */
3583 static int redrawComplete, WMPAINT_count;
3585 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3590 trace("doing WM_PAINT %d\n", WMPAINT_count);
3592 if (WMPAINT_count > 10 && redrawComplete == 0) {
3594 BeginPaint(hwnd, &ps);
3595 EndPaint(hwnd, &ps);
3600 return DefWindowProc(hwnd, msg, wparam, lparam);
3603 /* Ensure we exit from RedrawNow regardless of invalidated area */
3604 static void test_redrawnow(void)
3609 cls.style = CS_DBLCLKS;
3610 cls.lpfnWndProc = redraw_window_procA;
3613 cls.hInstance = GetModuleHandleA(0);
3615 cls.hCursor = LoadCursorA(0, IDC_ARROW);
3616 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3617 cls.lpszMenuName = NULL;
3618 cls.lpszClassName = "RedrawWindowClass";
3620 if(!RegisterClassA(&cls)) {
3621 trace("Register failed %d\n", GetLastError());
3625 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3626 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3628 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3629 ShowWindow(hwndMain, SW_SHOW);
3630 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3631 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3632 ok( WMPAINT_count == 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3633 redrawComplete = TRUE;
3634 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3637 DestroyWindow( hwndMain);
3640 struct parentdc_stat {
3646 struct parentdc_test {
3647 struct parentdc_stat main, main_todo;
3648 struct parentdc_stat child1, child1_todo;
3649 struct parentdc_stat child2, child2_todo;
3652 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3657 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3662 GetClientRect(hwnd, &rc);
3663 CopyRect(&t->client, &rc);
3664 GetWindowRect(hwnd, &rc);
3665 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd,
3666 t->client.left, t->client.top, t->client.right, t->client.bottom,
3667 rc.left, rc.top, rc.right, rc.bottom);
3668 BeginPaint(hwnd, &ps);
3669 CopyRect(&t->paint, &ps.rcPaint);
3670 GetClipBox(ps.hdc, &rc);
3671 CopyRect(&t->clip, &rc);
3672 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
3673 rc.left, rc.top, rc.right, rc.bottom,
3674 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3675 EndPaint(hwnd, &ps);
3678 return DefWindowProc(hwnd, msg, wparam, lparam);
3681 static void zero_parentdc_stat(struct parentdc_stat *t)
3683 SetRectEmpty(&t->client);
3684 SetRectEmpty(&t->clip);
3685 SetRectEmpty(&t->paint);
3688 static void zero_parentdc_test(struct parentdc_test *t)
3690 zero_parentdc_stat(&t->main);
3691 zero_parentdc_stat(&t->child1);
3692 zero_parentdc_stat(&t->child2);
3695 #define parentdc_field_ok(t, w, r, f, got) \
3696 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3697 ": expected %d, got %d\n", \
3700 #define parentdc_todo_field_ok(t, w, r, f, got) \
3701 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3702 else parentdc_field_ok(t, w, r, f, got)
3704 #define parentdc_rect_ok(t, w, r, got) \
3705 parentdc_todo_field_ok(t, w, r, left, got); \
3706 parentdc_todo_field_ok(t, w, r, top, got); \
3707 parentdc_todo_field_ok(t, w, r, right, got); \
3708 parentdc_todo_field_ok(t, w, r, bottom, got);
3710 #define parentdc_win_ok(t, w, got) \
3711 parentdc_rect_ok(t, w, client, got); \
3712 parentdc_rect_ok(t, w, clip, got); \
3713 parentdc_rect_ok(t, w, paint, got);
3715 #define parentdc_ok(t, got) \
3716 parentdc_win_ok(t, main, got); \
3717 parentdc_win_ok(t, child1, got); \
3718 parentdc_win_ok(t, child2, got);
3720 static void test_csparentdc(void)
3722 WNDCLASSA clsMain, cls;
3723 HWND hwndMain, hwnd1, hwnd2;
3726 struct parentdc_test test_answer;
3728 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3729 const struct parentdc_test test1 =
3731 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
3732 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3733 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3736 const struct parentdc_test test2 =
3738 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
3739 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3740 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3743 const struct parentdc_test test3 =
3745 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3746 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3747 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3750 const struct parentdc_test test4 =
3752 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
3753 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
3754 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3757 const struct parentdc_test test5 =
3759 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
3760 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3761 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3764 const struct parentdc_test test6 =
3766 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3767 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3768 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3771 const struct parentdc_test test7 =
3773 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3774 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3775 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3779 clsMain.style = CS_DBLCLKS;
3780 clsMain.lpfnWndProc = parentdc_window_procA;
3781 clsMain.cbClsExtra = 0;
3782 clsMain.cbWndExtra = 0;
3783 clsMain.hInstance = GetModuleHandleA(0);
3785 clsMain.hCursor = LoadCursorA(0, IDC_ARROW);
3786 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
3787 clsMain.lpszMenuName = NULL;
3788 clsMain.lpszClassName = "ParentDcMainWindowClass";
3790 if(!RegisterClassA(&clsMain)) {
3791 trace("Register failed %d\n", GetLastError());
3795 cls.style = CS_DBLCLKS | CS_PARENTDC;
3796 cls.lpfnWndProc = parentdc_window_procA;
3799 cls.hInstance = GetModuleHandleA(0);
3801 cls.hCursor = LoadCursorA(0, IDC_ARROW);
3802 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3803 cls.lpszMenuName = NULL;
3804 cls.lpszClassName = "ParentDcWindowClass";
3806 if(!RegisterClassA(&cls)) {
3807 trace("Register failed %d\n", GetLastError());
3811 SetRect(&rc, 0, 0, 150, 150);
3812 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
3813 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3814 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
3815 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
3816 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
3817 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
3818 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
3819 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
3820 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
3821 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
3822 ShowWindow(hwndMain, SW_SHOW);
3823 ShowWindow(hwnd1, SW_SHOW);
3824 ShowWindow(hwnd2, SW_SHOW);
3825 SetWindowPos(hwndMain, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
3826 flush_events( TRUE );
3828 zero_parentdc_test(&test_answer);
3829 InvalidateRect(hwndMain, NULL, TRUE);
3830 flush_events( TRUE );
3831 parentdc_ok(test1, test_answer);
3833 zero_parentdc_test(&test_answer);
3834 SetRect(&rc, 0, 0, 50, 50);
3835 InvalidateRect(hwndMain, &rc, TRUE);
3836 flush_events( TRUE );
3837 parentdc_ok(test2, test_answer);
3839 zero_parentdc_test(&test_answer);
3840 SetRect(&rc, 0, 0, 10, 10);
3841 InvalidateRect(hwndMain, &rc, TRUE);
3842 flush_events( TRUE );
3843 parentdc_ok(test3, test_answer);
3845 zero_parentdc_test(&test_answer);
3846 SetRect(&rc, 40, 40, 50, 50);
3847 InvalidateRect(hwndMain, &rc, TRUE);
3848 flush_events( TRUE );
3849 parentdc_ok(test4, test_answer);
3851 zero_parentdc_test(&test_answer);
3852 SetRect(&rc, 20, 20, 60, 60);
3853 InvalidateRect(hwndMain, &rc, TRUE);
3854 flush_events( TRUE );
3855 parentdc_ok(test5, test_answer);
3857 zero_parentdc_test(&test_answer);
3858 SetRect(&rc, 0, 0, 10, 10);
3859 InvalidateRect(hwnd1, &rc, TRUE);
3860 flush_events( TRUE );
3861 parentdc_ok(test6, test_answer);
3863 zero_parentdc_test(&test_answer);
3864 SetRect(&rc, -5, -5, 65, 65);
3865 InvalidateRect(hwnd1, &rc, TRUE);
3866 flush_events( TRUE );
3867 parentdc_ok(test7, test_answer);
3869 DestroyWindow(hwndMain);
3870 DestroyWindow(hwnd1);
3871 DestroyWindow(hwnd2);
3874 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3876 return DefWindowProcA(hwnd, msg, wparam, lparam);
3879 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3881 return DefWindowProcW(hwnd, msg, wparam, lparam);
3884 static void test_IsWindowUnicode(void)
3886 static const char ansi_class_nameA[] = "ansi class name";
3887 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3888 static const char unicode_class_nameA[] = "unicode class name";
3889 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3894 memset(&classW, 0, sizeof(classW));
3895 classW.hInstance = GetModuleHandleA(0);
3896 classW.lpfnWndProc = def_window_procW;
3897 classW.lpszClassName = unicode_class_nameW;
3898 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
3900 memset(&classA, 0, sizeof(classA));
3901 classA.hInstance = GetModuleHandleA(0);
3902 classA.lpfnWndProc = def_window_procA;
3903 classA.lpszClassName = ansi_class_nameA;
3904 assert(RegisterClassA(&classA));
3906 /* unicode class: window proc */
3907 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3908 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3911 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3912 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3913 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3914 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3915 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3917 DestroyWindow(hwnd);
3919 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3920 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3923 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3924 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3925 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3926 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3927 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3929 DestroyWindow(hwnd);
3931 /* ansi class: window proc */
3932 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3933 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3936 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3937 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3938 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3939 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3940 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3942 DestroyWindow(hwnd);
3944 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3945 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3948 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3949 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3950 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3951 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3952 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3954 DestroyWindow(hwnd);
3956 /* unicode class: class proc */
3957 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3958 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3961 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3962 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3963 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3964 /* do not restore class window proc back to unicode */
3966 DestroyWindow(hwnd);
3968 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3969 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3972 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3973 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
3974 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3976 DestroyWindow(hwnd);
3978 /* ansi class: class proc */
3979 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3980 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3983 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3984 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
3985 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3986 /* do not restore class window proc back to ansi */
3988 DestroyWindow(hwnd);
3990 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3991 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3994 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3995 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3996 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3998 DestroyWindow(hwnd);
4001 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4005 if (msg != WM_GETMINMAXINFO)
4006 return DefWindowProc(hwnd, msg, wp, lp);
4008 minmax = (MINMAXINFO *)lp;
4010 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
4012 minmax->ptReserved.x = 0;
4013 minmax->ptReserved.y = 0;
4014 minmax->ptMaxSize.x = 400;
4015 minmax->ptMaxSize.y = 400;
4016 minmax->ptMaxPosition.x = 300;
4017 minmax->ptMaxPosition.y = 300;
4018 minmax->ptMaxTrackSize.x = 200;
4019 minmax->ptMaxTrackSize.y = 200;
4020 minmax->ptMinTrackSize.x = 100;
4021 minmax->ptMinTrackSize.y = 100;
4024 DefWindowProc(hwnd, msg, wp, lp);
4028 static int expected_cx, expected_cy;
4029 static RECT expected_rect, broken_rect;
4031 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4035 case WM_GETMINMAXINFO:
4038 GetWindowRect( hwnd, &rect );
4039 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
4040 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4041 return DefWindowProc(hwnd, msg, wp, lp);
4046 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
4048 GetWindowRect( hwnd, &rect );
4049 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
4050 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
4051 ok( cs->cx == expected_cx || broken(cs->cx == (short)expected_cx),
4052 "wrong x size %d/%d\n", cs->cx, expected_cx );
4053 ok( cs->cy == expected_cy || broken(cs->cy == (short)expected_cy),
4054 "wrong y size %d/%d\n", cs->cy, expected_cy );
4055 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
4056 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
4057 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
4058 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top) ||
4059 broken( rect.right - rect.left == (short)broken_rect.right - (short)broken_rect.left &&
4060 rect.bottom - rect.top == (short)broken_rect.bottom - (short)broken_rect.top),
4061 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
4062 rect.left, rect.top, rect.right, rect.bottom,
4063 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
4064 return DefWindowProc(hwnd, msg, wp, lp);
4068 RECT rect, *r = (RECT *)lp;
4069 GetWindowRect( hwnd, &rect );
4070 ok( !memcmp( &rect, r, sizeof(rect) ),
4071 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
4072 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
4073 return DefWindowProc(hwnd, msg, wp, lp);
4076 return DefWindowProc(hwnd, msg, wp, lp);
4080 static void test_CreateWindow(void)
4088 #define expect_menu(window, menu) \
4089 SetLastError(0xdeadbeef); \
4090 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
4092 #define expect_style(window, style)\
4093 ok((ULONG)GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
4095 #define expect_ex_style(window, ex_style)\
4096 ok((ULONG)GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
4098 #define expect_gle_broken_9x(gle)\
4099 ok(GetLastError() == gle ||\
4100 broken(GetLastError() == 0xdeadbeef),\
4101 "IsMenu set error %d\n", GetLastError())
4103 hmenu = CreateMenu();
4105 parent = GetDesktopWindow();
4106 assert(parent != 0);
4108 SetLastError(0xdeadbeef);
4109 ok(IsMenu(hmenu), "IsMenu error %d\n", GetLastError());
4112 SetLastError(0xdeadbeef);
4113 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
4114 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4115 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4116 expect_menu(hwnd, 1);
4117 expect_style(hwnd, WS_CHILD);
4118 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4119 DestroyWindow(hwnd);
4121 SetLastError(0xdeadbeef);
4122 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
4123 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4124 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4125 expect_menu(hwnd, 1);
4126 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4127 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4128 DestroyWindow(hwnd);
4130 SetLastError(0xdeadbeef);
4131 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
4132 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4133 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4134 expect_menu(hwnd, 1);
4135 expect_style(hwnd, WS_CHILD);
4136 expect_ex_style(hwnd, 0);
4137 DestroyWindow(hwnd);
4139 SetLastError(0xdeadbeef);
4140 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
4141 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4142 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4143 expect_menu(hwnd, 1);
4144 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4145 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4146 DestroyWindow(hwnd);
4149 SetLastError(0xdeadbeef);
4150 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4151 0, 0, 100, 100, parent, hmenu, 0, NULL);
4152 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4153 expect_menu(hwnd, hmenu);
4154 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4155 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4156 DestroyWindow(hwnd);
4157 SetLastError(0xdeadbeef);
4158 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4159 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4161 hmenu = CreateMenu();
4163 SetLastError(0xdeadbeef);
4164 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
4165 0, 0, 100, 100, parent, hmenu, 0, NULL);
4166 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4167 expect_menu(hwnd, hmenu);
4168 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4169 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4170 DestroyWindow(hwnd);
4171 SetLastError(0xdeadbeef);
4172 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4173 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4175 hmenu = CreateMenu();
4177 SetLastError(0xdeadbeef);
4178 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
4179 0, 0, 100, 100, parent, hmenu, 0, NULL);
4180 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4181 expect_menu(hwnd, hmenu);
4182 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4183 expect_ex_style(hwnd, 0);
4184 DestroyWindow(hwnd);
4185 SetLastError(0xdeadbeef);
4186 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4187 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4189 hmenu = CreateMenu();
4191 SetLastError(0xdeadbeef);
4192 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
4193 0, 0, 100, 100, parent, hmenu, 0, NULL);
4194 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4195 expect_menu(hwnd, hmenu);
4196 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4197 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4198 DestroyWindow(hwnd);
4199 SetLastError(0xdeadbeef);
4200 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4201 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4203 /* WS_CHILD | WS_POPUP */
4204 SetLastError(0xdeadbeef);
4205 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4206 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4207 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4208 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4210 DestroyWindow(hwnd);
4212 hmenu = CreateMenu();
4214 SetLastError(0xdeadbeef);
4215 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4216 0, 0, 100, 100, parent, hmenu, 0, NULL);
4217 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4218 expect_menu(hwnd, hmenu);
4219 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4220 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4221 DestroyWindow(hwnd);
4222 SetLastError(0xdeadbeef);
4223 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4224 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4226 SetLastError(0xdeadbeef);
4227 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4228 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4229 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4230 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4232 DestroyWindow(hwnd);
4234 hmenu = CreateMenu();
4236 SetLastError(0xdeadbeef);
4237 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4238 0, 0, 100, 100, parent, hmenu, 0, NULL);
4239 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4240 expect_menu(hwnd, hmenu);
4241 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4242 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4243 DestroyWindow(hwnd);
4244 SetLastError(0xdeadbeef);
4245 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4246 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4248 SetLastError(0xdeadbeef);
4249 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4250 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4251 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4252 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4254 DestroyWindow(hwnd);
4256 hmenu = CreateMenu();
4258 SetLastError(0xdeadbeef);
4259 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4260 0, 0, 100, 100, parent, hmenu, 0, NULL);
4261 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4262 expect_menu(hwnd, hmenu);
4263 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4264 expect_ex_style(hwnd, 0);
4265 DestroyWindow(hwnd);
4266 SetLastError(0xdeadbeef);
4267 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4268 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4270 SetLastError(0xdeadbeef);
4271 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4272 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4273 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4274 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4276 DestroyWindow(hwnd);
4278 hmenu = CreateMenu();
4280 SetLastError(0xdeadbeef);
4281 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4282 0, 0, 100, 100, parent, hmenu, 0, NULL);
4283 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4284 expect_menu(hwnd, hmenu);
4285 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4286 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4287 DestroyWindow(hwnd);
4288 SetLastError(0xdeadbeef);
4289 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4290 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4292 /* test child window sizing */
4294 cls.lpfnWndProc = minmax_wnd_proc;
4297 cls.hInstance = GetModuleHandle(0);
4299 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4300 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4301 cls.lpszMenuName = NULL;
4302 cls.lpszClassName = "MinMax_WndClass";
4303 RegisterClass(&cls);
4305 SetLastError(0xdeadbeef);
4306 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4307 0, 0, 100, 100, 0, 0, 0, NULL);
4308 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4309 expect_menu(parent, 0);
4310 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
4311 expect_ex_style(parent, WS_EX_WINDOWEDGE);
4313 memset(&minmax, 0, sizeof(minmax));
4314 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4315 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
4316 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
4317 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4318 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
4320 GetWindowRect(parent, &rc);
4321 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
4322 GetClientRect(parent, &rc);
4323 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
4325 InflateRect(&rc, 200, 200);
4326 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4328 SetLastError(0xdeadbeef);
4329 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4330 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
4331 parent, (HMENU)1, 0, NULL);
4332 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4333 expect_menu(hwnd, 1);
4334 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
4335 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4337 memset(&minmax, 0, sizeof(minmax));
4338 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4339 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4341 GetWindowRect(hwnd, &rc);
4342 OffsetRect(&rc, -rc.left, -rc.top);
4343 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4344 rc.left, rc.top, rc.right, rc.bottom,
4345 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
4346 DestroyWindow(hwnd);
4348 cls.lpfnWndProc = winsizes_wnd_proc;
4349 cls.lpszClassName = "Sizes_WndClass";
4350 RegisterClass(&cls);
4352 expected_cx = expected_cy = 200000;
4353 SetRect( &expected_rect, 0, 0, 200000, 200000 );
4354 broken_rect = expected_rect;
4355 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
4356 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4357 GetClientRect( hwnd, &rc );
4358 ok( rc.right == 200000 || broken(rc.right == (short)200000), "invalid rect right %u\n", rc.right );
4359 ok( rc.bottom == 200000 || broken(rc.bottom == (short)200000), "invalid rect bottom %u\n", rc.bottom );
4360 DestroyWindow(hwnd);
4362 expected_cx = expected_cy = -10;
4363 SetRect( &expected_rect, 0, 0, 0, 0 );
4364 SetRect( &broken_rect, 0, 0, -10, -10 );
4365 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
4366 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4367 GetClientRect( hwnd, &rc );
4368 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4369 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4370 DestroyWindow(hwnd);
4372 expected_cx = expected_cy = -200000;
4373 SetRect( &expected_rect, 0, 0, 0, 0 );
4374 SetRect( &broken_rect, 0, 0, -200000, -200000 );
4375 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
4376 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4377 GetClientRect( hwnd, &rc );
4378 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4379 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4380 DestroyWindow(hwnd);
4382 /* we need a parent at 0,0 so that child coordinates match */
4383 DestroyWindow(parent);
4384 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
4385 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4388 expected_cy = 0x7fffffff;
4389 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
4390 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
4391 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
4392 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4393 GetClientRect( hwnd, &rc );
4394 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
4395 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4396 DestroyWindow(hwnd);
4398 expected_cx = 0x7fffffff;
4399 expected_cy = 0x7fffffff;
4400 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
4401 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
4402 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
4403 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4404 GetClientRect( hwnd, &rc );
4405 ok( rc.right == 0x7fffffff - 20 || broken(rc.right == 0), "invalid rect right %u\n", rc.right );
4406 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4407 DestroyWindow(hwnd);
4409 /* top level window */
4410 expected_cx = expected_cy = 200000;
4411 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
4412 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
4413 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4414 GetClientRect( hwnd, &rc );
4415 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
4416 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
4417 DestroyWindow(hwnd);
4419 DestroyWindow(parent);
4421 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4422 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4424 #undef expect_gle_broken_9x
4427 #undef expect_ex_style
4430 /* function that remembers whether the system the test is running on sets the
4431 * last error for user32 functions to make the tests stricter */
4432 static int check_error(DWORD actual, DWORD expected)
4434 static int sets_last_error = -1;
4435 if (sets_last_error == -1)
4436 sets_last_error = (actual != 0xdeadbeef);
4437 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
4440 static void test_SetWindowLong(void)
4443 WNDPROC old_window_procW;
4445 SetLastError(0xdeadbeef);
4446 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
4447 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
4448 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
4449 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4451 SetLastError(0xdeadbeef);
4452 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
4453 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
4454 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
4455 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4457 SetLastError(0xdeadbeef);
4458 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4459 ok((WNDPROC)retval == main_window_procA || broken(!retval), /* win9x */
4460 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
4461 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4462 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
4463 ok((WNDPROC)retval == main_window_procA,
4464 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4465 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
4467 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
4468 SetLastError(0xdeadbeef);
4469 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
4470 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
4472 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4473 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
4474 ok((WNDPROC)retval == old_window_procW,
4475 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4476 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
4478 /* set it back to ANSI */
4479 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4483 static void test_ShowWindow(void)
4490 SetRect(&rcMain, 120, 120, 210, 210);
4492 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
4493 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4494 WS_MAXIMIZEBOX | WS_POPUP,
4495 rcMain.left, rcMain.top,
4496 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
4500 style = GetWindowLong(hwnd, GWL_STYLE);
4501 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4502 ok(!(style & WS_VISIBLE), "window should not be visible\n");
4503 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4504 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4505 GetWindowRect(hwnd, &rc);
4506 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4507 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4508 rc.left, rc.top, rc.right, rc.bottom);
4510 ret = ShowWindow(hwnd, SW_SHOW);
4511 ok(!ret, "not expected ret: %lu\n", ret);
4512 style = GetWindowLong(hwnd, GWL_STYLE);
4513 ok(!(style & WS_DISABLED), "window should not 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 = ShowWindow(hwnd, SW_MINIMIZE);
4523 ok(ret, "not expected ret: %lu\n", ret);
4524 style = GetWindowLong(hwnd, GWL_STYLE);
4525 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4526 ok(style & WS_VISIBLE, "window should be visible\n");
4527 ok(style & WS_MINIMIZE, "window should be minimized\n");
4528 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4529 GetWindowRect(hwnd, &rc);
4530 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4532 ShowWindow(hwnd, SW_RESTORE);
4533 ok(ret, "not expected ret: %lu\n", ret);
4534 style = GetWindowLong(hwnd, GWL_STYLE);
4535 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4536 ok(style & WS_VISIBLE, "window should be visible\n");
4537 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4538 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4539 GetWindowRect(hwnd, &rc);
4540 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4541 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4542 rc.left, rc.top, rc.right, rc.bottom);
4544 ret = EnableWindow(hwnd, FALSE);
4545 ok(!ret, "not expected ret: %lu\n", ret);
4546 style = GetWindowLong(hwnd, GWL_STYLE);
4547 ok(style & WS_DISABLED, "window should be disabled\n");
4549 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
4550 ok(!ret, "not expected ret: %lu\n", ret);
4551 style = GetWindowLong(hwnd, GWL_STYLE);
4552 ok(style & WS_DISABLED, "window should be disabled\n");
4553 ok(style & WS_VISIBLE, "window should be visible\n");
4554 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4555 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4556 GetWindowRect(hwnd, &rc);
4557 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4558 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4559 rc.left, rc.top, rc.right, rc.bottom);
4561 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
4562 ok(!ret, "not expected ret: %lu\n", ret);
4563 style = GetWindowLong(hwnd, GWL_STYLE);
4564 ok(style & WS_DISABLED, "window should be disabled\n");
4565 ok(style & WS_VISIBLE, "window should be visible\n");
4566 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4567 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4568 GetWindowRect(hwnd, &rc);
4569 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4570 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4571 rc.left, rc.top, rc.right, rc.bottom);
4573 ret = ShowWindow(hwnd, SW_MINIMIZE);
4574 ok(ret, "not expected ret: %lu\n", ret);
4575 style = GetWindowLong(hwnd, GWL_STYLE);
4576 ok(style & WS_DISABLED, "window should be disabled\n");
4577 ok(style & WS_VISIBLE, "window should be visible\n");
4578 ok(style & WS_MINIMIZE, "window should be minimized\n");
4579 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4580 GetWindowRect(hwnd, &rc);
4581 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4583 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
4584 ok(!ret, "not expected ret: %lu\n", ret);
4585 style = GetWindowLong(hwnd, GWL_STYLE);
4586 ok(style & WS_DISABLED, "window should be disabled\n");
4587 ok(style & WS_VISIBLE, "window should be visible\n");
4588 ok(style & WS_MINIMIZE, "window should be minimized\n");
4589 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4590 GetWindowRect(hwnd, &rc);
4591 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4593 ret = ShowWindow(hwnd, SW_RESTORE);
4594 ok(ret, "not expected ret: %lu\n", ret);
4595 style = GetWindowLong(hwnd, GWL_STYLE);
4596 ok(style & WS_DISABLED, "window should be disabled\n");
4597 ok(style & WS_VISIBLE, "window should be visible\n");
4598 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4599 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4600 GetWindowRect(hwnd, &rc);
4601 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4602 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4603 rc.left, rc.top, rc.right, rc.bottom);
4605 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4606 ok(!ret, "not expected ret: %lu\n", ret);
4607 ok(IsWindow(hwnd), "window should exist\n");
4609 ret = EnableWindow(hwnd, TRUE);
4610 ok(ret, "not expected ret: %lu\n", ret);
4612 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4613 ok(!ret, "not expected ret: %lu\n", ret);
4614 ok(!IsWindow(hwnd), "window should not exist\n");
4617 static void test_gettext(void)
4620 LPCSTR clsname = "gettexttest";
4624 memset( &cls, 0, sizeof cls );
4625 cls.lpfnWndProc = DefWindowProc;
4626 cls.lpszClassName = clsname;
4627 cls.hInstance = GetModuleHandle(NULL);
4629 if (!RegisterClass( &cls )) return;
4631 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
4632 ok( hwnd != NULL, "window was null\n");
4634 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
4635 ok( r == 0, "settext should return zero\n");
4637 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
4638 ok( r == 0, "settext should return zero (%ld)\n", r);
4640 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
4641 ok( r == 0, "settext should return zero (%ld)\n", r);
4643 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
4644 ok( r == 0, "settext should return zero (%ld)\n", r);
4646 DestroyWindow(hwnd);
4647 UnregisterClass( clsname, NULL );
4651 static void test_GetUpdateRect(void)
4654 BOOL ret, parent_wm_paint, grandparent_wm_paint;
4656 HWND hgrandparent, hparent, hchild;
4658 static const char classNameA[] = "GetUpdateRectClass";
4660 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
4661 0, 0, 100, 100, NULL, NULL, 0, NULL);
4663 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
4664 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4666 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
4667 10, 10, 30, 30, hparent, NULL, 0, NULL);
4669 ShowWindow(hgrandparent, SW_SHOW);
4670 UpdateWindow(hgrandparent);
4671 flush_events( TRUE );
4673 ShowWindow(hchild, SW_HIDE);
4674 SetRect(&rc2, 0, 0, 0, 0);
4675 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4676 ok(!ret, "GetUpdateRect returned not empty region\n");
4677 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4678 rc1.left, rc1.top, rc1.right, rc1.bottom,
4679 rc2.left, rc2.top, rc2.right, rc2.bottom);
4681 SetRect(&rc2, 10, 10, 40, 40);
4682 ret = GetUpdateRect(hparent, &rc1, FALSE);
4683 ok(ret, "GetUpdateRect returned empty region\n");
4684 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4685 rc1.left, rc1.top, rc1.right, rc1.bottom,
4686 rc2.left, rc2.top, rc2.right, rc2.bottom);
4688 parent_wm_paint = FALSE;
4689 grandparent_wm_paint = FALSE;
4690 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4692 if (msg.message == WM_PAINT)
4694 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4695 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4697 DispatchMessage(&msg);
4699 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4700 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4702 DestroyWindow(hgrandparent);
4705 cls.lpfnWndProc = DefWindowProcA;
4708 cls.hInstance = GetModuleHandleA(0);
4710 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4711 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4712 cls.lpszMenuName = NULL;
4713 cls.lpszClassName = classNameA;
4715 if(!RegisterClassA(&cls)) {
4716 trace("Register failed %d\n", GetLastError());
4720 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
4721 0, 0, 100, 100, NULL, NULL, 0, NULL);
4723 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
4724 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4726 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
4727 10, 10, 30, 30, hparent, NULL, 0, NULL);
4729 ShowWindow(hgrandparent, SW_SHOW);
4730 UpdateWindow(hgrandparent);
4731 flush_events( TRUE );
4733 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4734 ok(!ret, "GetUpdateRect returned not empty region\n");
4736 ShowWindow(hchild, SW_HIDE);
4738 SetRect(&rc2, 0, 0, 0, 0);
4739 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4740 ok(!ret, "GetUpdateRect returned not empty region\n");
4741 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4742 rc1.left, rc1.top, rc1.right, rc1.bottom,
4743 rc2.left, rc2.top, rc2.right, rc2.bottom);
4745 SetRect(&rc2, 10, 10, 40, 40);
4746 ret = GetUpdateRect(hparent, &rc1, FALSE);
4747 ok(ret, "GetUpdateRect returned empty region\n");
4748 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4749 rc1.left, rc1.top, rc1.right, rc1.bottom,
4750 rc2.left, rc2.top, rc2.right, rc2.bottom);
4752 parent_wm_paint = FALSE;
4753 grandparent_wm_paint = FALSE;
4754 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4756 if (msg.message == WM_PAINT)
4758 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4759 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4761 DispatchMessage(&msg);
4763 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4764 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4766 DestroyWindow(hgrandparent);
4770 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
4778 const int waitTime = 2000;
4780 BeginPaint(hwnd, &ps);
4782 /* create and destroy window to create an exposed region on this window */
4783 win = CreateWindowA("static", "win", WS_VISIBLE,
4784 10,10,50,50, NULL, NULL, 0, NULL);
4787 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
4789 ValidateRect(hwnd, NULL);
4790 EndPaint(hwnd, &ps);
4792 if(waitResult != WAIT_TIMEOUT)
4794 GetUpdateRect(hwnd, &updateRect, FALSE);
4795 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
4800 return DefWindowProc(hwnd, msg, wParam, lParam);
4803 static void test_Expose(void)
4808 memset(&cls, 0, sizeof(WNDCLASSA));
4809 cls.lpfnWndProc = TestExposedRegion_WndProc;
4810 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4811 cls.lpszClassName = "TestExposeClass";
4812 atom = RegisterClassA(&cls);
4814 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
4815 0, 0, 200, 100, NULL, NULL, 0, NULL);
4821 static void test_GetWindowModuleFileName(void)
4826 char buf1[MAX_PATH], buf2[MAX_PATH];
4828 if (!pGetWindowModuleFileNameA)
4830 skip("GetWindowModuleFileNameA is not available\n");
4834 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
4837 hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
4838 ok(hinst == 0 || broken(hinst == GetModuleHandle(0)), /* win9x */ "expected 0, got %p\n", hinst);
4841 SetLastError(0xdeadbeef);
4842 ret1 = GetModuleFileName(hinst, buf1, sizeof(buf1));
4843 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
4846 SetLastError(0xdeadbeef);
4847 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
4848 ok(ret2 || broken(!ret2), /* nt4 sp 3 */
4849 "GetWindowModuleFileNameA error %u\n", GetLastError());
4853 ok(ret1 == ret2 || broken(ret2 == ret1 + 1), /* win98 */ "%u != %u\n", ret1, ret2);
4854 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
4856 hinst = GetModuleHandle(0);
4858 SetLastError(0xdeadbeef);
4859 ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
4860 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
4861 "expected %u, got %u\n", ret1 - 2, ret2);
4862 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4863 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4864 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4866 SetLastError(0xdeadbeef);
4867 ret2 = GetModuleFileName(hinst, buf2, 0);
4868 ok(!ret2, "GetModuleFileName should return 0\n");
4869 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4870 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4871 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4873 SetLastError(0xdeadbeef);
4874 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
4875 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3) /* win98 */ || broken(!ret2), /* nt4 sp3 */
4876 "expected %u, got %u\n", ret1 - 2, ret2);
4877 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4878 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4879 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4881 SetLastError(0xdeadbeef);
4882 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
4883 ok(!ret2, "expected 0, got %u\n", ret2);
4884 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4885 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4886 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4888 DestroyWindow(hwnd);
4891 hwnd = (HWND)0xdeadbeef;
4892 SetLastError(0xdeadbeef);
4893 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4894 ok(!ret1, "expected 0, got %u\n", ret1);
4895 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef), /* win9x */
4896 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
4898 hwnd = FindWindow("Shell_TrayWnd", NULL);
4899 ok(IsWindow(hwnd), "got invalid tray window %p\n", hwnd);
4900 SetLastError(0xdeadbeef);
4901 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4902 ok(!ret1 || broken(ret1), /* win98 */ "expected 0, got %u\n", ret1);
4904 if (!ret1) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
4906 ret1 = GetModuleFileName(0, buf1, sizeof(buf1));
4907 hwnd = GetDesktopWindow();
4908 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
4909 SetLastError(0xdeadbeef);
4910 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
4911 ok(!ret2 || ret1 == ret2 /* vista */, "expected 0 or %u, got %u %s\n", ret1, ret2, buf2);
4915 static void test_hwnd_message(void)
4917 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
4918 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
4920 HWND parent = 0, hwnd, found;
4923 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
4924 on CreateWindowExA and crash later in the test.
4925 Use UNICODE here to fail on win9x */
4926 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
4927 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
4930 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
4934 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
4938 HWND root, desktop = GetDesktopWindow();
4940 parent = pGetAncestor(hwnd, GA_PARENT);
4941 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
4942 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
4943 root = pGetAncestor(hwnd, GA_ROOT);
4944 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
4945 ok( !pGetAncestor(parent, GA_PARENT) || broken(pGetAncestor(parent, GA_PARENT) != 0), /* win2k */
4946 "parent shouldn't have parent %p\n", pGetAncestor(parent, GA_PARENT) );
4947 trace("parent %p root %p desktop %p\n", parent, root, desktop);
4948 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
4949 ok( !lstrcmpi( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
4950 GetWindowRect( parent, &rect );
4951 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
4952 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4954 GetWindowRect( hwnd, &rect );
4955 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
4956 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4958 /* test FindWindow behavior */
4960 found = FindWindowExA( 0, 0, 0, "message window" );
4961 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
4962 SetLastError(0xdeadbeef);
4963 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
4964 ok( found == 0, "found message window %p/%p\n", found, hwnd );
4965 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
4968 found = FindWindowExA( parent, 0, 0, "message window" );
4969 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
4972 /* test IsChild behavior */
4974 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
4976 /* test IsWindowVisible behavior */
4978 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
4979 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
4981 DestroyWindow(hwnd);
4984 static void test_layered_window(void)
4992 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes)
4994 win_skip( "layered windows not supported\n" );
4997 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
4998 100, 100, 200, 200, 0, 0, 0, NULL);
5000 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5001 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
5002 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
5003 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
5004 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5005 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5006 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5007 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
5008 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5009 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5010 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5011 ok( key == 0x123456 || key == 0, "wrong color key %x\n", key );
5012 ok( alpha == 44, "wrong alpha %u\n", alpha );
5013 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
5015 /* clearing WS_EX_LAYERED resets attributes */
5016 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5017 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5018 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
5019 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5020 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5021 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5022 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
5023 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5024 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5025 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5026 ok( key == 0x654321, "wrong color key %x\n", key );
5027 ok( alpha == 22, "wrong alpha %u\n", alpha );
5028 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
5030 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
5031 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5033 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5034 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5035 ok( key == 0x888888, "wrong color key %x\n", key );
5036 /* alpha not changed on vista if LWA_ALPHA is not set */
5037 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
5038 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
5040 /* color key may or may not be changed without LWA_COLORKEY */
5041 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
5042 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5044 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5045 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5046 ok( key == 0x888888 || key == 0x999999, "wrong color key %x\n", key );
5047 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
5048 ok( flags == 0, "wrong flags %x\n", flags );
5050 /* default alpha and color key is 0 */
5051 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5052 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5053 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
5054 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5055 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5056 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5057 ok( key == 0 || key == 0x222222, "wrong color key %x\n", key );
5058 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
5059 ok( flags == 0, "wrong flags %x\n", flags );
5061 DestroyWindow( hwnd );
5064 static MONITORINFO mi;
5066 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
5072 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
5073 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs->x, cs->y, cs->cx, cs->cy);
5074 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
5075 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
5076 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
5077 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5078 cs->x, cs->y, cs->cx, cs->cy);
5081 case WM_GETMINMAXINFO:
5083 MINMAXINFO *minmax = (MINMAXINFO *)lp;
5084 dump_minmax_info(minmax);
5085 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
5086 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
5087 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
5088 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
5092 return DefWindowProc(hwnd, msg, wp, lp);
5095 static void test_fullscreen(void)
5097 static const DWORD t_style[] = {
5098 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
5100 static const DWORD t_ex_style[] = {
5101 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
5111 if (!pGetMonitorInfoA || !pMonitorFromPoint)
5113 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
5118 SetLastError(0xdeadbeef);
5119 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
5120 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
5122 mi.cbSize = sizeof(mi);
5123 SetLastError(0xdeadbeef);
5124 ret = pGetMonitorInfoA(hmon, &mi);
5125 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
5126 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
5127 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5128 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5131 cls.lpfnWndProc = fullscreen_wnd_proc;
5134 cls.hInstance = GetModuleHandle(0);
5136 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5137 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5138 cls.lpszMenuName = NULL;
5139 cls.lpszClassName = "fullscreen_class";
5140 RegisterClass(&cls);
5142 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
5144 DWORD style, ex_style;
5146 /* avoid a WM interaction */
5147 assert(!(t_style[i] & WS_VISIBLE));
5149 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
5154 ex_style = t_ex_style[j];
5156 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5157 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5158 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5159 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5160 GetWindowRect(hwnd, &rc);
5161 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5162 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5163 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5164 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5165 DestroyWindow(hwnd);
5167 style = t_style[i] | WS_MAXIMIZE;
5168 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5169 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5170 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5171 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5172 GetWindowRect(hwnd, &rc);
5173 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5174 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5175 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5176 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5177 DestroyWindow(hwnd);
5179 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
5180 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5181 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5182 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5183 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5184 GetWindowRect(hwnd, &rc);
5185 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5186 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5187 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5188 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5189 DestroyWindow(hwnd);
5191 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
5192 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5193 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5194 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5195 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5196 GetWindowRect(hwnd, &rc);
5197 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5198 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5199 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5200 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5201 DestroyWindow(hwnd);
5203 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
5204 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5205 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5206 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5207 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5208 GetWindowRect(hwnd, &rc);
5209 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5210 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5211 fixup = min(abs(rc.left), abs(rc.top));
5212 InflateRect(&rc, -fixup, -fixup);
5213 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5214 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5215 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
5216 ex_style, style, rc.left, rc.top, rc.right, rc.bottom,
5217 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5218 DestroyWindow(hwnd);
5220 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
5221 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5222 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5223 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5224 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5225 GetWindowRect(hwnd, &rc);
5226 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5227 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5228 fixup = min(abs(rc.left), abs(rc.top));
5229 InflateRect(&rc, -fixup, -fixup);
5230 if (style & (WS_CHILD | WS_POPUP))
5231 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5232 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5233 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5235 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5236 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5237 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5238 DestroyWindow(hwnd);
5242 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5245 static BOOL test_thick_child_got_minmax;
5246 static const char * test_thick_child_name;
5247 static LONG test_thick_child_style;
5248 static LONG test_thick_child_exStyle;
5250 static LRESULT WINAPI test_thick_child_size_winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5253 int expectedMinTrackX;
5254 int expectedMinTrackY;
5255 int actualMinTrackX;
5256 int actualMinTrackY;
5257 int expectedMaxTrackX;
5258 int expectedMaxTrackY;
5259 int actualMaxTrackX;
5260 int actualMaxTrackY;
5261 int expectedMaxSizeX;
5262 int expectedMaxSizeY;
5273 case WM_GETMINMAXINFO:
5275 minmax = (MINMAXINFO *)lparam;
5276 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
5277 dump_minmax_info( minmax );
5279 test_thick_child_got_minmax = TRUE;
5282 adjustedStyle = test_thick_child_style;
5283 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
5284 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5285 GetClientRect(GetParent(hwnd), &rect);
5286 AdjustWindowRectEx(&rect, adjustedStyle, FALSE, test_thick_child_exStyle);
5288 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
5290 expectedMinTrackX = GetSystemMetrics(SM_CXMINTRACK);
5291 expectedMinTrackY = GetSystemMetrics(SM_CYMINTRACK);
5295 expectedMinTrackX = -2 * rect.left;
5296 expectedMinTrackY = -2 * rect.top;
5298 actualMinTrackX = minmax->ptMinTrackSize.x;
5299 actualMinTrackY = minmax->ptMinTrackSize.y;
5301 ok(actualMinTrackX == expectedMinTrackX && actualMinTrackY == expectedMinTrackY,
5302 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
5303 expectedMinTrackX, expectedMinTrackY, actualMinTrackX, actualMinTrackY,
5304 test_thick_child_name);
5306 actualMaxTrackX = minmax->ptMaxTrackSize.x;
5307 actualMaxTrackY = minmax->ptMaxTrackSize.y;
5308 expectedMaxTrackX = GetSystemMetrics(SM_CXMAXTRACK);
5309 expectedMaxTrackY = GetSystemMetrics(SM_CYMAXTRACK);
5310 ok(actualMaxTrackX == expectedMaxTrackX && actualMaxTrackY == expectedMaxTrackY,
5311 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
5312 expectedMaxTrackX, expectedMaxTrackY, actualMaxTrackX, actualMaxTrackY,
5313 test_thick_child_name);
5315 expectedMaxSizeX = rect.right - rect.left;
5316 expectedMaxSizeY = rect.bottom - rect.top;
5317 actualMaxSizeX = minmax->ptMaxSize.x;
5318 actualMaxSizeY = minmax->ptMaxSize.y;
5320 ok(actualMaxSizeX == expectedMaxSizeX && actualMaxSizeY == expectedMaxSizeY,
5321 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
5322 expectedMaxSizeX, expectedMaxSizeY, actualMaxSizeX, actualMaxSizeY,
5323 test_thick_child_name);
5326 expectedPosX = rect.left;
5327 expectedPosY = rect.top;
5328 actualPosX = minmax->ptMaxPosition.x;
5329 actualPosY = minmax->ptMaxPosition.y;
5330 ok(actualPosX == expectedPosX && actualPosY == expectedPosY,
5331 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
5332 expectedPosX, expectedPosY, actualPosX, actualPosY, test_thick_child_name);
5338 return DefWindowProcA(hwnd, msg, wparam, lparam);
5341 #define NUMBER_OF_THICK_CHILD_TESTS 16
5342 static void test_thick_child_size(HWND parentWindow)
5346 RECT adjustedParentRect;
5351 LONG expectedHeight;
5353 LPCTSTR className = "THICK_CHILD_CLASS";
5356 static const LONG styles[NUMBER_OF_THICK_CHILD_TESTS] = {
5357 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5358 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5359 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5360 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5361 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5362 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5363 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5364 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5365 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5366 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5367 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5368 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5369 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5370 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5371 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5372 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5375 static const LONG exStyles[NUMBER_OF_THICK_CHILD_TESTS] = {
5380 WS_EX_DLGMODALFRAME,
5381 WS_EX_DLGMODALFRAME,
5382 WS_EX_DLGMODALFRAME,
5383 WS_EX_DLGMODALFRAME,
5388 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5389 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5390 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5391 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5393 static const char *styleName[NUMBER_OF_THICK_CHILD_TESTS] = {
5394 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
5395 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
5396 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
5397 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
5398 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
5399 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
5400 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5401 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5402 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
5403 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
5404 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5405 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5406 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5407 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5408 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5409 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5413 cls.lpfnWndProc = test_thick_child_size_winproc;
5416 cls.hInstance = GetModuleHandleA(0);
5418 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5419 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5420 cls.lpszMenuName = NULL;
5421 cls.lpszClassName = className;
5422 SetLastError(0xdeadbeef);
5423 ok(RegisterClassA(&cls),"RegisterClassA failed, error: %u\n", GetLastError());
5425 for(i = 0; i < NUMBER_OF_THICK_CHILD_TESTS; i++)
5427 test_thick_child_name = styleName[i];
5428 test_thick_child_style = styles[i];
5429 test_thick_child_exStyle = exStyles[i];
5430 test_thick_child_got_minmax = FALSE;
5432 SetLastError(0xdeadbeef);
5433 childWindow = CreateWindowEx( exStyles[i], className, "", styles[i], 0, 0, 0, 0, parentWindow, 0, GetModuleHandleA(0), NULL );
5434 ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
5436 ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
5438 SetLastError(0xdeadbeef);
5439 success = GetWindowRect(childWindow, &childRect);
5440 ok(success,"GetWindowRect call failed, error: %u\n", GetLastError());
5441 childWidth = childRect.right - childRect.left;
5442 childHeight = childRect.bottom - childRect.top;
5444 adjustedStyle = styles[i];
5445 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
5446 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5447 GetClientRect(GetParent(childWindow), &adjustedParentRect);
5448 AdjustWindowRectEx(&adjustedParentRect, adjustedStyle, FALSE, test_thick_child_exStyle);
5451 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
5453 expectedWidth = GetSystemMetrics(SM_CXMINTRACK);
5454 expectedHeight = GetSystemMetrics(SM_CYMINTRACK);
5458 expectedWidth = -2 * adjustedParentRect.left;
5459 expectedHeight = -2 * adjustedParentRect.top;
5462 ok((childWidth == expectedWidth) && (childHeight == expectedHeight),
5463 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
5464 test_thick_child_name, expectedWidth, expectedHeight, childWidth, childHeight);
5466 SetLastError(0xdeadbeef);
5467 success = DestroyWindow(childWindow);
5468 ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
5470 ok(UnregisterClass(className, GetModuleHandleA(0)),"UnregisterClass call failed\n");
5473 static void test_handles( HWND full_hwnd )
5475 HWND hwnd = full_hwnd;
5479 SetLastError( 0xdeadbeef );
5480 ret = GetWindowRect( hwnd, &rect );
5481 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5484 if ((ULONG_PTR)full_hwnd >> 32)
5485 hwnd = (HWND)((ULONG_PTR)full_hwnd & ~0u);
5487 hwnd = (HWND)((ULONG_PTR)full_hwnd | ((ULONG_PTR)~0u << 32));
5488 SetLastError( 0xdeadbeef );
5489 ret = GetWindowRect( hwnd, &rect );
5490 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5492 hwnd = (HWND)(((ULONG_PTR)full_hwnd & ~0u) | ((ULONG_PTR)0x1234 << 32));
5493 SetLastError( 0xdeadbeef );
5494 ret = GetWindowRect( hwnd, &rect );
5495 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5497 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x9876 << 16));
5498 SetLastError( 0xdeadbeef );
5499 ret = GetWindowRect( hwnd, &rect );
5500 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
5501 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
5503 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x12345678 << 16));
5504 SetLastError( 0xdeadbeef );
5505 ret = GetWindowRect( hwnd, &rect );
5506 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
5507 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
5513 HMODULE user32 = GetModuleHandleA( "user32.dll" );
5514 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
5515 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
5516 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
5517 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
5518 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
5519 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
5520 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
5522 if (!RegisterWindowClasses()) assert(0);
5524 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
5525 if (!hhook) win_skip( "Cannot set CBT hook, skipping some tests\n" );
5527 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
5528 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5529 WS_MAXIMIZEBOX | WS_POPUP,
5531 0, 0, GetModuleHandle(0), NULL);
5532 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
5533 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5534 WS_MAXIMIZEBOX | WS_POPUP,
5536 0, 0, GetModuleHandle(0), NULL);
5538 assert( hwndMain2 );
5540 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
5542 /* Add the tests below this line */
5543 test_thick_child_size(hwndMain);
5545 test_hwnd_message();
5546 test_nonclient_area(hwndMain);
5548 test_GetWindowModuleFileName();
5551 test_capture_3(hwndMain, hwndMain2);
5553 test_CreateWindow();
5554 test_parent_owner();
5559 test_SetWindowPos(hwndMain);
5560 test_SetMenu(hwndMain);
5561 test_SetFocus(hwndMain);
5562 test_SetActiveWindow(hwndMain);
5564 test_children_zorder(hwndMain);
5565 test_popup_zorder(hwndMain2, hwndMain);
5566 test_keyboard_input(hwndMain);
5567 test_mouse_input(hwndMain);
5568 test_validatergn(hwndMain);
5569 test_nccalcscroll( hwndMain);
5570 test_scrollvalidate( hwndMain);
5571 test_scrolldc( hwndMain);
5573 test_IsWindowUnicode();
5574 test_vis_rgn(hwndMain);
5576 test_AdjustWindowRect();
5577 test_window_styles();
5580 test_SetWindowLong();
5582 if (0) test_gettext(); /* crashes on NT4 */
5583 test_GetUpdateRect();
5585 test_layered_window();
5587 test_SetForegroundWindow(hwndMain);
5588 test_shell_window();
5589 test_handles( hwndMain );
5591 /* add the tests above this line */
5592 if (hhook) UnhookWindowsHookEx(hhook);
5594 DestroyWindow(hwndMain2);
5595 DestroyWindow(hwndMain);