user32: Add tests for MapWindowPoints, ClientToScreen and ScreenToClient.
[wine.git] / dlls / user32 / tests / win.c
bloba977ac2de6decc096d9958b136b11dd88abacbd9
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 (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &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 PeekMessage( &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, 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, 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
899 UINT border;
900 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
901 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
902 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
903 ok(info->cyWindowBorders == border,
904 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
905 #endif
906 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType for %p in hook %s\n",
907 hwnd, hook);
908 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
909 info->wCreatorVersion == 0x0500 /* Vista */,
910 "wrong wCreatorVersion %04x for %p in hook %s\n", info->wCreatorVersion, hwnd, hook);
913 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
915 AdjustWindowRectEx(rc, style, menu, exstyle);
916 /* AdjustWindowRectEx does not include scroll bars */
917 if (style & WS_VSCROLL)
919 if(exstyle & WS_EX_LEFTSCROLLBAR)
920 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
921 else
922 rc->right += GetSystemMetrics(SM_CXVSCROLL);
924 if (style & WS_HSCROLL)
925 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
928 static void test_nonclient_area(HWND hwnd)
930 DWORD style, exstyle;
931 RECT rc_window, rc_client, rc;
932 BOOL menu;
933 LRESULT ret;
935 style = GetWindowLongA(hwnd, GWL_STYLE);
936 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
937 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
939 GetWindowRect(hwnd, &rc_window);
940 GetClientRect(hwnd, &rc_client);
942 /* avoid some cases when things go wrong */
943 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
944 rc_window.right > 32768 || rc_window.bottom > 32768) return;
946 CopyRect(&rc, &rc_client);
947 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
948 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
950 ok(EqualRect(&rc, &rc_window),
951 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
952 style, exstyle, menu, rc_window.left, rc_window.top, rc_window.right, rc_window.bottom,
953 rc.left, rc.top, rc.right, rc.bottom);
956 CopyRect(&rc, &rc_window);
957 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
958 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
959 ok(EqualRect(&rc, &rc_client),
960 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
961 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
962 rc.left, rc.top, rc.right, rc.bottom);
964 /* NULL rectangle shouldn't crash */
965 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
966 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
968 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
969 if (is_win9x)
970 return;
972 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
973 SetRect(&rc_client, 0, 0, 250, 150);
974 CopyRect(&rc_window, &rc_client);
975 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
976 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
978 CopyRect(&rc, &rc_window);
979 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
980 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
981 ok(EqualRect(&rc, &rc_client),
982 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
983 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
984 rc.left, rc.top, rc.right, rc.bottom);
987 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
989 static const char *CBT_code_name[10] = {
990 "HCBT_MOVESIZE",
991 "HCBT_MINMAX",
992 "HCBT_QS",
993 "HCBT_CREATEWND",
994 "HCBT_DESTROYWND",
995 "HCBT_ACTIVATE",
996 "HCBT_CLICKSKIPPED",
997 "HCBT_KEYSKIPPED",
998 "HCBT_SYSCOMMAND",
999 "HCBT_SETFOCUS" };
1000 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
1001 HWND hwnd = (HWND)wParam;
1003 switch (nCode)
1005 case HCBT_CREATEWND:
1007 static const RECT rc_null;
1008 RECT rc;
1009 LONG style;
1010 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
1011 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
1013 if (pGetWindowInfo)
1015 WINDOWINFO info;
1016 info.cbSize = sizeof(WINDOWINFO);
1017 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
1018 verify_window_info(code_name, hwnd, &info);
1021 /* WS_VISIBLE should be turned off yet */
1022 style = createwnd->lpcs->style & ~WS_VISIBLE;
1023 ok(style == GetWindowLongA(hwnd, GWL_STYLE),
1024 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
1025 GetWindowLongA(hwnd, GWL_STYLE), style);
1027 if (0)
1029 /* Uncomment this once the test succeeds in all cases */
1030 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
1032 ok(GetParent(hwnd) == hwndMessage,
1033 "wrong result from GetParent %p: message window %p\n",
1034 GetParent(hwnd), hwndMessage);
1036 else
1037 ok(!GetParent(hwnd), "GetParent should return 0 at this point\n");
1039 ok(!GetWindow(hwnd, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
1041 if (0)
1043 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
1044 * Win9x still has them set to 0.
1046 ok(GetWindow(hwnd, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
1047 ok(GetWindow(hwnd, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
1049 ok(!GetWindow(hwnd, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
1050 ok(!GetWindow(hwnd, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
1052 if (0)
1054 /* Uncomment this once the test succeeds in all cases */
1055 if (pGetAncestor)
1057 ok(pGetAncestor(hwnd, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
1058 ok(pGetAncestor(hwnd, GA_ROOT) == hwnd,
1059 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOT), hwnd);
1061 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
1062 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwndMessage,
1063 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
1064 else
1065 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwnd,
1066 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOTOWNER), hwnd);
1069 ok(GetWindowRect(hwnd, &rc), "GetWindowRect failed\n");
1070 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
1071 ok(GetClientRect(hwnd, &rc), "GetClientRect failed\n");
1072 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
1074 break;
1076 case HCBT_MOVESIZE:
1077 case HCBT_MINMAX:
1078 case HCBT_ACTIVATE:
1079 if (pGetWindowInfo && IsWindow(hwnd))
1081 WINDOWINFO info;
1083 /* Win98 actually does check the info.cbSize and doesn't allow
1084 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
1085 * WinXP do not check it at all.
1087 info.cbSize = sizeof(WINDOWINFO);
1088 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
1089 verify_window_info(code_name, hwnd, &info);
1091 break;
1092 /* window state is undefined */
1093 case HCBT_SETFOCUS:
1094 case HCBT_DESTROYWND:
1095 break;
1096 default:
1097 break;
1100 return CallNextHookEx(hhook, nCode, wParam, lParam);
1103 static void test_shell_window(void)
1105 BOOL ret;
1106 DWORD error;
1107 HMODULE hinst, hUser32;
1108 BOOL (WINAPI*SetShellWindow)(HWND);
1109 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
1110 HWND shellWindow, nextWnd;
1112 if (is_win9x)
1114 win_skip("Skipping shell window test on Win9x\n");
1115 return;
1118 shellWindow = GetShellWindow();
1119 hinst = GetModuleHandle(0);
1120 hUser32 = GetModuleHandleA("user32");
1122 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
1124 trace("previous shell window: %p\n", shellWindow);
1126 if (shellWindow) {
1127 DWORD pid;
1128 HANDLE hProcess;
1130 GetWindowThreadProcessId(shellWindow, &pid);
1131 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
1132 if (!hProcess)
1134 skip( "cannot get access to shell process\n" );
1135 return;
1138 SetLastError(0xdeadbeef);
1139 ret = DestroyWindow(shellWindow);
1140 error = GetLastError();
1142 ok(!ret, "DestroyWindow(shellWindow)\n");
1143 /* passes on Win XP, but not on Win98 */
1144 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
1145 "got %u after DestroyWindow(shellWindow)\n", error);
1147 /* close old shell instance */
1148 ret = TerminateProcess(hProcess, 0);
1149 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1150 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
1151 CloseHandle(hProcess);
1154 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
1155 trace("created window 1: %p\n", hwnd1);
1157 ret = SetShellWindow(hwnd1);
1158 ok(ret, "first call to SetShellWindow(hwnd1)\n");
1159 shellWindow = GetShellWindow();
1160 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
1162 ret = SetShellWindow(hwnd1);
1163 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1165 ret = SetShellWindow(0);
1166 error = GetLastError();
1167 /* passes on Win XP, but not on Win98
1168 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1169 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1171 ret = SetShellWindow(hwnd1);
1172 /* passes on Win XP, but not on Win98
1173 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1175 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1176 ret = (GetWindowLong(hwnd1,GWL_EXSTYLE) & WS_EX_TOPMOST) != 0;
1177 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1179 ret = DestroyWindow(hwnd1);
1180 ok(ret, "DestroyWindow(hwnd1)\n");
1182 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1183 trace("created window 2: %p\n", hwnd2);
1184 ret = SetShellWindow(hwnd2);
1185 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1187 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1188 trace("created window 3: %p\n", hwnd3);
1190 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1191 trace("created window 4: %p\n", hwnd4);
1193 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1194 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1196 ret = SetShellWindow(hwnd4);
1197 ok(ret, "SetShellWindow(hwnd4)\n");
1198 shellWindow = GetShellWindow();
1199 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1201 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1202 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1204 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1205 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1207 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1208 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1210 ret = SetShellWindow(hwnd3);
1211 ok(!ret, "SetShellWindow(hwnd3)\n");
1212 shellWindow = GetShellWindow();
1213 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1215 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1216 trace("created window 5: %p\n", hwnd5);
1217 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1218 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1220 todo_wine
1222 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1223 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1226 /* destroy test windows */
1227 DestroyWindow(hwnd2);
1228 DestroyWindow(hwnd3);
1229 DestroyWindow(hwnd4);
1230 DestroyWindow(hwnd5);
1233 /************** MDI test ****************/
1235 static char mdi_lParam_test_message[] = "just a test string";
1237 static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
1239 MDICREATESTRUCTA mdi_cs;
1240 HWND mdi_child;
1241 INT_PTR id;
1242 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1243 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1244 BOOL isWin9x = FALSE;
1246 mdi_cs.szClass = "MDI_child_Class_1";
1247 mdi_cs.szTitle = "MDI child";
1248 mdi_cs.hOwner = GetModuleHandle(0);
1249 mdi_cs.x = CW_USEDEFAULT;
1250 mdi_cs.y = CW_USEDEFAULT;
1251 mdi_cs.cx = CW_USEDEFAULT;
1252 mdi_cs.cy = CW_USEDEFAULT;
1253 mdi_cs.style = 0;
1254 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1255 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1256 ok(mdi_child != 0, "MDI child creation failed\n");
1257 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1258 ok(id == first_id, "wrong child id %ld\n", id);
1259 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1260 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1262 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1263 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1264 ok(mdi_child != 0, "MDI child creation failed\n");
1265 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1266 ok(id == first_id, "wrong child id %ld\n", id);
1267 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1268 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1270 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1271 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1272 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1274 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1276 else
1278 ok(mdi_child != 0, "MDI child creation failed\n");
1279 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1280 ok(id == first_id, "wrong child id %ld\n", id);
1281 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1282 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1285 /* test MDICREATESTRUCT A<->W mapping */
1286 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1287 mdi_cs.style = 0;
1288 mdi_cs.szClass = (LPCSTR)classW;
1289 mdi_cs.szTitle = (LPCSTR)titleW;
1290 SetLastError(0xdeadbeef);
1291 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1292 if (!mdi_child)
1294 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1295 isWin9x = TRUE;
1296 else
1297 ok(mdi_child != 0, "MDI child creation failed\n");
1299 else
1301 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1302 ok(id == first_id, "wrong child id %ld\n", id);
1303 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1304 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1307 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1309 CW_USEDEFAULT, CW_USEDEFAULT,
1310 CW_USEDEFAULT, CW_USEDEFAULT,
1311 mdi_client, GetModuleHandle(0),
1312 (LPARAM)mdi_lParam_test_message);
1313 ok(mdi_child != 0, "MDI child creation failed\n");
1314 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1315 ok(id == first_id, "wrong child id %ld\n", id);
1316 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1317 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1319 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1320 0x7fffffff, /* without WS_POPUP */
1321 CW_USEDEFAULT, CW_USEDEFAULT,
1322 CW_USEDEFAULT, CW_USEDEFAULT,
1323 mdi_client, GetModuleHandle(0),
1324 (LPARAM)mdi_lParam_test_message);
1325 ok(mdi_child != 0, "MDI child creation failed\n");
1326 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1327 ok(id == first_id, "wrong child id %ld\n", id);
1328 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1329 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1331 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1332 0xffffffff, /* with WS_POPUP */
1333 CW_USEDEFAULT, CW_USEDEFAULT,
1334 CW_USEDEFAULT, CW_USEDEFAULT,
1335 mdi_client, GetModuleHandle(0),
1336 (LPARAM)mdi_lParam_test_message);
1337 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1339 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1341 else
1343 ok(mdi_child != 0, "MDI child creation failed\n");
1344 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1345 ok(id == first_id, "wrong child id %ld\n", id);
1346 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1347 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1350 /* test MDICREATESTRUCT A<->W mapping */
1351 SetLastError(0xdeadbeef);
1352 mdi_child = CreateMDIWindowW(classW, titleW,
1354 CW_USEDEFAULT, CW_USEDEFAULT,
1355 CW_USEDEFAULT, CW_USEDEFAULT,
1356 mdi_client, GetModuleHandle(0),
1357 (LPARAM)mdi_lParam_test_message);
1358 if (!mdi_child)
1360 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1361 isWin9x = TRUE;
1362 else
1363 ok(mdi_child != 0, "MDI child creation failed\n");
1365 else
1367 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1368 ok(id == first_id, "wrong child id %ld\n", id);
1369 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1370 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1373 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1375 CW_USEDEFAULT, CW_USEDEFAULT,
1376 CW_USEDEFAULT, CW_USEDEFAULT,
1377 mdi_client, 0, GetModuleHandle(0),
1378 mdi_lParam_test_message);
1379 ok(mdi_child != 0, "MDI child creation failed\n");
1380 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1381 ok(id == first_id, "wrong child id %ld\n", id);
1382 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1383 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1385 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1386 0x7fffffff, /* without WS_POPUP */
1387 CW_USEDEFAULT, CW_USEDEFAULT,
1388 CW_USEDEFAULT, CW_USEDEFAULT,
1389 mdi_client, 0, GetModuleHandle(0),
1390 mdi_lParam_test_message);
1391 ok(mdi_child != 0, "MDI child creation failed\n");
1392 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1393 ok(id == first_id, "wrong child id %ld\n", id);
1394 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1395 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1397 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1398 0xffffffff, /* with WS_POPUP */
1399 CW_USEDEFAULT, CW_USEDEFAULT,
1400 CW_USEDEFAULT, CW_USEDEFAULT,
1401 mdi_client, 0, GetModuleHandle(0),
1402 mdi_lParam_test_message);
1403 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1405 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1407 else
1409 ok(mdi_child != 0, "MDI child creation failed\n");
1410 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1411 ok(id == first_id, "wrong child id %ld\n", id);
1412 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1413 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1416 /* test MDICREATESTRUCT A<->W mapping */
1417 SetLastError(0xdeadbeef);
1418 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1420 CW_USEDEFAULT, CW_USEDEFAULT,
1421 CW_USEDEFAULT, CW_USEDEFAULT,
1422 mdi_client, 0, GetModuleHandle(0),
1423 mdi_lParam_test_message);
1424 if (!mdi_child)
1426 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1427 isWin9x = TRUE;
1428 else
1429 ok(mdi_child != 0, "MDI child creation failed\n");
1431 else
1433 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1434 ok(id == first_id, "wrong child id %ld\n", id);
1435 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1436 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1439 /* This test fails on Win9x */
1440 if (!isWin9x)
1442 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1443 WS_CHILD,
1444 CW_USEDEFAULT, CW_USEDEFAULT,
1445 CW_USEDEFAULT, CW_USEDEFAULT,
1446 parent, 0, GetModuleHandle(0),
1447 mdi_lParam_test_message);
1448 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1451 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1452 WS_CHILD, /* without WS_POPUP */
1453 CW_USEDEFAULT, CW_USEDEFAULT,
1454 CW_USEDEFAULT, CW_USEDEFAULT,
1455 mdi_client, 0, GetModuleHandle(0),
1456 mdi_lParam_test_message);
1457 ok(mdi_child != 0, "MDI child creation failed\n");
1458 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1459 ok(id == 0, "wrong child id %ld\n", id);
1460 DestroyWindow(mdi_child);
1462 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1463 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1464 CW_USEDEFAULT, CW_USEDEFAULT,
1465 CW_USEDEFAULT, CW_USEDEFAULT,
1466 mdi_client, 0, GetModuleHandle(0),
1467 mdi_lParam_test_message);
1468 ok(mdi_child != 0, "MDI child creation failed\n");
1469 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1470 ok(id == 0, "wrong child id %ld\n", id);
1471 DestroyWindow(mdi_child);
1473 /* maximized child */
1474 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1475 WS_CHILD | WS_MAXIMIZE,
1476 CW_USEDEFAULT, CW_USEDEFAULT,
1477 CW_USEDEFAULT, CW_USEDEFAULT,
1478 mdi_client, 0, GetModuleHandle(0),
1479 mdi_lParam_test_message);
1480 ok(mdi_child != 0, "MDI child creation failed\n");
1481 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1482 ok(id == 0, "wrong child id %ld\n", id);
1483 DestroyWindow(mdi_child);
1485 trace("Creating maximized child with a caption\n");
1486 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1487 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1488 CW_USEDEFAULT, CW_USEDEFAULT,
1489 CW_USEDEFAULT, CW_USEDEFAULT,
1490 mdi_client, 0, GetModuleHandle(0),
1491 mdi_lParam_test_message);
1492 ok(mdi_child != 0, "MDI child creation failed\n");
1493 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1494 ok(id == 0, "wrong child id %ld\n", id);
1495 DestroyWindow(mdi_child);
1497 trace("Creating maximized child with a caption and a thick frame\n");
1498 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1499 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1500 CW_USEDEFAULT, CW_USEDEFAULT,
1501 CW_USEDEFAULT, CW_USEDEFAULT,
1502 mdi_client, 0, GetModuleHandle(0),
1503 mdi_lParam_test_message);
1504 ok(mdi_child != 0, "MDI child creation failed\n");
1505 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1506 ok(id == 0, "wrong child id %ld\n", id);
1507 DestroyWindow(mdi_child);
1510 /**********************************************************************
1511 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1513 * Note: The rule here is that client rect of the maximized MDI child
1514 * is equal to the client rect of the MDI client window.
1516 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1518 RECT rect;
1520 GetClientRect( client, &rect );
1521 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1522 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1524 rect.right -= rect.left;
1525 rect.bottom -= rect.top;
1526 lpMinMax->ptMaxSize.x = rect.right;
1527 lpMinMax->ptMaxSize.y = rect.bottom;
1529 lpMinMax->ptMaxPosition.x = rect.left;
1530 lpMinMax->ptMaxPosition.y = rect.top;
1532 trace("max rect (%d,%d - %d, %d)\n",
1533 rect.left, rect.top, rect.right, rect.bottom);
1536 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1538 switch (msg)
1540 case WM_NCCREATE:
1541 case WM_CREATE:
1543 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1544 MDICREATESTRUCTA *mdi_cs = cs->lpCreateParams;
1546 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1547 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1549 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1550 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1551 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1552 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1553 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1555 /* MDICREATESTRUCT should have original values */
1556 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1557 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1558 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1559 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1560 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1561 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1563 /* CREATESTRUCT should have fixed values */
1564 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1565 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1567 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1568 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1569 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1571 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1573 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1575 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1576 ok(cs->style == style,
1577 "cs->style does not match (%08x)\n", cs->style);
1579 else
1581 LONG style = mdi_cs->style;
1582 style &= ~WS_POPUP;
1583 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1584 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1585 ok(cs->style == style,
1586 "cs->style does not match (%08x)\n", cs->style);
1588 break;
1591 case WM_GETMINMAXINFO:
1593 HWND client = GetParent(hwnd);
1594 RECT rc;
1595 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1596 MINMAXINFO my_minmax;
1597 LONG style, exstyle;
1599 style = GetWindowLongA(hwnd, GWL_STYLE);
1600 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1602 GetWindowRect(client, &rc);
1603 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1604 GetClientRect(client, &rc);
1605 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1606 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1607 GetSystemMetrics(SM_CYSCREEN));
1609 GetClientRect(client, &rc);
1610 if ((style & WS_CAPTION) == WS_CAPTION)
1611 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1612 AdjustWindowRectEx(&rc, style, 0, exstyle);
1613 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1614 dump_minmax_info( minmax );
1616 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1617 minmax->ptMaxSize.x, rc.right - rc.left);
1618 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1619 minmax->ptMaxSize.y, rc.bottom - rc.top);
1621 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1623 trace("DefMDIChildProc returned:\n");
1624 dump_minmax_info( minmax );
1626 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1627 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1628 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1629 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1630 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1632 return 1;
1635 case WM_MDIACTIVATE:
1637 HWND active, client = GetParent(hwnd);
1638 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1639 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1640 if (hwnd == (HWND)lparam) /* if we are being activated */
1641 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1642 else
1643 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1644 break;
1647 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1650 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1652 switch (msg)
1654 case WM_NCCREATE:
1655 case WM_CREATE:
1657 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1659 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE",
1660 cs->x, cs->y, cs->cx, cs->cy);
1662 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1663 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1665 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1666 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1668 /* CREATESTRUCT should have fixed values */
1669 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1670 while NT does. */
1671 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1672 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1674 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1675 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1676 while Win95, Win2k, WinXP do. */
1677 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1678 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1679 break;
1682 case WM_GETMINMAXINFO:
1684 HWND parent = GetParent(hwnd);
1685 RECT rc;
1686 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1687 LONG style, exstyle;
1689 style = GetWindowLongA(hwnd, GWL_STYLE);
1690 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1692 GetClientRect(parent, &rc);
1693 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1695 GetClientRect(parent, &rc);
1696 if ((style & WS_CAPTION) == WS_CAPTION)
1697 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1698 AdjustWindowRectEx(&rc, style, 0, exstyle);
1699 dump_minmax_info( minmax );
1701 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1702 minmax->ptMaxSize.x, rc.right - rc.left);
1703 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1704 minmax->ptMaxSize.y, rc.bottom - rc.top);
1705 break;
1708 case WM_WINDOWPOSCHANGED:
1710 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1711 RECT rc1, rc2;
1713 GetWindowRect(hwnd, &rc1);
1714 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1715 /* note: winpos coordinates are relative to parent */
1716 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1717 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) pos=(%d,%d)-(%d,%d)\n",
1718 rc1.left, rc1.top, rc1.right, rc1.bottom,
1719 rc2.left, rc2.top, rc2.right, rc2.bottom);
1720 GetWindowRect(hwnd, &rc1);
1721 GetClientRect(hwnd, &rc2);
1722 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1723 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1724 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1725 rc1.left, rc1.top, rc1.right, rc1.bottom,
1726 rc2.left, rc2.top, rc2.right, rc2.bottom);
1728 /* fall through */
1729 case WM_WINDOWPOSCHANGING:
1731 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1732 WINDOWPOS my_winpos = *winpos;
1734 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1735 (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
1736 winpos->hwnd, winpos->hwndInsertAfter,
1737 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1739 DefWindowProcA(hwnd, msg, wparam, lparam);
1741 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1742 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1743 winpos->hwnd, winpos->hwndInsertAfter,
1744 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1746 return 1;
1749 return DefWindowProcA(hwnd, msg, wparam, lparam);
1752 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1754 static HWND mdi_client;
1756 switch (msg)
1758 case WM_CREATE:
1760 CLIENTCREATESTRUCT client_cs;
1761 RECT rc;
1763 GetClientRect(hwnd, &rc);
1765 client_cs.hWindowMenu = 0;
1766 client_cs.idFirstChild = 1;
1768 /* MDIClient without MDIS_ALLCHILDSTYLES */
1769 mdi_client = CreateWindowExA(0, "mdiclient",
1770 NULL,
1771 WS_CHILD /*| WS_VISIBLE*/,
1772 /* tests depend on a not zero MDIClient size */
1773 0, 0, rc.right, rc.bottom,
1774 hwnd, 0, GetModuleHandle(0),
1775 &client_cs);
1776 assert(mdi_client);
1777 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1778 DestroyWindow(mdi_client);
1780 /* MDIClient with MDIS_ALLCHILDSTYLES */
1781 mdi_client = CreateWindowExA(0, "mdiclient",
1782 NULL,
1783 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1784 /* tests depend on a not zero MDIClient size */
1785 0, 0, rc.right, rc.bottom,
1786 hwnd, 0, GetModuleHandle(0),
1787 &client_cs);
1788 assert(mdi_client);
1789 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1790 DestroyWindow(mdi_client);
1791 break;
1794 case WM_WINDOWPOSCHANGED:
1796 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1797 RECT rc1, rc2;
1799 GetWindowRect(hwnd, &rc1);
1800 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1801 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1802 /* note: winpos coordinates are relative to parent */
1803 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1804 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1805 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1807 GetWindowRect(hwnd, &rc1);
1808 GetClientRect(hwnd, &rc2);
1809 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1810 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1811 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1813 /* fall through */
1814 case WM_WINDOWPOSCHANGING:
1816 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1817 WINDOWPOS my_winpos = *winpos;
1819 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1820 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1821 winpos->hwnd, winpos->hwndInsertAfter,
1822 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1824 DefWindowProcA(hwnd, msg, wparam, lparam);
1826 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1827 winpos->hwnd, winpos->hwndInsertAfter,
1828 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1830 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1831 "DefWindowProc should not change WINDOWPOS values\n");
1833 return 1;
1836 case WM_CLOSE:
1837 PostQuitMessage(0);
1838 break;
1840 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1843 static BOOL mdi_RegisterWindowClasses(void)
1845 WNDCLASSA cls;
1847 cls.style = 0;
1848 cls.lpfnWndProc = mdi_main_wnd_procA;
1849 cls.cbClsExtra = 0;
1850 cls.cbWndExtra = 0;
1851 cls.hInstance = GetModuleHandleA(0);
1852 cls.hIcon = 0;
1853 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1854 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1855 cls.lpszMenuName = NULL;
1856 cls.lpszClassName = "MDI_parent_Class";
1857 if(!RegisterClassA(&cls)) return FALSE;
1859 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1860 cls.lpszClassName = "MDI_child_Class_1";
1861 if(!RegisterClassA(&cls)) return FALSE;
1863 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1864 cls.lpszClassName = "MDI_child_Class_2";
1865 if(!RegisterClassA(&cls)) return FALSE;
1867 return TRUE;
1870 static void test_mdi(void)
1872 HWND mdi_hwndMain;
1873 /*MSG msg;*/
1875 if (!mdi_RegisterWindowClasses()) assert(0);
1877 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1878 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1879 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1880 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1881 GetDesktopWindow(), 0,
1882 GetModuleHandle(0), NULL);
1883 assert(mdi_hwndMain);
1885 while(GetMessage(&msg, 0, 0, 0))
1887 TranslateMessage(&msg);
1888 DispatchMessage(&msg);
1891 DestroyWindow(mdi_hwndMain);
1894 static void test_icons(void)
1896 WNDCLASSEXA cls;
1897 HWND hwnd;
1898 HICON icon = LoadIconA(0, IDI_APPLICATION);
1899 HICON icon2 = LoadIconA(0, IDI_QUESTION);
1900 HICON small_icon = LoadImageA(0, IDI_APPLICATION, IMAGE_ICON,
1901 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1902 HICON res;
1904 cls.cbSize = sizeof(cls);
1905 cls.style = 0;
1906 cls.lpfnWndProc = DefWindowProcA;
1907 cls.cbClsExtra = 0;
1908 cls.cbWndExtra = 0;
1909 cls.hInstance = 0;
1910 cls.hIcon = LoadIconA(0, IDI_HAND);
1911 cls.hIconSm = small_icon;
1912 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1913 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1914 cls.lpszMenuName = NULL;
1915 cls.lpszClassName = "IconWindowClass";
1917 RegisterClassExA(&cls);
1919 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1920 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1921 assert( hwnd );
1923 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1924 ok( res == 0, "wrong big icon %p/0\n", res );
1925 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1926 ok( res == 0, "wrong previous big icon %p/0\n", res );
1927 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1928 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1929 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1930 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1931 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1932 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1934 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1935 ok( res == 0, "wrong small icon %p/0\n", res );
1936 /* this test is XP specific */
1937 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1938 ok( res != 0, "wrong small icon %p\n", res );*/
1939 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1940 ok( res == 0, "wrong previous small icon %p/0\n", res );
1941 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1942 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1943 /* this test is XP specific */
1944 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1945 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1946 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1947 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1948 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1949 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1950 /* this test is XP specific */
1951 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1952 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1954 /* make sure the big icon hasn't changed */
1955 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1956 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1958 DestroyWindow( hwnd );
1961 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1963 if (msg == WM_NCCALCSIZE)
1965 RECT *rect = (RECT *)lparam;
1966 /* first time around increase the rectangle, next time decrease it */
1967 if (rect->left == 100) InflateRect( rect, 10, 10 );
1968 else InflateRect( rect, -10, -10 );
1969 return 0;
1971 return DefWindowProc( hwnd, msg, wparam, lparam );
1974 static void test_SetWindowPos(HWND hwnd, HWND hwnd2)
1976 RECT orig_win_rc, rect;
1977 LONG_PTR old_proc;
1978 HWND hwnd_grandchild, hwnd_child, hwnd_child2;
1979 HWND hwnd_desktop;
1980 RECT rc1, rc2;
1981 BOOL ret;
1983 SetRect(&rect, 111, 222, 333, 444);
1984 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1985 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1986 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1988 SetRect(&rect, 111, 222, 333, 444);
1989 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1990 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1991 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1993 GetWindowRect(hwnd, &orig_win_rc);
1995 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1996 ret = SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1997 ok(ret, "Got %d\n", ret);
1998 GetWindowRect( hwnd, &rect );
1999 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
2000 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2001 GetClientRect( hwnd, &rect );
2002 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
2003 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
2004 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2006 ret = SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
2007 ok(ret, "Got %d\n", ret);
2008 GetWindowRect( hwnd, &rect );
2009 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
2010 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2011 GetClientRect( hwnd, &rect );
2012 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
2013 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
2014 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2016 ret = SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
2017 orig_win_rc.right, orig_win_rc.bottom, 0);
2018 ok(ret, "Got %d\n", ret);
2019 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
2021 /* Win9x truncates coordinates to 16-bit irrespectively */
2022 if (!is_win9x)
2024 ret = SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
2025 ok(ret, "Got %d\n", ret);
2026 ret = SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
2027 ok(ret, "Got %d\n", ret);
2029 ret = SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
2030 ok(ret, "Got %d\n", ret);
2031 ret = SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
2032 ok(ret, "Got %d\n", ret);
2035 ret = SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
2036 orig_win_rc.right, orig_win_rc.bottom, 0);
2037 ok(ret, "Got %d\n", ret);
2039 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
2040 ret = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
2041 ok(ret, "Got %d\n", ret);
2042 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
2043 ret = SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
2044 ok(ret, "Got %d\n", ret);
2045 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
2046 ret = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
2047 ok(ret, "Got %d\n", ret);
2048 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
2050 hwnd_desktop = GetDesktopWindow();
2051 ok(!!hwnd_desktop, "Failed to get hwnd_desktop window (%d).\n", GetLastError());
2052 hwnd_child = create_tool_window(WS_VISIBLE|WS_CHILD, hwnd);
2053 ok(!!hwnd_child, "Failed to create child window (%d)\n", GetLastError());
2054 hwnd_grandchild = create_tool_window(WS_VISIBLE|WS_CHILD, hwnd_child);
2055 ok(!!hwnd_child, "Failed to create child window (%d)\n", GetLastError());
2056 hwnd_child2 = create_tool_window(WS_VISIBLE|WS_CHILD, hwnd);
2057 ok(!!hwnd_child2, "Failed to create second child window (%d)\n", GetLastError());
2059 ret = SetWindowPos(hwnd, hwnd2, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2060 ok(ret, "Got %d\n", ret);
2061 check_active_state(hwnd, hwnd, hwnd);
2063 ret = SetWindowPos(hwnd2, hwnd, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2064 ok(ret, "Got %d\n", ret);
2065 check_active_state(hwnd2, hwnd2, hwnd2);
2067 /* Returns TRUE also for windows that are not siblings */
2068 ret = SetWindowPos(hwnd_child, hwnd2, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2069 ok(ret, "Got %d\n", ret);
2070 check_active_state(hwnd2, hwnd2, hwnd2);
2072 ret = SetWindowPos(hwnd2, hwnd_child, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2073 ok(ret, "Got %d\n", ret);
2074 check_active_state(hwnd2, hwnd2, hwnd2);
2076 /* Does not seem to do anything even without passing flags, still returns TRUE */
2077 GetWindowRect(hwnd_child, &rc1);
2078 ret = SetWindowPos(hwnd_child, hwnd2 , 1, 2, 3, 4, 0);
2079 ok(ret, "Got %d\n", ret);
2080 GetWindowRect(hwnd_child, &rc2);
2081 ok(rc1.left == rc2.left && rc1.top == rc2.top &&
2082 rc1.right == rc2.right && rc1.bottom == rc2.bottom,
2083 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2084 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
2085 check_active_state(hwnd2, hwnd2, hwnd2);
2087 /* Same thing the other way around. */
2088 GetWindowRect(hwnd2, &rc1);
2089 ret = SetWindowPos(hwnd2, hwnd_child, 1, 2, 3, 4, 0);
2090 ok(ret, "Got %d\n", ret);
2091 GetWindowRect(hwnd2, &rc2);
2092 ok(rc1.left == rc2.left && rc1.top == rc2.top &&
2093 rc1.right == rc2.right && rc1.bottom == rc2.bottom,
2094 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2095 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
2096 check_active_state(hwnd2, hwnd2, hwnd2);
2098 /* .. and with these windows. */
2099 GetWindowRect(hwnd_grandchild, &rc1);
2100 ret = SetWindowPos(hwnd_grandchild, hwnd_child2, 1, 2, 3, 4, 0);
2101 ok(ret, "Got %d\n", ret);
2102 GetWindowRect(hwnd_grandchild, &rc2);
2103 ok(rc1.left == rc2.left && rc1.top == rc2.top &&
2104 rc1.right == rc2.right && rc1.bottom == rc2.bottom,
2105 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2106 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
2107 check_active_state(hwnd2, hwnd2, hwnd2);
2109 /* Add SWP_NOZORDER and it will be properly resized. */
2110 GetWindowRect(hwnd_grandchild, &rc1);
2111 ret = SetWindowPos(hwnd_grandchild, hwnd_child2, 1, 2, 3, 4, SWP_NOZORDER);
2112 ok(ret, "Got %d\n", ret);
2113 GetWindowRect(hwnd_grandchild, &rc2);
2114 ok((rc1.left+1) == rc2.left && (rc1.top+2) == rc2.top &&
2115 (rc1.left+4) == rc2.right && (rc1.top+6) == rc2.bottom,
2116 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2117 rc1.left+1, rc1.top+2, rc1.left+4, rc1.top+6, rc2.left, rc2.top, rc2.right, rc2.bottom);
2118 check_active_state(hwnd2, hwnd2, hwnd2);
2120 /* Given a sibling window, the window is properly resized. */
2121 GetWindowRect(hwnd_child, &rc1);
2122 ret = SetWindowPos(hwnd_child, hwnd_child2, 1, 2, 3, 4, 0);
2123 ok(ret, "Got %d\n", ret);
2124 GetWindowRect(hwnd_child, &rc2);
2125 ok((rc1.left+1) == rc2.left && (rc1.top+2) == rc2.top &&
2126 (rc1.left+4) == rc2.right && (rc1.top+6) == rc2.bottom,
2127 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2128 rc1.left+1, rc1.top+2, rc1.left+4, rc1.top+6, rc2.left, rc2.top, rc2.right, rc2.bottom);
2129 check_active_state(hwnd2, hwnd2, hwnd2);
2131 /* Involving the desktop window changes things. */
2132 ret = SetWindowPos(hwnd_child, hwnd_desktop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2133 ok(!ret, "Got %d\n", ret);
2134 check_active_state(hwnd2, hwnd2, hwnd2);
2136 GetWindowRect(hwnd_child, &rc1);
2137 ret = SetWindowPos(hwnd_child, hwnd_desktop, 0, 0, 0, 0, 0);
2138 ok(!ret, "Got %d\n", ret);
2139 GetWindowRect(hwnd_child, &rc2);
2140 ok(rc1.top == rc2.top && rc1.left == rc2.left &&
2141 rc1.bottom == rc2.bottom && rc1.right == rc2.right,
2142 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2143 rc1.top, rc1.left, rc1.bottom, rc1.right, rc2.top, rc2.left, rc2.bottom, rc2.right);
2144 check_active_state(hwnd2, hwnd2, hwnd2);
2146 ret = SetWindowPos(hwnd_desktop, hwnd_child, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2147 ok(!ret, "Got %d\n", ret);
2148 check_active_state(hwnd2, hwnd2, hwnd2);
2150 ret = SetWindowPos(hwnd_desktop, hwnd, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2151 ok(!ret, "Got %d\n", ret);
2152 check_active_state(hwnd2, hwnd2, hwnd2);
2154 ret = SetWindowPos(hwnd, hwnd_desktop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2155 ok(!ret, "Got %d\n", ret);
2156 check_active_state(hwnd2, hwnd2, hwnd2);
2158 DestroyWindow(hwnd_grandchild);
2159 DestroyWindow(hwnd_child);
2160 DestroyWindow(hwnd_child2);
2162 hwnd_child = create_tool_window(WS_CHILD|WS_POPUP|WS_SYSMENU, hwnd2);
2163 ok(!!hwnd_child, "Failed to create child window (%d)\n", GetLastError());
2164 ret = SetWindowPos(hwnd_child, NULL, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2165 ok(ret, "Got %d\n", ret);
2166 flush_events( TRUE );
2167 todo_wine check_active_state(hwnd2, hwnd2, hwnd2);
2168 DestroyWindow(hwnd_child);
2171 static void test_SetMenu(HWND parent)
2173 HWND child;
2174 HMENU hMenu, ret;
2175 BOOL retok;
2176 DWORD style;
2178 hMenu = CreateMenu();
2179 assert(hMenu);
2181 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2182 if (0)
2184 /* fails on (at least) Wine, NT4, XP SP2 */
2185 test_nonclient_area(parent);
2187 ret = GetMenu(parent);
2188 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2189 /* test whether we can destroy a menu assigned to a window */
2190 retok = DestroyMenu(hMenu);
2191 ok( retok, "DestroyMenu error %d\n", GetLastError());
2192 retok = IsMenu(hMenu);
2193 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
2194 ret = GetMenu(parent);
2195 /* This test fails on Win9x */
2196 if (!is_win9x)
2197 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2198 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2199 test_nonclient_area(parent);
2201 hMenu = CreateMenu();
2202 assert(hMenu);
2204 /* parent */
2205 ret = GetMenu(parent);
2206 ok(ret == 0, "unexpected menu id %p\n", ret);
2208 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2209 test_nonclient_area(parent);
2210 ret = GetMenu(parent);
2211 ok(ret == 0, "unexpected menu id %p\n", ret);
2213 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2214 if (0)
2216 /* fails on (at least) Wine, NT4, XP SP2 */
2217 test_nonclient_area(parent);
2219 ret = GetMenu(parent);
2220 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2222 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2223 test_nonclient_area(parent);
2224 ret = GetMenu(parent);
2225 ok(ret == 0, "unexpected menu id %p\n", ret);
2227 /* child */
2228 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
2229 assert(child);
2231 ret = GetMenu(child);
2232 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2234 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2235 test_nonclient_area(child);
2236 ret = GetMenu(child);
2237 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2239 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
2240 test_nonclient_area(child);
2241 ret = GetMenu(child);
2242 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2244 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
2245 test_nonclient_area(child);
2246 ret = GetMenu(child);
2247 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2249 style = GetWindowLong(child, GWL_STYLE);
2250 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
2251 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
2252 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
2253 SetWindowLong(child, GWL_STYLE, style);
2255 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
2256 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
2257 SetWindowLong(child, GWL_STYLE, style);
2259 DestroyWindow(child);
2260 DestroyMenu(hMenu);
2263 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
2265 HWND child[5], hwnd;
2266 INT_PTR i;
2268 assert(total <= 5);
2270 hwnd = GetWindow(parent, GW_CHILD);
2271 ok(!hwnd, "have to start without children to perform the test\n");
2273 for (i = 0; i < total; i++)
2275 if (style[i] & DS_CONTROL)
2277 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
2278 0,0,0,0, parent, (HMENU)i, 0, NULL);
2279 if (style[i] & WS_VISIBLE)
2280 ShowWindow(child[i], SW_SHOW);
2282 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
2284 else
2285 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
2286 parent, (HMENU)i, 0, NULL);
2287 trace("child[%ld] = %p\n", i, child[i]);
2288 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
2291 hwnd = GetWindow(parent, GW_CHILD);
2292 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
2293 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
2294 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
2296 for (i = 0; i < total; i++)
2298 trace("hwnd[%ld] = %p\n", i, hwnd);
2299 ok(child[order[i]] == hwnd, "Z order of child #%ld is wrong\n", i);
2301 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
2304 for (i = 0; i < total; i++)
2305 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2308 static void test_children_zorder(HWND parent)
2310 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2311 WS_CHILD };
2312 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2314 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2315 WS_CHILD | WS_VISIBLE, WS_CHILD,
2316 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2317 const int complex_order_1[1] = { 0 };
2318 const int complex_order_2[2] = { 1, 0 };
2319 const int complex_order_3[3] = { 1, 0, 2 };
2320 const int complex_order_4[4] = { 1, 0, 2, 3 };
2321 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2322 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2323 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2324 WS_CHILD | WS_VISIBLE };
2325 const int complex_order_6[3] = { 0, 1, 2 };
2327 /* simple WS_CHILD */
2328 test_window_tree(parent, simple_style, simple_order, 5);
2330 /* complex children styles */
2331 test_window_tree(parent, complex_style, complex_order_1, 1);
2332 test_window_tree(parent, complex_style, complex_order_2, 2);
2333 test_window_tree(parent, complex_style, complex_order_3, 3);
2334 test_window_tree(parent, complex_style, complex_order_4, 4);
2335 test_window_tree(parent, complex_style, complex_order_5, 5);
2337 /* another set of complex children styles */
2338 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2341 #define check_z_order(hwnd, next, prev, owner, topmost) \
2342 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2343 __FILE__, __LINE__)
2345 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2346 BOOL topmost, const char *file, int line)
2348 HWND test;
2349 DWORD ex_style;
2351 test = GetWindow(hwnd, GW_HWNDNEXT);
2352 /* skip foreign windows */
2353 while (test && test != next &&
2354 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2355 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2356 GetWindow(test, GW_OWNER) == next))
2358 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2359 test = GetWindow(test, GW_HWNDNEXT);
2361 ok_(file, line)(next == test, "%p: expected next %p, got %p\n", hwnd, next, test);
2363 test = GetWindow(hwnd, GW_HWNDPREV);
2364 /* skip foreign windows */
2365 while (test && test != prev &&
2366 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2367 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2368 GetWindow(test, GW_OWNER) == hwnd))
2370 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2371 test = GetWindow(test, GW_HWNDPREV);
2373 ok_(file, line)(prev == test, "%p: expected prev %p, got %p\n", hwnd, prev, test);
2375 test = GetWindow(hwnd, GW_OWNER);
2376 ok_(file, line)(owner == test, "%p: expected owner %p, got %p\n", hwnd, owner, test);
2378 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2379 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "%p: expected %stopmost\n",
2380 hwnd, topmost ? "" : "NOT ");
2383 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E, DWORD style)
2385 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2387 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2389 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2391 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2392 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2394 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2395 WS_OVERLAPPED | WS_CAPTION,
2396 100, 100, 100, 100,
2397 0, 0, GetModuleHandle(0), NULL);
2398 trace("hwnd_F %p\n", hwnd_F);
2399 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2401 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2402 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2403 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2404 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2406 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2407 style,
2408 100, 100, 100, 100,
2409 hwnd_F, 0, GetModuleHandle(0), NULL);
2410 trace("hwnd_C %p\n", hwnd_C);
2411 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2412 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2413 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2414 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2416 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2417 style,
2418 100, 100, 100, 100,
2419 hwnd_F, 0, GetModuleHandle(0), NULL);
2420 trace("hwnd_B %p\n", hwnd_B);
2421 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2422 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2423 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2424 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2425 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2427 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2428 style,
2429 100, 100, 100, 100,
2430 0, 0, GetModuleHandle(0), NULL);
2431 trace("hwnd_A %p\n", hwnd_A);
2432 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2433 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2434 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2435 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2436 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2437 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2439 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);
2441 /* move hwnd_F and its popups up */
2442 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2443 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2444 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2445 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2446 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2447 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2448 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2450 /* move hwnd_F and its popups down */
2451 #if 0 /* enable once Wine is fixed to pass this test */
2452 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2453 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2454 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2455 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2456 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2457 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2458 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2459 #endif
2461 /* make hwnd_C owned by a topmost window */
2462 DestroyWindow( hwnd_C );
2463 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2464 style,
2465 100, 100, 100, 100,
2466 hwnd_A, 0, GetModuleHandle(0), NULL);
2467 trace("hwnd_C %p\n", hwnd_C);
2468 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2469 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2470 check_z_order(hwnd_F, hwnd_D, hwnd_B, 0, FALSE);
2471 check_z_order(hwnd_B, hwnd_F, hwnd_A, hwnd_F, TRUE);
2472 check_z_order(hwnd_A, hwnd_B, hwnd_C, 0, TRUE);
2473 check_z_order(hwnd_C, hwnd_A, 0, hwnd_A, TRUE);
2475 DestroyWindow(hwnd_A);
2476 DestroyWindow(hwnd_B);
2477 DestroyWindow(hwnd_C);
2478 DestroyWindow(hwnd_F);
2481 static void test_vis_rgn( HWND hwnd )
2483 RECT win_rect, rgn_rect;
2484 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2485 HDC hdc;
2487 ShowWindow(hwnd,SW_SHOW);
2488 hdc = GetDC( hwnd );
2489 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2490 GetWindowRect( hwnd, &win_rect );
2491 GetRgnBox( hrgn, &rgn_rect );
2492 if (is_win9x)
2494 trace("win9x, mapping to screen coords\n");
2495 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2497 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2498 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2499 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2500 rgn_rect.left, win_rect.left );
2501 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2502 rgn_rect.top, win_rect.top );
2503 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2504 rgn_rect.right, win_rect.right );
2505 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2506 rgn_rect.bottom, win_rect.bottom );
2507 ReleaseDC( hwnd, hdc );
2510 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2512 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2514 HWND child = GetWindow(hwnd, GW_CHILD);
2515 ok(child != 0, "couldn't find child window\n");
2516 SetFocus(child);
2517 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2518 return 0;
2520 return DefWindowProc(hwnd, msg, wp, lp);
2523 static void test_SetFocus(HWND hwnd)
2525 HWND child, child2, ret;
2526 WNDPROC old_wnd_proc;
2528 /* check if we can set focus to non-visible windows */
2530 ShowWindow(hwnd, SW_SHOW);
2531 SetFocus(0);
2532 SetFocus(hwnd);
2533 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2534 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2535 ShowWindow(hwnd, SW_HIDE);
2536 SetFocus(0);
2537 SetFocus(hwnd);
2538 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2539 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2540 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2541 assert(child);
2542 SetFocus(child);
2543 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2544 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2545 ShowWindow(child, SW_SHOW);
2546 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2547 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2548 ShowWindow(child, SW_HIDE);
2549 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2550 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2551 ShowWindow(child, SW_SHOW);
2552 child2 = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, child, 0, 0, NULL);
2553 assert(child2);
2554 ShowWindow(child2, SW_SHOW);
2555 SetFocus(child2);
2556 ShowWindow(child, SW_HIDE);
2557 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2558 ok( GetFocus() == child2, "Focus should be on %p, not %p\n", child2, GetFocus() );
2559 ShowWindow(child, SW_SHOW);
2560 SetFocus(child);
2561 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2562 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2563 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2565 ShowWindow(child, SW_HIDE);
2566 SetFocus(hwnd);
2567 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2568 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2569 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2570 ShowWindow(child, SW_HIDE);
2571 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2573 ShowWindow(hwnd, SW_SHOW);
2574 ShowWindow(child, SW_SHOW);
2575 SetFocus(child);
2576 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2577 EnableWindow(hwnd, FALSE);
2578 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2579 EnableWindow(hwnd, TRUE);
2581 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2582 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2583 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2584 todo_wine
2585 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2586 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2587 ShowWindow(hwnd, SW_RESTORE);
2588 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2589 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2590 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2591 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2592 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2593 todo_wine
2594 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2595 old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2596 ShowWindow(hwnd, SW_RESTORE);
2597 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2598 todo_wine
2599 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2600 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2602 SetFocus( hwnd );
2603 SetParent( child, GetDesktopWindow());
2604 SetParent( child2, child );
2605 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2606 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2607 ret = SetFocus( child2 );
2608 ok( ret == 0, "SetFocus %p should fail\n", child2);
2609 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2610 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2611 ret = SetFocus( child );
2612 ok( ret == 0, "SetFocus %p should fail\n", child);
2613 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2614 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2615 SetWindowLongW( child, GWL_STYLE, WS_POPUP|WS_CHILD );
2616 SetFocus( child2 );
2617 ok( GetActiveWindow() == child, "child window %p should be active\n", child);
2618 ok( GetFocus() == child2, "Focus should be on child2 %p\n", child2 );
2619 SetFocus( hwnd );
2620 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2621 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2622 SetFocus( child );
2623 ok( GetActiveWindow() == child, "child window %p should be active\n", child);
2624 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2626 DestroyWindow( child2 );
2627 DestroyWindow( child );
2630 static void test_SetActiveWindow(HWND hwnd)
2632 HWND hwnd2;
2634 flush_events( TRUE );
2635 ShowWindow(hwnd, SW_HIDE);
2636 SetFocus(0);
2637 SetActiveWindow(0);
2638 check_wnd_state(0, 0, 0, 0);
2640 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2642 ShowWindow(hwnd, SW_SHOW);
2643 check_wnd_state(hwnd, hwnd, hwnd, 0);
2645 hwnd2 = SetActiveWindow(0);
2646 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2647 if (!GetActiveWindow()) /* doesn't always work on vista */
2649 check_wnd_state(0, 0, 0, 0);
2650 hwnd2 = SetActiveWindow(hwnd);
2651 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2653 check_wnd_state(hwnd, hwnd, hwnd, 0);
2655 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2656 check_wnd_state(hwnd, hwnd, hwnd, 0);
2658 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2659 check_wnd_state(hwnd, hwnd, hwnd, 0);
2661 ShowWindow(hwnd, SW_HIDE);
2662 check_wnd_state(0, 0, 0, 0);
2664 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2665 SetActiveWindow(hwnd);
2666 check_wnd_state(hwnd, hwnd, hwnd, 0);
2668 ShowWindow(hwnd, SW_SHOW);
2669 check_wnd_state(hwnd, hwnd, hwnd, 0);
2671 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2672 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2674 DestroyWindow(hwnd2);
2675 check_wnd_state(hwnd, hwnd, hwnd, 0);
2677 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2678 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2680 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2681 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2683 DestroyWindow(hwnd2);
2684 check_wnd_state(hwnd, hwnd, hwnd, 0);
2687 struct create_window_thread_params
2689 HWND window;
2690 HANDLE window_created;
2691 HANDLE test_finished;
2694 static DWORD WINAPI create_window_thread(void *param)
2696 struct create_window_thread_params *p = param;
2697 DWORD res;
2698 BOOL ret;
2700 p->window = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
2702 ret = SetEvent(p->window_created);
2703 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
2705 res = WaitForSingleObject(p->test_finished, INFINITE);
2706 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2708 DestroyWindow(p->window);
2709 return 0;
2712 static void test_SetForegroundWindow(HWND hwnd)
2714 struct create_window_thread_params thread_params;
2715 HANDLE thread;
2716 DWORD res, tid;
2717 BOOL ret;
2718 HWND hwnd2;
2719 MSG msg;
2721 flush_events( TRUE );
2722 ShowWindow(hwnd, SW_HIDE);
2723 SetFocus(0);
2724 SetActiveWindow(0);
2725 check_wnd_state(0, 0, 0, 0);
2727 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2729 ShowWindow(hwnd, SW_SHOW);
2730 check_wnd_state(hwnd, hwnd, hwnd, 0);
2732 hwnd2 = SetActiveWindow(0);
2733 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2734 if (GetActiveWindow() == hwnd) /* doesn't always work on vista */
2735 check_wnd_state(hwnd, hwnd, hwnd, 0);
2736 else
2737 check_wnd_state(0, 0, 0, 0);
2739 ret = SetForegroundWindow(hwnd);
2740 if (!ret)
2742 skip( "SetForegroundWindow not working\n" );
2743 return;
2745 check_wnd_state(hwnd, hwnd, hwnd, 0);
2747 SetLastError(0xdeadbeef);
2748 ret = SetForegroundWindow(0);
2749 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2750 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
2751 broken(GetLastError() == 0xdeadbeef), /* win9x */
2752 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2753 check_wnd_state(hwnd, hwnd, hwnd, 0);
2755 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2756 check_wnd_state(hwnd, hwnd, hwnd, 0);
2758 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2759 check_wnd_state(hwnd, hwnd, hwnd, 0);
2761 hwnd2 = GetForegroundWindow();
2762 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2763 ret = SetForegroundWindow( GetDesktopWindow() );
2764 ok(ret, "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2765 hwnd2 = GetForegroundWindow();
2766 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2768 ShowWindow(hwnd, SW_HIDE);
2769 check_wnd_state(0, 0, 0, 0);
2771 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2772 ret = SetForegroundWindow(hwnd);
2773 ok(ret || broken(!ret), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
2774 check_wnd_state(hwnd, hwnd, hwnd, 0);
2776 ShowWindow(hwnd, SW_SHOW);
2777 check_wnd_state(hwnd, hwnd, hwnd, 0);
2779 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2780 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2782 DestroyWindow(hwnd2);
2783 check_wnd_state(hwnd, hwnd, hwnd, 0);
2785 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2786 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2788 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2789 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2791 DestroyWindow(hwnd2);
2792 check_wnd_state(hwnd, hwnd, hwnd, 0);
2794 hwnd2 = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
2795 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2797 thread_params.window_created = CreateEvent(NULL, FALSE, FALSE, NULL);
2798 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
2799 thread_params.test_finished = CreateEvent(NULL, FALSE, FALSE, NULL);
2800 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
2801 thread = CreateThread(NULL, 0, create_window_thread, &thread_params, 0, &tid);
2802 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
2803 res = WaitForSingleObject(thread_params.window_created, INFINITE);
2804 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2805 check_wnd_state(hwnd2, thread_params.window, hwnd2, 0);
2807 SetForegroundWindow(hwnd2);
2808 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2810 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
2811 if (0) check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2812 todo_wine ok(GetActiveWindow() == hwnd2, "Expected active window %p, got %p.\n", hwnd2, GetActiveWindow());
2813 todo_wine ok(GetFocus() == hwnd2, "Expected focus window %p, got %p.\n", hwnd2, GetFocus());
2815 SetEvent(thread_params.test_finished);
2816 WaitForSingleObject(thread, INFINITE);
2817 CloseHandle(thread_params.test_finished);
2818 CloseHandle(thread_params.window_created);
2819 CloseHandle(thread);
2820 DestroyWindow(hwnd2);
2823 static WNDPROC old_button_proc;
2825 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2827 LRESULT ret;
2828 USHORT key_state;
2830 key_state = GetKeyState(VK_LBUTTON);
2831 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2833 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2835 if (msg == WM_LBUTTONDOWN)
2837 HWND hwnd, capture;
2839 check_wnd_state(button, button, button, button);
2841 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2842 assert(hwnd);
2843 trace("hwnd %p\n", hwnd);
2845 check_wnd_state(button, button, button, button);
2847 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2849 check_wnd_state(button, button, button, button);
2851 DestroyWindow(hwnd);
2853 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2854 assert(hwnd);
2855 trace("hwnd %p\n", hwnd);
2857 check_wnd_state(button, button, button, button);
2859 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2860 * match internal button state.
2862 SendMessage(button, WM_KILLFOCUS, 0, 0);
2863 check_wnd_state(button, button, button, 0);
2865 ShowWindow(hwnd, SW_SHOW);
2866 check_wnd_state(hwnd, hwnd, hwnd, 0);
2868 capture = SetCapture(hwnd);
2869 ok(capture == 0, "SetCapture() = %p\n", capture);
2871 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2873 DestroyWindow(hwnd);
2875 check_wnd_state(button, 0, button, 0);
2878 return ret;
2881 static void test_capture_1(void)
2883 HWND button, capture;
2885 capture = GetCapture();
2886 ok(capture == 0, "GetCapture() = %p\n", capture);
2888 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2889 assert(button);
2890 trace("button %p\n", button);
2892 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2894 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2896 capture = SetCapture(button);
2897 ok(capture == 0, "SetCapture() = %p\n", capture);
2898 check_wnd_state(button, 0, button, button);
2900 DestroyWindow(button);
2901 /* old active window test depends on previously executed window
2902 * activation tests, and fails under NT4.
2903 check_wnd_state(oldActive, 0, oldFocus, 0);*/
2906 static void test_capture_2(void)
2908 HWND button, hwnd, capture, oldFocus, oldActive;
2910 oldFocus = GetFocus();
2911 oldActive = GetActiveWindow();
2912 check_wnd_state(oldActive, 0, oldFocus, 0);
2914 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2915 assert(button);
2916 trace("button %p\n", button);
2918 check_wnd_state(button, button, button, 0);
2920 capture = SetCapture(button);
2921 ok(capture == 0, "SetCapture() = %p\n", capture);
2923 check_wnd_state(button, button, button, button);
2925 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2926 * internal button state.
2928 SendMessage(button, WM_KILLFOCUS, 0, 0);
2929 check_wnd_state(button, button, button, button);
2931 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2932 assert(hwnd);
2933 trace("hwnd %p\n", hwnd);
2935 check_wnd_state(button, button, button, button);
2937 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2939 check_wnd_state(button, button, button, button);
2941 DestroyWindow(hwnd);
2943 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2944 assert(hwnd);
2945 trace("hwnd %p\n", hwnd);
2947 check_wnd_state(button, button, button, button);
2949 ShowWindow(hwnd, SW_SHOW);
2951 check_wnd_state(hwnd, hwnd, hwnd, button);
2953 capture = SetCapture(hwnd);
2954 ok(capture == button, "SetCapture() = %p\n", capture);
2956 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2958 DestroyWindow(hwnd);
2959 check_wnd_state(button, button, button, 0);
2961 DestroyWindow(button);
2962 check_wnd_state(oldActive, 0, oldFocus, 0);
2965 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2967 BOOL ret;
2969 ShowWindow(hwnd1, SW_HIDE);
2970 ShowWindow(hwnd2, SW_HIDE);
2972 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2973 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2975 SetCapture(hwnd1);
2976 check_wnd_state(0, 0, 0, hwnd1);
2978 SetCapture(hwnd2);
2979 check_wnd_state(0, 0, 0, hwnd2);
2981 ShowWindow(hwnd1, SW_SHOW);
2982 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2984 ret = ReleaseCapture();
2985 ok (ret, "releasecapture did not return TRUE.\n");
2986 ret = ReleaseCapture();
2987 ok (ret, "releasecapture did not return TRUE after second try.\n");
2990 static LRESULT CALLBACK test_capture_4_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2992 GUITHREADINFO gti;
2993 HWND cap_wnd, cap_wnd2, set_cap_wnd;
2994 BOOL status;
2995 switch (msg)
2997 case WM_CAPTURECHANGED:
2999 /* now try to release capture from menu. this should fail */
3000 if (pGetGUIThreadInfo)
3002 memset(&gti, 0, sizeof(GUITHREADINFO));
3003 gti.cbSize = sizeof(GUITHREADINFO);
3004 status = pGetGUIThreadInfo(GetCurrentThreadId(), &gti);
3005 ok(status, "GetGUIThreadInfo() failed!\n");
3006 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
3008 cap_wnd = GetCapture();
3010 /* check that re-setting the capture for the menu fails */
3011 set_cap_wnd = SetCapture(cap_wnd);
3012 ok(!set_cap_wnd || broken(set_cap_wnd == cap_wnd), /* nt4 */
3013 "SetCapture should have failed!\n");
3014 if (set_cap_wnd)
3016 DestroyWindow(hWnd);
3017 break;
3020 /* check that SetCapture fails for another window and that it does not touch the error code */
3021 set_cap_wnd = SetCapture(hWnd);
3022 ok(!set_cap_wnd, "SetCapture should have failed!\n");
3024 /* check that ReleaseCapture fails and does not touch the error code */
3025 status = ReleaseCapture();
3026 ok(!status, "ReleaseCapture should have failed!\n");
3028 /* check that thread info did not change */
3029 if (pGetGUIThreadInfo)
3031 memset(&gti, 0, sizeof(GUITHREADINFO));
3032 gti.cbSize = sizeof(GUITHREADINFO);
3033 status = pGetGUIThreadInfo(GetCurrentThreadId(), &gti);
3034 ok(status, "GetGUIThreadInfo() failed!\n");
3035 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
3038 /* verify that no capture change took place */
3039 cap_wnd2 = GetCapture();
3040 ok(cap_wnd2 == cap_wnd, "Capture changed!\n");
3042 /* we are done. kill the window */
3043 DestroyWindow(hWnd);
3044 break;
3046 default:
3047 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
3049 return 0;
3052 /* Test that no-one can mess around with the current capture while a menu is open */
3053 static void test_capture_4(void)
3055 BOOL ret;
3056 HMENU hmenu;
3057 HWND hwnd;
3058 WNDCLASSA wclass;
3059 HINSTANCE hInstance = GetModuleHandleA( NULL );
3060 ATOM aclass;
3062 if (!pGetGUIThreadInfo)
3064 win_skip("GetGUIThreadInfo is not available\n");
3065 return;
3067 wclass.lpszClassName = "TestCapture4Class";
3068 wclass.style = CS_HREDRAW | CS_VREDRAW;
3069 wclass.lpfnWndProc = test_capture_4_proc;
3070 wclass.hInstance = hInstance;
3071 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
3072 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
3073 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
3074 wclass.lpszMenuName = 0;
3075 wclass.cbClsExtra = 0;
3076 wclass.cbWndExtra = 0;
3077 aclass = RegisterClassA( &wclass );
3078 ok( aclass, "RegisterClassA failed with error %d\n", GetLastError());
3079 hwnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
3080 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
3081 400, 200, NULL, NULL, hInstance, NULL);
3082 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
3083 if (!hwnd) return;
3084 hmenu = CreatePopupMenu();
3086 ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest2");
3087 ok( ret, "AppendMenuA has failed!\n");
3089 /* set main window to have initial capture */
3090 SetCapture(hwnd);
3092 if (is_win9x)
3094 win_skip("TrackPopupMenu test crashes on Win9x/WinMe\n");
3096 else
3098 /* create popup (it will self-destruct) */
3099 ret = TrackPopupMenu(hmenu, TPM_RETURNCMD, 100, 100, 0, hwnd, NULL);
3100 ok( ret == 0, "TrackPopupMenu returned %d expected zero\n", ret);
3103 /* clean up */
3104 DestroyMenu(hmenu);
3105 DestroyWindow(hwnd);
3108 /* PeekMessage wrapper that ignores the messages we don't care about */
3109 static BOOL peek_message( MSG *msg )
3111 BOOL ret;
3114 ret = PeekMessageA(msg, 0, 0, 0, PM_REMOVE);
3115 } while (ret && (msg->message == WM_TIMER || ignore_message(msg->message)));
3116 return ret;
3119 static void test_keyboard_input(HWND hwnd)
3121 MSG msg;
3122 BOOL ret;
3124 flush_events( TRUE );
3125 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
3126 UpdateWindow(hwnd);
3127 flush_events( TRUE );
3129 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
3131 SetFocus(hwnd);
3132 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
3134 flush_events( TRUE );
3136 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
3137 ret = peek_message(&msg);
3138 ok( ret, "no message available\n");
3139 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3140 ret = peek_message(&msg);
3141 ok( !ret, "message %04x available\n", msg.message);
3143 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
3145 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
3146 ret = peek_message(&msg);
3147 ok(ret, "no message available\n");
3148 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3149 ret = peek_message(&msg);
3150 ok( !ret, "message %04x available\n", msg.message);
3152 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
3154 keybd_event(VK_SPACE, 0, 0, 0);
3155 if (!peek_message(&msg))
3157 skip( "keybd_event didn't work, skipping keyboard test\n" );
3158 return;
3160 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3161 ret = peek_message(&msg);
3162 ok( !ret, "message %04x available\n", msg.message);
3164 SetFocus(0);
3165 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3167 flush_events( TRUE );
3169 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
3170 ret = peek_message(&msg);
3171 ok(ret, "no message available\n");
3172 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3173 ret = peek_message(&msg);
3174 ok( !ret, "message %04x available\n", msg.message);
3176 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3178 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
3179 ret = peek_message(&msg);
3180 ok(ret, "no message available\n");
3181 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3182 ret = peek_message(&msg);
3183 ok( !ret, "message %04x available\n", msg.message);
3185 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3187 keybd_event(VK_SPACE, 0, 0, 0);
3188 ret = peek_message(&msg);
3189 ok(ret, "no message available\n");
3190 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3191 ret = peek_message(&msg);
3192 ok( !ret, "message %04x available\n", msg.message);
3195 static BOOL wait_for_message( MSG *msg )
3197 BOOL ret;
3199 for (;;)
3201 ret = peek_message(msg);
3202 if (ret)
3204 if (msg->message == WM_PAINT) DispatchMessage(msg);
3205 else break;
3207 else if (MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
3209 if (!ret) msg->message = 0;
3210 return ret;
3213 static void test_mouse_input(HWND hwnd)
3215 RECT rc;
3216 POINT pt;
3217 int x, y;
3218 HWND popup;
3219 MSG msg;
3220 BOOL ret;
3221 LRESULT res;
3223 ShowWindow(hwnd, SW_SHOWNORMAL);
3224 UpdateWindow(hwnd);
3225 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3227 GetWindowRect(hwnd, &rc);
3228 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
3230 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
3231 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
3232 hwnd, 0, 0, NULL);
3233 assert(popup != 0);
3234 ShowWindow(popup, SW_SHOW);
3235 UpdateWindow(popup);
3236 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3238 GetWindowRect(popup, &rc);
3239 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
3241 x = rc.left + (rc.right - rc.left) / 2;
3242 y = rc.top + (rc.bottom - rc.top) / 2;
3243 trace("setting cursor to (%d,%d)\n", x, y);
3245 SetCursorPos(x, y);
3246 GetCursorPos(&pt);
3247 if (x != pt.x || y != pt.y)
3249 skip( "failed to set mouse position, skipping mouse input tests\n" );
3250 goto done;
3253 flush_events( TRUE );
3255 /* Check that setting the same position may generate WM_MOUSEMOVE */
3256 SetCursorPos(x, y);
3257 msg.message = 0;
3258 ret = peek_message(&msg);
3259 if (ret)
3261 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
3262 msg.hwnd, msg.message);
3263 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
3264 x, y, msg.pt.x, msg.pt.y);
3267 /* force the system to update its internal queue mouse position,
3268 * otherwise it won't generate relative mouse movements below.
3270 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3271 flush_events( TRUE );
3273 msg.message = 0;
3274 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3275 flush_events( FALSE );
3276 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
3277 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
3279 if (msg.message == WM_TIMER || ignore_message(msg.message)) continue;
3280 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
3281 "hwnd %p message %04x\n", msg.hwnd, msg.message);
3282 DispatchMessage(&msg);
3284 ret = peek_message(&msg);
3285 ok( !ret, "message %04x available\n", msg.message);
3287 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3288 ShowWindow(popup, SW_HIDE);
3289 ret = wait_for_message( &msg );
3290 if (ret)
3291 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3292 flush_events( TRUE );
3294 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3295 ShowWindow(hwnd, SW_HIDE);
3296 ret = wait_for_message( &msg );
3297 ok( !ret, "message %04x available\n", msg.message);
3298 flush_events( TRUE );
3300 /* test mouse clicks */
3302 ShowWindow(hwnd, SW_SHOW);
3303 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3304 flush_events( TRUE );
3305 ShowWindow(popup, SW_SHOW);
3306 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3307 flush_events( TRUE );
3309 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3310 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3311 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3312 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3314 ret = wait_for_message( &msg );
3315 if (!ret)
3317 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
3318 goto done;
3320 if (msg.message == WM_MOUSEMOVE) /* win2k has an extra WM_MOUSEMOVE here */
3322 ret = wait_for_message( &msg );
3323 ok(ret, "no message available\n");
3326 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3327 msg.hwnd, popup, msg.message);
3329 ret = wait_for_message( &msg );
3330 ok(ret, "no message available\n");
3331 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3332 msg.hwnd, popup, msg.message);
3334 ret = wait_for_message( &msg );
3335 ok(ret, "no message available\n");
3336 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
3337 msg.hwnd, popup, msg.message);
3339 ret = wait_for_message( &msg );
3340 ok(ret, "no message available\n");
3341 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3342 msg.hwnd, popup, msg.message);
3344 ret = peek_message(&msg);
3345 ok(!ret, "message %04x available\n", msg.message);
3347 ShowWindow(popup, SW_HIDE);
3348 flush_events( TRUE );
3350 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3351 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3352 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3353 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3355 ret = wait_for_message( &msg );
3356 ok(ret, "no message available\n");
3357 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3358 msg.hwnd, hwnd, msg.message);
3359 ret = wait_for_message( &msg );
3360 ok(ret, "no message available\n");
3361 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3362 msg.hwnd, hwnd, msg.message);
3364 test_lbuttondown_flag = TRUE;
3365 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
3366 test_lbuttondown_flag = FALSE;
3368 ret = wait_for_message( &msg );
3369 ok(ret, "no message available\n");
3370 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3371 msg.hwnd, popup, msg.message);
3372 ok(peek_message(&msg), "no message available\n");
3373 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3374 msg.hwnd, popup, msg.message);
3375 ok(peek_message(&msg), "no message available\n");
3377 /* Test WM_MOUSEACTIVATE */
3378 #define TEST_MOUSEACTIVATE(A,B) \
3379 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
3380 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
3382 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
3383 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
3384 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
3385 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
3386 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
3387 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
3388 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
3389 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
3390 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
3391 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
3392 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
3393 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
3394 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
3395 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
3396 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
3397 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
3398 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
3399 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
3400 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
3401 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
3402 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
3403 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
3404 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
3405 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
3407 done:
3408 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
3409 flush_events( TRUE );
3411 DestroyWindow(popup);
3414 static void test_validatergn(HWND hwnd)
3416 HWND child;
3417 RECT rc, rc2;
3418 HRGN rgn;
3419 int ret;
3420 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
3421 ShowWindow(hwnd, SW_SHOW);
3422 UpdateWindow( hwnd);
3423 /* test that ValidateRect validates children*/
3424 InvalidateRect( child, NULL, 1);
3425 GetWindowRect( child, &rc);
3426 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3427 ret = GetUpdateRect( child, &rc2, 0);
3428 ok( ret == 1, "Expected GetUpdateRect to return non-zero, got %d\n", ret);
3429 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
3430 "Update rectangle is empty!\n");
3431 ValidateRect( hwnd, &rc);
3432 ret = GetUpdateRect( child, &rc2, 0);
3433 ok( !ret, "Expected GetUpdateRect to return zero, got %d\n", ret);
3434 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3435 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3436 rc2.right, rc2.bottom);
3438 /* now test ValidateRgn */
3439 InvalidateRect( child, NULL, 1);
3440 GetWindowRect( child, &rc);
3441 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3442 rgn = CreateRectRgnIndirect( &rc);
3443 ValidateRgn( hwnd, rgn);
3444 ret = GetUpdateRect( child, &rc2, 0);
3445 ok( !ret, "Expected GetUpdateRect to return zero, got %d\n", ret);
3446 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3447 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3448 rc2.right, rc2.bottom);
3450 DeleteObject( rgn);
3451 DestroyWindow( child );
3454 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
3456 RECT rc;
3457 MoveWindow( hwnd, 0, 0, x, y, 0);
3458 GetWindowRect( hwnd, prc);
3459 rc = *prc;
3460 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
3461 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
3462 rc.left,rc.top,rc.right,rc.bottom, prc->left,prc->top,prc->right,prc->bottom);
3465 static void test_nccalcscroll(HWND parent)
3467 RECT rc1;
3468 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
3469 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
3470 HWND hwnd = CreateWindowExA(0, "static", NULL,
3471 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
3472 10, 10, 200, 200, parent, 0, 0, NULL);
3473 ShowWindow( parent, SW_SHOW);
3474 UpdateWindow( parent);
3476 /* test window too low for a horizontal scroll bar */
3477 nccalchelper( hwnd, 100, sbheight, &rc1);
3478 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
3479 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
3481 /* test window just high enough for a horizontal scroll bar */
3482 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
3483 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
3484 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3486 /* test window too narrow for a vertical scroll bar */
3487 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
3488 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
3489 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3491 /* test window just wide enough for a vertical scroll bar */
3492 nccalchelper( hwnd, sbwidth, 100, &rc1);
3493 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
3494 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
3496 /* same test, but with client edge: not enough width */
3497 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
3498 nccalchelper( hwnd, sbwidth, 100, &rc1);
3499 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
3500 "Width should be %d size is %d,%d - %d,%d\n",
3501 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
3503 DestroyWindow( hwnd);
3506 static void test_SetParent(void)
3508 HWND desktop = GetDesktopWindow();
3509 HMENU hMenu;
3510 HWND ret, parent, child1, child2, child3, child4, sibling, popup;
3511 BOOL bret;
3513 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3514 100, 100, 200, 200, 0, 0, 0, NULL);
3515 assert(parent != 0);
3516 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3517 0, 0, 50, 50, parent, 0, 0, NULL);
3518 assert(child1 != 0);
3519 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3520 0, 0, 50, 50, child1, 0, 0, NULL);
3521 assert(child2 != 0);
3522 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3523 0, 0, 50, 50, child2, 0, 0, NULL);
3524 assert(child3 != 0);
3525 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3526 0, 0, 50, 50, child3, 0, 0, NULL);
3527 assert(child4 != 0);
3529 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
3530 parent, child1, child2, child3, child4);
3532 check_parents(parent, desktop, 0, 0, 0, parent, parent);
3533 check_parents(child1, parent, parent, parent, 0, parent, parent);
3534 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3535 check_parents(child3, child2, child2, child2, 0, child2, parent);
3536 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3538 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
3539 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
3540 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3541 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
3542 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3544 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
3545 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3546 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
3547 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
3548 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
3549 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
3550 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
3551 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3552 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3554 if (!is_win9x) /* Win9x doesn't survive this test */
3556 ok(!SetParent(parent, child1), "SetParent should fail\n");
3557 ok(!SetParent(child2, child3), "SetParent should fail\n");
3558 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
3559 ret = SetParent(parent, child2);
3560 todo_wine ok( !ret || broken( ret != 0 ), "SetParent should fail\n");
3561 if (ret) /* nt4, win2k */
3563 ret = SetParent(parent, child3);
3564 ok(ret != 0, "SetParent should not fail\n");
3565 ret = SetParent(child2, parent);
3566 ok(!ret, "SetParent should fail\n");
3567 ret = SetParent(parent, child4);
3568 ok(ret != 0, "SetParent should not fail\n");
3569 check_parents(parent, child4, child4, 0, 0, child4, parent);
3570 check_parents(child1, parent, parent, parent, 0, child4, parent);
3571 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3572 check_parents(child3, child2, child2, child2, 0, child2, parent);
3573 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3575 else
3577 ret = SetParent(parent, child3);
3578 ok(ret != 0, "SetParent should not fail\n");
3579 ret = SetParent(child2, parent);
3580 ok(!ret, "SetParent should fail\n");
3581 ret = SetParent(parent, child4);
3582 ok(!ret, "SetParent should fail\n");
3583 check_parents(parent, child3, child3, 0, 0, child2, parent);
3584 check_parents(child1, parent, parent, parent, 0, child2, parent);
3585 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3586 check_parents(child3, child2, child2, child2, 0, child2, parent);
3587 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3590 else
3591 skip("Win9x/WinMe crash\n");
3593 hMenu = CreateMenu();
3594 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3595 100, 100, 200, 200, 0, hMenu, 0, NULL);
3596 assert(sibling != 0);
3598 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
3599 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
3601 ok(DestroyWindow(parent), "DestroyWindow() failed\n");
3603 ok(!IsWindow(parent), "parent still exists\n");
3604 ok(!IsWindow(sibling), "sibling still exists\n");
3605 ok(!IsWindow(child1), "child1 still exists\n");
3606 ok(!IsWindow(child2), "child2 still exists\n");
3607 ok(!IsWindow(child3), "child3 still exists\n");
3608 ok(!IsWindow(child4), "child4 still exists\n");
3610 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3611 100, 100, 200, 200, 0, 0, 0, NULL);
3612 assert(parent != 0);
3613 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3614 0, 0, 50, 50, parent, 0, 0, NULL);
3615 assert(child1 != 0);
3616 popup = CreateWindowExA(0, "static", NULL, WS_POPUP,
3617 0, 0, 50, 50, 0, 0, 0, NULL);
3618 assert(popup != 0);
3620 trace("parent %p, child %p, popup %p\n", parent, child1, popup);
3622 check_parents(parent, desktop, 0, 0, 0, parent, parent);
3623 check_parents(child1, parent, parent, parent, 0, parent, parent);
3624 check_parents(popup, desktop, 0, 0, 0, popup, popup);
3626 SetActiveWindow(parent);
3627 SetFocus(parent);
3628 check_active_state(parent, 0, parent);
3630 ret = SetParent(popup, child1);
3631 ok(ret == desktop, "expected %p, got %p\n", desktop, ret);
3632 check_parents(popup, child1, child1, 0, 0, parent, popup);
3633 todo_wine
3634 check_active_state(popup, 0, popup);
3636 SetActiveWindow(parent);
3637 SetFocus(parent);
3638 check_active_state(parent, 0, parent);
3640 bret = SetForegroundWindow(popup);
3641 todo_wine {
3642 ok(bret || broken(!bret), "SetForegroundWindow() failed\n");
3643 if (!bret)
3644 check_active_state(popup, 0, popup);
3645 else
3646 check_active_state(popup, popup, popup);
3649 ok(DestroyWindow(parent), "DestroyWindow() failed\n");
3651 ok(!IsWindow(parent), "parent still exists\n");
3652 ok(!IsWindow(child1), "child1 still exists\n");
3653 ok(!IsWindow(popup), "popup still exists\n");
3656 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3658 LPCREATESTRUCT lpcs;
3659 LPSTYLESTRUCT lpss;
3661 switch (msg)
3663 case WM_NCCREATE:
3664 case WM_CREATE:
3665 lpcs = (LPCREATESTRUCT)lparam;
3666 lpss = lpcs->lpCreateParams;
3667 if (lpss)
3669 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
3670 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
3671 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
3672 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
3673 else
3674 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3676 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
3677 "Ex style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3678 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
3680 ok(lpss->styleNew == lpcs->style,
3681 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3682 lpss->styleNew, lpcs->style);
3684 break;
3686 return DefWindowProc(hwnd, msg, wparam, lparam);
3689 static ATOM atomStyleCheckClass;
3691 static void register_style_check_class(void)
3693 WNDCLASS wc =
3696 StyleCheckProc,
3699 GetModuleHandle(NULL),
3700 NULL,
3701 LoadCursor(NULL, IDC_ARROW),
3702 (HBRUSH)(COLOR_BTNFACE+1),
3703 NULL,
3704 TEXT("WineStyleCheck"),
3707 atomStyleCheckClass = RegisterClass(&wc);
3708 assert(atomStyleCheckClass);
3711 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3713 DWORD dwActualStyle;
3714 DWORD dwActualExStyle;
3715 STYLESTRUCT ss;
3716 HWND hwnd;
3717 HWND hwndParent = NULL;
3719 ss.styleNew = dwStyleIn;
3720 ss.styleOld = dwExStyleIn;
3722 if (dwStyleIn & WS_CHILD)
3724 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
3725 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3728 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
3729 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3730 assert(hwnd);
3732 flush_events( TRUE );
3734 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3735 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3736 ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
3737 ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
3739 /* try setting the styles explicitly */
3740 SetWindowLong( hwnd, GWL_EXSTYLE, dwExStyleIn );
3741 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3742 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3743 /* WS_EX_WINDOWEDGE can't always be changed */
3744 if (dwExStyleIn & WS_EX_DLGMODALFRAME)
3745 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3746 else if ((dwActualStyle & (WS_DLGFRAME | WS_THICKFRAME)) && !(dwExStyleIn & WS_EX_STATICEDGE))
3747 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3748 else
3749 dwExStyleOut = dwExStyleIn & ~WS_EX_WINDOWEDGE;
3750 ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
3751 ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
3753 SetWindowLong( hwnd, GWL_STYLE, dwStyleIn );
3754 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3755 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3756 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3757 if ((dwStyleIn & (WS_CHILD|WS_POPUP)) == WS_CHILD) dwStyleOut = dwStyleIn;
3758 else dwStyleOut = dwStyleIn | WS_CLIPSIBLINGS;
3759 /* WS_EX_WINDOWEDGE can't always be changed */
3760 if (dwExStyleIn & WS_EX_DLGMODALFRAME)
3761 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3762 else if ((dwActualStyle & (WS_DLGFRAME | WS_THICKFRAME)) && !(dwExStyleIn & WS_EX_STATICEDGE))
3763 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3764 else
3765 dwExStyleOut = dwExStyleIn & ~WS_EX_WINDOWEDGE;
3766 ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
3767 /* FIXME: Remove the condition below once Wine is fixed */
3768 if (dwActualExStyle != dwExStyleOut)
3769 todo_wine ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
3770 else
3771 ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
3773 DestroyWindow(hwnd);
3774 if (hwndParent) DestroyWindow(hwndParent);
3777 /* tests what window styles the window manager automatically adds */
3778 static void test_window_styles(void)
3780 register_style_check_class();
3782 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3783 check_window_style(WS_DLGFRAME, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3784 check_window_style(WS_THICKFRAME, 0, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3785 check_window_style(WS_DLGFRAME, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE);
3786 check_window_style(WS_THICKFRAME, WS_EX_STATICEDGE, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE);
3787 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3788 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3789 check_window_style(WS_CHILD|WS_DLGFRAME, 0, WS_CHILD|WS_DLGFRAME, WS_EX_WINDOWEDGE);
3790 check_window_style(WS_CHILD|WS_THICKFRAME, 0, WS_CHILD|WS_THICKFRAME, WS_EX_WINDOWEDGE);
3791 check_window_style(WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE);
3792 check_window_style(WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE);
3793 check_window_style(WS_CHILD|WS_CAPTION, 0, WS_CHILD|WS_CAPTION, WS_EX_WINDOWEDGE);
3794 check_window_style(WS_CHILD|WS_CAPTION|WS_SYSMENU, 0, WS_CHILD|WS_CAPTION|WS_SYSMENU, WS_EX_WINDOWEDGE);
3795 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3796 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3797 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3798 check_window_style(WS_CHILD|WS_POPUP, 0, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
3799 check_window_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, 0, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3800 check_window_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, 0, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3801 check_window_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3802 check_window_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3803 check_window_style(WS_CHILD|WS_POPUP, WS_EX_APPWINDOW, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, WS_EX_APPWINDOW);
3804 check_window_style(WS_CHILD|WS_POPUP, WS_EX_WINDOWEDGE, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
3805 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3806 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3807 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3808 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3809 check_window_style(WS_POPUP|WS_DLGFRAME, 0, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3810 check_window_style(WS_POPUP|WS_THICKFRAME, 0, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3811 check_window_style(WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3812 check_window_style(WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3813 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3814 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3816 if (pGetLayeredWindowAttributes)
3818 check_window_style(0, WS_EX_LAYERED, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_WINDOWEDGE);
3819 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_WINDOWEDGE);
3820 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION,
3821 WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW|WS_EX_WINDOWEDGE);
3825 static INT_PTR WINAPI empty_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3827 return 0;
3830 static void check_dialog_style(DWORD style_in, DWORD ex_style_in, DWORD style_out, DWORD ex_style_out)
3832 struct
3834 DLGTEMPLATE dt;
3835 WORD menu_name;
3836 WORD class_id;
3837 WORD class_atom;
3838 WCHAR caption[1];
3839 } dlg_data;
3840 DWORD style, ex_style;
3841 HWND hwnd, parent = 0;
3843 if (style_in & WS_CHILD)
3844 parent = CreateWindowEx(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3845 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3847 dlg_data.dt.style = style_in;
3848 dlg_data.dt.dwExtendedStyle = ex_style_in;
3849 dlg_data.dt.cdit = 0;
3850 dlg_data.dt.x = 0;
3851 dlg_data.dt.y = 0;
3852 dlg_data.dt.cx = 100;
3853 dlg_data.dt.cy = 100;
3854 dlg_data.menu_name = 0;
3855 dlg_data.class_id = 0;
3856 dlg_data.class_atom = 0;
3857 dlg_data.caption[0] = 0;
3859 hwnd = CreateDialogIndirectParam(GetModuleHandle(0), &dlg_data.dt, parent, empty_dlg_proc, 0);
3860 ok(hwnd != 0, "dialog creation failed, style %#x, exstyle %#x\n", style_in, ex_style_in);
3862 flush_events( TRUE );
3864 style = GetWindowLong(hwnd, GWL_STYLE);
3865 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
3866 ok(style == (style_out | DS_3DLOOK), "expected style %#x, got %#x\n", style_out | DS_3DLOOK, style);
3867 ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
3869 /* try setting the styles explicitly */
3870 SetWindowLong(hwnd, GWL_EXSTYLE, ex_style_in);
3871 style = GetWindowLong(hwnd, GWL_STYLE);
3872 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
3873 ok(style == (style_out | DS_3DLOOK), "expected style %#x, got %#x\n", style_out|DS_3DLOOK, style);
3874 /* WS_EX_WINDOWEDGE can't always be changed */
3875 if (ex_style_in & WS_EX_DLGMODALFRAME)
3876 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
3877 else if ((style & (WS_DLGFRAME | WS_THICKFRAME)) && !(ex_style_in & WS_EX_STATICEDGE))
3878 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
3879 else
3880 ex_style_out = ex_style_in & ~WS_EX_WINDOWEDGE;
3881 ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
3883 SetWindowLong(hwnd, GWL_STYLE, style_in);
3884 style = GetWindowLong(hwnd, GWL_STYLE);
3885 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
3886 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3887 if ((style_in & (WS_CHILD | WS_POPUP)) == WS_CHILD) style_out = style_in;
3888 else style_out = style_in | WS_CLIPSIBLINGS;
3889 ok(style == style_out, "expected style %#x, got %#x\n", style_out, style);
3890 /* WS_EX_WINDOWEDGE can't always be changed */
3891 if (ex_style_in & WS_EX_DLGMODALFRAME)
3892 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
3893 else if ((style & (WS_DLGFRAME | WS_THICKFRAME)) && !(ex_style_in & WS_EX_STATICEDGE))
3894 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
3895 else
3896 ex_style_out = ex_style_in & ~WS_EX_WINDOWEDGE;
3897 /* FIXME: Remove the condition below once Wine is fixed */
3898 if (ex_style != ex_style_out)
3899 todo_wine ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
3900 else
3901 ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
3903 DestroyWindow(hwnd);
3904 DestroyWindow(parent);
3907 static void test_dialog_styles(void)
3909 check_dialog_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3910 check_dialog_style(WS_DLGFRAME, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3911 check_dialog_style(WS_THICKFRAME, 0, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3912 check_dialog_style(WS_DLGFRAME, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
3913 check_dialog_style(WS_THICKFRAME, WS_EX_STATICEDGE, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
3914 check_dialog_style(DS_CONTROL, 0, WS_CLIPSIBLINGS|WS_CAPTION|DS_CONTROL, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3915 check_dialog_style(WS_CAPTION, 0, WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3916 check_dialog_style(WS_BORDER, 0, WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3917 check_dialog_style(WS_DLGFRAME, 0, WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3918 check_dialog_style(WS_BORDER|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3919 check_dialog_style(WS_DLGFRAME|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3920 check_dialog_style(WS_CAPTION|WS_SYSMENU, 0, WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3921 check_dialog_style(WS_SYSMENU, 0, WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3922 check_dialog_style(WS_CAPTION|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3923 check_dialog_style(WS_SYSMENU|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3924 check_dialog_style(WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3925 check_dialog_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3926 check_dialog_style(WS_CHILD, 0, WS_CHILD, 0);
3927 check_dialog_style(WS_CHILD|WS_DLGFRAME, 0, WS_CHILD|WS_DLGFRAME, WS_EX_WINDOWEDGE);
3928 check_dialog_style(WS_CHILD|WS_THICKFRAME, 0, WS_CHILD|WS_THICKFRAME, WS_EX_WINDOWEDGE);
3929 check_dialog_style(WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE);
3930 check_dialog_style(WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE);
3931 check_dialog_style(WS_CHILD|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
3932 check_dialog_style(WS_CHILD|WS_CAPTION, 0, WS_CHILD|WS_CAPTION, WS_EX_WINDOWEDGE);
3933 check_dialog_style(WS_CHILD|WS_BORDER, 0, WS_CHILD|WS_BORDER, 0);
3934 check_dialog_style(WS_CHILD|WS_DLGFRAME, 0, WS_CHILD|WS_DLGFRAME, WS_EX_WINDOWEDGE);
3935 check_dialog_style(WS_CHILD|WS_BORDER|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
3936 check_dialog_style(WS_CHILD|WS_DLGFRAME|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
3937 check_dialog_style(WS_CHILD|WS_CAPTION|WS_SYSMENU, 0, WS_CHILD|WS_CAPTION|WS_SYSMENU, WS_EX_WINDOWEDGE);
3938 check_dialog_style(WS_CHILD|WS_SYSMENU, 0, WS_CHILD|WS_SYSMENU, 0);
3939 check_dialog_style(WS_CHILD|WS_CAPTION|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
3940 check_dialog_style(WS_CHILD|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
3941 check_dialog_style(WS_CHILD|WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
3942 check_dialog_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3943 check_dialog_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3944 check_dialog_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3945 check_dialog_style(WS_CHILD|WS_POPUP, 0, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
3946 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, 0, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3947 check_dialog_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, 0, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3948 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3949 check_dialog_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3950 check_dialog_style(WS_CHILD|WS_POPUP|DS_CONTROL, 0, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS|DS_CONTROL, WS_EX_CONTROLPARENT);
3951 check_dialog_style(WS_CHILD|WS_POPUP|WS_CAPTION, 0, WS_CHILD|WS_POPUP|WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3952 check_dialog_style(WS_CHILD|WS_POPUP|WS_BORDER, 0, WS_CHILD|WS_POPUP|WS_BORDER|WS_CLIPSIBLINGS, 0);
3953 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, 0, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3954 check_dialog_style(WS_CHILD|WS_POPUP|WS_BORDER|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
3955 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
3956 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);
3957 check_dialog_style(WS_CHILD|WS_POPUP|WS_SYSMENU, 0, WS_CHILD|WS_POPUP|WS_SYSMENU|WS_CLIPSIBLINGS, 0);
3958 check_dialog_style(WS_CHILD|WS_POPUP|WS_CAPTION|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
3959 check_dialog_style(WS_CHILD|WS_POPUP|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
3960 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);
3961 check_dialog_style(WS_CHILD|WS_POPUP, WS_EX_APPWINDOW, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, WS_EX_APPWINDOW);
3962 check_dialog_style(WS_CHILD|WS_POPUP, WS_EX_WINDOWEDGE, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
3963 check_dialog_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3964 check_dialog_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW|WS_EX_CONTROLPARENT);
3965 check_dialog_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
3966 check_dialog_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
3967 check_dialog_style(WS_POPUP|WS_DLGFRAME, 0, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3968 check_dialog_style(WS_POPUP|WS_THICKFRAME, 0, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3969 check_dialog_style(WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
3970 check_dialog_style(WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
3971 check_dialog_style(WS_POPUP|DS_CONTROL, 0, WS_POPUP|WS_CLIPSIBLINGS|DS_CONTROL, WS_EX_CONTROLPARENT);
3972 check_dialog_style(WS_POPUP|WS_CAPTION, 0, WS_POPUP|WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3973 check_dialog_style(WS_POPUP|WS_BORDER, 0, WS_POPUP|WS_BORDER|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
3974 check_dialog_style(WS_POPUP|WS_DLGFRAME, 0, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3975 check_dialog_style(WS_POPUP|WS_BORDER|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
3976 check_dialog_style(WS_POPUP|WS_DLGFRAME|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
3977 check_dialog_style(WS_POPUP|WS_CAPTION|WS_SYSMENU, 0, WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3978 check_dialog_style(WS_POPUP|WS_SYSMENU, 0, WS_POPUP|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
3979 check_dialog_style(WS_POPUP|WS_CAPTION|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
3980 check_dialog_style(WS_POPUP|WS_SYSMENU|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
3981 check_dialog_style(WS_POPUP|WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
3982 check_dialog_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3983 check_dialog_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3985 if (pGetLayeredWindowAttributes)
3987 check_dialog_style(0, WS_EX_LAYERED, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3988 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);
3989 check_dialog_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION,
3990 WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3994 static void test_scrollwindow( HWND hwnd)
3996 HDC hdc;
3997 RECT rc, rc2, rc3;
3998 COLORREF colr;
4000 ShowWindow( hwnd, SW_SHOW);
4001 UpdateWindow( hwnd);
4002 flush_events( TRUE );
4003 GetClientRect( hwnd, &rc);
4004 hdc = GetDC( hwnd);
4005 /* test ScrollWindow(Ex) with no clip rectangle */
4006 /* paint the lower half of the window black */
4007 rc2 = rc;
4008 rc2.top = ( rc2.top + rc2.bottom) / 2;
4009 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4010 /* paint the upper half of the window white */
4011 rc2.bottom = rc2.top;
4012 rc2.top =0;
4013 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
4014 /* scroll lower half up */
4015 rc2 = rc;
4016 rc2.top = ( rc2.top + rc2.bottom) / 2;
4017 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, NULL, NULL, NULL, SW_ERASE);
4018 flush_events(FALSE);
4019 /* expected: black should have scrolled to the upper half */
4020 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
4021 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4022 /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
4023 /* paint the lower half of the window black */
4024 rc2 = rc;
4025 rc2.top = ( rc2.top + rc2.bottom) / 2;
4026 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4027 /* paint the upper half of the window white */
4028 rc2.bottom = rc2.top;
4029 rc2.top =0;
4030 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
4031 /* scroll lower half up */
4032 rc2 = rc;
4033 rc2.top = ( rc2.top + rc2.bottom) / 2;
4034 rc3 = rc;
4035 rc3.left = rc3.right / 4;
4036 rc3.right -= rc3.right / 4;
4037 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, &rc3, NULL, NULL, SW_ERASE);
4038 flush_events(FALSE);
4039 /* expected: black should have scrolled to the upper half */
4040 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
4041 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4043 /* clean up */
4044 ReleaseDC( hwnd, hdc);
4047 static void test_scrollvalidate( HWND parent)
4049 HDC hdc;
4050 HRGN hrgn=CreateRectRgn(0,0,0,0);
4051 HRGN exprgn, tmprgn, clipping;
4052 RECT rc, rcu, cliprc;
4053 /* create two overlapping child windows. The visual region
4054 * of hwnd1 is clipped by the overlapping part of
4055 * hwnd2 because of the WS_CLIPSIBLING style */
4056 HWND hwnd1, hwnd2;
4058 clipping = CreateRectRgn(0,0,0,0);
4059 tmprgn = CreateRectRgn(0,0,0,0);
4060 exprgn = CreateRectRgn(0,0,0,0);
4061 hwnd2 = CreateWindowExA(0, "static", NULL,
4062 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
4063 75, 30, 100, 100, parent, 0, 0, NULL);
4064 hwnd1 = CreateWindowExA(0, "static", NULL,
4065 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
4066 25, 50, 100, 100, parent, 0, 0, NULL);
4067 ShowWindow( parent, SW_SHOW);
4068 UpdateWindow( parent);
4069 GetClientRect( hwnd1, &rc);
4070 cliprc=rc;
4071 SetRectRgn( clipping, 10, 10, 90, 90);
4072 hdc = GetDC( hwnd1);
4073 /* for a visual touch */
4074 TextOut( hdc, 0,10, "0123456789", 10);
4075 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
4076 if (winetest_debug > 0) dump_region(hrgn);
4077 /* create a region with what is expected */
4078 SetRectRgn( exprgn, 39,0,49,74);
4079 SetRectRgn( tmprgn, 88,79,98,93);
4080 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4081 SetRectRgn( tmprgn, 0,93,98,98);
4082 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4083 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4084 trace("update rect is %d,%d - %d,%d\n",
4085 rcu.left,rcu.top,rcu.right,rcu.bottom);
4086 /* now with clipping region */
4087 SelectClipRgn( hdc, clipping);
4088 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
4089 if (winetest_debug > 0) dump_region(hrgn);
4090 /* create a region with what is expected */
4091 SetRectRgn( exprgn, 39,10,49,74);
4092 SetRectRgn( tmprgn, 80,79,90,85);
4093 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4094 SetRectRgn( tmprgn, 10,85,90,90);
4095 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4096 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4097 trace("update rect is %d,%d - %d,%d\n",
4098 rcu.left,rcu.top,rcu.right,rcu.bottom);
4099 ReleaseDC( hwnd1, hdc);
4101 /* test scrolling a window with an update region */
4102 DestroyWindow( hwnd2);
4103 ValidateRect( hwnd1, NULL);
4104 SetRect( &rc, 40,40, 50,50);
4105 InvalidateRect( hwnd1, &rc, 1);
4106 GetClientRect( hwnd1, &rc);
4107 cliprc=rc;
4108 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
4109 SW_SCROLLCHILDREN | SW_INVALIDATE);
4110 if (winetest_debug > 0) dump_region(hrgn);
4111 SetRectRgn( exprgn, 88,0,98,98);
4112 SetRectRgn( tmprgn, 30, 40, 50, 50);
4113 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4114 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4116 /* clear an update region */
4117 UpdateWindow( hwnd1 );
4119 SetRect( &rc, 0,40, 100,60);
4120 SetRect( &cliprc, 0,0, 100,100);
4121 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
4122 if (winetest_debug > 0) dump_region( hrgn );
4123 SetRectRgn( exprgn, 0, 40, 98, 60 );
4124 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
4126 /* now test ScrollWindowEx with a combination of
4127 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
4128 /* make hwnd2 the child of hwnd1 */
4129 hwnd2 = CreateWindowExA(0, "static", NULL,
4130 WS_CHILD| WS_VISIBLE | WS_BORDER ,
4131 50, 50, 100, 100, hwnd1, 0, 0, NULL);
4132 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
4133 GetClientRect( hwnd1, &rc);
4134 cliprc=rc;
4136 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
4137 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
4138 ValidateRect( hwnd1, NULL);
4139 ValidateRect( hwnd2, NULL);
4140 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
4141 SW_SCROLLCHILDREN | SW_INVALIDATE);
4142 if (winetest_debug > 0) dump_region(hrgn);
4143 SetRectRgn( exprgn, 88,0,98,88);
4144 SetRectRgn( tmprgn, 0,88,98,98);
4145 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4146 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4148 /* SW_SCROLLCHILDREN */
4149 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
4150 ValidateRect( hwnd1, NULL);
4151 ValidateRect( hwnd2, NULL);
4152 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
4153 if (winetest_debug > 0) dump_region(hrgn);
4154 /* expected region is the same as in previous test */
4155 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4157 /* no SW_SCROLLCHILDREN */
4158 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
4159 ValidateRect( hwnd1, NULL);
4160 ValidateRect( hwnd2, NULL);
4161 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
4162 if (winetest_debug > 0) dump_region(hrgn);
4163 /* expected region is the same as in previous test */
4164 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4166 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
4167 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
4168 ValidateRect( hwnd1, NULL);
4169 ValidateRect( hwnd2, NULL);
4170 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
4171 if (winetest_debug > 0) dump_region(hrgn);
4172 SetRectRgn( exprgn, 88,0,98,20);
4173 SetRectRgn( tmprgn, 20,20,98,30);
4174 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4175 SetRectRgn( tmprgn, 20,30,30,88);
4176 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4177 SetRectRgn( tmprgn, 0,88,30,98);
4178 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4179 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4181 /* clean up */
4182 DeleteObject( hrgn);
4183 DeleteObject( exprgn);
4184 DeleteObject( tmprgn);
4185 DestroyWindow( hwnd1);
4186 DestroyWindow( hwnd2);
4189 /* couple of tests of return values of scrollbar functions
4190 * called on a scrollbarless window */
4191 static void test_scroll(void)
4193 BOOL ret;
4194 INT min, max;
4195 SCROLLINFO si;
4196 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
4197 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
4198 100, 100, 200, 200, 0, 0, 0, NULL);
4199 /* horizontal */
4200 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
4201 if (!ret) /* win9x */
4203 win_skip( "GetScrollRange doesn't work\n" );
4204 DestroyWindow( hwnd);
4205 return;
4207 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
4208 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
4209 si.cbSize = sizeof( si);
4210 si.fMask = SIF_PAGE;
4211 si.nPage = 0xdeadbeef;
4212 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
4213 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
4214 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
4215 /* vertical */
4216 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
4217 ok( ret, "GetScrollRange returns FALSE\n");
4218 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
4219 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
4220 si.cbSize = sizeof( si);
4221 si.fMask = SIF_PAGE;
4222 si.nPage = 0xdeadbeef;
4223 ret = GetScrollInfo( hwnd, SB_VERT, &si);
4224 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
4225 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
4226 /* clean up */
4227 DestroyWindow( hwnd);
4230 static void test_scrolldc( HWND parent)
4232 HDC hdc;
4233 HRGN exprgn, tmprgn, hrgn;
4234 RECT rc, rc2, rcu, cliprc;
4235 HWND hwnd1;
4236 COLORREF colr;
4238 hrgn = CreateRectRgn(0,0,0,0);
4239 tmprgn = CreateRectRgn(0,0,0,0);
4240 exprgn = CreateRectRgn(0,0,0,0);
4242 hwnd1 = CreateWindowExA(0, "static", NULL,
4243 WS_CHILD| WS_VISIBLE,
4244 25, 50, 100, 100, parent, 0, 0, NULL);
4245 ShowWindow( parent, SW_SHOW);
4246 UpdateWindow( parent);
4247 flush_events( TRUE );
4248 GetClientRect( hwnd1, &rc);
4249 hdc = GetDC( hwnd1);
4250 /* paint the upper half of the window black */
4251 rc2 = rc;
4252 rc2.bottom = ( rc.top + rc.bottom) /2;
4253 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4254 /* clip region is the lower half */
4255 cliprc=rc;
4256 cliprc.top = (rc.top + rc.bottom) /2;
4257 /* test whether scrolled pixels are properly clipped */
4258 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
4259 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4260 /* this scroll should not cause any visible changes */
4261 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
4262 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
4263 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4264 /* test with NULL clip rect */
4265 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
4266 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
4267 trace("update rect: %d,%d - %d,%d\n",
4268 rcu.left, rcu.top, rcu.right, rcu.bottom);
4269 if (winetest_debug > 0) dump_region(hrgn);
4270 SetRect(&rc2, 0, 0, 100, 100);
4271 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
4272 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
4274 SetRectRgn( exprgn, 0, 0, 20, 80);
4275 SetRectRgn( tmprgn, 0, 80, 100, 100);
4276 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
4277 if (winetest_debug > 0) dump_region(exprgn);
4278 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
4279 /* test clip rect > scroll rect */
4280 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
4281 rc2=rc;
4282 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
4283 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4284 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
4285 SetRectRgn( exprgn, 25, 25, 75, 35);
4286 SetRectRgn( tmprgn, 25, 35, 35, 75);
4287 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
4288 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
4289 trace("update rect: %d,%d - %d,%d\n",
4290 rcu.left, rcu.top, rcu.right, rcu.bottom);
4291 if (winetest_debug > 0) dump_region(hrgn);
4293 /* clean up */
4294 DeleteObject(hrgn);
4295 DeleteObject(exprgn);
4296 DeleteObject(tmprgn);
4297 DestroyWindow(hwnd1);
4300 static void test_params(void)
4302 HWND hwnd;
4303 INT rc;
4305 ok(!IsWindow(0), "IsWindow(0)\n");
4306 ok(!IsWindow(HWND_BROADCAST), "IsWindow(HWND_BROADCAST)\n");
4307 ok(!IsWindow(HWND_TOPMOST), "IsWindow(HWND_TOPMOST)\n");
4309 /* Just a param check */
4310 if (pGetMonitorInfoA)
4312 SetLastError(0xdeadbeef);
4313 rc = GetWindowText(hwndMain2, NULL, 1024);
4314 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
4316 else
4318 /* Skips actually on Win95 and NT4 */
4319 win_skip("Test would crash on Win95\n");
4322 SetLastError(0xdeadbeef);
4323 hwnd=CreateWindow("LISTBOX", "TestList",
4324 (LBS_STANDARD & ~LBS_SORT),
4325 0, 0, 100, 100,
4326 NULL, (HMENU)1, NULL, 0);
4328 ok(!hwnd || broken(hwnd != NULL), /* w2k3 sp2 */
4329 "CreateWindow with invalid menu handle should fail\n");
4330 if (!hwnd)
4331 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
4332 GetLastError() == 0xdeadbeef, /* Win9x */
4333 "wrong last error value %d\n", GetLastError());
4336 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
4338 HWND hwnd = 0;
4340 hwnd = CreateWindowEx(exStyle, class, class, style,
4341 110, 100,
4342 225, 200,
4344 menu ? hmenu : 0,
4345 0, 0);
4346 if (!hwnd) {
4347 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
4348 return;
4350 ShowWindow(hwnd, SW_SHOW);
4352 test_nonclient_area(hwnd);
4354 SetMenu(hwnd, 0);
4355 DestroyWindow(hwnd);
4358 static BOOL AWR_init(void)
4360 WNDCLASS class;
4362 class.style = CS_HREDRAW | CS_VREDRAW;
4363 class.lpfnWndProc = DefWindowProcA;
4364 class.cbClsExtra = 0;
4365 class.cbWndExtra = 0;
4366 class.hInstance = 0;
4367 class.hIcon = LoadIcon (0, IDI_APPLICATION);
4368 class.hCursor = LoadCursor (0, IDC_ARROW);
4369 class.hbrBackground = 0;
4370 class.lpszMenuName = 0;
4371 class.lpszClassName = szAWRClass;
4373 if (!RegisterClass (&class)) {
4374 ok(FALSE, "RegisterClass failed\n");
4375 return FALSE;
4378 hmenu = CreateMenu();
4379 if (!hmenu)
4380 return FALSE;
4381 ok(hmenu != 0, "Failed to create menu\n");
4382 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
4384 return TRUE;
4388 static void test_AWR_window_size(BOOL menu)
4390 LONG styles[] = {
4391 WS_POPUP,
4392 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
4393 WS_SYSMENU,
4394 WS_THICKFRAME,
4395 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
4396 WS_HSCROLL, WS_VSCROLL
4398 LONG exStyles[] = {
4399 WS_EX_CLIENTEDGE,
4400 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
4401 WS_EX_APPWINDOW,
4402 #if 0
4403 /* These styles have problems on (at least) WinXP (SP2) and Wine */
4404 WS_EX_DLGMODALFRAME,
4405 WS_EX_STATICEDGE,
4406 #endif
4409 int i;
4411 /* A exhaustive check of all the styles takes too long
4412 * so just do a (hopefully representative) sample
4414 for (i = 0; i < COUNTOF(styles); ++i)
4415 test_AWRwindow(szAWRClass, styles[i], 0, menu);
4416 for (i = 0; i < COUNTOF(exStyles); ++i) {
4417 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
4418 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
4421 #undef COUNTOF
4423 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
4425 static void test_AdjustWindowRect(void)
4427 if (!AWR_init())
4428 return;
4430 SHOWSYSMETRIC(SM_CYCAPTION);
4431 SHOWSYSMETRIC(SM_CYSMCAPTION);
4432 SHOWSYSMETRIC(SM_CYMENU);
4433 SHOWSYSMETRIC(SM_CXEDGE);
4434 SHOWSYSMETRIC(SM_CYEDGE);
4435 SHOWSYSMETRIC(SM_CXVSCROLL);
4436 SHOWSYSMETRIC(SM_CYHSCROLL);
4437 SHOWSYSMETRIC(SM_CXFRAME);
4438 SHOWSYSMETRIC(SM_CYFRAME);
4439 SHOWSYSMETRIC(SM_CXDLGFRAME);
4440 SHOWSYSMETRIC(SM_CYDLGFRAME);
4441 SHOWSYSMETRIC(SM_CXBORDER);
4442 SHOWSYSMETRIC(SM_CYBORDER);
4444 test_AWR_window_size(FALSE);
4445 test_AWR_window_size(TRUE);
4447 DestroyMenu(hmenu);
4449 #undef SHOWSYSMETRIC
4452 /* Global variables to trigger exit from loop */
4453 static int redrawComplete, WMPAINT_count;
4455 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4457 switch (msg)
4459 case WM_PAINT:
4460 trace("doing WM_PAINT %d\n", WMPAINT_count);
4461 WMPAINT_count++;
4462 if (WMPAINT_count > 10 && redrawComplete == 0) {
4463 PAINTSTRUCT ps;
4464 BeginPaint(hwnd, &ps);
4465 EndPaint(hwnd, &ps);
4466 return 1;
4468 return 0;
4470 return DefWindowProc(hwnd, msg, wparam, lparam);
4473 /* Ensure we exit from RedrawNow regardless of invalidated area */
4474 static void test_redrawnow(void)
4476 WNDCLASSA cls;
4477 HWND hwndMain;
4479 cls.style = CS_DBLCLKS;
4480 cls.lpfnWndProc = redraw_window_procA;
4481 cls.cbClsExtra = 0;
4482 cls.cbWndExtra = 0;
4483 cls.hInstance = GetModuleHandleA(0);
4484 cls.hIcon = 0;
4485 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4486 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4487 cls.lpszMenuName = NULL;
4488 cls.lpszClassName = "RedrawWindowClass";
4490 if(!RegisterClassA(&cls)) {
4491 trace("Register failed %d\n", GetLastError());
4492 return;
4495 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
4496 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
4498 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4499 ShowWindow(hwndMain, SW_SHOW);
4500 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4501 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
4502 ok( WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
4503 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4504 redrawComplete = TRUE;
4505 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
4507 /* clean up */
4508 DestroyWindow( hwndMain);
4511 struct parentdc_stat {
4512 RECT client;
4513 RECT clip;
4514 RECT paint;
4517 struct parentdc_test {
4518 struct parentdc_stat main, main_todo;
4519 struct parentdc_stat child1, child1_todo;
4520 struct parentdc_stat child2, child2_todo;
4523 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4525 RECT rc;
4526 PAINTSTRUCT ps;
4528 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
4530 switch (msg)
4532 case WM_PAINT:
4533 GetClientRect(hwnd, &rc);
4534 CopyRect(&t->client, &rc);
4535 GetWindowRect(hwnd, &rc);
4536 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd,
4537 t->client.left, t->client.top, t->client.right, t->client.bottom,
4538 rc.left, rc.top, rc.right, rc.bottom);
4539 BeginPaint(hwnd, &ps);
4540 CopyRect(&t->paint, &ps.rcPaint);
4541 GetClipBox(ps.hdc, &rc);
4542 CopyRect(&t->clip, &rc);
4543 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
4544 rc.left, rc.top, rc.right, rc.bottom,
4545 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
4546 EndPaint(hwnd, &ps);
4547 return 0;
4549 return DefWindowProc(hwnd, msg, wparam, lparam);
4552 static void zero_parentdc_stat(struct parentdc_stat *t)
4554 SetRectEmpty(&t->client);
4555 SetRectEmpty(&t->clip);
4556 SetRectEmpty(&t->paint);
4559 static void zero_parentdc_test(struct parentdc_test *t)
4561 zero_parentdc_stat(&t->main);
4562 zero_parentdc_stat(&t->child1);
4563 zero_parentdc_stat(&t->child2);
4566 #define parentdc_field_ok(t, w, r, f, got) \
4567 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
4568 ": expected %d, got %d\n", \
4569 t.w.r.f, got.w.r.f)
4571 #define parentdc_todo_field_ok(t, w, r, f, got) \
4572 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
4573 else parentdc_field_ok(t, w, r, f, got)
4575 #define parentdc_rect_ok(t, w, r, got) \
4576 parentdc_todo_field_ok(t, w, r, left, got); \
4577 parentdc_todo_field_ok(t, w, r, top, got); \
4578 parentdc_todo_field_ok(t, w, r, right, got); \
4579 parentdc_todo_field_ok(t, w, r, bottom, got);
4581 #define parentdc_win_ok(t, w, got) \
4582 parentdc_rect_ok(t, w, client, got); \
4583 parentdc_rect_ok(t, w, clip, got); \
4584 parentdc_rect_ok(t, w, paint, got);
4586 #define parentdc_ok(t, got) \
4587 parentdc_win_ok(t, main, got); \
4588 parentdc_win_ok(t, child1, got); \
4589 parentdc_win_ok(t, child2, got);
4591 static void test_csparentdc(void)
4593 WNDCLASSA clsMain, cls;
4594 HWND hwndMain, hwnd1, hwnd2;
4595 RECT rc;
4597 struct parentdc_test test_answer;
4599 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
4600 const struct parentdc_test test1 =
4602 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
4603 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4604 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4607 const struct parentdc_test test2 =
4609 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
4610 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4611 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4614 const struct parentdc_test test3 =
4616 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4617 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4618 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4621 const struct parentdc_test test4 =
4623 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
4624 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
4625 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4628 const struct parentdc_test test5 =
4630 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
4631 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4632 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4635 const struct parentdc_test test6 =
4637 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4638 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4639 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4642 const struct parentdc_test test7 =
4644 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4645 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4646 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4648 #undef nothing_todo
4650 clsMain.style = CS_DBLCLKS;
4651 clsMain.lpfnWndProc = parentdc_window_procA;
4652 clsMain.cbClsExtra = 0;
4653 clsMain.cbWndExtra = 0;
4654 clsMain.hInstance = GetModuleHandleA(0);
4655 clsMain.hIcon = 0;
4656 clsMain.hCursor = LoadCursorA(0, IDC_ARROW);
4657 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
4658 clsMain.lpszMenuName = NULL;
4659 clsMain.lpszClassName = "ParentDcMainWindowClass";
4661 if(!RegisterClassA(&clsMain)) {
4662 trace("Register failed %d\n", GetLastError());
4663 return;
4666 cls.style = CS_DBLCLKS | CS_PARENTDC;
4667 cls.lpfnWndProc = parentdc_window_procA;
4668 cls.cbClsExtra = 0;
4669 cls.cbWndExtra = 0;
4670 cls.hInstance = GetModuleHandleA(0);
4671 cls.hIcon = 0;
4672 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4673 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4674 cls.lpszMenuName = NULL;
4675 cls.lpszClassName = "ParentDcWindowClass";
4677 if(!RegisterClassA(&cls)) {
4678 trace("Register failed %d\n", GetLastError());
4679 return;
4682 SetRect(&rc, 0, 0, 150, 150);
4683 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
4684 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
4685 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
4686 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
4687 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
4688 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
4689 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
4690 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
4691 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
4692 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
4693 ShowWindow(hwndMain, SW_SHOW);
4694 ShowWindow(hwnd1, SW_SHOW);
4695 ShowWindow(hwnd2, SW_SHOW);
4696 SetWindowPos(hwndMain, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
4697 flush_events( TRUE );
4699 zero_parentdc_test(&test_answer);
4700 InvalidateRect(hwndMain, NULL, TRUE);
4701 flush_events( TRUE );
4702 parentdc_ok(test1, test_answer);
4704 zero_parentdc_test(&test_answer);
4705 SetRect(&rc, 0, 0, 50, 50);
4706 InvalidateRect(hwndMain, &rc, TRUE);
4707 flush_events( TRUE );
4708 parentdc_ok(test2, test_answer);
4710 zero_parentdc_test(&test_answer);
4711 SetRect(&rc, 0, 0, 10, 10);
4712 InvalidateRect(hwndMain, &rc, TRUE);
4713 flush_events( TRUE );
4714 parentdc_ok(test3, test_answer);
4716 zero_parentdc_test(&test_answer);
4717 SetRect(&rc, 40, 40, 50, 50);
4718 InvalidateRect(hwndMain, &rc, TRUE);
4719 flush_events( TRUE );
4720 parentdc_ok(test4, test_answer);
4722 zero_parentdc_test(&test_answer);
4723 SetRect(&rc, 20, 20, 60, 60);
4724 InvalidateRect(hwndMain, &rc, TRUE);
4725 flush_events( TRUE );
4726 parentdc_ok(test5, test_answer);
4728 zero_parentdc_test(&test_answer);
4729 SetRect(&rc, 0, 0, 10, 10);
4730 InvalidateRect(hwnd1, &rc, TRUE);
4731 flush_events( TRUE );
4732 parentdc_ok(test6, test_answer);
4734 zero_parentdc_test(&test_answer);
4735 SetRect(&rc, -5, -5, 65, 65);
4736 InvalidateRect(hwnd1, &rc, TRUE);
4737 flush_events( TRUE );
4738 parentdc_ok(test7, test_answer);
4740 DestroyWindow(hwndMain);
4741 DestroyWindow(hwnd1);
4742 DestroyWindow(hwnd2);
4745 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4747 return DefWindowProcA(hwnd, msg, wparam, lparam);
4750 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4752 return DefWindowProcW(hwnd, msg, wparam, lparam);
4755 static void test_IsWindowUnicode(void)
4757 static const char ansi_class_nameA[] = "ansi class name";
4758 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
4759 static const char unicode_class_nameA[] = "unicode class name";
4760 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
4761 WNDCLASSA classA;
4762 WNDCLASSW classW;
4763 HWND hwnd;
4765 memset(&classW, 0, sizeof(classW));
4766 classW.hInstance = GetModuleHandleA(0);
4767 classW.lpfnWndProc = def_window_procW;
4768 classW.lpszClassName = unicode_class_nameW;
4769 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
4771 memset(&classA, 0, sizeof(classA));
4772 classA.hInstance = GetModuleHandleA(0);
4773 classA.lpfnWndProc = def_window_procA;
4774 classA.lpszClassName = ansi_class_nameA;
4775 assert(RegisterClassA(&classA));
4777 /* unicode class: window proc */
4778 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4779 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4780 assert(hwnd);
4782 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4783 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4784 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4785 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4786 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4788 DestroyWindow(hwnd);
4790 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4791 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4792 assert(hwnd);
4794 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4795 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4796 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4797 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4798 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4800 DestroyWindow(hwnd);
4802 /* ansi class: window proc */
4803 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4804 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4805 assert(hwnd);
4807 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4808 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4809 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4810 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4811 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4813 DestroyWindow(hwnd);
4815 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4816 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4817 assert(hwnd);
4819 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4820 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4821 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4822 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4823 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4825 DestroyWindow(hwnd);
4827 /* unicode class: class proc */
4828 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4829 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4830 assert(hwnd);
4832 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4833 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4834 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4835 /* do not restore class window proc back to unicode */
4837 DestroyWindow(hwnd);
4839 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4840 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4841 assert(hwnd);
4843 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4844 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4845 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4847 DestroyWindow(hwnd);
4849 /* ansi class: class proc */
4850 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4851 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4852 assert(hwnd);
4854 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4855 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4856 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4857 /* do not restore class window proc back to ansi */
4859 DestroyWindow(hwnd);
4861 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4862 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4863 assert(hwnd);
4865 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4866 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4867 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4869 DestroyWindow(hwnd);
4872 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4874 MINMAXINFO *minmax;
4876 if (msg != WM_GETMINMAXINFO)
4877 return DefWindowProc(hwnd, msg, wp, lp);
4879 minmax = (MINMAXINFO *)lp;
4881 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
4883 minmax->ptReserved.x = 0;
4884 minmax->ptReserved.y = 0;
4885 minmax->ptMaxSize.x = 400;
4886 minmax->ptMaxSize.y = 400;
4887 minmax->ptMaxPosition.x = 300;
4888 minmax->ptMaxPosition.y = 300;
4889 minmax->ptMaxTrackSize.x = 200;
4890 minmax->ptMaxTrackSize.y = 200;
4891 minmax->ptMinTrackSize.x = 100;
4892 minmax->ptMinTrackSize.y = 100;
4894 else
4895 DefWindowProc(hwnd, msg, wp, lp);
4896 return 1;
4899 static int expected_cx, expected_cy;
4900 static RECT expected_rect, broken_rect;
4902 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4904 switch(msg)
4906 case WM_GETMINMAXINFO:
4908 RECT rect;
4909 GetWindowRect( hwnd, &rect );
4910 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
4911 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4912 return DefWindowProc(hwnd, msg, wp, lp);
4914 case WM_NCCREATE:
4915 case WM_CREATE:
4917 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
4918 RECT rect;
4919 GetWindowRect( hwnd, &rect );
4920 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
4921 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
4922 ok( cs->cx == expected_cx || broken(cs->cx == (short)expected_cx),
4923 "wrong x size %d/%d\n", cs->cx, expected_cx );
4924 ok( cs->cy == expected_cy || broken(cs->cy == (short)expected_cy),
4925 "wrong y size %d/%d\n", cs->cy, expected_cy );
4926 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
4927 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
4928 (rect.right - rect.left == min( 65535, expected_rect.right - expected_rect.left ) &&
4929 rect.bottom - rect.top == min( 65535, expected_rect.bottom - expected_rect.top )) ||
4930 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
4931 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top) ||
4932 broken( rect.right - rect.left == (short)broken_rect.right - (short)broken_rect.left &&
4933 rect.bottom - rect.top == (short)broken_rect.bottom - (short)broken_rect.top),
4934 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
4935 rect.left, rect.top, rect.right, rect.bottom,
4936 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
4937 return DefWindowProc(hwnd, msg, wp, lp);
4939 case WM_NCCALCSIZE:
4941 RECT rect, *r = (RECT *)lp;
4942 GetWindowRect( hwnd, &rect );
4943 ok( !memcmp( &rect, r, sizeof(rect) ),
4944 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
4945 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
4946 return DefWindowProc(hwnd, msg, wp, lp);
4948 default:
4949 return DefWindowProc(hwnd, msg, wp, lp);
4953 static void test_CreateWindow(void)
4955 WNDCLASS cls;
4956 HWND hwnd, parent;
4957 HMENU hmenu;
4958 RECT rc, rc_minmax;
4959 MINMAXINFO minmax;
4960 BOOL res;
4962 #define expect_menu(window, menu) \
4963 SetLastError(0xdeadbeef); \
4964 res = (GetMenu(window) == (HMENU)menu); \
4965 ok(res, "GetMenu error %d\n", GetLastError())
4967 #define expect_style(window, style)\
4968 ok((ULONG)GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
4970 #define expect_ex_style(window, ex_style)\
4971 ok((ULONG)GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
4973 #define expect_gle_broken_9x(gle)\
4974 ok(GetLastError() == gle ||\
4975 broken(GetLastError() == 0xdeadbeef),\
4976 "IsMenu set error %d\n", GetLastError())
4978 hmenu = CreateMenu();
4979 assert(hmenu != 0);
4980 parent = GetDesktopWindow();
4981 assert(parent != 0);
4983 SetLastError(0xdeadbeef);
4984 res = IsMenu(hmenu);
4985 ok(res, "IsMenu error %d\n", GetLastError());
4987 /* WS_CHILD */
4988 SetLastError(0xdeadbeef);
4989 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
4990 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4991 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4992 expect_menu(hwnd, 1);
4993 expect_style(hwnd, WS_CHILD);
4994 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4995 DestroyWindow(hwnd);
4997 SetLastError(0xdeadbeef);
4998 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
4999 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5000 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5001 expect_menu(hwnd, 1);
5002 expect_style(hwnd, WS_CHILD | WS_CAPTION);
5003 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
5004 DestroyWindow(hwnd);
5006 SetLastError(0xdeadbeef);
5007 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
5008 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5009 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5010 expect_menu(hwnd, 1);
5011 expect_style(hwnd, WS_CHILD);
5012 expect_ex_style(hwnd, 0);
5013 DestroyWindow(hwnd);
5015 SetLastError(0xdeadbeef);
5016 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
5017 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5018 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5019 expect_menu(hwnd, 1);
5020 expect_style(hwnd, WS_CHILD | WS_CAPTION);
5021 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5022 DestroyWindow(hwnd);
5024 /* WS_POPUP */
5025 SetLastError(0xdeadbeef);
5026 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
5027 0, 0, 100, 100, parent, hmenu, 0, NULL);
5028 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5029 expect_menu(hwnd, hmenu);
5030 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
5031 expect_ex_style(hwnd, WS_EX_APPWINDOW);
5032 DestroyWindow(hwnd);
5033 SetLastError(0xdeadbeef);
5034 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5035 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5037 hmenu = CreateMenu();
5038 assert(hmenu != 0);
5039 SetLastError(0xdeadbeef);
5040 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
5041 0, 0, 100, 100, parent, hmenu, 0, NULL);
5042 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5043 expect_menu(hwnd, hmenu);
5044 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5045 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
5046 DestroyWindow(hwnd);
5047 SetLastError(0xdeadbeef);
5048 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5049 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5051 hmenu = CreateMenu();
5052 assert(hmenu != 0);
5053 SetLastError(0xdeadbeef);
5054 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
5055 0, 0, 100, 100, parent, hmenu, 0, NULL);
5056 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5057 expect_menu(hwnd, hmenu);
5058 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
5059 expect_ex_style(hwnd, 0);
5060 DestroyWindow(hwnd);
5061 SetLastError(0xdeadbeef);
5062 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5063 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5065 hmenu = CreateMenu();
5066 assert(hmenu != 0);
5067 SetLastError(0xdeadbeef);
5068 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
5069 0, 0, 100, 100, parent, hmenu, 0, NULL);
5070 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5071 expect_menu(hwnd, hmenu);
5072 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5073 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5074 DestroyWindow(hwnd);
5075 SetLastError(0xdeadbeef);
5076 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5077 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5079 /* WS_CHILD | WS_POPUP */
5080 SetLastError(0xdeadbeef);
5081 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
5082 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5083 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
5084 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5085 if (hwnd)
5086 DestroyWindow(hwnd);
5088 hmenu = CreateMenu();
5089 assert(hmenu != 0);
5090 SetLastError(0xdeadbeef);
5091 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
5092 0, 0, 100, 100, parent, hmenu, 0, NULL);
5093 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5094 expect_menu(hwnd, hmenu);
5095 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
5096 expect_ex_style(hwnd, WS_EX_APPWINDOW);
5097 DestroyWindow(hwnd);
5098 SetLastError(0xdeadbeef);
5099 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5100 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5102 SetLastError(0xdeadbeef);
5103 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
5104 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5105 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
5106 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5107 if (hwnd)
5108 DestroyWindow(hwnd);
5110 hmenu = CreateMenu();
5111 assert(hmenu != 0);
5112 SetLastError(0xdeadbeef);
5113 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
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_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5118 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
5119 DestroyWindow(hwnd);
5120 SetLastError(0xdeadbeef);
5121 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5122 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5124 SetLastError(0xdeadbeef);
5125 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
5126 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5127 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
5128 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5129 if (hwnd)
5130 DestroyWindow(hwnd);
5132 hmenu = CreateMenu();
5133 assert(hmenu != 0);
5134 SetLastError(0xdeadbeef);
5135 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
5136 0, 0, 100, 100, parent, hmenu, 0, NULL);
5137 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5138 expect_menu(hwnd, hmenu);
5139 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
5140 expect_ex_style(hwnd, 0);
5141 DestroyWindow(hwnd);
5142 SetLastError(0xdeadbeef);
5143 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5144 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5146 SetLastError(0xdeadbeef);
5147 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
5148 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5149 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
5150 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5151 if (hwnd)
5152 DestroyWindow(hwnd);
5154 hmenu = CreateMenu();
5155 assert(hmenu != 0);
5156 SetLastError(0xdeadbeef);
5157 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
5158 0, 0, 100, 100, parent, hmenu, 0, NULL);
5159 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5160 expect_menu(hwnd, hmenu);
5161 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5162 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5163 DestroyWindow(hwnd);
5164 SetLastError(0xdeadbeef);
5165 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5166 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5168 /* test child window sizing */
5169 cls.style = 0;
5170 cls.lpfnWndProc = minmax_wnd_proc;
5171 cls.cbClsExtra = 0;
5172 cls.cbWndExtra = 0;
5173 cls.hInstance = GetModuleHandle(0);
5174 cls.hIcon = 0;
5175 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5176 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5177 cls.lpszMenuName = NULL;
5178 cls.lpszClassName = "MinMax_WndClass";
5179 RegisterClass(&cls);
5181 SetLastError(0xdeadbeef);
5182 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
5183 0, 0, 100, 100, 0, 0, 0, NULL);
5184 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
5185 expect_menu(parent, 0);
5186 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
5187 expect_ex_style(parent, WS_EX_WINDOWEDGE);
5189 memset(&minmax, 0, sizeof(minmax));
5190 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
5191 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
5192 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
5193 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
5194 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
5196 GetWindowRect(parent, &rc);
5197 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
5198 GetClientRect(parent, &rc);
5199 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
5201 InflateRect(&rc, 200, 200);
5202 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
5204 SetLastError(0xdeadbeef);
5205 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
5206 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
5207 parent, (HMENU)1, 0, NULL);
5208 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5209 expect_menu(hwnd, 1);
5210 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
5211 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5213 memset(&minmax, 0, sizeof(minmax));
5214 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
5215 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
5217 GetWindowRect(hwnd, &rc);
5218 OffsetRect(&rc, -rc.left, -rc.top);
5219 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
5220 rc.left, rc.top, rc.right, rc.bottom,
5221 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
5222 DestroyWindow(hwnd);
5224 cls.lpfnWndProc = winsizes_wnd_proc;
5225 cls.lpszClassName = "Sizes_WndClass";
5226 RegisterClass(&cls);
5228 expected_cx = expected_cy = 200000;
5229 SetRect( &expected_rect, 0, 0, 200000, 200000 );
5230 broken_rect = expected_rect;
5231 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
5232 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5233 GetClientRect( hwnd, &rc );
5234 ok( rc.right == 200000 || rc.right == 65535 || broken(rc.right == (short)200000),
5235 "invalid rect right %u\n", rc.right );
5236 ok( rc.bottom == 200000 || rc.bottom == 65535 || broken(rc.bottom == (short)200000),
5237 "invalid rect bottom %u\n", rc.bottom );
5238 DestroyWindow(hwnd);
5240 expected_cx = expected_cy = -10;
5241 SetRect( &expected_rect, 0, 0, 0, 0 );
5242 SetRect( &broken_rect, 0, 0, -10, -10 );
5243 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
5244 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5245 GetClientRect( hwnd, &rc );
5246 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
5247 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
5248 DestroyWindow(hwnd);
5250 expected_cx = expected_cy = -200000;
5251 SetRect( &expected_rect, 0, 0, 0, 0 );
5252 SetRect( &broken_rect, 0, 0, -200000, -200000 );
5253 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
5254 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5255 GetClientRect( hwnd, &rc );
5256 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
5257 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
5258 DestroyWindow(hwnd);
5260 /* we need a parent at 0,0 so that child coordinates match */
5261 DestroyWindow(parent);
5262 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
5263 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
5265 expected_cx = 100;
5266 expected_cy = 0x7fffffff;
5267 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
5268 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
5269 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
5270 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5271 GetClientRect( hwnd, &rc );
5272 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
5273 ok( rc.bottom == 0x7fffffff - 10 || rc.bottom ==65535 || broken(rc.bottom == 0),
5274 "invalid rect bottom %u\n", rc.bottom );
5275 DestroyWindow(hwnd);
5277 expected_cx = 0x7fffffff;
5278 expected_cy = 0x7fffffff;
5279 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
5280 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
5281 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
5282 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5283 GetClientRect( hwnd, &rc );
5284 ok( rc.right == 0x7fffffff - 20 || rc.right == 65535 || broken(rc.right == 0),
5285 "invalid rect right %u\n", rc.right );
5286 ok( rc.bottom == 0x7fffffff - 10 || rc.right == 65535 || broken(rc.bottom == 0),
5287 "invalid rect bottom %u\n", rc.bottom );
5288 DestroyWindow(hwnd);
5290 /* top level window */
5291 expected_cx = expected_cy = 200000;
5292 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
5293 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
5294 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5295 GetClientRect( hwnd, &rc );
5296 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
5297 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
5298 DestroyWindow(hwnd);
5300 if (pGetLayout && pSetLayout)
5302 HDC hdc = GetDC( parent );
5303 pSetLayout( hdc, LAYOUT_RTL );
5304 if (pGetLayout( hdc ))
5306 ReleaseDC( parent, hdc );
5307 DestroyWindow( parent );
5308 SetLastError( 0xdeadbeef );
5309 parent = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_LAYOUTRTL, "static", NULL, WS_POPUP,
5310 0, 0, 100, 100, 0, 0, 0, NULL);
5311 ok( parent != 0, "creation failed err %u\n", GetLastError());
5312 expect_ex_style( parent, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
5313 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 20, 20, parent, 0, 0, NULL);
5314 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5315 expect_ex_style( hwnd, WS_EX_LAYOUTRTL );
5316 DestroyWindow( hwnd );
5317 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 20, 20, parent, 0, 0, NULL);
5318 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5319 expect_ex_style( hwnd, 0 );
5320 DestroyWindow( hwnd );
5321 SetWindowLongW( parent, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT );
5322 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 20, 20, parent, 0, 0, NULL);
5323 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5324 expect_ex_style( hwnd, 0 );
5325 DestroyWindow( hwnd );
5327 if (pGetProcessDefaultLayout && pSetProcessDefaultLayout)
5329 DWORD layout;
5331 SetLastError( 0xdeadbeef );
5332 ok( !pGetProcessDefaultLayout( NULL ), "GetProcessDefaultLayout succeeded\n" );
5333 ok( GetLastError() == ERROR_NOACCESS, "wrong error %u\n", GetLastError() );
5334 SetLastError( 0xdeadbeef );
5335 res = pGetProcessDefaultLayout( &layout );
5336 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
5337 ok( layout == 0, "GetProcessDefaultLayout wrong layout %x\n", layout );
5338 SetLastError( 0xdeadbeef );
5339 res = pSetProcessDefaultLayout( 7 );
5340 ok( res, "SetProcessDefaultLayout failed err %u\n", GetLastError ());
5341 res = pGetProcessDefaultLayout( &layout );
5342 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
5343 ok( layout == 7, "GetProcessDefaultLayout wrong layout %x\n", layout );
5344 SetLastError( 0xdeadbeef );
5345 res = pSetProcessDefaultLayout( LAYOUT_RTL );
5346 ok( res, "SetProcessDefaultLayout failed err %u\n", GetLastError ());
5347 res = pGetProcessDefaultLayout( &layout );
5348 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
5349 ok( layout == LAYOUT_RTL, "GetProcessDefaultLayout wrong layout %x\n", layout );
5350 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
5351 0, 0, 100, 100, 0, 0, 0, NULL);
5352 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5353 expect_ex_style( hwnd, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
5354 DestroyWindow( hwnd );
5355 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
5356 0, 0, 100, 100, parent, 0, 0, NULL);
5357 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5358 expect_ex_style( hwnd, WS_EX_APPWINDOW );
5359 DestroyWindow( hwnd );
5360 pSetProcessDefaultLayout( 0 );
5362 else win_skip( "SetProcessDefaultLayout not supported\n" );
5364 else win_skip( "SetLayout not supported\n" );
5366 else win_skip( "SetLayout not available\n" );
5368 DestroyWindow(parent);
5370 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
5371 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
5373 #undef expect_gle_broken_9x
5374 #undef expect_menu
5375 #undef expect_style
5376 #undef expect_ex_style
5379 /* function that remembers whether the system the test is running on sets the
5380 * last error for user32 functions to make the tests stricter */
5381 static int check_error(DWORD actual, DWORD expected)
5383 static int sets_last_error = -1;
5384 if (sets_last_error == -1)
5385 sets_last_error = (actual != 0xdeadbeef);
5386 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
5389 static void test_SetWindowLong(void)
5391 LONG_PTR retval;
5392 WNDPROC old_window_procW;
5394 SetLastError(0xdeadbeef);
5395 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
5396 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
5397 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
5398 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instead of %d\n", GetLastError());
5400 SetLastError(0xdeadbeef);
5401 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
5402 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
5403 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
5404 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instead of %d\n", GetLastError());
5406 SetLastError(0xdeadbeef);
5407 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
5408 ok((WNDPROC)retval == main_window_procA || broken(!retval), /* win9x */
5409 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
5410 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
5411 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
5412 ok((WNDPROC)retval == main_window_procA,
5413 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
5414 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
5416 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
5417 SetLastError(0xdeadbeef);
5418 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
5419 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
5421 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
5422 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
5423 ok((WNDPROC)retval == old_window_procW,
5424 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
5425 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
5427 /* set it back to ANSI */
5428 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
5432 static void test_ShowWindow(void)
5434 HWND hwnd;
5435 DWORD style;
5436 RECT rcMain, rc, rcMinimized;
5437 LPARAM ret;
5439 SetRect(&rcMain, 120, 120, 210, 210);
5441 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
5442 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5443 WS_MAXIMIZEBOX | WS_POPUP,
5444 rcMain.left, rcMain.top,
5445 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
5446 0, 0, 0, NULL);
5447 assert(hwnd);
5449 style = GetWindowLong(hwnd, GWL_STYLE);
5450 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5451 ok(!(style & WS_VISIBLE), "window should not be visible\n");
5452 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5453 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5454 GetWindowRect(hwnd, &rc);
5455 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5456 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5457 rc.left, rc.top, rc.right, rc.bottom);
5459 ret = ShowWindow(hwnd, SW_SHOW);
5460 ok(!ret, "not expected ret: %lu\n", ret);
5461 style = GetWindowLong(hwnd, GWL_STYLE);
5462 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5463 ok(style & WS_VISIBLE, "window should be visible\n");
5464 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5465 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5466 GetWindowRect(hwnd, &rc);
5467 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5468 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5469 rc.left, rc.top, rc.right, rc.bottom);
5471 ret = ShowWindow(hwnd, SW_MINIMIZE);
5472 ok(ret, "not expected ret: %lu\n", ret);
5473 style = GetWindowLong(hwnd, GWL_STYLE);
5474 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5475 ok(style & WS_VISIBLE, "window should be visible\n");
5476 ok(style & WS_MINIMIZE, "window should be minimized\n");
5477 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5478 GetWindowRect(hwnd, &rcMinimized);
5479 ok(!EqualRect(&rcMain, &rcMinimized), "rects shouldn't match\n");
5480 /* shouldn't be able to resize minimized windows */
5481 ret = SetWindowPos(hwnd, 0, 0, 0,
5482 (rcMinimized.right - rcMinimized.left) * 2,
5483 (rcMinimized.bottom - rcMinimized.top) * 2,
5484 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
5485 ok(ret, "not expected ret: %lu\n", ret);
5486 GetWindowRect(hwnd, &rc);
5487 ok(EqualRect(&rc, &rcMinimized), "rects should match\n");
5489 ShowWindow(hwnd, SW_RESTORE);
5490 ok(ret, "not expected ret: %lu\n", ret);
5491 style = GetWindowLong(hwnd, GWL_STYLE);
5492 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5493 ok(style & WS_VISIBLE, "window should be visible\n");
5494 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5495 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5496 GetWindowRect(hwnd, &rc);
5497 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5498 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5499 rc.left, rc.top, rc.right, rc.bottom);
5501 ret = EnableWindow(hwnd, FALSE);
5502 ok(!ret, "not expected ret: %lu\n", ret);
5503 style = GetWindowLong(hwnd, GWL_STYLE);
5504 ok(style & WS_DISABLED, "window should be disabled\n");
5506 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
5507 ok(!ret, "not expected ret: %lu\n", ret);
5508 style = GetWindowLong(hwnd, GWL_STYLE);
5509 ok(style & WS_DISABLED, "window should be disabled\n");
5510 ok(style & WS_VISIBLE, "window should be visible\n");
5511 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5512 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5513 GetWindowRect(hwnd, &rc);
5514 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5515 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5516 rc.left, rc.top, rc.right, rc.bottom);
5518 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
5519 ok(!ret, "not expected ret: %lu\n", ret);
5520 style = GetWindowLong(hwnd, GWL_STYLE);
5521 ok(style & WS_DISABLED, "window should be disabled\n");
5522 ok(style & WS_VISIBLE, "window should be visible\n");
5523 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5524 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5525 GetWindowRect(hwnd, &rc);
5526 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5527 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5528 rc.left, rc.top, rc.right, rc.bottom);
5530 ret = ShowWindow(hwnd, SW_MINIMIZE);
5531 ok(ret, "not expected ret: %lu\n", ret);
5532 style = GetWindowLong(hwnd, GWL_STYLE);
5533 ok(style & WS_DISABLED, "window should be disabled\n");
5534 ok(style & WS_VISIBLE, "window should be visible\n");
5535 ok(style & WS_MINIMIZE, "window should be minimized\n");
5536 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5537 GetWindowRect(hwnd, &rc);
5538 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
5540 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
5541 ok(!ret, "not expected ret: %lu\n", ret);
5542 style = GetWindowLong(hwnd, GWL_STYLE);
5543 ok(style & WS_DISABLED, "window should be disabled\n");
5544 ok(style & WS_VISIBLE, "window should be visible\n");
5545 ok(style & WS_MINIMIZE, "window should be minimized\n");
5546 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5547 GetWindowRect(hwnd, &rc);
5548 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
5550 ret = ShowWindow(hwnd, SW_RESTORE);
5551 ok(ret, "not expected ret: %lu\n", ret);
5552 style = GetWindowLong(hwnd, GWL_STYLE);
5553 ok(style & WS_DISABLED, "window should be disabled\n");
5554 ok(style & WS_VISIBLE, "window should be visible\n");
5555 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5556 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5557 GetWindowRect(hwnd, &rc);
5558 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5559 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5560 rc.left, rc.top, rc.right, rc.bottom);
5562 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
5563 ok(!ret, "not expected ret: %lu\n", ret);
5564 ok(IsWindow(hwnd), "window should exist\n");
5566 ret = EnableWindow(hwnd, TRUE);
5567 ok(ret, "not expected ret: %lu\n", ret);
5569 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
5570 ok(!ret, "not expected ret: %lu\n", ret);
5571 ok(!IsWindow(hwnd), "window should not exist\n");
5574 static void test_gettext(void)
5576 WNDCLASS cls;
5577 LPCSTR clsname = "gettexttest";
5578 HWND hwnd;
5579 LRESULT r;
5581 memset( &cls, 0, sizeof cls );
5582 cls.lpfnWndProc = DefWindowProc;
5583 cls.lpszClassName = clsname;
5584 cls.hInstance = GetModuleHandle(NULL);
5586 if (!RegisterClass( &cls )) return;
5588 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
5589 ok( hwnd != NULL, "window was null\n");
5591 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
5592 ok( r == 0, "settext should return zero\n");
5594 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
5595 ok( r == 0, "settext should return zero (%ld)\n", r);
5597 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
5598 ok( r == 0, "settext should return zero (%ld)\n", r);
5600 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
5601 ok( r == 0, "settext should return zero (%ld)\n", r);
5603 DestroyWindow(hwnd);
5604 UnregisterClass( clsname, NULL );
5608 static void test_GetUpdateRect(void)
5610 MSG msg;
5611 BOOL ret, parent_wm_paint, grandparent_wm_paint;
5612 RECT rc1, rc2;
5613 HWND hgrandparent, hparent, hchild;
5614 WNDCLASSA cls;
5615 static const char classNameA[] = "GetUpdateRectClass";
5617 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
5618 0, 0, 100, 100, NULL, NULL, 0, NULL);
5620 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
5621 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
5623 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
5624 10, 10, 30, 30, hparent, NULL, 0, NULL);
5626 ShowWindow(hgrandparent, SW_SHOW);
5627 UpdateWindow(hgrandparent);
5628 flush_events( TRUE );
5630 ShowWindow(hchild, SW_HIDE);
5631 SetRect(&rc2, 0, 0, 0, 0);
5632 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5633 ok(!ret, "GetUpdateRect returned not empty region\n");
5634 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5635 rc1.left, rc1.top, rc1.right, rc1.bottom,
5636 rc2.left, rc2.top, rc2.right, rc2.bottom);
5638 SetRect(&rc2, 10, 10, 40, 40);
5639 ret = GetUpdateRect(hparent, &rc1, FALSE);
5640 ok(ret, "GetUpdateRect returned empty region\n");
5641 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5642 rc1.left, rc1.top, rc1.right, rc1.bottom,
5643 rc2.left, rc2.top, rc2.right, rc2.bottom);
5645 parent_wm_paint = FALSE;
5646 grandparent_wm_paint = FALSE;
5647 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
5649 if (msg.message == WM_PAINT)
5651 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
5652 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
5654 DispatchMessage(&msg);
5656 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
5657 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
5659 DestroyWindow(hgrandparent);
5661 cls.style = 0;
5662 cls.lpfnWndProc = DefWindowProcA;
5663 cls.cbClsExtra = 0;
5664 cls.cbWndExtra = 0;
5665 cls.hInstance = GetModuleHandleA(0);
5666 cls.hIcon = 0;
5667 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5668 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5669 cls.lpszMenuName = NULL;
5670 cls.lpszClassName = classNameA;
5672 if(!RegisterClassA(&cls)) {
5673 trace("Register failed %d\n", GetLastError());
5674 return;
5677 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
5678 0, 0, 100, 100, NULL, NULL, 0, NULL);
5680 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
5681 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
5683 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
5684 10, 10, 30, 30, hparent, NULL, 0, NULL);
5686 ShowWindow(hgrandparent, SW_SHOW);
5687 UpdateWindow(hgrandparent);
5688 flush_events( TRUE );
5690 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5691 ok(!ret, "GetUpdateRect returned not empty region\n");
5693 ShowWindow(hchild, SW_HIDE);
5695 SetRect(&rc2, 0, 0, 0, 0);
5696 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5697 ok(!ret, "GetUpdateRect returned not empty region\n");
5698 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5699 rc1.left, rc1.top, rc1.right, rc1.bottom,
5700 rc2.left, rc2.top, rc2.right, rc2.bottom);
5702 SetRect(&rc2, 10, 10, 40, 40);
5703 ret = GetUpdateRect(hparent, &rc1, FALSE);
5704 ok(ret, "GetUpdateRect returned empty region\n");
5705 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5706 rc1.left, rc1.top, rc1.right, rc1.bottom,
5707 rc2.left, rc2.top, rc2.right, rc2.bottom);
5709 parent_wm_paint = FALSE;
5710 grandparent_wm_paint = FALSE;
5711 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
5713 if (msg.message == WM_PAINT)
5715 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
5716 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
5718 DispatchMessage(&msg);
5720 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
5721 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
5723 DestroyWindow(hgrandparent);
5727 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5729 if(msg == WM_PAINT)
5731 PAINTSTRUCT ps;
5732 RECT updateRect;
5733 DWORD waitResult;
5734 HWND win;
5735 const int waitTime = 2000;
5737 BeginPaint(hwnd, &ps);
5739 /* create and destroy window to create an exposed region on this window */
5740 win = CreateWindowA("static", "win", WS_VISIBLE,
5741 10,10,50,50, NULL, NULL, 0, NULL);
5742 DestroyWindow(win);
5744 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
5746 ValidateRect(hwnd, NULL);
5747 EndPaint(hwnd, &ps);
5749 if(waitResult != WAIT_TIMEOUT)
5751 GetUpdateRect(hwnd, &updateRect, FALSE);
5752 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
5755 return 1;
5757 return DefWindowProc(hwnd, msg, wParam, lParam);
5760 static void test_Expose(void)
5762 WNDCLASSA cls;
5763 HWND mw;
5765 memset(&cls, 0, sizeof(WNDCLASSA));
5766 cls.lpfnWndProc = TestExposedRegion_WndProc;
5767 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5768 cls.lpszClassName = "TestExposeClass";
5769 RegisterClassA(&cls);
5771 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
5772 0, 0, 200, 100, NULL, NULL, 0, NULL);
5774 UpdateWindow(mw);
5775 DestroyWindow(mw);
5778 static LRESULT CALLBACK TestNCRedraw_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5780 static UINT ncredrawflags;
5781 PAINTSTRUCT ps;
5783 switch(msg)
5785 case WM_CREATE:
5786 ncredrawflags = *(UINT *) (((CREATESTRUCT *)lParam)->lpCreateParams);
5787 return 0;
5788 case WM_NCPAINT:
5789 RedrawWindow(hwnd, NULL, NULL, ncredrawflags);
5790 break;
5791 case WM_PAINT:
5792 BeginPaint(hwnd, &ps);
5793 EndPaint(hwnd, &ps);
5794 return 0;
5796 return DefWindowProc(hwnd, msg, wParam, lParam);
5799 static void run_NCRedrawLoop(UINT flags)
5801 HWND hwnd;
5802 MSG msg;
5804 UINT loopcount = 0;
5806 hwnd = CreateWindowA("TestNCRedrawClass", "MainWindow",
5807 WS_OVERLAPPEDWINDOW, 0, 0, 200, 100,
5808 NULL, NULL, 0, &flags);
5809 ShowWindow(hwnd, SW_SHOW);
5810 UpdateWindow(hwnd);
5811 flush_events( FALSE );
5812 while(PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE) != 0)
5814 if (msg.message == WM_PAINT) loopcount++;
5815 if (loopcount >= 100) break;
5816 TranslateMessage(&msg);
5817 DispatchMessage(&msg);
5818 MsgWaitForMultipleObjects(0, NULL, FALSE, 100, QS_ALLINPUT);
5820 if (flags == (RDW_INVALIDATE | RDW_FRAME))
5821 todo_wine ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
5822 else
5823 ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
5824 DestroyWindow(hwnd);
5827 static void test_NCRedraw(void)
5829 WNDCLASSA wndclass;
5831 wndclass.lpszClassName = "TestNCRedrawClass";
5832 wndclass.style = CS_HREDRAW | CS_VREDRAW;
5833 wndclass.lpfnWndProc = TestNCRedraw_WndProc;
5834 wndclass.cbClsExtra = 0;
5835 wndclass.cbWndExtra = 0;
5836 wndclass.hInstance = 0;
5837 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
5838 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
5839 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
5840 wndclass.lpszMenuName = NULL;
5842 RegisterClassA(&wndclass);
5844 run_NCRedrawLoop(RDW_INVALIDATE | RDW_FRAME);
5845 run_NCRedrawLoop(RDW_INVALIDATE);
5848 static void test_GetWindowModuleFileName(void)
5850 HWND hwnd;
5851 HINSTANCE hinst;
5852 UINT ret1, ret2;
5853 char buf1[MAX_PATH], buf2[MAX_PATH];
5855 if (!pGetWindowModuleFileNameA)
5857 win_skip("GetWindowModuleFileNameA is not available\n");
5858 return;
5861 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
5862 assert(hwnd);
5864 hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
5865 ok(hinst == 0 || broken(hinst == GetModuleHandle(0)), /* win9x */ "expected 0, got %p\n", hinst);
5867 buf1[0] = 0;
5868 SetLastError(0xdeadbeef);
5869 ret1 = GetModuleFileName(hinst, buf1, sizeof(buf1));
5870 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
5872 buf2[0] = 0;
5873 SetLastError(0xdeadbeef);
5874 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
5875 ok(ret2 || broken(!ret2), /* nt4 sp 3 */
5876 "GetWindowModuleFileNameA error %u\n", GetLastError());
5878 if (ret2)
5880 ok(ret1 == ret2 || broken(ret2 == ret1 + 1), /* win98 */ "%u != %u\n", ret1, ret2);
5881 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
5883 hinst = GetModuleHandle(0);
5885 SetLastError(0xdeadbeef);
5886 ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
5887 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
5888 "expected %u, got %u\n", ret1 - 2, ret2);
5889 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5890 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5891 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5893 SetLastError(0xdeadbeef);
5894 ret2 = GetModuleFileName(hinst, buf2, 0);
5895 ok(!ret2, "GetModuleFileName should return 0\n");
5896 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5897 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5898 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5900 SetLastError(0xdeadbeef);
5901 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
5902 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3) /* win98 */ || broken(!ret2), /* nt4 sp3 */
5903 "expected %u, got %u\n", ret1 - 2, ret2);
5904 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5905 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5906 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5908 SetLastError(0xdeadbeef);
5909 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
5910 ok(!ret2, "expected 0, got %u\n", ret2);
5911 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5912 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5913 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5915 DestroyWindow(hwnd);
5917 buf2[0] = 0;
5918 hwnd = (HWND)0xdeadbeef;
5919 SetLastError(0xdeadbeef);
5920 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
5921 ok(!ret1, "expected 0, got %u\n", ret1);
5922 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef), /* win9x */
5923 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
5925 hwnd = FindWindow("Shell_TrayWnd", NULL);
5926 ok(IsWindow(hwnd) || broken(!hwnd), "got invalid tray window %p\n", hwnd);
5927 SetLastError(0xdeadbeef);
5928 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
5929 ok(!ret1 || broken(ret1), /* win98 */ "expected 0, got %u\n", ret1);
5931 if (!ret1) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
5933 ret1 = GetModuleFileName(0, buf1, sizeof(buf1));
5934 hwnd = GetDesktopWindow();
5935 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
5936 SetLastError(0xdeadbeef);
5937 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
5938 ok(!ret2 ||
5939 ret1 == ret2 || /* vista */
5940 broken(ret2), /* some win98 return user.exe as file name */
5941 "expected 0 or %u, got %u %s\n", ret1, ret2, buf2);
5945 static void test_hwnd_message(void)
5947 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
5948 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
5950 HWND parent = 0, hwnd, found;
5951 RECT rect;
5953 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
5954 on CreateWindowExA and crash later in the test.
5955 Use UNICODE here to fail on win9x */
5956 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
5957 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
5958 if (!hwnd)
5960 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
5961 return;
5964 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
5965 if (pGetAncestor)
5967 char buffer[100];
5968 HWND root, desktop = GetDesktopWindow();
5970 parent = pGetAncestor(hwnd, GA_PARENT);
5971 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
5972 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
5973 root = pGetAncestor(hwnd, GA_ROOT);
5974 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
5975 ok( !pGetAncestor(parent, GA_PARENT) || broken(pGetAncestor(parent, GA_PARENT) != 0), /* win2k */
5976 "parent shouldn't have parent %p\n", pGetAncestor(parent, GA_PARENT) );
5977 trace("parent %p root %p desktop %p\n", parent, root, desktop);
5978 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
5979 ok( !lstrcmpi( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
5980 GetWindowRect( parent, &rect );
5981 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
5982 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
5984 GetWindowRect( hwnd, &rect );
5985 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
5986 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
5988 /* test FindWindow behavior */
5990 found = FindWindowExA( 0, 0, 0, "message window" );
5991 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
5992 SetLastError(0xdeadbeef);
5993 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
5994 ok( found == 0, "found message window %p/%p\n", found, hwnd );
5995 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
5996 if (parent)
5998 found = FindWindowExA( parent, 0, 0, "message window" );
5999 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
6002 /* test IsChild behavior */
6004 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
6006 /* test IsWindowVisible behavior */
6008 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
6009 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
6011 DestroyWindow(hwnd);
6014 static void test_layered_window(void)
6016 HWND hwnd;
6017 COLORREF key = 0;
6018 BYTE alpha = 0;
6019 DWORD flags = 0;
6020 POINT pt = { 0, 0 };
6021 SIZE sz = { 200, 200 };
6022 HDC hdc;
6023 HBITMAP hbm;
6024 BOOL ret;
6026 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes || !pUpdateLayeredWindow)
6028 win_skip( "layered windows not supported\n" );
6029 return;
6032 hdc = CreateCompatibleDC( 0 );
6033 hbm = CreateCompatibleBitmap( hdc, 200, 200 );
6034 SelectObject( hdc, hbm );
6036 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
6037 100, 100, 200, 200, 0, 0, 0, NULL);
6038 assert( hwnd );
6039 SetLastError( 0xdeadbeef );
6040 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6041 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
6042 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
6043 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6044 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
6045 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
6046 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
6047 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
6048 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6049 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
6050 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6051 ok( ret, "UpdateLayeredWindow should succeed on layered window\n" );
6052 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6053 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
6054 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
6055 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6056 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6057 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6058 ok( key == 0x123456 || key == 0, "wrong color key %x\n", key );
6059 ok( alpha == 44, "wrong alpha %u\n", alpha );
6060 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
6061 SetLastError( 0xdeadbeef );
6062 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6063 ok( !ret, "UpdateLayeredWindow should fail on layered but initialized window\n" );
6064 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
6066 /* clearing WS_EX_LAYERED resets attributes */
6067 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
6068 SetLastError( 0xdeadbeef );
6069 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6070 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
6071 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6072 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
6073 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
6074 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6075 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
6076 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6077 ok( ret, "UpdateLayeredWindow should succeed on layered window\n" );
6078 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE | ULW_EX_NORESIZE );
6079 ok( !ret, "UpdateLayeredWindow should fail with ex flag\n" );
6080 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
6081 if (pUpdateLayeredWindowIndirect)
6083 UPDATELAYEREDWINDOWINFO info;
6084 info.cbSize = sizeof(info);
6085 info.hdcDst = 0;
6086 info.pptDst = NULL;
6087 info.psize = &sz;
6088 info.hdcSrc = hdc;
6089 info.pptSrc = &pt;
6090 info.crKey = 0;
6091 info.pblend = NULL;
6092 info.dwFlags = ULW_OPAQUE | ULW_EX_NORESIZE;
6093 info.prcDirty = NULL;
6094 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6095 ok( ret, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
6096 sz.cx--;
6097 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6098 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
6099 ok( GetLastError() == ERROR_INCORRECT_SIZE || broken(GetLastError() == ERROR_MR_MID_NOT_FOUND),
6100 "wrong error %u\n", GetLastError() );
6101 info.dwFlags = ULW_OPAQUE;
6102 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6103 ok( ret, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
6104 sz.cx++;
6105 info.dwFlags = ULW_OPAQUE | 0xf00;
6106 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6107 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
6108 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
6109 info.cbSize--;
6110 info.dwFlags = ULW_OPAQUE;
6111 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6112 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
6113 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
6114 ret = pUpdateLayeredWindowIndirect( hwnd, NULL );
6115 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
6116 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
6119 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
6120 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6121 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6122 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6123 ok( key == 0x654321, "wrong color key %x\n", key );
6124 ok( alpha == 22, "wrong alpha %u\n", alpha );
6125 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
6126 SetLastError( 0xdeadbeef );
6127 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6128 ok( !ret, "UpdateLayeredWindow should fail on layered but initialized window\n" );
6129 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
6131 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
6132 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6133 alpha = 0;
6134 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6135 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6136 ok( key == 0x888888, "wrong color key %x\n", key );
6137 /* alpha not changed on vista if LWA_ALPHA is not set */
6138 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
6139 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
6141 /* color key may or may not be changed without LWA_COLORKEY */
6142 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
6143 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6144 alpha = 0;
6145 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6146 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6147 ok( key == 0x888888 || key == 0x999999, "wrong color key %x\n", key );
6148 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
6149 ok( flags == 0, "wrong flags %x\n", flags );
6151 /* default alpha and color key is 0 */
6152 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
6153 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
6154 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
6155 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6156 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6157 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6158 ok( key == 0 || key == 0x222222, "wrong color key %x\n", key );
6159 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
6160 ok( flags == 0, "wrong flags %x\n", flags );
6162 DestroyWindow( hwnd );
6163 DeleteDC( hdc );
6164 DeleteObject( hbm );
6167 static MONITORINFO mi;
6169 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
6171 switch (msg)
6173 case WM_NCCREATE:
6175 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
6176 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs->x, cs->y, cs->cx, cs->cy);
6177 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
6178 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
6179 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
6180 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6181 cs->x, cs->y, cs->cx, cs->cy);
6182 break;
6184 case WM_GETMINMAXINFO:
6186 MINMAXINFO *minmax = (MINMAXINFO *)lp;
6187 dump_minmax_info(minmax);
6188 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
6189 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
6190 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
6191 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
6192 break;
6195 return DefWindowProc(hwnd, msg, wp, lp);
6198 static void test_fullscreen(void)
6200 static const DWORD t_style[] = {
6201 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
6203 static const DWORD t_ex_style[] = {
6204 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
6206 WNDCLASS cls;
6207 HWND hwnd;
6208 int i, j;
6209 POINT pt;
6210 RECT rc;
6211 HMONITOR hmon;
6212 LRESULT ret;
6214 if (!pGetMonitorInfoA || !pMonitorFromPoint)
6216 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
6217 return;
6220 pt.x = pt.y = 0;
6221 SetLastError(0xdeadbeef);
6222 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
6223 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
6225 mi.cbSize = sizeof(mi);
6226 SetLastError(0xdeadbeef);
6227 ret = pGetMonitorInfoA(hmon, &mi);
6228 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
6229 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
6230 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6231 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
6233 cls.style = 0;
6234 cls.lpfnWndProc = fullscreen_wnd_proc;
6235 cls.cbClsExtra = 0;
6236 cls.cbWndExtra = 0;
6237 cls.hInstance = GetModuleHandle(0);
6238 cls.hIcon = 0;
6239 cls.hCursor = LoadCursorA(0, IDC_ARROW);
6240 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6241 cls.lpszMenuName = NULL;
6242 cls.lpszClassName = "fullscreen_class";
6243 RegisterClass(&cls);
6245 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
6247 DWORD style, ex_style;
6249 /* avoid a WM interaction */
6250 assert(!(t_style[i] & WS_VISIBLE));
6252 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
6254 int fixup;
6256 style = t_style[i];
6257 ex_style = t_ex_style[j];
6259 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6260 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6261 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
6262 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6263 GetWindowRect(hwnd, &rc);
6264 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6265 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6266 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6267 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6268 DestroyWindow(hwnd);
6270 style = t_style[i] | WS_MAXIMIZE;
6271 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6272 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6273 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
6274 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6275 GetWindowRect(hwnd, &rc);
6276 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6277 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6278 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6279 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6280 DestroyWindow(hwnd);
6282 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
6283 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6284 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6285 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
6286 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6287 GetWindowRect(hwnd, &rc);
6288 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6289 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6290 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6291 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6292 DestroyWindow(hwnd);
6294 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
6295 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6296 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6297 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
6298 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6299 GetWindowRect(hwnd, &rc);
6300 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6301 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6302 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6303 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6304 DestroyWindow(hwnd);
6306 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
6307 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6308 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6309 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
6310 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6311 GetWindowRect(hwnd, &rc);
6312 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6313 /* Windows makes a maximized window slightly larger (to hide the borders?) */
6314 fixup = min(abs(rc.left), abs(rc.top));
6315 InflateRect(&rc, -fixup, -fixup);
6316 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
6317 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
6318 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
6319 ex_style, style, rc.left, rc.top, rc.right, rc.bottom,
6320 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
6321 DestroyWindow(hwnd);
6323 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
6324 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6325 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6326 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
6327 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6328 GetWindowRect(hwnd, &rc);
6329 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6330 /* Windows makes a maximized window slightly larger (to hide the borders?) */
6331 fixup = min(abs(rc.left), abs(rc.top));
6332 InflateRect(&rc, -fixup, -fixup);
6333 if (style & (WS_CHILD | WS_POPUP))
6334 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6335 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6336 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6337 else
6338 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
6339 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
6340 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6341 DestroyWindow(hwnd);
6345 UnregisterClass("fullscreen_class", GetModuleHandle(0));
6348 static BOOL test_thick_child_got_minmax;
6349 static const char * test_thick_child_name;
6350 static LONG test_thick_child_style;
6351 static LONG test_thick_child_exStyle;
6353 static LRESULT WINAPI test_thick_child_size_winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
6355 MINMAXINFO* minmax;
6356 int expectedMinTrackX;
6357 int expectedMinTrackY;
6358 int actualMinTrackX;
6359 int actualMinTrackY;
6360 int expectedMaxTrackX;
6361 int expectedMaxTrackY;
6362 int actualMaxTrackX;
6363 int actualMaxTrackY;
6364 int expectedMaxSizeX;
6365 int expectedMaxSizeY;
6366 int actualMaxSizeX;
6367 int actualMaxSizeY;
6368 int expectedPosX;
6369 int expectedPosY;
6370 int actualPosX;
6371 int actualPosY;
6372 LONG adjustedStyle;
6373 RECT rect;
6374 switch (msg)
6376 case WM_GETMINMAXINFO:
6378 minmax = (MINMAXINFO *)lparam;
6379 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
6380 dump_minmax_info( minmax );
6382 test_thick_child_got_minmax = TRUE;
6385 adjustedStyle = test_thick_child_style;
6386 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
6387 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
6388 GetClientRect(GetParent(hwnd), &rect);
6389 AdjustWindowRectEx(&rect, adjustedStyle, FALSE, test_thick_child_exStyle);
6391 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
6393 expectedMinTrackX = GetSystemMetrics(SM_CXMINTRACK);
6394 expectedMinTrackY = GetSystemMetrics(SM_CYMINTRACK);
6396 else
6398 expectedMinTrackX = -2 * rect.left;
6399 expectedMinTrackY = -2 * rect.top;
6401 actualMinTrackX = minmax->ptMinTrackSize.x;
6402 actualMinTrackY = minmax->ptMinTrackSize.y;
6404 ok(actualMinTrackX == expectedMinTrackX && actualMinTrackY == expectedMinTrackY,
6405 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
6406 expectedMinTrackX, expectedMinTrackY, actualMinTrackX, actualMinTrackY,
6407 test_thick_child_name);
6409 actualMaxTrackX = minmax->ptMaxTrackSize.x;
6410 actualMaxTrackY = minmax->ptMaxTrackSize.y;
6411 expectedMaxTrackX = GetSystemMetrics(SM_CXMAXTRACK);
6412 expectedMaxTrackY = GetSystemMetrics(SM_CYMAXTRACK);
6413 ok(actualMaxTrackX == expectedMaxTrackX && actualMaxTrackY == expectedMaxTrackY,
6414 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
6415 expectedMaxTrackX, expectedMaxTrackY, actualMaxTrackX, actualMaxTrackY,
6416 test_thick_child_name);
6418 expectedMaxSizeX = rect.right - rect.left;
6419 expectedMaxSizeY = rect.bottom - rect.top;
6420 actualMaxSizeX = minmax->ptMaxSize.x;
6421 actualMaxSizeY = minmax->ptMaxSize.y;
6423 ok(actualMaxSizeX == expectedMaxSizeX && actualMaxSizeY == expectedMaxSizeY,
6424 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
6425 expectedMaxSizeX, expectedMaxSizeY, actualMaxSizeX, actualMaxSizeY,
6426 test_thick_child_name);
6429 expectedPosX = rect.left;
6430 expectedPosY = rect.top;
6431 actualPosX = minmax->ptMaxPosition.x;
6432 actualPosY = minmax->ptMaxPosition.y;
6433 ok(actualPosX == expectedPosX && actualPosY == expectedPosY,
6434 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
6435 expectedPosX, expectedPosY, actualPosX, actualPosY, test_thick_child_name);
6437 break;
6441 return DefWindowProcA(hwnd, msg, wparam, lparam);
6444 #define NUMBER_OF_THICK_CHILD_TESTS 16
6445 static void test_thick_child_size(HWND parentWindow)
6447 BOOL success;
6448 RECT childRect;
6449 RECT adjustedParentRect;
6450 HWND childWindow;
6451 LONG childWidth;
6452 LONG childHeight;
6453 LONG expectedWidth;
6454 LONG expectedHeight;
6455 WNDCLASSA cls;
6456 LPCTSTR className = "THICK_CHILD_CLASS";
6457 int i;
6458 LONG adjustedStyle;
6459 static const LONG styles[NUMBER_OF_THICK_CHILD_TESTS] = {
6460 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6461 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6462 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6463 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6464 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6465 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6466 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6467 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6468 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6469 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6470 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6471 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6472 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6473 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6474 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6475 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6478 static const LONG exStyles[NUMBER_OF_THICK_CHILD_TESTS] = {
6483 WS_EX_DLGMODALFRAME,
6484 WS_EX_DLGMODALFRAME,
6485 WS_EX_DLGMODALFRAME,
6486 WS_EX_DLGMODALFRAME,
6487 WS_EX_STATICEDGE,
6488 WS_EX_STATICEDGE,
6489 WS_EX_STATICEDGE,
6490 WS_EX_STATICEDGE,
6491 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6492 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6493 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6494 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6496 static const char *styleName[NUMBER_OF_THICK_CHILD_TESTS] = {
6497 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
6498 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
6499 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
6500 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
6501 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
6502 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
6503 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
6504 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
6505 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
6506 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
6507 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
6508 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
6509 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6510 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6511 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6512 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6515 cls.style = 0;
6516 cls.lpfnWndProc = test_thick_child_size_winproc;
6517 cls.cbClsExtra = 0;
6518 cls.cbWndExtra = 0;
6519 cls.hInstance = GetModuleHandleA(0);
6520 cls.hIcon = 0;
6521 cls.hCursor = LoadCursorA(0, IDC_ARROW);
6522 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6523 cls.lpszMenuName = NULL;
6524 cls.lpszClassName = className;
6525 SetLastError(0xdeadbeef);
6526 success = RegisterClassA(&cls);
6527 ok(success,"RegisterClassA failed, error: %u\n", GetLastError());
6529 for(i = 0; i < NUMBER_OF_THICK_CHILD_TESTS; i++)
6531 test_thick_child_name = styleName[i];
6532 test_thick_child_style = styles[i];
6533 test_thick_child_exStyle = exStyles[i];
6534 test_thick_child_got_minmax = FALSE;
6536 SetLastError(0xdeadbeef);
6537 childWindow = CreateWindowEx( exStyles[i], className, "", styles[i], 0, 0, 0, 0, parentWindow, 0, GetModuleHandleA(0), NULL );
6538 ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
6540 ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
6542 SetLastError(0xdeadbeef);
6543 success = GetWindowRect(childWindow, &childRect);
6544 ok(success,"GetWindowRect call failed, error: %u\n", GetLastError());
6545 childWidth = childRect.right - childRect.left;
6546 childHeight = childRect.bottom - childRect.top;
6548 adjustedStyle = styles[i];
6549 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
6550 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
6551 GetClientRect(GetParent(childWindow), &adjustedParentRect);
6552 AdjustWindowRectEx(&adjustedParentRect, adjustedStyle, FALSE, test_thick_child_exStyle);
6555 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
6557 expectedWidth = GetSystemMetrics(SM_CXMINTRACK);
6558 expectedHeight = GetSystemMetrics(SM_CYMINTRACK);
6560 else
6562 expectedWidth = -2 * adjustedParentRect.left;
6563 expectedHeight = -2 * adjustedParentRect.top;
6566 ok((childWidth == expectedWidth) && (childHeight == expectedHeight),
6567 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
6568 test_thick_child_name, expectedWidth, expectedHeight, childWidth, childHeight);
6570 SetLastError(0xdeadbeef);
6571 success = DestroyWindow(childWindow);
6572 ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
6574 ok(UnregisterClass(className, GetModuleHandleA(0)),"UnregisterClass call failed\n");
6577 static void test_handles( HWND full_hwnd )
6579 HWND hwnd = full_hwnd;
6580 BOOL ret;
6581 RECT rect;
6583 SetLastError( 0xdeadbeef );
6584 ret = GetWindowRect( hwnd, &rect );
6585 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6587 #ifdef _WIN64
6588 if ((ULONG_PTR)full_hwnd >> 32)
6589 hwnd = (HWND)((ULONG_PTR)full_hwnd & ~0u);
6590 else
6591 hwnd = (HWND)((ULONG_PTR)full_hwnd | ((ULONG_PTR)~0u << 32));
6592 SetLastError( 0xdeadbeef );
6593 ret = GetWindowRect( hwnd, &rect );
6594 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6596 hwnd = (HWND)(((ULONG_PTR)full_hwnd & ~0u) | ((ULONG_PTR)0x1234 << 32));
6597 SetLastError( 0xdeadbeef );
6598 ret = GetWindowRect( hwnd, &rect );
6599 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6601 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x9876 << 16));
6602 SetLastError( 0xdeadbeef );
6603 ret = GetWindowRect( hwnd, &rect );
6604 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
6605 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
6607 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x12345678 << 16));
6608 SetLastError( 0xdeadbeef );
6609 ret = GetWindowRect( hwnd, &rect );
6610 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
6611 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
6612 #endif
6615 static void test_winregion(void)
6617 HWND hwnd;
6618 RECT r;
6619 int ret, width;
6620 HRGN hrgn;
6622 if (!pGetWindowRgnBox)
6624 win_skip("GetWindowRgnBox not supported\n");
6625 return;
6628 hwnd = CreateWindowExA(0, "static", NULL, WS_VISIBLE, 10, 10, 10, 10, NULL, 0, 0, NULL);
6629 /* NULL prect */
6630 SetLastError(0xdeadbeef);
6631 ret = pGetWindowRgnBox(hwnd, NULL);
6632 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
6633 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
6635 hrgn = CreateRectRgn(2, 3, 10, 15);
6636 ok( hrgn != NULL, "Region creation failed\n");
6637 if (hrgn)
6639 SetWindowRgn(hwnd, hrgn, FALSE);
6641 SetLastError(0xdeadbeef);
6642 ret = pGetWindowRgnBox(hwnd, NULL);
6643 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
6644 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
6646 r.left = r.top = r.right = r.bottom = 0;
6647 ret = pGetWindowRgnBox(hwnd, &r);
6648 ok( ret == SIMPLEREGION, "Expected SIMPLEREGION, got %d\n", ret);
6649 ok( r.left == 2 && r.top == 3 && r.right == 10 && r.bottom == 15,
6650 "Expected (2,3,10,15), got (%d,%d,%d,%d)\n", r.left, r.top,
6651 r.right, r.bottom);
6652 if (pMirrorRgn)
6654 hrgn = CreateRectRgn(2, 3, 10, 15);
6655 ret = pMirrorRgn( hwnd, hrgn );
6656 ok( ret == TRUE, "MirrorRgn failed %u\n", ret );
6657 r.left = r.top = r.right = r.bottom = 0;
6658 GetWindowRect( hwnd, &r );
6659 width = r.right - r.left;
6660 r.left = r.top = r.right = r.bottom = 0;
6661 ret = GetRgnBox( hrgn, &r );
6662 ok( ret == SIMPLEREGION, "GetRgnBox failed %u\n", ret );
6663 ok( r.left == width - 10 && r.top == 3 && r.right == width - 2 && r.bottom == 15,
6664 "Wrong rectangle (%d,%d,%d,%d) for width %d\n", r.left, r.top, r.right, r.bottom, width );
6666 else win_skip( "MirrorRgn not supported\n" );
6668 DestroyWindow(hwnd);
6671 static void test_rtl_layout(void)
6673 HWND parent, child;
6674 RECT r;
6675 POINT pt;
6677 if (!pSetProcessDefaultLayout)
6679 win_skip( "SetProcessDefaultLayout not supported\n" );
6680 return;
6683 parent = CreateWindowExA(WS_EX_LAYOUTRTL, "static", NULL, WS_POPUP, 100, 100, 300, 300, NULL, 0, 0, NULL);
6684 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 10, 10, 20, 20, parent, 0, 0, NULL);
6686 GetWindowRect( parent, &r );
6687 ok( r.left == 100 && r.right == 400, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6688 GetClientRect( parent, &r );
6689 ok( r.left == 0 && r.right == 300, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6690 GetClientRect( child, &r );
6691 ok( r.left == 0 && r.right == 20, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6692 MapWindowPoints( child, parent, (POINT *)&r, 2 );
6693 ok( r.left == 10 && r.right == 30, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6694 GetWindowRect( child, &r );
6695 ok( r.left == 370 && r.right == 390, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6696 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
6697 ok( r.left == 10 && r.right == 30, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6698 GetWindowRect( child, &r );
6699 MapWindowPoints( NULL, parent, (POINT *)&r, 1 );
6700 MapWindowPoints( NULL, parent, (POINT *)&r + 1, 1 );
6701 ok( r.left == 30 && r.right == 10, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6702 pt.x = pt.y = 12;
6703 MapWindowPoints( child, parent, &pt, 1 );
6704 ok( pt.x == 22 && pt.y == 22, "wrong point %d,%d\n", pt.x, pt.y );
6705 SetWindowPos( parent, 0, 0, 0, 250, 250, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
6706 GetWindowRect( parent, &r );
6707 ok( r.left == 100 && r.right == 350, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6708 GetWindowRect( child, &r );
6709 ok( r.left == 320 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6710 SetWindowLongW( parent, GWL_EXSTYLE, 0 );
6711 GetWindowRect( child, &r );
6712 ok( r.left == 320 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6713 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
6714 ok( r.left == 220 && r.right == 240, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6715 SetWindowLongW( parent, GWL_EXSTYLE, WS_EX_LAYOUTRTL );
6716 GetWindowRect( child, &r );
6717 ok( r.left == 320 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6718 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
6719 ok( r.left == 10 && r.right == 30, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6720 SetWindowPos( child, 0, 0, 0, 30, 30, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
6721 GetWindowRect( child, &r );
6722 ok( r.left == 310 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6723 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
6724 ok( r.left == 10 && r.right == 40, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6725 DestroyWindow( child );
6726 DestroyWindow( parent );
6729 static void test_FlashWindowEx(void)
6731 HWND hwnd;
6732 FLASHWINFO finfo;
6733 BOOL prev, ret;
6735 if (!pFlashWindowEx)
6737 win_skip( "FlashWindowEx not supported\n" );
6738 return;
6741 hwnd = CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_POPUP,
6742 0, 0, 0, 0, 0, 0, 0, NULL );
6743 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
6745 finfo.cbSize = sizeof(FLASHWINFO);
6746 finfo.dwFlags = FLASHW_TIMER;
6747 finfo.uCount = 3;
6748 finfo.dwTimeout = 200;
6749 finfo.hwnd = NULL;
6750 SetLastError(0xdeadbeef);
6751 ret = pFlashWindowEx(&finfo);
6752 todo_wine ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
6753 "FlashWindowEx returned with %d\n", GetLastError());
6755 finfo.hwnd = hwnd;
6756 SetLastError(0xdeadbeef);
6757 ret = pFlashWindowEx(NULL);
6758 todo_wine ok(!ret && GetLastError() == ERROR_NOACCESS,
6759 "FlashWindowEx returned with %d\n", GetLastError());
6761 SetLastError(0xdeadbeef);
6762 ret = pFlashWindowEx(&finfo);
6763 todo_wine ok(!ret, "previous window state should not be active\n");
6765 finfo.cbSize = sizeof(FLASHWINFO) - 1;
6766 SetLastError(0xdeadbeef);
6767 ret = pFlashWindowEx(&finfo);
6768 todo_wine ok(!ret && GetLastError()==ERROR_INVALID_PARAMETER,
6769 "FlashWindowEx succeeded\n");
6771 finfo.cbSize = sizeof(FLASHWINFO) + 1;
6772 SetLastError(0xdeadbeef);
6773 ret = pFlashWindowEx(&finfo);
6774 todo_wine ok(!ret && GetLastError()==ERROR_INVALID_PARAMETER,
6775 "FlashWindowEx succeeded\n");
6776 finfo.cbSize = sizeof(FLASHWINFO);
6778 DestroyWindow( hwnd );
6780 SetLastError(0xdeadbeef);
6781 ret = pFlashWindowEx(&finfo);
6782 todo_wine ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
6783 "FlashWindowEx returned with %d\n", GetLastError());
6785 ok(finfo.cbSize == sizeof(FLASHWINFO), "FlashWindowEx modified cdSize to %x\n", finfo.cbSize);
6786 ok(finfo.hwnd == hwnd, "FlashWindowEx modified hwnd to %p\n", finfo.hwnd);
6787 ok(finfo.dwFlags == FLASHW_TIMER, "FlashWindowEx modified dwFlags to %x\n", finfo.dwFlags);
6788 ok(finfo.uCount == 3, "FlashWindowEx modified uCount to %x\n", finfo.uCount);
6789 ok(finfo.dwTimeout == 200, "FlashWindowEx modified dwTimeout to %x\n", finfo.dwTimeout);
6791 hwnd = CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_VISIBLE | WS_POPUPWINDOW,
6792 0, 0, 0, 0, 0, 0, 0, NULL );
6793 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
6794 finfo.hwnd = hwnd;
6796 SetLastError(0xdeadbeef);
6797 ret = pFlashWindowEx(NULL);
6798 todo_wine ok(!ret && GetLastError() == ERROR_NOACCESS,
6799 "FlashWindowEx returned with %d\n", GetLastError());
6801 SetLastError(0xdeadbeef);
6802 prev = pFlashWindowEx(&finfo);
6804 ok(finfo.cbSize == sizeof(FLASHWINFO), "FlashWindowEx modified cdSize to %x\n", finfo.cbSize);
6805 ok(finfo.hwnd == hwnd, "FlashWindowEx modified hwnd to %p\n", finfo.hwnd);
6806 ok(finfo.dwFlags == FLASHW_TIMER, "FlashWindowEx modified dwFlags to %x\n", finfo.dwFlags);
6807 ok(finfo.uCount == 3, "FlashWindowEx modified uCount to %x\n", finfo.uCount);
6808 ok(finfo.dwTimeout == 200, "FlashWindowEx modified dwTimeout to %x\n", finfo.dwTimeout);
6810 finfo.dwFlags = FLASHW_STOP;
6811 SetLastError(0xdeadbeef);
6812 ret = pFlashWindowEx(&finfo);
6813 todo_wine
6814 ok(prev != ret, "previous window state should be different\n");
6816 DestroyWindow( hwnd );
6819 static void test_FindWindowEx(void)
6821 HWND hwnd, found;
6822 CHAR title[1];
6824 hwnd = CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP, 0,0,0,0, 0, 0, 0, NULL );
6825 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
6827 title[0] = 0;
6829 found = FindWindowExA( 0, 0, "MainWindowClass", title );
6830 ok( found == NULL, "expected a NULL hwnd\n" );
6831 found = FindWindowExA( 0, 0, "MainWindowClass", NULL );
6832 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
6834 DestroyWindow( hwnd );
6836 hwnd = CreateWindowExA( 0, "MainWindowClass", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL );
6837 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
6839 found = FindWindowExA( 0, 0, "MainWindowClass", title );
6840 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
6841 found = FindWindowExA( 0, 0, "MainWindowClass", NULL );
6842 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
6844 DestroyWindow( hwnd );
6846 /* test behaviour with a window title that is an empty character */
6847 found = FindWindowExA( 0, 0, "Shell_TrayWnd", title );
6848 ok( found != NULL, "found is NULL, expected a valid hwnd\n" );
6849 found = FindWindowExA( 0, 0, "Shell_TrayWnd", NULL );
6850 ok( found != NULL, "found is NULL, expected a valid hwnd\n" );
6853 static void test_GetLastActivePopup(void)
6855 HWND hwndOwner, hwndPopup1, hwndPopup2;
6857 hwndOwner = CreateWindowExA(0, "MainWindowClass", NULL,
6858 WS_VISIBLE | WS_POPUPWINDOW,
6859 100, 100, 200, 200,
6860 NULL, 0, GetModuleHandle(0), NULL);
6861 hwndPopup1 = CreateWindowExA(0, "MainWindowClass", NULL,
6862 WS_VISIBLE | WS_POPUPWINDOW,
6863 100, 100, 200, 200,
6864 hwndOwner, 0, GetModuleHandle(0), NULL);
6865 hwndPopup2 = CreateWindowExA(0, "MainWindowClass", NULL,
6866 WS_VISIBLE | WS_POPUPWINDOW,
6867 100, 100, 200, 200,
6868 hwndPopup1, 0, GetModuleHandle(0), NULL);
6869 ok( GetLastActivePopup(hwndOwner) == hwndPopup2, "wrong last active popup\n" );
6870 DestroyWindow( hwndPopup2 );
6871 DestroyWindow( hwndPopup1 );
6872 DestroyWindow( hwndOwner );
6875 static LRESULT WINAPI my_httrasparent_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
6877 if (msg == WM_NCHITTEST) return HTTRANSPARENT;
6878 return DefWindowProc(hwnd, msg, wp, lp);
6881 static LRESULT WINAPI my_window_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
6883 return DefWindowProc(hwnd, msg, wp, lp);
6886 static void create_window_tree(HWND parent, HWND *window, int size)
6888 static const DWORD style[] = { 0, WS_VISIBLE, WS_DISABLED, WS_VISIBLE | WS_DISABLED };
6889 int i, pos;
6891 memset(window, 0, size * sizeof(window[0]));
6893 pos = 0;
6894 for (i = 0; i < sizeof(style)/sizeof(style[0]); i++)
6896 assert(pos < size);
6897 window[pos] = CreateWindowEx(0, "my_window", NULL, style[i] | WS_CHILD,
6898 0, 0, 100, 100, parent, 0, 0, NULL);
6899 ok(window[pos] != 0, "CreateWindowEx failed\n");
6900 pos++;
6901 assert(pos < size);
6902 window[pos] = CreateWindowEx(WS_EX_TRANSPARENT, "my_window", NULL, style[i] | WS_CHILD,
6903 0, 0, 100, 100, parent, 0, 0, NULL);
6904 ok(window[pos] != 0, "CreateWindowEx failed\n");
6905 pos++;
6907 assert(pos < size);
6908 window[pos] = CreateWindowEx(0, "my_httrasparent", NULL, style[i] | WS_CHILD,
6909 0, 0, 100, 100, parent, 0, 0, NULL);
6910 ok(window[pos] != 0, "CreateWindowEx failed\n");
6911 pos++;
6912 assert(pos < size);
6913 window[pos] = CreateWindowEx(WS_EX_TRANSPARENT, "my_httrasparent", NULL, style[i] | WS_CHILD,
6914 0, 0, 100, 100, parent, 0, 0, NULL);
6915 ok(window[pos] != 0, "CreateWindowEx failed\n");
6916 pos++;
6918 assert(pos < size);
6919 window[pos] = CreateWindowEx(0, "my_button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
6920 0, 0, 100, 100, parent, 0, 0, NULL);
6921 ok(window[pos] != 0, "CreateWindowEx failed\n");
6922 pos++;
6923 assert(pos < size);
6924 window[pos] = CreateWindowEx(WS_EX_TRANSPARENT, "my_button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
6925 0, 0, 100, 100, parent, 0, 0, NULL);
6926 ok(window[pos] != 0, "CreateWindowEx failed\n");
6927 pos++;
6928 assert(pos < size);
6929 window[pos] = CreateWindowEx(0, "my_button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
6930 0, 0, 100, 100, parent, 0, 0, NULL);
6931 ok(window[pos] != 0, "CreateWindowEx failed\n");
6932 pos++;
6933 assert(pos < size);
6934 window[pos] = CreateWindowEx(WS_EX_TRANSPARENT, "my_button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
6935 0, 0, 100, 100, parent, 0, 0, NULL);
6936 ok(window[pos] != 0, "CreateWindowEx failed\n");
6937 pos++;
6939 assert(pos < size);
6940 window[pos] = CreateWindowEx(0, "Button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
6941 0, 0, 100, 100, parent, 0, 0, NULL);
6942 ok(window[pos] != 0, "CreateWindowEx failed\n");
6943 pos++;
6944 assert(pos < size);
6945 window[pos] = CreateWindowEx(WS_EX_TRANSPARENT, "Button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
6946 0, 0, 100, 100, parent, 0, 0, NULL);
6947 ok(window[pos] != 0, "CreateWindowEx failed\n");
6948 pos++;
6949 assert(pos < size);
6950 window[pos] = CreateWindowEx(0, "Button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
6951 0, 0, 100, 100, parent, 0, 0, NULL);
6952 ok(window[pos] != 0, "CreateWindowEx failed\n");
6953 pos++;
6954 assert(pos < size);
6955 window[pos] = CreateWindowEx(WS_EX_TRANSPARENT, "Button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
6956 0, 0, 100, 100, parent, 0, 0, NULL);
6957 ok(window[pos] != 0, "CreateWindowEx failed\n");
6958 pos++;
6960 assert(pos < size);
6961 window[pos] = CreateWindowEx(0, "Static", NULL, style[i] | WS_CHILD,
6962 0, 0, 100, 100, parent, 0, 0, NULL);
6963 ok(window[pos] != 0, "CreateWindowEx failed\n");
6964 pos++;
6965 assert(pos < size);
6966 window[pos] = CreateWindowEx(WS_EX_TRANSPARENT, "Static", NULL, style[i] | WS_CHILD,
6967 0, 0, 100, 100, parent, 0, 0, NULL);
6968 ok(window[pos] != 0, "CreateWindowEx failed\n");
6969 pos++;
6973 struct window_attributes
6975 char class_name[128];
6976 int is_visible, is_enabled, is_groupbox, is_httransparent, is_extransparent;
6979 static void get_window_attributes(HWND hwnd, struct window_attributes *attrs)
6981 DWORD style, ex_style, hittest;
6983 style = GetWindowLong(hwnd, GWL_STYLE);
6984 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
6985 attrs->class_name[0] = 0;
6986 GetClassName(hwnd, attrs->class_name, sizeof(attrs->class_name));
6987 hittest = SendMessage(hwnd, WM_NCHITTEST, 0, 0);
6989 attrs->is_visible = (style & WS_VISIBLE) != 0;
6990 attrs->is_enabled = (style & WS_DISABLED) == 0;
6991 attrs->is_groupbox = !lstrcmpi(attrs->class_name, "Button") && (style & BS_TYPEMASK) == BS_GROUPBOX;
6992 attrs->is_httransparent = hittest == HTTRANSPARENT;
6993 attrs->is_extransparent = (ex_style & WS_EX_TRANSPARENT) != 0;
6996 static int window_to_index(HWND hwnd, HWND *window, int size)
6998 int i;
7000 for (i = 0; i < size; i++)
7002 if (!window[i]) break;
7003 if (window[i] == hwnd) return i;
7005 return -1;
7008 static void test_child_window_from_point(void)
7010 static const int real_child_pos[] = { 14,15,16,17,18,19,20,21,24,25,26,27,42,43,
7011 44,45,46,47,48,49,52,53,54,55,51,50,23,22,-1 };
7012 static const int real_child_pos_nt4[] = { 14,15,16,17,20,21,24,25,26,27,42,43,44,45,
7013 48,49,52,53,54,55,51,50,47,46,23,22,19,18,-1 };
7014 WNDCLASSA cls;
7015 HWND hwnd, parent, window[100];
7016 POINT pt;
7017 int found_invisible, found_disabled, found_groupbox, found_httransparent, found_extransparent;
7018 int ret, i;
7020 ret = GetClassInfo(0, "Button", &cls);
7021 ok(ret, "GetClassInfo(Button) failed\n");
7022 cls.lpszClassName = "my_button";
7023 ret = RegisterClass(&cls);
7024 ok(ret, "RegisterClass(my_button) failed\n");
7026 cls.lpszClassName = "my_httrasparent";
7027 cls.lpfnWndProc = my_httrasparent_proc;
7028 ret = RegisterClass(&cls);
7029 ok(ret, "RegisterClass(my_httrasparent) failed\n");
7031 cls.lpszClassName = "my_window";
7032 cls.lpfnWndProc = my_window_proc;
7033 ret = RegisterClass(&cls);
7034 ok(ret, "RegisterClass(my_window) failed\n");
7036 parent = CreateWindowEx(0, "MainWindowClass", NULL,
7037 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE,
7038 100, 100, 200, 200,
7039 0, 0, GetModuleHandle(0), NULL);
7040 ok(parent != 0, "CreateWindowEx failed\n");
7041 trace("parent %p\n", parent);
7043 create_window_tree(parent, window, sizeof(window)/sizeof(window[0]));
7045 found_invisible = 0;
7046 found_disabled = 0;
7047 found_groupbox = 0;
7048 found_httransparent = 0;
7049 found_extransparent = 0;
7051 /* FIXME: also test WindowFromPoint, ChildWindowFromPoint, ChildWindowFromPointEx */
7052 for (i = 0; i < sizeof(real_child_pos)/sizeof(real_child_pos[0]); i++)
7054 struct window_attributes attrs;
7056 pt.x = pt.y = 50;
7057 hwnd = RealChildWindowFromPoint(parent, pt);
7058 ok(hwnd != 0, "RealChildWindowFromPoint failed\n");
7059 ret = window_to_index(hwnd, window, sizeof(window)/sizeof(window[0]));
7060 /* FIXME: remove once Wine is fixed */
7061 if (ret != real_child_pos[i])
7062 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);
7063 else
7064 ok(ret == real_child_pos[i] || broken(ret == real_child_pos_nt4[i]), "expected %d, got %d\n", real_child_pos[i], ret);
7066 get_window_attributes(hwnd, &attrs);
7067 if (!attrs.is_visible) found_invisible++;
7068 if (!attrs.is_enabled) found_disabled++;
7069 if (attrs.is_groupbox) found_groupbox++;
7070 if (attrs.is_httransparent) found_httransparent++;
7071 if (attrs.is_extransparent) found_extransparent++;
7073 if (ret != real_child_pos[i] && ret != -1)
7075 trace("found hwnd %p (%s), is_visible %d, is_enabled %d, is_groupbox %d, is_httransparent %d, is_extransparent %d\n",
7076 hwnd, attrs.class_name, attrs.is_visible, attrs.is_enabled, attrs.is_groupbox, attrs.is_httransparent, attrs.is_extransparent);
7077 get_window_attributes(window[real_child_pos[i]], &attrs);
7078 trace("expected hwnd %p (%s), is_visible %d, is_enabled %d, is_groupbox %d, is_httransparent %d, is_extransparent %d\n",
7079 window[real_child_pos[i]], attrs.class_name, attrs.is_visible, attrs.is_enabled, attrs.is_groupbox, attrs.is_httransparent, attrs.is_extransparent);
7081 if (ret == -1)
7083 ok(hwnd == parent, "expected %p, got %p\n", parent, hwnd);
7084 break;
7086 DestroyWindow(hwnd);
7089 DestroyWindow(parent);
7091 ok(!found_invisible, "found %d invisible windows\n", found_invisible);
7092 ok(found_disabled, "found %d disabled windows\n", found_disabled);
7093 todo_wine
7094 ok(found_groupbox == 4, "found %d groupbox windows\n", found_groupbox);
7095 ok(found_httransparent, "found %d httransparent windows\n", found_httransparent);
7096 todo_wine
7097 ok(found_extransparent, "found %d extransparent windows\n", found_extransparent);
7099 ret = UnregisterClass("my_button", cls.hInstance);
7100 ok(ret, "UnregisterClass(my_button) failed\n");
7101 ret = UnregisterClass("my_httrasparent", cls.hInstance);
7102 ok(ret, "UnregisterClass(my_httrasparent) failed\n");
7103 ret = UnregisterClass("my_window", cls.hInstance);
7104 ok(ret, "UnregisterClass(my_window) failed\n");
7107 static void test_map_points(void)
7109 BOOL ret;
7110 POINT p;
7111 HWND wnd, wnd0, dwnd;
7112 INT n;
7113 DWORD err;
7114 POINT pos = { 100, 200 };
7115 int width = 150;
7116 int height = 150;
7117 RECT window_rect;
7118 RECT client_rect;
7120 /* Create test windows */
7121 wnd = CreateWindow("static", "test1", WS_POPUP, pos.x, pos.y, width, height, NULL, NULL, NULL, NULL);
7122 ok(wnd != NULL, "Failed %p\n", wnd);
7123 wnd0 = CreateWindow("static", "test2", WS_POPUP, 0, 0, width, height, NULL, NULL, NULL, NULL);
7124 ok(wnd0 != NULL, "Failed %p\n", wnd);
7125 dwnd = CreateWindow("static", "test3", 0, 200, 300, 150, 150, NULL, NULL, NULL, NULL);
7126 DestroyWindow(dwnd);
7127 ok(dwnd != NULL, "Failed %p\n", dwnd);
7129 /* Verify window rect and client rect (they should have the same width and height) */
7130 GetWindowRect(wnd, &window_rect);
7131 ok(window_rect.left == pos.x, "left is %d instead of %d\n", window_rect.left, pos.x);
7132 ok(window_rect.top == pos.y, "top is %d instead of %d\n", window_rect.top, pos.y);
7133 ok(window_rect.right == pos.x + width, "right is %d instead of %d\n", window_rect.right, pos.x + width);
7134 ok(window_rect.bottom == pos.y + height, "bottom is %d instead of %d\n", window_rect.bottom, pos.y + height);
7135 GetClientRect(wnd, &client_rect);
7136 ok(client_rect.left == 0, "left is %d instead of 0\n", client_rect.left);
7137 ok(client_rect.top == 0, "top is %d instead of 0\n", client_rect.top);
7138 ok(client_rect.right == width, "right is %d instead of %d\n", client_rect.right, width);
7139 ok(client_rect.bottom == height, "bottom is %d instead of %d\n", client_rect.bottom, height);
7141 /* Test MapWindowPoints */
7143 /* MapWindowPoints(NULL or wnd, NULL or wnd, NULL, 1); crashes on Windows */
7145 SetLastError(0xdeadbeef);
7146 n = MapWindowPoints(NULL, NULL, NULL, 0);
7147 err = GetLastError();
7148 ok(n == 0, "Got %d, expected %d\n", n, 0);
7149 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7151 SetLastError(0xdeadbeef);
7152 n = MapWindowPoints(wnd, wnd, NULL, 0);
7153 err = GetLastError();
7154 ok(n == 0, "Got %d, expected %d\n", n, 0);
7155 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7157 n = MapWindowPoints(wnd, NULL, NULL, 0);
7158 ok(n == MAKELONG(window_rect.left, window_rect.top), "Got %x, expected %x\n",
7159 n, MAKELONG(window_rect.left, window_rect.top));
7161 n = MapWindowPoints(NULL, wnd, NULL, 0);
7162 ok(n == MAKELONG(-window_rect.left, -window_rect.top), "Got %x, expected %x\n",
7163 n, MAKELONG(-window_rect.left, -window_rect.top));
7165 SetLastError(0xdeadbeef);
7166 p.x = p.y = 100;
7167 n = MapWindowPoints(dwnd, NULL, &p, 1);
7168 err = GetLastError();
7169 ok(n == 0, "Got %d, expected %d\n", n, 0);
7170 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7171 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7173 SetLastError(0xdeadbeef);
7174 p.x = p.y = 100;
7175 n = MapWindowPoints(dwnd, wnd, &p, 1);
7176 err = GetLastError();
7177 ok(n == 0, "Got %d, expected %d\n", n, 0);
7178 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7179 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7181 SetLastError(0xdeadbeef);
7182 p.x = p.y = 100;
7183 n = MapWindowPoints(NULL, dwnd, &p, 1);
7184 err = GetLastError();
7185 ok(n == 0, "Got %d, expected %d\n", n, 0);
7186 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7187 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7189 SetLastError(0xdeadbeef);
7190 p.x = p.y = 100;
7191 n = MapWindowPoints(wnd, dwnd, &p, 1);
7192 err = GetLastError();
7193 ok(n == 0, "Got %d, expected %d\n", n, 0);
7194 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7195 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7197 SetLastError(0xdeadbeef);
7198 p.x = p.y = 100;
7199 n = MapWindowPoints(dwnd, dwnd, &p, 1);
7200 err = GetLastError();
7201 ok(n == 0, "Got %d, expected %d\n", n, 0);
7202 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7203 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7205 SetLastError(0xdeadbeef);
7206 p.x = p.y = 100;
7207 n = MapWindowPoints(NULL, NULL, &p, 1);
7208 err = GetLastError();
7209 ok(n == 0, "Got %d, expected %d\n", n, 0);
7210 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7211 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7213 SetLastError(0xdeadbeef);
7214 p.x = p.y = 100;
7215 n = MapWindowPoints(wnd, wnd, &p, 1);
7216 err = GetLastError();
7217 ok(n == 0, "Got %d, expected %d\n", n, 0);
7218 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7219 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7221 p.x = p.y = 100;
7222 n = MapWindowPoints(wnd, NULL, &p, 1);
7223 ok(n == MAKELONG(window_rect.left, window_rect.top), "Got %x, expected %x\n",
7224 n, MAKELONG(window_rect.left, window_rect.top));
7225 ok((p.x == (window_rect.left + 100)) && (p.y == (window_rect.top + 100)), "Failed got (%d, %d), expected (%d, %d)\n",
7226 p.x, p.y, window_rect.left + 100, window_rect.top + 100);
7228 p.x = p.y = 100;
7229 n = MapWindowPoints(NULL, wnd, &p, 1);
7230 ok(n == MAKELONG(-window_rect.left, -window_rect.top), "Got %x, expected %x\n",
7231 n, MAKELONG(-window_rect.left, -window_rect.top));
7232 ok((p.x == (-window_rect.left + 100)) && (p.y == (-window_rect.top + 100)), "Failed got (%d, %d), expected (%d, %d)\n",
7233 p.x, p.y, -window_rect.left + 100, -window_rect.top + 100);
7235 SetLastError(0xdeadbeef);
7236 p.x = p.y = 0;
7237 n = MapWindowPoints(wnd0, NULL, &p, 1);
7238 err = GetLastError();
7239 ok(n == 0, "Got %x, expected 0\n", n);
7240 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
7241 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7243 SetLastError(0xdeadbeef);
7244 p.x = p.y = 0;
7245 n = MapWindowPoints(NULL, wnd0, &p, 1);
7246 err = GetLastError();
7247 ok(n == 0, "Got %x, expected 0\n", n);
7248 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
7249 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7251 /* Test ClientToScreen */
7253 /* ClientToScreen(wnd, NULL); crashes on Windows */
7255 SetLastError(0xdeadbeef);
7256 ret = ClientToScreen(NULL, NULL);
7257 err = GetLastError();
7258 ok(!ret, "Should fail\n");
7259 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7261 SetLastError(0xdeadbeef);
7262 p.x = p.y = 100;
7263 ret = ClientToScreen(NULL, &p);
7264 err = GetLastError();
7265 ok(!ret, "Should fail\n");
7266 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7267 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7269 SetLastError(0xdeadbeef);
7270 p.x = p.y = 100;
7271 ret = ClientToScreen(dwnd, &p);
7272 err = GetLastError();
7273 ok(!ret, "Should fail\n");
7274 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7275 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7277 p.x = p.y = 100;
7278 ret = ClientToScreen(wnd, &p);
7279 ok(ret, "Failed with error %u\n", GetLastError());
7280 ok((p.x == (window_rect.left + 100)) && (p.y == (window_rect.top + 100)), "Failed got (%d, %d), expected (%d, %d)\n",
7281 p.x, p.y, window_rect.left + 100, window_rect.top + 100);
7283 p.x = p.y = 0;
7284 ret = ClientToScreen(wnd0, &p);
7285 ok(ret, "Failed with error %u\n", GetLastError());
7286 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
7288 /* Test ScreenToClient */
7290 /* ScreenToClient(wnd, NULL); crashes on Windows */
7292 SetLastError(0xdeadbeef);
7293 ret = ScreenToClient(NULL, NULL);
7294 err = GetLastError();
7295 ok(!ret, "Should fail\n");
7296 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7298 SetLastError(0xdeadbeef);
7299 p.x = p.y = 100;
7300 ret = ScreenToClient(NULL, &p);
7301 err = GetLastError();
7302 ok(!ret, "Should fail\n");
7303 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7304 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7306 SetLastError(0xdeadbeef);
7307 p.x = p.y = 100;
7308 ret = ScreenToClient(dwnd, &p);
7309 err = GetLastError();
7310 ok(!ret, "Should fail\n");
7311 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7312 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7314 p.x = p.y = 100;
7315 ret = ScreenToClient(wnd, &p);
7316 ok(ret, "Failed with error %u\n", GetLastError());
7317 ok((p.x == (-window_rect.left + 100)) && (p.y == (-window_rect.top + 100)), "Failed got(%d, %d), expected (%d, %d)\n",
7318 p.x, p.y, -window_rect.left + 100, -window_rect.top + 100);
7320 p.x = p.y = 0;
7321 ret = ScreenToClient(wnd0, &p);
7322 ok(ret, "Failed with error %u\n", GetLastError());
7323 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
7325 DestroyWindow(wnd);
7326 DestroyWindow(wnd0);
7329 START_TEST(win)
7331 HMODULE user32 = GetModuleHandleA( "user32.dll" );
7332 HMODULE gdi32 = GetModuleHandleA("gdi32.dll");
7333 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
7334 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
7335 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
7336 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
7337 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
7338 pUpdateLayeredWindow = (void *)GetProcAddress( user32, "UpdateLayeredWindow" );
7339 pUpdateLayeredWindowIndirect = (void *)GetProcAddress( user32, "UpdateLayeredWindowIndirect" );
7340 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
7341 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
7342 pGetWindowRgnBox = (void *)GetProcAddress( user32, "GetWindowRgnBox" );
7343 pGetGUIThreadInfo = (void *)GetProcAddress( user32, "GetGUIThreadInfo" );
7344 pGetProcessDefaultLayout = (void *)GetProcAddress( user32, "GetProcessDefaultLayout" );
7345 pSetProcessDefaultLayout = (void *)GetProcAddress( user32, "SetProcessDefaultLayout" );
7346 pFlashWindowEx = (void *)GetProcAddress( user32, "FlashWindowEx" );
7347 pGetLayout = (void *)GetProcAddress( gdi32, "GetLayout" );
7348 pSetLayout = (void *)GetProcAddress( gdi32, "SetLayout" );
7349 pMirrorRgn = (void *)GetProcAddress( gdi32, "MirrorRgn" );
7351 if (!RegisterWindowClasses()) assert(0);
7353 SetLastError(0xdeafbeef);
7354 GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC);
7355 is_win9x = (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED);
7357 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
7358 if (!hhook) win_skip( "Cannot set CBT hook, skipping some tests\n" );
7360 /* make sure that these tests are executed first */
7361 test_FindWindowEx();
7362 test_SetParent();
7364 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
7365 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
7366 WS_MAXIMIZEBOX | WS_POPUP,
7367 100, 100, 200, 200,
7368 0, 0, GetModuleHandle(0), NULL);
7369 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
7370 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
7371 WS_MAXIMIZEBOX | WS_POPUP,
7372 100, 100, 200, 200,
7373 0, 0, GetModuleHandle(0), NULL);
7374 assert( hwndMain );
7375 assert( hwndMain2 );
7377 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
7379 /* Add the tests below this line */
7380 test_child_window_from_point();
7381 test_thick_child_size(hwndMain);
7382 test_fullscreen();
7383 test_hwnd_message();
7384 test_nonclient_area(hwndMain);
7385 test_params();
7386 test_GetWindowModuleFileName();
7387 test_capture_1();
7388 test_capture_2();
7389 test_capture_3(hwndMain, hwndMain2);
7390 test_capture_4();
7391 test_rtl_layout();
7392 test_FlashWindowEx();
7394 test_CreateWindow();
7395 test_parent_owner();
7396 test_enum_thread_windows();
7398 test_mdi();
7399 test_icons();
7400 test_SetWindowPos(hwndMain, hwndMain2);
7401 test_SetMenu(hwndMain);
7402 test_SetFocus(hwndMain);
7403 test_SetActiveWindow(hwndMain);
7404 test_NCRedraw();
7406 test_children_zorder(hwndMain);
7407 test_popup_zorder(hwndMain2, hwndMain, WS_POPUP);
7408 test_popup_zorder(hwndMain2, hwndMain, 0);
7409 test_GetLastActivePopup();
7410 test_keyboard_input(hwndMain);
7411 test_mouse_input(hwndMain);
7412 test_validatergn(hwndMain);
7413 test_nccalcscroll( hwndMain);
7414 test_scrollwindow( hwndMain);
7415 test_scrollvalidate( hwndMain);
7416 test_scrolldc( hwndMain);
7417 test_scroll();
7418 test_IsWindowUnicode();
7419 test_vis_rgn(hwndMain);
7421 test_AdjustWindowRect();
7422 test_window_styles();
7423 test_dialog_styles();
7424 test_redrawnow();
7425 test_csparentdc();
7426 test_SetWindowLong();
7427 test_ShowWindow();
7428 if (0) test_gettext(); /* crashes on NT4 */
7429 test_GetUpdateRect();
7430 test_Expose();
7431 test_layered_window();
7433 test_SetForegroundWindow(hwndMain);
7434 test_shell_window();
7435 test_handles( hwndMain );
7436 test_winregion();
7437 test_map_points();
7439 /* add the tests above this line */
7440 if (hhook) UnhookWindowsHookEx(hhook);
7442 DestroyWindow(hwndMain2);
7443 DestroyWindow(hwndMain);