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);
54 static int (WINAPI *pGetWindowRgnBox)(HWND,LPRECT);
55 static BOOL (WINAPI *pGetGUIThreadInfo)(DWORD, GUITHREADINFO*);
56 static BOOL (WINAPI *pGetProcessDefaultLayout)( DWORD *layout );
57 static BOOL (WINAPI *pSetProcessDefaultLayout)( DWORD layout );
58 static DWORD (WINAPI *pSetLayout)(HDC hdc, DWORD layout);
59 static DWORD (WINAPI *pGetLayout)(HDC hdc);
61 static BOOL test_lbuttondown_flag;
62 static HWND hwndMessage;
63 static HWND hwndMain, hwndMain2;
66 static const char* szAWRClass = "Winsize";
70 static BOOL is_win9x = FALSE;
72 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
74 static void dump_minmax_info( const MINMAXINFO *minmax )
76 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
77 minmax->ptReserved.x, minmax->ptReserved.y,
78 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
79 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
80 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
81 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
84 /* try to make sure pending X events have been processed before continuing */
85 static void flush_events( BOOL remove_messages )
89 int min_timeout = 100;
90 DWORD time = GetTickCount() + diff;
94 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
96 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
97 diff = time - GetTickCount();
102 /* check the values returned by the various parent/owner functions on a given window */
103 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
104 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
110 res = pGetAncestor( hwnd, GA_PARENT );
111 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
113 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
114 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
115 res = GetParent( hwnd );
116 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
117 res = GetWindow( hwnd, GW_OWNER );
118 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
121 res = pGetAncestor( hwnd, GA_ROOT );
122 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
123 res = pGetAncestor( hwnd, GA_ROOTOWNER );
124 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
128 static BOOL ignore_message( UINT message )
130 /* these are always ignored */
131 return (message >= 0xc000 ||
132 message == WM_GETICON ||
133 message == WM_GETOBJECT ||
134 message == WM_TIMECHANGE ||
135 message == WM_DEVICECHANGE);
138 static BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
141 trace("EnumChildProc on %p\n", hwndChild);
142 if (*(LPINT)lParam > 1) return FALSE;
146 /* will search for the given window */
147 static BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
149 trace("EnumChildProc1 on %p\n", hwndChild);
150 if ((HWND)lParam == hwndChild) return FALSE;
154 static HWND create_tool_window( LONG style, HWND parent )
156 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
157 0, 0, 100, 100, parent, 0, 0, NULL );
158 ok( ret != 0, "Creation failed\n" );
162 /* test parent and owner values for various combinations */
163 static void test_parent_owner(void)
166 HWND test, owner, ret;
167 HWND desktop = GetDesktopWindow();
168 HWND child = create_tool_window( WS_CHILD, hwndMain );
171 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
173 /* child without parent, should fail */
174 SetLastError(0xdeadbeef);
175 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
176 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
177 ok( !test, "WS_CHILD without parent created\n" );
178 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD ||
179 broken(GetLastError() == 0xdeadbeef), /* win9x */
180 "CreateWindowExA error %u\n", GetLastError() );
183 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
184 style = GetWindowLongA( desktop, GWL_STYLE );
185 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
186 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
187 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
189 /* normal child window */
190 test = create_tool_window( WS_CHILD, hwndMain );
191 trace( "created child %p\n", test );
192 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
193 SetWindowLongA( test, GWL_STYLE, 0 );
194 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
195 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
196 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
197 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
198 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
199 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
200 DestroyWindow( test );
202 /* normal child window with WS_MAXIMIZE */
203 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
204 DestroyWindow( test );
206 /* normal child window with WS_THICKFRAME */
207 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
208 DestroyWindow( test );
210 /* popup window with WS_THICKFRAME */
211 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
212 DestroyWindow( test );
214 /* child of desktop */
215 test = create_tool_window( WS_CHILD, desktop );
216 trace( "created child of desktop %p\n", test );
217 check_parents( test, desktop, 0, desktop, 0, test, desktop );
218 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
219 check_parents( test, desktop, 0, 0, 0, test, test );
220 SetWindowLongA( test, GWL_STYLE, 0 );
221 check_parents( test, desktop, 0, 0, 0, test, test );
222 DestroyWindow( test );
224 /* child of desktop with WS_MAXIMIZE */
225 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
226 DestroyWindow( test );
228 /* child of desktop with WS_MINIMIZE */
229 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
230 DestroyWindow( test );
233 test = create_tool_window( WS_CHILD, child );
234 trace( "created child of child %p\n", test );
235 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
236 SetWindowLongA( test, GWL_STYLE, 0 );
237 check_parents( test, child, child, 0, 0, hwndMain, test );
238 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
239 check_parents( test, child, child, 0, 0, hwndMain, test );
240 DestroyWindow( test );
242 /* child of child with WS_MAXIMIZE */
243 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
244 DestroyWindow( test );
246 /* child of child with WS_MINIMIZE */
247 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
248 DestroyWindow( test );
250 /* not owned top-level window */
251 test = create_tool_window( 0, 0 );
252 trace( "created top-level %p\n", test );
253 check_parents( test, desktop, 0, 0, 0, test, test );
254 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
255 check_parents( test, desktop, 0, 0, 0, test, test );
256 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
257 check_parents( test, desktop, 0, desktop, 0, test, desktop );
258 DestroyWindow( test );
260 /* not owned top-level window with WS_MAXIMIZE */
261 test = create_tool_window( WS_MAXIMIZE, 0 );
262 DestroyWindow( test );
264 /* owned top-level window */
265 test = create_tool_window( 0, hwndMain );
266 trace( "created owned top-level %p\n", test );
267 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
268 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
269 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
270 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
271 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
272 DestroyWindow( test );
274 /* owned top-level window with WS_MAXIMIZE */
275 test = create_tool_window( WS_MAXIMIZE, hwndMain );
276 DestroyWindow( test );
278 /* not owned popup */
279 test = create_tool_window( WS_POPUP, 0 );
280 trace( "created popup %p\n", test );
281 check_parents( test, desktop, 0, 0, 0, test, test );
282 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
283 check_parents( test, desktop, 0, desktop, 0, test, desktop );
284 SetWindowLongA( test, GWL_STYLE, 0 );
285 check_parents( test, desktop, 0, 0, 0, test, test );
286 DestroyWindow( test );
288 /* not owned popup with WS_MAXIMIZE */
289 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
290 DestroyWindow( test );
293 test = create_tool_window( WS_POPUP, hwndMain );
294 trace( "created owned popup %p\n", test );
295 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
296 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
297 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
298 SetWindowLongA( test, GWL_STYLE, 0 );
299 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
300 DestroyWindow( test );
302 /* owned popup with WS_MAXIMIZE */
303 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
304 DestroyWindow( test );
306 /* top-level window owned by child (same as owned by top-level) */
307 test = create_tool_window( 0, child );
308 trace( "created top-level owned by child %p\n", test );
309 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
310 DestroyWindow( test );
312 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
313 test = create_tool_window( WS_MAXIMIZE, child );
314 DestroyWindow( test );
316 /* popup owned by desktop (same as not owned) */
317 test = create_tool_window( WS_POPUP, desktop );
318 trace( "created popup owned by desktop %p\n", test );
319 check_parents( test, desktop, 0, 0, 0, test, test );
320 DestroyWindow( test );
322 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
323 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
324 DestroyWindow( test );
326 /* popup owned by child (same as owned by top-level) */
327 test = create_tool_window( WS_POPUP, child );
328 trace( "created popup owned by child %p\n", test );
329 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
330 DestroyWindow( test );
332 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
333 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
334 DestroyWindow( test );
336 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
337 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
338 trace( "created WS_CHILD popup %p\n", test );
339 check_parents( test, desktop, 0, 0, 0, test, test );
340 DestroyWindow( test );
342 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
343 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
344 DestroyWindow( test );
346 /* owned popup with WS_CHILD (same as WS_POPUP only) */
347 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
348 trace( "created owned WS_CHILD popup %p\n", test );
349 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
350 DestroyWindow( test );
352 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
353 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
354 DestroyWindow( test );
356 /******************** parent changes *************************/
357 trace( "testing parent changes\n" );
360 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
363 /* this test succeeds on NT but crashes on win9x systems */
364 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
365 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
366 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
367 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
368 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
370 /* normal child window */
371 test = create_tool_window( WS_CHILD, hwndMain );
372 trace( "created child %p\n", test );
374 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
375 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
376 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
378 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
379 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
380 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
382 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
383 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
384 check_parents( test, desktop, 0, desktop, 0, test, desktop );
386 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
389 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)test );
390 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
391 check_parents( test, desktop, 0, desktop, 0, test, desktop );
394 win_skip("Test creates circular window tree under Win9x/WinMe\n" );
396 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
397 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
398 check_parents( test, desktop, child, desktop, child, test, desktop );
400 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
401 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
402 check_parents( test, desktop, 0, desktop, 0, test, desktop );
403 DestroyWindow( test );
405 /* not owned top-level window */
406 test = create_tool_window( 0, 0 );
407 trace( "created top-level %p\n", test );
409 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
410 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
411 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
413 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
414 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
415 check_parents( test, desktop, child, 0, child, test, test );
417 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
418 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
419 check_parents( test, desktop, 0, 0, 0, test, test );
420 DestroyWindow( test );
422 /* not owned popup */
423 test = create_tool_window( WS_POPUP, 0 );
424 trace( "created popup %p\n", test );
426 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
427 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
428 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
430 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
431 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
432 check_parents( test, desktop, child, child, child, test, hwndMain );
434 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
435 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
436 check_parents( test, desktop, 0, 0, 0, test, test );
437 DestroyWindow( test );
439 /* normal child window */
440 test = create_tool_window( WS_CHILD, hwndMain );
441 trace( "created child %p\n", test );
443 ret = SetParent( test, desktop );
444 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
445 check_parents( test, desktop, 0, desktop, 0, test, desktop );
447 ret = SetParent( test, child );
448 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
449 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
451 ret = SetParent( test, hwndMain2 );
452 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
453 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
454 DestroyWindow( test );
456 /* not owned top-level window */
457 test = create_tool_window( 0, 0 );
458 trace( "created top-level %p\n", test );
460 ret = SetParent( test, child );
461 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
462 check_parents( test, child, child, 0, 0, hwndMain, test );
466 ShowWindow( test, SW_SHOW );
467 ret = SetParent( test, test );
468 ok( ret == NULL, "SetParent return value %p expected %p\n", ret, NULL );
469 ok( GetWindowLongA( test, GWL_STYLE ) & WS_VISIBLE, "window is not visible after SetParent\n" );
470 check_parents( test, child, child, 0, 0, hwndMain, test );
473 win_skip( "Test crashes on Win9x/WinMe\n" );
474 DestroyWindow( test );
477 test = create_tool_window( WS_POPUP, hwndMain2 );
478 trace( "created owned popup %p\n", test );
480 ret = SetParent( test, child );
481 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
482 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
484 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
485 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
486 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
487 DestroyWindow( test );
489 /**************** test owner destruction *******************/
491 /* owned child popup */
492 owner = create_tool_window( 0, 0 );
493 test = create_tool_window( WS_POPUP, owner );
494 trace( "created owner %p and popup %p\n", owner, test );
495 ret = SetParent( test, child );
496 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
497 check_parents( test, child, child, owner, owner, hwndMain, owner );
498 /* window is now child of 'child' but owned by 'owner' */
499 DestroyWindow( owner );
500 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
501 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
502 * while Win95, Win2k, WinXP do.
504 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
505 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
508 /* owned top-level popup */
509 owner = create_tool_window( 0, 0 );
510 test = create_tool_window( WS_POPUP, owner );
511 trace( "created owner %p and popup %p\n", owner, test );
512 check_parents( test, desktop, owner, owner, owner, test, owner );
513 DestroyWindow( owner );
514 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
516 /* top-level popup owned by child */
517 owner = create_tool_window( WS_CHILD, hwndMain2 );
518 test = create_tool_window( WS_POPUP, 0 );
519 trace( "created owner %p and popup %p\n", owner, test );
520 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
521 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
522 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
523 DestroyWindow( owner );
524 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
525 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
526 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
527 * while Win95, Win2k, WinXP do.
529 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
533 DestroyWindow(child);
536 owner = create_tool_window( WS_OVERLAPPED, 0 );
537 test = create_tool_window( WS_POPUP, desktop );
539 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
541 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
542 "EnumChildWindows should have returned FALSE\n" );
543 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
545 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
546 ret = SetParent( test, owner );
547 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
550 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
551 "EnumChildWindows should have returned TRUE\n" );
552 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
554 child = create_tool_window( WS_CHILD, owner );
556 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
557 "EnumChildWindows should have returned FALSE\n" );
558 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
559 DestroyWindow( child );
561 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
562 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
564 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
565 "EnumChildWindows should have returned TRUE\n" );
566 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
568 ret = SetParent( child, owner );
569 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
570 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
572 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
573 "EnumChildWindows should have returned FALSE\n" );
574 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
576 ret = SetParent( child, NULL );
577 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
578 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
580 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
581 "EnumChildWindows should have returned TRUE\n" );
582 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
584 /* even GW_OWNER == owner it's still a desktop's child */
585 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
586 "EnumChildWindows should have found %p and returned FALSE\n", child );
588 DestroyWindow( child );
589 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
591 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
592 "EnumChildWindows should have found %p and returned FALSE\n", child );
594 DestroyWindow( child );
595 DestroyWindow( test );
596 DestroyWindow( owner );
599 static BOOL CALLBACK enum_proc( HWND hwnd, LPARAM lParam)
602 if (*(LPINT)lParam > 2) return FALSE;
605 static DWORD CALLBACK enum_thread( void *arg )
612 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ); /* make sure we have a message queue */
615 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
616 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
617 ok( count == 0, "count should be 0 got %d\n", count );
619 hwnd[0] = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", WS_POPUP,
620 0, 0, 100, 100, 0, 0, 0, NULL );
622 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
623 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
624 if (count != 2) /* Vista gives us two windows for the price of one */
626 ok( count == 1, "count should be 1 got %d\n", count );
627 hwnd[2] = CreateWindowExA(0, "ToolWindowClass", "Tool window 2", WS_POPUP,
628 0, 0, 100, 100, 0, 0, 0, NULL );
632 hwnd[1] = CreateWindowExA(0, "ToolWindowClass", "Tool window 3", WS_POPUP,
633 0, 0, 100, 100, 0, 0, 0, NULL );
635 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
636 ok( !ret, "EnumThreadWindows should have returned FALSE\n" );
637 ok( count == 3, "count should be 3 got %d\n", count );
639 if (hwnd[2]) DestroyWindow(hwnd[2]);
640 DestroyWindow(hwnd[1]);
641 DestroyWindow(hwnd[0]);
645 /* test EnumThreadWindows in a separate thread */
646 static void test_enum_thread_windows(void)
649 HANDLE handle = CreateThread( NULL, 0, enum_thread, 0, 0, &id );
650 ok( !WaitForSingleObject( handle, 10000 ), "wait failed\n" );
651 CloseHandle( handle );
654 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
658 case WM_GETMINMAXINFO:
660 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
662 trace("WM_GETMINMAXINFO: hwnd %p, %08lx, %08lx\n", hwnd, wparam, lparam);
663 dump_minmax_info( minmax );
664 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
667 case WM_WINDOWPOSCHANGING:
669 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
670 trace("main: WM_WINDOWPOSCHANGING %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
671 winpos->hwnd, winpos->hwndInsertAfter,
672 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
673 if (!(winpos->flags & SWP_NOMOVE))
675 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
676 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
678 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
679 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
681 ok((winpos->cx >= 0 && winpos->cx <= 32767) ||
682 winpos->cx == 32768, /* win7 doesn't truncate */
683 "bad winpos->cx %d\n", winpos->cx);
684 ok((winpos->cy >= 0 && winpos->cy <= 32767) ||
685 winpos->cy == 40000, /* win7 doesn't truncate */
686 "bad winpos->cy %d\n", winpos->cy);
690 case WM_WINDOWPOSCHANGED:
693 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
694 trace("main: WM_WINDOWPOSCHANGED %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
695 winpos->hwnd, winpos->hwndInsertAfter,
696 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
697 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
698 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
700 ok((winpos->cx >= 0 && winpos->cx <= 32767) ||
701 winpos->cx == 32768, /* win7 doesn't truncate */
702 "bad winpos->cx %d\n", winpos->cx);
703 ok((winpos->cy >= 0 && winpos->cy <= 32767) ||
704 winpos->cy == 40000, /* win7 doesn't truncate */
705 "bad winpos->cy %d\n", winpos->cy);
707 GetWindowRect(hwnd, &rc1);
708 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
709 /* note: winpos coordinates are relative to parent */
710 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
713 /* Uncomment this once the test succeeds in all cases */
714 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
715 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
717 GetClientRect(hwnd, &rc2);
718 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
719 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
720 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
721 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
727 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
728 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
730 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
731 if (got_getminmaxinfo)
732 trace("%p got WM_GETMINMAXINFO\n", hwnd);
734 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
735 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
737 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
741 if (test_lbuttondown_flag)
743 ShowWindow((HWND)wparam, SW_SHOW);
744 flush_events( FALSE );
749 return DefWindowProcA(hwnd, msg, wparam, lparam);
752 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
756 case WM_GETMINMAXINFO:
758 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
760 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
761 dump_minmax_info( minmax );
762 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
767 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
768 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
770 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
771 if (got_getminmaxinfo)
772 trace("%p got WM_GETMINMAXINFO\n", hwnd);
774 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
775 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
777 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
782 return DefWindowProcA(hwnd, msg, wparam, lparam);
785 static BOOL RegisterWindowClasses(void)
789 cls.style = CS_DBLCLKS;
790 cls.lpfnWndProc = main_window_procA;
793 cls.hInstance = GetModuleHandleA(0);
795 cls.hCursor = LoadCursorA(0, IDC_ARROW);
796 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
797 cls.lpszMenuName = NULL;
798 cls.lpszClassName = "MainWindowClass";
800 if(!RegisterClassA(&cls)) return FALSE;
803 cls.lpfnWndProc = tool_window_procA;
806 cls.hInstance = GetModuleHandleA(0);
808 cls.hCursor = LoadCursorA(0, IDC_ARROW);
809 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
810 cls.lpszMenuName = NULL;
811 cls.lpszClassName = "ToolWindowClass";
813 if(!RegisterClassA(&cls)) return FALSE;
818 static void verify_window_info(const char *hook, HWND hwnd, const WINDOWINFO *info)
820 RECT rcWindow, rcClient;
823 ok(IsWindow(hwnd), "bad window handle %p in hook %s\n", hwnd, hook);
825 GetWindowRect(hwnd, &rcWindow);
826 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow for %p in hook %s\n", hwnd, hook);
828 GetClientRect(hwnd, &rcClient);
829 /* translate to screen coordinates */
830 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
831 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient for %p in hook %s\n", hwnd, hook);
833 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
834 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
835 info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE), hwnd, hook);
836 /* Windows reports some undocumented exstyles in WINDOWINFO, but
837 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
839 ok((info->dwExStyle & ~0xe0000800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
840 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
841 info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE), hwnd, hook);
842 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
843 if (GetForegroundWindow())
844 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
845 info->dwWindowStatus, status, GetActiveWindow(), GetForegroundWindow(), hook);
847 /* win2k and XP return broken border info in GetWindowInfo most of
848 * the time, so there is no point in testing it.
852 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
853 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
854 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
855 ok(info->cyWindowBorders == border,
856 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
858 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType for %p in hook %s\n",
860 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
861 info->wCreatorVersion == 0x0500 /* Vista */,
862 "wrong wCreatorVersion %04x for %p in hook %s\n", info->wCreatorVersion, hwnd, hook);
865 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
867 AdjustWindowRectEx(rc, style, menu, exstyle);
868 /* AdjustWindowRectEx does not include scroll bars */
869 if (style & WS_VSCROLL)
871 if(exstyle & WS_EX_LEFTSCROLLBAR)
872 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
874 rc->right += GetSystemMetrics(SM_CXVSCROLL);
876 if (style & WS_HSCROLL)
877 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
880 static void test_nonclient_area(HWND hwnd)
882 DWORD style, exstyle;
883 RECT rc_window, rc_client, rc;
887 style = GetWindowLongA(hwnd, GWL_STYLE);
888 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
889 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
891 GetWindowRect(hwnd, &rc_window);
892 GetClientRect(hwnd, &rc_client);
894 /* avoid some cases when things go wrong */
895 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
896 rc_window.right > 32768 || rc_window.bottom > 32768) return;
898 CopyRect(&rc, &rc_client);
899 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
900 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
902 ok(EqualRect(&rc, &rc_window),
903 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
904 style, exstyle, menu, rc_window.left, rc_window.top, rc_window.right, rc_window.bottom,
905 rc.left, rc.top, rc.right, rc.bottom);
908 CopyRect(&rc, &rc_window);
909 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
910 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
911 ok(EqualRect(&rc, &rc_client),
912 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
913 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
914 rc.left, rc.top, rc.right, rc.bottom);
916 /* NULL rectangle shouldn't crash */
917 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
918 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
920 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
924 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
925 SetRect(&rc_client, 0, 0, 250, 150);
926 CopyRect(&rc_window, &rc_client);
927 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
928 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
930 CopyRect(&rc, &rc_window);
931 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
932 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
933 ok(EqualRect(&rc, &rc_client),
934 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
935 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
936 rc.left, rc.top, rc.right, rc.bottom);
939 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
941 static const char *CBT_code_name[10] = {
952 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
953 HWND hwnd = (HWND)wParam;
959 static const RECT rc_null;
962 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
963 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
968 info.cbSize = sizeof(WINDOWINFO);
969 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
970 verify_window_info(code_name, hwnd, &info);
973 /* WS_VISIBLE should be turned off yet */
974 style = createwnd->lpcs->style & ~WS_VISIBLE;
975 ok(style == GetWindowLongA(hwnd, GWL_STYLE),
976 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
977 GetWindowLongA(hwnd, GWL_STYLE), style);
981 /* Uncomment this once the test succeeds in all cases */
982 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
984 ok(GetParent(hwnd) == hwndMessage,
985 "wrong result from GetParent %p: message window %p\n",
986 GetParent(hwnd), hwndMessage);
989 ok(!GetParent(hwnd), "GetParent should return 0 at this point\n");
991 ok(!GetWindow(hwnd, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
995 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
996 * Win9x still has them set to 0.
998 ok(GetWindow(hwnd, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
999 ok(GetWindow(hwnd, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
1001 ok(!GetWindow(hwnd, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
1002 ok(!GetWindow(hwnd, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
1006 /* Uncomment this once the test succeeds in all cases */
1009 ok(pGetAncestor(hwnd, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
1010 ok(pGetAncestor(hwnd, GA_ROOT) == hwnd,
1011 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOT), hwnd);
1013 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
1014 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwndMessage,
1015 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
1017 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwnd,
1018 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOTOWNER), hwnd);
1021 ok(GetWindowRect(hwnd, &rc), "GetWindowRect failed\n");
1022 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
1023 ok(GetClientRect(hwnd, &rc), "GetClientRect failed\n");
1024 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
1032 if (pGetWindowInfo && IsWindow(hwnd))
1036 /* Win98 actually does check the info.cbSize and doesn't allow
1037 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
1038 * WinXP do not check it at all.
1040 info.cbSize = sizeof(WINDOWINFO);
1041 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
1042 verify_window_info(code_name, hwnd, &info);
1045 /* on HCBT_DESTROYWND window state is undefined */
1046 case HCBT_DESTROYWND:
1052 return CallNextHookEx(hhook, nCode, wParam, lParam);
1055 static void test_shell_window(void)
1059 HMODULE hinst, hUser32;
1060 BOOL (WINAPI*SetShellWindow)(HWND);
1061 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
1062 HWND shellWindow, nextWnd;
1066 win_skip("Skipping shell window test on Win9x\n");
1070 shellWindow = GetShellWindow();
1071 hinst = GetModuleHandle(0);
1072 hUser32 = GetModuleHandleA("user32");
1074 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
1076 trace("previous shell window: %p\n", shellWindow);
1082 GetWindowThreadProcessId(shellWindow, &pid);
1083 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
1086 skip( "cannot get access to shell process\n" );
1090 SetLastError(0xdeadbeef);
1091 ret = DestroyWindow(shellWindow);
1092 error = GetLastError();
1094 ok(!ret, "DestroyWindow(shellWindow)\n");
1095 /* passes on Win XP, but not on Win98 */
1096 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
1097 "got %u after DestroyWindow(shellWindow)\n", error);
1099 /* close old shell instance */
1100 ret = TerminateProcess(hProcess, 0);
1101 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1102 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
1103 CloseHandle(hProcess);
1106 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
1107 trace("created window 1: %p\n", hwnd1);
1109 ret = SetShellWindow(hwnd1);
1110 ok(ret, "first call to SetShellWindow(hwnd1)\n");
1111 shellWindow = GetShellWindow();
1112 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
1114 ret = SetShellWindow(hwnd1);
1115 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1117 ret = SetShellWindow(0);
1118 error = GetLastError();
1119 /* passes on Win XP, but not on Win98
1120 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1121 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1123 ret = SetShellWindow(hwnd1);
1124 /* passes on Win XP, but not on Win98
1125 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1127 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1128 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
1129 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1131 ret = DestroyWindow(hwnd1);
1132 ok(ret, "DestroyWindow(hwnd1)\n");
1134 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1135 trace("created window 2: %p\n", hwnd2);
1136 ret = SetShellWindow(hwnd2);
1137 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1139 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1140 trace("created window 3: %p\n", hwnd3);
1142 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1143 trace("created window 4: %p\n", hwnd4);
1145 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1146 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1148 ret = SetShellWindow(hwnd4);
1149 ok(ret, "SetShellWindow(hwnd4)\n");
1150 shellWindow = GetShellWindow();
1151 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1153 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1154 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1156 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1157 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1159 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1160 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1162 ret = SetShellWindow(hwnd3);
1163 ok(!ret, "SetShellWindow(hwnd3)\n");
1164 shellWindow = GetShellWindow();
1165 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1167 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1168 trace("created window 5: %p\n", hwnd5);
1169 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1170 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1174 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1175 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1178 /* destroy test windows */
1179 DestroyWindow(hwnd2);
1180 DestroyWindow(hwnd3);
1181 DestroyWindow(hwnd4);
1182 DestroyWindow(hwnd5);
1185 /************** MDI test ****************/
1187 static char mdi_lParam_test_message[] = "just a test string";
1189 static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
1191 MDICREATESTRUCTA mdi_cs;
1194 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1195 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1196 BOOL isWin9x = FALSE;
1198 mdi_cs.szClass = "MDI_child_Class_1";
1199 mdi_cs.szTitle = "MDI child";
1200 mdi_cs.hOwner = GetModuleHandle(0);
1201 mdi_cs.x = CW_USEDEFAULT;
1202 mdi_cs.y = CW_USEDEFAULT;
1203 mdi_cs.cx = CW_USEDEFAULT;
1204 mdi_cs.cy = CW_USEDEFAULT;
1206 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1207 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1208 ok(mdi_child != 0, "MDI child creation failed\n");
1209 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1210 ok(id == first_id, "wrong child id %ld\n", id);
1211 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1212 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1214 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1215 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1216 ok(mdi_child != 0, "MDI child creation failed\n");
1217 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1218 ok(id == first_id, "wrong child id %ld\n", id);
1219 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1220 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1222 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1223 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1224 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1226 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1230 ok(mdi_child != 0, "MDI child creation failed\n");
1231 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1232 ok(id == first_id, "wrong child id %ld\n", id);
1233 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1234 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1237 /* test MDICREATESTRUCT A<->W mapping */
1238 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1240 mdi_cs.szClass = (LPCSTR)classW;
1241 mdi_cs.szTitle = (LPCSTR)titleW;
1242 SetLastError(0xdeadbeef);
1243 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1246 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1249 ok(mdi_child != 0, "MDI child creation failed\n");
1253 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1254 ok(id == first_id, "wrong child id %ld\n", id);
1255 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1256 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1259 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1261 CW_USEDEFAULT, CW_USEDEFAULT,
1262 CW_USEDEFAULT, CW_USEDEFAULT,
1263 mdi_client, GetModuleHandle(0),
1264 (LPARAM)mdi_lParam_test_message);
1265 ok(mdi_child != 0, "MDI child creation failed\n");
1266 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1267 ok(id == first_id, "wrong child id %ld\n", id);
1268 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1269 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1271 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1272 0x7fffffff, /* without WS_POPUP */
1273 CW_USEDEFAULT, CW_USEDEFAULT,
1274 CW_USEDEFAULT, CW_USEDEFAULT,
1275 mdi_client, GetModuleHandle(0),
1276 (LPARAM)mdi_lParam_test_message);
1277 ok(mdi_child != 0, "MDI child creation failed\n");
1278 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1279 ok(id == first_id, "wrong child id %ld\n", id);
1280 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1281 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1283 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1284 0xffffffff, /* with WS_POPUP */
1285 CW_USEDEFAULT, CW_USEDEFAULT,
1286 CW_USEDEFAULT, CW_USEDEFAULT,
1287 mdi_client, GetModuleHandle(0),
1288 (LPARAM)mdi_lParam_test_message);
1289 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1291 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1295 ok(mdi_child != 0, "MDI child creation failed\n");
1296 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1297 ok(id == first_id, "wrong child id %ld\n", id);
1298 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1299 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1302 /* test MDICREATESTRUCT A<->W mapping */
1303 SetLastError(0xdeadbeef);
1304 mdi_child = CreateMDIWindowW(classW, titleW,
1306 CW_USEDEFAULT, CW_USEDEFAULT,
1307 CW_USEDEFAULT, CW_USEDEFAULT,
1308 mdi_client, GetModuleHandle(0),
1309 (LPARAM)mdi_lParam_test_message);
1312 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1315 ok(mdi_child != 0, "MDI child creation failed\n");
1319 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1320 ok(id == first_id, "wrong child id %ld\n", id);
1321 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1322 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1325 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1327 CW_USEDEFAULT, CW_USEDEFAULT,
1328 CW_USEDEFAULT, CW_USEDEFAULT,
1329 mdi_client, 0, GetModuleHandle(0),
1330 mdi_lParam_test_message);
1331 ok(mdi_child != 0, "MDI child creation failed\n");
1332 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1333 ok(id == first_id, "wrong child id %ld\n", id);
1334 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1335 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1337 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1338 0x7fffffff, /* without WS_POPUP */
1339 CW_USEDEFAULT, CW_USEDEFAULT,
1340 CW_USEDEFAULT, CW_USEDEFAULT,
1341 mdi_client, 0, GetModuleHandle(0),
1342 mdi_lParam_test_message);
1343 ok(mdi_child != 0, "MDI child creation failed\n");
1344 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1345 ok(id == first_id, "wrong child id %ld\n", id);
1346 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1347 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1349 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1350 0xffffffff, /* with WS_POPUP */
1351 CW_USEDEFAULT, CW_USEDEFAULT,
1352 CW_USEDEFAULT, CW_USEDEFAULT,
1353 mdi_client, 0, GetModuleHandle(0),
1354 mdi_lParam_test_message);
1355 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1357 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1361 ok(mdi_child != 0, "MDI child creation failed\n");
1362 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1363 ok(id == first_id, "wrong child id %ld\n", id);
1364 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1365 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1368 /* test MDICREATESTRUCT A<->W mapping */
1369 SetLastError(0xdeadbeef);
1370 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1372 CW_USEDEFAULT, CW_USEDEFAULT,
1373 CW_USEDEFAULT, CW_USEDEFAULT,
1374 mdi_client, 0, GetModuleHandle(0),
1375 mdi_lParam_test_message);
1378 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1381 ok(mdi_child != 0, "MDI child creation failed\n");
1385 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1386 ok(id == first_id, "wrong child id %ld\n", id);
1387 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1388 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1391 /* This test fails on Win9x */
1394 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1396 CW_USEDEFAULT, CW_USEDEFAULT,
1397 CW_USEDEFAULT, CW_USEDEFAULT,
1398 parent, 0, GetModuleHandle(0),
1399 mdi_lParam_test_message);
1400 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1403 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1404 WS_CHILD, /* without WS_POPUP */
1405 CW_USEDEFAULT, CW_USEDEFAULT,
1406 CW_USEDEFAULT, CW_USEDEFAULT,
1407 mdi_client, 0, GetModuleHandle(0),
1408 mdi_lParam_test_message);
1409 ok(mdi_child != 0, "MDI child creation failed\n");
1410 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1411 ok(id == 0, "wrong child id %ld\n", id);
1412 DestroyWindow(mdi_child);
1414 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1415 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1416 CW_USEDEFAULT, CW_USEDEFAULT,
1417 CW_USEDEFAULT, CW_USEDEFAULT,
1418 mdi_client, 0, GetModuleHandle(0),
1419 mdi_lParam_test_message);
1420 ok(mdi_child != 0, "MDI child creation failed\n");
1421 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1422 ok(id == 0, "wrong child id %ld\n", id);
1423 DestroyWindow(mdi_child);
1425 /* maximized child */
1426 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1427 WS_CHILD | WS_MAXIMIZE,
1428 CW_USEDEFAULT, CW_USEDEFAULT,
1429 CW_USEDEFAULT, CW_USEDEFAULT,
1430 mdi_client, 0, GetModuleHandle(0),
1431 mdi_lParam_test_message);
1432 ok(mdi_child != 0, "MDI child creation failed\n");
1433 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1434 ok(id == 0, "wrong child id %ld\n", id);
1435 DestroyWindow(mdi_child);
1437 trace("Creating maximized child with a caption\n");
1438 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1439 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1440 CW_USEDEFAULT, CW_USEDEFAULT,
1441 CW_USEDEFAULT, CW_USEDEFAULT,
1442 mdi_client, 0, GetModuleHandle(0),
1443 mdi_lParam_test_message);
1444 ok(mdi_child != 0, "MDI child creation failed\n");
1445 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1446 ok(id == 0, "wrong child id %ld\n", id);
1447 DestroyWindow(mdi_child);
1449 trace("Creating maximized child with a caption and a thick frame\n");
1450 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1451 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1452 CW_USEDEFAULT, CW_USEDEFAULT,
1453 CW_USEDEFAULT, CW_USEDEFAULT,
1454 mdi_client, 0, GetModuleHandle(0),
1455 mdi_lParam_test_message);
1456 ok(mdi_child != 0, "MDI child creation failed\n");
1457 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1458 ok(id == 0, "wrong child id %ld\n", id);
1459 DestroyWindow(mdi_child);
1462 /**********************************************************************
1463 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1465 * Note: The rule here is that client rect of the maximized MDI child
1466 * is equal to the client rect of the MDI client window.
1468 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1472 GetClientRect( client, &rect );
1473 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1474 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1476 rect.right -= rect.left;
1477 rect.bottom -= rect.top;
1478 lpMinMax->ptMaxSize.x = rect.right;
1479 lpMinMax->ptMaxSize.y = rect.bottom;
1481 lpMinMax->ptMaxPosition.x = rect.left;
1482 lpMinMax->ptMaxPosition.y = rect.top;
1484 trace("max rect (%d,%d - %d, %d)\n",
1485 rect.left, rect.top, rect.right, rect.bottom);
1488 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1495 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1496 MDICREATESTRUCTA *mdi_cs = cs->lpCreateParams;
1498 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1499 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1501 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1502 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1503 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1504 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1505 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1507 /* MDICREATESTRUCT should have original values */
1508 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1509 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1510 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1511 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1512 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1513 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1515 /* CREATESTRUCT should have fixed values */
1516 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1517 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1519 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1520 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1521 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1523 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1525 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1527 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1528 ok(cs->style == style,
1529 "cs->style does not match (%08x)\n", cs->style);
1533 LONG style = mdi_cs->style;
1535 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1536 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1537 ok(cs->style == style,
1538 "cs->style does not match (%08x)\n", cs->style);
1543 case WM_GETMINMAXINFO:
1545 HWND client = GetParent(hwnd);
1547 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1548 MINMAXINFO my_minmax;
1549 LONG style, exstyle;
1551 style = GetWindowLongA(hwnd, GWL_STYLE);
1552 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1554 GetWindowRect(client, &rc);
1555 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1556 GetClientRect(client, &rc);
1557 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1558 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1559 GetSystemMetrics(SM_CYSCREEN));
1561 GetClientRect(client, &rc);
1562 if ((style & WS_CAPTION) == WS_CAPTION)
1563 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1564 AdjustWindowRectEx(&rc, style, 0, exstyle);
1565 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1566 dump_minmax_info( minmax );
1568 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1569 minmax->ptMaxSize.x, rc.right - rc.left);
1570 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1571 minmax->ptMaxSize.y, rc.bottom - rc.top);
1573 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1575 trace("DefMDIChildProc returned:\n");
1576 dump_minmax_info( minmax );
1578 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1579 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1580 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1581 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1582 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1587 case WM_MDIACTIVATE:
1589 HWND active, client = GetParent(hwnd);
1590 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1591 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1592 if (hwnd == (HWND)lparam) /* if we are being activated */
1593 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1595 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1599 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1602 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1609 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1611 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE",
1612 cs->x, cs->y, cs->cx, cs->cy);
1614 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1615 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1617 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1618 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1620 /* CREATESTRUCT should have fixed values */
1621 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1623 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1624 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1626 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1627 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1628 while Win95, Win2k, WinXP do. */
1629 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1630 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1634 case WM_GETMINMAXINFO:
1636 HWND parent = GetParent(hwnd);
1638 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1639 LONG style, exstyle;
1641 style = GetWindowLongA(hwnd, GWL_STYLE);
1642 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1644 GetClientRect(parent, &rc);
1645 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1647 GetClientRect(parent, &rc);
1648 if ((style & WS_CAPTION) == WS_CAPTION)
1649 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1650 AdjustWindowRectEx(&rc, style, 0, exstyle);
1651 dump_minmax_info( minmax );
1653 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1654 minmax->ptMaxSize.x, rc.right - rc.left);
1655 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1656 minmax->ptMaxSize.y, rc.bottom - rc.top);
1660 case WM_WINDOWPOSCHANGED:
1662 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1665 GetWindowRect(hwnd, &rc1);
1666 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1667 /* note: winpos coordinates are relative to parent */
1668 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1669 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) pos=(%d,%d)-(%d,%d)\n",
1670 rc1.left, rc1.top, rc1.right, rc1.bottom,
1671 rc2.left, rc2.top, rc2.right, rc2.bottom);
1672 GetWindowRect(hwnd, &rc1);
1673 GetClientRect(hwnd, &rc2);
1674 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1675 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1676 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1677 rc1.left, rc1.top, rc1.right, rc1.bottom,
1678 rc2.left, rc2.top, rc2.right, rc2.bottom);
1681 case WM_WINDOWPOSCHANGING:
1683 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1684 WINDOWPOS my_winpos = *winpos;
1686 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1687 (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
1688 winpos->hwnd, winpos->hwndInsertAfter,
1689 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1691 DefWindowProcA(hwnd, msg, wparam, lparam);
1693 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1694 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1695 winpos->hwnd, winpos->hwndInsertAfter,
1696 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1701 return DefWindowProcA(hwnd, msg, wparam, lparam);
1704 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1706 static HWND mdi_client;
1712 CLIENTCREATESTRUCT client_cs;
1715 GetClientRect(hwnd, &rc);
1717 client_cs.hWindowMenu = 0;
1718 client_cs.idFirstChild = 1;
1720 /* MDIClient without MDIS_ALLCHILDSTYLES */
1721 mdi_client = CreateWindowExA(0, "mdiclient",
1723 WS_CHILD /*| WS_VISIBLE*/,
1724 /* tests depend on a not zero MDIClient size */
1725 0, 0, rc.right, rc.bottom,
1726 hwnd, 0, GetModuleHandle(0),
1729 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1730 DestroyWindow(mdi_client);
1732 /* MDIClient with MDIS_ALLCHILDSTYLES */
1733 mdi_client = CreateWindowExA(0, "mdiclient",
1735 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1736 /* tests depend on a not zero MDIClient size */
1737 0, 0, rc.right, rc.bottom,
1738 hwnd, 0, GetModuleHandle(0),
1741 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1742 DestroyWindow(mdi_client);
1746 case WM_WINDOWPOSCHANGED:
1748 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1751 GetWindowRect(hwnd, &rc1);
1752 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1753 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1754 /* note: winpos coordinates are relative to parent */
1755 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1756 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1757 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1759 GetWindowRect(hwnd, &rc1);
1760 GetClientRect(hwnd, &rc2);
1761 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1762 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1763 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1766 case WM_WINDOWPOSCHANGING:
1768 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1769 WINDOWPOS my_winpos = *winpos;
1771 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1772 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1773 winpos->hwnd, winpos->hwndInsertAfter,
1774 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1776 DefWindowProcA(hwnd, msg, wparam, lparam);
1778 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1779 winpos->hwnd, winpos->hwndInsertAfter,
1780 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1782 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1783 "DefWindowProc should not change WINDOWPOS values\n");
1792 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1795 static BOOL mdi_RegisterWindowClasses(void)
1800 cls.lpfnWndProc = mdi_main_wnd_procA;
1803 cls.hInstance = GetModuleHandleA(0);
1805 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1806 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1807 cls.lpszMenuName = NULL;
1808 cls.lpszClassName = "MDI_parent_Class";
1809 if(!RegisterClassA(&cls)) return FALSE;
1811 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1812 cls.lpszClassName = "MDI_child_Class_1";
1813 if(!RegisterClassA(&cls)) return FALSE;
1815 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1816 cls.lpszClassName = "MDI_child_Class_2";
1817 if(!RegisterClassA(&cls)) return FALSE;
1822 static void test_mdi(void)
1827 if (!mdi_RegisterWindowClasses()) assert(0);
1829 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1830 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1831 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1832 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1833 GetDesktopWindow(), 0,
1834 GetModuleHandle(0), NULL);
1835 assert(mdi_hwndMain);
1837 while(GetMessage(&msg, 0, 0, 0))
1839 TranslateMessage(&msg);
1840 DispatchMessage(&msg);
1843 DestroyWindow(mdi_hwndMain);
1846 static void test_icons(void)
1850 HICON icon = LoadIconA(0, IDI_APPLICATION);
1851 HICON icon2 = LoadIconA(0, IDI_QUESTION);
1852 HICON small_icon = LoadImageA(0, IDI_APPLICATION, IMAGE_ICON,
1853 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1856 cls.cbSize = sizeof(cls);
1858 cls.lpfnWndProc = DefWindowProcA;
1862 cls.hIcon = LoadIconA(0, IDI_HAND);
1863 cls.hIconSm = small_icon;
1864 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1865 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1866 cls.lpszMenuName = NULL;
1867 cls.lpszClassName = "IconWindowClass";
1869 RegisterClassExA(&cls);
1871 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1872 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1875 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1876 ok( res == 0, "wrong big icon %p/0\n", res );
1877 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1878 ok( res == 0, "wrong previous big icon %p/0\n", res );
1879 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1880 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1881 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1882 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1883 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1884 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1886 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1887 ok( res == 0, "wrong small icon %p/0\n", res );
1888 /* this test is XP specific */
1889 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1890 ok( res != 0, "wrong small icon %p\n", res );*/
1891 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1892 ok( res == 0, "wrong previous small icon %p/0\n", res );
1893 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1894 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1895 /* this test is XP specific */
1896 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1897 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1898 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1899 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1900 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1901 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1902 /* this test is XP specific */
1903 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1904 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1906 /* make sure the big icon hasn't changed */
1907 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1908 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1910 DestroyWindow( hwnd );
1913 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1915 if (msg == WM_NCCALCSIZE)
1917 RECT *rect = (RECT *)lparam;
1918 /* first time around increase the rectangle, next time decrease it */
1919 if (rect->left == 100) InflateRect( rect, 10, 10 );
1920 else InflateRect( rect, -10, -10 );
1923 return DefWindowProc( hwnd, msg, wparam, lparam );
1926 static void test_SetWindowPos(HWND hwnd)
1928 RECT orig_win_rc, rect;
1931 SetRect(&rect, 111, 222, 333, 444);
1932 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1933 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1934 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1936 SetRect(&rect, 111, 222, 333, 444);
1937 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1938 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1939 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1941 GetWindowRect(hwnd, &orig_win_rc);
1943 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1944 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1945 GetWindowRect( hwnd, &rect );
1946 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1947 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1948 GetClientRect( hwnd, &rect );
1949 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1950 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1951 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1953 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1954 GetWindowRect( hwnd, &rect );
1955 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1956 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1957 GetClientRect( hwnd, &rect );
1958 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1959 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1960 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1962 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1963 orig_win_rc.right, orig_win_rc.bottom, 0);
1964 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1966 /* Win9x truncates coordinates to 16-bit irrespectively */
1969 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1970 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1972 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1973 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1976 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1977 orig_win_rc.right, orig_win_rc.bottom, 0);
1979 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1980 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1981 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1982 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1983 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1984 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1985 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1988 static void test_SetMenu(HWND parent)
1995 hMenu = CreateMenu();
1998 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2001 /* fails on (at least) Wine, NT4, XP SP2 */
2002 test_nonclient_area(parent);
2004 ret = GetMenu(parent);
2005 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2006 /* test whether we can destroy a menu assigned to a window */
2007 retok = DestroyMenu(hMenu);
2008 ok( retok, "DestroyMenu error %d\n", GetLastError());
2009 retok = IsMenu(hMenu);
2010 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
2011 ret = GetMenu(parent);
2012 /* This test fails on Win9x */
2014 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2015 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2016 test_nonclient_area(parent);
2018 hMenu = CreateMenu();
2022 ret = GetMenu(parent);
2023 ok(ret == 0, "unexpected menu id %p\n", ret);
2025 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2026 test_nonclient_area(parent);
2027 ret = GetMenu(parent);
2028 ok(ret == 0, "unexpected menu id %p\n", ret);
2030 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2033 /* fails on (at least) Wine, NT4, XP SP2 */
2034 test_nonclient_area(parent);
2036 ret = GetMenu(parent);
2037 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2039 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2040 test_nonclient_area(parent);
2041 ret = GetMenu(parent);
2042 ok(ret == 0, "unexpected menu id %p\n", ret);
2045 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
2048 ret = GetMenu(child);
2049 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2051 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2052 test_nonclient_area(child);
2053 ret = GetMenu(child);
2054 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2056 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
2057 test_nonclient_area(child);
2058 ret = GetMenu(child);
2059 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2061 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
2062 test_nonclient_area(child);
2063 ret = GetMenu(child);
2064 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2066 style = GetWindowLong(child, GWL_STYLE);
2067 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
2068 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
2069 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
2070 SetWindowLong(child, GWL_STYLE, style);
2072 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
2073 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
2074 SetWindowLong(child, GWL_STYLE, style);
2076 DestroyWindow(child);
2080 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
2082 HWND child[5], hwnd;
2087 hwnd = GetWindow(parent, GW_CHILD);
2088 ok(!hwnd, "have to start without children to perform the test\n");
2090 for (i = 0; i < total; i++)
2092 if (style[i] & DS_CONTROL)
2094 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
2095 0,0,0,0, parent, (HMENU)i, 0, NULL);
2096 if (style[i] & WS_VISIBLE)
2097 ShowWindow(child[i], SW_SHOW);
2099 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
2102 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
2103 parent, (HMENU)i, 0, NULL);
2104 trace("child[%ld] = %p\n", i, child[i]);
2105 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
2108 hwnd = GetWindow(parent, GW_CHILD);
2109 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
2110 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
2111 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
2113 for (i = 0; i < total; i++)
2115 trace("hwnd[%ld] = %p\n", i, hwnd);
2116 ok(child[order[i]] == hwnd, "Z order of child #%ld is wrong\n", i);
2118 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
2121 for (i = 0; i < total; i++)
2122 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2125 static void test_children_zorder(HWND parent)
2127 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2129 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2131 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2132 WS_CHILD | WS_VISIBLE, WS_CHILD,
2133 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2134 const int complex_order_1[1] = { 0 };
2135 const int complex_order_2[2] = { 1, 0 };
2136 const int complex_order_3[3] = { 1, 0, 2 };
2137 const int complex_order_4[4] = { 1, 0, 2, 3 };
2138 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2139 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2140 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2141 WS_CHILD | WS_VISIBLE };
2142 const int complex_order_6[3] = { 0, 1, 2 };
2144 /* simple WS_CHILD */
2145 test_window_tree(parent, simple_style, simple_order, 5);
2147 /* complex children styles */
2148 test_window_tree(parent, complex_style, complex_order_1, 1);
2149 test_window_tree(parent, complex_style, complex_order_2, 2);
2150 test_window_tree(parent, complex_style, complex_order_3, 3);
2151 test_window_tree(parent, complex_style, complex_order_4, 4);
2152 test_window_tree(parent, complex_style, complex_order_5, 5);
2154 /* another set of complex children styles */
2155 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2158 #define check_z_order(hwnd, next, prev, owner, topmost) \
2159 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2162 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2163 BOOL topmost, const char *file, int line)
2168 test = GetWindow(hwnd, GW_HWNDNEXT);
2169 /* skip foreign windows */
2170 while (test && test != next &&
2171 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2172 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2173 GetWindow(test, GW_OWNER) == next))
2175 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2176 test = GetWindow(test, GW_HWNDNEXT);
2178 ok_(file, line)(next == test, "%p: expected next %p, got %p\n", hwnd, next, test);
2180 test = GetWindow(hwnd, GW_HWNDPREV);
2181 /* skip foreign windows */
2182 while (test && test != prev &&
2183 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2184 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2185 GetWindow(test, GW_OWNER) == hwnd))
2187 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2188 test = GetWindow(test, GW_HWNDPREV);
2190 ok_(file, line)(prev == test, "%p: expected prev %p, got %p\n", hwnd, prev, test);
2192 test = GetWindow(hwnd, GW_OWNER);
2193 ok_(file, line)(owner == test, "%p: expected owner %p, got %p\n", hwnd, owner, test);
2195 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2196 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "%p: expected %stopmost\n",
2197 hwnd, topmost ? "" : "NOT ");
2200 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E, DWORD style)
2202 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2204 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2206 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2208 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2209 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2211 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2212 WS_OVERLAPPED | WS_CAPTION,
2214 0, 0, GetModuleHandle(0), NULL);
2215 trace("hwnd_F %p\n", hwnd_F);
2216 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2218 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2219 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2220 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2221 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2223 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2226 hwnd_F, 0, GetModuleHandle(0), NULL);
2227 trace("hwnd_C %p\n", hwnd_C);
2228 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2229 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2230 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2231 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2233 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2236 hwnd_F, 0, GetModuleHandle(0), NULL);
2237 trace("hwnd_B %p\n", hwnd_B);
2238 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2239 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2240 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2241 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2242 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2244 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2247 0, 0, GetModuleHandle(0), NULL);
2248 trace("hwnd_A %p\n", hwnd_A);
2249 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2250 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2251 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2252 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2253 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2254 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2256 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);
2258 /* move hwnd_F and its popups up */
2259 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2260 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2261 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2262 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2263 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2264 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2265 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2267 /* move hwnd_F and its popups down */
2268 #if 0 /* enable once Wine is fixed to pass this test */
2269 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2270 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2271 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2272 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2273 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2274 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2275 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2278 /* make hwnd_C owned by a topmost window */
2279 DestroyWindow( hwnd_C );
2280 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2283 hwnd_A, 0, GetModuleHandle(0), NULL);
2284 trace("hwnd_C %p\n", hwnd_C);
2285 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2286 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2287 check_z_order(hwnd_F, hwnd_D, hwnd_B, 0, FALSE);
2288 check_z_order(hwnd_B, hwnd_F, hwnd_A, hwnd_F, TRUE);
2289 check_z_order(hwnd_A, hwnd_B, hwnd_C, 0, TRUE);
2290 check_z_order(hwnd_C, hwnd_A, 0, hwnd_A, TRUE);
2292 DestroyWindow(hwnd_A);
2293 DestroyWindow(hwnd_B);
2294 DestroyWindow(hwnd_C);
2295 DestroyWindow(hwnd_F);
2298 static void test_vis_rgn( HWND hwnd )
2300 RECT win_rect, rgn_rect;
2301 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2304 ShowWindow(hwnd,SW_SHOW);
2305 hdc = GetDC( hwnd );
2306 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2307 GetWindowRect( hwnd, &win_rect );
2308 GetRgnBox( hrgn, &rgn_rect );
2311 trace("win9x, mapping to screen coords\n");
2312 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2314 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2315 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2316 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2317 rgn_rect.left, win_rect.left );
2318 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2319 rgn_rect.top, win_rect.top );
2320 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2321 rgn_rect.right, win_rect.right );
2322 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2323 rgn_rect.bottom, win_rect.bottom );
2324 ReleaseDC( hwnd, hdc );
2327 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2329 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2331 HWND child = GetWindow(hwnd, GW_CHILD);
2332 ok(child != 0, "couldn't find child window\n");
2334 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2337 return DefWindowProc(hwnd, msg, wp, lp);
2340 static void test_SetFocus(HWND hwnd)
2343 WNDPROC old_wnd_proc;
2345 /* check if we can set focus to non-visible windows */
2347 ShowWindow(hwnd, SW_SHOW);
2350 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2351 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2352 ShowWindow(hwnd, SW_HIDE);
2355 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2356 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2357 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2360 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2361 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2362 ShowWindow(child, SW_SHOW);
2363 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2364 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2365 ShowWindow(child, SW_HIDE);
2366 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2367 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2368 ShowWindow(child, SW_SHOW);
2369 child2 = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, child, 0, 0, NULL);
2371 ShowWindow(child2, SW_SHOW);
2373 ShowWindow(child, SW_HIDE);
2374 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2375 ok( GetFocus() == child2, "Focus should be on %p, not %p\n", child2, GetFocus() );
2376 ShowWindow(child, SW_SHOW);
2378 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2379 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2380 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2382 ShowWindow(child, SW_HIDE);
2384 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2385 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2386 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2387 ShowWindow(child, SW_HIDE);
2388 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2390 ShowWindow(hwnd, SW_SHOW);
2391 ShowWindow(child, SW_SHOW);
2393 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2394 EnableWindow(hwnd, FALSE);
2395 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2396 EnableWindow(hwnd, TRUE);
2398 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2399 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2400 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2402 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2403 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2404 ShowWindow(hwnd, SW_RESTORE);
2405 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2406 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2407 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2408 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2409 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2411 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2412 old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2413 ShowWindow(hwnd, SW_RESTORE);
2414 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2416 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2418 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2420 DestroyWindow( child2 );
2421 DestroyWindow( child );
2424 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
2425 static void check_wnd_state_(const char *file, int line,
2426 HWND active, HWND foreground, HWND focus, HWND capture)
2428 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2429 /* only check foreground if it belongs to the current thread */
2430 /* foreground can be moved to a different app pretty much at any time */
2431 if (foreground && GetForegroundWindow() &&
2432 GetWindowThreadProcessId(GetForegroundWindow(), NULL) == GetCurrentThreadId())
2433 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2434 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2435 ok_(file, line)(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2438 static void test_SetActiveWindow(HWND hwnd)
2442 flush_events( TRUE );
2443 ShowWindow(hwnd, SW_HIDE);
2446 check_wnd_state(0, 0, 0, 0);
2448 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2450 ShowWindow(hwnd, SW_SHOW);
2451 check_wnd_state(hwnd, hwnd, hwnd, 0);
2453 hwnd2 = SetActiveWindow(0);
2454 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2455 if (!GetActiveWindow()) /* doesn't always work on vista */
2457 check_wnd_state(0, 0, 0, 0);
2458 hwnd2 = SetActiveWindow(hwnd);
2459 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2461 check_wnd_state(hwnd, hwnd, hwnd, 0);
2463 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2464 check_wnd_state(hwnd, hwnd, hwnd, 0);
2466 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2467 check_wnd_state(hwnd, hwnd, hwnd, 0);
2469 ShowWindow(hwnd, SW_HIDE);
2470 check_wnd_state(0, 0, 0, 0);
2472 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2473 SetActiveWindow(hwnd);
2474 check_wnd_state(hwnd, hwnd, hwnd, 0);
2476 ShowWindow(hwnd, SW_SHOW);
2477 check_wnd_state(hwnd, hwnd, hwnd, 0);
2479 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2480 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2482 DestroyWindow(hwnd2);
2483 check_wnd_state(hwnd, hwnd, hwnd, 0);
2485 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2486 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2488 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2489 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2491 DestroyWindow(hwnd2);
2492 check_wnd_state(hwnd, hwnd, hwnd, 0);
2495 struct create_window_thread_params
2498 HANDLE window_created;
2499 HANDLE test_finished;
2502 static DWORD WINAPI create_window_thread(void *param)
2504 struct create_window_thread_params *p = param;
2508 p->window = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
2510 ret = SetEvent(p->window_created);
2511 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
2513 res = WaitForSingleObject(p->test_finished, INFINITE);
2514 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2516 DestroyWindow(p->window);
2520 static void test_SetForegroundWindow(HWND hwnd)
2522 struct create_window_thread_params thread_params;
2529 flush_events( TRUE );
2530 ShowWindow(hwnd, SW_HIDE);
2533 check_wnd_state(0, 0, 0, 0);
2535 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2537 ShowWindow(hwnd, SW_SHOW);
2538 check_wnd_state(hwnd, hwnd, hwnd, 0);
2540 hwnd2 = SetActiveWindow(0);
2541 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2542 if (GetActiveWindow() == hwnd) /* doesn't always work on vista */
2543 check_wnd_state(hwnd, hwnd, hwnd, 0);
2545 check_wnd_state(0, 0, 0, 0);
2547 ret = SetForegroundWindow(hwnd);
2550 skip( "SetForegroundWindow not working\n" );
2553 check_wnd_state(hwnd, hwnd, hwnd, 0);
2555 SetLastError(0xdeadbeef);
2556 ret = SetForegroundWindow(0);
2557 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2558 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
2559 broken(GetLastError() == 0xdeadbeef), /* win9x */
2560 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2561 check_wnd_state(hwnd, hwnd, hwnd, 0);
2563 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2564 check_wnd_state(hwnd, hwnd, hwnd, 0);
2566 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2567 check_wnd_state(hwnd, hwnd, hwnd, 0);
2569 hwnd2 = GetForegroundWindow();
2570 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2571 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2572 hwnd2 = GetForegroundWindow();
2573 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2575 ShowWindow(hwnd, SW_HIDE);
2576 check_wnd_state(0, 0, 0, 0);
2578 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2579 ret = SetForegroundWindow(hwnd);
2580 ok(ret || broken(!ret), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
2581 check_wnd_state(hwnd, hwnd, hwnd, 0);
2583 ShowWindow(hwnd, SW_SHOW);
2584 check_wnd_state(hwnd, hwnd, hwnd, 0);
2586 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2587 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2589 DestroyWindow(hwnd2);
2590 check_wnd_state(hwnd, hwnd, hwnd, 0);
2592 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2593 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2595 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2596 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2598 DestroyWindow(hwnd2);
2599 check_wnd_state(hwnd, hwnd, hwnd, 0);
2601 hwnd2 = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
2602 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2604 thread_params.window_created = CreateEvent(NULL, FALSE, FALSE, NULL);
2605 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
2606 thread_params.test_finished = CreateEvent(NULL, FALSE, FALSE, NULL);
2607 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
2608 thread = CreateThread(NULL, 0, create_window_thread, &thread_params, 0, &tid);
2609 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
2610 res = WaitForSingleObject(thread_params.window_created, INFINITE);
2611 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2612 check_wnd_state(hwnd2, thread_params.window, hwnd2, 0);
2614 SetForegroundWindow(hwnd2);
2615 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2617 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
2618 if (0) check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2619 todo_wine ok(GetActiveWindow() == hwnd2, "Expected active window %p, got %p.\n", hwnd2, GetActiveWindow());
2620 todo_wine ok(GetFocus() == hwnd2, "Expected focus window %p, got %p.\n", hwnd2, GetFocus());
2622 SetEvent(thread_params.test_finished);
2623 WaitForSingleObject(thread, INFINITE);
2624 CloseHandle(thread_params.test_finished);
2625 CloseHandle(thread_params.window_created);
2626 CloseHandle(thread);
2627 DestroyWindow(hwnd2);
2630 static WNDPROC old_button_proc;
2632 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2637 key_state = GetKeyState(VK_LBUTTON);
2638 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2640 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2642 if (msg == WM_LBUTTONDOWN)
2646 check_wnd_state(button, button, button, button);
2648 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2650 trace("hwnd %p\n", hwnd);
2652 check_wnd_state(button, button, button, button);
2654 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2656 check_wnd_state(button, button, button, button);
2658 DestroyWindow(hwnd);
2660 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2662 trace("hwnd %p\n", hwnd);
2664 check_wnd_state(button, button, button, button);
2666 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2667 * match internal button state.
2669 SendMessage(button, WM_KILLFOCUS, 0, 0);
2670 check_wnd_state(button, button, button, 0);
2672 ShowWindow(hwnd, SW_SHOW);
2673 check_wnd_state(hwnd, hwnd, hwnd, 0);
2675 capture = SetCapture(hwnd);
2676 ok(capture == 0, "SetCapture() = %p\n", capture);
2678 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2680 DestroyWindow(hwnd);
2682 check_wnd_state(button, 0, button, 0);
2688 static void test_capture_1(void)
2690 HWND button, capture, oldFocus, oldActive;
2692 oldFocus = GetFocus();
2693 oldActive = GetActiveWindow();
2695 capture = GetCapture();
2696 ok(capture == 0, "GetCapture() = %p\n", capture);
2698 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2700 trace("button %p\n", button);
2702 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2704 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2706 capture = SetCapture(button);
2707 ok(capture == 0, "SetCapture() = %p\n", capture);
2708 check_wnd_state(button, 0, button, button);
2710 DestroyWindow(button);
2711 check_wnd_state(oldActive, 0, oldFocus, 0);
2714 static void test_capture_2(void)
2716 HWND button, hwnd, capture, oldFocus, oldActive;
2718 oldFocus = GetFocus();
2719 oldActive = GetActiveWindow();
2720 check_wnd_state(oldActive, 0, oldFocus, 0);
2722 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2724 trace("button %p\n", button);
2726 check_wnd_state(button, button, button, 0);
2728 capture = SetCapture(button);
2729 ok(capture == 0, "SetCapture() = %p\n", capture);
2731 check_wnd_state(button, button, button, button);
2733 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2734 * internal button state.
2736 SendMessage(button, WM_KILLFOCUS, 0, 0);
2737 check_wnd_state(button, button, button, button);
2739 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2741 trace("hwnd %p\n", hwnd);
2743 check_wnd_state(button, button, button, button);
2745 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2747 check_wnd_state(button, button, button, button);
2749 DestroyWindow(hwnd);
2751 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2753 trace("hwnd %p\n", hwnd);
2755 check_wnd_state(button, button, button, button);
2757 ShowWindow(hwnd, SW_SHOW);
2759 check_wnd_state(hwnd, hwnd, hwnd, button);
2761 capture = SetCapture(hwnd);
2762 ok(capture == button, "SetCapture() = %p\n", capture);
2764 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2766 DestroyWindow(hwnd);
2767 check_wnd_state(button, button, button, 0);
2769 DestroyWindow(button);
2770 check_wnd_state(oldActive, 0, oldFocus, 0);
2773 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2777 ShowWindow(hwnd1, SW_HIDE);
2778 ShowWindow(hwnd2, SW_HIDE);
2780 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2781 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2784 check_wnd_state(0, 0, 0, hwnd1);
2787 check_wnd_state(0, 0, 0, hwnd2);
2789 ShowWindow(hwnd1, SW_SHOW);
2790 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2792 ret = ReleaseCapture();
2793 ok (ret, "releasecapture did not return TRUE.\n");
2794 ret = ReleaseCapture();
2795 ok (ret, "releasecapture did not return TRUE after second try.\n");
2798 static LRESULT CALLBACK test_capture_4_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2801 HWND cap_wnd, cap_wnd2, set_cap_wnd;
2805 case WM_CAPTURECHANGED:
2807 /* now try to release capture from menu. this should fail */
2808 if (pGetGUIThreadInfo)
2810 memset(>i, 0, sizeof(GUITHREADINFO));
2811 gti.cbSize = sizeof(GUITHREADINFO);
2812 status = pGetGUIThreadInfo(GetCurrentThreadId(), >i);
2813 ok(status, "GetGUIThreadInfo() failed!\n");
2814 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
2816 cap_wnd = GetCapture();
2818 /* check that re-setting the capture for the menu fails */
2819 set_cap_wnd = SetCapture(cap_wnd);
2820 ok(!set_cap_wnd || broken(set_cap_wnd == cap_wnd), /* nt4 */
2821 "SetCapture should have failed!\n");
2824 DestroyWindow(hWnd);
2828 /* check that SetCapture fails for another window and that it does not touch the error code */
2829 set_cap_wnd = SetCapture(hWnd);
2830 ok(!set_cap_wnd, "SetCapture should have failed!\n");
2832 /* check that ReleaseCapture fails and does not touch the error code */
2833 status = ReleaseCapture();
2834 ok(!status, "ReleaseCapture should have failed!\n");
2836 /* check that thread info did not change */
2837 if (pGetGUIThreadInfo)
2839 memset(>i, 0, sizeof(GUITHREADINFO));
2840 gti.cbSize = sizeof(GUITHREADINFO);
2841 status = pGetGUIThreadInfo(GetCurrentThreadId(), >i);
2842 ok(status, "GetGUIThreadInfo() failed!\n");
2843 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
2846 /* verify that no capture change took place */
2847 cap_wnd2 = GetCapture();
2848 ok(cap_wnd2 == cap_wnd, "Capture changed!\n");
2850 /* we are done. kill the window */
2851 DestroyWindow(hWnd);
2855 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
2860 /* Test that no-one can mess around with the current capture while a menu is open */
2861 static void test_capture_4(void)
2867 HINSTANCE hInstance = GetModuleHandleA( NULL );
2869 if (!pGetGUIThreadInfo)
2871 win_skip("GetGUIThreadInfo is not available\n");
2874 wclass.lpszClassName = "TestCapture4Class";
2875 wclass.style = CS_HREDRAW | CS_VREDRAW;
2876 wclass.lpfnWndProc = test_capture_4_proc;
2877 wclass.hInstance = hInstance;
2878 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
2879 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
2880 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2881 wclass.lpszMenuName = 0;
2882 wclass.cbClsExtra = 0;
2883 wclass.cbWndExtra = 0;
2884 assert (RegisterClassA( &wclass ));
2885 assert (hwnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
2886 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2887 400, 200, NULL, NULL, hInstance, NULL) );
2888 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
2890 hmenu = CreatePopupMenu();
2892 ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest2");
2893 ok( ret, "AppendMenuA has failed!\n");
2895 /* set main window to have initial capture */
2900 win_skip("TrackPopupMenu test crashes on Win9x/WinMe\n");
2904 /* create popup (it will self-destruct) */
2905 ret = TrackPopupMenu(hmenu, TPM_RETURNCMD, 100, 100, 0, hwnd, NULL);
2906 ok( ret == 0, "TrackPopupMenu returned %d expected zero\n", ret);
2911 DestroyWindow(hwnd);
2914 /* PeekMessage wrapper that ignores the messages we don't care about */
2915 static BOOL peek_message( MSG *msg )
2920 ret = PeekMessageA(msg, 0, 0, 0, PM_REMOVE);
2921 } while (ret && (msg->message == WM_TIMER || ignore_message(msg->message)));
2925 static void test_keyboard_input(HWND hwnd)
2930 flush_events( TRUE );
2931 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
2933 flush_events( TRUE );
2935 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2938 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2940 flush_events( TRUE );
2942 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2943 ret = peek_message(&msg);
2944 ok( ret, "no message available\n");
2945 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2946 ret = peek_message(&msg);
2947 ok( !ret, "message %04x available\n", msg.message);
2949 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2951 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2952 ret = peek_message(&msg);
2953 ok(ret, "no message available\n");
2954 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2955 ret = peek_message(&msg);
2956 ok( !ret, "message %04x available\n", msg.message);
2958 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2960 keybd_event(VK_SPACE, 0, 0, 0);
2961 if (!peek_message(&msg))
2963 skip( "keybd_event didn't work, skipping keyboard test\n" );
2966 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2967 ret = peek_message(&msg);
2968 ok( !ret, "message %04x available\n", msg.message);
2971 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2973 flush_events( TRUE );
2975 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2976 ret = peek_message(&msg);
2977 ok(ret, "no message available\n");
2978 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2979 ret = peek_message(&msg);
2980 ok( !ret, "message %04x available\n", msg.message);
2982 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2984 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2985 ret = peek_message(&msg);
2986 ok(ret, "no message available\n");
2987 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2988 ret = peek_message(&msg);
2989 ok( !ret, "message %04x available\n", msg.message);
2991 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2993 keybd_event(VK_SPACE, 0, 0, 0);
2994 ret = peek_message(&msg);
2995 ok(ret, "no message available\n");
2996 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2997 ret = peek_message(&msg);
2998 ok( !ret, "message %04x available\n", msg.message);
3001 static BOOL wait_for_message( MSG *msg )
3007 ret = peek_message(msg);
3010 if (msg->message == WM_PAINT) DispatchMessage(msg);
3013 else if (MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
3015 if (!ret) msg->message = 0;
3019 static void test_mouse_input(HWND hwnd)
3029 ShowWindow(hwnd, SW_SHOWNORMAL);
3031 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3033 GetWindowRect(hwnd, &rc);
3034 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
3036 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
3037 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
3040 ShowWindow(popup, SW_SHOW);
3041 UpdateWindow(popup);
3042 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3044 GetWindowRect(popup, &rc);
3045 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
3047 x = rc.left + (rc.right - rc.left) / 2;
3048 y = rc.top + (rc.bottom - rc.top) / 2;
3049 trace("setting cursor to (%d,%d)\n", x, y);
3053 if (x != pt.x || y != pt.y)
3055 skip( "failed to set mouse position, skipping mouse input tests\n" );
3059 flush_events( TRUE );
3061 /* Check that setting the same position may generate WM_MOUSEMOVE */
3064 ret = peek_message(&msg);
3067 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
3068 msg.hwnd, msg.message);
3069 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
3070 x, y, msg.pt.x, msg.pt.y);
3073 /* force the system to update its internal queue mouse position,
3074 * otherwise it won't generate relative mouse movements below.
3076 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3077 flush_events( TRUE );
3080 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3081 flush_events( FALSE );
3082 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
3083 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
3085 if (msg.message == WM_TIMER || ignore_message(msg.message)) continue;
3086 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
3087 "hwnd %p message %04x\n", msg.hwnd, msg.message);
3088 DispatchMessage(&msg);
3090 ret = peek_message(&msg);
3091 ok( !ret, "message %04x available\n", msg.message);
3093 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3094 ShowWindow(popup, SW_HIDE);
3095 ret = wait_for_message( &msg );
3097 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3098 flush_events( TRUE );
3100 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3101 ShowWindow(hwnd, SW_HIDE);
3102 ret = wait_for_message( &msg );
3103 ok( !ret, "message %04x available\n", msg.message);
3104 flush_events( TRUE );
3106 /* test mouse clicks */
3108 ShowWindow(hwnd, SW_SHOW);
3109 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3110 flush_events( TRUE );
3111 ShowWindow(popup, SW_SHOW);
3112 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3113 flush_events( TRUE );
3115 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3116 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3117 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3118 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3120 ret = wait_for_message( &msg );
3123 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
3126 if (msg.message == WM_MOUSEMOVE) /* win2k has an extra WM_MOUSEMOVE here */
3128 ret = wait_for_message( &msg );
3129 ok(ret, "no message available\n");
3132 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3133 msg.hwnd, popup, msg.message);
3135 ret = wait_for_message( &msg );
3136 ok(ret, "no message available\n");
3137 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3138 msg.hwnd, popup, msg.message);
3140 ret = wait_for_message( &msg );
3141 ok(ret, "no message available\n");
3142 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
3143 msg.hwnd, popup, msg.message);
3145 ret = wait_for_message( &msg );
3146 ok(ret, "no message available\n");
3147 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3148 msg.hwnd, popup, msg.message);
3150 ret = peek_message(&msg);
3151 ok(!ret, "message %04x available\n", msg.message);
3153 ShowWindow(popup, SW_HIDE);
3154 flush_events( TRUE );
3156 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3157 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3158 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3159 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3161 ret = wait_for_message( &msg );
3162 ok(ret, "no message available\n");
3163 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3164 msg.hwnd, hwnd, msg.message);
3165 ret = wait_for_message( &msg );
3166 ok(ret, "no message available\n");
3167 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3168 msg.hwnd, hwnd, msg.message);
3170 test_lbuttondown_flag = TRUE;
3171 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
3172 test_lbuttondown_flag = FALSE;
3174 ret = wait_for_message( &msg );
3175 ok(ret, "no message available\n");
3176 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3177 msg.hwnd, popup, msg.message);
3178 ok(peek_message(&msg), "no message available\n");
3179 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3180 msg.hwnd, popup, msg.message);
3181 ok(peek_message(&msg), "no message available\n");
3183 /* Test WM_MOUSEACTIVATE */
3184 #define TEST_MOUSEACTIVATE(A,B) \
3185 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
3186 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
3188 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
3189 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
3190 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
3191 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
3192 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
3193 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
3194 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
3195 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
3196 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
3197 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
3198 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
3199 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
3200 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
3201 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
3202 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
3203 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
3204 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
3205 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
3206 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
3207 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
3208 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
3209 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
3210 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
3211 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
3214 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
3215 flush_events( TRUE );
3217 DestroyWindow(popup);
3220 static void test_validatergn(HWND hwnd)
3226 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
3227 ShowWindow(hwnd, SW_SHOW);
3228 UpdateWindow( hwnd);
3229 /* test that ValidateRect validates children*/
3230 InvalidateRect( child, NULL, 1);
3231 GetWindowRect( child, &rc);
3232 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3233 ret = GetUpdateRect( child, &rc2, 0);
3234 ok( ret == 1, "Expected GetUpdateRect to return non-zero, got %d\n", ret);
3235 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
3236 "Update rectangle is empty!\n");
3237 ValidateRect( hwnd, &rc);
3238 ret = GetUpdateRect( child, &rc2, 0);
3239 ok( !ret, "Expected GetUpdateRect to return zero, got %d\n", ret);
3240 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3241 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3242 rc2.right, rc2.bottom);
3244 /* now test ValidateRgn */
3245 InvalidateRect( child, NULL, 1);
3246 GetWindowRect( child, &rc);
3247 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3248 rgn = CreateRectRgnIndirect( &rc);
3249 ValidateRgn( hwnd, rgn);
3250 ret = GetUpdateRect( child, &rc2, 0);
3251 ok( !ret, "Expected GetUpdateRect to return zero, got %d\n", ret);
3252 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3253 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3254 rc2.right, rc2.bottom);
3257 DestroyWindow( child );
3260 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
3263 MoveWindow( hwnd, 0, 0, x, y, 0);
3264 GetWindowRect( hwnd, prc);
3266 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
3267 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
3268 rc.left,rc.top,rc.right,rc.bottom, prc->left,prc->top,prc->right,prc->bottom);
3271 static void test_nccalcscroll(HWND parent)
3274 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
3275 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
3276 HWND hwnd = CreateWindowExA(0, "static", NULL,
3277 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
3278 10, 10, 200, 200, parent, 0, 0, NULL);
3279 ShowWindow( parent, SW_SHOW);
3280 UpdateWindow( parent);
3282 /* test window too low for a horizontal scroll bar */
3283 nccalchelper( hwnd, 100, sbheight, &rc1);
3284 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
3285 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
3287 /* test window just high enough for a horizontal scroll bar */
3288 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
3289 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
3290 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3292 /* test window too narrow for a vertical scroll bar */
3293 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
3294 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
3295 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3297 /* test window just wide enough for a vertical scroll bar */
3298 nccalchelper( hwnd, sbwidth, 100, &rc1);
3299 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
3300 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
3302 /* same test, but with client edge: not enough width */
3303 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
3304 nccalchelper( hwnd, sbwidth, 100, &rc1);
3305 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
3306 "Width should be %d size is %d,%d - %d,%d\n",
3307 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
3309 DestroyWindow( hwnd);
3312 static void test_SetParent(void)
3315 HWND desktop = GetDesktopWindow();
3317 HWND parent, child1, child2, child3, child4, sibling;
3319 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3320 100, 100, 200, 200, 0, 0, 0, NULL);
3321 assert(parent != 0);
3322 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3323 0, 0, 50, 50, parent, 0, 0, NULL);
3324 assert(child1 != 0);
3325 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3326 0, 0, 50, 50, child1, 0, 0, NULL);
3327 assert(child2 != 0);
3328 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3329 0, 0, 50, 50, child2, 0, 0, NULL);
3330 assert(child3 != 0);
3331 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3332 0, 0, 50, 50, child3, 0, 0, NULL);
3333 assert(child4 != 0);
3335 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
3336 parent, child1, child2, child3, child4);
3338 check_parents(parent, desktop, 0, 0, 0, parent, parent);
3339 check_parents(child1, parent, parent, parent, 0, parent, parent);
3340 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3341 check_parents(child3, child2, child2, child2, 0, child2, parent);
3342 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3344 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
3345 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
3346 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3347 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
3348 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3350 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
3351 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3352 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
3353 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
3354 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
3355 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
3356 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
3357 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3358 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3360 if (!is_win9x) /* Win9x doesn't survive this test */
3364 ok(!SetParent(parent, child1), "SetParent should fail\n");
3365 ok(!SetParent(child2, child3), "SetParent should fail\n");
3366 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
3367 ret = SetParent(parent, child2);
3368 todo_wine ok( !ret || broken( ret != 0 ), "SetParent should fail\n");
3369 if (ret) /* nt4, win2k */
3371 ret = SetParent(parent, child3);
3372 ok(ret != 0, "SetParent should not fail\n");
3373 ret = SetParent(child2, parent);
3374 ok(!ret, "SetParent should fail\n");
3375 ret = SetParent(parent, child4);
3376 ok(ret != 0, "SetParent should not fail\n");
3377 check_parents(parent, child4, child4, 0, 0, child4, parent);
3378 check_parents(child1, parent, parent, parent, 0, child4, parent);
3379 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3380 check_parents(child3, child2, child2, child2, 0, child2, parent);
3381 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3385 ret = SetParent(parent, child3);
3386 ok(ret != 0, "SetParent should not fail\n");
3387 ret = SetParent(child2, parent);
3388 ok(!ret, "SetParent should fail\n");
3389 ret = SetParent(parent, child4);
3390 ok(!ret, "SetParent should fail\n");
3391 check_parents(parent, child3, child3, 0, 0, child2, parent);
3392 check_parents(child1, parent, parent, parent, 0, child2, parent);
3393 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3394 check_parents(child3, child2, child2, child2, 0, child2, parent);
3395 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3399 skip("Win9x/WinMe crash\n");
3401 hMenu = CreateMenu();
3402 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3403 100, 100, 200, 200, 0, hMenu, 0, NULL);
3404 assert(sibling != 0);
3406 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
3407 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
3409 ret = DestroyWindow(parent);
3410 ok( ret, "DestroyWindow() error %d\n", GetLastError());
3412 ok(!IsWindow(parent), "parent still exists\n");
3413 ok(!IsWindow(sibling), "sibling still exists\n");
3414 ok(!IsWindow(child1), "child1 still exists\n");
3415 ok(!IsWindow(child2), "child2 still exists\n");
3416 ok(!IsWindow(child3), "child3 still exists\n");
3417 ok(!IsWindow(child4), "child4 still exists\n");
3420 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3422 LPCREATESTRUCT lpcs;
3429 lpcs = (LPCREATESTRUCT)lparam;
3430 lpss = lpcs->lpCreateParams;
3433 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
3434 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
3435 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
3436 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
3438 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3440 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
3441 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
3442 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
3444 ok(lpss->styleNew == lpcs->style,
3445 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3446 lpss->styleNew, lpcs->style);
3450 return DefWindowProc(hwnd, msg, wparam, lparam);
3453 static ATOM atomStyleCheckClass;
3455 static void register_style_check_class(void)
3463 GetModuleHandle(NULL),
3465 LoadCursor(NULL, IDC_ARROW),
3466 (HBRUSH)(COLOR_BTNFACE+1),
3468 TEXT("WineStyleCheck"),
3471 atomStyleCheckClass = RegisterClass(&wc);
3474 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3476 DWORD dwActualStyle;
3477 DWORD dwActualExStyle;
3480 HWND hwndParent = NULL;
3482 ss.styleNew = dwStyleIn;
3483 ss.styleOld = dwExStyleIn;
3485 if (dwStyleIn & WS_CHILD)
3487 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
3488 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3491 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
3492 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3495 flush_events( TRUE );
3497 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3498 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3499 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3500 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3501 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3503 /* try setting the styles explicitly */
3504 SetWindowLong( hwnd, GWL_EXSTYLE, dwExStyleIn );
3505 SetWindowLong( hwnd, GWL_STYLE, dwStyleIn );
3506 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3507 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3508 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3509 if (dwStyleIn & WS_CHILD) dwStyleOut = dwStyleIn;
3510 else dwStyleOut = dwStyleIn | WS_CLIPSIBLINGS;
3511 /* WS_EX_WINDOWEDGE can't always be changed */
3512 if ((dwExStyleIn & WS_EX_DLGMODALFRAME) || (dwStyleIn & WS_THICKFRAME))
3513 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3514 else if (dwStyleIn & (WS_CHILD | WS_POPUP))
3515 dwExStyleOut = dwExStyleIn & ~WS_EX_WINDOWEDGE;
3517 dwExStyleOut = dwExStyleIn;
3518 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3519 "%08x/%08x: Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3520 dwStyleIn, dwExStyleIn, dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3522 DestroyWindow(hwnd);
3523 if (hwndParent) DestroyWindow(hwndParent);
3526 /* tests what window styles the window manager automatically adds */
3527 static void test_window_styles(void)
3529 register_style_check_class();
3531 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3532 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3533 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3534 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3535 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3536 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3537 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3538 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3539 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3540 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3541 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3543 if (pGetLayeredWindowAttributes)
3545 check_window_style(0, WS_EX_LAYERED, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_WINDOWEDGE);
3546 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_WINDOWEDGE);
3547 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION,
3548 WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW|WS_EX_WINDOWEDGE);
3552 static void test_scrollwindow( HWND hwnd)
3558 ShowWindow( hwnd, SW_SHOW);
3559 UpdateWindow( hwnd);
3560 flush_events( TRUE );
3561 GetClientRect( hwnd, &rc);
3563 /* test ScrollWindow(Ex) with no clip rectangle */
3564 /* paint the lower half of the window black */
3566 rc2.top = ( rc2.top + rc2.bottom) / 2;
3567 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3568 /* paint the upper half of the window white */
3569 rc2.bottom = rc2.top;
3571 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
3572 /* scroll lower half up */
3574 rc2.top = ( rc2.top + rc2.bottom) / 2;
3575 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, NULL, NULL, NULL, SW_ERASE);
3576 flush_events(FALSE);
3577 /* expected: black should have scrolled to the upper half */
3578 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
3579 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3580 /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
3581 /* paint the lower half of the window black */
3583 rc2.top = ( rc2.top + rc2.bottom) / 2;
3584 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3585 /* paint the upper half of the window white */
3586 rc2.bottom = rc2.top;
3588 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
3589 /* scroll lower half up */
3591 rc2.top = ( rc2.top + rc2.bottom) / 2;
3593 rc3.left = rc3.right / 4;
3594 rc3.right -= rc3.right / 4;
3595 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, &rc3, NULL, NULL, SW_ERASE);
3596 flush_events(FALSE);
3597 /* expected: black should have scrolled to the upper half */
3598 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
3599 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3602 ReleaseDC( hwnd, hdc);
3605 static void test_scrollvalidate( HWND parent)
3608 HRGN hrgn=CreateRectRgn(0,0,0,0);
3609 HRGN exprgn, tmprgn, clipping;
3610 RECT rc, rcu, cliprc;
3611 /* create two overlapping child windows. The visual region
3612 * of hwnd1 is clipped by the overlapping part of
3613 * hwnd2 because of the WS_CLIPSIBLING style */
3616 clipping = CreateRectRgn(0,0,0,0);
3617 tmprgn = CreateRectRgn(0,0,0,0);
3618 exprgn = CreateRectRgn(0,0,0,0);
3619 hwnd2 = CreateWindowExA(0, "static", NULL,
3620 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3621 75, 30, 100, 100, parent, 0, 0, NULL);
3622 hwnd1 = CreateWindowExA(0, "static", NULL,
3623 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3624 25, 50, 100, 100, parent, 0, 0, NULL);
3625 ShowWindow( parent, SW_SHOW);
3626 UpdateWindow( parent);
3627 GetClientRect( hwnd1, &rc);
3629 SetRectRgn( clipping, 10, 10, 90, 90);
3630 hdc = GetDC( hwnd1);
3631 /* for a visual touch */
3632 TextOut( hdc, 0,10, "0123456789", 10);
3633 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3634 if (winetest_debug > 0) dump_region(hrgn);
3635 /* create a region with what is expected */
3636 SetRectRgn( exprgn, 39,0,49,74);
3637 SetRectRgn( tmprgn, 88,79,98,93);
3638 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3639 SetRectRgn( tmprgn, 0,93,98,98);
3640 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3641 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3642 trace("update rect is %d,%d - %d,%d\n",
3643 rcu.left,rcu.top,rcu.right,rcu.bottom);
3644 /* now with clipping region */
3645 SelectClipRgn( hdc, clipping);
3646 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3647 if (winetest_debug > 0) dump_region(hrgn);
3648 /* create a region with what is expected */
3649 SetRectRgn( exprgn, 39,10,49,74);
3650 SetRectRgn( tmprgn, 80,79,90,85);
3651 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3652 SetRectRgn( tmprgn, 10,85,90,90);
3653 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3654 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3655 trace("update rect is %d,%d - %d,%d\n",
3656 rcu.left,rcu.top,rcu.right,rcu.bottom);
3657 ReleaseDC( hwnd1, hdc);
3659 /* test scrolling a window with an update region */
3660 DestroyWindow( hwnd2);
3661 ValidateRect( hwnd1, NULL);
3662 SetRect( &rc, 40,40, 50,50);
3663 InvalidateRect( hwnd1, &rc, 1);
3664 GetClientRect( hwnd1, &rc);
3666 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
3667 SW_SCROLLCHILDREN | SW_INVALIDATE);
3668 if (winetest_debug > 0) dump_region(hrgn);
3669 SetRectRgn( exprgn, 88,0,98,98);
3670 SetRectRgn( tmprgn, 30, 40, 50, 50);
3671 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3672 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3674 /* clear an update region */
3675 UpdateWindow( hwnd1 );
3677 SetRect( &rc, 0,40, 100,60);
3678 SetRect( &cliprc, 0,0, 100,100);
3679 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3680 if (winetest_debug > 0) dump_region( hrgn );
3681 SetRectRgn( exprgn, 0, 40, 98, 60 );
3682 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
3684 /* now test ScrollWindowEx with a combination of
3685 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3686 /* make hwnd2 the child of hwnd1 */
3687 hwnd2 = CreateWindowExA(0, "static", NULL,
3688 WS_CHILD| WS_VISIBLE | WS_BORDER ,
3689 50, 50, 100, 100, hwnd1, 0, 0, NULL);
3690 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
3691 GetClientRect( hwnd1, &rc);
3694 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3695 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3696 ValidateRect( hwnd1, NULL);
3697 ValidateRect( hwnd2, NULL);
3698 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
3699 SW_SCROLLCHILDREN | SW_INVALIDATE);
3700 if (winetest_debug > 0) dump_region(hrgn);
3701 SetRectRgn( exprgn, 88,0,98,88);
3702 SetRectRgn( tmprgn, 0,88,98,98);
3703 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3704 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3706 /* SW_SCROLLCHILDREN */
3707 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3708 ValidateRect( hwnd1, NULL);
3709 ValidateRect( hwnd2, NULL);
3710 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3711 if (winetest_debug > 0) dump_region(hrgn);
3712 /* expected region is the same as in previous test */
3713 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3715 /* no SW_SCROLLCHILDREN */
3716 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3717 ValidateRect( hwnd1, NULL);
3718 ValidateRect( hwnd2, NULL);
3719 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3720 if (winetest_debug > 0) dump_region(hrgn);
3721 /* expected region is the same as in previous test */
3722 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3724 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3725 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3726 ValidateRect( hwnd1, NULL);
3727 ValidateRect( hwnd2, NULL);
3728 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3729 if (winetest_debug > 0) dump_region(hrgn);
3730 SetRectRgn( exprgn, 88,0,98,20);
3731 SetRectRgn( tmprgn, 20,20,98,30);
3732 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3733 SetRectRgn( tmprgn, 20,30,30,88);
3734 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3735 SetRectRgn( tmprgn, 0,88,30,98);
3736 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3737 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3740 DeleteObject( hrgn);
3741 DeleteObject( exprgn);
3742 DeleteObject( tmprgn);
3743 DestroyWindow( hwnd1);
3744 DestroyWindow( hwnd2);
3747 /* couple of tests of return values of scrollbar functions
3748 * called on a scrollbarless window */
3749 static void test_scroll(void)
3754 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3755 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3756 100, 100, 200, 200, 0, 0, 0, NULL);
3758 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3759 if (!ret) /* win9x */
3761 win_skip( "GetScrollRange doesn't work\n" );
3762 DestroyWindow( hwnd);
3765 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3766 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3767 si.cbSize = sizeof( si);
3768 si.fMask = SIF_PAGE;
3769 si.nPage = 0xdeadbeef;
3770 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3771 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3772 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3774 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3775 ok( ret, "GetScrollRange returns FALSE\n");
3776 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3777 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3778 si.cbSize = sizeof( si);
3779 si.fMask = SIF_PAGE;
3780 si.nPage = 0xdeadbeef;
3781 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3782 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3783 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3785 DestroyWindow( hwnd);
3788 static void test_scrolldc( HWND parent)
3791 HRGN exprgn, tmprgn, hrgn;
3792 RECT rc, rc2, rcu, cliprc;
3796 hrgn = CreateRectRgn(0,0,0,0);
3797 tmprgn = CreateRectRgn(0,0,0,0);
3798 exprgn = CreateRectRgn(0,0,0,0);
3800 hwnd1 = CreateWindowExA(0, "static", NULL,
3801 WS_CHILD| WS_VISIBLE,
3802 25, 50, 100, 100, parent, 0, 0, NULL);
3803 ShowWindow( parent, SW_SHOW);
3804 UpdateWindow( parent);
3805 flush_events( TRUE );
3806 GetClientRect( hwnd1, &rc);
3807 hdc = GetDC( hwnd1);
3808 /* paint the upper half of the window black */
3810 rc2.bottom = ( rc.top + rc.bottom) /2;
3811 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3812 /* clip region is the lower half */
3814 cliprc.top = (rc.top + rc.bottom) /2;
3815 /* test whether scrolled pixels are properly clipped */
3816 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3817 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3818 /* this scroll should not cause any visible changes */
3819 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3820 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3821 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3822 /* test with NULL clip rect */
3823 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3824 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3825 trace("update rect: %d,%d - %d,%d\n",
3826 rcu.left, rcu.top, rcu.right, rcu.bottom);
3827 if (winetest_debug > 0) dump_region(hrgn);
3828 SetRect(&rc2, 0, 0, 100, 100);
3829 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3830 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3832 SetRectRgn( exprgn, 0, 0, 20, 80);
3833 SetRectRgn( tmprgn, 0, 80, 100, 100);
3834 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3835 if (winetest_debug > 0) dump_region(exprgn);
3836 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3837 /* test clip rect > scroll rect */
3838 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3840 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3841 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3842 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3843 SetRectRgn( exprgn, 25, 25, 75, 35);
3844 SetRectRgn( tmprgn, 25, 35, 35, 75);
3845 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3846 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3847 trace("update rect: %d,%d - %d,%d\n",
3848 rcu.left, rcu.top, rcu.right, rcu.bottom);
3849 if (winetest_debug > 0) dump_region(hrgn);
3853 DeleteObject(exprgn);
3854 DeleteObject(tmprgn);
3855 DestroyWindow(hwnd1);
3858 static void test_params(void)
3863 /* Just a param check */
3864 if (pGetMonitorInfoA)
3866 SetLastError(0xdeadbeef);
3867 rc = GetWindowText(hwndMain2, NULL, 1024);
3868 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
3872 /* Skips actually on Win95 and NT4 */
3873 win_skip("Test would crash on Win95\n");
3876 SetLastError(0xdeadbeef);
3877 hwnd=CreateWindow("LISTBOX", "TestList",
3878 (LBS_STANDARD & ~LBS_SORT),
3880 NULL, (HMENU)1, NULL, 0);
3882 ok(!hwnd || broken(hwnd != NULL), /* w2k3 sp2 */
3883 "CreateWindow with invalid menu handle should fail\n");
3885 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3886 GetLastError() == 0xdeadbeef, /* Win9x */
3887 "wrong last error value %d\n", GetLastError());
3890 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3894 hwnd = CreateWindowEx(exStyle, class, class, style,
3901 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
3904 ShowWindow(hwnd, SW_SHOW);
3906 test_nonclient_area(hwnd);
3909 DestroyWindow(hwnd);
3912 static BOOL AWR_init(void)
3916 class.style = CS_HREDRAW | CS_VREDRAW;
3917 class.lpfnWndProc = DefWindowProcA;
3918 class.cbClsExtra = 0;
3919 class.cbWndExtra = 0;
3920 class.hInstance = 0;
3921 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3922 class.hCursor = LoadCursor (0, IDC_ARROW);
3923 class.hbrBackground = 0;
3924 class.lpszMenuName = 0;
3925 class.lpszClassName = szAWRClass;
3927 if (!RegisterClass (&class)) {
3928 ok(FALSE, "RegisterClass failed\n");
3932 hmenu = CreateMenu();
3935 ok(hmenu != 0, "Failed to create menu\n");
3936 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3942 static void test_AWR_window_size(BOOL menu)
3946 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3949 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3950 WS_HSCROLL, WS_VSCROLL
3954 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3957 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3958 WS_EX_DLGMODALFRAME,
3965 /* A exhaustive check of all the styles takes too long
3966 * so just do a (hopefully representative) sample
3968 for (i = 0; i < COUNTOF(styles); ++i)
3969 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3970 for (i = 0; i < COUNTOF(exStyles); ++i) {
3971 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3972 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3977 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3979 static void test_AdjustWindowRect(void)
3984 SHOWSYSMETRIC(SM_CYCAPTION);
3985 SHOWSYSMETRIC(SM_CYSMCAPTION);
3986 SHOWSYSMETRIC(SM_CYMENU);
3987 SHOWSYSMETRIC(SM_CXEDGE);
3988 SHOWSYSMETRIC(SM_CYEDGE);
3989 SHOWSYSMETRIC(SM_CXVSCROLL);
3990 SHOWSYSMETRIC(SM_CYHSCROLL);
3991 SHOWSYSMETRIC(SM_CXFRAME);
3992 SHOWSYSMETRIC(SM_CYFRAME);
3993 SHOWSYSMETRIC(SM_CXDLGFRAME);
3994 SHOWSYSMETRIC(SM_CYDLGFRAME);
3995 SHOWSYSMETRIC(SM_CXBORDER);
3996 SHOWSYSMETRIC(SM_CYBORDER);
3998 test_AWR_window_size(FALSE);
3999 test_AWR_window_size(TRUE);
4003 #undef SHOWSYSMETRIC
4006 /* Global variables to trigger exit from loop */
4007 static int redrawComplete, WMPAINT_count;
4009 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4014 trace("doing WM_PAINT %d\n", WMPAINT_count);
4016 if (WMPAINT_count > 10 && redrawComplete == 0) {
4018 BeginPaint(hwnd, &ps);
4019 EndPaint(hwnd, &ps);
4024 return DefWindowProc(hwnd, msg, wparam, lparam);
4027 /* Ensure we exit from RedrawNow regardless of invalidated area */
4028 static void test_redrawnow(void)
4033 cls.style = CS_DBLCLKS;
4034 cls.lpfnWndProc = redraw_window_procA;
4037 cls.hInstance = GetModuleHandleA(0);
4039 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4040 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4041 cls.lpszMenuName = NULL;
4042 cls.lpszClassName = "RedrawWindowClass";
4044 if(!RegisterClassA(&cls)) {
4045 trace("Register failed %d\n", GetLastError());
4049 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
4050 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
4052 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4053 ShowWindow(hwndMain, SW_SHOW);
4054 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4055 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
4056 ok( WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
4057 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4058 redrawComplete = TRUE;
4059 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
4062 DestroyWindow( hwndMain);
4065 struct parentdc_stat {
4071 struct parentdc_test {
4072 struct parentdc_stat main, main_todo;
4073 struct parentdc_stat child1, child1_todo;
4074 struct parentdc_stat child2, child2_todo;
4077 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4082 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
4087 GetClientRect(hwnd, &rc);
4088 CopyRect(&t->client, &rc);
4089 GetWindowRect(hwnd, &rc);
4090 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd,
4091 t->client.left, t->client.top, t->client.right, t->client.bottom,
4092 rc.left, rc.top, rc.right, rc.bottom);
4093 BeginPaint(hwnd, &ps);
4094 CopyRect(&t->paint, &ps.rcPaint);
4095 GetClipBox(ps.hdc, &rc);
4096 CopyRect(&t->clip, &rc);
4097 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
4098 rc.left, rc.top, rc.right, rc.bottom,
4099 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
4100 EndPaint(hwnd, &ps);
4103 return DefWindowProc(hwnd, msg, wparam, lparam);
4106 static void zero_parentdc_stat(struct parentdc_stat *t)
4108 SetRectEmpty(&t->client);
4109 SetRectEmpty(&t->clip);
4110 SetRectEmpty(&t->paint);
4113 static void zero_parentdc_test(struct parentdc_test *t)
4115 zero_parentdc_stat(&t->main);
4116 zero_parentdc_stat(&t->child1);
4117 zero_parentdc_stat(&t->child2);
4120 #define parentdc_field_ok(t, w, r, f, got) \
4121 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
4122 ": expected %d, got %d\n", \
4125 #define parentdc_todo_field_ok(t, w, r, f, got) \
4126 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
4127 else parentdc_field_ok(t, w, r, f, got)
4129 #define parentdc_rect_ok(t, w, r, got) \
4130 parentdc_todo_field_ok(t, w, r, left, got); \
4131 parentdc_todo_field_ok(t, w, r, top, got); \
4132 parentdc_todo_field_ok(t, w, r, right, got); \
4133 parentdc_todo_field_ok(t, w, r, bottom, got);
4135 #define parentdc_win_ok(t, w, got) \
4136 parentdc_rect_ok(t, w, client, got); \
4137 parentdc_rect_ok(t, w, clip, got); \
4138 parentdc_rect_ok(t, w, paint, got);
4140 #define parentdc_ok(t, got) \
4141 parentdc_win_ok(t, main, got); \
4142 parentdc_win_ok(t, child1, got); \
4143 parentdc_win_ok(t, child2, got);
4145 static void test_csparentdc(void)
4147 WNDCLASSA clsMain, cls;
4148 HWND hwndMain, hwnd1, hwnd2;
4151 struct parentdc_test test_answer;
4153 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
4154 const struct parentdc_test test1 =
4156 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
4157 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4158 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4161 const struct parentdc_test test2 =
4163 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
4164 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4165 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4168 const struct parentdc_test test3 =
4170 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4171 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4172 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4175 const struct parentdc_test test4 =
4177 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
4178 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
4179 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4182 const struct parentdc_test test5 =
4184 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
4185 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4186 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4189 const struct parentdc_test test6 =
4191 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4192 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4193 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4196 const struct parentdc_test test7 =
4198 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4199 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4200 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4204 clsMain.style = CS_DBLCLKS;
4205 clsMain.lpfnWndProc = parentdc_window_procA;
4206 clsMain.cbClsExtra = 0;
4207 clsMain.cbWndExtra = 0;
4208 clsMain.hInstance = GetModuleHandleA(0);
4210 clsMain.hCursor = LoadCursorA(0, IDC_ARROW);
4211 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
4212 clsMain.lpszMenuName = NULL;
4213 clsMain.lpszClassName = "ParentDcMainWindowClass";
4215 if(!RegisterClassA(&clsMain)) {
4216 trace("Register failed %d\n", GetLastError());
4220 cls.style = CS_DBLCLKS | CS_PARENTDC;
4221 cls.lpfnWndProc = parentdc_window_procA;
4224 cls.hInstance = GetModuleHandleA(0);
4226 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4227 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4228 cls.lpszMenuName = NULL;
4229 cls.lpszClassName = "ParentDcWindowClass";
4231 if(!RegisterClassA(&cls)) {
4232 trace("Register failed %d\n", GetLastError());
4236 SetRect(&rc, 0, 0, 150, 150);
4237 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
4238 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
4239 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
4240 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
4241 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
4242 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
4243 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
4244 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
4245 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
4246 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
4247 ShowWindow(hwndMain, SW_SHOW);
4248 ShowWindow(hwnd1, SW_SHOW);
4249 ShowWindow(hwnd2, SW_SHOW);
4250 SetWindowPos(hwndMain, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
4251 flush_events( TRUE );
4253 zero_parentdc_test(&test_answer);
4254 InvalidateRect(hwndMain, NULL, TRUE);
4255 flush_events( TRUE );
4256 parentdc_ok(test1, test_answer);
4258 zero_parentdc_test(&test_answer);
4259 SetRect(&rc, 0, 0, 50, 50);
4260 InvalidateRect(hwndMain, &rc, TRUE);
4261 flush_events( TRUE );
4262 parentdc_ok(test2, test_answer);
4264 zero_parentdc_test(&test_answer);
4265 SetRect(&rc, 0, 0, 10, 10);
4266 InvalidateRect(hwndMain, &rc, TRUE);
4267 flush_events( TRUE );
4268 parentdc_ok(test3, test_answer);
4270 zero_parentdc_test(&test_answer);
4271 SetRect(&rc, 40, 40, 50, 50);
4272 InvalidateRect(hwndMain, &rc, TRUE);
4273 flush_events( TRUE );
4274 parentdc_ok(test4, test_answer);
4276 zero_parentdc_test(&test_answer);
4277 SetRect(&rc, 20, 20, 60, 60);
4278 InvalidateRect(hwndMain, &rc, TRUE);
4279 flush_events( TRUE );
4280 parentdc_ok(test5, test_answer);
4282 zero_parentdc_test(&test_answer);
4283 SetRect(&rc, 0, 0, 10, 10);
4284 InvalidateRect(hwnd1, &rc, TRUE);
4285 flush_events( TRUE );
4286 parentdc_ok(test6, test_answer);
4288 zero_parentdc_test(&test_answer);
4289 SetRect(&rc, -5, -5, 65, 65);
4290 InvalidateRect(hwnd1, &rc, TRUE);
4291 flush_events( TRUE );
4292 parentdc_ok(test7, test_answer);
4294 DestroyWindow(hwndMain);
4295 DestroyWindow(hwnd1);
4296 DestroyWindow(hwnd2);
4299 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4301 return DefWindowProcA(hwnd, msg, wparam, lparam);
4304 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4306 return DefWindowProcW(hwnd, msg, wparam, lparam);
4309 static void test_IsWindowUnicode(void)
4311 static const char ansi_class_nameA[] = "ansi class name";
4312 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
4313 static const char unicode_class_nameA[] = "unicode class name";
4314 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
4319 memset(&classW, 0, sizeof(classW));
4320 classW.hInstance = GetModuleHandleA(0);
4321 classW.lpfnWndProc = def_window_procW;
4322 classW.lpszClassName = unicode_class_nameW;
4323 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
4325 memset(&classA, 0, sizeof(classA));
4326 classA.hInstance = GetModuleHandleA(0);
4327 classA.lpfnWndProc = def_window_procA;
4328 classA.lpszClassName = ansi_class_nameA;
4329 assert(RegisterClassA(&classA));
4331 /* unicode class: window proc */
4332 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4333 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4336 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4337 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4338 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4339 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4340 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4342 DestroyWindow(hwnd);
4344 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4345 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4348 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4349 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4350 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4351 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4352 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4354 DestroyWindow(hwnd);
4356 /* ansi class: window proc */
4357 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4358 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4361 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4362 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4363 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4364 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4365 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4367 DestroyWindow(hwnd);
4369 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4370 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4373 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4374 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4375 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4376 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4377 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4379 DestroyWindow(hwnd);
4381 /* unicode class: class proc */
4382 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4383 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4386 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4387 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4388 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4389 /* do not restore class window proc back to unicode */
4391 DestroyWindow(hwnd);
4393 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4394 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4397 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4398 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4399 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4401 DestroyWindow(hwnd);
4403 /* ansi class: class proc */
4404 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4405 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4408 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4409 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4410 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4411 /* do not restore class window proc back to ansi */
4413 DestroyWindow(hwnd);
4415 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4416 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4419 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4420 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4421 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4423 DestroyWindow(hwnd);
4426 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4430 if (msg != WM_GETMINMAXINFO)
4431 return DefWindowProc(hwnd, msg, wp, lp);
4433 minmax = (MINMAXINFO *)lp;
4435 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
4437 minmax->ptReserved.x = 0;
4438 minmax->ptReserved.y = 0;
4439 minmax->ptMaxSize.x = 400;
4440 minmax->ptMaxSize.y = 400;
4441 minmax->ptMaxPosition.x = 300;
4442 minmax->ptMaxPosition.y = 300;
4443 minmax->ptMaxTrackSize.x = 200;
4444 minmax->ptMaxTrackSize.y = 200;
4445 minmax->ptMinTrackSize.x = 100;
4446 minmax->ptMinTrackSize.y = 100;
4449 DefWindowProc(hwnd, msg, wp, lp);
4453 static int expected_cx, expected_cy;
4454 static RECT expected_rect, broken_rect;
4456 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4460 case WM_GETMINMAXINFO:
4463 GetWindowRect( hwnd, &rect );
4464 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
4465 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4466 return DefWindowProc(hwnd, msg, wp, lp);
4471 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
4473 GetWindowRect( hwnd, &rect );
4474 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
4475 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
4476 ok( cs->cx == expected_cx || broken(cs->cx == (short)expected_cx),
4477 "wrong x size %d/%d\n", cs->cx, expected_cx );
4478 ok( cs->cy == expected_cy || broken(cs->cy == (short)expected_cy),
4479 "wrong y size %d/%d\n", cs->cy, expected_cy );
4480 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
4481 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
4482 (rect.right - rect.left == min( 65535, expected_rect.right - expected_rect.left ) &&
4483 rect.bottom - rect.top == min( 65535, expected_rect.bottom - expected_rect.top )) ||
4484 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
4485 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top) ||
4486 broken( rect.right - rect.left == (short)broken_rect.right - (short)broken_rect.left &&
4487 rect.bottom - rect.top == (short)broken_rect.bottom - (short)broken_rect.top),
4488 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
4489 rect.left, rect.top, rect.right, rect.bottom,
4490 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
4491 return DefWindowProc(hwnd, msg, wp, lp);
4495 RECT rect, *r = (RECT *)lp;
4496 GetWindowRect( hwnd, &rect );
4497 ok( !memcmp( &rect, r, sizeof(rect) ),
4498 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
4499 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
4500 return DefWindowProc(hwnd, msg, wp, lp);
4503 return DefWindowProc(hwnd, msg, wp, lp);
4507 static void test_CreateWindow(void)
4515 #define expect_menu(window, menu) \
4516 SetLastError(0xdeadbeef); \
4517 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
4519 #define expect_style(window, style)\
4520 ok((ULONG)GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
4522 #define expect_ex_style(window, ex_style)\
4523 ok((ULONG)GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
4525 #define expect_gle_broken_9x(gle)\
4526 ok(GetLastError() == gle ||\
4527 broken(GetLastError() == 0xdeadbeef),\
4528 "IsMenu set error %d\n", GetLastError())
4530 hmenu = CreateMenu();
4532 parent = GetDesktopWindow();
4533 assert(parent != 0);
4535 SetLastError(0xdeadbeef);
4536 ok(IsMenu(hmenu), "IsMenu error %d\n", GetLastError());
4539 SetLastError(0xdeadbeef);
4540 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
4541 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4542 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4543 expect_menu(hwnd, 1);
4544 expect_style(hwnd, WS_CHILD);
4545 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4546 DestroyWindow(hwnd);
4548 SetLastError(0xdeadbeef);
4549 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
4550 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4551 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4552 expect_menu(hwnd, 1);
4553 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4554 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4555 DestroyWindow(hwnd);
4557 SetLastError(0xdeadbeef);
4558 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
4559 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4560 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4561 expect_menu(hwnd, 1);
4562 expect_style(hwnd, WS_CHILD);
4563 expect_ex_style(hwnd, 0);
4564 DestroyWindow(hwnd);
4566 SetLastError(0xdeadbeef);
4567 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
4568 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4569 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4570 expect_menu(hwnd, 1);
4571 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4572 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4573 DestroyWindow(hwnd);
4576 SetLastError(0xdeadbeef);
4577 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4578 0, 0, 100, 100, parent, hmenu, 0, NULL);
4579 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4580 expect_menu(hwnd, hmenu);
4581 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4582 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4583 DestroyWindow(hwnd);
4584 SetLastError(0xdeadbeef);
4585 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4586 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4588 hmenu = CreateMenu();
4590 SetLastError(0xdeadbeef);
4591 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
4592 0, 0, 100, 100, parent, hmenu, 0, NULL);
4593 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4594 expect_menu(hwnd, hmenu);
4595 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4596 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4597 DestroyWindow(hwnd);
4598 SetLastError(0xdeadbeef);
4599 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4600 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4602 hmenu = CreateMenu();
4604 SetLastError(0xdeadbeef);
4605 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
4606 0, 0, 100, 100, parent, hmenu, 0, NULL);
4607 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4608 expect_menu(hwnd, hmenu);
4609 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4610 expect_ex_style(hwnd, 0);
4611 DestroyWindow(hwnd);
4612 SetLastError(0xdeadbeef);
4613 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4614 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4616 hmenu = CreateMenu();
4618 SetLastError(0xdeadbeef);
4619 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
4620 0, 0, 100, 100, parent, hmenu, 0, NULL);
4621 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4622 expect_menu(hwnd, hmenu);
4623 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4624 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4625 DestroyWindow(hwnd);
4626 SetLastError(0xdeadbeef);
4627 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4628 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4630 /* WS_CHILD | WS_POPUP */
4631 SetLastError(0xdeadbeef);
4632 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4633 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4634 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4635 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4637 DestroyWindow(hwnd);
4639 hmenu = CreateMenu();
4641 SetLastError(0xdeadbeef);
4642 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4643 0, 0, 100, 100, parent, hmenu, 0, NULL);
4644 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4645 expect_menu(hwnd, hmenu);
4646 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4647 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4648 DestroyWindow(hwnd);
4649 SetLastError(0xdeadbeef);
4650 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4651 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4653 SetLastError(0xdeadbeef);
4654 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4655 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4656 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4657 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4659 DestroyWindow(hwnd);
4661 hmenu = CreateMenu();
4663 SetLastError(0xdeadbeef);
4664 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4665 0, 0, 100, 100, parent, hmenu, 0, NULL);
4666 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4667 expect_menu(hwnd, hmenu);
4668 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4669 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4670 DestroyWindow(hwnd);
4671 SetLastError(0xdeadbeef);
4672 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4673 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4675 SetLastError(0xdeadbeef);
4676 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4677 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4678 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4679 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4681 DestroyWindow(hwnd);
4683 hmenu = CreateMenu();
4685 SetLastError(0xdeadbeef);
4686 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4687 0, 0, 100, 100, parent, hmenu, 0, NULL);
4688 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4689 expect_menu(hwnd, hmenu);
4690 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4691 expect_ex_style(hwnd, 0);
4692 DestroyWindow(hwnd);
4693 SetLastError(0xdeadbeef);
4694 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4695 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4697 SetLastError(0xdeadbeef);
4698 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4699 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4700 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4701 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4703 DestroyWindow(hwnd);
4705 hmenu = CreateMenu();
4707 SetLastError(0xdeadbeef);
4708 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4709 0, 0, 100, 100, parent, hmenu, 0, NULL);
4710 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4711 expect_menu(hwnd, hmenu);
4712 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4713 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4714 DestroyWindow(hwnd);
4715 SetLastError(0xdeadbeef);
4716 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4717 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4719 /* test child window sizing */
4721 cls.lpfnWndProc = minmax_wnd_proc;
4724 cls.hInstance = GetModuleHandle(0);
4726 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4727 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4728 cls.lpszMenuName = NULL;
4729 cls.lpszClassName = "MinMax_WndClass";
4730 RegisterClass(&cls);
4732 SetLastError(0xdeadbeef);
4733 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4734 0, 0, 100, 100, 0, 0, 0, NULL);
4735 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4736 expect_menu(parent, 0);
4737 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
4738 expect_ex_style(parent, WS_EX_WINDOWEDGE);
4740 memset(&minmax, 0, sizeof(minmax));
4741 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4742 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
4743 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
4744 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4745 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
4747 GetWindowRect(parent, &rc);
4748 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
4749 GetClientRect(parent, &rc);
4750 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
4752 InflateRect(&rc, 200, 200);
4753 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4755 SetLastError(0xdeadbeef);
4756 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4757 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
4758 parent, (HMENU)1, 0, NULL);
4759 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4760 expect_menu(hwnd, 1);
4761 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
4762 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4764 memset(&minmax, 0, sizeof(minmax));
4765 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4766 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4768 GetWindowRect(hwnd, &rc);
4769 OffsetRect(&rc, -rc.left, -rc.top);
4770 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4771 rc.left, rc.top, rc.right, rc.bottom,
4772 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
4773 DestroyWindow(hwnd);
4775 cls.lpfnWndProc = winsizes_wnd_proc;
4776 cls.lpszClassName = "Sizes_WndClass";
4777 RegisterClass(&cls);
4779 expected_cx = expected_cy = 200000;
4780 SetRect( &expected_rect, 0, 0, 200000, 200000 );
4781 broken_rect = expected_rect;
4782 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
4783 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4784 GetClientRect( hwnd, &rc );
4785 ok( rc.right == 200000 || rc.right == 65535 || broken(rc.right == (short)200000),
4786 "invalid rect right %u\n", rc.right );
4787 ok( rc.bottom == 200000 || rc.bottom == 65535 || broken(rc.bottom == (short)200000),
4788 "invalid rect bottom %u\n", rc.bottom );
4789 DestroyWindow(hwnd);
4791 expected_cx = expected_cy = -10;
4792 SetRect( &expected_rect, 0, 0, 0, 0 );
4793 SetRect( &broken_rect, 0, 0, -10, -10 );
4794 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
4795 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4796 GetClientRect( hwnd, &rc );
4797 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4798 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4799 DestroyWindow(hwnd);
4801 expected_cx = expected_cy = -200000;
4802 SetRect( &expected_rect, 0, 0, 0, 0 );
4803 SetRect( &broken_rect, 0, 0, -200000, -200000 );
4804 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
4805 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4806 GetClientRect( hwnd, &rc );
4807 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4808 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4809 DestroyWindow(hwnd);
4811 /* we need a parent at 0,0 so that child coordinates match */
4812 DestroyWindow(parent);
4813 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
4814 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4817 expected_cy = 0x7fffffff;
4818 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
4819 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
4820 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
4821 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4822 GetClientRect( hwnd, &rc );
4823 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
4824 ok( rc.bottom == 0x7fffffff - 10 || rc.bottom ==65535 || broken(rc.bottom == 0),
4825 "invalid rect bottom %u\n", rc.bottom );
4826 DestroyWindow(hwnd);
4828 expected_cx = 0x7fffffff;
4829 expected_cy = 0x7fffffff;
4830 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
4831 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
4832 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
4833 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4834 GetClientRect( hwnd, &rc );
4835 ok( rc.right == 0x7fffffff - 20 || rc.right == 65535 || broken(rc.right == 0),
4836 "invalid rect right %u\n", rc.right );
4837 ok( rc.bottom == 0x7fffffff - 10 || rc.right == 65535 || broken(rc.bottom == 0),
4838 "invalid rect bottom %u\n", rc.bottom );
4839 DestroyWindow(hwnd);
4841 /* top level window */
4842 expected_cx = expected_cy = 200000;
4843 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
4844 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
4845 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4846 GetClientRect( hwnd, &rc );
4847 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
4848 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
4849 DestroyWindow(hwnd);
4851 if (pGetLayout && pSetLayout)
4853 HDC hdc = GetDC( parent );
4854 pSetLayout( hdc, LAYOUT_RTL );
4855 if (pGetLayout( hdc ))
4857 ReleaseDC( parent, hdc );
4858 DestroyWindow( parent );
4859 SetLastError( 0xdeadbeef );
4860 parent = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_LAYOUTRTL, "static", NULL, WS_POPUP,
4861 0, 0, 100, 100, 0, 0, 0, NULL);
4862 ok( parent != 0, "creation failed err %u\n", GetLastError());
4863 expect_ex_style( parent, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
4864 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 20, 20, parent, 0, 0, NULL);
4865 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4866 expect_ex_style( hwnd, WS_EX_LAYOUTRTL );
4867 DestroyWindow( hwnd );
4868 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 20, 20, parent, 0, 0, NULL);
4869 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4870 expect_ex_style( hwnd, 0 );
4871 DestroyWindow( hwnd );
4872 SetWindowLongW( parent, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT );
4873 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 20, 20, parent, 0, 0, NULL);
4874 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4875 expect_ex_style( hwnd, 0 );
4876 DestroyWindow( hwnd );
4878 if (pGetProcessDefaultLayout && pSetProcessDefaultLayout)
4882 SetLastError( 0xdeadbeef );
4883 ok( !pGetProcessDefaultLayout( NULL ), "GetProcessDefaultLayout succeeded\n" );
4884 ok( GetLastError() == ERROR_NOACCESS, "wrong error %u\n", GetLastError() );
4885 SetLastError( 0xdeadbeef );
4886 ok( pGetProcessDefaultLayout( &layout ),
4887 "GetProcessDefaultLayout failed err %u\n", GetLastError ());
4888 ok( layout == 0, "GetProcessDefaultLayout wrong layout %x\n", layout );
4889 SetLastError( 0xdeadbeef );
4890 ok( pSetProcessDefaultLayout( 7 ),
4891 "SetProcessDefaultLayout failed err %u\n", GetLastError ());
4892 ok( pGetProcessDefaultLayout( &layout ),
4893 "GetProcessDefaultLayout failed err %u\n", GetLastError ());
4894 ok( layout == 7, "GetProcessDefaultLayout wrong layout %x\n", layout );
4895 SetLastError( 0xdeadbeef );
4896 ok( pSetProcessDefaultLayout( LAYOUT_RTL ),
4897 "SetProcessDefaultLayout failed err %u\n", GetLastError ());
4898 ok( pGetProcessDefaultLayout( &layout ),
4899 "GetProcessDefaultLayout failed err %u\n", GetLastError ());
4900 ok( layout == LAYOUT_RTL, "GetProcessDefaultLayout wrong layout %x\n", layout );
4901 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4902 0, 0, 100, 100, 0, 0, 0, NULL);
4903 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4904 expect_ex_style( hwnd, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
4905 DestroyWindow( hwnd );
4906 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4907 0, 0, 100, 100, parent, 0, 0, NULL);
4908 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4909 expect_ex_style( hwnd, WS_EX_APPWINDOW );
4910 DestroyWindow( hwnd );
4911 pSetProcessDefaultLayout( 0 );
4913 else win_skip( "SetProcessDefaultLayout not supported\n" );
4915 else win_skip( "SetLayout not supported\n" );
4917 else win_skip( "SetLayout not available\n" );
4919 DestroyWindow(parent);
4921 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4922 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4924 #undef expect_gle_broken_9x
4927 #undef expect_ex_style
4930 /* function that remembers whether the system the test is running on sets the
4931 * last error for user32 functions to make the tests stricter */
4932 static int check_error(DWORD actual, DWORD expected)
4934 static int sets_last_error = -1;
4935 if (sets_last_error == -1)
4936 sets_last_error = (actual != 0xdeadbeef);
4937 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
4940 static void test_SetWindowLong(void)
4943 WNDPROC old_window_procW;
4945 SetLastError(0xdeadbeef);
4946 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
4947 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
4948 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
4949 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4951 SetLastError(0xdeadbeef);
4952 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
4953 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
4954 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
4955 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4957 SetLastError(0xdeadbeef);
4958 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4959 ok((WNDPROC)retval == main_window_procA || broken(!retval), /* win9x */
4960 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
4961 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4962 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
4963 ok((WNDPROC)retval == main_window_procA,
4964 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4965 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
4967 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
4968 SetLastError(0xdeadbeef);
4969 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
4970 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
4972 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4973 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
4974 ok((WNDPROC)retval == old_window_procW,
4975 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4976 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
4978 /* set it back to ANSI */
4979 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4983 static void test_ShowWindow(void)
4987 RECT rcMain, rc, rcMinimized;
4990 SetRect(&rcMain, 120, 120, 210, 210);
4992 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
4993 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4994 WS_MAXIMIZEBOX | WS_POPUP,
4995 rcMain.left, rcMain.top,
4996 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
5000 style = GetWindowLong(hwnd, GWL_STYLE);
5001 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5002 ok(!(style & WS_VISIBLE), "window should not be visible\n");
5003 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5004 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5005 GetWindowRect(hwnd, &rc);
5006 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5007 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5008 rc.left, rc.top, rc.right, rc.bottom);
5010 ret = ShowWindow(hwnd, SW_SHOW);
5011 ok(!ret, "not expected ret: %lu\n", ret);
5012 style = GetWindowLong(hwnd, GWL_STYLE);
5013 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5014 ok(style & WS_VISIBLE, "window should be visible\n");
5015 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5016 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5017 GetWindowRect(hwnd, &rc);
5018 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5019 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5020 rc.left, rc.top, rc.right, rc.bottom);
5022 ret = ShowWindow(hwnd, SW_MINIMIZE);
5023 ok(ret, "not expected ret: %lu\n", ret);
5024 style = GetWindowLong(hwnd, GWL_STYLE);
5025 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5026 ok(style & WS_VISIBLE, "window should be visible\n");
5027 ok(style & WS_MINIMIZE, "window should be minimized\n");
5028 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5029 GetWindowRect(hwnd, &rcMinimized);
5030 ok(!EqualRect(&rcMain, &rcMinimized), "rects shouldn't match\n");
5031 /* shouldn't be able to resize minized windows */
5032 ret = SetWindowPos(hwnd, 0, 0, 0,
5033 (rcMinimized.right - rcMinimized.left) * 2,
5034 (rcMinimized.bottom - rcMinimized.top) * 2,
5035 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
5036 ok(ret, "not expected ret: %lu\n", ret);
5037 GetWindowRect(hwnd, &rc);
5038 ok(EqualRect(&rc, &rcMinimized), "rects should match\n");
5040 ShowWindow(hwnd, SW_RESTORE);
5041 ok(ret, "not expected ret: %lu\n", ret);
5042 style = GetWindowLong(hwnd, GWL_STYLE);
5043 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5044 ok(style & WS_VISIBLE, "window should be visible\n");
5045 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5046 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5047 GetWindowRect(hwnd, &rc);
5048 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5049 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5050 rc.left, rc.top, rc.right, rc.bottom);
5052 ret = EnableWindow(hwnd, FALSE);
5053 ok(!ret, "not expected ret: %lu\n", ret);
5054 style = GetWindowLong(hwnd, GWL_STYLE);
5055 ok(style & WS_DISABLED, "window should be disabled\n");
5057 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
5058 ok(!ret, "not expected ret: %lu\n", ret);
5059 style = GetWindowLong(hwnd, GWL_STYLE);
5060 ok(style & WS_DISABLED, "window should be disabled\n");
5061 ok(style & WS_VISIBLE, "window should be visible\n");
5062 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5063 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5064 GetWindowRect(hwnd, &rc);
5065 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5066 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5067 rc.left, rc.top, rc.right, rc.bottom);
5069 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
5070 ok(!ret, "not expected ret: %lu\n", ret);
5071 style = GetWindowLong(hwnd, GWL_STYLE);
5072 ok(style & WS_DISABLED, "window should be disabled\n");
5073 ok(style & WS_VISIBLE, "window should be visible\n");
5074 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5075 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5076 GetWindowRect(hwnd, &rc);
5077 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5078 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5079 rc.left, rc.top, rc.right, rc.bottom);
5081 ret = ShowWindow(hwnd, SW_MINIMIZE);
5082 ok(ret, "not expected ret: %lu\n", ret);
5083 style = GetWindowLong(hwnd, GWL_STYLE);
5084 ok(style & WS_DISABLED, "window should be disabled\n");
5085 ok(style & WS_VISIBLE, "window should be visible\n");
5086 ok(style & WS_MINIMIZE, "window should be minimized\n");
5087 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5088 GetWindowRect(hwnd, &rc);
5089 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
5091 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
5092 ok(!ret, "not expected ret: %lu\n", ret);
5093 style = GetWindowLong(hwnd, GWL_STYLE);
5094 ok(style & WS_DISABLED, "window should be disabled\n");
5095 ok(style & WS_VISIBLE, "window should be visible\n");
5096 ok(style & WS_MINIMIZE, "window should be minimized\n");
5097 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5098 GetWindowRect(hwnd, &rc);
5099 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
5101 ret = ShowWindow(hwnd, SW_RESTORE);
5102 ok(ret, "not expected ret: %lu\n", ret);
5103 style = GetWindowLong(hwnd, GWL_STYLE);
5104 ok(style & WS_DISABLED, "window should be disabled\n");
5105 ok(style & WS_VISIBLE, "window should be visible\n");
5106 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5107 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5108 GetWindowRect(hwnd, &rc);
5109 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5110 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5111 rc.left, rc.top, rc.right, rc.bottom);
5113 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
5114 ok(!ret, "not expected ret: %lu\n", ret);
5115 ok(IsWindow(hwnd), "window should exist\n");
5117 ret = EnableWindow(hwnd, TRUE);
5118 ok(ret, "not expected ret: %lu\n", ret);
5120 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
5121 ok(!ret, "not expected ret: %lu\n", ret);
5122 ok(!IsWindow(hwnd), "window should not exist\n");
5125 static void test_gettext(void)
5128 LPCSTR clsname = "gettexttest";
5132 memset( &cls, 0, sizeof cls );
5133 cls.lpfnWndProc = DefWindowProc;
5134 cls.lpszClassName = clsname;
5135 cls.hInstance = GetModuleHandle(NULL);
5137 if (!RegisterClass( &cls )) return;
5139 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
5140 ok( hwnd != NULL, "window was null\n");
5142 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
5143 ok( r == 0, "settext should return zero\n");
5145 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
5146 ok( r == 0, "settext should return zero (%ld)\n", r);
5148 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
5149 ok( r == 0, "settext should return zero (%ld)\n", r);
5151 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
5152 ok( r == 0, "settext should return zero (%ld)\n", r);
5154 DestroyWindow(hwnd);
5155 UnregisterClass( clsname, NULL );
5159 static void test_GetUpdateRect(void)
5162 BOOL ret, parent_wm_paint, grandparent_wm_paint;
5164 HWND hgrandparent, hparent, hchild;
5166 static const char classNameA[] = "GetUpdateRectClass";
5168 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
5169 0, 0, 100, 100, NULL, NULL, 0, NULL);
5171 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
5172 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
5174 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
5175 10, 10, 30, 30, hparent, NULL, 0, NULL);
5177 ShowWindow(hgrandparent, SW_SHOW);
5178 UpdateWindow(hgrandparent);
5179 flush_events( TRUE );
5181 ShowWindow(hchild, SW_HIDE);
5182 SetRect(&rc2, 0, 0, 0, 0);
5183 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5184 ok(!ret, "GetUpdateRect returned not empty region\n");
5185 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5186 rc1.left, rc1.top, rc1.right, rc1.bottom,
5187 rc2.left, rc2.top, rc2.right, rc2.bottom);
5189 SetRect(&rc2, 10, 10, 40, 40);
5190 ret = GetUpdateRect(hparent, &rc1, FALSE);
5191 ok(ret, "GetUpdateRect returned empty region\n");
5192 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5193 rc1.left, rc1.top, rc1.right, rc1.bottom,
5194 rc2.left, rc2.top, rc2.right, rc2.bottom);
5196 parent_wm_paint = FALSE;
5197 grandparent_wm_paint = FALSE;
5198 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
5200 if (msg.message == WM_PAINT)
5202 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
5203 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
5205 DispatchMessage(&msg);
5207 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
5208 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
5210 DestroyWindow(hgrandparent);
5213 cls.lpfnWndProc = DefWindowProcA;
5216 cls.hInstance = GetModuleHandleA(0);
5218 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5219 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5220 cls.lpszMenuName = NULL;
5221 cls.lpszClassName = classNameA;
5223 if(!RegisterClassA(&cls)) {
5224 trace("Register failed %d\n", GetLastError());
5228 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
5229 0, 0, 100, 100, NULL, NULL, 0, NULL);
5231 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
5232 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
5234 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
5235 10, 10, 30, 30, hparent, NULL, 0, NULL);
5237 ShowWindow(hgrandparent, SW_SHOW);
5238 UpdateWindow(hgrandparent);
5239 flush_events( TRUE );
5241 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5242 ok(!ret, "GetUpdateRect returned not empty region\n");
5244 ShowWindow(hchild, SW_HIDE);
5246 SetRect(&rc2, 0, 0, 0, 0);
5247 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5248 ok(!ret, "GetUpdateRect returned not empty region\n");
5249 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5250 rc1.left, rc1.top, rc1.right, rc1.bottom,
5251 rc2.left, rc2.top, rc2.right, rc2.bottom);
5253 SetRect(&rc2, 10, 10, 40, 40);
5254 ret = GetUpdateRect(hparent, &rc1, FALSE);
5255 ok(ret, "GetUpdateRect returned empty region\n");
5256 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5257 rc1.left, rc1.top, rc1.right, rc1.bottom,
5258 rc2.left, rc2.top, rc2.right, rc2.bottom);
5260 parent_wm_paint = FALSE;
5261 grandparent_wm_paint = FALSE;
5262 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
5264 if (msg.message == WM_PAINT)
5266 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
5267 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
5269 DispatchMessage(&msg);
5271 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
5272 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
5274 DestroyWindow(hgrandparent);
5278 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5286 const int waitTime = 2000;
5288 BeginPaint(hwnd, &ps);
5290 /* create and destroy window to create an exposed region on this window */
5291 win = CreateWindowA("static", "win", WS_VISIBLE,
5292 10,10,50,50, NULL, NULL, 0, NULL);
5295 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
5297 ValidateRect(hwnd, NULL);
5298 EndPaint(hwnd, &ps);
5300 if(waitResult != WAIT_TIMEOUT)
5302 GetUpdateRect(hwnd, &updateRect, FALSE);
5303 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
5308 return DefWindowProc(hwnd, msg, wParam, lParam);
5311 static void test_Expose(void)
5316 memset(&cls, 0, sizeof(WNDCLASSA));
5317 cls.lpfnWndProc = TestExposedRegion_WndProc;
5318 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5319 cls.lpszClassName = "TestExposeClass";
5320 RegisterClassA(&cls);
5322 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
5323 0, 0, 200, 100, NULL, NULL, 0, NULL);
5329 static LRESULT CALLBACK TestNCRedraw_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5331 static UINT ncredrawflags;
5337 ncredrawflags = *(UINT *) (((CREATESTRUCT *)lParam)->lpCreateParams);
5340 RedrawWindow(hwnd, NULL, NULL, ncredrawflags);
5343 BeginPaint(hwnd, &ps);
5344 EndPaint(hwnd, &ps);
5347 return DefWindowProc(hwnd, msg, wParam, lParam);
5350 static void run_NCRedrawLoop(UINT flags)
5357 hwnd = CreateWindowA("TestNCRedrawClass", "MainWindow",
5358 WS_OVERLAPPEDWINDOW, 0, 0, 200, 100,
5359 NULL, NULL, 0, &flags);
5360 ShowWindow(hwnd, SW_SHOW);
5362 flush_events( FALSE );
5363 while(PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE) != 0)
5365 if (msg.message == WM_PAINT) loopcount++;
5366 if (loopcount >= 100) break;
5367 TranslateMessage(&msg);
5368 DispatchMessage(&msg);
5369 MsgWaitForMultipleObjects(0, NULL, FALSE, 100, QS_ALLINPUT);
5371 if (flags == (RDW_INVALIDATE | RDW_FRAME))
5372 todo_wine ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
5374 ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
5375 DestroyWindow(hwnd);
5378 static void test_NCRedraw(void)
5382 wndclass.lpszClassName = "TestNCRedrawClass";
5383 wndclass.style = CS_HREDRAW | CS_VREDRAW;
5384 wndclass.lpfnWndProc = TestNCRedraw_WndProc;
5385 wndclass.cbClsExtra = 0;
5386 wndclass.cbWndExtra = 0;
5387 wndclass.hInstance = 0;
5388 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
5389 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
5390 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
5391 wndclass.lpszMenuName = NULL;
5393 RegisterClassA(&wndclass);
5395 run_NCRedrawLoop(RDW_INVALIDATE | RDW_FRAME);
5396 run_NCRedrawLoop(RDW_INVALIDATE);
5399 static void test_GetWindowModuleFileName(void)
5404 char buf1[MAX_PATH], buf2[MAX_PATH];
5406 if (!pGetWindowModuleFileNameA)
5408 win_skip("GetWindowModuleFileNameA is not available\n");
5412 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
5415 hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
5416 ok(hinst == 0 || broken(hinst == GetModuleHandle(0)), /* win9x */ "expected 0, got %p\n", hinst);
5419 SetLastError(0xdeadbeef);
5420 ret1 = GetModuleFileName(hinst, buf1, sizeof(buf1));
5421 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
5424 SetLastError(0xdeadbeef);
5425 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
5426 ok(ret2 || broken(!ret2), /* nt4 sp 3 */
5427 "GetWindowModuleFileNameA error %u\n", GetLastError());
5431 ok(ret1 == ret2 || broken(ret2 == ret1 + 1), /* win98 */ "%u != %u\n", ret1, ret2);
5432 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
5434 hinst = GetModuleHandle(0);
5436 SetLastError(0xdeadbeef);
5437 ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
5438 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
5439 "expected %u, got %u\n", ret1 - 2, ret2);
5440 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5441 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5442 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5444 SetLastError(0xdeadbeef);
5445 ret2 = GetModuleFileName(hinst, buf2, 0);
5446 ok(!ret2, "GetModuleFileName should return 0\n");
5447 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5448 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5449 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5451 SetLastError(0xdeadbeef);
5452 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
5453 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3) /* win98 */ || broken(!ret2), /* nt4 sp3 */
5454 "expected %u, got %u\n", ret1 - 2, ret2);
5455 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5456 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5457 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5459 SetLastError(0xdeadbeef);
5460 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
5461 ok(!ret2, "expected 0, got %u\n", ret2);
5462 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5463 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5464 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5466 DestroyWindow(hwnd);
5469 hwnd = (HWND)0xdeadbeef;
5470 SetLastError(0xdeadbeef);
5471 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
5472 ok(!ret1, "expected 0, got %u\n", ret1);
5473 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef), /* win9x */
5474 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
5476 hwnd = FindWindow("Shell_TrayWnd", NULL);
5477 ok(IsWindow(hwnd) || broken(!hwnd), "got invalid tray window %p\n", hwnd);
5478 SetLastError(0xdeadbeef);
5479 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
5480 ok(!ret1 || broken(ret1), /* win98 */ "expected 0, got %u\n", ret1);
5482 if (!ret1) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
5484 ret1 = GetModuleFileName(0, buf1, sizeof(buf1));
5485 hwnd = GetDesktopWindow();
5486 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
5487 SetLastError(0xdeadbeef);
5488 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
5490 ret1 == ret2 || /* vista */
5491 broken(ret2), /* some win98 return user.exe as file name */
5492 "expected 0 or %u, got %u %s\n", ret1, ret2, buf2);
5496 static void test_hwnd_message(void)
5498 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
5499 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
5501 HWND parent = 0, hwnd, found;
5504 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
5505 on CreateWindowExA and crash later in the test.
5506 Use UNICODE here to fail on win9x */
5507 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
5508 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
5511 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
5515 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
5519 HWND root, desktop = GetDesktopWindow();
5521 parent = pGetAncestor(hwnd, GA_PARENT);
5522 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
5523 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
5524 root = pGetAncestor(hwnd, GA_ROOT);
5525 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
5526 ok( !pGetAncestor(parent, GA_PARENT) || broken(pGetAncestor(parent, GA_PARENT) != 0), /* win2k */
5527 "parent shouldn't have parent %p\n", pGetAncestor(parent, GA_PARENT) );
5528 trace("parent %p root %p desktop %p\n", parent, root, desktop);
5529 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
5530 ok( !lstrcmpi( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
5531 GetWindowRect( parent, &rect );
5532 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
5533 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
5535 GetWindowRect( hwnd, &rect );
5536 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
5537 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
5539 /* test FindWindow behavior */
5541 found = FindWindowExA( 0, 0, 0, "message window" );
5542 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
5543 SetLastError(0xdeadbeef);
5544 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
5545 ok( found == 0, "found message window %p/%p\n", found, hwnd );
5546 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
5549 found = FindWindowExA( parent, 0, 0, "message window" );
5550 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
5553 /* test IsChild behavior */
5555 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
5557 /* test IsWindowVisible behavior */
5559 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
5560 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
5562 DestroyWindow(hwnd);
5565 static void test_layered_window(void)
5573 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes)
5575 win_skip( "layered windows not supported\n" );
5578 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
5579 100, 100, 200, 200, 0, 0, 0, NULL);
5581 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5582 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
5583 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
5584 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
5585 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5586 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5587 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5588 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
5589 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5590 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5591 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5592 ok( key == 0x123456 || key == 0, "wrong color key %x\n", key );
5593 ok( alpha == 44, "wrong alpha %u\n", alpha );
5594 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
5596 /* clearing WS_EX_LAYERED resets attributes */
5597 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5598 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5599 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
5600 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5601 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5602 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5603 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
5604 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5605 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5606 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5607 ok( key == 0x654321, "wrong color key %x\n", key );
5608 ok( alpha == 22, "wrong alpha %u\n", alpha );
5609 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
5611 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
5612 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5614 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5615 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5616 ok( key == 0x888888, "wrong color key %x\n", key );
5617 /* alpha not changed on vista if LWA_ALPHA is not set */
5618 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
5619 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
5621 /* color key may or may not be changed without LWA_COLORKEY */
5622 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
5623 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5625 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5626 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5627 ok( key == 0x888888 || key == 0x999999, "wrong color key %x\n", key );
5628 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
5629 ok( flags == 0, "wrong flags %x\n", flags );
5631 /* default alpha and color key is 0 */
5632 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5633 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5634 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
5635 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5636 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5637 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5638 ok( key == 0 || key == 0x222222, "wrong color key %x\n", key );
5639 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
5640 ok( flags == 0, "wrong flags %x\n", flags );
5642 DestroyWindow( hwnd );
5645 static MONITORINFO mi;
5647 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
5653 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
5654 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs->x, cs->y, cs->cx, cs->cy);
5655 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
5656 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
5657 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
5658 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5659 cs->x, cs->y, cs->cx, cs->cy);
5662 case WM_GETMINMAXINFO:
5664 MINMAXINFO *minmax = (MINMAXINFO *)lp;
5665 dump_minmax_info(minmax);
5666 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
5667 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
5668 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
5669 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
5673 return DefWindowProc(hwnd, msg, wp, lp);
5676 static void test_fullscreen(void)
5678 static const DWORD t_style[] = {
5679 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
5681 static const DWORD t_ex_style[] = {
5682 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
5692 if (!pGetMonitorInfoA || !pMonitorFromPoint)
5694 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
5699 SetLastError(0xdeadbeef);
5700 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
5701 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
5703 mi.cbSize = sizeof(mi);
5704 SetLastError(0xdeadbeef);
5705 ret = pGetMonitorInfoA(hmon, &mi);
5706 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
5707 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
5708 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5709 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5712 cls.lpfnWndProc = fullscreen_wnd_proc;
5715 cls.hInstance = GetModuleHandle(0);
5717 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5718 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5719 cls.lpszMenuName = NULL;
5720 cls.lpszClassName = "fullscreen_class";
5721 RegisterClass(&cls);
5723 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
5725 DWORD style, ex_style;
5727 /* avoid a WM interaction */
5728 assert(!(t_style[i] & WS_VISIBLE));
5730 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
5735 ex_style = t_ex_style[j];
5737 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5738 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5739 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5740 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5741 GetWindowRect(hwnd, &rc);
5742 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5743 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5744 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5745 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5746 DestroyWindow(hwnd);
5748 style = t_style[i] | WS_MAXIMIZE;
5749 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5750 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5751 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5752 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5753 GetWindowRect(hwnd, &rc);
5754 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5755 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5756 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5757 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5758 DestroyWindow(hwnd);
5760 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
5761 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5762 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5763 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5764 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5765 GetWindowRect(hwnd, &rc);
5766 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5767 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5768 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5769 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5770 DestroyWindow(hwnd);
5772 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
5773 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5774 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5775 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5776 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5777 GetWindowRect(hwnd, &rc);
5778 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5779 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5780 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5781 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5782 DestroyWindow(hwnd);
5784 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
5785 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5786 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5787 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5788 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5789 GetWindowRect(hwnd, &rc);
5790 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5791 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5792 fixup = min(abs(rc.left), abs(rc.top));
5793 InflateRect(&rc, -fixup, -fixup);
5794 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5795 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5796 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
5797 ex_style, style, rc.left, rc.top, rc.right, rc.bottom,
5798 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5799 DestroyWindow(hwnd);
5801 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
5802 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5803 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5804 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5805 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5806 GetWindowRect(hwnd, &rc);
5807 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5808 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5809 fixup = min(abs(rc.left), abs(rc.top));
5810 InflateRect(&rc, -fixup, -fixup);
5811 if (style & (WS_CHILD | WS_POPUP))
5812 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5813 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5814 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5816 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5817 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5818 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5819 DestroyWindow(hwnd);
5823 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5826 static BOOL test_thick_child_got_minmax;
5827 static const char * test_thick_child_name;
5828 static LONG test_thick_child_style;
5829 static LONG test_thick_child_exStyle;
5831 static LRESULT WINAPI test_thick_child_size_winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5834 int expectedMinTrackX;
5835 int expectedMinTrackY;
5836 int actualMinTrackX;
5837 int actualMinTrackY;
5838 int expectedMaxTrackX;
5839 int expectedMaxTrackY;
5840 int actualMaxTrackX;
5841 int actualMaxTrackY;
5842 int expectedMaxSizeX;
5843 int expectedMaxSizeY;
5854 case WM_GETMINMAXINFO:
5856 minmax = (MINMAXINFO *)lparam;
5857 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
5858 dump_minmax_info( minmax );
5860 test_thick_child_got_minmax = TRUE;
5863 adjustedStyle = test_thick_child_style;
5864 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
5865 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5866 GetClientRect(GetParent(hwnd), &rect);
5867 AdjustWindowRectEx(&rect, adjustedStyle, FALSE, test_thick_child_exStyle);
5869 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
5871 expectedMinTrackX = GetSystemMetrics(SM_CXMINTRACK);
5872 expectedMinTrackY = GetSystemMetrics(SM_CYMINTRACK);
5876 expectedMinTrackX = -2 * rect.left;
5877 expectedMinTrackY = -2 * rect.top;
5879 actualMinTrackX = minmax->ptMinTrackSize.x;
5880 actualMinTrackY = minmax->ptMinTrackSize.y;
5882 ok(actualMinTrackX == expectedMinTrackX && actualMinTrackY == expectedMinTrackY,
5883 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
5884 expectedMinTrackX, expectedMinTrackY, actualMinTrackX, actualMinTrackY,
5885 test_thick_child_name);
5887 actualMaxTrackX = minmax->ptMaxTrackSize.x;
5888 actualMaxTrackY = minmax->ptMaxTrackSize.y;
5889 expectedMaxTrackX = GetSystemMetrics(SM_CXMAXTRACK);
5890 expectedMaxTrackY = GetSystemMetrics(SM_CYMAXTRACK);
5891 ok(actualMaxTrackX == expectedMaxTrackX && actualMaxTrackY == expectedMaxTrackY,
5892 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
5893 expectedMaxTrackX, expectedMaxTrackY, actualMaxTrackX, actualMaxTrackY,
5894 test_thick_child_name);
5896 expectedMaxSizeX = rect.right - rect.left;
5897 expectedMaxSizeY = rect.bottom - rect.top;
5898 actualMaxSizeX = minmax->ptMaxSize.x;
5899 actualMaxSizeY = minmax->ptMaxSize.y;
5901 ok(actualMaxSizeX == expectedMaxSizeX && actualMaxSizeY == expectedMaxSizeY,
5902 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
5903 expectedMaxSizeX, expectedMaxSizeY, actualMaxSizeX, actualMaxSizeY,
5904 test_thick_child_name);
5907 expectedPosX = rect.left;
5908 expectedPosY = rect.top;
5909 actualPosX = minmax->ptMaxPosition.x;
5910 actualPosY = minmax->ptMaxPosition.y;
5911 ok(actualPosX == expectedPosX && actualPosY == expectedPosY,
5912 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
5913 expectedPosX, expectedPosY, actualPosX, actualPosY, test_thick_child_name);
5919 return DefWindowProcA(hwnd, msg, wparam, lparam);
5922 #define NUMBER_OF_THICK_CHILD_TESTS 16
5923 static void test_thick_child_size(HWND parentWindow)
5927 RECT adjustedParentRect;
5932 LONG expectedHeight;
5934 LPCTSTR className = "THICK_CHILD_CLASS";
5937 static const LONG styles[NUMBER_OF_THICK_CHILD_TESTS] = {
5938 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5939 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5940 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5941 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5942 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5943 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5944 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5945 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5946 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5947 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5948 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5949 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5950 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5951 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5952 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5953 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5956 static const LONG exStyles[NUMBER_OF_THICK_CHILD_TESTS] = {
5961 WS_EX_DLGMODALFRAME,
5962 WS_EX_DLGMODALFRAME,
5963 WS_EX_DLGMODALFRAME,
5964 WS_EX_DLGMODALFRAME,
5969 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5970 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5971 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5972 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5974 static const char *styleName[NUMBER_OF_THICK_CHILD_TESTS] = {
5975 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
5976 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
5977 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
5978 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
5979 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
5980 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
5981 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5982 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5983 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
5984 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
5985 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5986 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5987 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5988 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5989 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5990 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5994 cls.lpfnWndProc = test_thick_child_size_winproc;
5997 cls.hInstance = GetModuleHandleA(0);
5999 cls.hCursor = LoadCursorA(0, IDC_ARROW);
6000 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6001 cls.lpszMenuName = NULL;
6002 cls.lpszClassName = className;
6003 SetLastError(0xdeadbeef);
6004 ok(RegisterClassA(&cls),"RegisterClassA failed, error: %u\n", GetLastError());
6006 for(i = 0; i < NUMBER_OF_THICK_CHILD_TESTS; i++)
6008 test_thick_child_name = styleName[i];
6009 test_thick_child_style = styles[i];
6010 test_thick_child_exStyle = exStyles[i];
6011 test_thick_child_got_minmax = FALSE;
6013 SetLastError(0xdeadbeef);
6014 childWindow = CreateWindowEx( exStyles[i], className, "", styles[i], 0, 0, 0, 0, parentWindow, 0, GetModuleHandleA(0), NULL );
6015 ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
6017 ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
6019 SetLastError(0xdeadbeef);
6020 success = GetWindowRect(childWindow, &childRect);
6021 ok(success,"GetWindowRect call failed, error: %u\n", GetLastError());
6022 childWidth = childRect.right - childRect.left;
6023 childHeight = childRect.bottom - childRect.top;
6025 adjustedStyle = styles[i];
6026 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
6027 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
6028 GetClientRect(GetParent(childWindow), &adjustedParentRect);
6029 AdjustWindowRectEx(&adjustedParentRect, adjustedStyle, FALSE, test_thick_child_exStyle);
6032 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
6034 expectedWidth = GetSystemMetrics(SM_CXMINTRACK);
6035 expectedHeight = GetSystemMetrics(SM_CYMINTRACK);
6039 expectedWidth = -2 * adjustedParentRect.left;
6040 expectedHeight = -2 * adjustedParentRect.top;
6043 ok((childWidth == expectedWidth) && (childHeight == expectedHeight),
6044 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
6045 test_thick_child_name, expectedWidth, expectedHeight, childWidth, childHeight);
6047 SetLastError(0xdeadbeef);
6048 success = DestroyWindow(childWindow);
6049 ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
6051 ok(UnregisterClass(className, GetModuleHandleA(0)),"UnregisterClass call failed\n");
6054 static void test_handles( HWND full_hwnd )
6056 HWND hwnd = full_hwnd;
6060 SetLastError( 0xdeadbeef );
6061 ret = GetWindowRect( hwnd, &rect );
6062 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6065 if ((ULONG_PTR)full_hwnd >> 32)
6066 hwnd = (HWND)((ULONG_PTR)full_hwnd & ~0u);
6068 hwnd = (HWND)((ULONG_PTR)full_hwnd | ((ULONG_PTR)~0u << 32));
6069 SetLastError( 0xdeadbeef );
6070 ret = GetWindowRect( hwnd, &rect );
6071 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6073 hwnd = (HWND)(((ULONG_PTR)full_hwnd & ~0u) | ((ULONG_PTR)0x1234 << 32));
6074 SetLastError( 0xdeadbeef );
6075 ret = GetWindowRect( hwnd, &rect );
6076 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6078 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x9876 << 16));
6079 SetLastError( 0xdeadbeef );
6080 ret = GetWindowRect( hwnd, &rect );
6081 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
6082 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
6084 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x12345678 << 16));
6085 SetLastError( 0xdeadbeef );
6086 ret = GetWindowRect( hwnd, &rect );
6087 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
6088 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
6092 static void test_winregion(void)
6099 if (!pGetWindowRgnBox)
6101 win_skip("GetWindowRgnBox not supported\n");
6105 hwnd = CreateWindowExA(0, "static", NULL, WS_VISIBLE, 10, 10, 10, 10, NULL, 0, 0, NULL);
6107 SetLastError(0xdeadbeef);
6108 ret = pGetWindowRgnBox(hwnd, NULL);
6109 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
6110 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
6112 hrgn = CreateRectRgn(2, 3, 10, 15);
6113 ok( hrgn != NULL, "Region creation failed\n");
6116 SetWindowRgn(hwnd, hrgn, FALSE);
6118 SetLastError(0xdeadbeef);
6119 ret = pGetWindowRgnBox(hwnd, NULL);
6120 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
6121 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
6123 r.left = r.top = r.right = r.bottom = 0;
6124 ret = pGetWindowRgnBox(hwnd, &r);
6125 ok( ret == SIMPLEREGION, "Expected SIMPLEREGION, got %d\n", ret);
6126 ok( r.left == 2 && r.top == 3 && r.right == 10 && r.bottom == 15,
6127 "Expected (2,3,10,15), got (%d,%d,%d,%d)\n", r.left, r.top,
6131 DestroyWindow(hwnd);
6136 HMODULE user32 = GetModuleHandleA( "user32.dll" );
6137 HMODULE gdi32 = GetModuleHandleA("gdi32.dll");
6138 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
6139 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
6140 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
6141 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
6142 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
6143 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
6144 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
6145 pGetWindowRgnBox = (void *)GetProcAddress( user32, "GetWindowRgnBox" );
6146 pGetGUIThreadInfo = (void *)GetProcAddress( user32, "GetGUIThreadInfo" );
6147 pGetProcessDefaultLayout = (void *)GetProcAddress( user32, "GetProcessDefaultLayout" );
6148 pSetProcessDefaultLayout = (void *)GetProcAddress( user32, "SetProcessDefaultLayout" );
6149 pGetLayout = (void *)GetProcAddress( gdi32, "GetLayout" );
6150 pSetLayout = (void *)GetProcAddress( gdi32, "SetLayout" );
6152 if (!RegisterWindowClasses()) assert(0);
6154 SetLastError(0xdeafbeef);
6155 GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC);
6156 is_win9x = (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED);
6158 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
6159 if (!hhook) win_skip( "Cannot set CBT hook, skipping some tests\n" );
6161 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
6162 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
6163 WS_MAXIMIZEBOX | WS_POPUP,
6165 0, 0, GetModuleHandle(0), NULL);
6166 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
6167 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
6168 WS_MAXIMIZEBOX | WS_POPUP,
6170 0, 0, GetModuleHandle(0), NULL);
6172 assert( hwndMain2 );
6174 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
6176 /* Add the tests below this line */
6177 test_thick_child_size(hwndMain);
6179 test_hwnd_message();
6180 test_nonclient_area(hwndMain);
6182 test_GetWindowModuleFileName();
6185 test_capture_3(hwndMain, hwndMain2);
6188 test_CreateWindow();
6189 test_parent_owner();
6191 test_enum_thread_windows();
6195 test_SetWindowPos(hwndMain);
6196 test_SetMenu(hwndMain);
6197 test_SetFocus(hwndMain);
6198 test_SetActiveWindow(hwndMain);
6201 test_children_zorder(hwndMain);
6202 test_popup_zorder(hwndMain2, hwndMain, WS_POPUP);
6203 test_popup_zorder(hwndMain2, hwndMain, 0);
6204 test_keyboard_input(hwndMain);
6205 test_mouse_input(hwndMain);
6206 test_validatergn(hwndMain);
6207 test_nccalcscroll( hwndMain);
6208 test_scrollwindow( hwndMain);
6209 test_scrollvalidate( hwndMain);
6210 test_scrolldc( hwndMain);
6212 test_IsWindowUnicode();
6213 test_vis_rgn(hwndMain);
6215 test_AdjustWindowRect();
6216 test_window_styles();
6219 test_SetWindowLong();
6221 if (0) test_gettext(); /* crashes on NT4 */
6222 test_GetUpdateRect();
6224 test_layered_window();
6226 test_SetForegroundWindow(hwndMain);
6227 test_shell_window();
6228 test_handles( hwndMain );
6231 /* add the tests above this line */
6232 if (hhook) UnhookWindowsHookEx(hhook);
6234 DestroyWindow(hwndMain2);
6235 DestroyWindow(hwndMain);