2 * Unit tests for window handling
4 * Copyright 2002 Bill Medland
5 * Copyright 2002 Alexandre Julliard
6 * Copyright 2003 Dmitry Timoshkov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 /* To get ICON_SMALL2 with the MSVC headers */
24 #define _WIN32_WINNT 0x0501
36 #include "wine/test.h"
38 #ifndef SPI_GETDESKWALLPAPER
39 #define SPI_GETDESKWALLPAPER 0x0073
42 #define LONG_PTR INT_PTR
43 #define ULONG_PTR UINT_PTR
45 void dump_region(HRGN hrgn);
47 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
48 static BOOL (WINAPI *pGetWindowInfo)(HWND,WINDOWINFO*);
49 static UINT (WINAPI *pGetWindowModuleFileNameA)(HWND,LPSTR,UINT);
50 static BOOL (WINAPI *pGetLayeredWindowAttributes)(HWND,COLORREF*,BYTE*,DWORD*);
51 static BOOL (WINAPI *pSetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD);
52 static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
53 static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
55 static BOOL test_lbuttondown_flag;
56 static HWND hwndMessage;
57 static HWND hwndMain, hwndMain2;
60 static const char* szAWRClass = "Winsize";
64 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
66 static void dump_minmax_info( const MINMAXINFO *minmax )
68 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
69 minmax->ptReserved.x, minmax->ptReserved.y,
70 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
71 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
72 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
73 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
76 /* try to make sure pending X events have been processed before continuing */
77 static void flush_events( BOOL remove_messages )
82 DWORD time = GetTickCount() + diff;
86 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
88 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
89 diff = time - GetTickCount();
94 /* check the values returned by the various parent/owner functions on a given window */
95 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
96 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
102 res = pGetAncestor( hwnd, GA_PARENT );
103 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
105 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
106 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
107 res = GetParent( hwnd );
108 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
109 res = GetWindow( hwnd, GW_OWNER );
110 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
113 res = pGetAncestor( hwnd, GA_ROOT );
114 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
115 res = pGetAncestor( hwnd, GA_ROOTOWNER );
116 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
120 static BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
123 trace("EnumChildProc on %p\n", hwndChild);
124 if (*(LPINT)lParam > 1) return FALSE;
128 /* will search for the given window */
129 static BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
131 trace("EnumChildProc1 on %p\n", hwndChild);
132 if ((HWND)lParam == hwndChild) return FALSE;
136 static HWND create_tool_window( LONG style, HWND parent )
138 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
139 0, 0, 100, 100, parent, 0, 0, NULL );
140 ok( ret != 0, "Creation failed\n" );
144 /* test parent and owner values for various combinations */
145 static void test_parent_owner(void)
148 HWND test, owner, ret;
149 HWND desktop = GetDesktopWindow();
150 HWND child = create_tool_window( WS_CHILD, hwndMain );
153 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
155 /* child without parent, should fail */
156 SetLastError(0xdeadbeef);
157 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
158 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
159 ok( !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("hwnd %p, WM_GETMINMAXINFO, %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\n");
580 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
581 winpos->hwnd, winpos->hwndInsertAfter,
582 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
583 if (!(winpos->flags & SWP_NOMOVE))
585 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
586 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
588 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
589 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
591 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
592 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
596 case WM_WINDOWPOSCHANGED:
599 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
600 trace("main: WM_WINDOWPOSCHANGED\n");
601 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
602 winpos->hwnd, winpos->hwndInsertAfter,
603 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
604 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
605 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
607 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
608 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
610 GetWindowRect(hwnd, &rc1);
611 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
612 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
613 /* note: winpos coordinates are relative to parent */
614 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
615 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
618 /* Uncomment this once the test succeeds in all cases */
619 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
622 GetClientRect(hwnd, &rc2);
623 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
624 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
625 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
626 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
631 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
632 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
634 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
635 if (got_getminmaxinfo)
636 trace("%p got WM_GETMINMAXINFO\n", hwnd);
638 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
639 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
641 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
645 if (test_lbuttondown_flag)
647 ShowWindow((HWND)wparam, SW_SHOW);
648 flush_events( FALSE );
653 return DefWindowProcA(hwnd, msg, wparam, lparam);
656 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
660 case WM_GETMINMAXINFO:
662 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
664 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
665 dump_minmax_info( minmax );
666 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
671 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
672 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
674 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
675 if (got_getminmaxinfo)
676 trace("%p got WM_GETMINMAXINFO\n", hwnd);
678 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
679 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
681 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
686 return DefWindowProcA(hwnd, msg, wparam, lparam);
689 static BOOL RegisterWindowClasses(void)
693 cls.style = CS_DBLCLKS;
694 cls.lpfnWndProc = main_window_procA;
697 cls.hInstance = GetModuleHandleA(0);
699 cls.hCursor = LoadCursorA(0, IDC_ARROW);
700 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
701 cls.lpszMenuName = NULL;
702 cls.lpszClassName = "MainWindowClass";
704 if(!RegisterClassA(&cls)) return FALSE;
707 cls.lpfnWndProc = tool_window_procA;
710 cls.hInstance = GetModuleHandleA(0);
712 cls.hCursor = LoadCursorA(0, IDC_ARROW);
713 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
714 cls.lpszMenuName = NULL;
715 cls.lpszClassName = "ToolWindowClass";
717 if(!RegisterClassA(&cls)) return FALSE;
722 static void verify_window_info(HWND hwnd, const WINDOWINFO *info)
724 RECT rcWindow, rcClient;
727 ok(IsWindow(hwnd), "bad window handle\n");
729 GetWindowRect(hwnd, &rcWindow);
730 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow\n");
732 GetClientRect(hwnd, &rcClient);
733 /* translate to screen coordinates */
734 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
735 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient\n");
737 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
738 "wrong dwStyle: %08x != %08x\n", info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE));
739 /* Windows reports some undocumented exstyles in WINDOWINFO, but
740 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
742 ok((info->dwExStyle & ~0xe0000800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
743 "wrong dwExStyle: %08x != %08x\n", info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE));
744 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
745 if (GetForegroundWindow())
746 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x active %p fg %p\n",
747 info->dwWindowStatus, status, GetActiveWindow(), GetForegroundWindow());
749 /* win2k and XP return broken border info in GetWindowInfo most of
750 * the time, so there is no point in testing it.
754 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
755 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
756 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
757 ok(info->cyWindowBorders == border,
758 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
760 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType\n");
761 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
762 info->wCreatorVersion == 0x0500 /* Vista */,
763 "wrong wCreatorVersion %04x\n", info->wCreatorVersion);
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 trace("window: (%d,%d)-(%d,%d)\n", rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
795 GetClientRect(hwnd, &rc_client);
796 trace("client: (%d,%d)-(%d,%d)\n", rc_client.left, rc_client.top, rc_client.right, rc_client.bottom);
798 /* avoid some cases when things go wrong */
799 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
800 rc_window.right > 32768 || rc_window.bottom > 32768) return;
802 CopyRect(&rc, &rc_client);
803 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
804 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
806 trace("calc window: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
807 ok(EqualRect(&rc, &rc_window), "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
810 CopyRect(&rc, &rc_window);
811 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
812 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
813 trace("calc client: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
814 ok(EqualRect(&rc, &rc_client), "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
816 /* NULL rectangle shouldn't crash */
817 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
818 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
820 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
824 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
825 SetRect(&rc_client, 0, 0, 250, 150);
826 CopyRect(&rc_window, &rc_client);
827 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
828 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
829 trace("calc window: (%d,%d)-(%d,%d)\n",
830 rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
832 CopyRect(&rc, &rc_window);
833 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
834 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
835 trace("calc client: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
836 ok(EqualRect(&rc, &rc_client), "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
839 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
841 static const char *CBT_code_name[10] = {
852 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
854 trace("CBT: %d (%s), %08lx, %08lx\n", nCode, code_name, wParam, lParam);
856 /* on HCBT_DESTROYWND window state is undefined */
857 if (nCode != HCBT_DESTROYWND && IsWindow((HWND)wParam))
863 /* Win98 actually does check the info.cbSize and doesn't allow
864 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
865 * WinXP do not check it at all.
867 info.cbSize = sizeof(WINDOWINFO);
868 ok(pGetWindowInfo((HWND)wParam, &info), "GetWindowInfo should not fail\n");
869 verify_window_info((HWND)wParam, &info);
877 static const RECT rc_null;
880 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
881 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
882 (HWND)wParam, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
883 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
885 /* WS_VISIBLE should be turned off yet */
886 style = createwnd->lpcs->style & ~WS_VISIBLE;
887 ok(style == GetWindowLongA((HWND)wParam, GWL_STYLE),
888 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
889 GetWindowLongA((HWND)wParam, GWL_STYLE), style);
893 /* Uncomment this once the test succeeds in all cases */
894 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
896 ok(GetParent((HWND)wParam) == hwndMessage,
897 "wrong result from GetParent %p: message window %p\n",
898 GetParent((HWND)wParam), hwndMessage);
901 ok(!GetParent((HWND)wParam), "GetParent should return 0 at this point\n");
903 ok(!GetWindow((HWND)wParam, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
907 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
908 * Win9x still has them set to 0.
910 ok(GetWindow((HWND)wParam, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
911 ok(GetWindow((HWND)wParam, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
913 ok(!GetWindow((HWND)wParam, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
914 ok(!GetWindow((HWND)wParam, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
918 /* Uncomment this once the test succeeds in all cases */
921 ok(pGetAncestor((HWND)wParam, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
922 ok(pGetAncestor((HWND)wParam, GA_ROOT) == (HWND)wParam,
923 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOT), (HWND)wParam);
925 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
926 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == hwndMessage,
927 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
929 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == (HWND)wParam,
930 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOTOWNER), (HWND)wParam);
933 ok(GetWindowRect((HWND)wParam, &rc), "GetWindowRect failed\n");
934 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
935 ok(GetClientRect((HWND)wParam, &rc), "GetClientRect failed\n");
936 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
942 return CallNextHookEx(hhook, nCode, wParam, lParam);
945 static void test_shell_window(void)
949 HMODULE hinst, hUser32;
950 BOOL (WINAPI*SetShellWindow)(HWND);
951 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
952 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
953 HWND shellWindow, nextWnd;
955 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
957 trace("Skipping shell window test on Win9x\n");
961 shellWindow = GetShellWindow();
962 hinst = GetModuleHandle(0);
963 hUser32 = GetModuleHandleA("user32");
965 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
966 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
968 trace("previous shell window: %p\n", shellWindow);
974 SetLastError(0xdeadbeef);
975 ret = DestroyWindow(shellWindow);
976 error = GetLastError();
978 ok(!ret, "DestroyWindow(shellWindow)\n");
979 /* passes on Win XP, but not on Win98 */
980 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
981 "got %u after DestroyWindow(shellWindow)\n", error);
983 /* close old shell instance */
984 GetWindowThreadProcessId(shellWindow, &pid);
985 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
986 ret = TerminateProcess(hProcess, 0);
987 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
988 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
989 CloseHandle(hProcess);
992 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
993 trace("created window 1: %p\n", hwnd1);
995 ret = SetShellWindow(hwnd1);
996 ok(ret, "first call to SetShellWindow(hwnd1)\n");
997 shellWindow = GetShellWindow();
998 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
1000 ret = SetShellWindow(hwnd1);
1001 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1003 ret = SetShellWindow(0);
1004 error = GetLastError();
1005 /* passes on Win XP, but not on Win98
1006 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1007 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1009 ret = SetShellWindow(hwnd1);
1010 /* passes on Win XP, but not on Win98
1011 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1013 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1014 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
1015 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1017 ret = DestroyWindow(hwnd1);
1018 ok(ret, "DestroyWindow(hwnd1)\n");
1020 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1021 trace("created window 2: %p\n", hwnd2);
1022 ret = SetShellWindow(hwnd2);
1023 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1025 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1026 trace("created window 3: %p\n", hwnd3);
1028 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1029 trace("created window 4: %p\n", hwnd4);
1031 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1032 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1034 ret = SetShellWindow(hwnd4);
1035 ok(ret, "SetShellWindow(hwnd4)\n");
1036 shellWindow = GetShellWindow();
1037 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1039 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1040 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1042 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1043 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1045 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1046 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1048 ret = SetShellWindow(hwnd3);
1049 ok(!ret, "SetShellWindow(hwnd3)\n");
1050 shellWindow = GetShellWindow();
1051 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1053 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1054 trace("created window 5: %p\n", hwnd5);
1055 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1056 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1060 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1061 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1064 /* destroy test windows */
1065 DestroyWindow(hwnd2);
1066 DestroyWindow(hwnd3);
1067 DestroyWindow(hwnd4);
1068 DestroyWindow(hwnd5);
1071 /************** MDI test ****************/
1073 static char mdi_lParam_test_message[] = "just a test string";
1075 static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
1077 MDICREATESTRUCTA mdi_cs;
1080 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1081 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1082 BOOL isWin9x = FALSE;
1084 mdi_cs.szClass = "MDI_child_Class_1";
1085 mdi_cs.szTitle = "MDI child";
1086 mdi_cs.hOwner = GetModuleHandle(0);
1087 mdi_cs.x = CW_USEDEFAULT;
1088 mdi_cs.y = CW_USEDEFAULT;
1089 mdi_cs.cx = CW_USEDEFAULT;
1090 mdi_cs.cy = CW_USEDEFAULT;
1092 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1093 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1094 ok(mdi_child != 0, "MDI child creation failed\n");
1095 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1096 ok(id == first_id, "wrong child id %ld\n", id);
1097 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1098 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1100 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1101 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1102 ok(mdi_child != 0, "MDI child creation failed\n");
1103 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1104 ok(id == first_id, "wrong child id %ld\n", id);
1105 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1106 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1108 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1109 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1110 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1112 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1116 ok(mdi_child != 0, "MDI child creation failed\n");
1117 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1118 ok(id == first_id, "wrong child id %ld\n", id);
1119 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1120 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1123 /* test MDICREATESTRUCT A<->W mapping */
1124 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1126 mdi_cs.szClass = (LPCSTR)classW;
1127 mdi_cs.szTitle = (LPCSTR)titleW;
1128 SetLastError(0xdeadbeef);
1129 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1132 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1135 ok(mdi_child != 0, "MDI child creation failed\n");
1139 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1140 ok(id == first_id, "wrong child id %ld\n", id);
1141 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1142 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1145 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1147 CW_USEDEFAULT, CW_USEDEFAULT,
1148 CW_USEDEFAULT, CW_USEDEFAULT,
1149 mdi_client, GetModuleHandle(0),
1150 (LPARAM)mdi_lParam_test_message);
1151 ok(mdi_child != 0, "MDI child creation failed\n");
1152 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1153 ok(id == first_id, "wrong child id %ld\n", id);
1154 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1155 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1157 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1158 0x7fffffff, /* without WS_POPUP */
1159 CW_USEDEFAULT, CW_USEDEFAULT,
1160 CW_USEDEFAULT, CW_USEDEFAULT,
1161 mdi_client, GetModuleHandle(0),
1162 (LPARAM)mdi_lParam_test_message);
1163 ok(mdi_child != 0, "MDI child creation failed\n");
1164 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1165 ok(id == first_id, "wrong child id %ld\n", id);
1166 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1167 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1169 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1170 0xffffffff, /* with WS_POPUP */
1171 CW_USEDEFAULT, CW_USEDEFAULT,
1172 CW_USEDEFAULT, CW_USEDEFAULT,
1173 mdi_client, GetModuleHandle(0),
1174 (LPARAM)mdi_lParam_test_message);
1175 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1177 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1181 ok(mdi_child != 0, "MDI child creation failed\n");
1182 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1183 ok(id == first_id, "wrong child id %ld\n", id);
1184 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1185 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1188 /* test MDICREATESTRUCT A<->W mapping */
1189 SetLastError(0xdeadbeef);
1190 mdi_child = CreateMDIWindowW(classW, titleW,
1192 CW_USEDEFAULT, CW_USEDEFAULT,
1193 CW_USEDEFAULT, CW_USEDEFAULT,
1194 mdi_client, GetModuleHandle(0),
1195 (LPARAM)mdi_lParam_test_message);
1198 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1201 ok(mdi_child != 0, "MDI child creation failed\n");
1205 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1206 ok(id == first_id, "wrong child id %ld\n", id);
1207 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1208 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1211 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1213 CW_USEDEFAULT, CW_USEDEFAULT,
1214 CW_USEDEFAULT, CW_USEDEFAULT,
1215 mdi_client, 0, GetModuleHandle(0),
1216 (LPVOID)mdi_lParam_test_message);
1217 ok(mdi_child != 0, "MDI child creation failed\n");
1218 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1219 ok(id == first_id, "wrong child id %ld\n", id);
1220 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1221 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1223 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1224 0x7fffffff, /* without WS_POPUP */
1225 CW_USEDEFAULT, CW_USEDEFAULT,
1226 CW_USEDEFAULT, CW_USEDEFAULT,
1227 mdi_client, 0, GetModuleHandle(0),
1228 (LPVOID)mdi_lParam_test_message);
1229 ok(mdi_child != 0, "MDI child creation failed\n");
1230 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1231 ok(id == first_id, "wrong child id %ld\n", id);
1232 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1233 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1235 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1236 0xffffffff, /* with WS_POPUP */
1237 CW_USEDEFAULT, CW_USEDEFAULT,
1238 CW_USEDEFAULT, CW_USEDEFAULT,
1239 mdi_client, 0, GetModuleHandle(0),
1240 (LPVOID)mdi_lParam_test_message);
1241 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1243 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1247 ok(mdi_child != 0, "MDI child creation failed\n");
1248 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1249 ok(id == first_id, "wrong child id %ld\n", id);
1250 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1251 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1254 /* test MDICREATESTRUCT A<->W mapping */
1255 SetLastError(0xdeadbeef);
1256 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1258 CW_USEDEFAULT, CW_USEDEFAULT,
1259 CW_USEDEFAULT, CW_USEDEFAULT,
1260 mdi_client, 0, GetModuleHandle(0),
1261 (LPVOID)mdi_lParam_test_message);
1264 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1267 ok(mdi_child != 0, "MDI child creation failed\n");
1271 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1272 ok(id == first_id, "wrong child id %ld\n", id);
1273 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1274 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1277 /* This test fails on Win9x */
1280 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1282 CW_USEDEFAULT, CW_USEDEFAULT,
1283 CW_USEDEFAULT, CW_USEDEFAULT,
1284 parent, 0, GetModuleHandle(0),
1285 (LPVOID)mdi_lParam_test_message);
1286 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1289 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1290 WS_CHILD, /* without WS_POPUP */
1291 CW_USEDEFAULT, CW_USEDEFAULT,
1292 CW_USEDEFAULT, CW_USEDEFAULT,
1293 mdi_client, 0, GetModuleHandle(0),
1294 (LPVOID)mdi_lParam_test_message);
1295 ok(mdi_child != 0, "MDI child creation failed\n");
1296 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1297 ok(id == 0, "wrong child id %ld\n", id);
1298 DestroyWindow(mdi_child);
1300 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1301 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1302 CW_USEDEFAULT, CW_USEDEFAULT,
1303 CW_USEDEFAULT, CW_USEDEFAULT,
1304 mdi_client, 0, GetModuleHandle(0),
1305 (LPVOID)mdi_lParam_test_message);
1306 ok(mdi_child != 0, "MDI child creation failed\n");
1307 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1308 ok(id == 0, "wrong child id %ld\n", id);
1309 DestroyWindow(mdi_child);
1311 /* maximized child */
1312 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1313 WS_CHILD | WS_MAXIMIZE,
1314 CW_USEDEFAULT, CW_USEDEFAULT,
1315 CW_USEDEFAULT, CW_USEDEFAULT,
1316 mdi_client, 0, GetModuleHandle(0),
1317 (LPVOID)mdi_lParam_test_message);
1318 ok(mdi_child != 0, "MDI child creation failed\n");
1319 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1320 ok(id == 0, "wrong child id %ld\n", id);
1321 DestroyWindow(mdi_child);
1323 trace("Creating maximized child with a caption\n");
1324 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1325 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1326 CW_USEDEFAULT, CW_USEDEFAULT,
1327 CW_USEDEFAULT, CW_USEDEFAULT,
1328 mdi_client, 0, GetModuleHandle(0),
1329 (LPVOID)mdi_lParam_test_message);
1330 ok(mdi_child != 0, "MDI child creation failed\n");
1331 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1332 ok(id == 0, "wrong child id %ld\n", id);
1333 DestroyWindow(mdi_child);
1335 trace("Creating maximized child with a caption and a thick frame\n");
1336 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1337 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1338 CW_USEDEFAULT, CW_USEDEFAULT,
1339 CW_USEDEFAULT, CW_USEDEFAULT,
1340 mdi_client, 0, GetModuleHandle(0),
1341 (LPVOID)mdi_lParam_test_message);
1342 ok(mdi_child != 0, "MDI child creation failed\n");
1343 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1344 ok(id == 0, "wrong child id %ld\n", id);
1345 DestroyWindow(mdi_child);
1348 /**********************************************************************
1349 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1351 * Note: The rule here is that client rect of the maximized MDI child
1352 * is equal to the client rect of the MDI client window.
1354 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1358 GetClientRect( client, &rect );
1359 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1360 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1362 rect.right -= rect.left;
1363 rect.bottom -= rect.top;
1364 lpMinMax->ptMaxSize.x = rect.right;
1365 lpMinMax->ptMaxSize.y = rect.bottom;
1367 lpMinMax->ptMaxPosition.x = rect.left;
1368 lpMinMax->ptMaxPosition.y = rect.top;
1370 trace("max rect (%d,%d - %d, %d)\n",
1371 rect.left, rect.top, rect.right, rect.bottom);
1374 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1381 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1382 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs->lpCreateParams;
1384 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1385 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1387 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1388 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1389 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1390 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1391 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1393 /* MDICREATESTRUCT should have original values */
1394 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1395 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1396 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1397 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1398 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1399 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1401 /* CREATESTRUCT should have fixed values */
1402 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1403 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1405 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1406 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1407 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1409 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1411 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1413 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1414 ok(cs->style == style,
1415 "cs->style does not match (%08x)\n", cs->style);
1419 LONG style = mdi_cs->style;
1421 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1422 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1423 ok(cs->style == style,
1424 "cs->style does not match (%08x)\n", cs->style);
1429 case WM_GETMINMAXINFO:
1431 HWND client = GetParent(hwnd);
1433 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1434 MINMAXINFO my_minmax;
1435 LONG style, exstyle;
1437 style = GetWindowLongA(hwnd, GWL_STYLE);
1438 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1440 GetWindowRect(client, &rc);
1441 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1442 GetClientRect(client, &rc);
1443 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1444 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1445 GetSystemMetrics(SM_CYSCREEN));
1447 GetClientRect(client, &rc);
1448 if ((style & WS_CAPTION) == WS_CAPTION)
1449 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1450 AdjustWindowRectEx(&rc, style, 0, exstyle);
1451 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1452 dump_minmax_info( minmax );
1454 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1455 minmax->ptMaxSize.x, rc.right - rc.left);
1456 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1457 minmax->ptMaxSize.y, rc.bottom - rc.top);
1459 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1461 trace("DefMDIChildProc returned:\n");
1462 dump_minmax_info( minmax );
1464 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1465 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1466 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1467 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1468 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1473 case WM_MDIACTIVATE:
1475 HWND active, client = GetParent(hwnd);
1476 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1477 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1478 if (hwnd == (HWND)lparam) /* if we are being activated */
1479 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1481 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1485 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1488 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1495 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1497 trace("%s\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE");
1498 trace("x %d, y %d, cx %d, cy %d\n", cs->x, cs->y, cs->cx, cs->cy);
1500 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1501 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1503 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1504 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1506 /* CREATESTRUCT should have fixed values */
1507 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1509 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1510 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1512 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1513 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1514 while Win95, Win2k, WinXP do. */
1515 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1516 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1520 case WM_GETMINMAXINFO:
1522 HWND parent = GetParent(hwnd);
1524 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1525 LONG style, exstyle;
1527 trace("WM_GETMINMAXINFO\n");
1529 style = GetWindowLongA(hwnd, GWL_STYLE);
1530 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1532 GetClientRect(parent, &rc);
1533 trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1535 GetClientRect(parent, &rc);
1536 if ((style & WS_CAPTION) == WS_CAPTION)
1537 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1538 AdjustWindowRectEx(&rc, style, 0, exstyle);
1539 trace("calculated max child window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1540 dump_minmax_info( minmax );
1542 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1543 minmax->ptMaxSize.x, rc.right - rc.left);
1544 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1545 minmax->ptMaxSize.y, rc.bottom - rc.top);
1549 case WM_WINDOWPOSCHANGED:
1551 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1554 GetWindowRect(hwnd, &rc1);
1555 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1556 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1557 /* note: winpos coordinates are relative to parent */
1558 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1559 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1560 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1562 GetWindowRect(hwnd, &rc1);
1563 GetClientRect(hwnd, &rc2);
1564 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1565 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1566 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1569 case WM_WINDOWPOSCHANGING:
1571 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1572 WINDOWPOS my_winpos = *winpos;
1574 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1575 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1576 winpos->hwnd, winpos->hwndInsertAfter,
1577 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1579 DefWindowProcA(hwnd, msg, wparam, lparam);
1581 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1582 winpos->hwnd, winpos->hwndInsertAfter,
1583 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1585 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1586 "DefWindowProc should not change WINDOWPOS values\n");
1591 return DefWindowProcA(hwnd, msg, wparam, lparam);
1594 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1596 static HWND mdi_client;
1602 CLIENTCREATESTRUCT client_cs;
1605 GetClientRect(hwnd, &rc);
1607 client_cs.hWindowMenu = 0;
1608 client_cs.idFirstChild = 1;
1610 /* MDIClient without MDIS_ALLCHILDSTYLES */
1611 mdi_client = CreateWindowExA(0, "mdiclient",
1613 WS_CHILD /*| WS_VISIBLE*/,
1614 /* tests depend on a not zero MDIClient size */
1615 0, 0, rc.right, rc.bottom,
1616 hwnd, 0, GetModuleHandle(0),
1617 (LPVOID)&client_cs);
1619 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1620 DestroyWindow(mdi_client);
1622 /* MDIClient with MDIS_ALLCHILDSTYLES */
1623 mdi_client = CreateWindowExA(0, "mdiclient",
1625 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1626 /* tests depend on a not zero MDIClient size */
1627 0, 0, rc.right, rc.bottom,
1628 hwnd, 0, GetModuleHandle(0),
1629 (LPVOID)&client_cs);
1631 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1632 DestroyWindow(mdi_client);
1636 case WM_WINDOWPOSCHANGED:
1638 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1641 GetWindowRect(hwnd, &rc1);
1642 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1643 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1644 /* note: winpos coordinates are relative to parent */
1645 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1646 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1647 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1649 GetWindowRect(hwnd, &rc1);
1650 GetClientRect(hwnd, &rc2);
1651 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1652 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1653 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1656 case WM_WINDOWPOSCHANGING:
1658 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1659 WINDOWPOS my_winpos = *winpos;
1661 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1662 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1663 winpos->hwnd, winpos->hwndInsertAfter,
1664 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1666 DefWindowProcA(hwnd, msg, wparam, lparam);
1668 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1669 winpos->hwnd, winpos->hwndInsertAfter,
1670 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1672 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1673 "DefWindowProc should not change WINDOWPOS values\n");
1682 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1685 static BOOL mdi_RegisterWindowClasses(void)
1690 cls.lpfnWndProc = mdi_main_wnd_procA;
1693 cls.hInstance = GetModuleHandleA(0);
1695 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1696 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1697 cls.lpszMenuName = NULL;
1698 cls.lpszClassName = "MDI_parent_Class";
1699 if(!RegisterClassA(&cls)) return FALSE;
1701 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1702 cls.lpszClassName = "MDI_child_Class_1";
1703 if(!RegisterClassA(&cls)) return FALSE;
1705 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1706 cls.lpszClassName = "MDI_child_Class_2";
1707 if(!RegisterClassA(&cls)) return FALSE;
1712 static void test_mdi(void)
1717 if (!mdi_RegisterWindowClasses()) assert(0);
1719 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1720 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1721 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1722 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1723 GetDesktopWindow(), 0,
1724 GetModuleHandle(0), NULL);
1725 assert(mdi_hwndMain);
1727 while(GetMessage(&msg, 0, 0, 0))
1729 TranslateMessage(&msg);
1730 DispatchMessage(&msg);
1733 DestroyWindow(mdi_hwndMain);
1736 static void test_icons(void)
1740 HICON icon = LoadIconA(0, IDI_APPLICATION);
1741 HICON icon2 = LoadIconA(0, IDI_QUESTION);
1742 HICON small_icon = LoadImageA(0, IDI_APPLICATION, IMAGE_ICON,
1743 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1746 cls.cbSize = sizeof(cls);
1748 cls.lpfnWndProc = DefWindowProcA;
1752 cls.hIcon = LoadIconA(0, IDI_HAND);
1753 cls.hIconSm = small_icon;
1754 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1755 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1756 cls.lpszMenuName = NULL;
1757 cls.lpszClassName = "IconWindowClass";
1759 RegisterClassExA(&cls);
1761 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1762 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1765 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1766 ok( res == 0, "wrong big icon %p/0\n", res );
1767 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1768 ok( res == 0, "wrong previous big icon %p/0\n", res );
1769 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1770 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1771 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1772 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1773 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1774 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1776 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1777 ok( res == 0, "wrong small icon %p/0\n", res );
1778 /* this test is XP specific */
1779 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1780 ok( res != 0, "wrong small icon %p\n", res );*/
1781 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1782 ok( res == 0, "wrong previous small icon %p/0\n", res );
1783 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1784 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1785 /* this test is XP specific */
1786 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1787 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1788 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1789 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1790 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1791 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1792 /* this test is XP specific */
1793 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1794 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1796 /* make sure the big icon hasn't changed */
1797 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1798 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1800 DestroyWindow( hwnd );
1803 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1805 if (msg == WM_NCCALCSIZE)
1807 RECT *rect = (RECT *)lparam;
1808 /* first time around increase the rectangle, next time decrease it */
1809 if (rect->left == 100) InflateRect( rect, 10, 10 );
1810 else InflateRect( rect, -10, -10 );
1813 return DefWindowProc( hwnd, msg, wparam, lparam );
1816 static void test_SetWindowPos(HWND hwnd)
1818 RECT orig_win_rc, rect;
1820 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1822 SetRect(&rect, 111, 222, 333, 444);
1823 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1824 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1825 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1827 SetRect(&rect, 111, 222, 333, 444);
1828 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1829 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1830 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1832 GetWindowRect(hwnd, &orig_win_rc);
1834 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1835 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1836 GetWindowRect( hwnd, &rect );
1837 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1838 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1839 GetClientRect( hwnd, &rect );
1840 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1841 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1842 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1844 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1845 GetWindowRect( hwnd, &rect );
1846 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1847 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1848 GetClientRect( hwnd, &rect );
1849 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1850 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1851 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1853 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1854 orig_win_rc.right, orig_win_rc.bottom, 0);
1855 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1857 /* Win9x truncates coordinates to 16-bit irrespectively */
1860 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1861 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1863 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1864 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1867 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1868 orig_win_rc.right, orig_win_rc.bottom, 0);
1870 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1871 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1872 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1873 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1874 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1875 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1876 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1879 static void test_SetMenu(HWND parent)
1883 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1887 hMenu = CreateMenu();
1890 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1893 /* fails on (at least) Wine, NT4, XP SP2 */
1894 test_nonclient_area(parent);
1896 ret = GetMenu(parent);
1897 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1898 /* test whether we can destroy a menu assigned to a window */
1899 retok = DestroyMenu(hMenu);
1900 ok( retok, "DestroyMenu error %d\n", GetLastError());
1901 retok = IsMenu(hMenu);
1902 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
1903 ret = GetMenu(parent);
1904 /* This test fails on Win9x */
1906 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1907 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1908 test_nonclient_area(parent);
1910 hMenu = CreateMenu();
1914 ret = GetMenu(parent);
1915 ok(ret == 0, "unexpected menu id %p\n", ret);
1917 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1918 test_nonclient_area(parent);
1919 ret = GetMenu(parent);
1920 ok(ret == 0, "unexpected menu id %p\n", ret);
1922 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1925 /* fails on (at least) Wine, NT4, XP SP2 */
1926 test_nonclient_area(parent);
1928 ret = GetMenu(parent);
1929 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1931 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1932 test_nonclient_area(parent);
1933 ret = GetMenu(parent);
1934 ok(ret == 0, "unexpected menu id %p\n", ret);
1937 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1940 ret = GetMenu(child);
1941 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1943 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1944 test_nonclient_area(child);
1945 ret = GetMenu(child);
1946 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1948 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1949 test_nonclient_area(child);
1950 ret = GetMenu(child);
1951 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1953 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1954 test_nonclient_area(child);
1955 ret = GetMenu(child);
1956 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1958 style = GetWindowLong(child, GWL_STYLE);
1959 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
1960 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
1961 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
1962 SetWindowLong(child, GWL_STYLE, style);
1964 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
1965 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
1966 SetWindowLong(child, GWL_STYLE, style);
1968 DestroyWindow(child);
1972 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1974 HWND child[5], hwnd;
1979 hwnd = GetWindow(parent, GW_CHILD);
1980 ok(!hwnd, "have to start without children to perform the test\n");
1982 for (i = 0; i < total; i++)
1984 if (style[i] & DS_CONTROL)
1986 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
1987 0,0,0,0, parent, (HMENU)i, 0, NULL);
1988 if (style[i] & WS_VISIBLE)
1989 ShowWindow(child[i], SW_SHOW);
1991 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
1994 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
1995 parent, (HMENU)i, 0, NULL);
1996 trace("child[%ld] = %p\n", i, child[i]);
1997 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
2000 hwnd = GetWindow(parent, GW_CHILD);
2001 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
2002 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
2003 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
2005 for (i = 0; i < total; i++)
2007 trace("hwnd[%ld] = %p\n", i, hwnd);
2008 ok(child[order[i]] == hwnd, "Z order of child #%ld is wrong\n", i);
2010 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
2013 for (i = 0; i < total; i++)
2014 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2017 static void test_children_zorder(HWND parent)
2019 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2021 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2023 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2024 WS_CHILD | WS_VISIBLE, WS_CHILD,
2025 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2026 const int complex_order_1[1] = { 0 };
2027 const int complex_order_2[2] = { 1, 0 };
2028 const int complex_order_3[3] = { 1, 0, 2 };
2029 const int complex_order_4[4] = { 1, 0, 2, 3 };
2030 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2031 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2032 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2033 WS_CHILD | WS_VISIBLE };
2034 const int complex_order_6[3] = { 0, 1, 2 };
2036 /* simple WS_CHILD */
2037 test_window_tree(parent, simple_style, simple_order, 5);
2039 /* complex children styles */
2040 test_window_tree(parent, complex_style, complex_order_1, 1);
2041 test_window_tree(parent, complex_style, complex_order_2, 2);
2042 test_window_tree(parent, complex_style, complex_order_3, 3);
2043 test_window_tree(parent, complex_style, complex_order_4, 4);
2044 test_window_tree(parent, complex_style, complex_order_5, 5);
2046 /* another set of complex children styles */
2047 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2050 #define check_z_order(hwnd, next, prev, owner, topmost) \
2051 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2054 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2055 BOOL topmost, const char *file, int line)
2060 test = GetWindow(hwnd, GW_HWNDNEXT);
2061 /* skip foreign windows */
2062 while (test && (GetWindowThreadProcessId(test, NULL) != our_pid ||
2063 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0)))
2065 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2066 test = GetWindow(test, GW_HWNDNEXT);
2068 ok_(file, line)(next == test, "expected next %p, got %p\n", next, test);
2070 test = GetWindow(hwnd, GW_HWNDPREV);
2071 /* skip foreign windows */
2072 while (test && (GetWindowThreadProcessId(test, NULL) != our_pid ||
2073 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0)))
2075 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2076 test = GetWindow(test, GW_HWNDPREV);
2078 ok_(file, line)(prev == test, "expected prev %p, got %p\n", prev, test);
2080 test = GetWindow(hwnd, GW_OWNER);
2081 ok_(file, line)(owner == test, "expected owner %p, got %p\n", owner, test);
2083 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2084 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "expected %stopmost\n", topmost ? "" : "NOT ");
2087 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E)
2089 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2091 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2093 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2095 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2096 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2098 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2099 WS_OVERLAPPED | WS_CAPTION,
2101 0, 0, GetModuleHandle(0), NULL);
2102 trace("hwnd_F %p\n", hwnd_F);
2103 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2105 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2106 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2107 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2108 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2110 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2113 hwnd_F, 0, GetModuleHandle(0), NULL);
2114 trace("hwnd_C %p\n", hwnd_C);
2115 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2116 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2117 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2118 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2120 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2123 hwnd_F, 0, GetModuleHandle(0), NULL);
2124 trace("hwnd_B %p\n", hwnd_B);
2125 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2126 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2127 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2128 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2129 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2131 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2134 0, 0, GetModuleHandle(0), NULL);
2135 trace("hwnd_A %p\n", hwnd_A);
2136 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2137 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2138 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2139 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2140 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2141 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2143 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);
2145 /* move hwnd_F and its popups up */
2146 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2147 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2148 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2149 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2150 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2151 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2152 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2154 /* move hwnd_F and its popups down */
2155 #if 0 /* enable once Wine is fixed to pass this test */
2156 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2157 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2158 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2159 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2160 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2161 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2162 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2165 DestroyWindow(hwnd_A);
2166 DestroyWindow(hwnd_B);
2167 DestroyWindow(hwnd_C);
2168 DestroyWindow(hwnd_F);
2171 static void test_vis_rgn( HWND hwnd )
2173 RECT win_rect, rgn_rect;
2174 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2177 ShowWindow(hwnd,SW_SHOW);
2178 hdc = GetDC( hwnd );
2179 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2180 GetWindowRect( hwnd, &win_rect );
2181 GetRgnBox( hrgn, &rgn_rect );
2182 if (GetVersion() & 0x80000000)
2184 trace("win9x, mapping to screen coords\n");
2185 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2187 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2188 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2189 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2190 rgn_rect.left, win_rect.left );
2191 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2192 rgn_rect.top, win_rect.top );
2193 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2194 rgn_rect.right, win_rect.right );
2195 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2196 rgn_rect.bottom, win_rect.bottom );
2197 ReleaseDC( hwnd, hdc );
2200 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2202 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2204 HWND child = GetWindow(hwnd, GW_CHILD);
2205 ok(child != 0, "couldn't find child window\n");
2207 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2210 return DefWindowProc(hwnd, msg, wp, lp);
2213 static void test_SetFocus(HWND hwnd)
2216 WNDPROC old_wnd_proc;
2218 /* check if we can set focus to non-visible windows */
2220 ShowWindow(hwnd, SW_SHOW);
2223 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2224 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2225 ShowWindow(hwnd, SW_HIDE);
2228 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2229 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2230 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2233 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2234 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2235 ShowWindow(child, SW_SHOW);
2236 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2237 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2238 ShowWindow(child, SW_HIDE);
2239 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2240 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2241 ShowWindow(child, SW_SHOW);
2243 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2244 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2245 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2247 ShowWindow(child, SW_HIDE);
2249 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2250 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2251 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2252 ShowWindow(child, SW_HIDE);
2253 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2255 ShowWindow(hwnd, SW_SHOW);
2256 ShowWindow(child, SW_SHOW);
2258 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2259 EnableWindow(hwnd, FALSE);
2260 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2261 EnableWindow(hwnd, TRUE);
2263 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2264 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2265 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2267 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2268 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2269 ShowWindow(hwnd, SW_RESTORE);
2270 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2271 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2272 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2273 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2274 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2276 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2277 old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2278 ShowWindow(hwnd, SW_RESTORE);
2279 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2281 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2283 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2285 DestroyWindow( child );
2288 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
2289 static void check_wnd_state_(const char *file, int line,
2290 HWND active, HWND foreground, HWND focus, HWND capture)
2292 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2293 if (foreground && GetForegroundWindow())
2294 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2295 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2296 ok_(file, line)(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2299 static void test_SetActiveWindow(HWND hwnd)
2303 flush_events( TRUE );
2304 ShowWindow(hwnd, SW_HIDE);
2307 check_wnd_state(0, 0, 0, 0);
2309 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2311 ShowWindow(hwnd, SW_SHOW);
2312 check_wnd_state(hwnd, hwnd, hwnd, 0);
2314 hwnd2 = SetActiveWindow(0);
2315 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2316 if (!GetActiveWindow()) /* doesn't always work on vista */
2318 check_wnd_state(0, 0, 0, 0);
2319 hwnd2 = SetActiveWindow(hwnd);
2320 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2322 check_wnd_state(hwnd, hwnd, hwnd, 0);
2324 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2325 check_wnd_state(hwnd, hwnd, hwnd, 0);
2327 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2328 check_wnd_state(hwnd, hwnd, hwnd, 0);
2330 ShowWindow(hwnd, SW_HIDE);
2331 check_wnd_state(0, 0, 0, 0);
2333 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2334 SetActiveWindow(hwnd);
2335 check_wnd_state(hwnd, hwnd, hwnd, 0);
2337 ShowWindow(hwnd, SW_SHOW);
2338 check_wnd_state(hwnd, hwnd, hwnd, 0);
2340 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2341 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2343 DestroyWindow(hwnd2);
2344 check_wnd_state(hwnd, hwnd, hwnd, 0);
2346 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2347 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2349 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2350 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2352 DestroyWindow(hwnd2);
2353 check_wnd_state(hwnd, hwnd, hwnd, 0);
2356 static void test_SetForegroundWindow(HWND hwnd)
2361 flush_events( TRUE );
2362 ShowWindow(hwnd, SW_HIDE);
2365 check_wnd_state(0, 0, 0, 0);
2367 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2369 ShowWindow(hwnd, SW_SHOW);
2370 check_wnd_state(hwnd, hwnd, hwnd, 0);
2372 hwnd2 = SetActiveWindow(0);
2373 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2374 if (GetActiveWindow() == hwnd) /* doesn't always work on vista */
2375 check_wnd_state(hwnd, hwnd, hwnd, 0);
2377 check_wnd_state(0, 0, 0, 0);
2379 ret = SetForegroundWindow(hwnd);
2380 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2381 check_wnd_state(hwnd, hwnd, hwnd, 0);
2383 SetLastError(0xdeadbeef);
2384 ret = SetForegroundWindow(0);
2385 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2386 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
2387 broken(GetLastError() == 0xdeadbeef), /* win9x */
2388 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2389 check_wnd_state(hwnd, hwnd, hwnd, 0);
2391 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2392 check_wnd_state(hwnd, hwnd, hwnd, 0);
2394 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2395 check_wnd_state(hwnd, hwnd, hwnd, 0);
2397 hwnd2 = GetForegroundWindow();
2398 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2399 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2400 hwnd2 = GetForegroundWindow();
2401 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2403 ShowWindow(hwnd, SW_HIDE);
2404 check_wnd_state(0, 0, 0, 0);
2406 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2407 ret = SetForegroundWindow(hwnd);
2408 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2409 check_wnd_state(hwnd, hwnd, hwnd, 0);
2411 ShowWindow(hwnd, SW_SHOW);
2412 check_wnd_state(hwnd, hwnd, hwnd, 0);
2414 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2415 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2417 DestroyWindow(hwnd2);
2418 check_wnd_state(hwnd, hwnd, hwnd, 0);
2420 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2421 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2423 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2424 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2426 DestroyWindow(hwnd2);
2427 check_wnd_state(hwnd, hwnd, hwnd, 0);
2430 static WNDPROC old_button_proc;
2432 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2437 key_state = GetKeyState(VK_LBUTTON);
2438 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2440 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2442 if (msg == WM_LBUTTONDOWN)
2446 check_wnd_state(button, button, button, button);
2448 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2450 trace("hwnd %p\n", hwnd);
2452 check_wnd_state(button, button, button, button);
2454 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2456 check_wnd_state(button, button, button, button);
2458 DestroyWindow(hwnd);
2460 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2462 trace("hwnd %p\n", hwnd);
2464 check_wnd_state(button, button, button, button);
2466 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2467 * match internal button state.
2469 SendMessage(button, WM_KILLFOCUS, 0, 0);
2470 check_wnd_state(button, button, button, 0);
2472 ShowWindow(hwnd, SW_SHOW);
2473 check_wnd_state(hwnd, hwnd, hwnd, 0);
2475 capture = SetCapture(hwnd);
2476 ok(capture == 0, "SetCapture() = %p\n", capture);
2478 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2480 DestroyWindow(hwnd);
2482 check_wnd_state(button, 0, button, 0);
2488 static void test_capture_1(void)
2490 HWND button, capture, oldFocus, oldActive;
2492 oldFocus = GetFocus();
2493 oldActive = GetActiveWindow();
2495 capture = GetCapture();
2496 ok(capture == 0, "GetCapture() = %p\n", capture);
2498 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2500 trace("button %p\n", button);
2502 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2504 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2506 capture = SetCapture(button);
2507 ok(capture == 0, "SetCapture() = %p\n", capture);
2508 check_wnd_state(button, 0, button, button);
2510 DestroyWindow(button);
2511 check_wnd_state(oldActive, 0, oldFocus, 0);
2514 static void test_capture_2(void)
2516 HWND button, hwnd, capture, oldFocus, oldActive;
2518 oldFocus = GetFocus();
2519 oldActive = GetActiveWindow();
2520 check_wnd_state(oldActive, 0, oldFocus, 0);
2522 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2524 trace("button %p\n", button);
2526 check_wnd_state(button, button, button, 0);
2528 capture = SetCapture(button);
2529 ok(capture == 0, "SetCapture() = %p\n", capture);
2531 check_wnd_state(button, button, button, button);
2533 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2534 * internal button state.
2536 SendMessage(button, WM_KILLFOCUS, 0, 0);
2537 check_wnd_state(button, button, button, button);
2539 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2541 trace("hwnd %p\n", hwnd);
2543 check_wnd_state(button, button, button, button);
2545 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2547 check_wnd_state(button, button, button, button);
2549 DestroyWindow(hwnd);
2551 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2553 trace("hwnd %p\n", hwnd);
2555 check_wnd_state(button, button, button, button);
2557 ShowWindow(hwnd, SW_SHOW);
2559 check_wnd_state(hwnd, hwnd, hwnd, button);
2561 capture = SetCapture(hwnd);
2562 ok(capture == button, "SetCapture() = %p\n", capture);
2564 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2566 DestroyWindow(hwnd);
2567 check_wnd_state(button, button, button, 0);
2569 DestroyWindow(button);
2570 check_wnd_state(oldActive, 0, oldFocus, 0);
2573 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2577 ShowWindow(hwnd1, SW_HIDE);
2578 ShowWindow(hwnd2, SW_HIDE);
2580 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2581 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2584 check_wnd_state(0, 0, 0, hwnd1);
2587 check_wnd_state(0, 0, 0, hwnd2);
2589 ShowWindow(hwnd1, SW_SHOW);
2590 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2592 ret = ReleaseCapture();
2593 ok (ret, "releasecapture did not return TRUE.\n");
2594 ret = ReleaseCapture();
2595 ok (ret, "releasecapture did not return TRUE after second try.\n");
2598 static void test_keyboard_input(HWND hwnd)
2603 flush_events( TRUE );
2604 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
2606 flush_events( TRUE );
2608 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2611 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2613 flush_events( TRUE );
2615 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2616 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2617 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2618 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2619 ok( !ret, "message %04x available\n", msg.message);
2621 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2623 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2624 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2625 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2626 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2627 ok( !ret, "message %04x available\n", msg.message);
2629 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2631 keybd_event(VK_SPACE, 0, 0, 0);
2632 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2633 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2634 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2635 ok( !ret, "message %04x available\n", msg.message);
2638 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2640 flush_events( TRUE );
2642 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2643 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2644 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2645 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2646 ok( !ret, "message %04x available\n", msg.message);
2648 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2650 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2651 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2652 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2653 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2654 ok( !ret, "message %04x available\n", msg.message);
2656 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2658 keybd_event(VK_SPACE, 0, 0, 0);
2659 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2660 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2661 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2662 ok( !ret, "message %04x available\n", msg.message);
2665 static void test_mouse_input(HWND hwnd)
2675 ShowWindow(hwnd, SW_SHOW);
2678 GetWindowRect(hwnd, &rc);
2679 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2681 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2682 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2685 ShowWindow(popup, SW_SHOW);
2686 UpdateWindow(popup);
2688 GetWindowRect(popup, &rc);
2689 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2691 x = rc.left + (rc.right - rc.left) / 2;
2692 y = rc.top + (rc.bottom - rc.top) / 2;
2693 trace("setting cursor to (%d,%d)\n", x, y);
2697 ok(x == pt.x && y == pt.y, "wrong cursor pos (%d,%d), expected (%d,%d)\n", pt.x, pt.y, x, y);
2699 flush_events( TRUE );
2701 /* Check that setting the same position may generate WM_MOUSEMOVE */
2705 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2706 while (ret && msg.message >= 0xc000); /* skip registered messages */
2709 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
2710 msg.hwnd, msg.message);
2711 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
2712 x, y, msg.pt.x, msg.pt.y);
2715 /* force the system to update its internal queue mouse position,
2716 * otherwise it won't generate relative mouse movements below.
2718 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2719 flush_events( TRUE );
2722 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2723 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2724 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2726 if (msg.message >= 0xc000) continue; /* skip registered messages */
2727 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
2728 "hwnd %p message %04x\n", msg.hwnd, msg.message);
2730 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2731 ok( !ret, "message %04x available\n", msg.message);
2733 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2734 ShowWindow(popup, SW_HIDE);
2736 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2737 while (msg.message >= 0xc000); /* skip registered messages */
2738 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2739 flush_events( TRUE );
2741 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2742 ShowWindow(hwnd, SW_HIDE);
2744 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2745 while (ret && msg.message >= 0xc000); /* skip registered messages */
2746 ok( !ret, "message %04x available\n", msg.message);
2747 flush_events( TRUE );
2749 /* test mouse clicks */
2751 ShowWindow(hwnd, SW_SHOW);
2752 flush_events( TRUE );
2753 ShowWindow(popup, SW_SHOW);
2754 flush_events( TRUE );
2756 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2757 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2758 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2759 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2761 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2762 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2763 msg.hwnd, popup, msg.message);
2764 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2765 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2766 msg.hwnd, popup, msg.message);
2768 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2769 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2770 msg.hwnd, popup, msg.message);
2771 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2772 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2773 msg.hwnd, popup, msg.message);
2775 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2776 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
2777 msg.hwnd, popup, msg.message);
2778 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2779 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
2780 msg.hwnd, popup, msg.message);
2782 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2783 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2784 msg.hwnd, popup, msg.message);
2785 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2786 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2787 msg.hwnd, popup, msg.message);
2789 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2790 ok(!ret, "message %04x available\n", msg.message);
2792 ShowWindow(popup, SW_HIDE);
2793 flush_events( TRUE );
2795 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2796 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2797 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2798 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2800 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2801 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2802 msg.hwnd, hwnd, msg.message);
2803 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2804 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2805 msg.hwnd, hwnd, msg.message);
2807 test_lbuttondown_flag = TRUE;
2808 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
2809 test_lbuttondown_flag = FALSE;
2812 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2813 while (msg.message >= 0xc000); /* skip registered messages */
2814 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2815 msg.hwnd, popup, msg.message);
2816 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2817 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2818 msg.hwnd, popup, msg.message);
2819 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2821 /* Test WM_MOUSEACTIVATE */
2822 #define TEST_MOUSEACTIVATE(A,B) \
2823 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2824 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2826 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
2827 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
2828 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
2829 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
2830 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
2831 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
2832 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
2833 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
2834 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
2835 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
2836 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
2837 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
2838 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
2839 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
2840 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
2841 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
2842 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
2843 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
2844 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
2845 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
2846 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
2847 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
2848 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
2849 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
2851 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2852 flush_events( TRUE );
2854 DestroyWindow(popup);
2857 static void test_validatergn(HWND hwnd)
2863 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
2864 ShowWindow(hwnd, SW_SHOW);
2865 UpdateWindow( hwnd);
2866 /* test that ValidateRect validates children*/
2867 InvalidateRect( child, NULL, 1);
2868 GetWindowRect( child, &rc);
2869 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2870 ret = GetUpdateRect( child, &rc2, 0);
2871 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
2872 "Update rectangle is empty!\n");
2873 ValidateRect( hwnd, &rc);
2874 ret = GetUpdateRect( child, &rc2, 0);
2875 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2876 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2877 rc2.right, rc2.bottom);
2879 /* now test ValidateRgn */
2880 InvalidateRect( child, NULL, 1);
2881 GetWindowRect( child, &rc);
2882 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2883 rgn = CreateRectRgnIndirect( &rc);
2884 ValidateRgn( hwnd, rgn);
2885 ret = GetUpdateRect( child, &rc2, 0);
2886 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2887 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2888 rc2.right, rc2.bottom);
2891 DestroyWindow( child );
2894 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
2896 MoveWindow( hwnd, 0, 0, x, y, 0);
2897 GetWindowRect( hwnd, prc);
2898 trace("window rect is %d,%d - %d,%d\n",
2899 prc->left,prc->top,prc->right,prc->bottom);
2900 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
2901 trace("nccalc rect is %d,%d - %d,%d\n",
2902 prc->left,prc->top,prc->right,prc->bottom);
2905 static void test_nccalcscroll(HWND parent)
2908 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
2909 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
2910 HWND hwnd = CreateWindowExA(0, "static", NULL,
2911 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
2912 10, 10, 200, 200, parent, 0, 0, NULL);
2913 ShowWindow( parent, SW_SHOW);
2914 UpdateWindow( parent);
2916 /* test window too low for a horizontal scroll bar */
2917 nccalchelper( hwnd, 100, sbheight, &rc1);
2918 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
2919 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
2921 /* test window just high enough for a horizontal scroll bar */
2922 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
2923 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
2924 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2926 /* test window too narrow for a vertical scroll bar */
2927 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
2928 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
2929 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2931 /* test window just wide enough for a vertical scroll bar */
2932 nccalchelper( hwnd, sbwidth, 100, &rc1);
2933 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
2934 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
2936 /* same test, but with client edge: not enough width */
2937 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
2938 nccalchelper( hwnd, sbwidth, 100, &rc1);
2939 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
2940 "Width should be %d size is %d,%d - %d,%d\n",
2941 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
2943 DestroyWindow( hwnd);
2946 static void test_SetParent(void)
2949 HWND desktop = GetDesktopWindow();
2951 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
2952 HWND parent, child1, child2, child3, child4, sibling;
2954 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2955 100, 100, 200, 200, 0, 0, 0, NULL);
2956 assert(parent != 0);
2957 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2958 0, 0, 50, 50, parent, 0, 0, NULL);
2959 assert(child1 != 0);
2960 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2961 0, 0, 50, 50, child1, 0, 0, NULL);
2962 assert(child2 != 0);
2963 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2964 0, 0, 50, 50, child2, 0, 0, NULL);
2965 assert(child3 != 0);
2966 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2967 0, 0, 50, 50, child3, 0, 0, NULL);
2968 assert(child4 != 0);
2970 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2971 parent, child1, child2, child3, child4);
2973 check_parents(parent, desktop, 0, 0, 0, parent, parent);
2974 check_parents(child1, parent, parent, parent, 0, parent, parent);
2975 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2976 check_parents(child3, child2, child2, child2, 0, child2, parent);
2977 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2979 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
2980 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
2981 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2982 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
2983 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2985 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
2986 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2987 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
2988 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
2989 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
2990 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
2991 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
2992 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
2993 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2995 if (!is_win9x) /* Win9x doesn't survive this test */
2997 ok(!SetParent(parent, child1), "SetParent should fail\n");
2998 ok(!SetParent(child2, child3), "SetParent should fail\n");
2999 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
3000 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
3001 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
3002 ok(!SetParent(child2, parent), "SetParent should fail\n");
3003 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
3005 check_parents(parent, child4, child4, 0, 0, child4, parent);
3006 check_parents(child1, parent, parent, parent, 0, child4, parent);
3007 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3008 check_parents(child3, child2, child2, child2, 0, child2, parent);
3009 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3012 hMenu = CreateMenu();
3013 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3014 100, 100, 200, 200, 0, hMenu, 0, NULL);
3015 assert(sibling != 0);
3017 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
3018 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
3020 ret = DestroyWindow(parent);
3021 ok( ret, "DestroyWindow() error %d\n", GetLastError());
3023 ok(!IsWindow(parent), "parent still exists\n");
3024 ok(!IsWindow(sibling), "sibling still exists\n");
3025 ok(!IsWindow(child1), "child1 still exists\n");
3026 ok(!IsWindow(child2), "child2 still exists\n");
3027 ok(!IsWindow(child3), "child3 still exists\n");
3028 ok(!IsWindow(child4), "child4 still exists\n");
3031 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3033 LPCREATESTRUCT lpcs;
3040 lpcs = (LPCREATESTRUCT)lparam;
3041 lpss = (LPSTYLESTRUCT)lpcs->lpCreateParams;
3044 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
3045 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
3046 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
3047 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
3049 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3051 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
3052 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
3053 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
3055 ok(lpss->styleNew == lpcs->style,
3056 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3057 lpss->styleNew, lpcs->style);
3061 return DefWindowProc(hwnd, msg, wparam, lparam);
3064 static ATOM atomStyleCheckClass;
3066 static void register_style_check_class(void)
3074 GetModuleHandle(NULL),
3076 LoadCursor(NULL, IDC_ARROW),
3077 (HBRUSH)(COLOR_BTNFACE+1),
3079 TEXT("WineStyleCheck"),
3082 atomStyleCheckClass = RegisterClass(&wc);
3085 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3087 DWORD dwActualStyle;
3088 DWORD dwActualExStyle;
3091 HWND hwndParent = NULL;
3093 ss.styleNew = dwStyleIn;
3094 ss.styleOld = dwExStyleIn;
3096 if (dwStyleIn & WS_CHILD)
3098 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
3099 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3102 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
3103 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3106 flush_events( TRUE );
3108 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3109 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3110 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3111 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3112 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3114 DestroyWindow(hwnd);
3115 if (hwndParent) DestroyWindow(hwndParent);
3118 /* tests what window styles the window manager automatically adds */
3119 static void test_window_styles(void)
3121 register_style_check_class();
3123 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3124 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3125 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3126 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3127 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3128 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3129 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3130 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3131 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3132 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3133 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3136 static void test_scrollvalidate( HWND parent)
3139 HRGN hrgn=CreateRectRgn(0,0,0,0);
3140 HRGN exprgn, tmprgn, clipping;
3141 RECT rc, rcu, cliprc;
3142 /* create two overlapping child windows. The visual region
3143 * of hwnd1 is clipped by the overlapping part of
3144 * hwnd2 because of the WS_CLIPSIBLING style */
3147 clipping = CreateRectRgn(0,0,0,0);
3148 tmprgn = CreateRectRgn(0,0,0,0);
3149 exprgn = CreateRectRgn(0,0,0,0);
3150 hwnd2 = CreateWindowExA(0, "static", NULL,
3151 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3152 75, 30, 100, 100, parent, 0, 0, NULL);
3153 hwnd1 = CreateWindowExA(0, "static", NULL,
3154 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3155 25, 50, 100, 100, parent, 0, 0, NULL);
3156 ShowWindow( parent, SW_SHOW);
3157 UpdateWindow( parent);
3158 GetClientRect( hwnd1, &rc);
3160 SetRectRgn( clipping, 10, 10, 90, 90);
3161 hdc = GetDC( hwnd1);
3162 /* for a visual touch */
3163 TextOut( hdc, 0,10, "0123456789", 10);
3164 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3165 if (winetest_debug > 0) dump_region(hrgn);
3166 /* create a region with what is expected */
3167 SetRectRgn( exprgn, 39,0,49,74);
3168 SetRectRgn( tmprgn, 88,79,98,93);
3169 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3170 SetRectRgn( tmprgn, 0,93,98,98);
3171 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3172 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3173 trace("update rect is %d,%d - %d,%d\n",
3174 rcu.left,rcu.top,rcu.right,rcu.bottom);
3175 /* now with clipping region */
3176 SelectClipRgn( hdc, clipping);
3177 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3178 if (winetest_debug > 0) dump_region(hrgn);
3179 /* create a region with what is expected */
3180 SetRectRgn( exprgn, 39,10,49,74);
3181 SetRectRgn( tmprgn, 80,79,90,85);
3182 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3183 SetRectRgn( tmprgn, 10,85,90,90);
3184 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3185 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3186 trace("update rect is %d,%d - %d,%d\n",
3187 rcu.left,rcu.top,rcu.right,rcu.bottom);
3188 ReleaseDC( hwnd1, hdc);
3190 /* test scrolling a window with an update region */
3191 DestroyWindow( hwnd2);
3192 ValidateRect( hwnd1, NULL);
3193 SetRect( &rc, 40,40, 50,50);
3194 InvalidateRect( hwnd1, &rc, 1);
3195 GetClientRect( hwnd1, &rc);
3197 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
3198 SW_SCROLLCHILDREN | SW_INVALIDATE);
3199 if (winetest_debug > 0) dump_region(hrgn);
3200 SetRectRgn( exprgn, 88,0,98,98);
3201 SetRectRgn( tmprgn, 30, 40, 50, 50);
3202 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3203 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3205 /* clear an update region */
3206 UpdateWindow( hwnd1 );
3208 SetRect( &rc, 0,40, 100,60);
3209 SetRect( &cliprc, 0,0, 100,100);
3210 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3211 if (winetest_debug > 0) dump_region( hrgn );
3212 SetRectRgn( exprgn, 0, 40, 98, 60 );
3213 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
3215 /* now test ScrollWindowEx with a combination of
3216 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3217 /* make hwnd2 the child of hwnd1 */
3218 hwnd2 = CreateWindowExA(0, "static", NULL,
3219 WS_CHILD| WS_VISIBLE | WS_BORDER ,
3220 50, 50, 100, 100, hwnd1, 0, 0, NULL);
3221 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
3222 GetClientRect( hwnd1, &rc);
3225 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3226 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3227 ValidateRect( hwnd1, NULL);
3228 ValidateRect( hwnd2, NULL);
3229 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
3230 SW_SCROLLCHILDREN | SW_INVALIDATE);
3231 if (winetest_debug > 0) dump_region(hrgn);
3232 SetRectRgn( exprgn, 88,0,98,88);
3233 SetRectRgn( tmprgn, 0,88,98,98);
3234 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3235 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3237 /* SW_SCROLLCHILDREN */
3238 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3239 ValidateRect( hwnd1, NULL);
3240 ValidateRect( hwnd2, NULL);
3241 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3242 if (winetest_debug > 0) dump_region(hrgn);
3243 /* expected region is the same as in previous test */
3244 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3246 /* no SW_SCROLLCHILDREN */
3247 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3248 ValidateRect( hwnd1, NULL);
3249 ValidateRect( hwnd2, NULL);
3250 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3251 if (winetest_debug > 0) dump_region(hrgn);
3252 /* expected region is the same as in previous test */
3253 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3255 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3256 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3257 ValidateRect( hwnd1, NULL);
3258 ValidateRect( hwnd2, NULL);
3259 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3260 if (winetest_debug > 0) dump_region(hrgn);
3261 SetRectRgn( exprgn, 88,0,98,20);
3262 SetRectRgn( tmprgn, 20,20,98,30);
3263 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3264 SetRectRgn( tmprgn, 20,30,30,88);
3265 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3266 SetRectRgn( tmprgn, 0,88,30,98);
3267 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3268 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3271 DeleteObject( hrgn);
3272 DeleteObject( exprgn);
3273 DeleteObject( tmprgn);
3274 DestroyWindow( hwnd1);
3275 DestroyWindow( hwnd2);
3278 /* couple of tests of return values of scrollbar functions
3279 * called on a scrollbarless window */
3280 static void test_scroll(void)
3285 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3286 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3287 100, 100, 200, 200, 0, 0, 0, NULL);
3289 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3290 if (!ret) /* win9x */
3292 win_skip( "GetScrollRange doesn't work\n" );
3293 DestroyWindow( hwnd);
3296 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3297 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3298 si.cbSize = sizeof( si);
3299 si.fMask = SIF_PAGE;
3300 si.nPage = 0xdeadbeef;
3301 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3302 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3303 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3305 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3306 ok( ret, "GetScrollRange returns FALSE\n");
3307 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3308 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3309 si.cbSize = sizeof( si);
3310 si.fMask = SIF_PAGE;
3311 si.nPage = 0xdeadbeef;
3312 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3313 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3314 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3316 DestroyWindow( hwnd);
3319 static void test_scrolldc( HWND parent)
3322 HRGN exprgn, tmprgn, hrgn;
3323 RECT rc, rc2, rcu, cliprc;
3327 hrgn = CreateRectRgn(0,0,0,0);
3328 tmprgn = CreateRectRgn(0,0,0,0);
3329 exprgn = CreateRectRgn(0,0,0,0);
3331 hwnd1 = CreateWindowExA(0, "static", NULL,
3332 WS_CHILD| WS_VISIBLE,
3333 25, 50, 100, 100, parent, 0, 0, NULL);
3334 ShowWindow( parent, SW_SHOW);
3335 UpdateWindow( parent);
3336 flush_events( TRUE );
3337 GetClientRect( hwnd1, &rc);
3338 hdc = GetDC( hwnd1);
3339 /* paint the upper half of the window black */
3341 rc2.bottom = ( rc.top + rc.bottom) /2;
3342 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3343 /* clip region is the lower half */
3345 cliprc.top = (rc.top + rc.bottom) /2;
3346 /* test whether scrolled pixels are properly clipped */
3347 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3348 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3349 /* this scroll should not cause any visible changes */
3350 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3351 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3352 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3353 /* test with NULL clip rect */
3354 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3355 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3356 trace("update rect: %d,%d - %d,%d\n",
3357 rcu.left, rcu.top, rcu.right, rcu.bottom);
3358 if (winetest_debug > 0) dump_region(hrgn);
3359 SetRect(&rc2, 0, 0, 100, 100);
3360 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3361 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3363 SetRectRgn( exprgn, 0, 0, 20, 80);
3364 SetRectRgn( tmprgn, 0, 80, 100, 100);
3365 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3366 if (winetest_debug > 0) dump_region(exprgn);
3367 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3368 /* test clip rect > scroll rect */
3369 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3371 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3372 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3373 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3374 SetRectRgn( exprgn, 25, 25, 75, 35);
3375 SetRectRgn( tmprgn, 25, 35, 35, 75);
3376 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3377 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3378 colr = GetPixel( hdc, 80, 80);
3379 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3380 trace("update rect: %d,%d - %d,%d\n",
3381 rcu.left, rcu.top, rcu.right, rcu.bottom);
3382 if (winetest_debug > 0) dump_region(hrgn);
3386 DeleteObject(exprgn);
3387 DeleteObject(tmprgn);
3388 DestroyWindow(hwnd1);
3391 static void test_params(void)
3396 /* Just a param check */
3397 if (pGetMonitorInfoA)
3399 SetLastError(0xdeadbeef);
3400 rc = GetWindowText(hwndMain2, NULL, 1024);
3401 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
3405 /* Skips actually on Win95 and NT4 */
3406 win_skip("Test would crash on Win95\n");
3409 SetLastError(0xdeadbeef);
3410 hwnd=CreateWindow("LISTBOX", "TestList",
3411 (LBS_STANDARD & ~LBS_SORT),
3413 NULL, (HMENU)1, NULL, 0);
3415 ok(!hwnd, "CreateWindow with invalid menu handle should fail\n");
3416 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3417 GetLastError() == 0xdeadbeef, /* Win9x */
3418 "wrong last error value %d\n", GetLastError());
3421 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3425 hwnd = CreateWindowEx(exStyle, class, class, style,
3432 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
3435 ShowWindow(hwnd, SW_SHOW);
3437 test_nonclient_area(hwnd);
3440 DestroyWindow(hwnd);
3443 static BOOL AWR_init(void)
3447 class.style = CS_HREDRAW | CS_VREDRAW;
3448 class.lpfnWndProc = DefWindowProcA;
3449 class.cbClsExtra = 0;
3450 class.cbWndExtra = 0;
3451 class.hInstance = 0;
3452 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3453 class.hCursor = LoadCursor (0, IDC_ARROW);
3454 class.hbrBackground = 0;
3455 class.lpszMenuName = 0;
3456 class.lpszClassName = szAWRClass;
3458 if (!RegisterClass (&class)) {
3459 ok(FALSE, "RegisterClass failed\n");
3463 hmenu = CreateMenu();
3466 ok(hmenu != 0, "Failed to create menu\n");
3467 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3473 static void test_AWR_window_size(BOOL menu)
3477 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3480 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3481 WS_HSCROLL, WS_VSCROLL
3485 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3488 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3489 WS_EX_DLGMODALFRAME,
3496 /* A exhaustive check of all the styles takes too long
3497 * so just do a (hopefully representative) sample
3499 for (i = 0; i < COUNTOF(styles); ++i)
3500 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3501 for (i = 0; i < COUNTOF(exStyles); ++i) {
3502 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3503 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3508 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3510 static void test_AdjustWindowRect(void)
3515 SHOWSYSMETRIC(SM_CYCAPTION);
3516 SHOWSYSMETRIC(SM_CYSMCAPTION);
3517 SHOWSYSMETRIC(SM_CYMENU);
3518 SHOWSYSMETRIC(SM_CXEDGE);
3519 SHOWSYSMETRIC(SM_CYEDGE);
3520 SHOWSYSMETRIC(SM_CXVSCROLL);
3521 SHOWSYSMETRIC(SM_CYHSCROLL);
3522 SHOWSYSMETRIC(SM_CXFRAME);
3523 SHOWSYSMETRIC(SM_CYFRAME);
3524 SHOWSYSMETRIC(SM_CXDLGFRAME);
3525 SHOWSYSMETRIC(SM_CYDLGFRAME);
3526 SHOWSYSMETRIC(SM_CXBORDER);
3527 SHOWSYSMETRIC(SM_CYBORDER);
3529 test_AWR_window_size(FALSE);
3530 test_AWR_window_size(TRUE);
3534 #undef SHOWSYSMETRIC
3537 /* Global variables to trigger exit from loop */
3538 static int redrawComplete, WMPAINT_count;
3540 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3545 trace("doing WM_PAINT %d\n", WMPAINT_count);
3547 if (WMPAINT_count > 10 && redrawComplete == 0) {
3549 BeginPaint(hwnd, &ps);
3550 EndPaint(hwnd, &ps);
3555 return DefWindowProc(hwnd, msg, wparam, lparam);
3558 /* Ensure we exit from RedrawNow regardless of invalidated area */
3559 static void test_redrawnow(void)
3564 cls.style = CS_DBLCLKS;
3565 cls.lpfnWndProc = redraw_window_procA;
3568 cls.hInstance = GetModuleHandleA(0);
3570 cls.hCursor = LoadCursorA(0, IDC_ARROW);
3571 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3572 cls.lpszMenuName = NULL;
3573 cls.lpszClassName = "RedrawWindowClass";
3575 if(!RegisterClassA(&cls)) {
3576 trace("Register failed %d\n", GetLastError());
3580 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3581 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3583 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3584 ShowWindow(hwndMain, SW_SHOW);
3585 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3586 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3587 ok( WMPAINT_count == 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3588 redrawComplete = TRUE;
3589 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3592 DestroyWindow( hwndMain);
3595 struct parentdc_stat {
3601 struct parentdc_test {
3602 struct parentdc_stat main, main_todo;
3603 struct parentdc_stat child1, child1_todo;
3604 struct parentdc_stat child2, child2_todo;
3607 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3612 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3617 trace("doing WM_PAINT on %p\n", hwnd);
3618 GetClientRect(hwnd, &rc);
3619 CopyRect(&t->client, &rc);
3620 trace("client rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3621 GetWindowRect(hwnd, &rc);
3622 trace("window rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3623 BeginPaint(hwnd, &ps);
3624 CopyRect(&t->paint, &ps.rcPaint);
3625 GetClipBox(ps.hdc, &rc);
3626 CopyRect(&t->clip, &rc);
3627 trace("clip rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3628 trace("paint rect (%d, %d)-(%d, %d)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3629 EndPaint(hwnd, &ps);
3632 return DefWindowProc(hwnd, msg, wparam, lparam);
3635 static void zero_parentdc_stat(struct parentdc_stat *t)
3637 SetRectEmpty(&t->client);
3638 SetRectEmpty(&t->clip);
3639 SetRectEmpty(&t->paint);
3642 static void zero_parentdc_test(struct parentdc_test *t)
3644 zero_parentdc_stat(&t->main);
3645 zero_parentdc_stat(&t->child1);
3646 zero_parentdc_stat(&t->child2);
3649 #define parentdc_field_ok(t, w, r, f, got) \
3650 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3651 ": expected %d, got %d\n", \
3654 #define parentdc_todo_field_ok(t, w, r, f, got) \
3655 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3656 else parentdc_field_ok(t, w, r, f, got)
3658 #define parentdc_rect_ok(t, w, r, got) \
3659 parentdc_todo_field_ok(t, w, r, left, got); \
3660 parentdc_todo_field_ok(t, w, r, top, got); \
3661 parentdc_todo_field_ok(t, w, r, right, got); \
3662 parentdc_todo_field_ok(t, w, r, bottom, got);
3664 #define parentdc_win_ok(t, w, got) \
3665 parentdc_rect_ok(t, w, client, got); \
3666 parentdc_rect_ok(t, w, clip, got); \
3667 parentdc_rect_ok(t, w, paint, got);
3669 #define parentdc_ok(t, got) \
3670 parentdc_win_ok(t, main, got); \
3671 parentdc_win_ok(t, child1, got); \
3672 parentdc_win_ok(t, child2, got);
3674 static void test_csparentdc(void)
3676 WNDCLASSA clsMain, cls;
3677 HWND hwndMain, hwnd1, hwnd2;
3680 struct parentdc_test test_answer;
3682 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3683 const struct parentdc_test test1 =
3685 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
3686 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3687 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3690 const struct parentdc_test test2 =
3692 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
3693 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3694 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3697 const struct parentdc_test test3 =
3699 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3700 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3701 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3704 const struct parentdc_test test4 =
3706 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
3707 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
3708 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3711 const struct parentdc_test test5 =
3713 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
3714 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3715 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3718 const struct parentdc_test test6 =
3720 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3721 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3722 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3725 const struct parentdc_test test7 =
3727 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3728 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3729 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3733 clsMain.style = CS_DBLCLKS;
3734 clsMain.lpfnWndProc = parentdc_window_procA;
3735 clsMain.cbClsExtra = 0;
3736 clsMain.cbWndExtra = 0;
3737 clsMain.hInstance = GetModuleHandleA(0);
3739 clsMain.hCursor = LoadCursorA(0, IDC_ARROW);
3740 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
3741 clsMain.lpszMenuName = NULL;
3742 clsMain.lpszClassName = "ParentDcMainWindowClass";
3744 if(!RegisterClassA(&clsMain)) {
3745 trace("Register failed %d\n", GetLastError());
3749 cls.style = CS_DBLCLKS | CS_PARENTDC;
3750 cls.lpfnWndProc = parentdc_window_procA;
3753 cls.hInstance = GetModuleHandleA(0);
3755 cls.hCursor = LoadCursorA(0, IDC_ARROW);
3756 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3757 cls.lpszMenuName = NULL;
3758 cls.lpszClassName = "ParentDcWindowClass";
3760 if(!RegisterClassA(&cls)) {
3761 trace("Register failed %d\n", GetLastError());
3765 SetRect(&rc, 0, 0, 150, 150);
3766 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
3767 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3768 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
3769 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
3770 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
3771 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
3772 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
3773 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
3774 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
3775 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
3776 ShowWindow(hwndMain, SW_SHOW);
3777 ShowWindow(hwnd1, SW_SHOW);
3778 ShowWindow(hwnd2, SW_SHOW);
3779 flush_events( TRUE );
3781 zero_parentdc_test(&test_answer);
3782 InvalidateRect(hwndMain, NULL, TRUE);
3783 flush_events( TRUE );
3784 parentdc_ok(test1, test_answer);
3786 zero_parentdc_test(&test_answer);
3787 SetRect(&rc, 0, 0, 50, 50);
3788 InvalidateRect(hwndMain, &rc, TRUE);
3789 flush_events( TRUE );
3790 parentdc_ok(test2, test_answer);
3792 zero_parentdc_test(&test_answer);
3793 SetRect(&rc, 0, 0, 10, 10);
3794 InvalidateRect(hwndMain, &rc, TRUE);
3795 flush_events( TRUE );
3796 parentdc_ok(test3, test_answer);
3798 zero_parentdc_test(&test_answer);
3799 SetRect(&rc, 40, 40, 50, 50);
3800 InvalidateRect(hwndMain, &rc, TRUE);
3801 flush_events( TRUE );
3802 parentdc_ok(test4, test_answer);
3804 zero_parentdc_test(&test_answer);
3805 SetRect(&rc, 20, 20, 60, 60);
3806 InvalidateRect(hwndMain, &rc, TRUE);
3807 flush_events( TRUE );
3808 parentdc_ok(test5, test_answer);
3810 zero_parentdc_test(&test_answer);
3811 SetRect(&rc, 0, 0, 10, 10);
3812 InvalidateRect(hwnd1, &rc, TRUE);
3813 flush_events( TRUE );
3814 parentdc_ok(test6, test_answer);
3816 zero_parentdc_test(&test_answer);
3817 SetRect(&rc, -5, -5, 65, 65);
3818 InvalidateRect(hwnd1, &rc, TRUE);
3819 flush_events( TRUE );
3820 parentdc_ok(test7, test_answer);
3822 DestroyWindow(hwndMain);
3823 DestroyWindow(hwnd1);
3824 DestroyWindow(hwnd2);
3827 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3829 return DefWindowProcA(hwnd, msg, wparam, lparam);
3832 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3834 return DefWindowProcW(hwnd, msg, wparam, lparam);
3837 static void test_IsWindowUnicode(void)
3839 static const char ansi_class_nameA[] = "ansi class name";
3840 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3841 static const char unicode_class_nameA[] = "unicode class name";
3842 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3847 memset(&classW, 0, sizeof(classW));
3848 classW.hInstance = GetModuleHandleA(0);
3849 classW.lpfnWndProc = def_window_procW;
3850 classW.lpszClassName = unicode_class_nameW;
3851 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
3853 memset(&classA, 0, sizeof(classA));
3854 classA.hInstance = GetModuleHandleA(0);
3855 classA.lpfnWndProc = def_window_procA;
3856 classA.lpszClassName = ansi_class_nameA;
3857 assert(RegisterClassA(&classA));
3859 /* unicode class: window proc */
3860 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3861 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3864 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3865 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3866 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3867 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3868 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3870 DestroyWindow(hwnd);
3872 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3873 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3876 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3877 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3878 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3879 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3880 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3882 DestroyWindow(hwnd);
3884 /* ansi class: window proc */
3885 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3886 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3889 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3890 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3891 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3892 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3893 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3895 DestroyWindow(hwnd);
3897 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3898 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3901 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3902 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3903 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3904 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3905 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3907 DestroyWindow(hwnd);
3909 /* unicode class: class proc */
3910 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3911 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3914 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3915 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3916 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3917 /* do not restore class window proc back to unicode */
3919 DestroyWindow(hwnd);
3921 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3922 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3925 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3926 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
3927 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3929 DestroyWindow(hwnd);
3931 /* ansi class: class 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 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
3938 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3939 /* do not restore class window proc back to ansi */
3941 DestroyWindow(hwnd);
3943 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3944 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3947 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3948 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3949 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3951 DestroyWindow(hwnd);
3954 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
3958 if (msg != WM_GETMINMAXINFO)
3959 return DefWindowProc(hwnd, msg, wp, lp);
3961 minmax = (MINMAXINFO *)lp;
3963 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
3965 minmax->ptReserved.x = 0;
3966 minmax->ptReserved.y = 0;
3967 minmax->ptMaxSize.x = 400;
3968 minmax->ptMaxSize.y = 400;
3969 minmax->ptMaxPosition.x = 300;
3970 minmax->ptMaxPosition.y = 300;
3971 minmax->ptMaxTrackSize.x = 200;
3972 minmax->ptMaxTrackSize.y = 200;
3973 minmax->ptMinTrackSize.x = 100;
3974 minmax->ptMinTrackSize.y = 100;
3977 DefWindowProc(hwnd, msg, wp, lp);
3981 static int expected_cx, expected_cy;
3982 static RECT expected_rect, broken_rect;
3984 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
3988 case WM_GETMINMAXINFO:
3991 GetWindowRect( hwnd, &rect );
3992 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
3993 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
3994 return DefWindowProc(hwnd, msg, wp, lp);
3999 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
4001 GetWindowRect( hwnd, &rect );
4002 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
4003 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
4004 ok( cs->cx == expected_cx || broken(cs->cx == (short)expected_cx),
4005 "wrong x size %d/%d\n", cs->cx, expected_cx );
4006 ok( cs->cy == expected_cy || broken(cs->cy == (short)expected_cy),
4007 "wrong y size %d/%d\n", cs->cy, expected_cy );
4008 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
4009 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
4010 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
4011 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top) ||
4012 broken( rect.right - rect.left == (short)broken_rect.right - (short)broken_rect.left &&
4013 rect.bottom - rect.top == (short)broken_rect.bottom - (short)broken_rect.top),
4014 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
4015 rect.left, rect.top, rect.right, rect.bottom,
4016 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
4017 return DefWindowProc(hwnd, msg, wp, lp);
4021 RECT rect, *r = (RECT *)lp;
4022 GetWindowRect( hwnd, &rect );
4023 ok( !memcmp( &rect, r, sizeof(rect) ),
4024 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
4025 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
4026 return DefWindowProc(hwnd, msg, wp, lp);
4029 return DefWindowProc(hwnd, msg, wp, lp);
4033 static void test_CreateWindow(void)
4041 #define expect_menu(window, menu) \
4042 SetLastError(0xdeadbeef); \
4043 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
4045 #define expect_style(window, style)\
4046 ok((ULONG)GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
4048 #define expect_ex_style(window, ex_style)\
4049 ok((ULONG)GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
4051 #define expect_gle_broken_9x(gle)\
4052 ok(GetLastError() == gle ||\
4053 broken(GetLastError() == 0xdeadbeef),\
4054 "IsMenu set error %d\n", GetLastError())
4056 hmenu = CreateMenu();
4058 parent = GetDesktopWindow();
4059 assert(parent != 0);
4061 SetLastError(0xdeadbeef);
4062 ok(IsMenu(hmenu), "IsMenu error %d\n", GetLastError());
4065 SetLastError(0xdeadbeef);
4066 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
4067 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4068 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4069 expect_menu(hwnd, 1);
4070 expect_style(hwnd, WS_CHILD);
4071 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4072 DestroyWindow(hwnd);
4074 SetLastError(0xdeadbeef);
4075 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
4076 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4077 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4078 expect_menu(hwnd, 1);
4079 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4080 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4081 DestroyWindow(hwnd);
4083 SetLastError(0xdeadbeef);
4084 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
4085 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4086 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4087 expect_menu(hwnd, 1);
4088 expect_style(hwnd, WS_CHILD);
4089 expect_ex_style(hwnd, 0);
4090 DestroyWindow(hwnd);
4092 SetLastError(0xdeadbeef);
4093 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
4094 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4095 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4096 expect_menu(hwnd, 1);
4097 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4098 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4099 DestroyWindow(hwnd);
4102 SetLastError(0xdeadbeef);
4103 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4104 0, 0, 100, 100, parent, hmenu, 0, NULL);
4105 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4106 expect_menu(hwnd, hmenu);
4107 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4108 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4109 DestroyWindow(hwnd);
4110 SetLastError(0xdeadbeef);
4111 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4112 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4114 hmenu = CreateMenu();
4116 SetLastError(0xdeadbeef);
4117 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
4118 0, 0, 100, 100, parent, hmenu, 0, NULL);
4119 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4120 expect_menu(hwnd, hmenu);
4121 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4122 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4123 DestroyWindow(hwnd);
4124 SetLastError(0xdeadbeef);
4125 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4126 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4128 hmenu = CreateMenu();
4130 SetLastError(0xdeadbeef);
4131 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
4132 0, 0, 100, 100, parent, hmenu, 0, NULL);
4133 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4134 expect_menu(hwnd, hmenu);
4135 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4136 expect_ex_style(hwnd, 0);
4137 DestroyWindow(hwnd);
4138 SetLastError(0xdeadbeef);
4139 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4140 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4142 hmenu = CreateMenu();
4144 SetLastError(0xdeadbeef);
4145 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
4146 0, 0, 100, 100, parent, hmenu, 0, NULL);
4147 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4148 expect_menu(hwnd, hmenu);
4149 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4150 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4151 DestroyWindow(hwnd);
4152 SetLastError(0xdeadbeef);
4153 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4154 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4156 /* WS_CHILD | WS_POPUP */
4157 SetLastError(0xdeadbeef);
4158 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4159 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4160 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4161 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4163 DestroyWindow(hwnd);
4165 hmenu = CreateMenu();
4167 SetLastError(0xdeadbeef);
4168 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4169 0, 0, 100, 100, parent, hmenu, 0, NULL);
4170 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4171 expect_menu(hwnd, hmenu);
4172 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4173 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4174 DestroyWindow(hwnd);
4175 SetLastError(0xdeadbeef);
4176 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4177 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4179 SetLastError(0xdeadbeef);
4180 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4181 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4182 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4183 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4185 DestroyWindow(hwnd);
4187 hmenu = CreateMenu();
4189 SetLastError(0xdeadbeef);
4190 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4191 0, 0, 100, 100, parent, hmenu, 0, NULL);
4192 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4193 expect_menu(hwnd, hmenu);
4194 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4195 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4196 DestroyWindow(hwnd);
4197 SetLastError(0xdeadbeef);
4198 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4199 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4201 SetLastError(0xdeadbeef);
4202 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4203 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4204 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4205 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4207 DestroyWindow(hwnd);
4209 hmenu = CreateMenu();
4211 SetLastError(0xdeadbeef);
4212 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4213 0, 0, 100, 100, parent, hmenu, 0, NULL);
4214 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4215 expect_menu(hwnd, hmenu);
4216 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4217 expect_ex_style(hwnd, 0);
4218 DestroyWindow(hwnd);
4219 SetLastError(0xdeadbeef);
4220 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4221 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4223 SetLastError(0xdeadbeef);
4224 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4225 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4226 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4227 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4229 DestroyWindow(hwnd);
4231 hmenu = CreateMenu();
4233 SetLastError(0xdeadbeef);
4234 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4235 0, 0, 100, 100, parent, hmenu, 0, NULL);
4236 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4237 expect_menu(hwnd, hmenu);
4238 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4239 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4240 DestroyWindow(hwnd);
4241 SetLastError(0xdeadbeef);
4242 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4243 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4245 /* test child window sizing */
4247 cls.lpfnWndProc = minmax_wnd_proc;
4250 cls.hInstance = GetModuleHandle(0);
4252 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4253 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4254 cls.lpszMenuName = NULL;
4255 cls.lpszClassName = "MinMax_WndClass";
4256 RegisterClass(&cls);
4258 SetLastError(0xdeadbeef);
4259 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4260 0, 0, 100, 100, 0, 0, 0, NULL);
4261 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4262 expect_menu(parent, 0);
4263 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
4264 expect_ex_style(parent, WS_EX_WINDOWEDGE);
4266 memset(&minmax, 0, sizeof(minmax));
4267 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4268 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
4269 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
4270 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4271 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
4273 GetWindowRect(parent, &rc);
4274 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
4275 GetClientRect(parent, &rc);
4276 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
4278 InflateRect(&rc, 200, 200);
4279 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4281 SetLastError(0xdeadbeef);
4282 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4283 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
4284 parent, (HMENU)1, 0, NULL);
4285 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4286 expect_menu(hwnd, 1);
4287 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
4288 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4290 memset(&minmax, 0, sizeof(minmax));
4291 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4292 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4294 GetWindowRect(hwnd, &rc);
4295 OffsetRect(&rc, -rc.left, -rc.top);
4296 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4297 rc.left, rc.top, rc.right, rc.bottom,
4298 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
4299 DestroyWindow(hwnd);
4301 cls.lpfnWndProc = winsizes_wnd_proc;
4302 cls.lpszClassName = "Sizes_WndClass";
4303 RegisterClass(&cls);
4305 expected_cx = expected_cy = 200000;
4306 SetRect( &expected_rect, 0, 0, 200000, 200000 );
4307 broken_rect = expected_rect;
4308 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
4309 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4310 GetClientRect( hwnd, &rc );
4311 ok( rc.right == 200000 || broken(rc.right == (short)200000), "invalid rect right %u\n", rc.right );
4312 ok( rc.bottom == 200000 || broken(rc.bottom == (short)200000), "invalid rect bottom %u\n", rc.bottom );
4313 DestroyWindow(hwnd);
4315 expected_cx = expected_cy = -10;
4316 SetRect( &expected_rect, 0, 0, 0, 0 );
4317 SetRect( &broken_rect, 0, 0, -10, -10 );
4318 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
4319 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4320 GetClientRect( hwnd, &rc );
4321 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4322 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4323 DestroyWindow(hwnd);
4325 expected_cx = expected_cy = -200000;
4326 SetRect( &expected_rect, 0, 0, 0, 0 );
4327 SetRect( &broken_rect, 0, 0, -200000, -200000 );
4328 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
4329 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4330 GetClientRect( hwnd, &rc );
4331 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4332 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4333 DestroyWindow(hwnd);
4335 /* we need a parent at 0,0 so that child coordinates match */
4336 DestroyWindow(parent);
4337 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
4338 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4341 expected_cy = 0x7fffffff;
4342 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
4343 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
4344 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
4345 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4346 GetClientRect( hwnd, &rc );
4347 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
4348 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4349 DestroyWindow(hwnd);
4351 expected_cx = 0x7fffffff;
4352 expected_cy = 0x7fffffff;
4353 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
4354 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
4355 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
4356 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4357 GetClientRect( hwnd, &rc );
4358 ok( rc.right == 0x7fffffff - 20 || broken(rc.right == 0), "invalid rect right %u\n", rc.right );
4359 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4360 DestroyWindow(hwnd);
4362 /* top level window */
4363 expected_cx = expected_cy = 200000;
4364 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
4365 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
4366 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4367 GetClientRect( hwnd, &rc );
4368 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
4369 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
4370 DestroyWindow(hwnd);
4372 DestroyWindow(parent);
4374 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4375 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4377 #undef expect_gle_broken_9x
4380 #undef expect_ex_style
4383 /* function that remembers whether the system the test is running on sets the
4384 * last error for user32 functions to make the tests stricter */
4385 static int check_error(DWORD actual, DWORD expected)
4387 static int sets_last_error = -1;
4388 if (sets_last_error == -1)
4389 sets_last_error = (actual != 0xdeadbeef);
4390 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
4393 static void test_SetWindowLong(void)
4396 WNDPROC old_window_procW;
4398 SetLastError(0xdeadbeef);
4399 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
4400 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
4401 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
4402 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4404 SetLastError(0xdeadbeef);
4405 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
4406 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
4407 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
4408 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4410 SetLastError(0xdeadbeef);
4411 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4412 ok((WNDPROC)retval == main_window_procA || broken(!retval), /* win9x */
4413 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
4414 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4415 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
4416 ok((WNDPROC)retval == main_window_procA,
4417 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4418 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
4420 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
4421 SetLastError(0xdeadbeef);
4422 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
4423 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
4425 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4426 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
4427 ok((WNDPROC)retval == old_window_procW,
4428 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4429 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
4431 /* set it back to ANSI */
4432 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4436 static void test_ShowWindow(void)
4443 SetRect(&rcMain, 120, 120, 210, 210);
4445 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
4446 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4447 WS_MAXIMIZEBOX | WS_POPUP,
4448 rcMain.left, rcMain.top,
4449 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
4453 style = GetWindowLong(hwnd, GWL_STYLE);
4454 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4455 ok(!(style & WS_VISIBLE), "window should not be visible\n");
4456 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4457 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4458 GetWindowRect(hwnd, &rc);
4459 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4460 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4461 rc.left, rc.top, rc.right, rc.bottom);
4463 ret = ShowWindow(hwnd, SW_SHOW);
4464 ok(!ret, "not expected ret: %lu\n", ret);
4465 style = GetWindowLong(hwnd, GWL_STYLE);
4466 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4467 ok(style & WS_VISIBLE, "window should be visible\n");
4468 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4469 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4470 GetWindowRect(hwnd, &rc);
4471 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4472 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4473 rc.left, rc.top, rc.right, rc.bottom);
4475 ret = ShowWindow(hwnd, SW_MINIMIZE);
4476 ok(ret, "not expected ret: %lu\n", ret);
4477 style = GetWindowLong(hwnd, GWL_STYLE);
4478 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4479 ok(style & WS_VISIBLE, "window should be visible\n");
4480 ok(style & WS_MINIMIZE, "window should be minimized\n");
4481 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4482 GetWindowRect(hwnd, &rc);
4483 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4485 ShowWindow(hwnd, SW_RESTORE);
4486 ok(ret, "not expected ret: %lu\n", ret);
4487 style = GetWindowLong(hwnd, GWL_STYLE);
4488 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4489 ok(style & WS_VISIBLE, "window should be visible\n");
4490 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4491 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4492 GetWindowRect(hwnd, &rc);
4493 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4494 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4495 rc.left, rc.top, rc.right, rc.bottom);
4497 ret = EnableWindow(hwnd, FALSE);
4498 ok(!ret, "not expected ret: %lu\n", ret);
4499 style = GetWindowLong(hwnd, GWL_STYLE);
4500 ok(style & WS_DISABLED, "window should be disabled\n");
4502 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
4503 ok(!ret, "not expected ret: %lu\n", ret);
4504 style = GetWindowLong(hwnd, GWL_STYLE);
4505 ok(style & WS_DISABLED, "window should be disabled\n");
4506 ok(style & WS_VISIBLE, "window should be visible\n");
4507 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4508 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4509 GetWindowRect(hwnd, &rc);
4510 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4511 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4512 rc.left, rc.top, rc.right, rc.bottom);
4514 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
4515 ok(!ret, "not expected ret: %lu\n", ret);
4516 style = GetWindowLong(hwnd, GWL_STYLE);
4517 ok(style & WS_DISABLED, "window should be disabled\n");
4518 ok(style & WS_VISIBLE, "window should be visible\n");
4519 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4520 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4521 GetWindowRect(hwnd, &rc);
4522 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4523 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4524 rc.left, rc.top, rc.right, rc.bottom);
4526 ret = ShowWindow(hwnd, SW_MINIMIZE);
4527 ok(ret, "not expected ret: %lu\n", ret);
4528 style = GetWindowLong(hwnd, GWL_STYLE);
4529 ok(style & WS_DISABLED, "window should be disabled\n");
4530 ok(style & WS_VISIBLE, "window should be visible\n");
4531 ok(style & WS_MINIMIZE, "window should be minimized\n");
4532 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4533 GetWindowRect(hwnd, &rc);
4534 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4536 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
4537 ok(!ret, "not expected ret: %lu\n", ret);
4538 style = GetWindowLong(hwnd, GWL_STYLE);
4539 ok(style & WS_DISABLED, "window should be disabled\n");
4540 ok(style & WS_VISIBLE, "window should be visible\n");
4541 ok(style & WS_MINIMIZE, "window should be minimized\n");
4542 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4543 GetWindowRect(hwnd, &rc);
4544 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4546 ret = ShowWindow(hwnd, SW_RESTORE);
4547 ok(ret, "not expected ret: %lu\n", ret);
4548 style = GetWindowLong(hwnd, GWL_STYLE);
4549 ok(style & WS_DISABLED, "window should be disabled\n");
4550 ok(style & WS_VISIBLE, "window should be visible\n");
4551 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4552 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4553 GetWindowRect(hwnd, &rc);
4554 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4555 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4556 rc.left, rc.top, rc.right, rc.bottom);
4558 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4559 ok(!ret, "not expected ret: %lu\n", ret);
4560 ok(IsWindow(hwnd), "window should exist\n");
4562 ret = EnableWindow(hwnd, TRUE);
4563 ok(ret, "not expected ret: %lu\n", ret);
4565 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4566 ok(!ret, "not expected ret: %lu\n", ret);
4567 ok(!IsWindow(hwnd), "window should not exist\n");
4570 static void test_gettext(void)
4573 LPCSTR clsname = "gettexttest";
4577 memset( &cls, 0, sizeof cls );
4578 cls.lpfnWndProc = DefWindowProc;
4579 cls.lpszClassName = clsname;
4580 cls.hInstance = GetModuleHandle(NULL);
4582 if (!RegisterClass( &cls )) return;
4584 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
4585 ok( hwnd != NULL, "window was null\n");
4587 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
4588 ok( r == 0, "settext should return zero\n");
4590 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
4591 ok( r == 0, "settext should return zero (%ld)\n", r);
4593 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
4594 ok( r == 0, "settext should return zero (%ld)\n", r);
4596 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
4597 ok( r == 0, "settext should return zero (%ld)\n", r);
4599 DestroyWindow(hwnd);
4600 UnregisterClass( clsname, NULL );
4604 static void test_GetUpdateRect(void)
4607 BOOL ret, parent_wm_paint, grandparent_wm_paint;
4609 HWND hgrandparent, hparent, hchild;
4611 static const char classNameA[] = "GetUpdateRectClass";
4613 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
4614 0, 0, 100, 100, NULL, NULL, 0, NULL);
4616 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
4617 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4619 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
4620 10, 10, 30, 30, hparent, NULL, 0, NULL);
4622 ShowWindow(hgrandparent, SW_SHOW);
4623 UpdateWindow(hgrandparent);
4624 flush_events( TRUE );
4626 ShowWindow(hchild, SW_HIDE);
4627 SetRect(&rc2, 0, 0, 0, 0);
4628 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4629 ok(!ret, "GetUpdateRect returned not empty region\n");
4630 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4631 rc1.left, rc1.top, rc1.right, rc1.bottom,
4632 rc2.left, rc2.top, rc2.right, rc2.bottom);
4634 SetRect(&rc2, 10, 10, 40, 40);
4635 ret = GetUpdateRect(hparent, &rc1, FALSE);
4636 ok(ret, "GetUpdateRect returned empty region\n");
4637 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4638 rc1.left, rc1.top, rc1.right, rc1.bottom,
4639 rc2.left, rc2.top, rc2.right, rc2.bottom);
4641 parent_wm_paint = FALSE;
4642 grandparent_wm_paint = FALSE;
4643 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4645 if (msg.message == WM_PAINT)
4647 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4648 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4650 DispatchMessage(&msg);
4652 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4653 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4655 DestroyWindow(hgrandparent);
4658 cls.lpfnWndProc = DefWindowProcA;
4661 cls.hInstance = GetModuleHandleA(0);
4663 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4664 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4665 cls.lpszMenuName = NULL;
4666 cls.lpszClassName = classNameA;
4668 if(!RegisterClassA(&cls)) {
4669 trace("Register failed %d\n", GetLastError());
4673 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
4674 0, 0, 100, 100, NULL, NULL, 0, NULL);
4676 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
4677 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4679 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
4680 10, 10, 30, 30, hparent, NULL, 0, NULL);
4682 ShowWindow(hgrandparent, SW_SHOW);
4683 UpdateWindow(hgrandparent);
4684 flush_events( TRUE );
4686 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4687 ok(!ret, "GetUpdateRect returned not empty region\n");
4689 ShowWindow(hchild, SW_HIDE);
4691 SetRect(&rc2, 0, 0, 0, 0);
4692 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4693 ok(!ret, "GetUpdateRect returned not empty region\n");
4694 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4695 rc1.left, rc1.top, rc1.right, rc1.bottom,
4696 rc2.left, rc2.top, rc2.right, rc2.bottom);
4698 SetRect(&rc2, 10, 10, 40, 40);
4699 ret = GetUpdateRect(hparent, &rc1, FALSE);
4700 ok(ret, "GetUpdateRect returned empty region\n");
4701 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4702 rc1.left, rc1.top, rc1.right, rc1.bottom,
4703 rc2.left, rc2.top, rc2.right, rc2.bottom);
4705 parent_wm_paint = FALSE;
4706 grandparent_wm_paint = FALSE;
4707 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4709 if (msg.message == WM_PAINT)
4711 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4712 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4714 DispatchMessage(&msg);
4716 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4717 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4719 DestroyWindow(hgrandparent);
4723 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
4731 const int waitTime = 2000;
4733 BeginPaint(hwnd, &ps);
4735 /* create and destroy window to create an exposed region on this window */
4736 win = CreateWindowA("static", "win", WS_VISIBLE,
4737 10,10,50,50, NULL, NULL, 0, NULL);
4740 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
4742 ValidateRect(hwnd, NULL);
4743 EndPaint(hwnd, &ps);
4745 if(waitResult != WAIT_TIMEOUT)
4747 GetUpdateRect(hwnd, &updateRect, FALSE);
4748 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
4753 return DefWindowProc(hwnd, msg, wParam, lParam);
4756 static void test_Expose(void)
4761 memset(&cls, 0, sizeof(WNDCLASSA));
4762 cls.lpfnWndProc = TestExposedRegion_WndProc;
4763 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4764 cls.lpszClassName = "TestExposeClass";
4765 atom = RegisterClassA(&cls);
4767 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
4768 0, 0, 200, 100, NULL, NULL, 0, NULL);
4774 static void test_GetWindowModuleFileName(void)
4779 char buf1[MAX_PATH], buf2[MAX_PATH];
4781 if (!pGetWindowModuleFileNameA)
4783 skip("GetWindowModuleFileNameA is not available\n");
4787 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
4790 hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
4791 ok(hinst == 0 || broken(hinst == GetModuleHandle(0)), /* win9x */ "expected 0, got %p\n", hinst);
4794 SetLastError(0xdeadbeef);
4795 ret1 = GetModuleFileName(hinst, buf1, sizeof(buf1));
4796 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
4799 SetLastError(0xdeadbeef);
4800 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
4801 ok(ret2, "GetWindowModuleFileNameA error %u\n", GetLastError());
4803 ok(ret1 == ret2 || broken(ret2 == ret1 + 1), /* win98 */ "%u != %u\n", ret1, ret2);
4804 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
4806 hinst = GetModuleHandle(0);
4808 SetLastError(0xdeadbeef);
4809 ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
4810 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
4811 "expected %u, got %u\n", ret1 - 2, ret2);
4812 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4813 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4814 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4816 SetLastError(0xdeadbeef);
4817 ret2 = GetModuleFileName(hinst, buf2, 0);
4818 ok(!ret2, "GetModuleFileName should return 0\n");
4819 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4820 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4821 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4823 SetLastError(0xdeadbeef);
4824 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
4825 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
4826 "expected %u, got %u\n", ret1 - 2, ret2);
4827 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4828 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4829 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4831 SetLastError(0xdeadbeef);
4832 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
4833 ok(!ret2, "expected 0, got %u\n", ret2);
4834 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4835 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4836 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4838 DestroyWindow(hwnd);
4841 hwnd = (HWND)0xdeadbeef;
4842 SetLastError(0xdeadbeef);
4843 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4844 ok(!ret1, "expected 0, got %u\n", ret1);
4845 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef), /* win9x */
4846 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
4848 hwnd = FindWindow("Shell_TrayWnd", NULL);
4849 ok(IsWindow(hwnd), "got invalid tray window %p\n", hwnd);
4850 SetLastError(0xdeadbeef);
4851 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4852 ok(!ret1 || broken(ret1), /* win98 */ "expected 0, got %u\n", ret1);
4854 if (!ret1) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
4856 ret1 = GetModuleFileName(0, buf1, sizeof(buf1));
4857 hwnd = GetDesktopWindow();
4858 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
4859 SetLastError(0xdeadbeef);
4860 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
4861 ok(!ret2 || ret1 == ret2 /* vista */, "expected 0 or %u, got %u %s\n", ret1, ret2, buf2);
4865 static void test_hwnd_message(void)
4867 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
4868 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
4870 HWND parent = 0, hwnd, found;
4873 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
4874 on CreateWindowExA and crash later in the test.
4875 Use UNICODE here to fail on win9x */
4876 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
4877 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
4880 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
4884 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
4888 HWND root, desktop = GetDesktopWindow();
4890 parent = pGetAncestor(hwnd, GA_PARENT);
4891 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
4892 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
4893 root = pGetAncestor(hwnd, GA_ROOT);
4894 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
4895 ok( !pGetAncestor(parent, GA_PARENT), "parent shouldn't have parent %p\n",
4896 pGetAncestor(parent, GA_PARENT) );
4897 trace("parent %p root %p desktop %p\n", parent, root, desktop);
4898 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
4899 ok( !lstrcmpi( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
4900 GetWindowRect( parent, &rect );
4901 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
4902 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4904 GetWindowRect( hwnd, &rect );
4905 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
4906 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4908 /* test FindWindow behavior */
4910 found = FindWindowExA( 0, 0, 0, "message window" );
4911 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
4912 SetLastError(0xdeadbeef);
4913 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
4914 ok( found == 0, "found message window %p/%p\n", found, hwnd );
4915 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
4918 found = FindWindowExA( parent, 0, 0, "message window" );
4919 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
4922 /* test IsChild behavior */
4924 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
4926 /* test IsWindowVisible behavior */
4928 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
4929 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
4931 DestroyWindow(hwnd);
4934 static void test_layered_window(void)
4942 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes)
4944 win_skip( "layered windows not supported\n" );
4947 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
4948 100, 100, 200, 200, 0, 0, 0, NULL);
4950 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4951 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
4952 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
4953 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
4954 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
4955 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4956 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
4957 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
4958 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4959 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4960 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4961 ok( key == 0x123456 || key == 0, "wrong color key %x\n", key );
4962 ok( alpha == 44, "wrong alpha %u\n", alpha );
4963 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
4965 /* clearing WS_EX_LAYERED resets attributes */
4966 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
4967 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4968 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
4969 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
4970 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4971 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
4972 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
4973 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4974 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4975 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4976 ok( key == 0x654321, "wrong color key %x\n", key );
4977 ok( alpha == 22, "wrong alpha %u\n", alpha );
4978 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
4980 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
4981 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4983 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4984 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4985 ok( key == 0x888888, "wrong color key %x\n", key );
4986 /* alpha not changed on vista if LWA_ALPHA is not set */
4987 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
4988 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
4990 /* color key may or may not be changed without LWA_COLORKEY */
4991 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
4992 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4994 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4995 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4996 ok( key == 0x888888 || key == 0x999999, "wrong color key %x\n", key );
4997 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
4998 ok( flags == 0, "wrong flags %x\n", flags );
5000 /* default alpha and color key is 0 */
5001 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5002 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5003 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
5004 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5005 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5006 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5007 ok( key == 0 || key == 0x222222, "wrong color key %x\n", key );
5008 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
5009 ok( flags == 0, "wrong flags %x\n", flags );
5011 DestroyWindow( hwnd );
5014 static MONITORINFO mi;
5016 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
5022 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
5023 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs->x, cs->y, cs->cx, cs->cy);
5024 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
5025 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
5026 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
5027 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5028 cs->x, cs->y, cs->cx, cs->cy);
5031 case WM_GETMINMAXINFO:
5033 MINMAXINFO *minmax = (MINMAXINFO *)lp;
5034 dump_minmax_info(minmax);
5035 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
5036 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
5037 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
5038 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
5042 return DefWindowProc(hwnd, msg, wp, lp);
5045 static void test_fullscreen(void)
5047 static const DWORD t_style[] = {
5048 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
5050 static const DWORD t_ex_style[] = {
5051 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
5061 if (!pGetMonitorInfoA || !pMonitorFromPoint)
5063 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
5068 SetLastError(0xdeadbeef);
5069 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
5070 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
5072 mi.cbSize = sizeof(mi);
5073 SetLastError(0xdeadbeef);
5074 ret = pGetMonitorInfoA(hmon, &mi);
5075 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
5076 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
5077 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5078 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5081 cls.lpfnWndProc = fullscreen_wnd_proc;
5084 cls.hInstance = GetModuleHandle(0);
5086 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5087 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5088 cls.lpszMenuName = NULL;
5089 cls.lpszClassName = "fullscreen_class";
5090 RegisterClass(&cls);
5092 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
5094 DWORD style, ex_style;
5096 /* avoid a WM interaction */
5097 assert(!(t_style[i] & WS_VISIBLE));
5099 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
5104 ex_style = t_ex_style[j];
5106 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5107 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5108 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5109 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5110 GetWindowRect(hwnd, &rc);
5111 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5112 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5113 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5114 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5115 DestroyWindow(hwnd);
5117 style = t_style[i] | WS_MAXIMIZE;
5118 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5119 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5120 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5121 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5122 GetWindowRect(hwnd, &rc);
5123 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5124 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5125 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5126 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5127 DestroyWindow(hwnd);
5129 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
5130 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5131 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5132 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5133 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5134 GetWindowRect(hwnd, &rc);
5135 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5136 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5137 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5138 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5139 DestroyWindow(hwnd);
5141 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
5142 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5143 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5144 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5145 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5146 GetWindowRect(hwnd, &rc);
5147 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5148 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5149 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5150 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5151 DestroyWindow(hwnd);
5153 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
5154 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5155 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5156 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5157 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5158 GetWindowRect(hwnd, &rc);
5159 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5160 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5161 fixup = min(abs(rc.left), abs(rc.top));
5162 InflateRect(&rc, -fixup, -fixup);
5163 /* FIXME: this doesn't work correctly in Wine for child windows yet */
5164 if (style & WS_CHILD)
5166 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5167 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5168 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5170 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5171 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5172 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5173 DestroyWindow(hwnd);
5175 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
5176 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5177 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5178 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5179 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5180 GetWindowRect(hwnd, &rc);
5181 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5182 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5183 fixup = min(abs(rc.left), abs(rc.top));
5184 InflateRect(&rc, -fixup, -fixup);
5185 if (style & (WS_CHILD | WS_POPUP))
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);
5190 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5191 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5192 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5193 DestroyWindow(hwnd);
5197 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5200 static BOOL test_thick_child_got_minmax;
5202 static int getExpectedThickChildInc(void)
5204 const int outer = 2;
5205 int resizeBorder = GetSystemMetrics(SM_CXFRAME) - GetSystemMetrics(SM_CXDLGFRAME);
5206 return (outer + resizeBorder);
5209 static LRESULT WINAPI test_thick_child_size_winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5212 int expectedMinTrack;
5213 int actualMinTrackX;
5214 int actualMinTrackY;
5215 int expectedMaxTrackX;
5216 int expectedMaxTrackY;
5217 int actualMaxTrackX;
5218 int actualMaxTrackY;
5219 int expectedMaxSizeX;
5220 int expectedMaxSizeY;
5230 case WM_GETMINMAXINFO:
5232 minmax = (MINMAXINFO *)lparam;
5233 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
5234 dump_minmax_info( minmax );
5236 test_thick_child_got_minmax = TRUE;
5238 expectedMinTrack = 2* getExpectedThickChildInc();
5239 actualMinTrackX = minmax->ptMinTrackSize.x;
5240 actualMinTrackY = minmax->ptMinTrackSize.y;
5242 ok(actualMinTrackX == expectedMinTrack && actualMinTrackY == expectedMinTrack,
5243 "expected minTrack %dx%d, actual minTrack %dx%d\n",
5244 expectedMinTrack, expectedMinTrack, actualMinTrackX, actualMinTrackY);
5246 actualMaxTrackX = minmax->ptMaxTrackSize.x;
5247 actualMaxTrackY = minmax->ptMaxTrackSize.y;
5248 expectedMaxTrackX = GetSystemMetrics(SM_CXMAXTRACK);
5249 expectedMaxTrackY = GetSystemMetrics(SM_CYMAXTRACK);
5250 ok(actualMaxTrackX == expectedMaxTrackX && actualMaxTrackY == expectedMaxTrackY,
5251 "expected maxTrack %dx%d, actual maxTrack %dx%d\n",
5252 expectedMaxTrackX, expectedMaxTrackY, actualMaxTrackX, actualMaxTrackY);
5254 GetClientRect(GetParent(hwnd), &rect);
5255 AdjustWindowRectEx(&rect, WS_CHILD | WS_VISIBLE | WS_THICKFRAME, FALSE, 0);
5256 expectedMaxSizeX = rect.right - rect.left;
5257 expectedMaxSizeY = rect.bottom - rect.top;
5258 actualMaxSizeX = minmax->ptMaxSize.x;
5259 actualMaxSizeY = minmax->ptMaxSize.y;
5260 ok(actualMaxSizeX == expectedMaxSizeX && actualMaxSizeY == expectedMaxSizeY,
5261 "expected maxTrack %dx%d, actual maxTrack %dx%d\n",
5262 expectedMaxSizeX, expectedMaxSizeY, actualMaxSizeX, actualMaxSizeY);
5264 expectedPosX = - getExpectedThickChildInc();
5265 expectedPosY = expectedPosX;
5266 actualPosX = minmax->ptMaxPosition.x;
5267 actualPosY = minmax->ptMaxPosition.y;
5269 ok(actualPosX == expectedPosX && actualPosY == expectedPosY,
5270 "expected maxPosition (%d/%d), actual maxPosition (%d/%d)\n",
5271 expectedPosX, expectedPosY, actualPosX, actualPosY);
5276 return DefWindowProcA(hwnd, msg, wparam, lparam);
5279 static void test_thick_child_size(HWND parentWindow)
5287 LPCTSTR className = "THICK_CHILD_CLASS";
5288 LONG style = WS_CHILD | WS_VISIBLE | WS_THICKFRAME;
5290 int expectedSize = 2*getExpectedThickChildInc();
5294 cls.lpfnWndProc = test_thick_child_size_winproc;
5297 cls.hInstance = GetModuleHandleA(0);
5299 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5300 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5301 cls.lpszMenuName = NULL;
5302 cls.lpszClassName = className;
5303 SetLastError(0xdeadbeef);
5304 ok(RegisterClassA(&cls),"RegisterClassA failed, error: %u\n", GetLastError());
5306 test_thick_child_got_minmax = FALSE;
5308 SetLastError(0xdeadbeef);
5309 childWindow = CreateWindowEx( exStyle, className, "", style, 0, 0, 0, 0, parentWindow, 0, GetModuleHandleA(0), NULL );
5310 ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
5312 ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
5314 SetLastError(0xdeadbeef);
5315 success = GetWindowRect(childWindow, &childRect);
5316 ok(success,"GetWindowRect call failed, error: %u\n", GetLastError());
5317 childWidth = childRect.right - childRect.left;
5318 childHeight = childRect.bottom - childRect.top;
5321 ok( (childWidth == expectedSize) && (childHeight == expectedSize),
5322 "size of window with style WS_CHILD | WS_VISIBLE | WS_THICKFRAME is wrong: expected size %dx%d != actual size %dx%d\n",
5323 expectedSize, expectedSize, childWidth, childHeight);
5326 SetLastError(0xdeadbeef);
5327 success = DestroyWindow(childWindow);
5328 ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
5329 ok(UnregisterClass(className, GetModuleHandleA(0)),"UnregisterClass call failed\n");
5332 static void test_handles( HWND full_hwnd )
5334 HWND hwnd = full_hwnd;
5338 SetLastError( 0xdeadbeef );
5339 ret = GetWindowRect( hwnd, &rect );
5340 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5343 if ((ULONG_PTR)full_hwnd >> 32)
5344 hwnd = (HWND)((ULONG_PTR)full_hwnd & ~0u);
5346 hwnd = (HWND)((ULONG_PTR)full_hwnd | ((ULONG_PTR)~0u << 32));
5347 SetLastError( 0xdeadbeef );
5348 ret = GetWindowRect( hwnd, &rect );
5349 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5351 hwnd = (HWND)(((ULONG_PTR)full_hwnd & ~0u) | ((ULONG_PTR)0x1234 << 32));
5352 SetLastError( 0xdeadbeef );
5353 ret = GetWindowRect( hwnd, &rect );
5354 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5356 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x9876 << 16));
5357 SetLastError( 0xdeadbeef );
5358 ret = GetWindowRect( hwnd, &rect );
5359 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
5360 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
5362 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x12345678 << 16));
5363 SetLastError( 0xdeadbeef );
5364 ret = GetWindowRect( hwnd, &rect );
5365 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
5366 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
5372 HMODULE user32 = GetModuleHandleA( "user32.dll" );
5373 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
5374 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
5375 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
5376 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
5377 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
5378 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
5379 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
5381 if (!RegisterWindowClasses()) assert(0);
5383 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
5386 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
5387 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5388 WS_MAXIMIZEBOX | WS_POPUP,
5390 0, 0, GetModuleHandle(0), NULL);
5391 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
5392 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5393 WS_MAXIMIZEBOX | WS_POPUP,
5395 0, 0, GetModuleHandle(0), NULL);
5397 assert( hwndMain2 );
5399 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
5401 /* Add the tests below this line */
5402 test_thick_child_size(hwndMain);
5404 test_hwnd_message();
5405 test_nonclient_area(hwndMain);
5407 test_GetWindowModuleFileName();
5410 test_capture_3(hwndMain, hwndMain2);
5412 test_CreateWindow();
5413 test_parent_owner();
5418 test_SetWindowPos(hwndMain);
5419 test_SetMenu(hwndMain);
5420 test_SetFocus(hwndMain);
5421 test_SetActiveWindow(hwndMain);
5423 test_children_zorder(hwndMain);
5424 test_popup_zorder(hwndMain2, hwndMain);
5425 test_keyboard_input(hwndMain);
5426 test_mouse_input(hwndMain);
5427 test_validatergn(hwndMain);
5428 test_nccalcscroll( hwndMain);
5429 test_scrollvalidate( hwndMain);
5430 test_scrolldc( hwndMain);
5432 test_IsWindowUnicode();
5433 test_vis_rgn(hwndMain);
5435 test_AdjustWindowRect();
5436 test_window_styles();
5439 test_SetWindowLong();
5441 if (0) test_gettext(); /* crashes on NT4 */
5442 test_GetUpdateRect();
5444 test_layered_window();
5446 test_SetForegroundWindow(hwndMain);
5447 test_shell_window();
5448 test_handles( hwndMain );
5450 /* add the tests above this line */
5451 UnhookWindowsHookEx(hhook);
5453 DestroyWindow(hwndMain2);
5454 DestroyWindow(hwndMain);