user32/tests: Workaround SetForegroundWindow failure due to foreground lock timeout.
[wine/multimedia.git] / dlls / user32 / tests / win.c
blobf8c919aac7ff6c00d2d0953d10a3f84f3238c709
1 /*
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
26 #include <assert.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <stdio.h>
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "winuser.h"
36 #include "wine/test.h"
38 #ifndef SPI_GETDESKWALLPAPER
39 #define SPI_GETDESKWALLPAPER 0x0073
40 #endif
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 *pUpdateLayeredWindow)(HWND,HDC,POINT*,SIZE*,HDC,POINT*,COLORREF,BLENDFUNCTION*,DWORD);
53 static BOOL (WINAPI *pUpdateLayeredWindowIndirect)(HWND,const UPDATELAYEREDWINDOWINFO*);
54 static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
55 static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
56 static int (WINAPI *pGetWindowRgnBox)(HWND,LPRECT);
57 static BOOL (WINAPI *pGetGUIThreadInfo)(DWORD, GUITHREADINFO*);
58 static BOOL (WINAPI *pGetProcessDefaultLayout)( DWORD *layout );
59 static BOOL (WINAPI *pSetProcessDefaultLayout)( DWORD layout );
60 static BOOL (WINAPI *pFlashWindowEx)( PFLASHWINFO pfwi );
61 static DWORD (WINAPI *pSetLayout)(HDC hdc, DWORD layout);
62 static DWORD (WINAPI *pGetLayout)(HDC hdc);
63 static BOOL (WINAPI *pMirrorRgn)(HWND hwnd, HRGN hrgn);
65 static BOOL test_lbuttondown_flag;
66 static HWND hwndMessage;
67 static HWND hwndMain, hwndMain2;
68 static HHOOK hhook;
70 static const char* szAWRClass = "Winsize";
71 static HMENU hmenu;
72 static DWORD our_pid;
74 static BOOL is_win9x = FALSE;
76 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
78 static void dump_minmax_info( const MINMAXINFO *minmax )
80 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
81 minmax->ptReserved.x, minmax->ptReserved.y,
82 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
83 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
84 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
85 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
88 /* try to make sure pending X events have been processed before continuing */
89 static void flush_events( BOOL remove_messages )
91 MSG msg;
92 int diff = 200;
93 int min_timeout = 100;
94 DWORD time = GetTickCount() + diff;
96 while (diff > 0)
98 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
99 if (remove_messages)
100 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
101 diff = time - GetTickCount();
102 min_timeout = 50;
106 /* check the values returned by the various parent/owner functions on a given window */
107 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
108 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
110 HWND res;
112 if (pGetAncestor)
114 res = pGetAncestor( hwnd, GA_PARENT );
115 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
117 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
118 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
119 res = GetParent( hwnd );
120 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
121 res = GetWindow( hwnd, GW_OWNER );
122 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
123 if (pGetAncestor)
125 res = pGetAncestor( hwnd, GA_ROOT );
126 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
127 res = pGetAncestor( hwnd, GA_ROOTOWNER );
128 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
132 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
133 static void check_wnd_state_(const char *file, int line,
134 HWND active, HWND foreground, HWND focus, HWND capture)
136 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
137 /* only check foreground if it belongs to the current thread */
138 /* foreground can be moved to a different app pretty much at any time */
139 if (foreground && GetForegroundWindow() &&
140 GetWindowThreadProcessId(GetForegroundWindow(), NULL) == GetCurrentThreadId())
141 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
142 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
143 ok_(file, line)(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
146 /* same as above but without capture test */
147 #define check_active_state(a,b,c) check_active_state_(__FILE__,__LINE__,a,b,c)
148 static void check_active_state_(const char *file, int line,
149 HWND active, HWND foreground, HWND focus)
151 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
152 /* only check foreground if it belongs to the current thread */
153 /* foreground can be moved to a different app pretty much at any time */
154 if (foreground && GetForegroundWindow() &&
155 GetWindowThreadProcessId(GetForegroundWindow(), NULL) == GetCurrentThreadId())
156 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
157 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
160 static BOOL ignore_message( UINT message )
162 /* these are always ignored */
163 return (message >= 0xc000 ||
164 message == WM_GETICON ||
165 message == WM_GETOBJECT ||
166 message == WM_TIMECHANGE ||
167 message == WM_DEVICECHANGE);
170 static BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
172 (*(LPINT)lParam)++;
173 trace("EnumChildProc on %p\n", hwndChild);
174 if (*(LPINT)lParam > 1) return FALSE;
175 return TRUE;
178 /* will search for the given window */
179 static BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
181 trace("EnumChildProc1 on %p\n", hwndChild);
182 if ((HWND)lParam == hwndChild) return FALSE;
183 return TRUE;
186 static HWND create_tool_window( LONG style, HWND parent )
188 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
189 0, 0, 100, 100, parent, 0, 0, NULL );
190 ok( ret != 0, "Creation failed\n" );
191 return ret;
194 /* test parent and owner values for various combinations */
195 static void test_parent_owner(void)
197 LONG style;
198 HWND test, owner, ret;
199 HWND desktop = GetDesktopWindow();
200 HWND child = create_tool_window( WS_CHILD, hwndMain );
201 INT numChildren;
203 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
205 /* child without parent, should fail */
206 SetLastError(0xdeadbeef);
207 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
208 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
209 ok( !test, "WS_CHILD without parent created\n" );
210 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD ||
211 broken(GetLastError() == 0xdeadbeef), /* win9x */
212 "CreateWindowExA error %u\n", GetLastError() );
214 /* desktop window */
215 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
216 style = GetWindowLongA( desktop, GWL_STYLE );
217 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
218 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
219 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
221 /* normal child window */
222 test = create_tool_window( WS_CHILD, hwndMain );
223 trace( "created child %p\n", test );
224 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
225 SetWindowLongA( test, GWL_STYLE, 0 );
226 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
227 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
228 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
229 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
230 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
231 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
232 DestroyWindow( test );
234 /* normal child window with WS_MAXIMIZE */
235 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
236 DestroyWindow( test );
238 /* normal child window with WS_THICKFRAME */
239 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
240 DestroyWindow( test );
242 /* popup window with WS_THICKFRAME */
243 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
244 DestroyWindow( test );
246 /* child of desktop */
247 test = create_tool_window( WS_CHILD, desktop );
248 trace( "created child of desktop %p\n", test );
249 check_parents( test, desktop, 0, desktop, 0, test, desktop );
250 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
251 check_parents( test, desktop, 0, 0, 0, test, test );
252 SetWindowLongA( test, GWL_STYLE, 0 );
253 check_parents( test, desktop, 0, 0, 0, test, test );
254 DestroyWindow( test );
256 /* child of desktop with WS_MAXIMIZE */
257 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
258 DestroyWindow( test );
260 /* child of desktop with WS_MINIMIZE */
261 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
262 DestroyWindow( test );
264 /* child of child */
265 test = create_tool_window( WS_CHILD, child );
266 trace( "created child of child %p\n", test );
267 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
268 SetWindowLongA( test, GWL_STYLE, 0 );
269 check_parents( test, child, child, 0, 0, hwndMain, test );
270 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
271 check_parents( test, child, child, 0, 0, hwndMain, test );
272 DestroyWindow( test );
274 /* child of child with WS_MAXIMIZE */
275 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
276 DestroyWindow( test );
278 /* child of child with WS_MINIMIZE */
279 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
280 DestroyWindow( test );
282 /* not owned top-level window */
283 test = create_tool_window( 0, 0 );
284 trace( "created top-level %p\n", test );
285 check_parents( test, desktop, 0, 0, 0, test, test );
286 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
287 check_parents( test, desktop, 0, 0, 0, test, test );
288 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
289 check_parents( test, desktop, 0, desktop, 0, test, desktop );
290 DestroyWindow( test );
292 /* not owned top-level window with WS_MAXIMIZE */
293 test = create_tool_window( WS_MAXIMIZE, 0 );
294 DestroyWindow( test );
296 /* owned top-level window */
297 test = create_tool_window( 0, hwndMain );
298 trace( "created owned top-level %p\n", test );
299 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
300 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
301 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
302 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
303 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
304 DestroyWindow( test );
306 /* owned top-level window with WS_MAXIMIZE */
307 test = create_tool_window( WS_MAXIMIZE, hwndMain );
308 DestroyWindow( test );
310 /* not owned popup */
311 test = create_tool_window( WS_POPUP, 0 );
312 trace( "created popup %p\n", test );
313 check_parents( test, desktop, 0, 0, 0, test, test );
314 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
315 check_parents( test, desktop, 0, desktop, 0, test, desktop );
316 SetWindowLongA( test, GWL_STYLE, 0 );
317 check_parents( test, desktop, 0, 0, 0, test, test );
318 DestroyWindow( test );
320 /* not owned popup with WS_MAXIMIZE */
321 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
322 DestroyWindow( test );
324 /* owned popup */
325 test = create_tool_window( WS_POPUP, hwndMain );
326 trace( "created owned popup %p\n", test );
327 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
328 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
329 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
330 SetWindowLongA( test, GWL_STYLE, 0 );
331 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
332 DestroyWindow( test );
334 /* owned popup with WS_MAXIMIZE */
335 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
336 DestroyWindow( test );
338 /* top-level window owned by child (same as owned by top-level) */
339 test = create_tool_window( 0, child );
340 trace( "created top-level owned by child %p\n", test );
341 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
342 DestroyWindow( test );
344 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
345 test = create_tool_window( WS_MAXIMIZE, child );
346 DestroyWindow( test );
348 /* popup owned by desktop (same as not owned) */
349 test = create_tool_window( WS_POPUP, desktop );
350 trace( "created popup owned by desktop %p\n", test );
351 check_parents( test, desktop, 0, 0, 0, test, test );
352 DestroyWindow( test );
354 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
355 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
356 DestroyWindow( test );
358 /* popup owned by child (same as owned by top-level) */
359 test = create_tool_window( WS_POPUP, child );
360 trace( "created popup owned by child %p\n", test );
361 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
362 DestroyWindow( test );
364 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
365 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
366 DestroyWindow( test );
368 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
369 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
370 trace( "created WS_CHILD popup %p\n", test );
371 check_parents( test, desktop, 0, 0, 0, test, test );
372 DestroyWindow( test );
374 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
375 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
376 DestroyWindow( test );
378 /* owned popup with WS_CHILD (same as WS_POPUP only) */
379 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
380 trace( "created owned WS_CHILD popup %p\n", test );
381 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
382 DestroyWindow( test );
384 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
385 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
386 DestroyWindow( test );
388 /******************** parent changes *************************/
389 trace( "testing parent changes\n" );
391 /* desktop window */
392 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
393 if (0)
395 /* this test succeeds on NT but crashes on win9x systems */
396 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
397 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
398 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
399 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
400 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
402 /* normal child window */
403 test = create_tool_window( WS_CHILD, hwndMain );
404 trace( "created child %p\n", test );
406 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
407 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
408 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
410 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
411 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
412 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
414 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
415 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
416 check_parents( test, desktop, 0, desktop, 0, test, desktop );
418 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
419 if (!is_win9x)
421 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)test );
422 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
423 check_parents( test, desktop, 0, desktop, 0, test, desktop );
425 else
426 win_skip("Test creates circular window tree under Win9x/WinMe\n" );
428 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
429 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
430 check_parents( test, desktop, child, desktop, child, test, desktop );
432 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
433 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
434 check_parents( test, desktop, 0, desktop, 0, test, desktop );
435 DestroyWindow( test );
437 /* not owned top-level window */
438 test = create_tool_window( 0, 0 );
439 trace( "created top-level %p\n", test );
441 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
442 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
443 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
445 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
446 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
447 check_parents( test, desktop, child, 0, child, test, test );
449 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
450 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
451 check_parents( test, desktop, 0, 0, 0, test, test );
452 DestroyWindow( test );
454 /* not owned popup */
455 test = create_tool_window( WS_POPUP, 0 );
456 trace( "created popup %p\n", test );
458 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
459 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
460 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
462 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
463 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
464 check_parents( test, desktop, child, child, child, test, hwndMain );
466 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
467 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
468 check_parents( test, desktop, 0, 0, 0, test, test );
469 DestroyWindow( test );
471 /* normal child window */
472 test = create_tool_window( WS_CHILD, hwndMain );
473 trace( "created child %p\n", test );
475 ret = SetParent( test, desktop );
476 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
477 check_parents( test, desktop, 0, desktop, 0, test, desktop );
479 ret = SetParent( test, child );
480 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
481 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
483 ret = SetParent( test, hwndMain2 );
484 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
485 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
486 DestroyWindow( test );
488 /* not owned top-level window */
489 test = create_tool_window( 0, 0 );
490 trace( "created top-level %p\n", test );
492 ret = SetParent( test, child );
493 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
494 check_parents( test, child, child, 0, 0, hwndMain, test );
496 if (!is_win9x)
498 ShowWindow( test, SW_SHOW );
499 ret = SetParent( test, test );
500 ok( ret == NULL, "SetParent return value %p expected %p\n", ret, NULL );
501 ok( GetWindowLongA( test, GWL_STYLE ) & WS_VISIBLE, "window is not visible after SetParent\n" );
502 check_parents( test, child, child, 0, 0, hwndMain, test );
504 else
505 win_skip( "Test crashes on Win9x/WinMe\n" );
506 DestroyWindow( test );
508 /* owned popup */
509 test = create_tool_window( WS_POPUP, hwndMain2 );
510 trace( "created owned popup %p\n", test );
512 ret = SetParent( test, child );
513 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
514 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
516 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
517 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
518 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
519 DestroyWindow( test );
521 /**************** test owner destruction *******************/
523 /* owned child popup */
524 owner = create_tool_window( 0, 0 );
525 test = create_tool_window( WS_POPUP, owner );
526 trace( "created owner %p and popup %p\n", owner, test );
527 ret = SetParent( test, child );
528 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
529 check_parents( test, child, child, owner, owner, hwndMain, owner );
530 /* window is now child of 'child' but owned by 'owner' */
531 DestroyWindow( owner );
532 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
533 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
534 * while Win95, Win2k, WinXP do.
536 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
537 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
538 DestroyWindow(test);
540 /* owned top-level popup */
541 owner = create_tool_window( 0, 0 );
542 test = create_tool_window( WS_POPUP, owner );
543 trace( "created owner %p and popup %p\n", owner, test );
544 check_parents( test, desktop, owner, owner, owner, test, owner );
545 DestroyWindow( owner );
546 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
548 /* top-level popup owned by child */
549 owner = create_tool_window( WS_CHILD, hwndMain2 );
550 test = create_tool_window( WS_POPUP, 0 );
551 trace( "created owner %p and popup %p\n", owner, test );
552 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
553 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
554 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
555 DestroyWindow( owner );
556 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
557 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
558 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
559 * while Win95, Win2k, WinXP do.
561 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
562 DestroyWindow(test);
564 /* final cleanup */
565 DestroyWindow(child);
568 owner = create_tool_window( WS_OVERLAPPED, 0 );
569 test = create_tool_window( WS_POPUP, desktop );
571 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
572 numChildren = 0;
573 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
574 "EnumChildWindows should have returned FALSE\n" );
575 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
577 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
578 ret = SetParent( test, owner );
579 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
581 numChildren = 0;
582 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
583 "EnumChildWindows should have returned TRUE\n" );
584 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
586 child = create_tool_window( WS_CHILD, owner );
587 numChildren = 0;
588 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
589 "EnumChildWindows should have returned FALSE\n" );
590 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
591 DestroyWindow( child );
593 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
594 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
595 numChildren = 0;
596 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
597 "EnumChildWindows should have returned TRUE\n" );
598 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
600 ret = SetParent( child, owner );
601 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
602 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
603 numChildren = 0;
604 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
605 "EnumChildWindows should have returned FALSE\n" );
606 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
608 ret = SetParent( child, NULL );
609 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
610 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
611 numChildren = 0;
612 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
613 "EnumChildWindows should have returned TRUE\n" );
614 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
616 /* even GW_OWNER == owner it's still a desktop's child */
617 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
618 "EnumChildWindows should have found %p and returned FALSE\n", child );
620 DestroyWindow( child );
621 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
623 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
624 "EnumChildWindows should have found %p and returned FALSE\n", child );
626 DestroyWindow( child );
627 DestroyWindow( test );
628 DestroyWindow( owner );
631 static BOOL CALLBACK enum_proc( HWND hwnd, LPARAM lParam)
633 (*(LPINT)lParam)++;
634 if (*(LPINT)lParam > 2) return FALSE;
635 return TRUE;
637 static DWORD CALLBACK enum_thread( void *arg )
639 INT count;
640 HWND hwnd[3];
641 BOOL ret;
642 MSG msg;
644 if (pGetGUIThreadInfo)
646 GUITHREADINFO info;
647 info.cbSize = sizeof(info);
648 ret = pGetGUIThreadInfo( GetCurrentThreadId(), &info );
649 ok( ret || broken(!ret), /* win9x */
650 "GetGUIThreadInfo failed without message queue\n" );
651 SetLastError( 0xdeadbeef );
652 info.cbSize = sizeof(info) + 1;
653 ret = pGetGUIThreadInfo( GetCurrentThreadId(), &info );
654 ok( !ret, "GetGUIThreadInfo succeeded with wrong size\n" );
655 ok( GetLastError() == ERROR_INVALID_PARAMETER ||
656 broken(GetLastError() == 0xdeadbeef), /* win9x */
657 "wrong error %u\n", GetLastError() );
660 PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ); /* make sure we have a message queue */
662 count = 0;
663 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
664 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
665 ok( count == 0, "count should be 0 got %d\n", count );
667 hwnd[0] = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", WS_POPUP,
668 0, 0, 100, 100, 0, 0, 0, NULL );
669 count = 0;
670 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
671 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
672 if (count != 2) /* Vista gives us two windows for the price of one */
674 ok( count == 1, "count should be 1 got %d\n", count );
675 hwnd[2] = CreateWindowExA(0, "ToolWindowClass", "Tool window 2", WS_POPUP,
676 0, 0, 100, 100, 0, 0, 0, NULL );
678 else hwnd[2] = 0;
680 hwnd[1] = CreateWindowExA(0, "ToolWindowClass", "Tool window 3", WS_POPUP,
681 0, 0, 100, 100, 0, 0, 0, NULL );
682 count = 0;
683 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
684 ok( !ret, "EnumThreadWindows should have returned FALSE\n" );
685 ok( count == 3, "count should be 3 got %d\n", count );
687 if (hwnd[2]) DestroyWindow(hwnd[2]);
688 DestroyWindow(hwnd[1]);
689 DestroyWindow(hwnd[0]);
690 return 0;
693 /* test EnumThreadWindows in a separate thread */
694 static void test_enum_thread_windows(void)
696 DWORD id;
697 HANDLE handle = CreateThread( NULL, 0, enum_thread, 0, 0, &id );
698 ok( !WaitForSingleObject( handle, 10000 ), "wait failed\n" );
699 CloseHandle( handle );
702 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
704 switch (msg)
706 case WM_GETMINMAXINFO:
708 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
710 trace("WM_GETMINMAXINFO: hwnd %p, %08lx, %08lx\n", hwnd, wparam, lparam);
711 dump_minmax_info( minmax );
712 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
713 break;
715 case WM_WINDOWPOSCHANGING:
717 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
718 trace("main: WM_WINDOWPOSCHANGING %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
719 winpos->hwnd, winpos->hwndInsertAfter,
720 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
721 if (!(winpos->flags & SWP_NOMOVE))
723 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
724 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
726 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
727 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
729 ok((winpos->cx >= 0 && winpos->cx <= 32767) ||
730 winpos->cx == 32768, /* win7 doesn't truncate */
731 "bad winpos->cx %d\n", winpos->cx);
732 ok((winpos->cy >= 0 && winpos->cy <= 32767) ||
733 winpos->cy == 40000, /* win7 doesn't truncate */
734 "bad winpos->cy %d\n", winpos->cy);
736 break;
738 case WM_WINDOWPOSCHANGED:
740 RECT rc1, rc2;
741 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
742 trace("main: WM_WINDOWPOSCHANGED %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
743 winpos->hwnd, winpos->hwndInsertAfter,
744 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
745 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
746 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
748 ok((winpos->cx >= 0 && winpos->cx <= 32767) ||
749 winpos->cx == 32768, /* win7 doesn't truncate */
750 "bad winpos->cx %d\n", winpos->cx);
751 ok((winpos->cy >= 0 && winpos->cy <= 32767) ||
752 winpos->cy == 40000, /* win7 doesn't truncate */
753 "bad winpos->cy %d\n", winpos->cy);
755 GetWindowRect(hwnd, &rc1);
756 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
757 /* note: winpos coordinates are relative to parent */
758 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
759 if (0)
761 /* Uncomment this once the test succeeds in all cases */
762 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
763 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
765 GetClientRect(hwnd, &rc2);
766 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
767 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
768 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
769 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
771 break;
773 case WM_NCCREATE:
775 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
776 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
778 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
779 if (got_getminmaxinfo)
780 trace("%p got WM_GETMINMAXINFO\n", hwnd);
782 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
783 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
784 else
785 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
786 break;
788 case WM_COMMAND:
789 if (test_lbuttondown_flag)
791 ShowWindow((HWND)wparam, SW_SHOW);
792 flush_events( FALSE );
794 break;
797 return DefWindowProcA(hwnd, msg, wparam, lparam);
800 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
802 switch (msg)
804 case WM_GETMINMAXINFO:
806 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
808 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
809 dump_minmax_info( minmax );
810 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
811 break;
813 case WM_NCCREATE:
815 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
816 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
818 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
819 if (got_getminmaxinfo)
820 trace("%p got WM_GETMINMAXINFO\n", hwnd);
822 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
823 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
824 else
825 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
826 break;
830 return DefWindowProcA(hwnd, msg, wparam, lparam);
833 static BOOL RegisterWindowClasses(void)
835 WNDCLASSA cls;
837 cls.style = CS_DBLCLKS;
838 cls.lpfnWndProc = main_window_procA;
839 cls.cbClsExtra = 0;
840 cls.cbWndExtra = 0;
841 cls.hInstance = GetModuleHandleA(0);
842 cls.hIcon = 0;
843 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
844 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
845 cls.lpszMenuName = NULL;
846 cls.lpszClassName = "MainWindowClass";
848 if(!RegisterClassA(&cls)) return FALSE;
850 cls.style = 0;
851 cls.lpfnWndProc = tool_window_procA;
852 cls.cbClsExtra = 0;
853 cls.cbWndExtra = 0;
854 cls.hInstance = GetModuleHandleA(0);
855 cls.hIcon = 0;
856 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
857 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
858 cls.lpszMenuName = NULL;
859 cls.lpszClassName = "ToolWindowClass";
861 if(!RegisterClassA(&cls)) return FALSE;
863 return TRUE;
866 static void verify_window_info(const char *hook, HWND hwnd, const WINDOWINFO *info)
868 RECT rcWindow, rcClient;
869 DWORD status;
871 ok(IsWindow(hwnd), "bad window handle %p in hook %s\n", hwnd, hook);
873 GetWindowRect(hwnd, &rcWindow);
874 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow for %p in hook %s\n", hwnd, hook);
876 GetClientRect(hwnd, &rcClient);
877 /* translate to screen coordinates */
878 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
879 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient for %p in hook %s\n", hwnd, hook);
881 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
882 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
883 info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE), hwnd, hook);
884 /* Windows reports some undocumented exstyles in WINDOWINFO, but
885 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
887 ok((info->dwExStyle & ~0xe0000800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
888 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
889 info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE), hwnd, hook);
890 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
891 if (GetForegroundWindow())
892 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
893 info->dwWindowStatus, status, GetActiveWindow(), GetForegroundWindow(), hook);
895 /* win2k and XP return broken border info in GetWindowInfo most of
896 * the time, so there is no point in testing it.
898 if (0)
900 UINT border;
901 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
902 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
903 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
904 ok(info->cyWindowBorders == border,
905 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
907 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType for %p in hook %s\n",
908 hwnd, hook);
909 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
910 info->wCreatorVersion == 0x0500 /* Vista */,
911 "wrong wCreatorVersion %04x for %p in hook %s\n", info->wCreatorVersion, hwnd, hook);
914 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
916 AdjustWindowRectEx(rc, style, menu, exstyle);
917 /* AdjustWindowRectEx does not include scroll bars */
918 if (style & WS_VSCROLL)
920 if(exstyle & WS_EX_LEFTSCROLLBAR)
921 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
922 else
923 rc->right += GetSystemMetrics(SM_CXVSCROLL);
925 if (style & WS_HSCROLL)
926 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
929 static void test_nonclient_area(HWND hwnd)
931 DWORD style, exstyle;
932 RECT rc_window, rc_client, rc;
933 BOOL menu;
934 LRESULT ret;
936 style = GetWindowLongA(hwnd, GWL_STYLE);
937 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
938 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
940 GetWindowRect(hwnd, &rc_window);
941 GetClientRect(hwnd, &rc_client);
943 /* avoid some cases when things go wrong */
944 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
945 rc_window.right > 32768 || rc_window.bottom > 32768) return;
947 CopyRect(&rc, &rc_client);
948 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
949 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
951 ok(EqualRect(&rc, &rc_window),
952 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
953 style, exstyle, menu, rc_window.left, rc_window.top, rc_window.right, rc_window.bottom,
954 rc.left, rc.top, rc.right, rc.bottom);
957 CopyRect(&rc, &rc_window);
958 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
959 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
960 ok(EqualRect(&rc, &rc_client),
961 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
962 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
963 rc.left, rc.top, rc.right, rc.bottom);
965 /* NULL rectangle shouldn't crash */
966 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
967 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
969 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
970 if (is_win9x)
971 return;
973 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
974 SetRect(&rc_client, 0, 0, 250, 150);
975 CopyRect(&rc_window, &rc_client);
976 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
977 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
979 CopyRect(&rc, &rc_window);
980 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
981 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
982 ok(EqualRect(&rc, &rc_client),
983 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
984 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
985 rc.left, rc.top, rc.right, rc.bottom);
988 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
990 static const char *CBT_code_name[10] = {
991 "HCBT_MOVESIZE",
992 "HCBT_MINMAX",
993 "HCBT_QS",
994 "HCBT_CREATEWND",
995 "HCBT_DESTROYWND",
996 "HCBT_ACTIVATE",
997 "HCBT_CLICKSKIPPED",
998 "HCBT_KEYSKIPPED",
999 "HCBT_SYSCOMMAND",
1000 "HCBT_SETFOCUS" };
1001 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
1002 HWND hwnd = (HWND)wParam;
1004 switch (nCode)
1006 case HCBT_CREATEWND:
1008 static const RECT rc_null;
1009 RECT rc;
1010 LONG style;
1011 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
1012 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
1014 if (pGetWindowInfo)
1016 WINDOWINFO info;
1017 info.cbSize = sizeof(WINDOWINFO);
1018 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
1019 verify_window_info(code_name, hwnd, &info);
1022 /* WS_VISIBLE should be turned off yet */
1023 style = createwnd->lpcs->style & ~WS_VISIBLE;
1024 ok(style == GetWindowLongA(hwnd, GWL_STYLE),
1025 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
1026 GetWindowLongA(hwnd, GWL_STYLE), style);
1028 if (0)
1030 /* Uncomment this once the test succeeds in all cases */
1031 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
1033 ok(GetParent(hwnd) == hwndMessage,
1034 "wrong result from GetParent %p: message window %p\n",
1035 GetParent(hwnd), hwndMessage);
1037 else
1038 ok(!GetParent(hwnd), "GetParent should return 0 at this point\n");
1040 ok(!GetWindow(hwnd, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
1042 if (0)
1044 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
1045 * Win9x still has them set to 0.
1047 ok(GetWindow(hwnd, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
1048 ok(GetWindow(hwnd, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
1050 ok(!GetWindow(hwnd, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
1051 ok(!GetWindow(hwnd, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
1053 if (0)
1055 /* Uncomment this once the test succeeds in all cases */
1056 if (pGetAncestor)
1058 ok(pGetAncestor(hwnd, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
1059 ok(pGetAncestor(hwnd, GA_ROOT) == hwnd,
1060 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOT), hwnd);
1062 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
1063 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwndMessage,
1064 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
1065 else
1066 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwnd,
1067 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOTOWNER), hwnd);
1070 ok(GetWindowRect(hwnd, &rc), "GetWindowRect failed\n");
1071 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
1072 ok(GetClientRect(hwnd, &rc), "GetClientRect failed\n");
1073 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
1075 break;
1077 case HCBT_MOVESIZE:
1078 case HCBT_MINMAX:
1079 case HCBT_ACTIVATE:
1080 if (pGetWindowInfo && IsWindow(hwnd))
1082 WINDOWINFO info;
1084 /* Win98 actually does check the info.cbSize and doesn't allow
1085 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
1086 * WinXP do not check it at all.
1088 info.cbSize = sizeof(WINDOWINFO);
1089 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
1090 verify_window_info(code_name, hwnd, &info);
1092 break;
1093 /* window state is undefined */
1094 case HCBT_SETFOCUS:
1095 case HCBT_DESTROYWND:
1096 break;
1097 default:
1098 break;
1101 return CallNextHookEx(hhook, nCode, wParam, lParam);
1104 static void test_shell_window(void)
1106 BOOL ret;
1107 DWORD error;
1108 HMODULE hinst, hUser32;
1109 BOOL (WINAPI*SetShellWindow)(HWND);
1110 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
1111 HWND shellWindow, nextWnd;
1113 if (is_win9x)
1115 win_skip("Skipping shell window test on Win9x\n");
1116 return;
1119 shellWindow = GetShellWindow();
1120 hinst = GetModuleHandleA(NULL);
1121 hUser32 = GetModuleHandleA("user32");
1123 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
1125 trace("previous shell window: %p\n", shellWindow);
1127 if (shellWindow) {
1128 DWORD pid;
1129 HANDLE hProcess;
1131 GetWindowThreadProcessId(shellWindow, &pid);
1132 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
1133 if (!hProcess)
1135 skip( "cannot get access to shell process\n" );
1136 return;
1139 SetLastError(0xdeadbeef);
1140 ret = DestroyWindow(shellWindow);
1141 error = GetLastError();
1143 ok(!ret, "DestroyWindow(shellWindow)\n");
1144 /* passes on Win XP, but not on Win98 */
1145 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
1146 "got %u after DestroyWindow(shellWindow)\n", error);
1148 /* close old shell instance */
1149 ret = TerminateProcess(hProcess, 0);
1150 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1151 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
1152 CloseHandle(hProcess);
1155 hwnd1 = CreateWindowExA(0, "#32770", "TEST1", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
1156 trace("created window 1: %p\n", hwnd1);
1158 ret = SetShellWindow(hwnd1);
1159 ok(ret, "first call to SetShellWindow(hwnd1)\n");
1160 shellWindow = GetShellWindow();
1161 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
1163 ret = SetShellWindow(hwnd1);
1164 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1166 ret = SetShellWindow(0);
1167 error = GetLastError();
1168 /* passes on Win XP, but not on Win98
1169 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1170 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1172 ret = SetShellWindow(hwnd1);
1173 /* passes on Win XP, but not on Win98
1174 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1176 SetWindowLongA(hwnd1, GWL_EXSTYLE, GetWindowLongA(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1177 ret = (GetWindowLongA(hwnd1,GWL_EXSTYLE) & WS_EX_TOPMOST) != 0;
1178 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1180 ret = DestroyWindow(hwnd1);
1181 ok(ret, "DestroyWindow(hwnd1)\n");
1183 hwnd2 = CreateWindowExA(WS_EX_TOPMOST, "#32770", "TEST2", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1184 trace("created window 2: %p\n", hwnd2);
1185 ret = SetShellWindow(hwnd2);
1186 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1188 hwnd3 = CreateWindowExA(0, "#32770", "TEST3", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1189 trace("created window 3: %p\n", hwnd3);
1191 hwnd4 = CreateWindowExA(0, "#32770", "TEST4", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1192 trace("created window 4: %p\n", hwnd4);
1194 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1195 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1197 ret = SetShellWindow(hwnd4);
1198 ok(ret, "SetShellWindow(hwnd4)\n");
1199 shellWindow = GetShellWindow();
1200 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1202 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1203 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1205 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1206 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1208 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1209 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1211 ret = SetShellWindow(hwnd3);
1212 ok(!ret, "SetShellWindow(hwnd3)\n");
1213 shellWindow = GetShellWindow();
1214 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1216 hwnd5 = CreateWindowExA(0, "#32770", "TEST5", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1217 trace("created window 5: %p\n", hwnd5);
1218 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1219 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1221 todo_wine
1223 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1224 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1227 /* destroy test windows */
1228 DestroyWindow(hwnd2);
1229 DestroyWindow(hwnd3);
1230 DestroyWindow(hwnd4);
1231 DestroyWindow(hwnd5);
1234 /************** MDI test ****************/
1236 static char mdi_lParam_test_message[] = "just a test string";
1238 static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
1240 MDICREATESTRUCTA mdi_cs;
1241 HWND mdi_child;
1242 INT_PTR id;
1243 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1244 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1245 BOOL isWin9x = FALSE;
1247 mdi_cs.szClass = "MDI_child_Class_1";
1248 mdi_cs.szTitle = "MDI child";
1249 mdi_cs.hOwner = GetModuleHandleA(NULL);
1250 mdi_cs.x = CW_USEDEFAULT;
1251 mdi_cs.y = CW_USEDEFAULT;
1252 mdi_cs.cx = CW_USEDEFAULT;
1253 mdi_cs.cy = CW_USEDEFAULT;
1254 mdi_cs.style = 0;
1255 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1256 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
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_cs.style = 0x7fffffff; /* without WS_POPUP */
1264 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1265 ok(mdi_child != 0, "MDI child creation failed\n");
1266 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1267 ok(id == first_id, "wrong child id %ld\n", id);
1268 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1269 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1271 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1272 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1273 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1275 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1277 else
1279 ok(mdi_child != 0, "MDI child creation failed\n");
1280 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1281 ok(id == first_id, "wrong child id %ld\n", id);
1282 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1283 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1286 /* test MDICREATESTRUCT A<->W mapping */
1287 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1288 mdi_cs.style = 0;
1289 mdi_cs.szClass = (LPCSTR)classW;
1290 mdi_cs.szTitle = (LPCSTR)titleW;
1291 SetLastError(0xdeadbeef);
1292 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1293 if (!mdi_child)
1295 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1296 isWin9x = TRUE;
1297 else
1298 ok(mdi_child != 0, "MDI child creation failed\n");
1300 else
1302 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1303 ok(id == first_id, "wrong child id %ld\n", id);
1304 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1305 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1308 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1310 CW_USEDEFAULT, CW_USEDEFAULT,
1311 CW_USEDEFAULT, CW_USEDEFAULT,
1312 mdi_client, GetModuleHandleA(NULL),
1313 (LPARAM)mdi_lParam_test_message);
1314 ok(mdi_child != 0, "MDI child creation failed\n");
1315 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1316 ok(id == first_id, "wrong child id %ld\n", id);
1317 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1318 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1320 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1321 0x7fffffff, /* without WS_POPUP */
1322 CW_USEDEFAULT, CW_USEDEFAULT,
1323 CW_USEDEFAULT, CW_USEDEFAULT,
1324 mdi_client, GetModuleHandleA(NULL),
1325 (LPARAM)mdi_lParam_test_message);
1326 ok(mdi_child != 0, "MDI child creation failed\n");
1327 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1328 ok(id == first_id, "wrong child id %ld\n", id);
1329 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1330 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1332 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1333 0xffffffff, /* with WS_POPUP */
1334 CW_USEDEFAULT, CW_USEDEFAULT,
1335 CW_USEDEFAULT, CW_USEDEFAULT,
1336 mdi_client, GetModuleHandleA(NULL),
1337 (LPARAM)mdi_lParam_test_message);
1338 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1340 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1342 else
1344 ok(mdi_child != 0, "MDI child creation failed\n");
1345 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1346 ok(id == first_id, "wrong child id %ld\n", id);
1347 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1348 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1351 /* test MDICREATESTRUCT A<->W mapping */
1352 SetLastError(0xdeadbeef);
1353 mdi_child = CreateMDIWindowW(classW, titleW,
1355 CW_USEDEFAULT, CW_USEDEFAULT,
1356 CW_USEDEFAULT, CW_USEDEFAULT,
1357 mdi_client, GetModuleHandleA(NULL),
1358 (LPARAM)mdi_lParam_test_message);
1359 if (!mdi_child)
1361 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1362 isWin9x = TRUE;
1363 else
1364 ok(mdi_child != 0, "MDI child creation failed\n");
1366 else
1368 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1369 ok(id == first_id, "wrong child id %ld\n", id);
1370 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1371 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1374 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1376 CW_USEDEFAULT, CW_USEDEFAULT,
1377 CW_USEDEFAULT, CW_USEDEFAULT,
1378 mdi_client, 0, GetModuleHandleA(NULL),
1379 mdi_lParam_test_message);
1380 ok(mdi_child != 0, "MDI child creation failed\n");
1381 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1382 ok(id == first_id, "wrong child id %ld\n", id);
1383 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1384 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1386 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1387 0x7fffffff, /* without WS_POPUP */
1388 CW_USEDEFAULT, CW_USEDEFAULT,
1389 CW_USEDEFAULT, CW_USEDEFAULT,
1390 mdi_client, 0, GetModuleHandleA(NULL),
1391 mdi_lParam_test_message);
1392 ok(mdi_child != 0, "MDI child creation failed\n");
1393 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1394 ok(id == first_id, "wrong child id %ld\n", id);
1395 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1396 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1398 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1399 0xffffffff, /* with WS_POPUP */
1400 CW_USEDEFAULT, CW_USEDEFAULT,
1401 CW_USEDEFAULT, CW_USEDEFAULT,
1402 mdi_client, 0, GetModuleHandleA(NULL),
1403 mdi_lParam_test_message);
1404 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1406 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1408 else
1410 ok(mdi_child != 0, "MDI child creation failed\n");
1411 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1412 ok(id == first_id, "wrong child id %ld\n", id);
1413 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1414 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1417 /* test MDICREATESTRUCT A<->W mapping */
1418 SetLastError(0xdeadbeef);
1419 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1421 CW_USEDEFAULT, CW_USEDEFAULT,
1422 CW_USEDEFAULT, CW_USEDEFAULT,
1423 mdi_client, 0, GetModuleHandleA(NULL),
1424 mdi_lParam_test_message);
1425 if (!mdi_child)
1427 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1428 isWin9x = TRUE;
1429 else
1430 ok(mdi_child != 0, "MDI child creation failed\n");
1432 else
1434 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1435 ok(id == first_id, "wrong child id %ld\n", id);
1436 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1437 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1440 /* This test fails on Win9x */
1441 if (!isWin9x)
1443 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1444 WS_CHILD,
1445 CW_USEDEFAULT, CW_USEDEFAULT,
1446 CW_USEDEFAULT, CW_USEDEFAULT,
1447 parent, 0, GetModuleHandleA(NULL),
1448 mdi_lParam_test_message);
1449 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1452 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1453 WS_CHILD, /* without WS_POPUP */
1454 CW_USEDEFAULT, CW_USEDEFAULT,
1455 CW_USEDEFAULT, CW_USEDEFAULT,
1456 mdi_client, 0, GetModuleHandleA(NULL),
1457 mdi_lParam_test_message);
1458 ok(mdi_child != 0, "MDI child creation failed\n");
1459 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1460 ok(id == 0, "wrong child id %ld\n", id);
1461 DestroyWindow(mdi_child);
1463 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1464 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1465 CW_USEDEFAULT, CW_USEDEFAULT,
1466 CW_USEDEFAULT, CW_USEDEFAULT,
1467 mdi_client, 0, GetModuleHandleA(NULL),
1468 mdi_lParam_test_message);
1469 ok(mdi_child != 0, "MDI child creation failed\n");
1470 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1471 ok(id == 0, "wrong child id %ld\n", id);
1472 DestroyWindow(mdi_child);
1474 /* maximized child */
1475 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1476 WS_CHILD | WS_MAXIMIZE,
1477 CW_USEDEFAULT, CW_USEDEFAULT,
1478 CW_USEDEFAULT, CW_USEDEFAULT,
1479 mdi_client, 0, GetModuleHandleA(NULL),
1480 mdi_lParam_test_message);
1481 ok(mdi_child != 0, "MDI child creation failed\n");
1482 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1483 ok(id == 0, "wrong child id %ld\n", id);
1484 DestroyWindow(mdi_child);
1486 trace("Creating maximized child with a caption\n");
1487 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1488 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1489 CW_USEDEFAULT, CW_USEDEFAULT,
1490 CW_USEDEFAULT, CW_USEDEFAULT,
1491 mdi_client, 0, GetModuleHandleA(NULL),
1492 mdi_lParam_test_message);
1493 ok(mdi_child != 0, "MDI child creation failed\n");
1494 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1495 ok(id == 0, "wrong child id %ld\n", id);
1496 DestroyWindow(mdi_child);
1498 trace("Creating maximized child with a caption and a thick frame\n");
1499 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1500 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1501 CW_USEDEFAULT, CW_USEDEFAULT,
1502 CW_USEDEFAULT, CW_USEDEFAULT,
1503 mdi_client, 0, GetModuleHandleA(NULL),
1504 mdi_lParam_test_message);
1505 ok(mdi_child != 0, "MDI child creation failed\n");
1506 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1507 ok(id == 0, "wrong child id %ld\n", id);
1508 DestroyWindow(mdi_child);
1511 static void test_MDI_child_stack(HWND mdi_client)
1513 HWND child_1, child_2, child_3, child_4;
1514 HWND stack[4];
1515 MDICREATESTRUCTA cs;
1517 cs.szClass = "MDI_child_Class_1";
1518 cs.szTitle = "MDI child";
1519 cs.hOwner = GetModuleHandleA(0);
1520 cs.x = CW_USEDEFAULT;
1521 cs.y = CW_USEDEFAULT;
1522 cs.cx = CW_USEDEFAULT;
1523 cs.cy = CW_USEDEFAULT;
1524 cs.style = 0;
1525 cs.lParam = (LPARAM)mdi_lParam_test_message;
1527 child_1 = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&cs);
1528 ok(child_1 != 0, "expected child_1 to be non NULL\n");
1529 child_2 = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&cs);
1530 ok(child_2 != 0, "expected child_2 to be non NULL\n");
1531 child_3 = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&cs);
1532 ok(child_3 != 0, "expected child_3 to be non NULL\n");
1533 child_4 = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&cs);
1534 ok(child_4 != 0, "expected child_4 to be non NULL\n");
1536 stack[0] = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1537 stack[1] = GetWindow(stack[0], GW_HWNDNEXT);
1538 stack[2] = GetWindow(stack[1], GW_HWNDNEXT);
1539 stack[3] = GetWindow(stack[2], GW_HWNDNEXT);
1540 trace("Initial MDI child stack: %p->%p->%p->%p\n", stack[0], stack[1], stack[2], stack[3]);
1541 ok(stack[0] == child_4 && stack[1] == child_3 &&
1542 stack[2] == child_2 && stack[3] == child_1,
1543 "Unexpected initial order, should be: %p->%p->%p->%p\n",
1544 child_4, child_3, child_2, child_1);
1546 trace("Activate child next to %p\n", child_3);
1547 SendMessageA(mdi_client, WM_MDINEXT, (WPARAM)child_3, 0);
1549 stack[0] = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1550 stack[1] = GetWindow(stack[0], GW_HWNDNEXT);
1551 stack[2] = GetWindow(stack[1], GW_HWNDNEXT);
1552 stack[3] = GetWindow(stack[2], GW_HWNDNEXT);
1553 ok(stack[0] == child_2 && stack[1] == child_4 &&
1554 stack[2] == child_1 && stack[3] == child_3,
1555 "Broken MDI child stack:\nexpected: %p->%p->%p->%p, but got: %p->%p->%p->%p\n",
1556 child_2, child_4, child_1, child_3, stack[0], stack[1], stack[2], stack[3]);
1558 trace("Activate child previous to %p\n", child_1);
1559 SendMessageA(mdi_client, WM_MDINEXT, (WPARAM)child_1, 1);
1561 stack[0] = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1562 stack[1] = GetWindow(stack[0], GW_HWNDNEXT);
1563 stack[2] = GetWindow(stack[1], GW_HWNDNEXT);
1564 stack[3] = GetWindow(stack[2], GW_HWNDNEXT);
1565 ok(stack[0] == child_4 && stack[1] == child_2 &&
1566 stack[2] == child_1 && stack[3] == child_3,
1567 "Broken MDI child stack:\nexpected: %p->%p->%p->%p, but got: %p->%p->%p->%p\n",
1568 child_4, child_2, child_1, child_3, stack[0], stack[1], stack[2], stack[3]);
1570 DestroyWindow(child_1);
1571 DestroyWindow(child_2);
1572 DestroyWindow(child_3);
1573 DestroyWindow(child_4);
1576 /**********************************************************************
1577 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1579 * Note: The rule here is that client rect of the maximized MDI child
1580 * is equal to the client rect of the MDI client window.
1582 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1584 RECT rect;
1586 GetClientRect( client, &rect );
1587 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1588 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1590 rect.right -= rect.left;
1591 rect.bottom -= rect.top;
1592 lpMinMax->ptMaxSize.x = rect.right;
1593 lpMinMax->ptMaxSize.y = rect.bottom;
1595 lpMinMax->ptMaxPosition.x = rect.left;
1596 lpMinMax->ptMaxPosition.y = rect.top;
1598 trace("max rect (%d,%d - %d, %d)\n",
1599 rect.left, rect.top, rect.right, rect.bottom);
1602 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1604 switch (msg)
1606 case WM_NCCREATE:
1607 case WM_CREATE:
1609 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1610 MDICREATESTRUCTA *mdi_cs = cs->lpCreateParams;
1612 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1613 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1615 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1616 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1617 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1618 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1619 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1621 /* MDICREATESTRUCT should have original values */
1622 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1623 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1624 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1625 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1626 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1627 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1629 /* CREATESTRUCT should have fixed values */
1630 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1631 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1633 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1634 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1635 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1637 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1639 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1641 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1642 ok(cs->style == style,
1643 "cs->style does not match (%08x)\n", cs->style);
1645 else
1647 LONG style = mdi_cs->style;
1648 style &= ~WS_POPUP;
1649 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1650 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1651 ok(cs->style == style,
1652 "cs->style does not match (%08x)\n", cs->style);
1654 break;
1657 case WM_GETMINMAXINFO:
1659 HWND client = GetParent(hwnd);
1660 RECT rc;
1661 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1662 MINMAXINFO my_minmax;
1663 LONG style, exstyle;
1665 style = GetWindowLongA(hwnd, GWL_STYLE);
1666 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1668 GetWindowRect(client, &rc);
1669 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1670 GetClientRect(client, &rc);
1671 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1672 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1673 GetSystemMetrics(SM_CYSCREEN));
1675 GetClientRect(client, &rc);
1676 if ((style & WS_CAPTION) == WS_CAPTION)
1677 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1678 AdjustWindowRectEx(&rc, style, 0, exstyle);
1679 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1680 dump_minmax_info( minmax );
1682 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1683 minmax->ptMaxSize.x, rc.right - rc.left);
1684 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1685 minmax->ptMaxSize.y, rc.bottom - rc.top);
1687 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1689 trace("DefMDIChildProc returned:\n");
1690 dump_minmax_info( minmax );
1692 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1693 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1694 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1695 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1696 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1698 return 1;
1701 case WM_MDIACTIVATE:
1703 HWND active, client = GetParent(hwnd);
1704 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1705 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1706 if (hwnd == (HWND)lparam) /* if we are being activated */
1707 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1708 else
1709 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1710 break;
1713 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1716 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1718 switch (msg)
1720 case WM_NCCREATE:
1721 case WM_CREATE:
1723 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1725 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE",
1726 cs->x, cs->y, cs->cx, cs->cy);
1728 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1729 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1731 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1732 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1734 /* CREATESTRUCT should have fixed values */
1735 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1736 while NT does. */
1737 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1738 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1740 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1741 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1742 while Win95, Win2k, WinXP do. */
1743 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1744 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1745 break;
1748 case WM_GETMINMAXINFO:
1750 HWND parent = GetParent(hwnd);
1751 RECT rc;
1752 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1753 LONG style, exstyle;
1755 style = GetWindowLongA(hwnd, GWL_STYLE);
1756 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1758 GetClientRect(parent, &rc);
1759 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1761 GetClientRect(parent, &rc);
1762 if ((style & WS_CAPTION) == WS_CAPTION)
1763 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1764 AdjustWindowRectEx(&rc, style, 0, exstyle);
1765 dump_minmax_info( minmax );
1767 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1768 minmax->ptMaxSize.x, rc.right - rc.left);
1769 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1770 minmax->ptMaxSize.y, rc.bottom - rc.top);
1771 break;
1774 case WM_WINDOWPOSCHANGED:
1776 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1777 RECT rc1, rc2;
1779 GetWindowRect(hwnd, &rc1);
1780 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1781 /* note: winpos coordinates are relative to parent */
1782 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1783 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) pos=(%d,%d)-(%d,%d)\n",
1784 rc1.left, rc1.top, rc1.right, rc1.bottom,
1785 rc2.left, rc2.top, rc2.right, rc2.bottom);
1786 GetWindowRect(hwnd, &rc1);
1787 GetClientRect(hwnd, &rc2);
1788 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1789 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1790 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1791 rc1.left, rc1.top, rc1.right, rc1.bottom,
1792 rc2.left, rc2.top, rc2.right, rc2.bottom);
1794 /* fall through */
1795 case WM_WINDOWPOSCHANGING:
1797 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1798 WINDOWPOS my_winpos = *winpos;
1800 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1801 (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
1802 winpos->hwnd, winpos->hwndInsertAfter,
1803 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1805 DefWindowProcA(hwnd, msg, wparam, lparam);
1807 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1808 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1809 winpos->hwnd, winpos->hwndInsertAfter,
1810 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1812 return 1;
1815 return DefWindowProcA(hwnd, msg, wparam, lparam);
1818 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1820 static HWND mdi_client;
1822 switch (msg)
1824 case WM_CREATE:
1826 CLIENTCREATESTRUCT client_cs;
1827 RECT rc;
1829 GetClientRect(hwnd, &rc);
1831 client_cs.hWindowMenu = 0;
1832 client_cs.idFirstChild = 1;
1834 /* MDIClient without MDIS_ALLCHILDSTYLES */
1835 mdi_client = CreateWindowExA(0, "mdiclient",
1836 NULL,
1837 WS_CHILD /*| WS_VISIBLE*/,
1838 /* tests depend on a not zero MDIClient size */
1839 0, 0, rc.right, rc.bottom,
1840 hwnd, 0, GetModuleHandleA(NULL),
1841 &client_cs);
1842 assert(mdi_client);
1843 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1844 DestroyWindow(mdi_client);
1846 /* MDIClient with MDIS_ALLCHILDSTYLES */
1847 mdi_client = CreateWindowExA(0, "mdiclient",
1848 NULL,
1849 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1850 /* tests depend on a not zero MDIClient size */
1851 0, 0, rc.right, rc.bottom,
1852 hwnd, 0, GetModuleHandleA(NULL),
1853 &client_cs);
1854 assert(mdi_client);
1855 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1856 DestroyWindow(mdi_client);
1858 /* Test child window stack management */
1859 mdi_client = CreateWindowExA(0, "mdiclient",
1860 NULL,
1861 WS_CHILD,
1862 0, 0, rc.right, rc.bottom,
1863 hwnd, 0, GetModuleHandleA(NULL),
1864 &client_cs);
1865 assert(mdi_client);
1866 test_MDI_child_stack(mdi_client);
1867 DestroyWindow(mdi_client);
1868 break;
1871 case WM_WINDOWPOSCHANGED:
1873 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1874 RECT rc1, rc2;
1876 GetWindowRect(hwnd, &rc1);
1877 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1878 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1879 /* note: winpos coordinates are relative to parent */
1880 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1881 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1882 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1884 GetWindowRect(hwnd, &rc1);
1885 GetClientRect(hwnd, &rc2);
1886 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1887 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1888 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1890 /* fall through */
1891 case WM_WINDOWPOSCHANGING:
1893 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1894 WINDOWPOS my_winpos = *winpos;
1896 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1897 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1898 winpos->hwnd, winpos->hwndInsertAfter,
1899 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1901 DefWindowProcA(hwnd, msg, wparam, lparam);
1903 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1904 winpos->hwnd, winpos->hwndInsertAfter,
1905 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1907 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1908 "DefWindowProc should not change WINDOWPOS values\n");
1910 return 1;
1913 case WM_CLOSE:
1914 PostQuitMessage(0);
1915 break;
1917 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1920 static BOOL mdi_RegisterWindowClasses(void)
1922 WNDCLASSA cls;
1924 cls.style = 0;
1925 cls.lpfnWndProc = mdi_main_wnd_procA;
1926 cls.cbClsExtra = 0;
1927 cls.cbWndExtra = 0;
1928 cls.hInstance = GetModuleHandleA(0);
1929 cls.hIcon = 0;
1930 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
1931 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1932 cls.lpszMenuName = NULL;
1933 cls.lpszClassName = "MDI_parent_Class";
1934 if(!RegisterClassA(&cls)) return FALSE;
1936 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1937 cls.lpszClassName = "MDI_child_Class_1";
1938 if(!RegisterClassA(&cls)) return FALSE;
1940 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1941 cls.lpszClassName = "MDI_child_Class_2";
1942 if(!RegisterClassA(&cls)) return FALSE;
1944 return TRUE;
1947 static void test_mdi(void)
1949 HWND mdi_hwndMain;
1950 /*MSG msg;*/
1952 if (!mdi_RegisterWindowClasses()) assert(0);
1954 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1955 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1956 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1957 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1958 GetDesktopWindow(), 0,
1959 GetModuleHandleA(NULL), NULL);
1960 assert(mdi_hwndMain);
1962 while(GetMessage(&msg, 0, 0, 0))
1964 TranslateMessage(&msg);
1965 DispatchMessage(&msg);
1968 DestroyWindow(mdi_hwndMain);
1971 static void test_icons(void)
1973 WNDCLASSEXA cls;
1974 HWND hwnd;
1975 HICON icon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
1976 HICON icon2 = LoadIconA(0, (LPCSTR)IDI_QUESTION);
1977 HICON small_icon = LoadImageA(0, (LPCSTR)IDI_APPLICATION, IMAGE_ICON,
1978 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1979 HICON res;
1981 cls.cbSize = sizeof(cls);
1982 cls.style = 0;
1983 cls.lpfnWndProc = DefWindowProcA;
1984 cls.cbClsExtra = 0;
1985 cls.cbWndExtra = 0;
1986 cls.hInstance = 0;
1987 cls.hIcon = LoadIconA(0, (LPCSTR)IDI_HAND);
1988 cls.hIconSm = small_icon;
1989 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
1990 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1991 cls.lpszMenuName = NULL;
1992 cls.lpszClassName = "IconWindowClass";
1994 RegisterClassExA(&cls);
1996 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1997 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1998 assert( hwnd );
2000 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
2001 ok( res == 0, "wrong big icon %p/0\n", res );
2002 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
2003 ok( res == 0, "wrong previous big icon %p/0\n", res );
2004 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
2005 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
2006 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
2007 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
2008 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
2009 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
2011 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
2012 ok( res == 0, "wrong small icon %p/0\n", res );
2013 /* this test is XP specific */
2014 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
2015 ok( res != 0, "wrong small icon %p\n", res );*/
2016 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
2017 ok( res == 0, "wrong previous small icon %p/0\n", res );
2018 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
2019 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
2020 /* this test is XP specific */
2021 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
2022 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
2023 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
2024 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
2025 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
2026 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
2027 /* this test is XP specific */
2028 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
2029 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
2031 /* make sure the big icon hasn't changed */
2032 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
2033 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
2035 DestroyWindow( hwnd );
2038 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2040 if (msg == WM_NCCALCSIZE)
2042 RECT *rect = (RECT *)lparam;
2043 /* first time around increase the rectangle, next time decrease it */
2044 if (rect->left == 100) InflateRect( rect, 10, 10 );
2045 else InflateRect( rect, -10, -10 );
2046 return 0;
2048 return DefWindowProcA( hwnd, msg, wparam, lparam );
2051 static void test_SetWindowPos(HWND hwnd, HWND hwnd2)
2053 RECT orig_win_rc, rect;
2054 LONG_PTR old_proc;
2055 HWND hwnd_grandchild, hwnd_child, hwnd_child2;
2056 HWND hwnd_desktop;
2057 RECT rc1, rc2;
2058 BOOL ret;
2060 SetRect(&rect, 111, 222, 333, 444);
2061 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
2062 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
2063 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2065 SetRect(&rect, 111, 222, 333, 444);
2066 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
2067 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
2068 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2070 GetWindowRect(hwnd, &orig_win_rc);
2072 old_proc = SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
2073 ret = SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
2074 ok(ret, "Got %d\n", ret);
2075 GetWindowRect( hwnd, &rect );
2076 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
2077 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2078 GetClientRect( hwnd, &rect );
2079 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
2080 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
2081 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2083 ret = SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
2084 ok(ret, "Got %d\n", ret);
2085 GetWindowRect( hwnd, &rect );
2086 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
2087 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2088 GetClientRect( hwnd, &rect );
2089 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
2090 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
2091 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2093 ret = SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
2094 orig_win_rc.right, orig_win_rc.bottom, 0);
2095 ok(ret, "Got %d\n", ret);
2096 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, old_proc );
2098 /* Win9x truncates coordinates to 16-bit irrespectively */
2099 if (!is_win9x)
2101 ret = SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
2102 ok(ret, "Got %d\n", ret);
2103 ret = SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
2104 ok(ret, "Got %d\n", ret);
2106 ret = SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
2107 ok(ret, "Got %d\n", ret);
2108 ret = SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
2109 ok(ret, "Got %d\n", ret);
2112 ret = SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
2113 orig_win_rc.right, orig_win_rc.bottom, 0);
2114 ok(ret, "Got %d\n", ret);
2116 ok(!(GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
2117 ret = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
2118 ok(ret, "Got %d\n", ret);
2119 ok(GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
2120 ret = SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
2121 ok(ret, "Got %d\n", ret);
2122 ok(GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
2123 ret = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
2124 ok(ret, "Got %d\n", ret);
2125 ok(!(GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
2127 hwnd_desktop = GetDesktopWindow();
2128 ok(!!hwnd_desktop, "Failed to get hwnd_desktop window (%d).\n", GetLastError());
2129 hwnd_child = create_tool_window(WS_VISIBLE|WS_CHILD, hwnd);
2130 ok(!!hwnd_child, "Failed to create child window (%d)\n", GetLastError());
2131 hwnd_grandchild = create_tool_window(WS_VISIBLE|WS_CHILD, hwnd_child);
2132 ok(!!hwnd_child, "Failed to create child window (%d)\n", GetLastError());
2133 hwnd_child2 = create_tool_window(WS_VISIBLE|WS_CHILD, hwnd);
2134 ok(!!hwnd_child2, "Failed to create second child window (%d)\n", GetLastError());
2136 ret = SetWindowPos(hwnd, hwnd2, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2137 ok(ret, "Got %d\n", ret);
2138 check_active_state(hwnd, hwnd, hwnd);
2140 ret = SetWindowPos(hwnd2, hwnd, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2141 ok(ret, "Got %d\n", ret);
2142 check_active_state(hwnd2, hwnd2, hwnd2);
2144 /* Returns TRUE also for windows that are not siblings */
2145 ret = SetWindowPos(hwnd_child, hwnd2, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2146 ok(ret, "Got %d\n", ret);
2147 check_active_state(hwnd2, hwnd2, hwnd2);
2149 ret = SetWindowPos(hwnd2, hwnd_child, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2150 ok(ret, "Got %d\n", ret);
2151 check_active_state(hwnd2, hwnd2, hwnd2);
2153 /* Does not seem to do anything even without passing flags, still returns TRUE */
2154 GetWindowRect(hwnd_child, &rc1);
2155 ret = SetWindowPos(hwnd_child, hwnd2 , 1, 2, 3, 4, 0);
2156 ok(ret, "Got %d\n", ret);
2157 GetWindowRect(hwnd_child, &rc2);
2158 ok(rc1.left == rc2.left && rc1.top == rc2.top &&
2159 rc1.right == rc2.right && rc1.bottom == rc2.bottom,
2160 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2161 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
2162 check_active_state(hwnd2, hwnd2, hwnd2);
2164 /* Same thing the other way around. */
2165 GetWindowRect(hwnd2, &rc1);
2166 ret = SetWindowPos(hwnd2, hwnd_child, 1, 2, 3, 4, 0);
2167 ok(ret, "Got %d\n", ret);
2168 GetWindowRect(hwnd2, &rc2);
2169 ok(rc1.left == rc2.left && rc1.top == rc2.top &&
2170 rc1.right == rc2.right && rc1.bottom == rc2.bottom,
2171 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2172 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
2173 check_active_state(hwnd2, hwnd2, hwnd2);
2175 /* .. and with these windows. */
2176 GetWindowRect(hwnd_grandchild, &rc1);
2177 ret = SetWindowPos(hwnd_grandchild, hwnd_child2, 1, 2, 3, 4, 0);
2178 ok(ret, "Got %d\n", ret);
2179 GetWindowRect(hwnd_grandchild, &rc2);
2180 ok(rc1.left == rc2.left && rc1.top == rc2.top &&
2181 rc1.right == rc2.right && rc1.bottom == rc2.bottom,
2182 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2183 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
2184 check_active_state(hwnd2, hwnd2, hwnd2);
2186 /* Add SWP_NOZORDER and it will be properly resized. */
2187 GetWindowRect(hwnd_grandchild, &rc1);
2188 ret = SetWindowPos(hwnd_grandchild, hwnd_child2, 1, 2, 3, 4, SWP_NOZORDER);
2189 ok(ret, "Got %d\n", ret);
2190 GetWindowRect(hwnd_grandchild, &rc2);
2191 ok((rc1.left+1) == rc2.left && (rc1.top+2) == rc2.top &&
2192 (rc1.left+4) == rc2.right && (rc1.top+6) == rc2.bottom,
2193 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2194 rc1.left+1, rc1.top+2, rc1.left+4, rc1.top+6, rc2.left, rc2.top, rc2.right, rc2.bottom);
2195 check_active_state(hwnd2, hwnd2, hwnd2);
2197 /* Given a sibling window, the window is properly resized. */
2198 GetWindowRect(hwnd_child, &rc1);
2199 ret = SetWindowPos(hwnd_child, hwnd_child2, 1, 2, 3, 4, 0);
2200 ok(ret, "Got %d\n", ret);
2201 GetWindowRect(hwnd_child, &rc2);
2202 ok((rc1.left+1) == rc2.left && (rc1.top+2) == rc2.top &&
2203 (rc1.left+4) == rc2.right && (rc1.top+6) == rc2.bottom,
2204 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2205 rc1.left+1, rc1.top+2, rc1.left+4, rc1.top+6, rc2.left, rc2.top, rc2.right, rc2.bottom);
2206 check_active_state(hwnd2, hwnd2, hwnd2);
2208 /* Involving the desktop window changes things. */
2209 ret = SetWindowPos(hwnd_child, hwnd_desktop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2210 ok(!ret, "Got %d\n", ret);
2211 check_active_state(hwnd2, hwnd2, hwnd2);
2213 GetWindowRect(hwnd_child, &rc1);
2214 ret = SetWindowPos(hwnd_child, hwnd_desktop, 0, 0, 0, 0, 0);
2215 ok(!ret, "Got %d\n", ret);
2216 GetWindowRect(hwnd_child, &rc2);
2217 ok(rc1.top == rc2.top && rc1.left == rc2.left &&
2218 rc1.bottom == rc2.bottom && rc1.right == rc2.right,
2219 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2220 rc1.top, rc1.left, rc1.bottom, rc1.right, rc2.top, rc2.left, rc2.bottom, rc2.right);
2221 check_active_state(hwnd2, hwnd2, hwnd2);
2223 ret = SetWindowPos(hwnd_desktop, hwnd_child, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2224 ok(!ret, "Got %d\n", ret);
2225 check_active_state(hwnd2, hwnd2, hwnd2);
2227 ret = SetWindowPos(hwnd_desktop, hwnd, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2228 ok(!ret, "Got %d\n", ret);
2229 check_active_state(hwnd2, hwnd2, hwnd2);
2231 ret = SetWindowPos(hwnd, hwnd_desktop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2232 ok(!ret, "Got %d\n", ret);
2233 check_active_state(hwnd2, hwnd2, hwnd2);
2235 DestroyWindow(hwnd_grandchild);
2236 DestroyWindow(hwnd_child);
2237 DestroyWindow(hwnd_child2);
2239 hwnd_child = create_tool_window(WS_CHILD|WS_POPUP|WS_SYSMENU, hwnd2);
2240 ok(!!hwnd_child, "Failed to create child window (%d)\n", GetLastError());
2241 ret = SetWindowPos(hwnd_child, NULL, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2242 ok(ret, "Got %d\n", ret);
2243 flush_events( TRUE );
2244 todo_wine check_active_state(hwnd2, hwnd2, hwnd2);
2245 DestroyWindow(hwnd_child);
2248 static void test_SetMenu(HWND parent)
2250 HWND child;
2251 HMENU hMenu, ret;
2252 BOOL retok;
2253 DWORD style;
2255 hMenu = CreateMenu();
2256 assert(hMenu);
2258 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2259 if (0)
2261 /* fails on (at least) Wine, NT4, XP SP2 */
2262 test_nonclient_area(parent);
2264 ret = GetMenu(parent);
2265 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2266 /* test whether we can destroy a menu assigned to a window */
2267 retok = DestroyMenu(hMenu);
2268 ok( retok, "DestroyMenu error %d\n", GetLastError());
2269 retok = IsMenu(hMenu);
2270 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
2271 ret = GetMenu(parent);
2272 /* This test fails on Win9x */
2273 if (!is_win9x)
2274 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2275 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2276 test_nonclient_area(parent);
2278 hMenu = CreateMenu();
2279 assert(hMenu);
2281 /* parent */
2282 ret = GetMenu(parent);
2283 ok(ret == 0, "unexpected menu id %p\n", ret);
2285 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2286 test_nonclient_area(parent);
2287 ret = GetMenu(parent);
2288 ok(ret == 0, "unexpected menu id %p\n", ret);
2290 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2291 if (0)
2293 /* fails on (at least) Wine, NT4, XP SP2 */
2294 test_nonclient_area(parent);
2296 ret = GetMenu(parent);
2297 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2299 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2300 test_nonclient_area(parent);
2301 ret = GetMenu(parent);
2302 ok(ret == 0, "unexpected menu id %p\n", ret);
2304 /* child */
2305 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
2306 assert(child);
2308 ret = GetMenu(child);
2309 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2311 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2312 test_nonclient_area(child);
2313 ret = GetMenu(child);
2314 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2316 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
2317 test_nonclient_area(child);
2318 ret = GetMenu(child);
2319 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2321 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
2322 test_nonclient_area(child);
2323 ret = GetMenu(child);
2324 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2326 style = GetWindowLongA(child, GWL_STYLE);
2327 SetWindowLongA(child, GWL_STYLE, style | WS_POPUP);
2328 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
2329 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
2330 SetWindowLongA(child, GWL_STYLE, style);
2332 SetWindowLongA(child, GWL_STYLE, style | WS_OVERLAPPED);
2333 ok(!SetMenu(child, hMenu), "SetMenu on an overlapped child window should fail\n");
2334 SetWindowLongA(child, GWL_STYLE, style);
2336 DestroyWindow(child);
2337 DestroyMenu(hMenu);
2340 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
2342 HWND child[5], hwnd;
2343 INT_PTR i;
2345 assert(total <= 5);
2347 hwnd = GetWindow(parent, GW_CHILD);
2348 ok(!hwnd, "have to start without children to perform the test\n");
2350 for (i = 0; i < total; i++)
2352 if (style[i] & DS_CONTROL)
2354 child[i] = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
2355 0,0,0,0, parent, (HMENU)i, 0, NULL);
2356 if (style[i] & WS_VISIBLE)
2357 ShowWindow(child[i], SW_SHOW);
2359 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
2361 else
2362 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
2363 parent, (HMENU)i, 0, NULL);
2364 trace("child[%ld] = %p\n", i, child[i]);
2365 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
2368 hwnd = GetWindow(parent, GW_CHILD);
2369 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
2370 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
2371 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
2373 for (i = 0; i < total; i++)
2375 trace("hwnd[%ld] = %p\n", i, hwnd);
2376 ok(child[order[i]] == hwnd, "Z order of child #%ld is wrong\n", i);
2378 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
2381 for (i = 0; i < total; i++)
2382 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2385 static void test_children_zorder(HWND parent)
2387 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2388 WS_CHILD };
2389 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2391 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2392 WS_CHILD | WS_VISIBLE, WS_CHILD,
2393 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2394 const int complex_order_1[1] = { 0 };
2395 const int complex_order_2[2] = { 1, 0 };
2396 const int complex_order_3[3] = { 1, 0, 2 };
2397 const int complex_order_4[4] = { 1, 0, 2, 3 };
2398 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2399 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2400 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2401 WS_CHILD | WS_VISIBLE };
2402 const int complex_order_6[3] = { 0, 1, 2 };
2404 /* simple WS_CHILD */
2405 test_window_tree(parent, simple_style, simple_order, 5);
2407 /* complex children styles */
2408 test_window_tree(parent, complex_style, complex_order_1, 1);
2409 test_window_tree(parent, complex_style, complex_order_2, 2);
2410 test_window_tree(parent, complex_style, complex_order_3, 3);
2411 test_window_tree(parent, complex_style, complex_order_4, 4);
2412 test_window_tree(parent, complex_style, complex_order_5, 5);
2414 /* another set of complex children styles */
2415 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2418 #define check_z_order(hwnd, next, prev, owner, topmost) \
2419 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2420 __FILE__, __LINE__)
2422 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2423 BOOL topmost, const char *file, int line)
2425 HWND test;
2426 DWORD ex_style;
2428 test = GetWindow(hwnd, GW_HWNDNEXT);
2429 /* skip foreign windows */
2430 while (test && test != next &&
2431 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2432 UlongToHandle(GetWindowLongPtrA(test, GWLP_HINSTANCE)) != GetModuleHandleA(NULL) ||
2433 GetWindow(test, GW_OWNER) == next))
2435 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2436 test = GetWindow(test, GW_HWNDNEXT);
2438 ok_(file, line)(next == test, "%p: expected next %p, got %p\n", hwnd, next, test);
2440 test = GetWindow(hwnd, GW_HWNDPREV);
2441 /* skip foreign windows */
2442 while (test && test != prev &&
2443 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2444 UlongToHandle(GetWindowLongPtrA(test, GWLP_HINSTANCE)) != GetModuleHandleA(NULL) ||
2445 GetWindow(test, GW_OWNER) == hwnd))
2447 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2448 test = GetWindow(test, GW_HWNDPREV);
2450 ok_(file, line)(prev == test, "%p: expected prev %p, got %p\n", hwnd, prev, test);
2452 test = GetWindow(hwnd, GW_OWNER);
2453 ok_(file, line)(owner == test, "%p: expected owner %p, got %p\n", hwnd, owner, test);
2455 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
2456 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "%p: expected %stopmost\n",
2457 hwnd, topmost ? "" : "NOT ");
2460 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E, DWORD style)
2462 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2464 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2466 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2468 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2469 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2471 hwnd_F = CreateWindowExA(0, "MainWindowClass", "Owner window",
2472 WS_OVERLAPPED | WS_CAPTION,
2473 100, 100, 100, 100,
2474 0, 0, GetModuleHandleA(NULL), NULL);
2475 trace("hwnd_F %p\n", hwnd_F);
2476 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2478 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2479 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2480 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2481 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2483 hwnd_C = CreateWindowExA(0, "MainWindowClass", NULL,
2484 style,
2485 100, 100, 100, 100,
2486 hwnd_F, 0, GetModuleHandleA(NULL), NULL);
2487 trace("hwnd_C %p\n", hwnd_C);
2488 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2489 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2490 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2491 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2493 hwnd_B = CreateWindowExA(WS_EX_TOPMOST, "MainWindowClass", NULL,
2494 style,
2495 100, 100, 100, 100,
2496 hwnd_F, 0, GetModuleHandleA(NULL), NULL);
2497 trace("hwnd_B %p\n", hwnd_B);
2498 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2499 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2500 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2501 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2502 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2504 hwnd_A = CreateWindowExA(WS_EX_TOPMOST, "MainWindowClass", NULL,
2505 style,
2506 100, 100, 100, 100,
2507 0, 0, GetModuleHandleA(NULL), NULL);
2508 trace("hwnd_A %p\n", hwnd_A);
2509 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2510 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2511 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2512 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2513 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2514 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2516 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);
2518 /* move hwnd_F and its popups up */
2519 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2520 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2521 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2522 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2523 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2524 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2525 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2527 /* move hwnd_F and its popups down */
2528 #if 0 /* enable once Wine is fixed to pass this test */
2529 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2530 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2531 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2532 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2533 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2534 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2535 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2536 #endif
2538 /* make hwnd_C owned by a topmost window */
2539 DestroyWindow( hwnd_C );
2540 hwnd_C = CreateWindowExA(0, "MainWindowClass", NULL,
2541 style,
2542 100, 100, 100, 100,
2543 hwnd_A, 0, GetModuleHandleA(NULL), NULL);
2544 trace("hwnd_C %p\n", hwnd_C);
2545 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2546 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2547 check_z_order(hwnd_F, hwnd_D, hwnd_B, 0, FALSE);
2548 check_z_order(hwnd_B, hwnd_F, hwnd_A, hwnd_F, TRUE);
2549 check_z_order(hwnd_A, hwnd_B, hwnd_C, 0, TRUE);
2550 check_z_order(hwnd_C, hwnd_A, 0, hwnd_A, TRUE);
2552 DestroyWindow(hwnd_A);
2553 DestroyWindow(hwnd_B);
2554 DestroyWindow(hwnd_C);
2555 DestroyWindow(hwnd_F);
2558 static void test_vis_rgn( HWND hwnd )
2560 RECT win_rect, rgn_rect;
2561 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2562 HDC hdc;
2564 ShowWindow(hwnd,SW_SHOW);
2565 hdc = GetDC( hwnd );
2566 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2567 GetWindowRect( hwnd, &win_rect );
2568 GetRgnBox( hrgn, &rgn_rect );
2569 if (is_win9x)
2571 trace("win9x, mapping to screen coords\n");
2572 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2574 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2575 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2576 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2577 rgn_rect.left, win_rect.left );
2578 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2579 rgn_rect.top, win_rect.top );
2580 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2581 rgn_rect.right, win_rect.right );
2582 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2583 rgn_rect.bottom, win_rect.bottom );
2584 ReleaseDC( hwnd, hdc );
2587 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2589 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2591 HWND child = GetWindow(hwnd, GW_CHILD);
2592 ok(child != 0, "couldn't find child window\n");
2593 SetFocus(child);
2594 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2595 return 0;
2597 return DefWindowProcA(hwnd, msg, wp, lp);
2600 static void test_SetFocus(HWND hwnd)
2602 HWND child, child2, ret;
2603 WNDPROC old_wnd_proc;
2605 /* check if we can set focus to non-visible windows */
2607 ShowWindow(hwnd, SW_SHOW);
2608 SetFocus(0);
2609 SetFocus(hwnd);
2610 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2611 ok( GetWindowLongA(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2612 ShowWindow(hwnd, SW_HIDE);
2613 SetFocus(0);
2614 SetFocus(hwnd);
2615 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2616 ok( !(GetWindowLongA(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2617 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2618 assert(child);
2619 SetFocus(child);
2620 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2621 ok( !(GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2622 ShowWindow(child, SW_SHOW);
2623 ok( GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2624 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2625 ShowWindow(child, SW_HIDE);
2626 ok( !(GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2627 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2628 ShowWindow(child, SW_SHOW);
2629 child2 = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, child, 0, 0, NULL);
2630 assert(child2);
2631 ShowWindow(child2, SW_SHOW);
2632 SetFocus(child2);
2633 ShowWindow(child, SW_HIDE);
2634 ok( !(GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2635 ok( GetFocus() == child2, "Focus should be on %p, not %p\n", child2, GetFocus() );
2636 ShowWindow(child, SW_SHOW);
2637 SetFocus(child);
2638 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2639 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2640 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2642 ShowWindow(child, SW_HIDE);
2643 SetFocus(hwnd);
2644 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2645 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2646 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2647 ShowWindow(child, SW_HIDE);
2648 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2650 ShowWindow(hwnd, SW_SHOW);
2651 ShowWindow(child, SW_SHOW);
2652 SetFocus(child);
2653 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2654 EnableWindow(hwnd, FALSE);
2655 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2656 EnableWindow(hwnd, TRUE);
2658 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2659 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2660 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2661 todo_wine
2662 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2663 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2664 ShowWindow(hwnd, SW_RESTORE);
2665 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2666 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2667 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2668 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2669 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2670 todo_wine
2671 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2672 old_wnd_proc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2673 ShowWindow(hwnd, SW_RESTORE);
2674 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2675 todo_wine
2676 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2677 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2679 SetFocus( hwnd );
2680 SetParent( child, GetDesktopWindow());
2681 SetParent( child2, child );
2682 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2683 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2684 ret = SetFocus( child2 );
2685 ok( ret == 0, "SetFocus %p should fail\n", child2);
2686 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2687 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2688 ret = SetFocus( child );
2689 ok( ret == 0, "SetFocus %p should fail\n", child);
2690 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2691 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2692 SetWindowLongW( child, GWL_STYLE, WS_POPUP|WS_CHILD );
2693 SetFocus( child2 );
2694 ok( GetActiveWindow() == child, "child window %p should be active\n", child);
2695 ok( GetFocus() == child2, "Focus should be on child2 %p\n", child2 );
2696 SetFocus( hwnd );
2697 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2698 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2699 SetFocus( child );
2700 ok( GetActiveWindow() == child, "child window %p should be active\n", child);
2701 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2703 DestroyWindow( child2 );
2704 DestroyWindow( child );
2707 static void test_SetActiveWindow(HWND hwnd)
2709 HWND hwnd2;
2711 flush_events( TRUE );
2712 ShowWindow(hwnd, SW_HIDE);
2713 SetFocus(0);
2714 SetActiveWindow(0);
2715 check_wnd_state(0, 0, 0, 0);
2717 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2719 ShowWindow(hwnd, SW_SHOW);
2720 check_wnd_state(hwnd, hwnd, hwnd, 0);
2722 hwnd2 = SetActiveWindow(0);
2723 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2724 if (!GetActiveWindow()) /* doesn't always work on vista */
2726 check_wnd_state(0, 0, 0, 0);
2727 hwnd2 = SetActiveWindow(hwnd);
2728 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2730 check_wnd_state(hwnd, hwnd, hwnd, 0);
2732 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2733 check_wnd_state(hwnd, hwnd, hwnd, 0);
2735 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2736 check_wnd_state(hwnd, hwnd, hwnd, 0);
2738 ShowWindow(hwnd, SW_HIDE);
2739 check_wnd_state(0, 0, 0, 0);
2741 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2742 SetActiveWindow(hwnd);
2743 check_wnd_state(hwnd, hwnd, hwnd, 0);
2745 ShowWindow(hwnd, SW_SHOW);
2746 check_wnd_state(hwnd, hwnd, hwnd, 0);
2748 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2749 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2751 DestroyWindow(hwnd2);
2752 check_wnd_state(hwnd, hwnd, hwnd, 0);
2754 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2755 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2757 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2758 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2760 DestroyWindow(hwnd2);
2761 check_wnd_state(hwnd, hwnd, hwnd, 0);
2764 struct create_window_thread_params
2766 HWND window;
2767 HANDLE window_created;
2768 HANDLE test_finished;
2771 static DWORD WINAPI create_window_thread(void *param)
2773 struct create_window_thread_params *p = param;
2774 DWORD res;
2775 BOOL ret;
2777 p->window = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
2779 ret = SetEvent(p->window_created);
2780 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
2782 res = WaitForSingleObject(p->test_finished, INFINITE);
2783 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2785 DestroyWindow(p->window);
2786 return 0;
2789 static void test_SetForegroundWindow(HWND hwnd)
2791 struct create_window_thread_params thread_params;
2792 HANDLE thread;
2793 DWORD res, tid;
2794 BOOL ret;
2795 HWND hwnd2;
2796 MSG msg;
2798 flush_events( TRUE );
2799 ShowWindow(hwnd, SW_HIDE);
2800 SetFocus(0);
2801 SetActiveWindow(0);
2802 check_wnd_state(0, 0, 0, 0);
2804 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2806 ShowWindow(hwnd, SW_SHOW);
2807 check_wnd_state(hwnd, hwnd, hwnd, 0);
2809 hwnd2 = SetActiveWindow(0);
2810 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2811 if (GetActiveWindow() == hwnd) /* doesn't always work on vista */
2812 check_wnd_state(hwnd, hwnd, hwnd, 0);
2813 else
2814 check_wnd_state(0, 0, 0, 0);
2816 ret = SetForegroundWindow(hwnd);
2817 if (!ret)
2819 skip( "SetForegroundWindow not working\n" );
2820 return;
2822 check_wnd_state(hwnd, hwnd, hwnd, 0);
2824 SetLastError(0xdeadbeef);
2825 ret = SetForegroundWindow(0);
2826 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2827 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
2828 broken(GetLastError() == 0xdeadbeef), /* win9x */
2829 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2830 check_wnd_state(hwnd, hwnd, hwnd, 0);
2832 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2833 check_wnd_state(hwnd, hwnd, hwnd, 0);
2835 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2836 check_wnd_state(hwnd, hwnd, hwnd, 0);
2838 hwnd2 = GetForegroundWindow();
2839 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2840 ret = SetForegroundWindow( GetDesktopWindow() );
2841 ok(ret, "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2842 hwnd2 = GetForegroundWindow();
2843 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2845 ShowWindow(hwnd, SW_HIDE);
2846 check_wnd_state(0, 0, 0, 0);
2848 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2849 ret = SetForegroundWindow(hwnd);
2850 ok(ret || broken(!ret), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
2851 check_wnd_state(hwnd, hwnd, hwnd, 0);
2853 ShowWindow(hwnd, SW_SHOW);
2854 check_wnd_state(hwnd, hwnd, hwnd, 0);
2856 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2857 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2859 DestroyWindow(hwnd2);
2860 check_wnd_state(hwnd, hwnd, hwnd, 0);
2862 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2863 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2865 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2866 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2868 DestroyWindow(hwnd2);
2869 check_wnd_state(hwnd, hwnd, hwnd, 0);
2871 hwnd2 = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
2872 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2874 thread_params.window_created = CreateEventW(NULL, FALSE, FALSE, NULL);
2875 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
2876 thread_params.test_finished = CreateEventW(NULL, FALSE, FALSE, NULL);
2877 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
2878 thread = CreateThread(NULL, 0, create_window_thread, &thread_params, 0, &tid);
2879 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
2880 res = WaitForSingleObject(thread_params.window_created, INFINITE);
2881 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2882 check_wnd_state(hwnd2, thread_params.window, hwnd2, 0);
2884 SetForegroundWindow(hwnd2);
2885 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2887 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2888 if (0) check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2889 todo_wine ok(GetActiveWindow() == hwnd2, "Expected active window %p, got %p.\n", hwnd2, GetActiveWindow());
2890 todo_wine ok(GetFocus() == hwnd2, "Expected focus window %p, got %p.\n", hwnd2, GetFocus());
2892 SetEvent(thread_params.test_finished);
2893 WaitForSingleObject(thread, INFINITE);
2894 CloseHandle(thread_params.test_finished);
2895 CloseHandle(thread_params.window_created);
2896 CloseHandle(thread);
2897 DestroyWindow(hwnd2);
2900 static WNDPROC old_button_proc;
2902 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2904 LRESULT ret;
2905 USHORT key_state;
2907 key_state = GetKeyState(VK_LBUTTON);
2908 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2910 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2912 if (msg == WM_LBUTTONDOWN)
2914 HWND hwnd, capture;
2916 check_wnd_state(button, button, button, button);
2918 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2919 assert(hwnd);
2920 trace("hwnd %p\n", hwnd);
2922 check_wnd_state(button, button, button, button);
2924 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2926 check_wnd_state(button, button, button, button);
2928 DestroyWindow(hwnd);
2930 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2931 assert(hwnd);
2932 trace("hwnd %p\n", hwnd);
2934 check_wnd_state(button, button, button, button);
2936 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2937 * match internal button state.
2939 SendMessageA(button, WM_KILLFOCUS, 0, 0);
2940 check_wnd_state(button, button, button, 0);
2942 ShowWindow(hwnd, SW_SHOW);
2943 check_wnd_state(hwnd, hwnd, hwnd, 0);
2945 capture = SetCapture(hwnd);
2946 ok(capture == 0, "SetCapture() = %p\n", capture);
2948 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2950 DestroyWindow(hwnd);
2952 check_wnd_state(button, 0, button, 0);
2955 return ret;
2958 static void test_capture_1(void)
2960 HWND button, capture;
2962 capture = GetCapture();
2963 ok(capture == 0, "GetCapture() = %p\n", capture);
2965 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2966 assert(button);
2967 trace("button %p\n", button);
2969 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2971 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2973 capture = SetCapture(button);
2974 ok(capture == 0, "SetCapture() = %p\n", capture);
2975 check_wnd_state(button, 0, button, button);
2977 DestroyWindow(button);
2978 /* old active window test depends on previously executed window
2979 * activation tests, and fails under NT4.
2980 check_wnd_state(oldActive, 0, oldFocus, 0);*/
2983 static void test_capture_2(void)
2985 HWND button, hwnd, capture, oldFocus, oldActive;
2987 oldFocus = GetFocus();
2988 oldActive = GetActiveWindow();
2989 check_wnd_state(oldActive, 0, oldFocus, 0);
2991 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2992 assert(button);
2993 trace("button %p\n", button);
2995 check_wnd_state(button, button, button, 0);
2997 capture = SetCapture(button);
2998 ok(capture == 0, "SetCapture() = %p\n", capture);
3000 check_wnd_state(button, button, button, button);
3002 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
3003 * internal button state.
3005 SendMessageA(button, WM_KILLFOCUS, 0, 0);
3006 check_wnd_state(button, button, button, button);
3008 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
3009 assert(hwnd);
3010 trace("hwnd %p\n", hwnd);
3012 check_wnd_state(button, button, button, button);
3014 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
3016 check_wnd_state(button, button, button, button);
3018 DestroyWindow(hwnd);
3020 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
3021 assert(hwnd);
3022 trace("hwnd %p\n", hwnd);
3024 check_wnd_state(button, button, button, button);
3026 ShowWindow(hwnd, SW_SHOW);
3028 check_wnd_state(hwnd, hwnd, hwnd, button);
3030 capture = SetCapture(hwnd);
3031 ok(capture == button, "SetCapture() = %p\n", capture);
3033 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
3035 DestroyWindow(hwnd);
3036 check_wnd_state(button, button, button, 0);
3038 DestroyWindow(button);
3039 check_wnd_state(oldActive, 0, oldFocus, 0);
3042 static void test_capture_3(HWND hwnd1, HWND hwnd2)
3044 BOOL ret;
3046 ShowWindow(hwnd1, SW_HIDE);
3047 ShowWindow(hwnd2, SW_HIDE);
3049 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
3050 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
3052 SetCapture(hwnd1);
3053 check_wnd_state(0, 0, 0, hwnd1);
3055 SetCapture(hwnd2);
3056 check_wnd_state(0, 0, 0, hwnd2);
3058 ShowWindow(hwnd1, SW_SHOW);
3059 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
3061 ret = ReleaseCapture();
3062 ok (ret, "releasecapture did not return TRUE.\n");
3063 ret = ReleaseCapture();
3064 ok (ret, "releasecapture did not return TRUE after second try.\n");
3067 static LRESULT CALLBACK test_capture_4_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3069 GUITHREADINFO gti;
3070 HWND cap_wnd, cap_wnd2, set_cap_wnd;
3071 BOOL status;
3072 switch (msg)
3074 case WM_CAPTURECHANGED:
3076 /* now try to release capture from menu. this should fail */
3077 if (pGetGUIThreadInfo)
3079 memset(&gti, 0, sizeof(GUITHREADINFO));
3080 gti.cbSize = sizeof(GUITHREADINFO);
3081 status = pGetGUIThreadInfo(GetCurrentThreadId(), &gti);
3082 ok(status, "GetGUIThreadInfo() failed!\n");
3083 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
3085 cap_wnd = GetCapture();
3087 /* check that re-setting the capture for the menu fails */
3088 set_cap_wnd = SetCapture(cap_wnd);
3089 ok(!set_cap_wnd || broken(set_cap_wnd == cap_wnd), /* nt4 */
3090 "SetCapture should have failed!\n");
3091 if (set_cap_wnd)
3093 DestroyWindow(hWnd);
3094 break;
3097 /* check that SetCapture fails for another window and that it does not touch the error code */
3098 set_cap_wnd = SetCapture(hWnd);
3099 ok(!set_cap_wnd, "SetCapture should have failed!\n");
3101 /* check that ReleaseCapture fails and does not touch the error code */
3102 status = ReleaseCapture();
3103 ok(!status, "ReleaseCapture should have failed!\n");
3105 /* check that thread info did not change */
3106 if (pGetGUIThreadInfo)
3108 memset(&gti, 0, sizeof(GUITHREADINFO));
3109 gti.cbSize = sizeof(GUITHREADINFO);
3110 status = pGetGUIThreadInfo(GetCurrentThreadId(), &gti);
3111 ok(status, "GetGUIThreadInfo() failed!\n");
3112 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
3115 /* verify that no capture change took place */
3116 cap_wnd2 = GetCapture();
3117 ok(cap_wnd2 == cap_wnd, "Capture changed!\n");
3119 /* we are done. kill the window */
3120 DestroyWindow(hWnd);
3121 break;
3123 default:
3124 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
3126 return 0;
3129 /* Test that no-one can mess around with the current capture while a menu is open */
3130 static void test_capture_4(void)
3132 BOOL ret;
3133 HMENU hmenu;
3134 HWND hwnd;
3135 WNDCLASSA wclass;
3136 HINSTANCE hInstance = GetModuleHandleA( NULL );
3137 ATOM aclass;
3139 if (!pGetGUIThreadInfo)
3141 win_skip("GetGUIThreadInfo is not available\n");
3142 return;
3144 wclass.lpszClassName = "TestCapture4Class";
3145 wclass.style = CS_HREDRAW | CS_VREDRAW;
3146 wclass.lpfnWndProc = test_capture_4_proc;
3147 wclass.hInstance = hInstance;
3148 wclass.hIcon = LoadIconA( 0, (LPCSTR)IDI_APPLICATION );
3149 wclass.hCursor = LoadCursorA( 0, (LPCSTR)IDC_ARROW );
3150 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
3151 wclass.lpszMenuName = 0;
3152 wclass.cbClsExtra = 0;
3153 wclass.cbWndExtra = 0;
3154 aclass = RegisterClassA( &wclass );
3155 ok( aclass, "RegisterClassA failed with error %d\n", GetLastError());
3156 hwnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
3157 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
3158 400, 200, NULL, NULL, hInstance, NULL);
3159 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
3160 if (!hwnd) return;
3161 hmenu = CreatePopupMenu();
3163 ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest2");
3164 ok( ret, "AppendMenuA has failed!\n");
3166 /* set main window to have initial capture */
3167 SetCapture(hwnd);
3169 if (is_win9x)
3171 win_skip("TrackPopupMenu test crashes on Win9x/WinMe\n");
3173 else
3175 /* create popup (it will self-destruct) */
3176 ret = TrackPopupMenu(hmenu, TPM_RETURNCMD, 100, 100, 0, hwnd, NULL);
3177 ok( ret == 0, "TrackPopupMenu returned %d expected zero\n", ret);
3180 /* clean up */
3181 DestroyMenu(hmenu);
3182 DestroyWindow(hwnd);
3185 /* PeekMessage wrapper that ignores the messages we don't care about */
3186 static BOOL peek_message( MSG *msg )
3188 BOOL ret;
3191 ret = PeekMessageA(msg, 0, 0, 0, PM_REMOVE);
3192 } while (ret && (msg->message == WM_TIMER || ignore_message(msg->message)));
3193 return ret;
3196 static void test_keyboard_input(HWND hwnd)
3198 MSG msg;
3199 BOOL ret;
3201 flush_events( TRUE );
3202 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
3203 UpdateWindow(hwnd);
3204 flush_events( TRUE );
3206 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
3208 SetFocus(hwnd);
3209 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
3211 flush_events( TRUE );
3213 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
3214 ret = peek_message(&msg);
3215 ok( ret, "no message available\n");
3216 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3217 ret = peek_message(&msg);
3218 ok( !ret, "message %04x available\n", msg.message);
3220 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
3222 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
3223 ret = peek_message(&msg);
3224 ok(ret, "no message available\n");
3225 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3226 ret = peek_message(&msg);
3227 ok( !ret, "message %04x available\n", msg.message);
3229 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
3231 keybd_event(VK_SPACE, 0, 0, 0);
3232 if (!peek_message(&msg))
3234 skip( "keybd_event didn't work, skipping keyboard test\n" );
3235 return;
3237 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3238 ret = peek_message(&msg);
3239 ok( !ret, "message %04x available\n", msg.message);
3241 SetFocus(0);
3242 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3244 flush_events( TRUE );
3246 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
3247 ret = peek_message(&msg);
3248 ok(ret, "no message available\n");
3249 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3250 ret = peek_message(&msg);
3251 ok( !ret, "message %04x available\n", msg.message);
3253 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3255 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
3256 ret = peek_message(&msg);
3257 ok(ret, "no message available\n");
3258 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3259 ret = peek_message(&msg);
3260 ok( !ret, "message %04x available\n", msg.message);
3262 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3264 keybd_event(VK_SPACE, 0, 0, 0);
3265 ret = peek_message(&msg);
3266 ok(ret, "no message available\n");
3267 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3268 ret = peek_message(&msg);
3269 ok( !ret, "message %04x available\n", msg.message);
3272 static BOOL wait_for_message( MSG *msg )
3274 BOOL ret;
3276 for (;;)
3278 ret = peek_message(msg);
3279 if (ret)
3281 if (msg->message == WM_PAINT) DispatchMessageA(msg);
3282 else break;
3284 else if (MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
3286 if (!ret) msg->message = 0;
3287 return ret;
3290 static void test_mouse_input(HWND hwnd)
3292 RECT rc;
3293 POINT pt;
3294 int x, y;
3295 HWND popup;
3296 MSG msg;
3297 BOOL ret;
3298 LRESULT res;
3300 ShowWindow(hwnd, SW_SHOWNORMAL);
3301 UpdateWindow(hwnd);
3302 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3304 GetWindowRect(hwnd, &rc);
3305 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
3307 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
3308 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
3309 hwnd, 0, 0, NULL);
3310 assert(popup != 0);
3311 ShowWindow(popup, SW_SHOW);
3312 UpdateWindow(popup);
3313 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3315 GetWindowRect(popup, &rc);
3316 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
3318 x = rc.left + (rc.right - rc.left) / 2;
3319 y = rc.top + (rc.bottom - rc.top) / 2;
3320 trace("setting cursor to (%d,%d)\n", x, y);
3322 SetCursorPos(x, y);
3323 GetCursorPos(&pt);
3324 if (x != pt.x || y != pt.y)
3326 skip( "failed to set mouse position, skipping mouse input tests\n" );
3327 goto done;
3330 flush_events( TRUE );
3332 /* Check that setting the same position may generate WM_MOUSEMOVE */
3333 SetCursorPos(x, y);
3334 msg.message = 0;
3335 ret = peek_message(&msg);
3336 if (ret)
3338 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
3339 msg.hwnd, msg.message);
3340 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
3341 x, y, msg.pt.x, msg.pt.y);
3344 /* force the system to update its internal queue mouse position,
3345 * otherwise it won't generate relative mouse movements below.
3347 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3348 flush_events( TRUE );
3350 msg.message = 0;
3351 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3352 flush_events( FALSE );
3353 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
3354 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
3356 if (msg.message == WM_TIMER || ignore_message(msg.message)) continue;
3357 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
3358 "hwnd %p message %04x\n", msg.hwnd, msg.message);
3359 DispatchMessageA(&msg);
3361 ret = peek_message(&msg);
3362 ok( !ret, "message %04x available\n", msg.message);
3364 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3365 ShowWindow(popup, SW_HIDE);
3366 ret = wait_for_message( &msg );
3367 if (ret)
3368 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3369 flush_events( TRUE );
3371 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3372 ShowWindow(hwnd, SW_HIDE);
3373 ret = wait_for_message( &msg );
3374 ok( !ret, "message %04x available\n", msg.message);
3375 flush_events( TRUE );
3377 /* test mouse clicks */
3379 ShowWindow(hwnd, SW_SHOW);
3380 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3381 flush_events( TRUE );
3382 ShowWindow(popup, SW_SHOW);
3383 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3384 flush_events( TRUE );
3386 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3387 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3388 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3389 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3391 ret = wait_for_message( &msg );
3392 if (!ret)
3394 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
3395 goto done;
3397 if (msg.message == WM_MOUSEMOVE) /* win2k has an extra WM_MOUSEMOVE here */
3399 ret = wait_for_message( &msg );
3400 ok(ret, "no message available\n");
3403 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3404 msg.hwnd, popup, msg.message);
3406 ret = wait_for_message( &msg );
3407 ok(ret, "no message available\n");
3408 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3409 msg.hwnd, popup, msg.message);
3411 ret = wait_for_message( &msg );
3412 ok(ret, "no message available\n");
3413 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
3414 msg.hwnd, popup, msg.message);
3416 ret = wait_for_message( &msg );
3417 ok(ret, "no message available\n");
3418 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3419 msg.hwnd, popup, msg.message);
3421 ret = peek_message(&msg);
3422 ok(!ret, "message %04x available\n", msg.message);
3424 ShowWindow(popup, SW_HIDE);
3425 flush_events( TRUE );
3427 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3428 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3429 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3430 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3432 ret = wait_for_message( &msg );
3433 ok(ret, "no message available\n");
3434 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3435 msg.hwnd, hwnd, msg.message);
3436 ret = wait_for_message( &msg );
3437 ok(ret, "no message available\n");
3438 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3439 msg.hwnd, hwnd, msg.message);
3441 test_lbuttondown_flag = TRUE;
3442 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
3443 test_lbuttondown_flag = FALSE;
3445 ret = wait_for_message( &msg );
3446 ok(ret, "no message available\n");
3447 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3448 msg.hwnd, popup, msg.message);
3449 ok(peek_message(&msg), "no message available\n");
3450 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3451 msg.hwnd, popup, msg.message);
3452 ok(peek_message(&msg), "no message available\n");
3454 /* Test WM_MOUSEACTIVATE */
3455 #define TEST_MOUSEACTIVATE(A,B) \
3456 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
3457 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
3459 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
3460 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
3461 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
3462 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
3463 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
3464 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
3465 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
3466 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
3467 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
3468 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
3469 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
3470 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
3471 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
3472 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
3473 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
3474 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
3475 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
3476 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
3477 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
3478 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
3479 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
3480 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
3481 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
3482 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
3484 done:
3485 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
3486 flush_events( TRUE );
3488 DestroyWindow(popup);
3491 static void test_validatergn(HWND hwnd)
3493 HWND child;
3494 RECT rc, rc2;
3495 HRGN rgn;
3496 int ret;
3497 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
3498 ShowWindow(hwnd, SW_SHOW);
3499 UpdateWindow( hwnd);
3500 /* test that ValidateRect validates children*/
3501 InvalidateRect( child, NULL, 1);
3502 GetWindowRect( child, &rc);
3503 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3504 ret = GetUpdateRect( child, &rc2, 0);
3505 ok( ret == 1, "Expected GetUpdateRect to return non-zero, got %d\n", ret);
3506 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
3507 "Update rectangle is empty!\n");
3508 ValidateRect( hwnd, &rc);
3509 ret = GetUpdateRect( child, &rc2, 0);
3510 ok( !ret, "Expected GetUpdateRect to return zero, got %d\n", ret);
3511 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3512 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3513 rc2.right, rc2.bottom);
3515 /* now test ValidateRgn */
3516 InvalidateRect( child, NULL, 1);
3517 GetWindowRect( child, &rc);
3518 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3519 rgn = CreateRectRgnIndirect( &rc);
3520 ValidateRgn( hwnd, rgn);
3521 ret = GetUpdateRect( child, &rc2, 0);
3522 ok( !ret, "Expected GetUpdateRect to return zero, got %d\n", ret);
3523 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3524 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3525 rc2.right, rc2.bottom);
3527 DeleteObject( rgn);
3528 DestroyWindow( child );
3531 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
3533 RECT rc;
3534 MoveWindow( hwnd, 0, 0, x, y, 0);
3535 GetWindowRect( hwnd, prc);
3536 rc = *prc;
3537 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
3538 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
3539 rc.left,rc.top,rc.right,rc.bottom, prc->left,prc->top,prc->right,prc->bottom);
3542 static void test_nccalcscroll(HWND parent)
3544 RECT rc1;
3545 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
3546 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
3547 HWND hwnd = CreateWindowExA(0, "static", NULL,
3548 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
3549 10, 10, 200, 200, parent, 0, 0, NULL);
3550 ShowWindow( parent, SW_SHOW);
3551 UpdateWindow( parent);
3553 /* test window too low for a horizontal scroll bar */
3554 nccalchelper( hwnd, 100, sbheight, &rc1);
3555 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
3556 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
3558 /* test window just high enough for a horizontal scroll bar */
3559 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
3560 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
3561 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3563 /* test window too narrow for a vertical scroll bar */
3564 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
3565 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
3566 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3568 /* test window just wide enough for a vertical scroll bar */
3569 nccalchelper( hwnd, sbwidth, 100, &rc1);
3570 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
3571 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
3573 /* same test, but with client edge: not enough width */
3574 SetWindowLongA( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLongA( hwnd, GWL_EXSTYLE));
3575 nccalchelper( hwnd, sbwidth, 100, &rc1);
3576 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
3577 "Width should be %d size is %d,%d - %d,%d\n",
3578 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
3580 DestroyWindow( hwnd);
3583 static void test_SetParent(void)
3585 HWND desktop = GetDesktopWindow();
3586 HMENU hMenu;
3587 HWND ret, parent, child1, child2, child3, child4, sibling, popup;
3588 BOOL bret;
3590 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3591 100, 100, 200, 200, 0, 0, 0, NULL);
3592 assert(parent != 0);
3593 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3594 0, 0, 50, 50, parent, 0, 0, NULL);
3595 assert(child1 != 0);
3596 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3597 0, 0, 50, 50, child1, 0, 0, NULL);
3598 assert(child2 != 0);
3599 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3600 0, 0, 50, 50, child2, 0, 0, NULL);
3601 assert(child3 != 0);
3602 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3603 0, 0, 50, 50, child3, 0, 0, NULL);
3604 assert(child4 != 0);
3606 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
3607 parent, child1, child2, child3, child4);
3609 check_parents(parent, desktop, 0, 0, 0, parent, parent);
3610 check_parents(child1, parent, parent, parent, 0, parent, parent);
3611 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3612 check_parents(child3, child2, child2, child2, 0, child2, parent);
3613 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3615 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
3616 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
3617 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3618 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
3619 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3621 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
3622 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3623 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
3624 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
3625 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
3626 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
3627 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
3628 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3629 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3631 if (!is_win9x) /* Win9x doesn't survive this test */
3633 ok(!SetParent(parent, child1), "SetParent should fail\n");
3634 ok(!SetParent(child2, child3), "SetParent should fail\n");
3635 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
3636 ret = SetParent(parent, child2);
3637 todo_wine ok( !ret || broken( ret != 0 ), "SetParent should fail\n");
3638 if (ret) /* nt4, win2k */
3640 ret = SetParent(parent, child3);
3641 ok(ret != 0, "SetParent should not fail\n");
3642 ret = SetParent(child2, parent);
3643 ok(!ret, "SetParent should fail\n");
3644 ret = SetParent(parent, child4);
3645 ok(ret != 0, "SetParent should not fail\n");
3646 check_parents(parent, child4, child4, 0, 0, child4, parent);
3647 check_parents(child1, parent, parent, parent, 0, child4, parent);
3648 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3649 check_parents(child3, child2, child2, child2, 0, child2, parent);
3650 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3652 else
3654 ret = SetParent(parent, child3);
3655 ok(ret != 0, "SetParent should not fail\n");
3656 ret = SetParent(child2, parent);
3657 ok(!ret, "SetParent should fail\n");
3658 ret = SetParent(parent, child4);
3659 ok(!ret, "SetParent should fail\n");
3660 check_parents(parent, child3, child3, 0, 0, child2, parent);
3661 check_parents(child1, parent, parent, parent, 0, child2, parent);
3662 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3663 check_parents(child3, child2, child2, child2, 0, child2, parent);
3664 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3667 else
3668 skip("Win9x/WinMe crash\n");
3670 hMenu = CreateMenu();
3671 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3672 100, 100, 200, 200, 0, hMenu, 0, NULL);
3673 assert(sibling != 0);
3675 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
3676 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
3678 ok(SetParent(parent, desktop) != 0, "SetParent should not fail\n");
3679 ok(SetParent(child4, child3) != 0, "SetParent should not fail\n");
3680 ok(SetParent(child3, child2) != 0, "SetParent should not fail\n");
3681 ok(SetParent(child2, child1) != 0, "SetParent should not fail\n");
3682 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3683 SetWindowLongW(child4, GWL_STYLE, WS_CHILD);
3684 ok(IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3685 ok(IsChild(child2, child4), "wrong parent/child %p/%p\n", child2, child4);
3686 ok(!IsChild(child1, child4), "wrong parent/child %p/%p\n", child1, child4);
3687 SetWindowLongW(child2, GWL_STYLE, WS_CHILD);
3688 ok(IsChild(child1, child4), "wrong parent/child %p/%p\n", child1, child4);
3689 ok(IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
3691 ok(DestroyWindow(parent), "DestroyWindow() failed\n");
3693 ok(!IsWindow(parent), "parent still exists\n");
3694 ok(!IsWindow(sibling), "sibling still exists\n");
3695 ok(!IsWindow(child1), "child1 still exists\n");
3696 ok(!IsWindow(child2), "child2 still exists\n");
3697 ok(!IsWindow(child3), "child3 still exists\n");
3698 ok(!IsWindow(child4), "child4 still exists\n");
3700 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3701 100, 100, 200, 200, 0, 0, 0, NULL);
3702 assert(parent != 0);
3703 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3704 0, 0, 50, 50, parent, 0, 0, NULL);
3705 assert(child1 != 0);
3706 popup = CreateWindowExA(0, "static", NULL, WS_POPUP,
3707 0, 0, 50, 50, 0, 0, 0, NULL);
3708 assert(popup != 0);
3710 trace("parent %p, child %p, popup %p\n", parent, child1, popup);
3712 check_parents(parent, desktop, 0, 0, 0, parent, parent);
3713 check_parents(child1, parent, parent, parent, 0, parent, parent);
3714 check_parents(popup, desktop, 0, 0, 0, popup, popup);
3716 SetActiveWindow(parent);
3717 SetFocus(parent);
3718 check_active_state(parent, 0, parent);
3720 ret = SetParent(popup, child1);
3721 ok(ret == desktop, "expected %p, got %p\n", desktop, ret);
3722 check_parents(popup, child1, child1, 0, 0, parent, popup);
3723 todo_wine
3724 check_active_state(popup, 0, popup);
3726 SetActiveWindow(parent);
3727 SetFocus(parent);
3728 check_active_state(parent, 0, parent);
3730 bret = SetForegroundWindow(popup);
3731 todo_wine
3732 ok(bret, "SetForegroundWindow() failed\n");
3733 if (bret)
3734 check_active_state(popup, popup, popup);
3736 ok(DestroyWindow(parent), "DestroyWindow() failed\n");
3738 ok(!IsWindow(parent), "parent still exists\n");
3739 ok(!IsWindow(child1), "child1 still exists\n");
3740 ok(!IsWindow(popup), "popup still exists\n");
3743 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3745 LPCREATESTRUCTA lpcs;
3746 LPSTYLESTRUCT lpss;
3748 switch (msg)
3750 case WM_NCCREATE:
3751 case WM_CREATE:
3752 lpcs = (LPCREATESTRUCTA)lparam;
3753 lpss = lpcs->lpCreateParams;
3754 if (lpss)
3756 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
3757 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
3758 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
3759 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
3760 else
3761 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3763 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
3764 "Ex style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3765 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
3767 ok(lpss->styleNew == lpcs->style,
3768 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3769 lpss->styleNew, lpcs->style);
3771 break;
3773 return DefWindowProcA(hwnd, msg, wparam, lparam);
3776 static ATOM atomStyleCheckClass;
3778 static void register_style_check_class(void)
3780 WNDCLASSA wc =
3783 StyleCheckProc,
3786 GetModuleHandleA(NULL),
3787 NULL,
3788 LoadCursorA(0, (LPCSTR)IDC_ARROW),
3789 (HBRUSH)(COLOR_BTNFACE+1),
3790 NULL,
3791 "WineStyleCheck",
3794 atomStyleCheckClass = RegisterClassA(&wc);
3795 assert(atomStyleCheckClass);
3798 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3800 DWORD dwActualStyle;
3801 DWORD dwActualExStyle;
3802 STYLESTRUCT ss;
3803 HWND hwnd;
3804 HWND hwndParent = NULL;
3806 ss.styleNew = dwStyleIn;
3807 ss.styleOld = dwExStyleIn;
3809 if (dwStyleIn & WS_CHILD)
3811 hwndParent = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomStyleCheckClass), NULL,
3812 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3815 hwnd = CreateWindowExA(dwExStyleIn, (LPCSTR)MAKEINTATOM(atomStyleCheckClass), NULL,
3816 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3817 assert(hwnd);
3819 flush_events( TRUE );
3821 dwActualStyle = GetWindowLongA(hwnd, GWL_STYLE);
3822 dwActualExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3823 ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
3824 ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
3826 /* try setting the styles explicitly */
3827 SetWindowLongA( hwnd, GWL_EXSTYLE, dwExStyleIn );
3828 dwActualStyle = GetWindowLongA(hwnd, GWL_STYLE);
3829 dwActualExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3830 /* WS_EX_WINDOWEDGE can't always be changed */
3831 if (dwExStyleIn & WS_EX_DLGMODALFRAME)
3832 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3833 else if ((dwActualStyle & (WS_DLGFRAME | WS_THICKFRAME)) && !(dwExStyleIn & WS_EX_STATICEDGE))
3834 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3835 else
3836 dwExStyleOut = dwExStyleIn & ~WS_EX_WINDOWEDGE;
3837 ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
3838 ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
3840 SetWindowLongA( hwnd, GWL_STYLE, dwStyleIn );
3841 dwActualStyle = GetWindowLongA(hwnd, GWL_STYLE);
3842 dwActualExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3843 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3844 if ((dwStyleIn & (WS_CHILD|WS_POPUP)) == WS_CHILD) dwStyleOut = dwStyleIn;
3845 else dwStyleOut = dwStyleIn | WS_CLIPSIBLINGS;
3846 /* WS_EX_WINDOWEDGE can't always be changed */
3847 if (dwExStyleIn & WS_EX_DLGMODALFRAME)
3848 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3849 else if ((dwActualStyle & (WS_DLGFRAME | WS_THICKFRAME)) && !(dwExStyleIn & WS_EX_STATICEDGE))
3850 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3851 else
3852 dwExStyleOut = dwExStyleIn & ~WS_EX_WINDOWEDGE;
3853 ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
3854 /* FIXME: Remove the condition below once Wine is fixed */
3855 if (dwActualExStyle != dwExStyleOut)
3856 todo_wine ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
3857 else
3858 ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
3860 DestroyWindow(hwnd);
3861 if (hwndParent) DestroyWindow(hwndParent);
3864 /* tests what window styles the window manager automatically adds */
3865 static void test_window_styles(void)
3867 register_style_check_class();
3869 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3870 check_window_style(WS_DLGFRAME, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3871 check_window_style(WS_THICKFRAME, 0, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3872 check_window_style(WS_DLGFRAME, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE);
3873 check_window_style(WS_THICKFRAME, WS_EX_STATICEDGE, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE);
3874 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3875 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3876 check_window_style(WS_CHILD|WS_DLGFRAME, 0, WS_CHILD|WS_DLGFRAME, WS_EX_WINDOWEDGE);
3877 check_window_style(WS_CHILD|WS_THICKFRAME, 0, WS_CHILD|WS_THICKFRAME, WS_EX_WINDOWEDGE);
3878 check_window_style(WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE);
3879 check_window_style(WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE);
3880 check_window_style(WS_CHILD|WS_CAPTION, 0, WS_CHILD|WS_CAPTION, WS_EX_WINDOWEDGE);
3881 check_window_style(WS_CHILD|WS_CAPTION|WS_SYSMENU, 0, WS_CHILD|WS_CAPTION|WS_SYSMENU, WS_EX_WINDOWEDGE);
3882 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3883 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3884 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3885 check_window_style(WS_CHILD|WS_POPUP, 0, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
3886 check_window_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, 0, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3887 check_window_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, 0, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3888 check_window_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3889 check_window_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3890 check_window_style(WS_CHILD|WS_POPUP, WS_EX_APPWINDOW, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, WS_EX_APPWINDOW);
3891 check_window_style(WS_CHILD|WS_POPUP, WS_EX_WINDOWEDGE, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
3892 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3893 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3894 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3895 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3896 check_window_style(WS_POPUP|WS_DLGFRAME, 0, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3897 check_window_style(WS_POPUP|WS_THICKFRAME, 0, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3898 check_window_style(WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3899 check_window_style(WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3900 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3901 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3903 if (pGetLayeredWindowAttributes)
3905 check_window_style(0, WS_EX_LAYERED, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_WINDOWEDGE);
3906 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_WINDOWEDGE);
3907 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION,
3908 WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW|WS_EX_WINDOWEDGE);
3912 static INT_PTR WINAPI empty_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3914 return 0;
3917 static void check_dialog_style(DWORD style_in, DWORD ex_style_in, DWORD style_out, DWORD ex_style_out)
3919 struct
3921 DLGTEMPLATE dt;
3922 WORD menu_name;
3923 WORD class_id;
3924 WORD class_atom;
3925 WCHAR caption[1];
3926 } dlg_data;
3927 DWORD style, ex_style;
3928 HWND hwnd, parent = 0;
3930 if (style_in & WS_CHILD)
3931 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3932 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3934 dlg_data.dt.style = style_in;
3935 dlg_data.dt.dwExtendedStyle = ex_style_in;
3936 dlg_data.dt.cdit = 0;
3937 dlg_data.dt.x = 0;
3938 dlg_data.dt.y = 0;
3939 dlg_data.dt.cx = 100;
3940 dlg_data.dt.cy = 100;
3941 dlg_data.menu_name = 0;
3942 dlg_data.class_id = 0;
3943 dlg_data.class_atom = 0;
3944 dlg_data.caption[0] = 0;
3946 hwnd = CreateDialogIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, parent, empty_dlg_proc, 0);
3947 ok(hwnd != 0, "dialog creation failed, style %#x, exstyle %#x\n", style_in, ex_style_in);
3949 flush_events( TRUE );
3951 style = GetWindowLongA(hwnd, GWL_STYLE);
3952 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
3953 ok(style == (style_out | DS_3DLOOK), "expected style %#x, got %#x\n", style_out | DS_3DLOOK, style);
3954 ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
3956 /* try setting the styles explicitly */
3957 SetWindowLongA(hwnd, GWL_EXSTYLE, ex_style_in);
3958 style = GetWindowLongA(hwnd, GWL_STYLE);
3959 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
3960 ok(style == (style_out | DS_3DLOOK), "expected style %#x, got %#x\n", style_out|DS_3DLOOK, style);
3961 /* WS_EX_WINDOWEDGE can't always be changed */
3962 if (ex_style_in & WS_EX_DLGMODALFRAME)
3963 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
3964 else if ((style & (WS_DLGFRAME | WS_THICKFRAME)) && !(ex_style_in & WS_EX_STATICEDGE))
3965 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
3966 else
3967 ex_style_out = ex_style_in & ~WS_EX_WINDOWEDGE;
3968 ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
3970 SetWindowLongA(hwnd, GWL_STYLE, style_in);
3971 style = GetWindowLongA(hwnd, GWL_STYLE);
3972 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
3973 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3974 if ((style_in & (WS_CHILD | WS_POPUP)) == WS_CHILD) style_out = style_in;
3975 else style_out = style_in | WS_CLIPSIBLINGS;
3976 ok(style == style_out, "expected style %#x, got %#x\n", style_out, style);
3977 /* WS_EX_WINDOWEDGE can't always be changed */
3978 if (ex_style_in & WS_EX_DLGMODALFRAME)
3979 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
3980 else if ((style & (WS_DLGFRAME | WS_THICKFRAME)) && !(ex_style_in & WS_EX_STATICEDGE))
3981 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
3982 else
3983 ex_style_out = ex_style_in & ~WS_EX_WINDOWEDGE;
3984 /* FIXME: Remove the condition below once Wine is fixed */
3985 if (ex_style != ex_style_out)
3986 todo_wine ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
3987 else
3988 ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
3990 DestroyWindow(hwnd);
3991 DestroyWindow(parent);
3994 static void test_dialog_styles(void)
3996 check_dialog_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3997 check_dialog_style(WS_DLGFRAME, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3998 check_dialog_style(WS_THICKFRAME, 0, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3999 check_dialog_style(WS_DLGFRAME, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4000 check_dialog_style(WS_THICKFRAME, WS_EX_STATICEDGE, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4001 check_dialog_style(DS_CONTROL, 0, WS_CLIPSIBLINGS|WS_CAPTION|DS_CONTROL, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4002 check_dialog_style(WS_CAPTION, 0, WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4003 check_dialog_style(WS_BORDER, 0, WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4004 check_dialog_style(WS_DLGFRAME, 0, WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4005 check_dialog_style(WS_BORDER|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4006 check_dialog_style(WS_DLGFRAME|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4007 check_dialog_style(WS_CAPTION|WS_SYSMENU, 0, WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4008 check_dialog_style(WS_SYSMENU, 0, WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4009 check_dialog_style(WS_CAPTION|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4010 check_dialog_style(WS_SYSMENU|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4011 check_dialog_style(WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4012 check_dialog_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4013 check_dialog_style(WS_CHILD, 0, WS_CHILD, 0);
4014 check_dialog_style(WS_CHILD|WS_DLGFRAME, 0, WS_CHILD|WS_DLGFRAME, WS_EX_WINDOWEDGE);
4015 check_dialog_style(WS_CHILD|WS_THICKFRAME, 0, WS_CHILD|WS_THICKFRAME, WS_EX_WINDOWEDGE);
4016 check_dialog_style(WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE);
4017 check_dialog_style(WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE);
4018 check_dialog_style(WS_CHILD|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4019 check_dialog_style(WS_CHILD|WS_CAPTION, 0, WS_CHILD|WS_CAPTION, WS_EX_WINDOWEDGE);
4020 check_dialog_style(WS_CHILD|WS_BORDER, 0, WS_CHILD|WS_BORDER, 0);
4021 check_dialog_style(WS_CHILD|WS_DLGFRAME, 0, WS_CHILD|WS_DLGFRAME, WS_EX_WINDOWEDGE);
4022 check_dialog_style(WS_CHILD|WS_BORDER|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4023 check_dialog_style(WS_CHILD|WS_DLGFRAME|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4024 check_dialog_style(WS_CHILD|WS_CAPTION|WS_SYSMENU, 0, WS_CHILD|WS_CAPTION|WS_SYSMENU, WS_EX_WINDOWEDGE);
4025 check_dialog_style(WS_CHILD|WS_SYSMENU, 0, WS_CHILD|WS_SYSMENU, 0);
4026 check_dialog_style(WS_CHILD|WS_CAPTION|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4027 check_dialog_style(WS_CHILD|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4028 check_dialog_style(WS_CHILD|WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4029 check_dialog_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
4030 check_dialog_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
4031 check_dialog_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
4032 check_dialog_style(WS_CHILD|WS_POPUP, 0, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
4033 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, 0, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4034 check_dialog_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, 0, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4035 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
4036 check_dialog_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
4037 check_dialog_style(WS_CHILD|WS_POPUP|DS_CONTROL, 0, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS|DS_CONTROL, WS_EX_CONTROLPARENT);
4038 check_dialog_style(WS_CHILD|WS_POPUP|WS_CAPTION, 0, WS_CHILD|WS_POPUP|WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4039 check_dialog_style(WS_CHILD|WS_POPUP|WS_BORDER, 0, WS_CHILD|WS_POPUP|WS_BORDER|WS_CLIPSIBLINGS, 0);
4040 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, 0, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4041 check_dialog_style(WS_CHILD|WS_POPUP|WS_BORDER|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4042 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4043 check_dialog_style(WS_CHILD|WS_POPUP|WS_CAPTION|WS_SYSMENU, 0, WS_CHILD|WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4044 check_dialog_style(WS_CHILD|WS_POPUP|WS_SYSMENU, 0, WS_CHILD|WS_POPUP|WS_SYSMENU|WS_CLIPSIBLINGS, 0);
4045 check_dialog_style(WS_CHILD|WS_POPUP|WS_CAPTION|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4046 check_dialog_style(WS_CHILD|WS_POPUP|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4047 check_dialog_style(WS_CHILD|WS_POPUP|WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4048 check_dialog_style(WS_CHILD|WS_POPUP, WS_EX_APPWINDOW, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, WS_EX_APPWINDOW);
4049 check_dialog_style(WS_CHILD|WS_POPUP, WS_EX_WINDOWEDGE, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
4050 check_dialog_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
4051 check_dialog_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW|WS_EX_CONTROLPARENT);
4052 check_dialog_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4053 check_dialog_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4054 check_dialog_style(WS_POPUP|WS_DLGFRAME, 0, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4055 check_dialog_style(WS_POPUP|WS_THICKFRAME, 0, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4056 check_dialog_style(WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4057 check_dialog_style(WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4058 check_dialog_style(WS_POPUP|DS_CONTROL, 0, WS_POPUP|WS_CLIPSIBLINGS|DS_CONTROL, WS_EX_CONTROLPARENT);
4059 check_dialog_style(WS_POPUP|WS_CAPTION, 0, WS_POPUP|WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4060 check_dialog_style(WS_POPUP|WS_BORDER, 0, WS_POPUP|WS_BORDER|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4061 check_dialog_style(WS_POPUP|WS_DLGFRAME, 0, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4062 check_dialog_style(WS_POPUP|WS_BORDER|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4063 check_dialog_style(WS_POPUP|WS_DLGFRAME|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4064 check_dialog_style(WS_POPUP|WS_CAPTION|WS_SYSMENU, 0, WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4065 check_dialog_style(WS_POPUP|WS_SYSMENU, 0, WS_POPUP|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4066 check_dialog_style(WS_POPUP|WS_CAPTION|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4067 check_dialog_style(WS_POPUP|WS_SYSMENU|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4068 check_dialog_style(WS_POPUP|WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4069 check_dialog_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4070 check_dialog_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4072 if (pGetLayeredWindowAttributes)
4074 check_dialog_style(0, WS_EX_LAYERED, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4075 check_dialog_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4076 check_dialog_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION,
4077 WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4081 static void test_scrollwindow( HWND hwnd)
4083 HDC hdc;
4084 RECT rc, rc2, rc3;
4085 COLORREF colr;
4087 ShowWindow( hwnd, SW_SHOW);
4088 UpdateWindow( hwnd);
4089 flush_events( TRUE );
4090 GetClientRect( hwnd, &rc);
4091 hdc = GetDC( hwnd);
4092 /* test ScrollWindow(Ex) with no clip rectangle */
4093 /* paint the lower half of the window black */
4094 rc2 = rc;
4095 rc2.top = ( rc2.top + rc2.bottom) / 2;
4096 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4097 /* paint the upper half of the window white */
4098 rc2.bottom = rc2.top;
4099 rc2.top =0;
4100 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
4101 /* scroll lower half up */
4102 rc2 = rc;
4103 rc2.top = ( rc2.top + rc2.bottom) / 2;
4104 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, NULL, NULL, NULL, SW_ERASE);
4105 flush_events(FALSE);
4106 /* expected: black should have scrolled to the upper half */
4107 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
4108 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4109 /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
4110 /* paint the lower half of the window black */
4111 rc2 = rc;
4112 rc2.top = ( rc2.top + rc2.bottom) / 2;
4113 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4114 /* paint the upper half of the window white */
4115 rc2.bottom = rc2.top;
4116 rc2.top =0;
4117 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
4118 /* scroll lower half up */
4119 rc2 = rc;
4120 rc2.top = ( rc2.top + rc2.bottom) / 2;
4121 rc3 = rc;
4122 rc3.left = rc3.right / 4;
4123 rc3.right -= rc3.right / 4;
4124 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, &rc3, NULL, NULL, SW_ERASE);
4125 flush_events(FALSE);
4126 /* expected: black should have scrolled to the upper half */
4127 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
4128 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4130 /* clean up */
4131 ReleaseDC( hwnd, hdc);
4134 static void test_scrollvalidate( HWND parent)
4136 HDC hdc;
4137 HRGN hrgn=CreateRectRgn(0,0,0,0);
4138 HRGN exprgn, tmprgn, clipping;
4139 RECT rc, rcu, cliprc;
4140 /* create two overlapping child windows. The visual region
4141 * of hwnd1 is clipped by the overlapping part of
4142 * hwnd2 because of the WS_CLIPSIBLING style */
4143 HWND hwnd1, hwnd2;
4145 clipping = CreateRectRgn(0,0,0,0);
4146 tmprgn = CreateRectRgn(0,0,0,0);
4147 exprgn = CreateRectRgn(0,0,0,0);
4148 hwnd2 = CreateWindowExA(0, "static", NULL,
4149 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
4150 75, 30, 100, 100, parent, 0, 0, NULL);
4151 hwnd1 = CreateWindowExA(0, "static", NULL,
4152 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
4153 25, 50, 100, 100, parent, 0, 0, NULL);
4154 ShowWindow( parent, SW_SHOW);
4155 UpdateWindow( parent);
4156 GetClientRect( hwnd1, &rc);
4157 cliprc=rc;
4158 SetRectRgn( clipping, 10, 10, 90, 90);
4159 hdc = GetDC( hwnd1);
4160 /* for a visual touch */
4161 TextOutA( hdc, 0,10, "0123456789", 10);
4162 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
4163 if (winetest_debug > 0) dump_region(hrgn);
4164 /* create a region with what is expected */
4165 SetRectRgn( exprgn, 39,0,49,74);
4166 SetRectRgn( tmprgn, 88,79,98,93);
4167 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4168 SetRectRgn( tmprgn, 0,93,98,98);
4169 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4170 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4171 trace("update rect is %d,%d - %d,%d\n",
4172 rcu.left,rcu.top,rcu.right,rcu.bottom);
4173 /* now with clipping region */
4174 SelectClipRgn( hdc, clipping);
4175 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
4176 if (winetest_debug > 0) dump_region(hrgn);
4177 /* create a region with what is expected */
4178 SetRectRgn( exprgn, 39,10,49,74);
4179 SetRectRgn( tmprgn, 80,79,90,85);
4180 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4181 SetRectRgn( tmprgn, 10,85,90,90);
4182 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4183 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4184 trace("update rect is %d,%d - %d,%d\n",
4185 rcu.left,rcu.top,rcu.right,rcu.bottom);
4186 ReleaseDC( hwnd1, hdc);
4188 /* test scrolling a window with an update region */
4189 DestroyWindow( hwnd2);
4190 ValidateRect( hwnd1, NULL);
4191 SetRect( &rc, 40,40, 50,50);
4192 InvalidateRect( hwnd1, &rc, 1);
4193 GetClientRect( hwnd1, &rc);
4194 cliprc=rc;
4195 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
4196 SW_SCROLLCHILDREN | SW_INVALIDATE);
4197 if (winetest_debug > 0) dump_region(hrgn);
4198 SetRectRgn( exprgn, 88,0,98,98);
4199 SetRectRgn( tmprgn, 30, 40, 50, 50);
4200 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4201 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4203 /* clear an update region */
4204 UpdateWindow( hwnd1 );
4206 SetRect( &rc, 0,40, 100,60);
4207 SetRect( &cliprc, 0,0, 100,100);
4208 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
4209 if (winetest_debug > 0) dump_region( hrgn );
4210 SetRectRgn( exprgn, 0, 40, 98, 60 );
4211 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
4213 /* now test ScrollWindowEx with a combination of
4214 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
4215 /* make hwnd2 the child of hwnd1 */
4216 hwnd2 = CreateWindowExA(0, "static", NULL,
4217 WS_CHILD| WS_VISIBLE | WS_BORDER ,
4218 50, 50, 100, 100, hwnd1, 0, 0, NULL);
4219 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
4220 GetClientRect( hwnd1, &rc);
4221 cliprc=rc;
4223 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
4224 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
4225 ValidateRect( hwnd1, NULL);
4226 ValidateRect( hwnd2, NULL);
4227 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
4228 SW_SCROLLCHILDREN | SW_INVALIDATE);
4229 if (winetest_debug > 0) dump_region(hrgn);
4230 SetRectRgn( exprgn, 88,0,98,88);
4231 SetRectRgn( tmprgn, 0,88,98,98);
4232 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4233 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4235 /* SW_SCROLLCHILDREN */
4236 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
4237 ValidateRect( hwnd1, NULL);
4238 ValidateRect( hwnd2, NULL);
4239 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
4240 if (winetest_debug > 0) dump_region(hrgn);
4241 /* expected region is the same as in previous test */
4242 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4244 /* no SW_SCROLLCHILDREN */
4245 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
4246 ValidateRect( hwnd1, NULL);
4247 ValidateRect( hwnd2, NULL);
4248 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
4249 if (winetest_debug > 0) dump_region(hrgn);
4250 /* expected region is the same as in previous test */
4251 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4253 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
4254 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
4255 ValidateRect( hwnd1, NULL);
4256 ValidateRect( hwnd2, NULL);
4257 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
4258 if (winetest_debug > 0) dump_region(hrgn);
4259 SetRectRgn( exprgn, 88,0,98,20);
4260 SetRectRgn( tmprgn, 20,20,98,30);
4261 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4262 SetRectRgn( tmprgn, 20,30,30,88);
4263 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4264 SetRectRgn( tmprgn, 0,88,30,98);
4265 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4266 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4268 /* clean up */
4269 DeleteObject( hrgn);
4270 DeleteObject( exprgn);
4271 DeleteObject( tmprgn);
4272 DestroyWindow( hwnd1);
4273 DestroyWindow( hwnd2);
4276 /* couple of tests of return values of scrollbar functions
4277 * called on a scrollbarless window */
4278 static void test_scroll(void)
4280 BOOL ret;
4281 INT min, max;
4282 SCROLLINFO si;
4283 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
4284 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
4285 100, 100, 200, 200, 0, 0, 0, NULL);
4286 /* horizontal */
4287 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
4288 if (!ret) /* win9x */
4290 win_skip( "GetScrollRange doesn't work\n" );
4291 DestroyWindow( hwnd);
4292 return;
4294 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
4295 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
4296 si.cbSize = sizeof( si);
4297 si.fMask = SIF_PAGE;
4298 si.nPage = 0xdeadbeef;
4299 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
4300 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
4301 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
4302 /* vertical */
4303 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
4304 ok( ret, "GetScrollRange returns FALSE\n");
4305 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
4306 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
4307 si.cbSize = sizeof( si);
4308 si.fMask = SIF_PAGE;
4309 si.nPage = 0xdeadbeef;
4310 ret = GetScrollInfo( hwnd, SB_VERT, &si);
4311 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
4312 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
4313 /* clean up */
4314 DestroyWindow( hwnd);
4317 static void test_scrolldc( HWND parent)
4319 HDC hdc;
4320 HRGN exprgn, tmprgn, hrgn;
4321 RECT rc, rc2, rcu, cliprc;
4322 HWND hwnd1;
4323 COLORREF colr;
4325 hrgn = CreateRectRgn(0,0,0,0);
4326 tmprgn = CreateRectRgn(0,0,0,0);
4327 exprgn = CreateRectRgn(0,0,0,0);
4329 hwnd1 = CreateWindowExA(0, "static", NULL,
4330 WS_CHILD| WS_VISIBLE,
4331 25, 50, 100, 100, parent, 0, 0, NULL);
4332 ShowWindow( parent, SW_SHOW);
4333 UpdateWindow( parent);
4334 flush_events( TRUE );
4335 GetClientRect( hwnd1, &rc);
4336 hdc = GetDC( hwnd1);
4337 /* paint the upper half of the window black */
4338 rc2 = rc;
4339 rc2.bottom = ( rc.top + rc.bottom) /2;
4340 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4341 /* clip region is the lower half */
4342 cliprc=rc;
4343 cliprc.top = (rc.top + rc.bottom) /2;
4344 /* test whether scrolled pixels are properly clipped */
4345 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
4346 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4347 /* this scroll should not cause any visible changes */
4348 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
4349 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
4350 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4351 /* test with NULL clip rect */
4352 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
4353 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
4354 trace("update rect: %d,%d - %d,%d\n",
4355 rcu.left, rcu.top, rcu.right, rcu.bottom);
4356 if (winetest_debug > 0) dump_region(hrgn);
4357 SetRect(&rc2, 0, 0, 100, 100);
4358 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
4359 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
4361 SetRectRgn( exprgn, 0, 0, 20, 80);
4362 SetRectRgn( tmprgn, 0, 80, 100, 100);
4363 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
4364 if (winetest_debug > 0) dump_region(exprgn);
4365 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
4366 /* test clip rect > scroll rect */
4367 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
4368 rc2=rc;
4369 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
4370 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4371 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
4372 SetRectRgn( exprgn, 25, 25, 75, 35);
4373 SetRectRgn( tmprgn, 25, 35, 35, 75);
4374 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
4375 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
4376 trace("update rect: %d,%d - %d,%d\n",
4377 rcu.left, rcu.top, rcu.right, rcu.bottom);
4378 if (winetest_debug > 0) dump_region(hrgn);
4380 /* clean up */
4381 DeleteObject(hrgn);
4382 DeleteObject(exprgn);
4383 DeleteObject(tmprgn);
4384 DestroyWindow(hwnd1);
4387 static void test_params(void)
4389 HWND hwnd;
4390 INT rc;
4392 ok(!IsWindow(0), "IsWindow(0)\n");
4393 ok(!IsWindow(HWND_BROADCAST), "IsWindow(HWND_BROADCAST)\n");
4394 ok(!IsWindow(HWND_TOPMOST), "IsWindow(HWND_TOPMOST)\n");
4396 /* Just a param check */
4397 if (pGetMonitorInfoA)
4399 SetLastError(0xdeadbeef);
4400 rc = GetWindowTextA(hwndMain2, NULL, 1024);
4401 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
4403 else
4405 /* Skips actually on Win95 and NT4 */
4406 win_skip("Test would crash on Win95\n");
4409 SetLastError(0xdeadbeef);
4410 hwnd=CreateWindowA("LISTBOX", "TestList",
4411 (LBS_STANDARD & ~LBS_SORT),
4412 0, 0, 100, 100,
4413 NULL, (HMENU)1, NULL, 0);
4415 ok(!hwnd || broken(hwnd != NULL), /* w2k3 sp2 */
4416 "CreateWindow with invalid menu handle should fail\n");
4417 if (!hwnd)
4418 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
4419 GetLastError() == 0xdeadbeef, /* Win9x */
4420 "wrong last error value %d\n", GetLastError());
4423 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
4425 HWND hwnd = 0;
4427 hwnd = CreateWindowExA(exStyle, class, class, style,
4428 110, 100,
4429 225, 200,
4431 menu ? hmenu : 0,
4432 0, 0);
4433 if (!hwnd) {
4434 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
4435 return;
4437 ShowWindow(hwnd, SW_SHOW);
4439 test_nonclient_area(hwnd);
4441 SetMenu(hwnd, 0);
4442 DestroyWindow(hwnd);
4445 static BOOL AWR_init(void)
4447 WNDCLASSA class;
4449 class.style = CS_HREDRAW | CS_VREDRAW;
4450 class.lpfnWndProc = DefWindowProcA;
4451 class.cbClsExtra = 0;
4452 class.cbWndExtra = 0;
4453 class.hInstance = 0;
4454 class.hIcon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
4455 class.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
4456 class.hbrBackground = 0;
4457 class.lpszMenuName = 0;
4458 class.lpszClassName = szAWRClass;
4460 if (!RegisterClassA(&class)) {
4461 ok(FALSE, "RegisterClass failed\n");
4462 return FALSE;
4465 hmenu = CreateMenu();
4466 if (!hmenu)
4467 return FALSE;
4468 ok(hmenu != 0, "Failed to create menu\n");
4469 ok(AppendMenuA(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
4471 return TRUE;
4475 static void test_AWR_window_size(BOOL menu)
4477 LONG styles[] = {
4478 WS_POPUP,
4479 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
4480 WS_SYSMENU,
4481 WS_THICKFRAME,
4482 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
4483 WS_HSCROLL, WS_VSCROLL
4485 LONG exStyles[] = {
4486 WS_EX_CLIENTEDGE,
4487 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
4488 WS_EX_APPWINDOW,
4489 #if 0
4490 /* These styles have problems on (at least) WinXP (SP2) and Wine */
4491 WS_EX_DLGMODALFRAME,
4492 WS_EX_STATICEDGE,
4493 #endif
4496 int i;
4498 /* A exhaustive check of all the styles takes too long
4499 * so just do a (hopefully representative) sample
4501 for (i = 0; i < COUNTOF(styles); ++i)
4502 test_AWRwindow(szAWRClass, styles[i], 0, menu);
4503 for (i = 0; i < COUNTOF(exStyles); ++i) {
4504 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
4505 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
4508 #undef COUNTOF
4510 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
4512 static void test_AdjustWindowRect(void)
4514 if (!AWR_init())
4515 return;
4517 SHOWSYSMETRIC(SM_CYCAPTION);
4518 SHOWSYSMETRIC(SM_CYSMCAPTION);
4519 SHOWSYSMETRIC(SM_CYMENU);
4520 SHOWSYSMETRIC(SM_CXEDGE);
4521 SHOWSYSMETRIC(SM_CYEDGE);
4522 SHOWSYSMETRIC(SM_CXVSCROLL);
4523 SHOWSYSMETRIC(SM_CYHSCROLL);
4524 SHOWSYSMETRIC(SM_CXFRAME);
4525 SHOWSYSMETRIC(SM_CYFRAME);
4526 SHOWSYSMETRIC(SM_CXDLGFRAME);
4527 SHOWSYSMETRIC(SM_CYDLGFRAME);
4528 SHOWSYSMETRIC(SM_CXBORDER);
4529 SHOWSYSMETRIC(SM_CYBORDER);
4531 test_AWR_window_size(FALSE);
4532 test_AWR_window_size(TRUE);
4534 DestroyMenu(hmenu);
4536 #undef SHOWSYSMETRIC
4539 /* Global variables to trigger exit from loop */
4540 static int redrawComplete, WMPAINT_count;
4542 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4544 switch (msg)
4546 case WM_PAINT:
4547 trace("doing WM_PAINT %d\n", WMPAINT_count);
4548 WMPAINT_count++;
4549 if (WMPAINT_count > 10 && redrawComplete == 0) {
4550 PAINTSTRUCT ps;
4551 BeginPaint(hwnd, &ps);
4552 EndPaint(hwnd, &ps);
4553 return 1;
4555 return 0;
4557 return DefWindowProcA(hwnd, msg, wparam, lparam);
4560 /* Ensure we exit from RedrawNow regardless of invalidated area */
4561 static void test_redrawnow(void)
4563 WNDCLASSA cls;
4564 HWND hwndMain;
4566 cls.style = CS_DBLCLKS;
4567 cls.lpfnWndProc = redraw_window_procA;
4568 cls.cbClsExtra = 0;
4569 cls.cbWndExtra = 0;
4570 cls.hInstance = GetModuleHandleA(0);
4571 cls.hIcon = 0;
4572 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
4573 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4574 cls.lpszMenuName = NULL;
4575 cls.lpszClassName = "RedrawWindowClass";
4577 if(!RegisterClassA(&cls)) {
4578 trace("Register failed %d\n", GetLastError());
4579 return;
4582 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
4583 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
4585 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4586 ShowWindow(hwndMain, SW_SHOW);
4587 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4588 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
4589 ok( WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
4590 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4591 redrawComplete = TRUE;
4592 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
4594 /* clean up */
4595 DestroyWindow( hwndMain);
4598 struct parentdc_stat {
4599 RECT client;
4600 RECT clip;
4601 RECT paint;
4604 struct parentdc_test {
4605 struct parentdc_stat main, main_todo;
4606 struct parentdc_stat child1, child1_todo;
4607 struct parentdc_stat child2, child2_todo;
4610 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4612 RECT rc;
4613 PAINTSTRUCT ps;
4615 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
4617 switch (msg)
4619 case WM_PAINT:
4620 GetClientRect(hwnd, &rc);
4621 CopyRect(&t->client, &rc);
4622 GetWindowRect(hwnd, &rc);
4623 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd,
4624 t->client.left, t->client.top, t->client.right, t->client.bottom,
4625 rc.left, rc.top, rc.right, rc.bottom);
4626 BeginPaint(hwnd, &ps);
4627 CopyRect(&t->paint, &ps.rcPaint);
4628 GetClipBox(ps.hdc, &rc);
4629 CopyRect(&t->clip, &rc);
4630 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
4631 rc.left, rc.top, rc.right, rc.bottom,
4632 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
4633 EndPaint(hwnd, &ps);
4634 return 0;
4636 return DefWindowProcA(hwnd, msg, wparam, lparam);
4639 static void zero_parentdc_stat(struct parentdc_stat *t)
4641 SetRectEmpty(&t->client);
4642 SetRectEmpty(&t->clip);
4643 SetRectEmpty(&t->paint);
4646 static void zero_parentdc_test(struct parentdc_test *t)
4648 zero_parentdc_stat(&t->main);
4649 zero_parentdc_stat(&t->child1);
4650 zero_parentdc_stat(&t->child2);
4653 #define parentdc_field_ok(t, w, r, f, got) \
4654 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
4655 ": expected %d, got %d\n", \
4656 t.w.r.f, got.w.r.f)
4658 #define parentdc_todo_field_ok(t, w, r, f, got) \
4659 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
4660 else parentdc_field_ok(t, w, r, f, got)
4662 #define parentdc_rect_ok(t, w, r, got) \
4663 parentdc_todo_field_ok(t, w, r, left, got); \
4664 parentdc_todo_field_ok(t, w, r, top, got); \
4665 parentdc_todo_field_ok(t, w, r, right, got); \
4666 parentdc_todo_field_ok(t, w, r, bottom, got);
4668 #define parentdc_win_ok(t, w, got) \
4669 parentdc_rect_ok(t, w, client, got); \
4670 parentdc_rect_ok(t, w, clip, got); \
4671 parentdc_rect_ok(t, w, paint, got);
4673 #define parentdc_ok(t, got) \
4674 parentdc_win_ok(t, main, got); \
4675 parentdc_win_ok(t, child1, got); \
4676 parentdc_win_ok(t, child2, got);
4678 static void test_csparentdc(void)
4680 WNDCLASSA clsMain, cls;
4681 HWND hwndMain, hwnd1, hwnd2;
4682 RECT rc;
4684 struct parentdc_test test_answer;
4686 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
4687 const struct parentdc_test test1 =
4689 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
4690 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4691 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4694 const struct parentdc_test test2 =
4696 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
4697 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4698 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4701 const struct parentdc_test test3 =
4703 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4704 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4705 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4708 const struct parentdc_test test4 =
4710 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
4711 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
4712 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4715 const struct parentdc_test test5 =
4717 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
4718 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4719 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4722 const struct parentdc_test test6 =
4724 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4725 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4726 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4729 const struct parentdc_test test7 =
4731 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4732 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4733 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4735 #undef nothing_todo
4737 clsMain.style = CS_DBLCLKS;
4738 clsMain.lpfnWndProc = parentdc_window_procA;
4739 clsMain.cbClsExtra = 0;
4740 clsMain.cbWndExtra = 0;
4741 clsMain.hInstance = GetModuleHandleA(0);
4742 clsMain.hIcon = 0;
4743 clsMain.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
4744 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
4745 clsMain.lpszMenuName = NULL;
4746 clsMain.lpszClassName = "ParentDcMainWindowClass";
4748 if(!RegisterClassA(&clsMain)) {
4749 trace("Register failed %d\n", GetLastError());
4750 return;
4753 cls.style = CS_DBLCLKS | CS_PARENTDC;
4754 cls.lpfnWndProc = parentdc_window_procA;
4755 cls.cbClsExtra = 0;
4756 cls.cbWndExtra = 0;
4757 cls.hInstance = GetModuleHandleA(0);
4758 cls.hIcon = 0;
4759 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
4760 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4761 cls.lpszMenuName = NULL;
4762 cls.lpszClassName = "ParentDcWindowClass";
4764 if(!RegisterClassA(&cls)) {
4765 trace("Register failed %d\n", GetLastError());
4766 return;
4769 SetRect(&rc, 0, 0, 150, 150);
4770 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
4771 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
4772 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
4773 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
4774 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
4775 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
4776 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
4777 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
4778 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
4779 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
4780 ShowWindow(hwndMain, SW_SHOW);
4781 ShowWindow(hwnd1, SW_SHOW);
4782 ShowWindow(hwnd2, SW_SHOW);
4783 SetWindowPos(hwndMain, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
4784 flush_events( TRUE );
4786 zero_parentdc_test(&test_answer);
4787 InvalidateRect(hwndMain, NULL, TRUE);
4788 flush_events( TRUE );
4789 parentdc_ok(test1, test_answer);
4791 zero_parentdc_test(&test_answer);
4792 SetRect(&rc, 0, 0, 50, 50);
4793 InvalidateRect(hwndMain, &rc, TRUE);
4794 flush_events( TRUE );
4795 parentdc_ok(test2, test_answer);
4797 zero_parentdc_test(&test_answer);
4798 SetRect(&rc, 0, 0, 10, 10);
4799 InvalidateRect(hwndMain, &rc, TRUE);
4800 flush_events( TRUE );
4801 parentdc_ok(test3, test_answer);
4803 zero_parentdc_test(&test_answer);
4804 SetRect(&rc, 40, 40, 50, 50);
4805 InvalidateRect(hwndMain, &rc, TRUE);
4806 flush_events( TRUE );
4807 parentdc_ok(test4, test_answer);
4809 zero_parentdc_test(&test_answer);
4810 SetRect(&rc, 20, 20, 60, 60);
4811 InvalidateRect(hwndMain, &rc, TRUE);
4812 flush_events( TRUE );
4813 parentdc_ok(test5, test_answer);
4815 zero_parentdc_test(&test_answer);
4816 SetRect(&rc, 0, 0, 10, 10);
4817 InvalidateRect(hwnd1, &rc, TRUE);
4818 flush_events( TRUE );
4819 parentdc_ok(test6, test_answer);
4821 zero_parentdc_test(&test_answer);
4822 SetRect(&rc, -5, -5, 65, 65);
4823 InvalidateRect(hwnd1, &rc, TRUE);
4824 flush_events( TRUE );
4825 parentdc_ok(test7, test_answer);
4827 DestroyWindow(hwndMain);
4828 DestroyWindow(hwnd1);
4829 DestroyWindow(hwnd2);
4832 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4834 return DefWindowProcA(hwnd, msg, wparam, lparam);
4837 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4839 return DefWindowProcW(hwnd, msg, wparam, lparam);
4842 static void test_IsWindowUnicode(void)
4844 static const char ansi_class_nameA[] = "ansi class name";
4845 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
4846 static const char unicode_class_nameA[] = "unicode class name";
4847 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
4848 WNDCLASSA classA;
4849 WNDCLASSW classW;
4850 HWND hwnd;
4852 memset(&classW, 0, sizeof(classW));
4853 classW.hInstance = GetModuleHandleA(0);
4854 classW.lpfnWndProc = def_window_procW;
4855 classW.lpszClassName = unicode_class_nameW;
4856 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
4858 memset(&classA, 0, sizeof(classA));
4859 classA.hInstance = GetModuleHandleA(0);
4860 classA.lpfnWndProc = def_window_procA;
4861 classA.lpszClassName = ansi_class_nameA;
4862 assert(RegisterClassA(&classA));
4864 /* unicode class: window proc */
4865 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4866 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4867 assert(hwnd);
4869 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4870 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4871 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4872 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4873 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4875 DestroyWindow(hwnd);
4877 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4878 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4879 assert(hwnd);
4881 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4882 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4883 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4884 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4885 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4887 DestroyWindow(hwnd);
4889 /* ansi class: window proc */
4890 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4891 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4892 assert(hwnd);
4894 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4895 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4896 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4897 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4898 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4900 DestroyWindow(hwnd);
4902 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4903 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4904 assert(hwnd);
4906 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4907 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4908 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4909 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4910 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4912 DestroyWindow(hwnd);
4914 /* unicode class: class proc */
4915 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4916 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4917 assert(hwnd);
4919 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4920 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4921 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4922 /* do not restore class window proc back to unicode */
4924 DestroyWindow(hwnd);
4926 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4927 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4928 assert(hwnd);
4930 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4931 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4932 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4934 DestroyWindow(hwnd);
4936 /* ansi class: class proc */
4937 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4938 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4939 assert(hwnd);
4941 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4942 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4943 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4944 /* do not restore class window proc back to ansi */
4946 DestroyWindow(hwnd);
4948 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4949 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4950 assert(hwnd);
4952 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4953 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4954 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4956 DestroyWindow(hwnd);
4959 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4961 MINMAXINFO *minmax;
4963 if (msg != WM_GETMINMAXINFO)
4964 return DefWindowProcA(hwnd, msg, wp, lp);
4966 minmax = (MINMAXINFO *)lp;
4968 if ((GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
4970 minmax->ptReserved.x = 0;
4971 minmax->ptReserved.y = 0;
4972 minmax->ptMaxSize.x = 400;
4973 minmax->ptMaxSize.y = 400;
4974 minmax->ptMaxPosition.x = 300;
4975 minmax->ptMaxPosition.y = 300;
4976 minmax->ptMaxTrackSize.x = 200;
4977 minmax->ptMaxTrackSize.y = 200;
4978 minmax->ptMinTrackSize.x = 100;
4979 minmax->ptMinTrackSize.y = 100;
4981 else
4982 DefWindowProcA(hwnd, msg, wp, lp);
4983 return 1;
4986 static int expected_cx, expected_cy;
4987 static RECT expected_rect, broken_rect;
4989 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4991 switch(msg)
4993 case WM_GETMINMAXINFO:
4995 RECT rect;
4996 GetWindowRect( hwnd, &rect );
4997 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
4998 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4999 return DefWindowProcA(hwnd, msg, wp, lp);
5001 case WM_NCCREATE:
5002 case WM_CREATE:
5004 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
5005 RECT rect;
5006 GetWindowRect( hwnd, &rect );
5007 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
5008 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
5009 ok( cs->cx == expected_cx || broken(cs->cx == (short)expected_cx),
5010 "wrong x size %d/%d\n", cs->cx, expected_cx );
5011 ok( cs->cy == expected_cy || broken(cs->cy == (short)expected_cy),
5012 "wrong y size %d/%d\n", cs->cy, expected_cy );
5013 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
5014 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
5015 (rect.right - rect.left == min( 65535, expected_rect.right - expected_rect.left ) &&
5016 rect.bottom - rect.top == min( 65535, expected_rect.bottom - expected_rect.top )) ||
5017 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
5018 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top) ||
5019 broken( rect.right - rect.left == (short)broken_rect.right - (short)broken_rect.left &&
5020 rect.bottom - rect.top == (short)broken_rect.bottom - (short)broken_rect.top),
5021 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
5022 rect.left, rect.top, rect.right, rect.bottom,
5023 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
5024 return DefWindowProcA(hwnd, msg, wp, lp);
5026 case WM_NCCALCSIZE:
5028 RECT rect, *r = (RECT *)lp;
5029 GetWindowRect( hwnd, &rect );
5030 ok( !memcmp( &rect, r, sizeof(rect) ),
5031 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
5032 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
5033 return DefWindowProcA(hwnd, msg, wp, lp);
5035 default:
5036 return DefWindowProcA(hwnd, msg, wp, lp);
5040 static void test_CreateWindow(void)
5042 WNDCLASSA cls;
5043 HWND hwnd, parent;
5044 HMENU hmenu;
5045 RECT rc, rc_minmax;
5046 MINMAXINFO minmax;
5047 BOOL res;
5049 #define expect_menu(window, menu) \
5050 SetLastError(0xdeadbeef); \
5051 res = (GetMenu(window) == (HMENU)menu); \
5052 ok(res, "GetMenu error %d\n", GetLastError())
5054 #define expect_style(window, style)\
5055 ok((ULONG)GetWindowLongA(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLongA(window, GWL_STYLE))
5057 #define expect_ex_style(window, ex_style)\
5058 ok((ULONG)GetWindowLongA(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLongA(window, GWL_EXSTYLE))
5060 #define expect_gle_broken_9x(gle)\
5061 ok(GetLastError() == gle ||\
5062 broken(GetLastError() == 0xdeadbeef),\
5063 "IsMenu set error %d\n", GetLastError())
5065 hmenu = CreateMenu();
5066 assert(hmenu != 0);
5067 parent = GetDesktopWindow();
5068 assert(parent != 0);
5070 SetLastError(0xdeadbeef);
5071 res = IsMenu(hmenu);
5072 ok(res, "IsMenu error %d\n", GetLastError());
5074 /* WS_CHILD */
5075 SetLastError(0xdeadbeef);
5076 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
5077 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5078 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5079 expect_menu(hwnd, 1);
5080 expect_style(hwnd, WS_CHILD);
5081 expect_ex_style(hwnd, WS_EX_APPWINDOW);
5082 DestroyWindow(hwnd);
5084 SetLastError(0xdeadbeef);
5085 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
5086 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5087 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5088 expect_menu(hwnd, 1);
5089 expect_style(hwnd, WS_CHILD | WS_CAPTION);
5090 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
5091 DestroyWindow(hwnd);
5093 SetLastError(0xdeadbeef);
5094 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD,
5095 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5096 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5097 expect_menu(hwnd, 1);
5098 expect_style(hwnd, WS_CHILD);
5099 expect_ex_style(hwnd, 0);
5100 DestroyWindow(hwnd);
5102 SetLastError(0xdeadbeef);
5103 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_CAPTION,
5104 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5105 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5106 expect_menu(hwnd, 1);
5107 expect_style(hwnd, WS_CHILD | WS_CAPTION);
5108 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5109 DestroyWindow(hwnd);
5111 /* WS_POPUP */
5112 SetLastError(0xdeadbeef);
5113 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
5114 0, 0, 100, 100, parent, hmenu, 0, NULL);
5115 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5116 expect_menu(hwnd, hmenu);
5117 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
5118 expect_ex_style(hwnd, WS_EX_APPWINDOW);
5119 DestroyWindow(hwnd);
5120 SetLastError(0xdeadbeef);
5121 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5122 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5124 hmenu = CreateMenu();
5125 assert(hmenu != 0);
5126 SetLastError(0xdeadbeef);
5127 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
5128 0, 0, 100, 100, parent, hmenu, 0, NULL);
5129 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5130 expect_menu(hwnd, hmenu);
5131 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5132 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
5133 DestroyWindow(hwnd);
5134 SetLastError(0xdeadbeef);
5135 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5136 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5138 hmenu = CreateMenu();
5139 assert(hmenu != 0);
5140 SetLastError(0xdeadbeef);
5141 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
5142 0, 0, 100, 100, parent, hmenu, 0, NULL);
5143 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5144 expect_menu(hwnd, hmenu);
5145 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
5146 expect_ex_style(hwnd, 0);
5147 DestroyWindow(hwnd);
5148 SetLastError(0xdeadbeef);
5149 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5150 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5152 hmenu = CreateMenu();
5153 assert(hmenu != 0);
5154 SetLastError(0xdeadbeef);
5155 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP | WS_CAPTION,
5156 0, 0, 100, 100, parent, hmenu, 0, NULL);
5157 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5158 expect_menu(hwnd, hmenu);
5159 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5160 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5161 DestroyWindow(hwnd);
5162 SetLastError(0xdeadbeef);
5163 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5164 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5166 /* WS_CHILD | WS_POPUP */
5167 SetLastError(0xdeadbeef);
5168 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
5169 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5170 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
5171 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5172 if (hwnd)
5173 DestroyWindow(hwnd);
5175 hmenu = CreateMenu();
5176 assert(hmenu != 0);
5177 SetLastError(0xdeadbeef);
5178 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
5179 0, 0, 100, 100, parent, hmenu, 0, NULL);
5180 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5181 expect_menu(hwnd, hmenu);
5182 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
5183 expect_ex_style(hwnd, WS_EX_APPWINDOW);
5184 DestroyWindow(hwnd);
5185 SetLastError(0xdeadbeef);
5186 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5187 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5189 SetLastError(0xdeadbeef);
5190 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
5191 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5192 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
5193 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5194 if (hwnd)
5195 DestroyWindow(hwnd);
5197 hmenu = CreateMenu();
5198 assert(hmenu != 0);
5199 SetLastError(0xdeadbeef);
5200 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
5201 0, 0, 100, 100, parent, hmenu, 0, NULL);
5202 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5203 expect_menu(hwnd, hmenu);
5204 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5205 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
5206 DestroyWindow(hwnd);
5207 SetLastError(0xdeadbeef);
5208 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5209 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5211 SetLastError(0xdeadbeef);
5212 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP,
5213 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5214 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
5215 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5216 if (hwnd)
5217 DestroyWindow(hwnd);
5219 hmenu = CreateMenu();
5220 assert(hmenu != 0);
5221 SetLastError(0xdeadbeef);
5222 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP,
5223 0, 0, 100, 100, parent, hmenu, 0, NULL);
5224 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5225 expect_menu(hwnd, hmenu);
5226 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
5227 expect_ex_style(hwnd, 0);
5228 DestroyWindow(hwnd);
5229 SetLastError(0xdeadbeef);
5230 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5231 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5233 SetLastError(0xdeadbeef);
5234 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
5235 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5236 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
5237 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5238 if (hwnd)
5239 DestroyWindow(hwnd);
5241 hmenu = CreateMenu();
5242 assert(hmenu != 0);
5243 SetLastError(0xdeadbeef);
5244 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
5245 0, 0, 100, 100, parent, hmenu, 0, NULL);
5246 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5247 expect_menu(hwnd, hmenu);
5248 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5249 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5250 DestroyWindow(hwnd);
5251 SetLastError(0xdeadbeef);
5252 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5253 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5255 /* test child window sizing */
5256 cls.style = 0;
5257 cls.lpfnWndProc = minmax_wnd_proc;
5258 cls.cbClsExtra = 0;
5259 cls.cbWndExtra = 0;
5260 cls.hInstance = GetModuleHandleA(NULL);
5261 cls.hIcon = 0;
5262 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
5263 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5264 cls.lpszMenuName = NULL;
5265 cls.lpszClassName = "MinMax_WndClass";
5266 RegisterClassA(&cls);
5268 SetLastError(0xdeadbeef);
5269 parent = CreateWindowExA(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
5270 0, 0, 100, 100, 0, 0, 0, NULL);
5271 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
5272 expect_menu(parent, 0);
5273 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
5274 expect_ex_style(parent, WS_EX_WINDOWEDGE);
5276 memset(&minmax, 0, sizeof(minmax));
5277 SendMessageA(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
5278 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
5279 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
5280 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
5281 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
5283 GetWindowRect(parent, &rc);
5284 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
5285 GetClientRect(parent, &rc);
5286 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
5288 InflateRect(&rc, 200, 200);
5289 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
5291 SetLastError(0xdeadbeef);
5292 hwnd = CreateWindowExA(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
5293 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
5294 parent, (HMENU)1, 0, NULL);
5295 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5296 expect_menu(hwnd, 1);
5297 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
5298 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5300 memset(&minmax, 0, sizeof(minmax));
5301 SendMessageA(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
5302 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
5304 GetWindowRect(hwnd, &rc);
5305 OffsetRect(&rc, -rc.left, -rc.top);
5306 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
5307 rc.left, rc.top, rc.right, rc.bottom,
5308 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
5309 DestroyWindow(hwnd);
5311 cls.lpfnWndProc = winsizes_wnd_proc;
5312 cls.lpszClassName = "Sizes_WndClass";
5313 RegisterClassA(&cls);
5315 expected_cx = expected_cy = 200000;
5316 SetRect( &expected_rect, 0, 0, 200000, 200000 );
5317 broken_rect = expected_rect;
5318 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
5319 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5320 GetClientRect( hwnd, &rc );
5321 ok( rc.right == 200000 || rc.right == 65535 || broken(rc.right == (short)200000),
5322 "invalid rect right %u\n", rc.right );
5323 ok( rc.bottom == 200000 || rc.bottom == 65535 || broken(rc.bottom == (short)200000),
5324 "invalid rect bottom %u\n", rc.bottom );
5325 DestroyWindow(hwnd);
5327 expected_cx = expected_cy = -10;
5328 SetRect( &expected_rect, 0, 0, 0, 0 );
5329 SetRect( &broken_rect, 0, 0, -10, -10 );
5330 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
5331 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5332 GetClientRect( hwnd, &rc );
5333 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
5334 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
5335 DestroyWindow(hwnd);
5337 expected_cx = expected_cy = -200000;
5338 SetRect( &expected_rect, 0, 0, 0, 0 );
5339 SetRect( &broken_rect, 0, 0, -200000, -200000 );
5340 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
5341 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5342 GetClientRect( hwnd, &rc );
5343 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
5344 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
5345 DestroyWindow(hwnd);
5347 /* we need a parent at 0,0 so that child coordinates match */
5348 DestroyWindow(parent);
5349 parent = CreateWindowExA(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
5350 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
5352 expected_cx = 100;
5353 expected_cy = 0x7fffffff;
5354 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
5355 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
5356 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
5357 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5358 GetClientRect( hwnd, &rc );
5359 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
5360 ok( rc.bottom == 0x7fffffff - 10 || rc.bottom ==65535 || broken(rc.bottom == 0),
5361 "invalid rect bottom %u\n", rc.bottom );
5362 DestroyWindow(hwnd);
5364 expected_cx = 0x7fffffff;
5365 expected_cy = 0x7fffffff;
5366 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
5367 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
5368 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
5369 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5370 GetClientRect( hwnd, &rc );
5371 ok( rc.right == 0x7fffffff - 20 || rc.right == 65535 || broken(rc.right == 0),
5372 "invalid rect right %u\n", rc.right );
5373 ok( rc.bottom == 0x7fffffff - 10 || rc.right == 65535 || broken(rc.bottom == 0),
5374 "invalid rect bottom %u\n", rc.bottom );
5375 DestroyWindow(hwnd);
5377 /* top level window */
5378 expected_cx = expected_cy = 200000;
5379 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
5380 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
5381 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5382 GetClientRect( hwnd, &rc );
5383 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
5384 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
5385 DestroyWindow(hwnd);
5387 if (pGetLayout && pSetLayout)
5389 HDC hdc = GetDC( parent );
5390 pSetLayout( hdc, LAYOUT_RTL );
5391 if (pGetLayout( hdc ))
5393 ReleaseDC( parent, hdc );
5394 DestroyWindow( parent );
5395 SetLastError( 0xdeadbeef );
5396 parent = CreateWindowExA(WS_EX_APPWINDOW | WS_EX_LAYOUTRTL, "static", NULL, WS_POPUP,
5397 0, 0, 100, 100, 0, 0, 0, NULL);
5398 ok( parent != 0, "creation failed err %u\n", GetLastError());
5399 expect_ex_style( parent, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
5400 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 20, 20, parent, 0, 0, NULL);
5401 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5402 expect_ex_style( hwnd, WS_EX_LAYOUTRTL );
5403 DestroyWindow( hwnd );
5404 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 20, 20, parent, 0, 0, NULL);
5405 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5406 expect_ex_style( hwnd, 0 );
5407 DestroyWindow( hwnd );
5408 SetWindowLongW( parent, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT );
5409 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 20, 20, parent, 0, 0, NULL);
5410 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5411 expect_ex_style( hwnd, 0 );
5412 DestroyWindow( hwnd );
5414 if (pGetProcessDefaultLayout && pSetProcessDefaultLayout)
5416 DWORD layout;
5418 SetLastError( 0xdeadbeef );
5419 ok( !pGetProcessDefaultLayout( NULL ), "GetProcessDefaultLayout succeeded\n" );
5420 ok( GetLastError() == ERROR_NOACCESS, "wrong error %u\n", GetLastError() );
5421 SetLastError( 0xdeadbeef );
5422 res = pGetProcessDefaultLayout( &layout );
5423 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
5424 ok( layout == 0, "GetProcessDefaultLayout wrong layout %x\n", layout );
5425 SetLastError( 0xdeadbeef );
5426 res = pSetProcessDefaultLayout( 7 );
5427 ok( res, "SetProcessDefaultLayout failed err %u\n", GetLastError ());
5428 res = pGetProcessDefaultLayout( &layout );
5429 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
5430 ok( layout == 7, "GetProcessDefaultLayout wrong layout %x\n", layout );
5431 SetLastError( 0xdeadbeef );
5432 res = pSetProcessDefaultLayout( LAYOUT_RTL );
5433 ok( res, "SetProcessDefaultLayout failed err %u\n", GetLastError ());
5434 res = pGetProcessDefaultLayout( &layout );
5435 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
5436 ok( layout == LAYOUT_RTL, "GetProcessDefaultLayout wrong layout %x\n", layout );
5437 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
5438 0, 0, 100, 100, 0, 0, 0, NULL);
5439 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5440 expect_ex_style( hwnd, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
5441 DestroyWindow( hwnd );
5442 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
5443 0, 0, 100, 100, parent, 0, 0, NULL);
5444 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5445 expect_ex_style( hwnd, WS_EX_APPWINDOW );
5446 DestroyWindow( hwnd );
5447 pSetProcessDefaultLayout( 0 );
5449 else win_skip( "SetProcessDefaultLayout not supported\n" );
5451 else win_skip( "SetLayout not supported\n" );
5453 else win_skip( "SetLayout not available\n" );
5455 DestroyWindow(parent);
5457 UnregisterClassA("MinMax_WndClass", GetModuleHandleA(NULL));
5458 UnregisterClassA("Sizes_WndClass", GetModuleHandleA(NULL));
5460 #undef expect_gle_broken_9x
5461 #undef expect_menu
5462 #undef expect_style
5463 #undef expect_ex_style
5466 /* function that remembers whether the system the test is running on sets the
5467 * last error for user32 functions to make the tests stricter */
5468 static int check_error(DWORD actual, DWORD expected)
5470 static int sets_last_error = -1;
5471 if (sets_last_error == -1)
5472 sets_last_error = (actual != 0xdeadbeef);
5473 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
5476 static void test_SetWindowLong(void)
5478 LONG_PTR retval;
5479 WNDPROC old_window_procW;
5481 SetLastError(0xdeadbeef);
5482 retval = SetWindowLongPtrA(NULL, GWLP_WNDPROC, 0);
5483 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
5484 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
5485 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instead of %d\n", GetLastError());
5487 SetLastError(0xdeadbeef);
5488 retval = SetWindowLongPtrA(hwndMain, 0xdeadbeef, 0);
5489 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
5490 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
5491 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instead of %d\n", GetLastError());
5493 SetLastError(0xdeadbeef);
5494 retval = SetWindowLongPtrA(hwndMain, GWLP_WNDPROC, 0);
5495 ok((WNDPROC)retval == main_window_procA || broken(!retval), /* win9x */
5496 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
5497 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
5498 retval = GetWindowLongPtrA(hwndMain, GWLP_WNDPROC);
5499 ok((WNDPROC)retval == main_window_procA,
5500 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
5501 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
5503 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
5504 SetLastError(0xdeadbeef);
5505 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
5506 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
5508 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
5509 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
5510 ok((WNDPROC)retval == old_window_procW,
5511 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
5512 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
5514 /* set it back to ANSI */
5515 SetWindowLongPtrA(hwndMain, GWLP_WNDPROC, 0);
5519 static void test_ShowWindow(void)
5521 HWND hwnd;
5522 DWORD style;
5523 RECT rcMain, rc, rcMinimized;
5524 LPARAM ret;
5526 SetRect(&rcMain, 120, 120, 210, 210);
5528 hwnd = CreateWindowExA(0, "MainWindowClass", NULL,
5529 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5530 WS_MAXIMIZEBOX | WS_POPUP,
5531 rcMain.left, rcMain.top,
5532 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
5533 0, 0, 0, NULL);
5534 assert(hwnd);
5536 style = GetWindowLongA(hwnd, GWL_STYLE);
5537 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5538 ok(!(style & WS_VISIBLE), "window should not be visible\n");
5539 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5540 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5541 GetWindowRect(hwnd, &rc);
5542 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5543 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5544 rc.left, rc.top, rc.right, rc.bottom);
5546 ret = ShowWindow(hwnd, SW_SHOW);
5547 ok(!ret, "not expected ret: %lu\n", ret);
5548 style = GetWindowLongA(hwnd, GWL_STYLE);
5549 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5550 ok(style & WS_VISIBLE, "window should be visible\n");
5551 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5552 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5553 GetWindowRect(hwnd, &rc);
5554 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5555 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5556 rc.left, rc.top, rc.right, rc.bottom);
5558 ret = ShowWindow(hwnd, SW_MINIMIZE);
5559 ok(ret, "not expected ret: %lu\n", ret);
5560 style = GetWindowLongA(hwnd, GWL_STYLE);
5561 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5562 ok(style & WS_VISIBLE, "window should be visible\n");
5563 ok(style & WS_MINIMIZE, "window should be minimized\n");
5564 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5565 GetWindowRect(hwnd, &rcMinimized);
5566 ok(!EqualRect(&rcMain, &rcMinimized), "rects shouldn't match\n");
5567 /* shouldn't be able to resize minimized windows */
5568 ret = SetWindowPos(hwnd, 0, 0, 0,
5569 (rcMinimized.right - rcMinimized.left) * 2,
5570 (rcMinimized.bottom - rcMinimized.top) * 2,
5571 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
5572 ok(ret, "not expected ret: %lu\n", ret);
5573 GetWindowRect(hwnd, &rc);
5574 ok(EqualRect(&rc, &rcMinimized), "rects should match\n");
5576 ShowWindow(hwnd, SW_RESTORE);
5577 ok(ret, "not expected ret: %lu\n", ret);
5578 style = GetWindowLongA(hwnd, GWL_STYLE);
5579 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5580 ok(style & WS_VISIBLE, "window should be visible\n");
5581 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5582 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5583 GetWindowRect(hwnd, &rc);
5584 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5585 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5586 rc.left, rc.top, rc.right, rc.bottom);
5588 ret = EnableWindow(hwnd, FALSE);
5589 ok(!ret, "not expected ret: %lu\n", ret);
5590 style = GetWindowLongA(hwnd, GWL_STYLE);
5591 ok(style & WS_DISABLED, "window should be disabled\n");
5593 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
5594 ok(!ret, "not expected ret: %lu\n", ret);
5595 style = GetWindowLongA(hwnd, GWL_STYLE);
5596 ok(style & WS_DISABLED, "window should be disabled\n");
5597 ok(style & WS_VISIBLE, "window should be visible\n");
5598 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5599 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5600 GetWindowRect(hwnd, &rc);
5601 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5602 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5603 rc.left, rc.top, rc.right, rc.bottom);
5605 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
5606 ok(!ret, "not expected ret: %lu\n", ret);
5607 style = GetWindowLongA(hwnd, GWL_STYLE);
5608 ok(style & WS_DISABLED, "window should be disabled\n");
5609 ok(style & WS_VISIBLE, "window should be visible\n");
5610 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5611 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5612 GetWindowRect(hwnd, &rc);
5613 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5614 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5615 rc.left, rc.top, rc.right, rc.bottom);
5617 ret = ShowWindow(hwnd, SW_MINIMIZE);
5618 ok(ret, "not expected ret: %lu\n", ret);
5619 style = GetWindowLongA(hwnd, GWL_STYLE);
5620 ok(style & WS_DISABLED, "window should be disabled\n");
5621 ok(style & WS_VISIBLE, "window should be visible\n");
5622 ok(style & WS_MINIMIZE, "window should be minimized\n");
5623 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5624 GetWindowRect(hwnd, &rc);
5625 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
5627 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
5628 ok(!ret, "not expected ret: %lu\n", ret);
5629 style = GetWindowLongA(hwnd, GWL_STYLE);
5630 ok(style & WS_DISABLED, "window should be disabled\n");
5631 ok(style & WS_VISIBLE, "window should be visible\n");
5632 ok(style & WS_MINIMIZE, "window should be minimized\n");
5633 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5634 GetWindowRect(hwnd, &rc);
5635 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
5637 ret = ShowWindow(hwnd, SW_RESTORE);
5638 ok(ret, "not expected ret: %lu\n", ret);
5639 style = GetWindowLongA(hwnd, GWL_STYLE);
5640 ok(style & WS_DISABLED, "window should be disabled\n");
5641 ok(style & WS_VISIBLE, "window should be visible\n");
5642 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5643 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5644 GetWindowRect(hwnd, &rc);
5645 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5646 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5647 rc.left, rc.top, rc.right, rc.bottom);
5649 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
5650 ok(!ret, "not expected ret: %lu\n", ret);
5651 ok(IsWindow(hwnd), "window should exist\n");
5653 ret = EnableWindow(hwnd, TRUE);
5654 ok(ret, "not expected ret: %lu\n", ret);
5656 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
5657 ok(!ret, "not expected ret: %lu\n", ret);
5658 ok(!IsWindow(hwnd), "window should not exist\n");
5661 static void test_gettext(void)
5663 WNDCLASSA cls;
5664 LPCSTR clsname = "gettexttest";
5665 HWND hwnd;
5666 LRESULT r;
5668 memset( &cls, 0, sizeof cls );
5669 cls.lpfnWndProc = DefWindowProcA;
5670 cls.lpszClassName = clsname;
5671 cls.hInstance = GetModuleHandleA(NULL);
5673 if (!RegisterClassA( &cls )) return;
5675 hwnd = CreateWindowA( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
5676 ok( hwnd != NULL, "window was null\n");
5678 r = SendMessageA( hwnd, WM_GETTEXT, 0x10, 0x1000);
5679 ok( r == 0, "settext should return zero\n");
5681 r = SendMessageA( hwnd, WM_GETTEXT, 0x10000, 0);
5682 ok( r == 0, "settext should return zero (%ld)\n", r);
5684 r = SendMessageA( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
5685 ok( r == 0, "settext should return zero (%ld)\n", r);
5687 r = SendMessageA( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
5688 ok( r == 0, "settext should return zero (%ld)\n", r);
5690 DestroyWindow(hwnd);
5691 UnregisterClassA( clsname, NULL );
5695 static void test_GetUpdateRect(void)
5697 MSG msg;
5698 BOOL ret, parent_wm_paint, grandparent_wm_paint;
5699 RECT rc1, rc2;
5700 HWND hgrandparent, hparent, hchild;
5701 WNDCLASSA cls;
5702 static const char classNameA[] = "GetUpdateRectClass";
5704 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
5705 0, 0, 100, 100, NULL, NULL, 0, NULL);
5707 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
5708 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
5710 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
5711 10, 10, 30, 30, hparent, NULL, 0, NULL);
5713 ShowWindow(hgrandparent, SW_SHOW);
5714 UpdateWindow(hgrandparent);
5715 flush_events( TRUE );
5717 ShowWindow(hchild, SW_HIDE);
5718 SetRect(&rc2, 0, 0, 0, 0);
5719 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5720 ok(!ret, "GetUpdateRect returned not empty region\n");
5721 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5722 rc1.left, rc1.top, rc1.right, rc1.bottom,
5723 rc2.left, rc2.top, rc2.right, rc2.bottom);
5725 SetRect(&rc2, 10, 10, 40, 40);
5726 ret = GetUpdateRect(hparent, &rc1, FALSE);
5727 ok(ret, "GetUpdateRect returned empty region\n");
5728 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5729 rc1.left, rc1.top, rc1.right, rc1.bottom,
5730 rc2.left, rc2.top, rc2.right, rc2.bottom);
5732 parent_wm_paint = FALSE;
5733 grandparent_wm_paint = FALSE;
5734 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
5736 if (msg.message == WM_PAINT)
5738 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
5739 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
5741 DispatchMessageA(&msg);
5743 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
5744 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
5746 DestroyWindow(hgrandparent);
5748 cls.style = 0;
5749 cls.lpfnWndProc = DefWindowProcA;
5750 cls.cbClsExtra = 0;
5751 cls.cbWndExtra = 0;
5752 cls.hInstance = GetModuleHandleA(0);
5753 cls.hIcon = 0;
5754 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
5755 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5756 cls.lpszMenuName = NULL;
5757 cls.lpszClassName = classNameA;
5759 if(!RegisterClassA(&cls)) {
5760 trace("Register failed %d\n", GetLastError());
5761 return;
5764 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
5765 0, 0, 100, 100, NULL, NULL, 0, NULL);
5767 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
5768 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
5770 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
5771 10, 10, 30, 30, hparent, NULL, 0, NULL);
5773 ShowWindow(hgrandparent, SW_SHOW);
5774 UpdateWindow(hgrandparent);
5775 flush_events( TRUE );
5777 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5778 ok(!ret, "GetUpdateRect returned not empty region\n");
5780 ShowWindow(hchild, SW_HIDE);
5782 SetRect(&rc2, 0, 0, 0, 0);
5783 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5784 ok(!ret, "GetUpdateRect returned not empty region\n");
5785 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5786 rc1.left, rc1.top, rc1.right, rc1.bottom,
5787 rc2.left, rc2.top, rc2.right, rc2.bottom);
5789 SetRect(&rc2, 10, 10, 40, 40);
5790 ret = GetUpdateRect(hparent, &rc1, FALSE);
5791 ok(ret, "GetUpdateRect returned empty region\n");
5792 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5793 rc1.left, rc1.top, rc1.right, rc1.bottom,
5794 rc2.left, rc2.top, rc2.right, rc2.bottom);
5796 parent_wm_paint = FALSE;
5797 grandparent_wm_paint = FALSE;
5798 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
5800 if (msg.message == WM_PAINT)
5802 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
5803 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
5805 DispatchMessageA(&msg);
5807 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
5808 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
5810 DestroyWindow(hgrandparent);
5814 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5816 if(msg == WM_PAINT)
5818 PAINTSTRUCT ps;
5819 RECT updateRect;
5820 DWORD waitResult;
5821 HWND win;
5822 const int waitTime = 2000;
5824 BeginPaint(hwnd, &ps);
5826 /* create and destroy window to create an exposed region on this window */
5827 win = CreateWindowA("static", "win", WS_VISIBLE,
5828 10,10,50,50, NULL, NULL, 0, NULL);
5829 DestroyWindow(win);
5831 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
5833 ValidateRect(hwnd, NULL);
5834 EndPaint(hwnd, &ps);
5836 if(waitResult != WAIT_TIMEOUT)
5838 GetUpdateRect(hwnd, &updateRect, FALSE);
5839 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
5842 return 1;
5844 return DefWindowProcA(hwnd, msg, wParam, lParam);
5847 static void test_Expose(void)
5849 WNDCLASSA cls;
5850 HWND mw;
5852 memset(&cls, 0, sizeof(WNDCLASSA));
5853 cls.lpfnWndProc = TestExposedRegion_WndProc;
5854 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5855 cls.lpszClassName = "TestExposeClass";
5856 RegisterClassA(&cls);
5858 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
5859 0, 0, 200, 100, NULL, NULL, 0, NULL);
5861 UpdateWindow(mw);
5862 DestroyWindow(mw);
5865 static LRESULT CALLBACK TestNCRedraw_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5867 static UINT ncredrawflags;
5868 PAINTSTRUCT ps;
5870 switch(msg)
5872 case WM_CREATE:
5873 ncredrawflags = *(UINT *) (((CREATESTRUCTA *)lParam)->lpCreateParams);
5874 return 0;
5875 case WM_NCPAINT:
5876 RedrawWindow(hwnd, NULL, NULL, ncredrawflags);
5877 break;
5878 case WM_PAINT:
5879 BeginPaint(hwnd, &ps);
5880 EndPaint(hwnd, &ps);
5881 return 0;
5883 return DefWindowProcA(hwnd, msg, wParam, lParam);
5886 static void run_NCRedrawLoop(UINT flags)
5888 HWND hwnd;
5889 MSG msg;
5891 UINT loopcount = 0;
5893 hwnd = CreateWindowA("TestNCRedrawClass", "MainWindow",
5894 WS_OVERLAPPEDWINDOW, 0, 0, 200, 100,
5895 NULL, NULL, 0, &flags);
5896 ShowWindow(hwnd, SW_SHOW);
5897 UpdateWindow(hwnd);
5898 flush_events( FALSE );
5899 while (PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE))
5901 if (msg.message == WM_PAINT) loopcount++;
5902 if (loopcount >= 100) break;
5903 TranslateMessage(&msg);
5904 DispatchMessageA(&msg);
5905 MsgWaitForMultipleObjects(0, NULL, FALSE, 100, QS_ALLINPUT);
5907 if (flags == (RDW_INVALIDATE | RDW_FRAME))
5908 todo_wine ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
5909 else
5910 ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
5911 DestroyWindow(hwnd);
5914 static void test_NCRedraw(void)
5916 WNDCLASSA wndclass;
5918 wndclass.lpszClassName = "TestNCRedrawClass";
5919 wndclass.style = CS_HREDRAW | CS_VREDRAW;
5920 wndclass.lpfnWndProc = TestNCRedraw_WndProc;
5921 wndclass.cbClsExtra = 0;
5922 wndclass.cbWndExtra = 0;
5923 wndclass.hInstance = 0;
5924 wndclass.hIcon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
5925 wndclass.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
5926 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
5927 wndclass.lpszMenuName = NULL;
5929 RegisterClassA(&wndclass);
5931 run_NCRedrawLoop(RDW_INVALIDATE | RDW_FRAME);
5932 run_NCRedrawLoop(RDW_INVALIDATE);
5935 static void test_GetWindowModuleFileName(void)
5937 HWND hwnd;
5938 HINSTANCE hinst;
5939 UINT ret1, ret2;
5940 char buf1[MAX_PATH], buf2[MAX_PATH];
5942 if (!pGetWindowModuleFileNameA)
5944 win_skip("GetWindowModuleFileNameA is not available\n");
5945 return;
5948 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
5949 assert(hwnd);
5951 hinst = (HINSTANCE)GetWindowLongPtrA(hwnd, GWLP_HINSTANCE);
5952 ok(hinst == 0 || broken(hinst == GetModuleHandleA(NULL)), /* win9x */ "expected 0, got %p\n", hinst);
5954 buf1[0] = 0;
5955 SetLastError(0xdeadbeef);
5956 ret1 = GetModuleFileNameA(hinst, buf1, sizeof(buf1));
5957 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
5959 buf2[0] = 0;
5960 SetLastError(0xdeadbeef);
5961 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
5962 ok(ret2 || broken(!ret2), /* nt4 sp 3 */
5963 "GetWindowModuleFileNameA error %u\n", GetLastError());
5965 if (ret2)
5967 ok(ret1 == ret2 || broken(ret2 == ret1 + 1), /* win98 */ "%u != %u\n", ret1, ret2);
5968 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
5970 hinst = GetModuleHandleA(NULL);
5972 SetLastError(0xdeadbeef);
5973 ret2 = GetModuleFileNameA(hinst, buf2, ret1 - 2);
5974 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
5975 "expected %u, got %u\n", ret1 - 2, ret2);
5976 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5977 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5978 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5980 SetLastError(0xdeadbeef);
5981 ret2 = GetModuleFileNameA(hinst, buf2, 0);
5982 ok(!ret2, "GetModuleFileName should return 0\n");
5983 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5984 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5985 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5987 SetLastError(0xdeadbeef);
5988 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
5989 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3) /* win98 */ || broken(!ret2), /* nt4 sp3 */
5990 "expected %u, got %u\n", ret1 - 2, ret2);
5991 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5992 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5993 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5995 SetLastError(0xdeadbeef);
5996 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
5997 ok(!ret2, "expected 0, got %u\n", ret2);
5998 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5999 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
6000 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
6002 DestroyWindow(hwnd);
6004 buf2[0] = 0;
6005 hwnd = (HWND)0xdeadbeef;
6006 SetLastError(0xdeadbeef);
6007 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
6008 ok(!ret1, "expected 0, got %u\n", ret1);
6009 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef), /* win9x */
6010 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
6012 hwnd = FindWindowA("Shell_TrayWnd", NULL);
6013 ok(IsWindow(hwnd) || broken(!hwnd), "got invalid tray window %p\n", hwnd);
6014 SetLastError(0xdeadbeef);
6015 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
6016 ok(!ret1 || broken(ret1), /* win98 */ "expected 0, got %u\n", ret1);
6018 if (!ret1) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
6020 ret1 = GetModuleFileNameA(0, buf1, sizeof(buf1));
6021 hwnd = GetDesktopWindow();
6022 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
6023 SetLastError(0xdeadbeef);
6024 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
6025 ok(!ret2 ||
6026 ret1 == ret2 || /* vista */
6027 broken(ret2), /* some win98 return user.exe as file name */
6028 "expected 0 or %u, got %u %s\n", ret1, ret2, buf2);
6032 static void test_hwnd_message(void)
6034 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
6035 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
6037 HWND parent = 0, hwnd, found;
6038 RECT rect;
6040 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
6041 on CreateWindowExA and crash later in the test.
6042 Use UNICODE here to fail on win9x */
6043 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
6044 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
6045 if (!hwnd)
6047 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
6048 return;
6051 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
6052 if (pGetAncestor)
6054 char buffer[100];
6055 HWND root, desktop = GetDesktopWindow();
6057 parent = pGetAncestor(hwnd, GA_PARENT);
6058 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
6059 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
6060 root = pGetAncestor(hwnd, GA_ROOT);
6061 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
6062 ok( !pGetAncestor(parent, GA_PARENT) || broken(pGetAncestor(parent, GA_PARENT) != 0), /* win2k */
6063 "parent shouldn't have parent %p\n", pGetAncestor(parent, GA_PARENT) );
6064 trace("parent %p root %p desktop %p\n", parent, root, desktop);
6065 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
6066 ok( !lstrcmpiA( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
6067 GetWindowRect( parent, &rect );
6068 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
6069 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
6071 GetWindowRect( hwnd, &rect );
6072 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
6073 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
6075 /* test FindWindow behavior */
6077 found = FindWindowExA( 0, 0, 0, "message window" );
6078 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
6079 SetLastError(0xdeadbeef);
6080 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
6081 ok( found == 0, "found message window %p/%p\n", found, hwnd );
6082 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
6083 if (parent)
6085 found = FindWindowExA( parent, 0, 0, "message window" );
6086 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
6089 /* test IsChild behavior */
6091 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
6093 /* test IsWindowVisible behavior */
6095 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
6096 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
6098 DestroyWindow(hwnd);
6101 static void test_layered_window(void)
6103 HWND hwnd;
6104 COLORREF key = 0;
6105 BYTE alpha = 0;
6106 DWORD flags = 0;
6107 POINT pt = { 0, 0 };
6108 SIZE sz = { 200, 200 };
6109 HDC hdc;
6110 HBITMAP hbm;
6111 BOOL ret;
6113 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes || !pUpdateLayeredWindow)
6115 win_skip( "layered windows not supported\n" );
6116 return;
6119 hdc = CreateCompatibleDC( 0 );
6120 hbm = CreateCompatibleBitmap( hdc, 200, 200 );
6121 SelectObject( hdc, hbm );
6123 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
6124 100, 100, 200, 200, 0, 0, 0, NULL);
6125 assert( hwnd );
6126 SetLastError( 0xdeadbeef );
6127 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6128 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
6129 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
6130 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6131 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
6132 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
6133 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
6134 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
6135 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6136 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
6137 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6138 ok( ret, "UpdateLayeredWindow should succeed on layered window\n" );
6139 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6140 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
6141 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
6142 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6143 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6144 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6145 ok( key == 0x123456 || key == 0, "wrong color key %x\n", key );
6146 ok( alpha == 44, "wrong alpha %u\n", alpha );
6147 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
6148 SetLastError( 0xdeadbeef );
6149 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6150 ok( !ret, "UpdateLayeredWindow should fail on layered but initialized window\n" );
6151 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
6153 /* clearing WS_EX_LAYERED resets attributes */
6154 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
6155 SetLastError( 0xdeadbeef );
6156 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6157 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
6158 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6159 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
6160 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
6161 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6162 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
6163 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6164 ok( ret, "UpdateLayeredWindow should succeed on layered window\n" );
6165 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE | ULW_EX_NORESIZE );
6166 ok( !ret, "UpdateLayeredWindow should fail with ex flag\n" );
6167 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
6168 if (pUpdateLayeredWindowIndirect)
6170 UPDATELAYEREDWINDOWINFO info;
6171 info.cbSize = sizeof(info);
6172 info.hdcDst = 0;
6173 info.pptDst = NULL;
6174 info.psize = &sz;
6175 info.hdcSrc = hdc;
6176 info.pptSrc = &pt;
6177 info.crKey = 0;
6178 info.pblend = NULL;
6179 info.dwFlags = ULW_OPAQUE | ULW_EX_NORESIZE;
6180 info.prcDirty = NULL;
6181 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6182 ok( ret, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
6183 sz.cx--;
6184 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6185 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
6186 ok( GetLastError() == ERROR_INCORRECT_SIZE || broken(GetLastError() == ERROR_MR_MID_NOT_FOUND),
6187 "wrong error %u\n", GetLastError() );
6188 info.dwFlags = ULW_OPAQUE;
6189 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6190 ok( ret, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
6191 sz.cx++;
6192 info.dwFlags = ULW_OPAQUE | 0xf00;
6193 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6194 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
6195 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
6196 info.cbSize--;
6197 info.dwFlags = ULW_OPAQUE;
6198 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6199 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
6200 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
6201 ret = pUpdateLayeredWindowIndirect( hwnd, NULL );
6202 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
6203 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
6206 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
6207 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6208 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6209 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6210 ok( key == 0x654321, "wrong color key %x\n", key );
6211 ok( alpha == 22, "wrong alpha %u\n", alpha );
6212 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
6213 SetLastError( 0xdeadbeef );
6214 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6215 ok( !ret, "UpdateLayeredWindow should fail on layered but initialized window\n" );
6216 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
6218 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
6219 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6220 alpha = 0;
6221 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6222 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6223 ok( key == 0x888888, "wrong color key %x\n", key );
6224 /* alpha not changed on vista if LWA_ALPHA is not set */
6225 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
6226 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
6228 /* color key may or may not be changed without LWA_COLORKEY */
6229 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
6230 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6231 alpha = 0;
6232 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6233 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6234 ok( key == 0x888888 || key == 0x999999, "wrong color key %x\n", key );
6235 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
6236 ok( flags == 0, "wrong flags %x\n", flags );
6238 /* default alpha and color key is 0 */
6239 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
6240 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
6241 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
6242 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6243 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6244 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6245 ok( key == 0 || key == 0x222222, "wrong color key %x\n", key );
6246 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
6247 ok( flags == 0, "wrong flags %x\n", flags );
6249 DestroyWindow( hwnd );
6250 DeleteDC( hdc );
6251 DeleteObject( hbm );
6254 static MONITORINFO mi;
6256 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
6258 switch (msg)
6260 case WM_NCCREATE:
6262 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
6263 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs->x, cs->y, cs->cx, cs->cy);
6264 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
6265 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
6266 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
6267 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6268 cs->x, cs->y, cs->cx, cs->cy);
6269 break;
6271 case WM_GETMINMAXINFO:
6273 MINMAXINFO *minmax = (MINMAXINFO *)lp;
6274 dump_minmax_info(minmax);
6275 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
6276 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
6277 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
6278 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
6279 break;
6282 return DefWindowProcA(hwnd, msg, wp, lp);
6285 static void test_fullscreen(void)
6287 static const DWORD t_style[] = {
6288 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
6290 static const DWORD t_ex_style[] = {
6291 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
6293 WNDCLASSA cls;
6294 HWND hwnd;
6295 int i, j;
6296 POINT pt;
6297 RECT rc;
6298 HMONITOR hmon;
6299 LRESULT ret;
6301 if (!pGetMonitorInfoA || !pMonitorFromPoint)
6303 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
6304 return;
6307 pt.x = pt.y = 0;
6308 SetLastError(0xdeadbeef);
6309 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
6310 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
6312 mi.cbSize = sizeof(mi);
6313 SetLastError(0xdeadbeef);
6314 ret = pGetMonitorInfoA(hmon, &mi);
6315 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
6316 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
6317 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6318 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
6320 cls.style = 0;
6321 cls.lpfnWndProc = fullscreen_wnd_proc;
6322 cls.cbClsExtra = 0;
6323 cls.cbWndExtra = 0;
6324 cls.hInstance = GetModuleHandleA(NULL);
6325 cls.hIcon = 0;
6326 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
6327 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6328 cls.lpszMenuName = NULL;
6329 cls.lpszClassName = "fullscreen_class";
6330 RegisterClassA(&cls);
6332 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
6334 DWORD style, ex_style;
6336 /* avoid a WM interaction */
6337 assert(!(t_style[i] & WS_VISIBLE));
6339 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
6341 int fixup;
6343 style = t_style[i];
6344 ex_style = t_ex_style[j];
6346 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6347 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6348 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
6349 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6350 GetWindowRect(hwnd, &rc);
6351 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6352 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6353 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6354 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6355 DestroyWindow(hwnd);
6357 style = t_style[i] | WS_MAXIMIZE;
6358 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6359 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6360 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
6361 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6362 GetWindowRect(hwnd, &rc);
6363 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6364 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6365 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6366 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6367 DestroyWindow(hwnd);
6369 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
6370 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6371 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6372 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
6373 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6374 GetWindowRect(hwnd, &rc);
6375 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6376 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6377 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6378 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6379 DestroyWindow(hwnd);
6381 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
6382 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6383 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6384 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
6385 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6386 GetWindowRect(hwnd, &rc);
6387 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6388 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6389 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6390 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6391 DestroyWindow(hwnd);
6393 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
6394 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6395 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6396 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
6397 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6398 GetWindowRect(hwnd, &rc);
6399 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6400 /* Windows makes a maximized window slightly larger (to hide the borders?) */
6401 fixup = min(abs(rc.left), abs(rc.top));
6402 InflateRect(&rc, -fixup, -fixup);
6403 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
6404 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
6405 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
6406 ex_style, style, rc.left, rc.top, rc.right, rc.bottom,
6407 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
6408 DestroyWindow(hwnd);
6410 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
6411 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6412 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6413 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
6414 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6415 GetWindowRect(hwnd, &rc);
6416 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6417 /* Windows makes a maximized window slightly larger (to hide the borders?) */
6418 fixup = min(abs(rc.left), abs(rc.top));
6419 InflateRect(&rc, -fixup, -fixup);
6420 if (style & (WS_CHILD | WS_POPUP))
6421 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6422 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6423 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6424 else
6425 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
6426 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
6427 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6428 DestroyWindow(hwnd);
6432 UnregisterClassA("fullscreen_class", GetModuleHandleA(NULL));
6435 static BOOL test_thick_child_got_minmax;
6436 static const char * test_thick_child_name;
6437 static LONG test_thick_child_style;
6438 static LONG test_thick_child_exStyle;
6440 static LRESULT WINAPI test_thick_child_size_winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
6442 MINMAXINFO* minmax;
6443 int expectedMinTrackX;
6444 int expectedMinTrackY;
6445 int actualMinTrackX;
6446 int actualMinTrackY;
6447 int expectedMaxTrackX;
6448 int expectedMaxTrackY;
6449 int actualMaxTrackX;
6450 int actualMaxTrackY;
6451 int expectedMaxSizeX;
6452 int expectedMaxSizeY;
6453 int actualMaxSizeX;
6454 int actualMaxSizeY;
6455 int expectedPosX;
6456 int expectedPosY;
6457 int actualPosX;
6458 int actualPosY;
6459 LONG adjustedStyle;
6460 RECT rect;
6461 switch (msg)
6463 case WM_GETMINMAXINFO:
6465 minmax = (MINMAXINFO *)lparam;
6466 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
6467 dump_minmax_info( minmax );
6469 test_thick_child_got_minmax = TRUE;
6472 adjustedStyle = test_thick_child_style;
6473 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
6474 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
6475 GetClientRect(GetParent(hwnd), &rect);
6476 AdjustWindowRectEx(&rect, adjustedStyle, FALSE, test_thick_child_exStyle);
6478 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
6480 expectedMinTrackX = GetSystemMetrics(SM_CXMINTRACK);
6481 expectedMinTrackY = GetSystemMetrics(SM_CYMINTRACK);
6483 else
6485 expectedMinTrackX = -2 * rect.left;
6486 expectedMinTrackY = -2 * rect.top;
6488 actualMinTrackX = minmax->ptMinTrackSize.x;
6489 actualMinTrackY = minmax->ptMinTrackSize.y;
6491 ok(actualMinTrackX == expectedMinTrackX && actualMinTrackY == expectedMinTrackY,
6492 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
6493 expectedMinTrackX, expectedMinTrackY, actualMinTrackX, actualMinTrackY,
6494 test_thick_child_name);
6496 actualMaxTrackX = minmax->ptMaxTrackSize.x;
6497 actualMaxTrackY = minmax->ptMaxTrackSize.y;
6498 expectedMaxTrackX = GetSystemMetrics(SM_CXMAXTRACK);
6499 expectedMaxTrackY = GetSystemMetrics(SM_CYMAXTRACK);
6500 ok(actualMaxTrackX == expectedMaxTrackX && actualMaxTrackY == expectedMaxTrackY,
6501 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
6502 expectedMaxTrackX, expectedMaxTrackY, actualMaxTrackX, actualMaxTrackY,
6503 test_thick_child_name);
6505 expectedMaxSizeX = rect.right - rect.left;
6506 expectedMaxSizeY = rect.bottom - rect.top;
6507 actualMaxSizeX = minmax->ptMaxSize.x;
6508 actualMaxSizeY = minmax->ptMaxSize.y;
6510 ok(actualMaxSizeX == expectedMaxSizeX && actualMaxSizeY == expectedMaxSizeY,
6511 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
6512 expectedMaxSizeX, expectedMaxSizeY, actualMaxSizeX, actualMaxSizeY,
6513 test_thick_child_name);
6516 expectedPosX = rect.left;
6517 expectedPosY = rect.top;
6518 actualPosX = minmax->ptMaxPosition.x;
6519 actualPosY = minmax->ptMaxPosition.y;
6520 ok(actualPosX == expectedPosX && actualPosY == expectedPosY,
6521 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
6522 expectedPosX, expectedPosY, actualPosX, actualPosY, test_thick_child_name);
6524 break;
6528 return DefWindowProcA(hwnd, msg, wparam, lparam);
6531 #define NUMBER_OF_THICK_CHILD_TESTS 16
6532 static void test_thick_child_size(HWND parentWindow)
6534 BOOL success;
6535 RECT childRect;
6536 RECT adjustedParentRect;
6537 HWND childWindow;
6538 LONG childWidth;
6539 LONG childHeight;
6540 LONG expectedWidth;
6541 LONG expectedHeight;
6542 WNDCLASSA cls;
6543 static const char className[] = "THICK_CHILD_CLASS";
6544 int i;
6545 LONG adjustedStyle;
6546 static const LONG styles[NUMBER_OF_THICK_CHILD_TESTS] = {
6547 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6548 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6549 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6550 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6551 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6552 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6553 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6554 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6555 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6556 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6557 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6558 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6559 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6560 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6561 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6562 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6565 static const LONG exStyles[NUMBER_OF_THICK_CHILD_TESTS] = {
6570 WS_EX_DLGMODALFRAME,
6571 WS_EX_DLGMODALFRAME,
6572 WS_EX_DLGMODALFRAME,
6573 WS_EX_DLGMODALFRAME,
6574 WS_EX_STATICEDGE,
6575 WS_EX_STATICEDGE,
6576 WS_EX_STATICEDGE,
6577 WS_EX_STATICEDGE,
6578 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6579 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6580 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6581 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6583 static const char *styleName[NUMBER_OF_THICK_CHILD_TESTS] = {
6584 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
6585 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
6586 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
6587 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
6588 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
6589 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
6590 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
6591 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
6592 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
6593 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
6594 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
6595 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
6596 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6597 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6598 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6599 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6602 cls.style = 0;
6603 cls.lpfnWndProc = test_thick_child_size_winproc;
6604 cls.cbClsExtra = 0;
6605 cls.cbWndExtra = 0;
6606 cls.hInstance = GetModuleHandleA(0);
6607 cls.hIcon = 0;
6608 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
6609 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6610 cls.lpszMenuName = NULL;
6611 cls.lpszClassName = className;
6612 SetLastError(0xdeadbeef);
6613 success = RegisterClassA(&cls);
6614 ok(success,"RegisterClassA failed, error: %u\n", GetLastError());
6616 for(i = 0; i < NUMBER_OF_THICK_CHILD_TESTS; i++)
6618 test_thick_child_name = styleName[i];
6619 test_thick_child_style = styles[i];
6620 test_thick_child_exStyle = exStyles[i];
6621 test_thick_child_got_minmax = FALSE;
6623 SetLastError(0xdeadbeef);
6624 childWindow = CreateWindowExA( exStyles[i], className, "", styles[i], 0, 0, 0, 0, parentWindow, 0, GetModuleHandleA(0), NULL );
6625 ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
6627 ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
6629 SetLastError(0xdeadbeef);
6630 success = GetWindowRect(childWindow, &childRect);
6631 ok(success,"GetWindowRect call failed, error: %u\n", GetLastError());
6632 childWidth = childRect.right - childRect.left;
6633 childHeight = childRect.bottom - childRect.top;
6635 adjustedStyle = styles[i];
6636 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
6637 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
6638 GetClientRect(GetParent(childWindow), &adjustedParentRect);
6639 AdjustWindowRectEx(&adjustedParentRect, adjustedStyle, FALSE, test_thick_child_exStyle);
6642 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
6644 expectedWidth = GetSystemMetrics(SM_CXMINTRACK);
6645 expectedHeight = GetSystemMetrics(SM_CYMINTRACK);
6647 else
6649 expectedWidth = -2 * adjustedParentRect.left;
6650 expectedHeight = -2 * adjustedParentRect.top;
6653 ok((childWidth == expectedWidth) && (childHeight == expectedHeight),
6654 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
6655 test_thick_child_name, expectedWidth, expectedHeight, childWidth, childHeight);
6657 SetLastError(0xdeadbeef);
6658 success = DestroyWindow(childWindow);
6659 ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
6661 ok(UnregisterClassA(className, GetModuleHandleA(NULL)),"UnregisterClass call failed\n");
6664 static void test_handles( HWND full_hwnd )
6666 HWND hwnd = full_hwnd;
6667 BOOL ret;
6668 RECT rect;
6670 SetLastError( 0xdeadbeef );
6671 ret = GetWindowRect( hwnd, &rect );
6672 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6674 #ifdef _WIN64
6675 if ((ULONG_PTR)full_hwnd >> 32)
6676 hwnd = (HWND)((ULONG_PTR)full_hwnd & ~0u);
6677 else
6678 hwnd = (HWND)((ULONG_PTR)full_hwnd | ((ULONG_PTR)~0u << 32));
6679 SetLastError( 0xdeadbeef );
6680 ret = GetWindowRect( hwnd, &rect );
6681 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6683 hwnd = (HWND)(((ULONG_PTR)full_hwnd & ~0u) | ((ULONG_PTR)0x1234 << 32));
6684 SetLastError( 0xdeadbeef );
6685 ret = GetWindowRect( hwnd, &rect );
6686 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6688 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x9876 << 16));
6689 SetLastError( 0xdeadbeef );
6690 ret = GetWindowRect( hwnd, &rect );
6691 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
6692 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
6694 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x12345678 << 16));
6695 SetLastError( 0xdeadbeef );
6696 ret = GetWindowRect( hwnd, &rect );
6697 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
6698 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
6699 #endif
6702 static void test_winregion(void)
6704 HWND hwnd;
6705 RECT r;
6706 int ret, width;
6707 HRGN hrgn;
6709 if (!pGetWindowRgnBox)
6711 win_skip("GetWindowRgnBox not supported\n");
6712 return;
6715 hwnd = CreateWindowExA(0, "static", NULL, WS_VISIBLE, 10, 10, 10, 10, NULL, 0, 0, NULL);
6716 /* NULL prect */
6717 SetLastError(0xdeadbeef);
6718 ret = pGetWindowRgnBox(hwnd, NULL);
6719 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
6720 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
6722 hrgn = CreateRectRgn(2, 3, 10, 15);
6723 ok( hrgn != NULL, "Region creation failed\n");
6724 if (hrgn)
6726 SetWindowRgn(hwnd, hrgn, FALSE);
6728 SetLastError(0xdeadbeef);
6729 ret = pGetWindowRgnBox(hwnd, NULL);
6730 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
6731 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
6733 r.left = r.top = r.right = r.bottom = 0;
6734 ret = pGetWindowRgnBox(hwnd, &r);
6735 ok( ret == SIMPLEREGION, "Expected SIMPLEREGION, got %d\n", ret);
6736 ok( r.left == 2 && r.top == 3 && r.right == 10 && r.bottom == 15,
6737 "Expected (2,3,10,15), got (%d,%d,%d,%d)\n", r.left, r.top,
6738 r.right, r.bottom);
6739 if (pMirrorRgn)
6741 hrgn = CreateRectRgn(2, 3, 10, 15);
6742 ret = pMirrorRgn( hwnd, hrgn );
6743 ok( ret == TRUE, "MirrorRgn failed %u\n", ret );
6744 r.left = r.top = r.right = r.bottom = 0;
6745 GetWindowRect( hwnd, &r );
6746 width = r.right - r.left;
6747 r.left = r.top = r.right = r.bottom = 0;
6748 ret = GetRgnBox( hrgn, &r );
6749 ok( ret == SIMPLEREGION, "GetRgnBox failed %u\n", ret );
6750 ok( r.left == width - 10 && r.top == 3 && r.right == width - 2 && r.bottom == 15,
6751 "Wrong rectangle (%d,%d,%d,%d) for width %d\n", r.left, r.top, r.right, r.bottom, width );
6753 else win_skip( "MirrorRgn not supported\n" );
6755 DestroyWindow(hwnd);
6758 static void test_rtl_layout(void)
6760 HWND parent, child;
6761 RECT r;
6762 POINT pt;
6764 if (!pSetProcessDefaultLayout)
6766 win_skip( "SetProcessDefaultLayout not supported\n" );
6767 return;
6770 parent = CreateWindowExA(WS_EX_LAYOUTRTL, "static", NULL, WS_POPUP, 100, 100, 300, 300, NULL, 0, 0, NULL);
6771 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 10, 10, 20, 20, parent, 0, 0, NULL);
6773 GetWindowRect( parent, &r );
6774 ok( r.left == 100 && r.right == 400, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6775 GetClientRect( parent, &r );
6776 ok( r.left == 0 && r.right == 300, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6777 GetClientRect( child, &r );
6778 ok( r.left == 0 && r.right == 20, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6779 MapWindowPoints( child, parent, (POINT *)&r, 2 );
6780 ok( r.left == 10 && r.right == 30, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6781 GetWindowRect( child, &r );
6782 ok( r.left == 370 && r.right == 390, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6783 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
6784 ok( r.left == 10 && r.right == 30, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6785 GetWindowRect( child, &r );
6786 MapWindowPoints( NULL, parent, (POINT *)&r, 1 );
6787 MapWindowPoints( NULL, parent, (POINT *)&r + 1, 1 );
6788 ok( r.left == 30 && r.right == 10, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6789 pt.x = pt.y = 12;
6790 MapWindowPoints( child, parent, &pt, 1 );
6791 ok( pt.x == 22 && pt.y == 22, "wrong point %d,%d\n", pt.x, pt.y );
6792 SetWindowPos( parent, 0, 0, 0, 250, 250, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
6793 GetWindowRect( parent, &r );
6794 ok( r.left == 100 && r.right == 350, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6795 GetWindowRect( child, &r );
6796 ok( r.left == 320 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6797 SetWindowLongW( parent, GWL_EXSTYLE, 0 );
6798 GetWindowRect( child, &r );
6799 ok( r.left == 320 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6800 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
6801 ok( r.left == 220 && r.right == 240, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6802 SetWindowLongW( parent, GWL_EXSTYLE, WS_EX_LAYOUTRTL );
6803 GetWindowRect( child, &r );
6804 ok( r.left == 320 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6805 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
6806 ok( r.left == 10 && r.right == 30, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6807 SetWindowPos( child, 0, 0, 0, 30, 30, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
6808 GetWindowRect( child, &r );
6809 ok( r.left == 310 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6810 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
6811 ok( r.left == 10 && r.right == 40, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6812 DestroyWindow( child );
6813 DestroyWindow( parent );
6816 static void test_FlashWindowEx(void)
6818 HWND hwnd;
6819 FLASHWINFO finfo;
6820 BOOL prev, ret;
6822 if (!pFlashWindowEx)
6824 win_skip( "FlashWindowEx not supported\n" );
6825 return;
6828 hwnd = CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_POPUP,
6829 0, 0, 0, 0, 0, 0, 0, NULL );
6830 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
6832 finfo.cbSize = sizeof(FLASHWINFO);
6833 finfo.dwFlags = FLASHW_TIMER;
6834 finfo.uCount = 3;
6835 finfo.dwTimeout = 200;
6836 finfo.hwnd = NULL;
6837 SetLastError(0xdeadbeef);
6838 ret = pFlashWindowEx(&finfo);
6839 todo_wine ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
6840 "FlashWindowEx returned with %d\n", GetLastError());
6842 finfo.hwnd = hwnd;
6843 SetLastError(0xdeadbeef);
6844 ret = pFlashWindowEx(NULL);
6845 todo_wine ok(!ret && GetLastError() == ERROR_NOACCESS,
6846 "FlashWindowEx returned with %d\n", GetLastError());
6848 SetLastError(0xdeadbeef);
6849 ret = pFlashWindowEx(&finfo);
6850 todo_wine ok(!ret, "previous window state should not be active\n");
6852 finfo.cbSize = sizeof(FLASHWINFO) - 1;
6853 SetLastError(0xdeadbeef);
6854 ret = pFlashWindowEx(&finfo);
6855 todo_wine ok(!ret && GetLastError()==ERROR_INVALID_PARAMETER,
6856 "FlashWindowEx succeeded\n");
6858 finfo.cbSize = sizeof(FLASHWINFO) + 1;
6859 SetLastError(0xdeadbeef);
6860 ret = pFlashWindowEx(&finfo);
6861 todo_wine ok(!ret && GetLastError()==ERROR_INVALID_PARAMETER,
6862 "FlashWindowEx succeeded\n");
6863 finfo.cbSize = sizeof(FLASHWINFO);
6865 DestroyWindow( hwnd );
6867 SetLastError(0xdeadbeef);
6868 ret = pFlashWindowEx(&finfo);
6869 todo_wine ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
6870 "FlashWindowEx returned with %d\n", GetLastError());
6872 ok(finfo.cbSize == sizeof(FLASHWINFO), "FlashWindowEx modified cdSize to %x\n", finfo.cbSize);
6873 ok(finfo.hwnd == hwnd, "FlashWindowEx modified hwnd to %p\n", finfo.hwnd);
6874 ok(finfo.dwFlags == FLASHW_TIMER, "FlashWindowEx modified dwFlags to %x\n", finfo.dwFlags);
6875 ok(finfo.uCount == 3, "FlashWindowEx modified uCount to %x\n", finfo.uCount);
6876 ok(finfo.dwTimeout == 200, "FlashWindowEx modified dwTimeout to %x\n", finfo.dwTimeout);
6878 hwnd = CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_VISIBLE | WS_POPUPWINDOW,
6879 0, 0, 0, 0, 0, 0, 0, NULL );
6880 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
6881 finfo.hwnd = hwnd;
6883 SetLastError(0xdeadbeef);
6884 ret = pFlashWindowEx(NULL);
6885 todo_wine ok(!ret && GetLastError() == ERROR_NOACCESS,
6886 "FlashWindowEx returned with %d\n", GetLastError());
6888 SetLastError(0xdeadbeef);
6889 prev = pFlashWindowEx(&finfo);
6891 ok(finfo.cbSize == sizeof(FLASHWINFO), "FlashWindowEx modified cdSize to %x\n", finfo.cbSize);
6892 ok(finfo.hwnd == hwnd, "FlashWindowEx modified hwnd to %p\n", finfo.hwnd);
6893 ok(finfo.dwFlags == FLASHW_TIMER, "FlashWindowEx modified dwFlags to %x\n", finfo.dwFlags);
6894 ok(finfo.uCount == 3, "FlashWindowEx modified uCount to %x\n", finfo.uCount);
6895 ok(finfo.dwTimeout == 200, "FlashWindowEx modified dwTimeout to %x\n", finfo.dwTimeout);
6897 finfo.dwFlags = FLASHW_STOP;
6898 SetLastError(0xdeadbeef);
6899 ret = pFlashWindowEx(&finfo);
6900 todo_wine
6901 ok(prev != ret, "previous window state should be different\n");
6903 DestroyWindow( hwnd );
6906 static void test_FindWindowEx(void)
6908 HWND hwnd, found;
6909 CHAR title[1];
6911 hwnd = CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP, 0,0,0,0, 0, 0, 0, NULL );
6912 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
6914 title[0] = 0;
6916 found = FindWindowExA( 0, 0, "MainWindowClass", title );
6917 ok( found == NULL, "expected a NULL hwnd\n" );
6918 found = FindWindowExA( 0, 0, "MainWindowClass", NULL );
6919 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
6921 DestroyWindow( hwnd );
6923 hwnd = CreateWindowExA( 0, "MainWindowClass", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL );
6924 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
6926 found = FindWindowExA( 0, 0, "MainWindowClass", title );
6927 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
6928 found = FindWindowExA( 0, 0, "MainWindowClass", NULL );
6929 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
6931 DestroyWindow( hwnd );
6933 /* test behaviour with a window title that is an empty character */
6934 found = FindWindowExA( 0, 0, "Shell_TrayWnd", title );
6935 ok( found != NULL, "found is NULL, expected a valid hwnd\n" );
6936 found = FindWindowExA( 0, 0, "Shell_TrayWnd", NULL );
6937 ok( found != NULL, "found is NULL, expected a valid hwnd\n" );
6940 static void test_GetLastActivePopup(void)
6942 HWND hwndOwner, hwndPopup1, hwndPopup2;
6944 hwndOwner = CreateWindowExA(0, "MainWindowClass", NULL,
6945 WS_VISIBLE | WS_POPUPWINDOW,
6946 100, 100, 200, 200,
6947 NULL, 0, GetModuleHandleA(NULL), NULL);
6948 hwndPopup1 = CreateWindowExA(0, "MainWindowClass", NULL,
6949 WS_VISIBLE | WS_POPUPWINDOW,
6950 100, 100, 200, 200,
6951 hwndOwner, 0, GetModuleHandleA(NULL), NULL);
6952 hwndPopup2 = CreateWindowExA(0, "MainWindowClass", NULL,
6953 WS_VISIBLE | WS_POPUPWINDOW,
6954 100, 100, 200, 200,
6955 hwndPopup1, 0, GetModuleHandleA(NULL), NULL);
6956 ok( GetLastActivePopup(hwndOwner) == hwndPopup2, "wrong last active popup\n" );
6957 DestroyWindow( hwndPopup2 );
6958 DestroyWindow( hwndPopup1 );
6959 DestroyWindow( hwndOwner );
6962 static LRESULT WINAPI my_httrasparent_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
6964 if (msg == WM_NCHITTEST) return HTTRANSPARENT;
6965 return DefWindowProcA(hwnd, msg, wp, lp);
6968 static LRESULT WINAPI my_window_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
6970 return DefWindowProcA(hwnd, msg, wp, lp);
6973 static void create_window_tree(HWND parent, HWND *window, int size)
6975 static const DWORD style[] = { 0, WS_VISIBLE, WS_DISABLED, WS_VISIBLE | WS_DISABLED };
6976 int i, pos;
6978 memset(window, 0, size * sizeof(window[0]));
6980 pos = 0;
6981 for (i = 0; i < sizeof(style)/sizeof(style[0]); i++)
6983 assert(pos < size);
6984 window[pos] = CreateWindowExA(0, "my_window", NULL, style[i] | WS_CHILD,
6985 0, 0, 100, 100, parent, 0, 0, NULL);
6986 ok(window[pos] != 0, "CreateWindowEx failed\n");
6987 pos++;
6988 assert(pos < size);
6989 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_window", NULL, style[i] | WS_CHILD,
6990 0, 0, 100, 100, parent, 0, 0, NULL);
6991 ok(window[pos] != 0, "CreateWindowEx failed\n");
6992 pos++;
6994 assert(pos < size);
6995 window[pos] = CreateWindowExA(0, "my_httrasparent", NULL, style[i] | WS_CHILD,
6996 0, 0, 100, 100, parent, 0, 0, NULL);
6997 ok(window[pos] != 0, "CreateWindowEx failed\n");
6998 pos++;
6999 assert(pos < size);
7000 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_httrasparent", NULL, style[i] | WS_CHILD,
7001 0, 0, 100, 100, parent, 0, 0, NULL);
7002 ok(window[pos] != 0, "CreateWindowEx failed\n");
7003 pos++;
7005 assert(pos < size);
7006 window[pos] = CreateWindowExA(0, "my_button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
7007 0, 0, 100, 100, parent, 0, 0, NULL);
7008 ok(window[pos] != 0, "CreateWindowEx failed\n");
7009 pos++;
7010 assert(pos < size);
7011 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
7012 0, 0, 100, 100, parent, 0, 0, NULL);
7013 ok(window[pos] != 0, "CreateWindowEx failed\n");
7014 pos++;
7015 assert(pos < size);
7016 window[pos] = CreateWindowExA(0, "my_button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
7017 0, 0, 100, 100, parent, 0, 0, NULL);
7018 ok(window[pos] != 0, "CreateWindowEx failed\n");
7019 pos++;
7020 assert(pos < size);
7021 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
7022 0, 0, 100, 100, parent, 0, 0, NULL);
7023 ok(window[pos] != 0, "CreateWindowEx failed\n");
7024 pos++;
7026 assert(pos < size);
7027 window[pos] = CreateWindowExA(0, "Button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
7028 0, 0, 100, 100, parent, 0, 0, NULL);
7029 ok(window[pos] != 0, "CreateWindowEx failed\n");
7030 pos++;
7031 assert(pos < size);
7032 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "Button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
7033 0, 0, 100, 100, parent, 0, 0, NULL);
7034 ok(window[pos] != 0, "CreateWindowEx failed\n");
7035 pos++;
7036 assert(pos < size);
7037 window[pos] = CreateWindowExA(0, "Button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
7038 0, 0, 100, 100, parent, 0, 0, NULL);
7039 ok(window[pos] != 0, "CreateWindowEx failed\n");
7040 pos++;
7041 assert(pos < size);
7042 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "Button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
7043 0, 0, 100, 100, parent, 0, 0, NULL);
7044 ok(window[pos] != 0, "CreateWindowEx failed\n");
7045 pos++;
7047 assert(pos < size);
7048 window[pos] = CreateWindowExA(0, "Static", NULL, style[i] | WS_CHILD,
7049 0, 0, 100, 100, parent, 0, 0, NULL);
7050 ok(window[pos] != 0, "CreateWindowEx failed\n");
7051 pos++;
7052 assert(pos < size);
7053 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "Static", NULL, style[i] | WS_CHILD,
7054 0, 0, 100, 100, parent, 0, 0, NULL);
7055 ok(window[pos] != 0, "CreateWindowEx failed\n");
7056 pos++;
7060 struct window_attributes
7062 char class_name[128];
7063 BOOL is_visible, is_enabled, is_groupbox, is_httransparent, is_extransparent;
7066 static void get_window_attributes(HWND hwnd, struct window_attributes *attrs)
7068 DWORD style, ex_style, hittest;
7070 style = GetWindowLongA(hwnd, GWL_STYLE);
7071 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
7072 attrs->class_name[0] = 0;
7073 GetClassNameA(hwnd, attrs->class_name, sizeof(attrs->class_name));
7074 hittest = SendMessageA(hwnd, WM_NCHITTEST, 0, 0);
7076 attrs->is_visible = (style & WS_VISIBLE) != 0;
7077 attrs->is_enabled = (style & WS_DISABLED) == 0;
7078 attrs->is_groupbox = !lstrcmpiA(attrs->class_name, "Button") && (style & BS_TYPEMASK) == BS_GROUPBOX;
7079 attrs->is_httransparent = hittest == HTTRANSPARENT;
7080 attrs->is_extransparent = (ex_style & WS_EX_TRANSPARENT) != 0;
7083 static int window_to_index(HWND hwnd, HWND *window, int size)
7085 int i;
7087 for (i = 0; i < size; i++)
7089 if (!window[i]) break;
7090 if (window[i] == hwnd) return i;
7092 return -1;
7095 static void test_child_window_from_point(void)
7097 static const int real_child_pos[] = { 14,15,16,17,18,19,20,21,24,25,26,27,42,43,
7098 44,45,46,47,48,49,52,53,54,55,51,50,23,22,-1 };
7099 static const int real_child_pos_nt4[] = { 14,15,16,17,20,21,24,25,26,27,42,43,44,45,
7100 48,49,52,53,54,55,51,50,47,46,23,22,19,18,-1 };
7101 WNDCLASSA cls;
7102 HWND hwnd, parent, window[100];
7103 POINT pt;
7104 int found_invisible, found_disabled, found_groupbox, found_httransparent, found_extransparent;
7105 int ret, i;
7107 ret = GetClassInfoA(0, "Button", &cls);
7108 ok(ret, "GetClassInfo(Button) failed\n");
7109 cls.lpszClassName = "my_button";
7110 ret = RegisterClassA(&cls);
7111 ok(ret, "RegisterClass(my_button) failed\n");
7113 cls.lpszClassName = "my_httrasparent";
7114 cls.lpfnWndProc = my_httrasparent_proc;
7115 ret = RegisterClassA(&cls);
7116 ok(ret, "RegisterClass(my_httrasparent) failed\n");
7118 cls.lpszClassName = "my_window";
7119 cls.lpfnWndProc = my_window_proc;
7120 ret = RegisterClassA(&cls);
7121 ok(ret, "RegisterClass(my_window) failed\n");
7123 parent = CreateWindowExA(0, "MainWindowClass", NULL,
7124 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE,
7125 100, 100, 200, 200,
7126 0, 0, GetModuleHandleA(NULL), NULL);
7127 ok(parent != 0, "CreateWindowEx failed\n");
7128 trace("parent %p\n", parent);
7130 create_window_tree(parent, window, sizeof(window)/sizeof(window[0]));
7132 found_invisible = 0;
7133 found_disabled = 0;
7134 found_groupbox = 0;
7135 found_httransparent = 0;
7136 found_extransparent = 0;
7138 /* FIXME: also test WindowFromPoint, ChildWindowFromPoint, ChildWindowFromPointEx */
7139 for (i = 0; i < sizeof(real_child_pos)/sizeof(real_child_pos[0]); i++)
7141 struct window_attributes attrs;
7143 pt.x = pt.y = 50;
7144 hwnd = RealChildWindowFromPoint(parent, pt);
7145 ok(hwnd != 0, "RealChildWindowFromPoint failed\n");
7146 ret = window_to_index(hwnd, window, sizeof(window)/sizeof(window[0]));
7147 /* FIXME: remove once Wine is fixed */
7148 if (ret != real_child_pos[i])
7149 todo_wine ok(ret == real_child_pos[i] || broken(ret == real_child_pos_nt4[i]), "expected %d, got %d\n", real_child_pos[i], ret);
7150 else
7151 ok(ret == real_child_pos[i] || broken(ret == real_child_pos_nt4[i]), "expected %d, got %d\n", real_child_pos[i], ret);
7153 get_window_attributes(hwnd, &attrs);
7154 if (!attrs.is_visible) found_invisible++;
7155 if (!attrs.is_enabled) found_disabled++;
7156 if (attrs.is_groupbox) found_groupbox++;
7157 if (attrs.is_httransparent) found_httransparent++;
7158 if (attrs.is_extransparent) found_extransparent++;
7160 if (ret != real_child_pos[i] && ret != -1)
7162 trace("found hwnd %p (%s), is_visible %d, is_enabled %d, is_groupbox %d, is_httransparent %d, is_extransparent %d\n",
7163 hwnd, attrs.class_name, attrs.is_visible, attrs.is_enabled, attrs.is_groupbox, attrs.is_httransparent, attrs.is_extransparent);
7164 get_window_attributes(window[real_child_pos[i]], &attrs);
7165 trace("expected hwnd %p (%s), is_visible %d, is_enabled %d, is_groupbox %d, is_httransparent %d, is_extransparent %d\n",
7166 window[real_child_pos[i]], attrs.class_name, attrs.is_visible, attrs.is_enabled, attrs.is_groupbox, attrs.is_httransparent, attrs.is_extransparent);
7168 if (ret == -1)
7170 ok(hwnd == parent, "expected %p, got %p\n", parent, hwnd);
7171 break;
7173 DestroyWindow(hwnd);
7176 DestroyWindow(parent);
7178 ok(!found_invisible, "found %d invisible windows\n", found_invisible);
7179 ok(found_disabled, "found %d disabled windows\n", found_disabled);
7180 todo_wine
7181 ok(found_groupbox == 4, "found %d groupbox windows\n", found_groupbox);
7182 ok(found_httransparent, "found %d httransparent windows\n", found_httransparent);
7183 todo_wine
7184 ok(found_extransparent, "found %d extransparent windows\n", found_extransparent);
7186 ret = UnregisterClassA("my_button", cls.hInstance);
7187 ok(ret, "UnregisterClass(my_button) failed\n");
7188 ret = UnregisterClassA("my_httrasparent", cls.hInstance);
7189 ok(ret, "UnregisterClass(my_httrasparent) failed\n");
7190 ret = UnregisterClassA("my_window", cls.hInstance);
7191 ok(ret, "UnregisterClass(my_window) failed\n");
7194 static void test_map_points(void)
7196 BOOL ret;
7197 POINT p;
7198 HWND wnd, wnd0, dwnd;
7199 INT n;
7200 DWORD err;
7201 POINT pos = { 100, 200 };
7202 int width = 150;
7203 int height = 150;
7204 RECT window_rect;
7205 RECT client_rect;
7207 /* Create test windows */
7208 wnd = CreateWindowA("static", "test1", WS_POPUP, pos.x, pos.y, width, height, NULL, NULL, NULL, NULL);
7209 ok(wnd != NULL, "Failed %p\n", wnd);
7210 wnd0 = CreateWindowA("static", "test2", WS_POPUP, 0, 0, width, height, NULL, NULL, NULL, NULL);
7211 ok(wnd0 != NULL, "Failed %p\n", wnd);
7212 dwnd = CreateWindowA("static", "test3", 0, 200, 300, 150, 150, NULL, NULL, NULL, NULL);
7213 DestroyWindow(dwnd);
7214 ok(dwnd != NULL, "Failed %p\n", dwnd);
7216 /* Verify window rect and client rect (they should have the same width and height) */
7217 GetWindowRect(wnd, &window_rect);
7218 ok(window_rect.left == pos.x, "left is %d instead of %d\n", window_rect.left, pos.x);
7219 ok(window_rect.top == pos.y, "top is %d instead of %d\n", window_rect.top, pos.y);
7220 ok(window_rect.right == pos.x + width, "right is %d instead of %d\n", window_rect.right, pos.x + width);
7221 ok(window_rect.bottom == pos.y + height, "bottom is %d instead of %d\n", window_rect.bottom, pos.y + height);
7222 GetClientRect(wnd, &client_rect);
7223 ok(client_rect.left == 0, "left is %d instead of 0\n", client_rect.left);
7224 ok(client_rect.top == 0, "top is %d instead of 0\n", client_rect.top);
7225 ok(client_rect.right == width, "right is %d instead of %d\n", client_rect.right, width);
7226 ok(client_rect.bottom == height, "bottom is %d instead of %d\n", client_rect.bottom, height);
7228 /* Test MapWindowPoints */
7230 /* MapWindowPoints(NULL or wnd, NULL or wnd, NULL, 1); crashes on Windows */
7232 SetLastError(0xdeadbeef);
7233 n = MapWindowPoints(NULL, NULL, NULL, 0);
7234 err = GetLastError();
7235 ok(n == 0, "Got %d, expected %d\n", n, 0);
7236 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7238 SetLastError(0xdeadbeef);
7239 n = MapWindowPoints(wnd, wnd, NULL, 0);
7240 err = GetLastError();
7241 ok(n == 0, "Got %d, expected %d\n", n, 0);
7242 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7244 n = MapWindowPoints(wnd, NULL, NULL, 0);
7245 ok(n == MAKELONG(window_rect.left, window_rect.top), "Got %x, expected %x\n",
7246 n, MAKELONG(window_rect.left, window_rect.top));
7248 n = MapWindowPoints(NULL, wnd, NULL, 0);
7249 ok(n == MAKELONG(-window_rect.left, -window_rect.top), "Got %x, expected %x\n",
7250 n, MAKELONG(-window_rect.left, -window_rect.top));
7252 SetLastError(0xdeadbeef);
7253 p.x = p.y = 100;
7254 n = MapWindowPoints(dwnd, NULL, &p, 1);
7255 err = GetLastError();
7256 ok(n == 0, "Got %d, expected %d\n", n, 0);
7257 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7258 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7260 SetLastError(0xdeadbeef);
7261 p.x = p.y = 100;
7262 n = MapWindowPoints(dwnd, wnd, &p, 1);
7263 err = GetLastError();
7264 ok(n == 0, "Got %d, expected %d\n", n, 0);
7265 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7266 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7268 SetLastError(0xdeadbeef);
7269 p.x = p.y = 100;
7270 n = MapWindowPoints(NULL, dwnd, &p, 1);
7271 err = GetLastError();
7272 ok(n == 0, "Got %d, expected %d\n", n, 0);
7273 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7274 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7276 SetLastError(0xdeadbeef);
7277 p.x = p.y = 100;
7278 n = MapWindowPoints(wnd, dwnd, &p, 1);
7279 err = GetLastError();
7280 ok(n == 0, "Got %d, expected %d\n", n, 0);
7281 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7282 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7284 SetLastError(0xdeadbeef);
7285 p.x = p.y = 100;
7286 n = MapWindowPoints(dwnd, dwnd, &p, 1);
7287 err = GetLastError();
7288 ok(n == 0, "Got %d, expected %d\n", n, 0);
7289 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7290 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7292 SetLastError(0xdeadbeef);
7293 p.x = p.y = 100;
7294 n = MapWindowPoints(NULL, NULL, &p, 1);
7295 err = GetLastError();
7296 ok(n == 0, "Got %d, expected %d\n", n, 0);
7297 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7298 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7300 SetLastError(0xdeadbeef);
7301 p.x = p.y = 100;
7302 n = MapWindowPoints(wnd, wnd, &p, 1);
7303 err = GetLastError();
7304 ok(n == 0, "Got %d, expected %d\n", n, 0);
7305 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7306 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7308 p.x = p.y = 100;
7309 n = MapWindowPoints(wnd, NULL, &p, 1);
7310 ok(n == MAKELONG(window_rect.left, window_rect.top), "Got %x, expected %x\n",
7311 n, MAKELONG(window_rect.left, window_rect.top));
7312 ok((p.x == (window_rect.left + 100)) && (p.y == (window_rect.top + 100)), "Failed got (%d, %d), expected (%d, %d)\n",
7313 p.x, p.y, window_rect.left + 100, window_rect.top + 100);
7315 p.x = p.y = 100;
7316 n = MapWindowPoints(NULL, wnd, &p, 1);
7317 ok(n == MAKELONG(-window_rect.left, -window_rect.top), "Got %x, expected %x\n",
7318 n, MAKELONG(-window_rect.left, -window_rect.top));
7319 ok((p.x == (-window_rect.left + 100)) && (p.y == (-window_rect.top + 100)), "Failed got (%d, %d), expected (%d, %d)\n",
7320 p.x, p.y, -window_rect.left + 100, -window_rect.top + 100);
7322 SetLastError(0xdeadbeef);
7323 p.x = p.y = 0;
7324 n = MapWindowPoints(wnd0, NULL, &p, 1);
7325 err = GetLastError();
7326 ok(n == 0, "Got %x, expected 0\n", n);
7327 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
7328 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7330 SetLastError(0xdeadbeef);
7331 p.x = p.y = 0;
7332 n = MapWindowPoints(NULL, wnd0, &p, 1);
7333 err = GetLastError();
7334 ok(n == 0, "Got %x, expected 0\n", n);
7335 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
7336 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7338 /* Test ClientToScreen */
7340 /* ClientToScreen(wnd, NULL); crashes on Windows */
7342 SetLastError(0xdeadbeef);
7343 ret = ClientToScreen(NULL, NULL);
7344 err = GetLastError();
7345 ok(!ret, "Should fail\n");
7346 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7348 SetLastError(0xdeadbeef);
7349 p.x = p.y = 100;
7350 ret = ClientToScreen(NULL, &p);
7351 err = GetLastError();
7352 ok(!ret, "Should fail\n");
7353 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7354 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7356 SetLastError(0xdeadbeef);
7357 p.x = p.y = 100;
7358 ret = ClientToScreen(dwnd, &p);
7359 err = GetLastError();
7360 ok(!ret, "Should fail\n");
7361 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7362 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7364 p.x = p.y = 100;
7365 ret = ClientToScreen(wnd, &p);
7366 ok(ret, "Failed with error %u\n", GetLastError());
7367 ok((p.x == (window_rect.left + 100)) && (p.y == (window_rect.top + 100)), "Failed got (%d, %d), expected (%d, %d)\n",
7368 p.x, p.y, window_rect.left + 100, window_rect.top + 100);
7370 p.x = p.y = 0;
7371 ret = ClientToScreen(wnd0, &p);
7372 ok(ret, "Failed with error %u\n", GetLastError());
7373 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
7375 /* Test ScreenToClient */
7377 /* ScreenToClient(wnd, NULL); crashes on Windows */
7379 SetLastError(0xdeadbeef);
7380 ret = ScreenToClient(NULL, NULL);
7381 err = GetLastError();
7382 ok(!ret, "Should fail\n");
7383 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7385 SetLastError(0xdeadbeef);
7386 p.x = p.y = 100;
7387 ret = ScreenToClient(NULL, &p);
7388 err = GetLastError();
7389 ok(!ret, "Should fail\n");
7390 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7391 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7393 SetLastError(0xdeadbeef);
7394 p.x = p.y = 100;
7395 ret = ScreenToClient(dwnd, &p);
7396 err = GetLastError();
7397 ok(!ret, "Should fail\n");
7398 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7399 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7401 p.x = p.y = 100;
7402 ret = ScreenToClient(wnd, &p);
7403 ok(ret, "Failed with error %u\n", GetLastError());
7404 ok((p.x == (-window_rect.left + 100)) && (p.y == (-window_rect.top + 100)), "Failed got(%d, %d), expected (%d, %d)\n",
7405 p.x, p.y, -window_rect.left + 100, -window_rect.top + 100);
7407 p.x = p.y = 0;
7408 ret = ScreenToClient(wnd0, &p);
7409 ok(ret, "Failed with error %u\n", GetLastError());
7410 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
7412 DestroyWindow(wnd);
7413 DestroyWindow(wnd0);
7416 static void test_update_region(void)
7418 HWND hwnd, parent, child;
7419 HRGN rgn1, rgn2;
7420 const RECT rc = {15, 15, 40, 40};
7421 const POINT wnd_orig = {30, 20};
7422 const POINT child_orig = {10, 5};
7424 parent = CreateWindowExA(0, "MainWindowClass", NULL,
7425 WS_VISIBLE | WS_CLIPCHILDREN,
7426 0, 0, 300, 150, NULL, NULL, GetModuleHandleA(0), 0);
7427 hwnd = CreateWindowExA(0, "MainWindowClass", NULL,
7428 WS_VISIBLE | WS_CLIPCHILDREN | WS_CHILD,
7429 0, 0, 200, 100, parent, NULL, GetModuleHandleA(0), 0);
7430 child = CreateWindowExA(0, "MainWindowClass", NULL,
7431 WS_VISIBLE | WS_CHILD,
7432 child_orig.x, child_orig.y, 100, 50,
7433 hwnd, NULL, GetModuleHandleA(0), 0);
7434 assert(parent && hwnd && child);
7436 ValidateRgn(parent, NULL);
7437 ValidateRgn(hwnd, NULL);
7438 InvalidateRect(hwnd, &rc, FALSE);
7439 ValidateRgn(child, NULL);
7441 rgn1 = CreateRectRgn(0, 0, 0, 0);
7442 ok(GetUpdateRgn(parent, rgn1, FALSE) == NULLREGION,
7443 "has invalid area after ValidateRgn(NULL)\n");
7444 GetUpdateRgn(hwnd, rgn1, FALSE);
7445 rgn2 = CreateRectRgnIndirect(&rc);
7446 ok(EqualRgn(rgn1, rgn2), "assigned and retrieved update regions are different\n");
7447 ok(GetUpdateRgn(child, rgn2, FALSE) == NULLREGION,
7448 "has invalid area after ValidateRgn(NULL)\n");
7450 SetWindowPos(hwnd, 0, wnd_orig.x, wnd_orig.y, 0, 0,
7451 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
7453 /* parent now has non-simple update region, it consist of
7454 * two rects, that was exposed after hwnd moving ... */
7455 SetRectRgn(rgn1, 0, 0, 200, wnd_orig.y);
7456 SetRectRgn(rgn2, 0, 0, wnd_orig.x, 100);
7457 CombineRgn(rgn1, rgn1, rgn2, RGN_OR);
7458 /* ... and mapped hwnd's invalid area, that hwnd has before moving */
7459 SetRectRgn(rgn2, rc.left + wnd_orig.x, rc.top + wnd_orig.y,
7460 rc.right + wnd_orig.x, rc.bottom + wnd_orig.y);
7461 CombineRgn(rgn1, rgn1, rgn2, RGN_OR);
7462 GetUpdateRgn(parent, rgn2, FALSE);
7463 todo_wine
7464 ok(EqualRgn(rgn1, rgn2), "wrong update region\n");
7466 /* hwnd has the same invalid region as before moving */
7467 SetRectRgn(rgn1, rc.left, rc.top, rc.right, rc.bottom);
7468 GetUpdateRgn(hwnd, rgn2, FALSE);
7469 ok(EqualRgn(rgn1, rgn2), "wrong update region\n");
7471 /* hwnd's invalid area maps to child during moving */
7472 SetRectRgn(rgn1, rc.left - child_orig.x , rc.top - child_orig.y,
7473 rc.right - child_orig.x, rc.bottom - child_orig.y);
7474 GetUpdateRgn(child, rgn2, FALSE);
7475 todo_wine
7476 ok(EqualRgn(rgn1, rgn2), "wrong update region\n");
7478 DeleteObject(rgn1);
7479 DeleteObject(rgn2);
7480 DestroyWindow(parent);
7483 START_TEST(win)
7485 HMODULE user32 = GetModuleHandleA( "user32.dll" );
7486 HMODULE gdi32 = GetModuleHandleA("gdi32.dll");
7487 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
7488 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
7489 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
7490 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
7491 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
7492 pUpdateLayeredWindow = (void *)GetProcAddress( user32, "UpdateLayeredWindow" );
7493 pUpdateLayeredWindowIndirect = (void *)GetProcAddress( user32, "UpdateLayeredWindowIndirect" );
7494 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
7495 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
7496 pGetWindowRgnBox = (void *)GetProcAddress( user32, "GetWindowRgnBox" );
7497 pGetGUIThreadInfo = (void *)GetProcAddress( user32, "GetGUIThreadInfo" );
7498 pGetProcessDefaultLayout = (void *)GetProcAddress( user32, "GetProcessDefaultLayout" );
7499 pSetProcessDefaultLayout = (void *)GetProcAddress( user32, "SetProcessDefaultLayout" );
7500 pFlashWindowEx = (void *)GetProcAddress( user32, "FlashWindowEx" );
7501 pGetLayout = (void *)GetProcAddress( gdi32, "GetLayout" );
7502 pSetLayout = (void *)GetProcAddress( gdi32, "SetLayout" );
7503 pMirrorRgn = (void *)GetProcAddress( gdi32, "MirrorRgn" );
7505 if (!RegisterWindowClasses()) assert(0);
7507 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
7508 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
7509 WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE,
7510 100, 100, 200, 200,
7511 0, 0, GetModuleHandleA(NULL), NULL);
7512 assert( hwndMain );
7514 if(!SetForegroundWindow(hwndMain)) {
7515 /* workaround for foreground lock timeout */
7516 INPUT input[2];
7517 UINT events_no;
7519 memset(input, 0, sizeof(input));
7520 input[0].type = INPUT_MOUSE;
7521 input[0].mi.dx = 101;
7522 input[0].mi.dy = 101;
7523 input[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
7524 input[0].type = INPUT_MOUSE;
7525 input[0].mi.dx = 101;
7526 input[0].mi.dy = 101;
7527 input[0].mi.dwFlags = MOUSEEVENTF_LEFTUP;
7528 events_no = SendInput(2, input, sizeof(input[0]));
7529 ok(events_no == 2, "SendInput returned %d\n", events_no);
7530 ok(SetForegroundWindow(hwndMain), "SetForegroundWindow failed\n");
7533 SetLastError(0xdeafbeef);
7534 GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC);
7535 is_win9x = (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED);
7537 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
7538 if (!hhook) win_skip( "Cannot set CBT hook, skipping some tests\n" );
7540 /* make sure that these tests are executed first */
7541 test_FindWindowEx();
7542 test_SetParent();
7544 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
7545 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
7546 WS_MAXIMIZEBOX | WS_POPUP,
7547 100, 100, 200, 200,
7548 0, 0, GetModuleHandleA(NULL), NULL);
7549 assert( hwndMain2 );
7551 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
7553 /* Add the tests below this line */
7554 test_child_window_from_point();
7555 test_thick_child_size(hwndMain);
7556 test_fullscreen();
7557 test_hwnd_message();
7558 test_nonclient_area(hwndMain);
7559 test_params();
7560 test_GetWindowModuleFileName();
7561 test_capture_1();
7562 test_capture_2();
7563 test_capture_3(hwndMain, hwndMain2);
7564 test_capture_4();
7565 test_rtl_layout();
7566 test_FlashWindowEx();
7568 test_CreateWindow();
7569 test_parent_owner();
7570 test_enum_thread_windows();
7572 test_mdi();
7573 test_icons();
7574 test_SetWindowPos(hwndMain, hwndMain2);
7575 test_SetMenu(hwndMain);
7576 test_SetFocus(hwndMain);
7577 test_SetActiveWindow(hwndMain);
7578 test_NCRedraw();
7580 test_children_zorder(hwndMain);
7581 test_popup_zorder(hwndMain2, hwndMain, WS_POPUP);
7582 test_popup_zorder(hwndMain2, hwndMain, 0);
7583 test_GetLastActivePopup();
7584 test_keyboard_input(hwndMain);
7585 test_mouse_input(hwndMain);
7586 test_validatergn(hwndMain);
7587 test_nccalcscroll( hwndMain);
7588 test_scrollwindow( hwndMain);
7589 test_scrollvalidate( hwndMain);
7590 test_scrolldc( hwndMain);
7591 test_scroll();
7592 test_IsWindowUnicode();
7593 test_vis_rgn(hwndMain);
7595 test_AdjustWindowRect();
7596 test_window_styles();
7597 test_dialog_styles();
7598 test_redrawnow();
7599 test_csparentdc();
7600 test_SetWindowLong();
7601 test_ShowWindow();
7602 if (0) test_gettext(); /* crashes on NT4 */
7603 test_GetUpdateRect();
7604 test_Expose();
7605 test_layered_window();
7607 test_SetForegroundWindow(hwndMain);
7608 test_shell_window();
7609 test_handles( hwndMain );
7610 test_winregion();
7611 test_map_points();
7612 test_update_region();
7614 /* add the tests above this line */
7615 if (hhook) UnhookWindowsHookEx(hhook);
7617 DestroyWindow(hwndMain2);
7618 DestroyWindow(hwndMain);