user32/tests: Flush events after test_ShowWindow().
[wine.git] / dlls / user32 / tests / win.c
blob9cf4ed37357bd970bb66607683cacd2214617c9d
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"
35 #include "winreg.h"
37 #include "wine/test.h"
39 #ifndef SPI_GETDESKWALLPAPER
40 #define SPI_GETDESKWALLPAPER 0x0073
41 #endif
43 #ifndef WM_SYSTIMER
44 #define WM_SYSTIMER 0x0118
45 #endif
47 #define LONG_PTR INT_PTR
48 #define ULONG_PTR UINT_PTR
50 void dump_region(HRGN hrgn);
52 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
53 static BOOL (WINAPI *pGetWindowInfo)(HWND,WINDOWINFO*);
54 static UINT (WINAPI *pGetWindowModuleFileNameA)(HWND,LPSTR,UINT);
55 static BOOL (WINAPI *pGetLayeredWindowAttributes)(HWND,COLORREF*,BYTE*,DWORD*);
56 static BOOL (WINAPI *pSetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD);
57 static BOOL (WINAPI *pUpdateLayeredWindow)(HWND,HDC,POINT*,SIZE*,HDC,POINT*,COLORREF,BLENDFUNCTION*,DWORD);
58 static BOOL (WINAPI *pUpdateLayeredWindowIndirect)(HWND,const UPDATELAYEREDWINDOWINFO*);
59 static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
60 static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
61 static int (WINAPI *pGetWindowRgnBox)(HWND,LPRECT);
62 static BOOL (WINAPI *pGetGUIThreadInfo)(DWORD, GUITHREADINFO*);
63 static BOOL (WINAPI *pGetProcessDefaultLayout)( DWORD *layout );
64 static BOOL (WINAPI *pSetProcessDefaultLayout)( DWORD layout );
65 static BOOL (WINAPI *pFlashWindow)( HWND hwnd, BOOL bInvert );
66 static BOOL (WINAPI *pFlashWindowEx)( PFLASHWINFO pfwi );
67 static DWORD (WINAPI *pSetLayout)(HDC hdc, DWORD layout);
68 static DWORD (WINAPI *pGetLayout)(HDC hdc);
69 static BOOL (WINAPI *pMirrorRgn)(HWND hwnd, HRGN hrgn);
71 static BOOL test_lbuttondown_flag;
72 static DWORD num_gettext_msgs;
73 static DWORD num_settext_msgs;
74 static HWND hwndMessage;
75 static HWND hwndMain, hwndMain2;
76 static HHOOK hhook;
77 static BOOL app_activated, app_deactivated;
79 static const char* szAWRClass = "Winsize";
80 static HMENU hmenu;
81 static DWORD our_pid;
83 static BOOL is_win9x = FALSE;
85 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
87 static void dump_minmax_info( const MINMAXINFO *minmax )
89 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
90 minmax->ptReserved.x, minmax->ptReserved.y,
91 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
92 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
93 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
94 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
97 /* try to make sure pending X events have been processed before continuing */
98 static void flush_events( BOOL remove_messages )
100 MSG msg;
101 int diff = 200;
102 int min_timeout = 100;
103 DWORD time = GetTickCount() + diff;
105 while (diff > 0)
107 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
108 if (remove_messages)
109 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
110 diff = time - GetTickCount();
111 min_timeout = 50;
115 static BOOL wait_for_event(HANDLE event, int timeout)
117 DWORD end_time = GetTickCount() + timeout;
118 MSG msg;
120 do {
121 if(MsgWaitForMultipleObjects(1, &event, FALSE, timeout, QS_ALLINPUT) == WAIT_OBJECT_0)
122 return TRUE;
123 while(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
124 DispatchMessageA(&msg);
125 timeout = end_time - GetTickCount();
126 }while(timeout > 0);
128 return FALSE;
131 /* check the values returned by the various parent/owner functions on a given window */
132 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
133 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
135 HWND res;
137 if (pGetAncestor)
139 res = pGetAncestor( hwnd, GA_PARENT );
140 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
142 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
143 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
144 res = GetParent( hwnd );
145 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
146 res = GetWindow( hwnd, GW_OWNER );
147 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
148 if (pGetAncestor)
150 res = pGetAncestor( hwnd, GA_ROOT );
151 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
152 res = pGetAncestor( hwnd, GA_ROOTOWNER );
153 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
157 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
158 static void check_wnd_state_(const char *file, int line,
159 HWND active, HWND foreground, HWND focus, HWND capture)
161 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
162 /* only check foreground if it belongs to the current thread */
163 /* foreground can be moved to a different app pretty much at any time */
164 if (foreground && GetForegroundWindow() &&
165 GetWindowThreadProcessId(GetForegroundWindow(), NULL) == GetCurrentThreadId())
166 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
167 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
168 ok_(file, line)(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
171 /* same as above but without capture test */
172 #define check_active_state(a,b,c) check_active_state_(__FILE__,__LINE__,a,b,c)
173 static void check_active_state_(const char *file, int line,
174 HWND active, HWND foreground, HWND focus)
176 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
177 /* only check foreground if it belongs to the current thread */
178 /* foreground can be moved to a different app pretty much at any time */
179 if (foreground && GetForegroundWindow() &&
180 GetWindowThreadProcessId(GetForegroundWindow(), NULL) == GetCurrentThreadId())
181 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
182 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
185 static BOOL ignore_message( UINT message )
187 /* these are always ignored */
188 return (message >= 0xc000 ||
189 message == WM_GETICON ||
190 message == WM_GETOBJECT ||
191 message == WM_TIMER ||
192 message == WM_SYSTIMER ||
193 message == WM_TIMECHANGE ||
194 message == WM_DEVICECHANGE);
197 static BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
199 (*(LPINT)lParam)++;
200 trace("EnumChildProc on %p\n", hwndChild);
201 if (*(LPINT)lParam > 1) return FALSE;
202 return TRUE;
205 /* will search for the given window */
206 static BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
208 trace("EnumChildProc1 on %p\n", hwndChild);
209 if ((HWND)lParam == hwndChild) return FALSE;
210 return TRUE;
213 static HWND create_tool_window( LONG style, HWND parent )
215 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
216 0, 0, 100, 100, parent, 0, 0, NULL );
217 ok( ret != 0, "Creation failed\n" );
218 return ret;
221 /* test parent and owner values for various combinations */
222 static void test_parent_owner(void)
224 LONG style;
225 HWND test, owner, ret;
226 HWND desktop = GetDesktopWindow();
227 HWND child = create_tool_window( WS_CHILD, hwndMain );
228 INT numChildren;
230 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
232 /* child without parent, should fail */
233 SetLastError(0xdeadbeef);
234 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
235 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
236 ok( !test, "WS_CHILD without parent created\n" );
237 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD ||
238 broken(GetLastError() == 0xdeadbeef), /* win9x */
239 "CreateWindowExA error %u\n", GetLastError() );
241 /* desktop window */
242 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
243 style = GetWindowLongA( desktop, GWL_STYLE );
244 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
245 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
246 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
248 /* normal child window */
249 test = create_tool_window( WS_CHILD, hwndMain );
250 trace( "created child %p\n", test );
251 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
252 SetWindowLongA( test, GWL_STYLE, 0 );
253 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
254 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
255 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
256 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
257 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
258 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
259 DestroyWindow( test );
261 /* normal child window with WS_MAXIMIZE */
262 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
263 DestroyWindow( test );
265 /* normal child window with WS_THICKFRAME */
266 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
267 DestroyWindow( test );
269 /* popup window with WS_THICKFRAME */
270 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
271 DestroyWindow( test );
273 /* child of desktop */
274 test = create_tool_window( WS_CHILD, desktop );
275 trace( "created child of desktop %p\n", test );
276 check_parents( test, desktop, 0, desktop, 0, test, desktop );
277 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
278 check_parents( test, desktop, 0, 0, 0, test, test );
279 SetWindowLongA( test, GWL_STYLE, 0 );
280 check_parents( test, desktop, 0, 0, 0, test, test );
281 DestroyWindow( test );
283 /* child of desktop with WS_MAXIMIZE */
284 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
285 DestroyWindow( test );
287 /* child of desktop with WS_MINIMIZE */
288 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
289 DestroyWindow( test );
291 /* child of child */
292 test = create_tool_window( WS_CHILD, child );
293 trace( "created child of child %p\n", test );
294 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
295 SetWindowLongA( test, GWL_STYLE, 0 );
296 check_parents( test, child, child, 0, 0, hwndMain, test );
297 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
298 check_parents( test, child, child, 0, 0, hwndMain, test );
299 DestroyWindow( test );
301 /* child of child with WS_MAXIMIZE */
302 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
303 DestroyWindow( test );
305 /* child of child with WS_MINIMIZE */
306 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
307 DestroyWindow( test );
309 /* not owned top-level window */
310 test = create_tool_window( 0, 0 );
311 trace( "created top-level %p\n", test );
312 check_parents( test, desktop, 0, 0, 0, test, test );
313 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
314 check_parents( test, desktop, 0, 0, 0, test, test );
315 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
316 check_parents( test, desktop, 0, desktop, 0, test, desktop );
317 DestroyWindow( test );
319 /* not owned top-level window with WS_MAXIMIZE */
320 test = create_tool_window( WS_MAXIMIZE, 0 );
321 DestroyWindow( test );
323 /* owned top-level window */
324 test = create_tool_window( 0, hwndMain );
325 trace( "created owned top-level %p\n", test );
326 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
327 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
328 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
329 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
330 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
331 DestroyWindow( test );
333 /* owned top-level window with WS_MAXIMIZE */
334 test = create_tool_window( WS_MAXIMIZE, hwndMain );
335 DestroyWindow( test );
337 /* not owned popup */
338 test = create_tool_window( WS_POPUP, 0 );
339 trace( "created popup %p\n", test );
340 check_parents( test, desktop, 0, 0, 0, test, test );
341 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
342 check_parents( test, desktop, 0, desktop, 0, test, desktop );
343 SetWindowLongA( test, GWL_STYLE, 0 );
344 check_parents( test, desktop, 0, 0, 0, test, test );
345 DestroyWindow( test );
347 /* not owned popup with WS_MAXIMIZE */
348 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
349 DestroyWindow( test );
351 /* owned popup */
352 test = create_tool_window( WS_POPUP, hwndMain );
353 trace( "created owned popup %p\n", test );
354 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
355 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
356 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
357 SetWindowLongA( test, GWL_STYLE, 0 );
358 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
359 DestroyWindow( test );
361 /* owned popup with WS_MAXIMIZE */
362 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
363 DestroyWindow( test );
365 /* top-level window owned by child (same as owned by top-level) */
366 test = create_tool_window( 0, child );
367 trace( "created top-level owned by child %p\n", test );
368 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
369 DestroyWindow( test );
371 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
372 test = create_tool_window( WS_MAXIMIZE, child );
373 DestroyWindow( test );
375 /* popup owned by desktop (same as not owned) */
376 test = create_tool_window( WS_POPUP, desktop );
377 trace( "created popup owned by desktop %p\n", test );
378 check_parents( test, desktop, 0, 0, 0, test, test );
379 DestroyWindow( test );
381 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
382 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
383 DestroyWindow( test );
385 /* popup owned by child (same as owned by top-level) */
386 test = create_tool_window( WS_POPUP, child );
387 trace( "created popup owned by child %p\n", test );
388 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
389 DestroyWindow( test );
391 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
392 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
393 DestroyWindow( test );
395 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
396 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
397 trace( "created WS_CHILD popup %p\n", test );
398 check_parents( test, desktop, 0, 0, 0, test, test );
399 DestroyWindow( test );
401 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
402 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
403 DestroyWindow( test );
405 /* owned popup with WS_CHILD (same as WS_POPUP only) */
406 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
407 trace( "created owned WS_CHILD popup %p\n", test );
408 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
409 DestroyWindow( test );
411 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
412 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
413 DestroyWindow( test );
415 /******************** parent changes *************************/
416 trace( "testing parent changes\n" );
418 /* desktop window */
419 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
420 if (0)
422 /* this test succeeds on NT but crashes on win9x systems */
423 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
424 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
425 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
426 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
427 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
429 /* normal child window */
430 test = create_tool_window( WS_CHILD, hwndMain );
431 trace( "created child %p\n", test );
433 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
434 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
435 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
437 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
438 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
439 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
441 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
442 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
443 check_parents( test, desktop, 0, desktop, 0, test, desktop );
445 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
446 if (!is_win9x)
448 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)test );
449 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
450 check_parents( test, desktop, 0, desktop, 0, test, desktop );
452 else
453 win_skip("Test creates circular window tree under Win9x/WinMe\n" );
455 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
456 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
457 check_parents( test, desktop, child, desktop, child, test, desktop );
459 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
460 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
461 check_parents( test, desktop, 0, desktop, 0, test, desktop );
462 DestroyWindow( test );
464 /* not owned top-level window */
465 test = create_tool_window( 0, 0 );
466 trace( "created top-level %p\n", test );
468 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
469 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
470 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
472 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
473 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
474 check_parents( test, desktop, child, 0, child, test, test );
476 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
477 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
478 check_parents( test, desktop, 0, 0, 0, test, test );
479 DestroyWindow( test );
481 /* not owned popup */
482 test = create_tool_window( WS_POPUP, 0 );
483 trace( "created popup %p\n", test );
485 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
486 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
487 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
489 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
490 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
491 check_parents( test, desktop, child, child, child, test, hwndMain );
493 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
494 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
495 check_parents( test, desktop, 0, 0, 0, test, test );
496 DestroyWindow( test );
498 /* normal child window */
499 test = create_tool_window( WS_CHILD, hwndMain );
500 trace( "created child %p\n", test );
502 ret = SetParent( test, desktop );
503 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
504 check_parents( test, desktop, 0, desktop, 0, test, desktop );
506 ret = SetParent( test, child );
507 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
508 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
510 ret = SetParent( test, hwndMain2 );
511 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
512 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
513 DestroyWindow( test );
515 /* not owned top-level window */
516 test = create_tool_window( 0, 0 );
517 trace( "created top-level %p\n", test );
519 ret = SetParent( test, child );
520 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
521 check_parents( test, child, child, 0, 0, hwndMain, test );
523 if (!is_win9x)
525 ShowWindow( test, SW_SHOW );
526 ret = SetParent( test, test );
527 ok( ret == NULL, "SetParent return value %p expected %p\n", ret, NULL );
528 ok( GetWindowLongA( test, GWL_STYLE ) & WS_VISIBLE, "window is not visible after SetParent\n" );
529 check_parents( test, child, child, 0, 0, hwndMain, test );
531 else
532 win_skip( "Test crashes on Win9x/WinMe\n" );
533 DestroyWindow( test );
535 /* owned popup */
536 test = create_tool_window( WS_POPUP, hwndMain2 );
537 trace( "created owned popup %p\n", test );
539 ret = SetParent( test, child );
540 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
541 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
543 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
544 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
545 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
546 DestroyWindow( test );
548 /**************** test owner destruction *******************/
550 /* owned child popup */
551 owner = create_tool_window( 0, 0 );
552 test = create_tool_window( WS_POPUP, owner );
553 trace( "created owner %p and popup %p\n", owner, test );
554 ret = SetParent( test, child );
555 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
556 check_parents( test, child, child, owner, owner, hwndMain, owner );
557 /* window is now child of 'child' but owned by 'owner' */
558 DestroyWindow( owner );
559 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
560 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
561 * while Win95, Win2k, WinXP do.
563 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
564 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
565 DestroyWindow(test);
567 /* owned top-level popup */
568 owner = create_tool_window( 0, 0 );
569 test = create_tool_window( WS_POPUP, owner );
570 trace( "created owner %p and popup %p\n", owner, test );
571 check_parents( test, desktop, owner, owner, owner, test, owner );
572 DestroyWindow( owner );
573 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
575 /* top-level popup owned by child */
576 owner = create_tool_window( WS_CHILD, hwndMain2 );
577 test = create_tool_window( WS_POPUP, 0 );
578 trace( "created owner %p and popup %p\n", owner, test );
579 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
580 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
581 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
582 DestroyWindow( owner );
583 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
584 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
585 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
586 * while Win95, Win2k, WinXP do.
588 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
589 DestroyWindow(test);
591 /* final cleanup */
592 DestroyWindow(child);
595 owner = create_tool_window( WS_OVERLAPPED, 0 );
596 test = create_tool_window( WS_POPUP, desktop );
598 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
599 numChildren = 0;
600 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
601 "EnumChildWindows should have returned FALSE\n" );
602 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
604 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
605 ret = SetParent( test, owner );
606 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
608 numChildren = 0;
609 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
610 "EnumChildWindows should have returned TRUE\n" );
611 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
613 child = create_tool_window( WS_CHILD, owner );
614 numChildren = 0;
615 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
616 "EnumChildWindows should have returned FALSE\n" );
617 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
618 DestroyWindow( child );
620 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
621 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
622 numChildren = 0;
623 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
624 "EnumChildWindows should have returned TRUE\n" );
625 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
627 ret = SetParent( child, owner );
628 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
629 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
630 numChildren = 0;
631 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
632 "EnumChildWindows should have returned FALSE\n" );
633 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
635 ret = SetParent( child, NULL );
636 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
637 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
638 numChildren = 0;
639 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
640 "EnumChildWindows should have returned TRUE\n" );
641 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
643 /* even GW_OWNER == owner it's still a desktop's child */
644 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
645 "EnumChildWindows should have found %p and returned FALSE\n", child );
647 DestroyWindow( child );
648 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
650 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
651 "EnumChildWindows should have found %p and returned FALSE\n", child );
653 DestroyWindow( child );
654 DestroyWindow( test );
655 DestroyWindow( owner );
657 /* Test that owner window takes into account WS_CHILD flag even if parent is set by SetParent. */
658 owner = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, desktop );
659 SetParent(owner, hwndMain);
660 check_parents( owner, hwndMain, hwndMain, NULL, NULL, hwndMain, owner );
661 test = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
662 check_parents( test, desktop, owner, NULL, owner, test, test );
663 DestroyWindow( owner );
664 DestroyWindow( test );
666 owner = create_tool_window( WS_VISIBLE | WS_CHILD, desktop );
667 SetParent(owner, hwndMain);
668 check_parents( owner, hwndMain, hwndMain, hwndMain, NULL, hwndMain, hwndMain );
669 test = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
670 check_parents( test, desktop, hwndMain, NULL, hwndMain, test, test );
671 DestroyWindow( owner );
672 DestroyWindow( test );
674 owner = create_tool_window( WS_VISIBLE | WS_POPUP | WS_CHILD, desktop );
675 SetParent(owner, hwndMain);
676 check_parents( owner, hwndMain, hwndMain, NULL, NULL, hwndMain, owner );
677 test = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
678 check_parents( test, desktop, owner, NULL, owner, test, test );
679 DestroyWindow( owner );
680 DestroyWindow( test );
683 static BOOL CALLBACK enum_proc( HWND hwnd, LPARAM lParam)
685 (*(LPINT)lParam)++;
686 if (*(LPINT)lParam > 2) return FALSE;
687 return TRUE;
689 static DWORD CALLBACK enum_thread( void *arg )
691 INT count;
692 HWND hwnd[3];
693 BOOL ret;
694 MSG msg;
696 if (pGetGUIThreadInfo)
698 GUITHREADINFO info;
699 info.cbSize = sizeof(info);
700 ret = pGetGUIThreadInfo( GetCurrentThreadId(), &info );
701 ok( ret || broken(!ret), /* win9x */
702 "GetGUIThreadInfo failed without message queue\n" );
703 SetLastError( 0xdeadbeef );
704 info.cbSize = sizeof(info) + 1;
705 ret = pGetGUIThreadInfo( GetCurrentThreadId(), &info );
706 ok( !ret, "GetGUIThreadInfo succeeded with wrong size\n" );
707 ok( GetLastError() == ERROR_INVALID_PARAMETER ||
708 broken(GetLastError() == 0xdeadbeef), /* win9x */
709 "wrong error %u\n", GetLastError() );
712 PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ); /* make sure we have a message queue */
714 count = 0;
715 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
716 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
717 ok( count == 0, "count should be 0 got %d\n", count );
719 hwnd[0] = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", WS_POPUP,
720 0, 0, 100, 100, 0, 0, 0, NULL );
721 count = 0;
722 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
723 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
724 if (count != 2) /* Vista gives us two windows for the price of one */
726 ok( count == 1, "count should be 1 got %d\n", count );
727 hwnd[2] = CreateWindowExA(0, "ToolWindowClass", "Tool window 2", WS_POPUP,
728 0, 0, 100, 100, 0, 0, 0, NULL );
730 else hwnd[2] = 0;
732 hwnd[1] = CreateWindowExA(0, "ToolWindowClass", "Tool window 3", WS_POPUP,
733 0, 0, 100, 100, 0, 0, 0, NULL );
734 count = 0;
735 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
736 ok( !ret, "EnumThreadWindows should have returned FALSE\n" );
737 ok( count == 3, "count should be 3 got %d\n", count );
739 if (hwnd[2]) DestroyWindow(hwnd[2]);
740 DestroyWindow(hwnd[1]);
741 DestroyWindow(hwnd[0]);
742 return 0;
745 /* test EnumThreadWindows in a separate thread */
746 static void test_enum_thread_windows(void)
748 DWORD id;
749 HANDLE handle = CreateThread( NULL, 0, enum_thread, 0, 0, &id );
750 ok( !WaitForSingleObject( handle, 10000 ), "wait failed\n" );
751 CloseHandle( handle );
754 static struct wm_gettext_override_data
756 BOOL enabled; /* when 1 bypasses default procedure */
757 BOOL dont_terminate; /* don't null terminate returned string in WM_GETTEXT handler */
758 char *buff; /* expected text buffer pointer */
759 WCHAR *buffW; /* same, for W test */
760 } g_wm_gettext_override;
762 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
764 switch (msg)
766 case WM_GETMINMAXINFO:
768 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
769 break;
771 case WM_WINDOWPOSCHANGING:
773 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
774 if (!(winpos->flags & SWP_NOMOVE))
776 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
777 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
779 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
780 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
782 ok((winpos->cx >= 0 && winpos->cx <= 32767) ||
783 winpos->cx == 32768, /* win7 doesn't truncate */
784 "bad winpos->cx %d\n", winpos->cx);
785 ok((winpos->cy >= 0 && winpos->cy <= 32767) ||
786 winpos->cy == 40000, /* win7 doesn't truncate */
787 "bad winpos->cy %d\n", winpos->cy);
789 break;
791 case WM_WINDOWPOSCHANGED:
793 RECT rc1, rc2;
794 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
795 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
796 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
798 ok((winpos->cx >= 0 && winpos->cx <= 32767) ||
799 winpos->cx == 32768, /* win7 doesn't truncate */
800 "bad winpos->cx %d\n", winpos->cx);
801 ok((winpos->cy >= 0 && winpos->cy <= 32767) ||
802 winpos->cy == 40000, /* win7 doesn't truncate */
803 "bad winpos->cy %d\n", winpos->cy);
805 GetWindowRect(hwnd, &rc1);
806 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
807 /* note: winpos coordinates are relative to parent */
808 MapWindowPoints(GetAncestor(hwnd,GA_PARENT), 0, (LPPOINT)&rc2, 2);
809 ok(EqualRect(&rc1, &rc2), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1),
810 wine_dbgstr_rect(&rc2));
812 GetClientRect(hwnd, &rc2);
813 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
814 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
815 ok(EqualRect(&rc1, &rc2), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1),
816 wine_dbgstr_rect(&rc2));
817 break;
819 case WM_NCCREATE:
821 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
822 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
824 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
825 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
826 else
827 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
828 break;
830 case WM_COMMAND:
831 if (test_lbuttondown_flag)
833 ShowWindow((HWND)wparam, SW_SHOW);
834 flush_events( FALSE );
836 break;
837 case WM_GETTEXT:
838 num_gettext_msgs++;
839 if (g_wm_gettext_override.enabled)
841 char *text = (char*)lparam;
842 ok(g_wm_gettext_override.buff == text, "expected buffer %p, got %p\n", g_wm_gettext_override.buff, text);
843 ok(*text == 0, "expected empty string buffer %x\n", *text);
844 return 0;
846 else if (g_wm_gettext_override.dont_terminate)
848 char *text = (char *)lparam;
849 if (text)
851 memcpy(text, "text", 4);
852 return 4;
854 return 0;
856 break;
857 case WM_SETTEXT:
858 num_settext_msgs++;
859 break;
860 case WM_ACTIVATEAPP:
861 if (wparam) app_activated = TRUE;
862 else app_deactivated = TRUE;
863 break;
866 return DefWindowProcA(hwnd, msg, wparam, lparam);
869 static LRESULT WINAPI main_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
871 switch (msg)
873 case WM_GETTEXT:
874 num_gettext_msgs++;
875 if (g_wm_gettext_override.enabled)
877 WCHAR *text = (WCHAR*)lparam;
878 ok(g_wm_gettext_override.buffW == text, "expected buffer %p, got %p\n", g_wm_gettext_override.buffW, text);
879 ok(*text == 0, "expected empty string buffer %x\n", *text);
880 return 0;
882 else if (g_wm_gettext_override.dont_terminate)
884 static const WCHAR textW[] = {'t','e','x','t'};
885 WCHAR *text = (WCHAR *)lparam;
886 if (text)
888 memcpy(text, textW, sizeof(textW));
889 return 4;
891 return 0;
893 break;
896 return DefWindowProcA(hwnd, msg, wparam, lparam);
899 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
901 switch (msg)
903 case WM_GETMINMAXINFO:
905 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
906 break;
908 case WM_NCCREATE:
910 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
911 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
913 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
914 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
915 else
916 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
917 break;
921 return DefWindowProcA(hwnd, msg, wparam, lparam);
924 static const WCHAR mainclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s','W',0};
926 static BOOL RegisterWindowClasses(void)
928 WNDCLASSW clsW;
929 WNDCLASSA cls;
931 cls.style = CS_DBLCLKS;
932 cls.lpfnWndProc = main_window_procA;
933 cls.cbClsExtra = 0;
934 cls.cbWndExtra = 0;
935 cls.hInstance = GetModuleHandleA(0);
936 cls.hIcon = 0;
937 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
938 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
939 cls.lpszMenuName = NULL;
940 cls.lpszClassName = "MainWindowClass";
942 if(!RegisterClassA(&cls)) return FALSE;
944 clsW.style = CS_DBLCLKS;
945 clsW.lpfnWndProc = main_window_procW;
946 clsW.cbClsExtra = 0;
947 clsW.cbWndExtra = 0;
948 clsW.hInstance = GetModuleHandleA(0);
949 clsW.hIcon = 0;
950 clsW.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
951 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
952 clsW.lpszMenuName = NULL;
953 clsW.lpszClassName = mainclassW;
955 if(!RegisterClassW(&clsW)) return FALSE;
957 cls.style = 0;
958 cls.lpfnWndProc = tool_window_procA;
959 cls.cbClsExtra = 0;
960 cls.cbWndExtra = 0;
961 cls.hInstance = GetModuleHandleA(0);
962 cls.hIcon = 0;
963 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
964 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
965 cls.lpszMenuName = NULL;
966 cls.lpszClassName = "ToolWindowClass";
968 if(!RegisterClassA(&cls)) return FALSE;
970 return TRUE;
973 static void verify_window_info(const char *hook, HWND hwnd, const WINDOWINFO *info)
975 RECT rcWindow, rcClient;
976 DWORD status;
978 ok(IsWindow(hwnd), "bad window handle %p in hook %s\n", hwnd, hook);
980 GetWindowRect(hwnd, &rcWindow);
981 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow for %p in hook %s\n", hwnd, hook);
983 GetClientRect(hwnd, &rcClient);
984 /* translate to screen coordinates */
985 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
986 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient for %p in hook %s\n", hwnd, hook);
988 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
989 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
990 info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE), hwnd, hook);
991 /* Windows reports some undocumented exstyles in WINDOWINFO, but
992 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
994 ok((info->dwExStyle & ~0xe0000800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
995 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
996 info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE), hwnd, hook);
997 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
998 if (GetForegroundWindow())
999 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
1000 info->dwWindowStatus, status, GetActiveWindow(), GetForegroundWindow(), hook);
1002 /* win2k and XP return broken border info in GetWindowInfo most of
1003 * the time, so there is no point in testing it.
1005 if (0)
1007 UINT border;
1008 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
1009 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
1010 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
1011 ok(info->cyWindowBorders == border,
1012 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
1014 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType for %p in hook %s\n",
1015 hwnd, hook);
1016 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
1017 info->wCreatorVersion == 0x0500 /* Vista */,
1018 "wrong wCreatorVersion %04x for %p in hook %s\n", info->wCreatorVersion, hwnd, hook);
1021 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
1023 AdjustWindowRectEx(rc, style, menu, exstyle);
1024 /* AdjustWindowRectEx does not include scroll bars */
1025 if (style & WS_VSCROLL)
1027 if(exstyle & WS_EX_LEFTSCROLLBAR)
1028 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
1029 else
1030 rc->right += GetSystemMetrics(SM_CXVSCROLL);
1032 if (style & WS_HSCROLL)
1033 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
1036 /* reimplement it to check that the Wine algorithm gives the correct result */
1037 static void wine_AdjustWindowRectEx( RECT *rect, LONG style, BOOL menu, LONG exStyle )
1039 int adjust;
1041 if ((exStyle & (WS_EX_STATICEDGE|WS_EX_DLGMODALFRAME)) ==
1042 WS_EX_STATICEDGE)
1044 adjust = 1; /* for the outer frame always present */
1046 else
1048 adjust = 0;
1049 if ((exStyle & WS_EX_DLGMODALFRAME) ||
1050 (style & (WS_THICKFRAME|WS_DLGFRAME))) adjust = 2; /* outer */
1052 if (style & WS_THICKFRAME)
1053 adjust += GetSystemMetrics(SM_CXFRAME) - GetSystemMetrics(SM_CXDLGFRAME); /* The resize border */
1054 if ((style & (WS_BORDER|WS_DLGFRAME)) ||
1055 (exStyle & WS_EX_DLGMODALFRAME))
1056 adjust++; /* The other border */
1058 InflateRect (rect, adjust, adjust);
1060 if ((style & WS_CAPTION) == WS_CAPTION)
1062 if (exStyle & WS_EX_TOOLWINDOW)
1063 rect->top -= GetSystemMetrics(SM_CYSMCAPTION);
1064 else
1065 rect->top -= GetSystemMetrics(SM_CYCAPTION);
1067 if (menu) rect->top -= GetSystemMetrics(SM_CYMENU);
1069 if (exStyle & WS_EX_CLIENTEDGE)
1070 InflateRect(rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
1072 if (style & WS_VSCROLL)
1074 if((exStyle & WS_EX_LEFTSCROLLBAR) != 0)
1075 rect->left -= GetSystemMetrics(SM_CXVSCROLL);
1076 else
1077 rect->right += GetSystemMetrics(SM_CXVSCROLL);
1079 if (style & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL);
1082 static void test_nonclient_area(HWND hwnd)
1084 DWORD style, exstyle;
1085 RECT rc_window, rc_client, rc;
1086 BOOL menu;
1087 LRESULT ret;
1089 style = GetWindowLongA(hwnd, GWL_STYLE);
1090 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1091 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
1093 GetWindowRect(hwnd, &rc_window);
1094 GetClientRect(hwnd, &rc_client);
1096 /* avoid some cases when things go wrong */
1097 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
1098 rc_window.right > 32768 || rc_window.bottom > 32768) return;
1100 rc = rc_client;
1101 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
1102 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
1104 ok(EqualRect(&rc, &rc_window),
1105 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=%s, calc=%s\n",
1106 style, exstyle, menu, wine_dbgstr_rect(&rc_window), wine_dbgstr_rect(&rc));
1108 rc = rc_client;
1109 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
1110 wine_AdjustWindowRectEx(&rc, style, menu, exstyle);
1111 ok(EqualRect(&rc, &rc_window),
1112 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=%s, calc=%s\n",
1113 style, exstyle, menu, wine_dbgstr_rect(&rc_window), wine_dbgstr_rect(&rc));
1116 rc = rc_window;
1117 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
1118 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
1119 ok(EqualRect(&rc, &rc_client),
1120 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=%s, calc=%s\n",
1121 style, exstyle, menu, wine_dbgstr_rect(&rc_client), wine_dbgstr_rect(&rc));
1123 /* NULL rectangle shouldn't crash */
1124 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
1125 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
1127 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
1128 if (is_win9x)
1129 return;
1131 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
1132 SetRect(&rc_client, 0, 0, 250, 150);
1133 rc_window = rc_client;
1134 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
1135 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
1137 rc = rc_window;
1138 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
1139 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
1140 ok(EqualRect(&rc, &rc_client),
1141 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=%s, calc=%s\n",
1142 style, exstyle, menu, wine_dbgstr_rect(&rc_client), wine_dbgstr_rect(&rc));
1145 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
1147 static const char *CBT_code_name[10] = {
1148 "HCBT_MOVESIZE",
1149 "HCBT_MINMAX",
1150 "HCBT_QS",
1151 "HCBT_CREATEWND",
1152 "HCBT_DESTROYWND",
1153 "HCBT_ACTIVATE",
1154 "HCBT_CLICKSKIPPED",
1155 "HCBT_KEYSKIPPED",
1156 "HCBT_SYSCOMMAND",
1157 "HCBT_SETFOCUS" };
1158 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
1159 HWND hwnd = (HWND)wParam;
1161 switch (nCode)
1163 case HCBT_CREATEWND:
1165 static const RECT rc_null;
1166 RECT rc;
1167 LONG style;
1168 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
1169 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
1171 if (pGetWindowInfo)
1173 WINDOWINFO info;
1174 info.cbSize = sizeof(WINDOWINFO);
1175 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
1176 verify_window_info(code_name, hwnd, &info);
1179 /* WS_VISIBLE should be turned off yet */
1180 style = createwnd->lpcs->style & ~WS_VISIBLE;
1181 ok(style == GetWindowLongA(hwnd, GWL_STYLE),
1182 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
1183 GetWindowLongA(hwnd, GWL_STYLE), style);
1185 if (0)
1187 /* Uncomment this once the test succeeds in all cases */
1188 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
1190 ok(GetParent(hwnd) == hwndMessage,
1191 "wrong result from GetParent %p: message window %p\n",
1192 GetParent(hwnd), hwndMessage);
1194 else
1195 ok(!GetParent(hwnd), "GetParent should return 0 at this point\n");
1197 ok(!GetWindow(hwnd, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
1199 if (0)
1201 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
1202 * Win9x still has them set to 0.
1204 ok(GetWindow(hwnd, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
1205 ok(GetWindow(hwnd, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
1207 ok(!GetWindow(hwnd, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
1208 ok(!GetWindow(hwnd, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
1210 if (0)
1212 /* Uncomment this once the test succeeds in all cases */
1213 if (pGetAncestor)
1215 ok(pGetAncestor(hwnd, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
1216 ok(pGetAncestor(hwnd, GA_ROOT) == hwnd,
1217 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOT), hwnd);
1219 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
1220 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwndMessage,
1221 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
1222 else
1223 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwnd,
1224 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOTOWNER), hwnd);
1227 ok(GetWindowRect(hwnd, &rc), "GetWindowRect failed\n");
1228 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
1229 ok(GetClientRect(hwnd, &rc), "GetClientRect failed\n");
1230 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
1232 break;
1234 case HCBT_MOVESIZE:
1235 case HCBT_MINMAX:
1236 case HCBT_ACTIVATE:
1237 if (pGetWindowInfo && IsWindow(hwnd))
1239 WINDOWINFO info;
1241 /* Win98 actually does check the info.cbSize and doesn't allow
1242 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
1243 * WinXP do not check it at all.
1245 info.cbSize = sizeof(WINDOWINFO);
1246 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
1247 verify_window_info(code_name, hwnd, &info);
1249 break;
1250 /* window state is undefined */
1251 case HCBT_SETFOCUS:
1252 case HCBT_DESTROYWND:
1253 break;
1254 default:
1255 break;
1258 return CallNextHookEx(hhook, nCode, wParam, lParam);
1261 static const WCHAR winlogonW[] =
1262 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
1263 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1264 'W','i','n','l','o','g','o','n',0};
1265 static const WCHAR autorestartshellW[] =
1266 {'A','u','t','o','R','e','s','t','a','r','t','S','h','e','l','l',0};
1268 static DWORD get_autorestart(void)
1270 DWORD type, val, len = sizeof(val);
1271 REGSAM access = KEY_ALL_ACCESS|KEY_WOW64_64KEY;
1272 HKEY hkey;
1273 LONG res;
1275 if (RegCreateKeyExW( HKEY_LOCAL_MACHINE, winlogonW, 0, 0, 0, access, NULL, &hkey, 0 )) return 0;
1276 res = RegQueryValueExW( hkey, autorestartshellW, NULL, &type, (BYTE *)&val, &len );
1277 RegCloseKey( hkey );
1278 return (!res && type == REG_DWORD) ? val : 0;
1281 static BOOL set_autorestart( DWORD val )
1283 REGSAM access = KEY_ALL_ACCESS|KEY_WOW64_64KEY;
1284 HKEY hkey;
1285 LONG res;
1287 if (RegCreateKeyExW( HKEY_LOCAL_MACHINE, winlogonW, 0, 0, 0, access, NULL, &hkey, 0 )) return FALSE;
1288 res = RegSetValueExW( hkey, autorestartshellW, 0, REG_DWORD, (BYTE *)&val, sizeof(val) );
1289 RegCloseKey( hkey );
1290 return !res;
1293 static void test_shell_window(void)
1295 BOOL ret;
1296 DWORD error, restart = get_autorestart();
1297 HMODULE hinst, hUser32;
1298 BOOL (WINAPI*SetShellWindow)(HWND);
1299 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
1300 HWND shellWindow, nextWnd;
1302 if (is_win9x)
1304 win_skip("Skipping shell window test on Win9x\n");
1305 return;
1308 if (restart && !set_autorestart(0))
1310 skip("cannot disable automatic shell restart (needs admin rights\n");
1311 return;
1314 shellWindow = GetShellWindow();
1315 hinst = GetModuleHandleA(NULL);
1316 hUser32 = GetModuleHandleA("user32");
1318 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
1320 trace("previous shell window: %p\n", shellWindow);
1322 if (shellWindow) {
1323 DWORD pid;
1324 HANDLE hProcess;
1326 GetWindowThreadProcessId(shellWindow, &pid);
1327 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
1328 if (!hProcess)
1330 skip( "cannot get access to shell process\n" );
1331 set_autorestart(restart);
1332 return;
1335 SetLastError(0xdeadbeef);
1336 ret = DestroyWindow(shellWindow);
1337 error = GetLastError();
1339 ok(!ret, "DestroyWindow(shellWindow)\n");
1340 /* passes on Win XP, but not on Win98 */
1341 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
1342 "got %u after DestroyWindow(shellWindow)\n", error);
1344 /* close old shell instance */
1345 ret = TerminateProcess(hProcess, 0);
1346 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1347 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
1348 CloseHandle(hProcess);
1351 hwnd1 = CreateWindowExA(0, "#32770", "TEST1", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
1352 trace("created window 1: %p\n", hwnd1);
1354 ret = SetShellWindow(hwnd1);
1355 ok(ret, "first call to SetShellWindow(hwnd1)\n");
1356 shellWindow = GetShellWindow();
1357 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
1359 ret = SetShellWindow(hwnd1);
1360 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1362 ret = SetShellWindow(0);
1363 error = GetLastError();
1364 /* passes on Win XP, but not on Win98
1365 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1366 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1368 ret = SetShellWindow(hwnd1);
1369 /* passes on Win XP, but not on Win98
1370 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1372 SetWindowLongA(hwnd1, GWL_EXSTYLE, GetWindowLongA(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1373 ret = (GetWindowLongA(hwnd1,GWL_EXSTYLE) & WS_EX_TOPMOST) != 0;
1374 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1376 ret = DestroyWindow(hwnd1);
1377 ok(ret, "DestroyWindow(hwnd1)\n");
1379 hwnd2 = CreateWindowExA(WS_EX_TOPMOST, "#32770", "TEST2", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1380 trace("created window 2: %p\n", hwnd2);
1381 ret = SetShellWindow(hwnd2);
1382 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1384 hwnd3 = CreateWindowExA(0, "#32770", "TEST3", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1385 trace("created window 3: %p\n", hwnd3);
1387 hwnd4 = CreateWindowExA(0, "#32770", "TEST4", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1388 trace("created window 4: %p\n", hwnd4);
1390 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1391 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1393 ret = SetShellWindow(hwnd4);
1394 ok(ret, "SetShellWindow(hwnd4)\n");
1395 shellWindow = GetShellWindow();
1396 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1398 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1399 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1401 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1402 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1404 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1405 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1407 ret = SetShellWindow(hwnd3);
1408 ok(!ret, "SetShellWindow(hwnd3)\n");
1409 shellWindow = GetShellWindow();
1410 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1412 hwnd5 = CreateWindowExA(0, "#32770", "TEST5", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1413 trace("created window 5: %p\n", hwnd5);
1414 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1415 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1417 todo_wine
1419 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1420 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1423 /* destroy test windows */
1424 DestroyWindow(hwnd2);
1425 DestroyWindow(hwnd3);
1426 DestroyWindow(hwnd4);
1427 DestroyWindow(hwnd5);
1428 set_autorestart(restart);
1431 /************** MDI test ****************/
1433 static char mdi_lParam_test_message[] = "just a test string";
1435 static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
1437 MDICREATESTRUCTA mdi_cs;
1438 HWND mdi_child, hwnd, exp_hwnd;
1439 INT_PTR id;
1440 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1441 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1442 BOOL isWin9x = FALSE;
1443 HMENU frame_menu = GetMenu(parent);
1445 ok(frame_menu != NULL, "Frame window didn't have a menu\n");
1447 mdi_cs.szClass = "MDI_child_Class_1";
1448 mdi_cs.szTitle = "MDI child";
1449 mdi_cs.hOwner = GetModuleHandleA(NULL);
1450 mdi_cs.x = CW_USEDEFAULT;
1451 mdi_cs.y = CW_USEDEFAULT;
1452 mdi_cs.cx = CW_USEDEFAULT;
1453 mdi_cs.cy = CW_USEDEFAULT;
1454 mdi_cs.style = 0;
1455 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1456 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1457 ok(mdi_child != 0, "MDI child creation failed\n");
1458 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1459 ok(id == first_id, "wrong child id %ld\n", id);
1460 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1461 exp_hwnd = (GetWindowLongW(mdi_child, GWL_STYLE) & WS_VISIBLE) ? mdi_child : 0;
1462 ok(hwnd == exp_hwnd, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd, hwnd);
1463 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1464 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1466 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1467 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1468 ok(mdi_child != 0, "MDI child creation failed\n");
1469 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1470 ok(id == first_id, "wrong child id %ld\n", id);
1471 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1472 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1473 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1474 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1476 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1477 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1478 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1480 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1482 else
1484 ok(mdi_child != 0, "MDI child creation failed\n");
1485 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1486 ok(id == first_id, "wrong child id %ld\n", id);
1487 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1488 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1489 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1490 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1491 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1494 /* test MDICREATESTRUCT A<->W mapping */
1495 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1496 mdi_cs.style = 0;
1497 mdi_cs.szClass = (LPCSTR)classW;
1498 mdi_cs.szTitle = (LPCSTR)titleW;
1499 SetLastError(0xdeadbeef);
1500 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1501 if (!mdi_child)
1503 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1504 isWin9x = TRUE;
1505 else
1506 ok(mdi_child != 0, "MDI child creation failed\n");
1508 else
1510 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1511 ok(id == first_id, "wrong child id %ld\n", id);
1512 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1513 exp_hwnd = (GetWindowLongW(mdi_child, GWL_STYLE) & WS_VISIBLE) ? mdi_child : 0;
1514 ok(hwnd == exp_hwnd, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd, hwnd);
1515 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1516 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1517 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1520 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1522 CW_USEDEFAULT, CW_USEDEFAULT,
1523 CW_USEDEFAULT, CW_USEDEFAULT,
1524 mdi_client, GetModuleHandleA(NULL),
1525 (LPARAM)mdi_lParam_test_message);
1526 ok(mdi_child != 0, "MDI child creation failed\n");
1527 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1528 ok(id == first_id, "wrong child id %ld\n", id);
1529 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1530 exp_hwnd = (GetWindowLongW(mdi_child, GWL_STYLE) & WS_VISIBLE) ? mdi_child : 0;
1531 ok(hwnd == exp_hwnd, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd, hwnd);
1532 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1533 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1534 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1536 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1537 0x7fffffff, /* without WS_POPUP */
1538 CW_USEDEFAULT, CW_USEDEFAULT,
1539 CW_USEDEFAULT, CW_USEDEFAULT,
1540 mdi_client, GetModuleHandleA(NULL),
1541 (LPARAM)mdi_lParam_test_message);
1542 ok(mdi_child != 0, "MDI child creation failed\n");
1543 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1544 ok(id == first_id, "wrong child id %ld\n", id);
1545 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1546 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1547 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1548 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1549 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1551 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1552 0xffffffff, /* with WS_POPUP */
1553 CW_USEDEFAULT, CW_USEDEFAULT,
1554 CW_USEDEFAULT, CW_USEDEFAULT,
1555 mdi_client, GetModuleHandleA(NULL),
1556 (LPARAM)mdi_lParam_test_message);
1557 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1559 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1561 else
1563 ok(mdi_child != 0, "MDI child creation failed\n");
1564 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1565 ok(id == first_id, "wrong child id %ld\n", id);
1566 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1567 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1568 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1569 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1570 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1573 /* test MDICREATESTRUCT A<->W mapping */
1574 SetLastError(0xdeadbeef);
1575 mdi_child = CreateMDIWindowW(classW, titleW,
1577 CW_USEDEFAULT, CW_USEDEFAULT,
1578 CW_USEDEFAULT, CW_USEDEFAULT,
1579 mdi_client, GetModuleHandleA(NULL),
1580 (LPARAM)mdi_lParam_test_message);
1581 if (!mdi_child)
1583 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1584 isWin9x = TRUE;
1585 else
1586 ok(mdi_child != 0, "MDI child creation failed\n");
1588 else
1590 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1591 ok(id == first_id, "wrong child id %ld\n", id);
1592 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1593 exp_hwnd = (GetWindowLongW(mdi_child, GWL_STYLE) & WS_VISIBLE) ? mdi_child : 0;
1594 ok(hwnd == exp_hwnd, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd, hwnd);
1595 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1596 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1597 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1600 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1602 CW_USEDEFAULT, CW_USEDEFAULT,
1603 CW_USEDEFAULT, CW_USEDEFAULT,
1604 mdi_client, 0, GetModuleHandleA(NULL),
1605 mdi_lParam_test_message);
1606 ok(mdi_child != 0, "MDI child creation failed\n");
1607 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1608 ok(id == first_id, "wrong child id %ld\n", id);
1609 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1610 exp_hwnd = (GetWindowLongW(mdi_child, GWL_STYLE) & WS_VISIBLE) ? mdi_child : 0;
1611 ok(hwnd == exp_hwnd, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd, hwnd);
1612 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1613 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1614 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1616 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1617 WS_MAXIMIZE,
1618 CW_USEDEFAULT, CW_USEDEFAULT,
1619 CW_USEDEFAULT, CW_USEDEFAULT,
1620 mdi_client, 0, GetModuleHandleA(NULL),
1621 mdi_lParam_test_message);
1622 ok(mdi_child != 0, "MDI child creation failed\n");
1623 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1624 ok(id == first_id, "wrong child id %ld\n", id);
1625 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1626 exp_hwnd = (GetWindowLongW(mdi_child, GWL_STYLE) & WS_VISIBLE) ? mdi_child : 0;
1627 ok(hwnd == exp_hwnd, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd, hwnd);
1628 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1629 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1630 else
1631 ok(GetMenuItemCount(frame_menu) == 4, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1632 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1633 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1635 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1636 0x7fffffff, /* without WS_POPUP */
1637 CW_USEDEFAULT, CW_USEDEFAULT,
1638 CW_USEDEFAULT, CW_USEDEFAULT,
1639 mdi_client, 0, GetModuleHandleA(NULL),
1640 mdi_lParam_test_message);
1641 ok(mdi_child != 0, "MDI child creation failed\n");
1642 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1643 ok(id == first_id, "wrong child id %ld\n", id);
1644 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1645 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1646 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1647 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1648 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1650 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1651 0xffffffff, /* with WS_POPUP */
1652 CW_USEDEFAULT, CW_USEDEFAULT,
1653 CW_USEDEFAULT, CW_USEDEFAULT,
1654 mdi_client, 0, GetModuleHandleA(NULL),
1655 mdi_lParam_test_message);
1656 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1658 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1660 else
1662 ok(mdi_child != 0, "MDI child creation failed\n");
1663 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1664 ok(id == first_id, "wrong child id %ld\n", id);
1665 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1666 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1667 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1668 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1669 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1672 /* test MDICREATESTRUCT A<->W mapping */
1673 SetLastError(0xdeadbeef);
1674 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1676 CW_USEDEFAULT, CW_USEDEFAULT,
1677 CW_USEDEFAULT, CW_USEDEFAULT,
1678 mdi_client, 0, GetModuleHandleA(NULL),
1679 mdi_lParam_test_message);
1680 if (!mdi_child)
1682 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1683 isWin9x = TRUE;
1684 else
1685 ok(mdi_child != 0, "MDI child creation failed\n");
1687 else
1689 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1690 ok(id == first_id, "wrong child id %ld\n", id);
1691 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1692 exp_hwnd = (GetWindowLongW(mdi_child, GWL_STYLE) & WS_VISIBLE) ? mdi_child : 0;
1693 ok(hwnd == exp_hwnd, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd, hwnd);
1694 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1695 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1696 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1699 /* This test fails on Win9x */
1700 if (!isWin9x)
1702 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1703 WS_CHILD,
1704 CW_USEDEFAULT, CW_USEDEFAULT,
1705 CW_USEDEFAULT, CW_USEDEFAULT,
1706 parent, 0, GetModuleHandleA(NULL),
1707 mdi_lParam_test_message);
1708 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1711 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1712 WS_CHILD, /* without WS_POPUP */
1713 CW_USEDEFAULT, CW_USEDEFAULT,
1714 CW_USEDEFAULT, CW_USEDEFAULT,
1715 mdi_client, 0, GetModuleHandleA(NULL),
1716 mdi_lParam_test_message);
1717 ok(mdi_child != 0, "MDI child creation failed\n");
1718 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1719 ok(id == 0, "wrong child id %ld\n", id);
1720 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1721 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1722 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1723 DestroyWindow(mdi_child);
1725 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1726 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1727 CW_USEDEFAULT, CW_USEDEFAULT,
1728 CW_USEDEFAULT, CW_USEDEFAULT,
1729 mdi_client, 0, GetModuleHandleA(NULL),
1730 mdi_lParam_test_message);
1731 ok(mdi_child != 0, "MDI child creation failed\n");
1732 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1733 ok(id == 0, "wrong child id %ld\n", id);
1734 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1735 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1736 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1737 DestroyWindow(mdi_child);
1739 /* maximized child */
1740 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1741 WS_CHILD | WS_MAXIMIZE,
1742 CW_USEDEFAULT, CW_USEDEFAULT,
1743 CW_USEDEFAULT, CW_USEDEFAULT,
1744 mdi_client, 0, GetModuleHandleA(NULL),
1745 mdi_lParam_test_message);
1746 ok(mdi_child != 0, "MDI child creation failed\n");
1747 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1748 ok(id == 0, "wrong child id %ld\n", id);
1749 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1750 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1751 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1752 DestroyWindow(mdi_child);
1754 trace("Creating maximized child with a caption\n");
1755 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1756 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1757 CW_USEDEFAULT, CW_USEDEFAULT,
1758 CW_USEDEFAULT, CW_USEDEFAULT,
1759 mdi_client, 0, GetModuleHandleA(NULL),
1760 mdi_lParam_test_message);
1761 ok(mdi_child != 0, "MDI child creation failed\n");
1762 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1763 ok(id == 0, "wrong child id %ld\n", id);
1764 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1765 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1766 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1767 DestroyWindow(mdi_child);
1769 trace("Creating maximized child with a caption and a thick frame\n");
1770 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1771 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1772 CW_USEDEFAULT, CW_USEDEFAULT,
1773 CW_USEDEFAULT, CW_USEDEFAULT,
1774 mdi_client, 0, GetModuleHandleA(NULL),
1775 mdi_lParam_test_message);
1776 ok(mdi_child != 0, "MDI child creation failed\n");
1777 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1778 ok(id == 0, "wrong child id %ld\n", id);
1779 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1780 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1781 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1782 DestroyWindow(mdi_child);
1785 static void test_MDI_child_stack(HWND mdi_client)
1787 HWND child_1, child_2, child_3, child_4;
1788 HWND stack[4];
1789 MDICREATESTRUCTA cs;
1791 cs.szClass = "MDI_child_Class_1";
1792 cs.szTitle = "MDI child";
1793 cs.hOwner = GetModuleHandleA(0);
1794 cs.x = CW_USEDEFAULT;
1795 cs.y = CW_USEDEFAULT;
1796 cs.cx = CW_USEDEFAULT;
1797 cs.cy = CW_USEDEFAULT;
1798 cs.style = 0;
1799 cs.lParam = (LPARAM)mdi_lParam_test_message;
1801 child_1 = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&cs);
1802 ok(child_1 != 0, "expected child_1 to be non NULL\n");
1803 child_2 = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&cs);
1804 ok(child_2 != 0, "expected child_2 to be non NULL\n");
1805 child_3 = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&cs);
1806 ok(child_3 != 0, "expected child_3 to be non NULL\n");
1807 child_4 = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&cs);
1808 ok(child_4 != 0, "expected child_4 to be non NULL\n");
1810 stack[0] = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1811 stack[1] = GetWindow(stack[0], GW_HWNDNEXT);
1812 stack[2] = GetWindow(stack[1], GW_HWNDNEXT);
1813 stack[3] = GetWindow(stack[2], GW_HWNDNEXT);
1814 trace("Initial MDI child stack: %p->%p->%p->%p\n", stack[0], stack[1], stack[2], stack[3]);
1815 ok(stack[0] == child_4 && stack[1] == child_3 &&
1816 stack[2] == child_2 && stack[3] == child_1,
1817 "Unexpected initial order, should be: %p->%p->%p->%p\n",
1818 child_4, child_3, child_2, child_1);
1820 trace("Activate child next to %p\n", child_3);
1821 SendMessageA(mdi_client, WM_MDINEXT, (WPARAM)child_3, 0);
1823 stack[0] = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1824 stack[1] = GetWindow(stack[0], GW_HWNDNEXT);
1825 stack[2] = GetWindow(stack[1], GW_HWNDNEXT);
1826 stack[3] = GetWindow(stack[2], GW_HWNDNEXT);
1827 ok(stack[0] == child_2 && stack[1] == child_4 &&
1828 stack[2] == child_1 && stack[3] == child_3,
1829 "Broken MDI child stack:\nexpected: %p->%p->%p->%p, but got: %p->%p->%p->%p\n",
1830 child_2, child_4, child_1, child_3, stack[0], stack[1], stack[2], stack[3]);
1832 trace("Activate child previous to %p\n", child_1);
1833 SendMessageA(mdi_client, WM_MDINEXT, (WPARAM)child_1, 1);
1835 stack[0] = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1836 stack[1] = GetWindow(stack[0], GW_HWNDNEXT);
1837 stack[2] = GetWindow(stack[1], GW_HWNDNEXT);
1838 stack[3] = GetWindow(stack[2], GW_HWNDNEXT);
1839 ok(stack[0] == child_4 && stack[1] == child_2 &&
1840 stack[2] == child_1 && stack[3] == child_3,
1841 "Broken MDI child stack:\nexpected: %p->%p->%p->%p, but got: %p->%p->%p->%p\n",
1842 child_4, child_2, child_1, child_3, stack[0], stack[1], stack[2], stack[3]);
1844 trace("Minimize child %p\n", child_4);
1845 ShowWindow(child_4, SW_MINIMIZE);
1847 stack[0] = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1848 stack[1] = GetWindow(stack[0], GW_HWNDNEXT);
1849 todo_wine ok(stack[0] == child_4, "Expected %p, got %p\n", child_4, stack[0]);
1850 todo_wine ok(stack[1] == NULL, "Expected NULL, got %p\n", stack[1]);
1852 DestroyWindow(child_1);
1853 DestroyWindow(child_2);
1854 DestroyWindow(child_3);
1855 DestroyWindow(child_4);
1858 /**********************************************************************
1859 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1861 * Note: The rule here is that client rect of the maximized MDI child
1862 * is equal to the client rect of the MDI client window.
1864 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1866 RECT rect;
1868 GetClientRect( client, &rect );
1869 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1870 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1872 rect.right -= rect.left;
1873 rect.bottom -= rect.top;
1874 lpMinMax->ptMaxSize.x = rect.right;
1875 lpMinMax->ptMaxSize.y = rect.bottom;
1877 lpMinMax->ptMaxPosition.x = rect.left;
1878 lpMinMax->ptMaxPosition.y = rect.top;
1880 trace("max rect %s\n", wine_dbgstr_rect(&rect));
1883 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1885 switch (msg)
1887 case WM_NCCREATE:
1888 case WM_CREATE:
1890 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1891 MDICREATESTRUCTA *mdi_cs = cs->lpCreateParams;
1893 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1894 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1896 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1897 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1898 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1899 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1900 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1902 /* MDICREATESTRUCT should have original values */
1903 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff || mdi_cs->style == WS_MAXIMIZE,
1904 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1905 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1906 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1907 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1908 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1910 /* CREATESTRUCT should have fixed values */
1911 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1912 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1914 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1915 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1916 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1918 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1920 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1922 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1923 ok(cs->style == style,
1924 "cs->style does not match (%08x)\n", cs->style);
1926 else
1928 LONG style = mdi_cs->style;
1929 style &= ~WS_POPUP;
1930 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1931 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1932 ok(cs->style == style,
1933 "cs->style does not match (%08x)\n", cs->style);
1935 break;
1938 case WM_GETMINMAXINFO:
1940 HWND client = GetParent(hwnd);
1941 RECT rc;
1942 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1943 MINMAXINFO my_minmax;
1944 LONG style, exstyle;
1946 style = GetWindowLongA(hwnd, GWL_STYLE);
1947 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1949 GetClientRect(client, &rc);
1951 GetClientRect(client, &rc);
1952 if ((style & WS_CAPTION) == WS_CAPTION)
1953 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1954 AdjustWindowRectEx(&rc, style, 0, exstyle);
1955 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1956 dump_minmax_info( minmax );
1958 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1959 minmax->ptMaxSize.x, rc.right - rc.left);
1960 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1961 minmax->ptMaxSize.y, rc.bottom - rc.top);
1963 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1965 trace("DefMDIChildProc returned:\n");
1966 dump_minmax_info( minmax );
1968 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1969 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1970 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1971 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1972 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1974 return 1;
1977 case WM_MDIACTIVATE:
1979 HWND active, client = GetParent(hwnd);
1980 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1981 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1982 if (hwnd == (HWND)lparam) /* if we are being activated */
1983 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1984 else
1985 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1986 break;
1989 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1992 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1994 switch (msg)
1996 case WM_NCCREATE:
1997 case WM_CREATE:
1999 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
2001 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE",
2002 cs->x, cs->y, cs->cx, cs->cy);
2004 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
2005 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
2007 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
2008 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
2010 /* CREATESTRUCT should have fixed values */
2011 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
2012 while NT does. */
2013 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
2014 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
2016 /* cx/cy == CW_USEDEFAULT are translated to 0 */
2017 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
2018 while Win95, Win2k, WinXP do. */
2019 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
2020 ok(cs->cy == 0, "%d != 0\n", cs->cy);
2021 break;
2024 case WM_GETMINMAXINFO:
2026 HWND parent = GetParent(hwnd);
2027 RECT rc;
2028 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
2029 LONG style, exstyle;
2031 style = GetWindowLongA(hwnd, GWL_STYLE);
2032 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
2034 GetClientRect(parent, &rc);
2035 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
2037 GetClientRect(parent, &rc);
2038 if ((style & WS_CAPTION) == WS_CAPTION)
2039 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
2040 AdjustWindowRectEx(&rc, style, 0, exstyle);
2041 dump_minmax_info( minmax );
2043 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
2044 minmax->ptMaxSize.x, rc.right - rc.left);
2045 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
2046 minmax->ptMaxSize.y, rc.bottom - rc.top);
2047 break;
2050 case WM_WINDOWPOSCHANGED:
2052 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
2053 RECT rc1, rc2;
2055 GetWindowRect(hwnd, &rc1);
2056 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
2057 /* note: winpos coordinates are relative to parent */
2058 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
2059 ok(EqualRect(&rc1, &rc2), "rects do not match, window=%s pos=%s\n",
2060 wine_dbgstr_rect(&rc1), wine_dbgstr_rect(&rc2));
2061 GetWindowRect(hwnd, &rc1);
2062 GetClientRect(hwnd, &rc2);
2063 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
2064 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
2065 ok(EqualRect(&rc1, &rc2), "rects do not match, window=%s client=%s\n",
2066 wine_dbgstr_rect(&rc1), wine_dbgstr_rect(&rc2));
2068 /* fall through */
2069 case WM_WINDOWPOSCHANGING:
2071 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
2072 WINDOWPOS my_winpos = *winpos;
2074 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2075 (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
2076 winpos->hwnd, winpos->hwndInsertAfter,
2077 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2079 DefWindowProcA(hwnd, msg, wparam, lparam);
2081 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
2082 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2083 winpos->hwnd, winpos->hwndInsertAfter,
2084 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2086 return 1;
2089 return DefWindowProcA(hwnd, msg, wparam, lparam);
2092 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2094 static HWND mdi_client;
2096 switch (msg)
2098 case WM_CREATE:
2099 return 1;
2101 case WM_WINDOWPOSCHANGED:
2103 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
2104 RECT rc1, rc2;
2106 GetWindowRect(hwnd, &rc1);
2107 trace("window: %s\n", wine_dbgstr_rect(&rc1));
2108 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
2109 /* note: winpos coordinates are relative to parent */
2110 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
2111 trace("pos: %s\n", wine_dbgstr_rect(&rc2));
2112 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
2114 GetWindowRect(hwnd, &rc1);
2115 GetClientRect(hwnd, &rc2);
2116 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
2117 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
2118 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
2120 /* fall through */
2121 case WM_WINDOWPOSCHANGING:
2123 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
2124 WINDOWPOS my_winpos = *winpos;
2126 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2127 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2128 winpos->hwnd, winpos->hwndInsertAfter,
2129 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2131 DefWindowProcA(hwnd, msg, wparam, lparam);
2133 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2134 winpos->hwnd, winpos->hwndInsertAfter,
2135 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2137 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
2138 "DefWindowProc should not change WINDOWPOS values\n");
2140 return 1;
2143 case WM_CLOSE:
2144 PostQuitMessage(0);
2145 break;
2147 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
2150 static BOOL mdi_RegisterWindowClasses(void)
2152 WNDCLASSA cls;
2154 cls.style = 0;
2155 cls.lpfnWndProc = mdi_main_wnd_procA;
2156 cls.cbClsExtra = 0;
2157 cls.cbWndExtra = 0;
2158 cls.hInstance = GetModuleHandleA(0);
2159 cls.hIcon = 0;
2160 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
2161 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
2162 cls.lpszMenuName = NULL;
2163 cls.lpszClassName = "MDI_parent_Class";
2164 if(!RegisterClassA(&cls)) return FALSE;
2166 cls.lpfnWndProc = mdi_child_wnd_proc_1;
2167 cls.lpszClassName = "MDI_child_Class_1";
2168 if(!RegisterClassA(&cls)) return FALSE;
2170 cls.lpfnWndProc = mdi_child_wnd_proc_2;
2171 cls.lpszClassName = "MDI_child_Class_2";
2172 if(!RegisterClassA(&cls)) return FALSE;
2174 return TRUE;
2177 static void test_mdi(void)
2179 static const DWORD style[] = { 0, WS_HSCROLL, WS_VSCROLL, WS_HSCROLL | WS_VSCROLL };
2180 HWND mdi_hwndMain, mdi_client, mdi_child;
2181 CLIENTCREATESTRUCT client_cs;
2182 RECT rc;
2183 DWORD i;
2184 MSG msg;
2185 HMENU frame_menu, child_menu;
2187 if (!mdi_RegisterWindowClasses()) assert(0);
2189 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
2190 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
2191 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
2192 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
2193 GetDesktopWindow(), 0,
2194 GetModuleHandleA(NULL), NULL);
2195 assert(mdi_hwndMain);
2197 frame_menu = CreateMenu();
2199 GetClientRect(mdi_hwndMain, &rc);
2201 client_cs.hWindowMenu = 0;
2202 client_cs.idFirstChild = 1;
2204 for (i = 0; i < sizeof(style)/sizeof(style[0]); i++)
2206 SCROLLINFO si;
2207 BOOL ret, gotit;
2209 mdi_client = CreateWindowExA(0, "mdiclient", NULL,
2210 WS_CHILD | style[i],
2211 0, 0, rc.right, rc.bottom,
2212 mdi_hwndMain, 0, 0, &client_cs);
2213 ok(mdi_client != 0, "MDI client creation failed\n");
2215 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
2217 CW_USEDEFAULT, CW_USEDEFAULT,
2218 CW_USEDEFAULT, CW_USEDEFAULT,
2219 mdi_client, 0, 0,
2220 mdi_lParam_test_message);
2221 ok(mdi_child != 0, "MDI child creation failed\n");
2223 SendMessageW(mdi_child, WM_SIZE, SIZE_MAXIMIZED, 0);
2224 SetMenu(mdi_hwndMain, frame_menu);
2226 ok(GetMenuItemCount(frame_menu) == 0, "Frame menu should be empty after child maximize, but has %u\n",
2227 GetMenuItemCount(frame_menu));
2229 child_menu = CreateMenu();
2230 SendMessageW(mdi_client, WM_MDISETMENU, 0, (LPARAM)child_menu);
2232 ok(GetMenuItemCount(frame_menu) == 0, "Frame menu should be empty after WM_MDISETMENU, but has %u\n",
2233 GetMenuItemCount(frame_menu));
2235 SendMessageW(mdi_child, WM_SIZE, SIZE_RESTORED, 0);
2237 ok(GetMenuItemCount(frame_menu) == 0, "Frame menu should be empty after child restored, but has %u items\n",
2238 GetMenuItemCount(frame_menu));
2240 SetMenu(mdi_hwndMain, NULL);
2242 si.cbSize = sizeof(si);
2243 si.fMask = SIF_ALL;
2244 ret = GetScrollInfo(mdi_client, SB_HORZ, &si);
2245 if (style[i] & (WS_HSCROLL | WS_VSCROLL))
2247 ok(ret, "style %#x: GetScrollInfo(SB_HORZ) failed\n", style[i]);
2248 ok(si.nPage == 0, "expected 0\n");
2249 ok(si.nPos == 0, "expected 0\n");
2250 ok(si.nTrackPos == 0, "expected 0\n");
2251 ok(si.nMin == 0, "expected 0\n");
2252 ok(si.nMax == 100, "expected 100\n");
2254 else
2255 ok(!ret, "style %#x: GetScrollInfo(SB_HORZ) should fail\n", style[i]);
2257 ret = GetScrollInfo(mdi_client, SB_VERT, &si);
2258 if (style[i] & (WS_HSCROLL | WS_VSCROLL))
2260 ok(ret, "style %#x: GetScrollInfo(SB_VERT) failed\n", style[i]);
2261 ok(si.nPage == 0, "expected 0\n");
2262 ok(si.nPos == 0, "expected 0\n");
2263 ok(si.nTrackPos == 0, "expected 0\n");
2264 ok(si.nMin == 0, "expected 0\n");
2265 ok(si.nMax == 100, "expected 100\n");
2267 else
2268 ok(!ret, "style %#x: GetScrollInfo(SB_VERT) should fail\n", style[i]);
2270 SetWindowPos(mdi_child, 0, -100, -100, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
2272 si.cbSize = sizeof(si);
2273 si.fMask = SIF_ALL;
2274 ret = GetScrollInfo(mdi_client, SB_HORZ, &si);
2275 if (style[i] & (WS_HSCROLL | WS_VSCROLL))
2277 ok(ret, "style %#x: GetScrollInfo(SB_HORZ) failed\n", style[i]);
2278 ok(si.nPage == 0, "expected 0\n");
2279 ok(si.nPos == 0, "expected 0\n");
2280 ok(si.nTrackPos == 0, "expected 0\n");
2281 ok(si.nMin == 0, "expected 0\n");
2282 ok(si.nMax == 100, "expected 100\n");
2284 else
2285 ok(!ret, "style %#x: GetScrollInfo(SB_HORZ) should fail\n", style[i]);
2287 ret = GetScrollInfo(mdi_client, SB_VERT, &si);
2288 if (style[i] & (WS_HSCROLL | WS_VSCROLL))
2290 ok(ret, "style %#x: GetScrollInfo(SB_VERT) failed\n", style[i]);
2291 ok(si.nPage == 0, "expected 0\n");
2292 ok(si.nPos == 0, "expected 0\n");
2293 ok(si.nTrackPos == 0, "expected 0\n");
2294 ok(si.nMin == 0, "expected 0\n");
2295 ok(si.nMax == 100, "expected 100\n");
2297 else
2298 ok(!ret, "style %#x: GetScrollInfo(SB_VERT) should fail\n", style[i]);
2300 gotit = FALSE;
2301 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2303 if (msg.message == WM_MOUSEMOVE || msg.message == WM_PAINT)
2305 DispatchMessageA(&msg);
2306 continue;
2309 if (msg.message == 0x003f) /* WM_MDICALCCHILDSCROLL ??? */
2311 ok(msg.hwnd == mdi_client, "message 0x003f should be posted to mdiclient\n");
2312 gotit = TRUE;
2314 else
2315 ok(msg.hwnd != mdi_client, "message %04x should not be posted to mdiclient\n", msg.message);
2316 DispatchMessageA(&msg);
2318 ok(gotit, "message 0x003f should appear after SetWindowPos\n");
2320 si.cbSize = sizeof(si);
2321 si.fMask = SIF_ALL;
2322 ret = GetScrollInfo(mdi_client, SB_HORZ, &si);
2323 if (style[i] & (WS_HSCROLL | WS_VSCROLL))
2325 ok(ret, "style %#x: GetScrollInfo(SB_HORZ) failed\n", style[i]);
2326 todo_wine
2327 ok(si.nPage != 0, "expected !0\n");
2328 ok(si.nPos == 0, "expected 0\n");
2329 ok(si.nTrackPos == 0, "expected 0\n");
2330 ok(si.nMin != 0, "expected !0\n");
2331 ok(si.nMax != 100, "expected !100\n");
2333 else
2334 ok(!ret, "style %#x: GetScrollInfo(SB_HORZ) should fail\n", style[i]);
2336 ret = GetScrollInfo(mdi_client, SB_VERT, &si);
2337 if (style[i] & (WS_HSCROLL | WS_VSCROLL))
2339 ok(ret, "style %#x: GetScrollInfo(SB_VERT) failed\n", style[i]);
2340 todo_wine
2341 ok(si.nPage != 0, "expected !0\n");
2342 ok(si.nPos == 0, "expected 0\n");
2343 ok(si.nTrackPos == 0, "expected 0\n");
2344 ok(si.nMin != 0, "expected !0\n");
2345 ok(si.nMax != 100, "expected !100\n");
2347 else
2348 ok(!ret, "style %#x: GetScrollInfo(SB_VERT) should fail\n", style[i]);
2350 DestroyMenu(child_menu);
2351 DestroyWindow(mdi_child);
2352 DestroyWindow(mdi_client);
2355 SetMenu(mdi_hwndMain, frame_menu);
2357 mdi_client = CreateWindowExA(0, "mdiclient", NULL,
2358 WS_CHILD,
2359 0, 0, rc.right, rc.bottom,
2360 mdi_hwndMain, 0, 0, &client_cs);
2361 ok(mdi_client != 0, "MDI client creation failed\n");
2363 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
2365 CW_USEDEFAULT, CW_USEDEFAULT,
2366 CW_USEDEFAULT, CW_USEDEFAULT,
2367 mdi_client, 0, 0,
2368 mdi_lParam_test_message);
2369 ok(mdi_child != 0, "MDI child creation failed\n");
2371 SendMessageW(mdi_child, WM_SIZE, SIZE_MAXIMIZED, 0);
2372 ok(GetMenuItemCount(frame_menu) == 4, "Frame menu should have 4 items after child maximize, but has %u\n",
2373 GetMenuItemCount(frame_menu));
2375 child_menu = CreateMenu();
2376 SendMessageW(mdi_client, WM_MDISETMENU, 0, (LPARAM)child_menu);
2378 ok(GetMenuItemCount(frame_menu) == 4, "Frame menu should have 4 items after WM_MDISETMENU, but has %u\n",
2379 GetMenuItemCount(frame_menu));
2381 SendMessageW(mdi_child, WM_SIZE, SIZE_RESTORED, 0);
2383 ok(GetMenuItemCount(frame_menu) == 0, "Frame menu should be empty after child restored, but has %u items\n",
2384 GetMenuItemCount(frame_menu));
2386 DestroyMenu(child_menu);
2387 DestroyWindow(mdi_child);
2388 DestroyWindow(mdi_client);
2390 /* MDIClient without MDIS_ALLCHILDSTYLES */
2391 mdi_client = CreateWindowExA(0, "mdiclient",
2392 NULL,
2393 WS_CHILD /*| WS_VISIBLE*/,
2394 /* tests depend on a not zero MDIClient size */
2395 0, 0, rc.right, rc.bottom,
2396 mdi_hwndMain, 0, GetModuleHandleA(NULL),
2397 &client_cs);
2398 assert(mdi_client);
2399 test_MDI_create(mdi_hwndMain, mdi_client, client_cs.idFirstChild);
2400 DestroyWindow(mdi_client);
2402 /* MDIClient with MDIS_ALLCHILDSTYLES */
2403 mdi_client = CreateWindowExA(0, "mdiclient",
2404 NULL,
2405 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
2406 /* tests depend on a not zero MDIClient size */
2407 0, 0, rc.right, rc.bottom,
2408 mdi_hwndMain, 0, GetModuleHandleA(NULL),
2409 &client_cs);
2410 assert(mdi_client);
2411 test_MDI_create(mdi_hwndMain, mdi_client, client_cs.idFirstChild);
2412 DestroyWindow(mdi_client);
2414 /* Test child window stack management */
2415 mdi_client = CreateWindowExA(0, "mdiclient",
2416 NULL,
2417 WS_CHILD,
2418 0, 0, rc.right, rc.bottom,
2419 mdi_hwndMain, 0, GetModuleHandleA(NULL),
2420 &client_cs);
2421 assert(mdi_client);
2422 test_MDI_child_stack(mdi_client);
2423 DestroyWindow(mdi_client);
2425 while(GetMessage(&msg, 0, 0, 0))
2427 TranslateMessage(&msg);
2428 DispatchMessage(&msg);
2431 DestroyWindow(mdi_hwndMain);
2434 static void test_icons(void)
2436 WNDCLASSEXA cls;
2437 HWND hwnd;
2438 HICON icon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
2439 HICON icon2 = LoadIconA(0, (LPCSTR)IDI_QUESTION);
2440 HICON small_icon = LoadImageA(0, (LPCSTR)IDI_APPLICATION, IMAGE_ICON,
2441 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
2442 HICON res;
2444 cls.cbSize = sizeof(cls);
2445 cls.style = 0;
2446 cls.lpfnWndProc = DefWindowProcA;
2447 cls.cbClsExtra = 0;
2448 cls.cbWndExtra = 0;
2449 cls.hInstance = 0;
2450 cls.hIcon = LoadIconA(0, (LPCSTR)IDI_HAND);
2451 cls.hIconSm = small_icon;
2452 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
2453 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
2454 cls.lpszMenuName = NULL;
2455 cls.lpszClassName = "IconWindowClass";
2457 RegisterClassExA(&cls);
2459 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
2460 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
2461 assert( hwnd );
2463 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
2464 ok( res == 0, "wrong big icon %p/0\n", res );
2465 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
2466 ok( res == 0, "wrong previous big icon %p/0\n", res );
2467 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
2468 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
2469 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
2470 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
2471 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
2472 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
2474 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
2475 ok( res == 0, "wrong small icon %p/0\n", res );
2476 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
2477 ok( (res && res != small_icon && res != icon2) || broken(!res), "wrong small2 icon %p\n", res );
2478 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
2479 ok( res == 0, "wrong previous small icon %p/0\n", res );
2480 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
2481 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
2482 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
2483 ok( res == icon || broken(!res), "wrong small2 icon after set %p/%p\n", res, icon );
2484 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
2485 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
2486 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
2487 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
2488 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
2489 ok( res == small_icon || broken(!res), "wrong small2 icon after set %p/%p\n", res, small_icon );
2491 /* make sure the big icon hasn't changed */
2492 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
2493 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
2495 DestroyWindow( hwnd );
2498 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2500 if (msg == WM_NCCALCSIZE)
2502 RECT *rect = (RECT *)lparam;
2503 /* first time around increase the rectangle, next time decrease it */
2504 if (rect->left == 100) InflateRect( rect, 10, 10 );
2505 else InflateRect( rect, -10, -10 );
2506 return 0;
2508 return DefWindowProcA( hwnd, msg, wparam, lparam );
2511 static void test_SetWindowPos(HWND hwnd, HWND hwnd2)
2513 RECT orig_win_rc, rect;
2514 LONG_PTR old_proc;
2515 HWND hwnd_grandchild, hwnd_child, hwnd_child2;
2516 HWND hwnd_desktop;
2517 RECT rc1, rc2;
2518 BOOL ret;
2520 SetRect(&rect, 111, 222, 333, 444);
2521 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
2522 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
2523 "wrong window rect %s\n", wine_dbgstr_rect(&rect));
2525 SetRect(&rect, 111, 222, 333, 444);
2526 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
2527 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
2528 "wrong window rect %s\n", wine_dbgstr_rect(&rect));
2530 GetWindowRect(hwnd, &orig_win_rc);
2532 old_proc = SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
2533 ret = SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
2534 ok(ret, "Got %d\n", ret);
2535 GetWindowRect( hwnd, &rect );
2536 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
2537 "invalid window rect %s\n", wine_dbgstr_rect(&rect));
2538 GetClientRect( hwnd, &rect );
2539 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
2540 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
2541 "invalid client rect %s\n", wine_dbgstr_rect(&rect));
2543 ret = SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
2544 ok(ret, "Got %d\n", ret);
2545 GetWindowRect( hwnd, &rect );
2546 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
2547 "invalid window rect %s\n", wine_dbgstr_rect(&rect));
2548 GetClientRect( hwnd, &rect );
2549 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
2550 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
2551 "invalid client rect %s\n", wine_dbgstr_rect(&rect));
2553 ret = SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
2554 orig_win_rc.right, orig_win_rc.bottom, 0);
2555 ok(ret, "Got %d\n", ret);
2556 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, old_proc );
2558 /* Win9x truncates coordinates to 16-bit irrespectively */
2559 if (!is_win9x)
2561 ret = SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
2562 ok(ret, "Got %d\n", ret);
2563 ret = SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
2564 ok(ret, "Got %d\n", ret);
2566 ret = SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
2567 ok(ret, "Got %d\n", ret);
2568 ret = SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
2569 ok(ret, "Got %d\n", ret);
2572 ret = SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
2573 orig_win_rc.right, orig_win_rc.bottom, 0);
2574 ok(ret, "Got %d\n", ret);
2576 hwnd_desktop = GetDesktopWindow();
2577 ok(!!hwnd_desktop, "Failed to get hwnd_desktop window (%d).\n", GetLastError());
2578 hwnd_child = create_tool_window(WS_VISIBLE|WS_CHILD, hwnd);
2579 ok(!!hwnd_child, "Failed to create child window (%d)\n", GetLastError());
2580 hwnd_grandchild = create_tool_window(WS_VISIBLE|WS_CHILD, hwnd_child);
2581 ok(!!hwnd_child, "Failed to create child window (%d)\n", GetLastError());
2582 hwnd_child2 = create_tool_window(WS_VISIBLE|WS_CHILD, hwnd);
2583 ok(!!hwnd_child2, "Failed to create second child window (%d)\n", GetLastError());
2585 ret = SetWindowPos(hwnd, hwnd2, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2586 ok(ret, "Got %d\n", ret);
2587 check_active_state(hwnd, hwnd, hwnd);
2589 ret = SetWindowPos(hwnd2, hwnd, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2590 ok(ret, "Got %d\n", ret);
2591 check_active_state(hwnd2, hwnd2, hwnd2);
2593 /* Returns TRUE also for windows that are not siblings */
2594 ret = SetWindowPos(hwnd_child, hwnd2, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2595 ok(ret, "Got %d\n", ret);
2596 check_active_state(hwnd2, hwnd2, hwnd2);
2598 ret = SetWindowPos(hwnd2, hwnd_child, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2599 ok(ret, "Got %d\n", ret);
2600 check_active_state(hwnd2, hwnd2, hwnd2);
2602 /* Does not seem to do anything even without passing flags, still returns TRUE */
2603 GetWindowRect(hwnd_child, &rc1);
2604 ret = SetWindowPos(hwnd_child, hwnd2 , 1, 2, 3, 4, 0);
2605 ok(ret, "Got %d\n", ret);
2606 GetWindowRect(hwnd_child, &rc2);
2607 ok(EqualRect(&rc1, &rc2), "%s != %s\n", wine_dbgstr_rect(&rc1), wine_dbgstr_rect(&rc2));
2608 check_active_state(hwnd2, hwnd2, hwnd2);
2610 /* Same thing the other way around. */
2611 GetWindowRect(hwnd2, &rc1);
2612 ret = SetWindowPos(hwnd2, hwnd_child, 1, 2, 3, 4, 0);
2613 ok(ret, "Got %d\n", ret);
2614 GetWindowRect(hwnd2, &rc2);
2615 ok(EqualRect(&rc1, &rc2), "%s != %s\n", wine_dbgstr_rect(&rc1), wine_dbgstr_rect(&rc2));
2616 check_active_state(hwnd2, hwnd2, hwnd2);
2618 /* .. and with these windows. */
2619 GetWindowRect(hwnd_grandchild, &rc1);
2620 ret = SetWindowPos(hwnd_grandchild, hwnd_child2, 1, 2, 3, 4, 0);
2621 ok(ret, "Got %d\n", ret);
2622 GetWindowRect(hwnd_grandchild, &rc2);
2623 ok(EqualRect(&rc1, &rc2), "%s != %s\n", wine_dbgstr_rect(&rc1), wine_dbgstr_rect(&rc2));
2624 check_active_state(hwnd2, hwnd2, hwnd2);
2626 /* Add SWP_NOZORDER and it will be properly resized. */
2627 GetWindowRect(hwnd_grandchild, &rc1);
2628 ret = SetWindowPos(hwnd_grandchild, hwnd_child2, 1, 2, 3, 4, SWP_NOZORDER);
2629 ok(ret, "Got %d\n", ret);
2630 GetWindowRect(hwnd_grandchild, &rc2);
2631 ok((rc1.left+1) == rc2.left && (rc1.top+2) == rc2.top &&
2632 (rc1.left+4) == rc2.right && (rc1.top+6) == rc2.bottom,
2633 "(%d,%d)-(%d,%d) != %s\n", rc1.left+1, rc1.top+2, rc1.left+4, rc1.top+6,
2634 wine_dbgstr_rect(&rc2));
2635 check_active_state(hwnd2, hwnd2, hwnd2);
2637 /* Given a sibling window, the window is properly resized. */
2638 GetWindowRect(hwnd_child, &rc1);
2639 ret = SetWindowPos(hwnd_child, hwnd_child2, 1, 2, 3, 4, 0);
2640 ok(ret, "Got %d\n", ret);
2641 GetWindowRect(hwnd_child, &rc2);
2642 ok((rc1.left+1) == rc2.left && (rc1.top+2) == rc2.top &&
2643 (rc1.left+4) == rc2.right && (rc1.top+6) == rc2.bottom,
2644 "(%d,%d)-(%d,%d) != %s\n", rc1.left+1, rc1.top+2, rc1.left+4, rc1.top+6,
2645 wine_dbgstr_rect(&rc2));
2646 check_active_state(hwnd2, hwnd2, hwnd2);
2648 /* Involving the desktop window changes things. */
2649 ret = SetWindowPos(hwnd_child, hwnd_desktop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2650 ok(!ret, "Got %d\n", ret);
2651 check_active_state(hwnd2, hwnd2, hwnd2);
2653 GetWindowRect(hwnd_child, &rc1);
2654 ret = SetWindowPos(hwnd_child, hwnd_desktop, 0, 0, 0, 0, 0);
2655 ok(!ret, "Got %d\n", ret);
2656 GetWindowRect(hwnd_child, &rc2);
2657 ok(EqualRect(&rc1, &rc2), "%s != %s\n", wine_dbgstr_rect(&rc1), wine_dbgstr_rect(&rc2));
2658 check_active_state(hwnd2, hwnd2, hwnd2);
2660 ret = SetWindowPos(hwnd_desktop, hwnd_child, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2661 ok(!ret, "Got %d\n", ret);
2662 check_active_state(hwnd2, hwnd2, hwnd2);
2664 ret = SetWindowPos(hwnd_desktop, hwnd, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2665 ok(!ret, "Got %d\n", ret);
2666 check_active_state(hwnd2, hwnd2, hwnd2);
2668 ret = SetWindowPos(hwnd, hwnd_desktop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2669 ok(!ret, "Got %d\n", ret);
2670 check_active_state(hwnd2, hwnd2, hwnd2);
2672 DestroyWindow(hwnd_grandchild);
2673 DestroyWindow(hwnd_child);
2674 DestroyWindow(hwnd_child2);
2676 hwnd_child = create_tool_window(WS_CHILD|WS_POPUP|WS_SYSMENU, hwnd2);
2677 ok(!!hwnd_child, "Failed to create child window (%d)\n", GetLastError());
2678 ret = SetWindowPos(hwnd_child, NULL, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2679 ok(ret, "Got %d\n", ret);
2680 flush_events( TRUE );
2681 todo_wine check_active_state(hwnd2, hwnd2, hwnd2);
2682 DestroyWindow(hwnd_child);
2685 static void test_SetMenu(HWND parent)
2687 HWND child;
2688 HMENU hMenu, ret;
2689 BOOL retok;
2690 DWORD style;
2692 hMenu = CreateMenu();
2693 assert(hMenu);
2695 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2696 if (0)
2698 /* fails on (at least) Wine, NT4, XP SP2 */
2699 test_nonclient_area(parent);
2701 ret = GetMenu(parent);
2702 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2703 /* test whether we can destroy a menu assigned to a window */
2704 retok = DestroyMenu(hMenu);
2705 ok( retok, "DestroyMenu error %d\n", GetLastError());
2706 retok = IsMenu(hMenu);
2707 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
2708 ret = GetMenu(parent);
2709 /* This test fails on Win9x */
2710 if (!is_win9x)
2711 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2712 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2713 test_nonclient_area(parent);
2715 hMenu = CreateMenu();
2716 assert(hMenu);
2718 /* parent */
2719 ret = GetMenu(parent);
2720 ok(ret == 0, "unexpected menu id %p\n", ret);
2722 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2723 test_nonclient_area(parent);
2724 ret = GetMenu(parent);
2725 ok(ret == 0, "unexpected menu id %p\n", ret);
2727 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2728 if (0)
2730 /* fails on (at least) Wine, NT4, XP SP2 */
2731 test_nonclient_area(parent);
2733 ret = GetMenu(parent);
2734 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2736 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2737 test_nonclient_area(parent);
2738 ret = GetMenu(parent);
2739 ok(ret == 0, "unexpected menu id %p\n", ret);
2741 /* child */
2742 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
2743 assert(child);
2745 ret = GetMenu(child);
2746 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2748 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2749 test_nonclient_area(child);
2750 ret = GetMenu(child);
2751 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2753 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
2754 test_nonclient_area(child);
2755 ret = GetMenu(child);
2756 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2758 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
2759 test_nonclient_area(child);
2760 ret = GetMenu(child);
2761 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2763 style = GetWindowLongA(child, GWL_STYLE);
2764 SetWindowLongA(child, GWL_STYLE, style | WS_POPUP);
2765 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
2766 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
2767 SetWindowLongA(child, GWL_STYLE, style);
2769 SetWindowLongA(child, GWL_STYLE, style | WS_OVERLAPPED);
2770 ok(!SetMenu(child, hMenu), "SetMenu on an overlapped child window should fail\n");
2771 SetWindowLongA(child, GWL_STYLE, style);
2773 DestroyWindow(child);
2774 DestroyMenu(hMenu);
2777 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
2779 HWND child[5], hwnd;
2780 INT_PTR i;
2782 assert(total <= 5);
2784 hwnd = GetWindow(parent, GW_CHILD);
2785 ok(!hwnd, "have to start without children to perform the test\n");
2787 for (i = 0; i < total; i++)
2789 if (style[i] & DS_CONTROL)
2791 child[i] = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
2792 0,0,0,0, parent, (HMENU)i, 0, NULL);
2793 if (style[i] & WS_VISIBLE)
2794 ShowWindow(child[i], SW_SHOW);
2796 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
2798 else
2799 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
2800 parent, (HMENU)i, 0, NULL);
2801 trace("child[%ld] = %p\n", i, child[i]);
2802 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
2805 hwnd = GetWindow(parent, GW_CHILD);
2806 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
2807 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
2808 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
2810 for (i = 0; i < total; i++)
2812 trace("hwnd[%ld] = %p\n", i, hwnd);
2813 ok(child[order[i]] == hwnd, "Z order of child #%ld is wrong\n", i);
2815 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
2818 for (i = 0; i < total; i++)
2819 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2822 static void test_children_zorder(HWND parent)
2824 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2825 WS_CHILD };
2826 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2828 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2829 WS_CHILD | WS_VISIBLE, WS_CHILD,
2830 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2831 const int complex_order_1[1] = { 0 };
2832 const int complex_order_2[2] = { 1, 0 };
2833 const int complex_order_3[3] = { 1, 0, 2 };
2834 const int complex_order_4[4] = { 1, 0, 2, 3 };
2835 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2836 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2837 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2838 WS_CHILD | WS_VISIBLE };
2839 const int complex_order_6[3] = { 0, 1, 2 };
2841 /* simple WS_CHILD */
2842 test_window_tree(parent, simple_style, simple_order, 5);
2844 /* complex children styles */
2845 test_window_tree(parent, complex_style, complex_order_1, 1);
2846 test_window_tree(parent, complex_style, complex_order_2, 2);
2847 test_window_tree(parent, complex_style, complex_order_3, 3);
2848 test_window_tree(parent, complex_style, complex_order_4, 4);
2849 test_window_tree(parent, complex_style, complex_order_5, 5);
2851 /* another set of complex children styles */
2852 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2855 #define check_z_order(hwnd, next, prev, owner, topmost) \
2856 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2857 __FILE__, __LINE__)
2859 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2860 BOOL topmost, const char *file, int line)
2862 HWND test;
2863 DWORD ex_style;
2865 test = GetWindow(hwnd, GW_HWNDNEXT);
2866 /* skip foreign windows */
2867 while (test && test != next &&
2868 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2869 UlongToHandle(GetWindowLongPtrA(test, GWLP_HINSTANCE)) != GetModuleHandleA(NULL) ||
2870 GetWindow(test, GW_OWNER) == next))
2872 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2873 test = GetWindow(test, GW_HWNDNEXT);
2875 ok_(file, line)(next == test, "%p: expected next %p, got %p\n", hwnd, next, test);
2877 test = GetWindow(hwnd, GW_HWNDPREV);
2878 /* skip foreign windows */
2879 while (test && test != prev &&
2880 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2881 UlongToHandle(GetWindowLongPtrA(test, GWLP_HINSTANCE)) != GetModuleHandleA(NULL) ||
2882 GetWindow(test, GW_OWNER) == hwnd))
2884 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2885 test = GetWindow(test, GW_HWNDPREV);
2887 ok_(file, line)(prev == test, "%p: expected prev %p, got %p\n", hwnd, prev, test);
2889 test = GetWindow(hwnd, GW_OWNER);
2890 ok_(file, line)(owner == test, "%p: expected owner %p, got %p\n", hwnd, owner, test);
2892 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
2893 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "%p: expected %stopmost\n",
2894 hwnd, topmost ? "" : "NOT ");
2897 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E, DWORD style)
2899 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2901 /* Give current thread foreground state otherwise the tests may fail. */
2902 if (!SetForegroundWindow(hwnd_D))
2904 skip("SetForegroundWindow not working\n");
2905 return;
2908 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2910 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2912 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2913 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2915 hwnd_F = CreateWindowExA(0, "MainWindowClass", "Owner window",
2916 WS_OVERLAPPED | WS_CAPTION,
2917 100, 100, 100, 100,
2918 0, 0, GetModuleHandleA(NULL), NULL);
2919 trace("hwnd_F %p\n", hwnd_F);
2920 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2922 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2923 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2924 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2925 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2927 hwnd_C = CreateWindowExA(0, "MainWindowClass", NULL,
2928 style,
2929 100, 100, 100, 100,
2930 hwnd_F, 0, GetModuleHandleA(NULL), NULL);
2931 trace("hwnd_C %p\n", hwnd_C);
2932 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2933 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2934 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2935 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2937 hwnd_B = CreateWindowExA(WS_EX_TOPMOST, "MainWindowClass", NULL,
2938 style,
2939 100, 100, 100, 100,
2940 hwnd_F, 0, GetModuleHandleA(NULL), NULL);
2941 trace("hwnd_B %p\n", hwnd_B);
2942 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2943 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2944 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2945 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2946 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2948 hwnd_A = CreateWindowExA(WS_EX_TOPMOST, "MainWindowClass", NULL,
2949 style,
2950 100, 100, 100, 100,
2951 0, 0, GetModuleHandleA(NULL), NULL);
2952 trace("hwnd_A %p\n", hwnd_A);
2953 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2954 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2955 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2956 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2957 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2958 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2960 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);
2962 /* move hwnd_F and its popups up */
2963 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2964 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2965 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2966 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2967 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2968 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2969 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2971 /* move hwnd_F and its popups down */
2972 #if 0 /* enable once Wine is fixed to pass this test */
2973 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2974 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2975 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2976 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2977 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2978 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2979 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2980 #endif
2982 /* make hwnd_C owned by a topmost window */
2983 DestroyWindow( hwnd_C );
2984 hwnd_C = CreateWindowExA(0, "MainWindowClass", NULL,
2985 style,
2986 100, 100, 100, 100,
2987 hwnd_A, 0, GetModuleHandleA(NULL), NULL);
2988 trace("hwnd_C %p\n", hwnd_C);
2989 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2990 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2991 check_z_order(hwnd_F, hwnd_D, hwnd_B, 0, FALSE);
2992 check_z_order(hwnd_B, hwnd_F, hwnd_A, hwnd_F, TRUE);
2993 check_z_order(hwnd_A, hwnd_B, hwnd_C, 0, TRUE);
2994 check_z_order(hwnd_C, hwnd_A, 0, hwnd_A, TRUE);
2996 DestroyWindow(hwnd_A);
2997 DestroyWindow(hwnd_B);
2998 DestroyWindow(hwnd_C);
2999 DestroyWindow(hwnd_F);
3002 static void test_vis_rgn( HWND hwnd )
3004 RECT win_rect, rgn_rect;
3005 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3006 HDC hdc;
3008 ShowWindow(hwnd,SW_SHOW);
3009 hdc = GetDC( hwnd );
3010 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
3011 GetWindowRect( hwnd, &win_rect );
3012 GetRgnBox( hrgn, &rgn_rect );
3013 if (is_win9x)
3015 trace("win9x, mapping to screen coords\n");
3016 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
3018 trace("win: %s\n", wine_dbgstr_rect(&win_rect));
3019 trace("rgn: %s\n", wine_dbgstr_rect(&rgn_rect));
3020 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
3021 rgn_rect.left, win_rect.left );
3022 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
3023 rgn_rect.top, win_rect.top );
3024 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
3025 rgn_rect.right, win_rect.right );
3026 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
3027 rgn_rect.bottom, win_rect.bottom );
3028 ReleaseDC( hwnd, hdc );
3031 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
3033 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
3035 HWND child = GetWindow(hwnd, GW_CHILD);
3036 ok(child != 0, "couldn't find child window\n");
3037 SetFocus(child);
3038 ok(GetFocus() == child, "Focus should be on child %p\n", child);
3039 return 0;
3041 return DefWindowProcA(hwnd, msg, wp, lp);
3044 static void test_SetFocus(HWND hwnd)
3046 HWND child, child2, ret;
3047 WNDPROC old_wnd_proc;
3049 /* check if we can set focus to non-visible windows */
3051 ShowWindow(hwnd, SW_SHOW);
3052 SetFocus(0);
3053 SetFocus(hwnd);
3054 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
3055 ok( GetWindowLongA(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
3056 ShowWindow(hwnd, SW_HIDE);
3057 SetFocus(0);
3058 SetFocus(hwnd);
3059 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
3060 ok( !(GetWindowLongA(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
3061 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
3062 assert(child);
3063 SetFocus(child);
3064 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
3065 ok( !(GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
3066 ShowWindow(child, SW_SHOW);
3067 ok( GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
3068 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
3069 ShowWindow(child, SW_HIDE);
3070 ok( !(GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
3071 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
3072 ShowWindow(child, SW_SHOW);
3073 child2 = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, child, 0, 0, NULL);
3074 assert(child2);
3075 ShowWindow(child2, SW_SHOW);
3076 SetFocus(child2);
3077 ShowWindow(child, SW_HIDE);
3078 ok( !(GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
3079 ok( GetFocus() == child2, "Focus should be on %p, not %p\n", child2, GetFocus() );
3080 ShowWindow(child, SW_SHOW);
3081 SetFocus(child);
3082 ok( GetFocus() == child, "Focus should be on child %p\n", child );
3083 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
3084 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
3086 ShowWindow(child, SW_HIDE);
3087 SetFocus(hwnd);
3088 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
3089 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
3090 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
3091 ShowWindow(child, SW_HIDE);
3092 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
3094 ShowWindow(hwnd, SW_SHOW);
3095 ShowWindow(child, SW_SHOW);
3096 SetFocus(child);
3097 ok( GetFocus() == child, "Focus should be on child %p\n", child );
3098 SetLastError(0xdeadbeef);
3099 EnableWindow(hwnd, FALSE);
3100 ok(GetLastError() == 0xdeadbeef, "got error %u in EnableWindow call\n", GetLastError());
3101 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
3102 EnableWindow(hwnd, TRUE);
3104 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
3105 ShowWindow(hwnd, SW_SHOWMINIMIZED);
3106 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
3107 todo_wine
3108 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
3109 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
3110 ShowWindow(hwnd, SW_RESTORE);
3111 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
3112 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
3113 ShowWindow(hwnd, SW_SHOWMINIMIZED);
3114 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
3115 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
3116 todo_wine
3117 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
3118 old_wnd_proc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
3119 ShowWindow(hwnd, SW_RESTORE);
3120 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
3121 todo_wine
3122 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
3123 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
3125 SetFocus( hwnd );
3126 SetParent( child, GetDesktopWindow());
3127 SetParent( child2, child );
3128 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
3129 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
3130 ret = SetFocus( child2 );
3131 ok( ret == 0, "SetFocus %p should fail\n", child2);
3132 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
3133 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
3134 ret = SetFocus( child );
3135 ok( ret == 0, "SetFocus %p should fail\n", child);
3136 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
3137 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
3138 SetWindowLongW( child, GWL_STYLE, WS_POPUP|WS_CHILD );
3139 SetFocus( child2 );
3140 ok( GetActiveWindow() == child, "child window %p should be active\n", child);
3141 ok( GetFocus() == child2, "Focus should be on child2 %p\n", child2 );
3142 SetFocus( hwnd );
3143 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
3144 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
3145 SetFocus( child );
3146 ok( GetActiveWindow() == child, "child window %p should be active\n", child);
3147 ok( GetFocus() == child, "Focus should be on child %p\n", child );
3149 DestroyWindow( child2 );
3150 DestroyWindow( child );
3153 static void test_SetActiveWindow(HWND hwnd)
3155 HWND hwnd2, ret;
3157 flush_events( TRUE );
3158 ShowWindow(hwnd, SW_HIDE);
3159 SetFocus(0);
3160 SetActiveWindow(0);
3161 check_wnd_state(0, 0, 0, 0);
3163 /*trace("testing SetActiveWindow %p\n", hwnd);*/
3165 ShowWindow(hwnd, SW_SHOW);
3166 check_wnd_state(hwnd, hwnd, hwnd, 0);
3168 ret = SetActiveWindow(0);
3169 ok(ret == hwnd, "SetActiveWindow returned %p instead of %p\n", ret, hwnd);
3170 if (!GetActiveWindow()) /* doesn't always work on vista */
3172 check_wnd_state(0, 0, 0, 0);
3173 ret = SetActiveWindow(hwnd);
3174 ok(ret == 0, "SetActiveWindow returned %p instead of 0\n", ret);
3176 check_wnd_state(hwnd, hwnd, hwnd, 0);
3178 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
3179 check_wnd_state(hwnd, hwnd, hwnd, 0);
3181 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
3182 check_wnd_state(hwnd, hwnd, hwnd, 0);
3184 ShowWindow(hwnd, SW_HIDE);
3185 check_wnd_state(0, 0, 0, 0);
3187 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
3188 SetActiveWindow(hwnd);
3189 check_wnd_state(hwnd, hwnd, hwnd, 0);
3191 ShowWindow(hwnd, SW_SHOW);
3192 check_wnd_state(hwnd, hwnd, hwnd, 0);
3194 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
3195 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
3197 SetActiveWindow(hwnd);
3198 check_wnd_state(hwnd, hwnd, hwnd, 0);
3200 DestroyWindow(hwnd2);
3201 check_wnd_state(hwnd, hwnd, hwnd, 0);
3203 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
3204 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
3206 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
3207 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
3209 DestroyWindow(hwnd2);
3210 check_wnd_state(hwnd, hwnd, hwnd, 0);
3212 /* try to activate the desktop */
3213 SetLastError(0xdeadbeef);
3214 ret = SetActiveWindow(GetDesktopWindow());
3215 ok(ret == NULL, "expected NULL, got %p\n", ret);
3216 todo_wine
3217 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %u\n", GetLastError());
3218 check_wnd_state(hwnd, hwnd, hwnd, 0);
3220 /* activating a child should activate the parent */
3221 hwnd2 = CreateWindowExA(0, "MainWindowClass", "Child window", WS_CHILD, 0, 0, 0, 0, hwnd, 0, GetModuleHandleA(NULL), NULL);
3222 check_wnd_state(hwnd, hwnd, hwnd, 0);
3223 ret = SetActiveWindow(hwnd2);
3224 ok(ret == hwnd, "expected %p, got %p\n", hwnd, ret);
3225 check_wnd_state(hwnd, hwnd, hwnd, 0);
3226 ret = SetActiveWindow(0);
3227 ok(ret == hwnd, "expected %p, got %p\n", hwnd, ret);
3228 if (!GetActiveWindow())
3230 ret = SetActiveWindow(hwnd2);
3231 ok(ret == NULL, "expected NULL, got %p\n", ret);
3232 todo_wine
3233 check_active_state(hwnd, hwnd, hwnd);
3235 DestroyWindow(hwnd2);
3238 struct create_window_thread_params
3240 HWND window;
3241 HANDLE window_created;
3242 HANDLE test_finished;
3245 static DWORD WINAPI create_window_thread(void *param)
3247 struct create_window_thread_params *p = param;
3248 DWORD res;
3249 BOOL ret;
3251 p->window = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
3253 ret = SetEvent(p->window_created);
3254 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
3256 res = WaitForSingleObject(p->test_finished, INFINITE);
3257 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
3259 DestroyWindow(p->window);
3260 return 0;
3263 static void test_SetForegroundWindow(HWND hwnd)
3265 struct create_window_thread_params thread_params;
3266 HANDLE thread;
3267 DWORD res, tid;
3268 BOOL ret;
3269 HWND hwnd2;
3270 MSG msg;
3271 LONG style;
3273 flush_events( TRUE );
3274 ShowWindow(hwnd, SW_HIDE);
3275 SetFocus(0);
3276 SetActiveWindow(0);
3277 check_wnd_state(0, 0, 0, 0);
3279 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
3281 ShowWindow(hwnd, SW_SHOW);
3282 check_wnd_state(hwnd, hwnd, hwnd, 0);
3284 hwnd2 = SetActiveWindow(0);
3285 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
3286 if (GetActiveWindow() == hwnd) /* doesn't always work on vista */
3287 check_wnd_state(hwnd, hwnd, hwnd, 0);
3288 else
3289 check_wnd_state(0, 0, 0, 0);
3291 ret = SetForegroundWindow(hwnd);
3292 if (!ret)
3294 skip( "SetForegroundWindow not working\n" );
3295 return;
3297 check_wnd_state(hwnd, hwnd, hwnd, 0);
3299 SetLastError(0xdeadbeef);
3300 ret = SetForegroundWindow(0);
3301 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
3302 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
3303 broken(GetLastError() == 0xdeadbeef), /* win9x */
3304 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
3305 check_wnd_state(hwnd, hwnd, hwnd, 0);
3307 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
3308 check_wnd_state(hwnd, hwnd, hwnd, 0);
3310 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
3311 check_wnd_state(hwnd, hwnd, hwnd, 0);
3313 hwnd2 = GetForegroundWindow();
3314 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
3315 ret = SetForegroundWindow( GetDesktopWindow() );
3316 ok(ret, "SetForegroundWindow(desktop) error: %d\n", GetLastError());
3317 hwnd2 = GetForegroundWindow();
3318 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
3320 ShowWindow(hwnd, SW_HIDE);
3321 check_wnd_state(0, 0, 0, 0);
3323 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
3324 ret = SetForegroundWindow(hwnd);
3325 ok(ret || broken(!ret), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
3326 check_wnd_state(hwnd, hwnd, hwnd, 0);
3328 ShowWindow(hwnd, SW_SHOW);
3329 check_wnd_state(hwnd, hwnd, hwnd, 0);
3331 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
3332 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
3334 DestroyWindow(hwnd2);
3335 check_wnd_state(hwnd, hwnd, hwnd, 0);
3337 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
3338 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
3340 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
3341 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
3343 DestroyWindow(hwnd2);
3344 check_wnd_state(hwnd, hwnd, hwnd, 0);
3346 hwnd2 = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
3347 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
3349 thread_params.window_created = CreateEventW(NULL, FALSE, FALSE, NULL);
3350 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
3351 thread_params.test_finished = CreateEventW(NULL, FALSE, FALSE, NULL);
3352 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
3353 thread = CreateThread(NULL, 0, create_window_thread, &thread_params, 0, &tid);
3354 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
3355 res = WaitForSingleObject(thread_params.window_created, INFINITE);
3356 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
3357 check_wnd_state(hwnd2, thread_params.window, hwnd2, 0);
3359 SetForegroundWindow(hwnd2);
3360 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
3362 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3363 if (0) check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
3364 todo_wine ok(GetActiveWindow() == hwnd2, "Expected active window %p, got %p.\n", hwnd2, GetActiveWindow());
3365 todo_wine ok(GetFocus() == hwnd2, "Expected focus window %p, got %p.\n", hwnd2, GetFocus());
3367 SetForegroundWindow(hwnd);
3368 check_wnd_state(hwnd, hwnd, hwnd, 0);
3369 style = GetWindowLongA(hwnd2, GWL_STYLE) | WS_CHILD;
3370 ok(SetWindowLongA(hwnd2, GWL_STYLE, style), "SetWindowLong failed\n");
3371 ok(SetForegroundWindow(hwnd2), "SetForegroundWindow failed\n");
3372 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
3374 SetForegroundWindow(hwnd);
3375 check_wnd_state(hwnd, hwnd, hwnd, 0);
3376 ok(SetWindowLongA(hwnd2, GWL_STYLE, style & (~WS_POPUP)), "SetWindowLong failed\n");
3377 ok(!SetForegroundWindow(hwnd2), "SetForegroundWindow failed\n");
3378 check_wnd_state(hwnd, hwnd, hwnd, 0);
3380 SetEvent(thread_params.test_finished);
3381 WaitForSingleObject(thread, INFINITE);
3382 CloseHandle(thread_params.test_finished);
3383 CloseHandle(thread_params.window_created);
3384 CloseHandle(thread);
3385 DestroyWindow(hwnd2);
3388 static WNDPROC old_button_proc;
3390 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
3392 LRESULT ret;
3393 USHORT key_state;
3395 key_state = GetKeyState(VK_LBUTTON);
3396 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
3398 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
3400 if (msg == WM_LBUTTONDOWN)
3402 HWND hwnd, capture;
3404 check_wnd_state(button, button, button, button);
3406 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
3407 assert(hwnd);
3408 trace("hwnd %p\n", hwnd);
3410 check_wnd_state(button, button, button, button);
3412 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
3414 check_wnd_state(button, button, button, button);
3416 DestroyWindow(hwnd);
3418 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
3419 assert(hwnd);
3420 trace("hwnd %p\n", hwnd);
3422 check_wnd_state(button, button, button, button);
3424 /* button wnd proc should release capture on WM_KILLFOCUS if it does
3425 * match internal button state.
3427 SendMessageA(button, WM_KILLFOCUS, 0, 0);
3428 check_wnd_state(button, button, button, 0);
3430 ShowWindow(hwnd, SW_SHOW);
3431 check_wnd_state(hwnd, hwnd, hwnd, 0);
3433 capture = SetCapture(hwnd);
3434 ok(capture == 0, "SetCapture() = %p\n", capture);
3436 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
3438 DestroyWindow(hwnd);
3440 check_wnd_state(button, 0, button, 0);
3443 return ret;
3446 static void test_capture_1(void)
3448 HWND button, capture;
3450 capture = GetCapture();
3451 ok(capture == 0, "GetCapture() = %p\n", capture);
3453 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
3454 assert(button);
3455 trace("button %p\n", button);
3457 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
3459 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
3461 capture = SetCapture(button);
3462 ok(capture == 0, "SetCapture() = %p\n", capture);
3463 check_wnd_state(button, 0, button, button);
3465 DestroyWindow(button);
3466 /* old active window test depends on previously executed window
3467 * activation tests, and fails under NT4.
3468 check_wnd_state(oldActive, 0, oldFocus, 0);*/
3471 static void test_capture_2(void)
3473 HWND button, hwnd, capture, oldFocus, oldActive;
3475 oldFocus = GetFocus();
3476 oldActive = GetActiveWindow();
3477 check_wnd_state(oldActive, 0, oldFocus, 0);
3479 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
3480 assert(button);
3481 trace("button %p\n", button);
3483 check_wnd_state(button, button, button, 0);
3485 capture = SetCapture(button);
3486 ok(capture == 0, "SetCapture() = %p\n", capture);
3488 check_wnd_state(button, button, button, button);
3490 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
3491 * internal button state.
3493 SendMessageA(button, WM_KILLFOCUS, 0, 0);
3494 check_wnd_state(button, button, button, button);
3496 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
3497 assert(hwnd);
3498 trace("hwnd %p\n", hwnd);
3500 check_wnd_state(button, button, button, button);
3502 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
3504 check_wnd_state(button, button, button, button);
3506 DestroyWindow(hwnd);
3508 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
3509 assert(hwnd);
3510 trace("hwnd %p\n", hwnd);
3512 check_wnd_state(button, button, button, button);
3514 ShowWindow(hwnd, SW_SHOW);
3516 check_wnd_state(hwnd, hwnd, hwnd, button);
3518 capture = SetCapture(hwnd);
3519 ok(capture == button, "SetCapture() = %p\n", capture);
3521 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
3523 DestroyWindow(hwnd);
3524 check_wnd_state(button, button, button, 0);
3526 DestroyWindow(button);
3527 check_wnd_state(oldActive, 0, oldFocus, 0);
3530 static void test_capture_3(HWND hwnd1, HWND hwnd2)
3532 BOOL ret;
3534 ShowWindow(hwnd1, SW_HIDE);
3535 ShowWindow(hwnd2, SW_HIDE);
3537 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
3538 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
3540 SetCapture(hwnd1);
3541 check_wnd_state(0, 0, 0, hwnd1);
3543 SetCapture(hwnd2);
3544 check_wnd_state(0, 0, 0, hwnd2);
3546 ShowWindow(hwnd1, SW_SHOW);
3547 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
3549 ret = ReleaseCapture();
3550 ok (ret, "releasecapture did not return TRUE.\n");
3551 ret = ReleaseCapture();
3552 ok (ret, "releasecapture did not return TRUE after second try.\n");
3555 static LRESULT CALLBACK test_capture_4_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3557 GUITHREADINFO gti;
3558 HWND cap_wnd, cap_wnd2, set_cap_wnd;
3559 BOOL status;
3560 switch (msg)
3562 case WM_CAPTURECHANGED:
3564 /* now try to release capture from menu. this should fail */
3565 if (pGetGUIThreadInfo)
3567 memset(&gti, 0, sizeof(GUITHREADINFO));
3568 gti.cbSize = sizeof(GUITHREADINFO);
3569 status = pGetGUIThreadInfo(GetCurrentThreadId(), &gti);
3570 ok(status, "GetGUIThreadInfo() failed!\n");
3571 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
3573 cap_wnd = GetCapture();
3575 ok(cap_wnd == (HWND)lParam, "capture window %p does not match lparam %lx\n", cap_wnd, lParam);
3576 todo_wine ok(cap_wnd == hWnd, "capture window %p does not match hwnd %p\n", cap_wnd, hWnd);
3578 /* check that re-setting the capture for the menu fails */
3579 set_cap_wnd = SetCapture(cap_wnd);
3580 ok(!set_cap_wnd || broken(set_cap_wnd == cap_wnd), /* nt4 */
3581 "SetCapture should have failed!\n");
3582 if (set_cap_wnd)
3584 DestroyWindow(hWnd);
3585 break;
3588 /* check that SetCapture fails for another window and that it does not touch the error code */
3589 set_cap_wnd = SetCapture(hWnd);
3590 ok(!set_cap_wnd, "SetCapture should have failed!\n");
3592 /* check that ReleaseCapture fails and does not touch the error code */
3593 status = ReleaseCapture();
3594 ok(!status, "ReleaseCapture should have failed!\n");
3596 /* check that thread info did not change */
3597 if (pGetGUIThreadInfo)
3599 memset(&gti, 0, sizeof(GUITHREADINFO));
3600 gti.cbSize = sizeof(GUITHREADINFO);
3601 status = pGetGUIThreadInfo(GetCurrentThreadId(), &gti);
3602 ok(status, "GetGUIThreadInfo() failed!\n");
3603 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
3606 /* verify that no capture change took place */
3607 cap_wnd2 = GetCapture();
3608 ok(cap_wnd2 == cap_wnd, "Capture changed!\n");
3610 /* we are done. kill the window */
3611 DestroyWindow(hWnd);
3612 break;
3614 default:
3615 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
3617 return 0;
3620 /* Test that no-one can mess around with the current capture while a menu is open */
3621 static void test_capture_4(void)
3623 BOOL ret;
3624 HMENU hmenu;
3625 HWND hwnd;
3626 WNDCLASSA wclass;
3627 HINSTANCE hInstance = GetModuleHandleA( NULL );
3628 ATOM aclass;
3630 if (!pGetGUIThreadInfo)
3632 win_skip("GetGUIThreadInfo is not available\n");
3633 return;
3635 wclass.lpszClassName = "TestCapture4Class";
3636 wclass.style = CS_HREDRAW | CS_VREDRAW;
3637 wclass.lpfnWndProc = test_capture_4_proc;
3638 wclass.hInstance = hInstance;
3639 wclass.hIcon = LoadIconA( 0, (LPCSTR)IDI_APPLICATION );
3640 wclass.hCursor = LoadCursorA( 0, (LPCSTR)IDC_ARROW );
3641 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
3642 wclass.lpszMenuName = 0;
3643 wclass.cbClsExtra = 0;
3644 wclass.cbWndExtra = 0;
3645 aclass = RegisterClassA( &wclass );
3646 ok( aclass, "RegisterClassA failed with error %d\n", GetLastError());
3647 hwnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
3648 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
3649 400, 200, NULL, NULL, hInstance, NULL);
3650 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
3651 if (!hwnd) return;
3652 hmenu = CreatePopupMenu();
3654 ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest2");
3655 ok( ret, "AppendMenuA has failed!\n");
3657 /* set main window to have initial capture */
3658 SetCapture(hwnd);
3660 if (is_win9x)
3662 win_skip("TrackPopupMenu test crashes on Win9x/WinMe\n");
3664 else
3666 /* create popup (it will self-destruct) */
3667 ret = TrackPopupMenu(hmenu, TPM_RETURNCMD, 100, 100, 0, hwnd, NULL);
3668 ok( ret == 0, "TrackPopupMenu returned %d expected zero\n", ret);
3671 /* clean up */
3672 DestroyMenu(hmenu);
3673 DestroyWindow(hwnd);
3676 /* PeekMessage wrapper that ignores the messages we don't care about */
3677 static BOOL peek_message( MSG *msg )
3679 BOOL ret;
3682 ret = PeekMessageA(msg, 0, 0, 0, PM_REMOVE);
3683 } while (ret && ignore_message(msg->message));
3684 return ret;
3687 static void test_keyboard_input(HWND hwnd)
3689 MSG msg;
3690 BOOL ret;
3692 flush_events( TRUE );
3693 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
3694 UpdateWindow(hwnd);
3695 flush_events( TRUE );
3697 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
3699 SetFocus(hwnd);
3700 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
3702 flush_events( TRUE );
3704 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
3705 ret = peek_message(&msg);
3706 ok( ret, "no message available\n");
3707 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3708 ret = peek_message(&msg);
3709 ok( !ret, "message %04x available\n", msg.message);
3711 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
3713 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
3714 ret = peek_message(&msg);
3715 ok(ret, "no message available\n");
3716 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3717 ret = peek_message(&msg);
3718 ok( !ret, "message %04x available\n", msg.message);
3720 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
3722 keybd_event(VK_SPACE, 0, 0, 0);
3723 if (!peek_message(&msg))
3725 skip( "keybd_event didn't work, skipping keyboard test\n" );
3726 return;
3728 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3729 ret = peek_message(&msg);
3730 ok( !ret, "message %04x available\n", msg.message);
3732 SetFocus(0);
3733 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3735 flush_events( TRUE );
3737 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
3738 ret = peek_message(&msg);
3739 ok(ret, "no message available\n");
3740 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3741 ret = peek_message(&msg);
3742 ok( !ret, "message %04x available\n", msg.message);
3744 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3746 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
3747 ret = peek_message(&msg);
3748 ok(ret, "no message available\n");
3749 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3750 ret = peek_message(&msg);
3751 ok( !ret, "message %04x available\n", msg.message);
3753 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3755 keybd_event(VK_SPACE, 0, 0, 0);
3756 ret = peek_message(&msg);
3757 ok(ret, "no message available\n");
3758 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3759 ret = peek_message(&msg);
3760 ok( !ret, "message %04x available\n", msg.message);
3763 static BOOL wait_for_message( MSG *msg )
3765 BOOL ret;
3767 for (;;)
3769 ret = peek_message(msg);
3770 if (ret)
3772 if (msg->message == WM_PAINT) DispatchMessageA(msg);
3773 else break;
3775 else if (MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
3777 if (!ret) msg->message = 0;
3778 return ret;
3781 static void test_mouse_input(HWND hwnd)
3783 RECT rc;
3784 POINT pt;
3785 int x, y;
3786 HWND popup, child = NULL;
3787 MSG msg;
3788 BOOL ret;
3789 LRESULT res;
3791 ShowWindow(hwnd, SW_SHOWNORMAL);
3792 UpdateWindow(hwnd);
3793 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3795 GetWindowRect(hwnd, &rc);
3796 trace("main window %p: %s\n", hwnd, wine_dbgstr_rect(&rc));
3798 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
3799 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
3800 hwnd, 0, 0, NULL);
3801 assert(popup != 0);
3802 ShowWindow(popup, SW_SHOW);
3803 UpdateWindow(popup);
3804 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3806 GetWindowRect(popup, &rc);
3807 trace("popup window %p: %s\n", popup, wine_dbgstr_rect(&rc));
3809 x = rc.left + (rc.right - rc.left) / 2;
3810 y = rc.top + (rc.bottom - rc.top) / 2;
3811 trace("setting cursor to (%d,%d)\n", x, y);
3813 SetCursorPos(x, y);
3814 GetCursorPos(&pt);
3815 if (x != pt.x || y != pt.y)
3817 skip( "failed to set mouse position, skipping mouse input tests\n" );
3818 goto done;
3821 flush_events( TRUE );
3823 /* Check that setting the same position may generate WM_MOUSEMOVE */
3824 SetCursorPos(x, y);
3825 msg.message = 0;
3826 ret = peek_message(&msg);
3827 if (ret)
3829 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
3830 msg.hwnd, msg.message);
3831 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
3832 x, y, msg.pt.x, msg.pt.y);
3835 /* force the system to update its internal queue mouse position,
3836 * otherwise it won't generate relative mouse movements below.
3838 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3839 flush_events( TRUE );
3841 msg.message = 0;
3842 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3843 flush_events( FALSE );
3844 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
3845 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
3847 if (ignore_message(msg.message)) continue;
3848 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
3849 "hwnd %p message %04x\n", msg.hwnd, msg.message);
3850 DispatchMessageA(&msg);
3852 ret = peek_message(&msg);
3853 ok( !ret, "message %04x available\n", msg.message);
3855 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3856 ShowWindow(popup, SW_HIDE);
3857 ret = wait_for_message( &msg );
3858 if (ret)
3859 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3860 flush_events( TRUE );
3862 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3863 ShowWindow(hwnd, SW_HIDE);
3864 ret = wait_for_message( &msg );
3865 ok( !ret, "message %04x available\n", msg.message);
3866 flush_events( TRUE );
3868 /* test mouse clicks */
3870 ShowWindow(hwnd, SW_SHOW);
3871 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3872 flush_events( TRUE );
3873 ShowWindow(popup, SW_SHOW);
3874 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3875 flush_events( TRUE );
3877 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3878 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3879 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3880 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3882 ret = wait_for_message( &msg );
3883 if (!ret)
3885 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
3886 goto done;
3888 if (msg.message == WM_MOUSEMOVE) /* win2k has an extra WM_MOUSEMOVE here */
3890 ret = wait_for_message( &msg );
3891 ok(ret, "no message available\n");
3894 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3895 msg.hwnd, popup, msg.message);
3897 ret = wait_for_message( &msg );
3898 ok(ret, "no message available\n");
3899 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3900 msg.hwnd, popup, msg.message);
3902 ret = wait_for_message( &msg );
3903 ok(ret, "no message available\n");
3904 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
3905 msg.hwnd, popup, msg.message);
3907 ret = wait_for_message( &msg );
3908 ok(ret, "no message available\n");
3909 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3910 msg.hwnd, popup, msg.message);
3912 ret = peek_message(&msg);
3913 ok(!ret, "message %04x available\n", msg.message);
3915 ShowWindow(popup, SW_HIDE);
3916 flush_events( TRUE );
3918 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3919 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3920 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3921 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3923 ret = wait_for_message( &msg );
3924 ok(ret, "no message available\n");
3925 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3926 msg.hwnd, hwnd, msg.message);
3927 ret = wait_for_message( &msg );
3928 ok(ret, "no message available\n");
3929 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3930 msg.hwnd, hwnd, msg.message);
3932 test_lbuttondown_flag = TRUE;
3933 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
3934 test_lbuttondown_flag = FALSE;
3936 ret = wait_for_message( &msg );
3937 ok(ret, "no message available\n");
3938 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3939 msg.hwnd, popup, msg.message);
3940 ok(peek_message(&msg), "no message available\n");
3941 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3942 msg.hwnd, popup, msg.message);
3943 ok(peek_message(&msg), "no message available\n");
3945 /* Test WM_MOUSEACTIVATE */
3946 #define TEST_MOUSEACTIVATE(A,B) \
3947 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
3948 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
3950 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
3951 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
3952 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
3953 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
3954 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
3955 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
3956 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
3957 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
3958 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
3959 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
3960 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
3961 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
3962 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
3963 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
3964 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
3965 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
3966 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
3967 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
3968 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
3969 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
3970 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
3971 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
3972 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
3973 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
3975 ShowWindow(popup, SW_HIDE);
3977 /* Test sending double click to the non-client area, while capturing the window after
3978 the first click has been processed. Use a child window to ensure that Wine's graphics
3979 driver isn't managing the non-client area. */
3981 GetWindowRect(hwnd, &rc);
3982 child = CreateWindowExA(0, "MainWindowClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_VISIBLE,
3983 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
3984 hwnd, 0, 0, NULL);
3985 GetWindowRect(child, &rc);
3987 UpdateWindow(child);
3988 SetCursorPos( rc.left + 5, rc.top + 5 );
3989 flush_events( TRUE );
3991 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3992 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3993 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3994 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3996 ret = wait_for_message( &msg );
3997 ok(ret, "no message available\n");
3998 todo_wine
3999 ok(msg.hwnd == child && msg.message == WM_NCMOUSEMOVE, "hwnd %p/%p message %04x\n",
4000 msg.hwnd, child, msg.message);
4002 if (msg.message == WM_NCMOUSEMOVE)
4003 ret = wait_for_message( &msg );
4004 ok(ret, "no message available\n");
4005 ok(msg.hwnd == child && msg.message == WM_NCLBUTTONDOWN, "hwnd %p/%p message %04x\n",
4006 msg.hwnd, child, msg.message);
4007 ok(msg.wParam == HTSYSMENU, "wparam %ld\n", msg.wParam);
4009 ret = wait_for_message( &msg );
4010 ok(ret, "no message available\n");
4011 ok(msg.hwnd == child && msg.message == WM_NCLBUTTONUP, "hwnd %p/%p message %04x\n",
4012 msg.hwnd, child, msg.message);
4014 SetCapture( child );
4016 ret = wait_for_message( &msg );
4017 ok(ret, "no message available\n");
4018 ok(msg.hwnd == child && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
4019 msg.hwnd, child, msg.message);
4020 ok(msg.wParam == MK_LBUTTON, "wparam %ld\n", msg.wParam);
4022 ret = wait_for_message( &msg );
4023 ok(ret, "no message available\n");
4024 todo_wine
4025 ok(msg.hwnd == child && (msg.message == WM_NCMOUSELEAVE || broken(msg.message == WM_LBUTTONUP)),
4026 "hwnd %p/%p message %04x\n", msg.hwnd, child, msg.message);
4028 if (msg.message == WM_NCMOUSELEAVE)
4029 ret = wait_for_message( &msg );
4030 ok(ret, "no message available\n");
4031 ok(msg.hwnd == child && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
4032 msg.hwnd, child, msg.message);
4034 ret = peek_message(&msg);
4035 ok(!ret, "message %04x available\n", msg.message);
4037 done:
4038 flush_events( TRUE );
4040 if (child) DestroyWindow(child);
4041 DestroyWindow(popup);
4043 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
4046 static void test_validatergn(HWND hwnd)
4048 HWND child;
4049 RECT rc, rc2;
4050 HRGN rgn;
4051 int ret;
4052 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
4053 ShowWindow(hwnd, SW_SHOW);
4054 UpdateWindow( hwnd);
4055 /* test that ValidateRect validates children*/
4056 InvalidateRect( child, NULL, 1);
4057 GetWindowRect( child, &rc);
4058 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
4059 ret = GetUpdateRect( child, &rc2, 0);
4060 ok( ret == 1, "Expected GetUpdateRect to return non-zero, got %d\n", ret);
4061 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
4062 "Update rectangle is empty!\n");
4063 ValidateRect( hwnd, &rc);
4064 ret = GetUpdateRect( child, &rc2, 0);
4065 ok( !ret, "Expected GetUpdateRect to return zero, got %d\n", ret);
4066 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
4067 "Update rectangle %s is not empty!\n", wine_dbgstr_rect(&rc2));
4069 /* now test ValidateRgn */
4070 InvalidateRect( child, NULL, 1);
4071 GetWindowRect( child, &rc);
4072 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
4073 rgn = CreateRectRgnIndirect( &rc);
4074 ValidateRgn( hwnd, rgn);
4075 ret = GetUpdateRect( child, &rc2, 0);
4076 ok( !ret, "Expected GetUpdateRect to return zero, got %d\n", ret);
4077 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
4078 "Update rectangle %s is not empty!\n", wine_dbgstr_rect(&rc2));
4080 DeleteObject( rgn);
4081 DestroyWindow( child );
4084 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
4086 RECT rc;
4087 MoveWindow( hwnd, 0, 0, x, y, 0);
4088 GetWindowRect( hwnd, prc);
4089 rc = *prc;
4090 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
4091 trace("window rect is %s, nccalc rect is %s\n", wine_dbgstr_rect(&rc), wine_dbgstr_rect(prc));
4094 static void test_nccalcscroll(HWND parent)
4096 RECT rc1;
4097 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
4098 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
4099 HWND hwnd = CreateWindowExA(0, "static", NULL,
4100 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
4101 10, 10, 200, 200, parent, 0, 0, NULL);
4102 ShowWindow( parent, SW_SHOW);
4103 UpdateWindow( parent);
4105 /* test window too low for a horizontal scroll bar */
4106 nccalchelper( hwnd, 100, sbheight, &rc1);
4107 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %s\n", sbheight,
4108 wine_dbgstr_rect(&rc1));
4110 /* test window just high enough for a horizontal scroll bar */
4111 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
4112 ok( rc1.bottom - rc1.top == 1, "Height should be 1 size is %s\n", wine_dbgstr_rect(&rc1));
4114 /* test window too narrow for a vertical scroll bar */
4115 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
4116 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %s\n", sbwidth - 1,
4117 wine_dbgstr_rect(&rc1));
4119 /* test window just wide enough for a vertical scroll bar */
4120 nccalchelper( hwnd, sbwidth, 100, &rc1);
4121 ok( rc1.right - rc1.left == 0, "Width should be 0 size is %s\n", wine_dbgstr_rect(&rc1));
4123 /* same test, but with client edge: not enough width */
4124 SetWindowLongA( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLongA( hwnd, GWL_EXSTYLE));
4125 nccalchelper( hwnd, sbwidth, 100, &rc1);
4126 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
4127 "Width should be %d size is %s\n", sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
4128 wine_dbgstr_rect(&rc1));
4130 DestroyWindow( hwnd);
4133 static void test_SetParent(void)
4135 HWND desktop = GetDesktopWindow();
4136 HMENU hMenu;
4137 HWND ret, parent, child1, child2, child3, child4, sibling, popup;
4138 BOOL bret;
4140 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
4141 100, 100, 200, 200, 0, 0, 0, NULL);
4142 assert(parent != 0);
4143 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
4144 0, 0, 50, 50, parent, 0, 0, NULL);
4145 assert(child1 != 0);
4146 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
4147 0, 0, 50, 50, child1, 0, 0, NULL);
4148 assert(child2 != 0);
4149 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
4150 0, 0, 50, 50, child2, 0, 0, NULL);
4151 assert(child3 != 0);
4152 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
4153 0, 0, 50, 50, child3, 0, 0, NULL);
4154 assert(child4 != 0);
4156 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
4157 parent, child1, child2, child3, child4);
4159 check_parents(parent, desktop, 0, 0, 0, parent, parent);
4160 check_parents(child1, parent, parent, parent, 0, parent, parent);
4161 check_parents(child2, desktop, parent, parent, parent, child2, parent);
4162 check_parents(child3, child2, child2, child2, 0, child2, parent);
4163 check_parents(child4, desktop, child2, child2, child2, child4, parent);
4165 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
4166 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
4167 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
4168 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
4169 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
4171 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
4172 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
4173 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
4174 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
4175 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
4176 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
4177 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
4178 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
4179 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
4181 if (!is_win9x) /* Win9x doesn't survive this test */
4183 ok(!SetParent(parent, child1), "SetParent should fail\n");
4184 ok(!SetParent(child2, child3), "SetParent should fail\n");
4185 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
4186 ret = SetParent(parent, child2);
4187 todo_wine ok( !ret || broken( ret != 0 ), "SetParent should fail\n");
4188 if (ret) /* nt4, win2k */
4190 ret = SetParent(parent, child3);
4191 ok(ret != 0, "SetParent should not fail\n");
4192 ret = SetParent(child2, parent);
4193 ok(!ret, "SetParent should fail\n");
4194 ret = SetParent(parent, child4);
4195 ok(ret != 0, "SetParent should not fail\n");
4196 check_parents(parent, child4, child4, 0, 0, child4, parent);
4197 check_parents(child1, parent, parent, parent, 0, child4, parent);
4198 check_parents(child2, desktop, parent, parent, parent, child2, parent);
4199 check_parents(child3, child2, child2, child2, 0, child2, parent);
4200 check_parents(child4, desktop, child2, child2, child2, child4, parent);
4202 else
4204 ret = SetParent(parent, child3);
4205 ok(ret != 0, "SetParent should not fail\n");
4206 ret = SetParent(child2, parent);
4207 ok(!ret, "SetParent should fail\n");
4208 ret = SetParent(parent, child4);
4209 ok(!ret, "SetParent should fail\n");
4210 check_parents(parent, child3, child3, 0, 0, child2, parent);
4211 check_parents(child1, parent, parent, parent, 0, child2, parent);
4212 check_parents(child2, desktop, parent, parent, parent, child2, parent);
4213 check_parents(child3, child2, child2, child2, 0, child2, parent);
4214 check_parents(child4, desktop, child2, child2, child2, child4, parent);
4217 else
4218 skip("Win9x/WinMe crash\n");
4220 hMenu = CreateMenu();
4221 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
4222 100, 100, 200, 200, 0, hMenu, 0, NULL);
4223 assert(sibling != 0);
4225 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
4226 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
4228 ok(SetParent(parent, desktop) != 0, "SetParent should not fail\n");
4229 ok(SetParent(child4, child3) != 0, "SetParent should not fail\n");
4230 ok(SetParent(child3, child2) != 0, "SetParent should not fail\n");
4231 ok(SetParent(child2, child1) != 0, "SetParent should not fail\n");
4232 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
4233 SetWindowLongW(child4, GWL_STYLE, WS_CHILD);
4234 ok(IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
4235 ok(IsChild(child2, child4), "wrong parent/child %p/%p\n", child2, child4);
4236 ok(!IsChild(child1, child4), "wrong parent/child %p/%p\n", child1, child4);
4237 SetWindowLongW(child2, GWL_STYLE, WS_CHILD);
4238 ok(IsChild(child1, child4), "wrong parent/child %p/%p\n", child1, child4);
4239 ok(IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
4241 ok(DestroyWindow(parent), "DestroyWindow() failed\n");
4243 ok(!IsWindow(parent), "parent still exists\n");
4244 ok(!IsWindow(sibling), "sibling still exists\n");
4245 ok(!IsWindow(child1), "child1 still exists\n");
4246 ok(!IsWindow(child2), "child2 still exists\n");
4247 ok(!IsWindow(child3), "child3 still exists\n");
4248 ok(!IsWindow(child4), "child4 still exists\n");
4250 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
4251 100, 100, 200, 200, 0, 0, 0, NULL);
4252 assert(parent != 0);
4253 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
4254 0, 0, 50, 50, parent, 0, 0, NULL);
4255 assert(child1 != 0);
4256 popup = CreateWindowExA(0, "static", NULL, WS_POPUP,
4257 0, 0, 50, 50, 0, 0, 0, NULL);
4258 assert(popup != 0);
4260 trace("parent %p, child %p, popup %p\n", parent, child1, popup);
4262 check_parents(parent, desktop, 0, 0, 0, parent, parent);
4263 check_parents(child1, parent, parent, parent, 0, parent, parent);
4264 check_parents(popup, desktop, 0, 0, 0, popup, popup);
4266 SetActiveWindow(parent);
4267 SetFocus(parent);
4268 check_active_state(parent, 0, parent);
4270 ret = SetParent(popup, child1);
4271 ok(ret == desktop, "expected %p, got %p\n", desktop, ret);
4272 check_parents(popup, child1, child1, 0, 0, parent, popup);
4273 check_active_state(popup, 0, popup);
4275 SetActiveWindow(parent);
4276 SetFocus(popup);
4277 check_active_state(popup, 0, popup);
4279 EnableWindow(child1, FALSE);
4280 check_active_state(popup, 0, popup);
4281 SetFocus(parent);
4282 check_active_state(parent, 0, parent);
4283 SetFocus(popup);
4284 check_active_state(popup, 0, popup);
4285 EnableWindow(child1, TRUE);
4287 ShowWindow(child1, SW_MINIMIZE);
4288 SetFocus(parent);
4289 check_active_state(parent, 0, parent);
4290 SetFocus(popup);
4291 check_active_state(popup, 0, popup);
4292 ShowWindow(child1, SW_HIDE);
4294 SetActiveWindow(parent);
4295 SetFocus(parent);
4296 check_active_state(parent, 0, parent);
4298 bret = SetForegroundWindow(popup);
4299 ok(bret, "SetForegroundWindow() failed\n");
4300 check_active_state(popup, popup, popup);
4302 ShowWindow(parent, SW_SHOW);
4303 SetActiveWindow(popup);
4304 ok(DestroyWindow(popup), "DestroyWindow() failed\n");
4305 check_active_state(parent, parent, parent);
4307 ok(DestroyWindow(parent), "DestroyWindow() failed\n");
4309 ok(!IsWindow(parent), "parent still exists\n");
4310 ok(!IsWindow(child1), "child1 still exists\n");
4311 ok(!IsWindow(popup), "popup still exists\n");
4314 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4316 LPCREATESTRUCTA lpcs;
4317 LPSTYLESTRUCT lpss;
4319 switch (msg)
4321 case WM_NCCREATE:
4322 case WM_CREATE:
4323 lpcs = (LPCREATESTRUCTA)lparam;
4324 lpss = lpcs->lpCreateParams;
4325 if (lpss)
4327 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
4328 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
4329 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
4330 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
4331 else
4332 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
4334 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
4335 "Ex style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
4336 lpss->styleOld, lpcs->dwExStyle);
4338 ok(lpss->styleNew == lpcs->style,
4339 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
4340 lpss->styleNew, lpcs->style);
4342 break;
4344 return DefWindowProcA(hwnd, msg, wparam, lparam);
4347 static ATOM atomStyleCheckClass;
4349 static void register_style_check_class(void)
4351 WNDCLASSA wc =
4354 StyleCheckProc,
4357 GetModuleHandleA(NULL),
4358 NULL,
4359 LoadCursorA(0, (LPCSTR)IDC_ARROW),
4360 (HBRUSH)(COLOR_BTNFACE+1),
4361 NULL,
4362 "WineStyleCheck",
4365 atomStyleCheckClass = RegisterClassA(&wc);
4366 assert(atomStyleCheckClass);
4369 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
4371 DWORD dwActualStyle;
4372 DWORD dwActualExStyle;
4373 STYLESTRUCT ss;
4374 HWND hwnd;
4375 HWND hwndParent = NULL;
4377 ss.styleNew = dwStyleIn;
4378 ss.styleOld = dwExStyleIn;
4380 if (dwStyleIn & WS_CHILD)
4382 hwndParent = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomStyleCheckClass), NULL,
4383 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
4386 hwnd = CreateWindowExA(dwExStyleIn, (LPCSTR)MAKEINTATOM(atomStyleCheckClass), NULL,
4387 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
4388 assert(hwnd);
4390 flush_events( TRUE );
4392 dwActualStyle = GetWindowLongA(hwnd, GWL_STYLE);
4393 dwActualExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
4394 ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
4395 ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
4397 /* try setting the styles explicitly */
4398 SetWindowLongA( hwnd, GWL_EXSTYLE, dwExStyleIn );
4399 dwActualStyle = GetWindowLongA(hwnd, GWL_STYLE);
4400 dwActualExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
4401 /* WS_EX_WINDOWEDGE can't always be changed */
4402 if (dwExStyleIn & WS_EX_DLGMODALFRAME)
4403 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
4404 else if ((dwActualStyle & (WS_DLGFRAME | WS_THICKFRAME)) && !(dwExStyleIn & WS_EX_STATICEDGE))
4405 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
4406 else
4407 dwExStyleOut = dwExStyleIn & ~WS_EX_WINDOWEDGE;
4408 ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
4409 ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
4411 SetWindowLongA( hwnd, GWL_STYLE, dwStyleIn );
4412 dwActualStyle = GetWindowLongA(hwnd, GWL_STYLE);
4413 dwActualExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
4414 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
4415 if ((dwStyleIn & (WS_CHILD|WS_POPUP)) == WS_CHILD) dwStyleOut = dwStyleIn;
4416 else dwStyleOut = dwStyleIn | WS_CLIPSIBLINGS;
4417 /* WS_EX_WINDOWEDGE can't always be changed */
4418 if (dwExStyleIn & WS_EX_DLGMODALFRAME)
4419 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
4420 else if ((dwActualStyle & (WS_DLGFRAME | WS_THICKFRAME)) && !(dwExStyleIn & WS_EX_STATICEDGE))
4421 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
4422 else
4423 dwExStyleOut = dwExStyleIn & ~WS_EX_WINDOWEDGE;
4424 ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
4425 /* FIXME: Remove the condition below once Wine is fixed */
4426 todo_wine_if (dwActualExStyle != dwExStyleOut)
4427 ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
4429 DestroyWindow(hwnd);
4430 if (hwndParent) DestroyWindow(hwndParent);
4433 /* tests what window styles the window manager automatically adds */
4434 static void test_window_styles(void)
4436 register_style_check_class();
4438 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
4439 check_window_style(WS_DLGFRAME, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
4440 check_window_style(WS_THICKFRAME, 0, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
4441 check_window_style(WS_DLGFRAME, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE);
4442 check_window_style(WS_THICKFRAME, WS_EX_STATICEDGE, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE);
4443 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
4444 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
4445 check_window_style(WS_CHILD|WS_DLGFRAME, 0, WS_CHILD|WS_DLGFRAME, WS_EX_WINDOWEDGE);
4446 check_window_style(WS_CHILD|WS_THICKFRAME, 0, WS_CHILD|WS_THICKFRAME, WS_EX_WINDOWEDGE);
4447 check_window_style(WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE);
4448 check_window_style(WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE);
4449 check_window_style(WS_CHILD|WS_CAPTION, 0, WS_CHILD|WS_CAPTION, WS_EX_WINDOWEDGE);
4450 check_window_style(WS_CHILD|WS_CAPTION|WS_SYSMENU, 0, WS_CHILD|WS_CAPTION|WS_SYSMENU, WS_EX_WINDOWEDGE);
4451 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
4452 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
4453 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
4454 check_window_style(WS_CHILD|WS_POPUP, 0, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
4455 check_window_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, 0, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4456 check_window_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, 0, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4457 check_window_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
4458 check_window_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
4459 check_window_style(WS_CHILD|WS_POPUP, WS_EX_APPWINDOW, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, WS_EX_APPWINDOW);
4460 check_window_style(WS_CHILD|WS_POPUP, WS_EX_WINDOWEDGE, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
4461 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
4462 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
4463 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
4464 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
4465 check_window_style(WS_POPUP|WS_DLGFRAME, 0, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4466 check_window_style(WS_POPUP|WS_THICKFRAME, 0, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4467 check_window_style(WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
4468 check_window_style(WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
4469 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
4470 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
4472 if (pGetLayeredWindowAttributes)
4474 check_window_style(0, WS_EX_LAYERED, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_WINDOWEDGE);
4475 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_WINDOWEDGE);
4476 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION,
4477 WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW|WS_EX_WINDOWEDGE);
4481 static INT_PTR WINAPI empty_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4483 return 0;
4486 static INT_PTR WINAPI empty_dlg_proc3(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4488 if (msg == WM_INITDIALOG)
4489 EndDialog(hwnd, 0);
4491 return 0;
4494 struct dialog_param
4496 HWND parent, grand_parent;
4497 DLGTEMPLATE *dlg_data;
4500 static INT_PTR WINAPI empty_dlg_proc2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4502 if (msg == WM_INITDIALOG)
4504 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
4505 struct dialog_param *param = (struct dialog_param *)lparam;
4506 BOOL parent_is_child;
4507 HWND disabled_hwnd;
4509 parent_is_child = (GetWindowLongA(param->parent, GWL_STYLE) & (WS_POPUP | WS_CHILD)) == WS_CHILD;
4511 ok(IsWindowEnabled(hwnd), "wrong state for %p\n", hwnd);
4512 if (parent_is_child)
4514 ok(IsWindowEnabled(param->parent), "wrong state for %08x\n", style);
4515 disabled_hwnd = param->grand_parent;
4517 else
4519 ok(!IsWindowEnabled(param->parent), "wrong state for %08x\n", style);
4520 disabled_hwnd = param->parent;
4523 if (param->grand_parent)
4525 if (parent_is_child)
4526 ok(!IsWindowEnabled(param->grand_parent), "wrong state for %08x\n", style);
4527 else
4528 ok(IsWindowEnabled(param->grand_parent), "wrong state for %08x\n", style);
4531 DialogBoxIndirectParamA(GetModuleHandleA(NULL), param->dlg_data, disabled_hwnd, empty_dlg_proc3, 0);
4532 ok(IsWindowEnabled(disabled_hwnd), "wrong state for %08x\n", style);
4534 ok(IsWindowEnabled(hwnd), "wrong state for %p\n", hwnd);
4535 ok(IsWindowEnabled(param->parent), "wrong state for %p\n", param->parent);
4536 if (param->grand_parent)
4537 ok(IsWindowEnabled(param->grand_parent), "wrong state for %p (%08x)\n", param->grand_parent, style);
4539 DialogBoxIndirectParamA(GetModuleHandleA(NULL), param->dlg_data, hwnd, empty_dlg_proc3, 0);
4540 ok(IsWindowEnabled(hwnd), "wrong state for %p\n", hwnd);
4541 ok(IsWindowEnabled(param->parent), "wrong state for %p\n", param->parent);
4542 if (param->grand_parent)
4543 ok(IsWindowEnabled(param->grand_parent), "wrong state for %p (%08x)\n", param->grand_parent, style);
4545 param->dlg_data->style |= WS_CHILD;
4546 DialogBoxIndirectParamA(GetModuleHandleA(NULL), param->dlg_data, hwnd, empty_dlg_proc3, 0);
4547 ok(IsWindowEnabled(hwnd), "wrong state for %p (%08x)\n", hwnd, style);
4549 EndDialog(hwnd, 0);
4551 return 0;
4554 static void check_dialog_style(DWORD style_in, DWORD ex_style_in, DWORD style_out, DWORD ex_style_out)
4556 struct
4558 DLGTEMPLATE dt;
4559 WORD menu_name;
4560 WORD class_id;
4561 WORD class_atom;
4562 WCHAR caption[1];
4563 } dlg_data;
4564 DWORD style, ex_style;
4565 HWND hwnd, grand_parent = 0, parent = 0;
4566 struct dialog_param param;
4568 if (style_in & WS_CHILD)
4570 grand_parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
4571 0, 0, 0, 0, NULL, NULL, NULL, NULL);
4572 ok(grand_parent != 0, "grand_parent creation failed\n");
4575 parent = CreateWindowExA(0, "static", NULL, style_in,
4576 0, 0, 0, 0, grand_parent, NULL, NULL, NULL);
4577 ok(parent != 0, "parent creation failed, style %#x\n", style_in);
4579 dlg_data.dt.style = style_in;
4580 dlg_data.dt.dwExtendedStyle = ex_style_in;
4581 dlg_data.dt.cdit = 0;
4582 dlg_data.dt.x = 0;
4583 dlg_data.dt.y = 0;
4584 dlg_data.dt.cx = 100;
4585 dlg_data.dt.cy = 100;
4586 dlg_data.menu_name = 0;
4587 dlg_data.class_id = 0;
4588 dlg_data.class_atom = 0;
4589 dlg_data.caption[0] = 0;
4591 hwnd = CreateDialogIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, parent, empty_dlg_proc, 0);
4592 ok(hwnd != 0, "dialog creation failed, style %#x, exstyle %#x\n", style_in, ex_style_in);
4594 flush_events( TRUE );
4596 style = GetWindowLongA(hwnd, GWL_STYLE);
4597 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
4598 ok(style == (style_out | DS_3DLOOK), "got %#x\n", style);
4599 ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
4601 ok(IsWindowEnabled(parent), "wrong parent state (dialog style %#x)\n", style_in);
4603 /* try setting the styles explicitly */
4604 SetWindowLongA(hwnd, GWL_EXSTYLE, ex_style_in);
4605 style = GetWindowLongA(hwnd, GWL_STYLE);
4606 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
4607 ok(style == (style_out | DS_3DLOOK), "got %#x\n", style);
4608 /* WS_EX_WINDOWEDGE can't always be changed */
4609 if (ex_style_in & WS_EX_DLGMODALFRAME)
4610 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
4611 else if ((style & (WS_DLGFRAME | WS_THICKFRAME)) && !(ex_style_in & WS_EX_STATICEDGE))
4612 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
4613 else
4614 ex_style_out = ex_style_in & ~WS_EX_WINDOWEDGE;
4615 ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
4617 SetWindowLongA(hwnd, GWL_STYLE, style_in);
4618 style = GetWindowLongA(hwnd, GWL_STYLE);
4619 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
4620 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
4621 if ((style_in & (WS_CHILD | WS_POPUP)) == WS_CHILD) style_out = style_in;
4622 else style_out = style_in | WS_CLIPSIBLINGS;
4623 ok(style == style_out, "expected style %#x, got %#x\n", style_out, style);
4624 /* WS_EX_WINDOWEDGE can't always be changed */
4625 if (ex_style_in & WS_EX_DLGMODALFRAME)
4626 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
4627 else if ((style & (WS_DLGFRAME | WS_THICKFRAME)) && !(ex_style_in & WS_EX_STATICEDGE))
4628 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
4629 else
4630 ex_style_out = ex_style_in & ~WS_EX_WINDOWEDGE;
4631 /* FIXME: Remove the condition below once Wine is fixed */
4632 todo_wine_if (ex_style != ex_style_out)
4633 ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
4635 DestroyWindow(hwnd);
4637 param.parent = parent;
4638 param.grand_parent = grand_parent;
4639 param.dlg_data = &dlg_data.dt;
4640 DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, parent, empty_dlg_proc2, (LPARAM)&param);
4642 ok(IsWindowEnabled(parent), "wrong parent state (dialog style %#x)\n", style_in);
4643 if (grand_parent)
4644 ok(IsWindowEnabled(grand_parent), "wrong grand parent state (dialog style %#x)\n", style_in);
4646 DestroyWindow(parent);
4647 DestroyWindow(grand_parent);
4650 static void test_dialog_styles(void)
4652 check_dialog_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4653 check_dialog_style(WS_DLGFRAME, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4654 check_dialog_style(WS_THICKFRAME, 0, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4655 check_dialog_style(WS_DLGFRAME, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4656 check_dialog_style(WS_THICKFRAME, WS_EX_STATICEDGE, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4657 check_dialog_style(DS_CONTROL, 0, WS_CLIPSIBLINGS|WS_CAPTION|DS_CONTROL, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4658 check_dialog_style(WS_CAPTION, 0, WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4659 check_dialog_style(WS_BORDER, 0, WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4660 check_dialog_style(WS_DLGFRAME, 0, WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4661 check_dialog_style(WS_BORDER|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4662 check_dialog_style(WS_DLGFRAME|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4663 check_dialog_style(WS_CAPTION|WS_SYSMENU, 0, WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4664 check_dialog_style(WS_SYSMENU, 0, WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4665 check_dialog_style(WS_CAPTION|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4666 check_dialog_style(WS_SYSMENU|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4667 check_dialog_style(WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4668 check_dialog_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4669 check_dialog_style(WS_CHILD, 0, WS_CHILD, 0);
4670 check_dialog_style(WS_CHILD|WS_DLGFRAME, 0, WS_CHILD|WS_DLGFRAME, WS_EX_WINDOWEDGE);
4671 check_dialog_style(WS_CHILD|WS_THICKFRAME, 0, WS_CHILD|WS_THICKFRAME, WS_EX_WINDOWEDGE);
4672 check_dialog_style(WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE);
4673 check_dialog_style(WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE);
4674 check_dialog_style(WS_CHILD|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4675 check_dialog_style(WS_CHILD|WS_CAPTION, 0, WS_CHILD|WS_CAPTION, WS_EX_WINDOWEDGE);
4676 check_dialog_style(WS_CHILD|WS_BORDER, 0, WS_CHILD|WS_BORDER, 0);
4677 check_dialog_style(WS_CHILD|WS_DLGFRAME, 0, WS_CHILD|WS_DLGFRAME, WS_EX_WINDOWEDGE);
4678 check_dialog_style(WS_CHILD|WS_BORDER|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4679 check_dialog_style(WS_CHILD|WS_DLGFRAME|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4680 check_dialog_style(WS_CHILD|WS_CAPTION|WS_SYSMENU, 0, WS_CHILD|WS_CAPTION|WS_SYSMENU, WS_EX_WINDOWEDGE);
4681 check_dialog_style(WS_CHILD|WS_SYSMENU, 0, WS_CHILD|WS_SYSMENU, 0);
4682 check_dialog_style(WS_CHILD|WS_CAPTION|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4683 check_dialog_style(WS_CHILD|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4684 check_dialog_style(WS_CHILD|WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4685 check_dialog_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
4686 check_dialog_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
4687 check_dialog_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
4688 check_dialog_style(WS_CHILD|WS_POPUP, 0, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
4689 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, 0, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4690 check_dialog_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, 0, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4691 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
4692 check_dialog_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
4693 check_dialog_style(WS_CHILD|WS_POPUP|DS_CONTROL, 0, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS|DS_CONTROL, WS_EX_CONTROLPARENT);
4694 check_dialog_style(WS_CHILD|WS_POPUP|WS_CAPTION, 0, WS_CHILD|WS_POPUP|WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4695 check_dialog_style(WS_CHILD|WS_POPUP|WS_BORDER, 0, WS_CHILD|WS_POPUP|WS_BORDER|WS_CLIPSIBLINGS, 0);
4696 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, 0, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4697 check_dialog_style(WS_CHILD|WS_POPUP|WS_BORDER|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4698 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4699 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);
4700 check_dialog_style(WS_CHILD|WS_POPUP|WS_SYSMENU, 0, WS_CHILD|WS_POPUP|WS_SYSMENU|WS_CLIPSIBLINGS, 0);
4701 check_dialog_style(WS_CHILD|WS_POPUP|WS_CAPTION|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4702 check_dialog_style(WS_CHILD|WS_POPUP|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4703 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);
4704 check_dialog_style(WS_CHILD|WS_POPUP, WS_EX_APPWINDOW, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, WS_EX_APPWINDOW);
4705 check_dialog_style(WS_CHILD|WS_POPUP, WS_EX_WINDOWEDGE, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
4706 check_dialog_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
4707 check_dialog_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW|WS_EX_CONTROLPARENT);
4708 check_dialog_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4709 check_dialog_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4710 check_dialog_style(WS_POPUP|WS_DLGFRAME, 0, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4711 check_dialog_style(WS_POPUP|WS_THICKFRAME, 0, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4712 check_dialog_style(WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4713 check_dialog_style(WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4714 check_dialog_style(WS_POPUP|DS_CONTROL, 0, WS_POPUP|WS_CLIPSIBLINGS|DS_CONTROL, WS_EX_CONTROLPARENT);
4715 check_dialog_style(WS_POPUP|WS_CAPTION, 0, WS_POPUP|WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4716 check_dialog_style(WS_POPUP|WS_BORDER, 0, WS_POPUP|WS_BORDER|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4717 check_dialog_style(WS_POPUP|WS_DLGFRAME, 0, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4718 check_dialog_style(WS_POPUP|WS_BORDER|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4719 check_dialog_style(WS_POPUP|WS_DLGFRAME|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4720 check_dialog_style(WS_POPUP|WS_CAPTION|WS_SYSMENU, 0, WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4721 check_dialog_style(WS_POPUP|WS_SYSMENU, 0, WS_POPUP|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4722 check_dialog_style(WS_POPUP|WS_CAPTION|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4723 check_dialog_style(WS_POPUP|WS_SYSMENU|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4724 check_dialog_style(WS_POPUP|WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4725 check_dialog_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4726 check_dialog_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4728 if (pGetLayeredWindowAttributes)
4730 check_dialog_style(0, WS_EX_LAYERED, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4731 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);
4732 check_dialog_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION,
4733 WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4737 struct dlg_parent_param
4739 HWND ga_parent;
4740 HWND gwl_parent;
4741 HWND get_parent;
4742 HWND owner;
4743 HWND root;
4744 HWND ga_root_owner;
4747 static INT_PTR WINAPI parent_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4749 if (msg == WM_INITDIALOG) {
4750 struct dlg_parent_param *param = (void*)lparam;
4751 check_parents(hwnd, param->ga_parent, param->gwl_parent, param->get_parent, param->owner,
4752 param->root ? param->root : hwnd, param->ga_root_owner ? param->ga_root_owner : hwnd);
4754 ok(!IsWindowEnabled(param->gwl_parent), "parent is not disabled\n");
4755 EndDialog(hwnd, 2);
4756 ok(IsWindowEnabled(param->gwl_parent), "parent is not enabled\n");
4759 return 0;
4762 static INT_PTR WINAPI reparent_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4764 if (msg == WM_INITDIALOG) {
4765 ok(!IsWindowEnabled(GetParent(hwnd)), "parent is not disabled\n");
4766 SetParent(hwnd, (HWND)lparam);
4769 return 0;
4772 static INT_PTR WINAPI reparent_owned_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4774 if (msg == WM_INITDIALOG) {
4775 HWND new_parent = (HWND)lparam;
4776 HWND owner = GetWindow(hwnd, GW_OWNER);
4777 ok(!IsWindowEnabled(owner), "owner is not disabled\n");
4778 SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) | WS_CHILD);
4779 SetParent(hwnd, new_parent);
4780 ok(GetParent(hwnd) == new_parent, "GetParent(hwnd) = %p, expected %p\n", GetParent(hwnd), new_parent);
4781 PostMessageA(hwnd, WM_QUIT, 0, 0);
4784 return 0;
4787 static LRESULT WINAPI reparent_dialog_owner_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4789 if (msg == WM_ENTERIDLE) {
4790 HWND dialog = (HWND)lparam;
4791 HWND owner = GetParent(dialog);
4792 /* EndDialog will enable owner */
4793 EnableWindow(owner, FALSE);
4794 EndDialog(dialog, 2);
4795 ok(IsWindowEnabled(owner), "owner is not enabled\n");
4796 /* ...but it won't be enabled on dialog exit */
4797 EnableWindow(owner, FALSE);
4799 return DefWindowProcA( hwnd, msg, wparam, lparam );
4802 static LRESULT WINAPI post_quit_dialog_owner_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4804 if (msg == WM_ENTERIDLE) {
4805 HWND dialog = (HWND)lparam;
4806 PostMessageA(dialog, WM_QUIT, 0, 0);
4808 return DefWindowProcA( hwnd, msg, wparam, lparam );
4811 static LRESULT WINAPI destroy_dialog_owner_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4813 if (msg == WM_ENTERIDLE) {
4814 HWND dialog = (HWND)lparam;
4815 DestroyWindow(dialog);
4817 return DefWindowProcA( hwnd, msg, wparam, lparam );
4820 static void test_dialog_parent(void)
4822 HWND dialog, parent, child, child2, other, desktop = GetDesktopWindow();
4823 struct dlg_parent_param param;
4824 INT_PTR ret;
4825 struct
4827 DLGTEMPLATE dt;
4828 WORD menu_name;
4829 WORD class_id;
4830 WORD class_atom;
4831 WCHAR caption[1];
4832 } dlg_data;
4834 dlg_data.dt.dwExtendedStyle = 0;
4835 dlg_data.dt.cdit = 0;
4836 dlg_data.dt.x = 0;
4837 dlg_data.dt.y = 0;
4838 dlg_data.dt.cx = 100;
4839 dlg_data.dt.cy = 100;
4840 dlg_data.menu_name = 0;
4841 dlg_data.class_id = 0;
4842 dlg_data.class_atom = 0;
4843 dlg_data.caption[0] = 0;
4845 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
4846 /* Create a child without WS_CHILD flag. It's a valid owner window. */
4847 child = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
4848 SetParent(child, parent);
4849 /* Regular child. If passed as an owner, its parent will be true owner window. */
4850 child2 = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, child, NULL, NULL, NULL);
4852 trace("parent %p child %p child2 %p desktop %p\n", parent, child, child2, desktop);
4854 /* When dialog is created with WS_CHILD style, its parent depends on function used to create it. */
4855 dlg_data.dt.style = WS_CHILD;
4857 /* CreateDialogIndirectParam uses passed parent as dialog parent. */
4858 dialog = CreateDialogIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, empty_dlg_proc, 0);
4859 ok(dialog != 0, "dialog creation failed\n");
4860 check_parents(dialog, child2, child2, child2, NULL, parent, child);
4862 ok(IsWindowEnabled(child2), "child2 is disabled\n");
4863 EnableWindow(child2, FALSE);
4864 EndDialog(dialog, 0);
4865 ok(IsWindowEnabled(child2), "child2 is not enabled\n");
4866 DestroyWindow(dialog);
4868 /* DialogBoxIndirectParam uses the first parent of passed owner that's not a child window as dialog
4869 * parent (like in case of dialog with owner). */
4870 param.ga_parent = param.gwl_parent = param.get_parent = child;
4871 param.owner = NULL;
4872 param.root = parent;
4873 param.ga_root_owner = child;
4874 ret = DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, parent_dlg_proc, (LPARAM)&param);
4875 ok(ret == 2, "DialogBoxIndirectParam returned %ld\n", ret);
4877 /* Dialogs without WS_CHILD behave as expected, they use passed owner just like CreateWindow does. */
4878 dlg_data.dt.style = WS_OVERLAPPEDWINDOW;
4880 dialog = CreateDialogIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, empty_dlg_proc, 0);
4881 ok(dialog != 0, "dialog creation failed\n");
4882 check_parents(dialog, desktop, child, NULL, child, dialog, dialog);
4884 ok(IsWindowEnabled(child), "child is disabled\n");
4885 EnableWindow(child, FALSE);
4886 EndDialog(dialog, 0);
4887 ok(IsWindowEnabled(child), "child is not enabled\n");
4888 DestroyWindow(dialog);
4890 param.ga_parent = desktop;
4891 param.gwl_parent = child;
4892 param.get_parent = NULL;
4893 param.owner = child;
4894 param.root = param.ga_root_owner = NULL;
4895 ret = DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, parent_dlg_proc, (LPARAM)&param);
4896 ok(ret == 2, "DialogBoxIndirectParam returned %ld\n", ret);
4898 other = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
4899 SetWindowLongPtrA(child, GWLP_WNDPROC, (ULONG_PTR)reparent_dialog_owner_proc);
4901 /* When dialog is created with WS_CHILD|WS_POPUP style, we have an owner. */
4902 dlg_data.dt.style = WS_CHILD|WS_POPUP;
4904 dialog = CreateDialogIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, empty_dlg_proc, 0);
4905 ok(dialog != 0, "dialog creation failed\n");
4906 check_parents(dialog, desktop, child, child, child, dialog, child);
4908 ok(IsWindowEnabled(child), "child is disabled\n");
4909 EnableWindow(child, FALSE);
4910 EndDialog(dialog, 0);
4911 ok(IsWindowEnabled(child), "child is not enabled\n");
4912 DestroyWindow(dialog);
4914 param.ga_parent = desktop;
4915 param.gwl_parent = param.get_parent = child;
4916 param.owner = child;
4917 param.root = NULL;
4918 param.ga_root_owner = child;
4919 ret = DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, parent_dlg_proc, (LPARAM)&param);
4920 ok(ret == 2, "DialogBoxIndirectParam returned %ld\n", ret);
4922 /* If we change parent in WM_INITDIALOG for WS_CHILD dialog WM_ENTERIDLE is still sent to the original
4923 * parent. EndDialog will enable the new parent. */
4924 EnableWindow(child, TRUE);
4925 EnableWindow(other, FALSE);
4926 dlg_data.dt.style = WS_CHILD;
4927 ret = DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, reparent_dlg_proc, (LPARAM)other);
4928 ok(ret == 2, "DialogBoxIndirectParam returned %ld\n", ret);
4929 ok(!IsWindowEnabled(other), "other is not disabled\n");
4930 ok(!IsWindowEnabled(child), "child is not disabled\n");
4931 ok(IsWindowEnabled(child2), "child2 is not enabled\n");
4932 EnableWindow(child, TRUE);
4934 /* If we change parent and style in WM_INITDIALOG for dialog with an owner to make it true child
4935 * (thus GetParent() will return the new parent instead of an owner), WM_ENTERIDLE is still sent
4936 * to the original parent. EndDialog will enable the new parent. */
4937 EnableWindow(other, FALSE);
4938 dlg_data.dt.style = WS_OVERLAPPED;
4939 ret = DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, reparent_owned_dlg_proc, (LPARAM)other);
4940 ok(ret == 1, "DialogBoxIndirectParam returned %ld\n", ret);
4941 ok(!IsWindowEnabled(other), "other is not disabled\n");
4942 ok(!IsWindowEnabled(child), "child is not disabled\n");
4943 ok(IsWindowEnabled(child2), "child2 is not enabled\n");
4944 EnableWindow(child, TRUE);
4945 EnableWindow(other, TRUE);
4947 /* Quit dialog message loop by sending WM_QUIT message. Dialog owner is not enabled. */
4948 SetWindowLongPtrA(child, GWLP_WNDPROC, (ULONG_PTR)post_quit_dialog_owner_proc);
4949 ret = DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, other, empty_dlg_proc, 0);
4950 ok(ret == 1, "DialogBoxIndirectParam returned %ld\n", ret);
4951 ok(!IsWindowEnabled(other), "other is enabled\n");
4952 EnableWindow(other, TRUE);
4954 /* Quit dialog message loop by destroying the window. Dialog owner is not enabled. */
4955 SetWindowLongPtrA(child, GWLP_WNDPROC, (ULONG_PTR)destroy_dialog_owner_proc);
4956 ret = DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, other, empty_dlg_proc, 0);
4957 ok(ret == 1, "DialogBoxIndirectParam returned %ld\n", ret);
4958 ok(!IsWindowEnabled(other), "other is enabled\n");
4959 EnableWindow(other, TRUE);
4961 DestroyWindow(other);
4962 DestroyWindow(parent);
4965 static void test_scrollwindow( HWND hwnd)
4967 HDC hdc;
4968 RECT rc, rc2, rc3;
4969 COLORREF colr;
4971 ShowWindow( hwnd, SW_SHOW);
4972 UpdateWindow( hwnd);
4973 flush_events( TRUE );
4974 GetClientRect( hwnd, &rc);
4975 hdc = GetDC( hwnd);
4976 /* test ScrollWindow(Ex) with no clip rectangle */
4977 /* paint the lower half of the window black */
4978 rc2 = rc;
4979 rc2.top = ( rc2.top + rc2.bottom) / 2;
4980 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4981 /* paint the upper half of the window white */
4982 rc2.bottom = rc2.top;
4983 rc2.top =0;
4984 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
4985 /* scroll lower half up */
4986 rc2 = rc;
4987 rc2.top = ( rc2.top + rc2.bottom) / 2;
4988 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, NULL, NULL, NULL, SW_ERASE);
4989 flush_events(FALSE);
4990 /* expected: black should have scrolled to the upper half */
4991 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
4992 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4993 /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
4994 /* paint the lower half of the window black */
4995 rc2 = rc;
4996 rc2.top = ( rc2.top + rc2.bottom) / 2;
4997 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4998 /* paint the upper half of the window white */
4999 rc2.bottom = rc2.top;
5000 rc2.top =0;
5001 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
5002 /* scroll lower half up */
5003 rc2 = rc;
5004 rc2.top = ( rc2.top + rc2.bottom) / 2;
5005 rc3 = rc;
5006 rc3.left = rc3.right / 4;
5007 rc3.right -= rc3.right / 4;
5008 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, &rc3, NULL, NULL, SW_ERASE);
5009 flush_events(FALSE);
5010 /* expected: black should have scrolled to the upper half */
5011 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
5012 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
5014 /* clean up */
5015 ReleaseDC( hwnd, hdc);
5018 static void test_scrollvalidate( HWND parent)
5020 HDC hdc;
5021 HRGN hrgn=CreateRectRgn(0,0,0,0);
5022 HRGN exprgn, tmprgn, clipping;
5023 RECT rc, rcu, cliprc;
5024 /* create two overlapping child windows. The visual region
5025 * of hwnd1 is clipped by the overlapping part of
5026 * hwnd2 because of the WS_CLIPSIBLING style */
5027 HWND hwnd1, hwnd2;
5029 clipping = CreateRectRgn(0,0,0,0);
5030 tmprgn = CreateRectRgn(0,0,0,0);
5031 exprgn = CreateRectRgn(0,0,0,0);
5032 hwnd2 = CreateWindowExA(0, "static", NULL,
5033 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
5034 75, 30, 100, 100, parent, 0, 0, NULL);
5035 hwnd1 = CreateWindowExA(0, "static", NULL,
5036 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
5037 25, 50, 100, 100, parent, 0, 0, NULL);
5038 ShowWindow( parent, SW_SHOW);
5039 UpdateWindow( parent);
5040 GetClientRect( hwnd1, &rc);
5041 cliprc=rc;
5042 SetRectRgn( clipping, 10, 10, 90, 90);
5043 hdc = GetDC( hwnd1);
5044 /* for a visual touch */
5045 TextOutA( hdc, 0,10, "0123456789", 10);
5046 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
5047 if (winetest_debug > 0) dump_region(hrgn);
5048 /* create a region with what is expected */
5049 SetRectRgn( exprgn, 39,0,49,74);
5050 SetRectRgn( tmprgn, 88,79,98,93);
5051 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
5052 SetRectRgn( tmprgn, 0,93,98,98);
5053 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
5054 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
5055 trace("update rect is %s\n", wine_dbgstr_rect(&rcu));
5056 /* now with clipping region */
5057 SelectClipRgn( hdc, clipping);
5058 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
5059 if (winetest_debug > 0) dump_region(hrgn);
5060 /* create a region with what is expected */
5061 SetRectRgn( exprgn, 39,10,49,74);
5062 SetRectRgn( tmprgn, 80,79,90,85);
5063 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
5064 SetRectRgn( tmprgn, 10,85,90,90);
5065 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
5066 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
5067 trace("update rect is %s\n", wine_dbgstr_rect(&rcu));
5068 ReleaseDC( hwnd1, hdc);
5070 /* test scrolling a rect by more than its size */
5071 DestroyWindow( hwnd2);
5072 ValidateRect( hwnd1, NULL);
5073 SetRect( &rc, 40,40, 50,50);
5074 InvalidateRect( hwnd1, &rc, 1);
5075 ScrollWindowEx( hwnd1, -20, 0, &rc, NULL, hrgn, &rcu,
5076 SW_SCROLLCHILDREN | SW_INVALIDATE);
5077 if (winetest_debug > 0) dump_region(hrgn);
5078 SetRectRgn( exprgn, 20, 40, 30, 50);
5079 SetRectRgn( tmprgn, 40, 40, 50, 50);
5080 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
5081 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
5082 ok( rcu.left == 20 && rcu.top == 40 && rcu.right == 50 && rcu.bottom == 50,
5083 "unexpected update rect: %s\n", wine_dbgstr_rect(&rcu));
5085 /* test scrolling a window with an update region */
5086 ValidateRect( hwnd1, NULL);
5087 SetRect( &rc, 40,40, 50,50);
5088 InvalidateRect( hwnd1, &rc, 1);
5089 GetClientRect( hwnd1, &rc);
5090 cliprc=rc;
5091 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
5092 SW_SCROLLCHILDREN | SW_INVALIDATE);
5093 if (winetest_debug > 0) dump_region(hrgn);
5094 SetRectRgn( exprgn, 88,0,98,98);
5095 SetRectRgn( tmprgn, 30, 40, 50, 50);
5096 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
5097 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
5099 /* clear an update region */
5100 UpdateWindow( hwnd1 );
5102 SetRect( &rc, 0,40, 100,60);
5103 SetRect( &cliprc, 0,0, 100,100);
5104 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
5105 if (winetest_debug > 0) dump_region( hrgn );
5106 SetRectRgn( exprgn, 0, 40, 98, 60 );
5107 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
5109 /* now test ScrollWindowEx with a combination of
5110 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
5111 /* make hwnd2 the child of hwnd1 */
5112 hwnd2 = CreateWindowExA(0, "static", NULL,
5113 WS_CHILD| WS_VISIBLE | WS_BORDER ,
5114 50, 50, 100, 100, hwnd1, 0, 0, NULL);
5115 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
5116 GetClientRect( hwnd1, &rc);
5117 cliprc=rc;
5119 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
5120 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
5121 ValidateRect( hwnd1, NULL);
5122 ValidateRect( hwnd2, NULL);
5123 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
5124 SW_SCROLLCHILDREN | SW_INVALIDATE);
5125 if (winetest_debug > 0) dump_region(hrgn);
5126 SetRectRgn( exprgn, 88,0,98,88);
5127 SetRectRgn( tmprgn, 0,88,98,98);
5128 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
5129 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
5131 /* SW_SCROLLCHILDREN */
5132 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
5133 ValidateRect( hwnd1, NULL);
5134 ValidateRect( hwnd2, NULL);
5135 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
5136 if (winetest_debug > 0) dump_region(hrgn);
5137 /* expected region is the same as in previous test */
5138 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
5140 /* no SW_SCROLLCHILDREN */
5141 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
5142 ValidateRect( hwnd1, NULL);
5143 ValidateRect( hwnd2, NULL);
5144 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
5145 if (winetest_debug > 0) dump_region(hrgn);
5146 /* expected region is the same as in previous test */
5147 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
5149 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
5150 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
5151 ValidateRect( hwnd1, NULL);
5152 ValidateRect( hwnd2, NULL);
5153 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
5154 if (winetest_debug > 0) dump_region(hrgn);
5155 SetRectRgn( exprgn, 88,0,98,20);
5156 SetRectRgn( tmprgn, 20,20,98,30);
5157 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
5158 SetRectRgn( tmprgn, 20,30,30,88);
5159 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
5160 SetRectRgn( tmprgn, 0,88,30,98);
5161 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
5162 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
5164 /* clean up */
5165 DeleteObject( hrgn);
5166 DeleteObject( exprgn);
5167 DeleteObject( tmprgn);
5168 DestroyWindow( hwnd1);
5169 DestroyWindow( hwnd2);
5172 /* couple of tests of return values of scrollbar functions
5173 * called on a scrollbarless window */
5174 static void test_scroll(void)
5176 BOOL ret;
5177 INT min, max;
5178 SCROLLINFO si;
5179 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
5180 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
5181 100, 100, 200, 200, 0, 0, 0, NULL);
5182 /* horizontal */
5183 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
5184 if (!ret) /* win9x */
5186 win_skip( "GetScrollRange doesn't work\n" );
5187 DestroyWindow( hwnd);
5188 return;
5190 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
5191 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
5192 si.cbSize = sizeof( si);
5193 si.fMask = SIF_PAGE;
5194 si.nPage = 0xdeadbeef;
5195 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
5196 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
5197 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
5198 /* vertical */
5199 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
5200 ok( ret, "GetScrollRange returns FALSE\n");
5201 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
5202 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
5203 si.cbSize = sizeof( si);
5204 si.fMask = SIF_PAGE;
5205 si.nPage = 0xdeadbeef;
5206 ret = GetScrollInfo( hwnd, SB_VERT, &si);
5207 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
5208 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
5209 /* clean up */
5210 DestroyWindow( hwnd);
5213 static void test_scrolldc( HWND parent)
5215 HDC hdc;
5216 HRGN exprgn, tmprgn, hrgn;
5217 RECT rc, rc2, rcu, cliprc;
5218 HWND hwnd1;
5219 COLORREF colr;
5221 hrgn = CreateRectRgn(0,0,0,0);
5222 tmprgn = CreateRectRgn(0,0,0,0);
5223 exprgn = CreateRectRgn(0,0,0,0);
5225 hwnd1 = CreateWindowExA(0, "static", NULL,
5226 WS_CHILD| WS_VISIBLE,
5227 25, 50, 100, 100, parent, 0, 0, NULL);
5228 ShowWindow( parent, SW_SHOW);
5229 UpdateWindow( parent);
5230 flush_events( TRUE );
5231 GetClientRect( hwnd1, &rc);
5232 hdc = GetDC( hwnd1);
5233 /* paint the upper half of the window black */
5234 rc2 = rc;
5235 rc2.bottom = ( rc.top + rc.bottom) /2;
5236 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
5237 /* clip region is the lower half */
5238 cliprc=rc;
5239 cliprc.top = (rc.top + rc.bottom) /2;
5240 /* test whether scrolled pixels are properly clipped */
5241 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
5242 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
5243 /* this scroll should not cause any visible changes */
5244 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
5245 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
5246 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
5247 /* test with NULL clip rect */
5248 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
5249 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
5250 trace("update rect: %s\n", wine_dbgstr_rect(&rcu));
5251 if (winetest_debug > 0) dump_region(hrgn);
5252 SetRect(&rc2, 0, 0, 100, 100);
5253 ok(EqualRect(&rcu, &rc2), "rects do not match %s / %s\n", wine_dbgstr_rect(&rcu),
5254 wine_dbgstr_rect(&rc2));
5256 SetRectRgn( exprgn, 0, 0, 20, 80);
5257 SetRectRgn( tmprgn, 0, 80, 100, 100);
5258 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
5259 if (winetest_debug > 0) dump_region(exprgn);
5260 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
5261 /* test clip rect > scroll rect */
5262 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
5263 rc2=rc;
5264 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
5265 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
5266 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
5267 SetRectRgn( exprgn, 25, 25, 75, 35);
5268 SetRectRgn( tmprgn, 25, 35, 35, 75);
5269 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
5270 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
5271 trace("update rect: %s\n", wine_dbgstr_rect(&rcu));
5272 if (winetest_debug > 0) dump_region(hrgn);
5274 /* clean up */
5275 ReleaseDC(hwnd1, hdc);
5276 DeleteObject(hrgn);
5277 DeleteObject(exprgn);
5278 DeleteObject(tmprgn);
5279 DestroyWindow(hwnd1);
5282 static void test_params(void)
5284 HWND hwnd;
5285 INT rc;
5287 ok(!IsWindow(0), "IsWindow(0)\n");
5288 ok(!IsWindow(HWND_BROADCAST), "IsWindow(HWND_BROADCAST)\n");
5289 ok(!IsWindow(HWND_TOPMOST), "IsWindow(HWND_TOPMOST)\n");
5291 /* Just a param check */
5292 if (pGetMonitorInfoA)
5294 SetLastError(0xdeadbeef);
5295 rc = GetWindowTextA(hwndMain2, NULL, 1024);
5296 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
5298 else
5300 /* Skips actually on Win95 and NT4 */
5301 win_skip("Test would crash on Win95\n");
5304 SetLastError(0xdeadbeef);
5305 hwnd=CreateWindowA("LISTBOX", "TestList",
5306 (LBS_STANDARD & ~LBS_SORT),
5307 0, 0, 100, 100,
5308 NULL, (HMENU)1, NULL, 0);
5310 ok(!hwnd || broken(hwnd != NULL), /* w2k3 sp2 */
5311 "CreateWindow with invalid menu handle should fail\n");
5312 if (!hwnd)
5313 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
5314 GetLastError() == 0xdeadbeef, /* Win9x */
5315 "wrong last error value %d\n", GetLastError());
5318 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
5320 HWND hwnd = 0;
5322 hwnd = CreateWindowExA(exStyle, class, class, style,
5323 110, 100,
5324 225, 200,
5326 menu ? hmenu : 0,
5327 0, 0);
5328 if (!hwnd) {
5329 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
5330 return;
5332 ShowWindow(hwnd, SW_SHOW);
5334 test_nonclient_area(hwnd);
5336 SetMenu(hwnd, 0);
5337 DestroyWindow(hwnd);
5340 static BOOL AWR_init(void)
5342 WNDCLASSA class;
5344 class.style = CS_HREDRAW | CS_VREDRAW;
5345 class.lpfnWndProc = DefWindowProcA;
5346 class.cbClsExtra = 0;
5347 class.cbWndExtra = 0;
5348 class.hInstance = 0;
5349 class.hIcon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
5350 class.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
5351 class.hbrBackground = 0;
5352 class.lpszMenuName = 0;
5353 class.lpszClassName = szAWRClass;
5355 if (!RegisterClassA(&class)) {
5356 ok(FALSE, "RegisterClass failed\n");
5357 return FALSE;
5360 hmenu = CreateMenu();
5361 if (!hmenu)
5362 return FALSE;
5363 ok(hmenu != 0, "Failed to create menu\n");
5364 ok(AppendMenuA(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
5366 return TRUE;
5370 static void test_AWR_window_size(BOOL menu)
5372 static const DWORD styles[] = {
5373 WS_POPUP, WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME, WS_CAPTION, WS_SYSMENU,
5374 WS_THICKFRAME, WS_MINIMIZEBOX, WS_MAXIMIZEBOX, WS_HSCROLL, WS_VSCROLL
5376 static const DWORD exStyles[] = {
5377 WS_EX_CLIENTEDGE, WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE, WS_EX_APPWINDOW,
5378 WS_EX_DLGMODALFRAME, WS_EX_DLGMODALFRAME | WS_EX_STATICEDGE
5381 unsigned int i;
5383 /* A exhaustive check of all the styles takes too long
5384 * so just do a (hopefully representative) sample
5386 for (i = 0; i < COUNTOF(styles); ++i)
5387 test_AWRwindow(szAWRClass, styles[i], 0, menu);
5388 for (i = 0; i < COUNTOF(exStyles); ++i) {
5389 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
5390 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
5394 static void test_AWR_flags(void)
5396 static const DWORD styles[] = { WS_POPUP, WS_BORDER, WS_DLGFRAME, WS_THICKFRAME };
5397 static const DWORD exStyles[] = { WS_EX_CLIENTEDGE, WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
5398 WS_EX_APPWINDOW, WS_EX_DLGMODALFRAME, WS_EX_STATICEDGE };
5400 DWORD i, j, k, style, exstyle;
5401 RECT rect, rect2;
5403 for (i = 0; i < (1 << COUNTOF(styles)); i++)
5405 for (k = style = 0; k < COUNTOF(styles); k++) if (i & (1 << k)) style |= styles[k];
5407 for (j = 0; j < (1 << COUNTOF(exStyles)); j++)
5409 for (k = exstyle = 0; k < COUNTOF(exStyles); k++) if (j & (1 << k)) exstyle |= exStyles[k];
5410 SetRect( &rect, 100, 100, 200, 200 );
5411 rect2 = rect;
5412 AdjustWindowRectEx( &rect, style, FALSE, exstyle );
5413 wine_AdjustWindowRectEx( &rect2, style, FALSE, exstyle );
5414 ok( EqualRect( &rect, &rect2 ), "rects do not match: win %s wine %s\n",
5415 wine_dbgstr_rect( &rect ), wine_dbgstr_rect( &rect2 ));
5419 #undef COUNTOF
5421 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
5423 static void test_AdjustWindowRect(void)
5425 if (!AWR_init())
5426 return;
5428 SHOWSYSMETRIC(SM_CYCAPTION);
5429 SHOWSYSMETRIC(SM_CYSMCAPTION);
5430 SHOWSYSMETRIC(SM_CYMENU);
5431 SHOWSYSMETRIC(SM_CXEDGE);
5432 SHOWSYSMETRIC(SM_CYEDGE);
5433 SHOWSYSMETRIC(SM_CXVSCROLL);
5434 SHOWSYSMETRIC(SM_CYHSCROLL);
5435 SHOWSYSMETRIC(SM_CXFRAME);
5436 SHOWSYSMETRIC(SM_CYFRAME);
5437 SHOWSYSMETRIC(SM_CXDLGFRAME);
5438 SHOWSYSMETRIC(SM_CYDLGFRAME);
5439 SHOWSYSMETRIC(SM_CXBORDER);
5440 SHOWSYSMETRIC(SM_CYBORDER);
5442 test_AWR_window_size(FALSE);
5443 test_AWR_window_size(TRUE);
5444 test_AWR_flags();
5446 DestroyMenu(hmenu);
5448 #undef SHOWSYSMETRIC
5451 /* Global variables to trigger exit from loop */
5452 static int redrawComplete, WMPAINT_count;
5454 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5456 switch (msg)
5458 case WM_PAINT:
5459 trace("doing WM_PAINT %d\n", WMPAINT_count);
5460 WMPAINT_count++;
5461 if (WMPAINT_count > 10 && redrawComplete == 0) {
5462 PAINTSTRUCT ps;
5463 BeginPaint(hwnd, &ps);
5464 EndPaint(hwnd, &ps);
5465 return 1;
5467 return 0;
5469 return DefWindowProcA(hwnd, msg, wparam, lparam);
5472 /* Ensure we exit from RedrawNow regardless of invalidated area */
5473 static void test_redrawnow(void)
5475 WNDCLASSA cls;
5476 HWND hwndMain;
5478 cls.style = CS_DBLCLKS;
5479 cls.lpfnWndProc = redraw_window_procA;
5480 cls.cbClsExtra = 0;
5481 cls.cbWndExtra = 0;
5482 cls.hInstance = GetModuleHandleA(0);
5483 cls.hIcon = 0;
5484 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
5485 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5486 cls.lpszMenuName = NULL;
5487 cls.lpszClassName = "RedrawWindowClass";
5489 if(!RegisterClassA(&cls)) {
5490 trace("Register failed %d\n", GetLastError());
5491 return;
5494 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
5495 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
5497 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
5498 ShowWindow(hwndMain, SW_SHOW);
5499 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
5500 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
5501 ok( WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
5502 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
5503 redrawComplete = TRUE;
5504 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
5506 /* clean up */
5507 DestroyWindow( hwndMain);
5510 struct parentdc_stat {
5511 RECT client;
5512 RECT clip;
5513 RECT paint;
5516 struct parentdc_test {
5517 struct parentdc_stat main, main_todo;
5518 struct parentdc_stat child1, child1_todo;
5519 struct parentdc_stat child2, child2_todo;
5522 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5524 RECT rc;
5525 PAINTSTRUCT ps;
5527 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
5529 switch (msg)
5531 case WM_PAINT:
5532 GetClientRect(hwnd, &rc);
5533 t->client = rc;
5534 GetWindowRect(hwnd, &rc);
5535 trace("WM_PAINT: hwnd %p, client rect %s, window rect %s\n", hwnd,
5536 wine_dbgstr_rect(&t->client), wine_dbgstr_rect(&rc));
5537 BeginPaint(hwnd, &ps);
5538 t->paint = ps.rcPaint;
5539 GetClipBox(ps.hdc, &rc);
5540 t->clip = rc;
5541 trace("clip rect %s, paint rect %s\n", wine_dbgstr_rect(&rc),
5542 wine_dbgstr_rect(&ps.rcPaint));
5543 EndPaint(hwnd, &ps);
5544 return 0;
5546 return DefWindowProcA(hwnd, msg, wparam, lparam);
5549 static void zero_parentdc_stat(struct parentdc_stat *t)
5551 SetRectEmpty(&t->client);
5552 SetRectEmpty(&t->clip);
5553 SetRectEmpty(&t->paint);
5556 static void zero_parentdc_test(struct parentdc_test *t)
5558 zero_parentdc_stat(&t->main);
5559 zero_parentdc_stat(&t->child1);
5560 zero_parentdc_stat(&t->child2);
5563 #define parentdc_field_ok(t, w, r, f, got) \
5564 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
5565 ": expected %d, got %d\n", \
5566 t.w.r.f, got.w.r.f)
5568 #define parentdc_todo_field_ok(t, w, r, f, got) \
5569 todo_wine_if (t.w##_todo.r.f) \
5570 parentdc_field_ok(t, w, r, f, got);
5572 #define parentdc_rect_ok(t, w, r, got) \
5573 parentdc_todo_field_ok(t, w, r, left, got); \
5574 parentdc_todo_field_ok(t, w, r, top, got); \
5575 parentdc_todo_field_ok(t, w, r, right, got); \
5576 parentdc_todo_field_ok(t, w, r, bottom, got);
5578 #define parentdc_win_ok(t, w, got) \
5579 parentdc_rect_ok(t, w, client, got); \
5580 parentdc_rect_ok(t, w, clip, got); \
5581 parentdc_rect_ok(t, w, paint, got);
5583 #define parentdc_ok(t, got) \
5584 parentdc_win_ok(t, main, got); \
5585 parentdc_win_ok(t, child1, got); \
5586 parentdc_win_ok(t, child2, got);
5588 static void test_csparentdc(void)
5590 WNDCLASSA clsMain, cls;
5591 HWND hwndMain, hwnd1, hwnd2;
5592 RECT rc;
5594 struct parentdc_test test_answer;
5596 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
5597 const struct parentdc_test test1 =
5599 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
5600 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
5601 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
5604 const struct parentdc_test test2 =
5606 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
5607 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
5608 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
5611 const struct parentdc_test test3 =
5613 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
5614 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
5615 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
5618 const struct parentdc_test test4 =
5620 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
5621 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
5622 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
5625 const struct parentdc_test test5 =
5627 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
5628 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
5629 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
5632 const struct parentdc_test test6 =
5634 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
5635 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
5636 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
5639 const struct parentdc_test test7 =
5641 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
5642 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
5643 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
5645 #undef nothing_todo
5647 clsMain.style = CS_DBLCLKS;
5648 clsMain.lpfnWndProc = parentdc_window_procA;
5649 clsMain.cbClsExtra = 0;
5650 clsMain.cbWndExtra = 0;
5651 clsMain.hInstance = GetModuleHandleA(0);
5652 clsMain.hIcon = 0;
5653 clsMain.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
5654 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
5655 clsMain.lpszMenuName = NULL;
5656 clsMain.lpszClassName = "ParentDcMainWindowClass";
5658 if(!RegisterClassA(&clsMain)) {
5659 trace("Register failed %d\n", GetLastError());
5660 return;
5663 cls.style = CS_DBLCLKS | CS_PARENTDC;
5664 cls.lpfnWndProc = parentdc_window_procA;
5665 cls.cbClsExtra = 0;
5666 cls.cbWndExtra = 0;
5667 cls.hInstance = GetModuleHandleA(0);
5668 cls.hIcon = 0;
5669 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
5670 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5671 cls.lpszMenuName = NULL;
5672 cls.lpszClassName = "ParentDcWindowClass";
5674 if(!RegisterClassA(&cls)) {
5675 trace("Register failed %d\n", GetLastError());
5676 return;
5679 SetRect(&rc, 0, 0, 150, 150);
5680 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
5681 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
5682 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
5683 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
5684 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
5685 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
5686 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
5687 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
5688 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
5689 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
5690 ShowWindow(hwndMain, SW_SHOW);
5691 ShowWindow(hwnd1, SW_SHOW);
5692 ShowWindow(hwnd2, SW_SHOW);
5693 SetWindowPos(hwndMain, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
5694 flush_events( TRUE );
5696 zero_parentdc_test(&test_answer);
5697 InvalidateRect(hwndMain, NULL, TRUE);
5698 flush_events( TRUE );
5699 parentdc_ok(test1, test_answer);
5701 zero_parentdc_test(&test_answer);
5702 SetRect(&rc, 0, 0, 50, 50);
5703 InvalidateRect(hwndMain, &rc, TRUE);
5704 flush_events( TRUE );
5705 parentdc_ok(test2, test_answer);
5707 zero_parentdc_test(&test_answer);
5708 SetRect(&rc, 0, 0, 10, 10);
5709 InvalidateRect(hwndMain, &rc, TRUE);
5710 flush_events( TRUE );
5711 parentdc_ok(test3, test_answer);
5713 zero_parentdc_test(&test_answer);
5714 SetRect(&rc, 40, 40, 50, 50);
5715 InvalidateRect(hwndMain, &rc, TRUE);
5716 flush_events( TRUE );
5717 parentdc_ok(test4, test_answer);
5719 zero_parentdc_test(&test_answer);
5720 SetRect(&rc, 20, 20, 60, 60);
5721 InvalidateRect(hwndMain, &rc, TRUE);
5722 flush_events( TRUE );
5723 parentdc_ok(test5, test_answer);
5725 zero_parentdc_test(&test_answer);
5726 SetRect(&rc, 0, 0, 10, 10);
5727 InvalidateRect(hwnd1, &rc, TRUE);
5728 flush_events( TRUE );
5729 parentdc_ok(test6, test_answer);
5731 zero_parentdc_test(&test_answer);
5732 SetRect(&rc, -5, -5, 65, 65);
5733 InvalidateRect(hwnd1, &rc, TRUE);
5734 flush_events( TRUE );
5735 parentdc_ok(test7, test_answer);
5737 DestroyWindow(hwndMain);
5738 DestroyWindow(hwnd1);
5739 DestroyWindow(hwnd2);
5742 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5744 return DefWindowProcA(hwnd, msg, wparam, lparam);
5747 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5749 return DefWindowProcW(hwnd, msg, wparam, lparam);
5752 static void test_IsWindowUnicode(void)
5754 static const char ansi_class_nameA[] = "ansi class name";
5755 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
5756 static const char unicode_class_nameA[] = "unicode class name";
5757 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
5758 WNDCLASSA classA;
5759 WNDCLASSW classW;
5760 HWND hwnd;
5761 ATOM atom;
5763 memset(&classW, 0, sizeof(classW));
5764 classW.hInstance = GetModuleHandleA(0);
5765 classW.lpfnWndProc = def_window_procW;
5766 classW.lpszClassName = unicode_class_nameW;
5767 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
5769 memset(&classA, 0, sizeof(classA));
5770 classA.hInstance = GetModuleHandleA(0);
5771 classA.lpfnWndProc = def_window_procA;
5772 classA.lpszClassName = ansi_class_nameA;
5773 atom = RegisterClassA(&classA);
5774 assert(atom);
5776 /* unicode class: window proc */
5777 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
5778 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
5779 assert(hwnd);
5781 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5782 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
5783 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5784 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
5785 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5787 DestroyWindow(hwnd);
5789 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
5790 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
5791 assert(hwnd);
5793 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5794 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
5795 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5796 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
5797 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5799 DestroyWindow(hwnd);
5801 /* ansi class: window proc */
5802 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
5803 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
5804 assert(hwnd);
5806 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5807 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
5808 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5809 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
5810 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5812 DestroyWindow(hwnd);
5814 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
5815 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
5816 assert(hwnd);
5818 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5819 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
5820 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5821 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
5822 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5824 DestroyWindow(hwnd);
5826 /* unicode class: class proc */
5827 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
5828 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
5829 assert(hwnd);
5831 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5832 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
5833 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5834 /* do not restore class window proc back to unicode */
5836 DestroyWindow(hwnd);
5838 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
5839 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
5840 assert(hwnd);
5842 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5843 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
5844 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5846 DestroyWindow(hwnd);
5848 /* ansi class: class proc */
5849 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
5850 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
5851 assert(hwnd);
5853 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5854 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
5855 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5856 /* do not restore class window proc back to ansi */
5858 DestroyWindow(hwnd);
5860 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
5861 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
5862 assert(hwnd);
5864 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5865 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
5866 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5868 DestroyWindow(hwnd);
5871 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
5873 MINMAXINFO *minmax;
5875 if (msg != WM_GETMINMAXINFO)
5876 return DefWindowProcA(hwnd, msg, wp, lp);
5878 minmax = (MINMAXINFO *)lp;
5880 if ((GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
5882 minmax->ptReserved.x = 0;
5883 minmax->ptReserved.y = 0;
5884 minmax->ptMaxSize.x = 400;
5885 minmax->ptMaxSize.y = 400;
5886 minmax->ptMaxPosition.x = 300;
5887 minmax->ptMaxPosition.y = 300;
5888 minmax->ptMaxTrackSize.x = 200;
5889 minmax->ptMaxTrackSize.y = 200;
5890 minmax->ptMinTrackSize.x = 100;
5891 minmax->ptMinTrackSize.y = 100;
5893 else
5894 DefWindowProcA(hwnd, msg, wp, lp);
5895 return 1;
5898 static int expected_cx, expected_cy;
5899 static RECT expected_rect, broken_rect;
5901 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
5903 switch(msg)
5905 case WM_GETMINMAXINFO:
5907 RECT rect;
5908 GetWindowRect( hwnd, &rect );
5909 ok( !rect.left && !rect.top && !rect.right && !rect.bottom, "wrong rect %s\n",
5910 wine_dbgstr_rect( &rect ));
5911 return DefWindowProcA(hwnd, msg, wp, lp);
5913 case WM_NCCREATE:
5914 case WM_CREATE:
5916 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
5917 RECT rect;
5918 GetWindowRect( hwnd, &rect );
5919 trace( "hwnd %p msg %x size %dx%d rect %s\n", hwnd, msg, cs->cx, cs->cy,
5920 wine_dbgstr_rect( &rect ));
5921 ok( cs->cx == expected_cx || broken(cs->cx == (short)expected_cx),
5922 "wrong x size %d/%d\n", cs->cx, expected_cx );
5923 ok( cs->cy == expected_cy || broken(cs->cy == (short)expected_cy),
5924 "wrong y size %d/%d\n", cs->cy, expected_cy );
5925 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
5926 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
5927 (rect.right - rect.left == min( 65535, expected_rect.right - expected_rect.left ) &&
5928 rect.bottom - rect.top == min( 65535, expected_rect.bottom - expected_rect.top )) ||
5929 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
5930 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top) ||
5931 broken( rect.right - rect.left == (short)broken_rect.right - (short)broken_rect.left &&
5932 rect.bottom - rect.top == (short)broken_rect.bottom - (short)broken_rect.top),
5933 "wrong rect %s / %s\n", wine_dbgstr_rect( &rect ), wine_dbgstr_rect( &expected_rect ));
5934 return DefWindowProcA(hwnd, msg, wp, lp);
5936 case WM_NCCALCSIZE:
5938 RECT rect, *r = (RECT *)lp;
5939 GetWindowRect( hwnd, &rect );
5940 ok( EqualRect( &rect, r ), "passed rect %s doesn't match window rect %s\n",
5941 wine_dbgstr_rect( r ), wine_dbgstr_rect( &rect ));
5942 return DefWindowProcA(hwnd, msg, wp, lp);
5944 default:
5945 return DefWindowProcA(hwnd, msg, wp, lp);
5949 static void test_CreateWindow(void)
5951 WNDCLASSA cls;
5952 HWND hwnd, parent;
5953 HMENU hmenu;
5954 RECT rc, rc_minmax;
5955 MINMAXINFO minmax;
5956 BOOL res;
5958 #define expect_menu(window, menu) \
5959 SetLastError(0xdeadbeef); \
5960 res = (GetMenu(window) == (HMENU)menu); \
5961 ok(res, "GetMenu error %d\n", GetLastError())
5963 #define expect_style(window, style)\
5964 ok((ULONG)GetWindowLongA(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLongA(window, GWL_STYLE))
5966 #define expect_ex_style(window, ex_style)\
5967 ok((ULONG)GetWindowLongA(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLongA(window, GWL_EXSTYLE))
5969 #define expect_gle_broken_9x(gle)\
5970 ok(GetLastError() == gle ||\
5971 broken(GetLastError() == 0xdeadbeef),\
5972 "IsMenu set error %d\n", GetLastError())
5974 hmenu = CreateMenu();
5975 assert(hmenu != 0);
5976 parent = GetDesktopWindow();
5977 assert(parent != 0);
5979 SetLastError(0xdeadbeef);
5980 res = IsMenu(hmenu);
5981 ok(res, "IsMenu error %d\n", GetLastError());
5983 /* WS_CHILD */
5984 SetLastError(0xdeadbeef);
5985 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
5986 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5987 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5988 expect_menu(hwnd, 1);
5989 expect_style(hwnd, WS_CHILD);
5990 expect_ex_style(hwnd, WS_EX_APPWINDOW);
5991 DestroyWindow(hwnd);
5993 SetLastError(0xdeadbeef);
5994 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
5995 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5996 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5997 expect_menu(hwnd, 1);
5998 expect_style(hwnd, WS_CHILD | WS_CAPTION);
5999 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
6000 DestroyWindow(hwnd);
6002 SetLastError(0xdeadbeef);
6003 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD,
6004 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
6005 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
6006 expect_menu(hwnd, 1);
6007 expect_style(hwnd, WS_CHILD);
6008 expect_ex_style(hwnd, 0);
6009 DestroyWindow(hwnd);
6011 SetLastError(0xdeadbeef);
6012 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_CAPTION,
6013 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
6014 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
6015 expect_menu(hwnd, 1);
6016 expect_style(hwnd, WS_CHILD | WS_CAPTION);
6017 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
6018 DestroyWindow(hwnd);
6020 /* WS_POPUP */
6021 SetLastError(0xdeadbeef);
6022 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
6023 0, 0, 100, 100, parent, hmenu, 0, NULL);
6024 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
6025 expect_menu(hwnd, hmenu);
6026 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
6027 expect_ex_style(hwnd, WS_EX_APPWINDOW);
6028 DestroyWindow(hwnd);
6029 SetLastError(0xdeadbeef);
6030 ok(!IsMenu(hmenu), "IsMenu should fail\n");
6031 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
6033 hmenu = CreateMenu();
6034 assert(hmenu != 0);
6035 SetLastError(0xdeadbeef);
6036 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
6037 0, 0, 100, 100, parent, hmenu, 0, NULL);
6038 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
6039 expect_menu(hwnd, hmenu);
6040 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
6041 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
6042 DestroyWindow(hwnd);
6043 SetLastError(0xdeadbeef);
6044 ok(!IsMenu(hmenu), "IsMenu should fail\n");
6045 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
6047 hmenu = CreateMenu();
6048 assert(hmenu != 0);
6049 SetLastError(0xdeadbeef);
6050 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
6051 0, 0, 100, 100, parent, hmenu, 0, NULL);
6052 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
6053 expect_menu(hwnd, hmenu);
6054 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
6055 expect_ex_style(hwnd, 0);
6056 DestroyWindow(hwnd);
6057 SetLastError(0xdeadbeef);
6058 ok(!IsMenu(hmenu), "IsMenu should fail\n");
6059 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
6061 hmenu = CreateMenu();
6062 assert(hmenu != 0);
6063 SetLastError(0xdeadbeef);
6064 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP | WS_CAPTION,
6065 0, 0, 100, 100, parent, hmenu, 0, NULL);
6066 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
6067 expect_menu(hwnd, hmenu);
6068 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
6069 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
6070 DestroyWindow(hwnd);
6071 SetLastError(0xdeadbeef);
6072 ok(!IsMenu(hmenu), "IsMenu should fail\n");
6073 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
6075 /* WS_CHILD | WS_POPUP */
6076 SetLastError(0xdeadbeef);
6077 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
6078 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
6079 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
6080 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
6081 if (hwnd)
6082 DestroyWindow(hwnd);
6084 hmenu = CreateMenu();
6085 assert(hmenu != 0);
6086 SetLastError(0xdeadbeef);
6087 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
6088 0, 0, 100, 100, parent, hmenu, 0, NULL);
6089 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
6090 expect_menu(hwnd, hmenu);
6091 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
6092 expect_ex_style(hwnd, WS_EX_APPWINDOW);
6093 DestroyWindow(hwnd);
6094 SetLastError(0xdeadbeef);
6095 ok(!IsMenu(hmenu), "IsMenu should fail\n");
6096 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
6098 SetLastError(0xdeadbeef);
6099 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
6100 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
6101 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
6102 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
6103 if (hwnd)
6104 DestroyWindow(hwnd);
6106 hmenu = CreateMenu();
6107 assert(hmenu != 0);
6108 SetLastError(0xdeadbeef);
6109 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
6110 0, 0, 100, 100, parent, hmenu, 0, NULL);
6111 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
6112 expect_menu(hwnd, hmenu);
6113 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
6114 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
6115 DestroyWindow(hwnd);
6116 SetLastError(0xdeadbeef);
6117 ok(!IsMenu(hmenu), "IsMenu should fail\n");
6118 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
6120 SetLastError(0xdeadbeef);
6121 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP,
6122 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
6123 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
6124 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
6125 if (hwnd)
6126 DestroyWindow(hwnd);
6128 hmenu = CreateMenu();
6129 assert(hmenu != 0);
6130 SetLastError(0xdeadbeef);
6131 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP,
6132 0, 0, 100, 100, parent, hmenu, 0, NULL);
6133 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
6134 expect_menu(hwnd, hmenu);
6135 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
6136 expect_ex_style(hwnd, 0);
6137 DestroyWindow(hwnd);
6138 SetLastError(0xdeadbeef);
6139 ok(!IsMenu(hmenu), "IsMenu should fail\n");
6140 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
6142 SetLastError(0xdeadbeef);
6143 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
6144 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
6145 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
6146 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
6147 if (hwnd)
6148 DestroyWindow(hwnd);
6150 hmenu = CreateMenu();
6151 assert(hmenu != 0);
6152 SetLastError(0xdeadbeef);
6153 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
6154 0, 0, 100, 100, parent, hmenu, 0, NULL);
6155 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
6156 expect_menu(hwnd, hmenu);
6157 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
6158 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
6159 DestroyWindow(hwnd);
6160 SetLastError(0xdeadbeef);
6161 ok(!IsMenu(hmenu), "IsMenu should fail\n");
6162 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
6164 /* test child window sizing */
6165 cls.style = 0;
6166 cls.lpfnWndProc = minmax_wnd_proc;
6167 cls.cbClsExtra = 0;
6168 cls.cbWndExtra = 0;
6169 cls.hInstance = GetModuleHandleA(NULL);
6170 cls.hIcon = 0;
6171 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
6172 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6173 cls.lpszMenuName = NULL;
6174 cls.lpszClassName = "MinMax_WndClass";
6175 RegisterClassA(&cls);
6177 SetLastError(0xdeadbeef);
6178 parent = CreateWindowExA(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
6179 0, 0, 100, 100, 0, 0, 0, NULL);
6180 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
6181 expect_menu(parent, 0);
6182 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
6183 expect_ex_style(parent, WS_EX_WINDOWEDGE);
6185 memset(&minmax, 0, sizeof(minmax));
6186 SendMessageA(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
6187 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
6188 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
6189 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
6190 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
6192 GetWindowRect(parent, &rc);
6193 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
6194 GetClientRect(parent, &rc);
6195 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
6197 InflateRect(&rc, 200, 200);
6198 trace("creating child with rect %s\n", wine_dbgstr_rect(&rc));
6200 SetLastError(0xdeadbeef);
6201 hwnd = CreateWindowExA(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
6202 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
6203 parent, (HMENU)1, 0, NULL);
6204 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
6205 expect_menu(hwnd, 1);
6206 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
6207 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
6209 memset(&minmax, 0, sizeof(minmax));
6210 SendMessageA(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
6211 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
6213 GetWindowRect(hwnd, &rc);
6214 OffsetRect(&rc, -rc.left, -rc.top);
6215 ok(EqualRect(&rc, &rc_minmax), "rects don't match: %s and %s\n", wine_dbgstr_rect(&rc),
6216 wine_dbgstr_rect(&rc_minmax));
6217 DestroyWindow(hwnd);
6219 cls.lpfnWndProc = winsizes_wnd_proc;
6220 cls.lpszClassName = "Sizes_WndClass";
6221 RegisterClassA(&cls);
6223 expected_cx = expected_cy = 200000;
6224 SetRect( &expected_rect, 0, 0, 200000, 200000 );
6225 broken_rect = expected_rect;
6226 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
6227 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6228 GetClientRect( hwnd, &rc );
6229 ok( rc.right == 200000 || rc.right == 65535 || broken(rc.right == (short)200000),
6230 "invalid rect right %u\n", rc.right );
6231 ok( rc.bottom == 200000 || rc.bottom == 65535 || broken(rc.bottom == (short)200000),
6232 "invalid rect bottom %u\n", rc.bottom );
6233 DestroyWindow(hwnd);
6235 expected_cx = expected_cy = -10;
6236 SetRectEmpty(&expected_rect);
6237 SetRect( &broken_rect, 0, 0, -10, -10 );
6238 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
6239 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6240 GetClientRect( hwnd, &rc );
6241 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
6242 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
6243 DestroyWindow(hwnd);
6245 expected_cx = expected_cy = -200000;
6246 SetRectEmpty(&expected_rect);
6247 SetRect( &broken_rect, 0, 0, -200000, -200000 );
6248 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
6249 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6250 GetClientRect( hwnd, &rc );
6251 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
6252 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
6253 DestroyWindow(hwnd);
6255 /* we need a parent at 0,0 so that child coordinates match */
6256 DestroyWindow(parent);
6257 parent = CreateWindowExA(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
6258 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
6260 expected_cx = 100;
6261 expected_cy = 0x7fffffff;
6262 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
6263 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
6264 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
6265 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6266 GetClientRect( hwnd, &rc );
6267 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
6268 ok( rc.bottom == 0x7fffffff - 10 || rc.bottom ==65535 || broken(rc.bottom == 0),
6269 "invalid rect bottom %u\n", rc.bottom );
6270 DestroyWindow(hwnd);
6272 expected_cx = 0x7fffffff;
6273 expected_cy = 0x7fffffff;
6274 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
6275 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
6276 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
6277 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6278 GetClientRect( hwnd, &rc );
6279 ok( rc.right == 0x7fffffff - 20 || rc.right == 65535 || broken(rc.right == 0),
6280 "invalid rect right %u\n", rc.right );
6281 ok( rc.bottom == 0x7fffffff - 10 || rc.right == 65535 || broken(rc.bottom == 0),
6282 "invalid rect bottom %u\n", rc.bottom );
6283 DestroyWindow(hwnd);
6285 /* top level window */
6286 expected_cx = expected_cy = 200000;
6287 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
6288 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
6289 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6290 GetClientRect( hwnd, &rc );
6291 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
6292 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
6293 DestroyWindow(hwnd);
6295 /* invalid class */
6296 SetLastError(0xdeadbeef);
6297 hwnd = CreateWindowExA(0, "INVALID_CLASS", NULL, WS_CHILD, 10, 10, 100, 100, parent, 0, 0, NULL);
6298 ok(hwnd == 0, "CreateWindowEx succeeded\n");
6299 ok(GetLastError() == ERROR_CLASS_DOES_NOT_EXIST || GetLastError() == ERROR_CANNOT_FIND_WND_CLASS,
6300 "invalid error %u\n", GetLastError());
6301 DestroyWindow(hwnd);
6303 if (pGetLayout && pSetLayout)
6305 HDC hdc = GetDC( parent );
6306 pSetLayout( hdc, LAYOUT_RTL );
6307 if (pGetLayout( hdc ))
6309 ReleaseDC( parent, hdc );
6310 DestroyWindow( parent );
6311 SetLastError( 0xdeadbeef );
6312 parent = CreateWindowExA(WS_EX_APPWINDOW | WS_EX_LAYOUTRTL, "static", NULL, WS_POPUP,
6313 0, 0, 100, 100, 0, 0, 0, NULL);
6314 ok( parent != 0, "creation failed err %u\n", GetLastError());
6315 expect_ex_style( parent, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
6316 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 20, 20, parent, 0, 0, NULL);
6317 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6318 expect_ex_style( hwnd, WS_EX_LAYOUTRTL );
6319 DestroyWindow( hwnd );
6320 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 20, 20, parent, 0, 0, NULL);
6321 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6322 expect_ex_style( hwnd, 0 );
6323 DestroyWindow( hwnd );
6324 SetWindowLongW( parent, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT );
6325 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 20, 20, parent, 0, 0, NULL);
6326 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6327 expect_ex_style( hwnd, 0 );
6328 DestroyWindow( hwnd );
6330 if (pGetProcessDefaultLayout && pSetProcessDefaultLayout)
6332 DWORD layout;
6334 SetLastError( 0xdeadbeef );
6335 ok( !pGetProcessDefaultLayout( NULL ), "GetProcessDefaultLayout succeeded\n" );
6336 ok( GetLastError() == ERROR_NOACCESS, "wrong error %u\n", GetLastError() );
6337 SetLastError( 0xdeadbeef );
6338 res = pGetProcessDefaultLayout( &layout );
6339 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
6340 ok( layout == 0, "GetProcessDefaultLayout wrong layout %x\n", layout );
6341 SetLastError( 0xdeadbeef );
6342 res = pSetProcessDefaultLayout( 7 );
6343 ok( res, "SetProcessDefaultLayout failed err %u\n", GetLastError ());
6344 res = pGetProcessDefaultLayout( &layout );
6345 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
6346 ok( layout == 7, "GetProcessDefaultLayout wrong layout %x\n", layout );
6347 SetLastError( 0xdeadbeef );
6348 res = pSetProcessDefaultLayout( LAYOUT_RTL );
6349 ok( res, "SetProcessDefaultLayout failed err %u\n", GetLastError ());
6350 res = pGetProcessDefaultLayout( &layout );
6351 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
6352 ok( layout == LAYOUT_RTL, "GetProcessDefaultLayout wrong layout %x\n", layout );
6353 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
6354 0, 0, 100, 100, 0, 0, 0, NULL);
6355 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6356 expect_ex_style( hwnd, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
6357 DestroyWindow( hwnd );
6358 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
6359 0, 0, 100, 100, parent, 0, 0, NULL);
6360 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6361 expect_ex_style( hwnd, WS_EX_APPWINDOW );
6362 DestroyWindow( hwnd );
6363 pSetProcessDefaultLayout( 0 );
6365 else win_skip( "SetProcessDefaultLayout not supported\n" );
6367 else win_skip( "SetLayout not supported\n" );
6369 else win_skip( "SetLayout not available\n" );
6371 DestroyWindow(parent);
6373 UnregisterClassA("MinMax_WndClass", GetModuleHandleA(NULL));
6374 UnregisterClassA("Sizes_WndClass", GetModuleHandleA(NULL));
6376 #undef expect_gle_broken_9x
6377 #undef expect_menu
6378 #undef expect_style
6379 #undef expect_ex_style
6382 /* function that remembers whether the system the test is running on sets the
6383 * last error for user32 functions to make the tests stricter */
6384 static int check_error(DWORD actual, DWORD expected)
6386 static int sets_last_error = -1;
6387 if (sets_last_error == -1)
6388 sets_last_error = (actual != 0xdeadbeef);
6389 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
6392 static void test_SetWindowLong(void)
6394 LONG_PTR retval;
6395 WNDPROC old_window_procW;
6397 SetLastError(0xdeadbeef);
6398 retval = SetWindowLongPtrA(NULL, GWLP_WNDPROC, 0);
6399 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
6400 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
6401 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instead of %d\n", GetLastError());
6403 SetLastError(0xdeadbeef);
6404 retval = SetWindowLongPtrA(hwndMain, 0xdeadbeef, 0);
6405 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
6406 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
6407 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instead of %d\n", GetLastError());
6409 SetLastError(0xdeadbeef);
6410 retval = SetWindowLongPtrA(hwndMain, GWLP_WNDPROC, 0);
6411 ok((WNDPROC)retval == main_window_procA || broken(!retval), /* win9x */
6412 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
6413 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
6414 retval = GetWindowLongPtrA(hwndMain, GWLP_WNDPROC);
6415 ok((WNDPROC)retval == main_window_procA,
6416 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
6417 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
6419 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
6420 SetLastError(0xdeadbeef);
6421 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
6422 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
6424 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
6425 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
6426 ok((WNDPROC)retval == old_window_procW,
6427 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
6428 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
6430 /* set it back to ANSI */
6431 SetWindowLongPtrA(hwndMain, GWLP_WNDPROC, 0);
6435 static LRESULT WINAPI check_style_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6437 const STYLESTRUCT *expected = (STYLESTRUCT *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
6438 const STYLESTRUCT *got = (STYLESTRUCT *)lParam;
6440 if (message == WM_STYLECHANGING && wParam == GWL_STYLE)
6442 ok(got->styleOld == expected[0].styleOld, "expected old style %#x, got %#x\n",
6443 expected[0].styleOld, got->styleOld);
6444 ok(got->styleNew == expected[0].styleNew, "expected new style %#x, got %#x\n",
6445 expected[0].styleNew, got->styleNew);
6447 else if (message == WM_STYLECHANGED && wParam == GWL_STYLE)
6449 ok(got->styleOld == expected[1].styleOld, "expected old style %#x, got %#x\n",
6450 expected[1].styleOld, got->styleOld);
6451 ok(got->styleNew == expected[1].styleNew, "expected new style %#x, got %#x\n",
6452 expected[1].styleNew, got->styleNew);
6455 return DefWindowProcA(hwnd, message, wParam, lParam);
6458 static void test_set_window_style(void)
6460 LONG expected_style, new_style, old_style;
6461 STYLESTRUCT expected_stylestruct[2];
6462 unsigned int i;
6463 WNDCLASSA cls;
6464 HWND hwnd;
6466 static const struct
6468 LONG creation_style;
6469 LONG style;
6471 tests[] =
6473 { WS_MINIMIZE | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
6474 WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX },
6475 { WS_MINIMIZE | WS_CLIPSIBLINGS | WS_CAPTION,
6476 WS_CLIPSIBLINGS | WS_CAPTION },
6477 { WS_MAXIMIZE | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
6478 WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX },
6479 { WS_MAXIMIZE | WS_CLIPSIBLINGS | WS_CAPTION,
6480 WS_CLIPSIBLINGS | WS_CAPTION },
6481 { WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
6482 WS_MINIMIZE | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX },
6483 { WS_CLIPSIBLINGS | WS_CAPTION,
6484 WS_MINIMIZE | WS_CLIPSIBLINGS | WS_CAPTION },
6485 { WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
6486 WS_MAXIMIZE | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX },
6487 { WS_CLIPSIBLINGS | WS_CAPTION,
6488 WS_MAXIMIZE | WS_CLIPSIBLINGS | WS_CAPTION },
6491 memset(&cls, 0, sizeof(cls));
6492 cls.lpfnWndProc = check_style_wnd_proc;
6493 cls.hInstance = GetModuleHandleA(0);
6494 cls.lpszClassName = "TestSetWindowStylesClass";
6495 ok(RegisterClassA(&cls), "RegisterClass failed\n");
6497 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
6499 expected_style = tests[i].style;
6500 if (tests[i].creation_style & WS_MINIMIZE)
6501 expected_style |= WS_MINIMIZE;
6503 expected_stylestruct[0].styleOld = tests[i].creation_style;
6504 expected_stylestruct[0].styleNew = tests[i].style;
6505 expected_stylestruct[1].styleOld = tests[i].creation_style;
6506 expected_stylestruct[1].styleNew = expected_style;
6508 hwnd = CreateWindowA(cls.lpszClassName, "Test set styles",
6509 tests[i].creation_style, 100, 100, 200, 200, 0, 0, 0, NULL);
6510 ok(hwnd != 0, "CreateWindow failed\n");
6511 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)&expected_stylestruct);
6513 old_style = SetWindowLongA(hwnd, GWL_STYLE, tests[i].style);
6514 ok(old_style == tests[i].creation_style, "expected old style %#x, got %#x\n",
6515 tests[i].creation_style, old_style);
6516 new_style = GetWindowLongA(hwnd, GWL_STYLE);
6517 ok(new_style == expected_style, "expected new style %#x, got %#x\n",
6518 expected_style, new_style);
6520 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0);
6521 DestroyWindow(hwnd);
6524 UnregisterClassA(cls.lpszClassName, cls.hInstance);
6527 static void test_ShowWindow(void)
6529 HWND hwnd;
6530 DWORD style;
6531 RECT rcMain, rc, rcMinimized, rcClient, rcEmpty, rcMaximized, rcResized;
6532 LPARAM ret;
6533 MONITORINFO mon_info;
6535 SetRect(&rcClient, 0, 0, 90, 90);
6536 rcMain = rcClient;
6537 OffsetRect(&rcMain, 120, 120);
6538 AdjustWindowRect(&rcMain, WS_CAPTION, 0);
6539 SetRect(&rcMinimized, -32000, -32000, -32000 + GetSystemMetrics(SM_CXMINIMIZED),
6540 -32000 + GetSystemMetrics(SM_CYMINIMIZED));
6541 SetRectEmpty(&rcEmpty);
6543 hwnd = CreateWindowExA(0, "MainWindowClass", NULL,
6544 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
6545 WS_MAXIMIZEBOX | WS_POPUP,
6546 rcMain.left, rcMain.top,
6547 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
6548 0, 0, 0, NULL);
6549 assert(hwnd);
6551 mon_info.cbSize = sizeof(mon_info);
6552 GetMonitorInfoW(MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY), &mon_info);
6553 rcMaximized = mon_info.rcWork;
6554 AdjustWindowRectEx(&rcMaximized, GetWindowLongA(hwnd, GWL_STYLE) & ~WS_BORDER,
6555 0, GetWindowLongA(hwnd, GWL_EXSTYLE));
6557 style = GetWindowLongA(hwnd, GWL_STYLE);
6558 ok(!(style & WS_DISABLED), "window should not be disabled\n");
6559 ok(!(style & WS_VISIBLE), "window should not be visible\n");
6560 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
6561 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
6562 GetWindowRect(hwnd, &rc);
6563 ok(EqualRect(&rcMain, &rc), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain),
6564 wine_dbgstr_rect(&rc));
6565 GetClientRect(hwnd, &rc);
6566 ok(EqualRect(&rcClient, &rc), "expected %s, got %s\n",
6567 wine_dbgstr_rect(&rcClient), wine_dbgstr_rect(&rc));
6569 ret = ShowWindow(hwnd, SW_SHOW);
6570 ok(!ret, "not expected ret: %lu\n", ret);
6571 style = GetWindowLongA(hwnd, GWL_STYLE);
6572 ok(!(style & WS_DISABLED), "window should not be disabled\n");
6573 ok(style & WS_VISIBLE, "window should be visible\n");
6574 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
6575 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
6576 GetWindowRect(hwnd, &rc);
6577 ok(EqualRect(&rcMain, &rc), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain),
6578 wine_dbgstr_rect(&rc));
6579 GetClientRect(hwnd, &rc);
6580 ok(EqualRect(&rcClient, &rc), "expected %s, got %s\n",
6581 wine_dbgstr_rect(&rcClient), wine_dbgstr_rect(&rc));
6583 ret = ShowWindow(hwnd, SW_MINIMIZE);
6584 ok(ret, "not expected ret: %lu\n", ret);
6585 style = GetWindowLongA(hwnd, GWL_STYLE);
6586 ok(!(style & WS_DISABLED), "window should not be disabled\n");
6587 ok(style & WS_VISIBLE, "window should be visible\n");
6588 ok(style & WS_MINIMIZE, "window should be minimized\n");
6589 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
6590 GetWindowRect(hwnd, &rc);
6591 todo_wine
6592 ok(EqualRect(&rcMinimized, &rc), "expected %s, got %s\n",
6593 wine_dbgstr_rect(&rcMinimized), wine_dbgstr_rect(&rc));
6594 GetClientRect(hwnd, &rc);
6595 todo_wine
6596 ok(EqualRect(&rcEmpty, &rc), "expected %s, got %s\n",
6597 wine_dbgstr_rect(&rcEmpty), wine_dbgstr_rect(&rc));
6598 /* shouldn't be able to resize minimized windows */
6599 ret = SetWindowPos(hwnd, 0, 0, 0,
6600 (rcMinimized.right - rcMinimized.left) * 2,
6601 (rcMinimized.bottom - rcMinimized.top) * 2,
6602 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
6603 ok(ret, "not expected ret: %lu\n", ret);
6604 GetWindowRect(hwnd, &rc);
6605 todo_wine
6606 ok(EqualRect(&rcMinimized, &rc), "expected %s, got %s\n",
6607 wine_dbgstr_rect(&rcMinimized), wine_dbgstr_rect(&rc));
6608 GetClientRect(hwnd, &rc);
6609 todo_wine
6610 ok(EqualRect(&rcEmpty, &rc), "expected %s, got %s\n",
6611 wine_dbgstr_rect(&rcEmpty), wine_dbgstr_rect(&rc));
6613 ShowWindow(hwnd, SW_RESTORE);
6614 ok(ret, "not expected ret: %lu\n", ret);
6615 style = GetWindowLongA(hwnd, GWL_STYLE);
6616 ok(!(style & WS_DISABLED), "window should not be disabled\n");
6617 ok(style & WS_VISIBLE, "window should be visible\n");
6618 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
6619 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
6620 GetWindowRect(hwnd, &rc);
6621 ok(EqualRect(&rcMain, &rc), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain),
6622 wine_dbgstr_rect(&rc));
6623 GetClientRect(hwnd, &rc);
6624 ok(EqualRect(&rcClient, &rc), "expected %s, got %s\n",
6625 wine_dbgstr_rect(&rcClient), wine_dbgstr_rect(&rc));
6627 ShowWindow(hwnd, SW_MAXIMIZE);
6628 ok(ret, "not expected ret: %lu\n", ret);
6629 style = GetWindowLongA(hwnd, GWL_STYLE);
6630 ok(!(style & WS_DISABLED), "window should not be disabled\n");
6631 ok(style & WS_VISIBLE, "window should be visible\n");
6632 ok(!(style & WS_MINIMIZE), "window should be minimized\n");
6633 ok(style & WS_MAXIMIZE, "window should not be maximized\n");
6634 GetWindowRect(hwnd, &rc);
6635 ok(EqualRect(&rcMaximized, &rc), "expected %s, got %s\n",
6636 wine_dbgstr_rect(&rcMaximized), wine_dbgstr_rect(&rc));
6637 /* maximized windows can be resized */
6638 ret = SetWindowPos(hwnd, 0, 300, 300, 200, 200, SWP_NOACTIVATE | SWP_NOZORDER);
6639 ok(ret, "not expected ret: %lu\n", ret);
6640 SetRect(&rcResized, 300, 300, 500, 500);
6641 GetWindowRect(hwnd, &rc);
6642 ok(EqualRect(&rcResized, &rc), "expected %s, got %s\n",
6643 wine_dbgstr_rect(&rcResized), wine_dbgstr_rect(&rc));
6645 ShowWindow(hwnd, SW_RESTORE);
6646 ok(ret, "not expected ret: %lu\n", ret);
6647 style = GetWindowLongA(hwnd, GWL_STYLE);
6648 ok(!(style & WS_DISABLED), "window should not be disabled\n");
6649 ok(style & WS_VISIBLE, "window should be visible\n");
6650 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
6651 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
6652 GetWindowRect(hwnd, &rc);
6653 ok(EqualRect(&rcMain, &rc), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain),
6654 wine_dbgstr_rect(&rc));
6656 ret = EnableWindow(hwnd, FALSE);
6657 ok(!ret, "not expected ret: %lu\n", ret);
6658 style = GetWindowLongA(hwnd, GWL_STYLE);
6659 ok(style & WS_DISABLED, "window should be disabled\n");
6661 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
6662 ok(!ret, "not expected ret: %lu\n", ret);
6663 style = GetWindowLongA(hwnd, GWL_STYLE);
6664 ok(style & WS_DISABLED, "window should be disabled\n");
6665 ok(style & WS_VISIBLE, "window should be visible\n");
6666 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
6667 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
6668 GetWindowRect(hwnd, &rc);
6669 ok(EqualRect(&rcMain, &rc), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain),
6670 wine_dbgstr_rect(&rc));
6671 GetClientRect(hwnd, &rc);
6672 ok(EqualRect(&rcClient, &rc), "expected %s, got %s\n",
6673 wine_dbgstr_rect(&rcClient), wine_dbgstr_rect(&rc));
6675 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
6676 ok(!ret, "not expected ret: %lu\n", ret);
6677 style = GetWindowLongA(hwnd, GWL_STYLE);
6678 ok(style & WS_DISABLED, "window should be disabled\n");
6679 ok(style & WS_VISIBLE, "window should be visible\n");
6680 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
6681 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
6682 GetWindowRect(hwnd, &rc);
6683 ok(EqualRect(&rcMain, &rc), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain),
6684 wine_dbgstr_rect(&rc));
6685 GetClientRect(hwnd, &rc);
6686 ok(EqualRect(&rcClient, &rc), "expected %s, got %s\n",
6687 wine_dbgstr_rect(&rcClient), wine_dbgstr_rect(&rc));
6689 ret = ShowWindow(hwnd, SW_MINIMIZE);
6690 ok(ret, "not expected ret: %lu\n", ret);
6691 style = GetWindowLongA(hwnd, GWL_STYLE);
6692 ok(style & WS_DISABLED, "window should be disabled\n");
6693 ok(style & WS_VISIBLE, "window should be visible\n");
6694 ok(style & WS_MINIMIZE, "window should be minimized\n");
6695 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
6696 GetWindowRect(hwnd, &rc);
6697 todo_wine
6698 ok(EqualRect(&rcMinimized, &rc), "expected %s, got %s\n",
6699 wine_dbgstr_rect(&rcMinimized), wine_dbgstr_rect(&rc));
6700 GetClientRect(hwnd, &rc);
6701 todo_wine
6702 ok(EqualRect(&rcEmpty, &rc), "expected %s, got %s\n",
6703 wine_dbgstr_rect(&rcEmpty), wine_dbgstr_rect(&rc));
6705 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
6706 ok(!ret, "not expected ret: %lu\n", ret);
6707 style = GetWindowLongA(hwnd, GWL_STYLE);
6708 ok(style & WS_DISABLED, "window should be disabled\n");
6709 ok(style & WS_VISIBLE, "window should be visible\n");
6710 ok(style & WS_MINIMIZE, "window should be minimized\n");
6711 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
6712 GetWindowRect(hwnd, &rc);
6713 todo_wine
6714 ok(EqualRect(&rcMinimized, &rc), "expected %s, got %s\n",
6715 wine_dbgstr_rect(&rcMinimized), wine_dbgstr_rect(&rc));
6716 GetClientRect(hwnd, &rc);
6717 todo_wine
6718 ok(EqualRect(&rcEmpty, &rc), "expected %s, got %s\n",
6719 wine_dbgstr_rect(&rcEmpty), wine_dbgstr_rect(&rc));
6721 ret = ShowWindow(hwnd, SW_RESTORE);
6722 ok(ret, "not expected ret: %lu\n", ret);
6723 style = GetWindowLongA(hwnd, GWL_STYLE);
6724 ok(style & WS_DISABLED, "window should be disabled\n");
6725 ok(style & WS_VISIBLE, "window should be visible\n");
6726 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
6727 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
6728 GetWindowRect(hwnd, &rc);
6729 ok(EqualRect(&rcMain, &rc), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain),
6730 wine_dbgstr_rect(&rc));
6731 GetClientRect(hwnd, &rc);
6732 ok(EqualRect(&rcClient, &rc), "expected %s, got %s\n",
6733 wine_dbgstr_rect(&rcClient), wine_dbgstr_rect(&rc));
6735 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
6736 ok(!ret, "not expected ret: %lu\n", ret);
6737 ok(IsWindow(hwnd), "window should exist\n");
6739 ret = EnableWindow(hwnd, TRUE);
6740 ok(ret, "not expected ret: %lu\n", ret);
6742 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
6743 ok(!ret, "not expected ret: %lu\n", ret);
6744 ok(!IsWindow(hwnd), "window should not exist\n");
6746 hwnd = CreateWindowExA(0, "MainWindowClass", NULL,
6747 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
6748 WS_MAXIMIZEBOX | WS_POPUP | WS_MINIMIZE,
6749 rcMain.left, rcMain.top,
6750 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
6751 0, 0, 0, NULL);
6752 ok(hwnd != NULL, "failed to create window with error %u\n", GetLastError());
6753 style = GetWindowLongA(hwnd, GWL_STYLE);
6754 ok(style & WS_MINIMIZE, "window should be minimized\n");
6755 GetWindowRect(hwnd, &rc);
6756 todo_wine
6757 ok(EqualRect(&rcMinimized, &rc), "expected %s, got %s\n",
6758 wine_dbgstr_rect(&rcMinimized), wine_dbgstr_rect(&rc));
6759 GetClientRect(hwnd, &rc);
6760 todo_wine
6761 ok(EqualRect(&rcEmpty, &rc), "expected %s, got %s\n",
6762 wine_dbgstr_rect(&rcEmpty), wine_dbgstr_rect(&rc));
6763 DestroyWindow(hwnd);
6765 hwnd = CreateWindowExA(0, "MainWindowClass", NULL,
6766 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
6767 WS_MAXIMIZEBOX | WS_POPUP | WS_MINIMIZE | WS_VISIBLE,
6768 rcMain.left, rcMain.top,
6769 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
6770 0, 0, 0, NULL);
6771 ok(hwnd != NULL, "failed to create window with error %u\n", GetLastError());
6772 style = GetWindowLongA(hwnd, GWL_STYLE);
6773 ok(style & WS_MINIMIZE, "window should be minimized\n");
6774 GetWindowRect(hwnd, &rc);
6775 todo_wine
6776 ok(EqualRect(&rcMinimized, &rc), "expected %s, got %s\n",
6777 wine_dbgstr_rect(&rcMinimized), wine_dbgstr_rect(&rc));
6778 GetClientRect(hwnd, &rc);
6779 todo_wine
6780 ok(EqualRect(&rcEmpty, &rc), "expected %s, got %s\n",
6781 wine_dbgstr_rect(&rcEmpty), wine_dbgstr_rect(&rc));
6782 DestroyWindow(hwnd);
6784 flush_events(TRUE);
6787 static DWORD CALLBACK enablewindow_thread(LPVOID arg)
6789 HWND hwnd = arg;
6790 EnableWindow(hwnd, FALSE);
6791 return 0;
6794 static LRESULT CALLBACK enable_window_procA(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
6796 if (msg == WM_CANCELMODE)
6797 return 0;
6798 return DefWindowProcA(hwnd, msg, wParam, lParam);
6801 static void test_EnableWindow(void)
6803 WNDCLASSA cls;
6804 HWND hwnd;
6805 HANDLE hthread;
6806 DWORD tid;
6807 MSG msg;
6809 hwnd = CreateWindowExA(0, "MainWindowClass", NULL, WS_OVERLAPPEDWINDOW,
6810 0, 0, 100, 100, 0, 0, 0, NULL);
6811 assert(hwnd);
6812 ok(IsWindowEnabled(hwnd), "window should be enabled\n");
6813 SetFocus(hwnd);
6814 SetCapture(hwnd);
6816 EnableWindow(hwnd, FALSE);
6817 check_wnd_state(hwnd, hwnd, 0, 0);
6818 ok(!IsWindowEnabled(hwnd), "window should not be enabled\n");
6820 SetFocus(hwnd);
6821 SetCapture(hwnd);
6822 check_wnd_state(hwnd, hwnd, 0, hwnd);
6824 EnableWindow(hwnd, TRUE);
6825 SetFocus(hwnd);
6826 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
6827 ok(IsWindowEnabled(hwnd), "window should be enabled\n");
6829 /* test disabling from thread */
6830 hthread = CreateThread(NULL, 0, enablewindow_thread, hwnd, 0, &tid);
6832 while (MsgWaitForMultipleObjects(1, &hthread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
6834 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE))
6835 DispatchMessageA(&msg);
6838 ok(!IsWindowEnabled(hwnd), "window should not be enabled\n");
6839 check_active_state(hwnd, hwnd, hwnd);
6840 ok(0 == GetCapture(), "GetCapture() = %p\n", GetCapture());
6842 CloseHandle(hthread);
6843 DestroyWindow(hwnd);
6845 /* test preventing release of capture */
6846 memset(&cls, 0, sizeof(cls));
6847 cls.lpfnWndProc = enable_window_procA;
6848 cls.hInstance = GetModuleHandleA(0);
6849 cls.lpszClassName = "EnableWindowClass";
6850 ok(RegisterClassA(&cls), "RegisterClass failed\n");
6852 hwnd = CreateWindowExA(0, "EnableWindowClass", NULL, WS_OVERLAPPEDWINDOW,
6853 0, 0, 100, 100, 0, 0, 0, NULL);
6854 assert(hwnd);
6855 SetFocus(hwnd);
6856 SetCapture(hwnd);
6858 EnableWindow(hwnd, FALSE);
6859 check_wnd_state(hwnd, hwnd, 0, hwnd);
6861 DestroyWindow(hwnd);
6864 static DWORD CALLBACK gettext_msg_thread( LPVOID arg )
6866 HWND hwnd = arg;
6867 char buf[32];
6868 INT buf_len;
6870 /* test GetWindowTextA */
6871 num_gettext_msgs = 0;
6872 memset( buf, 0, sizeof(buf) );
6873 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
6874 ok( buf_len != 0, "expected a nonempty window text\n" );
6875 ok( !strcmp(buf, "another_caption"), "got wrong window text '%s'\n", buf );
6876 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
6878 return 0;
6881 static DWORD CALLBACK settext_msg_thread( LPVOID arg )
6883 HWND hwnd = arg;
6884 BOOL success;
6886 /* test SetWindowTextA */
6887 num_settext_msgs = 0;
6888 success = SetWindowTextA( hwnd, "thread_caption" );
6889 ok( success, "SetWindowTextA failed\n" );
6890 ok( num_settext_msgs == 1, "got %u WM_SETTEXT messages\n", num_settext_msgs );
6892 return 0;
6895 static void test_gettext(void)
6897 static const WCHAR textW[] = {'t','e','x','t'};
6898 DWORD tid, num_msgs;
6899 WCHAR bufW[32];
6900 HANDLE thread;
6901 BOOL success;
6902 char buf[32];
6903 INT buf_len;
6904 HWND hwnd, hwnd2;
6905 LRESULT r;
6906 MSG msg;
6908 hwnd = CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP, 0, 0, 0, 0, 0, 0, 0, NULL );
6909 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
6911 /* test GetWindowTextA */
6912 num_gettext_msgs = 0;
6913 memset( buf, 0, sizeof(buf) );
6914 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
6915 ok( buf_len != 0, "expected a nonempty window text\n" );
6916 ok( !strcmp(buf, "caption"), "got wrong window text '%s'\n", buf );
6917 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
6919 /* other process window */
6920 strcpy( buf, "a" );
6921 buf_len = GetWindowTextA( GetDesktopWindow(), buf, sizeof(buf) );
6922 ok( buf_len == 0, "expected a nonempty window text\n" );
6923 ok( *buf == 0, "got wrong window text '%s'\n", buf );
6925 strcpy( buf, "blah" );
6926 buf_len = GetWindowTextA( GetDesktopWindow(), buf, 0 );
6927 ok( buf_len == 0, "expected a nonempty window text\n" );
6928 ok( !strcmp(buf, "blah"), "got wrong window text '%s'\n", buf );
6930 bufW[0] = 0xcc;
6931 buf_len = GetWindowTextW( GetDesktopWindow(), bufW, 0 );
6932 ok( buf_len == 0, "expected a nonempty window text\n" );
6933 ok( bufW[0] == 0xcc, "got %x\n", bufW[0] );
6935 g_wm_gettext_override.enabled = TRUE;
6937 num_gettext_msgs = 0;
6938 memset( buf, 0xcc, sizeof(buf) );
6939 g_wm_gettext_override.buff = buf;
6940 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
6941 ok( buf_len == 0, "got %d\n", buf_len );
6942 ok( *buf == 0, "got %x\n", *buf );
6943 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
6945 num_gettext_msgs = 0;
6946 strcpy( buf, "blah" );
6947 g_wm_gettext_override.buff = buf;
6948 buf_len = GetWindowTextA( hwnd, buf, 0 );
6949 ok( buf_len == 0, "got %d\n", buf_len );
6950 ok( !strcmp(buf, "blah"), "got %s\n", buf );
6951 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
6953 g_wm_gettext_override.enabled = FALSE;
6955 /* same for W window */
6956 hwnd2 = CreateWindowExW( 0, mainclassW, NULL, WS_POPUP, 0, 0, 0, 0, 0, 0, 0, NULL );
6957 ok( hwnd2 != 0, "CreateWindowExA error %d\n", GetLastError() );
6959 g_wm_gettext_override.enabled = TRUE;
6961 num_gettext_msgs = 0;
6962 memset( bufW, 0xcc, sizeof(bufW) );
6963 g_wm_gettext_override.buffW = bufW;
6964 buf_len = GetWindowTextW( hwnd2, bufW, sizeof(bufW)/sizeof(WCHAR) );
6965 ok( buf_len == 0, "got %d\n", buf_len );
6966 ok( *bufW == 0, "got %x\n", *bufW );
6967 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
6969 num_gettext_msgs = 0;
6970 memset( bufW, 0xcc, sizeof(bufW) );
6971 g_wm_gettext_override.buffW = bufW;
6972 buf_len = GetWindowTextW( hwnd2, bufW, 0 );
6973 ok( buf_len == 0, "got %d\n", buf_len );
6974 ok( *bufW == 0xcccc, "got %x\n", *bufW );
6975 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
6977 g_wm_gettext_override.enabled = FALSE;
6979 DestroyWindow( hwnd2 );
6981 /* test WM_GETTEXT */
6982 num_gettext_msgs = 0;
6983 memset( buf, 0, sizeof(buf) );
6984 r = SendMessageA( hwnd, WM_GETTEXT, sizeof(buf), (LONG_PTR)buf );
6985 ok( r != 0, "expected a nonempty window text\n" );
6986 ok( !strcmp(buf, "caption"), "got wrong window text '%s'\n", buf );
6987 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
6989 /* test SetWindowTextA */
6990 num_settext_msgs = 0;
6991 success = SetWindowTextA( hwnd, "new_caption" );
6992 ok( success, "SetWindowTextA failed\n" );
6993 ok( num_settext_msgs == 1, "got %u WM_SETTEXT messages\n", num_settext_msgs );
6995 num_gettext_msgs = 0;
6996 memset( buf, 0, sizeof(buf) );
6997 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
6998 ok( buf_len != 0, "expected a nonempty window text\n" );
6999 ok( !strcmp(buf, "new_caption"), "got wrong window text '%s'\n", buf );
7000 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
7002 /* test WM_SETTEXT */
7003 num_settext_msgs = 0;
7004 r = SendMessageA( hwnd, WM_SETTEXT, 0, (ULONG_PTR)"another_caption" );
7005 ok( r != 0, "WM_SETTEXT failed\n" );
7006 ok( num_settext_msgs == 1, "got %u WM_SETTEXT messages\n", num_settext_msgs );
7008 num_gettext_msgs = 0;
7009 memset( buf, 0, sizeof(buf) );
7010 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
7011 ok( buf_len != 0, "expected a nonempty window text\n" );
7012 ok( !strcmp(buf, "another_caption"), "got wrong window text '%s'\n", buf );
7013 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
7015 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE ))
7016 DispatchMessageA( &msg );
7018 /* test interthread GetWindowTextA */
7019 num_msgs = 0;
7020 thread = CreateThread( NULL, 0, gettext_msg_thread, hwnd, 0, &tid );
7021 ok(thread != NULL, "CreateThread failed, error %d\n", GetLastError());
7022 while (MsgWaitForMultipleObjects( 1, &thread, FALSE, INFINITE, QS_SENDMESSAGE ) != WAIT_OBJECT_0)
7024 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE ))
7025 DispatchMessageA( &msg );
7026 num_msgs++;
7028 CloseHandle( thread );
7029 ok( num_msgs >= 1, "got %u wakeups from MsgWaitForMultipleObjects\n", num_msgs );
7031 /* test interthread SetWindowText */
7032 num_msgs = 0;
7033 thread = CreateThread( NULL, 0, settext_msg_thread, hwnd, 0, &tid );
7034 ok(thread != NULL, "CreateThread failed, error %d\n", GetLastError());
7035 while (MsgWaitForMultipleObjects( 1, &thread, FALSE, INFINITE, QS_SENDMESSAGE ) != WAIT_OBJECT_0)
7037 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE ))
7038 DispatchMessageA( &msg );
7039 num_msgs++;
7041 CloseHandle( thread );
7042 ok( num_msgs >= 1, "got %u wakeups from MsgWaitForMultipleObjects\n", num_msgs );
7044 num_gettext_msgs = 0;
7045 memset( buf, 0, sizeof(buf) );
7046 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
7047 ok( buf_len != 0, "expected a nonempty window text\n" );
7048 ok( !strcmp(buf, "thread_caption"), "got wrong window text '%s'\n", buf );
7049 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
7051 /* WM_GETTEXT does not terminate returned string */
7052 memset( buf, 0x1c, sizeof(buf) );
7053 g_wm_gettext_override.dont_terminate = TRUE;
7054 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
7055 ok( buf_len == 4, "Unexpected text length, %d\n", buf_len );
7056 ok( !memcmp(buf, "text", 4), "Unexpected window text, '%s'\n", buf );
7057 ok( buf[4] == 0x1c, "Unexpected buffer contents\n" );
7058 g_wm_gettext_override.dont_terminate = FALSE;
7060 memset( bufW, 0x1c, sizeof(bufW) );
7061 g_wm_gettext_override.dont_terminate = TRUE;
7062 buf_len = GetWindowTextW( hwnd, bufW, sizeof(bufW)/sizeof(bufW[0]) );
7063 ok( buf_len == 4, "Unexpected text length, %d\n", buf_len );
7064 ok( !memcmp(bufW, textW, 4 * sizeof(WCHAR)), "Unexpected window text, %s\n", wine_dbgstr_w(bufW) );
7065 ok( bufW[4] == 0, "Unexpected buffer contents, %#x\n", bufW[4] );
7066 g_wm_gettext_override.dont_terminate = FALSE;
7068 hwnd2 = CreateWindowExW( 0, mainclassW, NULL, WS_POPUP, 0, 0, 0, 0, 0, 0, 0, NULL );
7069 ok( hwnd2 != 0, "CreateWindowExA error %d\n", GetLastError() );
7071 memset( buf, 0x1c, sizeof(buf) );
7072 g_wm_gettext_override.dont_terminate = TRUE;
7073 buf_len = GetWindowTextA( hwnd2, buf, sizeof(buf) );
7074 ok( buf_len == 4, "Unexpected text length, %d\n", buf_len );
7075 ok( !memcmp(buf, "text", 4), "Unexpected window text, '%s'\n", buf );
7076 ok( buf[4] == 0, "Unexpected buffer contents, %#x\n", buf[4] );
7077 g_wm_gettext_override.dont_terminate = FALSE;
7079 memset( bufW, 0x1c, sizeof(bufW) );
7080 g_wm_gettext_override.dont_terminate = TRUE;
7081 buf_len = GetWindowTextW( hwnd2, bufW, sizeof(bufW)/sizeof(bufW[0]) );
7082 ok( buf_len == 4, "Unexpected text length, %d\n", buf_len );
7083 ok( !memcmp(bufW, textW, 4 * sizeof(WCHAR)), "Unexpected window text, %s\n", wine_dbgstr_w(bufW) );
7084 ok( bufW[4] == 0x1c1c, "Unexpected buffer contents, %#x\n", bufW[4] );
7085 g_wm_gettext_override.dont_terminate = FALSE;
7087 DestroyWindow(hwnd2);
7089 /* seems to crash on every modern Windows version */
7090 if (0)
7092 r = SendMessageA( hwnd, WM_GETTEXT, 0x10, 0x1000);
7093 ok( r == 0, "settext should return zero\n");
7095 r = SendMessageA( hwnd, WM_GETTEXT, 0x10000, 0);
7096 ok( r == 0, "settext should return zero (%ld)\n", r);
7098 r = SendMessageA( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
7099 ok( r == 0, "settext should return zero (%ld)\n", r);
7101 r = SendMessageA( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
7102 ok( r == 0, "settext should return zero (%ld)\n", r);
7105 DestroyWindow(hwnd);
7109 static void test_GetUpdateRect(void)
7111 MSG msg;
7112 BOOL ret, parent_wm_paint, grandparent_wm_paint;
7113 RECT rc1, rc2;
7114 HWND hgrandparent, hparent, hchild;
7115 WNDCLASSA cls;
7116 static const char classNameA[] = "GetUpdateRectClass";
7118 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
7119 0, 0, 100, 100, NULL, NULL, 0, NULL);
7121 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
7122 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
7124 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
7125 10, 10, 30, 30, hparent, NULL, 0, NULL);
7127 ShowWindow(hgrandparent, SW_SHOW);
7128 UpdateWindow(hgrandparent);
7129 flush_events( TRUE );
7131 ShowWindow(hchild, SW_HIDE);
7132 SetRectEmpty(&rc2);
7133 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
7134 ok(!ret, "GetUpdateRect returned not empty region\n");
7135 ok(EqualRect(&rc1, &rc2), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1),
7136 wine_dbgstr_rect(&rc2));
7138 SetRect(&rc2, 10, 10, 40, 40);
7139 ret = GetUpdateRect(hparent, &rc1, FALSE);
7140 ok(ret, "GetUpdateRect returned empty region\n");
7141 ok(EqualRect(&rc1, &rc2), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1),
7142 wine_dbgstr_rect(&rc2));
7144 parent_wm_paint = FALSE;
7145 grandparent_wm_paint = FALSE;
7146 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
7148 if (msg.message == WM_PAINT)
7150 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
7151 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
7153 DispatchMessageA(&msg);
7155 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
7156 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
7158 DestroyWindow(hgrandparent);
7160 cls.style = 0;
7161 cls.lpfnWndProc = DefWindowProcA;
7162 cls.cbClsExtra = 0;
7163 cls.cbWndExtra = 0;
7164 cls.hInstance = GetModuleHandleA(0);
7165 cls.hIcon = 0;
7166 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
7167 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7168 cls.lpszMenuName = NULL;
7169 cls.lpszClassName = classNameA;
7171 if(!RegisterClassA(&cls)) {
7172 trace("Register failed %d\n", GetLastError());
7173 return;
7176 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
7177 0, 0, 100, 100, NULL, NULL, 0, NULL);
7179 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
7180 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
7182 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
7183 10, 10, 30, 30, hparent, NULL, 0, NULL);
7185 ShowWindow(hgrandparent, SW_SHOW);
7186 UpdateWindow(hgrandparent);
7187 flush_events( TRUE );
7189 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
7190 ok(!ret, "GetUpdateRect returned not empty region\n");
7192 ShowWindow(hchild, SW_HIDE);
7194 SetRectEmpty(&rc2);
7195 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
7196 ok(!ret, "GetUpdateRect returned not empty region\n");
7197 ok(EqualRect(&rc1, &rc2), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1),
7198 wine_dbgstr_rect(&rc2));
7200 SetRect(&rc2, 10, 10, 40, 40);
7201 ret = GetUpdateRect(hparent, &rc1, FALSE);
7202 ok(ret, "GetUpdateRect returned empty region\n");
7203 ok(EqualRect(&rc1, &rc2), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1),
7204 wine_dbgstr_rect(&rc2));
7206 parent_wm_paint = FALSE;
7207 grandparent_wm_paint = FALSE;
7208 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
7210 if (msg.message == WM_PAINT)
7212 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
7213 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
7215 DispatchMessageA(&msg);
7217 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
7218 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
7220 DestroyWindow(hgrandparent);
7224 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
7226 if(msg == WM_PAINT)
7228 PAINTSTRUCT ps;
7229 RECT updateRect;
7230 DWORD waitResult;
7231 HWND win;
7232 const int waitTime = 2000;
7234 BeginPaint(hwnd, &ps);
7236 /* create and destroy window to create an exposed region on this window */
7237 win = CreateWindowA("static", "win", WS_VISIBLE,
7238 10,10,50,50, NULL, NULL, 0, NULL);
7239 DestroyWindow(win);
7241 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
7243 ValidateRect(hwnd, NULL);
7244 EndPaint(hwnd, &ps);
7246 if(waitResult != WAIT_TIMEOUT)
7248 GetUpdateRect(hwnd, &updateRect, FALSE);
7249 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
7252 return 1;
7254 return DefWindowProcA(hwnd, msg, wParam, lParam);
7257 static void test_Expose(void)
7259 WNDCLASSA cls;
7260 HWND mw;
7262 memset(&cls, 0, sizeof(WNDCLASSA));
7263 cls.lpfnWndProc = TestExposedRegion_WndProc;
7264 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7265 cls.lpszClassName = "TestExposeClass";
7266 RegisterClassA(&cls);
7268 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
7269 0, 0, 200, 100, NULL, NULL, 0, NULL);
7271 UpdateWindow(mw);
7272 DestroyWindow(mw);
7275 static LRESULT CALLBACK TestNCRedraw_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
7277 static UINT ncredrawflags;
7278 PAINTSTRUCT ps;
7280 switch(msg)
7282 case WM_CREATE:
7283 ncredrawflags = *(UINT *) (((CREATESTRUCTA *)lParam)->lpCreateParams);
7284 return 0;
7285 case WM_NCPAINT:
7286 RedrawWindow(hwnd, NULL, NULL, ncredrawflags);
7287 break;
7288 case WM_PAINT:
7289 BeginPaint(hwnd, &ps);
7290 EndPaint(hwnd, &ps);
7291 return 0;
7293 return DefWindowProcA(hwnd, msg, wParam, lParam);
7296 static void run_NCRedrawLoop(UINT flags)
7298 HWND hwnd;
7299 MSG msg;
7301 UINT loopcount = 0;
7303 hwnd = CreateWindowA("TestNCRedrawClass", "MainWindow",
7304 WS_OVERLAPPEDWINDOW, 0, 0, 200, 100,
7305 NULL, NULL, 0, &flags);
7306 ShowWindow(hwnd, SW_SHOW);
7307 UpdateWindow(hwnd);
7308 flush_events( FALSE );
7309 while (PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE))
7311 if (msg.message == WM_PAINT) loopcount++;
7312 if (loopcount >= 100) break;
7313 TranslateMessage(&msg);
7314 DispatchMessageA(&msg);
7315 MsgWaitForMultipleObjects(0, NULL, FALSE, 100, QS_ALLINPUT);
7317 todo_wine_if (flags == (RDW_INVALIDATE | RDW_FRAME))
7318 ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
7319 DestroyWindow(hwnd);
7322 static void test_NCRedraw(void)
7324 WNDCLASSA wndclass;
7326 wndclass.lpszClassName = "TestNCRedrawClass";
7327 wndclass.style = CS_HREDRAW | CS_VREDRAW;
7328 wndclass.lpfnWndProc = TestNCRedraw_WndProc;
7329 wndclass.cbClsExtra = 0;
7330 wndclass.cbWndExtra = 0;
7331 wndclass.hInstance = 0;
7332 wndclass.hIcon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
7333 wndclass.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
7334 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
7335 wndclass.lpszMenuName = NULL;
7337 RegisterClassA(&wndclass);
7339 run_NCRedrawLoop(RDW_INVALIDATE | RDW_FRAME);
7340 run_NCRedrawLoop(RDW_INVALIDATE);
7343 static void test_GetWindowModuleFileName(void)
7345 HWND hwnd;
7346 HINSTANCE hinst;
7347 UINT ret1, ret2;
7348 char buf1[MAX_PATH], buf2[MAX_PATH];
7350 if (!pGetWindowModuleFileNameA)
7352 win_skip("GetWindowModuleFileNameA is not available\n");
7353 return;
7356 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
7357 assert(hwnd);
7359 hinst = (HINSTANCE)GetWindowLongPtrA(hwnd, GWLP_HINSTANCE);
7360 ok(hinst == 0 || broken(hinst == GetModuleHandleA(NULL)), /* win9x */ "expected 0, got %p\n", hinst);
7362 buf1[0] = 0;
7363 SetLastError(0xdeadbeef);
7364 ret1 = GetModuleFileNameA(hinst, buf1, sizeof(buf1));
7365 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
7367 buf2[0] = 0;
7368 SetLastError(0xdeadbeef);
7369 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
7370 ok(ret2 || broken(!ret2), /* nt4 sp 3 */
7371 "GetWindowModuleFileNameA error %u\n", GetLastError());
7373 if (ret2)
7375 ok(ret1 == ret2 || broken(ret2 == ret1 + 1), /* win98 */ "%u != %u\n", ret1, ret2);
7376 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
7378 hinst = GetModuleHandleA(NULL);
7380 SetLastError(0xdeadbeef);
7381 ret2 = GetModuleFileNameA(hinst, buf2, ret1 - 2);
7382 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
7383 "expected %u, got %u\n", ret1 - 2, ret2);
7384 ok(GetLastError() == 0xdeadbeef /* XP */ ||
7385 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
7386 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
7388 SetLastError(0xdeadbeef);
7389 ret2 = GetModuleFileNameA(hinst, buf2, 0);
7390 ok(!ret2, "GetModuleFileName should return 0\n");
7391 ok(GetLastError() == 0xdeadbeef /* XP */ ||
7392 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
7393 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
7395 SetLastError(0xdeadbeef);
7396 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
7397 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3) /* win98 */ || broken(!ret2), /* nt4 sp3 */
7398 "expected %u, got %u\n", ret1 - 2, ret2);
7399 ok(GetLastError() == 0xdeadbeef /* XP */ ||
7400 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
7401 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
7403 SetLastError(0xdeadbeef);
7404 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
7405 ok(!ret2, "expected 0, got %u\n", ret2);
7406 ok(GetLastError() == 0xdeadbeef /* XP */ ||
7407 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
7408 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
7410 DestroyWindow(hwnd);
7412 buf2[0] = 0;
7413 hwnd = (HWND)0xdeadbeef;
7414 SetLastError(0xdeadbeef);
7415 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
7416 ok(!ret1, "expected 0, got %u\n", ret1);
7417 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef), /* win9x */
7418 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
7420 hwnd = FindWindowA("Shell_TrayWnd", NULL);
7421 ok(IsWindow(hwnd) || broken(!hwnd), "got invalid tray window %p\n", hwnd);
7422 SetLastError(0xdeadbeef);
7423 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
7424 ok(!ret1 || broken(ret1), /* win98 */ "expected 0, got %u\n", ret1);
7426 if (!ret1) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
7428 ret1 = GetModuleFileNameA(0, buf1, sizeof(buf1));
7429 hwnd = GetDesktopWindow();
7430 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
7431 SetLastError(0xdeadbeef);
7432 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
7433 ok(!ret2 ||
7434 ret1 == ret2 || /* vista */
7435 broken(ret2), /* some win98 return user.exe as file name */
7436 "expected 0 or %u, got %u %s\n", ret1, ret2, buf2);
7440 static void test_hwnd_message(void)
7442 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
7443 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
7445 HWND parent = 0, hwnd, found;
7446 RECT rect;
7447 static const struct
7449 int offset;
7450 ULONG_PTR expect;
7451 DWORD error;
7453 tests[] =
7455 { GWLP_USERDATA, 0, 0 },
7456 { GWL_STYLE, WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0 },
7457 { GWL_EXSTYLE, 0, 0 },
7458 { GWLP_ID, 0, 0 },
7459 /* GWLP_HWNDPARENT - returns random values */
7460 /* GWLP_HINSTANCE - not useful and not consistent between Windows versions */
7461 { GWLP_WNDPROC, 0, ERROR_ACCESS_DENIED },
7462 { DWLP_MSGRESULT, 0, ERROR_INVALID_INDEX }
7464 DWORD_PTR result;
7465 int i;
7467 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
7468 on CreateWindowExA and crash later in the test.
7469 Use UNICODE here to fail on win9x */
7470 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
7471 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
7472 if (!hwnd)
7474 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
7475 return;
7478 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
7479 if (pGetAncestor)
7481 char buffer[100];
7482 HWND root, desktop = GetDesktopWindow();
7484 parent = pGetAncestor(hwnd, GA_PARENT);
7485 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
7486 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
7487 root = pGetAncestor(hwnd, GA_ROOT);
7488 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
7489 ok( !pGetAncestor(parent, GA_PARENT),
7490 "parent shouldn't have parent %p\n", pGetAncestor(parent, GA_PARENT) );
7491 trace("parent %p root %p desktop %p\n", parent, root, desktop);
7492 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
7493 ok( !lstrcmpiA( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
7494 GetWindowRect( parent, &rect );
7495 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
7496 "wrong parent rect %s\n", wine_dbgstr_rect( &rect ));
7498 GetWindowRect( hwnd, &rect );
7499 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
7500 "wrong window rect %s\n", wine_dbgstr_rect( &rect ));
7502 /* test FindWindow behavior */
7504 found = FindWindowExA( 0, 0, 0, "message window" );
7505 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
7506 SetLastError(0xdeadbeef);
7507 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
7508 ok( found == 0, "found message window %p/%p\n", found, hwnd );
7509 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
7510 if (parent)
7512 found = FindWindowExA( parent, 0, 0, "message window" );
7513 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
7516 /* test IsChild behavior */
7518 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
7520 /* test IsWindowVisible behavior */
7522 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
7523 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
7525 /* GetWindowLong */
7526 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
7528 SetLastError( 0xdeadbeef );
7529 result = GetWindowLongPtrW( parent, tests[i].offset );
7530 ok( result == tests[i].expect, "offset %d, got %08lx expect %08lx\n",
7531 tests[i].offset, result, tests[i].expect );
7532 if (tests[i].error)
7533 ok( GetLastError() == tests[i].error, "offset %d: error %d expect %d\n",
7534 tests[i].offset, GetLastError(), tests[i].error );
7535 else
7536 ok( GetLastError() == 0xdeadbeef, "offset %d: error %d expect unchanged\n",
7537 tests[i].offset, GetLastError() );
7540 DestroyWindow(hwnd);
7543 static void test_layered_window(void)
7545 HWND hwnd, child;
7546 COLORREF key = 0;
7547 BYTE alpha = 0;
7548 DWORD flags = 0;
7549 POINT pt = { 0, 0 };
7550 SIZE sz = { 200, 200 };
7551 HDC hdc;
7552 HBITMAP hbm;
7553 BOOL ret;
7554 MSG msg;
7556 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes || !pUpdateLayeredWindow)
7558 win_skip( "layered windows not supported\n" );
7559 return;
7562 hdc = CreateCompatibleDC( 0 );
7563 hbm = CreateCompatibleBitmap( hdc, 200, 200 );
7564 SelectObject( hdc, hbm );
7566 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
7567 100, 100, 200, 200, 0, 0, 0, NULL);
7568 assert( hwnd );
7569 SetLastError( 0xdeadbeef );
7570 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
7571 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
7572 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
7573 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
7574 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
7575 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
7576 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
7577 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
7578 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
7579 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
7580 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
7581 ok( ret, "UpdateLayeredWindow should succeed on layered window\n" );
7582 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
7583 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
7584 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
7585 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
7586 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
7587 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
7588 ok( key == 0x123456 || key == 0, "wrong color key %x\n", key );
7589 ok( alpha == 44, "wrong alpha %u\n", alpha );
7590 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
7591 SetLastError( 0xdeadbeef );
7592 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
7593 ok( !ret, "UpdateLayeredWindow should fail on layered but initialized window\n" );
7594 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
7596 /* clearing WS_EX_LAYERED resets attributes */
7597 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
7598 SetLastError( 0xdeadbeef );
7599 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
7600 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
7601 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
7602 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
7603 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
7604 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
7605 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
7606 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
7607 ok( ret, "UpdateLayeredWindow should succeed on layered window\n" );
7608 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE | ULW_EX_NORESIZE );
7609 ok( !ret, "UpdateLayeredWindow should fail with ex flag\n" );
7610 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
7611 if (pUpdateLayeredWindowIndirect)
7613 UPDATELAYEREDWINDOWINFO info;
7614 info.cbSize = sizeof(info);
7615 info.hdcDst = 0;
7616 info.pptDst = NULL;
7617 info.psize = &sz;
7618 info.hdcSrc = hdc;
7619 info.pptSrc = &pt;
7620 info.crKey = 0;
7621 info.pblend = NULL;
7622 info.dwFlags = ULW_OPAQUE | ULW_EX_NORESIZE;
7623 info.prcDirty = NULL;
7624 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
7625 ok( ret, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
7626 sz.cx--;
7627 SetLastError(0);
7628 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
7629 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
7630 /* particular error code differs from version to version, could be ERROR_INCORRECT_SIZE,
7631 ERROR_MR_MID_NOT_FOUND or ERROR_GEN_FAILURE (Win8/Win10) */
7632 ok( GetLastError() != 0, "wrong error %u\n", GetLastError() );
7633 info.dwFlags = ULW_OPAQUE;
7634 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
7635 ok( ret, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
7636 sz.cx++;
7637 info.dwFlags = ULW_OPAQUE | 0xf00;
7638 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
7639 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
7640 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
7641 info.cbSize--;
7642 info.dwFlags = ULW_OPAQUE;
7643 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
7644 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
7645 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
7646 ret = pUpdateLayeredWindowIndirect( hwnd, NULL );
7647 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
7648 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
7651 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
7652 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
7653 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
7654 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
7655 ok( key == 0x654321, "wrong color key %x\n", key );
7656 ok( alpha == 22, "wrong alpha %u\n", alpha );
7657 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
7658 SetLastError( 0xdeadbeef );
7659 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
7660 ok( !ret, "UpdateLayeredWindow should fail on layered but initialized window\n" );
7661 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
7663 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
7664 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
7665 alpha = 0;
7666 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
7667 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
7668 ok( key == 0x888888, "wrong color key %x\n", key );
7669 /* alpha not changed on vista if LWA_ALPHA is not set */
7670 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
7671 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
7673 /* color key may or may not be changed without LWA_COLORKEY */
7674 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
7675 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
7676 alpha = 0;
7677 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
7678 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
7679 ok( key == 0x888888 || key == 0x999999, "wrong color key %x\n", key );
7680 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
7681 ok( flags == 0, "wrong flags %x\n", flags );
7683 /* default alpha and color key is 0 */
7684 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
7685 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
7686 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
7687 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
7688 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
7689 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
7690 ok( key == 0 || key == 0x222222, "wrong color key %x\n", key );
7691 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
7692 ok( flags == 0, "wrong flags %x\n", flags );
7694 /* test layered window with WS_CLIPCHILDREN flag */
7695 SetWindowLongA( hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) | WS_CLIPCHILDREN );
7696 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
7697 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
7698 child = CreateWindowExA( 0, "button", "button", WS_VISIBLE | WS_CHILD,
7699 0, 0, 50, 50, hwnd, 0, 0, NULL );
7700 ok( child != NULL, "CreateWindowEx error %u\n", GetLastError() );
7701 ShowWindow( hwnd, SW_SHOW );
7703 ret = pSetLayeredWindowAttributes( hwnd, 0, 255, LWA_ALPHA );
7704 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
7705 while (GetMessageA(&msg, 0, 0, 0))
7707 DispatchMessageA(&msg);
7709 if (msg.message == WM_PAINT && msg.hwnd == child)
7710 break;
7713 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
7714 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
7715 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
7716 ok( ret, "UpdateLayeredWindow should succeed on layered window\n" );
7718 ret = pSetLayeredWindowAttributes( hwnd, 0, 255, LWA_ALPHA );
7719 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
7720 while (GetMessageA(&msg, 0, 0, 0))
7722 DispatchMessageA(&msg);
7724 if (msg.message == WM_PAINT && msg.hwnd == child)
7725 break;
7728 DestroyWindow( hwnd );
7729 DeleteDC( hdc );
7730 DeleteObject( hbm );
7733 static MONITORINFO mi;
7735 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
7737 switch (msg)
7739 case WM_NCCREATE:
7741 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
7742 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
7743 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
7744 "expected %s, got (%d,%d)-(%d,%d)\n", wine_dbgstr_rect(&mi.rcMonitor),
7745 cs->x, cs->y, cs->cx, cs->cy);
7746 break;
7748 case WM_GETMINMAXINFO:
7750 MINMAXINFO *minmax = (MINMAXINFO *)lp;
7751 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
7752 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
7753 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
7754 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
7755 break;
7758 return DefWindowProcA(hwnd, msg, wp, lp);
7761 static void test_fullscreen(void)
7763 static const DWORD t_style[] = {
7764 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
7766 static const DWORD t_ex_style[] = {
7767 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
7769 WNDCLASSA cls;
7770 HWND hwnd;
7771 int i, j;
7772 POINT pt;
7773 RECT rc;
7774 HMONITOR hmon;
7775 LRESULT ret;
7777 if (!pGetMonitorInfoA || !pMonitorFromPoint)
7779 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
7780 return;
7783 pt.x = pt.y = 0;
7784 SetLastError(0xdeadbeef);
7785 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
7786 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
7788 mi.cbSize = sizeof(mi);
7789 SetLastError(0xdeadbeef);
7790 ret = pGetMonitorInfoA(hmon, &mi);
7791 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
7792 trace("monitor %s, work %s\n", wine_dbgstr_rect(&mi.rcMonitor), wine_dbgstr_rect(&mi.rcWork));
7794 cls.style = 0;
7795 cls.lpfnWndProc = fullscreen_wnd_proc;
7796 cls.cbClsExtra = 0;
7797 cls.cbWndExtra = 0;
7798 cls.hInstance = GetModuleHandleA(NULL);
7799 cls.hIcon = 0;
7800 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
7801 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7802 cls.lpszMenuName = NULL;
7803 cls.lpszClassName = "fullscreen_class";
7804 RegisterClassA(&cls);
7806 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
7808 DWORD style, ex_style;
7810 /* avoid a WM interaction */
7811 assert(!(t_style[i] & WS_VISIBLE));
7813 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
7815 int fixup;
7817 style = t_style[i];
7818 ex_style = t_ex_style[j];
7820 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
7821 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
7822 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
7823 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
7824 GetWindowRect(hwnd, &rc);
7825 trace("%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7826 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
7827 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
7828 "%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7829 DestroyWindow(hwnd);
7831 style = t_style[i] | WS_MAXIMIZE;
7832 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
7833 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
7834 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
7835 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
7836 GetWindowRect(hwnd, &rc);
7837 trace("%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7838 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
7839 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
7840 "%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7841 DestroyWindow(hwnd);
7843 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
7844 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
7845 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
7846 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
7847 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
7848 GetWindowRect(hwnd, &rc);
7849 trace("%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7850 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
7851 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
7852 "%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7853 DestroyWindow(hwnd);
7855 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
7856 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
7857 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
7858 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
7859 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
7860 GetWindowRect(hwnd, &rc);
7861 trace("%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7862 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
7863 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
7864 "%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7865 DestroyWindow(hwnd);
7867 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
7868 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
7869 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
7870 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
7871 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
7872 GetWindowRect(hwnd, &rc);
7873 trace("%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7874 /* Windows makes a maximized window slightly larger (to hide the borders?) */
7875 fixup = min(abs(rc.left), abs(rc.top));
7876 InflateRect(&rc, -fixup, -fixup);
7877 ok(rc.left >= mi.rcMonitor.left && rc.top >= mi.rcMonitor.top &&
7878 rc.right <= mi.rcMonitor.right && rc.bottom <= mi.rcMonitor.bottom,
7879 "%#x/%#x: window rect %s must be in %s\n", ex_style, style, wine_dbgstr_rect(&rc),
7880 wine_dbgstr_rect(&mi.rcMonitor));
7881 DestroyWindow(hwnd);
7883 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
7884 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
7885 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
7886 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
7887 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
7888 GetWindowRect(hwnd, &rc);
7889 trace("%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7890 /* Windows makes a maximized window slightly larger (to hide the borders?) */
7891 fixup = min(abs(rc.left), abs(rc.top));
7892 InflateRect(&rc, -fixup, -fixup);
7893 if (style & (WS_CHILD | WS_POPUP))
7894 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
7895 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
7896 "%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7897 else
7898 ok(rc.left >= mi.rcMonitor.left && rc.top >= mi.rcMonitor.top &&
7899 rc.right <= mi.rcMonitor.right && rc.bottom <= mi.rcMonitor.bottom,
7900 "%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7901 DestroyWindow(hwnd);
7905 UnregisterClassA("fullscreen_class", GetModuleHandleA(NULL));
7908 static BOOL test_thick_child_got_minmax;
7909 static const char * test_thick_child_name;
7910 static LONG test_thick_child_style;
7911 static LONG test_thick_child_exStyle;
7913 static LRESULT WINAPI test_thick_child_size_winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
7915 MINMAXINFO* minmax;
7916 int expectedMinTrackX;
7917 int expectedMinTrackY;
7918 int actualMinTrackX;
7919 int actualMinTrackY;
7920 int expectedMaxTrackX;
7921 int expectedMaxTrackY;
7922 int actualMaxTrackX;
7923 int actualMaxTrackY;
7924 int expectedMaxSizeX;
7925 int expectedMaxSizeY;
7926 int actualMaxSizeX;
7927 int actualMaxSizeY;
7928 int expectedPosX;
7929 int expectedPosY;
7930 int actualPosX;
7931 int actualPosY;
7932 LONG adjustedStyle;
7933 RECT rect;
7934 switch (msg)
7936 case WM_GETMINMAXINFO:
7938 minmax = (MINMAXINFO *)lparam;
7939 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
7940 dump_minmax_info( minmax );
7942 test_thick_child_got_minmax = TRUE;
7945 adjustedStyle = test_thick_child_style;
7946 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
7947 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
7948 GetClientRect(GetParent(hwnd), &rect);
7949 AdjustWindowRectEx(&rect, adjustedStyle, FALSE, test_thick_child_exStyle);
7951 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
7953 expectedMinTrackX = GetSystemMetrics(SM_CXMINTRACK);
7954 expectedMinTrackY = GetSystemMetrics(SM_CYMINTRACK);
7956 else
7958 expectedMinTrackX = -2 * rect.left;
7959 expectedMinTrackY = -2 * rect.top;
7961 actualMinTrackX = minmax->ptMinTrackSize.x;
7962 actualMinTrackY = minmax->ptMinTrackSize.y;
7964 ok(actualMinTrackX == expectedMinTrackX && actualMinTrackY == expectedMinTrackY,
7965 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
7966 expectedMinTrackX, expectedMinTrackY, actualMinTrackX, actualMinTrackY,
7967 test_thick_child_name);
7969 actualMaxTrackX = minmax->ptMaxTrackSize.x;
7970 actualMaxTrackY = minmax->ptMaxTrackSize.y;
7971 expectedMaxTrackX = GetSystemMetrics(SM_CXMAXTRACK);
7972 expectedMaxTrackY = GetSystemMetrics(SM_CYMAXTRACK);
7973 ok(actualMaxTrackX == expectedMaxTrackX && actualMaxTrackY == expectedMaxTrackY,
7974 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
7975 expectedMaxTrackX, expectedMaxTrackY, actualMaxTrackX, actualMaxTrackY,
7976 test_thick_child_name);
7978 expectedMaxSizeX = rect.right - rect.left;
7979 expectedMaxSizeY = rect.bottom - rect.top;
7980 actualMaxSizeX = minmax->ptMaxSize.x;
7981 actualMaxSizeY = minmax->ptMaxSize.y;
7983 ok(actualMaxSizeX == expectedMaxSizeX && actualMaxSizeY == expectedMaxSizeY,
7984 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
7985 expectedMaxSizeX, expectedMaxSizeY, actualMaxSizeX, actualMaxSizeY,
7986 test_thick_child_name);
7989 expectedPosX = rect.left;
7990 expectedPosY = rect.top;
7991 actualPosX = minmax->ptMaxPosition.x;
7992 actualPosY = minmax->ptMaxPosition.y;
7993 ok(actualPosX == expectedPosX && actualPosY == expectedPosY,
7994 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
7995 expectedPosX, expectedPosY, actualPosX, actualPosY, test_thick_child_name);
7997 break;
8001 return DefWindowProcA(hwnd, msg, wparam, lparam);
8004 #define NUMBER_OF_THICK_CHILD_TESTS 16
8005 static void test_thick_child_size(HWND parentWindow)
8007 BOOL success;
8008 RECT childRect;
8009 RECT adjustedParentRect;
8010 HWND childWindow;
8011 LONG childWidth;
8012 LONG childHeight;
8013 LONG expectedWidth;
8014 LONG expectedHeight;
8015 WNDCLASSA cls;
8016 static const char className[] = "THICK_CHILD_CLASS";
8017 int i;
8018 LONG adjustedStyle;
8019 static const LONG styles[NUMBER_OF_THICK_CHILD_TESTS] = {
8020 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
8021 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
8022 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
8023 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
8024 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
8025 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
8026 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
8027 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
8028 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
8029 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
8030 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
8031 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
8032 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
8033 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
8034 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
8035 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
8038 static const LONG exStyles[NUMBER_OF_THICK_CHILD_TESTS] = {
8043 WS_EX_DLGMODALFRAME,
8044 WS_EX_DLGMODALFRAME,
8045 WS_EX_DLGMODALFRAME,
8046 WS_EX_DLGMODALFRAME,
8047 WS_EX_STATICEDGE,
8048 WS_EX_STATICEDGE,
8049 WS_EX_STATICEDGE,
8050 WS_EX_STATICEDGE,
8051 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
8052 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
8053 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
8054 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
8056 static const char *styleName[NUMBER_OF_THICK_CHILD_TESTS] = {
8057 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
8058 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
8059 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
8060 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
8061 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
8062 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
8063 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
8064 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
8065 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
8066 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
8067 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
8068 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
8069 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
8070 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
8071 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
8072 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
8075 cls.style = 0;
8076 cls.lpfnWndProc = test_thick_child_size_winproc;
8077 cls.cbClsExtra = 0;
8078 cls.cbWndExtra = 0;
8079 cls.hInstance = GetModuleHandleA(0);
8080 cls.hIcon = 0;
8081 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
8082 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
8083 cls.lpszMenuName = NULL;
8084 cls.lpszClassName = className;
8085 SetLastError(0xdeadbeef);
8086 success = RegisterClassA(&cls);
8087 ok(success,"RegisterClassA failed, error: %u\n", GetLastError());
8089 for(i = 0; i < NUMBER_OF_THICK_CHILD_TESTS; i++)
8091 test_thick_child_name = styleName[i];
8092 test_thick_child_style = styles[i];
8093 test_thick_child_exStyle = exStyles[i];
8094 test_thick_child_got_minmax = FALSE;
8096 SetLastError(0xdeadbeef);
8097 childWindow = CreateWindowExA( exStyles[i], className, "", styles[i], 0, 0, 0, 0, parentWindow, 0, GetModuleHandleA(0), NULL );
8098 ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
8100 ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
8102 SetLastError(0xdeadbeef);
8103 success = GetWindowRect(childWindow, &childRect);
8104 ok(success,"GetWindowRect call failed, error: %u\n", GetLastError());
8105 childWidth = childRect.right - childRect.left;
8106 childHeight = childRect.bottom - childRect.top;
8108 adjustedStyle = styles[i];
8109 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
8110 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
8111 GetClientRect(GetParent(childWindow), &adjustedParentRect);
8112 AdjustWindowRectEx(&adjustedParentRect, adjustedStyle, FALSE, test_thick_child_exStyle);
8115 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
8117 expectedWidth = GetSystemMetrics(SM_CXMINTRACK);
8118 expectedHeight = GetSystemMetrics(SM_CYMINTRACK);
8120 else
8122 expectedWidth = -2 * adjustedParentRect.left;
8123 expectedHeight = -2 * adjustedParentRect.top;
8126 ok((childWidth == expectedWidth) && (childHeight == expectedHeight),
8127 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
8128 test_thick_child_name, expectedWidth, expectedHeight, childWidth, childHeight);
8130 SetLastError(0xdeadbeef);
8131 success = DestroyWindow(childWindow);
8132 ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
8134 ok(UnregisterClassA(className, GetModuleHandleA(NULL)),"UnregisterClass call failed\n");
8137 static void test_handles( HWND full_hwnd )
8139 HWND hwnd = full_hwnd;
8140 BOOL ret;
8141 RECT rect;
8143 SetLastError( 0xdeadbeef );
8144 ret = GetWindowRect( hwnd, &rect );
8145 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
8147 #ifdef _WIN64
8148 if ((ULONG_PTR)full_hwnd >> 32)
8149 hwnd = (HWND)((ULONG_PTR)full_hwnd & ~0u);
8150 else
8151 hwnd = (HWND)((ULONG_PTR)full_hwnd | ((ULONG_PTR)~0u << 32));
8152 SetLastError( 0xdeadbeef );
8153 ret = GetWindowRect( hwnd, &rect );
8154 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
8156 hwnd = (HWND)(((ULONG_PTR)full_hwnd & ~0u) | ((ULONG_PTR)0x1234 << 32));
8157 SetLastError( 0xdeadbeef );
8158 ret = GetWindowRect( hwnd, &rect );
8159 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
8161 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x9876 << 16));
8162 SetLastError( 0xdeadbeef );
8163 ret = GetWindowRect( hwnd, &rect );
8164 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
8165 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
8167 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x12345678 << 16));
8168 SetLastError( 0xdeadbeef );
8169 ret = GetWindowRect( hwnd, &rect );
8170 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
8171 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
8172 #endif
8175 static void test_winregion(void)
8177 HWND hwnd;
8178 RECT r;
8179 int ret, width;
8180 HRGN hrgn;
8182 if (!pGetWindowRgnBox)
8184 win_skip("GetWindowRgnBox not supported\n");
8185 return;
8188 hwnd = CreateWindowExA(0, "static", NULL, WS_VISIBLE, 10, 10, 10, 10, NULL, 0, 0, NULL);
8189 /* NULL prect */
8190 SetLastError(0xdeadbeef);
8191 ret = pGetWindowRgnBox(hwnd, NULL);
8192 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
8193 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
8195 hrgn = CreateRectRgn(2, 3, 10, 15);
8196 ok( hrgn != NULL, "Region creation failed\n");
8197 if (hrgn)
8199 SetWindowRgn(hwnd, hrgn, FALSE);
8201 SetLastError(0xdeadbeef);
8202 ret = pGetWindowRgnBox(hwnd, NULL);
8203 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
8204 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
8206 SetRectEmpty(&r);
8207 ret = pGetWindowRgnBox(hwnd, &r);
8208 ok( ret == SIMPLEREGION, "Expected SIMPLEREGION, got %d\n", ret);
8209 ok( r.left == 2 && r.top == 3 && r.right == 10 && r.bottom == 15,
8210 "Expected (2,3)-(10,15), got %s\n", wine_dbgstr_rect( &r ));
8211 if (pMirrorRgn)
8213 hrgn = CreateRectRgn(2, 3, 10, 15);
8214 ret = pMirrorRgn( hwnd, hrgn );
8215 ok( ret == TRUE, "MirrorRgn failed %u\n", ret );
8216 SetRectEmpty(&r);
8217 GetWindowRect( hwnd, &r );
8218 width = r.right - r.left;
8219 SetRectEmpty(&r);
8220 ret = GetRgnBox( hrgn, &r );
8221 ok( ret == SIMPLEREGION, "GetRgnBox failed %u\n", ret );
8222 ok( r.left == width - 10 && r.top == 3 && r.right == width - 2 && r.bottom == 15,
8223 "Wrong rectangle %s for width %d\n", wine_dbgstr_rect( &r ), width );
8225 else win_skip( "MirrorRgn not supported\n" );
8227 DestroyWindow(hwnd);
8230 static void test_rtl_layout(void)
8232 HWND parent, child;
8233 RECT r;
8234 POINT pt;
8236 if (!pSetProcessDefaultLayout)
8238 win_skip( "SetProcessDefaultLayout not supported\n" );
8239 return;
8242 parent = CreateWindowExA(WS_EX_LAYOUTRTL, "static", NULL, WS_POPUP, 100, 100, 300, 300, NULL, 0, 0, NULL);
8243 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 10, 10, 20, 20, parent, 0, 0, NULL);
8245 GetWindowRect( parent, &r );
8246 ok( r.left == 100 && r.right == 400, "wrong rect %s\n", wine_dbgstr_rect( &r ));
8247 GetClientRect( parent, &r );
8248 ok( r.left == 0 && r.right == 300, "wrong rect %s\n", wine_dbgstr_rect( &r ));
8249 GetClientRect( child, &r );
8250 ok( r.left == 0 && r.right == 20, "wrong rect %s\n", wine_dbgstr_rect( &r ));
8251 MapWindowPoints( child, parent, (POINT *)&r, 2 );
8252 ok( r.left == 10 && r.right == 30, "wrong rect %s\n", wine_dbgstr_rect( &r ));
8253 GetWindowRect( child, &r );
8254 ok( r.left == 370 && r.right == 390, "wrong rect %s\n", wine_dbgstr_rect( &r ));
8255 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
8256 ok( r.left == 10 && r.right == 30, "wrong rect %s\n", wine_dbgstr_rect( &r ));
8257 GetWindowRect( child, &r );
8258 MapWindowPoints( NULL, parent, (POINT *)&r, 1 );
8259 MapWindowPoints( NULL, parent, (POINT *)&r + 1, 1 );
8260 ok( r.left == 30 && r.right == 10, "wrong rect %s\n", wine_dbgstr_rect( &r ));
8261 pt.x = pt.y = 12;
8262 MapWindowPoints( child, parent, &pt, 1 );
8263 ok( pt.x == 22 && pt.y == 22, "wrong point %d,%d\n", pt.x, pt.y );
8264 SetWindowPos( parent, 0, 0, 0, 250, 250, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
8265 GetWindowRect( parent, &r );
8266 ok( r.left == 100 && r.right == 350, "wrong rect %s\n", wine_dbgstr_rect( &r ));
8267 GetWindowRect( child, &r );
8268 ok( r.left == 320 && r.right == 340, "wrong rect %s\n", wine_dbgstr_rect( &r ));
8269 SetWindowLongW( parent, GWL_EXSTYLE, 0 );
8270 GetWindowRect( child, &r );
8271 ok( r.left == 320 && r.right == 340, "wrong rect %s\n", wine_dbgstr_rect( &r ));
8272 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
8273 ok( r.left == 220 && r.right == 240, "wrong rect %s\n", wine_dbgstr_rect( &r ));
8274 SetWindowLongW( parent, GWL_EXSTYLE, WS_EX_LAYOUTRTL );
8275 GetWindowRect( child, &r );
8276 ok( r.left == 320 && r.right == 340, "wrong rect %s\n", wine_dbgstr_rect( &r ));
8277 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
8278 ok( r.left == 10 && r.right == 30, "wrong rect %s\n", wine_dbgstr_rect( &r ));
8279 SetWindowPos( child, 0, 0, 0, 30, 30, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
8280 GetWindowRect( child, &r );
8281 ok( r.left == 310 && r.right == 340, "wrong rect %s\n", wine_dbgstr_rect( &r ));
8282 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
8283 ok( r.left == 10 && r.right == 40, "wrong rect %s\n", wine_dbgstr_rect( &r ));
8284 DestroyWindow( child );
8285 DestroyWindow( parent );
8288 static void test_FlashWindow(void)
8290 HWND hwnd;
8291 BOOL ret;
8292 if (!pFlashWindow)
8294 win_skip( "FlashWindow not supported\n" );
8295 return;
8298 hwnd = CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_POPUP,
8299 0, 0, 0, 0, 0, 0, 0, NULL );
8300 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
8302 SetLastError( 0xdeadbeef );
8303 ret = pFlashWindow( NULL, TRUE );
8304 ok( !ret && (GetLastError() == ERROR_INVALID_PARAMETER ||
8305 GetLastError() == ERROR_INVALID_WINDOW_HANDLE),
8306 "FlashWindow returned with %d\n", GetLastError() );
8308 DestroyWindow( hwnd );
8310 SetLastError( 0xdeadbeef );
8311 ret = pFlashWindow( hwnd, TRUE );
8312 ok( !ret && (GetLastError() == ERROR_INVALID_PARAMETER ||
8313 GetLastError() == ERROR_INVALID_WINDOW_HANDLE),
8314 "FlashWindow returned with %d\n", GetLastError() );
8317 static void test_FlashWindowEx(void)
8319 HWND hwnd;
8320 FLASHWINFO finfo;
8321 BOOL prev, ret;
8323 if (!pFlashWindowEx)
8325 win_skip( "FlashWindowEx not supported\n" );
8326 return;
8329 hwnd = CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_POPUP,
8330 0, 0, 0, 0, 0, 0, 0, NULL );
8331 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
8333 finfo.cbSize = sizeof(FLASHWINFO);
8334 finfo.dwFlags = FLASHW_TIMER;
8335 finfo.uCount = 3;
8336 finfo.dwTimeout = 200;
8337 finfo.hwnd = NULL;
8338 SetLastError(0xdeadbeef);
8339 ret = pFlashWindowEx(&finfo);
8340 ok(!ret && (GetLastError() == ERROR_INVALID_PARAMETER ||
8341 GetLastError() == ERROR_INVALID_WINDOW_HANDLE),
8342 "FlashWindowEx returned with %d\n", GetLastError());
8344 finfo.hwnd = hwnd;
8345 SetLastError(0xdeadbeef);
8346 ret = pFlashWindowEx(NULL);
8347 ok(!ret && GetLastError() == ERROR_NOACCESS,
8348 "FlashWindowEx returned with %d\n", GetLastError());
8350 SetLastError(0xdeadbeef);
8351 ret = pFlashWindowEx(&finfo);
8352 todo_wine ok(!ret, "previous window state should not be active\n");
8354 finfo.cbSize = sizeof(FLASHWINFO) - 1;
8355 SetLastError(0xdeadbeef);
8356 ret = pFlashWindowEx(&finfo);
8357 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
8358 "FlashWindowEx succeeded\n");
8360 finfo.cbSize = sizeof(FLASHWINFO) + 1;
8361 SetLastError(0xdeadbeef);
8362 ret = pFlashWindowEx(&finfo);
8363 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
8364 "FlashWindowEx succeeded\n");
8365 finfo.cbSize = sizeof(FLASHWINFO);
8367 DestroyWindow( hwnd );
8369 SetLastError(0xdeadbeef);
8370 ret = pFlashWindowEx(&finfo);
8371 ok(!ret && (GetLastError() == ERROR_INVALID_PARAMETER ||
8372 GetLastError() == ERROR_INVALID_WINDOW_HANDLE),
8373 "FlashWindowEx returned with %d\n", GetLastError());
8375 ok(finfo.cbSize == sizeof(FLASHWINFO), "FlashWindowEx modified cdSize to %x\n", finfo.cbSize);
8376 ok(finfo.hwnd == hwnd, "FlashWindowEx modified hwnd to %p\n", finfo.hwnd);
8377 ok(finfo.dwFlags == FLASHW_TIMER, "FlashWindowEx modified dwFlags to %x\n", finfo.dwFlags);
8378 ok(finfo.uCount == 3, "FlashWindowEx modified uCount to %x\n", finfo.uCount);
8379 ok(finfo.dwTimeout == 200, "FlashWindowEx modified dwTimeout to %x\n", finfo.dwTimeout);
8381 hwnd = CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_VISIBLE | WS_POPUPWINDOW,
8382 0, 0, 0, 0, 0, 0, 0, NULL );
8383 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
8384 finfo.hwnd = hwnd;
8386 SetLastError(0xdeadbeef);
8387 ret = pFlashWindowEx(NULL);
8388 ok(!ret && GetLastError() == ERROR_NOACCESS,
8389 "FlashWindowEx returned with %d\n", GetLastError());
8391 SetLastError(0xdeadbeef);
8392 prev = pFlashWindowEx(&finfo);
8394 ok(finfo.cbSize == sizeof(FLASHWINFO), "FlashWindowEx modified cdSize to %x\n", finfo.cbSize);
8395 ok(finfo.hwnd == hwnd, "FlashWindowEx modified hwnd to %p\n", finfo.hwnd);
8396 ok(finfo.dwFlags == FLASHW_TIMER, "FlashWindowEx modified dwFlags to %x\n", finfo.dwFlags);
8397 ok(finfo.uCount == 3, "FlashWindowEx modified uCount to %x\n", finfo.uCount);
8398 ok(finfo.dwTimeout == 200, "FlashWindowEx modified dwTimeout to %x\n", finfo.dwTimeout);
8400 finfo.dwFlags = FLASHW_STOP;
8401 SetLastError(0xdeadbeef);
8402 ret = pFlashWindowEx(&finfo);
8403 ok(prev != ret, "previous window state should be different\n");
8405 DestroyWindow( hwnd );
8408 static void test_FindWindowEx(void)
8410 HWND hwnd, found;
8412 hwnd = CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP, 0,0,0,0, 0, 0, 0, NULL );
8413 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
8415 num_gettext_msgs = 0;
8416 found = FindWindowExA( 0, 0, "ClassThatDoesntExist", "" );
8417 ok( found == NULL, "expected a NULL hwnd\n" );
8418 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
8420 num_gettext_msgs = 0;
8421 found = FindWindowExA( 0, 0, "ClassThatDoesntExist", NULL );
8422 ok( found == NULL, "expected a NULL hwnd\n" );
8423 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
8425 num_gettext_msgs = 0;
8426 found = FindWindowExA( 0, 0, "MainWindowClass", "" );
8427 ok( found == NULL, "expected a NULL hwnd\n" );
8428 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
8430 num_gettext_msgs = 0;
8431 found = FindWindowExA( 0, 0, "MainWindowClass", NULL );
8432 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
8433 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
8435 num_gettext_msgs = 0;
8436 found = FindWindowExA( 0, 0, "MainWindowClass", "caption" );
8437 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
8438 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
8440 DestroyWindow( hwnd );
8442 hwnd = CreateWindowExA( 0, "MainWindowClass", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL );
8443 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
8445 num_gettext_msgs = 0;
8446 found = FindWindowExA( 0, 0, "MainWindowClass", "" );
8447 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
8448 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
8450 num_gettext_msgs = 0;
8451 found = FindWindowExA( 0, 0, "MainWindowClass", NULL );
8452 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
8453 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
8455 DestroyWindow( hwnd );
8457 /* test behaviour with a window title that is an empty character */
8458 found = FindWindowExA( 0, 0, "Shell_TrayWnd", "" );
8459 ok( found != NULL, "found is NULL, expected a valid hwnd\n" );
8460 found = FindWindowExA( 0, 0, "Shell_TrayWnd", NULL );
8461 ok( found != NULL, "found is NULL, expected a valid hwnd\n" );
8464 static void test_FindWindow(void)
8466 HWND hwnd, found;
8468 hwnd = CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP, 0,0,0,0, 0, 0, 0, NULL );
8469 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
8471 num_gettext_msgs = 0;
8472 found = FindWindowA( "ClassThatDoesntExist", "" );
8473 ok( found == NULL, "expected a NULL hwnd\n" );
8474 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
8476 num_gettext_msgs = 0;
8477 found = FindWindowA( "ClassThatDoesntExist", NULL );
8478 ok( found == NULL, "expected a NULL hwnd\n" );
8479 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
8481 num_gettext_msgs = 0;
8482 found = FindWindowA( "MainWindowClass", "" );
8483 ok( found == NULL, "expected a NULL hwnd\n" );
8484 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
8486 num_gettext_msgs = 0;
8487 found = FindWindowA( "MainWindowClass", NULL );
8488 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
8489 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
8491 num_gettext_msgs = 0;
8492 found = FindWindowA( "MainWindowClass", "caption" );
8493 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
8494 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
8496 DestroyWindow( hwnd );
8498 hwnd = CreateWindowExA( 0, "MainWindowClass", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL );
8499 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
8501 num_gettext_msgs = 0;
8502 found = FindWindowA( "MainWindowClass", "" );
8503 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
8504 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
8506 num_gettext_msgs = 0;
8507 found = FindWindowA( "MainWindowClass", NULL );
8508 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
8509 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
8511 DestroyWindow( hwnd );
8513 /* test behaviour with a window title that is an empty character */
8514 found = FindWindowA( "Shell_TrayWnd", "" );
8515 ok( found != NULL, "found is NULL, expected a valid hwnd\n" );
8516 found = FindWindowA( "Shell_TrayWnd", NULL );
8517 ok( found != NULL, "found is NULL, expected a valid hwnd\n" );
8520 static void test_GetLastActivePopup(void)
8522 HWND hwndOwner, hwndPopup1, hwndPopup2;
8524 hwndOwner = CreateWindowExA(0, "MainWindowClass", NULL,
8525 WS_VISIBLE | WS_POPUPWINDOW,
8526 100, 100, 200, 200,
8527 NULL, 0, GetModuleHandleA(NULL), NULL);
8528 hwndPopup1 = CreateWindowExA(0, "MainWindowClass", NULL,
8529 WS_VISIBLE | WS_POPUPWINDOW,
8530 100, 100, 200, 200,
8531 hwndOwner, 0, GetModuleHandleA(NULL), NULL);
8532 hwndPopup2 = CreateWindowExA(0, "MainWindowClass", NULL,
8533 WS_VISIBLE | WS_POPUPWINDOW,
8534 100, 100, 200, 200,
8535 hwndPopup1, 0, GetModuleHandleA(NULL), NULL);
8536 ok( GetLastActivePopup(hwndOwner) == hwndPopup2, "wrong last active popup\n" );
8537 DestroyWindow( hwndPopup2 );
8538 DestroyWindow( hwndPopup1 );
8539 DestroyWindow( hwndOwner );
8542 static LRESULT WINAPI my_httrasparent_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
8544 if (msg == WM_NCHITTEST) return HTTRANSPARENT;
8545 return DefWindowProcA(hwnd, msg, wp, lp);
8548 static LRESULT WINAPI my_window_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
8550 return DefWindowProcA(hwnd, msg, wp, lp);
8553 static void create_window_tree(HWND parent, HWND *window, int size)
8555 static const DWORD style[] = { 0, WS_VISIBLE, WS_DISABLED, WS_VISIBLE | WS_DISABLED };
8556 int i, pos;
8558 memset(window, 0, size * sizeof(window[0]));
8560 pos = 0;
8561 for (i = 0; i < sizeof(style)/sizeof(style[0]); i++)
8563 assert(pos < size);
8564 window[pos] = CreateWindowExA(0, "my_window", NULL, style[i] | WS_CHILD,
8565 0, 0, 100, 100, parent, 0, 0, NULL);
8566 ok(window[pos] != 0, "CreateWindowEx failed\n");
8567 pos++;
8568 assert(pos < size);
8569 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_window", NULL, style[i] | WS_CHILD,
8570 0, 0, 100, 100, parent, 0, 0, NULL);
8571 ok(window[pos] != 0, "CreateWindowEx failed\n");
8572 pos++;
8574 assert(pos < size);
8575 window[pos] = CreateWindowExA(0, "my_httrasparent", NULL, style[i] | WS_CHILD,
8576 0, 0, 100, 100, parent, 0, 0, NULL);
8577 ok(window[pos] != 0, "CreateWindowEx failed\n");
8578 pos++;
8579 assert(pos < size);
8580 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_httrasparent", NULL, style[i] | WS_CHILD,
8581 0, 0, 100, 100, parent, 0, 0, NULL);
8582 ok(window[pos] != 0, "CreateWindowEx failed\n");
8583 pos++;
8585 assert(pos < size);
8586 window[pos] = CreateWindowExA(0, "my_button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
8587 0, 0, 100, 100, parent, 0, 0, NULL);
8588 ok(window[pos] != 0, "CreateWindowEx failed\n");
8589 pos++;
8590 assert(pos < size);
8591 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
8592 0, 0, 100, 100, parent, 0, 0, NULL);
8593 ok(window[pos] != 0, "CreateWindowEx failed\n");
8594 pos++;
8595 assert(pos < size);
8596 window[pos] = CreateWindowExA(0, "my_button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
8597 0, 0, 100, 100, parent, 0, 0, NULL);
8598 ok(window[pos] != 0, "CreateWindowEx failed\n");
8599 pos++;
8600 assert(pos < size);
8601 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
8602 0, 0, 100, 100, parent, 0, 0, NULL);
8603 ok(window[pos] != 0, "CreateWindowEx failed\n");
8604 pos++;
8606 assert(pos < size);
8607 window[pos] = CreateWindowExA(0, "Button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
8608 0, 0, 100, 100, parent, 0, 0, NULL);
8609 ok(window[pos] != 0, "CreateWindowEx failed\n");
8610 pos++;
8611 assert(pos < size);
8612 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "Button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
8613 0, 0, 100, 100, parent, 0, 0, NULL);
8614 ok(window[pos] != 0, "CreateWindowEx failed\n");
8615 pos++;
8616 assert(pos < size);
8617 window[pos] = CreateWindowExA(0, "Button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
8618 0, 0, 100, 100, parent, 0, 0, NULL);
8619 ok(window[pos] != 0, "CreateWindowEx failed\n");
8620 pos++;
8621 assert(pos < size);
8622 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "Button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
8623 0, 0, 100, 100, parent, 0, 0, NULL);
8624 ok(window[pos] != 0, "CreateWindowEx failed\n");
8625 pos++;
8627 assert(pos < size);
8628 window[pos] = CreateWindowExA(0, "Static", NULL, style[i] | WS_CHILD,
8629 0, 0, 100, 100, parent, 0, 0, NULL);
8630 ok(window[pos] != 0, "CreateWindowEx failed\n");
8631 pos++;
8632 assert(pos < size);
8633 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "Static", NULL, style[i] | WS_CHILD,
8634 0, 0, 100, 100, parent, 0, 0, NULL);
8635 ok(window[pos] != 0, "CreateWindowEx failed\n");
8636 pos++;
8640 struct window_attributes
8642 char class_name[128];
8643 BOOL is_visible, is_enabled, is_groupbox, is_httransparent, is_extransparent;
8646 static void get_window_attributes(HWND hwnd, struct window_attributes *attrs)
8648 DWORD style, ex_style, hittest;
8650 style = GetWindowLongA(hwnd, GWL_STYLE);
8651 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
8652 attrs->class_name[0] = 0;
8653 GetClassNameA(hwnd, attrs->class_name, sizeof(attrs->class_name));
8654 hittest = SendMessageA(hwnd, WM_NCHITTEST, 0, 0);
8656 attrs->is_visible = (style & WS_VISIBLE) != 0;
8657 attrs->is_enabled = (style & WS_DISABLED) == 0;
8658 attrs->is_groupbox = !lstrcmpiA(attrs->class_name, "Button") && (style & BS_TYPEMASK) == BS_GROUPBOX;
8659 attrs->is_httransparent = hittest == HTTRANSPARENT;
8660 attrs->is_extransparent = (ex_style & WS_EX_TRANSPARENT) != 0;
8663 static int window_to_index(HWND hwnd, HWND *window, int size)
8665 int i;
8667 for (i = 0; i < size; i++)
8669 if (!window[i]) break;
8670 if (window[i] == hwnd) return i;
8672 return -1;
8675 static void test_child_window_from_point(void)
8677 static const int real_child_pos[] = { 14,15,16,17,18,19,20,21,24,25,26,27,42,43,
8678 44,45,46,47,48,49,52,53,54,55,51,50,23,22,-1 };
8679 static const int real_child_pos_nt4[] = { 14,15,16,17,20,21,24,25,26,27,42,43,44,45,
8680 48,49,52,53,54,55,51,50,47,46,23,22,19,18,-1 };
8681 WNDCLASSA cls;
8682 HWND hwnd, parent, window[100];
8683 POINT pt;
8684 int found_invisible, found_disabled, found_groupbox, found_httransparent, found_extransparent;
8685 int ret, i;
8687 ret = GetClassInfoA(0, "Button", &cls);
8688 ok(ret, "GetClassInfo(Button) failed\n");
8689 cls.lpszClassName = "my_button";
8690 ret = RegisterClassA(&cls);
8691 ok(ret, "RegisterClass(my_button) failed\n");
8693 cls.lpszClassName = "my_httrasparent";
8694 cls.lpfnWndProc = my_httrasparent_proc;
8695 ret = RegisterClassA(&cls);
8696 ok(ret, "RegisterClass(my_httrasparent) failed\n");
8698 cls.lpszClassName = "my_window";
8699 cls.lpfnWndProc = my_window_proc;
8700 ret = RegisterClassA(&cls);
8701 ok(ret, "RegisterClass(my_window) failed\n");
8703 parent = CreateWindowExA(0, "MainWindowClass", NULL,
8704 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE,
8705 100, 100, 200, 200,
8706 0, 0, GetModuleHandleA(NULL), NULL);
8707 ok(parent != 0, "CreateWindowEx failed\n");
8708 trace("parent %p\n", parent);
8710 create_window_tree(parent, window, sizeof(window)/sizeof(window[0]));
8712 found_invisible = 0;
8713 found_disabled = 0;
8714 found_groupbox = 0;
8715 found_httransparent = 0;
8716 found_extransparent = 0;
8718 /* FIXME: also test WindowFromPoint, ChildWindowFromPoint, ChildWindowFromPointEx */
8719 for (i = 0; i < sizeof(real_child_pos)/sizeof(real_child_pos[0]); i++)
8721 struct window_attributes attrs;
8723 pt.x = pt.y = 50;
8724 hwnd = RealChildWindowFromPoint(parent, pt);
8725 ok(hwnd != 0, "RealChildWindowFromPoint failed\n");
8726 ret = window_to_index(hwnd, window, sizeof(window)/sizeof(window[0]));
8727 /* FIXME: remove once Wine is fixed */
8728 todo_wine_if (ret != real_child_pos[i])
8729 ok(ret == real_child_pos[i] || broken(ret == real_child_pos_nt4[i]), "expected %d, got %d\n", real_child_pos[i], ret);
8731 get_window_attributes(hwnd, &attrs);
8732 if (!attrs.is_visible) found_invisible++;
8733 if (!attrs.is_enabled) found_disabled++;
8734 if (attrs.is_groupbox) found_groupbox++;
8735 if (attrs.is_httransparent) found_httransparent++;
8736 if (attrs.is_extransparent) found_extransparent++;
8738 if (ret != real_child_pos[i] && ret != -1)
8740 trace("found hwnd %p (%s), is_visible %d, is_enabled %d, is_groupbox %d, is_httransparent %d, is_extransparent %d\n",
8741 hwnd, attrs.class_name, attrs.is_visible, attrs.is_enabled, attrs.is_groupbox, attrs.is_httransparent, attrs.is_extransparent);
8742 get_window_attributes(window[real_child_pos[i]], &attrs);
8743 trace("expected hwnd %p (%s), is_visible %d, is_enabled %d, is_groupbox %d, is_httransparent %d, is_extransparent %d\n",
8744 window[real_child_pos[i]], attrs.class_name, attrs.is_visible, attrs.is_enabled, attrs.is_groupbox, attrs.is_httransparent, attrs.is_extransparent);
8746 if (ret == -1)
8748 ok(hwnd == parent, "expected %p, got %p\n", parent, hwnd);
8749 break;
8751 DestroyWindow(hwnd);
8754 DestroyWindow(parent);
8756 ok(!found_invisible, "found %d invisible windows\n", found_invisible);
8757 ok(found_disabled, "found %d disabled windows\n", found_disabled);
8758 todo_wine
8759 ok(found_groupbox == 4, "found %d groupbox windows\n", found_groupbox);
8760 ok(found_httransparent, "found %d httransparent windows\n", found_httransparent);
8761 todo_wine
8762 ok(found_extransparent, "found %d extransparent windows\n", found_extransparent);
8764 ret = UnregisterClassA("my_button", cls.hInstance);
8765 ok(ret, "UnregisterClass(my_button) failed\n");
8766 ret = UnregisterClassA("my_httrasparent", cls.hInstance);
8767 ok(ret, "UnregisterClass(my_httrasparent) failed\n");
8768 ret = UnregisterClassA("my_window", cls.hInstance);
8769 ok(ret, "UnregisterClass(my_window) failed\n");
8772 static void simulate_click(int x, int y)
8774 INPUT input[2];
8775 UINT events_no;
8777 SetCursorPos(x, y);
8778 memset(input, 0, sizeof(input));
8779 input[0].type = INPUT_MOUSE;
8780 U(input[0]).mi.dx = x;
8781 U(input[0]).mi.dy = y;
8782 U(input[0]).mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
8783 input[1].type = INPUT_MOUSE;
8784 U(input[1]).mi.dx = x;
8785 U(input[1]).mi.dy = y;
8786 U(input[1]).mi.dwFlags = MOUSEEVENTF_LEFTUP;
8787 events_no = SendInput(2, input, sizeof(input[0]));
8788 ok(events_no == 2, "SendInput returned %d\n", events_no);
8791 static WNDPROC def_static_proc;
8792 static BOOL got_hittest;
8793 static LRESULT WINAPI static_hook_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
8795 if(msg == WM_NCHITTEST)
8796 got_hittest = TRUE;
8797 if(msg == WM_LBUTTONDOWN)
8798 ok(0, "unexpected call\n");
8800 return def_static_proc(hwnd, msg, wp, lp);
8803 static void window_from_point_proc(HWND parent)
8805 HANDLE start_event, end_event;
8806 HANDLE win, child_static, child_button;
8807 BOOL got_click;
8808 DWORD ret;
8809 POINT pt;
8810 MSG msg;
8812 start_event = OpenEventA(EVENT_ALL_ACCESS, FALSE, "test_wfp_start");
8813 ok(start_event != 0, "OpenEvent failed\n");
8814 end_event = OpenEventA(EVENT_ALL_ACCESS, FALSE, "test_wfp_end");
8815 ok(end_event != 0, "OpenEvent failed\n");
8817 child_static = CreateWindowExA(0, "static", "static", WS_CHILD | WS_VISIBLE,
8818 0, 0, 100, 100, parent, 0, NULL, NULL);
8819 ok(child_static != 0, "CreateWindowEx failed\n");
8820 pt.x = pt.y = 150;
8821 win = WindowFromPoint(pt);
8822 ok(win == parent, "WindowFromPoint returned %p, expected %p\n", win, parent);
8824 child_button = CreateWindowExA(0, "button", "button", WS_CHILD | WS_VISIBLE,
8825 100, 0, 100, 100, parent, 0, NULL, NULL);
8826 ok(child_button != 0, "CreateWindowEx failed\n");
8827 pt.x = 250;
8828 win = WindowFromPoint(pt);
8829 ok(win == child_button, "WindowFromPoint returned %p, expected %p\n", win, child_button);
8831 /* without this window simulate click test keeps sending WM_NCHITTEST
8832 * message to child_static in an infinite loop */
8833 win = CreateWindowExA(0, "button", "button", WS_CHILD | WS_VISIBLE,
8834 0, 0, 100, 100, parent, 0, NULL, NULL);
8835 ok(win != 0, "CreateWindowEx failed\n");
8836 def_static_proc = (void*)SetWindowLongPtrA(child_static,
8837 GWLP_WNDPROC, (LONG_PTR)static_hook_proc);
8838 flush_events(TRUE);
8839 SetEvent(start_event);
8841 got_hittest = FALSE;
8842 got_click = FALSE;
8843 while(!got_click && wait_for_message(&msg)) {
8844 if(msg.message == WM_LBUTTONUP) {
8845 ok(msg.hwnd == win, "msg.hwnd = %p, expected %p\n", msg.hwnd, win);
8846 got_click = TRUE;
8848 DispatchMessageA(&msg);
8850 ok(got_hittest, "transparent window didn't get WM_NCHITTEST message\n");
8851 ok(got_click, "button under static window didn't get WM_LBUTTONUP\n");
8853 ret = WaitForSingleObject(end_event, 5000);
8854 ok(ret == WAIT_OBJECT_0, "WaitForSingleObject returned %x\n", ret);
8856 CloseHandle(start_event);
8857 CloseHandle(end_event);
8860 static void test_window_from_point(const char *argv0)
8862 HWND hwnd, child, win;
8863 POINT pt;
8864 PROCESS_INFORMATION info;
8865 STARTUPINFOA startup;
8866 char cmd[MAX_PATH];
8867 HANDLE start_event, end_event;
8869 hwnd = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP | WS_VISIBLE,
8870 100, 100, 200, 100, 0, 0, NULL, NULL);
8871 ok(hwnd != 0, "CreateWindowEx failed\n");
8873 pt.x = pt.y = 150;
8874 win = WindowFromPoint(pt);
8875 pt.x = 250;
8876 if(win == hwnd)
8877 win = WindowFromPoint(pt);
8878 if(win != hwnd) {
8879 skip("there's another window covering test window\n");
8880 DestroyWindow(hwnd);
8881 return;
8884 child = CreateWindowExA(0, "static", "static", WS_CHILD | WS_VISIBLE,
8885 0, 0, 100, 100, hwnd, 0, NULL, NULL);
8886 ok(child != 0, "CreateWindowEx failed\n");
8887 pt.x = pt.y = 150;
8888 win = WindowFromPoint(pt);
8889 ok(win == hwnd, "WindowFromPoint returned %p, expected %p\n", win, hwnd);
8890 DestroyWindow(child);
8892 child = CreateWindowExA(0, "button", "button", WS_CHILD | WS_VISIBLE,
8893 0, 0, 100, 100, hwnd, 0, NULL, NULL);
8894 ok(child != 0, "CreateWindowEx failed\n");
8895 win = WindowFromPoint(pt);
8896 ok(win == child, "WindowFromPoint returned %p, expected %p\n", win, child);
8897 DestroyWindow(child);
8899 start_event = CreateEventA(NULL, FALSE, FALSE, "test_wfp_start");
8900 ok(start_event != 0, "CreateEvent failed\n");
8901 end_event = CreateEventA(NULL, FALSE, FALSE, "test_wfp_end");
8902 ok(start_event != 0, "CreateEvent failed\n");
8904 sprintf(cmd, "%s win create_children %p\n", argv0, hwnd);
8905 memset(&startup, 0, sizeof(startup));
8906 startup.cb = sizeof(startup);
8907 ok(CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL,
8908 &startup, &info), "CreateProcess failed.\n");
8909 ok(wait_for_event(start_event, 1000), "didn't get start_event\n");
8911 child = GetWindow(hwnd, GW_CHILD);
8912 win = WindowFromPoint(pt);
8913 ok(win == child, "WindowFromPoint returned %p, expected %p\n", win, child);
8915 simulate_click(150, 150);
8916 flush_events(TRUE);
8918 child = GetWindow(child, GW_HWNDNEXT);
8919 pt.x = 250;
8920 win = WindowFromPoint(pt);
8921 ok(win == child, "WindowFromPoint returned %p, expected %p\n", win, child);
8923 SetEvent(end_event);
8924 winetest_wait_child_process(info.hProcess);
8925 CloseHandle(start_event);
8926 CloseHandle(end_event);
8927 CloseHandle(info.hProcess);
8928 CloseHandle(info.hThread);
8930 DestroyWindow(hwnd);
8933 static void test_map_points(void)
8935 BOOL ret;
8936 POINT p;
8937 HWND wnd, wnd0, dwnd;
8938 INT n;
8939 DWORD err;
8940 POINT pos = { 100, 200 };
8941 int width = 150;
8942 int height = 150;
8943 RECT window_rect;
8944 RECT client_rect;
8946 /* Create test windows */
8947 wnd = CreateWindowA("static", "test1", WS_POPUP, pos.x, pos.y, width, height, NULL, NULL, NULL, NULL);
8948 ok(wnd != NULL, "Failed %p\n", wnd);
8949 wnd0 = CreateWindowA("static", "test2", WS_POPUP, 0, 0, width, height, NULL, NULL, NULL, NULL);
8950 ok(wnd0 != NULL, "Failed %p\n", wnd);
8951 dwnd = CreateWindowA("static", "test3", 0, 200, 300, 150, 150, NULL, NULL, NULL, NULL);
8952 DestroyWindow(dwnd);
8953 ok(dwnd != NULL, "Failed %p\n", dwnd);
8955 /* Verify window rect and client rect (they should have the same width and height) */
8956 GetWindowRect(wnd, &window_rect);
8957 ok(window_rect.left == pos.x, "left is %d instead of %d\n", window_rect.left, pos.x);
8958 ok(window_rect.top == pos.y, "top is %d instead of %d\n", window_rect.top, pos.y);
8959 ok(window_rect.right == pos.x + width, "right is %d instead of %d\n", window_rect.right, pos.x + width);
8960 ok(window_rect.bottom == pos.y + height, "bottom is %d instead of %d\n", window_rect.bottom, pos.y + height);
8961 GetClientRect(wnd, &client_rect);
8962 ok(client_rect.left == 0, "left is %d instead of 0\n", client_rect.left);
8963 ok(client_rect.top == 0, "top is %d instead of 0\n", client_rect.top);
8964 ok(client_rect.right == width, "right is %d instead of %d\n", client_rect.right, width);
8965 ok(client_rect.bottom == height, "bottom is %d instead of %d\n", client_rect.bottom, height);
8967 /* Test MapWindowPoints */
8969 /* MapWindowPoints(NULL or wnd, NULL or wnd, NULL, 1); crashes on Windows */
8971 SetLastError(0xdeadbeef);
8972 n = MapWindowPoints(NULL, NULL, NULL, 0);
8973 err = GetLastError();
8974 ok(n == 0, "Got %d, expected %d\n", n, 0);
8975 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
8977 SetLastError(0xdeadbeef);
8978 n = MapWindowPoints(wnd, wnd, NULL, 0);
8979 err = GetLastError();
8980 ok(n == 0, "Got %d, expected %d\n", n, 0);
8981 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
8983 n = MapWindowPoints(wnd, NULL, NULL, 0);
8984 ok(n == MAKELONG(window_rect.left, window_rect.top), "Got %x, expected %x\n",
8985 n, MAKELONG(window_rect.left, window_rect.top));
8987 n = MapWindowPoints(NULL, wnd, NULL, 0);
8988 ok(n == MAKELONG(-window_rect.left, -window_rect.top), "Got %x, expected %x\n",
8989 n, MAKELONG(-window_rect.left, -window_rect.top));
8991 SetLastError(0xdeadbeef);
8992 p.x = p.y = 100;
8993 n = MapWindowPoints(dwnd, NULL, &p, 1);
8994 err = GetLastError();
8995 ok(n == 0, "Got %d, expected %d\n", n, 0);
8996 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
8997 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
8999 SetLastError(0xdeadbeef);
9000 p.x = p.y = 100;
9001 n = MapWindowPoints(dwnd, wnd, &p, 1);
9002 err = GetLastError();
9003 ok(n == 0, "Got %d, expected %d\n", n, 0);
9004 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
9005 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
9007 SetLastError(0xdeadbeef);
9008 p.x = p.y = 100;
9009 n = MapWindowPoints(NULL, dwnd, &p, 1);
9010 err = GetLastError();
9011 ok(n == 0, "Got %d, expected %d\n", n, 0);
9012 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
9013 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
9015 SetLastError(0xdeadbeef);
9016 p.x = p.y = 100;
9017 n = MapWindowPoints(wnd, dwnd, &p, 1);
9018 err = GetLastError();
9019 ok(n == 0, "Got %d, expected %d\n", n, 0);
9020 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
9021 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
9023 SetLastError(0xdeadbeef);
9024 p.x = p.y = 100;
9025 n = MapWindowPoints(dwnd, dwnd, &p, 1);
9026 err = GetLastError();
9027 ok(n == 0, "Got %d, expected %d\n", n, 0);
9028 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
9029 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
9031 SetLastError(0xdeadbeef);
9032 p.x = p.y = 100;
9033 n = MapWindowPoints(NULL, NULL, &p, 1);
9034 err = GetLastError();
9035 ok(n == 0, "Got %d, expected %d\n", n, 0);
9036 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
9037 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
9039 SetLastError(0xdeadbeef);
9040 p.x = p.y = 100;
9041 n = MapWindowPoints(wnd, wnd, &p, 1);
9042 err = GetLastError();
9043 ok(n == 0, "Got %d, expected %d\n", n, 0);
9044 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
9045 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
9047 p.x = p.y = 100;
9048 n = MapWindowPoints(wnd, NULL, &p, 1);
9049 ok(n == MAKELONG(window_rect.left, window_rect.top), "Got %x, expected %x\n",
9050 n, MAKELONG(window_rect.left, window_rect.top));
9051 ok((p.x == (window_rect.left + 100)) && (p.y == (window_rect.top + 100)), "Failed got (%d, %d), expected (%d, %d)\n",
9052 p.x, p.y, window_rect.left + 100, window_rect.top + 100);
9054 p.x = p.y = 100;
9055 n = MapWindowPoints(NULL, wnd, &p, 1);
9056 ok(n == MAKELONG(-window_rect.left, -window_rect.top), "Got %x, expected %x\n",
9057 n, MAKELONG(-window_rect.left, -window_rect.top));
9058 ok((p.x == (-window_rect.left + 100)) && (p.y == (-window_rect.top + 100)), "Failed got (%d, %d), expected (%d, %d)\n",
9059 p.x, p.y, -window_rect.left + 100, -window_rect.top + 100);
9061 SetLastError(0xdeadbeef);
9062 p.x = p.y = 0;
9063 n = MapWindowPoints(wnd0, NULL, &p, 1);
9064 err = GetLastError();
9065 ok(n == 0, "Got %x, expected 0\n", n);
9066 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
9067 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
9069 SetLastError(0xdeadbeef);
9070 p.x = p.y = 0;
9071 n = MapWindowPoints(NULL, wnd0, &p, 1);
9072 err = GetLastError();
9073 ok(n == 0, "Got %x, expected 0\n", n);
9074 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
9075 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
9077 /* Test ClientToScreen */
9079 /* ClientToScreen(wnd, NULL); crashes on Windows */
9081 SetLastError(0xdeadbeef);
9082 ret = ClientToScreen(NULL, NULL);
9083 err = GetLastError();
9084 ok(!ret, "Should fail\n");
9085 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
9087 SetLastError(0xdeadbeef);
9088 p.x = p.y = 100;
9089 ret = ClientToScreen(NULL, &p);
9090 err = GetLastError();
9091 ok(!ret, "Should fail\n");
9092 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
9093 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
9095 SetLastError(0xdeadbeef);
9096 p.x = p.y = 100;
9097 ret = ClientToScreen(dwnd, &p);
9098 err = GetLastError();
9099 ok(!ret, "Should fail\n");
9100 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
9101 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
9103 p.x = p.y = 100;
9104 ret = ClientToScreen(wnd, &p);
9105 ok(ret, "Failed with error %u\n", GetLastError());
9106 ok((p.x == (window_rect.left + 100)) && (p.y == (window_rect.top + 100)), "Failed got (%d, %d), expected (%d, %d)\n",
9107 p.x, p.y, window_rect.left + 100, window_rect.top + 100);
9109 p.x = p.y = 0;
9110 ret = ClientToScreen(wnd0, &p);
9111 ok(ret, "Failed with error %u\n", GetLastError());
9112 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
9114 /* Test ScreenToClient */
9116 /* ScreenToClient(wnd, NULL); crashes on Windows */
9118 SetLastError(0xdeadbeef);
9119 ret = ScreenToClient(NULL, NULL);
9120 err = GetLastError();
9121 ok(!ret, "Should fail\n");
9122 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
9124 SetLastError(0xdeadbeef);
9125 p.x = p.y = 100;
9126 ret = ScreenToClient(NULL, &p);
9127 err = GetLastError();
9128 ok(!ret, "Should fail\n");
9129 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
9130 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
9132 SetLastError(0xdeadbeef);
9133 p.x = p.y = 100;
9134 ret = ScreenToClient(dwnd, &p);
9135 err = GetLastError();
9136 ok(!ret, "Should fail\n");
9137 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
9138 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
9140 p.x = p.y = 100;
9141 ret = ScreenToClient(wnd, &p);
9142 ok(ret, "Failed with error %u\n", GetLastError());
9143 ok((p.x == (-window_rect.left + 100)) && (p.y == (-window_rect.top + 100)), "Failed got(%d, %d), expected (%d, %d)\n",
9144 p.x, p.y, -window_rect.left + 100, -window_rect.top + 100);
9146 p.x = p.y = 0;
9147 ret = ScreenToClient(wnd0, &p);
9148 ok(ret, "Failed with error %u\n", GetLastError());
9149 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
9151 DestroyWindow(wnd);
9152 DestroyWindow(wnd0);
9155 static void test_update_region(void)
9157 HWND hwnd, parent, child;
9158 HRGN rgn1, rgn2;
9159 const RECT rc = {15, 15, 40, 40};
9160 const POINT wnd_orig = {30, 20};
9161 const POINT child_orig = {10, 5};
9163 parent = CreateWindowExA(0, "MainWindowClass", NULL,
9164 WS_VISIBLE | WS_CLIPCHILDREN,
9165 0, 0, 300, 150, NULL, NULL, GetModuleHandleA(0), 0);
9166 hwnd = CreateWindowExA(0, "MainWindowClass", NULL,
9167 WS_VISIBLE | WS_CLIPCHILDREN | WS_CHILD,
9168 0, 0, 200, 100, parent, NULL, GetModuleHandleA(0), 0);
9169 child = CreateWindowExA(0, "MainWindowClass", NULL,
9170 WS_VISIBLE | WS_CHILD,
9171 child_orig.x, child_orig.y, 100, 50,
9172 hwnd, NULL, GetModuleHandleA(0), 0);
9173 assert(parent && hwnd && child);
9175 ValidateRgn(parent, NULL);
9176 ValidateRgn(hwnd, NULL);
9177 InvalidateRect(hwnd, &rc, FALSE);
9178 ValidateRgn(child, NULL);
9180 rgn1 = CreateRectRgn(0, 0, 0, 0);
9181 ok(GetUpdateRgn(parent, rgn1, FALSE) == NULLREGION,
9182 "has invalid area after ValidateRgn(NULL)\n");
9183 GetUpdateRgn(hwnd, rgn1, FALSE);
9184 rgn2 = CreateRectRgnIndirect(&rc);
9185 ok(EqualRgn(rgn1, rgn2), "assigned and retrieved update regions are different\n");
9186 ok(GetUpdateRgn(child, rgn2, FALSE) == NULLREGION,
9187 "has invalid area after ValidateRgn(NULL)\n");
9189 SetWindowPos(hwnd, 0, wnd_orig.x, wnd_orig.y, 0, 0,
9190 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
9192 /* parent now has non-simple update region, it consist of
9193 * two rects, that was exposed after hwnd moving ... */
9194 SetRectRgn(rgn1, 0, 0, 200, wnd_orig.y);
9195 SetRectRgn(rgn2, 0, 0, wnd_orig.x, 100);
9196 CombineRgn(rgn1, rgn1, rgn2, RGN_OR);
9197 /* ... and mapped hwnd's invalid area, that hwnd has before moving */
9198 SetRectRgn(rgn2, rc.left + wnd_orig.x, rc.top + wnd_orig.y,
9199 rc.right + wnd_orig.x, rc.bottom + wnd_orig.y);
9200 CombineRgn(rgn1, rgn1, rgn2, RGN_OR);
9201 GetUpdateRgn(parent, rgn2, FALSE);
9202 todo_wine
9203 ok(EqualRgn(rgn1, rgn2), "wrong update region\n");
9205 /* hwnd has the same invalid region as before moving */
9206 SetRectRgn(rgn1, rc.left, rc.top, rc.right, rc.bottom);
9207 GetUpdateRgn(hwnd, rgn2, FALSE);
9208 ok(EqualRgn(rgn1, rgn2), "wrong update region\n");
9210 /* hwnd's invalid area maps to child during moving */
9211 SetRectRgn(rgn1, rc.left - child_orig.x , rc.top - child_orig.y,
9212 rc.right - child_orig.x, rc.bottom - child_orig.y);
9213 GetUpdateRgn(child, rgn2, FALSE);
9214 todo_wine
9215 ok(EqualRgn(rgn1, rgn2), "wrong update region\n");
9217 DeleteObject(rgn1);
9218 DeleteObject(rgn2);
9219 DestroyWindow(parent);
9222 static void test_window_without_child_style(void)
9224 HWND hwnd;
9226 hwnd = CreateWindowExA(0, "edit", NULL, WS_VISIBLE|WS_CHILD,
9227 0, 0, 50, 50, hwndMain, NULL, 0, NULL);
9228 ok(hwnd != NULL, "CreateWindow failed\n");
9230 ok(SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) & (~WS_CHILD)),
9231 "can't remove WS_CHILD style\n");
9233 SetActiveWindow(hwndMain);
9234 PostMessageW(hwnd, WM_LBUTTONUP, 0, 0);
9235 SendMessageW(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);
9236 check_active_state(hwnd, hwnd, hwnd);
9237 flush_events(TRUE);
9239 DestroyWindow(hwnd);
9243 struct smresult_thread_data
9245 HWND main_hwnd;
9246 HWND thread_hwnd;
9247 HANDLE thread_started;
9248 HANDLE thread_got_wm_app;
9249 HANDLE main_in_wm_app_1;
9250 HANDLE thread_replied;
9254 static LRESULT WINAPI smresult_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
9256 switch (msg)
9258 case WM_APP:
9260 struct smresult_thread_data *data = (struct smresult_thread_data*)lparam;
9262 ok(hwnd == data->thread_hwnd, "unexpected hwnd %p\n", hwnd);
9264 SendNotifyMessageA(data->main_hwnd, WM_APP+1, 0, lparam);
9266 /* Don't return until the main thread is processing our sent message. */
9267 ok(WaitForSingleObject(data->main_in_wm_app_1, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
9269 /* Break the PeekMessage loop so we can notify the main thread after we return. */
9270 SetEvent(data->thread_got_wm_app);
9272 return 0x240408ea;
9274 case WM_APP+1:
9276 struct smresult_thread_data *data = (struct smresult_thread_data*)lparam;
9277 LRESULT res;
9279 ok(hwnd == data->main_hwnd, "unexpected hwnd %p\n", hwnd);
9281 /* Ask the thread to reply to our WM_APP message. */
9282 SetEvent(data->main_in_wm_app_1);
9284 /* Wait until the thread has sent a reply. */
9285 ok(WaitForSingleObject(data->thread_replied, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
9287 /* Send another message while we have a reply queued for the current one. */
9288 res = SendMessageA(data->thread_hwnd, WM_APP+2, 0, lparam);
9289 ok(res == 0x449b0190, "unexpected result %lx\n", res);
9291 return 0;
9293 case WM_APP+2:
9295 struct smresult_thread_data *data = (struct smresult_thread_data*)lparam;
9297 ok(hwnd == data->thread_hwnd, "unexpected hwnd %p\n", hwnd);
9299 /* Don't return until we know the main thread is processing sent messages. */
9300 SendMessageA(data->main_hwnd, WM_NULL, 0, 0);
9302 return 0x449b0190;
9304 case WM_CLOSE:
9305 PostQuitMessage(0);
9306 break;
9308 return DefWindowProcA(hwnd, msg, wparam, lparam);
9311 static DWORD WINAPI smresult_thread_proc(void *param)
9313 MSG msg;
9314 struct smresult_thread_data *data = param;
9316 data->thread_hwnd = CreateWindowExA(0, "SmresultClass", "window caption text", WS_OVERLAPPEDWINDOW,
9317 100, 100, 200, 200, 0, 0, 0, NULL);
9318 ok(data->thread_hwnd != 0, "Failed to create overlapped window\n");
9320 SetEvent(data->thread_started);
9322 /* Loop until we've processed WM_APP. */
9323 while (WaitForSingleObject(data->thread_got_wm_app, 0) != WAIT_OBJECT_0)
9325 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
9327 TranslateMessage(&msg);
9328 DispatchMessageA(&msg);
9330 else
9332 MsgWaitForMultipleObjects(1, &data->thread_got_wm_app, FALSE, INFINITE, QS_SENDMESSAGE);
9336 /* Notify the main thread that we replied to its WM_APP message. */
9337 SetEvent(data->thread_replied);
9339 while (GetMessageA(&msg, 0, 0, 0))
9341 TranslateMessage(&msg);
9342 DispatchMessageA(&msg);
9345 return 0;
9348 static void test_smresult(void)
9350 WNDCLASSA cls;
9351 HANDLE hThread;
9352 DWORD tid;
9353 struct smresult_thread_data data;
9354 BOOL ret;
9355 LRESULT res;
9357 cls.style = CS_DBLCLKS;
9358 cls.lpfnWndProc = smresult_wndproc;
9359 cls.cbClsExtra = 0;
9360 cls.cbWndExtra = 0;
9361 cls.hInstance = GetModuleHandleA(0);
9362 cls.hIcon = 0;
9363 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
9364 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
9365 cls.lpszMenuName = NULL;
9366 cls.lpszClassName = "SmresultClass";
9368 ret = RegisterClassA(&cls);
9369 ok(ret, "RegisterClassA failed\n");
9371 data.thread_started = CreateEventA(NULL, TRUE, FALSE, NULL);
9372 ok(data.thread_started != NULL, "CreateEventA failed\n");
9374 data.thread_got_wm_app = CreateEventA(NULL, TRUE, FALSE, NULL);
9375 ok(data.thread_got_wm_app != NULL, "CreateEventA failed\n");
9377 data.main_in_wm_app_1 = CreateEventA(NULL, TRUE, FALSE, NULL);
9378 ok(data.main_in_wm_app_1 != NULL, "CreateEventA failed\n");
9380 data.thread_replied = CreateEventA(NULL, TRUE, FALSE, NULL);
9381 ok(data.thread_replied != NULL, "CreateEventA failed\n");
9383 data.main_hwnd = CreateWindowExA(0, "SmresultClass", "window caption text", WS_OVERLAPPEDWINDOW,
9384 100, 100, 200, 200, 0, 0, 0, NULL);
9386 hThread = CreateThread(NULL, 0, smresult_thread_proc, &data, 0, &tid);
9387 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
9389 ok(WaitForSingleObject(data.thread_started, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
9391 res = SendMessageA(data.thread_hwnd, WM_APP, 0, (LPARAM)&data);
9392 ok(res == 0x240408ea, "unexpected result %lx\n", res);
9394 SendMessageA(data.thread_hwnd, WM_CLOSE, 0, 0);
9396 DestroyWindow(data.main_hwnd);
9398 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
9400 CloseHandle(data.thread_started);
9401 CloseHandle(data.thread_got_wm_app);
9402 CloseHandle(data.main_in_wm_app_1);
9403 CloseHandle(data.thread_replied);
9404 CloseHandle(hThread);
9407 static void test_GetMessagePos(void)
9409 HWND button;
9410 DWORD pos;
9411 MSG msg;
9413 button = CreateWindowExA(0, "button", "button", WS_VISIBLE,
9414 100, 100, 100, 100, 0, 0, 0, NULL);
9415 ok(button != 0, "CreateWindowExA failed\n");
9417 SetCursorPos(120, 140);
9418 flush_events(TRUE);
9419 pos = GetMessagePos();
9420 ok(pos == MAKELONG(120, 140), "pos = %08x\n", pos);
9422 SetCursorPos(340, 320);
9423 pos = GetMessagePos();
9424 ok(pos == MAKELONG(120, 140), "pos = %08x\n", pos);
9426 SendMessageW(button, WM_APP, 0, 0);
9427 pos = GetMessagePos();
9428 ok(pos == MAKELONG(120, 140), "pos = %08x\n", pos);
9430 PostMessageA(button, WM_APP, 0, 0);
9431 GetMessageA(&msg, button, 0, 0);
9432 ok(msg.message == WM_APP, "msg.message = %x\n", msg.message);
9433 pos = GetMessagePos();
9434 ok(pos == MAKELONG(340, 320), "pos = %08x\n", pos);
9436 PostMessageA(button, WM_APP, 0, 0);
9437 SetCursorPos(350, 330);
9438 GetMessageA(&msg, button, 0, 0);
9439 ok(msg.message == WM_APP, "msg.message = %x\n", msg.message);
9440 pos = GetMessagePos();
9441 ok(pos == MAKELONG(340, 320), "pos = %08x\n", pos);
9443 PostMessageA(button, WM_APP, 0, 0);
9444 SetCursorPos(320, 340);
9445 PostMessageA(button, WM_APP+1, 0, 0);
9446 pos = GetMessagePos();
9447 ok(pos == MAKELONG(340, 320), "pos = %08x\n", pos);
9448 GetMessageA(&msg, button, 0, 0);
9449 ok(msg.message == WM_APP, "msg.message = %x\n", msg.message);
9450 pos = GetMessagePos();
9451 ok(pos == MAKELONG(350, 330), "pos = %08x\n", pos);
9452 GetMessageA(&msg, button, 0, 0);
9453 ok(msg.message == WM_APP+1, "msg.message = %x\n", msg.message);
9454 pos = GetMessagePos();
9455 ok(pos == MAKELONG(320, 340), "pos = %08x\n", pos);
9457 SetTimer(button, 1, 250, NULL);
9458 SetCursorPos(330, 350);
9459 GetMessageA(&msg, button, 0, 0);
9460 while (msg.message == WM_PAINT)
9462 UpdateWindow( button );
9463 GetMessageA(&msg, button, 0, 0);
9465 ok(msg.message == WM_TIMER, "msg.message = %x\n", msg.message);
9466 pos = GetMessagePos();
9467 ok(pos == MAKELONG(330, 350), "pos = %08x\n", pos);
9468 KillTimer(button, 1);
9470 DestroyWindow(button);
9473 #define SET_FOREGROUND_STEAL_1 0x01
9474 #define SET_FOREGROUND_SET_1 0x02
9475 #define SET_FOREGROUND_STEAL_2 0x04
9476 #define SET_FOREGROUND_SET_2 0x08
9477 #define SET_FOREGROUND_INJECT 0x10
9479 struct set_foreground_thread_params
9481 UINT msg_quit, msg_command;
9482 HWND window1, window2, thread_window;
9483 HANDLE command_executed;
9486 static DWORD WINAPI set_foreground_thread(void *params)
9488 struct set_foreground_thread_params *p = params;
9489 MSG msg;
9491 p->thread_window = CreateWindowExA(0, "static", "thread window", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9492 0, 0, 10, 10, 0, 0, 0, NULL);
9493 SetEvent(p->command_executed);
9495 while(GetMessageA(&msg, 0, 0, 0))
9497 if (msg.message == p->msg_quit)
9498 break;
9500 if (msg.message == p->msg_command)
9502 if (msg.wParam & SET_FOREGROUND_STEAL_1)
9504 SetForegroundWindow(p->thread_window);
9505 check_wnd_state(p->thread_window, p->thread_window, p->thread_window, 0);
9507 if (msg.wParam & SET_FOREGROUND_INJECT)
9509 SendNotifyMessageA(p->window1, WM_ACTIVATEAPP, 0, 0);
9511 if (msg.wParam & SET_FOREGROUND_SET_1)
9513 SetForegroundWindow(p->window1);
9514 check_wnd_state(0, p->window1, 0, 0);
9516 if (msg.wParam & SET_FOREGROUND_STEAL_2)
9518 SetForegroundWindow(p->thread_window);
9519 check_wnd_state(p->thread_window, p->thread_window, p->thread_window, 0);
9521 if (msg.wParam & SET_FOREGROUND_SET_2)
9523 SetForegroundWindow(p->window2);
9524 check_wnd_state(0, p->window2, 0, 0);
9527 SetEvent(p->command_executed);
9528 continue;
9531 TranslateMessage(&msg);
9532 DispatchMessageA(&msg);
9535 DestroyWindow(p->thread_window);
9536 return 0;
9539 static void test_activateapp(HWND window1)
9541 HWND window2, test_window;
9542 HANDLE thread;
9543 struct set_foreground_thread_params thread_params;
9544 DWORD tid;
9545 MSG msg;
9547 window2 = CreateWindowExA(0, "static", "window 2", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9548 300, 0, 10, 10, 0, 0, 0, NULL);
9549 thread_params.msg_quit = WM_USER;
9550 thread_params.msg_command = WM_USER + 1;
9551 thread_params.window1 = window1;
9552 thread_params.window2 = window2;
9553 thread_params.command_executed = CreateEventW(NULL, FALSE, FALSE, NULL);
9555 thread = CreateThread(NULL, 0, set_foreground_thread, &thread_params, 0, &tid);
9556 WaitForSingleObject(thread_params.command_executed, INFINITE);
9558 SetForegroundWindow(window1);
9559 check_wnd_state(window1, window1, window1, 0);
9560 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
9562 /* Steal foreground: WM_ACTIVATEAPP(0) is delivered. */
9563 app_activated = app_deactivated = FALSE;
9564 PostThreadMessageA(tid, thread_params.msg_command, SET_FOREGROUND_STEAL_1, 0);
9565 WaitForSingleObject(thread_params.command_executed, INFINITE);
9566 test_window = GetForegroundWindow();
9567 ok(test_window == thread_params.thread_window, "Expected foreground window %p, got %p\n",
9568 thread_params.thread_window, test_window);
9569 /* Active and Focus window are sometimes 0 on KDE. Ignore them.
9570 * check_wnd_state(window1, thread_params.thread_window, window1, 0); */
9571 ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9572 ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9573 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
9574 check_wnd_state(0, thread_params.thread_window, 0, 0);
9575 test_window = GetForegroundWindow();
9576 ok(test_window == thread_params.thread_window, "Expected foreground window %p, got %p\n",
9577 thread_params.thread_window, test_window);
9578 ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9579 /* This message is reliable on Windows and inside a virtual desktop.
9580 * It is unreliable on KDE (50/50) and never arrives on FVWM.
9581 * ok(app_deactivated, "Expected WM_ACTIVATEAPP(0), did not receive it.\n"); */
9583 /* Set foreground: WM_ACTIVATEAPP (1) is delivered. */
9584 app_activated = app_deactivated = FALSE;
9585 PostThreadMessageA(tid, thread_params.msg_command, SET_FOREGROUND_SET_1, 0);
9586 WaitForSingleObject(thread_params.command_executed, INFINITE);
9587 check_wnd_state(0, 0, 0, 0);
9588 test_window = GetForegroundWindow();
9589 ok(!test_window, "Expected foreground window 0, got %p\n", test_window);
9590 ok(!app_activated, "Received WM_ACTIVATEAPP(!= 0), did not expect it.\n");
9591 ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9592 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
9593 check_wnd_state(window1, window1, window1, 0);
9594 test_window = GetForegroundWindow();
9595 ok(test_window == window1, "Expected foreground window %p, got %p\n",
9596 window1, test_window);
9597 ok(app_activated, "Expected WM_ACTIVATEAPP(1), did not receive it.\n");
9598 ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9600 /* Steal foreground then set it back: No messages are delivered. */
9601 app_activated = app_deactivated = FALSE;
9602 PostThreadMessageA(tid, thread_params.msg_command, SET_FOREGROUND_STEAL_1 | SET_FOREGROUND_SET_1, 0);
9603 WaitForSingleObject(thread_params.command_executed, INFINITE);
9604 test_window = GetForegroundWindow();
9605 ok(test_window == window1, "Expected foreground window %p, got %p\n",
9606 window1, test_window);
9607 check_wnd_state(window1, window1, window1, 0);
9608 ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9609 ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9610 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
9611 test_window = GetForegroundWindow();
9612 ok(test_window == window1, "Expected foreground window %p, got %p\n",
9613 window1, test_window);
9614 check_wnd_state(window1, window1, window1, 0);
9615 ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9616 ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9618 /* This is not implemented with a plain WM_ACTIVATEAPP filter. */
9619 app_activated = app_deactivated = FALSE;
9620 PostThreadMessageA(tid, thread_params.msg_command, SET_FOREGROUND_STEAL_1
9621 | SET_FOREGROUND_INJECT | SET_FOREGROUND_SET_1, 0);
9622 WaitForSingleObject(thread_params.command_executed, INFINITE);
9623 test_window = GetForegroundWindow();
9624 ok(test_window == window1, "Expected foreground window %p, got %p\n",
9625 window1, test_window);
9626 check_wnd_state(window1, window1, window1, 0);
9627 ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9628 ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9629 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
9630 test_window = GetForegroundWindow();
9631 ok(test_window == window1, "Expected foreground window %p, got %p\n",
9632 window1, test_window);
9633 check_wnd_state(window1, window1, window1, 0);
9634 ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9635 ok(app_deactivated, "Expected WM_ACTIVATEAPP(0), did not receive it.\n");
9637 SetForegroundWindow(thread_params.thread_window);
9639 /* Set foreground then remove: Both messages are delivered. */
9640 app_activated = app_deactivated = FALSE;
9641 PostThreadMessageA(tid, thread_params.msg_command, SET_FOREGROUND_SET_1 | SET_FOREGROUND_STEAL_2, 0);
9642 WaitForSingleObject(thread_params.command_executed, INFINITE);
9643 test_window = GetForegroundWindow();
9644 ok(test_window == thread_params.thread_window, "Expected foreground window %p, got %p\n",
9645 thread_params.thread_window, test_window);
9646 check_wnd_state(0, thread_params.thread_window, 0, 0);
9647 ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9648 ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9649 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
9650 test_window = GetForegroundWindow();
9651 ok(test_window == thread_params.thread_window, "Expected foreground window %p, got %p\n",
9652 thread_params.thread_window, test_window);
9653 /* Active and focus are window1 on wine because the internal WM_WINE_SETACTIVEWINDOW(0)
9654 * message is never generated. GetCapture() returns 0 though, so we'd get a test success
9655 * in todo_wine in the line below.
9656 * todo_wine check_wnd_state(0, thread_params.thread_window, 0, 0); */
9657 ok(app_activated, "Expected WM_ACTIVATEAPP(1), did not receive it.\n");
9658 todo_wine ok(app_deactivated, "Expected WM_ACTIVATEAPP(0), did not receive it.\n");
9660 SetForegroundWindow(window1);
9661 test_window = GetForegroundWindow();
9662 ok(test_window == window1, "Expected foreground window %p, got %p\n",
9663 window1, test_window);
9664 check_wnd_state(window1, window1, window1, 0);
9666 /* Switch to a different window from the same thread? No messages. */
9667 app_activated = app_deactivated = FALSE;
9668 PostThreadMessageA(tid, thread_params.msg_command, SET_FOREGROUND_STEAL_1 | SET_FOREGROUND_SET_2, 0);
9669 WaitForSingleObject(thread_params.command_executed, INFINITE);
9670 test_window = GetForegroundWindow();
9671 ok(test_window == window1, "Expected foreground window %p, got %p\n",
9672 window1, test_window);
9673 check_wnd_state(window1, window1, window1, 0);
9674 ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9675 ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9676 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
9677 test_window = GetForegroundWindow();
9678 ok(test_window == window2, "Expected foreground window %p, got %p\n",
9679 window2, test_window);
9680 check_wnd_state(window2, window2, window2, 0);
9681 ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9682 ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9684 PostThreadMessageA(tid, thread_params.msg_quit, 0, 0);
9685 WaitForSingleObject(thread, INFINITE);
9687 CloseHandle(thread_params.command_executed);
9688 DestroyWindow(window2);
9691 static LRESULT WINAPI winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
9693 if(!hwnd) {
9694 int *count = (int*)lparam;
9695 (*count)++;
9697 return 0;
9700 static LRESULT WINAPI winproc_convA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
9702 if(msg == WM_SETTEXT)
9704 const char *text = (const char*)lparam;
9706 ok(!wparam, "wparam = %08lx\n", wparam);
9707 ok(!strcmp(text, "text"), "WM_SETTEXT lparam = %s\n", text);
9708 return 1;
9710 return 0;
9713 static const WCHAR textW[] = {'t','e','x','t',0};
9714 static LRESULT WINAPI winproc_convW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
9716 if(msg == WM_SETTEXT)
9718 const WCHAR *text = (const WCHAR*)lparam;
9720 ok(!wparam, "wparam = %08lx\n", wparam);
9721 ok(!lstrcmpW(text, textW), "WM_SETTEXT lparam = %s\n", wine_dbgstr_w(text));
9722 return 1;
9724 return 0;
9727 static void test_winproc_handles(const char *argv0)
9729 static const WCHAR winproc_testW[] = {'w','i','n','p','r','o','c','_','t','e','s','t',0};
9731 HINSTANCE hinst = GetModuleHandleA(NULL);
9732 WNDCLASSA wnd_classA;
9733 WNDCLASSW wnd_classW;
9734 int count, ret;
9735 PROCESS_INFORMATION info;
9736 STARTUPINFOA startup;
9737 char cmd[MAX_PATH];
9739 memset(&wnd_classA, 0, sizeof(wnd_classA));
9740 wnd_classA.lpszClassName = "winproc_test";
9741 wnd_classA.lpfnWndProc = winproc;
9742 ret = RegisterClassA(&wnd_classA);
9743 ok(ret, "RegisterClass failed with error %d\n", GetLastError());
9745 ret = GetClassInfoW(hinst, winproc_testW, &wnd_classW);
9746 ok(ret, "GetClassInfoW failed with error %d\n", GetLastError());
9747 ok(wnd_classA.lpfnWndProc != wnd_classW.lpfnWndProc,
9748 "winproc pointers should not be identical\n");
9750 count = 0;
9751 CallWindowProcA(wnd_classW.lpfnWndProc, 0, 0, 0, (LPARAM)&count);
9752 ok(count == 1, "winproc should be called once (%d)\n", count);
9753 count = 0;
9754 CallWindowProcW(wnd_classW.lpfnWndProc, 0, 0, 0, (LPARAM)&count);
9755 ok(count == 1, "winproc should be called once (%d)\n", count);
9757 ret = UnregisterClassW(winproc_testW, hinst);
9758 ok(ret, "UnregisterClass failed with error %d\n", GetLastError());
9760 /* crashes on 64-bit windows because lpfnWndProc handle is already freed */
9761 if (sizeof(void*) == 4)
9763 count = 0;
9764 CallWindowProcA(wnd_classW.lpfnWndProc, 0, 0, 0, (LPARAM)&count);
9765 todo_wine ok(!count, "winproc should not be called (%d)\n", count);
9766 CallWindowProcW(wnd_classW.lpfnWndProc, 0, 0, 0, (LPARAM)&count);
9767 todo_wine ok(!count, "winproc should not be called (%d)\n", count);
9770 sprintf(cmd, "%s win winproc_limit", argv0);
9771 memset(&startup, 0, sizeof(startup));
9772 startup.cb = sizeof(startup);
9773 ok(CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL,
9774 &startup, &info), "CreateProcess failed.\n");
9775 winetest_wait_child_process(info.hProcess);
9776 CloseHandle(info.hProcess);
9777 CloseHandle(info.hThread);
9780 static void test_winproc_limit(void)
9782 WNDPROC winproc_handle;
9783 LONG_PTR ret;
9784 HWND hwnd;
9785 int i;
9787 hwnd = CreateWindowExA(0, "static", "test", WS_POPUP, 0, 0, 0, 0, 0, 0, 0, 0);
9788 ok(hwnd != 0, "CreateWindowEx failed\n");
9790 ok(SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)winproc),
9791 "SetWindowLongPtr failed\n");
9792 winproc_handle = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
9793 ok(winproc_handle != winproc, "winproc pointers should not be identical\n");
9795 /* run out of winproc slots */
9796 for(i = 2; i<0xffff; i++)
9798 ok(SetWindowLongPtrA(hwnd, GWLP_WNDPROC, i), "SetWindowLongPtr failed (%d)\n", i);
9799 if(GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == i)
9800 break;
9802 ok(i != 0xffff, "unable to run out of winproc slots\n");
9804 ret = SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)winproc_convA);
9805 ok(ret, "SetWindowLongPtr failed with error %d\n", GetLastError());
9806 ok(SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)"text"), "WM_SETTEXT failed\n");
9807 ok(SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)textW), "WM_SETTEXT with conversion failed\n");
9809 ret = SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)winproc_convW);
9810 ok(ret, "SetWindowLongPtr failed with error %d\n", GetLastError());
9811 ok(SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)"text"), "WM_SETTEXT failed\n");
9812 ok(SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)textW), "WM_SETTEXT with conversion failed\n");
9814 /* Show that there's no message conversion when CallWindowProc is used */
9815 ok(CallWindowProcA(winproc_convW, hwnd, WM_SETTEXT, 0, (LPARAM)textW) == 1,
9816 "winproc_convW returned error\n");
9817 ok(CallWindowProcW(winproc_convW, hwnd, WM_SETTEXT, 0, (LPARAM)textW) == 1,
9818 "winproc_convW returned error\n");
9820 i = 0;
9821 CallWindowProcA(winproc_handle, 0, 0, 0, (LPARAM)&i);
9822 ok(i == 1, "winproc should be called once (%d)\n", i);
9823 i = 0;
9824 CallWindowProcW(winproc_handle, 0, 0, 0, (LPARAM)&i);
9825 ok(i == 1, "winproc should be called once (%d)\n", i);
9827 DestroyWindow(hwnd);
9829 i = 0;
9830 CallWindowProcA(winproc_handle, 0, 0, 0, (LPARAM)&i);
9831 ok(i == 1, "winproc should be called once (%d)\n", i);
9832 i = 0;
9833 CallWindowProcW(winproc_handle, 0, 0, 0, (LPARAM)&i);
9834 ok(i == 1, "winproc should be called once (%d)\n", i);
9837 static void test_deferwindowpos(void)
9839 HDWP hdwp, hdwp2;
9840 HWND hwnd;
9841 BOOL ret;
9843 hdwp = BeginDeferWindowPos(0);
9844 ok(hdwp != NULL, "got %p\n", hdwp);
9846 ret = EndDeferWindowPos(NULL);
9847 ok(!ret, "got %d\n", ret);
9849 hdwp2 = DeferWindowPos(NULL, NULL, NULL, 0, 0, 10, 10, 0);
9850 todo_wine
9851 ok(hdwp2 == NULL && ((GetLastError() == ERROR_INVALID_DWP_HANDLE) ||
9852 broken(GetLastError() == ERROR_INVALID_WINDOW_HANDLE) /* before win8 */), "got %p, error %d\n", hdwp2, GetLastError());
9854 hdwp2 = DeferWindowPos((HDWP)0xdead, GetDesktopWindow(), NULL, 0, 0, 10, 10, 0);
9855 todo_wine
9856 ok(hdwp2 == NULL && ((GetLastError() == ERROR_INVALID_DWP_HANDLE) ||
9857 broken(GetLastError() == ERROR_INVALID_WINDOW_HANDLE) /* before win8 */), "got %p, error %d\n", hdwp2, GetLastError());
9859 hdwp2 = DeferWindowPos(hdwp, NULL, NULL, 0, 0, 10, 10, 0);
9860 ok(hdwp2 == NULL && GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got %p, error %d\n", hdwp2, GetLastError());
9862 hdwp2 = DeferWindowPos(hdwp, GetDesktopWindow(), NULL, 0, 0, 10, 10, 0);
9863 ok(hdwp2 == NULL && GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got %p, error %d\n", hdwp2, GetLastError());
9865 hdwp2 = DeferWindowPos(hdwp, (HWND)0xdead, NULL, 0, 0, 10, 10, 0);
9866 ok(hdwp2 == NULL && GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got %p, error %d\n", hdwp2, GetLastError());
9868 ret = EndDeferWindowPos(hdwp);
9869 ok(ret, "got %d\n", ret);
9870 hdwp = BeginDeferWindowPos(0);
9871 ok(hdwp != NULL, "got %p\n", hdwp);
9873 hwnd = create_tool_window(WS_POPUP, 0);
9874 hdwp2 = DeferWindowPos(hdwp, hwnd, NULL, 0, 0, 10, 10, 0);
9875 ok(hdwp2 != NULL, "got %p, error %d\n", hdwp2, GetLastError());
9876 DestroyWindow(hwnd);
9878 ret = EndDeferWindowPos(hdwp);
9879 ok(ret, "got %d\n", ret);
9882 static void test_LockWindowUpdate(HWND parent)
9884 typedef struct
9886 HWND hwnd_lock, hwnd_draw;
9887 BOOL allow_drawing;
9888 BOOL expect_valid;
9889 } TEST;
9891 int i;
9892 HWND child = CreateWindowA("static", 0, WS_CHILD | WS_VISIBLE, 0, 0, 20, 20, parent, 0, 0, 0);
9894 TEST tests[] = {
9895 {child, child, 0, 0},
9896 {child, child, 1, 1},
9897 {child, parent, 0, 1},
9898 {child, parent, 1, 1},
9899 {parent, child, 0, 0},
9900 {parent, child, 1, 1},
9901 {parent, parent, 0, 0},
9902 {parent, parent, 1, 1}
9905 if (!child)
9907 skip("CreateWindow failed, skipping LockWindowUpdate tests\n");
9908 return;
9911 ShowWindow(parent, SW_SHOW);
9912 UpdateWindow(parent);
9913 flush_events(TRUE);
9915 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
9917 HDC hdc;
9918 POINT p = {10, 10};
9919 BOOL ret;
9920 const DWORD dc_flags = DCX_USESTYLE | (tests[i].allow_drawing ? DCX_LOCKWINDOWUPDATE : 0);
9921 const COLORREF c1 = 0x111100, c2 = 0x222200;
9923 trace("hwnd_lock = %s, hwnd_draw = %s, allow_drawing = %d\n",
9924 tests[i].hwnd_lock == parent ? "parent" : "child",
9925 tests[i].hwnd_draw == parent ? "parent" : "child",
9926 tests[i].allow_drawing);
9928 hdc = GetDCEx(tests[i].hwnd_draw, 0, dc_flags);
9930 #define TEST_PIXEL(c_valid, c_invalid) \
9931 do { \
9932 COLORREF c = GetPixel(hdc, p.x, p.y); \
9933 COLORREF e = tests[i].expect_valid ? (c_valid) : (c_invalid); \
9934 todo_wine_if(!tests[i].expect_valid) \
9935 ok(c == e, "GetPixel: got %08x, expected %08x\n", c, e); \
9936 } while (0)
9938 SetPixel(hdc, p.x, p.y, c1);
9939 ret = LockWindowUpdate(tests[i].hwnd_lock);
9940 ok(ret, "LockWindowUpdate failed\n");
9941 TEST_PIXEL(c1, CLR_INVALID);
9942 SetPixel(hdc, p.x, p.y, c2);
9943 TEST_PIXEL(c2, CLR_INVALID);
9944 LockWindowUpdate(0);
9945 TEST_PIXEL(c2, c1);
9946 ReleaseDC(tests[i].hwnd_draw, hdc);
9947 #undef TEST_PIXEL
9949 DestroyWindow(child);
9952 static void test_hide_window(void)
9954 HWND hwnd, hwnd2, hwnd3;
9956 hwnd = CreateWindowExA(0, "MainWindowClass", "Main window", WS_POPUP | WS_VISIBLE,
9957 100, 100, 200, 200, 0, 0, GetModuleHandleA(NULL), NULL);
9958 hwnd2 = CreateWindowExA(0, "MainWindowClass", "Main window 2", WS_POPUP | WS_VISIBLE,
9959 100, 100, 200, 200, 0, 0, GetModuleHandleA(NULL), NULL);
9960 trace("hwnd = %p, hwnd2 = %p\n", hwnd, hwnd2);
9961 check_active_state(hwnd2, hwnd2, hwnd2);
9962 ok(GetWindow(hwnd2, GW_HWNDNEXT) == hwnd, "expected %p, got %p\n", hwnd, GetWindow(hwnd2, GW_HWNDNEXT));
9964 /* test hiding two normal windows */
9965 ShowWindow(hwnd2, SW_HIDE);
9966 check_active_state(hwnd, hwnd, hwnd);
9967 todo_wine
9968 ok(GetWindow(hwnd, GW_HWNDNEXT) == hwnd2, "expected %p, got %p\n", hwnd2, GetWindow(hwnd, GW_HWNDNEXT));
9970 ShowWindow(hwnd, SW_HIDE);
9971 check_active_state(hwndMain, 0, hwndMain);
9972 ok(GetWindow(hwnd, GW_HWNDNEXT) == hwnd2, "expected %p, got %p\n", hwnd2, GetWindow(hwnd, GW_HWNDNEXT));
9974 ShowWindow(hwnd, SW_SHOW);
9975 check_active_state(hwnd, hwnd, hwnd);
9977 ShowWindow(hwnd2, SW_SHOW);
9978 check_active_state(hwnd2, hwnd2, hwnd2);
9979 ok(GetWindow(hwnd2, GW_HWNDNEXT) == hwnd, "expected %p, got %p\n", hwnd, GetWindow(hwnd2, GW_HWNDNEXT));
9981 /* hide a non-active window */
9982 ShowWindow(hwnd, SW_HIDE);
9983 check_active_state(hwnd2, hwnd2, hwnd2);
9984 todo_wine
9985 ok(GetWindow(hwnd2, GW_HWNDNEXT) == hwnd, "expected %p, got %p\n", hwnd, GetWindow(hwnd2, GW_HWNDNEXT));
9987 /* hide a window in the middle */
9988 ShowWindow(hwnd, SW_SHOW);
9989 ShowWindow(hwnd2, SW_SHOW);
9990 hwnd3 = CreateWindowExA(0, "MainWindowClass", "Main window 3", WS_POPUP | WS_VISIBLE,
9991 100, 100, 200, 200, 0, 0, GetModuleHandleA(NULL), NULL);
9992 SetActiveWindow(hwnd2);
9993 ShowWindow(hwnd2, SW_HIDE);
9994 check_active_state(hwnd3, hwnd3, hwnd3);
9995 todo_wine {
9996 ok(GetWindow(hwnd3, GW_HWNDNEXT) == hwnd2, "expected %p, got %p\n", hwnd2, GetWindow(hwnd3, GW_HWNDNEXT));
9997 ok(GetWindow(hwnd2, GW_HWNDNEXT) == hwnd, "expected %p, got %p\n", hwnd, GetWindow(hwnd2, GW_HWNDNEXT));
10000 DestroyWindow(hwnd3);
10002 /* hide a normal window when there is a topmost window */
10003 hwnd3 = CreateWindowExA(WS_EX_TOPMOST, "MainWindowClass", "Topmost window 3", WS_POPUP|WS_VISIBLE,
10004 100, 100, 200, 200, 0, 0, GetModuleHandleA(NULL), NULL);
10005 ShowWindow(hwnd, SW_SHOW);
10006 ShowWindow(hwnd2, SW_SHOW);
10007 check_active_state(hwnd2, hwnd2, hwnd2);
10008 ShowWindow(hwnd2, SW_HIDE);
10009 todo_wine
10010 check_active_state(hwnd3, hwnd3, hwnd3);
10011 ok(GetWindow(hwnd2, GW_HWNDNEXT) == hwnd, "expected %p, got %p\n", hwnd, GetWindow(hwnd2, GW_HWNDNEXT));
10013 /* hide a topmost window */
10014 ShowWindow(hwnd2, SW_SHOW);
10015 ShowWindow(hwnd3, SW_SHOW);
10016 ShowWindow(hwnd3, SW_HIDE);
10017 check_active_state(hwnd2, hwnd2, hwnd2);
10018 ok(GetWindow(hwnd2, GW_HWNDNEXT) == hwnd, "expected %p, got %p\n", hwnd, GetWindow(hwnd2, GW_HWNDNEXT));
10020 DestroyWindow(hwnd3);
10022 /* hiding an owned window activates its owner */
10023 ShowWindow(hwnd, SW_SHOW);
10024 ShowWindow(hwnd2, SW_SHOW);
10025 hwnd3 = CreateWindowExA(0, "MainWindowClass", "Owned window 3", WS_POPUP|WS_VISIBLE,
10026 100, 100, 200, 200, hwnd, 0, GetModuleHandleA(NULL), NULL);
10027 ShowWindow(hwnd3, SW_HIDE);
10028 check_active_state(hwnd, hwnd, hwnd);
10029 todo_wine {
10030 ok(GetWindow(hwnd3, GW_HWNDNEXT) == hwnd, "expected %p, got %p\n", hwnd, GetWindow(hwnd3, GW_HWNDNEXT));
10031 ok(GetWindow(hwnd, GW_HWNDNEXT) == hwnd2, "expected %p, got %p\n", hwnd2, GetWindow(hwnd, GW_HWNDNEXT));
10034 /* hide an owner window */
10035 ShowWindow(hwnd, SW_SHOW);
10036 ShowWindow(hwnd2, SW_SHOW);
10037 ShowWindow(hwnd3, SW_SHOW);
10038 ShowWindow(hwnd, SW_HIDE);
10039 check_active_state(hwnd3, hwnd3, hwnd3);
10040 ok(GetWindow(hwnd3, GW_HWNDNEXT) == hwnd, "expected %p, got %p\n", hwnd, GetWindow(hwnd3, GW_HWNDNEXT));
10041 ok(GetWindow(hwnd, GW_HWNDNEXT) == hwnd2, "expected %p, got %p\n", hwnd2, GetWindow(hwnd, GW_HWNDNEXT));
10043 DestroyWindow(hwnd3);
10044 DestroyWindow(hwnd2);
10045 DestroyWindow(hwnd);
10048 static void test_minimize_window(HWND hwndMain)
10050 HWND hwnd, hwnd2, hwnd3;
10052 hwnd = CreateWindowExA(0, "MainWindowClass", "Main window", WS_POPUP | WS_VISIBLE,
10053 100, 100, 200, 200, 0, 0, GetModuleHandleA(NULL), NULL);
10054 hwnd2 = CreateWindowExA(0, "MainWindowClass", "Main window 2", WS_POPUP | WS_VISIBLE,
10055 100, 100, 200, 200, 0, 0, GetModuleHandleA(NULL), NULL);
10056 trace("hwnd = %p, hwnd2 = %p\n", hwnd, hwnd2);
10057 check_active_state(hwnd2, hwnd2, hwnd2);
10059 /* test hiding two normal windows */
10060 ShowWindow(hwnd2, SW_MINIMIZE);
10061 todo_wine
10062 check_active_state(hwnd, hwnd, hwnd);
10064 ShowWindow(hwnd, SW_MINIMIZE);
10065 todo_wine
10066 if (GetActiveWindow() == 0)
10067 check_active_state(0, 0, 0);
10069 ShowWindow(hwnd, SW_RESTORE);
10070 check_active_state(hwnd, hwnd, hwnd);
10072 ShowWindow(hwnd2, SW_RESTORE);
10073 check_active_state(hwnd2, hwnd2, hwnd2);
10075 /* hide a non-active window */
10076 ShowWindow(hwnd, SW_MINIMIZE);
10077 check_active_state(hwnd2, hwnd2, hwnd2);
10079 /* hide a window in the middle */
10080 ShowWindow(hwnd, SW_RESTORE);
10081 ShowWindow(hwnd2, SW_RESTORE);
10082 hwnd3 = CreateWindowExA(0, "MainWindowClass", "Main window 3", WS_POPUP | WS_VISIBLE,
10083 100, 100, 200, 200, 0, 0, GetModuleHandleA(NULL), NULL);
10084 SetActiveWindow(hwnd2);
10085 ShowWindow(hwnd2, SW_MINIMIZE);
10086 todo_wine
10087 check_active_state(hwnd3, hwnd3, hwnd3);
10089 DestroyWindow(hwnd3);
10091 /* hide a normal window when there is a topmost window */
10092 hwnd3 = CreateWindowExA(WS_EX_TOPMOST, "MainWindowClass", "Topmost window 3", WS_POPUP|WS_VISIBLE,
10093 100, 100, 200, 200, 0, 0, GetModuleHandleA(NULL), NULL);
10094 ShowWindow(hwnd, SW_RESTORE);
10095 ShowWindow(hwnd2, SW_RESTORE);
10096 check_active_state(hwnd2, hwnd2, hwnd2);
10097 ShowWindow(hwnd2, SW_MINIMIZE);
10098 todo_wine
10099 check_active_state(hwnd3, hwnd3, hwnd3);
10101 /* hide a topmost window */
10102 ShowWindow(hwnd2, SW_RESTORE);
10103 ShowWindow(hwnd3, SW_RESTORE);
10104 ShowWindow(hwnd3, SW_MINIMIZE);
10105 check_active_state(hwnd2, hwnd2, hwnd2);
10107 DestroyWindow(hwnd3);
10109 /* hide an owned window */
10110 ShowWindow(hwnd, SW_RESTORE);
10111 ShowWindow(hwnd2, SW_RESTORE);
10112 hwnd3 = CreateWindowExA(0, "MainWindowClass", "Owned window 3", WS_POPUP|WS_VISIBLE,
10113 100, 100, 200, 200, hwnd, 0, GetModuleHandleA(NULL), NULL);
10114 ShowWindow(hwnd3, SW_MINIMIZE);
10115 todo_wine
10116 check_active_state(hwnd2, hwnd2, hwnd2);
10118 /* hide an owner window */
10119 ShowWindow(hwnd, SW_RESTORE);
10120 ShowWindow(hwnd2, SW_RESTORE);
10121 ShowWindow(hwnd3, SW_RESTORE);
10122 ShowWindow(hwnd, SW_MINIMIZE);
10123 todo_wine
10124 check_active_state(hwnd2, hwnd2, hwnd2);
10126 DestroyWindow(hwnd3);
10127 DestroyWindow(hwnd2);
10128 DestroyWindow(hwnd);
10131 static void test_desktop( void )
10133 HWND desktop = GetDesktopWindow();
10134 /* GetWindowLong Desktop window tests */
10135 static const struct
10137 int offset;
10138 ULONG_PTR expect;
10139 DWORD error;
10141 tests[] =
10143 { GWLP_USERDATA, 0, 0 },
10144 { GWL_STYLE, WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0 },
10145 { GWL_EXSTYLE, 0, 0 },
10146 { GWLP_ID, 0, 0 },
10147 { GWLP_HWNDPARENT, 0, 0 },
10148 /* GWLP_HINSTANCE - not useful and not consistent between Windows versions */
10149 { GWLP_WNDPROC, 0, ERROR_ACCESS_DENIED },
10150 { DWLP_MSGRESULT, 0, ERROR_INVALID_INDEX }
10152 DWORD_PTR result;
10153 int i;
10155 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
10157 SetLastError( 0xdeadbeef );
10158 result = GetWindowLongPtrW( desktop, tests[i].offset );
10159 ok( result == tests[i].expect, "offset %d, got %08lx expect %08lx\n",
10160 tests[i].offset, result, tests[i].expect );
10161 if (tests[i].error)
10162 ok( GetLastError() == tests[i].error, "offset %d: error %d expect %d\n",
10163 tests[i].offset, GetLastError(), tests[i].error );
10164 else
10165 ok( GetLastError() == 0xdeadbeef, "offset %d: error %d expect unchanged\n",
10166 tests[i].offset, GetLastError() );
10170 static BOOL is_topmost(HWND hwnd)
10172 return (GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST) != 0;
10175 static void swp_after(HWND hwnd, HWND after)
10177 BOOL ret;
10179 ret = SetWindowPos(hwnd, after, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
10180 ok(ret, "SetWindowPos failed\n");
10181 flush_events( TRUE );
10184 static void reset_window_state(HWND *state, int n)
10186 int i;
10188 for (i = 0; i < n; i++)
10190 if (state[i])
10192 swp_after(state[i], HWND_NOTOPMOST);
10193 todo_wine_if(i == 5) /* FIXME: remove once Wine is fixed */
10194 ok(!is_topmost(state[i]), "%d: hwnd %p is still topmost\n", i, state[i]);
10195 swp_after(state[i], HWND_TOP);
10200 static void test_topmost(void)
10202 HWND owner, hwnd, hwnd2, hwnd_child, hwnd_child2, hwnd_grandchild, state[6] = { 0 };
10203 BOOL is_wine = !strcmp(winetest_platform, "wine");
10205 owner = create_tool_window(WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
10206 WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE, 0);
10207 ok(owner != 0, "Failed to create owner window (%d)\n", GetLastError());
10209 /* Give current thread foreground state otherwise the tests may fail. */
10210 if (!SetForegroundWindow(owner))
10212 DestroyWindow(owner);
10213 skip("SetForegroundWindow not working\n");
10214 return;
10217 hwnd = create_tool_window(WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
10218 WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE, owner);
10219 ok(hwnd != 0, "Failed to create popup window (%d)\n", GetLastError());
10220 hwnd2 = create_tool_window(WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
10221 WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE, owner);
10222 ok(hwnd2 != 0, "Failed to create popup window (%d)\n", GetLastError());
10224 flush_events( TRUE );
10226 trace("owner %p, hwnd %p, hwnd2 %p\n", owner, hwnd, hwnd2);
10227 state[0] = owner;
10228 state[1] = hwnd;
10229 state[2] = hwnd2;
10231 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10232 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10233 ok(!is_topmost(hwnd2), "hwnd %p topmost state is wrong\n", hwnd2);
10234 check_z_order(hwnd, 0, hwnd2, owner, FALSE);
10236 swp_after(hwnd, HWND_TOPMOST);
10237 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10238 ok(is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10239 ok(!is_topmost(hwnd2), "hwnd %p topmost state is wrong\n", hwnd2);
10240 check_z_order(hwnd, hwnd2, 0, owner, TRUE);
10241 swp_after(hwnd, HWND_TOP);
10242 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10243 ok(is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10244 ok(!is_topmost(hwnd2), "hwnd %p topmost state is wrong\n", hwnd2);
10245 check_z_order(hwnd, hwnd2, 0, owner, TRUE);
10246 swp_after(hwnd, HWND_NOTOPMOST);
10247 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10248 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10249 ok(!is_topmost(hwnd2), "hwnd %p topmost state is wrong\n", hwnd2);
10250 check_z_order(hwnd, hwnd2, 0, owner, FALSE);
10251 reset_window_state(state, sizeof(state)/sizeof(state[0]));
10253 swp_after(hwnd, HWND_TOPMOST);
10254 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10255 ok(is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10256 ok(!is_topmost(hwnd2), "hwnd %p topmost state is wrong\n", hwnd2);
10257 check_z_order(hwnd, hwnd2, 0, owner, TRUE);
10258 swp_after(hwnd2, hwnd);
10259 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10260 ok(is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10261 ok(!is_topmost(hwnd2), "hwnd %p topmost state is wrong\n", hwnd2);
10262 check_z_order(hwnd, hwnd2, 0, owner, TRUE);
10263 swp_after(hwnd, hwnd2);
10264 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10265 ok(is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10266 ok(!is_topmost(hwnd2), "hwnd %p topmost state is wrong\n", hwnd2);
10267 check_z_order(hwnd, hwnd2, 0, owner, TRUE);
10268 swp_after(hwnd2, HWND_TOP);
10269 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10270 ok(is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10271 ok(!is_topmost(hwnd2), "hwnd %p topmost state is wrong\n", hwnd2);
10272 check_z_order(hwnd, hwnd2, 0, owner, TRUE);
10273 swp_after(owner, HWND_TOPMOST);
10274 todo_wine
10275 ok(is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10276 ok(is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10277 todo_wine
10278 ok(is_topmost(hwnd2), "hwnd %p topmost state is wrong\n", hwnd2);
10279 swp_after(hwnd, HWND_NOTOPMOST);
10280 ok(!is_topmost(owner) || broken(is_topmost(owner)) /*win7 64-bit*/, "hwnd %p topmost state is wrong\n", owner);
10281 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10282 ok(!is_topmost(hwnd2) || broken(is_topmost(hwnd2)) /*win7 64-bit*/, "hwnd %p topmost state is wrong\n", hwnd2);
10283 if (0) /*win7 64-bit is broken*/
10284 check_z_order(hwnd, hwnd2, 0, owner, FALSE);
10285 swp_after(hwnd2, HWND_NOTOPMOST);
10286 ok(!is_topmost(owner) || broken(is_topmost(owner)) /*win7 64-bit*/, "hwnd %p topmost state is wrong\n", owner);
10287 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10288 ok(!is_topmost(hwnd2), "hwnd %p topmost state is wrong\n", hwnd2);
10289 if (!is_wine) /* FIXME: remove once Wine is fixed */
10290 check_z_order(hwnd, 0, hwnd2, owner, FALSE);
10291 reset_window_state(state, sizeof(state)/sizeof(state[0]));
10293 swp_after(hwnd, HWND_TOPMOST);
10294 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10295 ok(is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10296 ok(!is_topmost(hwnd2), "hwnd %p topmost state is wrong\n", hwnd2);
10297 check_z_order(hwnd, hwnd2, 0, owner, TRUE);
10298 swp_after(hwnd, HWND_BOTTOM);
10299 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10300 todo_wine
10301 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10302 ok(!is_topmost(hwnd2), "hwnd %p topmost state is wrong\n", hwnd2);
10303 if (!is_wine) /* FIXME: remove once Wine is fixed */
10304 check_z_order(hwnd, 0, hwnd2, owner, FALSE);
10305 reset_window_state(state, sizeof(state)/sizeof(state[0]));
10307 swp_after(hwnd, HWND_TOPMOST);
10308 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10309 ok(is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10310 ok(!is_topmost(hwnd2), "hwnd %p topmost state is wrong\n", hwnd2);
10311 check_z_order(hwnd, hwnd2, 0, owner, TRUE);
10312 swp_after(hwnd, hwnd2);
10313 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10314 todo_wine
10315 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10316 ok(!is_topmost(hwnd2), "hwnd %p topmost state is wrong\n", hwnd2);
10317 if (!is_wine) /* FIXME: remove once Wine is fixed */
10318 check_z_order(hwnd, 0, hwnd2, owner, FALSE);
10319 /* FIXME: compensate todo_wine above */
10320 swp_after(hwnd, HWND_NOTOPMOST);
10321 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10322 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10323 ok(!is_topmost(hwnd2), "hwnd %p topmost state is wrong\n", hwnd2);
10324 if (!is_wine) /* FIXME: remove once Wine is fixed */
10325 check_z_order(hwnd, 0, hwnd2, owner, FALSE);
10326 reset_window_state(state, sizeof(state)/sizeof(state[0]));
10328 hwnd_child2 = create_tool_window(WS_VISIBLE|WS_POPUP, hwnd);
10329 ok(hwnd_child2 != 0, "Failed to create popup window (%d)\n", GetLastError());
10330 hwnd_child = create_tool_window(WS_VISIBLE|WS_POPUP, hwnd);
10331 ok(hwnd_child != 0, "Failed to create popup window (%d)\n", GetLastError());
10332 hwnd_grandchild = create_tool_window(WS_VISIBLE|WS_POPUP, hwnd_child);
10333 ok(hwnd_grandchild != 0, "Failed to create popup window (%d)\n", GetLastError());
10335 flush_events( TRUE );
10337 trace("hwnd_child %p, hwnd_child2 %p, hwnd_grandchild %p\n", hwnd_child, hwnd_child2, hwnd_grandchild);
10338 state[3] = hwnd_child2;
10339 state[4] = hwnd_child;
10340 state[5] = hwnd_grandchild;
10342 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10343 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10344 ok(!is_topmost(hwnd2), "hwnd %p topmost state is wrong\n", hwnd2);
10345 ok(!is_topmost(hwnd_child), "hwnd %p topmost state is wrong\n", hwnd_child);
10346 ok(!is_topmost(hwnd_child2), "hwnd %p topmost state is wrong\n", hwnd_child2);
10347 ok(!is_topmost(hwnd_grandchild), "hwnd %p topmost state is wrong\n", hwnd_grandchild);
10348 if (!is_wine) /* FIXME: remove once Wine is fixed */
10349 check_z_order(hwnd, hwnd2, 0, owner, FALSE);
10350 check_z_order(hwnd_child, hwnd_child2, 0, hwnd, FALSE);
10352 swp_after(hwnd, HWND_TOPMOST);
10353 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10354 todo_wine
10355 ok(is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10356 todo_wine
10357 ok(is_topmost(hwnd_child), "hwnd %p topmost state is wrong\n", hwnd_child);
10358 todo_wine
10359 ok(is_topmost(hwnd_child2), "hwnd %p topmost state is wrong\n", hwnd_child2);
10360 ok(is_topmost(hwnd_grandchild), "hwnd %p topmost state is wrong\n", hwnd_grandchild);
10361 if (!is_wine) /* FIXME: remove once Wine is fixed */
10362 check_z_order(hwnd, hwnd2, 0, owner, TRUE);
10363 if (!is_wine) /* FIXME: remove once Wine is fixed */
10364 check_z_order(hwnd_child, hwnd_child2, 0, hwnd, TRUE);
10365 swp_after(hwnd, HWND_NOTOPMOST);
10366 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10367 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10368 ok(!is_topmost(hwnd_child), "hwnd %p topmost state is wrong\n", hwnd_child);
10369 ok(!is_topmost(hwnd_child2), "hwnd %p topmost state is wrong\n", hwnd_child2);
10370 todo_wine
10371 ok(!is_topmost(hwnd_grandchild), "hwnd %p topmost state is wrong\n", hwnd_grandchild);
10372 if (!is_wine) /* FIXME: remove once Wine is fixed */
10373 check_z_order(hwnd, hwnd2, 0, owner, FALSE);
10374 check_z_order(hwnd_child, hwnd_child2, 0, hwnd, FALSE);
10375 reset_window_state(state, sizeof(state)/sizeof(state[0]));
10377 swp_after(hwnd, HWND_TOPMOST);
10378 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10379 todo_wine
10380 ok(is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10381 todo_wine
10382 ok(is_topmost(hwnd_child), "hwnd %p topmost state is wrong\n", hwnd_child);
10383 todo_wine
10384 ok(is_topmost(hwnd_child2), "hwnd %p topmost state is wrong\n", hwnd_child2);
10385 ok(is_topmost(hwnd_grandchild), "hwnd %p topmost state is wrong\n", hwnd_grandchild);
10386 if (!is_wine) /* FIXME: remove once Wine is fixed */
10387 check_z_order(hwnd, hwnd2, 0, owner, TRUE);
10388 if (!is_wine) /* FIXME: remove once Wine is fixed */
10389 check_z_order(hwnd_child, hwnd_child2, 0, hwnd, TRUE);
10390 swp_after(hwnd_child, HWND_NOTOPMOST);
10391 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10392 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10393 ok(!is_topmost(hwnd_child), "hwnd %p topmost state is wrong\n", hwnd_child);
10394 ok(!is_topmost(hwnd_child2), "hwnd %p topmost state is wrong\n", hwnd_child2);
10395 todo_wine
10396 ok(!is_topmost(hwnd_grandchild), "hwnd %p topmost state is wrong\n", hwnd_grandchild);
10397 check_z_order(hwnd, hwnd2, 0, owner, FALSE);
10398 check_z_order(hwnd_child, hwnd_child2, 0, hwnd, FALSE);
10399 reset_window_state(state, sizeof(state)/sizeof(state[0]));
10401 swp_after(hwnd, HWND_TOPMOST);
10402 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10403 todo_wine
10404 ok(is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10405 todo_wine
10406 ok(is_topmost(hwnd_child), "hwnd %p topmost state is wrong\n", hwnd_child);
10407 todo_wine
10408 ok(is_topmost(hwnd_child2), "hwnd %p topmost state is wrong\n", hwnd_child2);
10409 ok(is_topmost(hwnd_grandchild), "hwnd %p topmost state is wrong\n", hwnd_grandchild);
10410 if (!is_wine) /* FIXME: remove once Wine is fixed */
10411 check_z_order(hwnd, hwnd2, 0, owner, TRUE);
10412 if (!is_wine) /* FIXME: remove once Wine is fixed */
10413 check_z_order(hwnd_child, hwnd_child2, 0, hwnd, TRUE);
10414 swp_after(hwnd_grandchild, HWND_NOTOPMOST);
10415 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10416 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10417 ok(!is_topmost(hwnd_child), "hwnd %p topmost state is wrong\n", hwnd_child);
10418 ok(!is_topmost(hwnd_child2), "hwnd %p topmost state is wrong\n", hwnd_child2);
10419 todo_wine
10420 ok(!is_topmost(hwnd_grandchild), "hwnd %p topmost state is wrong\n", hwnd_grandchild);
10421 check_z_order(hwnd, hwnd2, 0, owner, FALSE);
10422 check_z_order(hwnd_child, hwnd_child2, 0, hwnd, FALSE);
10423 reset_window_state(state, sizeof(state)/sizeof(state[0]));
10425 swp_after(hwnd_child, HWND_TOPMOST);
10426 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10427 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10428 todo_wine
10429 ok(is_topmost(hwnd_child), "hwnd %p topmost state is wrong\n", hwnd_child);
10430 ok(!is_topmost(hwnd_child2), "hwnd %p topmost state is wrong\n", hwnd_child2);
10431 ok(is_topmost(hwnd_grandchild), "hwnd %p topmost state is wrong\n", hwnd_grandchild);
10432 if (!is_wine) /* FIXME: remove once Wine is fixed */
10433 check_z_order(hwnd, hwnd2, 0, owner, FALSE);
10434 if (!is_wine) /* FIXME: remove once Wine is fixed */
10435 check_z_order(hwnd_child, hwnd_child2, 0, hwnd, TRUE);
10436 swp_after(hwnd_child, HWND_TOP);
10437 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10438 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10439 todo_wine
10440 ok(is_topmost(hwnd_child), "hwnd %p topmost state is wrong\n", hwnd_child);
10441 ok(!is_topmost(hwnd_child2), "hwnd %p topmost state is wrong\n", hwnd_child2);
10442 ok(is_topmost(hwnd_grandchild), "hwnd %p topmost state is wrong\n", hwnd_grandchild);
10443 if (!is_wine) /* FIXME: remove once Wine is fixed */
10444 check_z_order(hwnd, hwnd2, 0, owner, FALSE);
10445 if (!is_wine) /* FIXME: remove once Wine is fixed */
10446 check_z_order(hwnd_child, hwnd_child2, 0, hwnd, TRUE);
10447 swp_after(hwnd, HWND_NOTOPMOST);
10448 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10449 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10450 ok(!is_topmost(hwnd_child), "hwnd %p topmost state is wrong\n", hwnd_child);
10451 ok(!is_topmost(hwnd_child2), "hwnd %p topmost state is wrong\n", hwnd_child2);
10452 todo_wine
10453 ok(!is_topmost(hwnd_grandchild) || broken(is_topmost(hwnd_grandchild))/*win2008 64-bit*/, "hwnd %p topmost state is wrong\n", hwnd_grandchild);
10454 if (!is_wine) /* FIXME: remove once Wine is fixed */
10455 check_z_order(hwnd, hwnd2, 0, owner, FALSE);
10456 check_z_order(hwnd_child, hwnd_child2, 0, hwnd, FALSE);
10457 reset_window_state(state, sizeof(state)/sizeof(state[0]));
10459 swp_after(hwnd_child, HWND_TOPMOST);
10460 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10461 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10462 todo_wine
10463 ok(is_topmost(hwnd_child), "hwnd %p topmost state is wrong\n", hwnd_child);
10464 ok(!is_topmost(hwnd_child2), "hwnd %p topmost state is wrong\n", hwnd_child2);
10465 ok(is_topmost(hwnd_grandchild), "hwnd %p topmost state is wrong\n", hwnd_grandchild);
10466 if (!is_wine) /* FIXME: remove once Wine is fixed */
10467 check_z_order(hwnd, hwnd2, 0, owner, FALSE);
10468 if (!is_wine) /* FIXME: remove once Wine is fixed */
10469 check_z_order(hwnd_child, hwnd_child2, 0, hwnd, TRUE);
10470 swp_after(hwnd, HWND_NOTOPMOST);
10471 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10472 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10473 ok(!is_topmost(hwnd_child), "hwnd %p topmost state is wrong\n", hwnd_child);
10474 ok(!is_topmost(hwnd_child2), "hwnd %p topmost state is wrong\n", hwnd_child2);
10475 todo_wine
10476 ok(!is_topmost(hwnd_grandchild), "hwnd %p topmost state is wrong\n", hwnd_grandchild);
10477 if (!is_wine) /* FIXME: remove once Wine is fixed */
10478 check_z_order(hwnd, hwnd2, 0, owner, FALSE);
10479 check_z_order(hwnd_child, hwnd_child2, 0, hwnd, FALSE);
10480 reset_window_state(state, sizeof(state)/sizeof(state[0]));
10482 swp_after(hwnd_grandchild, HWND_TOPMOST);
10483 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10484 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10485 ok(!is_topmost(hwnd_child), "hwnd %p topmost state is wrong\n", hwnd_child);
10486 ok(!is_topmost(hwnd_child2), "hwnd %p topmost state is wrong\n", hwnd_child2);
10487 ok(is_topmost(hwnd_grandchild), "hwnd %p topmost state is wrong\n", hwnd_grandchild);
10488 if (!is_wine) /* FIXME: remove once Wine is fixed */
10489 check_z_order(hwnd, hwnd2, 0, owner, FALSE);
10490 check_z_order(hwnd_child, hwnd_child2, 0, hwnd, FALSE);
10491 swp_after(hwnd_child2, HWND_NOTOPMOST);
10492 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10493 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10494 ok(!is_topmost(hwnd_child), "hwnd %p topmost state is wrong\n", hwnd_child);
10495 ok(!is_topmost(hwnd_child2), "hwnd %p topmost state is wrong\n", hwnd_child2);
10496 ok(is_topmost(hwnd_grandchild) || broken(!is_topmost(hwnd_grandchild)) /* win8+ */, "hwnd %p topmost state is wrong\n", hwnd_grandchild);
10497 if (!is_wine) /* FIXME: remove once Wine is fixed */
10498 check_z_order(hwnd, hwnd2, 0, owner, FALSE);
10499 if (!is_wine) /* FIXME: remove once Wine is fixed */
10500 check_z_order(hwnd_child, 0, hwnd_child2, hwnd, FALSE);
10501 reset_window_state(state, sizeof(state)/sizeof(state[0]));
10503 swp_after(hwnd_child, HWND_TOPMOST);
10504 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10505 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10506 todo_wine
10507 ok(is_topmost(hwnd_child), "hwnd %p topmost state is wrong\n", hwnd_child);
10508 ok(!is_topmost(hwnd_child2), "hwnd %p topmost state is wrong\n", hwnd_child2);
10509 ok(is_topmost(hwnd_grandchild), "hwnd %p topmost state is wrong\n", hwnd_grandchild);
10510 if (!is_wine) /* FIXME: remove once Wine is fixed */
10511 check_z_order(hwnd, hwnd2, 0, owner, FALSE);
10512 if (!is_wine) /* FIXME: remove once Wine is fixed */
10513 check_z_order(hwnd_child, hwnd_child2, 0, hwnd, TRUE);
10514 swp_after(hwnd_child, HWND_BOTTOM);
10515 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10516 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10517 ok(!is_topmost(hwnd_child), "hwnd %p topmost state is wrong\n", hwnd_child);
10518 ok(!is_topmost(hwnd_child2), "hwnd %p topmost state is wrong\n", hwnd_child2);
10519 todo_wine
10520 ok(!is_topmost(hwnd_grandchild), "hwnd %p topmost state is wrong\n", hwnd_grandchild);
10521 if (!is_wine) /* FIXME: remove once Wine is fixed */
10522 check_z_order(hwnd, 0, hwnd2, owner, FALSE);
10523 if (!is_wine) /* FIXME: remove once Wine is fixed */
10524 check_z_order(hwnd_child, 0, hwnd_child2, hwnd, FALSE);
10525 reset_window_state(state, sizeof(state)/sizeof(state[0]));
10527 swp_after(hwnd_child, HWND_TOPMOST);
10528 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10529 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10530 todo_wine
10531 ok(is_topmost(hwnd_child), "hwnd %p topmost state is wrong\n", hwnd_child);
10532 ok(!is_topmost(hwnd_child2), "hwnd %p topmost state is wrong\n", hwnd_child2);
10533 ok(is_topmost(hwnd_grandchild), "hwnd %p topmost state is wrong\n", hwnd_grandchild);
10534 if (!is_wine) /* FIXME: remove once Wine is fixed */
10535 check_z_order(hwnd, hwnd2, 0, owner, FALSE);
10536 if (!is_wine) /* FIXME: remove once Wine is fixed */
10537 check_z_order(hwnd_child, hwnd_child2, 0, hwnd, TRUE);
10538 swp_after(hwnd_child, hwnd_child2);
10539 ok(!is_topmost(owner), "hwnd %p topmost state is wrong\n", owner);
10540 ok(!is_topmost(hwnd), "hwnd %p topmost state is wrong\n", hwnd);
10541 ok(!is_topmost(hwnd_child), "hwnd %p topmost state is wrong\n", hwnd_child);
10542 ok(!is_topmost(hwnd_child2), "hwnd %p topmost state is wrong\n", hwnd_child2);
10543 todo_wine
10544 ok(!is_topmost(hwnd_grandchild), "hwnd %p topmost state is wrong\n", hwnd_grandchild);
10545 if (!is_wine) /* FIXME: remove once Wine is fixed */
10546 check_z_order(hwnd, hwnd2, 0, owner, FALSE);
10547 if (!is_wine) /* FIXME: remove once Wine is fixed */
10548 check_z_order(hwnd_child, 0, hwnd_child2, hwnd, FALSE);
10549 reset_window_state(state, sizeof(state)/sizeof(state[0]));
10551 DestroyWindow(hwnd_grandchild);
10552 DestroyWindow(hwnd_child);
10553 DestroyWindow(hwnd_child2);
10554 DestroyWindow(hwnd);
10555 DestroyWindow(hwnd2);
10556 DestroyWindow(owner);
10559 START_TEST(win)
10561 char **argv;
10562 int argc = winetest_get_mainargs( &argv );
10563 HMODULE user32 = GetModuleHandleA( "user32.dll" );
10564 HMODULE gdi32 = GetModuleHandleA("gdi32.dll");
10565 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
10566 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
10567 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
10568 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
10569 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
10570 pUpdateLayeredWindow = (void *)GetProcAddress( user32, "UpdateLayeredWindow" );
10571 pUpdateLayeredWindowIndirect = (void *)GetProcAddress( user32, "UpdateLayeredWindowIndirect" );
10572 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
10573 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
10574 pGetWindowRgnBox = (void *)GetProcAddress( user32, "GetWindowRgnBox" );
10575 pGetGUIThreadInfo = (void *)GetProcAddress( user32, "GetGUIThreadInfo" );
10576 pGetProcessDefaultLayout = (void *)GetProcAddress( user32, "GetProcessDefaultLayout" );
10577 pSetProcessDefaultLayout = (void *)GetProcAddress( user32, "SetProcessDefaultLayout" );
10578 pFlashWindow = (void *)GetProcAddress( user32, "FlashWindow" );
10579 pFlashWindowEx = (void *)GetProcAddress( user32, "FlashWindowEx" );
10580 pGetLayout = (void *)GetProcAddress( gdi32, "GetLayout" );
10581 pSetLayout = (void *)GetProcAddress( gdi32, "SetLayout" );
10582 pMirrorRgn = (void *)GetProcAddress( gdi32, "MirrorRgn" );
10584 if (argc==4 && !strcmp(argv[2], "create_children"))
10586 HWND hwnd;
10588 sscanf(argv[3], "%p", &hwnd);
10589 window_from_point_proc(hwnd);
10590 return;
10593 if (argc==3 && !strcmp(argv[2], "winproc_limit"))
10595 test_winproc_limit();
10596 return;
10599 if (!RegisterWindowClasses()) assert(0);
10601 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
10602 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
10603 WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE,
10604 100, 100, 200, 200,
10605 0, 0, GetModuleHandleA(NULL), NULL);
10606 assert( hwndMain );
10608 if(!SetForegroundWindow(hwndMain)) {
10609 /* workaround for foreground lock timeout */
10610 simulate_click(101, 101);
10611 ok(SetForegroundWindow(hwndMain), "SetForegroundWindow failed\n");
10614 SetLastError(0xdeafbeef);
10615 GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC);
10616 is_win9x = (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED);
10618 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
10619 if (!hhook) win_skip( "Cannot set CBT hook, skipping some tests\n" );
10621 /* make sure that these tests are executed first */
10622 test_FindWindowEx();
10623 test_FindWindow();
10624 test_SetParent();
10626 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
10627 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
10628 WS_MAXIMIZEBOX | WS_POPUP,
10629 100, 100, 200, 200,
10630 0, 0, GetModuleHandleA(NULL), NULL);
10631 assert( hwndMain2 );
10633 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
10635 /* Add the tests below this line */
10636 test_child_window_from_point();
10637 test_window_from_point(argv[0]);
10638 test_thick_child_size(hwndMain);
10639 test_fullscreen();
10640 test_hwnd_message();
10641 test_nonclient_area(hwndMain);
10642 test_params();
10643 test_GetWindowModuleFileName();
10644 test_capture_1();
10645 test_capture_2();
10646 test_capture_3(hwndMain, hwndMain2);
10647 test_capture_4();
10648 test_rtl_layout();
10649 test_FlashWindow();
10650 test_FlashWindowEx();
10652 test_CreateWindow();
10653 test_parent_owner();
10654 test_enum_thread_windows();
10656 test_mdi();
10657 test_icons();
10658 test_SetWindowPos(hwndMain, hwndMain2);
10659 test_SetMenu(hwndMain);
10660 test_SetFocus(hwndMain);
10661 test_SetActiveWindow(hwndMain);
10662 test_NCRedraw();
10664 test_children_zorder(hwndMain);
10665 test_popup_zorder(hwndMain2, hwndMain, WS_POPUP);
10666 test_popup_zorder(hwndMain2, hwndMain, 0);
10667 test_GetLastActivePopup();
10668 test_keyboard_input(hwndMain);
10669 test_mouse_input(hwndMain);
10670 test_validatergn(hwndMain);
10671 test_nccalcscroll( hwndMain);
10672 test_scrollwindow( hwndMain);
10673 test_scrollvalidate( hwndMain);
10674 test_scrolldc( hwndMain);
10675 test_scroll();
10676 test_IsWindowUnicode();
10677 test_vis_rgn(hwndMain);
10679 test_AdjustWindowRect();
10680 test_window_styles();
10681 test_dialog_styles();
10682 test_dialog_parent();
10683 test_redrawnow();
10684 test_csparentdc();
10685 test_SetWindowLong();
10686 test_set_window_style();
10687 test_ShowWindow();
10688 test_EnableWindow();
10689 test_gettext();
10690 test_GetUpdateRect();
10691 test_Expose();
10692 test_layered_window();
10694 test_SetForegroundWindow(hwndMain);
10695 test_shell_window();
10696 test_handles( hwndMain );
10697 test_winregion();
10698 test_map_points();
10699 test_update_region();
10700 test_window_without_child_style();
10701 test_smresult();
10702 test_GetMessagePos();
10703 test_activateapp(hwndMain);
10704 test_winproc_handles(argv[0]);
10705 test_deferwindowpos();
10706 test_LockWindowUpdate(hwndMain);
10707 test_desktop();
10708 test_hide_window();
10709 test_minimize_window(hwndMain);
10711 /* add the tests above this line */
10712 if (hhook) UnhookWindowsHookEx(hhook);
10714 DestroyWindow(hwndMain2);
10715 DestroyWindow(hwndMain);
10717 /* Make sure that following tests are executed last, under Windows they
10718 * tend to break the tests which are sensitive to z-order and activation
10719 * state of hwndMain and hwndMain2 windows.
10721 test_topmost();