d3d11/tests: Port test_create_rasterizer_state() from d3d10core.
[wine/multimedia.git] / dlls / user32 / tests / win.c
blob10aa545a794df662106d63f2aaa444eae95dca12
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 DWORD num_gettext_msgs;
67 static DWORD num_settext_msgs;
68 static HWND hwndMessage;
69 static HWND hwndMain, hwndMain2;
70 static HHOOK hhook;
72 static const char* szAWRClass = "Winsize";
73 static HMENU hmenu;
74 static DWORD our_pid;
76 static BOOL is_win9x = FALSE;
78 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
80 static void dump_minmax_info( const MINMAXINFO *minmax )
82 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
83 minmax->ptReserved.x, minmax->ptReserved.y,
84 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
85 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
86 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
87 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
90 /* try to make sure pending X events have been processed before continuing */
91 static void flush_events( BOOL remove_messages )
93 MSG msg;
94 int diff = 200;
95 int min_timeout = 100;
96 DWORD time = GetTickCount() + diff;
98 while (diff > 0)
100 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
101 if (remove_messages)
102 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
103 diff = time - GetTickCount();
104 min_timeout = 50;
108 static BOOL wait_for_event(HANDLE event, int timeout)
110 DWORD end_time = GetTickCount() + timeout;
111 MSG msg;
113 do {
114 if(MsgWaitForMultipleObjects(1, &event, FALSE, timeout, QS_ALLINPUT) == WAIT_OBJECT_0)
115 return TRUE;
116 while(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
117 DispatchMessageA(&msg);
118 timeout = end_time - GetTickCount();
119 }while(timeout > 0);
121 return FALSE;
124 /* check the values returned by the various parent/owner functions on a given window */
125 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
126 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
128 HWND res;
130 if (pGetAncestor)
132 res = pGetAncestor( hwnd, GA_PARENT );
133 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
135 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
136 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
137 res = GetParent( hwnd );
138 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
139 res = GetWindow( hwnd, GW_OWNER );
140 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
141 if (pGetAncestor)
143 res = pGetAncestor( hwnd, GA_ROOT );
144 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
145 res = pGetAncestor( hwnd, GA_ROOTOWNER );
146 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
150 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
151 static void check_wnd_state_(const char *file, int line,
152 HWND active, HWND foreground, HWND focus, HWND capture)
154 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
155 /* only check foreground if it belongs to the current thread */
156 /* foreground can be moved to a different app pretty much at any time */
157 if (foreground && GetForegroundWindow() &&
158 GetWindowThreadProcessId(GetForegroundWindow(), NULL) == GetCurrentThreadId())
159 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
160 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
161 ok_(file, line)(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
164 /* same as above but without capture test */
165 #define check_active_state(a,b,c) check_active_state_(__FILE__,__LINE__,a,b,c)
166 static void check_active_state_(const char *file, int line,
167 HWND active, HWND foreground, HWND focus)
169 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
170 /* only check foreground if it belongs to the current thread */
171 /* foreground can be moved to a different app pretty much at any time */
172 if (foreground && GetForegroundWindow() &&
173 GetWindowThreadProcessId(GetForegroundWindow(), NULL) == GetCurrentThreadId())
174 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
175 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
178 static BOOL ignore_message( UINT message )
180 /* these are always ignored */
181 return (message >= 0xc000 ||
182 message == WM_GETICON ||
183 message == WM_GETOBJECT ||
184 message == WM_TIMECHANGE ||
185 message == WM_DEVICECHANGE);
188 static BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
190 (*(LPINT)lParam)++;
191 trace("EnumChildProc on %p\n", hwndChild);
192 if (*(LPINT)lParam > 1) return FALSE;
193 return TRUE;
196 /* will search for the given window */
197 static BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
199 trace("EnumChildProc1 on %p\n", hwndChild);
200 if ((HWND)lParam == hwndChild) return FALSE;
201 return TRUE;
204 static HWND create_tool_window( LONG style, HWND parent )
206 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
207 0, 0, 100, 100, parent, 0, 0, NULL );
208 ok( ret != 0, "Creation failed\n" );
209 return ret;
212 /* test parent and owner values for various combinations */
213 static void test_parent_owner(void)
215 LONG style;
216 HWND test, owner, ret;
217 HWND desktop = GetDesktopWindow();
218 HWND child = create_tool_window( WS_CHILD, hwndMain );
219 INT numChildren;
221 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
223 /* child without parent, should fail */
224 SetLastError(0xdeadbeef);
225 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
226 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
227 ok( !test, "WS_CHILD without parent created\n" );
228 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD ||
229 broken(GetLastError() == 0xdeadbeef), /* win9x */
230 "CreateWindowExA error %u\n", GetLastError() );
232 /* desktop window */
233 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
234 style = GetWindowLongA( desktop, GWL_STYLE );
235 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
236 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
237 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
239 /* normal child window */
240 test = create_tool_window( WS_CHILD, hwndMain );
241 trace( "created child %p\n", test );
242 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
243 SetWindowLongA( test, GWL_STYLE, 0 );
244 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
245 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
246 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
247 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
248 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
249 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
250 DestroyWindow( test );
252 /* normal child window with WS_MAXIMIZE */
253 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
254 DestroyWindow( test );
256 /* normal child window with WS_THICKFRAME */
257 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
258 DestroyWindow( test );
260 /* popup window with WS_THICKFRAME */
261 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
262 DestroyWindow( test );
264 /* child of desktop */
265 test = create_tool_window( WS_CHILD, desktop );
266 trace( "created child of desktop %p\n", test );
267 check_parents( test, desktop, 0, desktop, 0, test, desktop );
268 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
269 check_parents( test, desktop, 0, 0, 0, test, test );
270 SetWindowLongA( test, GWL_STYLE, 0 );
271 check_parents( test, desktop, 0, 0, 0, test, test );
272 DestroyWindow( test );
274 /* child of desktop with WS_MAXIMIZE */
275 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
276 DestroyWindow( test );
278 /* child of desktop with WS_MINIMIZE */
279 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
280 DestroyWindow( test );
282 /* child of child */
283 test = create_tool_window( WS_CHILD, child );
284 trace( "created child of child %p\n", test );
285 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
286 SetWindowLongA( test, GWL_STYLE, 0 );
287 check_parents( test, child, child, 0, 0, hwndMain, test );
288 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
289 check_parents( test, child, child, 0, 0, hwndMain, test );
290 DestroyWindow( test );
292 /* child of child with WS_MAXIMIZE */
293 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
294 DestroyWindow( test );
296 /* child of child with WS_MINIMIZE */
297 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
298 DestroyWindow( test );
300 /* not owned top-level window */
301 test = create_tool_window( 0, 0 );
302 trace( "created top-level %p\n", test );
303 check_parents( test, desktop, 0, 0, 0, test, test );
304 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
305 check_parents( test, desktop, 0, 0, 0, test, test );
306 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
307 check_parents( test, desktop, 0, desktop, 0, test, desktop );
308 DestroyWindow( test );
310 /* not owned top-level window with WS_MAXIMIZE */
311 test = create_tool_window( WS_MAXIMIZE, 0 );
312 DestroyWindow( test );
314 /* owned top-level window */
315 test = create_tool_window( 0, hwndMain );
316 trace( "created owned top-level %p\n", test );
317 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
318 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
319 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
320 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
321 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
322 DestroyWindow( test );
324 /* owned top-level window with WS_MAXIMIZE */
325 test = create_tool_window( WS_MAXIMIZE, hwndMain );
326 DestroyWindow( test );
328 /* not owned popup */
329 test = create_tool_window( WS_POPUP, 0 );
330 trace( "created popup %p\n", test );
331 check_parents( test, desktop, 0, 0, 0, test, test );
332 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
333 check_parents( test, desktop, 0, desktop, 0, test, desktop );
334 SetWindowLongA( test, GWL_STYLE, 0 );
335 check_parents( test, desktop, 0, 0, 0, test, test );
336 DestroyWindow( test );
338 /* not owned popup with WS_MAXIMIZE */
339 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
340 DestroyWindow( test );
342 /* owned popup */
343 test = create_tool_window( WS_POPUP, hwndMain );
344 trace( "created owned popup %p\n", test );
345 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
346 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
347 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
348 SetWindowLongA( test, GWL_STYLE, 0 );
349 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
350 DestroyWindow( test );
352 /* owned popup with WS_MAXIMIZE */
353 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
354 DestroyWindow( test );
356 /* top-level window owned by child (same as owned by top-level) */
357 test = create_tool_window( 0, child );
358 trace( "created top-level owned by child %p\n", test );
359 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
360 DestroyWindow( test );
362 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
363 test = create_tool_window( WS_MAXIMIZE, child );
364 DestroyWindow( test );
366 /* popup owned by desktop (same as not owned) */
367 test = create_tool_window( WS_POPUP, desktop );
368 trace( "created popup owned by desktop %p\n", test );
369 check_parents( test, desktop, 0, 0, 0, test, test );
370 DestroyWindow( test );
372 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
373 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
374 DestroyWindow( test );
376 /* popup owned by child (same as owned by top-level) */
377 test = create_tool_window( WS_POPUP, child );
378 trace( "created popup owned by child %p\n", test );
379 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
380 DestroyWindow( test );
382 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
383 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
384 DestroyWindow( test );
386 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
387 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
388 trace( "created WS_CHILD popup %p\n", test );
389 check_parents( test, desktop, 0, 0, 0, test, test );
390 DestroyWindow( test );
392 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
393 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
394 DestroyWindow( test );
396 /* owned popup with WS_CHILD (same as WS_POPUP only) */
397 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
398 trace( "created owned WS_CHILD popup %p\n", test );
399 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
400 DestroyWindow( test );
402 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
403 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
404 DestroyWindow( test );
406 /******************** parent changes *************************/
407 trace( "testing parent changes\n" );
409 /* desktop window */
410 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
411 if (0)
413 /* this test succeeds on NT but crashes on win9x systems */
414 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
415 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
416 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
417 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
418 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
420 /* normal child window */
421 test = create_tool_window( WS_CHILD, hwndMain );
422 trace( "created child %p\n", test );
424 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
425 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
426 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
428 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
429 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
430 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
432 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
433 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
434 check_parents( test, desktop, 0, desktop, 0, test, desktop );
436 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
437 if (!is_win9x)
439 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)test );
440 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
441 check_parents( test, desktop, 0, desktop, 0, test, desktop );
443 else
444 win_skip("Test creates circular window tree under Win9x/WinMe\n" );
446 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
447 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
448 check_parents( test, desktop, child, desktop, child, test, desktop );
450 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
451 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
452 check_parents( test, desktop, 0, desktop, 0, test, desktop );
453 DestroyWindow( test );
455 /* not owned top-level window */
456 test = create_tool_window( 0, 0 );
457 trace( "created top-level %p\n", test );
459 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
460 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
461 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
463 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
464 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
465 check_parents( test, desktop, child, 0, child, test, test );
467 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
468 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
469 check_parents( test, desktop, 0, 0, 0, test, test );
470 DestroyWindow( test );
472 /* not owned popup */
473 test = create_tool_window( WS_POPUP, 0 );
474 trace( "created popup %p\n", test );
476 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
477 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
478 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
480 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
481 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
482 check_parents( test, desktop, child, child, child, test, hwndMain );
484 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
485 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
486 check_parents( test, desktop, 0, 0, 0, test, test );
487 DestroyWindow( test );
489 /* normal child window */
490 test = create_tool_window( WS_CHILD, hwndMain );
491 trace( "created child %p\n", test );
493 ret = SetParent( test, desktop );
494 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
495 check_parents( test, desktop, 0, desktop, 0, test, desktop );
497 ret = SetParent( test, child );
498 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
499 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
501 ret = SetParent( test, hwndMain2 );
502 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
503 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
504 DestroyWindow( test );
506 /* not owned top-level window */
507 test = create_tool_window( 0, 0 );
508 trace( "created top-level %p\n", test );
510 ret = SetParent( test, child );
511 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
512 check_parents( test, child, child, 0, 0, hwndMain, test );
514 if (!is_win9x)
516 ShowWindow( test, SW_SHOW );
517 ret = SetParent( test, test );
518 ok( ret == NULL, "SetParent return value %p expected %p\n", ret, NULL );
519 ok( GetWindowLongA( test, GWL_STYLE ) & WS_VISIBLE, "window is not visible after SetParent\n" );
520 check_parents( test, child, child, 0, 0, hwndMain, test );
522 else
523 win_skip( "Test crashes on Win9x/WinMe\n" );
524 DestroyWindow( test );
526 /* owned popup */
527 test = create_tool_window( WS_POPUP, hwndMain2 );
528 trace( "created owned popup %p\n", test );
530 ret = SetParent( test, child );
531 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
532 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
534 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
535 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
536 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
537 DestroyWindow( test );
539 /**************** test owner destruction *******************/
541 /* owned child popup */
542 owner = create_tool_window( 0, 0 );
543 test = create_tool_window( WS_POPUP, owner );
544 trace( "created owner %p and popup %p\n", owner, test );
545 ret = SetParent( test, child );
546 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
547 check_parents( test, child, child, owner, owner, hwndMain, owner );
548 /* window is now child of 'child' but owned by 'owner' */
549 DestroyWindow( owner );
550 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
551 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
552 * while Win95, Win2k, WinXP do.
554 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
555 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
556 DestroyWindow(test);
558 /* owned top-level popup */
559 owner = create_tool_window( 0, 0 );
560 test = create_tool_window( WS_POPUP, owner );
561 trace( "created owner %p and popup %p\n", owner, test );
562 check_parents( test, desktop, owner, owner, owner, test, owner );
563 DestroyWindow( owner );
564 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
566 /* top-level popup owned by child */
567 owner = create_tool_window( WS_CHILD, hwndMain2 );
568 test = create_tool_window( WS_POPUP, 0 );
569 trace( "created owner %p and popup %p\n", owner, test );
570 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
571 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
572 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
573 DestroyWindow( owner );
574 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
575 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
576 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
577 * while Win95, Win2k, WinXP do.
579 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
580 DestroyWindow(test);
582 /* final cleanup */
583 DestroyWindow(child);
586 owner = create_tool_window( WS_OVERLAPPED, 0 );
587 test = create_tool_window( WS_POPUP, desktop );
589 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
590 numChildren = 0;
591 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
592 "EnumChildWindows should have returned FALSE\n" );
593 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
595 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
596 ret = SetParent( test, owner );
597 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
599 numChildren = 0;
600 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
601 "EnumChildWindows should have returned TRUE\n" );
602 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
604 child = create_tool_window( WS_CHILD, owner );
605 numChildren = 0;
606 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
607 "EnumChildWindows should have returned FALSE\n" );
608 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
609 DestroyWindow( child );
611 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
612 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
613 numChildren = 0;
614 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
615 "EnumChildWindows should have returned TRUE\n" );
616 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
618 ret = SetParent( child, owner );
619 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
620 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
621 numChildren = 0;
622 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
623 "EnumChildWindows should have returned FALSE\n" );
624 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
626 ret = SetParent( child, NULL );
627 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
628 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
629 numChildren = 0;
630 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
631 "EnumChildWindows should have returned TRUE\n" );
632 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
634 /* even GW_OWNER == owner it's still a desktop's child */
635 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
636 "EnumChildWindows should have found %p and returned FALSE\n", child );
638 DestroyWindow( child );
639 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
641 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
642 "EnumChildWindows should have found %p and returned FALSE\n", child );
644 DestroyWindow( child );
645 DestroyWindow( test );
646 DestroyWindow( owner );
649 static BOOL CALLBACK enum_proc( HWND hwnd, LPARAM lParam)
651 (*(LPINT)lParam)++;
652 if (*(LPINT)lParam > 2) return FALSE;
653 return TRUE;
655 static DWORD CALLBACK enum_thread( void *arg )
657 INT count;
658 HWND hwnd[3];
659 BOOL ret;
660 MSG msg;
662 if (pGetGUIThreadInfo)
664 GUITHREADINFO info;
665 info.cbSize = sizeof(info);
666 ret = pGetGUIThreadInfo( GetCurrentThreadId(), &info );
667 ok( ret || broken(!ret), /* win9x */
668 "GetGUIThreadInfo failed without message queue\n" );
669 SetLastError( 0xdeadbeef );
670 info.cbSize = sizeof(info) + 1;
671 ret = pGetGUIThreadInfo( GetCurrentThreadId(), &info );
672 ok( !ret, "GetGUIThreadInfo succeeded with wrong size\n" );
673 ok( GetLastError() == ERROR_INVALID_PARAMETER ||
674 broken(GetLastError() == 0xdeadbeef), /* win9x */
675 "wrong error %u\n", GetLastError() );
678 PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ); /* make sure we have a message queue */
680 count = 0;
681 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
682 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
683 ok( count == 0, "count should be 0 got %d\n", count );
685 hwnd[0] = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", WS_POPUP,
686 0, 0, 100, 100, 0, 0, 0, NULL );
687 count = 0;
688 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
689 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
690 if (count != 2) /* Vista gives us two windows for the price of one */
692 ok( count == 1, "count should be 1 got %d\n", count );
693 hwnd[2] = CreateWindowExA(0, "ToolWindowClass", "Tool window 2", WS_POPUP,
694 0, 0, 100, 100, 0, 0, 0, NULL );
696 else hwnd[2] = 0;
698 hwnd[1] = CreateWindowExA(0, "ToolWindowClass", "Tool window 3", WS_POPUP,
699 0, 0, 100, 100, 0, 0, 0, NULL );
700 count = 0;
701 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
702 ok( !ret, "EnumThreadWindows should have returned FALSE\n" );
703 ok( count == 3, "count should be 3 got %d\n", count );
705 if (hwnd[2]) DestroyWindow(hwnd[2]);
706 DestroyWindow(hwnd[1]);
707 DestroyWindow(hwnd[0]);
708 return 0;
711 /* test EnumThreadWindows in a separate thread */
712 static void test_enum_thread_windows(void)
714 DWORD id;
715 HANDLE handle = CreateThread( NULL, 0, enum_thread, 0, 0, &id );
716 ok( !WaitForSingleObject( handle, 10000 ), "wait failed\n" );
717 CloseHandle( handle );
720 static struct wm_gettext_override_data
722 BOOL enabled; /* when 1 bypasses default procedure */
723 char *buff; /* expected text buffer pointer */
724 WCHAR *buffW; /* same, for W test */
725 } g_wm_gettext_override;
727 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
729 switch (msg)
731 case WM_GETMINMAXINFO:
733 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
734 break;
736 case WM_WINDOWPOSCHANGING:
738 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
739 if (!(winpos->flags & SWP_NOMOVE))
741 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
742 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
744 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
745 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
747 ok((winpos->cx >= 0 && winpos->cx <= 32767) ||
748 winpos->cx == 32768, /* win7 doesn't truncate */
749 "bad winpos->cx %d\n", winpos->cx);
750 ok((winpos->cy >= 0 && winpos->cy <= 32767) ||
751 winpos->cy == 40000, /* win7 doesn't truncate */
752 "bad winpos->cy %d\n", winpos->cy);
754 break;
756 case WM_WINDOWPOSCHANGED:
758 RECT rc1, rc2;
759 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
760 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
761 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
763 ok((winpos->cx >= 0 && winpos->cx <= 32767) ||
764 winpos->cx == 32768, /* win7 doesn't truncate */
765 "bad winpos->cx %d\n", winpos->cx);
766 ok((winpos->cy >= 0 && winpos->cy <= 32767) ||
767 winpos->cy == 40000, /* win7 doesn't truncate */
768 "bad winpos->cy %d\n", winpos->cy);
770 GetWindowRect(hwnd, &rc1);
771 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
772 /* note: winpos coordinates are relative to parent */
773 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
774 if (0)
776 /* Uncomment this once the test succeeds in all cases */
777 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
778 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
780 GetClientRect(hwnd, &rc2);
781 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
782 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
783 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
784 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
786 break;
788 case WM_NCCREATE:
790 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
791 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
793 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
794 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
795 else
796 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
797 break;
799 case WM_COMMAND:
800 if (test_lbuttondown_flag)
802 ShowWindow((HWND)wparam, SW_SHOW);
803 flush_events( FALSE );
805 break;
806 case WM_GETTEXT:
807 num_gettext_msgs++;
808 if (g_wm_gettext_override.enabled)
810 char *text = (char*)lparam;
811 ok(g_wm_gettext_override.buff == text, "expected buffer %p, got %p\n", g_wm_gettext_override.buff, text);
812 ok(*text == 0, "expected empty string buffer %x\n", *text);
813 return 0;
815 break;
816 case WM_SETTEXT:
817 num_settext_msgs++;
818 break;
821 return DefWindowProcA(hwnd, msg, wparam, lparam);
824 static LRESULT WINAPI main_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
826 switch (msg)
828 case WM_GETTEXT:
829 num_gettext_msgs++;
830 if (g_wm_gettext_override.enabled)
832 WCHAR *text = (WCHAR*)lparam;
833 ok(g_wm_gettext_override.buffW == text, "expected buffer %p, got %p\n", g_wm_gettext_override.buffW, text);
834 ok(*text == 0, "expected empty string buffer %x\n", *text);
835 return 0;
837 break;
840 return DefWindowProcA(hwnd, msg, wparam, lparam);
843 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
845 switch (msg)
847 case WM_GETMINMAXINFO:
849 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
850 break;
852 case WM_NCCREATE:
854 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
855 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
857 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
858 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
859 else
860 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
861 break;
865 return DefWindowProcA(hwnd, msg, wparam, lparam);
868 static const WCHAR mainclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s','W',0};
870 static BOOL RegisterWindowClasses(void)
872 WNDCLASSW clsW;
873 WNDCLASSA cls;
875 cls.style = CS_DBLCLKS;
876 cls.lpfnWndProc = main_window_procA;
877 cls.cbClsExtra = 0;
878 cls.cbWndExtra = 0;
879 cls.hInstance = GetModuleHandleA(0);
880 cls.hIcon = 0;
881 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
882 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
883 cls.lpszMenuName = NULL;
884 cls.lpszClassName = "MainWindowClass";
886 if(!RegisterClassA(&cls)) return FALSE;
888 clsW.style = CS_DBLCLKS;
889 clsW.lpfnWndProc = main_window_procW;
890 clsW.cbClsExtra = 0;
891 clsW.cbWndExtra = 0;
892 clsW.hInstance = GetModuleHandleA(0);
893 clsW.hIcon = 0;
894 clsW.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
895 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
896 clsW.lpszMenuName = NULL;
897 clsW.lpszClassName = mainclassW;
899 if(!RegisterClassW(&clsW)) return FALSE;
901 cls.style = 0;
902 cls.lpfnWndProc = tool_window_procA;
903 cls.cbClsExtra = 0;
904 cls.cbWndExtra = 0;
905 cls.hInstance = GetModuleHandleA(0);
906 cls.hIcon = 0;
907 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
908 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
909 cls.lpszMenuName = NULL;
910 cls.lpszClassName = "ToolWindowClass";
912 if(!RegisterClassA(&cls)) return FALSE;
914 return TRUE;
917 static void verify_window_info(const char *hook, HWND hwnd, const WINDOWINFO *info)
919 RECT rcWindow, rcClient;
920 DWORD status;
922 ok(IsWindow(hwnd), "bad window handle %p in hook %s\n", hwnd, hook);
924 GetWindowRect(hwnd, &rcWindow);
925 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow for %p in hook %s\n", hwnd, hook);
927 GetClientRect(hwnd, &rcClient);
928 /* translate to screen coordinates */
929 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
930 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient for %p in hook %s\n", hwnd, hook);
932 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
933 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
934 info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE), hwnd, hook);
935 /* Windows reports some undocumented exstyles in WINDOWINFO, but
936 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
938 ok((info->dwExStyle & ~0xe0000800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
939 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
940 info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE), hwnd, hook);
941 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
942 if (GetForegroundWindow())
943 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
944 info->dwWindowStatus, status, GetActiveWindow(), GetForegroundWindow(), hook);
946 /* win2k and XP return broken border info in GetWindowInfo most of
947 * the time, so there is no point in testing it.
949 if (0)
951 UINT border;
952 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
953 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
954 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
955 ok(info->cyWindowBorders == border,
956 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
958 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType for %p in hook %s\n",
959 hwnd, hook);
960 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
961 info->wCreatorVersion == 0x0500 /* Vista */,
962 "wrong wCreatorVersion %04x for %p in hook %s\n", info->wCreatorVersion, hwnd, hook);
965 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
967 AdjustWindowRectEx(rc, style, menu, exstyle);
968 /* AdjustWindowRectEx does not include scroll bars */
969 if (style & WS_VSCROLL)
971 if(exstyle & WS_EX_LEFTSCROLLBAR)
972 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
973 else
974 rc->right += GetSystemMetrics(SM_CXVSCROLL);
976 if (style & WS_HSCROLL)
977 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
980 static void test_nonclient_area(HWND hwnd)
982 DWORD style, exstyle;
983 RECT rc_window, rc_client, rc;
984 BOOL menu;
985 LRESULT ret;
987 style = GetWindowLongA(hwnd, GWL_STYLE);
988 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
989 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
991 GetWindowRect(hwnd, &rc_window);
992 GetClientRect(hwnd, &rc_client);
994 /* avoid some cases when things go wrong */
995 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
996 rc_window.right > 32768 || rc_window.bottom > 32768) return;
998 CopyRect(&rc, &rc_client);
999 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
1000 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
1002 ok(EqualRect(&rc, &rc_window),
1003 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
1004 style, exstyle, menu, rc_window.left, rc_window.top, rc_window.right, rc_window.bottom,
1005 rc.left, rc.top, rc.right, rc.bottom);
1008 CopyRect(&rc, &rc_window);
1009 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
1010 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
1011 ok(EqualRect(&rc, &rc_client),
1012 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
1013 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
1014 rc.left, rc.top, rc.right, rc.bottom);
1016 /* NULL rectangle shouldn't crash */
1017 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
1018 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
1020 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
1021 if (is_win9x)
1022 return;
1024 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
1025 SetRect(&rc_client, 0, 0, 250, 150);
1026 CopyRect(&rc_window, &rc_client);
1027 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
1028 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
1030 CopyRect(&rc, &rc_window);
1031 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
1032 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
1033 ok(EqualRect(&rc, &rc_client),
1034 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
1035 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
1036 rc.left, rc.top, rc.right, rc.bottom);
1039 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
1041 static const char *CBT_code_name[10] = {
1042 "HCBT_MOVESIZE",
1043 "HCBT_MINMAX",
1044 "HCBT_QS",
1045 "HCBT_CREATEWND",
1046 "HCBT_DESTROYWND",
1047 "HCBT_ACTIVATE",
1048 "HCBT_CLICKSKIPPED",
1049 "HCBT_KEYSKIPPED",
1050 "HCBT_SYSCOMMAND",
1051 "HCBT_SETFOCUS" };
1052 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
1053 HWND hwnd = (HWND)wParam;
1055 switch (nCode)
1057 case HCBT_CREATEWND:
1059 static const RECT rc_null;
1060 RECT rc;
1061 LONG style;
1062 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
1063 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
1065 if (pGetWindowInfo)
1067 WINDOWINFO info;
1068 info.cbSize = sizeof(WINDOWINFO);
1069 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
1070 verify_window_info(code_name, hwnd, &info);
1073 /* WS_VISIBLE should be turned off yet */
1074 style = createwnd->lpcs->style & ~WS_VISIBLE;
1075 ok(style == GetWindowLongA(hwnd, GWL_STYLE),
1076 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
1077 GetWindowLongA(hwnd, GWL_STYLE), style);
1079 if (0)
1081 /* Uncomment this once the test succeeds in all cases */
1082 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
1084 ok(GetParent(hwnd) == hwndMessage,
1085 "wrong result from GetParent %p: message window %p\n",
1086 GetParent(hwnd), hwndMessage);
1088 else
1089 ok(!GetParent(hwnd), "GetParent should return 0 at this point\n");
1091 ok(!GetWindow(hwnd, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
1093 if (0)
1095 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
1096 * Win9x still has them set to 0.
1098 ok(GetWindow(hwnd, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
1099 ok(GetWindow(hwnd, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
1101 ok(!GetWindow(hwnd, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
1102 ok(!GetWindow(hwnd, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
1104 if (0)
1106 /* Uncomment this once the test succeeds in all cases */
1107 if (pGetAncestor)
1109 ok(pGetAncestor(hwnd, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
1110 ok(pGetAncestor(hwnd, GA_ROOT) == hwnd,
1111 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOT), hwnd);
1113 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
1114 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwndMessage,
1115 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
1116 else
1117 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwnd,
1118 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOTOWNER), hwnd);
1121 ok(GetWindowRect(hwnd, &rc), "GetWindowRect failed\n");
1122 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
1123 ok(GetClientRect(hwnd, &rc), "GetClientRect failed\n");
1124 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
1126 break;
1128 case HCBT_MOVESIZE:
1129 case HCBT_MINMAX:
1130 case HCBT_ACTIVATE:
1131 if (pGetWindowInfo && IsWindow(hwnd))
1133 WINDOWINFO info;
1135 /* Win98 actually does check the info.cbSize and doesn't allow
1136 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
1137 * WinXP do not check it at all.
1139 info.cbSize = sizeof(WINDOWINFO);
1140 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
1141 verify_window_info(code_name, hwnd, &info);
1143 break;
1144 /* window state is undefined */
1145 case HCBT_SETFOCUS:
1146 case HCBT_DESTROYWND:
1147 break;
1148 default:
1149 break;
1152 return CallNextHookEx(hhook, nCode, wParam, lParam);
1155 static void test_shell_window(void)
1157 BOOL ret;
1158 DWORD error;
1159 HMODULE hinst, hUser32;
1160 BOOL (WINAPI*SetShellWindow)(HWND);
1161 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
1162 HWND shellWindow, nextWnd;
1164 if (is_win9x)
1166 win_skip("Skipping shell window test on Win9x\n");
1167 return;
1170 shellWindow = GetShellWindow();
1171 hinst = GetModuleHandleA(NULL);
1172 hUser32 = GetModuleHandleA("user32");
1174 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
1176 trace("previous shell window: %p\n", shellWindow);
1178 if (shellWindow) {
1179 DWORD pid;
1180 HANDLE hProcess;
1182 GetWindowThreadProcessId(shellWindow, &pid);
1183 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
1184 if (!hProcess)
1186 skip( "cannot get access to shell process\n" );
1187 return;
1190 SetLastError(0xdeadbeef);
1191 ret = DestroyWindow(shellWindow);
1192 error = GetLastError();
1194 ok(!ret, "DestroyWindow(shellWindow)\n");
1195 /* passes on Win XP, but not on Win98 */
1196 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
1197 "got %u after DestroyWindow(shellWindow)\n", error);
1199 /* close old shell instance */
1200 ret = TerminateProcess(hProcess, 0);
1201 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1202 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
1203 CloseHandle(hProcess);
1206 hwnd1 = CreateWindowExA(0, "#32770", "TEST1", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
1207 trace("created window 1: %p\n", hwnd1);
1209 ret = SetShellWindow(hwnd1);
1210 ok(ret, "first call to SetShellWindow(hwnd1)\n");
1211 shellWindow = GetShellWindow();
1212 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
1214 ret = SetShellWindow(hwnd1);
1215 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1217 ret = SetShellWindow(0);
1218 error = GetLastError();
1219 /* passes on Win XP, but not on Win98
1220 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1221 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1223 ret = SetShellWindow(hwnd1);
1224 /* passes on Win XP, but not on Win98
1225 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1227 SetWindowLongA(hwnd1, GWL_EXSTYLE, GetWindowLongA(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1228 ret = (GetWindowLongA(hwnd1,GWL_EXSTYLE) & WS_EX_TOPMOST) != 0;
1229 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1231 ret = DestroyWindow(hwnd1);
1232 ok(ret, "DestroyWindow(hwnd1)\n");
1234 hwnd2 = CreateWindowExA(WS_EX_TOPMOST, "#32770", "TEST2", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1235 trace("created window 2: %p\n", hwnd2);
1236 ret = SetShellWindow(hwnd2);
1237 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1239 hwnd3 = CreateWindowExA(0, "#32770", "TEST3", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1240 trace("created window 3: %p\n", hwnd3);
1242 hwnd4 = CreateWindowExA(0, "#32770", "TEST4", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1243 trace("created window 4: %p\n", hwnd4);
1245 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1246 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1248 ret = SetShellWindow(hwnd4);
1249 ok(ret, "SetShellWindow(hwnd4)\n");
1250 shellWindow = GetShellWindow();
1251 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1253 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1254 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1256 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1257 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1259 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1260 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1262 ret = SetShellWindow(hwnd3);
1263 ok(!ret, "SetShellWindow(hwnd3)\n");
1264 shellWindow = GetShellWindow();
1265 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1267 hwnd5 = CreateWindowExA(0, "#32770", "TEST5", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1268 trace("created window 5: %p\n", hwnd5);
1269 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1270 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1272 todo_wine
1274 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1275 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1278 /* destroy test windows */
1279 DestroyWindow(hwnd2);
1280 DestroyWindow(hwnd3);
1281 DestroyWindow(hwnd4);
1282 DestroyWindow(hwnd5);
1285 /************** MDI test ****************/
1287 static char mdi_lParam_test_message[] = "just a test string";
1289 static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
1291 MDICREATESTRUCTA mdi_cs;
1292 HWND mdi_child;
1293 INT_PTR id;
1294 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1295 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1296 BOOL isWin9x = FALSE;
1298 mdi_cs.szClass = "MDI_child_Class_1";
1299 mdi_cs.szTitle = "MDI child";
1300 mdi_cs.hOwner = GetModuleHandleA(NULL);
1301 mdi_cs.x = CW_USEDEFAULT;
1302 mdi_cs.y = CW_USEDEFAULT;
1303 mdi_cs.cx = CW_USEDEFAULT;
1304 mdi_cs.cy = CW_USEDEFAULT;
1305 mdi_cs.style = 0;
1306 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1307 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1308 ok(mdi_child != 0, "MDI child creation failed\n");
1309 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1310 ok(id == first_id, "wrong child id %ld\n", id);
1311 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1312 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1314 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1315 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1316 ok(mdi_child != 0, "MDI child creation failed\n");
1317 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1318 ok(id == first_id, "wrong child id %ld\n", id);
1319 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1320 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1322 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1323 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1324 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1326 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1328 else
1330 ok(mdi_child != 0, "MDI child creation failed\n");
1331 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1332 ok(id == first_id, "wrong child id %ld\n", id);
1333 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1334 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1337 /* test MDICREATESTRUCT A<->W mapping */
1338 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1339 mdi_cs.style = 0;
1340 mdi_cs.szClass = (LPCSTR)classW;
1341 mdi_cs.szTitle = (LPCSTR)titleW;
1342 SetLastError(0xdeadbeef);
1343 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1344 if (!mdi_child)
1346 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1347 isWin9x = TRUE;
1348 else
1349 ok(mdi_child != 0, "MDI child creation failed\n");
1351 else
1353 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1354 ok(id == first_id, "wrong child id %ld\n", id);
1355 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1356 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1359 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1361 CW_USEDEFAULT, CW_USEDEFAULT,
1362 CW_USEDEFAULT, CW_USEDEFAULT,
1363 mdi_client, GetModuleHandleA(NULL),
1364 (LPARAM)mdi_lParam_test_message);
1365 ok(mdi_child != 0, "MDI child creation failed\n");
1366 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1367 ok(id == first_id, "wrong child id %ld\n", id);
1368 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1369 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1371 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1372 0x7fffffff, /* without WS_POPUP */
1373 CW_USEDEFAULT, CW_USEDEFAULT,
1374 CW_USEDEFAULT, CW_USEDEFAULT,
1375 mdi_client, GetModuleHandleA(NULL),
1376 (LPARAM)mdi_lParam_test_message);
1377 ok(mdi_child != 0, "MDI child creation failed\n");
1378 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1379 ok(id == first_id, "wrong child id %ld\n", id);
1380 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1381 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1383 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1384 0xffffffff, /* with WS_POPUP */
1385 CW_USEDEFAULT, CW_USEDEFAULT,
1386 CW_USEDEFAULT, CW_USEDEFAULT,
1387 mdi_client, GetModuleHandleA(NULL),
1388 (LPARAM)mdi_lParam_test_message);
1389 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1391 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1393 else
1395 ok(mdi_child != 0, "MDI child creation failed\n");
1396 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1397 ok(id == first_id, "wrong child id %ld\n", id);
1398 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1399 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1402 /* test MDICREATESTRUCT A<->W mapping */
1403 SetLastError(0xdeadbeef);
1404 mdi_child = CreateMDIWindowW(classW, titleW,
1406 CW_USEDEFAULT, CW_USEDEFAULT,
1407 CW_USEDEFAULT, CW_USEDEFAULT,
1408 mdi_client, GetModuleHandleA(NULL),
1409 (LPARAM)mdi_lParam_test_message);
1410 if (!mdi_child)
1412 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1413 isWin9x = TRUE;
1414 else
1415 ok(mdi_child != 0, "MDI child creation failed\n");
1417 else
1419 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1420 ok(id == first_id, "wrong child id %ld\n", id);
1421 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1422 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1425 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1427 CW_USEDEFAULT, CW_USEDEFAULT,
1428 CW_USEDEFAULT, CW_USEDEFAULT,
1429 mdi_client, 0, GetModuleHandleA(NULL),
1430 mdi_lParam_test_message);
1431 ok(mdi_child != 0, "MDI child creation failed\n");
1432 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1433 ok(id == first_id, "wrong child id %ld\n", id);
1434 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1435 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1437 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1438 0x7fffffff, /* without WS_POPUP */
1439 CW_USEDEFAULT, CW_USEDEFAULT,
1440 CW_USEDEFAULT, CW_USEDEFAULT,
1441 mdi_client, 0, GetModuleHandleA(NULL),
1442 mdi_lParam_test_message);
1443 ok(mdi_child != 0, "MDI child creation failed\n");
1444 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1445 ok(id == first_id, "wrong child id %ld\n", id);
1446 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1447 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1449 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1450 0xffffffff, /* with WS_POPUP */
1451 CW_USEDEFAULT, CW_USEDEFAULT,
1452 CW_USEDEFAULT, CW_USEDEFAULT,
1453 mdi_client, 0, GetModuleHandleA(NULL),
1454 mdi_lParam_test_message);
1455 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1457 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1459 else
1461 ok(mdi_child != 0, "MDI child creation failed\n");
1462 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1463 ok(id == first_id, "wrong child id %ld\n", id);
1464 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1465 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1468 /* test MDICREATESTRUCT A<->W mapping */
1469 SetLastError(0xdeadbeef);
1470 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1472 CW_USEDEFAULT, CW_USEDEFAULT,
1473 CW_USEDEFAULT, CW_USEDEFAULT,
1474 mdi_client, 0, GetModuleHandleA(NULL),
1475 mdi_lParam_test_message);
1476 if (!mdi_child)
1478 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1479 isWin9x = TRUE;
1480 else
1481 ok(mdi_child != 0, "MDI child creation failed\n");
1483 else
1485 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1486 ok(id == first_id, "wrong child id %ld\n", id);
1487 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1488 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1491 /* This test fails on Win9x */
1492 if (!isWin9x)
1494 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1495 WS_CHILD,
1496 CW_USEDEFAULT, CW_USEDEFAULT,
1497 CW_USEDEFAULT, CW_USEDEFAULT,
1498 parent, 0, GetModuleHandleA(NULL),
1499 mdi_lParam_test_message);
1500 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1503 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1504 WS_CHILD, /* without WS_POPUP */
1505 CW_USEDEFAULT, CW_USEDEFAULT,
1506 CW_USEDEFAULT, CW_USEDEFAULT,
1507 mdi_client, 0, GetModuleHandleA(NULL),
1508 mdi_lParam_test_message);
1509 ok(mdi_child != 0, "MDI child creation failed\n");
1510 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1511 ok(id == 0, "wrong child id %ld\n", id);
1512 DestroyWindow(mdi_child);
1514 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1515 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1516 CW_USEDEFAULT, CW_USEDEFAULT,
1517 CW_USEDEFAULT, CW_USEDEFAULT,
1518 mdi_client, 0, GetModuleHandleA(NULL),
1519 mdi_lParam_test_message);
1520 ok(mdi_child != 0, "MDI child creation failed\n");
1521 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1522 ok(id == 0, "wrong child id %ld\n", id);
1523 DestroyWindow(mdi_child);
1525 /* maximized child */
1526 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1527 WS_CHILD | WS_MAXIMIZE,
1528 CW_USEDEFAULT, CW_USEDEFAULT,
1529 CW_USEDEFAULT, CW_USEDEFAULT,
1530 mdi_client, 0, GetModuleHandleA(NULL),
1531 mdi_lParam_test_message);
1532 ok(mdi_child != 0, "MDI child creation failed\n");
1533 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1534 ok(id == 0, "wrong child id %ld\n", id);
1535 DestroyWindow(mdi_child);
1537 trace("Creating maximized child with a caption\n");
1538 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1539 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1540 CW_USEDEFAULT, CW_USEDEFAULT,
1541 CW_USEDEFAULT, CW_USEDEFAULT,
1542 mdi_client, 0, GetModuleHandleA(NULL),
1543 mdi_lParam_test_message);
1544 ok(mdi_child != 0, "MDI child creation failed\n");
1545 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1546 ok(id == 0, "wrong child id %ld\n", id);
1547 DestroyWindow(mdi_child);
1549 trace("Creating maximized child with a caption and a thick frame\n");
1550 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1551 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1552 CW_USEDEFAULT, CW_USEDEFAULT,
1553 CW_USEDEFAULT, CW_USEDEFAULT,
1554 mdi_client, 0, GetModuleHandleA(NULL),
1555 mdi_lParam_test_message);
1556 ok(mdi_child != 0, "MDI child creation failed\n");
1557 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1558 ok(id == 0, "wrong child id %ld\n", id);
1559 DestroyWindow(mdi_child);
1562 static void test_MDI_child_stack(HWND mdi_client)
1564 HWND child_1, child_2, child_3, child_4;
1565 HWND stack[4];
1566 MDICREATESTRUCTA cs;
1568 cs.szClass = "MDI_child_Class_1";
1569 cs.szTitle = "MDI child";
1570 cs.hOwner = GetModuleHandleA(0);
1571 cs.x = CW_USEDEFAULT;
1572 cs.y = CW_USEDEFAULT;
1573 cs.cx = CW_USEDEFAULT;
1574 cs.cy = CW_USEDEFAULT;
1575 cs.style = 0;
1576 cs.lParam = (LPARAM)mdi_lParam_test_message;
1578 child_1 = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&cs);
1579 ok(child_1 != 0, "expected child_1 to be non NULL\n");
1580 child_2 = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&cs);
1581 ok(child_2 != 0, "expected child_2 to be non NULL\n");
1582 child_3 = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&cs);
1583 ok(child_3 != 0, "expected child_3 to be non NULL\n");
1584 child_4 = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&cs);
1585 ok(child_4 != 0, "expected child_4 to be non NULL\n");
1587 stack[0] = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1588 stack[1] = GetWindow(stack[0], GW_HWNDNEXT);
1589 stack[2] = GetWindow(stack[1], GW_HWNDNEXT);
1590 stack[3] = GetWindow(stack[2], GW_HWNDNEXT);
1591 trace("Initial MDI child stack: %p->%p->%p->%p\n", stack[0], stack[1], stack[2], stack[3]);
1592 ok(stack[0] == child_4 && stack[1] == child_3 &&
1593 stack[2] == child_2 && stack[3] == child_1,
1594 "Unexpected initial order, should be: %p->%p->%p->%p\n",
1595 child_4, child_3, child_2, child_1);
1597 trace("Activate child next to %p\n", child_3);
1598 SendMessageA(mdi_client, WM_MDINEXT, (WPARAM)child_3, 0);
1600 stack[0] = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1601 stack[1] = GetWindow(stack[0], GW_HWNDNEXT);
1602 stack[2] = GetWindow(stack[1], GW_HWNDNEXT);
1603 stack[3] = GetWindow(stack[2], GW_HWNDNEXT);
1604 ok(stack[0] == child_2 && stack[1] == child_4 &&
1605 stack[2] == child_1 && stack[3] == child_3,
1606 "Broken MDI child stack:\nexpected: %p->%p->%p->%p, but got: %p->%p->%p->%p\n",
1607 child_2, child_4, child_1, child_3, stack[0], stack[1], stack[2], stack[3]);
1609 trace("Activate child previous to %p\n", child_1);
1610 SendMessageA(mdi_client, WM_MDINEXT, (WPARAM)child_1, 1);
1612 stack[0] = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1613 stack[1] = GetWindow(stack[0], GW_HWNDNEXT);
1614 stack[2] = GetWindow(stack[1], GW_HWNDNEXT);
1615 stack[3] = GetWindow(stack[2], GW_HWNDNEXT);
1616 ok(stack[0] == child_4 && stack[1] == child_2 &&
1617 stack[2] == child_1 && stack[3] == child_3,
1618 "Broken MDI child stack:\nexpected: %p->%p->%p->%p, but got: %p->%p->%p->%p\n",
1619 child_4, child_2, child_1, child_3, stack[0], stack[1], stack[2], stack[3]);
1621 DestroyWindow(child_1);
1622 DestroyWindow(child_2);
1623 DestroyWindow(child_3);
1624 DestroyWindow(child_4);
1627 /**********************************************************************
1628 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1630 * Note: The rule here is that client rect of the maximized MDI child
1631 * is equal to the client rect of the MDI client window.
1633 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1635 RECT rect;
1637 GetClientRect( client, &rect );
1638 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1639 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1641 rect.right -= rect.left;
1642 rect.bottom -= rect.top;
1643 lpMinMax->ptMaxSize.x = rect.right;
1644 lpMinMax->ptMaxSize.y = rect.bottom;
1646 lpMinMax->ptMaxPosition.x = rect.left;
1647 lpMinMax->ptMaxPosition.y = rect.top;
1649 trace("max rect (%d,%d - %d, %d)\n",
1650 rect.left, rect.top, rect.right, rect.bottom);
1653 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1655 switch (msg)
1657 case WM_NCCREATE:
1658 case WM_CREATE:
1660 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1661 MDICREATESTRUCTA *mdi_cs = cs->lpCreateParams;
1663 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1664 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1666 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1667 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1668 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1669 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1670 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1672 /* MDICREATESTRUCT should have original values */
1673 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1674 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1675 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1676 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1677 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1678 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1680 /* CREATESTRUCT should have fixed values */
1681 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1682 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1684 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1685 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1686 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1688 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1690 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1692 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1693 ok(cs->style == style,
1694 "cs->style does not match (%08x)\n", cs->style);
1696 else
1698 LONG style = mdi_cs->style;
1699 style &= ~WS_POPUP;
1700 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1701 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1702 ok(cs->style == style,
1703 "cs->style does not match (%08x)\n", cs->style);
1705 break;
1708 case WM_GETMINMAXINFO:
1710 HWND client = GetParent(hwnd);
1711 RECT rc;
1712 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1713 MINMAXINFO my_minmax;
1714 LONG style, exstyle;
1716 style = GetWindowLongA(hwnd, GWL_STYLE);
1717 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1719 GetClientRect(client, &rc);
1721 GetClientRect(client, &rc);
1722 if ((style & WS_CAPTION) == WS_CAPTION)
1723 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1724 AdjustWindowRectEx(&rc, style, 0, exstyle);
1725 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1726 dump_minmax_info( minmax );
1728 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1729 minmax->ptMaxSize.x, rc.right - rc.left);
1730 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1731 minmax->ptMaxSize.y, rc.bottom - rc.top);
1733 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1735 trace("DefMDIChildProc returned:\n");
1736 dump_minmax_info( minmax );
1738 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1739 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1740 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1741 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1742 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1744 return 1;
1747 case WM_MDIACTIVATE:
1749 HWND active, client = GetParent(hwnd);
1750 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1751 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1752 if (hwnd == (HWND)lparam) /* if we are being activated */
1753 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1754 else
1755 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1756 break;
1759 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1762 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1764 switch (msg)
1766 case WM_NCCREATE:
1767 case WM_CREATE:
1769 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1771 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE",
1772 cs->x, cs->y, cs->cx, cs->cy);
1774 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1775 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1777 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1778 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1780 /* CREATESTRUCT should have fixed values */
1781 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1782 while NT does. */
1783 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1784 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1786 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1787 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1788 while Win95, Win2k, WinXP do. */
1789 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1790 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1791 break;
1794 case WM_GETMINMAXINFO:
1796 HWND parent = GetParent(hwnd);
1797 RECT rc;
1798 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1799 LONG style, exstyle;
1801 style = GetWindowLongA(hwnd, GWL_STYLE);
1802 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1804 GetClientRect(parent, &rc);
1805 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1807 GetClientRect(parent, &rc);
1808 if ((style & WS_CAPTION) == WS_CAPTION)
1809 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1810 AdjustWindowRectEx(&rc, style, 0, exstyle);
1811 dump_minmax_info( minmax );
1813 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1814 minmax->ptMaxSize.x, rc.right - rc.left);
1815 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1816 minmax->ptMaxSize.y, rc.bottom - rc.top);
1817 break;
1820 case WM_WINDOWPOSCHANGED:
1822 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1823 RECT rc1, rc2;
1825 GetWindowRect(hwnd, &rc1);
1826 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1827 /* note: winpos coordinates are relative to parent */
1828 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1829 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) pos=(%d,%d)-(%d,%d)\n",
1830 rc1.left, rc1.top, rc1.right, rc1.bottom,
1831 rc2.left, rc2.top, rc2.right, rc2.bottom);
1832 GetWindowRect(hwnd, &rc1);
1833 GetClientRect(hwnd, &rc2);
1834 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1835 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1836 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1837 rc1.left, rc1.top, rc1.right, rc1.bottom,
1838 rc2.left, rc2.top, rc2.right, rc2.bottom);
1840 /* fall through */
1841 case WM_WINDOWPOSCHANGING:
1843 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1844 WINDOWPOS my_winpos = *winpos;
1846 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1847 (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
1848 winpos->hwnd, winpos->hwndInsertAfter,
1849 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1851 DefWindowProcA(hwnd, msg, wparam, lparam);
1853 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1854 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1855 winpos->hwnd, winpos->hwndInsertAfter,
1856 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1858 return 1;
1861 return DefWindowProcA(hwnd, msg, wparam, lparam);
1864 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1866 static HWND mdi_client;
1868 switch (msg)
1870 case WM_CREATE:
1872 CLIENTCREATESTRUCT client_cs;
1873 RECT rc;
1875 GetClientRect(hwnd, &rc);
1877 client_cs.hWindowMenu = 0;
1878 client_cs.idFirstChild = 1;
1880 /* MDIClient without MDIS_ALLCHILDSTYLES */
1881 mdi_client = CreateWindowExA(0, "mdiclient",
1882 NULL,
1883 WS_CHILD /*| WS_VISIBLE*/,
1884 /* tests depend on a not zero MDIClient size */
1885 0, 0, rc.right, rc.bottom,
1886 hwnd, 0, GetModuleHandleA(NULL),
1887 &client_cs);
1888 assert(mdi_client);
1889 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1890 DestroyWindow(mdi_client);
1892 /* MDIClient with MDIS_ALLCHILDSTYLES */
1893 mdi_client = CreateWindowExA(0, "mdiclient",
1894 NULL,
1895 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1896 /* tests depend on a not zero MDIClient size */
1897 0, 0, rc.right, rc.bottom,
1898 hwnd, 0, GetModuleHandleA(NULL),
1899 &client_cs);
1900 assert(mdi_client);
1901 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1902 DestroyWindow(mdi_client);
1904 /* Test child window stack management */
1905 mdi_client = CreateWindowExA(0, "mdiclient",
1906 NULL,
1907 WS_CHILD,
1908 0, 0, rc.right, rc.bottom,
1909 hwnd, 0, GetModuleHandleA(NULL),
1910 &client_cs);
1911 assert(mdi_client);
1912 test_MDI_child_stack(mdi_client);
1913 DestroyWindow(mdi_client);
1914 break;
1917 case WM_WINDOWPOSCHANGED:
1919 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1920 RECT rc1, rc2;
1922 GetWindowRect(hwnd, &rc1);
1923 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1924 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1925 /* note: winpos coordinates are relative to parent */
1926 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1927 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1928 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1930 GetWindowRect(hwnd, &rc1);
1931 GetClientRect(hwnd, &rc2);
1932 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1933 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1934 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1936 /* fall through */
1937 case WM_WINDOWPOSCHANGING:
1939 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1940 WINDOWPOS my_winpos = *winpos;
1942 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1943 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1944 winpos->hwnd, winpos->hwndInsertAfter,
1945 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1947 DefWindowProcA(hwnd, msg, wparam, lparam);
1949 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1950 winpos->hwnd, winpos->hwndInsertAfter,
1951 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1953 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1954 "DefWindowProc should not change WINDOWPOS values\n");
1956 return 1;
1959 case WM_CLOSE:
1960 PostQuitMessage(0);
1961 break;
1963 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1966 static BOOL mdi_RegisterWindowClasses(void)
1968 WNDCLASSA cls;
1970 cls.style = 0;
1971 cls.lpfnWndProc = mdi_main_wnd_procA;
1972 cls.cbClsExtra = 0;
1973 cls.cbWndExtra = 0;
1974 cls.hInstance = GetModuleHandleA(0);
1975 cls.hIcon = 0;
1976 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
1977 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1978 cls.lpszMenuName = NULL;
1979 cls.lpszClassName = "MDI_parent_Class";
1980 if(!RegisterClassA(&cls)) return FALSE;
1982 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1983 cls.lpszClassName = "MDI_child_Class_1";
1984 if(!RegisterClassA(&cls)) return FALSE;
1986 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1987 cls.lpszClassName = "MDI_child_Class_2";
1988 if(!RegisterClassA(&cls)) return FALSE;
1990 return TRUE;
1993 static void test_mdi(void)
1995 HWND mdi_hwndMain;
1996 /*MSG msg;*/
1998 if (!mdi_RegisterWindowClasses()) assert(0);
2000 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
2001 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
2002 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
2003 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
2004 GetDesktopWindow(), 0,
2005 GetModuleHandleA(NULL), NULL);
2006 assert(mdi_hwndMain);
2008 while(GetMessage(&msg, 0, 0, 0))
2010 TranslateMessage(&msg);
2011 DispatchMessage(&msg);
2014 DestroyWindow(mdi_hwndMain);
2017 static void test_icons(void)
2019 WNDCLASSEXA cls;
2020 HWND hwnd;
2021 HICON icon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
2022 HICON icon2 = LoadIconA(0, (LPCSTR)IDI_QUESTION);
2023 HICON small_icon = LoadImageA(0, (LPCSTR)IDI_APPLICATION, IMAGE_ICON,
2024 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
2025 HICON res;
2027 cls.cbSize = sizeof(cls);
2028 cls.style = 0;
2029 cls.lpfnWndProc = DefWindowProcA;
2030 cls.cbClsExtra = 0;
2031 cls.cbWndExtra = 0;
2032 cls.hInstance = 0;
2033 cls.hIcon = LoadIconA(0, (LPCSTR)IDI_HAND);
2034 cls.hIconSm = small_icon;
2035 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
2036 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
2037 cls.lpszMenuName = NULL;
2038 cls.lpszClassName = "IconWindowClass";
2040 RegisterClassExA(&cls);
2042 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
2043 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
2044 assert( hwnd );
2046 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
2047 ok( res == 0, "wrong big icon %p/0\n", res );
2048 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
2049 ok( res == 0, "wrong previous big icon %p/0\n", res );
2050 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
2051 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
2052 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
2053 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
2054 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
2055 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
2057 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
2058 ok( res == 0, "wrong small icon %p/0\n", res );
2059 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
2060 ok( (res && res != small_icon && res != icon2) || broken(!res), "wrong small2 icon %p\n", res );
2061 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
2062 ok( res == 0, "wrong previous small icon %p/0\n", res );
2063 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
2064 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
2065 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
2066 ok( res == icon || broken(!res), "wrong small2 icon after set %p/%p\n", res, icon );
2067 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
2068 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
2069 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
2070 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
2071 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
2072 ok( res == small_icon || broken(!res), "wrong small2 icon after set %p/%p\n", res, small_icon );
2074 /* make sure the big icon hasn't changed */
2075 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
2076 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
2078 DestroyWindow( hwnd );
2081 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2083 if (msg == WM_NCCALCSIZE)
2085 RECT *rect = (RECT *)lparam;
2086 /* first time around increase the rectangle, next time decrease it */
2087 if (rect->left == 100) InflateRect( rect, 10, 10 );
2088 else InflateRect( rect, -10, -10 );
2089 return 0;
2091 return DefWindowProcA( hwnd, msg, wparam, lparam );
2094 static void test_SetWindowPos(HWND hwnd, HWND hwnd2)
2096 RECT orig_win_rc, rect;
2097 LONG_PTR old_proc;
2098 HWND hwnd_grandchild, hwnd_child, hwnd_child2;
2099 HWND hwnd_desktop;
2100 RECT rc1, rc2;
2101 BOOL ret;
2103 SetRect(&rect, 111, 222, 333, 444);
2104 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
2105 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
2106 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2108 SetRect(&rect, 111, 222, 333, 444);
2109 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
2110 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
2111 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2113 GetWindowRect(hwnd, &orig_win_rc);
2115 old_proc = SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
2116 ret = SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
2117 ok(ret, "Got %d\n", ret);
2118 GetWindowRect( hwnd, &rect );
2119 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
2120 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2121 GetClientRect( hwnd, &rect );
2122 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
2123 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
2124 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2126 ret = SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
2127 ok(ret, "Got %d\n", ret);
2128 GetWindowRect( hwnd, &rect );
2129 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
2130 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2131 GetClientRect( hwnd, &rect );
2132 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
2133 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
2134 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2136 ret = SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
2137 orig_win_rc.right, orig_win_rc.bottom, 0);
2138 ok(ret, "Got %d\n", ret);
2139 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, old_proc );
2141 /* Win9x truncates coordinates to 16-bit irrespectively */
2142 if (!is_win9x)
2144 ret = SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
2145 ok(ret, "Got %d\n", ret);
2146 ret = SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
2147 ok(ret, "Got %d\n", ret);
2149 ret = SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
2150 ok(ret, "Got %d\n", ret);
2151 ret = SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
2152 ok(ret, "Got %d\n", ret);
2155 ret = SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
2156 orig_win_rc.right, orig_win_rc.bottom, 0);
2157 ok(ret, "Got %d\n", ret);
2159 ok(!(GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
2160 ret = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
2161 ok(ret, "Got %d\n", ret);
2162 ok(GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
2163 ret = SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
2164 ok(ret, "Got %d\n", ret);
2165 ok(GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
2166 ret = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
2167 ok(ret, "Got %d\n", ret);
2168 ok(!(GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
2170 hwnd_desktop = GetDesktopWindow();
2171 ok(!!hwnd_desktop, "Failed to get hwnd_desktop window (%d).\n", GetLastError());
2172 hwnd_child = create_tool_window(WS_VISIBLE|WS_CHILD, hwnd);
2173 ok(!!hwnd_child, "Failed to create child window (%d)\n", GetLastError());
2174 hwnd_grandchild = create_tool_window(WS_VISIBLE|WS_CHILD, hwnd_child);
2175 ok(!!hwnd_child, "Failed to create child window (%d)\n", GetLastError());
2176 hwnd_child2 = create_tool_window(WS_VISIBLE|WS_CHILD, hwnd);
2177 ok(!!hwnd_child2, "Failed to create second child window (%d)\n", GetLastError());
2179 ret = SetWindowPos(hwnd, hwnd2, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2180 ok(ret, "Got %d\n", ret);
2181 check_active_state(hwnd, hwnd, hwnd);
2183 ret = SetWindowPos(hwnd2, hwnd, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2184 ok(ret, "Got %d\n", ret);
2185 check_active_state(hwnd2, hwnd2, hwnd2);
2187 /* Returns TRUE also for windows that are not siblings */
2188 ret = SetWindowPos(hwnd_child, hwnd2, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2189 ok(ret, "Got %d\n", ret);
2190 check_active_state(hwnd2, hwnd2, hwnd2);
2192 ret = SetWindowPos(hwnd2, hwnd_child, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2193 ok(ret, "Got %d\n", ret);
2194 check_active_state(hwnd2, hwnd2, hwnd2);
2196 /* Does not seem to do anything even without passing flags, still returns TRUE */
2197 GetWindowRect(hwnd_child, &rc1);
2198 ret = SetWindowPos(hwnd_child, hwnd2 , 1, 2, 3, 4, 0);
2199 ok(ret, "Got %d\n", ret);
2200 GetWindowRect(hwnd_child, &rc2);
2201 ok(rc1.left == rc2.left && rc1.top == rc2.top &&
2202 rc1.right == rc2.right && rc1.bottom == rc2.bottom,
2203 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2204 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
2205 check_active_state(hwnd2, hwnd2, hwnd2);
2207 /* Same thing the other way around. */
2208 GetWindowRect(hwnd2, &rc1);
2209 ret = SetWindowPos(hwnd2, hwnd_child, 1, 2, 3, 4, 0);
2210 ok(ret, "Got %d\n", ret);
2211 GetWindowRect(hwnd2, &rc2);
2212 ok(rc1.left == rc2.left && rc1.top == rc2.top &&
2213 rc1.right == rc2.right && rc1.bottom == rc2.bottom,
2214 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2215 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
2216 check_active_state(hwnd2, hwnd2, hwnd2);
2218 /* .. and with these windows. */
2219 GetWindowRect(hwnd_grandchild, &rc1);
2220 ret = SetWindowPos(hwnd_grandchild, hwnd_child2, 1, 2, 3, 4, 0);
2221 ok(ret, "Got %d\n", ret);
2222 GetWindowRect(hwnd_grandchild, &rc2);
2223 ok(rc1.left == rc2.left && rc1.top == rc2.top &&
2224 rc1.right == rc2.right && rc1.bottom == rc2.bottom,
2225 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2226 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
2227 check_active_state(hwnd2, hwnd2, hwnd2);
2229 /* Add SWP_NOZORDER and it will be properly resized. */
2230 GetWindowRect(hwnd_grandchild, &rc1);
2231 ret = SetWindowPos(hwnd_grandchild, hwnd_child2, 1, 2, 3, 4, SWP_NOZORDER);
2232 ok(ret, "Got %d\n", ret);
2233 GetWindowRect(hwnd_grandchild, &rc2);
2234 ok((rc1.left+1) == rc2.left && (rc1.top+2) == rc2.top &&
2235 (rc1.left+4) == rc2.right && (rc1.top+6) == rc2.bottom,
2236 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2237 rc1.left+1, rc1.top+2, rc1.left+4, rc1.top+6, rc2.left, rc2.top, rc2.right, rc2.bottom);
2238 check_active_state(hwnd2, hwnd2, hwnd2);
2240 /* Given a sibling window, the window is properly resized. */
2241 GetWindowRect(hwnd_child, &rc1);
2242 ret = SetWindowPos(hwnd_child, hwnd_child2, 1, 2, 3, 4, 0);
2243 ok(ret, "Got %d\n", ret);
2244 GetWindowRect(hwnd_child, &rc2);
2245 ok((rc1.left+1) == rc2.left && (rc1.top+2) == rc2.top &&
2246 (rc1.left+4) == rc2.right && (rc1.top+6) == rc2.bottom,
2247 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2248 rc1.left+1, rc1.top+2, rc1.left+4, rc1.top+6, rc2.left, rc2.top, rc2.right, rc2.bottom);
2249 check_active_state(hwnd2, hwnd2, hwnd2);
2251 /* Involving the desktop window changes things. */
2252 ret = SetWindowPos(hwnd_child, hwnd_desktop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2253 ok(!ret, "Got %d\n", ret);
2254 check_active_state(hwnd2, hwnd2, hwnd2);
2256 GetWindowRect(hwnd_child, &rc1);
2257 ret = SetWindowPos(hwnd_child, hwnd_desktop, 0, 0, 0, 0, 0);
2258 ok(!ret, "Got %d\n", ret);
2259 GetWindowRect(hwnd_child, &rc2);
2260 ok(rc1.top == rc2.top && rc1.left == rc2.left &&
2261 rc1.bottom == rc2.bottom && rc1.right == rc2.right,
2262 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2263 rc1.top, rc1.left, rc1.bottom, rc1.right, rc2.top, rc2.left, rc2.bottom, rc2.right);
2264 check_active_state(hwnd2, hwnd2, hwnd2);
2266 ret = SetWindowPos(hwnd_desktop, hwnd_child, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2267 ok(!ret, "Got %d\n", ret);
2268 check_active_state(hwnd2, hwnd2, hwnd2);
2270 ret = SetWindowPos(hwnd_desktop, hwnd, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2271 ok(!ret, "Got %d\n", ret);
2272 check_active_state(hwnd2, hwnd2, hwnd2);
2274 ret = SetWindowPos(hwnd, hwnd_desktop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2275 ok(!ret, "Got %d\n", ret);
2276 check_active_state(hwnd2, hwnd2, hwnd2);
2278 DestroyWindow(hwnd_grandchild);
2279 DestroyWindow(hwnd_child);
2280 DestroyWindow(hwnd_child2);
2282 hwnd_child = create_tool_window(WS_CHILD|WS_POPUP|WS_SYSMENU, hwnd2);
2283 ok(!!hwnd_child, "Failed to create child window (%d)\n", GetLastError());
2284 ret = SetWindowPos(hwnd_child, NULL, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2285 ok(ret, "Got %d\n", ret);
2286 flush_events( TRUE );
2287 todo_wine check_active_state(hwnd2, hwnd2, hwnd2);
2288 DestroyWindow(hwnd_child);
2291 static void test_SetMenu(HWND parent)
2293 HWND child;
2294 HMENU hMenu, ret;
2295 BOOL retok;
2296 DWORD style;
2298 hMenu = CreateMenu();
2299 assert(hMenu);
2301 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2302 if (0)
2304 /* fails on (at least) Wine, NT4, XP SP2 */
2305 test_nonclient_area(parent);
2307 ret = GetMenu(parent);
2308 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2309 /* test whether we can destroy a menu assigned to a window */
2310 retok = DestroyMenu(hMenu);
2311 ok( retok, "DestroyMenu error %d\n", GetLastError());
2312 retok = IsMenu(hMenu);
2313 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
2314 ret = GetMenu(parent);
2315 /* This test fails on Win9x */
2316 if (!is_win9x)
2317 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2318 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2319 test_nonclient_area(parent);
2321 hMenu = CreateMenu();
2322 assert(hMenu);
2324 /* parent */
2325 ret = GetMenu(parent);
2326 ok(ret == 0, "unexpected menu id %p\n", ret);
2328 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2329 test_nonclient_area(parent);
2330 ret = GetMenu(parent);
2331 ok(ret == 0, "unexpected menu id %p\n", ret);
2333 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2334 if (0)
2336 /* fails on (at least) Wine, NT4, XP SP2 */
2337 test_nonclient_area(parent);
2339 ret = GetMenu(parent);
2340 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2342 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2343 test_nonclient_area(parent);
2344 ret = GetMenu(parent);
2345 ok(ret == 0, "unexpected menu id %p\n", ret);
2347 /* child */
2348 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
2349 assert(child);
2351 ret = GetMenu(child);
2352 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2354 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2355 test_nonclient_area(child);
2356 ret = GetMenu(child);
2357 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2359 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
2360 test_nonclient_area(child);
2361 ret = GetMenu(child);
2362 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2364 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
2365 test_nonclient_area(child);
2366 ret = GetMenu(child);
2367 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2369 style = GetWindowLongA(child, GWL_STYLE);
2370 SetWindowLongA(child, GWL_STYLE, style | WS_POPUP);
2371 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
2372 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
2373 SetWindowLongA(child, GWL_STYLE, style);
2375 SetWindowLongA(child, GWL_STYLE, style | WS_OVERLAPPED);
2376 ok(!SetMenu(child, hMenu), "SetMenu on an overlapped child window should fail\n");
2377 SetWindowLongA(child, GWL_STYLE, style);
2379 DestroyWindow(child);
2380 DestroyMenu(hMenu);
2383 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
2385 HWND child[5], hwnd;
2386 INT_PTR i;
2388 assert(total <= 5);
2390 hwnd = GetWindow(parent, GW_CHILD);
2391 ok(!hwnd, "have to start without children to perform the test\n");
2393 for (i = 0; i < total; i++)
2395 if (style[i] & DS_CONTROL)
2397 child[i] = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
2398 0,0,0,0, parent, (HMENU)i, 0, NULL);
2399 if (style[i] & WS_VISIBLE)
2400 ShowWindow(child[i], SW_SHOW);
2402 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
2404 else
2405 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
2406 parent, (HMENU)i, 0, NULL);
2407 trace("child[%ld] = %p\n", i, child[i]);
2408 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
2411 hwnd = GetWindow(parent, GW_CHILD);
2412 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
2413 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
2414 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
2416 for (i = 0; i < total; i++)
2418 trace("hwnd[%ld] = %p\n", i, hwnd);
2419 ok(child[order[i]] == hwnd, "Z order of child #%ld is wrong\n", i);
2421 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
2424 for (i = 0; i < total; i++)
2425 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2428 static void test_children_zorder(HWND parent)
2430 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2431 WS_CHILD };
2432 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2434 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2435 WS_CHILD | WS_VISIBLE, WS_CHILD,
2436 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2437 const int complex_order_1[1] = { 0 };
2438 const int complex_order_2[2] = { 1, 0 };
2439 const int complex_order_3[3] = { 1, 0, 2 };
2440 const int complex_order_4[4] = { 1, 0, 2, 3 };
2441 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2442 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2443 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2444 WS_CHILD | WS_VISIBLE };
2445 const int complex_order_6[3] = { 0, 1, 2 };
2447 /* simple WS_CHILD */
2448 test_window_tree(parent, simple_style, simple_order, 5);
2450 /* complex children styles */
2451 test_window_tree(parent, complex_style, complex_order_1, 1);
2452 test_window_tree(parent, complex_style, complex_order_2, 2);
2453 test_window_tree(parent, complex_style, complex_order_3, 3);
2454 test_window_tree(parent, complex_style, complex_order_4, 4);
2455 test_window_tree(parent, complex_style, complex_order_5, 5);
2457 /* another set of complex children styles */
2458 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2461 #define check_z_order(hwnd, next, prev, owner, topmost) \
2462 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2463 __FILE__, __LINE__)
2465 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2466 BOOL topmost, const char *file, int line)
2468 HWND test;
2469 DWORD ex_style;
2471 test = GetWindow(hwnd, GW_HWNDNEXT);
2472 /* skip foreign windows */
2473 while (test && test != next &&
2474 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2475 UlongToHandle(GetWindowLongPtrA(test, GWLP_HINSTANCE)) != GetModuleHandleA(NULL) ||
2476 GetWindow(test, GW_OWNER) == next))
2478 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2479 test = GetWindow(test, GW_HWNDNEXT);
2481 ok_(file, line)(next == test, "%p: expected next %p, got %p\n", hwnd, next, test);
2483 test = GetWindow(hwnd, GW_HWNDPREV);
2484 /* skip foreign windows */
2485 while (test && test != prev &&
2486 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2487 UlongToHandle(GetWindowLongPtrA(test, GWLP_HINSTANCE)) != GetModuleHandleA(NULL) ||
2488 GetWindow(test, GW_OWNER) == hwnd))
2490 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2491 test = GetWindow(test, GW_HWNDPREV);
2493 ok_(file, line)(prev == test, "%p: expected prev %p, got %p\n", hwnd, prev, test);
2495 test = GetWindow(hwnd, GW_OWNER);
2496 ok_(file, line)(owner == test, "%p: expected owner %p, got %p\n", hwnd, owner, test);
2498 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
2499 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "%p: expected %stopmost\n",
2500 hwnd, topmost ? "" : "NOT ");
2503 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E, DWORD style)
2505 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2507 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2509 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2511 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2512 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2514 hwnd_F = CreateWindowExA(0, "MainWindowClass", "Owner window",
2515 WS_OVERLAPPED | WS_CAPTION,
2516 100, 100, 100, 100,
2517 0, 0, GetModuleHandleA(NULL), NULL);
2518 trace("hwnd_F %p\n", hwnd_F);
2519 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2521 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2522 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2523 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2524 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2526 hwnd_C = CreateWindowExA(0, "MainWindowClass", NULL,
2527 style,
2528 100, 100, 100, 100,
2529 hwnd_F, 0, GetModuleHandleA(NULL), NULL);
2530 trace("hwnd_C %p\n", hwnd_C);
2531 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2532 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2533 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2534 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2536 hwnd_B = CreateWindowExA(WS_EX_TOPMOST, "MainWindowClass", NULL,
2537 style,
2538 100, 100, 100, 100,
2539 hwnd_F, 0, GetModuleHandleA(NULL), NULL);
2540 trace("hwnd_B %p\n", hwnd_B);
2541 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2542 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2543 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2544 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2545 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2547 hwnd_A = CreateWindowExA(WS_EX_TOPMOST, "MainWindowClass", NULL,
2548 style,
2549 100, 100, 100, 100,
2550 0, 0, GetModuleHandleA(NULL), NULL);
2551 trace("hwnd_A %p\n", hwnd_A);
2552 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2553 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2554 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2555 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2556 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2557 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2559 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);
2561 /* move hwnd_F and its popups up */
2562 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2563 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2564 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2565 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2566 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2567 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2568 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2570 /* move hwnd_F and its popups down */
2571 #if 0 /* enable once Wine is fixed to pass this test */
2572 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2573 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2574 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2575 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2576 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2577 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2578 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2579 #endif
2581 /* make hwnd_C owned by a topmost window */
2582 DestroyWindow( hwnd_C );
2583 hwnd_C = CreateWindowExA(0, "MainWindowClass", NULL,
2584 style,
2585 100, 100, 100, 100,
2586 hwnd_A, 0, GetModuleHandleA(NULL), NULL);
2587 trace("hwnd_C %p\n", hwnd_C);
2588 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2589 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2590 check_z_order(hwnd_F, hwnd_D, hwnd_B, 0, FALSE);
2591 check_z_order(hwnd_B, hwnd_F, hwnd_A, hwnd_F, TRUE);
2592 check_z_order(hwnd_A, hwnd_B, hwnd_C, 0, TRUE);
2593 check_z_order(hwnd_C, hwnd_A, 0, hwnd_A, TRUE);
2595 DestroyWindow(hwnd_A);
2596 DestroyWindow(hwnd_B);
2597 DestroyWindow(hwnd_C);
2598 DestroyWindow(hwnd_F);
2601 static void test_vis_rgn( HWND hwnd )
2603 RECT win_rect, rgn_rect;
2604 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2605 HDC hdc;
2607 ShowWindow(hwnd,SW_SHOW);
2608 hdc = GetDC( hwnd );
2609 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2610 GetWindowRect( hwnd, &win_rect );
2611 GetRgnBox( hrgn, &rgn_rect );
2612 if (is_win9x)
2614 trace("win9x, mapping to screen coords\n");
2615 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2617 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2618 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2619 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2620 rgn_rect.left, win_rect.left );
2621 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2622 rgn_rect.top, win_rect.top );
2623 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2624 rgn_rect.right, win_rect.right );
2625 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2626 rgn_rect.bottom, win_rect.bottom );
2627 ReleaseDC( hwnd, hdc );
2630 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2632 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2634 HWND child = GetWindow(hwnd, GW_CHILD);
2635 ok(child != 0, "couldn't find child window\n");
2636 SetFocus(child);
2637 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2638 return 0;
2640 return DefWindowProcA(hwnd, msg, wp, lp);
2643 static void test_SetFocus(HWND hwnd)
2645 HWND child, child2, ret;
2646 WNDPROC old_wnd_proc;
2648 /* check if we can set focus to non-visible windows */
2650 ShowWindow(hwnd, SW_SHOW);
2651 SetFocus(0);
2652 SetFocus(hwnd);
2653 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2654 ok( GetWindowLongA(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2655 ShowWindow(hwnd, SW_HIDE);
2656 SetFocus(0);
2657 SetFocus(hwnd);
2658 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2659 ok( !(GetWindowLongA(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2660 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2661 assert(child);
2662 SetFocus(child);
2663 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2664 ok( !(GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2665 ShowWindow(child, SW_SHOW);
2666 ok( GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2667 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2668 ShowWindow(child, SW_HIDE);
2669 ok( !(GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2670 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2671 ShowWindow(child, SW_SHOW);
2672 child2 = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, child, 0, 0, NULL);
2673 assert(child2);
2674 ShowWindow(child2, SW_SHOW);
2675 SetFocus(child2);
2676 ShowWindow(child, SW_HIDE);
2677 ok( !(GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2678 ok( GetFocus() == child2, "Focus should be on %p, not %p\n", child2, GetFocus() );
2679 ShowWindow(child, SW_SHOW);
2680 SetFocus(child);
2681 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2682 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2683 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2685 ShowWindow(child, SW_HIDE);
2686 SetFocus(hwnd);
2687 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2688 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2689 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2690 ShowWindow(child, SW_HIDE);
2691 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2693 ShowWindow(hwnd, SW_SHOW);
2694 ShowWindow(child, SW_SHOW);
2695 SetFocus(child);
2696 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2697 EnableWindow(hwnd, FALSE);
2698 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2699 EnableWindow(hwnd, TRUE);
2701 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2702 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2703 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2704 todo_wine
2705 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2706 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2707 ShowWindow(hwnd, SW_RESTORE);
2708 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2709 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2710 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2711 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2712 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2713 todo_wine
2714 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2715 old_wnd_proc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2716 ShowWindow(hwnd, SW_RESTORE);
2717 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2718 todo_wine
2719 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2720 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2722 SetFocus( hwnd );
2723 SetParent( child, GetDesktopWindow());
2724 SetParent( child2, child );
2725 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2726 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2727 ret = SetFocus( child2 );
2728 ok( ret == 0, "SetFocus %p should fail\n", child2);
2729 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2730 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2731 ret = SetFocus( child );
2732 ok( ret == 0, "SetFocus %p should fail\n", child);
2733 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2734 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2735 SetWindowLongW( child, GWL_STYLE, WS_POPUP|WS_CHILD );
2736 SetFocus( child2 );
2737 ok( GetActiveWindow() == child, "child window %p should be active\n", child);
2738 ok( GetFocus() == child2, "Focus should be on child2 %p\n", child2 );
2739 SetFocus( hwnd );
2740 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2741 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2742 SetFocus( child );
2743 ok( GetActiveWindow() == child, "child window %p should be active\n", child);
2744 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2746 DestroyWindow( child2 );
2747 DestroyWindow( child );
2750 static void test_SetActiveWindow(HWND hwnd)
2752 HWND hwnd2;
2754 flush_events( TRUE );
2755 ShowWindow(hwnd, SW_HIDE);
2756 SetFocus(0);
2757 SetActiveWindow(0);
2758 check_wnd_state(0, 0, 0, 0);
2760 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2762 ShowWindow(hwnd, SW_SHOW);
2763 check_wnd_state(hwnd, hwnd, hwnd, 0);
2765 hwnd2 = SetActiveWindow(0);
2766 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2767 if (!GetActiveWindow()) /* doesn't always work on vista */
2769 check_wnd_state(0, 0, 0, 0);
2770 hwnd2 = SetActiveWindow(hwnd);
2771 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2773 check_wnd_state(hwnd, hwnd, hwnd, 0);
2775 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2776 check_wnd_state(hwnd, hwnd, hwnd, 0);
2778 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2779 check_wnd_state(hwnd, hwnd, hwnd, 0);
2781 ShowWindow(hwnd, SW_HIDE);
2782 check_wnd_state(0, 0, 0, 0);
2784 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2785 SetActiveWindow(hwnd);
2786 check_wnd_state(hwnd, hwnd, hwnd, 0);
2788 ShowWindow(hwnd, SW_SHOW);
2789 check_wnd_state(hwnd, hwnd, hwnd, 0);
2791 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2792 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2794 DestroyWindow(hwnd2);
2795 check_wnd_state(hwnd, hwnd, hwnd, 0);
2797 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2798 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2800 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2801 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2803 DestroyWindow(hwnd2);
2804 check_wnd_state(hwnd, hwnd, hwnd, 0);
2807 struct create_window_thread_params
2809 HWND window;
2810 HANDLE window_created;
2811 HANDLE test_finished;
2814 static DWORD WINAPI create_window_thread(void *param)
2816 struct create_window_thread_params *p = param;
2817 DWORD res;
2818 BOOL ret;
2820 p->window = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
2822 ret = SetEvent(p->window_created);
2823 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
2825 res = WaitForSingleObject(p->test_finished, INFINITE);
2826 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2828 DestroyWindow(p->window);
2829 return 0;
2832 static void test_SetForegroundWindow(HWND hwnd)
2834 struct create_window_thread_params thread_params;
2835 HANDLE thread;
2836 DWORD res, tid;
2837 BOOL ret;
2838 HWND hwnd2;
2839 MSG msg;
2840 LONG style;
2842 flush_events( TRUE );
2843 ShowWindow(hwnd, SW_HIDE);
2844 SetFocus(0);
2845 SetActiveWindow(0);
2846 check_wnd_state(0, 0, 0, 0);
2848 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2850 ShowWindow(hwnd, SW_SHOW);
2851 check_wnd_state(hwnd, hwnd, hwnd, 0);
2853 hwnd2 = SetActiveWindow(0);
2854 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2855 if (GetActiveWindow() == hwnd) /* doesn't always work on vista */
2856 check_wnd_state(hwnd, hwnd, hwnd, 0);
2857 else
2858 check_wnd_state(0, 0, 0, 0);
2860 ret = SetForegroundWindow(hwnd);
2861 if (!ret)
2863 skip( "SetForegroundWindow not working\n" );
2864 return;
2866 check_wnd_state(hwnd, hwnd, hwnd, 0);
2868 SetLastError(0xdeadbeef);
2869 ret = SetForegroundWindow(0);
2870 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2871 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
2872 broken(GetLastError() == 0xdeadbeef), /* win9x */
2873 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2874 check_wnd_state(hwnd, hwnd, hwnd, 0);
2876 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2877 check_wnd_state(hwnd, hwnd, hwnd, 0);
2879 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2880 check_wnd_state(hwnd, hwnd, hwnd, 0);
2882 hwnd2 = GetForegroundWindow();
2883 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2884 ret = SetForegroundWindow( GetDesktopWindow() );
2885 ok(ret, "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2886 hwnd2 = GetForegroundWindow();
2887 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2889 ShowWindow(hwnd, SW_HIDE);
2890 check_wnd_state(0, 0, 0, 0);
2892 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2893 ret = SetForegroundWindow(hwnd);
2894 ok(ret || broken(!ret), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
2895 check_wnd_state(hwnd, hwnd, hwnd, 0);
2897 ShowWindow(hwnd, SW_SHOW);
2898 check_wnd_state(hwnd, hwnd, hwnd, 0);
2900 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2901 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2903 DestroyWindow(hwnd2);
2904 check_wnd_state(hwnd, hwnd, hwnd, 0);
2906 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2907 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2909 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2910 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2912 DestroyWindow(hwnd2);
2913 check_wnd_state(hwnd, hwnd, hwnd, 0);
2915 hwnd2 = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
2916 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2918 thread_params.window_created = CreateEventW(NULL, FALSE, FALSE, NULL);
2919 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
2920 thread_params.test_finished = CreateEventW(NULL, FALSE, FALSE, NULL);
2921 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
2922 thread = CreateThread(NULL, 0, create_window_thread, &thread_params, 0, &tid);
2923 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
2924 res = WaitForSingleObject(thread_params.window_created, INFINITE);
2925 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2926 check_wnd_state(hwnd2, thread_params.window, hwnd2, 0);
2928 SetForegroundWindow(hwnd2);
2929 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2931 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2932 if (0) check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2933 todo_wine ok(GetActiveWindow() == hwnd2, "Expected active window %p, got %p.\n", hwnd2, GetActiveWindow());
2934 todo_wine ok(GetFocus() == hwnd2, "Expected focus window %p, got %p.\n", hwnd2, GetFocus());
2936 SetForegroundWindow(hwnd);
2937 check_wnd_state(hwnd, hwnd, hwnd, 0);
2938 style = GetWindowLongA(hwnd2, GWL_STYLE) | WS_CHILD;
2939 ok(SetWindowLongA(hwnd2, GWL_STYLE, style), "SetWindowLong failed\n");
2940 ok(SetForegroundWindow(hwnd2), "SetForegroundWindow failed\n");
2941 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2943 SetForegroundWindow(hwnd);
2944 check_wnd_state(hwnd, hwnd, hwnd, 0);
2945 ok(SetWindowLongA(hwnd2, GWL_STYLE, style & (~WS_POPUP)), "SetWindowLong failed\n");
2946 ok(!SetForegroundWindow(hwnd2), "SetForegroundWindow failed\n");
2947 check_wnd_state(hwnd, hwnd, hwnd, 0);
2949 SetEvent(thread_params.test_finished);
2950 WaitForSingleObject(thread, INFINITE);
2951 CloseHandle(thread_params.test_finished);
2952 CloseHandle(thread_params.window_created);
2953 CloseHandle(thread);
2954 DestroyWindow(hwnd2);
2957 static WNDPROC old_button_proc;
2959 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2961 LRESULT ret;
2962 USHORT key_state;
2964 key_state = GetKeyState(VK_LBUTTON);
2965 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2967 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2969 if (msg == WM_LBUTTONDOWN)
2971 HWND hwnd, capture;
2973 check_wnd_state(button, button, button, button);
2975 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2976 assert(hwnd);
2977 trace("hwnd %p\n", hwnd);
2979 check_wnd_state(button, button, button, button);
2981 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2983 check_wnd_state(button, button, button, button);
2985 DestroyWindow(hwnd);
2987 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2988 assert(hwnd);
2989 trace("hwnd %p\n", hwnd);
2991 check_wnd_state(button, button, button, button);
2993 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2994 * match internal button state.
2996 SendMessageA(button, WM_KILLFOCUS, 0, 0);
2997 check_wnd_state(button, button, button, 0);
2999 ShowWindow(hwnd, SW_SHOW);
3000 check_wnd_state(hwnd, hwnd, hwnd, 0);
3002 capture = SetCapture(hwnd);
3003 ok(capture == 0, "SetCapture() = %p\n", capture);
3005 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
3007 DestroyWindow(hwnd);
3009 check_wnd_state(button, 0, button, 0);
3012 return ret;
3015 static void test_capture_1(void)
3017 HWND button, capture;
3019 capture = GetCapture();
3020 ok(capture == 0, "GetCapture() = %p\n", capture);
3022 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
3023 assert(button);
3024 trace("button %p\n", button);
3026 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
3028 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
3030 capture = SetCapture(button);
3031 ok(capture == 0, "SetCapture() = %p\n", capture);
3032 check_wnd_state(button, 0, button, button);
3034 DestroyWindow(button);
3035 /* old active window test depends on previously executed window
3036 * activation tests, and fails under NT4.
3037 check_wnd_state(oldActive, 0, oldFocus, 0);*/
3040 static void test_capture_2(void)
3042 HWND button, hwnd, capture, oldFocus, oldActive;
3044 oldFocus = GetFocus();
3045 oldActive = GetActiveWindow();
3046 check_wnd_state(oldActive, 0, oldFocus, 0);
3048 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
3049 assert(button);
3050 trace("button %p\n", button);
3052 check_wnd_state(button, button, button, 0);
3054 capture = SetCapture(button);
3055 ok(capture == 0, "SetCapture() = %p\n", capture);
3057 check_wnd_state(button, button, button, button);
3059 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
3060 * internal button state.
3062 SendMessageA(button, WM_KILLFOCUS, 0, 0);
3063 check_wnd_state(button, button, button, button);
3065 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
3066 assert(hwnd);
3067 trace("hwnd %p\n", hwnd);
3069 check_wnd_state(button, button, button, button);
3071 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
3073 check_wnd_state(button, button, button, button);
3075 DestroyWindow(hwnd);
3077 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
3078 assert(hwnd);
3079 trace("hwnd %p\n", hwnd);
3081 check_wnd_state(button, button, button, button);
3083 ShowWindow(hwnd, SW_SHOW);
3085 check_wnd_state(hwnd, hwnd, hwnd, button);
3087 capture = SetCapture(hwnd);
3088 ok(capture == button, "SetCapture() = %p\n", capture);
3090 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
3092 DestroyWindow(hwnd);
3093 check_wnd_state(button, button, button, 0);
3095 DestroyWindow(button);
3096 check_wnd_state(oldActive, 0, oldFocus, 0);
3099 static void test_capture_3(HWND hwnd1, HWND hwnd2)
3101 BOOL ret;
3103 ShowWindow(hwnd1, SW_HIDE);
3104 ShowWindow(hwnd2, SW_HIDE);
3106 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
3107 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
3109 SetCapture(hwnd1);
3110 check_wnd_state(0, 0, 0, hwnd1);
3112 SetCapture(hwnd2);
3113 check_wnd_state(0, 0, 0, hwnd2);
3115 ShowWindow(hwnd1, SW_SHOW);
3116 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
3118 ret = ReleaseCapture();
3119 ok (ret, "releasecapture did not return TRUE.\n");
3120 ret = ReleaseCapture();
3121 ok (ret, "releasecapture did not return TRUE after second try.\n");
3124 static LRESULT CALLBACK test_capture_4_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3126 GUITHREADINFO gti;
3127 HWND cap_wnd, cap_wnd2, set_cap_wnd;
3128 BOOL status;
3129 switch (msg)
3131 case WM_CAPTURECHANGED:
3133 /* now try to release capture from menu. this should fail */
3134 if (pGetGUIThreadInfo)
3136 memset(&gti, 0, sizeof(GUITHREADINFO));
3137 gti.cbSize = sizeof(GUITHREADINFO);
3138 status = pGetGUIThreadInfo(GetCurrentThreadId(), &gti);
3139 ok(status, "GetGUIThreadInfo() failed!\n");
3140 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
3142 cap_wnd = GetCapture();
3144 ok(cap_wnd == (HWND)lParam, "capture window %p does not match lparam %lx\n", cap_wnd, lParam);
3145 todo_wine ok(cap_wnd == hWnd, "capture window %p does not match hwnd %p\n", cap_wnd, hWnd);
3147 /* check that re-setting the capture for the menu fails */
3148 set_cap_wnd = SetCapture(cap_wnd);
3149 ok(!set_cap_wnd || broken(set_cap_wnd == cap_wnd), /* nt4 */
3150 "SetCapture should have failed!\n");
3151 if (set_cap_wnd)
3153 DestroyWindow(hWnd);
3154 break;
3157 /* check that SetCapture fails for another window and that it does not touch the error code */
3158 set_cap_wnd = SetCapture(hWnd);
3159 ok(!set_cap_wnd, "SetCapture should have failed!\n");
3161 /* check that ReleaseCapture fails and does not touch the error code */
3162 status = ReleaseCapture();
3163 ok(!status, "ReleaseCapture should have failed!\n");
3165 /* check that thread info did not change */
3166 if (pGetGUIThreadInfo)
3168 memset(&gti, 0, sizeof(GUITHREADINFO));
3169 gti.cbSize = sizeof(GUITHREADINFO);
3170 status = pGetGUIThreadInfo(GetCurrentThreadId(), &gti);
3171 ok(status, "GetGUIThreadInfo() failed!\n");
3172 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
3175 /* verify that no capture change took place */
3176 cap_wnd2 = GetCapture();
3177 ok(cap_wnd2 == cap_wnd, "Capture changed!\n");
3179 /* we are done. kill the window */
3180 DestroyWindow(hWnd);
3181 break;
3183 default:
3184 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
3186 return 0;
3189 /* Test that no-one can mess around with the current capture while a menu is open */
3190 static void test_capture_4(void)
3192 BOOL ret;
3193 HMENU hmenu;
3194 HWND hwnd;
3195 WNDCLASSA wclass;
3196 HINSTANCE hInstance = GetModuleHandleA( NULL );
3197 ATOM aclass;
3199 if (!pGetGUIThreadInfo)
3201 win_skip("GetGUIThreadInfo is not available\n");
3202 return;
3204 wclass.lpszClassName = "TestCapture4Class";
3205 wclass.style = CS_HREDRAW | CS_VREDRAW;
3206 wclass.lpfnWndProc = test_capture_4_proc;
3207 wclass.hInstance = hInstance;
3208 wclass.hIcon = LoadIconA( 0, (LPCSTR)IDI_APPLICATION );
3209 wclass.hCursor = LoadCursorA( 0, (LPCSTR)IDC_ARROW );
3210 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
3211 wclass.lpszMenuName = 0;
3212 wclass.cbClsExtra = 0;
3213 wclass.cbWndExtra = 0;
3214 aclass = RegisterClassA( &wclass );
3215 ok( aclass, "RegisterClassA failed with error %d\n", GetLastError());
3216 hwnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
3217 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
3218 400, 200, NULL, NULL, hInstance, NULL);
3219 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
3220 if (!hwnd) return;
3221 hmenu = CreatePopupMenu();
3223 ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest2");
3224 ok( ret, "AppendMenuA has failed!\n");
3226 /* set main window to have initial capture */
3227 SetCapture(hwnd);
3229 if (is_win9x)
3231 win_skip("TrackPopupMenu test crashes on Win9x/WinMe\n");
3233 else
3235 /* create popup (it will self-destruct) */
3236 ret = TrackPopupMenu(hmenu, TPM_RETURNCMD, 100, 100, 0, hwnd, NULL);
3237 ok( ret == 0, "TrackPopupMenu returned %d expected zero\n", ret);
3240 /* clean up */
3241 DestroyMenu(hmenu);
3242 DestroyWindow(hwnd);
3245 /* PeekMessage wrapper that ignores the messages we don't care about */
3246 static BOOL peek_message( MSG *msg )
3248 BOOL ret;
3251 ret = PeekMessageA(msg, 0, 0, 0, PM_REMOVE);
3252 } while (ret && (msg->message == WM_TIMER || ignore_message(msg->message)));
3253 return ret;
3256 static void test_keyboard_input(HWND hwnd)
3258 MSG msg;
3259 BOOL ret;
3261 flush_events( TRUE );
3262 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
3263 UpdateWindow(hwnd);
3264 flush_events( TRUE );
3266 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
3268 SetFocus(hwnd);
3269 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
3271 flush_events( TRUE );
3273 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
3274 ret = peek_message(&msg);
3275 ok( ret, "no message available\n");
3276 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3277 ret = peek_message(&msg);
3278 ok( !ret, "message %04x available\n", msg.message);
3280 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
3282 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
3283 ret = peek_message(&msg);
3284 ok(ret, "no message available\n");
3285 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3286 ret = peek_message(&msg);
3287 ok( !ret, "message %04x available\n", msg.message);
3289 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
3291 keybd_event(VK_SPACE, 0, 0, 0);
3292 if (!peek_message(&msg))
3294 skip( "keybd_event didn't work, skipping keyboard test\n" );
3295 return;
3297 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3298 ret = peek_message(&msg);
3299 ok( !ret, "message %04x available\n", msg.message);
3301 SetFocus(0);
3302 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3304 flush_events( TRUE );
3306 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
3307 ret = peek_message(&msg);
3308 ok(ret, "no message available\n");
3309 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3310 ret = peek_message(&msg);
3311 ok( !ret, "message %04x available\n", msg.message);
3313 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3315 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
3316 ret = peek_message(&msg);
3317 ok(ret, "no message available\n");
3318 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3319 ret = peek_message(&msg);
3320 ok( !ret, "message %04x available\n", msg.message);
3322 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3324 keybd_event(VK_SPACE, 0, 0, 0);
3325 ret = peek_message(&msg);
3326 ok(ret, "no message available\n");
3327 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3328 ret = peek_message(&msg);
3329 ok( !ret, "message %04x available\n", msg.message);
3332 static BOOL wait_for_message( MSG *msg )
3334 BOOL ret;
3336 for (;;)
3338 ret = peek_message(msg);
3339 if (ret)
3341 if (msg->message == WM_PAINT) DispatchMessageA(msg);
3342 else break;
3344 else if (MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
3346 if (!ret) msg->message = 0;
3347 return ret;
3350 static void test_mouse_input(HWND hwnd)
3352 RECT rc;
3353 POINT pt;
3354 int x, y;
3355 HWND popup;
3356 MSG msg;
3357 BOOL ret;
3358 LRESULT res;
3360 ShowWindow(hwnd, SW_SHOWNORMAL);
3361 UpdateWindow(hwnd);
3362 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3364 GetWindowRect(hwnd, &rc);
3365 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
3367 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
3368 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
3369 hwnd, 0, 0, NULL);
3370 assert(popup != 0);
3371 ShowWindow(popup, SW_SHOW);
3372 UpdateWindow(popup);
3373 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3375 GetWindowRect(popup, &rc);
3376 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
3378 x = rc.left + (rc.right - rc.left) / 2;
3379 y = rc.top + (rc.bottom - rc.top) / 2;
3380 trace("setting cursor to (%d,%d)\n", x, y);
3382 SetCursorPos(x, y);
3383 GetCursorPos(&pt);
3384 if (x != pt.x || y != pt.y)
3386 skip( "failed to set mouse position, skipping mouse input tests\n" );
3387 goto done;
3390 flush_events( TRUE );
3392 /* Check that setting the same position may generate WM_MOUSEMOVE */
3393 SetCursorPos(x, y);
3394 msg.message = 0;
3395 ret = peek_message(&msg);
3396 if (ret)
3398 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
3399 msg.hwnd, msg.message);
3400 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
3401 x, y, msg.pt.x, msg.pt.y);
3404 /* force the system to update its internal queue mouse position,
3405 * otherwise it won't generate relative mouse movements below.
3407 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3408 flush_events( TRUE );
3410 msg.message = 0;
3411 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3412 flush_events( FALSE );
3413 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
3414 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
3416 if (msg.message == WM_TIMER || ignore_message(msg.message)) continue;
3417 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
3418 "hwnd %p message %04x\n", msg.hwnd, msg.message);
3419 DispatchMessageA(&msg);
3421 ret = peek_message(&msg);
3422 ok( !ret, "message %04x available\n", msg.message);
3424 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3425 ShowWindow(popup, SW_HIDE);
3426 ret = wait_for_message( &msg );
3427 if (ret)
3428 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3429 flush_events( TRUE );
3431 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3432 ShowWindow(hwnd, SW_HIDE);
3433 ret = wait_for_message( &msg );
3434 ok( !ret, "message %04x available\n", msg.message);
3435 flush_events( TRUE );
3437 /* test mouse clicks */
3439 ShowWindow(hwnd, SW_SHOW);
3440 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3441 flush_events( TRUE );
3442 ShowWindow(popup, SW_SHOW);
3443 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3444 flush_events( TRUE );
3446 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3447 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3448 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3449 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3451 ret = wait_for_message( &msg );
3452 if (!ret)
3454 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
3455 goto done;
3457 if (msg.message == WM_MOUSEMOVE) /* win2k has an extra WM_MOUSEMOVE here */
3459 ret = wait_for_message( &msg );
3460 ok(ret, "no message available\n");
3463 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3464 msg.hwnd, popup, msg.message);
3466 ret = wait_for_message( &msg );
3467 ok(ret, "no message available\n");
3468 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3469 msg.hwnd, popup, msg.message);
3471 ret = wait_for_message( &msg );
3472 ok(ret, "no message available\n");
3473 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
3474 msg.hwnd, popup, msg.message);
3476 ret = wait_for_message( &msg );
3477 ok(ret, "no message available\n");
3478 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3479 msg.hwnd, popup, msg.message);
3481 ret = peek_message(&msg);
3482 ok(!ret, "message %04x available\n", msg.message);
3484 ShowWindow(popup, SW_HIDE);
3485 flush_events( TRUE );
3487 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3488 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3489 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3490 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3492 ret = wait_for_message( &msg );
3493 ok(ret, "no message available\n");
3494 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3495 msg.hwnd, hwnd, msg.message);
3496 ret = wait_for_message( &msg );
3497 ok(ret, "no message available\n");
3498 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3499 msg.hwnd, hwnd, msg.message);
3501 test_lbuttondown_flag = TRUE;
3502 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
3503 test_lbuttondown_flag = FALSE;
3505 ret = wait_for_message( &msg );
3506 ok(ret, "no message available\n");
3507 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3508 msg.hwnd, popup, msg.message);
3509 ok(peek_message(&msg), "no message available\n");
3510 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3511 msg.hwnd, popup, msg.message);
3512 ok(peek_message(&msg), "no message available\n");
3514 /* Test WM_MOUSEACTIVATE */
3515 #define TEST_MOUSEACTIVATE(A,B) \
3516 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
3517 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
3519 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
3520 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
3521 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
3522 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
3523 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
3524 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
3525 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
3526 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
3527 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
3528 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
3529 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
3530 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
3531 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
3532 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
3533 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
3534 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
3535 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
3536 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
3537 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
3538 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
3539 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
3540 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
3541 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
3542 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
3544 done:
3545 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
3546 flush_events( TRUE );
3548 DestroyWindow(popup);
3551 static void test_validatergn(HWND hwnd)
3553 HWND child;
3554 RECT rc, rc2;
3555 HRGN rgn;
3556 int ret;
3557 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
3558 ShowWindow(hwnd, SW_SHOW);
3559 UpdateWindow( hwnd);
3560 /* test that ValidateRect validates children*/
3561 InvalidateRect( child, NULL, 1);
3562 GetWindowRect( child, &rc);
3563 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3564 ret = GetUpdateRect( child, &rc2, 0);
3565 ok( ret == 1, "Expected GetUpdateRect to return non-zero, got %d\n", ret);
3566 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
3567 "Update rectangle is empty!\n");
3568 ValidateRect( hwnd, &rc);
3569 ret = GetUpdateRect( child, &rc2, 0);
3570 ok( !ret, "Expected GetUpdateRect to return zero, got %d\n", ret);
3571 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3572 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3573 rc2.right, rc2.bottom);
3575 /* now test ValidateRgn */
3576 InvalidateRect( child, NULL, 1);
3577 GetWindowRect( child, &rc);
3578 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3579 rgn = CreateRectRgnIndirect( &rc);
3580 ValidateRgn( hwnd, rgn);
3581 ret = GetUpdateRect( child, &rc2, 0);
3582 ok( !ret, "Expected GetUpdateRect to return zero, got %d\n", ret);
3583 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3584 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3585 rc2.right, rc2.bottom);
3587 DeleteObject( rgn);
3588 DestroyWindow( child );
3591 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
3593 RECT rc;
3594 MoveWindow( hwnd, 0, 0, x, y, 0);
3595 GetWindowRect( hwnd, prc);
3596 rc = *prc;
3597 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
3598 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
3599 rc.left,rc.top,rc.right,rc.bottom, prc->left,prc->top,prc->right,prc->bottom);
3602 static void test_nccalcscroll(HWND parent)
3604 RECT rc1;
3605 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
3606 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
3607 HWND hwnd = CreateWindowExA(0, "static", NULL,
3608 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
3609 10, 10, 200, 200, parent, 0, 0, NULL);
3610 ShowWindow( parent, SW_SHOW);
3611 UpdateWindow( parent);
3613 /* test window too low for a horizontal scroll bar */
3614 nccalchelper( hwnd, 100, sbheight, &rc1);
3615 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
3616 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
3618 /* test window just high enough for a horizontal scroll bar */
3619 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
3620 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
3621 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3623 /* test window too narrow for a vertical scroll bar */
3624 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
3625 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
3626 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3628 /* test window just wide enough for a vertical scroll bar */
3629 nccalchelper( hwnd, sbwidth, 100, &rc1);
3630 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
3631 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
3633 /* same test, but with client edge: not enough width */
3634 SetWindowLongA( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLongA( hwnd, GWL_EXSTYLE));
3635 nccalchelper( hwnd, sbwidth, 100, &rc1);
3636 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
3637 "Width should be %d size is %d,%d - %d,%d\n",
3638 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
3640 DestroyWindow( hwnd);
3643 static void test_SetParent(void)
3645 HWND desktop = GetDesktopWindow();
3646 HMENU hMenu;
3647 HWND ret, parent, child1, child2, child3, child4, sibling, popup;
3648 BOOL bret;
3650 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3651 100, 100, 200, 200, 0, 0, 0, NULL);
3652 assert(parent != 0);
3653 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3654 0, 0, 50, 50, parent, 0, 0, NULL);
3655 assert(child1 != 0);
3656 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3657 0, 0, 50, 50, child1, 0, 0, NULL);
3658 assert(child2 != 0);
3659 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3660 0, 0, 50, 50, child2, 0, 0, NULL);
3661 assert(child3 != 0);
3662 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3663 0, 0, 50, 50, child3, 0, 0, NULL);
3664 assert(child4 != 0);
3666 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
3667 parent, child1, child2, child3, child4);
3669 check_parents(parent, desktop, 0, 0, 0, parent, parent);
3670 check_parents(child1, parent, parent, parent, 0, parent, parent);
3671 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3672 check_parents(child3, child2, child2, child2, 0, child2, parent);
3673 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3675 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
3676 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
3677 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3678 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
3679 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3681 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
3682 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3683 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
3684 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
3685 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
3686 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
3687 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
3688 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3689 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3691 if (!is_win9x) /* Win9x doesn't survive this test */
3693 ok(!SetParent(parent, child1), "SetParent should fail\n");
3694 ok(!SetParent(child2, child3), "SetParent should fail\n");
3695 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
3696 ret = SetParent(parent, child2);
3697 todo_wine ok( !ret || broken( ret != 0 ), "SetParent should fail\n");
3698 if (ret) /* nt4, win2k */
3700 ret = SetParent(parent, child3);
3701 ok(ret != 0, "SetParent should not fail\n");
3702 ret = SetParent(child2, parent);
3703 ok(!ret, "SetParent should fail\n");
3704 ret = SetParent(parent, child4);
3705 ok(ret != 0, "SetParent should not fail\n");
3706 check_parents(parent, child4, child4, 0, 0, child4, parent);
3707 check_parents(child1, parent, parent, parent, 0, child4, parent);
3708 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3709 check_parents(child3, child2, child2, child2, 0, child2, parent);
3710 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3712 else
3714 ret = SetParent(parent, child3);
3715 ok(ret != 0, "SetParent should not fail\n");
3716 ret = SetParent(child2, parent);
3717 ok(!ret, "SetParent should fail\n");
3718 ret = SetParent(parent, child4);
3719 ok(!ret, "SetParent should fail\n");
3720 check_parents(parent, child3, child3, 0, 0, child2, parent);
3721 check_parents(child1, parent, parent, parent, 0, child2, parent);
3722 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3723 check_parents(child3, child2, child2, child2, 0, child2, parent);
3724 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3727 else
3728 skip("Win9x/WinMe crash\n");
3730 hMenu = CreateMenu();
3731 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3732 100, 100, 200, 200, 0, hMenu, 0, NULL);
3733 assert(sibling != 0);
3735 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
3736 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
3738 ok(SetParent(parent, desktop) != 0, "SetParent should not fail\n");
3739 ok(SetParent(child4, child3) != 0, "SetParent should not fail\n");
3740 ok(SetParent(child3, child2) != 0, "SetParent should not fail\n");
3741 ok(SetParent(child2, child1) != 0, "SetParent should not fail\n");
3742 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3743 SetWindowLongW(child4, GWL_STYLE, WS_CHILD);
3744 ok(IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3745 ok(IsChild(child2, child4), "wrong parent/child %p/%p\n", child2, child4);
3746 ok(!IsChild(child1, child4), "wrong parent/child %p/%p\n", child1, child4);
3747 SetWindowLongW(child2, GWL_STYLE, WS_CHILD);
3748 ok(IsChild(child1, child4), "wrong parent/child %p/%p\n", child1, child4);
3749 ok(IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
3751 ok(DestroyWindow(parent), "DestroyWindow() failed\n");
3753 ok(!IsWindow(parent), "parent still exists\n");
3754 ok(!IsWindow(sibling), "sibling still exists\n");
3755 ok(!IsWindow(child1), "child1 still exists\n");
3756 ok(!IsWindow(child2), "child2 still exists\n");
3757 ok(!IsWindow(child3), "child3 still exists\n");
3758 ok(!IsWindow(child4), "child4 still exists\n");
3760 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3761 100, 100, 200, 200, 0, 0, 0, NULL);
3762 assert(parent != 0);
3763 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3764 0, 0, 50, 50, parent, 0, 0, NULL);
3765 assert(child1 != 0);
3766 popup = CreateWindowExA(0, "static", NULL, WS_POPUP,
3767 0, 0, 50, 50, 0, 0, 0, NULL);
3768 assert(popup != 0);
3770 trace("parent %p, child %p, popup %p\n", parent, child1, popup);
3772 check_parents(parent, desktop, 0, 0, 0, parent, parent);
3773 check_parents(child1, parent, parent, parent, 0, parent, parent);
3774 check_parents(popup, desktop, 0, 0, 0, popup, popup);
3776 SetActiveWindow(parent);
3777 SetFocus(parent);
3778 check_active_state(parent, 0, parent);
3780 ret = SetParent(popup, child1);
3781 ok(ret == desktop, "expected %p, got %p\n", desktop, ret);
3782 check_parents(popup, child1, child1, 0, 0, parent, popup);
3783 check_active_state(popup, 0, popup);
3785 SetActiveWindow(parent);
3786 SetFocus(popup);
3787 check_active_state(popup, 0, popup);
3789 EnableWindow(child1, FALSE);
3790 check_active_state(popup, 0, popup);
3791 SetFocus(parent);
3792 check_active_state(parent, 0, parent);
3793 SetFocus(popup);
3794 check_active_state(popup, 0, popup);
3795 EnableWindow(child1, TRUE);
3797 ShowWindow(child1, SW_MINIMIZE);
3798 SetFocus(parent);
3799 check_active_state(parent, 0, parent);
3800 SetFocus(popup);
3801 check_active_state(popup, 0, popup);
3802 ShowWindow(child1, SW_HIDE);
3804 SetActiveWindow(parent);
3805 SetFocus(parent);
3806 check_active_state(parent, 0, parent);
3808 bret = SetForegroundWindow(popup);
3809 ok(bret, "SetForegroundWindow() failed\n");
3810 check_active_state(popup, popup, popup);
3812 ShowWindow(parent, SW_SHOW);
3813 SetActiveWindow(popup);
3814 ok(DestroyWindow(popup), "DestroyWindow() failed\n");
3815 check_active_state(parent, parent, parent);
3817 ok(DestroyWindow(parent), "DestroyWindow() failed\n");
3819 ok(!IsWindow(parent), "parent still exists\n");
3820 ok(!IsWindow(child1), "child1 still exists\n");
3821 ok(!IsWindow(popup), "popup still exists\n");
3824 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3826 LPCREATESTRUCTA lpcs;
3827 LPSTYLESTRUCT lpss;
3829 switch (msg)
3831 case WM_NCCREATE:
3832 case WM_CREATE:
3833 lpcs = (LPCREATESTRUCTA)lparam;
3834 lpss = lpcs->lpCreateParams;
3835 if (lpss)
3837 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
3838 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
3839 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
3840 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
3841 else
3842 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3844 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
3845 "Ex style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3846 lpss->styleOld, lpcs->dwExStyle);
3848 ok(lpss->styleNew == lpcs->style,
3849 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3850 lpss->styleNew, lpcs->style);
3852 break;
3854 return DefWindowProcA(hwnd, msg, wparam, lparam);
3857 static ATOM atomStyleCheckClass;
3859 static void register_style_check_class(void)
3861 WNDCLASSA wc =
3864 StyleCheckProc,
3867 GetModuleHandleA(NULL),
3868 NULL,
3869 LoadCursorA(0, (LPCSTR)IDC_ARROW),
3870 (HBRUSH)(COLOR_BTNFACE+1),
3871 NULL,
3872 "WineStyleCheck",
3875 atomStyleCheckClass = RegisterClassA(&wc);
3876 assert(atomStyleCheckClass);
3879 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3881 DWORD dwActualStyle;
3882 DWORD dwActualExStyle;
3883 STYLESTRUCT ss;
3884 HWND hwnd;
3885 HWND hwndParent = NULL;
3887 ss.styleNew = dwStyleIn;
3888 ss.styleOld = dwExStyleIn;
3890 if (dwStyleIn & WS_CHILD)
3892 hwndParent = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomStyleCheckClass), NULL,
3893 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3896 hwnd = CreateWindowExA(dwExStyleIn, (LPCSTR)MAKEINTATOM(atomStyleCheckClass), NULL,
3897 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3898 assert(hwnd);
3900 flush_events( TRUE );
3902 dwActualStyle = GetWindowLongA(hwnd, GWL_STYLE);
3903 dwActualExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3904 ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
3905 ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
3907 /* try setting the styles explicitly */
3908 SetWindowLongA( hwnd, GWL_EXSTYLE, dwExStyleIn );
3909 dwActualStyle = GetWindowLongA(hwnd, GWL_STYLE);
3910 dwActualExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3911 /* WS_EX_WINDOWEDGE can't always be changed */
3912 if (dwExStyleIn & WS_EX_DLGMODALFRAME)
3913 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3914 else if ((dwActualStyle & (WS_DLGFRAME | WS_THICKFRAME)) && !(dwExStyleIn & WS_EX_STATICEDGE))
3915 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3916 else
3917 dwExStyleOut = dwExStyleIn & ~WS_EX_WINDOWEDGE;
3918 ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
3919 ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
3921 SetWindowLongA( hwnd, GWL_STYLE, dwStyleIn );
3922 dwActualStyle = GetWindowLongA(hwnd, GWL_STYLE);
3923 dwActualExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3924 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3925 if ((dwStyleIn & (WS_CHILD|WS_POPUP)) == WS_CHILD) dwStyleOut = dwStyleIn;
3926 else dwStyleOut = dwStyleIn | WS_CLIPSIBLINGS;
3927 /* WS_EX_WINDOWEDGE can't always be changed */
3928 if (dwExStyleIn & WS_EX_DLGMODALFRAME)
3929 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3930 else if ((dwActualStyle & (WS_DLGFRAME | WS_THICKFRAME)) && !(dwExStyleIn & WS_EX_STATICEDGE))
3931 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3932 else
3933 dwExStyleOut = dwExStyleIn & ~WS_EX_WINDOWEDGE;
3934 ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
3935 /* FIXME: Remove the condition below once Wine is fixed */
3936 if (dwActualExStyle != dwExStyleOut)
3937 todo_wine ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
3938 else
3939 ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
3941 DestroyWindow(hwnd);
3942 if (hwndParent) DestroyWindow(hwndParent);
3945 /* tests what window styles the window manager automatically adds */
3946 static void test_window_styles(void)
3948 register_style_check_class();
3950 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3951 check_window_style(WS_DLGFRAME, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3952 check_window_style(WS_THICKFRAME, 0, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3953 check_window_style(WS_DLGFRAME, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE);
3954 check_window_style(WS_THICKFRAME, WS_EX_STATICEDGE, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE);
3955 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3956 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3957 check_window_style(WS_CHILD|WS_DLGFRAME, 0, WS_CHILD|WS_DLGFRAME, WS_EX_WINDOWEDGE);
3958 check_window_style(WS_CHILD|WS_THICKFRAME, 0, WS_CHILD|WS_THICKFRAME, WS_EX_WINDOWEDGE);
3959 check_window_style(WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE);
3960 check_window_style(WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE);
3961 check_window_style(WS_CHILD|WS_CAPTION, 0, WS_CHILD|WS_CAPTION, WS_EX_WINDOWEDGE);
3962 check_window_style(WS_CHILD|WS_CAPTION|WS_SYSMENU, 0, WS_CHILD|WS_CAPTION|WS_SYSMENU, WS_EX_WINDOWEDGE);
3963 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3964 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3965 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3966 check_window_style(WS_CHILD|WS_POPUP, 0, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
3967 check_window_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, 0, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3968 check_window_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, 0, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3969 check_window_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3970 check_window_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3971 check_window_style(WS_CHILD|WS_POPUP, WS_EX_APPWINDOW, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, WS_EX_APPWINDOW);
3972 check_window_style(WS_CHILD|WS_POPUP, WS_EX_WINDOWEDGE, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
3973 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3974 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3975 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3976 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3977 check_window_style(WS_POPUP|WS_DLGFRAME, 0, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3978 check_window_style(WS_POPUP|WS_THICKFRAME, 0, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3979 check_window_style(WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3980 check_window_style(WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3981 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3982 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3984 if (pGetLayeredWindowAttributes)
3986 check_window_style(0, WS_EX_LAYERED, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_WINDOWEDGE);
3987 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_WINDOWEDGE);
3988 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION,
3989 WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW|WS_EX_WINDOWEDGE);
3993 static INT_PTR WINAPI empty_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3995 return 0;
3998 static void check_dialog_style(DWORD style_in, DWORD ex_style_in, DWORD style_out, DWORD ex_style_out)
4000 struct
4002 DLGTEMPLATE dt;
4003 WORD menu_name;
4004 WORD class_id;
4005 WORD class_atom;
4006 WCHAR caption[1];
4007 } dlg_data;
4008 DWORD style, ex_style;
4009 HWND hwnd, parent = 0;
4011 if (style_in & WS_CHILD)
4012 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
4013 0, 0, 0, 0, NULL, NULL, NULL, NULL);
4015 dlg_data.dt.style = style_in;
4016 dlg_data.dt.dwExtendedStyle = ex_style_in;
4017 dlg_data.dt.cdit = 0;
4018 dlg_data.dt.x = 0;
4019 dlg_data.dt.y = 0;
4020 dlg_data.dt.cx = 100;
4021 dlg_data.dt.cy = 100;
4022 dlg_data.menu_name = 0;
4023 dlg_data.class_id = 0;
4024 dlg_data.class_atom = 0;
4025 dlg_data.caption[0] = 0;
4027 hwnd = CreateDialogIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, parent, empty_dlg_proc, 0);
4028 ok(hwnd != 0, "dialog creation failed, style %#x, exstyle %#x\n", style_in, ex_style_in);
4030 flush_events( TRUE );
4032 style = GetWindowLongA(hwnd, GWL_STYLE);
4033 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
4034 ok(style == (style_out | DS_3DLOOK), "got %#x\n", style);
4035 ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
4037 /* try setting the styles explicitly */
4038 SetWindowLongA(hwnd, GWL_EXSTYLE, ex_style_in);
4039 style = GetWindowLongA(hwnd, GWL_STYLE);
4040 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
4041 ok(style == (style_out | DS_3DLOOK), "got %#x\n", style);
4042 /* WS_EX_WINDOWEDGE can't always be changed */
4043 if (ex_style_in & WS_EX_DLGMODALFRAME)
4044 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
4045 else if ((style & (WS_DLGFRAME | WS_THICKFRAME)) && !(ex_style_in & WS_EX_STATICEDGE))
4046 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
4047 else
4048 ex_style_out = ex_style_in & ~WS_EX_WINDOWEDGE;
4049 ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
4051 SetWindowLongA(hwnd, GWL_STYLE, style_in);
4052 style = GetWindowLongA(hwnd, GWL_STYLE);
4053 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
4054 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
4055 if ((style_in & (WS_CHILD | WS_POPUP)) == WS_CHILD) style_out = style_in;
4056 else style_out = style_in | WS_CLIPSIBLINGS;
4057 ok(style == style_out, "expected style %#x, got %#x\n", style_out, style);
4058 /* WS_EX_WINDOWEDGE can't always be changed */
4059 if (ex_style_in & WS_EX_DLGMODALFRAME)
4060 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
4061 else if ((style & (WS_DLGFRAME | WS_THICKFRAME)) && !(ex_style_in & WS_EX_STATICEDGE))
4062 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
4063 else
4064 ex_style_out = ex_style_in & ~WS_EX_WINDOWEDGE;
4065 /* FIXME: Remove the condition below once Wine is fixed */
4066 if (ex_style != ex_style_out)
4067 todo_wine ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
4068 else
4069 ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
4071 DestroyWindow(hwnd);
4072 DestroyWindow(parent);
4075 static void test_dialog_styles(void)
4077 check_dialog_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4078 check_dialog_style(WS_DLGFRAME, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4079 check_dialog_style(WS_THICKFRAME, 0, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4080 check_dialog_style(WS_DLGFRAME, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4081 check_dialog_style(WS_THICKFRAME, WS_EX_STATICEDGE, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4082 check_dialog_style(DS_CONTROL, 0, WS_CLIPSIBLINGS|WS_CAPTION|DS_CONTROL, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4083 check_dialog_style(WS_CAPTION, 0, WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4084 check_dialog_style(WS_BORDER, 0, WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4085 check_dialog_style(WS_DLGFRAME, 0, WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4086 check_dialog_style(WS_BORDER|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4087 check_dialog_style(WS_DLGFRAME|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4088 check_dialog_style(WS_CAPTION|WS_SYSMENU, 0, WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4089 check_dialog_style(WS_SYSMENU, 0, WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4090 check_dialog_style(WS_CAPTION|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4091 check_dialog_style(WS_SYSMENU|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4092 check_dialog_style(WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4093 check_dialog_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4094 check_dialog_style(WS_CHILD, 0, WS_CHILD, 0);
4095 check_dialog_style(WS_CHILD|WS_DLGFRAME, 0, WS_CHILD|WS_DLGFRAME, WS_EX_WINDOWEDGE);
4096 check_dialog_style(WS_CHILD|WS_THICKFRAME, 0, WS_CHILD|WS_THICKFRAME, WS_EX_WINDOWEDGE);
4097 check_dialog_style(WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE);
4098 check_dialog_style(WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE);
4099 check_dialog_style(WS_CHILD|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4100 check_dialog_style(WS_CHILD|WS_CAPTION, 0, WS_CHILD|WS_CAPTION, WS_EX_WINDOWEDGE);
4101 check_dialog_style(WS_CHILD|WS_BORDER, 0, WS_CHILD|WS_BORDER, 0);
4102 check_dialog_style(WS_CHILD|WS_DLGFRAME, 0, WS_CHILD|WS_DLGFRAME, WS_EX_WINDOWEDGE);
4103 check_dialog_style(WS_CHILD|WS_BORDER|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4104 check_dialog_style(WS_CHILD|WS_DLGFRAME|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4105 check_dialog_style(WS_CHILD|WS_CAPTION|WS_SYSMENU, 0, WS_CHILD|WS_CAPTION|WS_SYSMENU, WS_EX_WINDOWEDGE);
4106 check_dialog_style(WS_CHILD|WS_SYSMENU, 0, WS_CHILD|WS_SYSMENU, 0);
4107 check_dialog_style(WS_CHILD|WS_CAPTION|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4108 check_dialog_style(WS_CHILD|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4109 check_dialog_style(WS_CHILD|WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4110 check_dialog_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
4111 check_dialog_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
4112 check_dialog_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
4113 check_dialog_style(WS_CHILD|WS_POPUP, 0, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
4114 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, 0, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4115 check_dialog_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, 0, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4116 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
4117 check_dialog_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
4118 check_dialog_style(WS_CHILD|WS_POPUP|DS_CONTROL, 0, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS|DS_CONTROL, WS_EX_CONTROLPARENT);
4119 check_dialog_style(WS_CHILD|WS_POPUP|WS_CAPTION, 0, WS_CHILD|WS_POPUP|WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4120 check_dialog_style(WS_CHILD|WS_POPUP|WS_BORDER, 0, WS_CHILD|WS_POPUP|WS_BORDER|WS_CLIPSIBLINGS, 0);
4121 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, 0, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4122 check_dialog_style(WS_CHILD|WS_POPUP|WS_BORDER|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4123 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4124 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);
4125 check_dialog_style(WS_CHILD|WS_POPUP|WS_SYSMENU, 0, WS_CHILD|WS_POPUP|WS_SYSMENU|WS_CLIPSIBLINGS, 0);
4126 check_dialog_style(WS_CHILD|WS_POPUP|WS_CAPTION|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4127 check_dialog_style(WS_CHILD|WS_POPUP|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4128 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);
4129 check_dialog_style(WS_CHILD|WS_POPUP, WS_EX_APPWINDOW, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, WS_EX_APPWINDOW);
4130 check_dialog_style(WS_CHILD|WS_POPUP, WS_EX_WINDOWEDGE, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
4131 check_dialog_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
4132 check_dialog_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW|WS_EX_CONTROLPARENT);
4133 check_dialog_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4134 check_dialog_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4135 check_dialog_style(WS_POPUP|WS_DLGFRAME, 0, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4136 check_dialog_style(WS_POPUP|WS_THICKFRAME, 0, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4137 check_dialog_style(WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4138 check_dialog_style(WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4139 check_dialog_style(WS_POPUP|DS_CONTROL, 0, WS_POPUP|WS_CLIPSIBLINGS|DS_CONTROL, WS_EX_CONTROLPARENT);
4140 check_dialog_style(WS_POPUP|WS_CAPTION, 0, WS_POPUP|WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4141 check_dialog_style(WS_POPUP|WS_BORDER, 0, WS_POPUP|WS_BORDER|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4142 check_dialog_style(WS_POPUP|WS_DLGFRAME, 0, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4143 check_dialog_style(WS_POPUP|WS_BORDER|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4144 check_dialog_style(WS_POPUP|WS_DLGFRAME|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4145 check_dialog_style(WS_POPUP|WS_CAPTION|WS_SYSMENU, 0, WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4146 check_dialog_style(WS_POPUP|WS_SYSMENU, 0, WS_POPUP|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4147 check_dialog_style(WS_POPUP|WS_CAPTION|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4148 check_dialog_style(WS_POPUP|WS_SYSMENU|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4149 check_dialog_style(WS_POPUP|WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4150 check_dialog_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4151 check_dialog_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4153 if (pGetLayeredWindowAttributes)
4155 check_dialog_style(0, WS_EX_LAYERED, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4156 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);
4157 check_dialog_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION,
4158 WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4162 static void test_scrollwindow( HWND hwnd)
4164 HDC hdc;
4165 RECT rc, rc2, rc3;
4166 COLORREF colr;
4168 ShowWindow( hwnd, SW_SHOW);
4169 UpdateWindow( hwnd);
4170 flush_events( TRUE );
4171 GetClientRect( hwnd, &rc);
4172 hdc = GetDC( hwnd);
4173 /* test ScrollWindow(Ex) with no clip rectangle */
4174 /* paint the lower half of the window black */
4175 rc2 = rc;
4176 rc2.top = ( rc2.top + rc2.bottom) / 2;
4177 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4178 /* paint the upper half of the window white */
4179 rc2.bottom = rc2.top;
4180 rc2.top =0;
4181 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
4182 /* scroll lower half up */
4183 rc2 = rc;
4184 rc2.top = ( rc2.top + rc2.bottom) / 2;
4185 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, NULL, NULL, NULL, SW_ERASE);
4186 flush_events(FALSE);
4187 /* expected: black should have scrolled to the upper half */
4188 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
4189 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4190 /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
4191 /* paint the lower half of the window black */
4192 rc2 = rc;
4193 rc2.top = ( rc2.top + rc2.bottom) / 2;
4194 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4195 /* paint the upper half of the window white */
4196 rc2.bottom = rc2.top;
4197 rc2.top =0;
4198 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
4199 /* scroll lower half up */
4200 rc2 = rc;
4201 rc2.top = ( rc2.top + rc2.bottom) / 2;
4202 rc3 = rc;
4203 rc3.left = rc3.right / 4;
4204 rc3.right -= rc3.right / 4;
4205 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, &rc3, NULL, NULL, SW_ERASE);
4206 flush_events(FALSE);
4207 /* expected: black should have scrolled to the upper half */
4208 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
4209 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4211 /* clean up */
4212 ReleaseDC( hwnd, hdc);
4215 static void test_scrollvalidate( HWND parent)
4217 HDC hdc;
4218 HRGN hrgn=CreateRectRgn(0,0,0,0);
4219 HRGN exprgn, tmprgn, clipping;
4220 RECT rc, rcu, cliprc;
4221 /* create two overlapping child windows. The visual region
4222 * of hwnd1 is clipped by the overlapping part of
4223 * hwnd2 because of the WS_CLIPSIBLING style */
4224 HWND hwnd1, hwnd2;
4226 clipping = CreateRectRgn(0,0,0,0);
4227 tmprgn = CreateRectRgn(0,0,0,0);
4228 exprgn = CreateRectRgn(0,0,0,0);
4229 hwnd2 = CreateWindowExA(0, "static", NULL,
4230 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
4231 75, 30, 100, 100, parent, 0, 0, NULL);
4232 hwnd1 = CreateWindowExA(0, "static", NULL,
4233 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
4234 25, 50, 100, 100, parent, 0, 0, NULL);
4235 ShowWindow( parent, SW_SHOW);
4236 UpdateWindow( parent);
4237 GetClientRect( hwnd1, &rc);
4238 cliprc=rc;
4239 SetRectRgn( clipping, 10, 10, 90, 90);
4240 hdc = GetDC( hwnd1);
4241 /* for a visual touch */
4242 TextOutA( hdc, 0,10, "0123456789", 10);
4243 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
4244 if (winetest_debug > 0) dump_region(hrgn);
4245 /* create a region with what is expected */
4246 SetRectRgn( exprgn, 39,0,49,74);
4247 SetRectRgn( tmprgn, 88,79,98,93);
4248 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4249 SetRectRgn( tmprgn, 0,93,98,98);
4250 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4251 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4252 trace("update rect is %d,%d - %d,%d\n",
4253 rcu.left,rcu.top,rcu.right,rcu.bottom);
4254 /* now with clipping region */
4255 SelectClipRgn( hdc, clipping);
4256 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
4257 if (winetest_debug > 0) dump_region(hrgn);
4258 /* create a region with what is expected */
4259 SetRectRgn( exprgn, 39,10,49,74);
4260 SetRectRgn( tmprgn, 80,79,90,85);
4261 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4262 SetRectRgn( tmprgn, 10,85,90,90);
4263 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4264 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4265 trace("update rect is %d,%d - %d,%d\n",
4266 rcu.left,rcu.top,rcu.right,rcu.bottom);
4267 ReleaseDC( hwnd1, hdc);
4269 /* test scrolling a window with an update region */
4270 DestroyWindow( hwnd2);
4271 ValidateRect( hwnd1, NULL);
4272 SetRect( &rc, 40,40, 50,50);
4273 InvalidateRect( hwnd1, &rc, 1);
4274 GetClientRect( hwnd1, &rc);
4275 cliprc=rc;
4276 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
4277 SW_SCROLLCHILDREN | SW_INVALIDATE);
4278 if (winetest_debug > 0) dump_region(hrgn);
4279 SetRectRgn( exprgn, 88,0,98,98);
4280 SetRectRgn( tmprgn, 30, 40, 50, 50);
4281 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4282 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4284 /* clear an update region */
4285 UpdateWindow( hwnd1 );
4287 SetRect( &rc, 0,40, 100,60);
4288 SetRect( &cliprc, 0,0, 100,100);
4289 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
4290 if (winetest_debug > 0) dump_region( hrgn );
4291 SetRectRgn( exprgn, 0, 40, 98, 60 );
4292 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
4294 /* now test ScrollWindowEx with a combination of
4295 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
4296 /* make hwnd2 the child of hwnd1 */
4297 hwnd2 = CreateWindowExA(0, "static", NULL,
4298 WS_CHILD| WS_VISIBLE | WS_BORDER ,
4299 50, 50, 100, 100, hwnd1, 0, 0, NULL);
4300 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
4301 GetClientRect( hwnd1, &rc);
4302 cliprc=rc;
4304 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
4305 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
4306 ValidateRect( hwnd1, NULL);
4307 ValidateRect( hwnd2, NULL);
4308 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
4309 SW_SCROLLCHILDREN | SW_INVALIDATE);
4310 if (winetest_debug > 0) dump_region(hrgn);
4311 SetRectRgn( exprgn, 88,0,98,88);
4312 SetRectRgn( tmprgn, 0,88,98,98);
4313 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4314 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4316 /* SW_SCROLLCHILDREN */
4317 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
4318 ValidateRect( hwnd1, NULL);
4319 ValidateRect( hwnd2, NULL);
4320 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
4321 if (winetest_debug > 0) dump_region(hrgn);
4322 /* expected region is the same as in previous test */
4323 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4325 /* no SW_SCROLLCHILDREN */
4326 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
4327 ValidateRect( hwnd1, NULL);
4328 ValidateRect( hwnd2, NULL);
4329 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
4330 if (winetest_debug > 0) dump_region(hrgn);
4331 /* expected region is the same as in previous test */
4332 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4334 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
4335 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
4336 ValidateRect( hwnd1, NULL);
4337 ValidateRect( hwnd2, NULL);
4338 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
4339 if (winetest_debug > 0) dump_region(hrgn);
4340 SetRectRgn( exprgn, 88,0,98,20);
4341 SetRectRgn( tmprgn, 20,20,98,30);
4342 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4343 SetRectRgn( tmprgn, 20,30,30,88);
4344 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4345 SetRectRgn( tmprgn, 0,88,30,98);
4346 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4347 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4349 /* clean up */
4350 DeleteObject( hrgn);
4351 DeleteObject( exprgn);
4352 DeleteObject( tmprgn);
4353 DestroyWindow( hwnd1);
4354 DestroyWindow( hwnd2);
4357 /* couple of tests of return values of scrollbar functions
4358 * called on a scrollbarless window */
4359 static void test_scroll(void)
4361 BOOL ret;
4362 INT min, max;
4363 SCROLLINFO si;
4364 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
4365 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
4366 100, 100, 200, 200, 0, 0, 0, NULL);
4367 /* horizontal */
4368 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
4369 if (!ret) /* win9x */
4371 win_skip( "GetScrollRange doesn't work\n" );
4372 DestroyWindow( hwnd);
4373 return;
4375 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
4376 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
4377 si.cbSize = sizeof( si);
4378 si.fMask = SIF_PAGE;
4379 si.nPage = 0xdeadbeef;
4380 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
4381 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
4382 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
4383 /* vertical */
4384 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
4385 ok( ret, "GetScrollRange returns FALSE\n");
4386 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
4387 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
4388 si.cbSize = sizeof( si);
4389 si.fMask = SIF_PAGE;
4390 si.nPage = 0xdeadbeef;
4391 ret = GetScrollInfo( hwnd, SB_VERT, &si);
4392 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
4393 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
4394 /* clean up */
4395 DestroyWindow( hwnd);
4398 static void test_scrolldc( HWND parent)
4400 HDC hdc;
4401 HRGN exprgn, tmprgn, hrgn;
4402 RECT rc, rc2, rcu, cliprc;
4403 HWND hwnd1;
4404 COLORREF colr;
4406 hrgn = CreateRectRgn(0,0,0,0);
4407 tmprgn = CreateRectRgn(0,0,0,0);
4408 exprgn = CreateRectRgn(0,0,0,0);
4410 hwnd1 = CreateWindowExA(0, "static", NULL,
4411 WS_CHILD| WS_VISIBLE,
4412 25, 50, 100, 100, parent, 0, 0, NULL);
4413 ShowWindow( parent, SW_SHOW);
4414 UpdateWindow( parent);
4415 flush_events( TRUE );
4416 GetClientRect( hwnd1, &rc);
4417 hdc = GetDC( hwnd1);
4418 /* paint the upper half of the window black */
4419 rc2 = rc;
4420 rc2.bottom = ( rc.top + rc.bottom) /2;
4421 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4422 /* clip region is the lower half */
4423 cliprc=rc;
4424 cliprc.top = (rc.top + rc.bottom) /2;
4425 /* test whether scrolled pixels are properly clipped */
4426 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
4427 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4428 /* this scroll should not cause any visible changes */
4429 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
4430 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
4431 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4432 /* test with NULL clip rect */
4433 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
4434 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
4435 trace("update rect: %d,%d - %d,%d\n",
4436 rcu.left, rcu.top, rcu.right, rcu.bottom);
4437 if (winetest_debug > 0) dump_region(hrgn);
4438 SetRect(&rc2, 0, 0, 100, 100);
4439 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
4440 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
4442 SetRectRgn( exprgn, 0, 0, 20, 80);
4443 SetRectRgn( tmprgn, 0, 80, 100, 100);
4444 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
4445 if (winetest_debug > 0) dump_region(exprgn);
4446 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
4447 /* test clip rect > scroll rect */
4448 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
4449 rc2=rc;
4450 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
4451 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4452 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
4453 SetRectRgn( exprgn, 25, 25, 75, 35);
4454 SetRectRgn( tmprgn, 25, 35, 35, 75);
4455 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
4456 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
4457 trace("update rect: %d,%d - %d,%d\n",
4458 rcu.left, rcu.top, rcu.right, rcu.bottom);
4459 if (winetest_debug > 0) dump_region(hrgn);
4461 /* clean up */
4462 DeleteObject(hrgn);
4463 DeleteObject(exprgn);
4464 DeleteObject(tmprgn);
4465 DestroyWindow(hwnd1);
4468 static void test_params(void)
4470 HWND hwnd;
4471 INT rc;
4473 ok(!IsWindow(0), "IsWindow(0)\n");
4474 ok(!IsWindow(HWND_BROADCAST), "IsWindow(HWND_BROADCAST)\n");
4475 ok(!IsWindow(HWND_TOPMOST), "IsWindow(HWND_TOPMOST)\n");
4477 /* Just a param check */
4478 if (pGetMonitorInfoA)
4480 SetLastError(0xdeadbeef);
4481 rc = GetWindowTextA(hwndMain2, NULL, 1024);
4482 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
4484 else
4486 /* Skips actually on Win95 and NT4 */
4487 win_skip("Test would crash on Win95\n");
4490 SetLastError(0xdeadbeef);
4491 hwnd=CreateWindowA("LISTBOX", "TestList",
4492 (LBS_STANDARD & ~LBS_SORT),
4493 0, 0, 100, 100,
4494 NULL, (HMENU)1, NULL, 0);
4496 ok(!hwnd || broken(hwnd != NULL), /* w2k3 sp2 */
4497 "CreateWindow with invalid menu handle should fail\n");
4498 if (!hwnd)
4499 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
4500 GetLastError() == 0xdeadbeef, /* Win9x */
4501 "wrong last error value %d\n", GetLastError());
4504 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
4506 HWND hwnd = 0;
4508 hwnd = CreateWindowExA(exStyle, class, class, style,
4509 110, 100,
4510 225, 200,
4512 menu ? hmenu : 0,
4513 0, 0);
4514 if (!hwnd) {
4515 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
4516 return;
4518 ShowWindow(hwnd, SW_SHOW);
4520 test_nonclient_area(hwnd);
4522 SetMenu(hwnd, 0);
4523 DestroyWindow(hwnd);
4526 static BOOL AWR_init(void)
4528 WNDCLASSA class;
4530 class.style = CS_HREDRAW | CS_VREDRAW;
4531 class.lpfnWndProc = DefWindowProcA;
4532 class.cbClsExtra = 0;
4533 class.cbWndExtra = 0;
4534 class.hInstance = 0;
4535 class.hIcon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
4536 class.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
4537 class.hbrBackground = 0;
4538 class.lpszMenuName = 0;
4539 class.lpszClassName = szAWRClass;
4541 if (!RegisterClassA(&class)) {
4542 ok(FALSE, "RegisterClass failed\n");
4543 return FALSE;
4546 hmenu = CreateMenu();
4547 if (!hmenu)
4548 return FALSE;
4549 ok(hmenu != 0, "Failed to create menu\n");
4550 ok(AppendMenuA(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
4552 return TRUE;
4556 static void test_AWR_window_size(BOOL menu)
4558 LONG styles[] = {
4559 WS_POPUP,
4560 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
4561 WS_SYSMENU,
4562 WS_THICKFRAME,
4563 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
4564 WS_HSCROLL, WS_VSCROLL
4566 LONG exStyles[] = {
4567 WS_EX_CLIENTEDGE,
4568 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
4569 WS_EX_APPWINDOW,
4570 #if 0
4571 /* These styles have problems on (at least) WinXP (SP2) and Wine */
4572 WS_EX_DLGMODALFRAME,
4573 WS_EX_STATICEDGE,
4574 #endif
4577 int i;
4579 /* A exhaustive check of all the styles takes too long
4580 * so just do a (hopefully representative) sample
4582 for (i = 0; i < COUNTOF(styles); ++i)
4583 test_AWRwindow(szAWRClass, styles[i], 0, menu);
4584 for (i = 0; i < COUNTOF(exStyles); ++i) {
4585 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
4586 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
4589 #undef COUNTOF
4591 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
4593 static void test_AdjustWindowRect(void)
4595 if (!AWR_init())
4596 return;
4598 SHOWSYSMETRIC(SM_CYCAPTION);
4599 SHOWSYSMETRIC(SM_CYSMCAPTION);
4600 SHOWSYSMETRIC(SM_CYMENU);
4601 SHOWSYSMETRIC(SM_CXEDGE);
4602 SHOWSYSMETRIC(SM_CYEDGE);
4603 SHOWSYSMETRIC(SM_CXVSCROLL);
4604 SHOWSYSMETRIC(SM_CYHSCROLL);
4605 SHOWSYSMETRIC(SM_CXFRAME);
4606 SHOWSYSMETRIC(SM_CYFRAME);
4607 SHOWSYSMETRIC(SM_CXDLGFRAME);
4608 SHOWSYSMETRIC(SM_CYDLGFRAME);
4609 SHOWSYSMETRIC(SM_CXBORDER);
4610 SHOWSYSMETRIC(SM_CYBORDER);
4612 test_AWR_window_size(FALSE);
4613 test_AWR_window_size(TRUE);
4615 DestroyMenu(hmenu);
4617 #undef SHOWSYSMETRIC
4620 /* Global variables to trigger exit from loop */
4621 static int redrawComplete, WMPAINT_count;
4623 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4625 switch (msg)
4627 case WM_PAINT:
4628 trace("doing WM_PAINT %d\n", WMPAINT_count);
4629 WMPAINT_count++;
4630 if (WMPAINT_count > 10 && redrawComplete == 0) {
4631 PAINTSTRUCT ps;
4632 BeginPaint(hwnd, &ps);
4633 EndPaint(hwnd, &ps);
4634 return 1;
4636 return 0;
4638 return DefWindowProcA(hwnd, msg, wparam, lparam);
4641 /* Ensure we exit from RedrawNow regardless of invalidated area */
4642 static void test_redrawnow(void)
4644 WNDCLASSA cls;
4645 HWND hwndMain;
4647 cls.style = CS_DBLCLKS;
4648 cls.lpfnWndProc = redraw_window_procA;
4649 cls.cbClsExtra = 0;
4650 cls.cbWndExtra = 0;
4651 cls.hInstance = GetModuleHandleA(0);
4652 cls.hIcon = 0;
4653 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
4654 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4655 cls.lpszMenuName = NULL;
4656 cls.lpszClassName = "RedrawWindowClass";
4658 if(!RegisterClassA(&cls)) {
4659 trace("Register failed %d\n", GetLastError());
4660 return;
4663 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
4664 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
4666 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4667 ShowWindow(hwndMain, SW_SHOW);
4668 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4669 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
4670 ok( WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
4671 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4672 redrawComplete = TRUE;
4673 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
4675 /* clean up */
4676 DestroyWindow( hwndMain);
4679 struct parentdc_stat {
4680 RECT client;
4681 RECT clip;
4682 RECT paint;
4685 struct parentdc_test {
4686 struct parentdc_stat main, main_todo;
4687 struct parentdc_stat child1, child1_todo;
4688 struct parentdc_stat child2, child2_todo;
4691 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4693 RECT rc;
4694 PAINTSTRUCT ps;
4696 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
4698 switch (msg)
4700 case WM_PAINT:
4701 GetClientRect(hwnd, &rc);
4702 CopyRect(&t->client, &rc);
4703 GetWindowRect(hwnd, &rc);
4704 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd,
4705 t->client.left, t->client.top, t->client.right, t->client.bottom,
4706 rc.left, rc.top, rc.right, rc.bottom);
4707 BeginPaint(hwnd, &ps);
4708 CopyRect(&t->paint, &ps.rcPaint);
4709 GetClipBox(ps.hdc, &rc);
4710 CopyRect(&t->clip, &rc);
4711 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
4712 rc.left, rc.top, rc.right, rc.bottom,
4713 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
4714 EndPaint(hwnd, &ps);
4715 return 0;
4717 return DefWindowProcA(hwnd, msg, wparam, lparam);
4720 static void zero_parentdc_stat(struct parentdc_stat *t)
4722 SetRectEmpty(&t->client);
4723 SetRectEmpty(&t->clip);
4724 SetRectEmpty(&t->paint);
4727 static void zero_parentdc_test(struct parentdc_test *t)
4729 zero_parentdc_stat(&t->main);
4730 zero_parentdc_stat(&t->child1);
4731 zero_parentdc_stat(&t->child2);
4734 #define parentdc_field_ok(t, w, r, f, got) \
4735 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
4736 ": expected %d, got %d\n", \
4737 t.w.r.f, got.w.r.f)
4739 #define parentdc_todo_field_ok(t, w, r, f, got) \
4740 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
4741 else parentdc_field_ok(t, w, r, f, got)
4743 #define parentdc_rect_ok(t, w, r, got) \
4744 parentdc_todo_field_ok(t, w, r, left, got); \
4745 parentdc_todo_field_ok(t, w, r, top, got); \
4746 parentdc_todo_field_ok(t, w, r, right, got); \
4747 parentdc_todo_field_ok(t, w, r, bottom, got);
4749 #define parentdc_win_ok(t, w, got) \
4750 parentdc_rect_ok(t, w, client, got); \
4751 parentdc_rect_ok(t, w, clip, got); \
4752 parentdc_rect_ok(t, w, paint, got);
4754 #define parentdc_ok(t, got) \
4755 parentdc_win_ok(t, main, got); \
4756 parentdc_win_ok(t, child1, got); \
4757 parentdc_win_ok(t, child2, got);
4759 static void test_csparentdc(void)
4761 WNDCLASSA clsMain, cls;
4762 HWND hwndMain, hwnd1, hwnd2;
4763 RECT rc;
4765 struct parentdc_test test_answer;
4767 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
4768 const struct parentdc_test test1 =
4770 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
4771 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4772 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4775 const struct parentdc_test test2 =
4777 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
4778 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4779 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4782 const struct parentdc_test test3 =
4784 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4785 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4786 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4789 const struct parentdc_test test4 =
4791 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
4792 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
4793 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4796 const struct parentdc_test test5 =
4798 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
4799 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4800 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4803 const struct parentdc_test test6 =
4805 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4806 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4807 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4810 const struct parentdc_test test7 =
4812 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4813 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4814 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4816 #undef nothing_todo
4818 clsMain.style = CS_DBLCLKS;
4819 clsMain.lpfnWndProc = parentdc_window_procA;
4820 clsMain.cbClsExtra = 0;
4821 clsMain.cbWndExtra = 0;
4822 clsMain.hInstance = GetModuleHandleA(0);
4823 clsMain.hIcon = 0;
4824 clsMain.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
4825 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
4826 clsMain.lpszMenuName = NULL;
4827 clsMain.lpszClassName = "ParentDcMainWindowClass";
4829 if(!RegisterClassA(&clsMain)) {
4830 trace("Register failed %d\n", GetLastError());
4831 return;
4834 cls.style = CS_DBLCLKS | CS_PARENTDC;
4835 cls.lpfnWndProc = parentdc_window_procA;
4836 cls.cbClsExtra = 0;
4837 cls.cbWndExtra = 0;
4838 cls.hInstance = GetModuleHandleA(0);
4839 cls.hIcon = 0;
4840 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
4841 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4842 cls.lpszMenuName = NULL;
4843 cls.lpszClassName = "ParentDcWindowClass";
4845 if(!RegisterClassA(&cls)) {
4846 trace("Register failed %d\n", GetLastError());
4847 return;
4850 SetRect(&rc, 0, 0, 150, 150);
4851 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
4852 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
4853 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
4854 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
4855 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
4856 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
4857 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
4858 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
4859 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
4860 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
4861 ShowWindow(hwndMain, SW_SHOW);
4862 ShowWindow(hwnd1, SW_SHOW);
4863 ShowWindow(hwnd2, SW_SHOW);
4864 SetWindowPos(hwndMain, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
4865 flush_events( TRUE );
4867 zero_parentdc_test(&test_answer);
4868 InvalidateRect(hwndMain, NULL, TRUE);
4869 flush_events( TRUE );
4870 parentdc_ok(test1, test_answer);
4872 zero_parentdc_test(&test_answer);
4873 SetRect(&rc, 0, 0, 50, 50);
4874 InvalidateRect(hwndMain, &rc, TRUE);
4875 flush_events( TRUE );
4876 parentdc_ok(test2, test_answer);
4878 zero_parentdc_test(&test_answer);
4879 SetRect(&rc, 0, 0, 10, 10);
4880 InvalidateRect(hwndMain, &rc, TRUE);
4881 flush_events( TRUE );
4882 parentdc_ok(test3, test_answer);
4884 zero_parentdc_test(&test_answer);
4885 SetRect(&rc, 40, 40, 50, 50);
4886 InvalidateRect(hwndMain, &rc, TRUE);
4887 flush_events( TRUE );
4888 parentdc_ok(test4, test_answer);
4890 zero_parentdc_test(&test_answer);
4891 SetRect(&rc, 20, 20, 60, 60);
4892 InvalidateRect(hwndMain, &rc, TRUE);
4893 flush_events( TRUE );
4894 parentdc_ok(test5, test_answer);
4896 zero_parentdc_test(&test_answer);
4897 SetRect(&rc, 0, 0, 10, 10);
4898 InvalidateRect(hwnd1, &rc, TRUE);
4899 flush_events( TRUE );
4900 parentdc_ok(test6, test_answer);
4902 zero_parentdc_test(&test_answer);
4903 SetRect(&rc, -5, -5, 65, 65);
4904 InvalidateRect(hwnd1, &rc, TRUE);
4905 flush_events( TRUE );
4906 parentdc_ok(test7, test_answer);
4908 DestroyWindow(hwndMain);
4909 DestroyWindow(hwnd1);
4910 DestroyWindow(hwnd2);
4913 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4915 return DefWindowProcA(hwnd, msg, wparam, lparam);
4918 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4920 return DefWindowProcW(hwnd, msg, wparam, lparam);
4923 static void test_IsWindowUnicode(void)
4925 static const char ansi_class_nameA[] = "ansi class name";
4926 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
4927 static const char unicode_class_nameA[] = "unicode class name";
4928 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
4929 WNDCLASSA classA;
4930 WNDCLASSW classW;
4931 HWND hwnd;
4932 ATOM atom;
4934 memset(&classW, 0, sizeof(classW));
4935 classW.hInstance = GetModuleHandleA(0);
4936 classW.lpfnWndProc = def_window_procW;
4937 classW.lpszClassName = unicode_class_nameW;
4938 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
4940 memset(&classA, 0, sizeof(classA));
4941 classA.hInstance = GetModuleHandleA(0);
4942 classA.lpfnWndProc = def_window_procA;
4943 classA.lpszClassName = ansi_class_nameA;
4944 atom = RegisterClassA(&classA);
4945 assert(atom);
4947 /* unicode class: window proc */
4948 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4949 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4950 assert(hwnd);
4952 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4953 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4954 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4955 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4956 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4958 DestroyWindow(hwnd);
4960 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4961 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4962 assert(hwnd);
4964 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4965 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4966 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4967 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4968 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4970 DestroyWindow(hwnd);
4972 /* ansi class: window proc */
4973 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4974 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4975 assert(hwnd);
4977 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4978 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4979 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4980 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4981 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4983 DestroyWindow(hwnd);
4985 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4986 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4987 assert(hwnd);
4989 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4990 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4991 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4992 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4993 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4995 DestroyWindow(hwnd);
4997 /* unicode class: class proc */
4998 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4999 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
5000 assert(hwnd);
5002 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5003 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
5004 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5005 /* do not restore class window proc back to unicode */
5007 DestroyWindow(hwnd);
5009 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
5010 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
5011 assert(hwnd);
5013 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5014 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
5015 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5017 DestroyWindow(hwnd);
5019 /* ansi class: class proc */
5020 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
5021 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
5022 assert(hwnd);
5024 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5025 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
5026 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5027 /* do not restore class window proc back to ansi */
5029 DestroyWindow(hwnd);
5031 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
5032 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
5033 assert(hwnd);
5035 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5036 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
5037 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5039 DestroyWindow(hwnd);
5042 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
5044 MINMAXINFO *minmax;
5046 if (msg != WM_GETMINMAXINFO)
5047 return DefWindowProcA(hwnd, msg, wp, lp);
5049 minmax = (MINMAXINFO *)lp;
5051 if ((GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
5053 minmax->ptReserved.x = 0;
5054 minmax->ptReserved.y = 0;
5055 minmax->ptMaxSize.x = 400;
5056 minmax->ptMaxSize.y = 400;
5057 minmax->ptMaxPosition.x = 300;
5058 minmax->ptMaxPosition.y = 300;
5059 minmax->ptMaxTrackSize.x = 200;
5060 minmax->ptMaxTrackSize.y = 200;
5061 minmax->ptMinTrackSize.x = 100;
5062 minmax->ptMinTrackSize.y = 100;
5064 else
5065 DefWindowProcA(hwnd, msg, wp, lp);
5066 return 1;
5069 static int expected_cx, expected_cy;
5070 static RECT expected_rect, broken_rect;
5072 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
5074 switch(msg)
5076 case WM_GETMINMAXINFO:
5078 RECT rect;
5079 GetWindowRect( hwnd, &rect );
5080 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
5081 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
5082 return DefWindowProcA(hwnd, msg, wp, lp);
5084 case WM_NCCREATE:
5085 case WM_CREATE:
5087 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
5088 RECT rect;
5089 GetWindowRect( hwnd, &rect );
5090 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
5091 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
5092 ok( cs->cx == expected_cx || broken(cs->cx == (short)expected_cx),
5093 "wrong x size %d/%d\n", cs->cx, expected_cx );
5094 ok( cs->cy == expected_cy || broken(cs->cy == (short)expected_cy),
5095 "wrong y size %d/%d\n", cs->cy, expected_cy );
5096 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
5097 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
5098 (rect.right - rect.left == min( 65535, expected_rect.right - expected_rect.left ) &&
5099 rect.bottom - rect.top == min( 65535, expected_rect.bottom - expected_rect.top )) ||
5100 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
5101 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top) ||
5102 broken( rect.right - rect.left == (short)broken_rect.right - (short)broken_rect.left &&
5103 rect.bottom - rect.top == (short)broken_rect.bottom - (short)broken_rect.top),
5104 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
5105 rect.left, rect.top, rect.right, rect.bottom,
5106 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
5107 return DefWindowProcA(hwnd, msg, wp, lp);
5109 case WM_NCCALCSIZE:
5111 RECT rect, *r = (RECT *)lp;
5112 GetWindowRect( hwnd, &rect );
5113 ok( !memcmp( &rect, r, sizeof(rect) ),
5114 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
5115 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
5116 return DefWindowProcA(hwnd, msg, wp, lp);
5118 default:
5119 return DefWindowProcA(hwnd, msg, wp, lp);
5123 static void test_CreateWindow(void)
5125 WNDCLASSA cls;
5126 HWND hwnd, parent;
5127 HMENU hmenu;
5128 RECT rc, rc_minmax;
5129 MINMAXINFO minmax;
5130 BOOL res;
5132 #define expect_menu(window, menu) \
5133 SetLastError(0xdeadbeef); \
5134 res = (GetMenu(window) == (HMENU)menu); \
5135 ok(res, "GetMenu error %d\n", GetLastError())
5137 #define expect_style(window, style)\
5138 ok((ULONG)GetWindowLongA(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLongA(window, GWL_STYLE))
5140 #define expect_ex_style(window, ex_style)\
5141 ok((ULONG)GetWindowLongA(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLongA(window, GWL_EXSTYLE))
5143 #define expect_gle_broken_9x(gle)\
5144 ok(GetLastError() == gle ||\
5145 broken(GetLastError() == 0xdeadbeef),\
5146 "IsMenu set error %d\n", GetLastError())
5148 hmenu = CreateMenu();
5149 assert(hmenu != 0);
5150 parent = GetDesktopWindow();
5151 assert(parent != 0);
5153 SetLastError(0xdeadbeef);
5154 res = IsMenu(hmenu);
5155 ok(res, "IsMenu error %d\n", GetLastError());
5157 /* WS_CHILD */
5158 SetLastError(0xdeadbeef);
5159 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
5160 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5161 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5162 expect_menu(hwnd, 1);
5163 expect_style(hwnd, WS_CHILD);
5164 expect_ex_style(hwnd, WS_EX_APPWINDOW);
5165 DestroyWindow(hwnd);
5167 SetLastError(0xdeadbeef);
5168 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
5169 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5170 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5171 expect_menu(hwnd, 1);
5172 expect_style(hwnd, WS_CHILD | WS_CAPTION);
5173 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
5174 DestroyWindow(hwnd);
5176 SetLastError(0xdeadbeef);
5177 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD,
5178 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5179 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5180 expect_menu(hwnd, 1);
5181 expect_style(hwnd, WS_CHILD);
5182 expect_ex_style(hwnd, 0);
5183 DestroyWindow(hwnd);
5185 SetLastError(0xdeadbeef);
5186 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_CAPTION,
5187 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5188 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5189 expect_menu(hwnd, 1);
5190 expect_style(hwnd, WS_CHILD | WS_CAPTION);
5191 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5192 DestroyWindow(hwnd);
5194 /* WS_POPUP */
5195 SetLastError(0xdeadbeef);
5196 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
5197 0, 0, 100, 100, parent, hmenu, 0, NULL);
5198 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5199 expect_menu(hwnd, hmenu);
5200 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
5201 expect_ex_style(hwnd, WS_EX_APPWINDOW);
5202 DestroyWindow(hwnd);
5203 SetLastError(0xdeadbeef);
5204 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5205 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5207 hmenu = CreateMenu();
5208 assert(hmenu != 0);
5209 SetLastError(0xdeadbeef);
5210 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
5211 0, 0, 100, 100, parent, hmenu, 0, NULL);
5212 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5213 expect_menu(hwnd, hmenu);
5214 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5215 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
5216 DestroyWindow(hwnd);
5217 SetLastError(0xdeadbeef);
5218 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5219 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5221 hmenu = CreateMenu();
5222 assert(hmenu != 0);
5223 SetLastError(0xdeadbeef);
5224 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
5225 0, 0, 100, 100, parent, hmenu, 0, NULL);
5226 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5227 expect_menu(hwnd, hmenu);
5228 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
5229 expect_ex_style(hwnd, 0);
5230 DestroyWindow(hwnd);
5231 SetLastError(0xdeadbeef);
5232 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5233 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5235 hmenu = CreateMenu();
5236 assert(hmenu != 0);
5237 SetLastError(0xdeadbeef);
5238 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP | WS_CAPTION,
5239 0, 0, 100, 100, parent, hmenu, 0, NULL);
5240 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5241 expect_menu(hwnd, hmenu);
5242 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5243 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5244 DestroyWindow(hwnd);
5245 SetLastError(0xdeadbeef);
5246 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5247 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5249 /* WS_CHILD | WS_POPUP */
5250 SetLastError(0xdeadbeef);
5251 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
5252 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5253 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
5254 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5255 if (hwnd)
5256 DestroyWindow(hwnd);
5258 hmenu = CreateMenu();
5259 assert(hmenu != 0);
5260 SetLastError(0xdeadbeef);
5261 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
5262 0, 0, 100, 100, parent, hmenu, 0, NULL);
5263 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5264 expect_menu(hwnd, hmenu);
5265 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
5266 expect_ex_style(hwnd, WS_EX_APPWINDOW);
5267 DestroyWindow(hwnd);
5268 SetLastError(0xdeadbeef);
5269 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5270 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5272 SetLastError(0xdeadbeef);
5273 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
5274 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5275 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
5276 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5277 if (hwnd)
5278 DestroyWindow(hwnd);
5280 hmenu = CreateMenu();
5281 assert(hmenu != 0);
5282 SetLastError(0xdeadbeef);
5283 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
5284 0, 0, 100, 100, parent, hmenu, 0, NULL);
5285 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5286 expect_menu(hwnd, hmenu);
5287 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5288 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
5289 DestroyWindow(hwnd);
5290 SetLastError(0xdeadbeef);
5291 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5292 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5294 SetLastError(0xdeadbeef);
5295 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP,
5296 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5297 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
5298 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5299 if (hwnd)
5300 DestroyWindow(hwnd);
5302 hmenu = CreateMenu();
5303 assert(hmenu != 0);
5304 SetLastError(0xdeadbeef);
5305 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP,
5306 0, 0, 100, 100, parent, hmenu, 0, NULL);
5307 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5308 expect_menu(hwnd, hmenu);
5309 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
5310 expect_ex_style(hwnd, 0);
5311 DestroyWindow(hwnd);
5312 SetLastError(0xdeadbeef);
5313 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5314 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5316 SetLastError(0xdeadbeef);
5317 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
5318 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5319 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
5320 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5321 if (hwnd)
5322 DestroyWindow(hwnd);
5324 hmenu = CreateMenu();
5325 assert(hmenu != 0);
5326 SetLastError(0xdeadbeef);
5327 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
5328 0, 0, 100, 100, parent, hmenu, 0, NULL);
5329 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5330 expect_menu(hwnd, hmenu);
5331 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5332 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5333 DestroyWindow(hwnd);
5334 SetLastError(0xdeadbeef);
5335 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5336 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5338 /* test child window sizing */
5339 cls.style = 0;
5340 cls.lpfnWndProc = minmax_wnd_proc;
5341 cls.cbClsExtra = 0;
5342 cls.cbWndExtra = 0;
5343 cls.hInstance = GetModuleHandleA(NULL);
5344 cls.hIcon = 0;
5345 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
5346 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5347 cls.lpszMenuName = NULL;
5348 cls.lpszClassName = "MinMax_WndClass";
5349 RegisterClassA(&cls);
5351 SetLastError(0xdeadbeef);
5352 parent = CreateWindowExA(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
5353 0, 0, 100, 100, 0, 0, 0, NULL);
5354 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
5355 expect_menu(parent, 0);
5356 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
5357 expect_ex_style(parent, WS_EX_WINDOWEDGE);
5359 memset(&minmax, 0, sizeof(minmax));
5360 SendMessageA(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
5361 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
5362 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
5363 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
5364 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
5366 GetWindowRect(parent, &rc);
5367 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
5368 GetClientRect(parent, &rc);
5369 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
5371 InflateRect(&rc, 200, 200);
5372 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
5374 SetLastError(0xdeadbeef);
5375 hwnd = CreateWindowExA(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
5376 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
5377 parent, (HMENU)1, 0, NULL);
5378 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5379 expect_menu(hwnd, 1);
5380 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
5381 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5383 memset(&minmax, 0, sizeof(minmax));
5384 SendMessageA(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
5385 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
5387 GetWindowRect(hwnd, &rc);
5388 OffsetRect(&rc, -rc.left, -rc.top);
5389 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
5390 rc.left, rc.top, rc.right, rc.bottom,
5391 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
5392 DestroyWindow(hwnd);
5394 cls.lpfnWndProc = winsizes_wnd_proc;
5395 cls.lpszClassName = "Sizes_WndClass";
5396 RegisterClassA(&cls);
5398 expected_cx = expected_cy = 200000;
5399 SetRect( &expected_rect, 0, 0, 200000, 200000 );
5400 broken_rect = expected_rect;
5401 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
5402 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5403 GetClientRect( hwnd, &rc );
5404 ok( rc.right == 200000 || rc.right == 65535 || broken(rc.right == (short)200000),
5405 "invalid rect right %u\n", rc.right );
5406 ok( rc.bottom == 200000 || rc.bottom == 65535 || broken(rc.bottom == (short)200000),
5407 "invalid rect bottom %u\n", rc.bottom );
5408 DestroyWindow(hwnd);
5410 expected_cx = expected_cy = -10;
5411 SetRect( &expected_rect, 0, 0, 0, 0 );
5412 SetRect( &broken_rect, 0, 0, -10, -10 );
5413 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
5414 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5415 GetClientRect( hwnd, &rc );
5416 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
5417 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
5418 DestroyWindow(hwnd);
5420 expected_cx = expected_cy = -200000;
5421 SetRect( &expected_rect, 0, 0, 0, 0 );
5422 SetRect( &broken_rect, 0, 0, -200000, -200000 );
5423 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
5424 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5425 GetClientRect( hwnd, &rc );
5426 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
5427 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
5428 DestroyWindow(hwnd);
5430 /* we need a parent at 0,0 so that child coordinates match */
5431 DestroyWindow(parent);
5432 parent = CreateWindowExA(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
5433 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
5435 expected_cx = 100;
5436 expected_cy = 0x7fffffff;
5437 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
5438 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
5439 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
5440 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5441 GetClientRect( hwnd, &rc );
5442 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
5443 ok( rc.bottom == 0x7fffffff - 10 || rc.bottom ==65535 || broken(rc.bottom == 0),
5444 "invalid rect bottom %u\n", rc.bottom );
5445 DestroyWindow(hwnd);
5447 expected_cx = 0x7fffffff;
5448 expected_cy = 0x7fffffff;
5449 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
5450 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
5451 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
5452 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5453 GetClientRect( hwnd, &rc );
5454 ok( rc.right == 0x7fffffff - 20 || rc.right == 65535 || broken(rc.right == 0),
5455 "invalid rect right %u\n", rc.right );
5456 ok( rc.bottom == 0x7fffffff - 10 || rc.right == 65535 || broken(rc.bottom == 0),
5457 "invalid rect bottom %u\n", rc.bottom );
5458 DestroyWindow(hwnd);
5460 /* top level window */
5461 expected_cx = expected_cy = 200000;
5462 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
5463 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
5464 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5465 GetClientRect( hwnd, &rc );
5466 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
5467 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
5468 DestroyWindow(hwnd);
5470 if (pGetLayout && pSetLayout)
5472 HDC hdc = GetDC( parent );
5473 pSetLayout( hdc, LAYOUT_RTL );
5474 if (pGetLayout( hdc ))
5476 ReleaseDC( parent, hdc );
5477 DestroyWindow( parent );
5478 SetLastError( 0xdeadbeef );
5479 parent = CreateWindowExA(WS_EX_APPWINDOW | WS_EX_LAYOUTRTL, "static", NULL, WS_POPUP,
5480 0, 0, 100, 100, 0, 0, 0, NULL);
5481 ok( parent != 0, "creation failed err %u\n", GetLastError());
5482 expect_ex_style( parent, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
5483 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 20, 20, parent, 0, 0, NULL);
5484 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5485 expect_ex_style( hwnd, WS_EX_LAYOUTRTL );
5486 DestroyWindow( hwnd );
5487 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 20, 20, parent, 0, 0, NULL);
5488 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5489 expect_ex_style( hwnd, 0 );
5490 DestroyWindow( hwnd );
5491 SetWindowLongW( parent, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT );
5492 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 20, 20, parent, 0, 0, NULL);
5493 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5494 expect_ex_style( hwnd, 0 );
5495 DestroyWindow( hwnd );
5497 if (pGetProcessDefaultLayout && pSetProcessDefaultLayout)
5499 DWORD layout;
5501 SetLastError( 0xdeadbeef );
5502 ok( !pGetProcessDefaultLayout( NULL ), "GetProcessDefaultLayout succeeded\n" );
5503 ok( GetLastError() == ERROR_NOACCESS, "wrong error %u\n", GetLastError() );
5504 SetLastError( 0xdeadbeef );
5505 res = pGetProcessDefaultLayout( &layout );
5506 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
5507 ok( layout == 0, "GetProcessDefaultLayout wrong layout %x\n", layout );
5508 SetLastError( 0xdeadbeef );
5509 res = pSetProcessDefaultLayout( 7 );
5510 ok( res, "SetProcessDefaultLayout failed err %u\n", GetLastError ());
5511 res = pGetProcessDefaultLayout( &layout );
5512 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
5513 ok( layout == 7, "GetProcessDefaultLayout wrong layout %x\n", layout );
5514 SetLastError( 0xdeadbeef );
5515 res = pSetProcessDefaultLayout( LAYOUT_RTL );
5516 ok( res, "SetProcessDefaultLayout failed err %u\n", GetLastError ());
5517 res = pGetProcessDefaultLayout( &layout );
5518 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
5519 ok( layout == LAYOUT_RTL, "GetProcessDefaultLayout wrong layout %x\n", layout );
5520 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
5521 0, 0, 100, 100, 0, 0, 0, NULL);
5522 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5523 expect_ex_style( hwnd, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
5524 DestroyWindow( hwnd );
5525 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
5526 0, 0, 100, 100, parent, 0, 0, NULL);
5527 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5528 expect_ex_style( hwnd, WS_EX_APPWINDOW );
5529 DestroyWindow( hwnd );
5530 pSetProcessDefaultLayout( 0 );
5532 else win_skip( "SetProcessDefaultLayout not supported\n" );
5534 else win_skip( "SetLayout not supported\n" );
5536 else win_skip( "SetLayout not available\n" );
5538 DestroyWindow(parent);
5540 UnregisterClassA("MinMax_WndClass", GetModuleHandleA(NULL));
5541 UnregisterClassA("Sizes_WndClass", GetModuleHandleA(NULL));
5543 #undef expect_gle_broken_9x
5544 #undef expect_menu
5545 #undef expect_style
5546 #undef expect_ex_style
5549 /* function that remembers whether the system the test is running on sets the
5550 * last error for user32 functions to make the tests stricter */
5551 static int check_error(DWORD actual, DWORD expected)
5553 static int sets_last_error = -1;
5554 if (sets_last_error == -1)
5555 sets_last_error = (actual != 0xdeadbeef);
5556 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
5559 static void test_SetWindowLong(void)
5561 LONG_PTR retval;
5562 WNDPROC old_window_procW;
5564 SetLastError(0xdeadbeef);
5565 retval = SetWindowLongPtrA(NULL, GWLP_WNDPROC, 0);
5566 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
5567 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
5568 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instead of %d\n", GetLastError());
5570 SetLastError(0xdeadbeef);
5571 retval = SetWindowLongPtrA(hwndMain, 0xdeadbeef, 0);
5572 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
5573 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
5574 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instead of %d\n", GetLastError());
5576 SetLastError(0xdeadbeef);
5577 retval = SetWindowLongPtrA(hwndMain, GWLP_WNDPROC, 0);
5578 ok((WNDPROC)retval == main_window_procA || broken(!retval), /* win9x */
5579 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
5580 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
5581 retval = GetWindowLongPtrA(hwndMain, GWLP_WNDPROC);
5582 ok((WNDPROC)retval == main_window_procA,
5583 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
5584 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
5586 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
5587 SetLastError(0xdeadbeef);
5588 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
5589 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
5591 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
5592 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
5593 ok((WNDPROC)retval == old_window_procW,
5594 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
5595 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
5597 /* set it back to ANSI */
5598 SetWindowLongPtrA(hwndMain, GWLP_WNDPROC, 0);
5602 static void test_ShowWindow(void)
5604 HWND hwnd;
5605 DWORD style;
5606 RECT rcMain, rc, rcMinimized;
5607 LPARAM ret;
5609 SetRect(&rcMain, 120, 120, 210, 210);
5611 hwnd = CreateWindowExA(0, "MainWindowClass", NULL,
5612 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5613 WS_MAXIMIZEBOX | WS_POPUP,
5614 rcMain.left, rcMain.top,
5615 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
5616 0, 0, 0, NULL);
5617 assert(hwnd);
5619 style = GetWindowLongA(hwnd, GWL_STYLE);
5620 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5621 ok(!(style & WS_VISIBLE), "window should not be visible\n");
5622 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5623 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5624 GetWindowRect(hwnd, &rc);
5625 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5626 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5627 rc.left, rc.top, rc.right, rc.bottom);
5629 ret = ShowWindow(hwnd, SW_SHOW);
5630 ok(!ret, "not expected ret: %lu\n", ret);
5631 style = GetWindowLongA(hwnd, GWL_STYLE);
5632 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5633 ok(style & WS_VISIBLE, "window should be visible\n");
5634 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5635 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5636 GetWindowRect(hwnd, &rc);
5637 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5638 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5639 rc.left, rc.top, rc.right, rc.bottom);
5641 ret = ShowWindow(hwnd, SW_MINIMIZE);
5642 ok(ret, "not expected ret: %lu\n", ret);
5643 style = GetWindowLongA(hwnd, GWL_STYLE);
5644 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5645 ok(style & WS_VISIBLE, "window should be visible\n");
5646 ok(style & WS_MINIMIZE, "window should be minimized\n");
5647 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5648 GetWindowRect(hwnd, &rcMinimized);
5649 ok(!EqualRect(&rcMain, &rcMinimized), "rects shouldn't match\n");
5650 /* shouldn't be able to resize minimized windows */
5651 ret = SetWindowPos(hwnd, 0, 0, 0,
5652 (rcMinimized.right - rcMinimized.left) * 2,
5653 (rcMinimized.bottom - rcMinimized.top) * 2,
5654 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
5655 ok(ret, "not expected ret: %lu\n", ret);
5656 GetWindowRect(hwnd, &rc);
5657 ok(EqualRect(&rc, &rcMinimized), "rects should match\n");
5659 ShowWindow(hwnd, SW_RESTORE);
5660 ok(ret, "not expected ret: %lu\n", ret);
5661 style = GetWindowLongA(hwnd, GWL_STYLE);
5662 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5663 ok(style & WS_VISIBLE, "window should be visible\n");
5664 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5665 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5666 GetWindowRect(hwnd, &rc);
5667 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5668 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5669 rc.left, rc.top, rc.right, rc.bottom);
5671 ret = EnableWindow(hwnd, FALSE);
5672 ok(!ret, "not expected ret: %lu\n", ret);
5673 style = GetWindowLongA(hwnd, GWL_STYLE);
5674 ok(style & WS_DISABLED, "window should be disabled\n");
5676 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
5677 ok(!ret, "not expected ret: %lu\n", ret);
5678 style = GetWindowLongA(hwnd, GWL_STYLE);
5679 ok(style & WS_DISABLED, "window should be disabled\n");
5680 ok(style & WS_VISIBLE, "window should be visible\n");
5681 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5682 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5683 GetWindowRect(hwnd, &rc);
5684 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5685 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5686 rc.left, rc.top, rc.right, rc.bottom);
5688 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
5689 ok(!ret, "not expected ret: %lu\n", ret);
5690 style = GetWindowLongA(hwnd, GWL_STYLE);
5691 ok(style & WS_DISABLED, "window should be disabled\n");
5692 ok(style & WS_VISIBLE, "window should be visible\n");
5693 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5694 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5695 GetWindowRect(hwnd, &rc);
5696 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5697 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5698 rc.left, rc.top, rc.right, rc.bottom);
5700 ret = ShowWindow(hwnd, SW_MINIMIZE);
5701 ok(ret, "not expected ret: %lu\n", ret);
5702 style = GetWindowLongA(hwnd, GWL_STYLE);
5703 ok(style & WS_DISABLED, "window should be disabled\n");
5704 ok(style & WS_VISIBLE, "window should be visible\n");
5705 ok(style & WS_MINIMIZE, "window should be minimized\n");
5706 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5707 GetWindowRect(hwnd, &rc);
5708 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
5710 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
5711 ok(!ret, "not expected ret: %lu\n", ret);
5712 style = GetWindowLongA(hwnd, GWL_STYLE);
5713 ok(style & WS_DISABLED, "window should be disabled\n");
5714 ok(style & WS_VISIBLE, "window should be visible\n");
5715 ok(style & WS_MINIMIZE, "window should be minimized\n");
5716 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5717 GetWindowRect(hwnd, &rc);
5718 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
5720 ret = ShowWindow(hwnd, SW_RESTORE);
5721 ok(ret, "not expected ret: %lu\n", ret);
5722 style = GetWindowLongA(hwnd, GWL_STYLE);
5723 ok(style & WS_DISABLED, "window should be disabled\n");
5724 ok(style & WS_VISIBLE, "window should be visible\n");
5725 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5726 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5727 GetWindowRect(hwnd, &rc);
5728 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5729 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5730 rc.left, rc.top, rc.right, rc.bottom);
5732 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
5733 ok(!ret, "not expected ret: %lu\n", ret);
5734 ok(IsWindow(hwnd), "window should exist\n");
5736 ret = EnableWindow(hwnd, TRUE);
5737 ok(ret, "not expected ret: %lu\n", ret);
5739 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
5740 ok(!ret, "not expected ret: %lu\n", ret);
5741 ok(!IsWindow(hwnd), "window should not exist\n");
5744 static DWORD CALLBACK gettext_msg_thread( LPVOID arg )
5746 HWND hwnd = arg;
5747 char buf[32];
5748 INT buf_len;
5750 /* test GetWindowTextA */
5751 num_gettext_msgs = 0;
5752 memset( buf, 0, sizeof(buf) );
5753 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
5754 ok( buf_len != 0, "expected a nonempty window text\n" );
5755 ok( !strcmp(buf, "another_caption"), "got wrong window text '%s'\n", buf );
5756 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
5758 return 0;
5761 static DWORD CALLBACK settext_msg_thread( LPVOID arg )
5763 HWND hwnd = arg;
5764 BOOL success;
5766 /* test SetWindowTextA */
5767 num_settext_msgs = 0;
5768 success = SetWindowTextA( hwnd, "thread_caption" );
5769 ok( success, "SetWindowTextA failed\n" );
5770 ok( num_settext_msgs == 1, "got %u WM_SETTEXT messages\n", num_settext_msgs );
5772 return 0;
5775 static void test_gettext(void)
5777 DWORD tid, num_msgs;
5778 WCHAR bufW[32];
5779 HANDLE thread;
5780 BOOL success;
5781 char buf[32];
5782 INT buf_len;
5783 HWND hwnd, hwnd2;
5784 LRESULT r;
5785 MSG msg;
5787 hwnd = CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP, 0, 0, 0, 0, 0, 0, 0, NULL );
5788 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
5790 /* test GetWindowTextA */
5791 num_gettext_msgs = 0;
5792 memset( buf, 0, sizeof(buf) );
5793 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
5794 ok( buf_len != 0, "expected a nonempty window text\n" );
5795 ok( !strcmp(buf, "caption"), "got wrong window text '%s'\n", buf );
5796 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
5798 /* other process window */
5799 strcpy( buf, "a" );
5800 buf_len = GetWindowTextA( GetDesktopWindow(), buf, sizeof(buf) );
5801 ok( buf_len == 0, "expected a nonempty window text\n" );
5802 ok( *buf == 0, "got wrong window text '%s'\n", buf );
5804 strcpy( buf, "blah" );
5805 buf_len = GetWindowTextA( GetDesktopWindow(), buf, 0 );
5806 ok( buf_len == 0, "expected a nonempty window text\n" );
5807 ok( !strcmp(buf, "blah"), "got wrong window text '%s'\n", buf );
5809 bufW[0] = 0xcc;
5810 buf_len = GetWindowTextW( GetDesktopWindow(), bufW, 0 );
5811 ok( buf_len == 0, "expected a nonempty window text\n" );
5812 ok( bufW[0] == 0xcc, "got %x\n", bufW[0] );
5814 g_wm_gettext_override.enabled = TRUE;
5816 num_gettext_msgs = 0;
5817 memset( buf, 0xcc, sizeof(buf) );
5818 g_wm_gettext_override.buff = buf;
5819 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
5820 ok( buf_len == 0, "got %d\n", buf_len );
5821 ok( *buf == 0, "got %x\n", *buf );
5822 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
5824 num_gettext_msgs = 0;
5825 strcpy( buf, "blah" );
5826 g_wm_gettext_override.buff = buf;
5827 buf_len = GetWindowTextA( hwnd, buf, 0 );
5828 ok( buf_len == 0, "got %d\n", buf_len );
5829 ok( !strcmp(buf, "blah"), "got %s\n", buf );
5830 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
5832 g_wm_gettext_override.enabled = FALSE;
5834 /* same for W window */
5835 hwnd2 = CreateWindowExW( 0, mainclassW, NULL, WS_POPUP, 0, 0, 0, 0, 0, 0, 0, NULL );
5836 ok( hwnd2 != 0, "CreateWindowExA error %d\n", GetLastError() );
5838 g_wm_gettext_override.enabled = TRUE;
5840 num_gettext_msgs = 0;
5841 memset( bufW, 0xcc, sizeof(bufW) );
5842 g_wm_gettext_override.buffW = bufW;
5843 buf_len = GetWindowTextW( hwnd2, bufW, sizeof(bufW)/sizeof(WCHAR) );
5844 ok( buf_len == 0, "got %d\n", buf_len );
5845 ok( *bufW == 0, "got %x\n", *bufW );
5846 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
5848 num_gettext_msgs = 0;
5849 memset( bufW, 0xcc, sizeof(bufW) );
5850 g_wm_gettext_override.buffW = bufW;
5851 buf_len = GetWindowTextW( hwnd2, bufW, 0 );
5852 ok( buf_len == 0, "got %d\n", buf_len );
5853 ok( *bufW == 0xcccc, "got %x\n", *bufW );
5854 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
5856 g_wm_gettext_override.enabled = FALSE;
5858 DestroyWindow( hwnd2 );
5860 /* test WM_GETTEXT */
5861 num_gettext_msgs = 0;
5862 memset( buf, 0, sizeof(buf) );
5863 r = SendMessageA( hwnd, WM_GETTEXT, sizeof(buf), (LONG_PTR)buf );
5864 ok( r != 0, "expected a nonempty window text\n" );
5865 ok( !strcmp(buf, "caption"), "got wrong window text '%s'\n", buf );
5866 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
5868 /* test SetWindowTextA */
5869 num_settext_msgs = 0;
5870 success = SetWindowTextA( hwnd, "new_caption" );
5871 ok( success, "SetWindowTextA failed\n" );
5872 ok( num_settext_msgs == 1, "got %u WM_SETTEXT messages\n", num_settext_msgs );
5874 num_gettext_msgs = 0;
5875 memset( buf, 0, sizeof(buf) );
5876 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
5877 ok( buf_len != 0, "expected a nonempty window text\n" );
5878 ok( !strcmp(buf, "new_caption"), "got wrong window text '%s'\n", buf );
5879 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
5881 /* test WM_SETTEXT */
5882 num_settext_msgs = 0;
5883 r = SendMessageA( hwnd, WM_SETTEXT, 0, (ULONG_PTR)"another_caption" );
5884 ok( r != 0, "WM_SETTEXT failed\n" );
5885 ok( num_settext_msgs == 1, "got %u WM_SETTEXT messages\n", num_settext_msgs );
5887 num_gettext_msgs = 0;
5888 memset( buf, 0, sizeof(buf) );
5889 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
5890 ok( buf_len != 0, "expected a nonempty window text\n" );
5891 ok( !strcmp(buf, "another_caption"), "got wrong window text '%s'\n", buf );
5892 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
5894 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE ))
5895 DispatchMessageA( &msg );
5897 /* test interthread GetWindowTextA */
5898 num_msgs = 0;
5899 thread = CreateThread( NULL, 0, gettext_msg_thread, hwnd, 0, &tid );
5900 ok(thread != NULL, "CreateThread failed, error %d\n", GetLastError());
5901 while (MsgWaitForMultipleObjects( 1, &thread, FALSE, INFINITE, QS_SENDMESSAGE ) != WAIT_OBJECT_0)
5903 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE ))
5904 DispatchMessageA( &msg );
5905 num_msgs++;
5907 CloseHandle( thread );
5908 ok( num_msgs >= 1, "got %u wakeups from MsgWaitForMultipleObjects\n", num_msgs );
5910 /* test interthread SetWindowText */
5911 num_msgs = 0;
5912 thread = CreateThread( NULL, 0, settext_msg_thread, hwnd, 0, &tid );
5913 ok(thread != NULL, "CreateThread failed, error %d\n", GetLastError());
5914 while (MsgWaitForMultipleObjects( 1, &thread, FALSE, INFINITE, QS_SENDMESSAGE ) != WAIT_OBJECT_0)
5916 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE ))
5917 DispatchMessageA( &msg );
5918 num_msgs++;
5920 CloseHandle( thread );
5921 ok( num_msgs >= 1, "got %u wakeups from MsgWaitForMultipleObjects\n", num_msgs );
5923 num_gettext_msgs = 0;
5924 memset( buf, 0, sizeof(buf) );
5925 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
5926 ok( buf_len != 0, "expected a nonempty window text\n" );
5927 ok( !strcmp(buf, "thread_caption"), "got wrong window text '%s'\n", buf );
5928 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
5930 /* seems to crash on every modern Windows version */
5931 if (0)
5933 r = SendMessageA( hwnd, WM_GETTEXT, 0x10, 0x1000);
5934 ok( r == 0, "settext should return zero\n");
5936 r = SendMessageA( hwnd, WM_GETTEXT, 0x10000, 0);
5937 ok( r == 0, "settext should return zero (%ld)\n", r);
5939 r = SendMessageA( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
5940 ok( r == 0, "settext should return zero (%ld)\n", r);
5942 r = SendMessageA( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
5943 ok( r == 0, "settext should return zero (%ld)\n", r);
5946 DestroyWindow(hwnd);
5950 static void test_GetUpdateRect(void)
5952 MSG msg;
5953 BOOL ret, parent_wm_paint, grandparent_wm_paint;
5954 RECT rc1, rc2;
5955 HWND hgrandparent, hparent, hchild;
5956 WNDCLASSA cls;
5957 static const char classNameA[] = "GetUpdateRectClass";
5959 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
5960 0, 0, 100, 100, NULL, NULL, 0, NULL);
5962 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
5963 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
5965 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
5966 10, 10, 30, 30, hparent, NULL, 0, NULL);
5968 ShowWindow(hgrandparent, SW_SHOW);
5969 UpdateWindow(hgrandparent);
5970 flush_events( TRUE );
5972 ShowWindow(hchild, SW_HIDE);
5973 SetRect(&rc2, 0, 0, 0, 0);
5974 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5975 ok(!ret, "GetUpdateRect returned not empty region\n");
5976 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5977 rc1.left, rc1.top, rc1.right, rc1.bottom,
5978 rc2.left, rc2.top, rc2.right, rc2.bottom);
5980 SetRect(&rc2, 10, 10, 40, 40);
5981 ret = GetUpdateRect(hparent, &rc1, FALSE);
5982 ok(ret, "GetUpdateRect returned empty region\n");
5983 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5984 rc1.left, rc1.top, rc1.right, rc1.bottom,
5985 rc2.left, rc2.top, rc2.right, rc2.bottom);
5987 parent_wm_paint = FALSE;
5988 grandparent_wm_paint = FALSE;
5989 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
5991 if (msg.message == WM_PAINT)
5993 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
5994 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
5996 DispatchMessageA(&msg);
5998 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
5999 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
6001 DestroyWindow(hgrandparent);
6003 cls.style = 0;
6004 cls.lpfnWndProc = DefWindowProcA;
6005 cls.cbClsExtra = 0;
6006 cls.cbWndExtra = 0;
6007 cls.hInstance = GetModuleHandleA(0);
6008 cls.hIcon = 0;
6009 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
6010 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6011 cls.lpszMenuName = NULL;
6012 cls.lpszClassName = classNameA;
6014 if(!RegisterClassA(&cls)) {
6015 trace("Register failed %d\n", GetLastError());
6016 return;
6019 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
6020 0, 0, 100, 100, NULL, NULL, 0, NULL);
6022 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
6023 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
6025 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
6026 10, 10, 30, 30, hparent, NULL, 0, NULL);
6028 ShowWindow(hgrandparent, SW_SHOW);
6029 UpdateWindow(hgrandparent);
6030 flush_events( TRUE );
6032 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
6033 ok(!ret, "GetUpdateRect returned not empty region\n");
6035 ShowWindow(hchild, SW_HIDE);
6037 SetRect(&rc2, 0, 0, 0, 0);
6038 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
6039 ok(!ret, "GetUpdateRect returned not empty region\n");
6040 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
6041 rc1.left, rc1.top, rc1.right, rc1.bottom,
6042 rc2.left, rc2.top, rc2.right, rc2.bottom);
6044 SetRect(&rc2, 10, 10, 40, 40);
6045 ret = GetUpdateRect(hparent, &rc1, FALSE);
6046 ok(ret, "GetUpdateRect returned empty region\n");
6047 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
6048 rc1.left, rc1.top, rc1.right, rc1.bottom,
6049 rc2.left, rc2.top, rc2.right, rc2.bottom);
6051 parent_wm_paint = FALSE;
6052 grandparent_wm_paint = FALSE;
6053 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
6055 if (msg.message == WM_PAINT)
6057 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
6058 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
6060 DispatchMessageA(&msg);
6062 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
6063 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
6065 DestroyWindow(hgrandparent);
6069 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
6071 if(msg == WM_PAINT)
6073 PAINTSTRUCT ps;
6074 RECT updateRect;
6075 DWORD waitResult;
6076 HWND win;
6077 const int waitTime = 2000;
6079 BeginPaint(hwnd, &ps);
6081 /* create and destroy window to create an exposed region on this window */
6082 win = CreateWindowA("static", "win", WS_VISIBLE,
6083 10,10,50,50, NULL, NULL, 0, NULL);
6084 DestroyWindow(win);
6086 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
6088 ValidateRect(hwnd, NULL);
6089 EndPaint(hwnd, &ps);
6091 if(waitResult != WAIT_TIMEOUT)
6093 GetUpdateRect(hwnd, &updateRect, FALSE);
6094 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
6097 return 1;
6099 return DefWindowProcA(hwnd, msg, wParam, lParam);
6102 static void test_Expose(void)
6104 WNDCLASSA cls;
6105 HWND mw;
6107 memset(&cls, 0, sizeof(WNDCLASSA));
6108 cls.lpfnWndProc = TestExposedRegion_WndProc;
6109 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6110 cls.lpszClassName = "TestExposeClass";
6111 RegisterClassA(&cls);
6113 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
6114 0, 0, 200, 100, NULL, NULL, 0, NULL);
6116 UpdateWindow(mw);
6117 DestroyWindow(mw);
6120 static LRESULT CALLBACK TestNCRedraw_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
6122 static UINT ncredrawflags;
6123 PAINTSTRUCT ps;
6125 switch(msg)
6127 case WM_CREATE:
6128 ncredrawflags = *(UINT *) (((CREATESTRUCTA *)lParam)->lpCreateParams);
6129 return 0;
6130 case WM_NCPAINT:
6131 RedrawWindow(hwnd, NULL, NULL, ncredrawflags);
6132 break;
6133 case WM_PAINT:
6134 BeginPaint(hwnd, &ps);
6135 EndPaint(hwnd, &ps);
6136 return 0;
6138 return DefWindowProcA(hwnd, msg, wParam, lParam);
6141 static void run_NCRedrawLoop(UINT flags)
6143 HWND hwnd;
6144 MSG msg;
6146 UINT loopcount = 0;
6148 hwnd = CreateWindowA("TestNCRedrawClass", "MainWindow",
6149 WS_OVERLAPPEDWINDOW, 0, 0, 200, 100,
6150 NULL, NULL, 0, &flags);
6151 ShowWindow(hwnd, SW_SHOW);
6152 UpdateWindow(hwnd);
6153 flush_events( FALSE );
6154 while (PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE))
6156 if (msg.message == WM_PAINT) loopcount++;
6157 if (loopcount >= 100) break;
6158 TranslateMessage(&msg);
6159 DispatchMessageA(&msg);
6160 MsgWaitForMultipleObjects(0, NULL, FALSE, 100, QS_ALLINPUT);
6162 if (flags == (RDW_INVALIDATE | RDW_FRAME))
6163 todo_wine ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
6164 else
6165 ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
6166 DestroyWindow(hwnd);
6169 static void test_NCRedraw(void)
6171 WNDCLASSA wndclass;
6173 wndclass.lpszClassName = "TestNCRedrawClass";
6174 wndclass.style = CS_HREDRAW | CS_VREDRAW;
6175 wndclass.lpfnWndProc = TestNCRedraw_WndProc;
6176 wndclass.cbClsExtra = 0;
6177 wndclass.cbWndExtra = 0;
6178 wndclass.hInstance = 0;
6179 wndclass.hIcon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
6180 wndclass.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
6181 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
6182 wndclass.lpszMenuName = NULL;
6184 RegisterClassA(&wndclass);
6186 run_NCRedrawLoop(RDW_INVALIDATE | RDW_FRAME);
6187 run_NCRedrawLoop(RDW_INVALIDATE);
6190 static void test_GetWindowModuleFileName(void)
6192 HWND hwnd;
6193 HINSTANCE hinst;
6194 UINT ret1, ret2;
6195 char buf1[MAX_PATH], buf2[MAX_PATH];
6197 if (!pGetWindowModuleFileNameA)
6199 win_skip("GetWindowModuleFileNameA is not available\n");
6200 return;
6203 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
6204 assert(hwnd);
6206 hinst = (HINSTANCE)GetWindowLongPtrA(hwnd, GWLP_HINSTANCE);
6207 ok(hinst == 0 || broken(hinst == GetModuleHandleA(NULL)), /* win9x */ "expected 0, got %p\n", hinst);
6209 buf1[0] = 0;
6210 SetLastError(0xdeadbeef);
6211 ret1 = GetModuleFileNameA(hinst, buf1, sizeof(buf1));
6212 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
6214 buf2[0] = 0;
6215 SetLastError(0xdeadbeef);
6216 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
6217 ok(ret2 || broken(!ret2), /* nt4 sp 3 */
6218 "GetWindowModuleFileNameA error %u\n", GetLastError());
6220 if (ret2)
6222 ok(ret1 == ret2 || broken(ret2 == ret1 + 1), /* win98 */ "%u != %u\n", ret1, ret2);
6223 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
6225 hinst = GetModuleHandleA(NULL);
6227 SetLastError(0xdeadbeef);
6228 ret2 = GetModuleFileNameA(hinst, buf2, ret1 - 2);
6229 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
6230 "expected %u, got %u\n", ret1 - 2, ret2);
6231 ok(GetLastError() == 0xdeadbeef /* XP */ ||
6232 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
6233 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
6235 SetLastError(0xdeadbeef);
6236 ret2 = GetModuleFileNameA(hinst, buf2, 0);
6237 ok(!ret2, "GetModuleFileName should return 0\n");
6238 ok(GetLastError() == 0xdeadbeef /* XP */ ||
6239 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
6240 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
6242 SetLastError(0xdeadbeef);
6243 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
6244 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3) /* win98 */ || broken(!ret2), /* nt4 sp3 */
6245 "expected %u, got %u\n", ret1 - 2, ret2);
6246 ok(GetLastError() == 0xdeadbeef /* XP */ ||
6247 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
6248 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
6250 SetLastError(0xdeadbeef);
6251 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
6252 ok(!ret2, "expected 0, got %u\n", ret2);
6253 ok(GetLastError() == 0xdeadbeef /* XP */ ||
6254 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
6255 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
6257 DestroyWindow(hwnd);
6259 buf2[0] = 0;
6260 hwnd = (HWND)0xdeadbeef;
6261 SetLastError(0xdeadbeef);
6262 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
6263 ok(!ret1, "expected 0, got %u\n", ret1);
6264 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef), /* win9x */
6265 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
6267 hwnd = FindWindowA("Shell_TrayWnd", NULL);
6268 ok(IsWindow(hwnd) || broken(!hwnd), "got invalid tray window %p\n", hwnd);
6269 SetLastError(0xdeadbeef);
6270 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
6271 ok(!ret1 || broken(ret1), /* win98 */ "expected 0, got %u\n", ret1);
6273 if (!ret1) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
6275 ret1 = GetModuleFileNameA(0, buf1, sizeof(buf1));
6276 hwnd = GetDesktopWindow();
6277 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
6278 SetLastError(0xdeadbeef);
6279 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
6280 ok(!ret2 ||
6281 ret1 == ret2 || /* vista */
6282 broken(ret2), /* some win98 return user.exe as file name */
6283 "expected 0 or %u, got %u %s\n", ret1, ret2, buf2);
6287 static void test_hwnd_message(void)
6289 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
6290 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
6292 HWND parent = 0, hwnd, found;
6293 RECT rect;
6295 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
6296 on CreateWindowExA and crash later in the test.
6297 Use UNICODE here to fail on win9x */
6298 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
6299 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
6300 if (!hwnd)
6302 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
6303 return;
6306 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
6307 if (pGetAncestor)
6309 char buffer[100];
6310 HWND root, desktop = GetDesktopWindow();
6312 parent = pGetAncestor(hwnd, GA_PARENT);
6313 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
6314 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
6315 root = pGetAncestor(hwnd, GA_ROOT);
6316 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
6317 ok( !pGetAncestor(parent, GA_PARENT) || broken(pGetAncestor(parent, GA_PARENT) != 0), /* win2k */
6318 "parent shouldn't have parent %p\n", pGetAncestor(parent, GA_PARENT) );
6319 trace("parent %p root %p desktop %p\n", parent, root, desktop);
6320 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
6321 ok( !lstrcmpiA( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
6322 GetWindowRect( parent, &rect );
6323 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
6324 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
6326 GetWindowRect( hwnd, &rect );
6327 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
6328 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
6330 /* test FindWindow behavior */
6332 found = FindWindowExA( 0, 0, 0, "message window" );
6333 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
6334 SetLastError(0xdeadbeef);
6335 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
6336 ok( found == 0, "found message window %p/%p\n", found, hwnd );
6337 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
6338 if (parent)
6340 found = FindWindowExA( parent, 0, 0, "message window" );
6341 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
6344 /* test IsChild behavior */
6346 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
6348 /* test IsWindowVisible behavior */
6350 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
6351 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
6353 DestroyWindow(hwnd);
6356 static void test_layered_window(void)
6358 HWND hwnd;
6359 COLORREF key = 0;
6360 BYTE alpha = 0;
6361 DWORD flags = 0;
6362 POINT pt = { 0, 0 };
6363 SIZE sz = { 200, 200 };
6364 HDC hdc;
6365 HBITMAP hbm;
6366 BOOL ret;
6368 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes || !pUpdateLayeredWindow)
6370 win_skip( "layered windows not supported\n" );
6371 return;
6374 hdc = CreateCompatibleDC( 0 );
6375 hbm = CreateCompatibleBitmap( hdc, 200, 200 );
6376 SelectObject( hdc, hbm );
6378 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
6379 100, 100, 200, 200, 0, 0, 0, NULL);
6380 assert( hwnd );
6381 SetLastError( 0xdeadbeef );
6382 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6383 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
6384 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
6385 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6386 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
6387 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
6388 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
6389 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
6390 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6391 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
6392 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6393 ok( ret, "UpdateLayeredWindow should succeed on layered window\n" );
6394 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6395 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
6396 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
6397 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6398 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6399 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6400 ok( key == 0x123456 || key == 0, "wrong color key %x\n", key );
6401 ok( alpha == 44, "wrong alpha %u\n", alpha );
6402 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
6403 SetLastError( 0xdeadbeef );
6404 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6405 ok( !ret, "UpdateLayeredWindow should fail on layered but initialized window\n" );
6406 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
6408 /* clearing WS_EX_LAYERED resets attributes */
6409 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
6410 SetLastError( 0xdeadbeef );
6411 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6412 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
6413 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6414 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
6415 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
6416 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6417 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
6418 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6419 ok( ret, "UpdateLayeredWindow should succeed on layered window\n" );
6420 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE | ULW_EX_NORESIZE );
6421 ok( !ret, "UpdateLayeredWindow should fail with ex flag\n" );
6422 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
6423 if (pUpdateLayeredWindowIndirect)
6425 UPDATELAYEREDWINDOWINFO info;
6426 info.cbSize = sizeof(info);
6427 info.hdcDst = 0;
6428 info.pptDst = NULL;
6429 info.psize = &sz;
6430 info.hdcSrc = hdc;
6431 info.pptSrc = &pt;
6432 info.crKey = 0;
6433 info.pblend = NULL;
6434 info.dwFlags = ULW_OPAQUE | ULW_EX_NORESIZE;
6435 info.prcDirty = NULL;
6436 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6437 ok( ret, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
6438 sz.cx--;
6439 SetLastError(0);
6440 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6441 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
6442 /* particular error code differs from version to version, could be ERROR_INCORRECT_SIZE,
6443 ERROR_MR_MID_NOT_FOUND or ERROR_GEN_FAILURE (Win8/Win10) */
6444 ok( GetLastError() != 0, "wrong error %u\n", GetLastError() );
6445 info.dwFlags = ULW_OPAQUE;
6446 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6447 ok( ret, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
6448 sz.cx++;
6449 info.dwFlags = ULW_OPAQUE | 0xf00;
6450 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6451 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
6452 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
6453 info.cbSize--;
6454 info.dwFlags = ULW_OPAQUE;
6455 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6456 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
6457 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
6458 ret = pUpdateLayeredWindowIndirect( hwnd, NULL );
6459 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
6460 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
6463 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
6464 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6465 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6466 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6467 ok( key == 0x654321, "wrong color key %x\n", key );
6468 ok( alpha == 22, "wrong alpha %u\n", alpha );
6469 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
6470 SetLastError( 0xdeadbeef );
6471 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6472 ok( !ret, "UpdateLayeredWindow should fail on layered but initialized window\n" );
6473 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
6475 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
6476 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6477 alpha = 0;
6478 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6479 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6480 ok( key == 0x888888, "wrong color key %x\n", key );
6481 /* alpha not changed on vista if LWA_ALPHA is not set */
6482 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
6483 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
6485 /* color key may or may not be changed without LWA_COLORKEY */
6486 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
6487 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6488 alpha = 0;
6489 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6490 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6491 ok( key == 0x888888 || key == 0x999999, "wrong color key %x\n", key );
6492 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
6493 ok( flags == 0, "wrong flags %x\n", flags );
6495 /* default alpha and color key is 0 */
6496 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
6497 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
6498 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
6499 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6500 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6501 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6502 ok( key == 0 || key == 0x222222, "wrong color key %x\n", key );
6503 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
6504 ok( flags == 0, "wrong flags %x\n", flags );
6506 DestroyWindow( hwnd );
6507 DeleteDC( hdc );
6508 DeleteObject( hbm );
6511 static MONITORINFO mi;
6513 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
6515 switch (msg)
6517 case WM_NCCREATE:
6519 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
6520 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
6521 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
6522 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
6523 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6524 cs->x, cs->y, cs->cx, cs->cy);
6525 break;
6527 case WM_GETMINMAXINFO:
6529 MINMAXINFO *minmax = (MINMAXINFO *)lp;
6530 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
6531 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
6532 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
6533 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
6534 break;
6537 return DefWindowProcA(hwnd, msg, wp, lp);
6540 static void test_fullscreen(void)
6542 static const DWORD t_style[] = {
6543 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
6545 static const DWORD t_ex_style[] = {
6546 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
6548 WNDCLASSA cls;
6549 HWND hwnd;
6550 int i, j;
6551 POINT pt;
6552 RECT rc;
6553 HMONITOR hmon;
6554 LRESULT ret;
6556 if (!pGetMonitorInfoA || !pMonitorFromPoint)
6558 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
6559 return;
6562 pt.x = pt.y = 0;
6563 SetLastError(0xdeadbeef);
6564 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
6565 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
6567 mi.cbSize = sizeof(mi);
6568 SetLastError(0xdeadbeef);
6569 ret = pGetMonitorInfoA(hmon, &mi);
6570 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
6571 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
6572 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6573 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
6575 cls.style = 0;
6576 cls.lpfnWndProc = fullscreen_wnd_proc;
6577 cls.cbClsExtra = 0;
6578 cls.cbWndExtra = 0;
6579 cls.hInstance = GetModuleHandleA(NULL);
6580 cls.hIcon = 0;
6581 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
6582 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6583 cls.lpszMenuName = NULL;
6584 cls.lpszClassName = "fullscreen_class";
6585 RegisterClassA(&cls);
6587 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
6589 DWORD style, ex_style;
6591 /* avoid a WM interaction */
6592 assert(!(t_style[i] & WS_VISIBLE));
6594 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
6596 int fixup;
6598 style = t_style[i];
6599 ex_style = t_ex_style[j];
6601 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6602 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6603 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
6604 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6605 GetWindowRect(hwnd, &rc);
6606 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6607 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6608 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6609 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6610 DestroyWindow(hwnd);
6612 style = t_style[i] | WS_MAXIMIZE;
6613 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6614 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6615 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
6616 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6617 GetWindowRect(hwnd, &rc);
6618 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6619 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6620 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6621 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6622 DestroyWindow(hwnd);
6624 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
6625 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6626 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6627 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
6628 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6629 GetWindowRect(hwnd, &rc);
6630 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6631 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6632 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6633 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6634 DestroyWindow(hwnd);
6636 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
6637 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6638 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6639 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
6640 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6641 GetWindowRect(hwnd, &rc);
6642 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6643 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6644 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6645 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6646 DestroyWindow(hwnd);
6648 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
6649 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6650 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6651 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
6652 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6653 GetWindowRect(hwnd, &rc);
6654 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6655 /* Windows makes a maximized window slightly larger (to hide the borders?) */
6656 fixup = min(abs(rc.left), abs(rc.top));
6657 InflateRect(&rc, -fixup, -fixup);
6658 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
6659 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
6660 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
6661 ex_style, style, rc.left, rc.top, rc.right, rc.bottom,
6662 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
6663 DestroyWindow(hwnd);
6665 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
6666 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6667 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6668 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
6669 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6670 GetWindowRect(hwnd, &rc);
6671 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6672 /* Windows makes a maximized window slightly larger (to hide the borders?) */
6673 fixup = min(abs(rc.left), abs(rc.top));
6674 InflateRect(&rc, -fixup, -fixup);
6675 if (style & (WS_CHILD | WS_POPUP))
6676 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6677 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6678 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6679 else
6680 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
6681 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
6682 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6683 DestroyWindow(hwnd);
6687 UnregisterClassA("fullscreen_class", GetModuleHandleA(NULL));
6690 static BOOL test_thick_child_got_minmax;
6691 static const char * test_thick_child_name;
6692 static LONG test_thick_child_style;
6693 static LONG test_thick_child_exStyle;
6695 static LRESULT WINAPI test_thick_child_size_winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
6697 MINMAXINFO* minmax;
6698 int expectedMinTrackX;
6699 int expectedMinTrackY;
6700 int actualMinTrackX;
6701 int actualMinTrackY;
6702 int expectedMaxTrackX;
6703 int expectedMaxTrackY;
6704 int actualMaxTrackX;
6705 int actualMaxTrackY;
6706 int expectedMaxSizeX;
6707 int expectedMaxSizeY;
6708 int actualMaxSizeX;
6709 int actualMaxSizeY;
6710 int expectedPosX;
6711 int expectedPosY;
6712 int actualPosX;
6713 int actualPosY;
6714 LONG adjustedStyle;
6715 RECT rect;
6716 switch (msg)
6718 case WM_GETMINMAXINFO:
6720 minmax = (MINMAXINFO *)lparam;
6721 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
6722 dump_minmax_info( minmax );
6724 test_thick_child_got_minmax = TRUE;
6727 adjustedStyle = test_thick_child_style;
6728 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
6729 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
6730 GetClientRect(GetParent(hwnd), &rect);
6731 AdjustWindowRectEx(&rect, adjustedStyle, FALSE, test_thick_child_exStyle);
6733 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
6735 expectedMinTrackX = GetSystemMetrics(SM_CXMINTRACK);
6736 expectedMinTrackY = GetSystemMetrics(SM_CYMINTRACK);
6738 else
6740 expectedMinTrackX = -2 * rect.left;
6741 expectedMinTrackY = -2 * rect.top;
6743 actualMinTrackX = minmax->ptMinTrackSize.x;
6744 actualMinTrackY = minmax->ptMinTrackSize.y;
6746 ok(actualMinTrackX == expectedMinTrackX && actualMinTrackY == expectedMinTrackY,
6747 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
6748 expectedMinTrackX, expectedMinTrackY, actualMinTrackX, actualMinTrackY,
6749 test_thick_child_name);
6751 actualMaxTrackX = minmax->ptMaxTrackSize.x;
6752 actualMaxTrackY = minmax->ptMaxTrackSize.y;
6753 expectedMaxTrackX = GetSystemMetrics(SM_CXMAXTRACK);
6754 expectedMaxTrackY = GetSystemMetrics(SM_CYMAXTRACK);
6755 ok(actualMaxTrackX == expectedMaxTrackX && actualMaxTrackY == expectedMaxTrackY,
6756 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
6757 expectedMaxTrackX, expectedMaxTrackY, actualMaxTrackX, actualMaxTrackY,
6758 test_thick_child_name);
6760 expectedMaxSizeX = rect.right - rect.left;
6761 expectedMaxSizeY = rect.bottom - rect.top;
6762 actualMaxSizeX = minmax->ptMaxSize.x;
6763 actualMaxSizeY = minmax->ptMaxSize.y;
6765 ok(actualMaxSizeX == expectedMaxSizeX && actualMaxSizeY == expectedMaxSizeY,
6766 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
6767 expectedMaxSizeX, expectedMaxSizeY, actualMaxSizeX, actualMaxSizeY,
6768 test_thick_child_name);
6771 expectedPosX = rect.left;
6772 expectedPosY = rect.top;
6773 actualPosX = minmax->ptMaxPosition.x;
6774 actualPosY = minmax->ptMaxPosition.y;
6775 ok(actualPosX == expectedPosX && actualPosY == expectedPosY,
6776 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
6777 expectedPosX, expectedPosY, actualPosX, actualPosY, test_thick_child_name);
6779 break;
6783 return DefWindowProcA(hwnd, msg, wparam, lparam);
6786 #define NUMBER_OF_THICK_CHILD_TESTS 16
6787 static void test_thick_child_size(HWND parentWindow)
6789 BOOL success;
6790 RECT childRect;
6791 RECT adjustedParentRect;
6792 HWND childWindow;
6793 LONG childWidth;
6794 LONG childHeight;
6795 LONG expectedWidth;
6796 LONG expectedHeight;
6797 WNDCLASSA cls;
6798 static const char className[] = "THICK_CHILD_CLASS";
6799 int i;
6800 LONG adjustedStyle;
6801 static const LONG styles[NUMBER_OF_THICK_CHILD_TESTS] = {
6802 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6803 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6804 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6805 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6806 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6807 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6808 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6809 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6810 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6811 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6812 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6813 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6814 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6815 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6816 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6817 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6820 static const LONG exStyles[NUMBER_OF_THICK_CHILD_TESTS] = {
6825 WS_EX_DLGMODALFRAME,
6826 WS_EX_DLGMODALFRAME,
6827 WS_EX_DLGMODALFRAME,
6828 WS_EX_DLGMODALFRAME,
6829 WS_EX_STATICEDGE,
6830 WS_EX_STATICEDGE,
6831 WS_EX_STATICEDGE,
6832 WS_EX_STATICEDGE,
6833 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6834 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6835 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6836 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6838 static const char *styleName[NUMBER_OF_THICK_CHILD_TESTS] = {
6839 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
6840 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
6841 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
6842 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
6843 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
6844 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
6845 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
6846 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
6847 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
6848 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
6849 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
6850 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
6851 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6852 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6853 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6854 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6857 cls.style = 0;
6858 cls.lpfnWndProc = test_thick_child_size_winproc;
6859 cls.cbClsExtra = 0;
6860 cls.cbWndExtra = 0;
6861 cls.hInstance = GetModuleHandleA(0);
6862 cls.hIcon = 0;
6863 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
6864 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6865 cls.lpszMenuName = NULL;
6866 cls.lpszClassName = className;
6867 SetLastError(0xdeadbeef);
6868 success = RegisterClassA(&cls);
6869 ok(success,"RegisterClassA failed, error: %u\n", GetLastError());
6871 for(i = 0; i < NUMBER_OF_THICK_CHILD_TESTS; i++)
6873 test_thick_child_name = styleName[i];
6874 test_thick_child_style = styles[i];
6875 test_thick_child_exStyle = exStyles[i];
6876 test_thick_child_got_minmax = FALSE;
6878 SetLastError(0xdeadbeef);
6879 childWindow = CreateWindowExA( exStyles[i], className, "", styles[i], 0, 0, 0, 0, parentWindow, 0, GetModuleHandleA(0), NULL );
6880 ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
6882 ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
6884 SetLastError(0xdeadbeef);
6885 success = GetWindowRect(childWindow, &childRect);
6886 ok(success,"GetWindowRect call failed, error: %u\n", GetLastError());
6887 childWidth = childRect.right - childRect.left;
6888 childHeight = childRect.bottom - childRect.top;
6890 adjustedStyle = styles[i];
6891 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
6892 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
6893 GetClientRect(GetParent(childWindow), &adjustedParentRect);
6894 AdjustWindowRectEx(&adjustedParentRect, adjustedStyle, FALSE, test_thick_child_exStyle);
6897 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
6899 expectedWidth = GetSystemMetrics(SM_CXMINTRACK);
6900 expectedHeight = GetSystemMetrics(SM_CYMINTRACK);
6902 else
6904 expectedWidth = -2 * adjustedParentRect.left;
6905 expectedHeight = -2 * adjustedParentRect.top;
6908 ok((childWidth == expectedWidth) && (childHeight == expectedHeight),
6909 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
6910 test_thick_child_name, expectedWidth, expectedHeight, childWidth, childHeight);
6912 SetLastError(0xdeadbeef);
6913 success = DestroyWindow(childWindow);
6914 ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
6916 ok(UnregisterClassA(className, GetModuleHandleA(NULL)),"UnregisterClass call failed\n");
6919 static void test_handles( HWND full_hwnd )
6921 HWND hwnd = full_hwnd;
6922 BOOL ret;
6923 RECT rect;
6925 SetLastError( 0xdeadbeef );
6926 ret = GetWindowRect( hwnd, &rect );
6927 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6929 #ifdef _WIN64
6930 if ((ULONG_PTR)full_hwnd >> 32)
6931 hwnd = (HWND)((ULONG_PTR)full_hwnd & ~0u);
6932 else
6933 hwnd = (HWND)((ULONG_PTR)full_hwnd | ((ULONG_PTR)~0u << 32));
6934 SetLastError( 0xdeadbeef );
6935 ret = GetWindowRect( hwnd, &rect );
6936 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6938 hwnd = (HWND)(((ULONG_PTR)full_hwnd & ~0u) | ((ULONG_PTR)0x1234 << 32));
6939 SetLastError( 0xdeadbeef );
6940 ret = GetWindowRect( hwnd, &rect );
6941 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6943 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x9876 << 16));
6944 SetLastError( 0xdeadbeef );
6945 ret = GetWindowRect( hwnd, &rect );
6946 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
6947 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
6949 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x12345678 << 16));
6950 SetLastError( 0xdeadbeef );
6951 ret = GetWindowRect( hwnd, &rect );
6952 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
6953 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
6954 #endif
6957 static void test_winregion(void)
6959 HWND hwnd;
6960 RECT r;
6961 int ret, width;
6962 HRGN hrgn;
6964 if (!pGetWindowRgnBox)
6966 win_skip("GetWindowRgnBox not supported\n");
6967 return;
6970 hwnd = CreateWindowExA(0, "static", NULL, WS_VISIBLE, 10, 10, 10, 10, NULL, 0, 0, NULL);
6971 /* NULL prect */
6972 SetLastError(0xdeadbeef);
6973 ret = pGetWindowRgnBox(hwnd, NULL);
6974 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
6975 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
6977 hrgn = CreateRectRgn(2, 3, 10, 15);
6978 ok( hrgn != NULL, "Region creation failed\n");
6979 if (hrgn)
6981 SetWindowRgn(hwnd, hrgn, FALSE);
6983 SetLastError(0xdeadbeef);
6984 ret = pGetWindowRgnBox(hwnd, NULL);
6985 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
6986 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
6988 r.left = r.top = r.right = r.bottom = 0;
6989 ret = pGetWindowRgnBox(hwnd, &r);
6990 ok( ret == SIMPLEREGION, "Expected SIMPLEREGION, got %d\n", ret);
6991 ok( r.left == 2 && r.top == 3 && r.right == 10 && r.bottom == 15,
6992 "Expected (2,3,10,15), got (%d,%d,%d,%d)\n", r.left, r.top,
6993 r.right, r.bottom);
6994 if (pMirrorRgn)
6996 hrgn = CreateRectRgn(2, 3, 10, 15);
6997 ret = pMirrorRgn( hwnd, hrgn );
6998 ok( ret == TRUE, "MirrorRgn failed %u\n", ret );
6999 r.left = r.top = r.right = r.bottom = 0;
7000 GetWindowRect( hwnd, &r );
7001 width = r.right - r.left;
7002 r.left = r.top = r.right = r.bottom = 0;
7003 ret = GetRgnBox( hrgn, &r );
7004 ok( ret == SIMPLEREGION, "GetRgnBox failed %u\n", ret );
7005 ok( r.left == width - 10 && r.top == 3 && r.right == width - 2 && r.bottom == 15,
7006 "Wrong rectangle (%d,%d,%d,%d) for width %d\n", r.left, r.top, r.right, r.bottom, width );
7008 else win_skip( "MirrorRgn not supported\n" );
7010 DestroyWindow(hwnd);
7013 static void test_rtl_layout(void)
7015 HWND parent, child;
7016 RECT r;
7017 POINT pt;
7019 if (!pSetProcessDefaultLayout)
7021 win_skip( "SetProcessDefaultLayout not supported\n" );
7022 return;
7025 parent = CreateWindowExA(WS_EX_LAYOUTRTL, "static", NULL, WS_POPUP, 100, 100, 300, 300, NULL, 0, 0, NULL);
7026 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 10, 10, 20, 20, parent, 0, 0, NULL);
7028 GetWindowRect( parent, &r );
7029 ok( r.left == 100 && r.right == 400, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
7030 GetClientRect( parent, &r );
7031 ok( r.left == 0 && r.right == 300, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
7032 GetClientRect( child, &r );
7033 ok( r.left == 0 && r.right == 20, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
7034 MapWindowPoints( child, parent, (POINT *)&r, 2 );
7035 ok( r.left == 10 && r.right == 30, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
7036 GetWindowRect( child, &r );
7037 ok( r.left == 370 && r.right == 390, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
7038 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
7039 ok( r.left == 10 && r.right == 30, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
7040 GetWindowRect( child, &r );
7041 MapWindowPoints( NULL, parent, (POINT *)&r, 1 );
7042 MapWindowPoints( NULL, parent, (POINT *)&r + 1, 1 );
7043 ok( r.left == 30 && r.right == 10, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
7044 pt.x = pt.y = 12;
7045 MapWindowPoints( child, parent, &pt, 1 );
7046 ok( pt.x == 22 && pt.y == 22, "wrong point %d,%d\n", pt.x, pt.y );
7047 SetWindowPos( parent, 0, 0, 0, 250, 250, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
7048 GetWindowRect( parent, &r );
7049 ok( r.left == 100 && r.right == 350, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
7050 GetWindowRect( child, &r );
7051 ok( r.left == 320 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
7052 SetWindowLongW( parent, GWL_EXSTYLE, 0 );
7053 GetWindowRect( child, &r );
7054 ok( r.left == 320 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
7055 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
7056 ok( r.left == 220 && r.right == 240, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
7057 SetWindowLongW( parent, GWL_EXSTYLE, WS_EX_LAYOUTRTL );
7058 GetWindowRect( child, &r );
7059 ok( r.left == 320 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
7060 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
7061 ok( r.left == 10 && r.right == 30, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
7062 SetWindowPos( child, 0, 0, 0, 30, 30, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
7063 GetWindowRect( child, &r );
7064 ok( r.left == 310 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
7065 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
7066 ok( r.left == 10 && r.right == 40, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
7067 DestroyWindow( child );
7068 DestroyWindow( parent );
7071 static void test_FlashWindowEx(void)
7073 HWND hwnd;
7074 FLASHWINFO finfo;
7075 BOOL prev, ret;
7077 if (!pFlashWindowEx)
7079 win_skip( "FlashWindowEx not supported\n" );
7080 return;
7083 hwnd = CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_POPUP,
7084 0, 0, 0, 0, 0, 0, 0, NULL );
7085 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
7087 finfo.cbSize = sizeof(FLASHWINFO);
7088 finfo.dwFlags = FLASHW_TIMER;
7089 finfo.uCount = 3;
7090 finfo.dwTimeout = 200;
7091 finfo.hwnd = NULL;
7092 SetLastError(0xdeadbeef);
7093 ret = pFlashWindowEx(&finfo);
7094 todo_wine ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
7095 "FlashWindowEx returned with %d\n", GetLastError());
7097 finfo.hwnd = hwnd;
7098 SetLastError(0xdeadbeef);
7099 ret = pFlashWindowEx(NULL);
7100 todo_wine ok(!ret && GetLastError() == ERROR_NOACCESS,
7101 "FlashWindowEx returned with %d\n", GetLastError());
7103 SetLastError(0xdeadbeef);
7104 ret = pFlashWindowEx(&finfo);
7105 todo_wine ok(!ret, "previous window state should not be active\n");
7107 finfo.cbSize = sizeof(FLASHWINFO) - 1;
7108 SetLastError(0xdeadbeef);
7109 ret = pFlashWindowEx(&finfo);
7110 todo_wine ok(!ret && GetLastError()==ERROR_INVALID_PARAMETER,
7111 "FlashWindowEx succeeded\n");
7113 finfo.cbSize = sizeof(FLASHWINFO) + 1;
7114 SetLastError(0xdeadbeef);
7115 ret = pFlashWindowEx(&finfo);
7116 todo_wine ok(!ret && GetLastError()==ERROR_INVALID_PARAMETER,
7117 "FlashWindowEx succeeded\n");
7118 finfo.cbSize = sizeof(FLASHWINFO);
7120 DestroyWindow( hwnd );
7122 SetLastError(0xdeadbeef);
7123 ret = pFlashWindowEx(&finfo);
7124 todo_wine ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
7125 "FlashWindowEx returned with %d\n", GetLastError());
7127 ok(finfo.cbSize == sizeof(FLASHWINFO), "FlashWindowEx modified cdSize to %x\n", finfo.cbSize);
7128 ok(finfo.hwnd == hwnd, "FlashWindowEx modified hwnd to %p\n", finfo.hwnd);
7129 ok(finfo.dwFlags == FLASHW_TIMER, "FlashWindowEx modified dwFlags to %x\n", finfo.dwFlags);
7130 ok(finfo.uCount == 3, "FlashWindowEx modified uCount to %x\n", finfo.uCount);
7131 ok(finfo.dwTimeout == 200, "FlashWindowEx modified dwTimeout to %x\n", finfo.dwTimeout);
7133 hwnd = CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_VISIBLE | WS_POPUPWINDOW,
7134 0, 0, 0, 0, 0, 0, 0, NULL );
7135 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
7136 finfo.hwnd = hwnd;
7138 SetLastError(0xdeadbeef);
7139 ret = pFlashWindowEx(NULL);
7140 todo_wine ok(!ret && GetLastError() == ERROR_NOACCESS,
7141 "FlashWindowEx returned with %d\n", GetLastError());
7143 SetLastError(0xdeadbeef);
7144 prev = pFlashWindowEx(&finfo);
7146 ok(finfo.cbSize == sizeof(FLASHWINFO), "FlashWindowEx modified cdSize to %x\n", finfo.cbSize);
7147 ok(finfo.hwnd == hwnd, "FlashWindowEx modified hwnd to %p\n", finfo.hwnd);
7148 ok(finfo.dwFlags == FLASHW_TIMER, "FlashWindowEx modified dwFlags to %x\n", finfo.dwFlags);
7149 ok(finfo.uCount == 3, "FlashWindowEx modified uCount to %x\n", finfo.uCount);
7150 ok(finfo.dwTimeout == 200, "FlashWindowEx modified dwTimeout to %x\n", finfo.dwTimeout);
7152 finfo.dwFlags = FLASHW_STOP;
7153 SetLastError(0xdeadbeef);
7154 ret = pFlashWindowEx(&finfo);
7155 todo_wine
7156 ok(prev != ret, "previous window state should be different\n");
7158 DestroyWindow( hwnd );
7161 static void test_FindWindowEx(void)
7163 HWND hwnd, found;
7165 hwnd = CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP, 0,0,0,0, 0, 0, 0, NULL );
7166 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
7168 num_gettext_msgs = 0;
7169 found = FindWindowExA( 0, 0, "MainWindowClass", "" );
7170 ok( found == NULL, "expected a NULL hwnd\n" );
7171 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
7173 num_gettext_msgs = 0;
7174 found = FindWindowExA( 0, 0, "MainWindowClass", NULL );
7175 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
7176 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
7178 num_gettext_msgs = 0;
7179 found = FindWindowExA( 0, 0, "MainWindowClass", "caption" );
7180 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
7181 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
7183 DestroyWindow( hwnd );
7185 hwnd = CreateWindowExA( 0, "MainWindowClass", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL );
7186 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
7188 num_gettext_msgs = 0;
7189 found = FindWindowExA( 0, 0, "MainWindowClass", "" );
7190 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
7191 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
7193 num_gettext_msgs = 0;
7194 found = FindWindowExA( 0, 0, "MainWindowClass", NULL );
7195 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
7196 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
7198 DestroyWindow( hwnd );
7200 /* test behaviour with a window title that is an empty character */
7201 found = FindWindowExA( 0, 0, "Shell_TrayWnd", "" );
7202 ok( found != NULL, "found is NULL, expected a valid hwnd\n" );
7203 found = FindWindowExA( 0, 0, "Shell_TrayWnd", NULL );
7204 ok( found != NULL, "found is NULL, expected a valid hwnd\n" );
7207 static void test_GetLastActivePopup(void)
7209 HWND hwndOwner, hwndPopup1, hwndPopup2;
7211 hwndOwner = CreateWindowExA(0, "MainWindowClass", NULL,
7212 WS_VISIBLE | WS_POPUPWINDOW,
7213 100, 100, 200, 200,
7214 NULL, 0, GetModuleHandleA(NULL), NULL);
7215 hwndPopup1 = CreateWindowExA(0, "MainWindowClass", NULL,
7216 WS_VISIBLE | WS_POPUPWINDOW,
7217 100, 100, 200, 200,
7218 hwndOwner, 0, GetModuleHandleA(NULL), NULL);
7219 hwndPopup2 = CreateWindowExA(0, "MainWindowClass", NULL,
7220 WS_VISIBLE | WS_POPUPWINDOW,
7221 100, 100, 200, 200,
7222 hwndPopup1, 0, GetModuleHandleA(NULL), NULL);
7223 ok( GetLastActivePopup(hwndOwner) == hwndPopup2, "wrong last active popup\n" );
7224 DestroyWindow( hwndPopup2 );
7225 DestroyWindow( hwndPopup1 );
7226 DestroyWindow( hwndOwner );
7229 static LRESULT WINAPI my_httrasparent_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
7231 if (msg == WM_NCHITTEST) return HTTRANSPARENT;
7232 return DefWindowProcA(hwnd, msg, wp, lp);
7235 static LRESULT WINAPI my_window_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
7237 return DefWindowProcA(hwnd, msg, wp, lp);
7240 static void create_window_tree(HWND parent, HWND *window, int size)
7242 static const DWORD style[] = { 0, WS_VISIBLE, WS_DISABLED, WS_VISIBLE | WS_DISABLED };
7243 int i, pos;
7245 memset(window, 0, size * sizeof(window[0]));
7247 pos = 0;
7248 for (i = 0; i < sizeof(style)/sizeof(style[0]); i++)
7250 assert(pos < size);
7251 window[pos] = CreateWindowExA(0, "my_window", NULL, style[i] | WS_CHILD,
7252 0, 0, 100, 100, parent, 0, 0, NULL);
7253 ok(window[pos] != 0, "CreateWindowEx failed\n");
7254 pos++;
7255 assert(pos < size);
7256 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_window", NULL, style[i] | WS_CHILD,
7257 0, 0, 100, 100, parent, 0, 0, NULL);
7258 ok(window[pos] != 0, "CreateWindowEx failed\n");
7259 pos++;
7261 assert(pos < size);
7262 window[pos] = CreateWindowExA(0, "my_httrasparent", NULL, style[i] | WS_CHILD,
7263 0, 0, 100, 100, parent, 0, 0, NULL);
7264 ok(window[pos] != 0, "CreateWindowEx failed\n");
7265 pos++;
7266 assert(pos < size);
7267 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_httrasparent", NULL, style[i] | WS_CHILD,
7268 0, 0, 100, 100, parent, 0, 0, NULL);
7269 ok(window[pos] != 0, "CreateWindowEx failed\n");
7270 pos++;
7272 assert(pos < size);
7273 window[pos] = CreateWindowExA(0, "my_button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
7274 0, 0, 100, 100, parent, 0, 0, NULL);
7275 ok(window[pos] != 0, "CreateWindowEx failed\n");
7276 pos++;
7277 assert(pos < size);
7278 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
7279 0, 0, 100, 100, parent, 0, 0, NULL);
7280 ok(window[pos] != 0, "CreateWindowEx failed\n");
7281 pos++;
7282 assert(pos < size);
7283 window[pos] = CreateWindowExA(0, "my_button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
7284 0, 0, 100, 100, parent, 0, 0, NULL);
7285 ok(window[pos] != 0, "CreateWindowEx failed\n");
7286 pos++;
7287 assert(pos < size);
7288 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
7289 0, 0, 100, 100, parent, 0, 0, NULL);
7290 ok(window[pos] != 0, "CreateWindowEx failed\n");
7291 pos++;
7293 assert(pos < size);
7294 window[pos] = CreateWindowExA(0, "Button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
7295 0, 0, 100, 100, parent, 0, 0, NULL);
7296 ok(window[pos] != 0, "CreateWindowEx failed\n");
7297 pos++;
7298 assert(pos < size);
7299 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "Button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
7300 0, 0, 100, 100, parent, 0, 0, NULL);
7301 ok(window[pos] != 0, "CreateWindowEx failed\n");
7302 pos++;
7303 assert(pos < size);
7304 window[pos] = CreateWindowExA(0, "Button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
7305 0, 0, 100, 100, parent, 0, 0, NULL);
7306 ok(window[pos] != 0, "CreateWindowEx failed\n");
7307 pos++;
7308 assert(pos < size);
7309 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "Button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
7310 0, 0, 100, 100, parent, 0, 0, NULL);
7311 ok(window[pos] != 0, "CreateWindowEx failed\n");
7312 pos++;
7314 assert(pos < size);
7315 window[pos] = CreateWindowExA(0, "Static", NULL, style[i] | WS_CHILD,
7316 0, 0, 100, 100, parent, 0, 0, NULL);
7317 ok(window[pos] != 0, "CreateWindowEx failed\n");
7318 pos++;
7319 assert(pos < size);
7320 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "Static", NULL, style[i] | WS_CHILD,
7321 0, 0, 100, 100, parent, 0, 0, NULL);
7322 ok(window[pos] != 0, "CreateWindowEx failed\n");
7323 pos++;
7327 struct window_attributes
7329 char class_name[128];
7330 BOOL is_visible, is_enabled, is_groupbox, is_httransparent, is_extransparent;
7333 static void get_window_attributes(HWND hwnd, struct window_attributes *attrs)
7335 DWORD style, ex_style, hittest;
7337 style = GetWindowLongA(hwnd, GWL_STYLE);
7338 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
7339 attrs->class_name[0] = 0;
7340 GetClassNameA(hwnd, attrs->class_name, sizeof(attrs->class_name));
7341 hittest = SendMessageA(hwnd, WM_NCHITTEST, 0, 0);
7343 attrs->is_visible = (style & WS_VISIBLE) != 0;
7344 attrs->is_enabled = (style & WS_DISABLED) == 0;
7345 attrs->is_groupbox = !lstrcmpiA(attrs->class_name, "Button") && (style & BS_TYPEMASK) == BS_GROUPBOX;
7346 attrs->is_httransparent = hittest == HTTRANSPARENT;
7347 attrs->is_extransparent = (ex_style & WS_EX_TRANSPARENT) != 0;
7350 static int window_to_index(HWND hwnd, HWND *window, int size)
7352 int i;
7354 for (i = 0; i < size; i++)
7356 if (!window[i]) break;
7357 if (window[i] == hwnd) return i;
7359 return -1;
7362 static void test_child_window_from_point(void)
7364 static const int real_child_pos[] = { 14,15,16,17,18,19,20,21,24,25,26,27,42,43,
7365 44,45,46,47,48,49,52,53,54,55,51,50,23,22,-1 };
7366 static const int real_child_pos_nt4[] = { 14,15,16,17,20,21,24,25,26,27,42,43,44,45,
7367 48,49,52,53,54,55,51,50,47,46,23,22,19,18,-1 };
7368 WNDCLASSA cls;
7369 HWND hwnd, parent, window[100];
7370 POINT pt;
7371 int found_invisible, found_disabled, found_groupbox, found_httransparent, found_extransparent;
7372 int ret, i;
7374 ret = GetClassInfoA(0, "Button", &cls);
7375 ok(ret, "GetClassInfo(Button) failed\n");
7376 cls.lpszClassName = "my_button";
7377 ret = RegisterClassA(&cls);
7378 ok(ret, "RegisterClass(my_button) failed\n");
7380 cls.lpszClassName = "my_httrasparent";
7381 cls.lpfnWndProc = my_httrasparent_proc;
7382 ret = RegisterClassA(&cls);
7383 ok(ret, "RegisterClass(my_httrasparent) failed\n");
7385 cls.lpszClassName = "my_window";
7386 cls.lpfnWndProc = my_window_proc;
7387 ret = RegisterClassA(&cls);
7388 ok(ret, "RegisterClass(my_window) failed\n");
7390 parent = CreateWindowExA(0, "MainWindowClass", NULL,
7391 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE,
7392 100, 100, 200, 200,
7393 0, 0, GetModuleHandleA(NULL), NULL);
7394 ok(parent != 0, "CreateWindowEx failed\n");
7395 trace("parent %p\n", parent);
7397 create_window_tree(parent, window, sizeof(window)/sizeof(window[0]));
7399 found_invisible = 0;
7400 found_disabled = 0;
7401 found_groupbox = 0;
7402 found_httransparent = 0;
7403 found_extransparent = 0;
7405 /* FIXME: also test WindowFromPoint, ChildWindowFromPoint, ChildWindowFromPointEx */
7406 for (i = 0; i < sizeof(real_child_pos)/sizeof(real_child_pos[0]); i++)
7408 struct window_attributes attrs;
7410 pt.x = pt.y = 50;
7411 hwnd = RealChildWindowFromPoint(parent, pt);
7412 ok(hwnd != 0, "RealChildWindowFromPoint failed\n");
7413 ret = window_to_index(hwnd, window, sizeof(window)/sizeof(window[0]));
7414 /* FIXME: remove once Wine is fixed */
7415 if (ret != real_child_pos[i])
7416 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);
7417 else
7418 ok(ret == real_child_pos[i] || broken(ret == real_child_pos_nt4[i]), "expected %d, got %d\n", real_child_pos[i], ret);
7420 get_window_attributes(hwnd, &attrs);
7421 if (!attrs.is_visible) found_invisible++;
7422 if (!attrs.is_enabled) found_disabled++;
7423 if (attrs.is_groupbox) found_groupbox++;
7424 if (attrs.is_httransparent) found_httransparent++;
7425 if (attrs.is_extransparent) found_extransparent++;
7427 if (ret != real_child_pos[i] && ret != -1)
7429 trace("found hwnd %p (%s), is_visible %d, is_enabled %d, is_groupbox %d, is_httransparent %d, is_extransparent %d\n",
7430 hwnd, attrs.class_name, attrs.is_visible, attrs.is_enabled, attrs.is_groupbox, attrs.is_httransparent, attrs.is_extransparent);
7431 get_window_attributes(window[real_child_pos[i]], &attrs);
7432 trace("expected hwnd %p (%s), is_visible %d, is_enabled %d, is_groupbox %d, is_httransparent %d, is_extransparent %d\n",
7433 window[real_child_pos[i]], attrs.class_name, attrs.is_visible, attrs.is_enabled, attrs.is_groupbox, attrs.is_httransparent, attrs.is_extransparent);
7435 if (ret == -1)
7437 ok(hwnd == parent, "expected %p, got %p\n", parent, hwnd);
7438 break;
7440 DestroyWindow(hwnd);
7443 DestroyWindow(parent);
7445 ok(!found_invisible, "found %d invisible windows\n", found_invisible);
7446 ok(found_disabled, "found %d disabled windows\n", found_disabled);
7447 todo_wine
7448 ok(found_groupbox == 4, "found %d groupbox windows\n", found_groupbox);
7449 ok(found_httransparent, "found %d httransparent windows\n", found_httransparent);
7450 todo_wine
7451 ok(found_extransparent, "found %d extransparent windows\n", found_extransparent);
7453 ret = UnregisterClassA("my_button", cls.hInstance);
7454 ok(ret, "UnregisterClass(my_button) failed\n");
7455 ret = UnregisterClassA("my_httrasparent", cls.hInstance);
7456 ok(ret, "UnregisterClass(my_httrasparent) failed\n");
7457 ret = UnregisterClassA("my_window", cls.hInstance);
7458 ok(ret, "UnregisterClass(my_window) failed\n");
7461 static void simulate_click(int x, int y)
7463 INPUT input[2];
7464 UINT events_no;
7466 SetCursorPos(x, y);
7467 memset(input, 0, sizeof(input));
7468 input[0].type = INPUT_MOUSE;
7469 U(input[0]).mi.dx = x;
7470 U(input[0]).mi.dy = y;
7471 U(input[0]).mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
7472 input[1].type = INPUT_MOUSE;
7473 U(input[1]).mi.dx = x;
7474 U(input[1]).mi.dy = y;
7475 U(input[1]).mi.dwFlags = MOUSEEVENTF_LEFTUP;
7476 events_no = SendInput(2, input, sizeof(input[0]));
7477 ok(events_no == 2, "SendInput returned %d\n", events_no);
7480 static WNDPROC def_static_proc;
7481 static BOOL got_hittest;
7482 static LRESULT WINAPI static_hook_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
7484 if(msg == WM_NCHITTEST)
7485 got_hittest = TRUE;
7486 if(msg == WM_LBUTTONDOWN)
7487 ok(0, "unexpected call\n");
7489 return def_static_proc(hwnd, msg, wp, lp);
7492 static void window_from_point_proc(HWND parent)
7494 HANDLE start_event, end_event;
7495 HANDLE win, child_static, child_button;
7496 BOOL got_click;
7497 DWORD ret;
7498 POINT pt;
7499 MSG msg;
7501 start_event = OpenEventA(EVENT_ALL_ACCESS, FALSE, "test_wfp_start");
7502 ok(start_event != 0, "OpenEvent failed\n");
7503 end_event = OpenEventA(EVENT_ALL_ACCESS, FALSE, "test_wfp_end");
7504 ok(end_event != 0, "OpenEvent failed\n");
7506 child_static = CreateWindowExA(0, "static", "static", WS_CHILD | WS_VISIBLE,
7507 0, 0, 100, 100, parent, 0, NULL, NULL);
7508 ok(child_static != 0, "CreateWindowEx failed\n");
7509 pt.x = pt.y = 150;
7510 win = WindowFromPoint(pt);
7511 ok(win == parent, "WindowFromPoint returned %p, expected %p\n", win, parent);
7513 child_button = CreateWindowExA(0, "button", "button", WS_CHILD | WS_VISIBLE,
7514 100, 0, 100, 100, parent, 0, NULL, NULL);
7515 ok(child_button != 0, "CreateWindowEx failed\n");
7516 pt.x = 250;
7517 win = WindowFromPoint(pt);
7518 ok(win == child_button, "WindowFromPoint returned %p, expected %p\n", win, child_button);
7520 /* without this window simulate click test keeps sending WM_NCHITTEST
7521 * message to child_static in an infinite loop */
7522 win = CreateWindowExA(0, "button", "button", WS_CHILD | WS_VISIBLE,
7523 0, 0, 100, 100, parent, 0, NULL, NULL);
7524 ok(win != 0, "CreateWindowEx failed\n");
7525 def_static_proc = (void*)SetWindowLongPtrA(child_static,
7526 GWLP_WNDPROC, (LONG_PTR)static_hook_proc);
7527 flush_events(TRUE);
7528 SetEvent(start_event);
7530 got_hittest = FALSE;
7531 got_click = FALSE;
7532 while(!got_click && wait_for_message(&msg)) {
7533 if(msg.message == WM_LBUTTONUP) {
7534 ok(msg.hwnd == win, "msg.hwnd = %p, expected %p\n", msg.hwnd, win);
7535 got_click = TRUE;
7537 DispatchMessageA(&msg);
7539 ok(got_hittest, "transparent window didn't get WM_NCHITTEST message\n");
7540 ok(got_click, "button under static window didn't get WM_LBUTTONUP\n");
7542 ret = WaitForSingleObject(end_event, 5000);
7543 ok(ret == WAIT_OBJECT_0, "WaitForSingleObject returned %x\n", ret);
7545 CloseHandle(start_event);
7546 CloseHandle(end_event);
7549 static void test_window_from_point(const char *argv0)
7551 HWND hwnd, child, win;
7552 POINT pt;
7553 PROCESS_INFORMATION info;
7554 STARTUPINFOA startup;
7555 char cmd[MAX_PATH];
7556 HANDLE start_event, end_event;
7558 hwnd = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP | WS_VISIBLE,
7559 100, 100, 200, 100, 0, 0, NULL, NULL);
7560 ok(hwnd != 0, "CreateWindowEx failed\n");
7562 pt.x = pt.y = 150;
7563 win = WindowFromPoint(pt);
7564 pt.x = 250;
7565 if(win == hwnd)
7566 win = WindowFromPoint(pt);
7567 if(win != hwnd) {
7568 skip("there's another window covering test window\n");
7569 DestroyWindow(hwnd);
7570 return;
7573 child = CreateWindowExA(0, "static", "static", WS_CHILD | WS_VISIBLE,
7574 0, 0, 100, 100, hwnd, 0, NULL, NULL);
7575 ok(child != 0, "CreateWindowEx failed\n");
7576 pt.x = pt.y = 150;
7577 win = WindowFromPoint(pt);
7578 ok(win == hwnd, "WindowFromPoint returned %p, expected %p\n", win, hwnd);
7579 DestroyWindow(child);
7581 child = CreateWindowExA(0, "button", "button", WS_CHILD | WS_VISIBLE,
7582 0, 0, 100, 100, hwnd, 0, NULL, NULL);
7583 ok(child != 0, "CreateWindowEx failed\n");
7584 win = WindowFromPoint(pt);
7585 ok(win == child, "WindowFromPoint returned %p, expected %p\n", win, child);
7586 DestroyWindow(child);
7588 start_event = CreateEventA(NULL, FALSE, FALSE, "test_wfp_start");
7589 ok(start_event != 0, "CreateEvent failed\n");
7590 end_event = CreateEventA(NULL, FALSE, FALSE, "test_wfp_end");
7591 ok(start_event != 0, "CreateEvent failed\n");
7593 sprintf(cmd, "%s win create_children %p\n", argv0, hwnd);
7594 memset(&startup, 0, sizeof(startup));
7595 startup.cb = sizeof(startup);
7596 ok(CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL,
7597 &startup, &info), "CreateProcess failed.\n");
7598 ok(wait_for_event(start_event, 1000), "didn't get start_event\n");
7600 child = GetWindow(hwnd, GW_CHILD);
7601 win = WindowFromPoint(pt);
7602 ok(win == child, "WindowFromPoint returned %p, expected %p\n", win, child);
7604 simulate_click(150, 150);
7605 flush_events(TRUE);
7607 child = GetWindow(child, GW_HWNDNEXT);
7608 pt.x = 250;
7609 win = WindowFromPoint(pt);
7610 ok(win == child, "WindowFromPoint returned %p, expected %p\n", win, child);
7612 SetEvent(end_event);
7613 winetest_wait_child_process(info.hProcess);
7614 CloseHandle(start_event);
7615 CloseHandle(end_event);
7616 CloseHandle(info.hProcess);
7617 CloseHandle(info.hThread);
7619 DestroyWindow(hwnd);
7622 static void test_map_points(void)
7624 BOOL ret;
7625 POINT p;
7626 HWND wnd, wnd0, dwnd;
7627 INT n;
7628 DWORD err;
7629 POINT pos = { 100, 200 };
7630 int width = 150;
7631 int height = 150;
7632 RECT window_rect;
7633 RECT client_rect;
7635 /* Create test windows */
7636 wnd = CreateWindowA("static", "test1", WS_POPUP, pos.x, pos.y, width, height, NULL, NULL, NULL, NULL);
7637 ok(wnd != NULL, "Failed %p\n", wnd);
7638 wnd0 = CreateWindowA("static", "test2", WS_POPUP, 0, 0, width, height, NULL, NULL, NULL, NULL);
7639 ok(wnd0 != NULL, "Failed %p\n", wnd);
7640 dwnd = CreateWindowA("static", "test3", 0, 200, 300, 150, 150, NULL, NULL, NULL, NULL);
7641 DestroyWindow(dwnd);
7642 ok(dwnd != NULL, "Failed %p\n", dwnd);
7644 /* Verify window rect and client rect (they should have the same width and height) */
7645 GetWindowRect(wnd, &window_rect);
7646 ok(window_rect.left == pos.x, "left is %d instead of %d\n", window_rect.left, pos.x);
7647 ok(window_rect.top == pos.y, "top is %d instead of %d\n", window_rect.top, pos.y);
7648 ok(window_rect.right == pos.x + width, "right is %d instead of %d\n", window_rect.right, pos.x + width);
7649 ok(window_rect.bottom == pos.y + height, "bottom is %d instead of %d\n", window_rect.bottom, pos.y + height);
7650 GetClientRect(wnd, &client_rect);
7651 ok(client_rect.left == 0, "left is %d instead of 0\n", client_rect.left);
7652 ok(client_rect.top == 0, "top is %d instead of 0\n", client_rect.top);
7653 ok(client_rect.right == width, "right is %d instead of %d\n", client_rect.right, width);
7654 ok(client_rect.bottom == height, "bottom is %d instead of %d\n", client_rect.bottom, height);
7656 /* Test MapWindowPoints */
7658 /* MapWindowPoints(NULL or wnd, NULL or wnd, NULL, 1); crashes on Windows */
7660 SetLastError(0xdeadbeef);
7661 n = MapWindowPoints(NULL, NULL, NULL, 0);
7662 err = GetLastError();
7663 ok(n == 0, "Got %d, expected %d\n", n, 0);
7664 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7666 SetLastError(0xdeadbeef);
7667 n = MapWindowPoints(wnd, wnd, NULL, 0);
7668 err = GetLastError();
7669 ok(n == 0, "Got %d, expected %d\n", n, 0);
7670 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7672 n = MapWindowPoints(wnd, NULL, NULL, 0);
7673 ok(n == MAKELONG(window_rect.left, window_rect.top), "Got %x, expected %x\n",
7674 n, MAKELONG(window_rect.left, window_rect.top));
7676 n = MapWindowPoints(NULL, wnd, NULL, 0);
7677 ok(n == MAKELONG(-window_rect.left, -window_rect.top), "Got %x, expected %x\n",
7678 n, MAKELONG(-window_rect.left, -window_rect.top));
7680 SetLastError(0xdeadbeef);
7681 p.x = p.y = 100;
7682 n = MapWindowPoints(dwnd, NULL, &p, 1);
7683 err = GetLastError();
7684 ok(n == 0, "Got %d, expected %d\n", n, 0);
7685 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7686 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7688 SetLastError(0xdeadbeef);
7689 p.x = p.y = 100;
7690 n = MapWindowPoints(dwnd, wnd, &p, 1);
7691 err = GetLastError();
7692 ok(n == 0, "Got %d, expected %d\n", n, 0);
7693 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7694 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7696 SetLastError(0xdeadbeef);
7697 p.x = p.y = 100;
7698 n = MapWindowPoints(NULL, dwnd, &p, 1);
7699 err = GetLastError();
7700 ok(n == 0, "Got %d, expected %d\n", n, 0);
7701 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7702 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7704 SetLastError(0xdeadbeef);
7705 p.x = p.y = 100;
7706 n = MapWindowPoints(wnd, dwnd, &p, 1);
7707 err = GetLastError();
7708 ok(n == 0, "Got %d, expected %d\n", n, 0);
7709 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7710 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7712 SetLastError(0xdeadbeef);
7713 p.x = p.y = 100;
7714 n = MapWindowPoints(dwnd, dwnd, &p, 1);
7715 err = GetLastError();
7716 ok(n == 0, "Got %d, expected %d\n", n, 0);
7717 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7718 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7720 SetLastError(0xdeadbeef);
7721 p.x = p.y = 100;
7722 n = MapWindowPoints(NULL, NULL, &p, 1);
7723 err = GetLastError();
7724 ok(n == 0, "Got %d, expected %d\n", n, 0);
7725 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7726 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7728 SetLastError(0xdeadbeef);
7729 p.x = p.y = 100;
7730 n = MapWindowPoints(wnd, wnd, &p, 1);
7731 err = GetLastError();
7732 ok(n == 0, "Got %d, expected %d\n", n, 0);
7733 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7734 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7736 p.x = p.y = 100;
7737 n = MapWindowPoints(wnd, NULL, &p, 1);
7738 ok(n == MAKELONG(window_rect.left, window_rect.top), "Got %x, expected %x\n",
7739 n, MAKELONG(window_rect.left, window_rect.top));
7740 ok((p.x == (window_rect.left + 100)) && (p.y == (window_rect.top + 100)), "Failed got (%d, %d), expected (%d, %d)\n",
7741 p.x, p.y, window_rect.left + 100, window_rect.top + 100);
7743 p.x = p.y = 100;
7744 n = MapWindowPoints(NULL, wnd, &p, 1);
7745 ok(n == MAKELONG(-window_rect.left, -window_rect.top), "Got %x, expected %x\n",
7746 n, MAKELONG(-window_rect.left, -window_rect.top));
7747 ok((p.x == (-window_rect.left + 100)) && (p.y == (-window_rect.top + 100)), "Failed got (%d, %d), expected (%d, %d)\n",
7748 p.x, p.y, -window_rect.left + 100, -window_rect.top + 100);
7750 SetLastError(0xdeadbeef);
7751 p.x = p.y = 0;
7752 n = MapWindowPoints(wnd0, NULL, &p, 1);
7753 err = GetLastError();
7754 ok(n == 0, "Got %x, expected 0\n", n);
7755 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
7756 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7758 SetLastError(0xdeadbeef);
7759 p.x = p.y = 0;
7760 n = MapWindowPoints(NULL, wnd0, &p, 1);
7761 err = GetLastError();
7762 ok(n == 0, "Got %x, expected 0\n", n);
7763 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
7764 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7766 /* Test ClientToScreen */
7768 /* ClientToScreen(wnd, NULL); crashes on Windows */
7770 SetLastError(0xdeadbeef);
7771 ret = ClientToScreen(NULL, NULL);
7772 err = GetLastError();
7773 ok(!ret, "Should fail\n");
7774 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7776 SetLastError(0xdeadbeef);
7777 p.x = p.y = 100;
7778 ret = ClientToScreen(NULL, &p);
7779 err = GetLastError();
7780 ok(!ret, "Should fail\n");
7781 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7782 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7784 SetLastError(0xdeadbeef);
7785 p.x = p.y = 100;
7786 ret = ClientToScreen(dwnd, &p);
7787 err = GetLastError();
7788 ok(!ret, "Should fail\n");
7789 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7790 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7792 p.x = p.y = 100;
7793 ret = ClientToScreen(wnd, &p);
7794 ok(ret, "Failed with error %u\n", GetLastError());
7795 ok((p.x == (window_rect.left + 100)) && (p.y == (window_rect.top + 100)), "Failed got (%d, %d), expected (%d, %d)\n",
7796 p.x, p.y, window_rect.left + 100, window_rect.top + 100);
7798 p.x = p.y = 0;
7799 ret = ClientToScreen(wnd0, &p);
7800 ok(ret, "Failed with error %u\n", GetLastError());
7801 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
7803 /* Test ScreenToClient */
7805 /* ScreenToClient(wnd, NULL); crashes on Windows */
7807 SetLastError(0xdeadbeef);
7808 ret = ScreenToClient(NULL, NULL);
7809 err = GetLastError();
7810 ok(!ret, "Should fail\n");
7811 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7813 SetLastError(0xdeadbeef);
7814 p.x = p.y = 100;
7815 ret = ScreenToClient(NULL, &p);
7816 err = GetLastError();
7817 ok(!ret, "Should fail\n");
7818 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7819 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7821 SetLastError(0xdeadbeef);
7822 p.x = p.y = 100;
7823 ret = ScreenToClient(dwnd, &p);
7824 err = GetLastError();
7825 ok(!ret, "Should fail\n");
7826 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7827 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7829 p.x = p.y = 100;
7830 ret = ScreenToClient(wnd, &p);
7831 ok(ret, "Failed with error %u\n", GetLastError());
7832 ok((p.x == (-window_rect.left + 100)) && (p.y == (-window_rect.top + 100)), "Failed got(%d, %d), expected (%d, %d)\n",
7833 p.x, p.y, -window_rect.left + 100, -window_rect.top + 100);
7835 p.x = p.y = 0;
7836 ret = ScreenToClient(wnd0, &p);
7837 ok(ret, "Failed with error %u\n", GetLastError());
7838 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
7840 DestroyWindow(wnd);
7841 DestroyWindow(wnd0);
7844 static void test_update_region(void)
7846 HWND hwnd, parent, child;
7847 HRGN rgn1, rgn2;
7848 const RECT rc = {15, 15, 40, 40};
7849 const POINT wnd_orig = {30, 20};
7850 const POINT child_orig = {10, 5};
7852 parent = CreateWindowExA(0, "MainWindowClass", NULL,
7853 WS_VISIBLE | WS_CLIPCHILDREN,
7854 0, 0, 300, 150, NULL, NULL, GetModuleHandleA(0), 0);
7855 hwnd = CreateWindowExA(0, "MainWindowClass", NULL,
7856 WS_VISIBLE | WS_CLIPCHILDREN | WS_CHILD,
7857 0, 0, 200, 100, parent, NULL, GetModuleHandleA(0), 0);
7858 child = CreateWindowExA(0, "MainWindowClass", NULL,
7859 WS_VISIBLE | WS_CHILD,
7860 child_orig.x, child_orig.y, 100, 50,
7861 hwnd, NULL, GetModuleHandleA(0), 0);
7862 assert(parent && hwnd && child);
7864 ValidateRgn(parent, NULL);
7865 ValidateRgn(hwnd, NULL);
7866 InvalidateRect(hwnd, &rc, FALSE);
7867 ValidateRgn(child, NULL);
7869 rgn1 = CreateRectRgn(0, 0, 0, 0);
7870 ok(GetUpdateRgn(parent, rgn1, FALSE) == NULLREGION,
7871 "has invalid area after ValidateRgn(NULL)\n");
7872 GetUpdateRgn(hwnd, rgn1, FALSE);
7873 rgn2 = CreateRectRgnIndirect(&rc);
7874 ok(EqualRgn(rgn1, rgn2), "assigned and retrieved update regions are different\n");
7875 ok(GetUpdateRgn(child, rgn2, FALSE) == NULLREGION,
7876 "has invalid area after ValidateRgn(NULL)\n");
7878 SetWindowPos(hwnd, 0, wnd_orig.x, wnd_orig.y, 0, 0,
7879 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
7881 /* parent now has non-simple update region, it consist of
7882 * two rects, that was exposed after hwnd moving ... */
7883 SetRectRgn(rgn1, 0, 0, 200, wnd_orig.y);
7884 SetRectRgn(rgn2, 0, 0, wnd_orig.x, 100);
7885 CombineRgn(rgn1, rgn1, rgn2, RGN_OR);
7886 /* ... and mapped hwnd's invalid area, that hwnd has before moving */
7887 SetRectRgn(rgn2, rc.left + wnd_orig.x, rc.top + wnd_orig.y,
7888 rc.right + wnd_orig.x, rc.bottom + wnd_orig.y);
7889 CombineRgn(rgn1, rgn1, rgn2, RGN_OR);
7890 GetUpdateRgn(parent, rgn2, FALSE);
7891 todo_wine
7892 ok(EqualRgn(rgn1, rgn2), "wrong update region\n");
7894 /* hwnd has the same invalid region as before moving */
7895 SetRectRgn(rgn1, rc.left, rc.top, rc.right, rc.bottom);
7896 GetUpdateRgn(hwnd, rgn2, FALSE);
7897 ok(EqualRgn(rgn1, rgn2), "wrong update region\n");
7899 /* hwnd's invalid area maps to child during moving */
7900 SetRectRgn(rgn1, rc.left - child_orig.x , rc.top - child_orig.y,
7901 rc.right - child_orig.x, rc.bottom - child_orig.y);
7902 GetUpdateRgn(child, rgn2, FALSE);
7903 todo_wine
7904 ok(EqualRgn(rgn1, rgn2), "wrong update region\n");
7906 DeleteObject(rgn1);
7907 DeleteObject(rgn2);
7908 DestroyWindow(parent);
7911 static void test_window_without_child_style(void)
7913 HWND hwnd;
7915 hwnd = CreateWindowExA(0, "edit", NULL, WS_VISIBLE|WS_CHILD,
7916 0, 0, 50, 50, hwndMain, NULL, 0, NULL);
7917 ok(hwnd != NULL, "CreateWindow failed\n");
7919 ok(SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) & (~WS_CHILD)),
7920 "can't remove WS_CHILD style\n");
7922 SetActiveWindow(hwndMain);
7923 PostMessageW(hwnd, WM_LBUTTONUP, 0, 0);
7924 SendMessageW(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);
7925 check_active_state(hwnd, hwnd, hwnd);
7926 flush_events(TRUE);
7928 DestroyWindow(hwnd);
7932 struct smresult_thread_data
7934 HWND main_hwnd;
7935 HWND thread_hwnd;
7936 HANDLE thread_started;
7937 HANDLE thread_got_wm_app;
7938 HANDLE main_in_wm_app_1;
7939 HANDLE thread_replied;
7943 static LRESULT WINAPI smresult_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
7945 switch (msg)
7947 case WM_APP:
7949 struct smresult_thread_data *data = (struct smresult_thread_data*)lparam;
7951 ok(hwnd == data->thread_hwnd, "unexpected hwnd %p\n", hwnd);
7953 SendNotifyMessageA(data->main_hwnd, WM_APP+1, 0, lparam);
7955 /* Don't return until the main thread is processing our sent message. */
7956 ok(WaitForSingleObject(data->main_in_wm_app_1, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7958 /* Break the PeekMessage loop so we can notify the main thread after we return. */
7959 SetEvent(data->thread_got_wm_app);
7961 return 0x240408ea;
7963 case WM_APP+1:
7965 struct smresult_thread_data *data = (struct smresult_thread_data*)lparam;
7966 LRESULT res;
7968 ok(hwnd == data->main_hwnd, "unexpected hwnd %p\n", hwnd);
7970 /* Ask the thread to reply to our WM_APP message. */
7971 SetEvent(data->main_in_wm_app_1);
7973 /* Wait until the thread has sent a reply. */
7974 ok(WaitForSingleObject(data->thread_replied, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7976 /* Send another message while we have a reply queued for the current one. */
7977 res = SendMessageA(data->thread_hwnd, WM_APP+2, 0, lparam);
7978 ok(res == 0x449b0190, "unexpected result %lx\n", res);
7980 return 0;
7982 case WM_APP+2:
7984 struct smresult_thread_data *data = (struct smresult_thread_data*)lparam;
7986 ok(hwnd == data->thread_hwnd, "unexpected hwnd %p\n", hwnd);
7988 /* Don't return until we know the main thread is processing sent messages. */
7989 SendMessageA(data->main_hwnd, WM_NULL, 0, 0);
7991 return 0x449b0190;
7993 case WM_CLOSE:
7994 PostQuitMessage(0);
7995 break;
7997 return DefWindowProcA(hwnd, msg, wparam, lparam);
8000 static DWORD WINAPI smresult_thread_proc(void *param)
8002 MSG msg;
8003 struct smresult_thread_data *data = param;
8005 data->thread_hwnd = CreateWindowExA(0, "SmresultClass", "window caption text", WS_OVERLAPPEDWINDOW,
8006 100, 100, 200, 200, 0, 0, 0, NULL);
8007 ok(data->thread_hwnd != 0, "Failed to create overlapped window\n");
8009 SetEvent(data->thread_started);
8011 /* Loop until we've processed WM_APP. */
8012 while (WaitForSingleObject(data->thread_got_wm_app, 0) != WAIT_OBJECT_0)
8014 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
8016 TranslateMessage(&msg);
8017 DispatchMessageA(&msg);
8019 else
8021 MsgWaitForMultipleObjects(1, &data->thread_got_wm_app, FALSE, INFINITE, QS_SENDMESSAGE);
8025 /* Notify the main thread that we replied to its WM_APP message. */
8026 SetEvent(data->thread_replied);
8028 while (GetMessageA(&msg, 0, 0, 0))
8030 TranslateMessage(&msg);
8031 DispatchMessageA(&msg);
8034 return 0;
8037 static void test_smresult(void)
8039 WNDCLASSA cls;
8040 HANDLE hThread;
8041 DWORD tid;
8042 struct smresult_thread_data data;
8043 BOOL ret;
8044 LRESULT res;
8046 cls.style = CS_DBLCLKS;
8047 cls.lpfnWndProc = smresult_wndproc;
8048 cls.cbClsExtra = 0;
8049 cls.cbWndExtra = 0;
8050 cls.hInstance = GetModuleHandleA(0);
8051 cls.hIcon = 0;
8052 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
8053 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
8054 cls.lpszMenuName = NULL;
8055 cls.lpszClassName = "SmresultClass";
8057 ret = RegisterClassA(&cls);
8058 ok(ret, "RegisterClassA failed\n");
8060 data.thread_started = CreateEventA(NULL, TRUE, FALSE, NULL);
8061 ok(data.thread_started != NULL, "CreateEventA failed\n");
8063 data.thread_got_wm_app = CreateEventA(NULL, TRUE, FALSE, NULL);
8064 ok(data.thread_got_wm_app != NULL, "CreateEventA failed\n");
8066 data.main_in_wm_app_1 = CreateEventA(NULL, TRUE, FALSE, NULL);
8067 ok(data.main_in_wm_app_1 != NULL, "CreateEventA failed\n");
8069 data.thread_replied = CreateEventA(NULL, TRUE, FALSE, NULL);
8070 ok(data.thread_replied != NULL, "CreateEventA failed\n");
8072 data.main_hwnd = CreateWindowExA(0, "SmresultClass", "window caption text", WS_OVERLAPPEDWINDOW,
8073 100, 100, 200, 200, 0, 0, 0, NULL);
8075 hThread = CreateThread(NULL, 0, smresult_thread_proc, &data, 0, &tid);
8076 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
8078 ok(WaitForSingleObject(data.thread_started, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8080 res = SendMessageA(data.thread_hwnd, WM_APP, 0, (LPARAM)&data);
8081 ok(res == 0x240408ea, "unexpected result %lx\n", res);
8083 SendMessageA(data.thread_hwnd, WM_CLOSE, 0, 0);
8085 DestroyWindow(data.main_hwnd);
8087 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8089 CloseHandle(data.thread_started);
8090 CloseHandle(data.thread_got_wm_app);
8091 CloseHandle(data.main_in_wm_app_1);
8092 CloseHandle(data.thread_replied);
8095 static void test_GetMessagePos(void)
8097 HWND button;
8098 DWORD pos;
8099 MSG msg;
8101 button = CreateWindowExA(0, "button", "button", WS_VISIBLE,
8102 100, 100, 100, 100, 0, 0, 0, NULL);
8103 ok(button != 0, "CreateWindowExA failed\n");
8105 SetCursorPos(120, 140);
8106 flush_events(TRUE);
8107 pos = GetMessagePos();
8108 ok(pos == MAKELONG(120, 140), "pos = %08x\n", pos);
8110 SetCursorPos(340, 320);
8111 pos = GetMessagePos();
8112 ok(pos == MAKELONG(120, 140), "pos = %08x\n", pos);
8114 SendMessageW(button, WM_APP, 0, 0);
8115 pos = GetMessagePos();
8116 ok(pos == MAKELONG(120, 140), "pos = %08x\n", pos);
8118 PostMessageA(button, WM_APP, 0, 0);
8119 GetMessageA(&msg, button, 0, 0);
8120 ok(msg.message == WM_APP, "msg.message = %x\n", msg.message);
8121 pos = GetMessagePos();
8122 ok(pos == MAKELONG(340, 320), "pos = %08x\n", pos);
8124 PostMessageA(button, WM_APP, 0, 0);
8125 SetCursorPos(350, 330);
8126 GetMessageA(&msg, button, 0, 0);
8127 ok(msg.message == WM_APP, "msg.message = %x\n", msg.message);
8128 pos = GetMessagePos();
8129 ok(pos == MAKELONG(340, 320), "pos = %08x\n", pos);
8131 PostMessageA(button, WM_APP, 0, 0);
8132 SetCursorPos(320, 340);
8133 PostMessageA(button, WM_APP+1, 0, 0);
8134 pos = GetMessagePos();
8135 ok(pos == MAKELONG(340, 320), "pos = %08x\n", pos);
8136 GetMessageA(&msg, button, 0, 0);
8137 ok(msg.message == WM_APP, "msg.message = %x\n", msg.message);
8138 pos = GetMessagePos();
8139 ok(pos == MAKELONG(350, 330), "pos = %08x\n", pos);
8140 GetMessageA(&msg, button, 0, 0);
8141 ok(msg.message == WM_APP+1, "msg.message = %x\n", msg.message);
8142 pos = GetMessagePos();
8143 ok(pos == MAKELONG(320, 340), "pos = %08x\n", pos);
8145 SetTimer(button, 1, 250, NULL);
8146 SetCursorPos(330, 350);
8147 GetMessageA(&msg, button, 0, 0);
8148 while (msg.message == WM_PAINT)
8150 UpdateWindow( button );
8151 GetMessageA(&msg, button, 0, 0);
8153 ok(msg.message == WM_TIMER, "msg.message = %x\n", msg.message);
8154 pos = GetMessagePos();
8155 ok(pos == MAKELONG(330, 350), "pos = %08x\n", pos);
8156 KillTimer(button, 1);
8158 DestroyWindow(button);
8161 START_TEST(win)
8163 char **argv;
8164 int argc = winetest_get_mainargs( &argv );
8165 HMODULE user32 = GetModuleHandleA( "user32.dll" );
8166 HMODULE gdi32 = GetModuleHandleA("gdi32.dll");
8167 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
8168 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
8169 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
8170 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
8171 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
8172 pUpdateLayeredWindow = (void *)GetProcAddress( user32, "UpdateLayeredWindow" );
8173 pUpdateLayeredWindowIndirect = (void *)GetProcAddress( user32, "UpdateLayeredWindowIndirect" );
8174 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
8175 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
8176 pGetWindowRgnBox = (void *)GetProcAddress( user32, "GetWindowRgnBox" );
8177 pGetGUIThreadInfo = (void *)GetProcAddress( user32, "GetGUIThreadInfo" );
8178 pGetProcessDefaultLayout = (void *)GetProcAddress( user32, "GetProcessDefaultLayout" );
8179 pSetProcessDefaultLayout = (void *)GetProcAddress( user32, "SetProcessDefaultLayout" );
8180 pFlashWindowEx = (void *)GetProcAddress( user32, "FlashWindowEx" );
8181 pGetLayout = (void *)GetProcAddress( gdi32, "GetLayout" );
8182 pSetLayout = (void *)GetProcAddress( gdi32, "SetLayout" );
8183 pMirrorRgn = (void *)GetProcAddress( gdi32, "MirrorRgn" );
8185 if (argc==4 && !strcmp(argv[2], "create_children"))
8187 HWND hwnd;
8189 sscanf(argv[3], "%p", &hwnd);
8190 window_from_point_proc(hwnd);
8191 return;
8194 if (!RegisterWindowClasses()) assert(0);
8196 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
8197 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
8198 WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE,
8199 100, 100, 200, 200,
8200 0, 0, GetModuleHandleA(NULL), NULL);
8201 assert( hwndMain );
8203 if(!SetForegroundWindow(hwndMain)) {
8204 /* workaround for foreground lock timeout */
8205 simulate_click(101, 101);
8206 ok(SetForegroundWindow(hwndMain), "SetForegroundWindow failed\n");
8209 SetLastError(0xdeafbeef);
8210 GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC);
8211 is_win9x = (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED);
8213 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
8214 if (!hhook) win_skip( "Cannot set CBT hook, skipping some tests\n" );
8216 /* make sure that these tests are executed first */
8217 test_FindWindowEx();
8218 test_SetParent();
8220 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
8221 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
8222 WS_MAXIMIZEBOX | WS_POPUP,
8223 100, 100, 200, 200,
8224 0, 0, GetModuleHandleA(NULL), NULL);
8225 assert( hwndMain2 );
8227 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
8229 /* Add the tests below this line */
8230 test_child_window_from_point();
8231 test_window_from_point(argv[0]);
8232 test_thick_child_size(hwndMain);
8233 test_fullscreen();
8234 test_hwnd_message();
8235 test_nonclient_area(hwndMain);
8236 test_params();
8237 test_GetWindowModuleFileName();
8238 test_capture_1();
8239 test_capture_2();
8240 test_capture_3(hwndMain, hwndMain2);
8241 test_capture_4();
8242 test_rtl_layout();
8243 test_FlashWindowEx();
8245 test_CreateWindow();
8246 test_parent_owner();
8247 test_enum_thread_windows();
8249 test_mdi();
8250 test_icons();
8251 test_SetWindowPos(hwndMain, hwndMain2);
8252 test_SetMenu(hwndMain);
8253 test_SetFocus(hwndMain);
8254 test_SetActiveWindow(hwndMain);
8255 test_NCRedraw();
8257 test_children_zorder(hwndMain);
8258 test_popup_zorder(hwndMain2, hwndMain, WS_POPUP);
8259 test_popup_zorder(hwndMain2, hwndMain, 0);
8260 test_GetLastActivePopup();
8261 test_keyboard_input(hwndMain);
8262 test_mouse_input(hwndMain);
8263 test_validatergn(hwndMain);
8264 test_nccalcscroll( hwndMain);
8265 test_scrollwindow( hwndMain);
8266 test_scrollvalidate( hwndMain);
8267 test_scrolldc( hwndMain);
8268 test_scroll();
8269 test_IsWindowUnicode();
8270 test_vis_rgn(hwndMain);
8272 test_AdjustWindowRect();
8273 test_window_styles();
8274 test_dialog_styles();
8275 test_redrawnow();
8276 test_csparentdc();
8277 test_SetWindowLong();
8278 test_ShowWindow();
8279 test_gettext();
8280 test_GetUpdateRect();
8281 test_Expose();
8282 test_layered_window();
8284 test_SetForegroundWindow(hwndMain);
8285 test_shell_window();
8286 test_handles( hwndMain );
8287 test_winregion();
8288 test_map_points();
8289 test_update_region();
8290 test_window_without_child_style();
8291 test_smresult();
8292 test_GetMessagePos();
8294 /* add the tests above this line */
8295 if (hhook) UnhookWindowsHookEx(hhook);
8297 DestroyWindow(hwndMain2);
8298 DestroyWindow(hwndMain);