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, "bad winpos->cx %d\n", winpos->cx);
682 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
686 case WM_WINDOWPOSCHANGED:
689 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
690 trace("main: WM_WINDOWPOSCHANGED %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
691 winpos->hwnd, winpos->hwndInsertAfter,
692 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
693 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
694 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
696 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
697 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
699 GetWindowRect(hwnd, &rc1);
700 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
701 /* note: winpos coordinates are relative to parent */
702 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
705 /* Uncomment this once the test succeeds in all cases */
706 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
707 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
709 GetClientRect(hwnd, &rc2);
710 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
711 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
712 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
713 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
719 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
720 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
722 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
723 if (got_getminmaxinfo)
724 trace("%p got WM_GETMINMAXINFO\n", hwnd);
726 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
727 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
729 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
733 if (test_lbuttondown_flag)
735 ShowWindow((HWND)wparam, SW_SHOW);
736 flush_events( FALSE );
741 return DefWindowProcA(hwnd, msg, wparam, lparam);
744 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
748 case WM_GETMINMAXINFO:
750 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
752 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
753 dump_minmax_info( minmax );
754 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
759 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
760 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
762 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
763 if (got_getminmaxinfo)
764 trace("%p got WM_GETMINMAXINFO\n", hwnd);
766 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
767 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
769 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
774 return DefWindowProcA(hwnd, msg, wparam, lparam);
777 static BOOL RegisterWindowClasses(void)
781 cls.style = CS_DBLCLKS;
782 cls.lpfnWndProc = main_window_procA;
785 cls.hInstance = GetModuleHandleA(0);
787 cls.hCursor = LoadCursorA(0, IDC_ARROW);
788 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
789 cls.lpszMenuName = NULL;
790 cls.lpszClassName = "MainWindowClass";
792 if(!RegisterClassA(&cls)) return FALSE;
795 cls.lpfnWndProc = tool_window_procA;
798 cls.hInstance = GetModuleHandleA(0);
800 cls.hCursor = LoadCursorA(0, IDC_ARROW);
801 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
802 cls.lpszMenuName = NULL;
803 cls.lpszClassName = "ToolWindowClass";
805 if(!RegisterClassA(&cls)) return FALSE;
810 static void verify_window_info(const char *hook, HWND hwnd, const WINDOWINFO *info)
812 RECT rcWindow, rcClient;
815 ok(IsWindow(hwnd), "bad window handle %p in hook %s\n", hwnd, hook);
817 GetWindowRect(hwnd, &rcWindow);
818 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow for %p in hook %s\n", hwnd, hook);
820 GetClientRect(hwnd, &rcClient);
821 /* translate to screen coordinates */
822 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
823 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient for %p in hook %s\n", hwnd, hook);
825 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
826 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
827 info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE), hwnd, hook);
828 /* Windows reports some undocumented exstyles in WINDOWINFO, but
829 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
831 ok((info->dwExStyle & ~0xe0000800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
832 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
833 info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE), hwnd, hook);
834 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
835 if (GetForegroundWindow())
836 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
837 info->dwWindowStatus, status, GetActiveWindow(), GetForegroundWindow(), hook);
839 /* win2k and XP return broken border info in GetWindowInfo most of
840 * the time, so there is no point in testing it.
844 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
845 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
846 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
847 ok(info->cyWindowBorders == border,
848 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
850 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType for %p in hook %s\n",
852 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
853 info->wCreatorVersion == 0x0500 /* Vista */,
854 "wrong wCreatorVersion %04x for %p in hook %s\n", info->wCreatorVersion, hwnd, hook);
857 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
859 AdjustWindowRectEx(rc, style, menu, exstyle);
860 /* AdjustWindowRectEx does not include scroll bars */
861 if (style & WS_VSCROLL)
863 if(exstyle & WS_EX_LEFTSCROLLBAR)
864 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
866 rc->right += GetSystemMetrics(SM_CXVSCROLL);
868 if (style & WS_HSCROLL)
869 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
872 static void test_nonclient_area(HWND hwnd)
874 DWORD style, exstyle;
875 RECT rc_window, rc_client, rc;
879 style = GetWindowLongA(hwnd, GWL_STYLE);
880 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
881 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
883 GetWindowRect(hwnd, &rc_window);
884 GetClientRect(hwnd, &rc_client);
886 /* avoid some cases when things go wrong */
887 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
888 rc_window.right > 32768 || rc_window.bottom > 32768) return;
890 CopyRect(&rc, &rc_client);
891 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
892 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
894 ok(EqualRect(&rc, &rc_window),
895 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
896 style, exstyle, menu, rc_window.left, rc_window.top, rc_window.right, rc_window.bottom,
897 rc.left, rc.top, rc.right, rc.bottom);
900 CopyRect(&rc, &rc_window);
901 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
902 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
903 ok(EqualRect(&rc, &rc_client),
904 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
905 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
906 rc.left, rc.top, rc.right, rc.bottom);
908 /* NULL rectangle shouldn't crash */
909 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
910 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
912 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
916 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
917 SetRect(&rc_client, 0, 0, 250, 150);
918 CopyRect(&rc_window, &rc_client);
919 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
920 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
922 CopyRect(&rc, &rc_window);
923 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
924 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
925 ok(EqualRect(&rc, &rc_client),
926 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
927 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
928 rc.left, rc.top, rc.right, rc.bottom);
931 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
933 static const char *CBT_code_name[10] = {
944 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
945 HWND hwnd = (HWND)wParam;
951 static const RECT rc_null;
954 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
955 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
960 info.cbSize = sizeof(WINDOWINFO);
961 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
962 verify_window_info(code_name, hwnd, &info);
965 /* WS_VISIBLE should be turned off yet */
966 style = createwnd->lpcs->style & ~WS_VISIBLE;
967 ok(style == GetWindowLongA(hwnd, GWL_STYLE),
968 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
969 GetWindowLongA(hwnd, GWL_STYLE), style);
973 /* Uncomment this once the test succeeds in all cases */
974 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
976 ok(GetParent(hwnd) == hwndMessage,
977 "wrong result from GetParent %p: message window %p\n",
978 GetParent(hwnd), hwndMessage);
981 ok(!GetParent(hwnd), "GetParent should return 0 at this point\n");
983 ok(!GetWindow(hwnd, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
987 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
988 * Win9x still has them set to 0.
990 ok(GetWindow(hwnd, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
991 ok(GetWindow(hwnd, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
993 ok(!GetWindow(hwnd, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
994 ok(!GetWindow(hwnd, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
998 /* Uncomment this once the test succeeds in all cases */
1001 ok(pGetAncestor(hwnd, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
1002 ok(pGetAncestor(hwnd, GA_ROOT) == hwnd,
1003 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOT), hwnd);
1005 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
1006 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwndMessage,
1007 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
1009 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwnd,
1010 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOTOWNER), hwnd);
1013 ok(GetWindowRect(hwnd, &rc), "GetWindowRect failed\n");
1014 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
1015 ok(GetClientRect(hwnd, &rc), "GetClientRect failed\n");
1016 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
1024 if (pGetWindowInfo && IsWindow(hwnd))
1028 /* Win98 actually does check the info.cbSize and doesn't allow
1029 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
1030 * WinXP do not check it at all.
1032 info.cbSize = sizeof(WINDOWINFO);
1033 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
1034 verify_window_info(code_name, hwnd, &info);
1037 /* on HCBT_DESTROYWND window state is undefined */
1038 case HCBT_DESTROYWND:
1044 return CallNextHookEx(hhook, nCode, wParam, lParam);
1047 static void test_shell_window(void)
1051 HMODULE hinst, hUser32;
1052 BOOL (WINAPI*SetShellWindow)(HWND);
1053 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
1054 HWND shellWindow, nextWnd;
1058 win_skip("Skipping shell window test on Win9x\n");
1062 shellWindow = GetShellWindow();
1063 hinst = GetModuleHandle(0);
1064 hUser32 = GetModuleHandleA("user32");
1066 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
1068 trace("previous shell window: %p\n", shellWindow);
1074 GetWindowThreadProcessId(shellWindow, &pid);
1075 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
1078 skip( "cannot get access to shell process\n" );
1082 SetLastError(0xdeadbeef);
1083 ret = DestroyWindow(shellWindow);
1084 error = GetLastError();
1086 ok(!ret, "DestroyWindow(shellWindow)\n");
1087 /* passes on Win XP, but not on Win98 */
1088 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
1089 "got %u after DestroyWindow(shellWindow)\n", error);
1091 /* close old shell instance */
1092 ret = TerminateProcess(hProcess, 0);
1093 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1094 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
1095 CloseHandle(hProcess);
1098 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
1099 trace("created window 1: %p\n", hwnd1);
1101 ret = SetShellWindow(hwnd1);
1102 ok(ret, "first call to SetShellWindow(hwnd1)\n");
1103 shellWindow = GetShellWindow();
1104 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
1106 ret = SetShellWindow(hwnd1);
1107 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1109 ret = SetShellWindow(0);
1110 error = GetLastError();
1111 /* passes on Win XP, but not on Win98
1112 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1113 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1115 ret = SetShellWindow(hwnd1);
1116 /* passes on Win XP, but not on Win98
1117 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1119 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1120 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
1121 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1123 ret = DestroyWindow(hwnd1);
1124 ok(ret, "DestroyWindow(hwnd1)\n");
1126 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1127 trace("created window 2: %p\n", hwnd2);
1128 ret = SetShellWindow(hwnd2);
1129 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1131 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1132 trace("created window 3: %p\n", hwnd3);
1134 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1135 trace("created window 4: %p\n", hwnd4);
1137 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1138 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1140 ret = SetShellWindow(hwnd4);
1141 ok(ret, "SetShellWindow(hwnd4)\n");
1142 shellWindow = GetShellWindow();
1143 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1145 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1146 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1148 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1149 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1151 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1152 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1154 ret = SetShellWindow(hwnd3);
1155 ok(!ret, "SetShellWindow(hwnd3)\n");
1156 shellWindow = GetShellWindow();
1157 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1159 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1160 trace("created window 5: %p\n", hwnd5);
1161 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1162 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1166 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1167 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1170 /* destroy test windows */
1171 DestroyWindow(hwnd2);
1172 DestroyWindow(hwnd3);
1173 DestroyWindow(hwnd4);
1174 DestroyWindow(hwnd5);
1177 /************** MDI test ****************/
1179 static char mdi_lParam_test_message[] = "just a test string";
1181 static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
1183 MDICREATESTRUCTA mdi_cs;
1186 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1187 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1188 BOOL isWin9x = FALSE;
1190 mdi_cs.szClass = "MDI_child_Class_1";
1191 mdi_cs.szTitle = "MDI child";
1192 mdi_cs.hOwner = GetModuleHandle(0);
1193 mdi_cs.x = CW_USEDEFAULT;
1194 mdi_cs.y = CW_USEDEFAULT;
1195 mdi_cs.cx = CW_USEDEFAULT;
1196 mdi_cs.cy = CW_USEDEFAULT;
1198 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1199 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1200 ok(mdi_child != 0, "MDI child creation failed\n");
1201 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1202 ok(id == first_id, "wrong child id %ld\n", id);
1203 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1204 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1206 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
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 = 0xffffffff; /* with WS_POPUP */
1215 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1216 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1218 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1222 ok(mdi_child != 0, "MDI child creation failed\n");
1223 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1224 ok(id == first_id, "wrong child id %ld\n", id);
1225 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1226 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1229 /* test MDICREATESTRUCT A<->W mapping */
1230 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1232 mdi_cs.szClass = (LPCSTR)classW;
1233 mdi_cs.szTitle = (LPCSTR)titleW;
1234 SetLastError(0xdeadbeef);
1235 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1238 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1241 ok(mdi_child != 0, "MDI child creation failed\n");
1245 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1246 ok(id == first_id, "wrong child id %ld\n", id);
1247 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1248 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1251 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1253 CW_USEDEFAULT, CW_USEDEFAULT,
1254 CW_USEDEFAULT, CW_USEDEFAULT,
1255 mdi_client, GetModuleHandle(0),
1256 (LPARAM)mdi_lParam_test_message);
1257 ok(mdi_child != 0, "MDI child creation failed\n");
1258 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1259 ok(id == first_id, "wrong child id %ld\n", id);
1260 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1261 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1263 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1264 0x7fffffff, /* without WS_POPUP */
1265 CW_USEDEFAULT, CW_USEDEFAULT,
1266 CW_USEDEFAULT, CW_USEDEFAULT,
1267 mdi_client, GetModuleHandle(0),
1268 (LPARAM)mdi_lParam_test_message);
1269 ok(mdi_child != 0, "MDI child creation failed\n");
1270 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1271 ok(id == first_id, "wrong child id %ld\n", id);
1272 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1273 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1275 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1276 0xffffffff, /* with WS_POPUP */
1277 CW_USEDEFAULT, CW_USEDEFAULT,
1278 CW_USEDEFAULT, CW_USEDEFAULT,
1279 mdi_client, GetModuleHandle(0),
1280 (LPARAM)mdi_lParam_test_message);
1281 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1283 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1287 ok(mdi_child != 0, "MDI child creation failed\n");
1288 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1289 ok(id == first_id, "wrong child id %ld\n", id);
1290 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1291 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1294 /* test MDICREATESTRUCT A<->W mapping */
1295 SetLastError(0xdeadbeef);
1296 mdi_child = CreateMDIWindowW(classW, titleW,
1298 CW_USEDEFAULT, CW_USEDEFAULT,
1299 CW_USEDEFAULT, CW_USEDEFAULT,
1300 mdi_client, GetModuleHandle(0),
1301 (LPARAM)mdi_lParam_test_message);
1304 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1307 ok(mdi_child != 0, "MDI child creation failed\n");
1311 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1312 ok(id == first_id, "wrong child id %ld\n", id);
1313 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1314 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1317 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1319 CW_USEDEFAULT, CW_USEDEFAULT,
1320 CW_USEDEFAULT, CW_USEDEFAULT,
1321 mdi_client, 0, GetModuleHandle(0),
1322 mdi_lParam_test_message);
1323 ok(mdi_child != 0, "MDI child creation failed\n");
1324 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1325 ok(id == first_id, "wrong child id %ld\n", id);
1326 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1327 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1329 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1330 0x7fffffff, /* without WS_POPUP */
1331 CW_USEDEFAULT, CW_USEDEFAULT,
1332 CW_USEDEFAULT, CW_USEDEFAULT,
1333 mdi_client, 0, GetModuleHandle(0),
1334 mdi_lParam_test_message);
1335 ok(mdi_child != 0, "MDI child creation failed\n");
1336 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1337 ok(id == first_id, "wrong child id %ld\n", id);
1338 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1339 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1341 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1342 0xffffffff, /* with WS_POPUP */
1343 CW_USEDEFAULT, CW_USEDEFAULT,
1344 CW_USEDEFAULT, CW_USEDEFAULT,
1345 mdi_client, 0, GetModuleHandle(0),
1346 mdi_lParam_test_message);
1347 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1349 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1353 ok(mdi_child != 0, "MDI child creation failed\n");
1354 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1355 ok(id == first_id, "wrong child id %ld\n", id);
1356 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1357 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1360 /* test MDICREATESTRUCT A<->W mapping */
1361 SetLastError(0xdeadbeef);
1362 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1364 CW_USEDEFAULT, CW_USEDEFAULT,
1365 CW_USEDEFAULT, CW_USEDEFAULT,
1366 mdi_client, 0, GetModuleHandle(0),
1367 mdi_lParam_test_message);
1370 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1373 ok(mdi_child != 0, "MDI child creation failed\n");
1377 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1378 ok(id == first_id, "wrong child id %ld\n", id);
1379 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1380 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1383 /* This test fails on Win9x */
1386 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1388 CW_USEDEFAULT, CW_USEDEFAULT,
1389 CW_USEDEFAULT, CW_USEDEFAULT,
1390 parent, 0, GetModuleHandle(0),
1391 mdi_lParam_test_message);
1392 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1395 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1396 WS_CHILD, /* without WS_POPUP */
1397 CW_USEDEFAULT, CW_USEDEFAULT,
1398 CW_USEDEFAULT, CW_USEDEFAULT,
1399 mdi_client, 0, GetModuleHandle(0),
1400 mdi_lParam_test_message);
1401 ok(mdi_child != 0, "MDI child creation failed\n");
1402 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1403 ok(id == 0, "wrong child id %ld\n", id);
1404 DestroyWindow(mdi_child);
1406 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1407 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1408 CW_USEDEFAULT, CW_USEDEFAULT,
1409 CW_USEDEFAULT, CW_USEDEFAULT,
1410 mdi_client, 0, GetModuleHandle(0),
1411 mdi_lParam_test_message);
1412 ok(mdi_child != 0, "MDI child creation failed\n");
1413 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1414 ok(id == 0, "wrong child id %ld\n", id);
1415 DestroyWindow(mdi_child);
1417 /* maximized child */
1418 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1419 WS_CHILD | WS_MAXIMIZE,
1420 CW_USEDEFAULT, CW_USEDEFAULT,
1421 CW_USEDEFAULT, CW_USEDEFAULT,
1422 mdi_client, 0, GetModuleHandle(0),
1423 mdi_lParam_test_message);
1424 ok(mdi_child != 0, "MDI child creation failed\n");
1425 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1426 ok(id == 0, "wrong child id %ld\n", id);
1427 DestroyWindow(mdi_child);
1429 trace("Creating maximized child with a caption\n");
1430 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1431 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1432 CW_USEDEFAULT, CW_USEDEFAULT,
1433 CW_USEDEFAULT, CW_USEDEFAULT,
1434 mdi_client, 0, GetModuleHandle(0),
1435 mdi_lParam_test_message);
1436 ok(mdi_child != 0, "MDI child creation failed\n");
1437 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1438 ok(id == 0, "wrong child id %ld\n", id);
1439 DestroyWindow(mdi_child);
1441 trace("Creating maximized child with a caption and a thick frame\n");
1442 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1443 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1444 CW_USEDEFAULT, CW_USEDEFAULT,
1445 CW_USEDEFAULT, CW_USEDEFAULT,
1446 mdi_client, 0, GetModuleHandle(0),
1447 mdi_lParam_test_message);
1448 ok(mdi_child != 0, "MDI child creation failed\n");
1449 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1450 ok(id == 0, "wrong child id %ld\n", id);
1451 DestroyWindow(mdi_child);
1454 /**********************************************************************
1455 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1457 * Note: The rule here is that client rect of the maximized MDI child
1458 * is equal to the client rect of the MDI client window.
1460 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1464 GetClientRect( client, &rect );
1465 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1466 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1468 rect.right -= rect.left;
1469 rect.bottom -= rect.top;
1470 lpMinMax->ptMaxSize.x = rect.right;
1471 lpMinMax->ptMaxSize.y = rect.bottom;
1473 lpMinMax->ptMaxPosition.x = rect.left;
1474 lpMinMax->ptMaxPosition.y = rect.top;
1476 trace("max rect (%d,%d - %d, %d)\n",
1477 rect.left, rect.top, rect.right, rect.bottom);
1480 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1487 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1488 MDICREATESTRUCTA *mdi_cs = cs->lpCreateParams;
1490 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1491 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1493 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1494 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1495 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1496 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1497 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1499 /* MDICREATESTRUCT should have original values */
1500 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1501 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1502 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1503 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1504 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1505 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1507 /* CREATESTRUCT should have fixed values */
1508 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1509 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1511 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1512 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1513 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1515 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1517 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1519 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1520 ok(cs->style == style,
1521 "cs->style does not match (%08x)\n", cs->style);
1525 LONG style = mdi_cs->style;
1527 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1528 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1529 ok(cs->style == style,
1530 "cs->style does not match (%08x)\n", cs->style);
1535 case WM_GETMINMAXINFO:
1537 HWND client = GetParent(hwnd);
1539 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1540 MINMAXINFO my_minmax;
1541 LONG style, exstyle;
1543 style = GetWindowLongA(hwnd, GWL_STYLE);
1544 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1546 GetWindowRect(client, &rc);
1547 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1548 GetClientRect(client, &rc);
1549 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1550 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1551 GetSystemMetrics(SM_CYSCREEN));
1553 GetClientRect(client, &rc);
1554 if ((style & WS_CAPTION) == WS_CAPTION)
1555 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1556 AdjustWindowRectEx(&rc, style, 0, exstyle);
1557 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1558 dump_minmax_info( minmax );
1560 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1561 minmax->ptMaxSize.x, rc.right - rc.left);
1562 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1563 minmax->ptMaxSize.y, rc.bottom - rc.top);
1565 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1567 trace("DefMDIChildProc returned:\n");
1568 dump_minmax_info( minmax );
1570 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1571 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1572 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1573 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1574 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1579 case WM_MDIACTIVATE:
1581 HWND active, client = GetParent(hwnd);
1582 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1583 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1584 if (hwnd == (HWND)lparam) /* if we are being activated */
1585 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1587 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1591 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1594 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1601 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1603 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE",
1604 cs->x, cs->y, cs->cx, cs->cy);
1606 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1607 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1609 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1610 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1612 /* CREATESTRUCT should have fixed values */
1613 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1615 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1616 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1618 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1619 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1620 while Win95, Win2k, WinXP do. */
1621 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1622 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1626 case WM_GETMINMAXINFO:
1628 HWND parent = GetParent(hwnd);
1630 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1631 LONG style, exstyle;
1633 style = GetWindowLongA(hwnd, GWL_STYLE);
1634 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1636 GetClientRect(parent, &rc);
1637 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1639 GetClientRect(parent, &rc);
1640 if ((style & WS_CAPTION) == WS_CAPTION)
1641 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1642 AdjustWindowRectEx(&rc, style, 0, exstyle);
1643 dump_minmax_info( minmax );
1645 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1646 minmax->ptMaxSize.x, rc.right - rc.left);
1647 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1648 minmax->ptMaxSize.y, rc.bottom - rc.top);
1652 case WM_WINDOWPOSCHANGED:
1654 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1657 GetWindowRect(hwnd, &rc1);
1658 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1659 /* note: winpos coordinates are relative to parent */
1660 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1661 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) pos=(%d,%d)-(%d,%d)\n",
1662 rc1.left, rc1.top, rc1.right, rc1.bottom,
1663 rc2.left, rc2.top, rc2.right, rc2.bottom);
1664 GetWindowRect(hwnd, &rc1);
1665 GetClientRect(hwnd, &rc2);
1666 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1667 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1668 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1669 rc1.left, rc1.top, rc1.right, rc1.bottom,
1670 rc2.left, rc2.top, rc2.right, rc2.bottom);
1673 case WM_WINDOWPOSCHANGING:
1675 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1676 WINDOWPOS my_winpos = *winpos;
1678 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1679 (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
1680 winpos->hwnd, winpos->hwndInsertAfter,
1681 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1683 DefWindowProcA(hwnd, msg, wparam, lparam);
1685 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1686 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1687 winpos->hwnd, winpos->hwndInsertAfter,
1688 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1693 return DefWindowProcA(hwnd, msg, wparam, lparam);
1696 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1698 static HWND mdi_client;
1704 CLIENTCREATESTRUCT client_cs;
1707 GetClientRect(hwnd, &rc);
1709 client_cs.hWindowMenu = 0;
1710 client_cs.idFirstChild = 1;
1712 /* MDIClient without MDIS_ALLCHILDSTYLES */
1713 mdi_client = CreateWindowExA(0, "mdiclient",
1715 WS_CHILD /*| WS_VISIBLE*/,
1716 /* tests depend on a not zero MDIClient size */
1717 0, 0, rc.right, rc.bottom,
1718 hwnd, 0, GetModuleHandle(0),
1721 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1722 DestroyWindow(mdi_client);
1724 /* MDIClient with MDIS_ALLCHILDSTYLES */
1725 mdi_client = CreateWindowExA(0, "mdiclient",
1727 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1728 /* tests depend on a not zero MDIClient size */
1729 0, 0, rc.right, rc.bottom,
1730 hwnd, 0, GetModuleHandle(0),
1733 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1734 DestroyWindow(mdi_client);
1738 case WM_WINDOWPOSCHANGED:
1740 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1743 GetWindowRect(hwnd, &rc1);
1744 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1745 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1746 /* note: winpos coordinates are relative to parent */
1747 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1748 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1749 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1751 GetWindowRect(hwnd, &rc1);
1752 GetClientRect(hwnd, &rc2);
1753 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1754 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1755 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1758 case WM_WINDOWPOSCHANGING:
1760 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1761 WINDOWPOS my_winpos = *winpos;
1763 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1764 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1765 winpos->hwnd, winpos->hwndInsertAfter,
1766 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1768 DefWindowProcA(hwnd, msg, wparam, lparam);
1770 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1771 winpos->hwnd, winpos->hwndInsertAfter,
1772 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1774 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1775 "DefWindowProc should not change WINDOWPOS values\n");
1784 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1787 static BOOL mdi_RegisterWindowClasses(void)
1792 cls.lpfnWndProc = mdi_main_wnd_procA;
1795 cls.hInstance = GetModuleHandleA(0);
1797 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1798 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1799 cls.lpszMenuName = NULL;
1800 cls.lpszClassName = "MDI_parent_Class";
1801 if(!RegisterClassA(&cls)) return FALSE;
1803 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1804 cls.lpszClassName = "MDI_child_Class_1";
1805 if(!RegisterClassA(&cls)) return FALSE;
1807 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1808 cls.lpszClassName = "MDI_child_Class_2";
1809 if(!RegisterClassA(&cls)) return FALSE;
1814 static void test_mdi(void)
1819 if (!mdi_RegisterWindowClasses()) assert(0);
1821 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1822 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1823 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1824 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1825 GetDesktopWindow(), 0,
1826 GetModuleHandle(0), NULL);
1827 assert(mdi_hwndMain);
1829 while(GetMessage(&msg, 0, 0, 0))
1831 TranslateMessage(&msg);
1832 DispatchMessage(&msg);
1835 DestroyWindow(mdi_hwndMain);
1838 static void test_icons(void)
1842 HICON icon = LoadIconA(0, IDI_APPLICATION);
1843 HICON icon2 = LoadIconA(0, IDI_QUESTION);
1844 HICON small_icon = LoadImageA(0, IDI_APPLICATION, IMAGE_ICON,
1845 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1848 cls.cbSize = sizeof(cls);
1850 cls.lpfnWndProc = DefWindowProcA;
1854 cls.hIcon = LoadIconA(0, IDI_HAND);
1855 cls.hIconSm = small_icon;
1856 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1857 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1858 cls.lpszMenuName = NULL;
1859 cls.lpszClassName = "IconWindowClass";
1861 RegisterClassExA(&cls);
1863 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1864 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1867 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1868 ok( res == 0, "wrong big icon %p/0\n", res );
1869 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1870 ok( res == 0, "wrong previous big icon %p/0\n", res );
1871 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1872 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1873 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1874 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1875 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1876 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1878 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1879 ok( res == 0, "wrong small icon %p/0\n", res );
1880 /* this test is XP specific */
1881 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1882 ok( res != 0, "wrong small icon %p\n", res );*/
1883 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1884 ok( res == 0, "wrong previous small icon %p/0\n", res );
1885 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1886 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1887 /* this test is XP specific */
1888 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1889 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1890 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1891 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1892 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1893 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1894 /* this test is XP specific */
1895 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1896 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1898 /* make sure the big icon hasn't changed */
1899 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1900 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1902 DestroyWindow( hwnd );
1905 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1907 if (msg == WM_NCCALCSIZE)
1909 RECT *rect = (RECT *)lparam;
1910 /* first time around increase the rectangle, next time decrease it */
1911 if (rect->left == 100) InflateRect( rect, 10, 10 );
1912 else InflateRect( rect, -10, -10 );
1915 return DefWindowProc( hwnd, msg, wparam, lparam );
1918 static void test_SetWindowPos(HWND hwnd)
1920 RECT orig_win_rc, rect;
1923 SetRect(&rect, 111, 222, 333, 444);
1924 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1925 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1926 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1928 SetRect(&rect, 111, 222, 333, 444);
1929 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1930 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1931 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1933 GetWindowRect(hwnd, &orig_win_rc);
1935 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1936 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1937 GetWindowRect( hwnd, &rect );
1938 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1939 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1940 GetClientRect( hwnd, &rect );
1941 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1942 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1943 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1945 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1946 GetWindowRect( hwnd, &rect );
1947 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1948 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1949 GetClientRect( hwnd, &rect );
1950 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1951 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1952 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1954 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1955 orig_win_rc.right, orig_win_rc.bottom, 0);
1956 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1958 /* Win9x truncates coordinates to 16-bit irrespectively */
1961 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1962 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1964 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1965 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1968 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1969 orig_win_rc.right, orig_win_rc.bottom, 0);
1971 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1972 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1973 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1974 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1975 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1976 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1977 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1980 static void test_SetMenu(HWND parent)
1987 hMenu = CreateMenu();
1990 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1993 /* fails on (at least) Wine, NT4, XP SP2 */
1994 test_nonclient_area(parent);
1996 ret = GetMenu(parent);
1997 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1998 /* test whether we can destroy a menu assigned to a window */
1999 retok = DestroyMenu(hMenu);
2000 ok( retok, "DestroyMenu error %d\n", GetLastError());
2001 retok = IsMenu(hMenu);
2002 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
2003 ret = GetMenu(parent);
2004 /* This test fails on Win9x */
2006 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2007 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2008 test_nonclient_area(parent);
2010 hMenu = CreateMenu();
2014 ret = GetMenu(parent);
2015 ok(ret == 0, "unexpected menu id %p\n", ret);
2017 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2018 test_nonclient_area(parent);
2019 ret = GetMenu(parent);
2020 ok(ret == 0, "unexpected menu id %p\n", ret);
2022 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2025 /* fails on (at least) Wine, NT4, XP SP2 */
2026 test_nonclient_area(parent);
2028 ret = GetMenu(parent);
2029 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2031 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2032 test_nonclient_area(parent);
2033 ret = GetMenu(parent);
2034 ok(ret == 0, "unexpected menu id %p\n", ret);
2037 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
2040 ret = GetMenu(child);
2041 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2043 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2044 test_nonclient_area(child);
2045 ret = GetMenu(child);
2046 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2048 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
2049 test_nonclient_area(child);
2050 ret = GetMenu(child);
2051 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2053 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
2054 test_nonclient_area(child);
2055 ret = GetMenu(child);
2056 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2058 style = GetWindowLong(child, GWL_STYLE);
2059 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
2060 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
2061 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
2062 SetWindowLong(child, GWL_STYLE, style);
2064 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
2065 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
2066 SetWindowLong(child, GWL_STYLE, style);
2068 DestroyWindow(child);
2072 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
2074 HWND child[5], hwnd;
2079 hwnd = GetWindow(parent, GW_CHILD);
2080 ok(!hwnd, "have to start without children to perform the test\n");
2082 for (i = 0; i < total; i++)
2084 if (style[i] & DS_CONTROL)
2086 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
2087 0,0,0,0, parent, (HMENU)i, 0, NULL);
2088 if (style[i] & WS_VISIBLE)
2089 ShowWindow(child[i], SW_SHOW);
2091 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
2094 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
2095 parent, (HMENU)i, 0, NULL);
2096 trace("child[%ld] = %p\n", i, child[i]);
2097 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
2100 hwnd = GetWindow(parent, GW_CHILD);
2101 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
2102 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
2103 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
2105 for (i = 0; i < total; i++)
2107 trace("hwnd[%ld] = %p\n", i, hwnd);
2108 ok(child[order[i]] == hwnd, "Z order of child #%ld is wrong\n", i);
2110 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
2113 for (i = 0; i < total; i++)
2114 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2117 static void test_children_zorder(HWND parent)
2119 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2121 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2123 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2124 WS_CHILD | WS_VISIBLE, WS_CHILD,
2125 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2126 const int complex_order_1[1] = { 0 };
2127 const int complex_order_2[2] = { 1, 0 };
2128 const int complex_order_3[3] = { 1, 0, 2 };
2129 const int complex_order_4[4] = { 1, 0, 2, 3 };
2130 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2131 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2132 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2133 WS_CHILD | WS_VISIBLE };
2134 const int complex_order_6[3] = { 0, 1, 2 };
2136 /* simple WS_CHILD */
2137 test_window_tree(parent, simple_style, simple_order, 5);
2139 /* complex children styles */
2140 test_window_tree(parent, complex_style, complex_order_1, 1);
2141 test_window_tree(parent, complex_style, complex_order_2, 2);
2142 test_window_tree(parent, complex_style, complex_order_3, 3);
2143 test_window_tree(parent, complex_style, complex_order_4, 4);
2144 test_window_tree(parent, complex_style, complex_order_5, 5);
2146 /* another set of complex children styles */
2147 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2150 #define check_z_order(hwnd, next, prev, owner, topmost) \
2151 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2154 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2155 BOOL topmost, const char *file, int line)
2160 test = GetWindow(hwnd, GW_HWNDNEXT);
2161 /* skip foreign windows */
2162 while (test && test != next &&
2163 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2164 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2165 GetWindow(test, GW_OWNER) == next))
2167 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2168 test = GetWindow(test, GW_HWNDNEXT);
2170 ok_(file, line)(next == test, "%p: expected next %p, got %p\n", hwnd, next, test);
2172 test = GetWindow(hwnd, GW_HWNDPREV);
2173 /* skip foreign windows */
2174 while (test && test != prev &&
2175 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2176 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2177 GetWindow(test, GW_OWNER) == hwnd))
2179 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2180 test = GetWindow(test, GW_HWNDPREV);
2182 ok_(file, line)(prev == test, "%p: expected prev %p, got %p\n", hwnd, prev, test);
2184 test = GetWindow(hwnd, GW_OWNER);
2185 ok_(file, line)(owner == test, "%p: expected owner %p, got %p\n", hwnd, owner, test);
2187 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2188 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "%p: expected %stopmost\n",
2189 hwnd, topmost ? "" : "NOT ");
2192 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E, DWORD style)
2194 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2196 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2198 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2200 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2201 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2203 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2204 WS_OVERLAPPED | WS_CAPTION,
2206 0, 0, GetModuleHandle(0), NULL);
2207 trace("hwnd_F %p\n", hwnd_F);
2208 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2210 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2211 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2212 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2213 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2215 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2218 hwnd_F, 0, GetModuleHandle(0), NULL);
2219 trace("hwnd_C %p\n", hwnd_C);
2220 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2221 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2222 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2223 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2225 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2228 hwnd_F, 0, GetModuleHandle(0), NULL);
2229 trace("hwnd_B %p\n", hwnd_B);
2230 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2231 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2232 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2233 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2234 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2236 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2239 0, 0, GetModuleHandle(0), NULL);
2240 trace("hwnd_A %p\n", hwnd_A);
2241 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2242 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2243 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2244 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2245 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2246 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2248 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);
2250 /* move hwnd_F and its popups up */
2251 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2252 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2253 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2254 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2255 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2256 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2257 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2259 /* move hwnd_F and its popups down */
2260 #if 0 /* enable once Wine is fixed to pass this test */
2261 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2262 check_z_order(hwnd_F, 0, 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_E, hwnd_F, FALSE);
2265 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2266 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2267 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2270 /* make hwnd_C owned by a topmost window */
2271 DestroyWindow( hwnd_C );
2272 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2275 hwnd_A, 0, GetModuleHandle(0), NULL);
2276 trace("hwnd_C %p\n", hwnd_C);
2277 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2278 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2279 check_z_order(hwnd_F, hwnd_D, hwnd_B, 0, FALSE);
2280 check_z_order(hwnd_B, hwnd_F, hwnd_A, hwnd_F, TRUE);
2281 check_z_order(hwnd_A, hwnd_B, hwnd_C, 0, TRUE);
2282 check_z_order(hwnd_C, hwnd_A, 0, hwnd_A, TRUE);
2284 DestroyWindow(hwnd_A);
2285 DestroyWindow(hwnd_B);
2286 DestroyWindow(hwnd_C);
2287 DestroyWindow(hwnd_F);
2290 static void test_vis_rgn( HWND hwnd )
2292 RECT win_rect, rgn_rect;
2293 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2296 ShowWindow(hwnd,SW_SHOW);
2297 hdc = GetDC( hwnd );
2298 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2299 GetWindowRect( hwnd, &win_rect );
2300 GetRgnBox( hrgn, &rgn_rect );
2303 trace("win9x, mapping to screen coords\n");
2304 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2306 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2307 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2308 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2309 rgn_rect.left, win_rect.left );
2310 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2311 rgn_rect.top, win_rect.top );
2312 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2313 rgn_rect.right, win_rect.right );
2314 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2315 rgn_rect.bottom, win_rect.bottom );
2316 ReleaseDC( hwnd, hdc );
2319 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2321 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2323 HWND child = GetWindow(hwnd, GW_CHILD);
2324 ok(child != 0, "couldn't find child window\n");
2326 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2329 return DefWindowProc(hwnd, msg, wp, lp);
2332 static void test_SetFocus(HWND hwnd)
2335 WNDPROC old_wnd_proc;
2337 /* check if we can set focus to non-visible windows */
2339 ShowWindow(hwnd, SW_SHOW);
2342 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2343 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2344 ShowWindow(hwnd, SW_HIDE);
2347 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2348 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2349 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2352 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2353 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2354 ShowWindow(child, SW_SHOW);
2355 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2356 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2357 ShowWindow(child, SW_HIDE);
2358 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2359 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2360 ShowWindow(child, SW_SHOW);
2361 child2 = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, child, 0, 0, NULL);
2363 ShowWindow(child2, SW_SHOW);
2365 ShowWindow(child, SW_HIDE);
2366 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2367 ok( GetFocus() == child2, "Focus should be on %p, not %p\n", child2, GetFocus() );
2368 ShowWindow(child, SW_SHOW);
2370 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2371 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2372 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2374 ShowWindow(child, SW_HIDE);
2376 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2377 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2378 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2379 ShowWindow(child, SW_HIDE);
2380 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2382 ShowWindow(hwnd, SW_SHOW);
2383 ShowWindow(child, SW_SHOW);
2385 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2386 EnableWindow(hwnd, FALSE);
2387 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2388 EnableWindow(hwnd, TRUE);
2390 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2391 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2392 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2394 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2395 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2396 ShowWindow(hwnd, SW_RESTORE);
2397 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2398 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2399 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2400 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2401 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 old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2405 ShowWindow(hwnd, SW_RESTORE);
2406 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2408 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2410 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2412 DestroyWindow( child2 );
2413 DestroyWindow( child );
2416 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
2417 static void check_wnd_state_(const char *file, int line,
2418 HWND active, HWND foreground, HWND focus, HWND capture)
2420 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2421 /* only check foreground if it belongs to the current thread */
2422 /* foreground can be moved to a different app pretty much at any time */
2423 if (foreground && GetForegroundWindow() &&
2424 GetWindowThreadProcessId(GetForegroundWindow(), NULL) == GetCurrentThreadId())
2425 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2426 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2427 ok_(file, line)(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2430 static void test_SetActiveWindow(HWND hwnd)
2434 flush_events( TRUE );
2435 ShowWindow(hwnd, SW_HIDE);
2438 check_wnd_state(0, 0, 0, 0);
2440 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2442 ShowWindow(hwnd, SW_SHOW);
2443 check_wnd_state(hwnd, hwnd, hwnd, 0);
2445 hwnd2 = SetActiveWindow(0);
2446 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2447 if (!GetActiveWindow()) /* doesn't always work on vista */
2449 check_wnd_state(0, 0, 0, 0);
2450 hwnd2 = SetActiveWindow(hwnd);
2451 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2453 check_wnd_state(hwnd, hwnd, hwnd, 0);
2455 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2456 check_wnd_state(hwnd, hwnd, hwnd, 0);
2458 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2459 check_wnd_state(hwnd, hwnd, hwnd, 0);
2461 ShowWindow(hwnd, SW_HIDE);
2462 check_wnd_state(0, 0, 0, 0);
2464 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2465 SetActiveWindow(hwnd);
2466 check_wnd_state(hwnd, hwnd, hwnd, 0);
2468 ShowWindow(hwnd, SW_SHOW);
2469 check_wnd_state(hwnd, hwnd, hwnd, 0);
2471 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2472 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2474 DestroyWindow(hwnd2);
2475 check_wnd_state(hwnd, hwnd, hwnd, 0);
2477 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2478 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2480 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2481 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2483 DestroyWindow(hwnd2);
2484 check_wnd_state(hwnd, hwnd, hwnd, 0);
2487 struct create_window_thread_params
2490 HANDLE window_created;
2491 HANDLE test_finished;
2494 static DWORD WINAPI create_window_thread(void *param)
2496 struct create_window_thread_params *p = param;
2500 p->window = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
2502 ret = SetEvent(p->window_created);
2503 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
2505 res = WaitForSingleObject(p->test_finished, INFINITE);
2506 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2508 DestroyWindow(p->window);
2512 static void test_SetForegroundWindow(HWND hwnd)
2514 struct create_window_thread_params thread_params;
2521 flush_events( TRUE );
2522 ShowWindow(hwnd, SW_HIDE);
2525 check_wnd_state(0, 0, 0, 0);
2527 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2529 ShowWindow(hwnd, SW_SHOW);
2530 check_wnd_state(hwnd, hwnd, hwnd, 0);
2532 hwnd2 = SetActiveWindow(0);
2533 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2534 if (GetActiveWindow() == hwnd) /* doesn't always work on vista */
2535 check_wnd_state(hwnd, hwnd, hwnd, 0);
2537 check_wnd_state(0, 0, 0, 0);
2539 ret = SetForegroundWindow(hwnd);
2542 skip( "SetForegroundWindow not working\n" );
2545 check_wnd_state(hwnd, hwnd, hwnd, 0);
2547 SetLastError(0xdeadbeef);
2548 ret = SetForegroundWindow(0);
2549 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2550 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
2551 broken(GetLastError() == 0xdeadbeef), /* win9x */
2552 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2553 check_wnd_state(hwnd, hwnd, hwnd, 0);
2555 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2556 check_wnd_state(hwnd, hwnd, hwnd, 0);
2558 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2559 check_wnd_state(hwnd, hwnd, hwnd, 0);
2561 hwnd2 = GetForegroundWindow();
2562 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2563 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2564 hwnd2 = GetForegroundWindow();
2565 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2567 ShowWindow(hwnd, SW_HIDE);
2568 check_wnd_state(0, 0, 0, 0);
2570 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2571 ret = SetForegroundWindow(hwnd);
2572 ok(ret || broken(!ret), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
2573 check_wnd_state(hwnd, hwnd, hwnd, 0);
2575 ShowWindow(hwnd, SW_SHOW);
2576 check_wnd_state(hwnd, hwnd, hwnd, 0);
2578 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2579 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2581 DestroyWindow(hwnd2);
2582 check_wnd_state(hwnd, hwnd, hwnd, 0);
2584 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2585 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2587 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2588 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2590 DestroyWindow(hwnd2);
2591 check_wnd_state(hwnd, hwnd, hwnd, 0);
2593 hwnd2 = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
2594 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2596 thread_params.window_created = CreateEvent(NULL, FALSE, FALSE, NULL);
2597 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
2598 thread_params.test_finished = CreateEvent(NULL, FALSE, FALSE, NULL);
2599 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
2600 thread = CreateThread(NULL, 0, create_window_thread, &thread_params, 0, &tid);
2601 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
2602 res = WaitForSingleObject(thread_params.window_created, INFINITE);
2603 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2604 check_wnd_state(hwnd2, thread_params.window, hwnd2, 0);
2606 SetForegroundWindow(hwnd2);
2607 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2609 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
2610 if (0) check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2611 todo_wine ok(GetActiveWindow() == hwnd2, "Expected active window %p, got %p.\n", hwnd2, GetActiveWindow());
2612 todo_wine ok(GetFocus() == hwnd2, "Expected focus window %p, got %p.\n", hwnd2, GetFocus());
2614 SetEvent(thread_params.test_finished);
2615 WaitForSingleObject(thread, INFINITE);
2616 CloseHandle(thread_params.test_finished);
2617 CloseHandle(thread_params.window_created);
2618 CloseHandle(thread);
2619 DestroyWindow(hwnd2);
2622 static WNDPROC old_button_proc;
2624 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2629 key_state = GetKeyState(VK_LBUTTON);
2630 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2632 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2634 if (msg == WM_LBUTTONDOWN)
2638 check_wnd_state(button, button, button, button);
2640 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2642 trace("hwnd %p\n", hwnd);
2644 check_wnd_state(button, button, button, button);
2646 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2648 check_wnd_state(button, button, button, button);
2650 DestroyWindow(hwnd);
2652 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2654 trace("hwnd %p\n", hwnd);
2656 check_wnd_state(button, button, button, button);
2658 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2659 * match internal button state.
2661 SendMessage(button, WM_KILLFOCUS, 0, 0);
2662 check_wnd_state(button, button, button, 0);
2664 ShowWindow(hwnd, SW_SHOW);
2665 check_wnd_state(hwnd, hwnd, hwnd, 0);
2667 capture = SetCapture(hwnd);
2668 ok(capture == 0, "SetCapture() = %p\n", capture);
2670 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2672 DestroyWindow(hwnd);
2674 check_wnd_state(button, 0, button, 0);
2680 static void test_capture_1(void)
2682 HWND button, capture, oldFocus, oldActive;
2684 oldFocus = GetFocus();
2685 oldActive = GetActiveWindow();
2687 capture = GetCapture();
2688 ok(capture == 0, "GetCapture() = %p\n", capture);
2690 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2692 trace("button %p\n", button);
2694 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2696 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2698 capture = SetCapture(button);
2699 ok(capture == 0, "SetCapture() = %p\n", capture);
2700 check_wnd_state(button, 0, button, button);
2702 DestroyWindow(button);
2703 check_wnd_state(oldActive, 0, oldFocus, 0);
2706 static void test_capture_2(void)
2708 HWND button, hwnd, capture, oldFocus, oldActive;
2710 oldFocus = GetFocus();
2711 oldActive = GetActiveWindow();
2712 check_wnd_state(oldActive, 0, oldFocus, 0);
2714 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2716 trace("button %p\n", button);
2718 check_wnd_state(button, button, button, 0);
2720 capture = SetCapture(button);
2721 ok(capture == 0, "SetCapture() = %p\n", capture);
2723 check_wnd_state(button, button, button, button);
2725 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2726 * internal button state.
2728 SendMessage(button, WM_KILLFOCUS, 0, 0);
2729 check_wnd_state(button, button, button, button);
2731 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2733 trace("hwnd %p\n", hwnd);
2735 check_wnd_state(button, button, button, button);
2737 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2739 check_wnd_state(button, button, button, button);
2741 DestroyWindow(hwnd);
2743 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2745 trace("hwnd %p\n", hwnd);
2747 check_wnd_state(button, button, button, button);
2749 ShowWindow(hwnd, SW_SHOW);
2751 check_wnd_state(hwnd, hwnd, hwnd, button);
2753 capture = SetCapture(hwnd);
2754 ok(capture == button, "SetCapture() = %p\n", capture);
2756 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2758 DestroyWindow(hwnd);
2759 check_wnd_state(button, button, button, 0);
2761 DestroyWindow(button);
2762 check_wnd_state(oldActive, 0, oldFocus, 0);
2765 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2769 ShowWindow(hwnd1, SW_HIDE);
2770 ShowWindow(hwnd2, SW_HIDE);
2772 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2773 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2776 check_wnd_state(0, 0, 0, hwnd1);
2779 check_wnd_state(0, 0, 0, hwnd2);
2781 ShowWindow(hwnd1, SW_SHOW);
2782 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2784 ret = ReleaseCapture();
2785 ok (ret, "releasecapture did not return TRUE.\n");
2786 ret = ReleaseCapture();
2787 ok (ret, "releasecapture did not return TRUE after second try.\n");
2790 static LRESULT CALLBACK test_capture_4_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2793 HWND cap_wnd, cap_wnd2, set_cap_wnd;
2797 case WM_CAPTURECHANGED:
2799 /* now try to release capture from menu. this should fail */
2800 if (pGetGUIThreadInfo)
2802 memset(>i, 0, sizeof(GUITHREADINFO));
2803 gti.cbSize = sizeof(GUITHREADINFO);
2804 status = pGetGUIThreadInfo(GetCurrentThreadId(), >i);
2805 ok(status, "GetGUIThreadInfo() failed!\n");
2806 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
2808 cap_wnd = GetCapture();
2810 /* check that re-setting the capture for the menu fails */
2811 set_cap_wnd = SetCapture(cap_wnd);
2812 ok(!set_cap_wnd || broken(set_cap_wnd == cap_wnd), /* nt4 */
2813 "SetCapture should have failed!\n");
2816 DestroyWindow(hWnd);
2820 /* check that SetCapture fails for another window and that it does not touch the error code */
2821 set_cap_wnd = SetCapture(hWnd);
2822 ok(!set_cap_wnd, "SetCapture should have failed!\n");
2824 /* check that ReleaseCapture fails and does not touch the error code */
2825 status = ReleaseCapture();
2826 ok(!status, "ReleaseCapture should have failed!\n");
2828 /* check that thread info did not change */
2829 if (pGetGUIThreadInfo)
2831 memset(>i, 0, sizeof(GUITHREADINFO));
2832 gti.cbSize = sizeof(GUITHREADINFO);
2833 status = pGetGUIThreadInfo(GetCurrentThreadId(), >i);
2834 ok(status, "GetGUIThreadInfo() failed!\n");
2835 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
2838 /* verify that no capture change took place */
2839 cap_wnd2 = GetCapture();
2840 ok(cap_wnd2 == cap_wnd, "Capture changed!\n");
2842 /* we are done. kill the window */
2843 DestroyWindow(hWnd);
2847 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
2852 /* Test that no-one can mess around with the current capture while a menu is open */
2853 static void test_capture_4(void)
2859 HINSTANCE hInstance = GetModuleHandleA( NULL );
2861 if (!pGetGUIThreadInfo)
2863 win_skip("GetGUIThreadInfo is not available\n");
2866 wclass.lpszClassName = "TestCapture4Class";
2867 wclass.style = CS_HREDRAW | CS_VREDRAW;
2868 wclass.lpfnWndProc = test_capture_4_proc;
2869 wclass.hInstance = hInstance;
2870 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
2871 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
2872 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2873 wclass.lpszMenuName = 0;
2874 wclass.cbClsExtra = 0;
2875 wclass.cbWndExtra = 0;
2876 assert (RegisterClassA( &wclass ));
2877 assert (hwnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
2878 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2879 400, 200, NULL, NULL, hInstance, NULL) );
2880 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
2882 hmenu = CreatePopupMenu();
2884 ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest2");
2885 ok( ret, "AppendMenuA has failed!\n");
2887 /* set main window to have initial capture */
2892 win_skip("TrackPopupMenu test crashes on Win9x/WinMe\n");
2896 /* create popup (it will self-destruct) */
2897 ret = TrackPopupMenu(hmenu, TPM_RETURNCMD, 100, 100, 0, hwnd, NULL);
2898 ok( ret == 0, "TrackPopupMenu returned %d expected zero\n", ret);
2903 DestroyWindow(hwnd);
2906 /* PeekMessage wrapper that ignores the messages we don't care about */
2907 static BOOL peek_message( MSG *msg )
2912 ret = PeekMessageA(msg, 0, 0, 0, PM_REMOVE);
2913 } while (ret && (msg->message == WM_TIMER || ignore_message(msg->message)));
2917 static void test_keyboard_input(HWND hwnd)
2922 flush_events( TRUE );
2923 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
2925 flush_events( TRUE );
2927 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2930 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2932 flush_events( TRUE );
2934 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2935 ret = peek_message(&msg);
2936 ok( ret, "no message available\n");
2937 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2938 ret = peek_message(&msg);
2939 ok( !ret, "message %04x available\n", msg.message);
2941 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2943 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2944 ret = peek_message(&msg);
2945 ok(ret, "no message available\n");
2946 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2947 ret = peek_message(&msg);
2948 ok( !ret, "message %04x available\n", msg.message);
2950 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2952 keybd_event(VK_SPACE, 0, 0, 0);
2953 if (!peek_message(&msg))
2955 skip( "keybd_event didn't work, skipping keyboard test\n" );
2958 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2959 ret = peek_message(&msg);
2960 ok( !ret, "message %04x available\n", msg.message);
2963 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2965 flush_events( TRUE );
2967 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2968 ret = peek_message(&msg);
2969 ok(ret, "no message available\n");
2970 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2971 ret = peek_message(&msg);
2972 ok( !ret, "message %04x available\n", msg.message);
2974 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2976 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2977 ret = peek_message(&msg);
2978 ok(ret, "no message available\n");
2979 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2980 ret = peek_message(&msg);
2981 ok( !ret, "message %04x available\n", msg.message);
2983 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2985 keybd_event(VK_SPACE, 0, 0, 0);
2986 ret = peek_message(&msg);
2987 ok(ret, "no message available\n");
2988 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2989 ret = peek_message(&msg);
2990 ok( !ret, "message %04x available\n", msg.message);
2993 static BOOL wait_for_message( MSG *msg )
2999 ret = peek_message(msg);
3002 if (msg->message == WM_PAINT) DispatchMessage(msg);
3005 else if (MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
3007 if (!ret) msg->message = 0;
3011 static void test_mouse_input(HWND hwnd)
3021 ShowWindow(hwnd, SW_SHOWNORMAL);
3023 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3025 GetWindowRect(hwnd, &rc);
3026 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
3028 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
3029 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
3032 ShowWindow(popup, SW_SHOW);
3033 UpdateWindow(popup);
3034 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3036 GetWindowRect(popup, &rc);
3037 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
3039 x = rc.left + (rc.right - rc.left) / 2;
3040 y = rc.top + (rc.bottom - rc.top) / 2;
3041 trace("setting cursor to (%d,%d)\n", x, y);
3045 if (x != pt.x || y != pt.y)
3047 skip( "failed to set mouse position, skipping mouse input tests\n" );
3051 flush_events( TRUE );
3053 /* Check that setting the same position may generate WM_MOUSEMOVE */
3056 ret = peek_message(&msg);
3059 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
3060 msg.hwnd, msg.message);
3061 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
3062 x, y, msg.pt.x, msg.pt.y);
3065 /* force the system to update its internal queue mouse position,
3066 * otherwise it won't generate relative mouse movements below.
3068 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3069 flush_events( TRUE );
3072 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3073 flush_events( FALSE );
3074 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
3075 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
3077 if (msg.message == WM_TIMER || ignore_message(msg.message)) continue;
3078 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
3079 "hwnd %p message %04x\n", msg.hwnd, msg.message);
3080 DispatchMessage(&msg);
3082 ret = peek_message(&msg);
3083 ok( !ret, "message %04x available\n", msg.message);
3085 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3086 ShowWindow(popup, SW_HIDE);
3087 ret = wait_for_message( &msg );
3089 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3090 flush_events( TRUE );
3092 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3093 ShowWindow(hwnd, SW_HIDE);
3094 ret = wait_for_message( &msg );
3095 ok( !ret, "message %04x available\n", msg.message);
3096 flush_events( TRUE );
3098 /* test mouse clicks */
3100 ShowWindow(hwnd, SW_SHOW);
3101 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3102 flush_events( TRUE );
3103 ShowWindow(popup, SW_SHOW);
3104 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3105 flush_events( TRUE );
3107 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3108 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3109 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3110 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3112 ret = wait_for_message( &msg );
3115 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
3118 if (msg.message == WM_MOUSEMOVE) /* win2k has an extra WM_MOUSEMOVE here */
3120 ret = wait_for_message( &msg );
3121 ok(ret, "no message available\n");
3124 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3125 msg.hwnd, popup, msg.message);
3127 ret = wait_for_message( &msg );
3128 ok(ret, "no message available\n");
3129 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3130 msg.hwnd, popup, msg.message);
3132 ret = wait_for_message( &msg );
3133 ok(ret, "no message available\n");
3134 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
3135 msg.hwnd, popup, msg.message);
3137 ret = wait_for_message( &msg );
3138 ok(ret, "no message available\n");
3139 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3140 msg.hwnd, popup, msg.message);
3142 ret = peek_message(&msg);
3143 ok(!ret, "message %04x available\n", msg.message);
3145 ShowWindow(popup, SW_HIDE);
3146 flush_events( TRUE );
3148 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3149 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3150 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3151 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3153 ret = wait_for_message( &msg );
3154 ok(ret, "no message available\n");
3155 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3156 msg.hwnd, hwnd, msg.message);
3157 ret = wait_for_message( &msg );
3158 ok(ret, "no message available\n");
3159 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3160 msg.hwnd, hwnd, msg.message);
3162 test_lbuttondown_flag = TRUE;
3163 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
3164 test_lbuttondown_flag = FALSE;
3166 ret = wait_for_message( &msg );
3167 ok(ret, "no message available\n");
3168 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3169 msg.hwnd, popup, msg.message);
3170 ok(peek_message(&msg), "no message available\n");
3171 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3172 msg.hwnd, popup, msg.message);
3173 ok(peek_message(&msg), "no message available\n");
3175 /* Test WM_MOUSEACTIVATE */
3176 #define TEST_MOUSEACTIVATE(A,B) \
3177 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
3178 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
3180 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
3181 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
3182 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
3183 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
3184 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
3185 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
3186 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
3187 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
3188 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
3189 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
3190 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
3191 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
3192 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
3193 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
3194 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
3195 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
3196 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
3197 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
3198 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
3199 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
3200 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
3201 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
3202 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
3203 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
3206 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
3207 flush_events( TRUE );
3209 DestroyWindow(popup);
3212 static void test_validatergn(HWND hwnd)
3218 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
3219 ShowWindow(hwnd, SW_SHOW);
3220 UpdateWindow( hwnd);
3221 /* test that ValidateRect validates children*/
3222 InvalidateRect( child, NULL, 1);
3223 GetWindowRect( child, &rc);
3224 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3225 ret = GetUpdateRect( child, &rc2, 0);
3226 ok( ret == 1, "Expected GetUpdateRect to return non-zero, got %d\n", ret);
3227 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
3228 "Update rectangle is empty!\n");
3229 ValidateRect( hwnd, &rc);
3230 ret = GetUpdateRect( child, &rc2, 0);
3231 ok( !ret, "Expected GetUpdateRect to return zero, got %d\n", ret);
3232 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3233 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3234 rc2.right, rc2.bottom);
3236 /* now test ValidateRgn */
3237 InvalidateRect( child, NULL, 1);
3238 GetWindowRect( child, &rc);
3239 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3240 rgn = CreateRectRgnIndirect( &rc);
3241 ValidateRgn( hwnd, rgn);
3242 ret = GetUpdateRect( child, &rc2, 0);
3243 ok( !ret, "Expected GetUpdateRect to return zero, got %d\n", ret);
3244 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3245 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3246 rc2.right, rc2.bottom);
3249 DestroyWindow( child );
3252 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
3255 MoveWindow( hwnd, 0, 0, x, y, 0);
3256 GetWindowRect( hwnd, prc);
3258 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
3259 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
3260 rc.left,rc.top,rc.right,rc.bottom, prc->left,prc->top,prc->right,prc->bottom);
3263 static void test_nccalcscroll(HWND parent)
3266 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
3267 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
3268 HWND hwnd = CreateWindowExA(0, "static", NULL,
3269 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
3270 10, 10, 200, 200, parent, 0, 0, NULL);
3271 ShowWindow( parent, SW_SHOW);
3272 UpdateWindow( parent);
3274 /* test window too low for a horizontal scroll bar */
3275 nccalchelper( hwnd, 100, sbheight, &rc1);
3276 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
3277 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
3279 /* test window just high enough for a horizontal scroll bar */
3280 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
3281 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
3282 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3284 /* test window too narrow for a vertical scroll bar */
3285 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
3286 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
3287 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3289 /* test window just wide enough for a vertical scroll bar */
3290 nccalchelper( hwnd, sbwidth, 100, &rc1);
3291 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
3292 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
3294 /* same test, but with client edge: not enough width */
3295 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
3296 nccalchelper( hwnd, sbwidth, 100, &rc1);
3297 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
3298 "Width should be %d size is %d,%d - %d,%d\n",
3299 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
3301 DestroyWindow( hwnd);
3304 static void test_SetParent(void)
3307 HWND desktop = GetDesktopWindow();
3309 HWND parent, child1, child2, child3, child4, sibling;
3311 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3312 100, 100, 200, 200, 0, 0, 0, NULL);
3313 assert(parent != 0);
3314 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3315 0, 0, 50, 50, parent, 0, 0, NULL);
3316 assert(child1 != 0);
3317 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3318 0, 0, 50, 50, child1, 0, 0, NULL);
3319 assert(child2 != 0);
3320 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3321 0, 0, 50, 50, child2, 0, 0, NULL);
3322 assert(child3 != 0);
3323 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3324 0, 0, 50, 50, child3, 0, 0, NULL);
3325 assert(child4 != 0);
3327 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
3328 parent, child1, child2, child3, child4);
3330 check_parents(parent, desktop, 0, 0, 0, parent, parent);
3331 check_parents(child1, parent, parent, parent, 0, parent, parent);
3332 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3333 check_parents(child3, child2, child2, child2, 0, child2, parent);
3334 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3336 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
3337 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
3338 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3339 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
3340 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3342 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
3343 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3344 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
3345 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
3346 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
3347 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
3348 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
3349 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3350 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3352 if (!is_win9x) /* Win9x doesn't survive this test */
3356 ok(!SetParent(parent, child1), "SetParent should fail\n");
3357 ok(!SetParent(child2, child3), "SetParent should fail\n");
3358 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
3359 ret = SetParent(parent, child2);
3360 todo_wine ok( !ret || broken( ret != 0 ), "SetParent should fail\n");
3361 if (ret) /* nt4, win2k */
3363 ret = SetParent(parent, child3);
3364 ok(ret != 0, "SetParent should not fail\n");
3365 ret = SetParent(child2, parent);
3366 ok(!ret, "SetParent should fail\n");
3367 ret = SetParent(parent, child4);
3368 ok(ret != 0, "SetParent should not fail\n");
3369 check_parents(parent, child4, child4, 0, 0, child4, parent);
3370 check_parents(child1, parent, parent, parent, 0, child4, parent);
3371 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3372 check_parents(child3, child2, child2, child2, 0, child2, parent);
3373 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3377 ret = SetParent(parent, child3);
3378 ok(ret != 0, "SetParent should not fail\n");
3379 ret = SetParent(child2, parent);
3380 ok(!ret, "SetParent should fail\n");
3381 ret = SetParent(parent, child4);
3382 ok(!ret, "SetParent should fail\n");
3383 check_parents(parent, child3, child3, 0, 0, child2, parent);
3384 check_parents(child1, parent, parent, parent, 0, child2, parent);
3385 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3386 check_parents(child3, child2, child2, child2, 0, child2, parent);
3387 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3391 skip("Win9x/WinMe crash\n");
3393 hMenu = CreateMenu();
3394 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3395 100, 100, 200, 200, 0, hMenu, 0, NULL);
3396 assert(sibling != 0);
3398 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
3399 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
3401 ret = DestroyWindow(parent);
3402 ok( ret, "DestroyWindow() error %d\n", GetLastError());
3404 ok(!IsWindow(parent), "parent still exists\n");
3405 ok(!IsWindow(sibling), "sibling still exists\n");
3406 ok(!IsWindow(child1), "child1 still exists\n");
3407 ok(!IsWindow(child2), "child2 still exists\n");
3408 ok(!IsWindow(child3), "child3 still exists\n");
3409 ok(!IsWindow(child4), "child4 still exists\n");
3412 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3414 LPCREATESTRUCT lpcs;
3421 lpcs = (LPCREATESTRUCT)lparam;
3422 lpss = lpcs->lpCreateParams;
3425 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
3426 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
3427 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
3428 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
3430 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3432 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
3433 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
3434 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
3436 ok(lpss->styleNew == lpcs->style,
3437 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3438 lpss->styleNew, lpcs->style);
3442 return DefWindowProc(hwnd, msg, wparam, lparam);
3445 static ATOM atomStyleCheckClass;
3447 static void register_style_check_class(void)
3455 GetModuleHandle(NULL),
3457 LoadCursor(NULL, IDC_ARROW),
3458 (HBRUSH)(COLOR_BTNFACE+1),
3460 TEXT("WineStyleCheck"),
3463 atomStyleCheckClass = RegisterClass(&wc);
3466 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3468 DWORD dwActualStyle;
3469 DWORD dwActualExStyle;
3472 HWND hwndParent = NULL;
3474 ss.styleNew = dwStyleIn;
3475 ss.styleOld = dwExStyleIn;
3477 if (dwStyleIn & WS_CHILD)
3479 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
3480 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3483 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
3484 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3487 flush_events( TRUE );
3489 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3490 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3491 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3492 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3493 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3495 /* try setting the styles explicitly */
3496 SetWindowLong( hwnd, GWL_EXSTYLE, dwExStyleIn );
3497 SetWindowLong( hwnd, GWL_STYLE, dwStyleIn );
3498 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3499 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3500 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3501 if (dwStyleIn & WS_CHILD) dwStyleOut = dwStyleIn;
3502 else dwStyleOut = dwStyleIn | WS_CLIPSIBLINGS;
3503 /* WS_EX_WINDOWEDGE can't always be changed */
3504 if ((dwExStyleIn & WS_EX_DLGMODALFRAME) || (dwStyleIn & WS_THICKFRAME))
3505 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3506 else if (dwStyleIn & (WS_CHILD | WS_POPUP))
3507 dwExStyleOut = dwExStyleIn & ~WS_EX_WINDOWEDGE;
3509 dwExStyleOut = dwExStyleIn;
3510 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3511 "%08x/%08x: Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3512 dwStyleIn, dwExStyleIn, dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3514 DestroyWindow(hwnd);
3515 if (hwndParent) DestroyWindow(hwndParent);
3518 /* tests what window styles the window manager automatically adds */
3519 static void test_window_styles(void)
3521 register_style_check_class();
3523 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3524 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3525 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3526 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3527 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3528 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3529 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3530 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3531 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3532 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3533 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3535 if (pGetLayeredWindowAttributes)
3537 check_window_style(0, WS_EX_LAYERED, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_WINDOWEDGE);
3538 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_WINDOWEDGE);
3539 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION,
3540 WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW|WS_EX_WINDOWEDGE);
3544 static void test_scrollwindow( HWND hwnd)
3550 ShowWindow( hwnd, SW_SHOW);
3551 UpdateWindow( hwnd);
3552 flush_events( TRUE );
3553 GetClientRect( hwnd, &rc);
3555 /* test ScrollWindow(Ex) with no clip rectangle */
3556 /* paint the lower half of the window black */
3558 rc2.top = ( rc2.top + rc2.bottom) / 2;
3559 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3560 /* paint the upper half of the window white */
3561 rc2.bottom = rc2.top;
3563 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
3564 /* scroll lower half up */
3566 rc2.top = ( rc2.top + rc2.bottom) / 2;
3567 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, NULL, NULL, NULL, SW_ERASE);
3568 flush_events(FALSE);
3569 /* expected: black should have scrolled to the upper half */
3570 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
3571 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3572 /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
3573 /* paint the lower half of the window black */
3575 rc2.top = ( rc2.top + rc2.bottom) / 2;
3576 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3577 /* paint the upper half of the window white */
3578 rc2.bottom = rc2.top;
3580 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
3581 /* scroll lower half up */
3583 rc2.top = ( rc2.top + rc2.bottom) / 2;
3585 rc3.left = rc3.right / 4;
3586 rc3.right -= rc3.right / 4;
3587 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, &rc3, NULL, NULL, SW_ERASE);
3588 flush_events(FALSE);
3589 /* expected: black should have scrolled to the upper half */
3590 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
3591 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3594 ReleaseDC( hwnd, hdc);
3597 static void test_scrollvalidate( HWND parent)
3600 HRGN hrgn=CreateRectRgn(0,0,0,0);
3601 HRGN exprgn, tmprgn, clipping;
3602 RECT rc, rcu, cliprc;
3603 /* create two overlapping child windows. The visual region
3604 * of hwnd1 is clipped by the overlapping part of
3605 * hwnd2 because of the WS_CLIPSIBLING style */
3608 clipping = CreateRectRgn(0,0,0,0);
3609 tmprgn = CreateRectRgn(0,0,0,0);
3610 exprgn = CreateRectRgn(0,0,0,0);
3611 hwnd2 = CreateWindowExA(0, "static", NULL,
3612 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3613 75, 30, 100, 100, parent, 0, 0, NULL);
3614 hwnd1 = CreateWindowExA(0, "static", NULL,
3615 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3616 25, 50, 100, 100, parent, 0, 0, NULL);
3617 ShowWindow( parent, SW_SHOW);
3618 UpdateWindow( parent);
3619 GetClientRect( hwnd1, &rc);
3621 SetRectRgn( clipping, 10, 10, 90, 90);
3622 hdc = GetDC( hwnd1);
3623 /* for a visual touch */
3624 TextOut( hdc, 0,10, "0123456789", 10);
3625 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3626 if (winetest_debug > 0) dump_region(hrgn);
3627 /* create a region with what is expected */
3628 SetRectRgn( exprgn, 39,0,49,74);
3629 SetRectRgn( tmprgn, 88,79,98,93);
3630 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3631 SetRectRgn( tmprgn, 0,93,98,98);
3632 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3633 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3634 trace("update rect is %d,%d - %d,%d\n",
3635 rcu.left,rcu.top,rcu.right,rcu.bottom);
3636 /* now with clipping region */
3637 SelectClipRgn( hdc, clipping);
3638 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3639 if (winetest_debug > 0) dump_region(hrgn);
3640 /* create a region with what is expected */
3641 SetRectRgn( exprgn, 39,10,49,74);
3642 SetRectRgn( tmprgn, 80,79,90,85);
3643 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3644 SetRectRgn( tmprgn, 10,85,90,90);
3645 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3646 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3647 trace("update rect is %d,%d - %d,%d\n",
3648 rcu.left,rcu.top,rcu.right,rcu.bottom);
3649 ReleaseDC( hwnd1, hdc);
3651 /* test scrolling a window with an update region */
3652 DestroyWindow( hwnd2);
3653 ValidateRect( hwnd1, NULL);
3654 SetRect( &rc, 40,40, 50,50);
3655 InvalidateRect( hwnd1, &rc, 1);
3656 GetClientRect( hwnd1, &rc);
3658 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
3659 SW_SCROLLCHILDREN | SW_INVALIDATE);
3660 if (winetest_debug > 0) dump_region(hrgn);
3661 SetRectRgn( exprgn, 88,0,98,98);
3662 SetRectRgn( tmprgn, 30, 40, 50, 50);
3663 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3664 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3666 /* clear an update region */
3667 UpdateWindow( hwnd1 );
3669 SetRect( &rc, 0,40, 100,60);
3670 SetRect( &cliprc, 0,0, 100,100);
3671 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3672 if (winetest_debug > 0) dump_region( hrgn );
3673 SetRectRgn( exprgn, 0, 40, 98, 60 );
3674 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
3676 /* now test ScrollWindowEx with a combination of
3677 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3678 /* make hwnd2 the child of hwnd1 */
3679 hwnd2 = CreateWindowExA(0, "static", NULL,
3680 WS_CHILD| WS_VISIBLE | WS_BORDER ,
3681 50, 50, 100, 100, hwnd1, 0, 0, NULL);
3682 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
3683 GetClientRect( hwnd1, &rc);
3686 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3687 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3688 ValidateRect( hwnd1, NULL);
3689 ValidateRect( hwnd2, NULL);
3690 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
3691 SW_SCROLLCHILDREN | SW_INVALIDATE);
3692 if (winetest_debug > 0) dump_region(hrgn);
3693 SetRectRgn( exprgn, 88,0,98,88);
3694 SetRectRgn( tmprgn, 0,88,98,98);
3695 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3696 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3698 /* SW_SCROLLCHILDREN */
3699 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3700 ValidateRect( hwnd1, NULL);
3701 ValidateRect( hwnd2, NULL);
3702 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3703 if (winetest_debug > 0) dump_region(hrgn);
3704 /* expected region is the same as in previous test */
3705 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3707 /* no SW_SCROLLCHILDREN */
3708 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3709 ValidateRect( hwnd1, NULL);
3710 ValidateRect( hwnd2, NULL);
3711 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3712 if (winetest_debug > 0) dump_region(hrgn);
3713 /* expected region is the same as in previous test */
3714 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3716 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3717 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3718 ValidateRect( hwnd1, NULL);
3719 ValidateRect( hwnd2, NULL);
3720 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3721 if (winetest_debug > 0) dump_region(hrgn);
3722 SetRectRgn( exprgn, 88,0,98,20);
3723 SetRectRgn( tmprgn, 20,20,98,30);
3724 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3725 SetRectRgn( tmprgn, 20,30,30,88);
3726 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3727 SetRectRgn( tmprgn, 0,88,30,98);
3728 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3729 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3732 DeleteObject( hrgn);
3733 DeleteObject( exprgn);
3734 DeleteObject( tmprgn);
3735 DestroyWindow( hwnd1);
3736 DestroyWindow( hwnd2);
3739 /* couple of tests of return values of scrollbar functions
3740 * called on a scrollbarless window */
3741 static void test_scroll(void)
3746 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3747 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3748 100, 100, 200, 200, 0, 0, 0, NULL);
3750 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3751 if (!ret) /* win9x */
3753 win_skip( "GetScrollRange doesn't work\n" );
3754 DestroyWindow( hwnd);
3757 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3758 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3759 si.cbSize = sizeof( si);
3760 si.fMask = SIF_PAGE;
3761 si.nPage = 0xdeadbeef;
3762 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3763 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3764 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3766 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3767 ok( ret, "GetScrollRange returns FALSE\n");
3768 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3769 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3770 si.cbSize = sizeof( si);
3771 si.fMask = SIF_PAGE;
3772 si.nPage = 0xdeadbeef;
3773 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3774 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3775 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3777 DestroyWindow( hwnd);
3780 static void test_scrolldc( HWND parent)
3783 HRGN exprgn, tmprgn, hrgn;
3784 RECT rc, rc2, rcu, cliprc;
3788 hrgn = CreateRectRgn(0,0,0,0);
3789 tmprgn = CreateRectRgn(0,0,0,0);
3790 exprgn = CreateRectRgn(0,0,0,0);
3792 hwnd1 = CreateWindowExA(0, "static", NULL,
3793 WS_CHILD| WS_VISIBLE,
3794 25, 50, 100, 100, parent, 0, 0, NULL);
3795 ShowWindow( parent, SW_SHOW);
3796 UpdateWindow( parent);
3797 flush_events( TRUE );
3798 GetClientRect( hwnd1, &rc);
3799 hdc = GetDC( hwnd1);
3800 /* paint the upper half of the window black */
3802 rc2.bottom = ( rc.top + rc.bottom) /2;
3803 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3804 /* clip region is the lower half */
3806 cliprc.top = (rc.top + rc.bottom) /2;
3807 /* test whether scrolled pixels are properly clipped */
3808 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3809 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3810 /* this scroll should not cause any visible changes */
3811 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3812 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3813 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3814 /* test with NULL clip rect */
3815 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3816 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3817 trace("update rect: %d,%d - %d,%d\n",
3818 rcu.left, rcu.top, rcu.right, rcu.bottom);
3819 if (winetest_debug > 0) dump_region(hrgn);
3820 SetRect(&rc2, 0, 0, 100, 100);
3821 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3822 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3824 SetRectRgn( exprgn, 0, 0, 20, 80);
3825 SetRectRgn( tmprgn, 0, 80, 100, 100);
3826 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3827 if (winetest_debug > 0) dump_region(exprgn);
3828 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3829 /* test clip rect > scroll rect */
3830 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3832 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3833 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3834 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3835 SetRectRgn( exprgn, 25, 25, 75, 35);
3836 SetRectRgn( tmprgn, 25, 35, 35, 75);
3837 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3838 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3839 trace("update rect: %d,%d - %d,%d\n",
3840 rcu.left, rcu.top, rcu.right, rcu.bottom);
3841 if (winetest_debug > 0) dump_region(hrgn);
3845 DeleteObject(exprgn);
3846 DeleteObject(tmprgn);
3847 DestroyWindow(hwnd1);
3850 static void test_params(void)
3855 /* Just a param check */
3856 if (pGetMonitorInfoA)
3858 SetLastError(0xdeadbeef);
3859 rc = GetWindowText(hwndMain2, NULL, 1024);
3860 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
3864 /* Skips actually on Win95 and NT4 */
3865 win_skip("Test would crash on Win95\n");
3868 SetLastError(0xdeadbeef);
3869 hwnd=CreateWindow("LISTBOX", "TestList",
3870 (LBS_STANDARD & ~LBS_SORT),
3872 NULL, (HMENU)1, NULL, 0);
3874 ok(!hwnd || broken(hwnd != NULL), /* w2k3 sp2 */
3875 "CreateWindow with invalid menu handle should fail\n");
3877 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3878 GetLastError() == 0xdeadbeef, /* Win9x */
3879 "wrong last error value %d\n", GetLastError());
3882 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3886 hwnd = CreateWindowEx(exStyle, class, class, style,
3893 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
3896 ShowWindow(hwnd, SW_SHOW);
3898 test_nonclient_area(hwnd);
3901 DestroyWindow(hwnd);
3904 static BOOL AWR_init(void)
3908 class.style = CS_HREDRAW | CS_VREDRAW;
3909 class.lpfnWndProc = DefWindowProcA;
3910 class.cbClsExtra = 0;
3911 class.cbWndExtra = 0;
3912 class.hInstance = 0;
3913 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3914 class.hCursor = LoadCursor (0, IDC_ARROW);
3915 class.hbrBackground = 0;
3916 class.lpszMenuName = 0;
3917 class.lpszClassName = szAWRClass;
3919 if (!RegisterClass (&class)) {
3920 ok(FALSE, "RegisterClass failed\n");
3924 hmenu = CreateMenu();
3927 ok(hmenu != 0, "Failed to create menu\n");
3928 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3934 static void test_AWR_window_size(BOOL menu)
3938 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3941 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3942 WS_HSCROLL, WS_VSCROLL
3946 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3949 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3950 WS_EX_DLGMODALFRAME,
3957 /* A exhaustive check of all the styles takes too long
3958 * so just do a (hopefully representative) sample
3960 for (i = 0; i < COUNTOF(styles); ++i)
3961 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3962 for (i = 0; i < COUNTOF(exStyles); ++i) {
3963 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3964 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3969 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3971 static void test_AdjustWindowRect(void)
3976 SHOWSYSMETRIC(SM_CYCAPTION);
3977 SHOWSYSMETRIC(SM_CYSMCAPTION);
3978 SHOWSYSMETRIC(SM_CYMENU);
3979 SHOWSYSMETRIC(SM_CXEDGE);
3980 SHOWSYSMETRIC(SM_CYEDGE);
3981 SHOWSYSMETRIC(SM_CXVSCROLL);
3982 SHOWSYSMETRIC(SM_CYHSCROLL);
3983 SHOWSYSMETRIC(SM_CXFRAME);
3984 SHOWSYSMETRIC(SM_CYFRAME);
3985 SHOWSYSMETRIC(SM_CXDLGFRAME);
3986 SHOWSYSMETRIC(SM_CYDLGFRAME);
3987 SHOWSYSMETRIC(SM_CXBORDER);
3988 SHOWSYSMETRIC(SM_CYBORDER);
3990 test_AWR_window_size(FALSE);
3991 test_AWR_window_size(TRUE);
3995 #undef SHOWSYSMETRIC
3998 /* Global variables to trigger exit from loop */
3999 static int redrawComplete, WMPAINT_count;
4001 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4006 trace("doing WM_PAINT %d\n", WMPAINT_count);
4008 if (WMPAINT_count > 10 && redrawComplete == 0) {
4010 BeginPaint(hwnd, &ps);
4011 EndPaint(hwnd, &ps);
4016 return DefWindowProc(hwnd, msg, wparam, lparam);
4019 /* Ensure we exit from RedrawNow regardless of invalidated area */
4020 static void test_redrawnow(void)
4025 cls.style = CS_DBLCLKS;
4026 cls.lpfnWndProc = redraw_window_procA;
4029 cls.hInstance = GetModuleHandleA(0);
4031 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4032 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4033 cls.lpszMenuName = NULL;
4034 cls.lpszClassName = "RedrawWindowClass";
4036 if(!RegisterClassA(&cls)) {
4037 trace("Register failed %d\n", GetLastError());
4041 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
4042 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
4044 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4045 ShowWindow(hwndMain, SW_SHOW);
4046 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4047 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
4048 ok( WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
4049 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4050 redrawComplete = TRUE;
4051 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
4054 DestroyWindow( hwndMain);
4057 struct parentdc_stat {
4063 struct parentdc_test {
4064 struct parentdc_stat main, main_todo;
4065 struct parentdc_stat child1, child1_todo;
4066 struct parentdc_stat child2, child2_todo;
4069 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4074 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
4079 GetClientRect(hwnd, &rc);
4080 CopyRect(&t->client, &rc);
4081 GetWindowRect(hwnd, &rc);
4082 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd,
4083 t->client.left, t->client.top, t->client.right, t->client.bottom,
4084 rc.left, rc.top, rc.right, rc.bottom);
4085 BeginPaint(hwnd, &ps);
4086 CopyRect(&t->paint, &ps.rcPaint);
4087 GetClipBox(ps.hdc, &rc);
4088 CopyRect(&t->clip, &rc);
4089 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
4090 rc.left, rc.top, rc.right, rc.bottom,
4091 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
4092 EndPaint(hwnd, &ps);
4095 return DefWindowProc(hwnd, msg, wparam, lparam);
4098 static void zero_parentdc_stat(struct parentdc_stat *t)
4100 SetRectEmpty(&t->client);
4101 SetRectEmpty(&t->clip);
4102 SetRectEmpty(&t->paint);
4105 static void zero_parentdc_test(struct parentdc_test *t)
4107 zero_parentdc_stat(&t->main);
4108 zero_parentdc_stat(&t->child1);
4109 zero_parentdc_stat(&t->child2);
4112 #define parentdc_field_ok(t, w, r, f, got) \
4113 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
4114 ": expected %d, got %d\n", \
4117 #define parentdc_todo_field_ok(t, w, r, f, got) \
4118 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
4119 else parentdc_field_ok(t, w, r, f, got)
4121 #define parentdc_rect_ok(t, w, r, got) \
4122 parentdc_todo_field_ok(t, w, r, left, got); \
4123 parentdc_todo_field_ok(t, w, r, top, got); \
4124 parentdc_todo_field_ok(t, w, r, right, got); \
4125 parentdc_todo_field_ok(t, w, r, bottom, got);
4127 #define parentdc_win_ok(t, w, got) \
4128 parentdc_rect_ok(t, w, client, got); \
4129 parentdc_rect_ok(t, w, clip, got); \
4130 parentdc_rect_ok(t, w, paint, got);
4132 #define parentdc_ok(t, got) \
4133 parentdc_win_ok(t, main, got); \
4134 parentdc_win_ok(t, child1, got); \
4135 parentdc_win_ok(t, child2, got);
4137 static void test_csparentdc(void)
4139 WNDCLASSA clsMain, cls;
4140 HWND hwndMain, hwnd1, hwnd2;
4143 struct parentdc_test test_answer;
4145 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
4146 const struct parentdc_test test1 =
4148 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
4149 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4150 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4153 const struct parentdc_test test2 =
4155 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
4156 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4157 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4160 const struct parentdc_test test3 =
4162 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4163 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4164 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4167 const struct parentdc_test test4 =
4169 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
4170 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
4171 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4174 const struct parentdc_test test5 =
4176 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
4177 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4178 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4181 const struct parentdc_test test6 =
4183 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4184 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4185 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4188 const struct parentdc_test test7 =
4190 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4191 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4192 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4196 clsMain.style = CS_DBLCLKS;
4197 clsMain.lpfnWndProc = parentdc_window_procA;
4198 clsMain.cbClsExtra = 0;
4199 clsMain.cbWndExtra = 0;
4200 clsMain.hInstance = GetModuleHandleA(0);
4202 clsMain.hCursor = LoadCursorA(0, IDC_ARROW);
4203 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
4204 clsMain.lpszMenuName = NULL;
4205 clsMain.lpszClassName = "ParentDcMainWindowClass";
4207 if(!RegisterClassA(&clsMain)) {
4208 trace("Register failed %d\n", GetLastError());
4212 cls.style = CS_DBLCLKS | CS_PARENTDC;
4213 cls.lpfnWndProc = parentdc_window_procA;
4216 cls.hInstance = GetModuleHandleA(0);
4218 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4219 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4220 cls.lpszMenuName = NULL;
4221 cls.lpszClassName = "ParentDcWindowClass";
4223 if(!RegisterClassA(&cls)) {
4224 trace("Register failed %d\n", GetLastError());
4228 SetRect(&rc, 0, 0, 150, 150);
4229 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
4230 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
4231 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
4232 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
4233 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
4234 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
4235 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
4236 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
4237 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
4238 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
4239 ShowWindow(hwndMain, SW_SHOW);
4240 ShowWindow(hwnd1, SW_SHOW);
4241 ShowWindow(hwnd2, SW_SHOW);
4242 SetWindowPos(hwndMain, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
4243 flush_events( TRUE );
4245 zero_parentdc_test(&test_answer);
4246 InvalidateRect(hwndMain, NULL, TRUE);
4247 flush_events( TRUE );
4248 parentdc_ok(test1, test_answer);
4250 zero_parentdc_test(&test_answer);
4251 SetRect(&rc, 0, 0, 50, 50);
4252 InvalidateRect(hwndMain, &rc, TRUE);
4253 flush_events( TRUE );
4254 parentdc_ok(test2, test_answer);
4256 zero_parentdc_test(&test_answer);
4257 SetRect(&rc, 0, 0, 10, 10);
4258 InvalidateRect(hwndMain, &rc, TRUE);
4259 flush_events( TRUE );
4260 parentdc_ok(test3, test_answer);
4262 zero_parentdc_test(&test_answer);
4263 SetRect(&rc, 40, 40, 50, 50);
4264 InvalidateRect(hwndMain, &rc, TRUE);
4265 flush_events( TRUE );
4266 parentdc_ok(test4, test_answer);
4268 zero_parentdc_test(&test_answer);
4269 SetRect(&rc, 20, 20, 60, 60);
4270 InvalidateRect(hwndMain, &rc, TRUE);
4271 flush_events( TRUE );
4272 parentdc_ok(test5, test_answer);
4274 zero_parentdc_test(&test_answer);
4275 SetRect(&rc, 0, 0, 10, 10);
4276 InvalidateRect(hwnd1, &rc, TRUE);
4277 flush_events( TRUE );
4278 parentdc_ok(test6, test_answer);
4280 zero_parentdc_test(&test_answer);
4281 SetRect(&rc, -5, -5, 65, 65);
4282 InvalidateRect(hwnd1, &rc, TRUE);
4283 flush_events( TRUE );
4284 parentdc_ok(test7, test_answer);
4286 DestroyWindow(hwndMain);
4287 DestroyWindow(hwnd1);
4288 DestroyWindow(hwnd2);
4291 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4293 return DefWindowProcA(hwnd, msg, wparam, lparam);
4296 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4298 return DefWindowProcW(hwnd, msg, wparam, lparam);
4301 static void test_IsWindowUnicode(void)
4303 static const char ansi_class_nameA[] = "ansi class name";
4304 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
4305 static const char unicode_class_nameA[] = "unicode class name";
4306 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
4311 memset(&classW, 0, sizeof(classW));
4312 classW.hInstance = GetModuleHandleA(0);
4313 classW.lpfnWndProc = def_window_procW;
4314 classW.lpszClassName = unicode_class_nameW;
4315 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
4317 memset(&classA, 0, sizeof(classA));
4318 classA.hInstance = GetModuleHandleA(0);
4319 classA.lpfnWndProc = def_window_procA;
4320 classA.lpszClassName = ansi_class_nameA;
4321 assert(RegisterClassA(&classA));
4323 /* unicode class: window proc */
4324 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4325 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4328 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4329 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4330 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4331 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4332 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4334 DestroyWindow(hwnd);
4336 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4337 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4340 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4341 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4342 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4343 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4344 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4346 DestroyWindow(hwnd);
4348 /* ansi class: window proc */
4349 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4350 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4353 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4354 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4355 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4356 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4357 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4359 DestroyWindow(hwnd);
4361 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4362 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4365 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4366 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4367 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4368 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4369 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4371 DestroyWindow(hwnd);
4373 /* unicode class: class proc */
4374 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4375 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4378 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4379 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4380 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4381 /* do not restore class window proc back to unicode */
4383 DestroyWindow(hwnd);
4385 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4386 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4389 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4390 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4391 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4393 DestroyWindow(hwnd);
4395 /* ansi class: class proc */
4396 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4397 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4400 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4401 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4402 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4403 /* do not restore class window proc back to ansi */
4405 DestroyWindow(hwnd);
4407 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4408 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4411 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4412 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4413 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4415 DestroyWindow(hwnd);
4418 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4422 if (msg != WM_GETMINMAXINFO)
4423 return DefWindowProc(hwnd, msg, wp, lp);
4425 minmax = (MINMAXINFO *)lp;
4427 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
4429 minmax->ptReserved.x = 0;
4430 minmax->ptReserved.y = 0;
4431 minmax->ptMaxSize.x = 400;
4432 minmax->ptMaxSize.y = 400;
4433 minmax->ptMaxPosition.x = 300;
4434 minmax->ptMaxPosition.y = 300;
4435 minmax->ptMaxTrackSize.x = 200;
4436 minmax->ptMaxTrackSize.y = 200;
4437 minmax->ptMinTrackSize.x = 100;
4438 minmax->ptMinTrackSize.y = 100;
4441 DefWindowProc(hwnd, msg, wp, lp);
4445 static int expected_cx, expected_cy;
4446 static RECT expected_rect, broken_rect;
4448 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4452 case WM_GETMINMAXINFO:
4455 GetWindowRect( hwnd, &rect );
4456 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
4457 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4458 return DefWindowProc(hwnd, msg, wp, lp);
4463 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
4465 GetWindowRect( hwnd, &rect );
4466 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
4467 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
4468 ok( cs->cx == expected_cx || broken(cs->cx == (short)expected_cx),
4469 "wrong x size %d/%d\n", cs->cx, expected_cx );
4470 ok( cs->cy == expected_cy || broken(cs->cy == (short)expected_cy),
4471 "wrong y size %d/%d\n", cs->cy, expected_cy );
4472 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
4473 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
4474 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
4475 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top) ||
4476 broken( rect.right - rect.left == (short)broken_rect.right - (short)broken_rect.left &&
4477 rect.bottom - rect.top == (short)broken_rect.bottom - (short)broken_rect.top),
4478 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
4479 rect.left, rect.top, rect.right, rect.bottom,
4480 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
4481 return DefWindowProc(hwnd, msg, wp, lp);
4485 RECT rect, *r = (RECT *)lp;
4486 GetWindowRect( hwnd, &rect );
4487 ok( !memcmp( &rect, r, sizeof(rect) ),
4488 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
4489 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
4490 return DefWindowProc(hwnd, msg, wp, lp);
4493 return DefWindowProc(hwnd, msg, wp, lp);
4497 static void test_CreateWindow(void)
4505 #define expect_menu(window, menu) \
4506 SetLastError(0xdeadbeef); \
4507 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
4509 #define expect_style(window, style)\
4510 ok((ULONG)GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
4512 #define expect_ex_style(window, ex_style)\
4513 ok((ULONG)GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
4515 #define expect_gle_broken_9x(gle)\
4516 ok(GetLastError() == gle ||\
4517 broken(GetLastError() == 0xdeadbeef),\
4518 "IsMenu set error %d\n", GetLastError())
4520 hmenu = CreateMenu();
4522 parent = GetDesktopWindow();
4523 assert(parent != 0);
4525 SetLastError(0xdeadbeef);
4526 ok(IsMenu(hmenu), "IsMenu error %d\n", GetLastError());
4529 SetLastError(0xdeadbeef);
4530 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
4531 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4532 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4533 expect_menu(hwnd, 1);
4534 expect_style(hwnd, WS_CHILD);
4535 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4536 DestroyWindow(hwnd);
4538 SetLastError(0xdeadbeef);
4539 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
4540 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4541 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4542 expect_menu(hwnd, 1);
4543 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4544 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4545 DestroyWindow(hwnd);
4547 SetLastError(0xdeadbeef);
4548 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
4549 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4550 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4551 expect_menu(hwnd, 1);
4552 expect_style(hwnd, WS_CHILD);
4553 expect_ex_style(hwnd, 0);
4554 DestroyWindow(hwnd);
4556 SetLastError(0xdeadbeef);
4557 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
4558 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4559 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4560 expect_menu(hwnd, 1);
4561 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4562 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4563 DestroyWindow(hwnd);
4566 SetLastError(0xdeadbeef);
4567 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4568 0, 0, 100, 100, parent, hmenu, 0, NULL);
4569 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4570 expect_menu(hwnd, hmenu);
4571 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4572 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4573 DestroyWindow(hwnd);
4574 SetLastError(0xdeadbeef);
4575 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4576 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4578 hmenu = CreateMenu();
4580 SetLastError(0xdeadbeef);
4581 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
4582 0, 0, 100, 100, parent, hmenu, 0, NULL);
4583 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4584 expect_menu(hwnd, hmenu);
4585 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4586 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4587 DestroyWindow(hwnd);
4588 SetLastError(0xdeadbeef);
4589 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4590 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4592 hmenu = CreateMenu();
4594 SetLastError(0xdeadbeef);
4595 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
4596 0, 0, 100, 100, parent, hmenu, 0, NULL);
4597 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4598 expect_menu(hwnd, hmenu);
4599 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4600 expect_ex_style(hwnd, 0);
4601 DestroyWindow(hwnd);
4602 SetLastError(0xdeadbeef);
4603 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4604 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4606 hmenu = CreateMenu();
4608 SetLastError(0xdeadbeef);
4609 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
4610 0, 0, 100, 100, parent, hmenu, 0, NULL);
4611 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4612 expect_menu(hwnd, hmenu);
4613 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4614 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4615 DestroyWindow(hwnd);
4616 SetLastError(0xdeadbeef);
4617 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4618 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4620 /* WS_CHILD | WS_POPUP */
4621 SetLastError(0xdeadbeef);
4622 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4623 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4624 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4625 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4627 DestroyWindow(hwnd);
4629 hmenu = CreateMenu();
4631 SetLastError(0xdeadbeef);
4632 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4633 0, 0, 100, 100, parent, hmenu, 0, NULL);
4634 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4635 expect_menu(hwnd, hmenu);
4636 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4637 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4638 DestroyWindow(hwnd);
4639 SetLastError(0xdeadbeef);
4640 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4641 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4643 SetLastError(0xdeadbeef);
4644 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4645 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4646 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4647 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4649 DestroyWindow(hwnd);
4651 hmenu = CreateMenu();
4653 SetLastError(0xdeadbeef);
4654 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4655 0, 0, 100, 100, parent, hmenu, 0, NULL);
4656 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4657 expect_menu(hwnd, hmenu);
4658 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4659 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4660 DestroyWindow(hwnd);
4661 SetLastError(0xdeadbeef);
4662 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4663 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4665 SetLastError(0xdeadbeef);
4666 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4667 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4668 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4669 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4671 DestroyWindow(hwnd);
4673 hmenu = CreateMenu();
4675 SetLastError(0xdeadbeef);
4676 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4677 0, 0, 100, 100, parent, hmenu, 0, NULL);
4678 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4679 expect_menu(hwnd, hmenu);
4680 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4681 expect_ex_style(hwnd, 0);
4682 DestroyWindow(hwnd);
4683 SetLastError(0xdeadbeef);
4684 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4685 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4687 SetLastError(0xdeadbeef);
4688 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4689 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4690 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4691 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4693 DestroyWindow(hwnd);
4695 hmenu = CreateMenu();
4697 SetLastError(0xdeadbeef);
4698 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4699 0, 0, 100, 100, parent, hmenu, 0, NULL);
4700 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4701 expect_menu(hwnd, hmenu);
4702 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4703 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4704 DestroyWindow(hwnd);
4705 SetLastError(0xdeadbeef);
4706 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4707 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4709 /* test child window sizing */
4711 cls.lpfnWndProc = minmax_wnd_proc;
4714 cls.hInstance = GetModuleHandle(0);
4716 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4717 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4718 cls.lpszMenuName = NULL;
4719 cls.lpszClassName = "MinMax_WndClass";
4720 RegisterClass(&cls);
4722 SetLastError(0xdeadbeef);
4723 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4724 0, 0, 100, 100, 0, 0, 0, NULL);
4725 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4726 expect_menu(parent, 0);
4727 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
4728 expect_ex_style(parent, WS_EX_WINDOWEDGE);
4730 memset(&minmax, 0, sizeof(minmax));
4731 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4732 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
4733 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
4734 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4735 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
4737 GetWindowRect(parent, &rc);
4738 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
4739 GetClientRect(parent, &rc);
4740 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
4742 InflateRect(&rc, 200, 200);
4743 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4745 SetLastError(0xdeadbeef);
4746 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4747 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
4748 parent, (HMENU)1, 0, NULL);
4749 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4750 expect_menu(hwnd, 1);
4751 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
4752 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4754 memset(&minmax, 0, sizeof(minmax));
4755 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4756 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4758 GetWindowRect(hwnd, &rc);
4759 OffsetRect(&rc, -rc.left, -rc.top);
4760 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4761 rc.left, rc.top, rc.right, rc.bottom,
4762 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
4763 DestroyWindow(hwnd);
4765 cls.lpfnWndProc = winsizes_wnd_proc;
4766 cls.lpszClassName = "Sizes_WndClass";
4767 RegisterClass(&cls);
4769 expected_cx = expected_cy = 200000;
4770 SetRect( &expected_rect, 0, 0, 200000, 200000 );
4771 broken_rect = expected_rect;
4772 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
4773 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4774 GetClientRect( hwnd, &rc );
4775 ok( rc.right == 200000 || broken(rc.right == (short)200000), "invalid rect right %u\n", rc.right );
4776 ok( rc.bottom == 200000 || broken(rc.bottom == (short)200000), "invalid rect bottom %u\n", rc.bottom );
4777 DestroyWindow(hwnd);
4779 expected_cx = expected_cy = -10;
4780 SetRect( &expected_rect, 0, 0, 0, 0 );
4781 SetRect( &broken_rect, 0, 0, -10, -10 );
4782 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
4783 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4784 GetClientRect( hwnd, &rc );
4785 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4786 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4787 DestroyWindow(hwnd);
4789 expected_cx = expected_cy = -200000;
4790 SetRect( &expected_rect, 0, 0, 0, 0 );
4791 SetRect( &broken_rect, 0, 0, -200000, -200000 );
4792 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
4793 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4794 GetClientRect( hwnd, &rc );
4795 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4796 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4797 DestroyWindow(hwnd);
4799 /* we need a parent at 0,0 so that child coordinates match */
4800 DestroyWindow(parent);
4801 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
4802 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4805 expected_cy = 0x7fffffff;
4806 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
4807 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
4808 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
4809 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4810 GetClientRect( hwnd, &rc );
4811 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
4812 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4813 DestroyWindow(hwnd);
4815 expected_cx = 0x7fffffff;
4816 expected_cy = 0x7fffffff;
4817 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
4818 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
4819 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
4820 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4821 GetClientRect( hwnd, &rc );
4822 ok( rc.right == 0x7fffffff - 20 || broken(rc.right == 0), "invalid rect right %u\n", rc.right );
4823 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4824 DestroyWindow(hwnd);
4826 /* top level window */
4827 expected_cx = expected_cy = 200000;
4828 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
4829 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
4830 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4831 GetClientRect( hwnd, &rc );
4832 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
4833 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
4834 DestroyWindow(hwnd);
4836 if (pGetLayout && pSetLayout)
4838 HDC hdc = GetDC( parent );
4839 pSetLayout( hdc, LAYOUT_RTL );
4840 if (pGetLayout( hdc ))
4842 ReleaseDC( parent, hdc );
4843 DestroyWindow( parent );
4844 SetLastError( 0xdeadbeef );
4845 parent = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_LAYOUTRTL, "static", NULL, WS_POPUP,
4846 0, 0, 100, 100, 0, 0, 0, NULL);
4847 ok( parent != 0, "creation failed err %u\n", GetLastError());
4848 expect_ex_style( parent, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
4849 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 20, 20, parent, 0, 0, NULL);
4850 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4851 expect_ex_style( hwnd, WS_EX_LAYOUTRTL );
4852 DestroyWindow( hwnd );
4853 SetWindowLongW( parent, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT );
4854 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 20, 20, parent, 0, 0, NULL);
4855 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4856 expect_ex_style( hwnd, 0 );
4857 DestroyWindow( hwnd );
4859 if (pGetProcessDefaultLayout && pSetProcessDefaultLayout)
4863 SetLastError( 0xdeadbeef );
4864 ok( !pGetProcessDefaultLayout( NULL ), "GetProcessDefaultLayout succeeded\n" );
4865 ok( GetLastError() == ERROR_NOACCESS, "wrong error %u\n", GetLastError() );
4866 SetLastError( 0xdeadbeef );
4867 ok( pGetProcessDefaultLayout( &layout ),
4868 "GetProcessDefaultLayout failed err %u\n", GetLastError ());
4869 ok( layout == 0, "GetProcessDefaultLayout wrong layout %x\n", layout );
4870 SetLastError( 0xdeadbeef );
4871 ok( pSetProcessDefaultLayout( 7 ),
4872 "SetProcessDefaultLayout failed err %u\n", GetLastError ());
4873 ok( pGetProcessDefaultLayout( &layout ),
4874 "GetProcessDefaultLayout failed err %u\n", GetLastError ());
4875 ok( layout == 7, "GetProcessDefaultLayout wrong layout %x\n", layout );
4876 SetLastError( 0xdeadbeef );
4877 ok( pSetProcessDefaultLayout( LAYOUT_RTL ),
4878 "SetProcessDefaultLayout failed err %u\n", GetLastError ());
4879 ok( pGetProcessDefaultLayout( &layout ),
4880 "GetProcessDefaultLayout failed err %u\n", GetLastError ());
4881 ok( layout == LAYOUT_RTL, "GetProcessDefaultLayout wrong layout %x\n", layout );
4882 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4883 0, 0, 100, 100, 0, 0, 0, NULL);
4884 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4885 expect_ex_style( hwnd, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
4886 DestroyWindow( hwnd );
4887 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4888 0, 0, 100, 100, parent, 0, 0, NULL);
4889 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4890 expect_ex_style( hwnd, WS_EX_APPWINDOW );
4891 DestroyWindow( hwnd );
4892 pSetProcessDefaultLayout( 0 );
4894 else win_skip( "SetProcessDefaultLayout not supported\n" );
4896 else win_skip( "SetLayout not supported\n" );
4898 else win_skip( "SetLayout not available\n" );
4900 DestroyWindow(parent);
4902 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4903 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4905 #undef expect_gle_broken_9x
4908 #undef expect_ex_style
4911 /* function that remembers whether the system the test is running on sets the
4912 * last error for user32 functions to make the tests stricter */
4913 static int check_error(DWORD actual, DWORD expected)
4915 static int sets_last_error = -1;
4916 if (sets_last_error == -1)
4917 sets_last_error = (actual != 0xdeadbeef);
4918 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
4921 static void test_SetWindowLong(void)
4924 WNDPROC old_window_procW;
4926 SetLastError(0xdeadbeef);
4927 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
4928 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
4929 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
4930 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4932 SetLastError(0xdeadbeef);
4933 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
4934 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
4935 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
4936 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4938 SetLastError(0xdeadbeef);
4939 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4940 ok((WNDPROC)retval == main_window_procA || broken(!retval), /* win9x */
4941 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
4942 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4943 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
4944 ok((WNDPROC)retval == main_window_procA,
4945 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4946 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
4948 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
4949 SetLastError(0xdeadbeef);
4950 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
4951 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
4953 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4954 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
4955 ok((WNDPROC)retval == old_window_procW,
4956 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4957 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
4959 /* set it back to ANSI */
4960 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4964 static void test_ShowWindow(void)
4968 RECT rcMain, rc, rcMinimized;
4971 SetRect(&rcMain, 120, 120, 210, 210);
4973 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
4974 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4975 WS_MAXIMIZEBOX | WS_POPUP,
4976 rcMain.left, rcMain.top,
4977 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
4981 style = GetWindowLong(hwnd, GWL_STYLE);
4982 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4983 ok(!(style & WS_VISIBLE), "window should not be visible\n");
4984 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4985 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4986 GetWindowRect(hwnd, &rc);
4987 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4988 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4989 rc.left, rc.top, rc.right, rc.bottom);
4991 ret = ShowWindow(hwnd, SW_SHOW);
4992 ok(!ret, "not expected ret: %lu\n", ret);
4993 style = GetWindowLong(hwnd, GWL_STYLE);
4994 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4995 ok(style & WS_VISIBLE, "window should be visible\n");
4996 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4997 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4998 GetWindowRect(hwnd, &rc);
4999 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5000 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5001 rc.left, rc.top, rc.right, rc.bottom);
5003 ret = ShowWindow(hwnd, SW_MINIMIZE);
5004 ok(ret, "not expected ret: %lu\n", ret);
5005 style = GetWindowLong(hwnd, GWL_STYLE);
5006 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5007 ok(style & WS_VISIBLE, "window should be visible\n");
5008 ok(style & WS_MINIMIZE, "window should be minimized\n");
5009 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5010 GetWindowRect(hwnd, &rcMinimized);
5011 ok(!EqualRect(&rcMain, &rcMinimized), "rects shouldn't match\n");
5012 /* shouldn't be able to resize minized windows */
5013 ret = SetWindowPos(hwnd, 0, 0, 0,
5014 (rcMinimized.right - rcMinimized.left) * 2,
5015 (rcMinimized.bottom - rcMinimized.top) * 2,
5016 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
5017 ok(ret, "not expected ret: %lu\n", ret);
5018 GetWindowRect(hwnd, &rc);
5019 ok(EqualRect(&rc, &rcMinimized), "rects should match\n");
5021 ShowWindow(hwnd, SW_RESTORE);
5022 ok(ret, "not expected ret: %lu\n", ret);
5023 style = GetWindowLong(hwnd, GWL_STYLE);
5024 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5025 ok(style & WS_VISIBLE, "window should be visible\n");
5026 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5027 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5028 GetWindowRect(hwnd, &rc);
5029 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5030 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5031 rc.left, rc.top, rc.right, rc.bottom);
5033 ret = EnableWindow(hwnd, FALSE);
5034 ok(!ret, "not expected ret: %lu\n", ret);
5035 style = GetWindowLong(hwnd, GWL_STYLE);
5036 ok(style & WS_DISABLED, "window should be disabled\n");
5038 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
5039 ok(!ret, "not expected ret: %lu\n", ret);
5040 style = GetWindowLong(hwnd, GWL_STYLE);
5041 ok(style & WS_DISABLED, "window should be disabled\n");
5042 ok(style & WS_VISIBLE, "window should be visible\n");
5043 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5044 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5045 GetWindowRect(hwnd, &rc);
5046 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5047 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5048 rc.left, rc.top, rc.right, rc.bottom);
5050 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
5051 ok(!ret, "not expected ret: %lu\n", ret);
5052 style = GetWindowLong(hwnd, GWL_STYLE);
5053 ok(style & WS_DISABLED, "window should be disabled\n");
5054 ok(style & WS_VISIBLE, "window should be visible\n");
5055 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5056 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5057 GetWindowRect(hwnd, &rc);
5058 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5059 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5060 rc.left, rc.top, rc.right, rc.bottom);
5062 ret = ShowWindow(hwnd, SW_MINIMIZE);
5063 ok(ret, "not expected ret: %lu\n", ret);
5064 style = GetWindowLong(hwnd, GWL_STYLE);
5065 ok(style & WS_DISABLED, "window should be disabled\n");
5066 ok(style & WS_VISIBLE, "window should be visible\n");
5067 ok(style & WS_MINIMIZE, "window should be minimized\n");
5068 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5069 GetWindowRect(hwnd, &rc);
5070 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
5072 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
5073 ok(!ret, "not expected ret: %lu\n", ret);
5074 style = GetWindowLong(hwnd, GWL_STYLE);
5075 ok(style & WS_DISABLED, "window should be disabled\n");
5076 ok(style & WS_VISIBLE, "window should be visible\n");
5077 ok(style & WS_MINIMIZE, "window should be minimized\n");
5078 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5079 GetWindowRect(hwnd, &rc);
5080 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
5082 ret = ShowWindow(hwnd, SW_RESTORE);
5083 ok(ret, "not expected ret: %lu\n", ret);
5084 style = GetWindowLong(hwnd, GWL_STYLE);
5085 ok(style & WS_DISABLED, "window should be disabled\n");
5086 ok(style & WS_VISIBLE, "window should be visible\n");
5087 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5088 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5089 GetWindowRect(hwnd, &rc);
5090 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5091 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5092 rc.left, rc.top, rc.right, rc.bottom);
5094 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
5095 ok(!ret, "not expected ret: %lu\n", ret);
5096 ok(IsWindow(hwnd), "window should exist\n");
5098 ret = EnableWindow(hwnd, TRUE);
5099 ok(ret, "not expected ret: %lu\n", ret);
5101 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
5102 ok(!ret, "not expected ret: %lu\n", ret);
5103 ok(!IsWindow(hwnd), "window should not exist\n");
5106 static void test_gettext(void)
5109 LPCSTR clsname = "gettexttest";
5113 memset( &cls, 0, sizeof cls );
5114 cls.lpfnWndProc = DefWindowProc;
5115 cls.lpszClassName = clsname;
5116 cls.hInstance = GetModuleHandle(NULL);
5118 if (!RegisterClass( &cls )) return;
5120 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
5121 ok( hwnd != NULL, "window was null\n");
5123 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
5124 ok( r == 0, "settext should return zero\n");
5126 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
5127 ok( r == 0, "settext should return zero (%ld)\n", r);
5129 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
5130 ok( r == 0, "settext should return zero (%ld)\n", r);
5132 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
5133 ok( r == 0, "settext should return zero (%ld)\n", r);
5135 DestroyWindow(hwnd);
5136 UnregisterClass( clsname, NULL );
5140 static void test_GetUpdateRect(void)
5143 BOOL ret, parent_wm_paint, grandparent_wm_paint;
5145 HWND hgrandparent, hparent, hchild;
5147 static const char classNameA[] = "GetUpdateRectClass";
5149 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
5150 0, 0, 100, 100, NULL, NULL, 0, NULL);
5152 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
5153 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
5155 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
5156 10, 10, 30, 30, hparent, NULL, 0, NULL);
5158 ShowWindow(hgrandparent, SW_SHOW);
5159 UpdateWindow(hgrandparent);
5160 flush_events( TRUE );
5162 ShowWindow(hchild, SW_HIDE);
5163 SetRect(&rc2, 0, 0, 0, 0);
5164 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5165 ok(!ret, "GetUpdateRect returned not empty region\n");
5166 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5167 rc1.left, rc1.top, rc1.right, rc1.bottom,
5168 rc2.left, rc2.top, rc2.right, rc2.bottom);
5170 SetRect(&rc2, 10, 10, 40, 40);
5171 ret = GetUpdateRect(hparent, &rc1, FALSE);
5172 ok(ret, "GetUpdateRect returned empty region\n");
5173 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5174 rc1.left, rc1.top, rc1.right, rc1.bottom,
5175 rc2.left, rc2.top, rc2.right, rc2.bottom);
5177 parent_wm_paint = FALSE;
5178 grandparent_wm_paint = FALSE;
5179 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
5181 if (msg.message == WM_PAINT)
5183 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
5184 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
5186 DispatchMessage(&msg);
5188 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
5189 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
5191 DestroyWindow(hgrandparent);
5194 cls.lpfnWndProc = DefWindowProcA;
5197 cls.hInstance = GetModuleHandleA(0);
5199 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5200 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5201 cls.lpszMenuName = NULL;
5202 cls.lpszClassName = classNameA;
5204 if(!RegisterClassA(&cls)) {
5205 trace("Register failed %d\n", GetLastError());
5209 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
5210 0, 0, 100, 100, NULL, NULL, 0, NULL);
5212 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
5213 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
5215 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
5216 10, 10, 30, 30, hparent, NULL, 0, NULL);
5218 ShowWindow(hgrandparent, SW_SHOW);
5219 UpdateWindow(hgrandparent);
5220 flush_events( TRUE );
5222 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5223 ok(!ret, "GetUpdateRect returned not empty region\n");
5225 ShowWindow(hchild, SW_HIDE);
5227 SetRect(&rc2, 0, 0, 0, 0);
5228 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5229 ok(!ret, "GetUpdateRect returned not empty region\n");
5230 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5231 rc1.left, rc1.top, rc1.right, rc1.bottom,
5232 rc2.left, rc2.top, rc2.right, rc2.bottom);
5234 SetRect(&rc2, 10, 10, 40, 40);
5235 ret = GetUpdateRect(hparent, &rc1, FALSE);
5236 ok(ret, "GetUpdateRect returned empty region\n");
5237 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5238 rc1.left, rc1.top, rc1.right, rc1.bottom,
5239 rc2.left, rc2.top, rc2.right, rc2.bottom);
5241 parent_wm_paint = FALSE;
5242 grandparent_wm_paint = FALSE;
5243 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
5245 if (msg.message == WM_PAINT)
5247 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
5248 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
5250 DispatchMessage(&msg);
5252 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
5253 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
5255 DestroyWindow(hgrandparent);
5259 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5267 const int waitTime = 2000;
5269 BeginPaint(hwnd, &ps);
5271 /* create and destroy window to create an exposed region on this window */
5272 win = CreateWindowA("static", "win", WS_VISIBLE,
5273 10,10,50,50, NULL, NULL, 0, NULL);
5276 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
5278 ValidateRect(hwnd, NULL);
5279 EndPaint(hwnd, &ps);
5281 if(waitResult != WAIT_TIMEOUT)
5283 GetUpdateRect(hwnd, &updateRect, FALSE);
5284 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
5289 return DefWindowProc(hwnd, msg, wParam, lParam);
5292 static void test_Expose(void)
5297 memset(&cls, 0, sizeof(WNDCLASSA));
5298 cls.lpfnWndProc = TestExposedRegion_WndProc;
5299 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5300 cls.lpszClassName = "TestExposeClass";
5301 RegisterClassA(&cls);
5303 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
5304 0, 0, 200, 100, NULL, NULL, 0, NULL);
5310 static LRESULT CALLBACK TestNCRedraw_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5312 static UINT ncredrawflags;
5318 ncredrawflags = *(UINT *) (((CREATESTRUCT *)lParam)->lpCreateParams);
5321 RedrawWindow(hwnd, NULL, NULL, ncredrawflags);
5324 BeginPaint(hwnd, &ps);
5325 EndPaint(hwnd, &ps);
5328 return DefWindowProc(hwnd, msg, wParam, lParam);
5331 static void run_NCRedrawLoop(UINT flags)
5338 hwnd = CreateWindowA("TestNCRedrawClass", "MainWindow",
5339 WS_OVERLAPPEDWINDOW, 0, 0, 200, 100,
5340 NULL, NULL, 0, &flags);
5341 ShowWindow(hwnd, SW_SHOW);
5343 flush_events( FALSE );
5344 while(PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE) != 0)
5346 if (msg.message == WM_PAINT) loopcount++;
5347 if (loopcount >= 100) break;
5348 TranslateMessage(&msg);
5349 DispatchMessage(&msg);
5350 MsgWaitForMultipleObjects(0, NULL, FALSE, 100, QS_ALLINPUT);
5352 if (flags == (RDW_INVALIDATE | RDW_FRAME))
5353 todo_wine ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
5355 ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
5356 DestroyWindow(hwnd);
5359 static void test_NCRedraw(void)
5363 wndclass.lpszClassName = "TestNCRedrawClass";
5364 wndclass.style = CS_HREDRAW | CS_VREDRAW;
5365 wndclass.lpfnWndProc = TestNCRedraw_WndProc;
5366 wndclass.cbClsExtra = 0;
5367 wndclass.cbWndExtra = 0;
5368 wndclass.hInstance = 0;
5369 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
5370 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
5371 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
5372 wndclass.lpszMenuName = NULL;
5374 RegisterClassA(&wndclass);
5376 run_NCRedrawLoop(RDW_INVALIDATE | RDW_FRAME);
5377 run_NCRedrawLoop(RDW_INVALIDATE);
5380 static void test_GetWindowModuleFileName(void)
5385 char buf1[MAX_PATH], buf2[MAX_PATH];
5387 if (!pGetWindowModuleFileNameA)
5389 win_skip("GetWindowModuleFileNameA is not available\n");
5393 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
5396 hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
5397 ok(hinst == 0 || broken(hinst == GetModuleHandle(0)), /* win9x */ "expected 0, got %p\n", hinst);
5400 SetLastError(0xdeadbeef);
5401 ret1 = GetModuleFileName(hinst, buf1, sizeof(buf1));
5402 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
5405 SetLastError(0xdeadbeef);
5406 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
5407 ok(ret2 || broken(!ret2), /* nt4 sp 3 */
5408 "GetWindowModuleFileNameA error %u\n", GetLastError());
5412 ok(ret1 == ret2 || broken(ret2 == ret1 + 1), /* win98 */ "%u != %u\n", ret1, ret2);
5413 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
5415 hinst = GetModuleHandle(0);
5417 SetLastError(0xdeadbeef);
5418 ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
5419 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
5420 "expected %u, got %u\n", ret1 - 2, ret2);
5421 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5422 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5423 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5425 SetLastError(0xdeadbeef);
5426 ret2 = GetModuleFileName(hinst, buf2, 0);
5427 ok(!ret2, "GetModuleFileName should return 0\n");
5428 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5429 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5430 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5432 SetLastError(0xdeadbeef);
5433 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
5434 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3) /* win98 */ || broken(!ret2), /* nt4 sp3 */
5435 "expected %u, got %u\n", ret1 - 2, ret2);
5436 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5437 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5438 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5440 SetLastError(0xdeadbeef);
5441 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
5442 ok(!ret2, "expected 0, got %u\n", ret2);
5443 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5444 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5445 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5447 DestroyWindow(hwnd);
5450 hwnd = (HWND)0xdeadbeef;
5451 SetLastError(0xdeadbeef);
5452 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
5453 ok(!ret1, "expected 0, got %u\n", ret1);
5454 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef), /* win9x */
5455 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
5457 hwnd = FindWindow("Shell_TrayWnd", NULL);
5458 ok(IsWindow(hwnd) || broken(!hwnd), "got invalid tray window %p\n", hwnd);
5459 SetLastError(0xdeadbeef);
5460 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
5461 ok(!ret1 || broken(ret1), /* win98 */ "expected 0, got %u\n", ret1);
5463 if (!ret1) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
5465 ret1 = GetModuleFileName(0, buf1, sizeof(buf1));
5466 hwnd = GetDesktopWindow();
5467 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
5468 SetLastError(0xdeadbeef);
5469 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
5471 ret1 == ret2 || /* vista */
5472 broken(ret2), /* some win98 return user.exe as file name */
5473 "expected 0 or %u, got %u %s\n", ret1, ret2, buf2);
5477 static void test_hwnd_message(void)
5479 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
5480 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
5482 HWND parent = 0, hwnd, found;
5485 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
5486 on CreateWindowExA and crash later in the test.
5487 Use UNICODE here to fail on win9x */
5488 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
5489 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
5492 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
5496 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
5500 HWND root, desktop = GetDesktopWindow();
5502 parent = pGetAncestor(hwnd, GA_PARENT);
5503 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
5504 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
5505 root = pGetAncestor(hwnd, GA_ROOT);
5506 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
5507 ok( !pGetAncestor(parent, GA_PARENT) || broken(pGetAncestor(parent, GA_PARENT) != 0), /* win2k */
5508 "parent shouldn't have parent %p\n", pGetAncestor(parent, GA_PARENT) );
5509 trace("parent %p root %p desktop %p\n", parent, root, desktop);
5510 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
5511 ok( !lstrcmpi( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
5512 GetWindowRect( parent, &rect );
5513 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
5514 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
5516 GetWindowRect( hwnd, &rect );
5517 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
5518 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
5520 /* test FindWindow behavior */
5522 found = FindWindowExA( 0, 0, 0, "message window" );
5523 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
5524 SetLastError(0xdeadbeef);
5525 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
5526 ok( found == 0, "found message window %p/%p\n", found, hwnd );
5527 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
5530 found = FindWindowExA( parent, 0, 0, "message window" );
5531 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
5534 /* test IsChild behavior */
5536 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
5538 /* test IsWindowVisible behavior */
5540 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
5541 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
5543 DestroyWindow(hwnd);
5546 static void test_layered_window(void)
5554 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes)
5556 win_skip( "layered windows not supported\n" );
5559 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
5560 100, 100, 200, 200, 0, 0, 0, NULL);
5562 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5563 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
5564 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
5565 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
5566 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5567 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5568 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5569 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
5570 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5571 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5572 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5573 ok( key == 0x123456 || key == 0, "wrong color key %x\n", key );
5574 ok( alpha == 44, "wrong alpha %u\n", alpha );
5575 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
5577 /* clearing WS_EX_LAYERED resets attributes */
5578 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5579 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5580 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
5581 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5582 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5583 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5584 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
5585 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5586 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5587 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5588 ok( key == 0x654321, "wrong color key %x\n", key );
5589 ok( alpha == 22, "wrong alpha %u\n", alpha );
5590 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
5592 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
5593 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5595 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5596 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5597 ok( key == 0x888888, "wrong color key %x\n", key );
5598 /* alpha not changed on vista if LWA_ALPHA is not set */
5599 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
5600 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
5602 /* color key may or may not be changed without LWA_COLORKEY */
5603 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
5604 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5606 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5607 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5608 ok( key == 0x888888 || key == 0x999999, "wrong color key %x\n", key );
5609 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
5610 ok( flags == 0, "wrong flags %x\n", flags );
5612 /* default alpha and color key is 0 */
5613 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5614 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5615 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
5616 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5617 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5618 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5619 ok( key == 0 || key == 0x222222, "wrong color key %x\n", key );
5620 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
5621 ok( flags == 0, "wrong flags %x\n", flags );
5623 DestroyWindow( hwnd );
5626 static MONITORINFO mi;
5628 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
5634 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
5635 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs->x, cs->y, cs->cx, cs->cy);
5636 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
5637 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
5638 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
5639 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5640 cs->x, cs->y, cs->cx, cs->cy);
5643 case WM_GETMINMAXINFO:
5645 MINMAXINFO *minmax = (MINMAXINFO *)lp;
5646 dump_minmax_info(minmax);
5647 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
5648 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
5649 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
5650 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
5654 return DefWindowProc(hwnd, msg, wp, lp);
5657 static void test_fullscreen(void)
5659 static const DWORD t_style[] = {
5660 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
5662 static const DWORD t_ex_style[] = {
5663 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
5673 if (!pGetMonitorInfoA || !pMonitorFromPoint)
5675 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
5680 SetLastError(0xdeadbeef);
5681 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
5682 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
5684 mi.cbSize = sizeof(mi);
5685 SetLastError(0xdeadbeef);
5686 ret = pGetMonitorInfoA(hmon, &mi);
5687 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
5688 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
5689 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5690 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5693 cls.lpfnWndProc = fullscreen_wnd_proc;
5696 cls.hInstance = GetModuleHandle(0);
5698 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5699 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5700 cls.lpszMenuName = NULL;
5701 cls.lpszClassName = "fullscreen_class";
5702 RegisterClass(&cls);
5704 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
5706 DWORD style, ex_style;
5708 /* avoid a WM interaction */
5709 assert(!(t_style[i] & WS_VISIBLE));
5711 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
5716 ex_style = t_ex_style[j];
5718 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5719 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5720 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5721 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5722 GetWindowRect(hwnd, &rc);
5723 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5724 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5725 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5726 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5727 DestroyWindow(hwnd);
5729 style = t_style[i] | WS_MAXIMIZE;
5730 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5731 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5732 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5733 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5734 GetWindowRect(hwnd, &rc);
5735 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5736 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5737 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5738 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5739 DestroyWindow(hwnd);
5741 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
5742 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5743 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5744 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5745 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5746 GetWindowRect(hwnd, &rc);
5747 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5748 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5749 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5750 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5751 DestroyWindow(hwnd);
5753 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
5754 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5755 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5756 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5757 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5758 GetWindowRect(hwnd, &rc);
5759 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5760 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5761 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5762 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5763 DestroyWindow(hwnd);
5765 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
5766 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5767 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5768 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5769 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5770 GetWindowRect(hwnd, &rc);
5771 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5772 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5773 fixup = min(abs(rc.left), abs(rc.top));
5774 InflateRect(&rc, -fixup, -fixup);
5775 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5776 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5777 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
5778 ex_style, style, rc.left, rc.top, rc.right, rc.bottom,
5779 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5780 DestroyWindow(hwnd);
5782 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
5783 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5784 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5785 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5786 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5787 GetWindowRect(hwnd, &rc);
5788 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5789 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5790 fixup = min(abs(rc.left), abs(rc.top));
5791 InflateRect(&rc, -fixup, -fixup);
5792 if (style & (WS_CHILD | WS_POPUP))
5793 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5794 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5795 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5797 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5798 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5799 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5800 DestroyWindow(hwnd);
5804 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5807 static BOOL test_thick_child_got_minmax;
5808 static const char * test_thick_child_name;
5809 static LONG test_thick_child_style;
5810 static LONG test_thick_child_exStyle;
5812 static LRESULT WINAPI test_thick_child_size_winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5815 int expectedMinTrackX;
5816 int expectedMinTrackY;
5817 int actualMinTrackX;
5818 int actualMinTrackY;
5819 int expectedMaxTrackX;
5820 int expectedMaxTrackY;
5821 int actualMaxTrackX;
5822 int actualMaxTrackY;
5823 int expectedMaxSizeX;
5824 int expectedMaxSizeY;
5835 case WM_GETMINMAXINFO:
5837 minmax = (MINMAXINFO *)lparam;
5838 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
5839 dump_minmax_info( minmax );
5841 test_thick_child_got_minmax = TRUE;
5844 adjustedStyle = test_thick_child_style;
5845 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
5846 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5847 GetClientRect(GetParent(hwnd), &rect);
5848 AdjustWindowRectEx(&rect, adjustedStyle, FALSE, test_thick_child_exStyle);
5850 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
5852 expectedMinTrackX = GetSystemMetrics(SM_CXMINTRACK);
5853 expectedMinTrackY = GetSystemMetrics(SM_CYMINTRACK);
5857 expectedMinTrackX = -2 * rect.left;
5858 expectedMinTrackY = -2 * rect.top;
5860 actualMinTrackX = minmax->ptMinTrackSize.x;
5861 actualMinTrackY = minmax->ptMinTrackSize.y;
5863 ok(actualMinTrackX == expectedMinTrackX && actualMinTrackY == expectedMinTrackY,
5864 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
5865 expectedMinTrackX, expectedMinTrackY, actualMinTrackX, actualMinTrackY,
5866 test_thick_child_name);
5868 actualMaxTrackX = minmax->ptMaxTrackSize.x;
5869 actualMaxTrackY = minmax->ptMaxTrackSize.y;
5870 expectedMaxTrackX = GetSystemMetrics(SM_CXMAXTRACK);
5871 expectedMaxTrackY = GetSystemMetrics(SM_CYMAXTRACK);
5872 ok(actualMaxTrackX == expectedMaxTrackX && actualMaxTrackY == expectedMaxTrackY,
5873 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
5874 expectedMaxTrackX, expectedMaxTrackY, actualMaxTrackX, actualMaxTrackY,
5875 test_thick_child_name);
5877 expectedMaxSizeX = rect.right - rect.left;
5878 expectedMaxSizeY = rect.bottom - rect.top;
5879 actualMaxSizeX = minmax->ptMaxSize.x;
5880 actualMaxSizeY = minmax->ptMaxSize.y;
5882 ok(actualMaxSizeX == expectedMaxSizeX && actualMaxSizeY == expectedMaxSizeY,
5883 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
5884 expectedMaxSizeX, expectedMaxSizeY, actualMaxSizeX, actualMaxSizeY,
5885 test_thick_child_name);
5888 expectedPosX = rect.left;
5889 expectedPosY = rect.top;
5890 actualPosX = minmax->ptMaxPosition.x;
5891 actualPosY = minmax->ptMaxPosition.y;
5892 ok(actualPosX == expectedPosX && actualPosY == expectedPosY,
5893 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
5894 expectedPosX, expectedPosY, actualPosX, actualPosY, test_thick_child_name);
5900 return DefWindowProcA(hwnd, msg, wparam, lparam);
5903 #define NUMBER_OF_THICK_CHILD_TESTS 16
5904 static void test_thick_child_size(HWND parentWindow)
5908 RECT adjustedParentRect;
5913 LONG expectedHeight;
5915 LPCTSTR className = "THICK_CHILD_CLASS";
5918 static const LONG styles[NUMBER_OF_THICK_CHILD_TESTS] = {
5919 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5920 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5921 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5922 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5923 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5924 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5925 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5926 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5927 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5928 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5929 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5930 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5931 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5932 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5933 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5934 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5937 static const LONG exStyles[NUMBER_OF_THICK_CHILD_TESTS] = {
5942 WS_EX_DLGMODALFRAME,
5943 WS_EX_DLGMODALFRAME,
5944 WS_EX_DLGMODALFRAME,
5945 WS_EX_DLGMODALFRAME,
5950 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5951 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5952 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5953 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5955 static const char *styleName[NUMBER_OF_THICK_CHILD_TESTS] = {
5956 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
5957 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
5958 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
5959 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
5960 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
5961 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
5962 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5963 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5964 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
5965 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
5966 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5967 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5968 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5969 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5970 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5971 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5975 cls.lpfnWndProc = test_thick_child_size_winproc;
5978 cls.hInstance = GetModuleHandleA(0);
5980 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5981 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5982 cls.lpszMenuName = NULL;
5983 cls.lpszClassName = className;
5984 SetLastError(0xdeadbeef);
5985 ok(RegisterClassA(&cls),"RegisterClassA failed, error: %u\n", GetLastError());
5987 for(i = 0; i < NUMBER_OF_THICK_CHILD_TESTS; i++)
5989 test_thick_child_name = styleName[i];
5990 test_thick_child_style = styles[i];
5991 test_thick_child_exStyle = exStyles[i];
5992 test_thick_child_got_minmax = FALSE;
5994 SetLastError(0xdeadbeef);
5995 childWindow = CreateWindowEx( exStyles[i], className, "", styles[i], 0, 0, 0, 0, parentWindow, 0, GetModuleHandleA(0), NULL );
5996 ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
5998 ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
6000 SetLastError(0xdeadbeef);
6001 success = GetWindowRect(childWindow, &childRect);
6002 ok(success,"GetWindowRect call failed, error: %u\n", GetLastError());
6003 childWidth = childRect.right - childRect.left;
6004 childHeight = childRect.bottom - childRect.top;
6006 adjustedStyle = styles[i];
6007 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
6008 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
6009 GetClientRect(GetParent(childWindow), &adjustedParentRect);
6010 AdjustWindowRectEx(&adjustedParentRect, adjustedStyle, FALSE, test_thick_child_exStyle);
6013 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
6015 expectedWidth = GetSystemMetrics(SM_CXMINTRACK);
6016 expectedHeight = GetSystemMetrics(SM_CYMINTRACK);
6020 expectedWidth = -2 * adjustedParentRect.left;
6021 expectedHeight = -2 * adjustedParentRect.top;
6024 ok((childWidth == expectedWidth) && (childHeight == expectedHeight),
6025 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
6026 test_thick_child_name, expectedWidth, expectedHeight, childWidth, childHeight);
6028 SetLastError(0xdeadbeef);
6029 success = DestroyWindow(childWindow);
6030 ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
6032 ok(UnregisterClass(className, GetModuleHandleA(0)),"UnregisterClass call failed\n");
6035 static void test_handles( HWND full_hwnd )
6037 HWND hwnd = full_hwnd;
6041 SetLastError( 0xdeadbeef );
6042 ret = GetWindowRect( hwnd, &rect );
6043 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6046 if ((ULONG_PTR)full_hwnd >> 32)
6047 hwnd = (HWND)((ULONG_PTR)full_hwnd & ~0u);
6049 hwnd = (HWND)((ULONG_PTR)full_hwnd | ((ULONG_PTR)~0u << 32));
6050 SetLastError( 0xdeadbeef );
6051 ret = GetWindowRect( hwnd, &rect );
6052 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6054 hwnd = (HWND)(((ULONG_PTR)full_hwnd & ~0u) | ((ULONG_PTR)0x1234 << 32));
6055 SetLastError( 0xdeadbeef );
6056 ret = GetWindowRect( hwnd, &rect );
6057 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6059 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x9876 << 16));
6060 SetLastError( 0xdeadbeef );
6061 ret = GetWindowRect( hwnd, &rect );
6062 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
6063 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
6065 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x12345678 << 16));
6066 SetLastError( 0xdeadbeef );
6067 ret = GetWindowRect( hwnd, &rect );
6068 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
6069 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
6073 static void test_winregion(void)
6080 if (!pGetWindowRgnBox)
6082 win_skip("GetWindowRgnBox not supported\n");
6086 hwnd = CreateWindowExA(0, "static", NULL, WS_VISIBLE, 10, 10, 10, 10, NULL, 0, 0, NULL);
6088 SetLastError(0xdeadbeef);
6089 ret = pGetWindowRgnBox(hwnd, NULL);
6090 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
6091 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
6093 hrgn = CreateRectRgn(2, 3, 10, 15);
6094 ok( hrgn != NULL, "Region creation failed\n");
6097 SetWindowRgn(hwnd, hrgn, FALSE);
6099 SetLastError(0xdeadbeef);
6100 ret = pGetWindowRgnBox(hwnd, NULL);
6101 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
6102 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
6104 r.left = r.top = r.right = r.bottom = 0;
6105 ret = pGetWindowRgnBox(hwnd, &r);
6106 ok( ret == SIMPLEREGION, "Expected SIMPLEREGION, got %d\n", ret);
6107 ok( r.left == 2 && r.top == 3 && r.right == 10 && r.bottom == 15,
6108 "Expected (2,3,10,15), got (%d,%d,%d,%d)\n", r.left, r.top,
6112 DestroyWindow(hwnd);
6117 HMODULE user32 = GetModuleHandleA( "user32.dll" );
6118 HMODULE gdi32 = GetModuleHandleA("gdi32.dll");
6119 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
6120 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
6121 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
6122 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
6123 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
6124 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
6125 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
6126 pGetWindowRgnBox = (void *)GetProcAddress( user32, "GetWindowRgnBox" );
6127 pGetGUIThreadInfo = (void *)GetProcAddress( user32, "GetGUIThreadInfo" );
6128 pGetProcessDefaultLayout = (void *)GetProcAddress( user32, "GetProcessDefaultLayout" );
6129 pSetProcessDefaultLayout = (void *)GetProcAddress( user32, "SetProcessDefaultLayout" );
6130 pGetLayout = (void *)GetProcAddress( gdi32, "GetLayout" );
6131 pSetLayout = (void *)GetProcAddress( gdi32, "SetLayout" );
6133 if (!RegisterWindowClasses()) assert(0);
6135 SetLastError(0xdeafbeef);
6136 GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC);
6137 is_win9x = (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED);
6139 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
6140 if (!hhook) win_skip( "Cannot set CBT hook, skipping some tests\n" );
6142 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
6143 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
6144 WS_MAXIMIZEBOX | WS_POPUP,
6146 0, 0, GetModuleHandle(0), NULL);
6147 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
6148 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
6149 WS_MAXIMIZEBOX | WS_POPUP,
6151 0, 0, GetModuleHandle(0), NULL);
6153 assert( hwndMain2 );
6155 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
6157 /* Add the tests below this line */
6158 test_thick_child_size(hwndMain);
6160 test_hwnd_message();
6161 test_nonclient_area(hwndMain);
6163 test_GetWindowModuleFileName();
6166 test_capture_3(hwndMain, hwndMain2);
6169 test_CreateWindow();
6170 test_parent_owner();
6172 test_enum_thread_windows();
6176 test_SetWindowPos(hwndMain);
6177 test_SetMenu(hwndMain);
6178 test_SetFocus(hwndMain);
6179 test_SetActiveWindow(hwndMain);
6182 test_children_zorder(hwndMain);
6183 test_popup_zorder(hwndMain2, hwndMain, WS_POPUP);
6184 test_popup_zorder(hwndMain2, hwndMain, 0);
6185 test_keyboard_input(hwndMain);
6186 test_mouse_input(hwndMain);
6187 test_validatergn(hwndMain);
6188 test_nccalcscroll( hwndMain);
6189 test_scrollwindow( hwndMain);
6190 test_scrollvalidate( hwndMain);
6191 test_scrolldc( hwndMain);
6193 test_IsWindowUnicode();
6194 test_vis_rgn(hwndMain);
6196 test_AdjustWindowRect();
6197 test_window_styles();
6200 test_SetWindowLong();
6202 if (0) test_gettext(); /* crashes on NT4 */
6203 test_GetUpdateRect();
6205 test_layered_window();
6207 test_SetForegroundWindow(hwndMain);
6208 test_shell_window();
6209 test_handles( hwndMain );
6212 /* add the tests above this line */
6213 if (hhook) UnhookWindowsHookEx(hhook);
6215 DestroyWindow(hwndMain2);
6216 DestroyWindow(hwndMain);