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
35 #include "wine/test.h"
37 #ifndef SPI_GETDESKWALLPAPER
38 #define SPI_GETDESKWALLPAPER 0x0073
42 #define WM_SYSTIMER 0x0118
45 #define LONG_PTR INT_PTR
46 #define ULONG_PTR UINT_PTR
48 void dump_region(HRGN hrgn
);
50 static BOOL (WINAPI
*pGetWindowInfo
)(HWND
,WINDOWINFO
*);
51 static UINT (WINAPI
*pGetWindowModuleFileNameA
)(HWND
,LPSTR
,UINT
);
52 static BOOL (WINAPI
*pGetLayeredWindowAttributes
)(HWND
,COLORREF
*,BYTE
*,DWORD
*);
53 static BOOL (WINAPI
*pSetLayeredWindowAttributes
)(HWND
,COLORREF
,BYTE
,DWORD
);
54 static BOOL (WINAPI
*pUpdateLayeredWindow
)(HWND
,HDC
,POINT
*,SIZE
*,HDC
,POINT
*,COLORREF
,BLENDFUNCTION
*,DWORD
);
55 static BOOL (WINAPI
*pUpdateLayeredWindowIndirect
)(HWND
,const UPDATELAYEREDWINDOWINFO
*);
56 static int (WINAPI
*pGetWindowRgnBox
)(HWND
,LPRECT
);
57 static BOOL (WINAPI
*pGetGUIThreadInfo
)(DWORD
, GUITHREADINFO
*);
58 static BOOL (WINAPI
*pGetProcessDefaultLayout
)( DWORD
*layout
);
59 static BOOL (WINAPI
*pSetProcessDefaultLayout
)( DWORD layout
);
60 static BOOL (WINAPI
*pFlashWindow
)( HWND hwnd
, BOOL bInvert
);
61 static BOOL (WINAPI
*pFlashWindowEx
)( PFLASHWINFO pfwi
);
62 static BOOL (WINAPI
*pMirrorRgn
)(HWND hwnd
, HRGN hrgn
);
63 static BOOL (WINAPI
*pGetWindowDisplayAffinity
)(HWND hwnd
, DWORD
*affinity
);
64 static BOOL (WINAPI
*pSetWindowDisplayAffinity
)(HWND hwnd
, DWORD affinity
);
65 static BOOL (WINAPI
*pAdjustWindowRectExForDpi
)(LPRECT
,DWORD
,BOOL
,DWORD
,UINT
);
66 static BOOL (WINAPI
*pSystemParametersInfoForDpi
)(UINT
,UINT
,void*,UINT
,UINT
);
68 static BOOL test_lbuttondown_flag
;
69 static DWORD num_gettext_msgs
;
70 static DWORD num_settext_msgs
;
71 static HWND hwndMessage
;
72 static HWND hwndMain
, hwndMain2
;
74 static BOOL app_activated
, app_deactivated
;
76 static const char* szAWRClass
= "Winsize";
80 static void dump_minmax_info( const MINMAXINFO
*minmax
)
82 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
83 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
84 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
85 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
86 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
87 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
90 /* try to make sure pending X events have been processed before continuing */
91 static void flush_events( BOOL remove_messages
)
95 int min_timeout
= 100;
96 DWORD time
= GetTickCount() + diff
;
100 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
102 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
103 diff
= time
- GetTickCount();
108 static BOOL
wait_for_event(HANDLE event
, int timeout
)
110 DWORD end_time
= GetTickCount() + timeout
;
114 if(MsgWaitForMultipleObjects(1, &event
, FALSE
, timeout
, QS_ALLINPUT
) == WAIT_OBJECT_0
)
116 while(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
117 DispatchMessageA(&msg
);
118 timeout
= end_time
- GetTickCount();
124 /* check the values returned by the various parent/owner functions on a given window */
125 static void check_parents( HWND hwnd
, HWND ga_parent
, HWND gwl_parent
, HWND get_parent
,
126 HWND gw_owner
, HWND ga_root
, HWND ga_root_owner
)
130 res
= GetAncestor( hwnd
, GA_PARENT
);
131 ok( res
== ga_parent
, "Wrong result for GA_PARENT %p expected %p\n", res
, ga_parent
);
132 res
= (HWND
)GetWindowLongPtrA( hwnd
, GWLP_HWNDPARENT
);
133 ok( res
== gwl_parent
, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res
, gwl_parent
);
134 res
= GetParent( hwnd
);
135 ok( res
== get_parent
, "Wrong result for GetParent %p expected %p\n", res
, get_parent
);
136 res
= GetWindow( hwnd
, GW_OWNER
);
137 ok( res
== gw_owner
, "Wrong result for GW_OWNER %p expected %p\n", res
, gw_owner
);
138 res
= GetAncestor( hwnd
, GA_ROOT
);
139 ok( res
== ga_root
, "Wrong result for GA_ROOT %p expected %p\n", res
, ga_root
);
140 res
= GetAncestor( hwnd
, GA_ROOTOWNER
);
141 ok( res
== ga_root_owner
, "Wrong result for GA_ROOTOWNER %p expected %p\n", res
, ga_root_owner
);
144 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
145 static void check_wnd_state_(const char *file
, int line
,
146 HWND active
, HWND foreground
, HWND focus
, HWND capture
)
148 ok_(file
, line
)(active
== GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
149 /* only check foreground if it belongs to the current thread */
150 /* foreground can be moved to a different app pretty much at any time */
151 if (foreground
&& GetForegroundWindow() &&
152 GetWindowThreadProcessId(GetForegroundWindow(), NULL
) == GetCurrentThreadId())
153 ok_(file
, line
)(foreground
== GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
154 ok_(file
, line
)(focus
== GetFocus(), "GetFocus() = %p\n", GetFocus());
155 ok_(file
, line
)(capture
== GetCapture(), "GetCapture() = %p\n", GetCapture());
158 /* same as above but without capture test */
159 #define check_active_state(a,b,c) check_active_state_(__FILE__,__LINE__,a,b,c)
160 static void check_active_state_(const char *file
, int line
,
161 HWND active
, HWND foreground
, HWND focus
)
163 ok_(file
, line
)(active
== GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
164 /* only check foreground if it belongs to the current thread */
165 /* foreground can be moved to a different app pretty much at any time */
166 if (foreground
&& GetForegroundWindow() &&
167 GetWindowThreadProcessId(GetForegroundWindow(), NULL
) == GetCurrentThreadId())
168 ok_(file
, line
)(foreground
== GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
169 ok_(file
, line
)(focus
== GetFocus(), "GetFocus() = %p\n", GetFocus());
172 static BOOL
ignore_message( UINT message
)
174 /* these are always ignored */
175 return (message
>= 0xc000 ||
176 message
== WM_GETICON
||
177 message
== WM_GETOBJECT
||
178 message
== WM_TIMER
||
179 message
== WM_SYSTIMER
||
180 message
== WM_TIMECHANGE
||
181 message
== WM_DEVICECHANGE
||
182 message
== 0x0060 /* undocumented, used by Win10 1709+ */);
185 static BOOL CALLBACK
EnumChildProc( HWND hwndChild
, LPARAM lParam
)
188 if (*(LPINT
)lParam
> 1) return FALSE
;
192 /* will search for the given window */
193 static BOOL CALLBACK
EnumChildProc1( HWND hwndChild
, LPARAM lParam
)
195 if ((HWND
)lParam
== hwndChild
) return FALSE
;
199 static HWND
create_tool_window( LONG style
, HWND parent
)
201 HWND ret
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style
,
202 0, 0, 100, 100, parent
, 0, 0, NULL
);
203 ok( ret
!= 0, "Creation failed\n" );
207 /* test parent and owner values for various combinations */
208 static void test_parent_owner(void)
211 HWND test
, owner
, ret
;
212 HWND desktop
= GetDesktopWindow();
213 HWND child
= create_tool_window( WS_CHILD
, hwndMain
);
216 if (winetest_debug
> 1)
217 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain
, hwndMain2
, desktop
, child
);
219 /* child without parent, should fail */
220 SetLastError(0xdeadbeef);
221 test
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
222 WS_CHILD
, 0, 0, 100, 100, 0, 0, 0, NULL
);
223 ok( !test
, "WS_CHILD without parent created\n" );
224 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD
, "CreateWindowExA error %u\n", GetLastError() );
227 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
228 style
= GetWindowLongA( desktop
, GWL_STYLE
);
229 ok( !SetWindowLongA( desktop
, GWL_STYLE
, WS_POPUP
), "Set GWL_STYLE on desktop succeeded\n" );
230 ok( !SetWindowLongA( desktop
, GWL_STYLE
, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
231 ok( GetWindowLongA( desktop
, GWL_STYLE
) == style
, "Desktop style changed\n" );
233 /* normal child window */
234 test
= create_tool_window( WS_CHILD
, hwndMain
);
235 if (winetest_debug
> 1) trace( "created child %p\n", test
);
236 check_parents( test
, hwndMain
, hwndMain
, hwndMain
, 0, hwndMain
, hwndMain
);
237 SetWindowLongA( test
, GWL_STYLE
, 0 );
238 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
239 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
240 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
241 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
|WS_CHILD
);
242 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
243 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
244 DestroyWindow( test
);
246 /* normal child window with WS_MAXIMIZE */
247 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
248 DestroyWindow( test
);
250 /* normal child window with WS_THICKFRAME */
251 test
= create_tool_window( WS_CHILD
| WS_THICKFRAME
, hwndMain
);
252 DestroyWindow( test
);
254 /* popup window with WS_THICKFRAME */
255 test
= create_tool_window( WS_POPUP
| WS_THICKFRAME
, hwndMain
);
256 DestroyWindow( test
);
258 /* child of desktop */
259 test
= create_tool_window( WS_CHILD
, desktop
);
260 if (winetest_debug
> 1) trace( "created child of desktop %p\n", test
);
261 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
262 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
263 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
264 SetWindowLongA( test
, GWL_STYLE
, 0 );
265 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
266 DestroyWindow( test
);
268 /* child of desktop with WS_MAXIMIZE */
269 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, desktop
);
270 DestroyWindow( test
);
272 /* child of desktop with WS_MINIMIZE */
273 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, desktop
);
274 DestroyWindow( test
);
277 test
= create_tool_window( WS_CHILD
, child
);
278 if (winetest_debug
> 1) trace( "created child of child %p\n", test
);
279 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
280 SetWindowLongA( test
, GWL_STYLE
, 0 );
281 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
282 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
283 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
284 DestroyWindow( test
);
286 /* child of child with WS_MAXIMIZE */
287 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, child
);
288 DestroyWindow( test
);
290 /* child of child with WS_MINIMIZE */
291 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, child
);
292 DestroyWindow( test
);
294 /* not owned top-level window */
295 test
= create_tool_window( 0, 0 );
296 if (winetest_debug
> 1) trace( "created top-level %p\n", test
);
297 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
298 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
299 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
300 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
301 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
302 DestroyWindow( test
);
304 /* not owned top-level window with WS_MAXIMIZE */
305 test
= create_tool_window( WS_MAXIMIZE
, 0 );
306 DestroyWindow( test
);
308 /* owned top-level window */
309 test
= create_tool_window( 0, hwndMain
);
310 if (winetest_debug
> 1) trace( "created owned top-level %p\n", test
);
311 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
312 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
313 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
314 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
315 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
316 DestroyWindow( test
);
318 /* owned top-level window with WS_MAXIMIZE */
319 test
= create_tool_window( WS_MAXIMIZE
, hwndMain
);
320 DestroyWindow( test
);
322 /* not owned popup */
323 test
= create_tool_window( WS_POPUP
, 0 );
324 if (winetest_debug
> 1) trace( "created popup %p\n", test
);
325 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
326 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
327 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
328 SetWindowLongA( test
, GWL_STYLE
, 0 );
329 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
330 DestroyWindow( test
);
332 /* not owned popup with WS_MAXIMIZE */
333 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, 0 );
334 DestroyWindow( test
);
337 test
= create_tool_window( WS_POPUP
, hwndMain
);
338 if (winetest_debug
> 1) trace( "created owned popup %p\n", test
);
339 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
340 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
341 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
342 SetWindowLongA( test
, GWL_STYLE
, 0 );
343 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
344 DestroyWindow( test
);
346 /* owned popup with WS_MAXIMIZE */
347 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, hwndMain
);
348 DestroyWindow( test
);
350 /* top-level window owned by child (same as owned by top-level) */
351 test
= create_tool_window( 0, child
);
352 if (winetest_debug
> 1) trace( "created top-level owned by child %p\n", test
);
353 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
354 DestroyWindow( test
);
356 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
357 test
= create_tool_window( WS_MAXIMIZE
, child
);
358 DestroyWindow( test
);
360 /* popup owned by desktop (same as not owned) */
361 test
= create_tool_window( WS_POPUP
, desktop
);
362 if (winetest_debug
> 1) trace( "created popup owned by desktop %p\n", test
);
363 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
364 DestroyWindow( test
);
366 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
367 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, desktop
);
368 DestroyWindow( test
);
370 /* popup owned by child (same as owned by top-level) */
371 test
= create_tool_window( WS_POPUP
, child
);
372 if (winetest_debug
> 1) trace( "created popup owned by child %p\n", test
);
373 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
374 DestroyWindow( test
);
376 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
377 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, child
);
378 DestroyWindow( test
);
380 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
381 test
= create_tool_window( WS_POPUP
| WS_CHILD
, 0 );
382 if (winetest_debug
> 1) trace( "created WS_CHILD popup %p\n", test
);
383 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
384 DestroyWindow( test
);
386 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
387 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, 0 );
388 DestroyWindow( test
);
390 /* owned popup with WS_CHILD (same as WS_POPUP only) */
391 test
= create_tool_window( WS_POPUP
| WS_CHILD
, hwndMain
);
392 if (winetest_debug
> 1) trace( "created owned WS_CHILD popup %p\n", test
);
393 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
394 DestroyWindow( test
);
396 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
397 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
398 DestroyWindow( test
);
400 /******************** parent changes *************************/
403 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
404 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
405 ok( !ret
, "Set GWL_HWNDPARENT succeeded on desktop\n" );
406 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
407 ok( !SetParent( desktop
, hwndMain
), "SetParent succeeded on desktop\n" );
408 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
409 /* normal child window */
410 test
= create_tool_window( WS_CHILD
, hwndMain
);
411 if (winetest_debug
> 1) trace( "created child %p\n", test
);
413 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
414 ok( ret
== hwndMain
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain
);
415 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
417 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
418 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
419 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
421 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)desktop
);
422 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
423 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
425 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
426 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)test
);
427 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
428 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
430 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
431 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
432 check_parents( test
, desktop
, child
, desktop
, child
, test
, desktop
);
434 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
435 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
436 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
437 DestroyWindow( test
);
439 /* not owned top-level window */
440 test
= create_tool_window( 0, 0 );
441 if (winetest_debug
> 1) trace( "created top-level %p\n", test
);
443 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
444 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
445 check_parents( test
, desktop
, hwndMain2
, 0, hwndMain2
, test
, test
);
447 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
448 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
449 check_parents( test
, desktop
, child
, 0, child
, test
, test
);
451 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
452 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
453 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
454 DestroyWindow( test
);
456 /* not owned popup */
457 test
= create_tool_window( WS_POPUP
, 0 );
458 if (winetest_debug
> 1) trace( "created popup %p\n", test
);
460 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
461 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
462 check_parents( test
, desktop
, hwndMain2
, hwndMain2
, hwndMain2
, test
, hwndMain2
);
464 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
465 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
466 check_parents( test
, desktop
, child
, child
, child
, test
, hwndMain
);
468 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
469 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
470 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
471 DestroyWindow( test
);
473 /* normal child window */
474 test
= create_tool_window( WS_CHILD
, hwndMain
);
475 if (winetest_debug
> 1) trace( "created child %p\n", test
);
477 ret
= SetParent( test
, desktop
);
478 ok( ret
== hwndMain
, "SetParent return value %p expected %p\n", ret
, hwndMain
);
479 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
481 ret
= SetParent( test
, child
);
482 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
483 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
485 ret
= SetParent( test
, hwndMain2
);
486 ok( ret
== child
, "SetParent return value %p expected %p\n", ret
, child
);
487 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
488 DestroyWindow( test
);
490 /* not owned top-level window */
491 test
= create_tool_window( 0, 0 );
492 if (winetest_debug
> 1) trace( "created top-level %p\n", test
);
494 ret
= SetParent( test
, child
);
495 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
496 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
498 ShowWindow( test
, SW_SHOW
);
499 ret
= SetParent( test
, test
);
500 ok( ret
== NULL
, "SetParent return value %p expected %p\n", ret
, NULL
);
501 ok( GetWindowLongA( test
, GWL_STYLE
) & WS_VISIBLE
, "window is not visible after SetParent\n" );
502 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
503 DestroyWindow( test
);
506 test
= create_tool_window( WS_POPUP
, hwndMain2
);
507 if (winetest_debug
> 1) trace( "created owned popup %p\n", test
);
509 ret
= SetParent( test
, child
);
510 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
511 check_parents( test
, child
, child
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
513 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)hwndMain
);
514 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
515 check_parents( test
, hwndMain
, hwndMain
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
516 DestroyWindow( test
);
518 /**************** test owner destruction *******************/
520 /* owned child popup */
521 owner
= create_tool_window( 0, 0 );
522 test
= create_tool_window( WS_POPUP
, owner
);
523 if (winetest_debug
> 1) trace( "created owner %p and popup %p\n", owner
, test
);
524 ret
= SetParent( test
, child
);
525 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
526 check_parents( test
, child
, child
, owner
, owner
, hwndMain
, owner
);
527 /* window is now child of 'child' but owned by 'owner' */
528 DestroyWindow( owner
);
529 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
530 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
531 * while Win95, Win2k, WinXP do.
533 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
534 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
537 /* owned top-level popup */
538 owner
= create_tool_window( 0, 0 );
539 test
= create_tool_window( WS_POPUP
, owner
);
540 if (winetest_debug
> 1) trace( "created owner %p and popup %p\n", owner
, test
);
541 check_parents( test
, desktop
, owner
, owner
, owner
, test
, owner
);
542 DestroyWindow( owner
);
543 ok( !IsWindow(test
), "Window %p not destroyed by owner destruction\n", test
);
545 /* top-level popup owned by child */
546 owner
= create_tool_window( WS_CHILD
, hwndMain2
);
547 test
= create_tool_window( WS_POPUP
, 0 );
548 if (winetest_debug
> 1) trace( "created owner %p and popup %p\n", owner
, test
);
549 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)owner
);
550 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
551 check_parents( test
, desktop
, owner
, owner
, owner
, test
, hwndMain2
);
552 DestroyWindow( owner
);
553 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
554 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
555 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
556 * while Win95, Win2k, WinXP do.
558 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
562 DestroyWindow(child
);
565 owner
= create_tool_window( WS_OVERLAPPED
, 0 );
566 test
= create_tool_window( WS_POPUP
, desktop
);
568 ok( !GetWindow( test
, GW_OWNER
), "Wrong owner window\n" );
570 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
571 "EnumChildWindows should have returned FALSE\n" );
572 ok( numChildren
== 0, "numChildren should be 0 got %d\n", numChildren
);
574 SetWindowLongA( test
, GWL_STYLE
, (GetWindowLongA( test
, GWL_STYLE
) & ~WS_POPUP
) | WS_CHILD
);
575 ret
= SetParent( test
, owner
);
576 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
579 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
580 "EnumChildWindows should have returned TRUE\n" );
581 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
583 child
= create_tool_window( WS_CHILD
, owner
);
585 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
586 "EnumChildWindows should have returned FALSE\n" );
587 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
588 DestroyWindow( child
);
590 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, owner
);
591 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
593 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
594 "EnumChildWindows should have returned TRUE\n" );
595 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
597 ret
= SetParent( child
, owner
);
598 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
599 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
601 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
602 "EnumChildWindows should have returned FALSE\n" );
603 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
605 ret
= SetParent( child
, NULL
);
606 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
607 ok( ret
== owner
, "SetParent return value %p expected %p\n", ret
, owner
);
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 /* even GW_OWNER == owner it's still a desktop's child */
614 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
615 "EnumChildWindows should have found %p and returned FALSE\n", child
);
617 DestroyWindow( child
);
618 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, NULL
);
620 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
621 "EnumChildWindows should have found %p and returned FALSE\n", child
);
623 DestroyWindow( child
);
624 DestroyWindow( test
);
625 DestroyWindow( owner
);
627 /* Test that owner window takes into account WS_CHILD flag even if parent is set by SetParent. */
628 owner
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, desktop
);
629 SetParent(owner
, hwndMain
);
630 check_parents( owner
, hwndMain
, hwndMain
, NULL
, NULL
, hwndMain
, owner
);
631 test
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, owner
);
632 check_parents( test
, desktop
, owner
, NULL
, owner
, test
, test
);
633 DestroyWindow( owner
);
634 DestroyWindow( test
);
636 owner
= create_tool_window( WS_VISIBLE
| WS_CHILD
, desktop
);
637 SetParent(owner
, hwndMain
);
638 check_parents( owner
, hwndMain
, hwndMain
, hwndMain
, NULL
, hwndMain
, hwndMain
);
639 test
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, owner
);
640 check_parents( test
, desktop
, hwndMain
, NULL
, hwndMain
, test
, test
);
641 DestroyWindow( owner
);
642 DestroyWindow( test
);
644 owner
= create_tool_window( WS_VISIBLE
| WS_POPUP
| WS_CHILD
, desktop
);
645 SetParent(owner
, hwndMain
);
646 check_parents( owner
, hwndMain
, hwndMain
, NULL
, NULL
, hwndMain
, owner
);
647 test
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, owner
);
648 check_parents( test
, desktop
, owner
, NULL
, owner
, test
, test
);
649 DestroyWindow( owner
);
650 DestroyWindow( test
);
653 static BOOL CALLBACK
enum_proc( HWND hwnd
, LPARAM lParam
)
656 if (*(LPINT
)lParam
> 2) return FALSE
;
659 static DWORD CALLBACK
enum_thread( void *arg
)
666 if (pGetGUIThreadInfo
)
669 info
.cbSize
= sizeof(info
);
670 ret
= pGetGUIThreadInfo( GetCurrentThreadId(), &info
);
671 ok( ret
, "GetGUIThreadInfo failed without message queue\n" );
672 SetLastError( 0xdeadbeef );
673 info
.cbSize
= sizeof(info
) + 1;
674 ret
= pGetGUIThreadInfo( GetCurrentThreadId(), &info
);
675 ok( !ret
, "GetGUIThreadInfo succeeded with wrong size\n" );
676 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %u\n", GetLastError() );
679 PeekMessageA( &msg
, 0, 0, 0, PM_NOREMOVE
); /* make sure we have a message queue */
682 ret
= EnumThreadWindows( GetCurrentThreadId(), enum_proc
, (LPARAM
)&count
);
683 ok( ret
, "EnumThreadWindows should have returned TRUE\n" );
684 ok( count
== 0, "count should be 0 got %d\n", count
);
686 hwnd
[0] = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", WS_POPUP
,
687 0, 0, 100, 100, 0, 0, 0, NULL
);
689 ret
= EnumThreadWindows( GetCurrentThreadId(), enum_proc
, (LPARAM
)&count
);
690 ok( ret
, "EnumThreadWindows should have returned TRUE\n" );
691 if (count
!= 2) /* Vista gives us two windows for the price of one */
693 ok( count
== 1, "count should be 1 got %d\n", count
);
694 hwnd
[2] = CreateWindowExA(0, "ToolWindowClass", "Tool window 2", WS_POPUP
,
695 0, 0, 100, 100, 0, 0, 0, NULL
);
699 hwnd
[1] = CreateWindowExA(0, "ToolWindowClass", "Tool window 3", WS_POPUP
,
700 0, 0, 100, 100, 0, 0, 0, NULL
);
702 ret
= EnumThreadWindows( GetCurrentThreadId(), enum_proc
, (LPARAM
)&count
);
703 ok( !ret
, "EnumThreadWindows should have returned FALSE\n" );
704 ok( count
== 3, "count should be 3 got %d\n", count
);
706 if (hwnd
[2]) DestroyWindow(hwnd
[2]);
707 DestroyWindow(hwnd
[1]);
708 DestroyWindow(hwnd
[0]);
712 /* test EnumThreadWindows in a separate thread */
713 static void test_enum_thread_windows(void)
716 HANDLE handle
= CreateThread( NULL
, 0, enum_thread
, 0, 0, &id
);
717 ok( !WaitForSingleObject( handle
, 10000 ), "wait failed\n" );
718 CloseHandle( handle
);
721 static struct wm_gettext_override_data
723 BOOL enabled
; /* when 1 bypasses default procedure */
724 BOOL dont_terminate
; /* don't null terminate returned string in WM_GETTEXT handler */
725 char *buff
; /* expected text buffer pointer */
726 WCHAR
*buffW
; /* same, for W test */
727 } g_wm_gettext_override
;
729 static LRESULT WINAPI
main_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
733 case WM_GETMINMAXINFO
:
735 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
738 case WM_WINDOWPOSCHANGING
:
740 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
741 if (!(winpos
->flags
& SWP_NOMOVE
))
743 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
744 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
746 if (!(winpos
->flags
& SWP_NOSIZE
))
748 ok((winpos
->cx
>= 0 && winpos
->cx
<= 32767) ||
749 winpos
->cx
== 32768, /* win7 doesn't truncate */
750 "bad winpos->cx %d\n", winpos
->cx
);
751 ok((winpos
->cy
>= 0 && winpos
->cy
<= 32767) ||
752 winpos
->cy
== 40000, /* win7 doesn't truncate */
753 "bad winpos->cy %d\n", winpos
->cy
);
757 case WM_WINDOWPOSCHANGED
:
760 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
761 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
762 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
764 ok((winpos
->cx
>= 0 && winpos
->cx
<= 32767) ||
765 winpos
->cx
== 32768, /* win7 doesn't truncate */
766 "bad winpos->cx %d\n", winpos
->cx
);
767 ok((winpos
->cy
>= 0 && winpos
->cy
<= 32767) ||
768 winpos
->cy
== 40000, /* win7 doesn't truncate */
769 "bad winpos->cy %d\n", winpos
->cy
);
771 GetWindowRect(hwnd
, &rc1
);
772 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
773 /* note: winpos coordinates are relative to parent */
774 MapWindowPoints(GetAncestor(hwnd
,GA_PARENT
), 0, (LPPOINT
)&rc2
, 2);
775 ok(EqualRect(&rc1
, &rc2
), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1
),
776 wine_dbgstr_rect(&rc2
));
778 GetClientRect(hwnd
, &rc2
);
779 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
780 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
781 ok(EqualRect(&rc1
, &rc2
), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1
),
782 wine_dbgstr_rect(&rc2
));
787 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
788 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
790 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
791 ok(got_getminmaxinfo
, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
793 ok(!got_getminmaxinfo
, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
797 if (test_lbuttondown_flag
)
799 ShowWindow((HWND
)wparam
, SW_SHOW
);
800 flush_events( FALSE
);
805 if (g_wm_gettext_override
.enabled
)
807 char *text
= (char*)lparam
;
808 ok(g_wm_gettext_override
.buff
== text
, "expected buffer %p, got %p\n", g_wm_gettext_override
.buff
, text
);
809 ok(*text
== 0, "expected empty string buffer %x\n", *text
);
812 else if (g_wm_gettext_override
.dont_terminate
)
814 char *text
= (char *)lparam
;
817 memcpy(text
, "text", 4);
827 if (wparam
) app_activated
= TRUE
;
828 else app_deactivated
= TRUE
;
830 case WM_MOUSEACTIVATE
:
834 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
837 static LRESULT WINAPI
main_window_procW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
843 if (g_wm_gettext_override
.enabled
)
845 WCHAR
*text
= (WCHAR
*)lparam
;
846 ok(g_wm_gettext_override
.buffW
== text
, "expected buffer %p, got %p\n", g_wm_gettext_override
.buffW
, text
);
847 ok(*text
== 0, "expected empty string buffer %x\n", *text
);
850 else if (g_wm_gettext_override
.dont_terminate
)
852 static const WCHAR textW
[] = {'t','e','x','t'};
853 WCHAR
*text
= (WCHAR
*)lparam
;
856 memcpy(text
, textW
, sizeof(textW
));
864 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
867 static LRESULT WINAPI
tool_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
871 case WM_GETMINMAXINFO
:
873 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
878 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
879 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
881 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
882 ok(got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
884 ok(!got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
889 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
892 static const WCHAR mainclassW
[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s','W',0};
894 static BOOL
RegisterWindowClasses(void)
899 cls
.style
= CS_DBLCLKS
;
900 cls
.lpfnWndProc
= main_window_procA
;
903 cls
.hInstance
= GetModuleHandleA(0);
905 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
906 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
907 cls
.lpszMenuName
= NULL
;
908 cls
.lpszClassName
= "MainWindowClass";
910 if(!RegisterClassA(&cls
)) return FALSE
;
912 clsW
.style
= CS_DBLCLKS
;
913 clsW
.lpfnWndProc
= main_window_procW
;
916 clsW
.hInstance
= GetModuleHandleA(0);
918 clsW
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
919 clsW
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
920 clsW
.lpszMenuName
= NULL
;
921 clsW
.lpszClassName
= mainclassW
;
923 if(!RegisterClassW(&clsW
)) return FALSE
;
926 cls
.lpfnWndProc
= tool_window_procA
;
929 cls
.hInstance
= GetModuleHandleA(0);
931 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
932 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
933 cls
.lpszMenuName
= NULL
;
934 cls
.lpszClassName
= "ToolWindowClass";
936 if(!RegisterClassA(&cls
)) return FALSE
;
941 static void verify_window_info(const char *hook
, HWND hwnd
, const WINDOWINFO
*info
)
943 RECT rcWindow
, rcClient
;
946 ok(IsWindow(hwnd
), "bad window handle %p in hook %s\n", hwnd
, hook
);
948 GetWindowRect(hwnd
, &rcWindow
);
949 ok(EqualRect(&rcWindow
, &info
->rcWindow
), "wrong rcWindow for %p in hook %s\n", hwnd
, hook
);
951 GetClientRect(hwnd
, &rcClient
);
952 /* translate to screen coordinates */
953 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rcClient
, 2);
954 ok(EqualRect(&rcClient
, &info
->rcClient
), "wrong rcClient for %p in hook %s\n", hwnd
, hook
);
956 ok(info
->dwStyle
== (DWORD
)GetWindowLongA(hwnd
, GWL_STYLE
),
957 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
958 info
->dwStyle
, GetWindowLongA(hwnd
, GWL_STYLE
), hwnd
, hook
);
959 /* Windows reports some undocumented exstyles in WINDOWINFO, but
960 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
962 ok((info
->dwExStyle
& ~0xe0000800) == (DWORD
)GetWindowLongA(hwnd
, GWL_EXSTYLE
),
963 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
964 info
->dwExStyle
, GetWindowLongA(hwnd
, GWL_EXSTYLE
), hwnd
, hook
);
965 status
= (GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0;
966 if (GetForegroundWindow())
967 ok(info
->dwWindowStatus
== status
, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
968 info
->dwWindowStatus
, status
, GetActiveWindow(), GetForegroundWindow(), hook
);
970 /* win2k and XP return broken border info in GetWindowInfo most of
971 * the time, so there is no point in testing it.
976 ok(info
->cxWindowBorders
== (unsigned)(rcClient
.left
- rcWindow
.left
),
977 "wrong cxWindowBorders %d != %d\n", info
->cxWindowBorders
, rcClient
.left
- rcWindow
.left
);
978 border
= min(rcWindow
.bottom
- rcClient
.bottom
, rcClient
.top
- rcWindow
.top
);
979 ok(info
->cyWindowBorders
== border
,
980 "wrong cyWindowBorders %d != %d\n", info
->cyWindowBorders
, border
);
982 ok(info
->atomWindowType
== GetClassLongA(hwnd
, GCW_ATOM
), "wrong atomWindowType for %p in hook %s\n",
984 ok(info
->wCreatorVersion
== 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
985 info
->wCreatorVersion
== 0x0500 /* Vista */,
986 "wrong wCreatorVersion %04x for %p in hook %s\n", info
->wCreatorVersion
, hwnd
, hook
);
989 static void test_window_info(const char *hook
, HWND hwnd
)
991 WINDOWINFO info
, info2
;
993 if (0) /* crashes on Win10 */
994 ok(!pGetWindowInfo(hwnd
, NULL
), "GetWindowInfo should fail\n");
996 if (0) { /* crashes on XP, 2003 */
997 SetLastError(0xdeadbeef);
998 ok(!pGetWindowInfo(0, NULL
), "GetWindowInfo should fail\n");
999 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
,
1000 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
1003 SetLastError(0xdeadbeef);
1004 ok(!pGetWindowInfo(0, &info
), "GetWindowInfo should fail\n");
1005 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
,
1006 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
1008 info
.cbSize
= sizeof(WINDOWINFO
);
1009 ok(pGetWindowInfo(hwnd
, &info
), "GetWindowInfo should not fail\n");
1010 verify_window_info(hook
, hwnd
, &info
);
1012 /* test different cbSize values.
1013 * Windows ignores it (except for Win98, according to an old comment).
1015 memset(&info
, 0xcc, sizeof(WINDOWINFO
));
1016 memset(&info2
, 0xcc, sizeof(WINDOWINFO
));
1018 info
.cbSize
= sizeof(WINDOWINFO
);
1019 info2
.cbSize
= sizeof(WINDOWINFO
);
1021 ok(pGetWindowInfo(hwnd
, &info
), "GetWindowInfo should not fail\n");
1022 ok(pGetWindowInfo(hwnd
, &info2
), "GetWindowInfo should not fail\n");
1023 ok(memcmp(&info
, &info2
, sizeof(WINDOWINFO
)) == 0, "identical GetWindowInfo calls produce different result\n");
1025 memset(&info2
, 0xcc, sizeof(WINDOWINFO
));
1027 ok(pGetWindowInfo(hwnd
, &info2
), "GetWindowInfo should not fail\n");
1028 info2
.cbSize
= sizeof(WINDOWINFO
);
1029 ok(memcmp(&info
, &info2
, sizeof(WINDOWINFO
)) == 0, "GetWindowInfo cbSize should be ignored\n");
1031 memset(&info2
, 0xcc, sizeof(WINDOWINFO
));
1032 info2
.cbSize
= sizeof(WINDOWINFO
)/2;
1033 ok(pGetWindowInfo(hwnd
, &info2
), "GetWindowInfo should not fail\n");
1034 info2
.cbSize
= sizeof(WINDOWINFO
);
1035 ok(memcmp(&info
, &info2
, sizeof(WINDOWINFO
)) == 0, "GetWindowInfo cbSize should be ignored\n");
1037 memset(&info2
, 0xcc, sizeof(WINDOWINFO
));
1038 info2
.cbSize
= UINT_MAX
;
1039 ok(pGetWindowInfo(hwnd
, &info2
), "GetWindowInfo should not fail\n");
1040 info2
.cbSize
= sizeof(WINDOWINFO
);
1041 ok(memcmp(&info
, &info2
, sizeof(WINDOWINFO
)) == 0, "GetWindowInfo cbSize should be ignored\n");
1044 static void FixedAdjustWindowRectEx(RECT
* rc
, LONG style
, BOOL menu
, LONG exstyle
)
1046 AdjustWindowRectEx(rc
, style
, menu
, exstyle
);
1047 /* AdjustWindowRectEx does not include scroll bars */
1048 if (style
& WS_VSCROLL
)
1050 if(exstyle
& WS_EX_LEFTSCROLLBAR
)
1051 rc
->left
-= GetSystemMetrics(SM_CXVSCROLL
);
1053 rc
->right
+= GetSystemMetrics(SM_CXVSCROLL
);
1055 if (style
& WS_HSCROLL
)
1056 rc
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
1059 /* reimplement it to check that the Wine algorithm gives the correct result */
1060 static void wine_AdjustWindowRectEx( RECT
*rect
, LONG style
, BOOL menu
, LONG exStyle
)
1062 NONCLIENTMETRICSW ncm
;
1065 ncm
.cbSize
= offsetof( NONCLIENTMETRICSW
, iPaddedBorderWidth
);
1066 SystemParametersInfoW( SPI_GETNONCLIENTMETRICS
, 0, &ncm
, 0 );
1068 if ((exStyle
& (WS_EX_STATICEDGE
|WS_EX_DLGMODALFRAME
)) == WS_EX_STATICEDGE
)
1069 adjust
= 1; /* for the outer frame always present */
1070 else if ((exStyle
& WS_EX_DLGMODALFRAME
) || (style
& (WS_THICKFRAME
|WS_DLGFRAME
)))
1071 adjust
= 2; /* outer */
1073 if (style
& WS_THICKFRAME
) adjust
+= ncm
.iBorderWidth
; /* The resize border */
1074 if ((style
& (WS_BORDER
|WS_DLGFRAME
)) || (exStyle
& WS_EX_DLGMODALFRAME
))
1075 adjust
++; /* The other border */
1077 InflateRect (rect
, adjust
, adjust
);
1079 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1081 if (exStyle
& WS_EX_TOOLWINDOW
)
1082 rect
->top
-= ncm
.iSmCaptionHeight
+ 1;
1084 rect
->top
-= ncm
.iCaptionHeight
+ 1;
1086 if (menu
) rect
->top
-= ncm
.iMenuHeight
+ 1;
1088 if (exStyle
& WS_EX_CLIENTEDGE
)
1089 InflateRect(rect
, GetSystemMetrics(SM_CXEDGE
), GetSystemMetrics(SM_CYEDGE
));
1091 if (style
& WS_VSCROLL
)
1093 if((exStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
1094 rect
->left
-= GetSystemMetrics(SM_CXVSCROLL
);
1096 rect
->right
+= GetSystemMetrics(SM_CXVSCROLL
);
1098 if (style
& WS_HSCROLL
) rect
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
1101 static void wine_AdjustWindowRectExForDpi( RECT
*rect
, LONG style
, BOOL menu
, LONG exStyle
, UINT dpi
)
1103 NONCLIENTMETRICSW ncm
;
1106 ncm
.cbSize
= sizeof(ncm
);
1107 pSystemParametersInfoForDpi( SPI_GETNONCLIENTMETRICS
, sizeof(ncm
), &ncm
, 0, dpi
);
1109 if ((exStyle
& (WS_EX_STATICEDGE
|WS_EX_DLGMODALFRAME
)) == WS_EX_STATICEDGE
)
1110 adjust
= 1; /* for the outer frame always present */
1111 else if ((exStyle
& WS_EX_DLGMODALFRAME
) || (style
& (WS_THICKFRAME
|WS_DLGFRAME
)))
1112 adjust
= 2; /* outer */
1114 if (style
& WS_THICKFRAME
) adjust
+= ncm
.iBorderWidth
+ ncm
.iPaddedBorderWidth
;
1116 if ((style
& (WS_BORDER
|WS_DLGFRAME
)) || (exStyle
& WS_EX_DLGMODALFRAME
))
1117 adjust
++; /* The other border */
1119 InflateRect (rect
, adjust
, adjust
);
1121 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1123 if (exStyle
& WS_EX_TOOLWINDOW
)
1124 rect
->top
-= ncm
.iSmCaptionHeight
+ 1;
1126 rect
->top
-= ncm
.iCaptionHeight
+ 1;
1128 if (menu
) rect
->top
-= ncm
.iMenuHeight
+ 1;
1130 if (exStyle
& WS_EX_CLIENTEDGE
)
1131 InflateRect(rect
, GetSystemMetrics(SM_CXEDGE
), GetSystemMetrics(SM_CYEDGE
));
1134 static void test_nonclient_area(HWND hwnd
)
1136 DWORD style
, exstyle
;
1137 RECT rc_window
, rc_client
, rc
;
1141 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1142 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1143 menu
= !(style
& WS_CHILD
) && GetMenu(hwnd
) != 0;
1145 GetWindowRect(hwnd
, &rc_window
);
1146 GetClientRect(hwnd
, &rc_client
);
1148 /* avoid some cases when things go wrong */
1149 if (IsRectEmpty(&rc_window
) || IsRectEmpty(&rc_client
) ||
1150 rc_window
.right
> 32768 || rc_window
.bottom
> 32768) return;
1153 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc
, 2);
1154 FixedAdjustWindowRectEx(&rc
, style
, menu
, exstyle
);
1156 ok(EqualRect(&rc
, &rc_window
),
1157 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=%s, calc=%s\n",
1158 style
, exstyle
, menu
, wine_dbgstr_rect(&rc_window
), wine_dbgstr_rect(&rc
));
1161 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc
, 2);
1162 wine_AdjustWindowRectEx(&rc
, style
, menu
, exstyle
);
1163 ok(EqualRect(&rc
, &rc_window
),
1164 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=%s, calc=%s\n",
1165 style
, exstyle
, menu
, wine_dbgstr_rect(&rc_window
), wine_dbgstr_rect(&rc
));
1169 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
1170 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
1171 ok(EqualRect(&rc
, &rc_client
),
1172 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=%s, calc=%s\n",
1173 style
, exstyle
, menu
, wine_dbgstr_rect(&rc_client
), wine_dbgstr_rect(&rc
));
1175 /* NULL rectangle shouldn't crash */
1176 ret
= DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, 0);
1177 ok(ret
== 0, "NULL rectangle returned %ld instead of 0\n", ret
);
1179 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
1180 SetRect(&rc_client
, 0, 0, 250, 150);
1181 rc_window
= rc_client
;
1182 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc_window
, 2);
1183 FixedAdjustWindowRectEx(&rc_window
, style
, menu
, exstyle
);
1186 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
1187 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
1188 ok(EqualRect(&rc
, &rc_client
),
1189 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=%s, calc=%s\n",
1190 style
, exstyle
, menu
, wine_dbgstr_rect(&rc_client
), wine_dbgstr_rect(&rc
));
1193 static LRESULT CALLBACK
cbt_hook_proc(int nCode
, WPARAM wParam
, LPARAM lParam
)
1195 static const char *CBT_code_name
[10] = {
1202 "HCBT_CLICKSKIPPED",
1206 const char *code_name
= (nCode
>= 0 && nCode
<= HCBT_SETFOCUS
) ? CBT_code_name
[nCode
] : "Unknown";
1207 HWND hwnd
= (HWND
)wParam
;
1211 case HCBT_CREATEWND
:
1213 static const RECT rc_null
;
1216 CBT_CREATEWNDA
*createwnd
= (CBT_CREATEWNDA
*)lParam
;
1217 ok(createwnd
->hwndInsertAfter
== HWND_TOP
, "hwndInsertAfter should be always HWND_TOP\n");
1220 test_window_info(code_name
, hwnd
);
1222 /* WS_VISIBLE should be turned off yet */
1223 style
= createwnd
->lpcs
->style
& ~WS_VISIBLE
;
1224 ok(style
== GetWindowLongA(hwnd
, GWL_STYLE
),
1225 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
1226 GetWindowLongA(hwnd
, GWL_STYLE
), style
);
1230 /* Uncomment this once the test succeeds in all cases */
1231 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1233 ok(GetParent(hwnd
) == hwndMessage
,
1234 "wrong result from GetParent %p: message window %p\n",
1235 GetParent(hwnd
), hwndMessage
);
1238 ok(!GetParent(hwnd
), "GetParent should return 0 at this point\n");
1240 ok(!GetWindow(hwnd
, GW_OWNER
), "GW_OWNER should be set to 0 at this point\n");
1244 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
1245 * Win9x still has them set to 0.
1247 ok(GetWindow(hwnd
, GW_HWNDFIRST
) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
1248 ok(GetWindow(hwnd
, GW_HWNDLAST
) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
1250 ok(!GetWindow(hwnd
, GW_HWNDPREV
), "GW_HWNDPREV should be set to 0 at this point\n");
1251 ok(!GetWindow(hwnd
, GW_HWNDNEXT
), "GW_HWNDNEXT should be set to 0 at this point\n");
1255 /* Uncomment this once the test succeeds in all cases */
1256 ok(GetAncestor(hwnd
, GA_PARENT
) == hwndMessage
, "GA_PARENT should be set to hwndMessage at this point\n");
1257 ok(GetAncestor(hwnd
, GA_ROOT
) == hwnd
,
1258 "GA_ROOT is set to %p, expected %p\n", GetAncestor(hwnd
, GA_ROOT
), hwnd
);
1260 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1261 ok(GetAncestor(hwnd
, GA_ROOTOWNER
) == hwndMessage
,
1262 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
1264 ok(GetAncestor(hwnd
, GA_ROOTOWNER
) == hwnd
,
1265 "GA_ROOTOWNER is set to %p, expected %p\n", GetAncestor(hwnd
, GA_ROOTOWNER
), hwnd
);
1267 ok(GetWindowRect(hwnd
, &rc
), "GetWindowRect failed\n");
1268 ok(EqualRect(&rc
, &rc_null
), "window rect should be set to 0 HCBT_CREATEWND\n");
1269 ok(GetClientRect(hwnd
, &rc
), "GetClientRect failed\n");
1270 ok(EqualRect(&rc
, &rc_null
), "client rect should be set to 0 on HCBT_CREATEWND\n");
1277 if (pGetWindowInfo
&& IsWindow(hwnd
))
1278 test_window_info(code_name
, hwnd
);
1280 /* window state is undefined */
1282 case HCBT_DESTROYWND
:
1288 return CallNextHookEx(hhook
, nCode
, wParam
, lParam
);
1291 static DWORD WINAPI
test_shell_window_thread(LPVOID param
)
1294 HMODULE hinst
, hUser32
;
1295 BOOL (WINAPI
*SetShellWindow
)(HWND
);
1296 HWND hwnd1
, hwnd2
, hwnd3
, hwnd4
, hwnd5
;
1297 HWND shellWindow
, nextWnd
;
1298 HDESK testDesktop
= (HDESK
)param
;
1300 SetThreadDesktop(testDesktop
);
1302 shellWindow
= GetShellWindow();
1303 hinst
= GetModuleHandleA(NULL
);
1304 hUser32
= GetModuleHandleA("user32");
1306 ok(shellWindow
== NULL
, "Newly created desktop has a shell window %p\n", shellWindow
);
1308 SetShellWindow
= (void *)GetProcAddress(hUser32
, "SetShellWindow");
1310 hwnd1
= CreateWindowExA(0, "#32770", "TEST1", WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst
, 0);
1312 ret
= SetShellWindow(hwnd1
);
1313 ok(ret
, "first call to SetShellWindow(hwnd1)\n");
1314 shellWindow
= GetShellWindow();
1315 ok(shellWindow
==hwnd1
, "wrong shell window: %p/%p\n", shellWindow
,hwnd1
);
1317 ret
= SetShellWindow(hwnd1
);
1318 ok(!ret
, "second call to SetShellWindow(hwnd1)\n");
1320 ret
= SetShellWindow(0);
1321 /* passes on Win XP, but not on Win98
1322 DWORD error = GetLastError();
1323 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1324 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1326 ret
= SetShellWindow(hwnd1
);
1327 /* passes on Win XP, but not on Win98
1328 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1330 SetWindowLongA(hwnd1
, GWL_EXSTYLE
, GetWindowLongA(hwnd1
,GWL_EXSTYLE
)|WS_EX_TOPMOST
);
1331 ret
= (GetWindowLongA(hwnd1
,GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0;
1332 ok(!ret
, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1334 ret
= DestroyWindow(hwnd1
);
1335 ok(ret
, "DestroyWindow(hwnd1)\n");
1337 hwnd2
= CreateWindowExA(WS_EX_TOPMOST
, "#32770", "TEST2", WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst
, 0);
1338 ret
= SetShellWindow(hwnd2
);
1339 ok(!ret
, "SetShellWindow(%p) with WS_EX_TOPMOST\n", hwnd2
);
1341 hwnd3
= CreateWindowExA(0, "#32770", "TEST3", WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst
, 0);
1343 hwnd4
= CreateWindowExA(0, "#32770", "TEST4", WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst
, 0);
1345 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1346 ok(nextWnd
==hwnd3
, "wrong next window for hwnd4 %p: %p - expected %p\n", hwnd4
, nextWnd
, hwnd3
);
1348 ret
= SetShellWindow(hwnd4
);
1349 ok(ret
, "SetShellWindow(hwnd4)\n");
1350 shellWindow
= GetShellWindow();
1351 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected %p\n", shellWindow
, hwnd4
);
1353 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1354 ok(nextWnd
==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd
);
1356 ret
= SetWindowPos(hwnd4
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1357 ok(ret
, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1359 ret
= SetWindowPos(hwnd4
, hwnd3
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1360 ok(ret
, "SetWindowPos(hwnd4, hwnd3\n");
1362 ret
= SetShellWindow(hwnd3
);
1363 ok(!ret
, "SetShellWindow(hwnd3)\n");
1364 shellWindow
= GetShellWindow();
1365 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected %p\n", shellWindow
, hwnd4
);
1367 hwnd5
= CreateWindowExA(0, "#32770", "TEST5", WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst
, 0);
1368 ret
= SetWindowPos(hwnd4
, hwnd5
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1369 ok(ret
, "SetWindowPos(hwnd4, hwnd5)\n");
1373 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1374 ok(nextWnd
==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd
);
1377 /* destroy test windows */
1378 DestroyWindow(hwnd2
);
1379 DestroyWindow(hwnd3
);
1380 DestroyWindow(hwnd4
);
1381 DestroyWindow(hwnd5
);
1386 static void test_shell_window(void)
1391 hdesk
= CreateDesktopA("winetest", NULL
, NULL
, 0, GENERIC_ALL
, NULL
);
1393 hthread
= CreateThread(NULL
, 0, test_shell_window_thread
, (LPVOID
)hdesk
, 0, NULL
);
1395 WaitForSingleObject(hthread
, INFINITE
);
1397 DeleteObject(hthread
);
1399 CloseDesktop(hdesk
);
1402 /************** MDI test ****************/
1404 static char mdi_lParam_test_message
[] = "just a test string";
1406 static void test_MDI_create(HWND parent
, HWND mdi_client
, INT_PTR first_id
)
1408 MDICREATESTRUCTA mdi_cs
;
1409 HWND mdi_child
, hwnd
, exp_hwnd
;
1411 static const WCHAR classW
[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1412 static const WCHAR titleW
[] = {'M','D','I',' ','c','h','i','l','d',0};
1413 HMENU frame_menu
= GetMenu(parent
);
1415 ok(frame_menu
!= NULL
, "Frame window didn't have a menu\n");
1417 mdi_cs
.szClass
= "MDI_child_Class_1";
1418 mdi_cs
.szTitle
= "MDI child";
1419 mdi_cs
.hOwner
= GetModuleHandleA(NULL
);
1420 mdi_cs
.x
= CW_USEDEFAULT
;
1421 mdi_cs
.y
= CW_USEDEFAULT
;
1422 mdi_cs
.cx
= CW_USEDEFAULT
;
1423 mdi_cs
.cy
= CW_USEDEFAULT
;
1425 mdi_cs
.lParam
= (LPARAM
)mdi_lParam_test_message
;
1426 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1427 ok(mdi_child
!= 0, "MDI child creation failed\n");
1428 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1429 ok(id
== first_id
, "wrong child id %ld\n", id
);
1430 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1431 exp_hwnd
= (GetWindowLongW(mdi_child
, GWL_STYLE
) & WS_VISIBLE
) ? mdi_child
: 0;
1432 ok(hwnd
== exp_hwnd
, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd
, hwnd
);
1433 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1434 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1436 mdi_cs
.style
= 0x7fffffff; /* without WS_POPUP */
1437 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1438 ok(mdi_child
!= 0, "MDI child creation failed\n");
1439 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1440 ok(id
== first_id
, "wrong child id %ld\n", id
);
1441 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1442 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1443 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1444 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1446 mdi_cs
.style
= 0xffffffff; /* with WS_POPUP */
1447 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1448 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1450 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1454 ok(mdi_child
!= 0, "MDI child creation failed\n");
1455 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1456 ok(id
== first_id
, "wrong child id %ld\n", id
);
1457 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1458 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1459 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1460 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1461 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1464 /* test MDICREATESTRUCT A<->W mapping */
1465 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1467 mdi_cs
.szClass
= (LPCSTR
)classW
;
1468 mdi_cs
.szTitle
= (LPCSTR
)titleW
;
1469 SetLastError(0xdeadbeef);
1470 mdi_child
= (HWND
)SendMessageW(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1471 ok(mdi_child
!= 0, "MDI child creation failed\n");
1472 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1473 ok(id
== first_id
, "wrong child id %ld\n", id
);
1474 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1475 exp_hwnd
= (GetWindowLongW(mdi_child
, GWL_STYLE
) & WS_VISIBLE
) ? mdi_child
: 0;
1476 ok(hwnd
== exp_hwnd
, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd
, hwnd
);
1477 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1478 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1479 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1481 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1483 CW_USEDEFAULT
, CW_USEDEFAULT
,
1484 CW_USEDEFAULT
, CW_USEDEFAULT
,
1485 mdi_client
, GetModuleHandleA(NULL
),
1486 (LPARAM
)mdi_lParam_test_message
);
1487 ok(mdi_child
!= 0, "MDI child creation failed\n");
1488 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1489 ok(id
== first_id
, "wrong child id %ld\n", id
);
1490 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1491 exp_hwnd
= (GetWindowLongW(mdi_child
, GWL_STYLE
) & WS_VISIBLE
) ? mdi_child
: 0;
1492 ok(hwnd
== exp_hwnd
, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd
, hwnd
);
1493 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1494 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1495 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1497 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1498 0x7fffffff, /* without WS_POPUP */
1499 CW_USEDEFAULT
, CW_USEDEFAULT
,
1500 CW_USEDEFAULT
, CW_USEDEFAULT
,
1501 mdi_client
, GetModuleHandleA(NULL
),
1502 (LPARAM
)mdi_lParam_test_message
);
1503 ok(mdi_child
!= 0, "MDI child creation failed\n");
1504 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1505 ok(id
== first_id
, "wrong child id %ld\n", id
);
1506 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1507 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1508 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1509 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1510 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1512 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1513 0xffffffff, /* with WS_POPUP */
1514 CW_USEDEFAULT
, CW_USEDEFAULT
,
1515 CW_USEDEFAULT
, CW_USEDEFAULT
,
1516 mdi_client
, GetModuleHandleA(NULL
),
1517 (LPARAM
)mdi_lParam_test_message
);
1518 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1520 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1524 ok(mdi_child
!= 0, "MDI child creation failed\n");
1525 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1526 ok(id
== first_id
, "wrong child id %ld\n", id
);
1527 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1528 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1529 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1530 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1531 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1534 /* test MDICREATESTRUCT A<->W mapping */
1535 SetLastError(0xdeadbeef);
1536 mdi_child
= CreateMDIWindowW(classW
, titleW
,
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 exp_hwnd
= (GetWindowLongW(mdi_child
, GWL_STYLE
) & WS_VISIBLE
) ? mdi_child
: 0;
1547 ok(hwnd
== exp_hwnd
, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd
, hwnd
);
1548 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1549 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1550 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1552 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1554 CW_USEDEFAULT
, CW_USEDEFAULT
,
1555 CW_USEDEFAULT
, CW_USEDEFAULT
,
1556 mdi_client
, 0, GetModuleHandleA(NULL
),
1557 mdi_lParam_test_message
);
1558 ok(mdi_child
!= 0, "MDI child creation failed\n");
1559 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1560 ok(id
== first_id
, "wrong child id %ld\n", id
);
1561 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1562 exp_hwnd
= (GetWindowLongW(mdi_child
, GWL_STYLE
) & WS_VISIBLE
) ? mdi_child
: 0;
1563 ok(hwnd
== exp_hwnd
, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd
, hwnd
);
1564 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1565 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1566 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1568 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1570 CW_USEDEFAULT
, CW_USEDEFAULT
,
1571 CW_USEDEFAULT
, CW_USEDEFAULT
,
1572 mdi_client
, 0, GetModuleHandleA(NULL
),
1573 mdi_lParam_test_message
);
1574 ok(mdi_child
!= 0, "MDI child creation failed\n");
1575 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1576 ok(id
== first_id
, "wrong child id %ld\n", id
);
1577 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1578 exp_hwnd
= (GetWindowLongW(mdi_child
, GWL_STYLE
) & WS_VISIBLE
) ? mdi_child
: 0;
1579 ok(hwnd
== exp_hwnd
, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd
, hwnd
);
1580 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1581 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1583 ok(GetMenuItemCount(frame_menu
) == 4, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1584 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1585 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1587 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1588 0x7fffffff, /* without WS_POPUP */
1589 CW_USEDEFAULT
, CW_USEDEFAULT
,
1590 CW_USEDEFAULT
, CW_USEDEFAULT
,
1591 mdi_client
, 0, GetModuleHandleA(NULL
),
1592 mdi_lParam_test_message
);
1593 ok(mdi_child
!= 0, "MDI child creation failed\n");
1594 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1595 ok(id
== first_id
, "wrong child id %ld\n", id
);
1596 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1597 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1598 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1599 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1600 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1602 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1603 0xffffffff, /* with WS_POPUP */
1604 CW_USEDEFAULT
, CW_USEDEFAULT
,
1605 CW_USEDEFAULT
, CW_USEDEFAULT
,
1606 mdi_client
, 0, GetModuleHandleA(NULL
),
1607 mdi_lParam_test_message
);
1608 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1610 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1614 ok(mdi_child
!= 0, "MDI child creation failed\n");
1615 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1616 ok(id
== first_id
, "wrong child id %ld\n", id
);
1617 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1618 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1619 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1620 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1621 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1624 /* test MDICREATESTRUCT A<->W mapping */
1625 SetLastError(0xdeadbeef);
1626 mdi_child
= CreateWindowExW(WS_EX_MDICHILD
, classW
, titleW
,
1628 CW_USEDEFAULT
, CW_USEDEFAULT
,
1629 CW_USEDEFAULT
, CW_USEDEFAULT
,
1630 mdi_client
, 0, GetModuleHandleA(NULL
),
1631 mdi_lParam_test_message
);
1632 ok(mdi_child
!= 0, "MDI child creation failed\n");
1633 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1634 ok(id
== first_id
, "wrong child id %ld\n", id
);
1635 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1636 exp_hwnd
= (GetWindowLongW(mdi_child
, GWL_STYLE
) & WS_VISIBLE
) ? mdi_child
: 0;
1637 ok(hwnd
== exp_hwnd
, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd
, hwnd
);
1638 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1639 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1640 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1642 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_2", "MDI child",
1644 CW_USEDEFAULT
, CW_USEDEFAULT
,
1645 CW_USEDEFAULT
, CW_USEDEFAULT
,
1646 parent
, 0, GetModuleHandleA(NULL
),
1647 mdi_lParam_test_message
);
1648 ok(!mdi_child
, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1650 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1651 WS_CHILD
, /* without WS_POPUP */
1652 CW_USEDEFAULT
, CW_USEDEFAULT
,
1653 CW_USEDEFAULT
, CW_USEDEFAULT
,
1654 mdi_client
, 0, GetModuleHandleA(NULL
),
1655 mdi_lParam_test_message
);
1656 ok(mdi_child
!= 0, "MDI child creation failed\n");
1657 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1658 ok(id
== 0, "wrong child id %ld\n", id
);
1659 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1660 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1661 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1662 DestroyWindow(mdi_child
);
1664 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1665 WS_CHILD
| WS_POPUP
, /* with WS_POPUP */
1666 CW_USEDEFAULT
, CW_USEDEFAULT
,
1667 CW_USEDEFAULT
, CW_USEDEFAULT
,
1668 mdi_client
, 0, GetModuleHandleA(NULL
),
1669 mdi_lParam_test_message
);
1670 ok(mdi_child
!= 0, "MDI child creation failed\n");
1671 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1672 ok(id
== 0, "wrong child id %ld\n", id
);
1673 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1674 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1675 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1676 DestroyWindow(mdi_child
);
1678 /* maximized child */
1679 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1680 WS_CHILD
| WS_MAXIMIZE
,
1681 CW_USEDEFAULT
, CW_USEDEFAULT
,
1682 CW_USEDEFAULT
, CW_USEDEFAULT
,
1683 mdi_client
, 0, GetModuleHandleA(NULL
),
1684 mdi_lParam_test_message
);
1685 ok(mdi_child
!= 0, "MDI child creation failed\n");
1686 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1687 ok(id
== 0, "wrong child id %ld\n", id
);
1688 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1689 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1690 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1691 DestroyWindow(mdi_child
);
1693 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1694 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
,
1695 CW_USEDEFAULT
, CW_USEDEFAULT
,
1696 CW_USEDEFAULT
, CW_USEDEFAULT
,
1697 mdi_client
, 0, GetModuleHandleA(NULL
),
1698 mdi_lParam_test_message
);
1699 ok(mdi_child
!= 0, "MDI child creation failed\n");
1700 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1701 ok(id
== 0, "wrong child id %ld\n", id
);
1702 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1703 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1704 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1705 DestroyWindow(mdi_child
);
1707 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1708 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
| WS_THICKFRAME
,
1709 CW_USEDEFAULT
, CW_USEDEFAULT
,
1710 CW_USEDEFAULT
, CW_USEDEFAULT
,
1711 mdi_client
, 0, GetModuleHandleA(NULL
),
1712 mdi_lParam_test_message
);
1713 ok(mdi_child
!= 0, "MDI child creation failed\n");
1714 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1715 ok(id
== 0, "wrong child id %ld\n", id
);
1716 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1717 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1718 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1719 DestroyWindow(mdi_child
);
1722 static void test_MDI_child_stack(HWND mdi_client
)
1724 HWND child_1
, child_2
, child_3
, child_4
;
1726 MDICREATESTRUCTA cs
;
1728 cs
.szClass
= "MDI_child_Class_1";
1729 cs
.szTitle
= "MDI child";
1730 cs
.hOwner
= GetModuleHandleA(0);
1731 cs
.x
= CW_USEDEFAULT
;
1732 cs
.y
= CW_USEDEFAULT
;
1733 cs
.cx
= CW_USEDEFAULT
;
1734 cs
.cy
= CW_USEDEFAULT
;
1736 cs
.lParam
= (LPARAM
)mdi_lParam_test_message
;
1738 child_1
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&cs
);
1739 ok(child_1
!= 0, "expected child_1 to be non NULL\n");
1740 child_2
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&cs
);
1741 ok(child_2
!= 0, "expected child_2 to be non NULL\n");
1742 child_3
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&cs
);
1743 ok(child_3
!= 0, "expected child_3 to be non NULL\n");
1744 child_4
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&cs
);
1745 ok(child_4
!= 0, "expected child_4 to be non NULL\n");
1747 stack
[0] = (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1748 stack
[1] = GetWindow(stack
[0], GW_HWNDNEXT
);
1749 stack
[2] = GetWindow(stack
[1], GW_HWNDNEXT
);
1750 stack
[3] = GetWindow(stack
[2], GW_HWNDNEXT
);
1751 ok(stack
[0] == child_4
&& stack
[1] == child_3
&&
1752 stack
[2] == child_2
&& stack
[3] == child_1
,
1753 "Unexpected initial order, should be: %p->%p->%p->%p\n",
1754 child_4
, child_3
, child_2
, child_1
);
1756 SendMessageA(mdi_client
, WM_MDINEXT
, (WPARAM
)child_3
, 0);
1758 stack
[0] = (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1759 stack
[1] = GetWindow(stack
[0], GW_HWNDNEXT
);
1760 stack
[2] = GetWindow(stack
[1], GW_HWNDNEXT
);
1761 stack
[3] = GetWindow(stack
[2], GW_HWNDNEXT
);
1762 ok(stack
[0] == child_2
&& stack
[1] == child_4
&&
1763 stack
[2] == child_1
&& stack
[3] == child_3
,
1764 "Broken MDI child stack:\nexpected: %p->%p->%p->%p, but got: %p->%p->%p->%p\n",
1765 child_2
, child_4
, child_1
, child_3
, stack
[0], stack
[1], stack
[2], stack
[3]);
1767 SendMessageA(mdi_client
, WM_MDINEXT
, (WPARAM
)child_1
, 1);
1769 stack
[0] = (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1770 stack
[1] = GetWindow(stack
[0], GW_HWNDNEXT
);
1771 stack
[2] = GetWindow(stack
[1], GW_HWNDNEXT
);
1772 stack
[3] = GetWindow(stack
[2], GW_HWNDNEXT
);
1773 ok(stack
[0] == child_4
&& stack
[1] == child_2
&&
1774 stack
[2] == child_1
&& stack
[3] == child_3
,
1775 "Broken MDI child stack:\nexpected: %p->%p->%p->%p, but got: %p->%p->%p->%p\n",
1776 child_4
, child_2
, child_1
, child_3
, stack
[0], stack
[1], stack
[2], stack
[3]);
1778 ShowWindow(child_4
, SW_MINIMIZE
);
1780 stack
[0] = (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1781 stack
[1] = GetWindow(stack
[0], GW_HWNDNEXT
);
1782 todo_wine
ok(stack
[0] == child_4
, "Expected %p, got %p\n", child_4
, stack
[0]);
1783 todo_wine
ok(stack
[1] == NULL
, "Expected NULL, got %p\n", stack
[1]);
1785 DestroyWindow(child_1
);
1786 DestroyWindow(child_2
);
1787 DestroyWindow(child_3
);
1788 DestroyWindow(child_4
);
1791 /**********************************************************************
1792 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1794 * Note: The rule here is that client rect of the maximized MDI child
1795 * is equal to the client rect of the MDI client window.
1797 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
1801 GetClientRect( client
, &rect
);
1802 AdjustWindowRectEx( &rect
, GetWindowLongA( hwnd
, GWL_STYLE
),
1803 0, GetWindowLongA( hwnd
, GWL_EXSTYLE
));
1805 rect
.right
-= rect
.left
;
1806 rect
.bottom
-= rect
.top
;
1807 lpMinMax
->ptMaxSize
.x
= rect
.right
;
1808 lpMinMax
->ptMaxSize
.y
= rect
.bottom
;
1810 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
1811 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
1814 static LRESULT WINAPI
mdi_child_wnd_proc_1(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1821 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1822 MDICREATESTRUCTA
*mdi_cs
= cs
->lpCreateParams
;
1824 ok(cs
->dwExStyle
& WS_EX_MDICHILD
, "WS_EX_MDICHILD should be set\n");
1825 ok(mdi_cs
->lParam
== (LPARAM
)mdi_lParam_test_message
, "wrong mdi_cs->lParam\n");
1827 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_1"), "wrong class name\n");
1828 ok(!lstrcmpA(cs
->lpszClass
, mdi_cs
->szClass
), "class name does not match\n");
1829 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1830 ok(!lstrcmpA(cs
->lpszName
, mdi_cs
->szTitle
), "title does not match\n");
1831 ok(cs
->hInstance
== mdi_cs
->hOwner
, "%p != %p\n", cs
->hInstance
, mdi_cs
->hOwner
);
1833 /* MDICREATESTRUCT should have original values */
1834 ok(mdi_cs
->style
== 0 || mdi_cs
->style
== 0x7fffffff || mdi_cs
->style
== 0xffffffff || mdi_cs
->style
== WS_MAXIMIZE
,
1835 "mdi_cs->style does not match (%08x)\n", mdi_cs
->style
);
1836 ok(mdi_cs
->x
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->x
);
1837 ok(mdi_cs
->y
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->y
);
1838 ok(mdi_cs
->cx
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cx
);
1839 ok(mdi_cs
->cy
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cy
);
1841 /* CREATESTRUCT should have fixed values */
1842 ok(cs
->x
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->x
);
1843 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1845 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1846 ok(cs
->cx
!= CW_USEDEFAULT
&& cs
->cx
!= 0, "%d == CW_USEDEFAULT\n", cs
->cx
);
1847 ok(cs
->cy
!= CW_USEDEFAULT
&& cs
->cy
!= 0, "%d == CW_USEDEFAULT\n", cs
->cy
);
1849 ok(!(cs
->style
& WS_POPUP
), "WS_POPUP is not allowed\n");
1851 if (GetWindowLongA(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1853 LONG style
= mdi_cs
->style
| WS_CHILD
| WS_CLIPSIBLINGS
;
1854 ok(cs
->style
== style
,
1855 "cs->style does not match (%08x)\n", cs
->style
);
1859 LONG style
= mdi_cs
->style
;
1861 style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1862 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1863 ok(cs
->style
== style
,
1864 "cs->style does not match (%08x)\n", cs
->style
);
1869 case WM_GETMINMAXINFO
:
1871 HWND client
= GetParent(hwnd
);
1873 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1874 MINMAXINFO my_minmax
;
1875 LONG style
, exstyle
;
1877 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1878 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1880 GetClientRect(client
, &rc
);
1882 GetClientRect(client
, &rc
);
1883 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1884 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1885 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1886 if (winetest_debug
> 1)
1888 trace("MDI child: calculated max window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1889 dump_minmax_info( minmax
);
1892 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1893 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1894 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1895 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1897 DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1899 if (winetest_debug
> 1)
1901 trace("DefMDIChildProc returned:\n");
1902 dump_minmax_info( minmax
);
1905 MDI_ChildGetMinMaxInfo(client
, hwnd
, &my_minmax
);
1906 ok(minmax
->ptMaxSize
.x
== my_minmax
.ptMaxSize
.x
, "default width of maximized child %d != %d\n",
1907 minmax
->ptMaxSize
.x
, my_minmax
.ptMaxSize
.x
);
1908 ok(minmax
->ptMaxSize
.y
== my_minmax
.ptMaxSize
.y
, "default height of maximized child %d != %d\n",
1909 minmax
->ptMaxSize
.y
, my_minmax
.ptMaxSize
.y
);
1914 case WM_MDIACTIVATE
:
1916 HWND active
, client
= GetParent(hwnd
);
1917 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1918 active
= (HWND
)SendMessageA(client
, WM_MDIGETACTIVE
, 0, 0);
1919 if (hwnd
== (HWND
)lparam
) /* if we are being activated */
1920 ok (active
== (HWND
)lparam
, "new active %p != active %p\n", (HWND
)lparam
, active
);
1922 ok (active
== (HWND
)wparam
, "old active %p != active %p\n", (HWND
)wparam
, active
);
1926 return DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1929 static LRESULT WINAPI
mdi_child_wnd_proc_2(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1936 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1938 if (winetest_debug
> 1)
1939 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg
== WM_NCCREATE
) ? "WM_NCCREATE" : "WM_CREATE",
1940 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
1942 ok(!(cs
->dwExStyle
& WS_EX_MDICHILD
), "WS_EX_MDICHILD should not be set\n");
1943 ok(cs
->lpCreateParams
== mdi_lParam_test_message
, "wrong cs->lpCreateParams\n");
1945 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_2"), "wrong class name\n");
1946 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1948 /* CREATESTRUCT should have fixed values */
1949 ok(cs
->x
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->x
);
1950 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1952 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1953 ok(cs
->cx
== 0, "%d != 0\n", cs
->cx
);
1954 ok(cs
->cy
== 0, "%d != 0\n", cs
->cy
);
1958 case WM_GETMINMAXINFO
:
1960 HWND parent
= GetParent(hwnd
);
1962 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1963 LONG style
, exstyle
;
1965 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1966 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1968 GetClientRect(parent
, &rc
);
1969 if (winetest_debug
> 1)
1971 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent
, rc
.right
, rc
.bottom
);
1972 dump_minmax_info( minmax
);
1974 GetClientRect(parent
, &rc
);
1975 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1976 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1977 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1979 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1980 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1981 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1982 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1986 case WM_WINDOWPOSCHANGED
:
1988 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1991 GetWindowRect(hwnd
, &rc1
);
1992 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1993 /* note: winpos coordinates are relative to parent */
1994 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1995 ok(EqualRect(&rc1
, &rc2
), "rects do not match, window=%s pos=%s\n",
1996 wine_dbgstr_rect(&rc1
), wine_dbgstr_rect(&rc2
));
1997 GetWindowRect(hwnd
, &rc1
);
1998 GetClientRect(hwnd
, &rc2
);
1999 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
2000 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
2001 ok(EqualRect(&rc1
, &rc2
), "rects do not match, window=%s client=%s\n",
2002 wine_dbgstr_rect(&rc1
), wine_dbgstr_rect(&rc2
));
2005 case WM_WINDOWPOSCHANGING
:
2007 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
2008 WINDOWPOS my_winpos
= *winpos
;
2010 if (winetest_debug
> 1)
2011 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2012 (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
2013 winpos
->hwnd
, winpos
->hwndInsertAfter
,
2014 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
2016 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
2018 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
2019 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2020 winpos
->hwnd
, winpos
->hwndInsertAfter
,
2021 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
2026 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
2029 static LRESULT WINAPI
mdi_main_wnd_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2031 static HWND mdi_client
;
2038 case WM_WINDOWPOSCHANGED
:
2040 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
2043 GetWindowRect(hwnd
, &rc1
);
2044 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
2045 /* note: winpos coordinates are relative to parent */
2046 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
2047 ok(EqualRect(&rc1
, &rc2
), "rects %s %s do not match\n",
2048 wine_dbgstr_rect(&rc1
), wine_dbgstr_rect(&rc2
));
2050 GetWindowRect(hwnd
, &rc1
);
2051 GetClientRect(hwnd
, &rc2
);
2052 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
2053 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
2054 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
2057 case WM_WINDOWPOSCHANGING
:
2059 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
2060 WINDOWPOS my_winpos
= *winpos
;
2062 if (winetest_debug
> 1)
2063 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2064 (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
2065 winpos
->hwnd
, winpos
->hwndInsertAfter
,
2066 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
2068 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
2070 if (winetest_debug
> 1)
2071 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2072 winpos
->hwnd
, winpos
->hwndInsertAfter
,
2073 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
2075 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
2076 "DefWindowProc should not change WINDOWPOS values\n");
2085 return DefFrameProcA(hwnd
, mdi_client
, msg
, wparam
, lparam
);
2088 static BOOL
mdi_RegisterWindowClasses(void)
2093 cls
.lpfnWndProc
= mdi_main_wnd_procA
;
2096 cls
.hInstance
= GetModuleHandleA(0);
2098 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
2099 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
2100 cls
.lpszMenuName
= NULL
;
2101 cls
.lpszClassName
= "MDI_parent_Class";
2102 if(!RegisterClassA(&cls
)) return FALSE
;
2104 cls
.lpfnWndProc
= mdi_child_wnd_proc_1
;
2105 cls
.lpszClassName
= "MDI_child_Class_1";
2106 if(!RegisterClassA(&cls
)) return FALSE
;
2108 cls
.lpfnWndProc
= mdi_child_wnd_proc_2
;
2109 cls
.lpszClassName
= "MDI_child_Class_2";
2110 if(!RegisterClassA(&cls
)) return FALSE
;
2115 static void test_mdi(void)
2117 static const DWORD style
[] = { 0, WS_HSCROLL
, WS_VSCROLL
, WS_HSCROLL
| WS_VSCROLL
};
2118 HWND mdi_hwndMain
, mdi_client
, mdi_child
;
2119 CLIENTCREATESTRUCT client_cs
;
2123 HMENU frame_menu
, child_menu
;
2125 if (!mdi_RegisterWindowClasses()) assert(0);
2127 mdi_hwndMain
= CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
2128 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
2129 WS_MAXIMIZEBOX
/*| WS_VISIBLE*/,
2130 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
2131 GetDesktopWindow(), 0,
2132 GetModuleHandleA(NULL
), NULL
);
2133 assert(mdi_hwndMain
);
2135 frame_menu
= CreateMenu();
2137 GetClientRect(mdi_hwndMain
, &rc
);
2139 client_cs
.hWindowMenu
= 0;
2140 client_cs
.idFirstChild
= 1;
2142 for (i
= 0; i
< ARRAY_SIZE(style
); i
++)
2147 mdi_client
= CreateWindowExA(0, "mdiclient", NULL
,
2148 WS_CHILD
| style
[i
],
2149 0, 0, rc
.right
, rc
.bottom
,
2150 mdi_hwndMain
, 0, 0, &client_cs
);
2151 ok(mdi_client
!= 0, "MDI client creation failed\n");
2153 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
2155 CW_USEDEFAULT
, CW_USEDEFAULT
,
2156 CW_USEDEFAULT
, CW_USEDEFAULT
,
2158 mdi_lParam_test_message
);
2159 ok(mdi_child
!= 0, "MDI child creation failed\n");
2161 SendMessageW(mdi_child
, WM_SIZE
, SIZE_MAXIMIZED
, 0);
2162 SetMenu(mdi_hwndMain
, frame_menu
);
2164 ok(GetMenuItemCount(frame_menu
) == 0, "Frame menu should be empty after child maximize, but has %u\n",
2165 GetMenuItemCount(frame_menu
));
2167 child_menu
= CreateMenu();
2168 SendMessageW(mdi_client
, WM_MDISETMENU
, 0, (LPARAM
)child_menu
);
2170 ok(GetMenuItemCount(frame_menu
) == 0, "Frame menu should be empty after WM_MDISETMENU, but has %u\n",
2171 GetMenuItemCount(frame_menu
));
2173 SendMessageW(mdi_child
, WM_SIZE
, SIZE_RESTORED
, 0);
2175 ok(GetMenuItemCount(frame_menu
) == 0, "Frame menu should be empty after child restored, but has %u items\n",
2176 GetMenuItemCount(frame_menu
));
2178 SetMenu(mdi_hwndMain
, NULL
);
2180 si
.cbSize
= sizeof(si
);
2182 ret
= GetScrollInfo(mdi_client
, SB_HORZ
, &si
);
2183 if (style
[i
] & (WS_HSCROLL
| WS_VSCROLL
))
2185 ok(ret
, "style %#x: GetScrollInfo(SB_HORZ) failed\n", style
[i
]);
2186 ok(si
.nPage
== 0, "expected 0\n");
2187 ok(si
.nPos
== 0, "expected 0\n");
2188 ok(si
.nTrackPos
== 0, "expected 0\n");
2189 ok(si
.nMin
== 0, "expected 0\n");
2190 ok(si
.nMax
== 100, "expected 100\n");
2193 ok(!ret
, "style %#x: GetScrollInfo(SB_HORZ) should fail\n", style
[i
]);
2195 ret
= GetScrollInfo(mdi_client
, SB_VERT
, &si
);
2196 if (style
[i
] & (WS_HSCROLL
| WS_VSCROLL
))
2198 ok(ret
, "style %#x: GetScrollInfo(SB_VERT) failed\n", style
[i
]);
2199 ok(si
.nPage
== 0, "expected 0\n");
2200 ok(si
.nPos
== 0, "expected 0\n");
2201 ok(si
.nTrackPos
== 0, "expected 0\n");
2202 ok(si
.nMin
== 0, "expected 0\n");
2203 ok(si
.nMax
== 100, "expected 100\n");
2206 ok(!ret
, "style %#x: GetScrollInfo(SB_VERT) should fail\n", style
[i
]);
2208 SetWindowPos(mdi_child
, 0, -100, -100, 0, 0, SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOSIZE
);
2210 si
.cbSize
= sizeof(si
);
2212 ret
= GetScrollInfo(mdi_client
, SB_HORZ
, &si
);
2213 if (style
[i
] & (WS_HSCROLL
| WS_VSCROLL
))
2215 ok(ret
, "style %#x: GetScrollInfo(SB_HORZ) failed\n", style
[i
]);
2216 ok(si
.nPage
== 0, "expected 0\n");
2217 ok(si
.nPos
== 0, "expected 0\n");
2218 ok(si
.nTrackPos
== 0, "expected 0\n");
2219 ok(si
.nMin
== 0, "expected 0\n");
2220 ok(si
.nMax
== 100, "expected 100\n");
2223 ok(!ret
, "style %#x: GetScrollInfo(SB_HORZ) should fail\n", style
[i
]);
2225 ret
= GetScrollInfo(mdi_client
, SB_VERT
, &si
);
2226 if (style
[i
] & (WS_HSCROLL
| WS_VSCROLL
))
2228 ok(ret
, "style %#x: GetScrollInfo(SB_VERT) failed\n", style
[i
]);
2229 ok(si
.nPage
== 0, "expected 0\n");
2230 ok(si
.nPos
== 0, "expected 0\n");
2231 ok(si
.nTrackPos
== 0, "expected 0\n");
2232 ok(si
.nMin
== 0, "expected 0\n");
2233 ok(si
.nMax
== 100, "expected 100\n");
2236 ok(!ret
, "style %#x: GetScrollInfo(SB_VERT) should fail\n", style
[i
]);
2239 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
2241 if (msg
.message
== WM_MOUSEMOVE
|| msg
.message
== WM_PAINT
)
2243 DispatchMessageA(&msg
);
2247 if (msg
.message
== 0x003f) /* WM_MDICALCCHILDSCROLL ??? */
2249 ok(msg
.hwnd
== mdi_client
, "message 0x003f should be posted to mdiclient\n");
2253 ok(msg
.hwnd
!= mdi_client
, "message %04x should not be posted to mdiclient\n", msg
.message
);
2254 DispatchMessageA(&msg
);
2256 ok(gotit
, "message 0x003f should appear after SetWindowPos\n");
2258 si
.cbSize
= sizeof(si
);
2260 ret
= GetScrollInfo(mdi_client
, SB_HORZ
, &si
);
2261 if (style
[i
] & (WS_HSCROLL
| WS_VSCROLL
))
2263 ok(ret
, "style %#x: GetScrollInfo(SB_HORZ) failed\n", style
[i
]);
2265 ok(si
.nPage
!= 0, "expected !0\n");
2266 ok(si
.nPos
== 0, "expected 0\n");
2267 ok(si
.nTrackPos
== 0, "expected 0\n");
2268 ok(si
.nMin
!= 0, "expected !0\n");
2269 ok(si
.nMax
!= 100, "expected !100\n");
2272 ok(!ret
, "style %#x: GetScrollInfo(SB_HORZ) should fail\n", style
[i
]);
2274 ret
= GetScrollInfo(mdi_client
, SB_VERT
, &si
);
2275 if (style
[i
] & (WS_HSCROLL
| WS_VSCROLL
))
2277 ok(ret
, "style %#x: GetScrollInfo(SB_VERT) failed\n", style
[i
]);
2279 ok(si
.nPage
!= 0, "expected !0\n");
2280 ok(si
.nPos
== 0, "expected 0\n");
2281 ok(si
.nTrackPos
== 0, "expected 0\n");
2282 ok(si
.nMin
!= 0, "expected !0\n");
2283 ok(si
.nMax
!= 100, "expected !100\n");
2286 ok(!ret
, "style %#x: GetScrollInfo(SB_VERT) should fail\n", style
[i
]);
2288 DestroyMenu(child_menu
);
2289 DestroyWindow(mdi_child
);
2290 DestroyWindow(mdi_client
);
2293 SetMenu(mdi_hwndMain
, frame_menu
);
2295 mdi_client
= CreateWindowExA(0, "mdiclient", NULL
,
2297 0, 0, rc
.right
, rc
.bottom
,
2298 mdi_hwndMain
, 0, 0, &client_cs
);
2299 ok(mdi_client
!= 0, "MDI client creation failed\n");
2301 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
2303 CW_USEDEFAULT
, CW_USEDEFAULT
,
2304 CW_USEDEFAULT
, CW_USEDEFAULT
,
2306 mdi_lParam_test_message
);
2307 ok(mdi_child
!= 0, "MDI child creation failed\n");
2309 SendMessageW(mdi_child
, WM_SIZE
, SIZE_MAXIMIZED
, 0);
2310 ok(GetMenuItemCount(frame_menu
) == 4, "Frame menu should have 4 items after child maximize, but has %u\n",
2311 GetMenuItemCount(frame_menu
));
2313 child_menu
= CreateMenu();
2314 SendMessageW(mdi_client
, WM_MDISETMENU
, 0, (LPARAM
)child_menu
);
2316 ok(GetMenuItemCount(frame_menu
) == 4, "Frame menu should have 4 items after WM_MDISETMENU, but has %u\n",
2317 GetMenuItemCount(frame_menu
));
2319 SendMessageW(mdi_child
, WM_SIZE
, SIZE_RESTORED
, 0);
2321 ok(GetMenuItemCount(frame_menu
) == 0, "Frame menu should be empty after child restored, but has %u items\n",
2322 GetMenuItemCount(frame_menu
));
2324 DestroyMenu(child_menu
);
2325 DestroyWindow(mdi_child
);
2326 DestroyWindow(mdi_client
);
2328 /* MDIClient without MDIS_ALLCHILDSTYLES */
2329 mdi_client
= CreateWindowExA(0, "mdiclient",
2331 WS_CHILD
/*| WS_VISIBLE*/,
2332 /* tests depend on a not zero MDIClient size */
2333 0, 0, rc
.right
, rc
.bottom
,
2334 mdi_hwndMain
, 0, GetModuleHandleA(NULL
),
2337 test_MDI_create(mdi_hwndMain
, mdi_client
, client_cs
.idFirstChild
);
2338 DestroyWindow(mdi_client
);
2340 /* MDIClient with MDIS_ALLCHILDSTYLES */
2341 mdi_client
= CreateWindowExA(0, "mdiclient",
2343 WS_CHILD
| MDIS_ALLCHILDSTYLES
/*| WS_VISIBLE*/,
2344 /* tests depend on a not zero MDIClient size */
2345 0, 0, rc
.right
, rc
.bottom
,
2346 mdi_hwndMain
, 0, GetModuleHandleA(NULL
),
2349 test_MDI_create(mdi_hwndMain
, mdi_client
, client_cs
.idFirstChild
);
2350 DestroyWindow(mdi_client
);
2352 /* Test child window stack management */
2353 mdi_client
= CreateWindowExA(0, "mdiclient",
2356 0, 0, rc
.right
, rc
.bottom
,
2357 mdi_hwndMain
, 0, GetModuleHandleA(NULL
),
2360 test_MDI_child_stack(mdi_client
);
2361 DestroyWindow(mdi_client
);
2363 while(GetMessage(&msg, 0, 0, 0))
2365 TranslateMessage(&msg);
2366 DispatchMessage(&msg);
2369 DestroyWindow(mdi_hwndMain
);
2372 static void test_icons(void)
2376 HICON icon
= LoadIconA(0, (LPCSTR
)IDI_APPLICATION
);
2377 HICON icon2
= LoadIconA(0, (LPCSTR
)IDI_QUESTION
);
2378 HICON small_icon
= LoadImageA(0, (LPCSTR
)IDI_APPLICATION
, IMAGE_ICON
,
2379 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
2382 cls
.cbSize
= sizeof(cls
);
2384 cls
.lpfnWndProc
= DefWindowProcA
;
2388 cls
.hIcon
= LoadIconA(0, (LPCSTR
)IDI_HAND
);
2389 cls
.hIconSm
= small_icon
;
2390 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
2391 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
2392 cls
.lpszMenuName
= NULL
;
2393 cls
.lpszClassName
= "IconWindowClass";
2395 RegisterClassExA(&cls
);
2397 hwnd
= CreateWindowExA(0, "IconWindowClass", "icon test", 0,
2398 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, NULL
, NULL
);
2401 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
2402 ok( res
== 0, "wrong big icon %p/0\n", res
);
2403 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon
);
2404 ok( res
== 0, "wrong previous big icon %p/0\n", res
);
2405 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
2406 ok( res
== icon
, "wrong big icon after set %p/%p\n", res
, icon
);
2407 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon2
);
2408 ok( res
== icon
, "wrong previous big icon %p/%p\n", res
, icon
);
2409 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
2410 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
2412 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
2413 ok( res
== 0, "wrong small icon %p/0\n", res
);
2414 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL2
, 0 );
2415 ok( (res
&& res
!= small_icon
&& res
!= icon2
) || broken(!res
), "wrong small2 icon %p\n", res
);
2416 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)icon
);
2417 ok( res
== 0, "wrong previous small icon %p/0\n", res
);
2418 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
2419 ok( res
== icon
, "wrong small icon after set %p/%p\n", res
, icon
);
2420 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL2
, 0 );
2421 ok( res
== icon
|| broken(!res
), "wrong small2 icon after set %p/%p\n", res
, icon
);
2422 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)small_icon
);
2423 ok( res
== icon
, "wrong previous small icon %p/%p\n", res
, icon
);
2424 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
2425 ok( res
== small_icon
, "wrong small icon after set %p/%p\n", res
, small_icon
);
2426 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL2
, 0 );
2427 ok( res
== small_icon
|| broken(!res
), "wrong small2 icon after set %p/%p\n", res
, small_icon
);
2429 /* make sure the big icon hasn't changed */
2430 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
2431 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
2433 DestroyWindow( hwnd
);
2436 static LRESULT WINAPI
nccalcsize_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2438 if (msg
== WM_NCCALCSIZE
)
2440 RECT
*rect
= (RECT
*)lparam
;
2441 /* first time around increase the rectangle, next time decrease it */
2442 if (rect
->left
== 100) InflateRect( rect
, 10, 10 );
2443 else InflateRect( rect
, -10, -10 );
2446 return DefWindowProcA( hwnd
, msg
, wparam
, lparam
);
2449 static void test_SetWindowPos(HWND hwnd
, HWND hwnd2
)
2451 RECT orig_win_rc
, rect
;
2453 HWND hwnd_grandchild
, hwnd_child
, hwnd_child2
;
2459 SetRect(&rect
, 111, 222, 333, 444);
2460 ok(!GetWindowRect(0, &rect
), "GetWindowRect succeeded\n");
2461 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
2462 "wrong window rect %s\n", wine_dbgstr_rect(&rect
));
2464 SetRect(&rect
, 111, 222, 333, 444);
2465 ok(!GetClientRect(0, &rect
), "GetClientRect succeeded\n");
2466 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
2467 "wrong window rect %s\n", wine_dbgstr_rect(&rect
));
2469 GetWindowRect(hwnd
, &orig_win_rc
);
2471 old_proc
= SetWindowLongPtrA( hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)nccalcsize_proc
);
2472 ret
= SetWindowPos(hwnd
, 0, 100, 100, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
2473 ok(ret
, "Got %d\n", ret
);
2474 GetWindowRect( hwnd
, &rect
);
2475 ok( rect
.left
== 100 && rect
.top
== 100 && rect
.right
== 100 && rect
.bottom
== 100,
2476 "invalid window rect %s\n", wine_dbgstr_rect(&rect
));
2477 GetClientRect( hwnd
, &rect
);
2478 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
2479 ok( rect
.left
== 90 && rect
.top
== 90 && rect
.right
== 110 && rect
.bottom
== 110,
2480 "invalid client rect %s\n", wine_dbgstr_rect(&rect
));
2482 flush_events( TRUE
); /* needed by Win10 1709+ */
2484 ret
= SetWindowPos(hwnd
, 0, 200, 200, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
2485 ok(ret
, "Got %d\n", ret
);
2486 GetWindowRect( hwnd
, &rect
);
2487 ok( rect
.left
== 200 && rect
.top
== 200 && rect
.right
== 200 && rect
.bottom
== 200,
2488 "invalid window rect %s\n", wine_dbgstr_rect(&rect
));
2489 GetClientRect( hwnd
, &rect
);
2490 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
2491 ok( rect
.left
== 210 && rect
.top
== 210 && rect
.right
== 190 && rect
.bottom
== 190,
2492 "invalid client rect %s\n", wine_dbgstr_rect(&rect
));
2494 ret
= SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
2495 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
2496 ok(ret
, "Got %d\n", ret
);
2497 SetWindowLongPtrA( hwnd
, GWLP_WNDPROC
, old_proc
);
2499 ret
= SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE
);
2500 ok(ret
, "Got %d\n", ret
);
2501 ret
= SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE
);
2502 ok(ret
, "Got %d\n", ret
);
2504 ret
= SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE
);
2505 ok(ret
, "Got %d\n", ret
);
2506 ret
= SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE
);
2507 ok(ret
, "Got %d\n", ret
);
2509 ret
= SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
2510 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
2511 ok(ret
, "Got %d\n", ret
);
2513 hwnd_desktop
= GetDesktopWindow();
2514 ok(!!hwnd_desktop
, "Failed to get hwnd_desktop window (%d).\n", GetLastError());
2515 hwnd_child
= create_tool_window(WS_VISIBLE
|WS_CHILD
, hwnd
);
2516 ok(!!hwnd_child
, "Failed to create child window (%d)\n", GetLastError());
2517 hwnd_grandchild
= create_tool_window(WS_VISIBLE
|WS_CHILD
, hwnd_child
);
2518 ok(!!hwnd_child
, "Failed to create child window (%d)\n", GetLastError());
2519 hwnd_child2
= create_tool_window(WS_VISIBLE
|WS_CHILD
, hwnd
);
2520 ok(!!hwnd_child2
, "Failed to create second child window (%d)\n", GetLastError());
2522 ret
= SetWindowPos(hwnd
, hwnd2
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2523 ok(ret
, "Got %d\n", ret
);
2524 check_active_state(hwnd
, hwnd
, hwnd
);
2526 ret
= SetWindowPos(hwnd2
, hwnd
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2527 ok(ret
, "Got %d\n", ret
);
2528 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2530 /* Returns TRUE also for windows that are not siblings */
2531 ret
= SetWindowPos(hwnd_child
, hwnd2
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2532 ok(ret
, "Got %d\n", ret
);
2533 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2535 ret
= SetWindowPos(hwnd2
, hwnd_child
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2536 ok(ret
, "Got %d\n", ret
);
2537 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2539 /* Does not seem to do anything even without passing flags, still returns TRUE */
2540 GetWindowRect(hwnd_child
, &rc1
);
2541 ret
= SetWindowPos(hwnd_child
, hwnd2
, 1, 2, 3, 4, 0);
2542 ok(ret
, "Got %d.\n", ret
);
2543 GetWindowRect(hwnd_child
, &rc2
);
2544 ok(EqualRect(&rc1
, &rc2
), "%s != %s.\n", wine_dbgstr_rect(&rc1
), wine_dbgstr_rect(&rc2
));
2545 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2547 GetWindowRect(hwnd_child
, &rc1
);
2548 ret
= SetWindowPos(hwnd_child
, HWND_NOTOPMOST
, 1, 2, 3, 4, 0);
2549 ok(ret
, "Got %d.\n", ret
);
2550 GetWindowRect(hwnd_child
, &rc2
);
2551 todo_wine
ok(EqualRect(&rc1
, &rc2
), "%s != %s.\n", wine_dbgstr_rect(&rc1
), wine_dbgstr_rect(&rc2
));
2552 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2553 SetWindowPos(hwnd_child
, HWND_NOTOPMOST
, 0, 0, rc1
.right
- rc1
.left
, rc1
.bottom
- rc1
.top
, 0);
2555 GetWindowRect(hwnd_child
, &rc1
);
2556 ret
= SetWindowPos(hwnd_child
, HWND_TOPMOST
, 1, 2, 3, 4, 0);
2557 ok(ret
, "Got %d.\n", ret
);
2558 GetWindowRect(hwnd_child
, &rc2
);
2559 todo_wine
ok(EqualRect(&rc1
, &rc2
), "%s != %s.\n", wine_dbgstr_rect(&rc1
), wine_dbgstr_rect(&rc2
));
2560 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2561 SetWindowPos(hwnd_child
, HWND_TOPMOST
, 0, 0, rc1
.right
- rc1
.left
, rc1
.bottom
- rc1
.top
, 0);
2563 /* HWND_TOP / HWND_BOTTOM are different. */
2564 GetWindowRect(hwnd_child
, &rc1
);
2565 rc_expected
.left
= rc1
.left
+ 1;
2566 rc_expected
.top
= rc1
.top
+ 2;
2567 rc_expected
.right
= rc1
.left
+ 4;
2568 rc_expected
.bottom
= rc1
.top
+ 6;
2569 ret
= SetWindowPos(hwnd_child
, HWND_TOP
, 1, 2, 3, 4, 0);
2570 ok(ret
, "Got %d.\n", ret
);
2571 GetWindowRect(hwnd_child
, &rc2
);
2572 ok(EqualRect(&rc_expected
, &rc2
), "%s != %s.\n",
2573 wine_dbgstr_rect(&rc_expected
), wine_dbgstr_rect(&rc2
));
2574 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2575 SetWindowPos(hwnd_child
, HWND_TOP
, 0, 0, rc1
.right
- rc1
.left
, rc1
.bottom
- rc1
.top
, 0);
2577 GetWindowRect(hwnd_child
, &rc1
);
2578 ret
= SetWindowPos(hwnd_child
, HWND_BOTTOM
, 1, 2, 3, 4, 0);
2579 ok(ret
, "Got %d.\n", ret
);
2580 GetWindowRect(hwnd_child
, &rc2
);
2581 ok(EqualRect(&rc_expected
, &rc2
), "%s != %s.\n",
2582 wine_dbgstr_rect(&rc_expected
), wine_dbgstr_rect(&rc2
));
2583 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2584 SetWindowPos(hwnd_child
, HWND_BOTTOM
, 0, 0, rc1
.right
- rc1
.left
, rc1
.bottom
- rc1
.top
, 0);
2586 GetWindowRect(hwnd_child
, &rc1
);
2587 ret
= SetWindowPos(hwnd_child
, NULL
, 1, 2, 3, 4, 0);
2588 ok(ret
, "Got %d.\n", ret
);
2589 GetWindowRect(hwnd_child
, &rc2
);
2590 ok(EqualRect(&rc_expected
, &rc2
), "%s != %s.\n",
2591 wine_dbgstr_rect(&rc_expected
), wine_dbgstr_rect(&rc2
));
2592 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2593 SetWindowPos(hwnd_child
, NULL
, 0, 0, rc1
.right
- rc1
.left
, rc1
.bottom
- rc1
.top
, 0);
2595 /* Same thing the other way around. */
2596 GetWindowRect(hwnd2
, &rc1
);
2597 ret
= SetWindowPos(hwnd2
, hwnd_child
, 1, 2, 3, 4, 0);
2598 ok(ret
, "Got %d\n", ret
);
2599 GetWindowRect(hwnd2
, &rc2
);
2600 ok(EqualRect(&rc1
, &rc2
), "%s != %s\n", wine_dbgstr_rect(&rc1
), wine_dbgstr_rect(&rc2
));
2601 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2603 /* .. and with these windows. */
2604 GetWindowRect(hwnd_grandchild
, &rc1
);
2605 ret
= SetWindowPos(hwnd_grandchild
, hwnd_child2
, 1, 2, 3, 4, 0);
2606 ok(ret
, "Got %d\n", ret
);
2607 GetWindowRect(hwnd_grandchild
, &rc2
);
2608 ok(EqualRect(&rc1
, &rc2
), "%s != %s\n", wine_dbgstr_rect(&rc1
), wine_dbgstr_rect(&rc2
));
2609 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2611 /* Add SWP_NOZORDER and it will be properly resized. */
2612 GetWindowRect(hwnd_grandchild
, &rc1
);
2613 ret
= SetWindowPos(hwnd_grandchild
, hwnd_child2
, 1, 2, 3, 4, SWP_NOZORDER
);
2614 ok(ret
, "Got %d\n", ret
);
2615 GetWindowRect(hwnd_grandchild
, &rc2
);
2616 ok(EqualRect(&rc_expected
, &rc2
),
2617 "%s != %s.\n", wine_dbgstr_rect(&rc_expected
), wine_dbgstr_rect(&rc2
));
2618 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2620 /* Given a sibling window, the window is properly resized. */
2621 GetWindowRect(hwnd_child
, &rc1
);
2622 ret
= SetWindowPos(hwnd_child
, hwnd_child2
, 1, 2, 3, 4, 0);
2623 ok(ret
, "Got %d\n", ret
);
2624 GetWindowRect(hwnd_child
, &rc2
);
2625 ok(EqualRect(&rc_expected
, &rc2
),
2626 "%s != %s.\n", wine_dbgstr_rect(&rc_expected
), wine_dbgstr_rect(&rc2
));
2627 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2629 /* Involving the desktop window changes things. */
2630 ret
= SetWindowPos(hwnd_child
, hwnd_desktop
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2631 ok(!ret
, "Got %d\n", ret
);
2632 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2634 GetWindowRect(hwnd_child
, &rc1
);
2635 ret
= SetWindowPos(hwnd_child
, hwnd_desktop
, 0, 0, 0, 0, 0);
2636 ok(!ret
, "Got %d\n", ret
);
2637 GetWindowRect(hwnd_child
, &rc2
);
2638 ok(EqualRect(&rc1
, &rc2
), "%s != %s\n", wine_dbgstr_rect(&rc1
), wine_dbgstr_rect(&rc2
));
2639 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2641 ret
= SetWindowPos(hwnd_desktop
, hwnd_child
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2642 ok(!ret
, "Got %d\n", ret
);
2643 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2645 ret
= SetWindowPos(hwnd_desktop
, hwnd
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2646 ok(!ret
, "Got %d\n", ret
);
2647 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2649 ret
= SetWindowPos(hwnd
, 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 DestroyWindow(hwnd_grandchild
);
2654 DestroyWindow(hwnd_child
);
2655 DestroyWindow(hwnd_child2
);
2657 hwnd_child
= create_tool_window(WS_CHILD
|WS_POPUP
|WS_SYSMENU
, hwnd2
);
2658 ok(!!hwnd_child
, "Failed to create child window (%d)\n", GetLastError());
2659 ret
= SetWindowPos(hwnd_child
, NULL
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2660 ok(ret
, "Got %d\n", ret
);
2661 flush_events( TRUE
);
2662 todo_wine
check_active_state(hwnd2
, hwnd2
, hwnd2
);
2663 DestroyWindow(hwnd_child
);
2666 static void test_SetMenu(HWND parent
)
2673 hMenu
= CreateMenu();
2676 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
2679 /* fails on (at least) Wine, NT4, XP SP2 */
2680 test_nonclient_area(parent
);
2682 ret
= GetMenu(parent
);
2683 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
2684 /* test whether we can destroy a menu assigned to a window */
2685 retok
= DestroyMenu(hMenu
);
2686 ok( retok
, "DestroyMenu error %d\n", GetLastError());
2687 retok
= IsMenu(hMenu
);
2688 ok(!retok
, "menu handle should be not valid after DestroyMenu\n");
2689 ret
= GetMenu(parent
);
2690 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
2691 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
2692 test_nonclient_area(parent
);
2694 hMenu
= CreateMenu();
2698 ret
= GetMenu(parent
);
2699 ok(ret
== 0, "unexpected menu id %p\n", ret
);
2701 ok(!SetMenu(parent
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
2702 test_nonclient_area(parent
);
2703 ret
= GetMenu(parent
);
2704 ok(ret
== 0, "unexpected menu id %p\n", ret
);
2706 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
2709 /* fails on (at least) Wine, NT4, XP SP2 */
2710 test_nonclient_area(parent
);
2712 ret
= GetMenu(parent
);
2713 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
2715 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
2716 test_nonclient_area(parent
);
2717 ret
= GetMenu(parent
);
2718 ok(ret
== 0, "unexpected menu id %p\n", ret
);
2721 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, parent
, (HMENU
)10, 0, NULL
);
2724 ret
= GetMenu(child
);
2725 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2727 ok(!SetMenu(child
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
2728 test_nonclient_area(child
);
2729 ret
= GetMenu(child
);
2730 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2732 ok(!SetMenu(child
, hMenu
), "SetMenu on a child window should fail\n");
2733 test_nonclient_area(child
);
2734 ret
= GetMenu(child
);
2735 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2737 ok(!SetMenu(child
, 0), "SetMenu(0) on a child window should fail\n");
2738 test_nonclient_area(child
);
2739 ret
= GetMenu(child
);
2740 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2742 style
= GetWindowLongA(child
, GWL_STYLE
);
2743 SetWindowLongA(child
, GWL_STYLE
, style
| WS_POPUP
);
2744 ok(SetMenu(child
, hMenu
), "SetMenu on a popup child window should not fail\n");
2745 ok(SetMenu(child
, 0), "SetMenu on a popup child window should not fail\n");
2746 SetWindowLongA(child
, GWL_STYLE
, style
);
2748 SetWindowLongA(child
, GWL_STYLE
, style
| WS_OVERLAPPED
);
2749 ok(!SetMenu(child
, hMenu
), "SetMenu on an overlapped child window should fail\n");
2750 SetWindowLongA(child
, GWL_STYLE
, style
);
2752 DestroyWindow(child
);
2756 static void test_window_tree(HWND parent
, const DWORD
*style
, const int *order
, int total
)
2758 HWND child
[5], hwnd
;
2763 hwnd
= GetWindow(parent
, GW_CHILD
);
2764 ok(!hwnd
, "have to start without children to perform the test\n");
2766 for (i
= 0; i
< total
; i
++)
2768 if (style
[i
] & DS_CONTROL
)
2770 child
[i
] = CreateWindowExA(0, (LPCSTR
)MAKEINTATOM(32770), "", style
[i
] & ~WS_VISIBLE
,
2771 0,0,0,0, parent
, (HMENU
)i
, 0, NULL
);
2772 if (style
[i
] & WS_VISIBLE
)
2773 ShowWindow(child
[i
], SW_SHOW
);
2775 SetWindowPos(child
[i
], HWND_BOTTOM
, 0,0,10,10, SWP_NOACTIVATE
);
2778 child
[i
] = CreateWindowExA(0, "static", "", style
[i
], 0,0,10,10,
2779 parent
, (HMENU
)i
, 0, NULL
);
2780 ok(child
[i
] != 0, "CreateWindowEx failed to create child window\n");
2783 hwnd
= GetWindow(parent
, GW_CHILD
);
2784 ok(hwnd
!= 0, "GetWindow(GW_CHILD) failed\n");
2785 ok(hwnd
== GetWindow(child
[total
- 1], GW_HWNDFIRST
), "GW_HWNDFIRST is wrong\n");
2786 ok(child
[order
[total
- 1]] == GetWindow(child
[0], GW_HWNDLAST
), "GW_HWNDLAST is wrong\n");
2788 for (i
= 0; i
< total
; i
++)
2790 ok(child
[order
[i
]] == hwnd
, "Z order of child #%ld is wrong\n", i
);
2791 hwnd
= GetWindow(hwnd
, GW_HWNDNEXT
);
2794 for (i
= 0; i
< total
; i
++)
2795 ok(DestroyWindow(child
[i
]), "DestroyWindow failed\n");
2798 static void test_children_zorder(HWND parent
)
2800 const DWORD simple_style
[5] = { WS_CHILD
, WS_CHILD
, WS_CHILD
, WS_CHILD
,
2802 const int simple_order
[5] = { 0, 1, 2, 3, 4 };
2804 const DWORD complex_style
[5] = { WS_CHILD
, WS_CHILD
| WS_MAXIMIZE
,
2805 WS_CHILD
| WS_VISIBLE
, WS_CHILD
,
2806 WS_CHILD
| WS_MAXIMIZE
| WS_VISIBLE
};
2807 const int complex_order_1
[1] = { 0 };
2808 const int complex_order_2
[2] = { 1, 0 };
2809 const int complex_order_3
[3] = { 1, 0, 2 };
2810 const int complex_order_4
[4] = { 1, 0, 2, 3 };
2811 const int complex_order_5
[5] = { 4, 1, 0, 2, 3 };
2812 const DWORD complex_style_6
[3] = { WS_CHILD
| WS_VISIBLE
,
2813 WS_CHILD
| WS_CLIPSIBLINGS
| DS_CONTROL
| WS_VISIBLE
,
2814 WS_CHILD
| WS_VISIBLE
};
2815 const int complex_order_6
[3] = { 0, 1, 2 };
2817 /* simple WS_CHILD */
2818 test_window_tree(parent
, simple_style
, simple_order
, 5);
2820 /* complex children styles */
2821 test_window_tree(parent
, complex_style
, complex_order_1
, 1);
2822 test_window_tree(parent
, complex_style
, complex_order_2
, 2);
2823 test_window_tree(parent
, complex_style
, complex_order_3
, 3);
2824 test_window_tree(parent
, complex_style
, complex_order_4
, 4);
2825 test_window_tree(parent
, complex_style
, complex_order_5
, 5);
2827 /* another set of complex children styles */
2828 test_window_tree(parent
, complex_style_6
, complex_order_6
, 3);
2831 #define check_z_order(hwnd, next, prev, owner, topmost) \
2832 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2835 static void check_z_order_debug(HWND hwnd
, HWND next
, HWND prev
, HWND owner
,
2836 BOOL topmost
, const char *file
, int line
)
2841 test
= GetWindow(hwnd
, GW_HWNDNEXT
);
2842 /* skip foreign windows */
2843 while (test
&& test
!= next
&&
2844 (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2845 UlongToHandle(GetWindowLongPtrA(test
, GWLP_HINSTANCE
)) != GetModuleHandleA(NULL
) ||
2846 GetWindow(test
, GW_OWNER
) == next
))
2848 test
= GetWindow(test
, GW_HWNDNEXT
);
2850 ok_(file
, line
)(next
== test
, "%p: expected next %p, got %p\n", hwnd
, next
, test
);
2852 test
= GetWindow(hwnd
, GW_HWNDPREV
);
2853 /* skip foreign windows */
2854 while (test
&& test
!= prev
&&
2855 (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2856 UlongToHandle(GetWindowLongPtrA(test
, GWLP_HINSTANCE
)) != GetModuleHandleA(NULL
) ||
2857 GetWindow(test
, GW_OWNER
) == hwnd
))
2859 test
= GetWindow(test
, GW_HWNDPREV
);
2861 ok_(file
, line
)(prev
== test
, "%p: expected prev %p, got %p\n", hwnd
, prev
, test
);
2863 test
= GetWindow(hwnd
, GW_OWNER
);
2864 ok_(file
, line
)(owner
== test
, "%p: expected owner %p, got %p\n", hwnd
, owner
, test
);
2866 ex_style
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
2867 ok_(file
, line
)(!(ex_style
& WS_EX_TOPMOST
) == !topmost
, "%p: expected %stopmost\n",
2868 hwnd
, topmost
? "" : "NOT ");
2871 static void test_popup_zorder(HWND hwnd_D
, HWND hwnd_E
, DWORD style
)
2873 HWND hwnd_A
, hwnd_B
, hwnd_C
, hwnd_F
;
2875 /* Give current thread foreground state otherwise the tests may fail. */
2876 if (!SetForegroundWindow(hwnd_D
))
2878 skip("SetForegroundWindow not working\n");
2882 SetWindowPos(hwnd_E
, hwnd_D
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2884 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2885 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2887 hwnd_F
= CreateWindowExA(0, "MainWindowClass", "Owner window",
2888 WS_OVERLAPPED
| WS_CAPTION
,
2890 0, 0, GetModuleHandleA(NULL
), NULL
);
2891 check_z_order(hwnd_F
, hwnd_D
, 0, 0, FALSE
);
2893 SetWindowPos(hwnd_F
, hwnd_E
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2894 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2895 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2896 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2898 hwnd_C
= CreateWindowExA(0, "MainWindowClass", NULL
,
2901 hwnd_F
, 0, GetModuleHandleA(NULL
), NULL
);
2902 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2903 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2904 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2905 check_z_order(hwnd_C
, hwnd_D
, 0, hwnd_F
, FALSE
);
2907 hwnd_B
= CreateWindowExA(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2910 hwnd_F
, 0, GetModuleHandleA(NULL
), NULL
);
2911 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2912 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2913 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2914 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2915 check_z_order(hwnd_B
, hwnd_C
, 0, hwnd_F
, TRUE
);
2917 hwnd_A
= CreateWindowExA(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2920 0, 0, GetModuleHandleA(NULL
), NULL
);
2921 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2922 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2923 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2924 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2925 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2926 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2928 if (winetest_debug
> 1)
2929 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
);
2931 /* move hwnd_F and its popups up */
2932 SetWindowPos(hwnd_F
, HWND_TOP
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2933 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2934 check_z_order(hwnd_D
, hwnd_E
, hwnd_F
, 0, FALSE
);
2935 check_z_order(hwnd_F
, hwnd_D
, hwnd_C
, 0, FALSE
);
2936 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2937 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2938 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2940 /* move hwnd_F and its popups down */
2941 #if 0 /* enable once Wine is fixed to pass this test */
2942 SetWindowPos(hwnd_F
, HWND_BOTTOM
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2943 check_z_order(hwnd_F
, 0, hwnd_C
, 0, FALSE
);
2944 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2945 check_z_order(hwnd_B
, hwnd_C
, hwnd_E
, hwnd_F
, FALSE
);
2946 check_z_order(hwnd_E
, hwnd_B
, hwnd_D
, 0, FALSE
);
2947 check_z_order(hwnd_D
, hwnd_E
, hwnd_A
, 0, FALSE
);
2948 check_z_order(hwnd_A
, hwnd_D
, 0, 0, TRUE
);
2951 /* make hwnd_C owned by a topmost window */
2952 DestroyWindow( hwnd_C
);
2953 hwnd_C
= CreateWindowExA(0, "MainWindowClass", NULL
,
2956 hwnd_A
, 0, GetModuleHandleA(NULL
), NULL
);
2957 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2958 check_z_order(hwnd_D
, hwnd_E
, hwnd_F
, 0, FALSE
);
2959 check_z_order(hwnd_F
, hwnd_D
, hwnd_B
, 0, FALSE
);
2960 check_z_order(hwnd_B
, hwnd_F
, hwnd_A
, hwnd_F
, TRUE
);
2961 check_z_order(hwnd_A
, hwnd_B
, hwnd_C
, 0, TRUE
);
2962 check_z_order(hwnd_C
, hwnd_A
, 0, hwnd_A
, TRUE
);
2964 DestroyWindow(hwnd_A
);
2965 DestroyWindow(hwnd_B
);
2966 DestroyWindow(hwnd_C
);
2967 DestroyWindow(hwnd_F
);
2970 static void test_vis_rgn( HWND hwnd
)
2972 RECT win_rect
, rgn_rect
;
2973 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2976 ShowWindow(hwnd
,SW_SHOW
);
2977 hdc
= GetDC( hwnd
);
2978 ok( GetRandomRgn( hdc
, hrgn
, SYSRGN
) != 0, "GetRandomRgn failed\n" );
2979 GetWindowRect( hwnd
, &win_rect
);
2980 GetRgnBox( hrgn
, &rgn_rect
);
2981 ok( win_rect
.left
<= rgn_rect
.left
&&
2982 win_rect
.top
<= rgn_rect
.top
&&
2983 win_rect
.right
>= rgn_rect
.right
&&
2984 win_rect
.bottom
>= rgn_rect
.bottom
,
2985 "rgn %s not inside win %s\n", wine_dbgstr_rect(&rgn_rect
), wine_dbgstr_rect(&win_rect
));
2986 ReleaseDC( hwnd
, hdc
);
2989 static LRESULT WINAPI
set_focus_on_activate_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
2991 if (msg
== WM_ACTIVATE
&& LOWORD(wp
) == WA_ACTIVE
)
2993 HWND child
= GetWindow(hwnd
, GW_CHILD
);
2994 ok(child
!= 0, "couldn't find child window\n");
2996 ok(GetFocus() == child
, "Focus should be on child %p\n", child
);
2999 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
3002 static void test_SetFocus(HWND hwnd
)
3004 HWND child
, child2
, ret
;
3005 WNDPROC old_wnd_proc
;
3007 /* check if we can set focus to non-visible windows */
3009 ShowWindow(hwnd
, SW_SHOW
);
3012 ok( GetFocus() == hwnd
, "Failed to set focus to visible window %p\n", hwnd
);
3013 ok( GetWindowLongA(hwnd
,GWL_STYLE
) & WS_VISIBLE
, "Window %p not visible\n", hwnd
);
3014 ShowWindow(hwnd
, SW_HIDE
);
3017 ok( GetFocus() == hwnd
, "Failed to set focus to invisible window %p\n", hwnd
);
3018 ok( !(GetWindowLongA(hwnd
,GWL_STYLE
) & WS_VISIBLE
), "Window %p still visible\n", hwnd
);
3019 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
3022 ok( GetFocus() == child
, "Failed to set focus to invisible child %p\n", child
);
3023 ok( !(GetWindowLongA(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
3024 ShowWindow(child
, SW_SHOW
);
3025 ok( GetWindowLongA(child
,GWL_STYLE
) & WS_VISIBLE
, "Child %p is not visible\n", child
);
3026 ok( GetFocus() == child
, "Focus no longer on child %p\n", child
);
3027 ShowWindow(child
, SW_HIDE
);
3028 ok( !(GetWindowLongA(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
3029 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
3030 ShowWindow(child
, SW_SHOW
);
3031 child2
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, child
, 0, 0, NULL
);
3033 ShowWindow(child2
, SW_SHOW
);
3035 ShowWindow(child
, SW_HIDE
);
3036 ok( !(GetWindowLongA(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
3037 ok( GetFocus() == child2
, "Focus should be on %p, not %p\n", child2
, GetFocus() );
3038 ShowWindow(child
, SW_SHOW
);
3040 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
3041 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_HIDEWINDOW
);
3042 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
3044 ShowWindow(child
, SW_HIDE
);
3046 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
3047 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_SHOWWINDOW
);
3048 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
3049 ShowWindow(child
, SW_HIDE
);
3050 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
3052 ShowWindow(hwnd
, SW_SHOW
);
3053 ShowWindow(child
, SW_SHOW
);
3055 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
3056 SetLastError(0xdeadbeef);
3057 EnableWindow(hwnd
, FALSE
);
3058 ok(GetLastError() == 0xdeadbeef, "got error %u in EnableWindow call\n", GetLastError());
3059 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
3060 EnableWindow(hwnd
, TRUE
);
3062 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
3063 ShowWindow(hwnd
, SW_SHOWMINIMIZED
);
3064 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
3066 ok( GetFocus() != child
, "Focus should not be on child %p\n", child
);
3067 ok( GetFocus() != hwnd
, "Focus should not be on parent %p\n", hwnd
);
3068 ShowWindow(hwnd
, SW_RESTORE
);
3069 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
3070 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
3071 ShowWindow(hwnd
, SW_SHOWMINIMIZED
);
3072 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
3073 ok( GetFocus() != child
, "Focus should not be on child %p\n", child
);
3074 ok( GetFocus() != hwnd
, "Focus should not be on parent %p\n", hwnd
);
3075 old_wnd_proc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)set_focus_on_activate_proc
);
3076 ShowWindow(hwnd
, SW_RESTORE
);
3077 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
3078 ok( GetFocus() == child
, "Focus should be on child %p, not %p\n", child
, GetFocus() );
3079 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)old_wnd_proc
);
3082 SetParent( child
, GetDesktopWindow());
3083 SetParent( child2
, child
);
3084 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
3085 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
3086 ret
= SetFocus( child2
);
3087 ok( ret
== 0, "SetFocus %p should fail\n", child2
);
3088 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
3089 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
3090 ret
= SetFocus( child
);
3091 ok( ret
== 0, "SetFocus %p should fail\n", child
);
3092 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
3093 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
3094 SetWindowLongW( child
, GWL_STYLE
, WS_POPUP
|WS_CHILD
);
3096 ok( GetActiveWindow() == child
, "child window %p should be active\n", child
);
3097 ok( GetFocus() == child2
, "Focus should be on child2 %p\n", child2
);
3099 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
3100 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
3102 ok( GetActiveWindow() == child
, "child window %p should be active\n", child
);
3103 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
3105 DestroyWindow( child2
);
3106 DestroyWindow( child
);
3109 static void test_SetActiveWindow(HWND hwnd
)
3113 flush_events( TRUE
);
3114 ShowWindow(hwnd
, SW_HIDE
);
3117 check_wnd_state(0, 0, 0, 0);
3119 ShowWindow(hwnd
, SW_SHOW
);
3120 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3122 SetLastError(0xdeadbeef);
3123 ret
= SetActiveWindow(0);
3124 ok(ret
== hwnd
|| broken(!ret
) /* Win10 1809 */, "expected %p, got %p\n", hwnd
, ret
);
3125 if (!ret
) ok(GetLastError() == 0xdeadbeef, "wrong error %u\n", GetLastError());
3126 if (!GetActiveWindow()) /* doesn't always work on vista */
3128 check_wnd_state(0, 0, 0, 0);
3129 ret
= SetActiveWindow(hwnd
);
3130 ok(ret
== 0, "SetActiveWindow returned %p instead of 0\n", ret
);
3132 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3134 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
3135 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3137 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
3138 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3140 ShowWindow(hwnd
, SW_HIDE
);
3141 check_wnd_state(0, 0, 0, 0);
3143 /* Invisible window. */
3144 SetActiveWindow(hwnd
);
3145 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3147 ShowWindow(hwnd
, SW_SHOW
);
3148 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3150 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
3151 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
3153 SetActiveWindow(hwnd
);
3154 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3156 DestroyWindow(hwnd2
);
3157 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3159 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
3160 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
3162 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
3163 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
3165 DestroyWindow(hwnd2
);
3166 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3168 /* try to activate the desktop */
3169 SetLastError(0xdeadbeef);
3170 ret
= SetActiveWindow(GetDesktopWindow());
3171 ok(ret
== NULL
, "expected NULL, got %p\n", ret
);
3173 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %u\n", GetLastError());
3174 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3176 /* activating a child should activate the parent */
3177 hwnd2
= CreateWindowExA(0, "MainWindowClass", "Child window", WS_CHILD
, 0, 0, 0, 0, hwnd
, 0, GetModuleHandleA(NULL
), NULL
);
3178 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3179 ret
= SetActiveWindow(hwnd2
);
3180 ok(ret
== hwnd
, "expected %p, got %p\n", hwnd
, ret
);
3181 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3182 SetLastError(0xdeadbeef);
3183 ret
= SetActiveWindow(0);
3184 ok(ret
== hwnd
|| broken(!ret
) /* Win10 1809 */, "expected %p, got %p\n", hwnd
, ret
);
3185 if (!ret
) ok(GetLastError() == 0xdeadbeef, "wrong error %u\n", GetLastError());
3186 if (!GetActiveWindow())
3188 ret
= SetActiveWindow(hwnd2
);
3189 ok(ret
== NULL
, "expected NULL, got %p\n", ret
);
3191 check_active_state(hwnd
, hwnd
, hwnd
);
3193 DestroyWindow(hwnd2
);
3196 struct create_window_thread_params
3199 HANDLE window_created
;
3200 HANDLE test_finished
;
3203 static DWORD WINAPI
create_window_thread(void *param
)
3205 struct create_window_thread_params
*p
= param
;
3209 p
->window
= CreateWindowA("static", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 0, 0, 0, 0, 0, 0);
3211 ret
= SetEvent(p
->window_created
);
3212 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
3214 res
= WaitForSingleObject(p
->test_finished
, INFINITE
);
3215 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
3217 DestroyWindow(p
->window
);
3221 static void test_SetForegroundWindow(HWND hwnd
)
3223 struct create_window_thread_params thread_params
;
3231 flush_events( TRUE
);
3232 ShowWindow(hwnd
, SW_HIDE
);
3235 check_wnd_state(0, 0, 0, 0);
3237 ShowWindow(hwnd
, SW_SHOW
);
3238 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3240 SetLastError(0xdeadbeef);
3241 hwnd2
= SetActiveWindow(0);
3242 ok(hwnd2
== hwnd
|| broken(!hwnd2
) /* Win10 1809 */, "expected %p, got %p\n", hwnd
, hwnd2
);
3243 if (!hwnd2
) ok(GetLastError() == 0xdeadbeef, "wrong error %u\n", GetLastError());
3244 if (GetActiveWindow() == hwnd
) /* doesn't always work on vista */
3245 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3247 check_wnd_state(0, 0, 0, 0);
3249 ret
= SetForegroundWindow(hwnd
);
3252 skip( "SetForegroundWindow not working\n" );
3255 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3257 SetLastError(0xdeadbeef);
3258 ret
= SetForegroundWindow(0);
3259 ok(!ret
, "SetForegroundWindow returned TRUE instead of FALSE\n");
3260 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
,
3261 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
3262 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3264 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
3265 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3267 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
3268 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3270 hwnd2
= GetForegroundWindow();
3271 ok(hwnd2
== hwnd
, "Wrong foreground window %p\n", hwnd2
);
3272 ret
= SetForegroundWindow( GetDesktopWindow() );
3273 ok(ret
, "SetForegroundWindow(desktop) error: %d\n", GetLastError());
3274 hwnd2
= GetForegroundWindow();
3275 ok(hwnd2
!= hwnd
, "Wrong foreground window %p\n", hwnd2
);
3277 ShowWindow(hwnd
, SW_HIDE
);
3278 check_wnd_state(0, 0, 0, 0);
3280 /* Invisible window. */
3281 ret
= SetForegroundWindow(hwnd
);
3282 ok(ret
, "SetForegroundWindow returned FALSE instead of TRUE\n");
3283 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3285 ShowWindow(hwnd
, SW_SHOW
);
3286 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3288 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
3289 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
3291 DestroyWindow(hwnd2
);
3292 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3294 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
3295 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
3297 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
3298 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
3300 DestroyWindow(hwnd2
);
3301 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3303 hwnd2
= CreateWindowA("static", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 0, 0, 0, 0, 0, 0);
3304 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
3306 thread_params
.window_created
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3307 ok(!!thread_params
.window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
3308 thread_params
.test_finished
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3309 ok(!!thread_params
.test_finished
, "CreateEvent failed, last error %#x.\n", GetLastError());
3310 thread
= CreateThread(NULL
, 0, create_window_thread
, &thread_params
, 0, &tid
);
3311 ok(!!thread
, "Failed to create thread, last error %#x.\n", GetLastError());
3312 res
= WaitForSingleObject(thread_params
.window_created
, INFINITE
);
3313 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
3314 check_wnd_state(hwnd2
, thread_params
.window
, hwnd2
, 0);
3316 SetForegroundWindow(hwnd2
);
3317 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
3319 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
3320 if (0) check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
3322 /* FIXME: these tests are failing because of a race condition
3323 * between internal focus state applied immediately and X11 focus
3324 * message coming late */
3325 todo_wine
ok(GetActiveWindow() == hwnd2
, "Expected active window %p, got %p.\n", hwnd2
, GetActiveWindow());
3326 todo_wine
ok(GetFocus() == hwnd2
, "Expected focus window %p, got %p.\n", hwnd2
, GetFocus());
3328 SetForegroundWindow(hwnd
);
3329 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3330 style
= GetWindowLongA(hwnd2
, GWL_STYLE
) | WS_CHILD
;
3331 ok(SetWindowLongA(hwnd2
, GWL_STYLE
, style
), "SetWindowLong failed\n");
3332 ok(SetForegroundWindow(hwnd2
), "SetForegroundWindow failed\n");
3333 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
3335 SetForegroundWindow(hwnd
);
3336 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3337 ok(SetWindowLongA(hwnd2
, GWL_STYLE
, style
& (~WS_POPUP
)), "SetWindowLong failed\n");
3338 ok(!SetForegroundWindow(hwnd2
), "SetForegroundWindow failed\n");
3339 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3341 SetEvent(thread_params
.test_finished
);
3342 WaitForSingleObject(thread
, INFINITE
);
3343 CloseHandle(thread_params
.test_finished
);
3344 CloseHandle(thread_params
.window_created
);
3345 CloseHandle(thread
);
3346 DestroyWindow(hwnd2
);
3349 static WNDPROC old_button_proc
;
3351 static LRESULT WINAPI
button_hook_proc(HWND button
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3356 key_state
= GetKeyState(VK_LBUTTON
);
3357 ok(!(key_state
& 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state
);
3359 ret
= CallWindowProcA(old_button_proc
, button
, msg
, wparam
, lparam
);
3361 if (msg
== WM_LBUTTONDOWN
)
3365 check_wnd_state(button
, button
, button
, button
);
3367 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
3370 check_wnd_state(button
, button
, button
, button
);
3372 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
3374 check_wnd_state(button
, button
, button
, button
);
3376 DestroyWindow(hwnd
);
3378 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
3381 check_wnd_state(button
, button
, button
, button
);
3383 /* button wnd proc should release capture on WM_KILLFOCUS if it does
3384 * match internal button state.
3386 SendMessageA(button
, WM_KILLFOCUS
, 0, 0);
3387 check_wnd_state(button
, button
, button
, 0);
3389 ShowWindow(hwnd
, SW_SHOW
);
3390 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3392 capture
= SetCapture(hwnd
);
3393 ok(capture
== 0, "SetCapture() = %p\n", capture
);
3395 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
3397 DestroyWindow(hwnd
);
3399 check_wnd_state(button
, 0, button
, 0);
3405 static void test_capture_1(void)
3407 HWND button
, capture
;
3409 capture
= GetCapture();
3410 ok(capture
== 0, "GetCapture() = %p\n", capture
);
3412 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
3415 old_button_proc
= (WNDPROC
)SetWindowLongPtrA(button
, GWLP_WNDPROC
, (LONG_PTR
)button_hook_proc
);
3417 SendMessageA(button
, WM_LBUTTONDOWN
, 0, 0);
3419 capture
= SetCapture(button
);
3420 ok(capture
== 0, "SetCapture() = %p\n", capture
);
3421 check_wnd_state(button
, 0, button
, button
);
3423 DestroyWindow(button
);
3424 /* old active window test depends on previously executed window
3425 * activation tests, and fails under NT4.
3426 check_wnd_state(oldActive, 0, oldFocus, 0);*/
3429 static void test_capture_2(void)
3431 HWND button
, hwnd
, capture
, oldFocus
, oldActive
;
3433 oldFocus
= GetFocus();
3434 oldActive
= GetActiveWindow();
3435 check_wnd_state(oldActive
, 0, oldFocus
, 0);
3437 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
3440 check_wnd_state(button
, button
, button
, 0);
3442 capture
= SetCapture(button
);
3443 ok(capture
== 0, "SetCapture() = %p\n", capture
);
3445 check_wnd_state(button
, button
, button
, button
);
3447 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
3448 * internal button state.
3450 SendMessageA(button
, WM_KILLFOCUS
, 0, 0);
3451 check_wnd_state(button
, button
, button
, button
);
3453 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
3456 check_wnd_state(button
, button
, button
, button
);
3458 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
3460 check_wnd_state(button
, button
, button
, button
);
3462 DestroyWindow(hwnd
);
3464 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
3467 check_wnd_state(button
, button
, button
, button
);
3469 ShowWindow(hwnd
, SW_SHOW
);
3471 check_wnd_state(hwnd
, hwnd
, hwnd
, button
);
3473 capture
= SetCapture(hwnd
);
3474 ok(capture
== button
, "SetCapture() = %p\n", capture
);
3476 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
3478 DestroyWindow(hwnd
);
3479 check_wnd_state(button
, button
, button
, 0);
3481 DestroyWindow(button
);
3482 check_wnd_state(oldActive
, 0, oldFocus
, 0);
3485 static void test_capture_3(HWND hwnd1
, HWND hwnd2
)
3489 ShowWindow(hwnd1
, SW_HIDE
);
3490 ShowWindow(hwnd2
, SW_HIDE
);
3492 ok(!IsWindowVisible(hwnd1
), "%p should be invisible\n", hwnd1
);
3493 ok(!IsWindowVisible(hwnd2
), "%p should be invisible\n", hwnd2
);
3496 check_wnd_state(0, 0, 0, hwnd1
);
3499 check_wnd_state(0, 0, 0, hwnd2
);
3501 ShowWindow(hwnd1
, SW_SHOW
);
3502 check_wnd_state(hwnd1
, hwnd1
, hwnd1
, hwnd2
);
3504 ret
= ReleaseCapture();
3505 ok (ret
, "releasecapture did not return TRUE.\n");
3506 ret
= ReleaseCapture();
3507 ok (ret
, "releasecapture did not return TRUE after second try.\n");
3510 static LRESULT CALLBACK
test_capture_4_proc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
3513 HWND cap_wnd
, cap_wnd2
, set_cap_wnd
;
3517 case WM_CAPTURECHANGED
:
3519 /* now try to release capture from menu. this should fail */
3520 if (pGetGUIThreadInfo
)
3522 memset(>i
, 0, sizeof(GUITHREADINFO
));
3523 gti
.cbSize
= sizeof(GUITHREADINFO
);
3524 status
= pGetGUIThreadInfo(GetCurrentThreadId(), >i
);
3525 ok(status
, "GetGUIThreadInfo() failed!\n");
3526 ok(gti
.flags
& GUI_INMENUMODE
, "Thread info incorrect (flags=%08X)!\n", gti
.flags
);
3528 cap_wnd
= GetCapture();
3530 ok(cap_wnd
== (HWND
)lParam
, "capture window %p does not match lparam %lx\n", cap_wnd
, lParam
);
3531 todo_wine
ok(cap_wnd
== hWnd
, "capture window %p does not match hwnd %p\n", cap_wnd
, hWnd
);
3533 /* check that re-setting the capture for the menu fails */
3534 set_cap_wnd
= SetCapture(cap_wnd
);
3535 ok(!set_cap_wnd
, "SetCapture should have failed!\n");
3538 DestroyWindow(hWnd
);
3542 /* check that SetCapture fails for another window and that it does not touch the error code */
3543 set_cap_wnd
= SetCapture(hWnd
);
3544 ok(!set_cap_wnd
, "SetCapture should have failed!\n");
3546 /* check that ReleaseCapture fails and does not touch the error code */
3547 status
= ReleaseCapture();
3548 ok(!status
, "ReleaseCapture should have failed!\n");
3550 /* check that thread info did not change */
3551 if (pGetGUIThreadInfo
)
3553 memset(>i
, 0, sizeof(GUITHREADINFO
));
3554 gti
.cbSize
= sizeof(GUITHREADINFO
);
3555 status
= pGetGUIThreadInfo(GetCurrentThreadId(), >i
);
3556 ok(status
, "GetGUIThreadInfo() failed!\n");
3557 ok(gti
.flags
& GUI_INMENUMODE
, "Thread info incorrect (flags=%08X)!\n", gti
.flags
);
3560 /* verify that no capture change took place */
3561 cap_wnd2
= GetCapture();
3562 ok(cap_wnd2
== cap_wnd
, "Capture changed!\n");
3564 /* we are done. kill the window */
3565 DestroyWindow(hWnd
);
3569 return( DefWindowProcA( hWnd
, msg
, wParam
, lParam
) );
3574 /* Test that no-one can mess around with the current capture while a menu is open */
3575 static void test_capture_4(void)
3581 HINSTANCE hInstance
= GetModuleHandleA( NULL
);
3584 if (!pGetGUIThreadInfo
)
3586 win_skip("GetGUIThreadInfo is not available\n");
3589 wclass
.lpszClassName
= "TestCapture4Class";
3590 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
3591 wclass
.lpfnWndProc
= test_capture_4_proc
;
3592 wclass
.hInstance
= hInstance
;
3593 wclass
.hIcon
= LoadIconA( 0, (LPCSTR
)IDI_APPLICATION
);
3594 wclass
.hCursor
= LoadCursorA( 0, (LPCSTR
)IDC_ARROW
);
3595 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
3596 wclass
.lpszMenuName
= 0;
3597 wclass
.cbClsExtra
= 0;
3598 wclass
.cbWndExtra
= 0;
3599 aclass
= RegisterClassA( &wclass
);
3600 ok( aclass
, "RegisterClassA failed with error %d\n", GetLastError());
3601 hwnd
= CreateWindowA( wclass
.lpszClassName
, "MenuTest",
3602 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0,
3603 400, 200, NULL
, NULL
, hInstance
, NULL
);
3604 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
3606 hmenu
= CreatePopupMenu();
3608 ret
= AppendMenuA( hmenu
, MF_STRING
, 1, "winetest2");
3609 ok( ret
, "AppendMenuA has failed!\n");
3611 /* set main window to have initial capture */
3614 /* create popup (it will self-destruct) */
3615 ret
= TrackPopupMenu(hmenu
, TPM_RETURNCMD
, 100, 100, 0, hwnd
, NULL
);
3616 ok( ret
== 0, "TrackPopupMenu returned %d expected zero\n", ret
);
3620 DestroyWindow(hwnd
);
3623 /* PeekMessage wrapper that ignores the messages we don't care about */
3624 static BOOL
peek_message( MSG
*msg
)
3629 ret
= PeekMessageA(msg
, 0, 0, 0, PM_REMOVE
);
3630 } while (ret
&& ignore_message(msg
->message
));
3634 static void test_keyboard_input(HWND hwnd
)
3639 flush_events( TRUE
);
3640 SetWindowPos(hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_SHOWWINDOW
);
3642 flush_events( TRUE
);
3644 ok(GetActiveWindow() == hwnd
, "wrong active window %p\n", GetActiveWindow());
3647 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
3649 flush_events( TRUE
);
3651 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
3652 ret
= peek_message(&msg
);
3653 ok( ret
, "no message available\n");
3654 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3655 ret
= peek_message(&msg
);
3656 ok( !ret
, "message %04x available\n", msg
.message
);
3658 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
3660 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
3661 ret
= peek_message(&msg
);
3662 ok(ret
, "no message available\n");
3663 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3664 ret
= peek_message(&msg
);
3665 ok( !ret
, "message %04x available\n", msg
.message
);
3667 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
3669 keybd_event(VK_SPACE
, 0, 0, 0);
3670 if (!peek_message(&msg
))
3672 skip( "keybd_event didn't work, skipping keyboard test\n" );
3675 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3676 ret
= peek_message(&msg
);
3677 ok( !ret
, "message %04x available\n", msg
.message
);
3680 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3682 flush_events( TRUE
);
3684 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
3685 ret
= peek_message(&msg
);
3686 ok(ret
, "no message available\n");
3687 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3688 ret
= peek_message(&msg
);
3689 ok( !ret
, "message %04x available\n", msg
.message
);
3691 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3693 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
3694 ret
= peek_message(&msg
);
3695 ok(ret
, "no message available\n");
3696 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3697 ret
= peek_message(&msg
);
3698 ok( !ret
, "message %04x available\n", msg
.message
);
3700 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3702 keybd_event(VK_SPACE
, 0, 0, 0);
3703 ret
= peek_message(&msg
);
3704 ok(ret
, "no message available\n");
3705 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_SYSKEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3706 ret
= peek_message(&msg
);
3707 ok( !ret
, "message %04x available\n", msg
.message
);
3710 static BOOL
wait_for_message( MSG
*msg
)
3716 ret
= peek_message(msg
);
3719 if (msg
->message
== WM_PAINT
) DispatchMessageA(msg
);
3722 else if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, 100, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
3724 if (!ret
) msg
->message
= 0;
3728 static void test_mouse_input(HWND hwnd
)
3733 HWND popup
, child
= NULL
;
3737 ShowWindow(hwnd
, SW_SHOWNORMAL
);
3739 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3741 GetWindowRect(hwnd
, &rc
);
3743 popup
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_POPUP
,
3744 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
,
3747 ShowWindow(popup
, SW_SHOW
);
3748 UpdateWindow(popup
);
3749 SetWindowPos( popup
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3751 GetWindowRect(popup
, &rc
);
3753 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
3754 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
3758 if (x
!= pt
.x
|| y
!= pt
.y
)
3760 skip( "failed to set mouse position, skipping mouse input tests\n" );
3764 flush_events( TRUE
);
3766 /* Check that setting the same position may generate WM_MOUSEMOVE */
3769 ret
= peek_message(&msg
);
3772 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n",
3773 msg
.hwnd
, msg
.message
);
3774 ok(msg
.pt
.x
== x
&& msg
.pt
.y
== y
, "wrong message coords (%d,%d)/(%d,%d)\n",
3775 x
, y
, msg
.pt
.x
, msg
.pt
.y
);
3778 /* force the system to update its internal queue mouse position,
3779 * otherwise it won't generate relative mouse movements below.
3781 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
3782 flush_events( TRUE
);
3785 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
3786 flush_events( FALSE
);
3787 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
3788 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
3790 if (ignore_message(msg
.message
)) continue;
3791 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
,
3792 "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3793 DispatchMessageA(&msg
);
3795 ret
= peek_message(&msg
);
3796 ok( !ret
, "message %04x available\n", msg
.message
);
3798 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
3799 ShowWindow(popup
, SW_HIDE
);
3800 ret
= wait_for_message( &msg
);
3802 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3803 flush_events( TRUE
);
3805 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
3806 ShowWindow(hwnd
, SW_HIDE
);
3807 ret
= wait_for_message( &msg
);
3808 ok( !ret
, "message %04x available\n", msg
.message
);
3809 flush_events( TRUE
);
3811 /* test mouse clicks */
3813 ShowWindow(hwnd
, SW_SHOW
);
3814 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3815 flush_events( TRUE
);
3816 ShowWindow(popup
, SW_SHOW
);
3817 SetWindowPos( popup
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3818 flush_events( TRUE
);
3820 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3821 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3822 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3823 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3825 ret
= wait_for_message( &msg
);
3828 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
3831 if (msg
.message
== WM_MOUSEMOVE
) /* win2k has an extra WM_MOUSEMOVE here */
3833 ret
= wait_for_message( &msg
);
3834 ok(ret
, "no message available\n");
3837 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
3838 msg
.hwnd
, popup
, msg
.message
);
3840 ret
= wait_for_message( &msg
);
3841 ok(ret
, "no message available\n");
3842 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
3843 msg
.hwnd
, popup
, msg
.message
);
3845 ret
= wait_for_message( &msg
);
3846 ok(ret
, "no message available\n");
3847 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p/%p message %04x\n",
3848 msg
.hwnd
, popup
, msg
.message
);
3850 ret
= wait_for_message( &msg
);
3851 ok(ret
, "no message available\n");
3852 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
3853 msg
.hwnd
, popup
, msg
.message
);
3855 ret
= peek_message(&msg
);
3856 ok(!ret
, "message %04x available\n", msg
.message
);
3858 ShowWindow(popup
, SW_HIDE
);
3859 flush_events( TRUE
);
3861 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3862 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3863 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3864 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3866 ret
= wait_for_message( &msg
);
3867 ok(ret
, "no message available\n");
3868 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
3869 msg
.hwnd
, hwnd
, msg
.message
);
3870 ret
= wait_for_message( &msg
);
3871 ok(ret
, "no message available\n");
3872 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
3873 msg
.hwnd
, hwnd
, msg
.message
);
3875 test_lbuttondown_flag
= TRUE
;
3876 SendMessageA(hwnd
, WM_COMMAND
, (WPARAM
)popup
, 0);
3877 test_lbuttondown_flag
= FALSE
;
3879 ret
= wait_for_message( &msg
);
3880 ok(ret
, "no message available\n");
3881 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
3882 msg
.hwnd
, popup
, msg
.message
);
3883 ok(peek_message(&msg
), "no message available\n");
3884 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
3885 msg
.hwnd
, popup
, msg
.message
);
3886 ok(peek_message(&msg
), "no message available\n");
3888 ShowWindow(popup
, SW_HIDE
);
3890 /* Test sending double click to the non-client area, while capturing the window after
3891 the first click has been processed. Use a child window to ensure that Wine's graphics
3892 driver isn't managing the non-client area. */
3894 GetWindowRect(hwnd
, &rc
);
3895 child
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_VISIBLE
,
3896 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
,
3898 GetWindowRect(child
, &rc
);
3900 UpdateWindow(child
);
3901 SetCursorPos( rc
.left
+ 5, rc
.top
+ 5 );
3902 flush_events( TRUE
);
3904 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3905 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3906 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3907 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3909 ret
= wait_for_message( &msg
);
3910 ok(ret
, "no message available\n");
3911 if (msg
.message
== WM_NCMOUSEMOVE
) /* not sent by Win10 1709+ */
3913 ok(msg
.hwnd
== child
, "expected %p, got %p\n", child
, msg
.hwnd
);
3914 ret
= wait_for_message( &msg
);
3915 ok(ret
, "no message available\n");
3917 ok(msg
.hwnd
== child
&& msg
.message
== WM_NCLBUTTONDOWN
, "hwnd %p/%p message %04x\n",
3918 msg
.hwnd
, child
, msg
.message
);
3919 ok(msg
.wParam
== HTSYSMENU
, "wparam %ld\n", msg
.wParam
);
3921 ret
= wait_for_message( &msg
);
3922 ok(ret
, "no message available\n");
3923 ok(msg
.hwnd
== child
&& msg
.message
== WM_NCLBUTTONUP
, "hwnd %p/%p message %04x\n",
3924 msg
.hwnd
, child
, msg
.message
);
3926 SetCapture( child
);
3928 ret
= wait_for_message( &msg
);
3929 ok(ret
, "no message available\n");
3930 ok(msg
.hwnd
== child
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p/%p message %04x\n",
3931 msg
.hwnd
, child
, msg
.message
);
3932 ok(msg
.wParam
== MK_LBUTTON
, "wparam %ld\n", msg
.wParam
);
3934 ret
= wait_for_message( &msg
);
3935 ok(ret
, "no message available\n");
3937 ok(msg
.hwnd
== child
&& (msg
.message
== WM_NCMOUSELEAVE
|| broken(msg
.message
== WM_LBUTTONUP
)),
3938 "hwnd %p/%p message %04x\n", msg
.hwnd
, child
, msg
.message
);
3940 if (msg
.message
== WM_NCMOUSELEAVE
)
3941 ret
= wait_for_message( &msg
);
3942 ok(ret
, "no message available\n");
3943 ok(msg
.hwnd
== child
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
3944 msg
.hwnd
, child
, msg
.message
);
3946 ret
= peek_message(&msg
);
3947 ok(!ret
, "message %04x available\n", msg
.message
);
3950 flush_events( TRUE
);
3952 if (child
) DestroyWindow(child
);
3953 DestroyWindow(popup
);
3955 SetWindowPos(hwnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3958 static void test_validatergn(HWND hwnd
)
3964 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_VISIBLE
, 10, 10, 10, 10, hwnd
, 0, 0, NULL
);
3965 ShowWindow(hwnd
, SW_SHOW
);
3966 UpdateWindow( hwnd
);
3967 /* test that ValidateRect validates children*/
3968 InvalidateRect( child
, NULL
, 1);
3969 GetWindowRect( child
, &rc
);
3970 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
3971 ret
= GetUpdateRect( child
, &rc2
, 0);
3972 ok( ret
== 1, "Expected GetUpdateRect to return non-zero, got %d\n", ret
);
3973 ok( rc2
.right
> rc2
.left
&& rc2
.bottom
> rc2
.top
,
3974 "Update rectangle is empty!\n");
3975 ValidateRect( hwnd
, &rc
);
3976 ret
= GetUpdateRect( child
, &rc2
, 0);
3977 ok( !ret
, "Expected GetUpdateRect to return zero, got %d\n", ret
);
3978 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
3979 "Update rectangle %s is not empty!\n", wine_dbgstr_rect(&rc2
));
3981 /* now test ValidateRgn */
3982 InvalidateRect( child
, NULL
, 1);
3983 GetWindowRect( child
, &rc
);
3984 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
3985 rgn
= CreateRectRgnIndirect( &rc
);
3986 ValidateRgn( hwnd
, rgn
);
3987 ret
= GetUpdateRect( child
, &rc2
, 0);
3988 ok( !ret
, "Expected GetUpdateRect to return zero, got %d\n", ret
);
3989 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
3990 "Update rectangle %s is not empty!\n", wine_dbgstr_rect(&rc2
));
3993 DestroyWindow( child
);
3996 static void nccalchelper(HWND hwnd
, INT x
, INT y
, RECT
*prc
)
3999 MoveWindow( hwnd
, 0, 0, x
, y
, 0);
4000 GetWindowRect( hwnd
, prc
);
4002 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)prc
);
4003 if (winetest_debug
> 1)
4004 trace("window rect is %s, nccalc rect is %s\n", wine_dbgstr_rect(&rc
), wine_dbgstr_rect(prc
));
4007 static void test_nccalcscroll(HWND parent
)
4010 INT sbheight
= GetSystemMetrics( SM_CYHSCROLL
);
4011 INT sbwidth
= GetSystemMetrics( SM_CXVSCROLL
);
4012 HWND hwnd
= CreateWindowExA(0, "static", NULL
,
4013 WS_CHILD
| WS_VISIBLE
| WS_VSCROLL
| WS_HSCROLL
,
4014 10, 10, 200, 200, parent
, 0, 0, NULL
);
4015 ShowWindow( parent
, SW_SHOW
);
4016 UpdateWindow( parent
);
4018 /* test window too low for a horizontal scroll bar */
4019 nccalchelper( hwnd
, 100, sbheight
, &rc1
);
4020 ok( rc1
.bottom
- rc1
.top
== sbheight
, "Height should be %d size is %s\n", sbheight
,
4021 wine_dbgstr_rect(&rc1
));
4023 /* test window just high enough for a horizontal scroll bar */
4024 nccalchelper( hwnd
, 100, sbheight
+ 1, &rc1
);
4025 ok( rc1
.bottom
- rc1
.top
== 1, "Height should be 1 size is %s\n", wine_dbgstr_rect(&rc1
));
4027 /* test window too narrow for a vertical scroll bar */
4028 nccalchelper( hwnd
, sbwidth
- 1, 100, &rc1
);
4029 ok( rc1
.right
- rc1
.left
== sbwidth
- 1 , "Width should be %d size is %s\n", sbwidth
- 1,
4030 wine_dbgstr_rect(&rc1
));
4032 /* test window just wide enough for a vertical scroll bar */
4033 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
4034 ok( rc1
.right
- rc1
.left
== 0, "Width should be 0 size is %s\n", wine_dbgstr_rect(&rc1
));
4036 /* same test, but with client edge: not enough width */
4037 SetWindowLongA( hwnd
, GWL_EXSTYLE
, WS_EX_CLIENTEDGE
| GetWindowLongA( hwnd
, GWL_EXSTYLE
));
4038 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
4039 ok( rc1
.right
- rc1
.left
== sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
),
4040 "Width should be %d size is %s\n", sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
),
4041 wine_dbgstr_rect(&rc1
));
4043 DestroyWindow( hwnd
);
4046 static void test_SetParent(void)
4048 HWND desktop
= GetDesktopWindow();
4050 HWND ret
, parent
, child1
, child2
, child3
, child4
, sibling
, popup
;
4053 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
4054 100, 100, 200, 200, 0, 0, 0, NULL
);
4055 assert(parent
!= 0);
4056 child1
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
4057 0, 0, 50, 50, parent
, 0, 0, NULL
);
4058 assert(child1
!= 0);
4059 child2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
4060 0, 0, 50, 50, child1
, 0, 0, NULL
);
4061 assert(child2
!= 0);
4062 child3
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
4063 0, 0, 50, 50, child2
, 0, 0, NULL
);
4064 assert(child3
!= 0);
4065 child4
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
4066 0, 0, 50, 50, child3
, 0, 0, NULL
);
4067 assert(child4
!= 0);
4069 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
4070 parent
, child1
, child2
, child3
, child4
);
4072 check_parents(parent
, desktop
, 0, 0, 0, parent
, parent
);
4073 check_parents(child1
, parent
, parent
, parent
, 0, parent
, parent
);
4074 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
4075 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
4076 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
4078 ok(!IsChild(desktop
, parent
), "wrong parent/child %p/%p\n", desktop
, parent
);
4079 ok(!IsChild(desktop
, child1
), "wrong parent/child %p/%p\n", desktop
, child1
);
4080 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
4081 ok(!IsChild(desktop
, child3
), "wrong parent/child %p/%p\n", desktop
, child3
);
4082 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
4084 ok(IsChild(parent
, child1
), "wrong parent/child %p/%p\n", parent
, child1
);
4085 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
4086 ok(!IsChild(parent
, child2
), "wrong parent/child %p/%p\n", parent
, child2
);
4087 ok(!IsChild(child1
, child2
), "wrong parent/child %p/%p\n", child1
, child2
);
4088 ok(!IsChild(parent
, child3
), "wrong parent/child %p/%p\n", parent
, child3
);
4089 ok(IsChild(child2
, child3
), "wrong parent/child %p/%p\n", child2
, child3
);
4090 ok(!IsChild(parent
, child4
), "wrong parent/child %p/%p\n", parent
, child4
);
4091 ok(!IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
4092 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
4094 ok(!SetParent(parent
, child1
), "SetParent should fail\n");
4095 ok(!SetParent(child2
, child3
), "SetParent should fail\n");
4096 ok(SetParent(child1
, parent
) != 0, "SetParent should not fail\n");
4097 ret
= SetParent(parent
, child2
);
4098 todo_wine
ok( !ret
|| broken( ret
!= 0 ), "SetParent should fail\n");
4099 if (ret
) /* nt4, win2k */
4101 ret
= SetParent(parent
, child3
);
4102 ok(ret
!= 0, "SetParent should not fail\n");
4103 ret
= SetParent(child2
, parent
);
4104 ok(!ret
, "SetParent should fail\n");
4105 ret
= SetParent(parent
, child4
);
4106 ok(ret
!= 0, "SetParent should not fail\n");
4107 check_parents(parent
, child4
, child4
, 0, 0, child4
, parent
);
4108 check_parents(child1
, parent
, parent
, parent
, 0, child4
, parent
);
4109 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
4110 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
4111 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
4115 ret
= SetParent(parent
, child3
);
4116 ok(ret
!= 0, "SetParent should not fail\n");
4117 ret
= SetParent(child2
, parent
);
4118 ok(!ret
, "SetParent should fail\n");
4119 ret
= SetParent(parent
, child4
);
4120 ok(!ret
, "SetParent should fail\n");
4121 check_parents(parent
, child3
, child3
, 0, 0, child2
, parent
);
4122 check_parents(child1
, parent
, parent
, parent
, 0, child2
, parent
);
4123 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
4124 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
4125 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
4128 hMenu
= CreateMenu();
4129 sibling
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
4130 100, 100, 200, 200, 0, hMenu
, 0, NULL
);
4131 assert(sibling
!= 0);
4133 ok(SetParent(sibling
, parent
) != 0, "SetParent should not fail\n");
4134 ok(GetMenu(sibling
) == hMenu
, "SetParent should not remove menu\n");
4136 ok(SetParent(parent
, desktop
) != 0, "SetParent should not fail\n");
4137 ok(SetParent(child4
, child3
) != 0, "SetParent should not fail\n");
4138 ok(SetParent(child3
, child2
) != 0, "SetParent should not fail\n");
4139 ok(SetParent(child2
, child1
) != 0, "SetParent should not fail\n");
4140 ok(!IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
4141 SetWindowLongW(child4
, GWL_STYLE
, WS_CHILD
);
4142 ok(IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
4143 ok(IsChild(child2
, child4
), "wrong parent/child %p/%p\n", child2
, child4
);
4144 ok(!IsChild(child1
, child4
), "wrong parent/child %p/%p\n", child1
, child4
);
4145 SetWindowLongW(child2
, GWL_STYLE
, WS_CHILD
);
4146 ok(IsChild(child1
, child4
), "wrong parent/child %p/%p\n", child1
, child4
);
4147 ok(IsChild(parent
, child4
), "wrong parent/child %p/%p\n", parent
, child4
);
4149 ok(DestroyWindow(parent
), "DestroyWindow() failed\n");
4151 ok(!IsWindow(parent
), "parent still exists\n");
4152 ok(!IsWindow(sibling
), "sibling still exists\n");
4153 ok(!IsWindow(child1
), "child1 still exists\n");
4154 ok(!IsWindow(child2
), "child2 still exists\n");
4155 ok(!IsWindow(child3
), "child3 still exists\n");
4156 ok(!IsWindow(child4
), "child4 still exists\n");
4158 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
4159 100, 100, 200, 200, 0, 0, 0, NULL
);
4160 assert(parent
!= 0);
4161 child1
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
4162 0, 0, 50, 50, parent
, 0, 0, NULL
);
4163 assert(child1
!= 0);
4164 popup
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
4165 0, 0, 50, 50, 0, 0, 0, NULL
);
4168 trace("parent %p, child %p, popup %p\n", parent
, child1
, popup
);
4170 check_parents(parent
, desktop
, 0, 0, 0, parent
, parent
);
4171 check_parents(child1
, parent
, parent
, parent
, 0, parent
, parent
);
4172 check_parents(popup
, desktop
, 0, 0, 0, popup
, popup
);
4174 SetActiveWindow(parent
);
4176 check_active_state(parent
, 0, parent
);
4178 ret
= SetParent(popup
, child1
);
4179 ok(ret
== desktop
, "expected %p, got %p\n", desktop
, ret
);
4180 check_parents(popup
, child1
, child1
, 0, 0, parent
, popup
);
4181 check_active_state(popup
, 0, popup
);
4183 SetActiveWindow(parent
);
4185 check_active_state(popup
, 0, popup
);
4187 EnableWindow(child1
, FALSE
);
4188 check_active_state(popup
, 0, popup
);
4190 check_active_state(parent
, 0, parent
);
4192 check_active_state(popup
, 0, popup
);
4193 EnableWindow(child1
, TRUE
);
4195 ShowWindow(child1
, SW_MINIMIZE
);
4197 check_active_state(parent
, 0, parent
);
4199 check_active_state(popup
, 0, popup
);
4200 ShowWindow(child1
, SW_HIDE
);
4202 SetActiveWindow(parent
);
4204 check_active_state(parent
, 0, parent
);
4206 bret
= SetForegroundWindow(popup
);
4207 ok(bret
, "SetForegroundWindow() failed\n");
4208 check_active_state(popup
, popup
, popup
);
4210 ShowWindow(parent
, SW_SHOW
);
4211 SetActiveWindow(popup
);
4212 ok(DestroyWindow(popup
), "DestroyWindow() failed\n");
4213 check_active_state(parent
, parent
, parent
);
4215 ok(DestroyWindow(parent
), "DestroyWindow() failed\n");
4217 ok(!IsWindow(parent
), "parent still exists\n");
4218 ok(!IsWindow(child1
), "child1 still exists\n");
4219 ok(!IsWindow(popup
), "popup still exists\n");
4222 static LRESULT WINAPI
StyleCheckProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4224 LPCREATESTRUCTA lpcs
;
4231 lpcs
= (LPCREATESTRUCTA
)lparam
;
4232 lpss
= lpcs
->lpCreateParams
;
4235 if ((lpcs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
4236 ((!(lpcs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
4237 (lpcs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
4238 ok(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
, "Window should have WS_EX_WINDOWEDGE style\n");
4240 ok(!(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
4242 ok((lpss
->styleOld
& ~WS_EX_WINDOWEDGE
) == (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
),
4243 "Ex style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
4244 lpss
->styleOld
, lpcs
->dwExStyle
);
4246 ok(lpss
->styleNew
== lpcs
->style
,
4247 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
4248 lpss
->styleNew
, lpcs
->style
);
4252 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
4255 static ATOM atomStyleCheckClass
;
4257 static void register_style_check_class(void)
4265 GetModuleHandleA(NULL
),
4267 LoadCursorA(0, (LPCSTR
)IDC_ARROW
),
4268 (HBRUSH
)(COLOR_BTNFACE
+1),
4273 atomStyleCheckClass
= RegisterClassA(&wc
);
4274 assert(atomStyleCheckClass
);
4277 static void check_window_style(DWORD dwStyleIn
, DWORD dwExStyleIn
, DWORD dwStyleOut
, DWORD dwExStyleOut
)
4279 DWORD dwActualStyle
;
4280 DWORD dwActualExStyle
;
4283 HWND hwndParent
= NULL
;
4285 ss
.styleNew
= dwStyleIn
;
4286 ss
.styleOld
= dwExStyleIn
;
4288 if (dwStyleIn
& WS_CHILD
)
4290 hwndParent
= CreateWindowExA(0, (LPCSTR
)MAKEINTATOM(atomStyleCheckClass
), NULL
,
4291 WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
4294 hwnd
= CreateWindowExA(dwExStyleIn
, (LPCSTR
)MAKEINTATOM(atomStyleCheckClass
), NULL
,
4295 dwStyleIn
, 0, 0, 0, 0, hwndParent
, NULL
, NULL
, &ss
);
4298 flush_events( TRUE
);
4300 dwActualStyle
= GetWindowLongA(hwnd
, GWL_STYLE
);
4301 dwActualExStyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
4302 ok(dwActualStyle
== dwStyleOut
, "expected style %#x, got %#x\n", dwStyleOut
, dwActualStyle
);
4303 ok(dwActualExStyle
== dwExStyleOut
, "expected ex_style %#x, got %#x\n", dwExStyleOut
, dwActualExStyle
);
4305 /* try setting the styles explicitly */
4306 SetWindowLongA( hwnd
, GWL_EXSTYLE
, dwExStyleIn
);
4307 dwActualStyle
= GetWindowLongA(hwnd
, GWL_STYLE
);
4308 dwActualExStyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
4309 /* WS_EX_WINDOWEDGE can't always be changed */
4310 if (dwExStyleIn
& WS_EX_DLGMODALFRAME
)
4311 dwExStyleOut
= dwExStyleIn
| WS_EX_WINDOWEDGE
;
4312 else if ((dwActualStyle
& (WS_DLGFRAME
| WS_THICKFRAME
)) && !(dwExStyleIn
& WS_EX_STATICEDGE
))
4313 dwExStyleOut
= dwExStyleIn
| WS_EX_WINDOWEDGE
;
4315 dwExStyleOut
= dwExStyleIn
& ~WS_EX_WINDOWEDGE
;
4316 ok(dwActualStyle
== dwStyleOut
, "expected style %#x, got %#x\n", dwStyleOut
, dwActualStyle
);
4317 ok(dwActualExStyle
== dwExStyleOut
, "expected ex_style %#x, got %#x\n", dwExStyleOut
, dwActualExStyle
);
4319 SetWindowLongA( hwnd
, GWL_STYLE
, dwStyleIn
);
4320 dwActualStyle
= GetWindowLongA(hwnd
, GWL_STYLE
);
4321 dwActualExStyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
4322 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
4323 if ((dwStyleIn
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
) dwStyleOut
= dwStyleIn
;
4324 else dwStyleOut
= dwStyleIn
| WS_CLIPSIBLINGS
;
4325 /* WS_EX_WINDOWEDGE can't always be changed */
4326 if (dwExStyleIn
& WS_EX_DLGMODALFRAME
)
4327 dwExStyleOut
= dwExStyleIn
| WS_EX_WINDOWEDGE
;
4328 else if ((dwActualStyle
& (WS_DLGFRAME
| WS_THICKFRAME
)) && !(dwExStyleIn
& WS_EX_STATICEDGE
))
4329 dwExStyleOut
= dwExStyleIn
| WS_EX_WINDOWEDGE
;
4331 dwExStyleOut
= dwExStyleIn
& ~WS_EX_WINDOWEDGE
;
4332 ok(dwActualStyle
== dwStyleOut
, "expected style %#x, got %#x\n", dwStyleOut
, dwActualStyle
);
4333 /* FIXME: Remove the condition below once Wine is fixed */
4334 todo_wine_if (dwActualExStyle
!= dwExStyleOut
)
4335 ok(dwActualExStyle
== dwExStyleOut
, "expected ex_style %#x, got %#x\n", dwExStyleOut
, dwActualExStyle
);
4337 DestroyWindow(hwnd
);
4338 if (hwndParent
) DestroyWindow(hwndParent
);
4341 /* tests what window styles the window manager automatically adds */
4342 static void test_window_styles(void)
4344 register_style_check_class();
4346 check_window_style(0, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
4347 check_window_style(WS_DLGFRAME
, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
4348 check_window_style(WS_THICKFRAME
, 0, WS_THICKFRAME
|WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
4349 check_window_style(WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_STATICEDGE
);
4350 check_window_style(WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_THICKFRAME
|WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_STATICEDGE
);
4351 check_window_style(WS_OVERLAPPEDWINDOW
, 0, WS_CLIPSIBLINGS
|WS_OVERLAPPEDWINDOW
, WS_EX_WINDOWEDGE
);
4352 check_window_style(WS_CHILD
, 0, WS_CHILD
, 0);
4353 check_window_style(WS_CHILD
|WS_DLGFRAME
, 0, WS_CHILD
|WS_DLGFRAME
, WS_EX_WINDOWEDGE
);
4354 check_window_style(WS_CHILD
|WS_THICKFRAME
, 0, WS_CHILD
|WS_THICKFRAME
, WS_EX_WINDOWEDGE
);
4355 check_window_style(WS_CHILD
|WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_DLGFRAME
, WS_EX_STATICEDGE
);
4356 check_window_style(WS_CHILD
|WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_THICKFRAME
, WS_EX_STATICEDGE
);
4357 check_window_style(WS_CHILD
|WS_CAPTION
, 0, WS_CHILD
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
4358 check_window_style(WS_CHILD
|WS_CAPTION
|WS_SYSMENU
, 0, WS_CHILD
|WS_CAPTION
|WS_SYSMENU
, WS_EX_WINDOWEDGE
);
4359 check_window_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
4360 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
, WS_CHILD
, WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
4361 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
|WS_EX_STATICEDGE
, WS_CHILD
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
4362 check_window_style(WS_CHILD
|WS_POPUP
, 0, WS_CHILD
|WS_POPUP
|WS_CLIPSIBLINGS
, 0);
4363 check_window_style(WS_CHILD
|WS_POPUP
|WS_DLGFRAME
, 0, WS_CHILD
|WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4364 check_window_style(WS_CHILD
|WS_POPUP
|WS_THICKFRAME
, 0, WS_CHILD
|WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4365 check_window_style(WS_CHILD
|WS_POPUP
|WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
);
4366 check_window_style(WS_CHILD
|WS_POPUP
|WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
);
4367 check_window_style(WS_CHILD
|WS_POPUP
, WS_EX_APPWINDOW
, WS_CHILD
|WS_POPUP
|WS_CLIPSIBLINGS
, WS_EX_APPWINDOW
);
4368 check_window_style(WS_CHILD
|WS_POPUP
, WS_EX_WINDOWEDGE
, WS_CHILD
|WS_POPUP
|WS_CLIPSIBLINGS
, 0);
4369 check_window_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
4370 check_window_style(0, WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_TOOLWINDOW
);
4371 check_window_style(WS_POPUP
, 0, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
4372 check_window_style(WS_POPUP
, WS_EX_WINDOWEDGE
, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
4373 check_window_style(WS_POPUP
|WS_DLGFRAME
, 0, WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4374 check_window_style(WS_POPUP
|WS_THICKFRAME
, 0, WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4375 check_window_style(WS_POPUP
|WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
);
4376 check_window_style(WS_POPUP
|WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
);
4377 check_window_style(WS_CAPTION
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
);
4378 check_window_style(0, WS_EX_APPWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_APPWINDOW
|WS_EX_WINDOWEDGE
);
4380 if (pGetLayeredWindowAttributes
)
4382 check_window_style(0, WS_EX_LAYERED
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_LAYERED
|WS_EX_WINDOWEDGE
);
4383 check_window_style(0, WS_EX_LAYERED
|WS_EX_TRANSPARENT
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_LAYERED
|WS_EX_TRANSPARENT
|WS_EX_WINDOWEDGE
);
4384 check_window_style(0, WS_EX_LAYERED
|WS_EX_TRANSPARENT
|WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
,
4385 WS_EX_LAYERED
|WS_EX_TRANSPARENT
|WS_EX_TOOLWINDOW
|WS_EX_WINDOWEDGE
);
4389 static INT_PTR WINAPI
empty_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4394 static INT_PTR WINAPI
empty_dlg_proc3(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4396 if (msg
== WM_INITDIALOG
)
4404 HWND parent
, grand_parent
;
4405 DLGTEMPLATE
*dlg_data
;
4408 static INT_PTR WINAPI
empty_dlg_proc2(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4410 if (msg
== WM_INITDIALOG
)
4412 DWORD style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4413 struct dialog_param
*param
= (struct dialog_param
*)lparam
;
4414 BOOL parent_is_child
;
4417 parent_is_child
= (GetWindowLongA(param
->parent
, GWL_STYLE
) & (WS_POPUP
| WS_CHILD
)) == WS_CHILD
;
4419 ok(IsWindowEnabled(hwnd
), "wrong state for %p\n", hwnd
);
4420 if (parent_is_child
)
4422 ok(IsWindowEnabled(param
->parent
), "wrong state for %08x\n", style
);
4423 disabled_hwnd
= param
->grand_parent
;
4427 ok(!IsWindowEnabled(param
->parent
), "wrong state for %08x\n", style
);
4428 disabled_hwnd
= param
->parent
;
4431 if (param
->grand_parent
)
4433 if (parent_is_child
)
4434 ok(!IsWindowEnabled(param
->grand_parent
), "wrong state for %08x\n", style
);
4436 ok(IsWindowEnabled(param
->grand_parent
), "wrong state for %08x\n", style
);
4439 DialogBoxIndirectParamA(GetModuleHandleA(NULL
), param
->dlg_data
, disabled_hwnd
, empty_dlg_proc3
, 0);
4440 ok(IsWindowEnabled(disabled_hwnd
), "wrong state for %08x\n", style
);
4442 ok(IsWindowEnabled(hwnd
), "wrong state for %p\n", hwnd
);
4443 ok(IsWindowEnabled(param
->parent
), "wrong state for %p\n", param
->parent
);
4444 if (param
->grand_parent
)
4445 ok(IsWindowEnabled(param
->grand_parent
), "wrong state for %p (%08x)\n", param
->grand_parent
, style
);
4447 DialogBoxIndirectParamA(GetModuleHandleA(NULL
), param
->dlg_data
, hwnd
, empty_dlg_proc3
, 0);
4448 ok(IsWindowEnabled(hwnd
), "wrong state for %p\n", hwnd
);
4449 ok(IsWindowEnabled(param
->parent
), "wrong state for %p\n", param
->parent
);
4450 if (param
->grand_parent
)
4451 ok(IsWindowEnabled(param
->grand_parent
), "wrong state for %p (%08x)\n", param
->grand_parent
, style
);
4453 param
->dlg_data
->style
|= WS_CHILD
;
4454 DialogBoxIndirectParamA(GetModuleHandleA(NULL
), param
->dlg_data
, hwnd
, empty_dlg_proc3
, 0);
4455 ok(IsWindowEnabled(hwnd
), "wrong state for %p (%08x)\n", hwnd
, style
);
4462 static void check_dialog_style(DWORD style_in
, DWORD ex_style_in
, DWORD style_out
, DWORD ex_style_out
)
4472 DWORD style
, ex_style
;
4473 HWND hwnd
, grand_parent
= 0, parent
= 0;
4474 struct dialog_param param
;
4476 if (style_in
& WS_CHILD
)
4478 grand_parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
4479 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
4480 ok(grand_parent
!= 0, "grand_parent creation failed\n");
4483 parent
= CreateWindowExA(0, "static", NULL
, style_in
,
4484 0, 0, 0, 0, grand_parent
, NULL
, NULL
, NULL
);
4485 ok(parent
!= 0, "parent creation failed, style %#x\n", style_in
);
4487 dlg_data
.dt
.style
= style_in
;
4488 dlg_data
.dt
.dwExtendedStyle
= ex_style_in
;
4489 dlg_data
.dt
.cdit
= 0;
4492 dlg_data
.dt
.cx
= 100;
4493 dlg_data
.dt
.cy
= 100;
4494 dlg_data
.menu_name
= 0;
4495 dlg_data
.class_id
= 0;
4496 dlg_data
.class_atom
= 0;
4497 dlg_data
.caption
[0] = 0;
4499 hwnd
= CreateDialogIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, parent
, empty_dlg_proc
, 0);
4500 ok(hwnd
!= 0, "dialog creation failed, style %#x, exstyle %#x\n", style_in
, ex_style_in
);
4502 flush_events( TRUE
);
4504 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4505 ex_style
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
4506 ok(style
== (style_out
| DS_3DLOOK
), "got %#x\n", style
);
4507 ok(ex_style
== ex_style_out
, "expected ex_style %#x, got %#x\n", ex_style_out
, ex_style
);
4509 ok(IsWindowEnabled(parent
), "wrong parent state (dialog style %#x)\n", style_in
);
4511 /* try setting the styles explicitly */
4512 SetWindowLongA(hwnd
, GWL_EXSTYLE
, ex_style_in
);
4513 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4514 ex_style
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
4515 ok(style
== (style_out
| DS_3DLOOK
), "got %#x\n", style
);
4516 /* WS_EX_WINDOWEDGE can't always be changed */
4517 if (ex_style_in
& WS_EX_DLGMODALFRAME
)
4518 ex_style_out
= ex_style_in
| WS_EX_WINDOWEDGE
;
4519 else if ((style
& (WS_DLGFRAME
| WS_THICKFRAME
)) && !(ex_style_in
& WS_EX_STATICEDGE
))
4520 ex_style_out
= ex_style_in
| WS_EX_WINDOWEDGE
;
4522 ex_style_out
= ex_style_in
& ~WS_EX_WINDOWEDGE
;
4523 ok(ex_style
== ex_style_out
, "expected ex_style %#x, got %#x\n", ex_style_out
, ex_style
);
4525 SetWindowLongA(hwnd
, GWL_STYLE
, style_in
);
4526 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4527 ex_style
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
4528 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
4529 if ((style_in
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
) style_out
= style_in
;
4530 else style_out
= style_in
| WS_CLIPSIBLINGS
;
4531 ok(style
== style_out
, "expected style %#x, got %#x\n", style_out
, style
);
4532 /* WS_EX_WINDOWEDGE can't always be changed */
4533 if (ex_style_in
& WS_EX_DLGMODALFRAME
)
4534 ex_style_out
= ex_style_in
| WS_EX_WINDOWEDGE
;
4535 else if ((style
& (WS_DLGFRAME
| WS_THICKFRAME
)) && !(ex_style_in
& WS_EX_STATICEDGE
))
4536 ex_style_out
= ex_style_in
| WS_EX_WINDOWEDGE
;
4538 ex_style_out
= ex_style_in
& ~WS_EX_WINDOWEDGE
;
4539 /* FIXME: Remove the condition below once Wine is fixed */
4540 todo_wine_if (ex_style
!= ex_style_out
)
4541 ok(ex_style
== ex_style_out
, "expected ex_style %#x, got %#x\n", ex_style_out
, ex_style
);
4543 DestroyWindow(hwnd
);
4545 param
.parent
= parent
;
4546 param
.grand_parent
= grand_parent
;
4547 param
.dlg_data
= &dlg_data
.dt
;
4548 DialogBoxIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, parent
, empty_dlg_proc2
, (LPARAM
)¶m
);
4550 ok(IsWindowEnabled(parent
), "wrong parent state (dialog style %#x)\n", style_in
);
4552 ok(IsWindowEnabled(grand_parent
), "wrong grand parent state (dialog style %#x)\n", style_in
);
4554 DestroyWindow(parent
);
4555 DestroyWindow(grand_parent
);
4558 static void test_dialog_styles(void)
4560 check_dialog_style(0, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4561 check_dialog_style(WS_DLGFRAME
, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4562 check_dialog_style(WS_THICKFRAME
, 0, WS_THICKFRAME
|WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4563 check_dialog_style(WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_STATICEDGE
|WS_EX_CONTROLPARENT
);
4564 check_dialog_style(WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_THICKFRAME
|WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_STATICEDGE
|WS_EX_CONTROLPARENT
);
4565 check_dialog_style(DS_CONTROL
, 0, WS_CLIPSIBLINGS
|WS_CAPTION
|DS_CONTROL
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4566 check_dialog_style(WS_CAPTION
, 0, WS_CAPTION
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4567 check_dialog_style(WS_BORDER
, 0, WS_CAPTION
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4568 check_dialog_style(WS_DLGFRAME
, 0, WS_CAPTION
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4569 check_dialog_style(WS_BORDER
|DS_CONTROL
, 0, WS_CAPTION
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4570 check_dialog_style(WS_DLGFRAME
|DS_CONTROL
, 0, WS_CAPTION
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4571 check_dialog_style(WS_CAPTION
|WS_SYSMENU
, 0, WS_CAPTION
|WS_SYSMENU
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4572 check_dialog_style(WS_SYSMENU
, 0, WS_CAPTION
|WS_SYSMENU
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4573 check_dialog_style(WS_CAPTION
|DS_CONTROL
, 0, WS_CAPTION
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4574 check_dialog_style(WS_SYSMENU
|DS_CONTROL
, 0, WS_CAPTION
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4575 check_dialog_style(WS_CAPTION
|WS_SYSMENU
|DS_CONTROL
, 0, WS_CAPTION
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4576 check_dialog_style(WS_OVERLAPPEDWINDOW
, 0, WS_CLIPSIBLINGS
|WS_OVERLAPPEDWINDOW
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4577 check_dialog_style(WS_CHILD
, 0, WS_CHILD
, 0);
4578 check_dialog_style(WS_CHILD
|WS_DLGFRAME
, 0, WS_CHILD
|WS_DLGFRAME
, WS_EX_WINDOWEDGE
);
4579 check_dialog_style(WS_CHILD
|WS_THICKFRAME
, 0, WS_CHILD
|WS_THICKFRAME
, WS_EX_WINDOWEDGE
);
4580 check_dialog_style(WS_CHILD
|WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_DLGFRAME
, WS_EX_STATICEDGE
);
4581 check_dialog_style(WS_CHILD
|WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_THICKFRAME
, WS_EX_STATICEDGE
);
4582 check_dialog_style(WS_CHILD
|DS_CONTROL
, 0, WS_CHILD
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4583 check_dialog_style(WS_CHILD
|WS_CAPTION
, 0, WS_CHILD
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
4584 check_dialog_style(WS_CHILD
|WS_BORDER
, 0, WS_CHILD
|WS_BORDER
, 0);
4585 check_dialog_style(WS_CHILD
|WS_DLGFRAME
, 0, WS_CHILD
|WS_DLGFRAME
, WS_EX_WINDOWEDGE
);
4586 check_dialog_style(WS_CHILD
|WS_BORDER
|DS_CONTROL
, 0, WS_CHILD
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4587 check_dialog_style(WS_CHILD
|WS_DLGFRAME
|DS_CONTROL
, 0, WS_CHILD
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4588 check_dialog_style(WS_CHILD
|WS_CAPTION
|WS_SYSMENU
, 0, WS_CHILD
|WS_CAPTION
|WS_SYSMENU
, WS_EX_WINDOWEDGE
);
4589 check_dialog_style(WS_CHILD
|WS_SYSMENU
, 0, WS_CHILD
|WS_SYSMENU
, 0);
4590 check_dialog_style(WS_CHILD
|WS_CAPTION
|DS_CONTROL
, 0, WS_CHILD
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4591 check_dialog_style(WS_CHILD
|WS_SYSMENU
|DS_CONTROL
, 0, WS_CHILD
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4592 check_dialog_style(WS_CHILD
|WS_CAPTION
|WS_SYSMENU
|DS_CONTROL
, 0, WS_CHILD
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4593 check_dialog_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
4594 check_dialog_style(WS_CHILD
, WS_EX_DLGMODALFRAME
, WS_CHILD
, WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
4595 check_dialog_style(WS_CHILD
, WS_EX_DLGMODALFRAME
|WS_EX_STATICEDGE
, WS_CHILD
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
4596 check_dialog_style(WS_CHILD
|WS_POPUP
, 0, WS_CHILD
|WS_POPUP
|WS_CLIPSIBLINGS
, 0);
4597 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_DLGFRAME
, 0, WS_CHILD
|WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4598 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_THICKFRAME
, 0, WS_CHILD
|WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4599 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
);
4600 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
);
4601 check_dialog_style(WS_CHILD
|WS_POPUP
|DS_CONTROL
, 0, WS_CHILD
|WS_POPUP
|WS_CLIPSIBLINGS
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4602 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_CAPTION
, 0, WS_CHILD
|WS_POPUP
|WS_CAPTION
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4603 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_BORDER
, 0, WS_CHILD
|WS_POPUP
|WS_BORDER
|WS_CLIPSIBLINGS
, 0);
4604 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_DLGFRAME
, 0, WS_CHILD
|WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4605 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_BORDER
|DS_CONTROL
, 0, WS_CHILD
|WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4606 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_DLGFRAME
|DS_CONTROL
, 0, WS_CHILD
|WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4607 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
);
4608 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_SYSMENU
, 0, WS_CHILD
|WS_POPUP
|WS_SYSMENU
|WS_CLIPSIBLINGS
, 0);
4609 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_CAPTION
|DS_CONTROL
, 0, WS_CHILD
|WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4610 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_SYSMENU
|DS_CONTROL
, 0, WS_CHILD
|WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4611 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
);
4612 check_dialog_style(WS_CHILD
|WS_POPUP
, WS_EX_APPWINDOW
, WS_CHILD
|WS_POPUP
|WS_CLIPSIBLINGS
, WS_EX_APPWINDOW
);
4613 check_dialog_style(WS_CHILD
|WS_POPUP
, WS_EX_WINDOWEDGE
, WS_CHILD
|WS_POPUP
|WS_CLIPSIBLINGS
, 0);
4614 check_dialog_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
4615 check_dialog_style(0, WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_TOOLWINDOW
|WS_EX_CONTROLPARENT
);
4616 check_dialog_style(WS_POPUP
, 0, WS_POPUP
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4617 check_dialog_style(WS_POPUP
, WS_EX_WINDOWEDGE
, WS_POPUP
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4618 check_dialog_style(WS_POPUP
|WS_DLGFRAME
, 0, WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4619 check_dialog_style(WS_POPUP
|WS_THICKFRAME
, 0, WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4620 check_dialog_style(WS_POPUP
|WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
|WS_EX_CONTROLPARENT
);
4621 check_dialog_style(WS_POPUP
|WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
|WS_EX_CONTROLPARENT
);
4622 check_dialog_style(WS_POPUP
|DS_CONTROL
, 0, WS_POPUP
|WS_CLIPSIBLINGS
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4623 check_dialog_style(WS_POPUP
|WS_CAPTION
, 0, WS_POPUP
|WS_CAPTION
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4624 check_dialog_style(WS_POPUP
|WS_BORDER
, 0, WS_POPUP
|WS_BORDER
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4625 check_dialog_style(WS_POPUP
|WS_DLGFRAME
, 0, WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4626 check_dialog_style(WS_POPUP
|WS_BORDER
|DS_CONTROL
, 0, WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4627 check_dialog_style(WS_POPUP
|WS_DLGFRAME
|DS_CONTROL
, 0, WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4628 check_dialog_style(WS_POPUP
|WS_CAPTION
|WS_SYSMENU
, 0, WS_POPUP
|WS_CAPTION
|WS_SYSMENU
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4629 check_dialog_style(WS_POPUP
|WS_SYSMENU
, 0, WS_POPUP
|WS_SYSMENU
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4630 check_dialog_style(WS_POPUP
|WS_CAPTION
|DS_CONTROL
, 0, WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4631 check_dialog_style(WS_POPUP
|WS_SYSMENU
|DS_CONTROL
, 0, WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4632 check_dialog_style(WS_POPUP
|WS_CAPTION
|WS_SYSMENU
|DS_CONTROL
, 0, WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4633 check_dialog_style(WS_CAPTION
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4634 check_dialog_style(0, WS_EX_APPWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_APPWINDOW
|WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4636 if (pGetLayeredWindowAttributes
)
4638 check_dialog_style(0, WS_EX_LAYERED
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_LAYERED
|WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4639 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
);
4640 check_dialog_style(0, WS_EX_LAYERED
|WS_EX_TRANSPARENT
|WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
,
4641 WS_EX_LAYERED
|WS_EX_TRANSPARENT
|WS_EX_TOOLWINDOW
|WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4645 struct dlg_parent_param
4655 static INT_PTR WINAPI
parent_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4657 if (msg
== WM_INITDIALOG
) {
4658 struct dlg_parent_param
*param
= (void*)lparam
;
4659 check_parents(hwnd
, param
->ga_parent
, param
->gwl_parent
, param
->get_parent
, param
->owner
,
4660 param
->root
? param
->root
: hwnd
, param
->ga_root_owner
? param
->ga_root_owner
: hwnd
);
4662 ok(!IsWindowEnabled(param
->gwl_parent
), "parent is not disabled\n");
4664 ok(IsWindowEnabled(param
->gwl_parent
), "parent is not enabled\n");
4670 static INT_PTR WINAPI
reparent_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4672 if (msg
== WM_INITDIALOG
) {
4673 ok(!IsWindowEnabled(GetParent(hwnd
)), "parent is not disabled\n");
4674 SetParent(hwnd
, (HWND
)lparam
);
4680 static INT_PTR WINAPI
reparent_owned_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4682 if (msg
== WM_INITDIALOG
) {
4683 HWND new_parent
= (HWND
)lparam
;
4684 HWND owner
= GetWindow(hwnd
, GW_OWNER
);
4685 ok(!IsWindowEnabled(owner
), "owner is not disabled\n");
4686 SetWindowLongA(hwnd
, GWL_STYLE
, GetWindowLongA(hwnd
, GWL_STYLE
) | WS_CHILD
);
4687 SetParent(hwnd
, new_parent
);
4688 ok(GetParent(hwnd
) == new_parent
, "GetParent(hwnd) = %p, expected %p\n", GetParent(hwnd
), new_parent
);
4689 PostMessageA(hwnd
, WM_QUIT
, 0, 0);
4695 static LRESULT WINAPI
reparent_dialog_owner_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4697 if (msg
== WM_ENTERIDLE
) {
4698 HWND dialog
= (HWND
)lparam
;
4699 HWND owner
= GetParent(dialog
);
4700 /* EndDialog will enable owner */
4701 EnableWindow(owner
, FALSE
);
4702 EndDialog(dialog
, 2);
4703 ok(IsWindowEnabled(owner
), "owner is not enabled\n");
4704 /* ...but it won't be enabled on dialog exit */
4705 EnableWindow(owner
, FALSE
);
4707 return DefWindowProcA( hwnd
, msg
, wparam
, lparam
);
4710 static LRESULT WINAPI
post_quit_dialog_owner_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4712 if (msg
== WM_ENTERIDLE
) {
4713 HWND dialog
= (HWND
)lparam
;
4714 PostMessageA(dialog
, WM_QUIT
, 0, 0);
4716 return DefWindowProcA( hwnd
, msg
, wparam
, lparam
);
4719 static LRESULT WINAPI
destroy_dialog_owner_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4721 if (msg
== WM_ENTERIDLE
) {
4722 HWND dialog
= (HWND
)lparam
;
4723 DestroyWindow(dialog
);
4725 return DefWindowProcA( hwnd
, msg
, wparam
, lparam
);
4728 static void test_dialog_parent(void)
4730 HWND dialog
, parent
, child
, child2
, other
, desktop
= GetDesktopWindow();
4731 struct dlg_parent_param param
;
4742 dlg_data
.dt
.dwExtendedStyle
= 0;
4743 dlg_data
.dt
.cdit
= 0;
4746 dlg_data
.dt
.cx
= 100;
4747 dlg_data
.dt
.cy
= 100;
4748 dlg_data
.menu_name
= 0;
4749 dlg_data
.class_id
= 0;
4750 dlg_data
.class_atom
= 0;
4751 dlg_data
.caption
[0] = 0;
4753 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
4754 /* Create a child without WS_CHILD flag. It's a valid owner window. */
4755 child
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
4756 SetParent(child
, parent
);
4757 /* Regular child. If passed as an owner, its parent will be true owner window. */
4758 child2
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, child
, NULL
, NULL
, NULL
);
4760 /* When dialog is created with WS_CHILD style, its parent depends on function used to create it. */
4761 dlg_data
.dt
.style
= WS_CHILD
;
4763 /* CreateDialogIndirectParam uses passed parent as dialog parent. */
4764 dialog
= CreateDialogIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, child2
, empty_dlg_proc
, 0);
4765 ok(dialog
!= 0, "dialog creation failed\n");
4766 check_parents(dialog
, child2
, child2
, child2
, NULL
, parent
, child
);
4768 ok(IsWindowEnabled(child2
), "child2 is disabled\n");
4769 EnableWindow(child2
, FALSE
);
4770 EndDialog(dialog
, 0);
4771 ok(IsWindowEnabled(child2
), "child2 is not enabled\n");
4772 DestroyWindow(dialog
);
4774 /* DialogBoxIndirectParam uses the first parent of passed owner that's not a child window as dialog
4775 * parent (like in case of dialog with owner). */
4776 param
.ga_parent
= param
.gwl_parent
= param
.get_parent
= child
;
4778 param
.root
= parent
;
4779 param
.ga_root_owner
= child
;
4780 ret
= DialogBoxIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, child2
, parent_dlg_proc
, (LPARAM
)¶m
);
4781 ok(ret
== 2, "DialogBoxIndirectParam returned %ld\n", ret
);
4783 /* Dialogs without WS_CHILD behave as expected, they use passed owner just like CreateWindow does. */
4784 dlg_data
.dt
.style
= WS_OVERLAPPEDWINDOW
;
4786 dialog
= CreateDialogIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, child2
, empty_dlg_proc
, 0);
4787 ok(dialog
!= 0, "dialog creation failed\n");
4788 check_parents(dialog
, desktop
, child
, NULL
, child
, dialog
, dialog
);
4790 ok(IsWindowEnabled(child
), "child is disabled\n");
4791 EnableWindow(child
, FALSE
);
4792 EndDialog(dialog
, 0);
4793 ok(IsWindowEnabled(child
), "child is not enabled\n");
4794 DestroyWindow(dialog
);
4796 param
.ga_parent
= desktop
;
4797 param
.gwl_parent
= child
;
4798 param
.get_parent
= NULL
;
4799 param
.owner
= child
;
4800 param
.root
= param
.ga_root_owner
= NULL
;
4801 ret
= DialogBoxIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, child2
, parent_dlg_proc
, (LPARAM
)¶m
);
4802 ok(ret
== 2, "DialogBoxIndirectParam returned %ld\n", ret
);
4804 other
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
4805 SetWindowLongPtrA(child
, GWLP_WNDPROC
, (ULONG_PTR
)reparent_dialog_owner_proc
);
4807 /* When dialog is created with WS_CHILD|WS_POPUP style, we have an owner. */
4808 dlg_data
.dt
.style
= WS_CHILD
|WS_POPUP
;
4810 dialog
= CreateDialogIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, child2
, empty_dlg_proc
, 0);
4811 ok(dialog
!= 0, "dialog creation failed\n");
4812 check_parents(dialog
, desktop
, child
, child
, child
, dialog
, child
);
4814 ok(IsWindowEnabled(child
), "child is disabled\n");
4815 EnableWindow(child
, FALSE
);
4816 EndDialog(dialog
, 0);
4817 ok(IsWindowEnabled(child
), "child is not enabled\n");
4818 DestroyWindow(dialog
);
4820 param
.ga_parent
= desktop
;
4821 param
.gwl_parent
= param
.get_parent
= child
;
4822 param
.owner
= child
;
4824 param
.ga_root_owner
= child
;
4825 ret
= DialogBoxIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, child2
, parent_dlg_proc
, (LPARAM
)¶m
);
4826 ok(ret
== 2, "DialogBoxIndirectParam returned %ld\n", ret
);
4828 /* If we change parent in WM_INITDIALOG for WS_CHILD dialog WM_ENTERIDLE is still sent to the original
4829 * parent. EndDialog will enable the new parent. */
4830 EnableWindow(child
, TRUE
);
4831 EnableWindow(other
, FALSE
);
4832 dlg_data
.dt
.style
= WS_CHILD
;
4833 ret
= DialogBoxIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, child2
, reparent_dlg_proc
, (LPARAM
)other
);
4834 ok(ret
== 2, "DialogBoxIndirectParam returned %ld\n", ret
);
4835 ok(!IsWindowEnabled(other
), "other is not disabled\n");
4836 ok(!IsWindowEnabled(child
), "child is not disabled\n");
4837 ok(IsWindowEnabled(child2
), "child2 is not enabled\n");
4838 EnableWindow(child
, TRUE
);
4840 /* If we change parent and style in WM_INITDIALOG for dialog with an owner to make it true child
4841 * (thus GetParent() will return the new parent instead of an owner), WM_ENTERIDLE is still sent
4842 * to the original parent. EndDialog will enable the new parent. */
4843 EnableWindow(other
, FALSE
);
4844 dlg_data
.dt
.style
= WS_OVERLAPPED
;
4845 ret
= DialogBoxIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, child2
, reparent_owned_dlg_proc
, (LPARAM
)other
);
4846 ok(ret
== 1, "DialogBoxIndirectParam returned %ld\n", ret
);
4847 ok(!IsWindowEnabled(other
), "other is not disabled\n");
4848 ok(!IsWindowEnabled(child
), "child is not disabled\n");
4849 ok(IsWindowEnabled(child2
), "child2 is not enabled\n");
4850 EnableWindow(child
, TRUE
);
4851 EnableWindow(other
, TRUE
);
4853 /* Quit dialog message loop by sending WM_QUIT message. Dialog owner is not enabled. */
4854 SetWindowLongPtrA(child
, GWLP_WNDPROC
, (ULONG_PTR
)post_quit_dialog_owner_proc
);
4855 ret
= DialogBoxIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, other
, empty_dlg_proc
, 0);
4856 ok(ret
== 1, "DialogBoxIndirectParam returned %ld\n", ret
);
4857 ok(!IsWindowEnabled(other
), "other is enabled\n");
4858 EnableWindow(other
, TRUE
);
4860 /* Quit dialog message loop by destroying the window. Dialog owner is not enabled. */
4861 SetWindowLongPtrA(child
, GWLP_WNDPROC
, (ULONG_PTR
)destroy_dialog_owner_proc
);
4862 ret
= DialogBoxIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, other
, empty_dlg_proc
, 0);
4863 ok(ret
== 1, "DialogBoxIndirectParam returned %ld\n", ret
);
4864 ok(!IsWindowEnabled(other
), "other is enabled\n");
4865 EnableWindow(other
, TRUE
);
4867 DestroyWindow(other
);
4868 DestroyWindow(parent
);
4871 static void test_scrollwindow( HWND hwnd
)
4877 ShowWindow( hwnd
, SW_SHOW
);
4878 UpdateWindow( hwnd
);
4879 flush_events( TRUE
);
4880 GetClientRect( hwnd
, &rc
);
4882 /* test ScrollWindow(Ex) with no clip rectangle */
4883 /* paint the lower half of the window black */
4885 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
4886 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
4887 /* paint the upper half of the window white */
4888 rc2
.bottom
= rc2
.top
;
4890 FillRect( hdc
, &rc2
, GetStockObject(WHITE_BRUSH
));
4891 /* scroll lower half up */
4893 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
4894 ScrollWindowEx( hwnd
, 0, - rc2
.top
, &rc2
, NULL
, NULL
, NULL
, SW_ERASE
);
4895 flush_events(FALSE
);
4896 /* expected: black should have scrolled to the upper half */
4897 colr
= GetPixel( hdc
, (rc2
.left
+rc2
.right
)/ 2, rc2
.bottom
/ 4 );
4898 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
4899 /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
4900 /* paint the lower half of the window black */
4902 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
4903 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
4904 /* paint the upper half of the window white */
4905 rc2
.bottom
= rc2
.top
;
4907 FillRect( hdc
, &rc2
, GetStockObject(WHITE_BRUSH
));
4908 /* scroll lower half up */
4910 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
4912 rc3
.left
= rc3
.right
/ 4;
4913 rc3
.right
-= rc3
.right
/ 4;
4914 ScrollWindowEx( hwnd
, 0, - rc2
.top
, &rc2
, &rc3
, NULL
, NULL
, SW_ERASE
);
4915 flush_events(FALSE
);
4916 /* expected: black should have scrolled to the upper half */
4917 colr
= GetPixel( hdc
, (rc2
.left
+rc2
.right
)/ 2, rc2
.bottom
/ 4 );
4918 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
4921 ReleaseDC( hwnd
, hdc
);
4924 static void test_scrollvalidate( HWND parent
)
4927 HRGN hrgn
=CreateRectRgn(0,0,0,0);
4928 HRGN exprgn
, tmprgn
, clipping
;
4929 RECT rc
, rcu
, cliprc
;
4930 /* create two overlapping child windows. The visual region
4931 * of hwnd1 is clipped by the overlapping part of
4932 * hwnd2 because of the WS_CLIPSIBLING style */
4935 clipping
= CreateRectRgn(0,0,0,0);
4936 tmprgn
= CreateRectRgn(0,0,0,0);
4937 exprgn
= CreateRectRgn(0,0,0,0);
4938 hwnd2
= CreateWindowExA(0, "static", NULL
,
4939 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
4940 75, 30, 100, 100, parent
, 0, 0, NULL
);
4941 hwnd1
= CreateWindowExA(0, "static", NULL
,
4942 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
4943 25, 50, 100, 100, parent
, 0, 0, NULL
);
4944 ShowWindow( parent
, SW_SHOW
);
4945 UpdateWindow( parent
);
4946 GetClientRect( hwnd1
, &rc
);
4948 SetRectRgn( clipping
, 10, 10, 90, 90);
4949 hdc
= GetDC( hwnd1
);
4950 /* for a visual touch */
4951 TextOutA( hdc
, 0,10, "0123456789", 10);
4952 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
4953 /* create a region with what is expected */
4954 SetRectRgn( exprgn
, 39,0,49,74);
4955 SetRectRgn( tmprgn
, 88,79,98,93);
4956 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
4957 SetRectRgn( tmprgn
, 0,93,98,98);
4958 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
4959 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
4960 if (!EqualRgn( exprgn
, hrgn
))
4962 trace("update rect is %s\n", wine_dbgstr_rect(&rcu
));
4965 /* now with clipping region */
4966 SelectClipRgn( hdc
, clipping
);
4967 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
4968 /* create a region with what is expected */
4969 SetRectRgn( exprgn
, 39,10,49,74);
4970 SetRectRgn( tmprgn
, 80,79,90,85);
4971 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
4972 SetRectRgn( tmprgn
, 10,85,90,90);
4973 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
4974 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
4975 if (!EqualRgn( exprgn
, hrgn
))
4977 trace("update rect is %s\n", wine_dbgstr_rect(&rcu
));
4980 ReleaseDC( hwnd1
, hdc
);
4982 /* test scrolling a rect by more than its size */
4983 DestroyWindow( hwnd2
);
4984 ValidateRect( hwnd1
, NULL
);
4985 SetRect( &rc
, 40,40, 50,50);
4986 InvalidateRect( hwnd1
, &rc
, 1);
4987 ScrollWindowEx( hwnd1
, -20, 0, &rc
, NULL
, hrgn
, &rcu
,
4988 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
4989 SetRectRgn( exprgn
, 20, 40, 30, 50);
4990 SetRectRgn( tmprgn
, 40, 40, 50, 50);
4991 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
4992 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
4993 if (!EqualRgn( exprgn
, hrgn
)) dump_region(hrgn
);
4994 ok( rcu
.left
== 20 && rcu
.top
== 40 && rcu
.right
== 50 && rcu
.bottom
== 50,
4995 "unexpected update rect: %s\n", wine_dbgstr_rect(&rcu
));
4997 /* test scrolling a window with an update region */
4998 ValidateRect( hwnd1
, NULL
);
4999 SetRect( &rc
, 40,40, 50,50);
5000 InvalidateRect( hwnd1
, &rc
, 1);
5001 GetClientRect( hwnd1
, &rc
);
5003 ScrollWindowEx( hwnd1
, -10, 0, &rc
, &cliprc
, hrgn
, &rcu
,
5004 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
5005 SetRectRgn( exprgn
, 88,0,98,98);
5006 SetRectRgn( tmprgn
, 30, 40, 50, 50);
5007 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
5008 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
5009 if (!EqualRgn( exprgn
, hrgn
)) dump_region(hrgn
);
5011 /* clear an update region */
5012 UpdateWindow( hwnd1
);
5014 SetRect( &rc
, 0,40, 100,60);
5015 SetRect( &cliprc
, 0,0, 100,100);
5016 ScrollWindowEx( hwnd1
, 0, -25, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
5017 SetRectRgn( exprgn
, 0, 40, 98, 60 );
5018 ok( EqualRgn( exprgn
, hrgn
), "wrong update region in excessive scroll\n");
5019 if (!EqualRgn( exprgn
, hrgn
)) dump_region(hrgn
);
5021 /* now test ScrollWindowEx with a combination of
5022 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
5023 /* make hwnd2 the child of hwnd1 */
5024 hwnd2
= CreateWindowExA(0, "static", NULL
,
5025 WS_CHILD
| WS_VISIBLE
| WS_BORDER
,
5026 50, 50, 100, 100, hwnd1
, 0, 0, NULL
);
5027 SetWindowLongA( hwnd1
, GWL_STYLE
, GetWindowLongA( hwnd1
, GWL_STYLE
) & ~WS_CLIPSIBLINGS
);
5028 GetClientRect( hwnd1
, &rc
);
5031 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
5032 SetWindowLongA( hwnd1
, GWL_STYLE
, GetWindowLongA( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
5033 ValidateRect( hwnd1
, NULL
);
5034 ValidateRect( hwnd2
, NULL
);
5035 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
,
5036 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
5037 SetRectRgn( exprgn
, 88,0,98,88);
5038 SetRectRgn( tmprgn
, 0,88,98,98);
5039 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
5040 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
5041 if (!EqualRgn( exprgn
, hrgn
)) dump_region(hrgn
);
5043 /* SW_SCROLLCHILDREN */
5044 SetWindowLongA( hwnd1
, GWL_STYLE
, GetWindowLongA( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
5045 ValidateRect( hwnd1
, NULL
);
5046 ValidateRect( hwnd2
, NULL
);
5047 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_SCROLLCHILDREN
| SW_INVALIDATE
);
5048 /* expected region is the same as in previous test */
5049 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
5050 if (!EqualRgn( exprgn
, hrgn
)) dump_region(hrgn
);
5052 /* no SW_SCROLLCHILDREN */
5053 SetWindowLongA( hwnd1
, GWL_STYLE
, GetWindowLongA( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
5054 ValidateRect( hwnd1
, NULL
);
5055 ValidateRect( hwnd2
, NULL
);
5056 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
5057 /* expected region is the same as in previous test */
5058 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
5059 if (!EqualRgn( exprgn
, hrgn
)) dump_region(hrgn
);
5061 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
5062 SetWindowLongA( hwnd1
, GWL_STYLE
, GetWindowLongA( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
5063 ValidateRect( hwnd1
, NULL
);
5064 ValidateRect( hwnd2
, NULL
);
5065 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
5066 SetRectRgn( exprgn
, 88,0,98,20);
5067 SetRectRgn( tmprgn
, 20,20,98,30);
5068 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
5069 SetRectRgn( tmprgn
, 20,30,30,88);
5070 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
5071 SetRectRgn( tmprgn
, 0,88,30,98);
5072 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
5073 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
5074 if (!EqualRgn( exprgn
, hrgn
)) dump_region(hrgn
);
5077 DeleteObject( hrgn
);
5078 DeleteObject( exprgn
);
5079 DeleteObject( tmprgn
);
5080 DestroyWindow( hwnd1
);
5081 DestroyWindow( hwnd2
);
5084 /* couple of tests of return values of scrollbar functions
5085 * called on a scrollbarless window */
5086 static void test_scroll(void)
5091 HWND hwnd
= CreateWindowExA(0, "Static", "Wine test window",
5092 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_POPUP
,
5093 100, 100, 200, 200, 0, 0, 0, NULL
);
5095 ret
= GetScrollRange( hwnd
, SB_HORZ
, &min
, &max
);
5096 ok( ret
, "GetScrollRange failed\n" );
5097 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
5098 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
5099 si
.cbSize
= sizeof( si
);
5100 si
.fMask
= SIF_PAGE
;
5101 si
.nPage
= 0xdeadbeef;
5102 ret
= GetScrollInfo( hwnd
, SB_HORZ
, &si
);
5103 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
5104 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
5106 ret
= GetScrollRange( hwnd
, SB_VERT
, &min
, &max
);
5107 ok( ret
, "GetScrollRange returns FALSE\n");
5108 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
5109 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
5110 si
.cbSize
= sizeof( si
);
5111 si
.fMask
= SIF_PAGE
;
5112 si
.nPage
= 0xdeadbeef;
5113 ret
= GetScrollInfo( hwnd
, SB_VERT
, &si
);
5114 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
5115 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
5117 DestroyWindow( hwnd
);
5120 static void test_scrolldc( HWND parent
)
5123 HRGN exprgn
, tmprgn
, hrgn
;
5124 RECT rc
, rc2
, rcu
, cliprc
;
5128 hrgn
= CreateRectRgn(0,0,0,0);
5129 tmprgn
= CreateRectRgn(0,0,0,0);
5130 exprgn
= CreateRectRgn(0,0,0,0);
5132 hwnd1
= CreateWindowExA(0, "static", NULL
,
5133 WS_CHILD
| WS_VISIBLE
,
5134 25, 50, 100, 100, parent
, 0, 0, NULL
);
5135 ShowWindow( parent
, SW_SHOW
);
5136 UpdateWindow( parent
);
5137 flush_events( TRUE
);
5138 GetClientRect( hwnd1
, &rc
);
5139 hdc
= GetDC( hwnd1
);
5140 /* paint the upper half of the window black */
5142 rc2
.bottom
= ( rc
.top
+ rc
.bottom
) /2;
5143 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
5144 /* clip region is the lower half */
5146 cliprc
.top
= (rc
.top
+ rc
.bottom
) /2;
5147 /* test whether scrolled pixels are properly clipped */
5148 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
5149 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
5150 /* this scroll should not cause any visible changes */
5151 ScrollDC( hdc
, 5, -20, &rc
, &cliprc
, hrgn
, &rcu
);
5152 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
5153 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
5154 /* test with NULL clip rect */
5155 ScrollDC( hdc
, 20, -20, &rc
, NULL
, hrgn
, &rcu
);
5156 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
5157 SetRect(&rc2
, 0, 0, 100, 100);
5158 ok(EqualRect(&rcu
, &rc2
), "rects do not match %s / %s\n", wine_dbgstr_rect(&rcu
),
5159 wine_dbgstr_rect(&rc2
));
5160 if (!EqualRect(&rcu
, &rc2
))
5162 trace("update rect: %s\n", wine_dbgstr_rect(&rcu
));
5166 SetRectRgn( exprgn
, 0, 0, 20, 80);
5167 SetRectRgn( tmprgn
, 0, 80, 100, 100);
5168 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
5169 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
5170 if (!EqualRgn(exprgn
, hrgn
)) dump_region(exprgn
);
5171 /* test clip rect > scroll rect */
5172 FillRect( hdc
, &rc
, GetStockObject(WHITE_BRUSH
));
5174 InflateRect( &rc2
, -(rc
.right
-rc
.left
)/4, -(rc
.bottom
-rc
.top
)/4);
5175 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
5176 ScrollDC( hdc
, 10, 10, &rc2
, &rc
, hrgn
, &rcu
);
5177 SetRectRgn( exprgn
, 25, 25, 75, 35);
5178 SetRectRgn( tmprgn
, 25, 35, 35, 75);
5179 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
5180 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
5181 if (!EqualRgn(exprgn
, hrgn
))
5183 trace("update rect: %s\n", wine_dbgstr_rect(&rcu
));
5187 ReleaseDC(hwnd1
, hdc
);
5189 DeleteObject(exprgn
);
5190 DeleteObject(tmprgn
);
5191 DestroyWindow(hwnd1
);
5194 static void test_params(void)
5199 ok(!IsWindow(0), "IsWindow(0)\n");
5200 ok(!IsWindow(HWND_BROADCAST
), "IsWindow(HWND_BROADCAST)\n");
5201 ok(!IsWindow(HWND_TOPMOST
), "IsWindow(HWND_TOPMOST)\n");
5203 /* Just a param check */
5204 SetLastError(0xdeadbeef);
5205 rc
= GetWindowTextA(hwndMain2
, NULL
, 1024);
5206 ok(!rc
, "GetWindowText: rc=%d err=%d\n",rc
,GetLastError());
5208 SetLastError(0xdeadbeef);
5209 hwnd
=CreateWindowA("LISTBOX", "TestList",
5210 (LBS_STANDARD
& ~LBS_SORT
),
5212 NULL
, (HMENU
)1, NULL
, 0);
5214 ok(!hwnd
|| broken(hwnd
!= NULL
), /* w2k3 sp2 */
5215 "CreateWindow with invalid menu handle should fail\n");
5217 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
,
5218 "wrong last error value %d\n", GetLastError());
5221 static void test_AWRwindow(LPCSTR
class, LONG style
, LONG exStyle
, BOOL menu
)
5225 hwnd
= CreateWindowExA(exStyle
, class, class, style
,
5231 ok(hwnd
!= NULL
, "Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style
, exStyle
);
5233 ShowWindow(hwnd
, SW_SHOW
);
5235 test_nonclient_area(hwnd
);
5238 DestroyWindow(hwnd
);
5241 static BOOL
AWR_init(void)
5245 class.style
= CS_HREDRAW
| CS_VREDRAW
;
5246 class.lpfnWndProc
= DefWindowProcA
;
5247 class.cbClsExtra
= 0;
5248 class.cbWndExtra
= 0;
5249 class.hInstance
= 0;
5250 class.hIcon
= LoadIconA(0, (LPCSTR
)IDI_APPLICATION
);
5251 class.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
5252 class.hbrBackground
= 0;
5253 class.lpszMenuName
= 0;
5254 class.lpszClassName
= szAWRClass
;
5256 if (!RegisterClassA(&class)) {
5257 ok(FALSE
, "RegisterClass failed\n");
5261 hmenu
= CreateMenu();
5264 ok(hmenu
!= 0, "Failed to create menu\n");
5265 ok(AppendMenuA(hmenu
, MF_STRING
, 1, "Test!"), "Failed to create menu item\n");
5271 static void test_AWR_window_size(BOOL menu
)
5273 static const DWORD styles
[] = {
5274 WS_POPUP
, WS_MAXIMIZE
, WS_BORDER
, WS_DLGFRAME
, WS_CAPTION
, WS_SYSMENU
,
5275 WS_THICKFRAME
, WS_MINIMIZEBOX
, WS_MAXIMIZEBOX
, WS_HSCROLL
, WS_VSCROLL
5277 static const DWORD exStyles
[] = {
5278 WS_EX_CLIENTEDGE
, WS_EX_TOOLWINDOW
, WS_EX_WINDOWEDGE
, WS_EX_APPWINDOW
,
5279 WS_EX_DLGMODALFRAME
, WS_EX_DLGMODALFRAME
| WS_EX_STATICEDGE
5284 /* A exhaustive check of all the styles takes too long
5285 * so just do a (hopefully representative) sample
5287 for (i
= 0; i
< ARRAY_SIZE(styles
); ++i
)
5288 test_AWRwindow(szAWRClass
, styles
[i
], 0, menu
);
5289 for (i
= 0; i
< ARRAY_SIZE(exStyles
); ++i
) {
5290 test_AWRwindow(szAWRClass
, WS_POPUP
, exStyles
[i
], menu
);
5291 test_AWRwindow(szAWRClass
, WS_THICKFRAME
, exStyles
[i
], menu
);
5295 static void test_AWR_flags(void)
5297 static const DWORD styles
[] = { WS_POPUP
, WS_BORDER
, WS_DLGFRAME
, WS_THICKFRAME
, WS_MINIMIZE
};
5298 static const DWORD exStyles
[] = { WS_EX_CLIENTEDGE
, WS_EX_TOOLWINDOW
, WS_EX_WINDOWEDGE
,
5299 WS_EX_APPWINDOW
, WS_EX_DLGMODALFRAME
, WS_EX_STATICEDGE
};
5301 DWORD i
, j
, k
, style
, exstyle
;
5304 for (i
= 0; i
< (1 << ARRAY_SIZE(styles
)); i
++)
5306 for (k
= style
= 0; k
< ARRAY_SIZE(styles
); k
++) if (i
& (1 << k
)) style
|= styles
[k
];
5308 for (j
= 0; j
< (1 << ARRAY_SIZE(exStyles
)); j
++)
5310 for (k
= exstyle
= 0; k
< ARRAY_SIZE(exStyles
); k
++) if (j
& (1 << k
)) exstyle
|= exStyles
[k
];
5311 SetRect( &rect
, 100, 100, 200, 200 );
5313 AdjustWindowRectEx( &rect
, style
, FALSE
, exstyle
);
5314 wine_AdjustWindowRectEx( &rect2
, style
, FALSE
, exstyle
);
5315 ok( EqualRect( &rect
, &rect2
), "%08x %08x rects do not match: win %s wine %s\n",
5316 style
, exstyle
, wine_dbgstr_rect( &rect
), wine_dbgstr_rect( &rect2
));
5317 if (pAdjustWindowRectExForDpi
)
5319 SetRect( &rect
, 100, 100, 200, 200 );
5321 pAdjustWindowRectExForDpi( &rect
, style
, FALSE
, exstyle
, 192 );
5322 wine_AdjustWindowRectExForDpi( &rect2
, style
, FALSE
, exstyle
, 192 );
5323 ok( EqualRect( &rect
, &rect2
), "%08x %08x rects do not match: win %s wine %s\n",
5324 style
, exstyle
, wine_dbgstr_rect( &rect
), wine_dbgstr_rect( &rect2
));
5330 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
5332 static void test_AdjustWindowRect(void)
5337 SHOWSYSMETRIC(SM_CYCAPTION
);
5338 SHOWSYSMETRIC(SM_CYSMCAPTION
);
5339 SHOWSYSMETRIC(SM_CYMENU
);
5340 SHOWSYSMETRIC(SM_CXEDGE
);
5341 SHOWSYSMETRIC(SM_CYEDGE
);
5342 SHOWSYSMETRIC(SM_CXVSCROLL
);
5343 SHOWSYSMETRIC(SM_CYHSCROLL
);
5344 SHOWSYSMETRIC(SM_CXFRAME
);
5345 SHOWSYSMETRIC(SM_CYFRAME
);
5346 SHOWSYSMETRIC(SM_CXDLGFRAME
);
5347 SHOWSYSMETRIC(SM_CYDLGFRAME
);
5348 SHOWSYSMETRIC(SM_CXBORDER
);
5349 SHOWSYSMETRIC(SM_CYBORDER
);
5351 test_AWR_window_size(FALSE
);
5352 test_AWR_window_size(TRUE
);
5357 #undef SHOWSYSMETRIC
5360 /* Global variables to trigger exit from loop */
5361 static int redrawComplete
, WMPAINT_count
;
5363 static LRESULT WINAPI
redraw_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
5369 if (WMPAINT_count
> 10 && redrawComplete
== 0) {
5371 BeginPaint(hwnd
, &ps
);
5372 EndPaint(hwnd
, &ps
);
5377 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
5380 /* Ensure we exit from RedrawNow regardless of invalidated area */
5381 static void test_redrawnow(void)
5387 cls
.style
= CS_DBLCLKS
;
5388 cls
.lpfnWndProc
= redraw_window_procA
;
5391 cls
.hInstance
= GetModuleHandleA(0);
5393 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
5394 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5395 cls
.lpszMenuName
= NULL
;
5396 cls
.lpszClassName
= "RedrawWindowClass";
5397 ret
= RegisterClassA(&cls
);
5398 ok(ret
, "Failed to register a test class.\n");
5400 hwndMain
= CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
5401 CW_USEDEFAULT
, 0, 100, 100, NULL
, NULL
, 0, NULL
);
5403 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
5404 ShowWindow(hwndMain
, SW_SHOW
);
5405 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
5406 RedrawWindow(hwndMain
, NULL
,NULL
,RDW_UPDATENOW
| RDW_ALLCHILDREN
);
5407 ok( WMPAINT_count
== 1,
5408 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
5409 redrawComplete
= TRUE
;
5410 ok( WMPAINT_count
< 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count
);
5413 DestroyWindow( hwndMain
);
5416 struct parentdc_stat
{
5422 struct parentdc_test
{
5423 struct parentdc_stat main
, main_todo
;
5424 struct parentdc_stat child1
, child1_todo
;
5425 struct parentdc_stat child2
, child2_todo
;
5428 static LRESULT WINAPI
parentdc_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
5433 struct parentdc_stat
*t
= (struct parentdc_stat
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
5438 GetClientRect(hwnd
, &rc
);
5440 GetWindowRect(hwnd
, &rc
);
5441 if (winetest_debug
> 1)
5442 trace("WM_PAINT: hwnd %p, client rect %s, window rect %s\n", hwnd
,
5443 wine_dbgstr_rect(&t
->client
), wine_dbgstr_rect(&rc
));
5444 BeginPaint(hwnd
, &ps
);
5445 t
->paint
= ps
.rcPaint
;
5446 GetClipBox(ps
.hdc
, &rc
);
5448 if (winetest_debug
> 1)
5449 trace("clip rect %s, paint rect %s\n", wine_dbgstr_rect(&rc
),
5450 wine_dbgstr_rect(&ps
.rcPaint
));
5451 EndPaint(hwnd
, &ps
);
5454 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
5457 static void zero_parentdc_stat(struct parentdc_stat
*t
)
5459 SetRectEmpty(&t
->client
);
5460 SetRectEmpty(&t
->clip
);
5461 SetRectEmpty(&t
->paint
);
5464 static void zero_parentdc_test(struct parentdc_test
*t
)
5466 zero_parentdc_stat(&t
->main
);
5467 zero_parentdc_stat(&t
->child1
);
5468 zero_parentdc_stat(&t
->child2
);
5471 #define parentdc_field_ok(t, w, r, f, got) \
5472 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
5473 ": expected %d, got %d\n", \
5476 #define parentdc_todo_field_ok(t, w, r, f, got) \
5477 todo_wine_if (t.w##_todo.r.f) \
5478 parentdc_field_ok(t, w, r, f, got);
5480 #define parentdc_rect_ok(t, w, r, got) \
5481 parentdc_todo_field_ok(t, w, r, left, got); \
5482 parentdc_todo_field_ok(t, w, r, top, got); \
5483 parentdc_todo_field_ok(t, w, r, right, got); \
5484 parentdc_todo_field_ok(t, w, r, bottom, got);
5486 #define parentdc_win_ok(t, w, got) \
5487 parentdc_rect_ok(t, w, client, got); \
5488 parentdc_rect_ok(t, w, clip, got); \
5489 parentdc_rect_ok(t, w, paint, got);
5491 #define parentdc_ok(t, got) \
5492 parentdc_win_ok(t, main, got); \
5493 parentdc_win_ok(t, child1, got); \
5494 parentdc_win_ok(t, child2, got);
5496 static void test_csparentdc(void)
5498 WNDCLASSA clsMain
, cls
;
5499 HWND hwndMain
, hwnd1
, hwnd2
;
5503 struct parentdc_test test_answer
;
5505 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
5506 const struct parentdc_test test1
=
5508 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo
,
5509 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
5510 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
5513 const struct parentdc_test test2
=
5515 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo
,
5516 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
5517 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
5520 const struct parentdc_test test3
=
5522 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
5523 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
5524 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
5527 const struct parentdc_test test4
=
5529 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo
,
5530 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo
,
5531 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
5534 const struct parentdc_test test5
=
5536 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo
,
5537 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
5538 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
5541 const struct parentdc_test test6
=
5543 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
5544 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
5545 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
5548 const struct parentdc_test test7
=
5550 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
5551 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
5552 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
5556 clsMain
.style
= CS_DBLCLKS
;
5557 clsMain
.lpfnWndProc
= parentdc_window_procA
;
5558 clsMain
.cbClsExtra
= 0;
5559 clsMain
.cbWndExtra
= 0;
5560 clsMain
.hInstance
= GetModuleHandleA(0);
5562 clsMain
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
5563 clsMain
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5564 clsMain
.lpszMenuName
= NULL
;
5565 clsMain
.lpszClassName
= "ParentDcMainWindowClass";
5566 ret
= RegisterClassA(&clsMain
);
5567 ok(ret
, "Failed to register a test class.\n");
5569 cls
.style
= CS_DBLCLKS
| CS_PARENTDC
;
5570 cls
.lpfnWndProc
= parentdc_window_procA
;
5573 cls
.hInstance
= GetModuleHandleA(0);
5575 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
5576 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5577 cls
.lpszMenuName
= NULL
;
5578 cls
.lpszClassName
= "ParentDcWindowClass";
5579 ret
= RegisterClassA(&cls
);
5580 ok(ret
, "Failed to register a test class.\n");
5582 SetRect(&rc
, 0, 0, 150, 150);
5583 AdjustWindowRectEx(&rc
, WS_OVERLAPPEDWINDOW
, FALSE
, 0);
5584 hwndMain
= CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
5585 CW_USEDEFAULT
, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, NULL
, NULL
, 0, NULL
);
5586 SetWindowLongPtrA(hwndMain
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.main
);
5587 hwnd1
= CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD
,
5588 20, 20, 40, 40, hwndMain
, NULL
, 0, NULL
);
5589 SetWindowLongPtrA(hwnd1
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child1
);
5590 hwnd2
= CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD
,
5591 40, 40, 40, 40, hwndMain
, NULL
, 0, NULL
);
5592 SetWindowLongPtrA(hwnd2
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child2
);
5593 ShowWindow(hwndMain
, SW_SHOW
);
5594 ShowWindow(hwnd1
, SW_SHOW
);
5595 ShowWindow(hwnd2
, SW_SHOW
);
5596 SetWindowPos(hwndMain
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
5597 flush_events( TRUE
);
5599 zero_parentdc_test(&test_answer
);
5600 InvalidateRect(hwndMain
, NULL
, TRUE
);
5601 flush_events( TRUE
);
5602 parentdc_ok(test1
, test_answer
);
5604 zero_parentdc_test(&test_answer
);
5605 SetRect(&rc
, 0, 0, 50, 50);
5606 InvalidateRect(hwndMain
, &rc
, TRUE
);
5607 flush_events( TRUE
);
5608 parentdc_ok(test2
, test_answer
);
5610 zero_parentdc_test(&test_answer
);
5611 SetRect(&rc
, 0, 0, 10, 10);
5612 InvalidateRect(hwndMain
, &rc
, TRUE
);
5613 flush_events( TRUE
);
5614 parentdc_ok(test3
, test_answer
);
5616 zero_parentdc_test(&test_answer
);
5617 SetRect(&rc
, 40, 40, 50, 50);
5618 InvalidateRect(hwndMain
, &rc
, TRUE
);
5619 flush_events( TRUE
);
5620 parentdc_ok(test4
, test_answer
);
5622 zero_parentdc_test(&test_answer
);
5623 SetRect(&rc
, 20, 20, 60, 60);
5624 InvalidateRect(hwndMain
, &rc
, TRUE
);
5625 flush_events( TRUE
);
5626 parentdc_ok(test5
, test_answer
);
5628 zero_parentdc_test(&test_answer
);
5629 SetRect(&rc
, 0, 0, 10, 10);
5630 InvalidateRect(hwnd1
, &rc
, TRUE
);
5631 flush_events( TRUE
);
5632 parentdc_ok(test6
, test_answer
);
5634 zero_parentdc_test(&test_answer
);
5635 SetRect(&rc
, -5, -5, 65, 65);
5636 InvalidateRect(hwnd1
, &rc
, TRUE
);
5637 flush_events( TRUE
);
5638 parentdc_ok(test7
, test_answer
);
5640 DestroyWindow(hwndMain
);
5641 DestroyWindow(hwnd1
);
5642 DestroyWindow(hwnd2
);
5645 static LRESULT WINAPI
def_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
5647 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
5650 static LRESULT WINAPI
def_window_procW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
5652 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
5655 static void test_IsWindowUnicode(void)
5657 static const char ansi_class_nameA
[] = "ansi class name";
5658 static const WCHAR ansi_class_nameW
[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
5659 static const char unicode_class_nameA
[] = "unicode class name";
5660 static const WCHAR unicode_class_nameW
[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
5666 memset(&classW
, 0, sizeof(classW
));
5667 classW
.hInstance
= GetModuleHandleA(0);
5668 classW
.lpfnWndProc
= def_window_procW
;
5669 classW
.lpszClassName
= unicode_class_nameW
;
5670 RegisterClassW(&classW
);
5672 memset(&classA
, 0, sizeof(classA
));
5673 classA
.hInstance
= GetModuleHandleA(0);
5674 classA
.lpfnWndProc
= def_window_procA
;
5675 classA
.lpszClassName
= ansi_class_nameA
;
5676 atom
= RegisterClassA(&classA
);
5679 /* unicode class: window proc */
5680 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
5681 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5684 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5685 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
5686 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5687 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
5688 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5690 DestroyWindow(hwnd
);
5692 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
5693 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5696 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5697 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
5698 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5699 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
5700 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5702 DestroyWindow(hwnd
);
5704 /* ansi class: window proc */
5705 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
5706 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5709 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5710 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
5711 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5712 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
5713 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5715 DestroyWindow(hwnd
);
5717 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
5718 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5721 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5722 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
5723 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5724 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
5725 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5727 DestroyWindow(hwnd
);
5729 /* unicode class: class proc */
5730 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
5731 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5734 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5735 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
5736 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5737 /* do not restore class window proc back to unicode */
5739 DestroyWindow(hwnd
);
5741 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
5742 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5745 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5746 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
5747 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5749 DestroyWindow(hwnd
);
5751 /* ansi class: class proc */
5752 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
5753 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5756 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5757 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
5758 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5759 /* do not restore class window proc back to ansi */
5761 DestroyWindow(hwnd
);
5763 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
5764 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5767 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5768 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
5769 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5771 DestroyWindow(hwnd
);
5774 static LRESULT CALLBACK
minmax_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
5778 if (msg
!= WM_GETMINMAXINFO
)
5779 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
5781 minmax
= (MINMAXINFO
*)lp
;
5783 if ((GetWindowLongA(hwnd
, GWL_STYLE
) & WS_CHILD
))
5785 minmax
->ptReserved
.x
= 0;
5786 minmax
->ptReserved
.y
= 0;
5787 minmax
->ptMaxSize
.x
= 400;
5788 minmax
->ptMaxSize
.y
= 400;
5789 minmax
->ptMaxPosition
.x
= 300;
5790 minmax
->ptMaxPosition
.y
= 300;
5791 minmax
->ptMaxTrackSize
.x
= 200;
5792 minmax
->ptMaxTrackSize
.y
= 200;
5793 minmax
->ptMinTrackSize
.x
= 100;
5794 minmax
->ptMinTrackSize
.y
= 100;
5797 DefWindowProcA(hwnd
, msg
, wp
, lp
);
5801 static int expected_cx
, expected_cy
;
5802 static RECT expected_rect
, broken_rect
;
5804 static LRESULT CALLBACK
winsizes_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
5808 case WM_GETMINMAXINFO
:
5811 GetWindowRect( hwnd
, &rect
);
5812 ok( !rect
.left
&& !rect
.top
&& !rect
.right
&& !rect
.bottom
, "wrong rect %s\n",
5813 wine_dbgstr_rect( &rect
));
5814 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
5819 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
5821 GetWindowRect( hwnd
, &rect
);
5822 ok( cs
->cx
== expected_cx
|| broken(cs
->cx
== (short)expected_cx
),
5823 "%p msg %x wrong x size %d/%d\n", hwnd
, msg
, cs
->cx
, expected_cx
);
5824 ok( cs
->cy
== expected_cy
|| broken(cs
->cy
== (short)expected_cy
),
5825 "%p msg %x wrong y size %d/%d\n", hwnd
, msg
, cs
->cy
, expected_cy
);
5826 ok( (rect
.right
- rect
.left
== expected_rect
.right
- expected_rect
.left
&&
5827 rect
.bottom
- rect
.top
== expected_rect
.bottom
- expected_rect
.top
) ||
5828 (rect
.right
- rect
.left
== min( 65535, expected_rect
.right
- expected_rect
.left
) &&
5829 rect
.bottom
- rect
.top
== min( 65535, expected_rect
.bottom
- expected_rect
.top
)) ||
5830 broken( rect
.right
- rect
.left
== broken_rect
.right
- broken_rect
.left
&&
5831 rect
.bottom
- rect
.top
== broken_rect
.bottom
- broken_rect
.top
) ||
5832 broken( rect
.right
- rect
.left
== (short)broken_rect
.right
- (short)broken_rect
.left
&&
5833 rect
.bottom
- rect
.top
== (short)broken_rect
.bottom
- (short)broken_rect
.top
),
5834 "%p msg %x wrong rect %s / %s\n", hwnd
, msg
, wine_dbgstr_rect( &rect
),
5835 wine_dbgstr_rect( &expected_rect
));
5836 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
5840 RECT rect
, *r
= (RECT
*)lp
;
5841 GetWindowRect( hwnd
, &rect
);
5842 ok( EqualRect( &rect
, r
), "passed rect %s doesn't match window rect %s\n",
5843 wine_dbgstr_rect( r
), wine_dbgstr_rect( &rect
));
5844 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
5847 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
5851 static void test_CreateWindow(void)
5861 #define expect_menu(window, menu) \
5862 SetLastError(0xdeadbeef); \
5863 res = (GetMenu(window) == (HMENU)menu); \
5864 ok(res, "GetMenu error %d\n", GetLastError())
5866 #define expect_style(window, style)\
5867 ok((ULONG)GetWindowLongA(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLongA(window, GWL_STYLE))
5869 #define expect_ex_style(window, ex_style)\
5870 ok((ULONG)GetWindowLongA(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLongA(window, GWL_EXSTYLE))
5872 hmenu
= CreateMenu();
5874 parent
= GetDesktopWindow();
5875 assert(parent
!= 0);
5877 SetLastError(0xdeadbeef);
5878 res
= IsMenu(hmenu
);
5879 ok(res
, "IsMenu error %d\n", GetLastError());
5882 SetLastError(0xdeadbeef);
5883 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
,
5884 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
5885 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5886 expect_menu(hwnd
, 1);
5887 expect_style(hwnd
, WS_CHILD
);
5888 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
5889 DestroyWindow(hwnd
);
5891 SetLastError(0xdeadbeef);
5892 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_CAPTION
,
5893 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
5894 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5895 expect_menu(hwnd
, 1);
5896 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
5897 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
5898 DestroyWindow(hwnd
);
5900 SetLastError(0xdeadbeef);
5901 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
5902 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
5903 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5904 expect_menu(hwnd
, 1);
5905 expect_style(hwnd
, WS_CHILD
);
5906 expect_ex_style(hwnd
, 0);
5907 DestroyWindow(hwnd
);
5909 SetLastError(0xdeadbeef);
5910 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_CAPTION
,
5911 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
5912 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5913 expect_menu(hwnd
, 1);
5914 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
5915 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
5916 DestroyWindow(hwnd
);
5919 SetLastError(0xdeadbeef);
5920 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
5921 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
5922 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5923 expect_menu(hwnd
, hmenu
);
5924 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
5925 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
5926 DestroyWindow(hwnd
);
5927 SetLastError(0xdeadbeef);
5928 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
5929 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
5931 hmenu
= CreateMenu();
5933 SetLastError(0xdeadbeef);
5934 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
| WS_CAPTION
,
5935 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
5936 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5937 expect_menu(hwnd
, hmenu
);
5938 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
5939 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
5940 DestroyWindow(hwnd
);
5941 SetLastError(0xdeadbeef);
5942 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
5943 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
5945 hmenu
= CreateMenu();
5947 SetLastError(0xdeadbeef);
5948 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
5949 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
5950 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5951 expect_menu(hwnd
, hmenu
);
5952 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
5953 expect_ex_style(hwnd
, 0);
5954 DestroyWindow(hwnd
);
5955 SetLastError(0xdeadbeef);
5956 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
5957 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
5959 hmenu
= CreateMenu();
5961 SetLastError(0xdeadbeef);
5962 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
| WS_CAPTION
,
5963 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
5964 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5965 expect_menu(hwnd
, hmenu
);
5966 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
5967 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
5968 DestroyWindow(hwnd
);
5969 SetLastError(0xdeadbeef);
5970 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
5971 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
5973 /* WS_CHILD | WS_POPUP */
5974 SetLastError(0xdeadbeef);
5975 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
5976 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
5977 ok(!hwnd
, "CreateWindowEx should fail\n");
5978 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
5980 DestroyWindow(hwnd
);
5982 hmenu
= CreateMenu();
5984 SetLastError(0xdeadbeef);
5985 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
5986 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
5987 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5988 expect_menu(hwnd
, hmenu
);
5989 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
5990 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
5991 DestroyWindow(hwnd
);
5992 SetLastError(0xdeadbeef);
5993 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
5994 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
5996 SetLastError(0xdeadbeef);
5997 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
5998 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
5999 ok(!hwnd
, "CreateWindowEx should fail\n");
6000 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
6002 DestroyWindow(hwnd
);
6004 hmenu
= CreateMenu();
6006 SetLastError(0xdeadbeef);
6007 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
6008 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
6009 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
6010 expect_menu(hwnd
, hmenu
);
6011 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
6012 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
6013 DestroyWindow(hwnd
);
6014 SetLastError(0xdeadbeef);
6015 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
6016 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
6018 SetLastError(0xdeadbeef);
6019 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
6020 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
6021 ok(!hwnd
, "CreateWindowEx should fail\n");
6022 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
6024 DestroyWindow(hwnd
);
6026 hmenu
= CreateMenu();
6028 SetLastError(0xdeadbeef);
6029 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
6030 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
6031 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
6032 expect_menu(hwnd
, hmenu
);
6033 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
6034 expect_ex_style(hwnd
, 0);
6035 DestroyWindow(hwnd
);
6036 SetLastError(0xdeadbeef);
6037 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
6038 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
6040 SetLastError(0xdeadbeef);
6041 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
6042 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
6043 ok(!hwnd
, "CreateWindowEx should fail\n");
6044 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
6046 DestroyWindow(hwnd
);
6048 hmenu
= CreateMenu();
6050 SetLastError(0xdeadbeef);
6051 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
6052 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
6053 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
6054 expect_menu(hwnd
, hmenu
);
6055 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
6056 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
6057 DestroyWindow(hwnd
);
6058 SetLastError(0xdeadbeef);
6059 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
6060 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
6062 /* test child window sizing */
6064 cls
.lpfnWndProc
= minmax_wnd_proc
;
6067 cls
.hInstance
= GetModuleHandleA(NULL
);
6069 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
6070 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
6071 cls
.lpszMenuName
= NULL
;
6072 cls
.lpszClassName
= "MinMax_WndClass";
6073 RegisterClassA(&cls
);
6075 SetLastError(0xdeadbeef);
6076 parent
= CreateWindowExA(0, "MinMax_WndClass", NULL
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
6077 0, 0, 100, 100, 0, 0, 0, NULL
);
6078 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
6079 expect_menu(parent
, 0);
6080 expect_style(parent
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
| WS_CLIPSIBLINGS
);
6081 expect_ex_style(parent
, WS_EX_WINDOWEDGE
);
6083 memset(&minmax
, 0, sizeof(minmax
));
6084 SendMessageA(parent
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
6085 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxSize
.x
, minmax
.ptMaxSize
.y
);
6086 ok(IsRectEmpty(&rc_minmax
), "ptMaxSize is not empty\n");
6087 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
6088 ok(IsRectEmpty(&rc_minmax
), "ptMaxTrackSize is not empty\n");
6090 GetWindowRect(parent
, &rc
);
6091 ok(!IsRectEmpty(&rc
), "parent window rect is empty\n");
6092 GetClientRect(parent
, &rc
);
6093 ok(!IsRectEmpty(&rc
), "parent client rect is empty\n");
6095 InflateRect(&rc
, 200, 200);
6097 SetLastError(0xdeadbeef);
6098 hwnd
= CreateWindowExA(0, "MinMax_WndClass", NULL
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
6099 rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
6100 parent
, (HMENU
)1, 0, NULL
);
6101 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
6102 expect_menu(hwnd
, 1);
6103 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
);
6104 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
6106 memset(&minmax
, 0, sizeof(minmax
));
6107 SendMessageA(hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
6108 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
6110 GetWindowRect(hwnd
, &rc
);
6111 OffsetRect(&rc
, -rc
.left
, -rc
.top
);
6112 ok(EqualRect(&rc
, &rc_minmax
), "rects don't match: %s and %s\n", wine_dbgstr_rect(&rc
),
6113 wine_dbgstr_rect(&rc_minmax
));
6114 DestroyWindow(hwnd
);
6116 cls
.lpfnWndProc
= winsizes_wnd_proc
;
6117 cls
.lpszClassName
= "Sizes_WndClass";
6118 RegisterClassA(&cls
);
6120 expected_cx
= expected_cy
= 200000;
6121 SetRect( &expected_rect
, 0, 0, 200000, 200000 );
6122 broken_rect
= expected_rect
;
6123 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 300000, 300000, 200000, 200000, parent
, 0, 0, NULL
);
6124 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6125 GetClientRect( hwnd
, &rc
);
6126 ok( rc
.right
== 200000 || rc
.right
== 65535 || broken(rc
.right
== (short)200000),
6127 "invalid rect right %u\n", rc
.right
);
6128 ok( rc
.bottom
== 200000 || rc
.bottom
== 65535 || broken(rc
.bottom
== (short)200000),
6129 "invalid rect bottom %u\n", rc
.bottom
);
6130 DestroyWindow(hwnd
);
6132 expected_cx
= expected_cy
= -10;
6133 SetRectEmpty(&expected_rect
);
6134 SetRect( &broken_rect
, 0, 0, -10, -10 );
6135 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -20, -20, -10, -10, parent
, 0, 0, NULL
);
6136 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6137 GetClientRect( hwnd
, &rc
);
6138 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
6139 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
6140 DestroyWindow(hwnd
);
6142 expected_cx
= expected_cy
= -200000;
6143 SetRectEmpty(&expected_rect
);
6144 SetRect( &broken_rect
, 0, 0, -200000, -200000 );
6145 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -300000, -300000, -200000, -200000, parent
, 0, 0, NULL
);
6146 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6147 GetClientRect( hwnd
, &rc
);
6148 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
6149 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
6150 DestroyWindow(hwnd
);
6152 /* we need a parent at 0,0 so that child coordinates match */
6153 DestroyWindow(parent
);
6154 parent
= CreateWindowExA(0, "MinMax_WndClass", NULL
, WS_POPUP
, 0, 0, 100, 100, 0, 0, 0, NULL
);
6155 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
6158 expected_cy
= 0x7fffffff;
6159 SetRect( &expected_rect
, 10, 10, 110, 0x7fffffff );
6160 SetRect( &broken_rect
, 10, 10, 110, 0x7fffffffU
+ 10 );
6161 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 10, 10, 100, 0x7fffffff, parent
, 0, 0, NULL
);
6162 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6163 GetClientRect( hwnd
, &rc
);
6164 ok( rc
.right
== 100, "invalid rect right %u\n", rc
.right
);
6165 ok( rc
.bottom
== 0x7fffffff - 10 || rc
.bottom
==65535 || broken(rc
.bottom
== 0),
6166 "invalid rect bottom %u\n", rc
.bottom
);
6167 DestroyWindow(hwnd
);
6169 expected_cx
= 0x7fffffff;
6170 expected_cy
= 0x7fffffff;
6171 SetRect( &expected_rect
, 20, 10, 0x7fffffff, 0x7fffffff );
6172 SetRect( &broken_rect
, 20, 10, 0x7fffffffU
+ 20, 0x7fffffffU
+ 10 );
6173 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 20, 10, 0x7fffffff, 0x7fffffff, parent
, 0, 0, NULL
);
6174 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6175 GetClientRect( hwnd
, &rc
);
6176 ok( rc
.right
== 0x7fffffff - 20 || rc
.right
== 65535 || broken(rc
.right
== 0),
6177 "invalid rect right %u\n", rc
.right
);
6178 ok( rc
.bottom
== 0x7fffffff - 10 || rc
.right
== 65535 || broken(rc
.bottom
== 0),
6179 "invalid rect bottom %u\n", rc
.bottom
);
6180 DestroyWindow(hwnd
);
6182 /* top level window */
6183 expected_cx
= expected_cy
= 200000;
6184 SetRect( &expected_rect
, 0, 0, GetSystemMetrics(SM_CXMAXTRACK
), GetSystemMetrics(SM_CYMAXTRACK
) );
6185 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_OVERLAPPEDWINDOW
, 300000, 300000, 200000, 200000, 0, 0, 0, NULL
);
6186 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6187 GetClientRect( hwnd
, &rc
);
6188 ok( rc
.right
<= expected_cx
, "invalid rect right %u\n", rc
.right
);
6189 ok( rc
.bottom
<= expected_cy
, "invalid rect bottom %u\n", rc
.bottom
);
6190 DestroyWindow(hwnd
);
6193 SetLastError(0xdeadbeef);
6194 hwnd
= CreateWindowExA(0, "INVALID_CLASS", NULL
, WS_CHILD
, 10, 10, 100, 100, parent
, 0, 0, NULL
);
6195 ok(hwnd
== 0, "CreateWindowEx succeeded\n");
6196 ok(GetLastError() == ERROR_CLASS_DOES_NOT_EXIST
|| GetLastError() == ERROR_CANNOT_FIND_WND_CLASS
,
6197 "invalid error %u\n", GetLastError());
6198 DestroyWindow(hwnd
);
6200 hdc
= GetDC( parent
);
6201 SetLayout( hdc
, LAYOUT_RTL
);
6202 if (GetLayout( hdc
))
6204 ReleaseDC( parent
, hdc
);
6205 DestroyWindow( parent
);
6206 SetLastError( 0xdeadbeef );
6207 parent
= CreateWindowExA(WS_EX_APPWINDOW
| WS_EX_LAYOUTRTL
, "static", NULL
, WS_POPUP
,
6208 0, 0, 100, 100, 0, 0, 0, NULL
);
6209 ok( parent
!= 0, "creation failed err %u\n", GetLastError());
6210 expect_ex_style( parent
, WS_EX_APPWINDOW
| WS_EX_LAYOUTRTL
);
6211 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 20, 20, parent
, 0, 0, NULL
);
6212 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6213 expect_ex_style( hwnd
, WS_EX_LAYOUTRTL
);
6214 DestroyWindow( hwnd
);
6215 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 20, 20, parent
, 0, 0, NULL
);
6216 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6217 expect_ex_style( hwnd
, 0 );
6218 DestroyWindow( hwnd
);
6219 SetWindowLongW( parent
, GWL_EXSTYLE
, WS_EX_APPWINDOW
| WS_EX_LAYOUTRTL
| WS_EX_NOINHERITLAYOUT
);
6220 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 20, 20, parent
, 0, 0, NULL
);
6221 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6222 expect_ex_style( hwnd
, 0 );
6223 DestroyWindow( hwnd
);
6225 if (pGetProcessDefaultLayout
&& pSetProcessDefaultLayout
)
6229 SetLastError( 0xdeadbeef );
6230 ok( !pGetProcessDefaultLayout( NULL
), "GetProcessDefaultLayout succeeded\n" );
6231 ok( GetLastError() == ERROR_NOACCESS
, "wrong error %u\n", GetLastError() );
6232 SetLastError( 0xdeadbeef );
6233 res
= pGetProcessDefaultLayout( &layout
);
6234 ok( res
, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
6235 ok( layout
== 0, "GetProcessDefaultLayout wrong layout %x\n", layout
);
6236 SetLastError( 0xdeadbeef );
6237 res
= pSetProcessDefaultLayout( 7 );
6238 ok( res
, "SetProcessDefaultLayout failed err %u\n", GetLastError ());
6239 res
= pGetProcessDefaultLayout( &layout
);
6240 ok( res
, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
6241 ok( layout
== 7, "GetProcessDefaultLayout wrong layout %x\n", layout
);
6242 SetLastError( 0xdeadbeef );
6243 res
= pSetProcessDefaultLayout( LAYOUT_RTL
);
6244 ok( res
, "SetProcessDefaultLayout failed err %u\n", GetLastError ());
6245 res
= pGetProcessDefaultLayout( &layout
);
6246 ok( res
, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
6247 ok( layout
== LAYOUT_RTL
, "GetProcessDefaultLayout wrong layout %x\n", layout
);
6248 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
6249 0, 0, 100, 100, 0, 0, 0, NULL
);
6250 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6251 expect_ex_style( hwnd
, WS_EX_APPWINDOW
| WS_EX_LAYOUTRTL
);
6252 DestroyWindow( hwnd
);
6253 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
6254 0, 0, 100, 100, parent
, 0, 0, NULL
);
6255 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6256 expect_ex_style( hwnd
, WS_EX_APPWINDOW
);
6257 DestroyWindow( hwnd
);
6258 pSetProcessDefaultLayout( 0 );
6260 else win_skip( "SetProcessDefaultLayout not supported\n" );
6262 else win_skip( "SetLayout not supported\n" );
6264 DestroyWindow(parent
);
6266 UnregisterClassA("MinMax_WndClass", GetModuleHandleA(NULL
));
6267 UnregisterClassA("Sizes_WndClass", GetModuleHandleA(NULL
));
6271 #undef expect_ex_style
6274 /* function that remembers whether the system the test is running on sets the
6275 * last error for user32 functions to make the tests stricter */
6276 static int check_error(DWORD actual
, DWORD expected
)
6278 static int sets_last_error
= -1;
6279 if (sets_last_error
== -1)
6280 sets_last_error
= (actual
!= 0xdeadbeef);
6281 return (!sets_last_error
&& (actual
== 0xdeadbeef)) || (actual
== expected
);
6284 static void test_set_window_long_size(void)
6287 WNDPROC wnd_proc
, wnd_proc_2
;
6292 /* It's not allowed to set or get 64-bit pointer values using 32-bit functions. */
6293 hwnd
= CreateWindowExA(0, "MainWindowClass", "Child window", WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_CHILD
|
6294 WS_MAXIMIZEBOX
| WS_VISIBLE
, 100, 100, 200, 200, hwndMain
, 0, GetModuleHandleA(NULL
), NULL
);
6295 ok(hwnd
!= NULL
, "Failed to create test window.\n");
6298 SetLastError(0xdeadbeef);
6299 wnd_proc
= (WNDPROC
)(LONG_PTR
)GetWindowLongA(hwnd
, GWLP_WNDPROC
);
6300 ok(!wnd_proc
&& GetLastError() == ERROR_INVALID_INDEX
, "Unexpected window proc.\n");
6302 wnd_proc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_WNDPROC
);
6303 ok(!!wnd_proc
, "Unexpected window proc.\n");
6305 SetLastError(0xdeadbeef);
6306 wnd_proc_2
= (WNDPROC
)(LONG_PTR
)SetWindowLongA(hwnd
, GWLP_WNDPROC
, 0xdeadbeef);
6307 ok(!wnd_proc_2
&& GetLastError() == ERROR_INVALID_INDEX
, "Unexpected window proc.\n");
6309 wnd_proc_2
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_WNDPROC
);
6310 ok(wnd_proc_2
== wnd_proc
, "Unexpected window proc.\n");
6312 SetLastError(0xdeadbeef);
6313 ret
= GetWindowWord(hwnd
, GWLP_WNDPROC
);
6314 ok(!ret
&& GetLastError() == ERROR_INVALID_INDEX
, "Unexpected return value.\n");
6317 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, ((LONG_PTR
)1 << 32) | 123);
6318 ret
= GetWindowLongA(hwnd
, GWLP_USERDATA
);
6319 ok(ret
== 123, "Unexpected user data %#x.\n", ret
);
6320 retval
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
6321 ok(retval
> 123, "Unexpected user data.\n");
6322 ret
= GetWindowWord(hwnd
, GWLP_USERDATA
);
6324 ok(ret
== 123, "Unexpected user data %#x.\n", ret
);
6325 ret
= SetWindowWord(hwnd
, GWLP_USERDATA
, 124);
6327 ok(ret
== 123, "Unexpected user data %#x.\n", ret
);
6328 ret
= GetWindowLongA(hwnd
, GWLP_USERDATA
);
6330 ok(ret
== 124, "Unexpected user data %#x.\n", ret
);
6331 retval
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
6333 ok(retval
== 124, "Unexpected user data.\n");
6335 SetWindowLongA(hwnd
, GWLP_USERDATA
, (1 << 16) | 123);
6336 ret
= GetWindowLongA(hwnd
, GWLP_USERDATA
);
6337 ok(ret
== ((1 << 16) | 123), "Unexpected user data %#x.\n", ret
);
6338 ret
= GetWindowWord(hwnd
, GWLP_USERDATA
);
6340 ok(ret
== 123, "Unexpected user data %#x.\n", ret
);
6342 ret
= SetWindowWord(hwnd
, GWLP_USERDATA
, 124);
6344 ok(ret
== 123, "Unexpected user data %#x.\n", ret
);
6345 ret
= GetWindowLongA(hwnd
, GWLP_USERDATA
);
6347 ok(ret
== ((1 << 16) | 124), "Unexpected user data %#x.\n", ret
);
6348 ret
= GetWindowWord(hwnd
, GWLP_USERDATA
);
6350 ok(ret
== 124, "Unexpected user data %#x.\n", ret
);
6353 ret
= SetWindowLongA(hwnd
, GWLP_ID
, 1);
6354 ok(!ret
, "Unexpected id %#x.\n", ret
);
6356 ret
= GetWindowLongA(hwnd
, GWLP_ID
);
6357 ok(ret
== 1, "Unexpected id %#x.\n", ret
);
6359 ret
= GetWindowLongW(hwnd
, GWLP_ID
);
6360 ok(ret
== 1, "Unexpected id %#x.\n", ret
);
6362 SetWindowLongPtrA(hwnd
, GWLP_ID
, ((LONG_PTR
)1 << 32) | 123);
6363 ret
= GetWindowLongA(hwnd
, GWLP_ID
);
6364 ok(ret
== 123, "Unexpected id %#x.\n", ret
);
6365 ret
= GetWindowLongW(hwnd
, GWLP_ID
);
6366 ok(ret
== 123, "Unexpected id %#x.\n", ret
);
6367 retval
= GetWindowLongPtrA(hwnd
, GWLP_ID
);
6368 ok(retval
> 123, "Unexpected id.\n");
6369 SetLastError(0xdeadbeef);
6370 ret
= GetWindowWord(hwnd
, GWLP_ID
);
6372 ok(!ret
&& GetLastError() == ERROR_INVALID_INDEX
, "Unexpected id %#x.\n", ret
);
6374 /* GWLP_HINSTANCE */
6375 retval
= GetWindowLongPtrA(hwnd
, GWLP_HINSTANCE
);
6376 ok(retval
== (LONG_PTR
)GetModuleHandleA(NULL
), "Unexpected instance %#lx.\n", retval
);
6378 SetLastError(0xdeadbeef);
6379 ret
= GetWindowLongA(hwnd
, GWLP_HINSTANCE
);
6380 ok(!ret
&& GetLastError() == ERROR_INVALID_INDEX
, "Unexpected instance %#x.\n", ret
);
6382 SetLastError(0xdeadbeef);
6383 ret
= GetWindowLongW(hwnd
, GWLP_HINSTANCE
);
6384 ok(!ret
&& GetLastError() == ERROR_INVALID_INDEX
, "Unexpected instance %#x.\n", ret
);
6386 SetLastError(0xdeadbeef);
6387 ret
= GetWindowWord(hwnd
, GWLP_HINSTANCE
);
6389 ok(!ret
&& GetLastError() == ERROR_INVALID_INDEX
, "Unexpected instance %#x.\n", ret
);
6391 SetLastError(0xdeadbeef);
6392 ret
= SetWindowLongA(hwnd
, GWLP_HINSTANCE
, 1);
6393 ok(!ret
&& GetLastError() == ERROR_INVALID_INDEX
, "Unexpected instance %#x.\n", ret
);
6395 SetLastError(0xdeadbeef);
6396 ret
= SetWindowLongW(hwnd
, GWLP_HINSTANCE
, 1);
6397 ok(!ret
&& GetLastError() == ERROR_INVALID_INDEX
, "Unexpected instance %#x.\n", ret
);
6399 /* GWLP_HWNDPARENT */
6400 SetLastError(0xdeadbeef);
6401 ret
= GetWindowLongA(hwnd
, GWLP_HWNDPARENT
);
6402 ok(!ret
&& GetLastError() == ERROR_INVALID_INDEX
, "Unexpected parent window %#x.\n", ret
);
6404 SetLastError(0xdeadbeef);
6405 ret
= SetWindowLongA(hwnd
, GWLP_HWNDPARENT
, 0);
6406 ok(!ret
&& GetLastError() == ERROR_INVALID_INDEX
, "Unexpected parent window %#x.\n", ret
);
6408 SetLastError(0xdeadbeef);
6409 ret
= SetWindowLongW(hwnd
, GWLP_HWNDPARENT
, 0);
6410 ok(!ret
&& GetLastError() == ERROR_INVALID_INDEX
, "Unexpected parent window %#x.\n", ret
);
6412 SetLastError(0xdeadbeef);
6413 ret
= GetWindowWord(hwnd
, GWLP_HWNDPARENT
);
6415 ok(!ret
&& GetLastError() == ERROR_INVALID_INDEX
, "Unexpected parent window %#x.\n", ret
);
6417 DestroyWindow(hwnd
);
6421 static void test_set_window_word_size(void)
6423 WNDPROC wnd_proc
, wnd_proc_2
;
6428 /* It's not allowed to set or get 64-bit pointer values using 32-bit functions. */
6429 hwnd
= CreateWindowExA(0, "MainWindowClass", "Child window", WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_CHILD
|
6430 WS_MAXIMIZEBOX
| WS_VISIBLE
, 100, 100, 200, 200, hwndMain
, 0, GetModuleHandleA(NULL
), NULL
);
6431 ok(hwnd
!= NULL
, "Failed to create test window.\n");
6434 wnd_proc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_WNDPROC
);
6435 ok(!!wnd_proc
, "Unexpected window proc.\n");
6437 SetLastError(0xdeadbeef);
6438 ret
= GetWindowWord(hwnd
, GWLP_WNDPROC
);
6439 ok(!ret
&& GetLastError() == ERROR_INVALID_INDEX
, "Unexpected window proc.\n");
6441 SetLastError(0xdeadbeef);
6442 ret
= SetWindowWord(hwnd
, GWLP_WNDPROC
, 0xbeef);
6443 ok(!ret
&& GetLastError() == ERROR_INVALID_INDEX
, "Unexpected window proc.\n");
6445 wnd_proc_2
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_WNDPROC
);
6446 ok(wnd_proc_2
== wnd_proc
, "Unexpected window proc.\n");
6449 ret
= SetWindowLongA(hwnd
, GWLP_USERDATA
, (1 << 16) | 123);
6450 ok(!ret
, "Unexpected user data %#x.\n", ret
);
6451 ret
= GetWindowLongA(hwnd
, GWLP_USERDATA
);
6452 ok(ret
> 123, "Unexpected user data %#x.\n", ret
);
6453 ret
= GetWindowWord(hwnd
, GWLP_USERDATA
);
6455 ok(ret
== 123, "Unexpected user data %#x.\n", ret
);
6456 ret
= SetWindowWord(hwnd
, GWLP_USERDATA
, 124);
6458 ok(ret
== 123, "Unexpected user data %#x.\n", ret
);
6459 ret
= GetWindowWord(hwnd
, GWLP_USERDATA
);
6461 ok(ret
== 124, "Unexpected user data %#x.\n", ret
);
6462 ret
= GetWindowLongA(hwnd
, GWLP_USERDATA
);
6464 ok(ret
== ((1 << 16) | 124), "Unexpected user data %#x.\n", ret
);
6467 ret
= SetWindowLongA(hwnd
, GWLP_ID
, 1);
6468 ok(!ret
, "Unexpected id %#x.\n", ret
);
6469 ret
= GetWindowLongA(hwnd
, GWLP_ID
);
6470 ok(ret
== 1, "Unexpected id %#x.\n", ret
);
6472 SetLastError(0xdeadbeef);
6473 ret
= GetWindowWord(hwnd
, GWLP_ID
);
6475 ok(!ret
&& GetLastError() == ERROR_INVALID_INDEX
, "Unexpected id %#x.\n", ret
);
6476 SetLastError(0xdeadbeef);
6477 ret
= SetWindowWord(hwnd
, GWLP_ID
, 2);
6479 ok(!ret
&& GetLastError() == ERROR_INVALID_INDEX
, "Unexpected id %#x.\n", ret
);
6481 /* GWLP_HINSTANCE */
6482 retval
= GetWindowLongPtrA(hwnd
, GWLP_HINSTANCE
);
6483 ok(retval
== (LONG_PTR
)GetModuleHandleA(NULL
), "Unexpected instance %#lx.\n", retval
);
6485 SetLastError(0xdeadbeef);
6486 ret
= GetWindowWord(hwnd
, GWLP_HINSTANCE
);
6488 ok(!ret
&& GetLastError() == ERROR_INVALID_INDEX
, "Unexpected instance %#x.\n", ret
);
6490 SetLastError(0xdeadbeef);
6491 ret
= SetWindowWord(hwnd
, GWLP_HINSTANCE
, 0xdead);
6493 ok(!ret
&& GetLastError() == ERROR_INVALID_INDEX
, "Unexpected instance %#x.\n", ret
);
6495 /* GWLP_HWNDPARENT */
6496 retval
= GetWindowLongPtrA(hwnd
, GWLP_HWNDPARENT
);
6497 ok(!!retval
, "Unexpected parent window %#x.\n", ret
);
6499 SetLastError(0xdeadbeef);
6500 ret
= GetWindowWord(hwnd
, GWLP_HWNDPARENT
);
6502 ok(!ret
&& GetLastError() == ERROR_INVALID_INDEX
, "Unexpected parent window %#x.\n", ret
);
6504 DestroyWindow(hwnd
);
6507 static void test_SetWindowLong(void)
6510 WNDPROC old_window_procW
;
6512 SetLastError(0xdeadbeef);
6513 retval
= SetWindowLongPtrA(NULL
, GWLP_WNDPROC
, 0);
6514 ok(!retval
, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval
);
6515 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE
),
6516 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instead of %d\n", GetLastError());
6518 SetLastError(0xdeadbeef);
6519 retval
= SetWindowLongPtrA(hwndMain
, 0xdeadbeef, 0);
6520 ok(!retval
, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval
);
6521 ok(check_error(GetLastError(), ERROR_INVALID_INDEX
),
6522 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instead of %d\n", GetLastError());
6524 SetLastError(0xdeadbeef);
6525 retval
= SetWindowLongPtrA(hwndMain
, GWLP_WNDPROC
, 0);
6526 ok((WNDPROC
)retval
== main_window_procA
,
6527 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval
);
6528 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
6529 retval
= GetWindowLongPtrA(hwndMain
, GWLP_WNDPROC
);
6530 ok((WNDPROC
)retval
== main_window_procA
,
6531 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
6532 ok(!IsWindowUnicode(hwndMain
), "hwndMain shouldn't be Unicode\n");
6534 old_window_procW
= (WNDPROC
)GetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
);
6535 SetLastError(0xdeadbeef);
6536 retval
= SetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
, 0);
6537 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED
)
6539 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
6540 ok(retval
!= 0, "SetWindowLongPtr error %d\n", GetLastError());
6541 ok((WNDPROC
)retval
== old_window_procW
,
6542 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
6543 ok(IsWindowUnicode(hwndMain
), "hwndMain should now be Unicode\n");
6545 /* set it back to ANSI */
6546 SetWindowLongPtrA(hwndMain
, GWLP_WNDPROC
, 0);
6549 test_set_window_long_size();
6550 test_set_window_word_size();
6553 static LRESULT WINAPI
check_style_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
6555 const STYLESTRUCT
*expected
= (STYLESTRUCT
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
6556 const STYLESTRUCT
*got
= (STYLESTRUCT
*)lParam
;
6558 if (message
== WM_STYLECHANGING
&& wParam
== GWL_STYLE
)
6560 ok(got
->styleOld
== expected
[0].styleOld
, "expected old style %#x, got %#x\n",
6561 expected
[0].styleOld
, got
->styleOld
);
6562 ok(got
->styleNew
== expected
[0].styleNew
, "expected new style %#x, got %#x\n",
6563 expected
[0].styleNew
, got
->styleNew
);
6565 else if (message
== WM_STYLECHANGED
&& wParam
== GWL_STYLE
)
6567 ok(got
->styleOld
== expected
[1].styleOld
, "expected old style %#x, got %#x\n",
6568 expected
[1].styleOld
, got
->styleOld
);
6569 ok(got
->styleNew
== expected
[1].styleNew
, "expected new style %#x, got %#x\n",
6570 expected
[1].styleNew
, got
->styleNew
);
6573 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
6576 static void test_set_window_style(void)
6578 LONG expected_style
, new_style
, old_style
;
6579 STYLESTRUCT expected_stylestruct
[2];
6586 LONG creation_style
;
6591 { WS_MINIMIZE
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
,
6592 WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
},
6593 { WS_MINIMIZE
| WS_CLIPSIBLINGS
| WS_CAPTION
,
6594 WS_CLIPSIBLINGS
| WS_CAPTION
},
6595 { WS_MAXIMIZE
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
,
6596 WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
},
6597 { WS_MAXIMIZE
| WS_CLIPSIBLINGS
| WS_CAPTION
,
6598 WS_CLIPSIBLINGS
| WS_CAPTION
},
6599 { WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
,
6600 WS_MINIMIZE
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
},
6601 { WS_CLIPSIBLINGS
| WS_CAPTION
,
6602 WS_MINIMIZE
| WS_CLIPSIBLINGS
| WS_CAPTION
},
6603 { WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
,
6604 WS_MAXIMIZE
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
},
6605 { WS_CLIPSIBLINGS
| WS_CAPTION
,
6606 WS_MAXIMIZE
| WS_CLIPSIBLINGS
| WS_CAPTION
},
6609 memset(&cls
, 0, sizeof(cls
));
6610 cls
.lpfnWndProc
= check_style_wnd_proc
;
6611 cls
.hInstance
= GetModuleHandleA(0);
6612 cls
.lpszClassName
= "TestSetWindowStylesClass";
6613 ok(RegisterClassA(&cls
), "RegisterClass failed\n");
6615 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
6617 expected_style
= tests
[i
].style
;
6618 if (tests
[i
].creation_style
& WS_MINIMIZE
)
6619 expected_style
|= WS_MINIMIZE
;
6621 expected_stylestruct
[0].styleOld
= tests
[i
].creation_style
;
6622 expected_stylestruct
[0].styleNew
= tests
[i
].style
;
6623 expected_stylestruct
[1].styleOld
= tests
[i
].creation_style
;
6624 expected_stylestruct
[1].styleNew
= expected_style
;
6626 hwnd
= CreateWindowA(cls
.lpszClassName
, "Test set styles",
6627 tests
[i
].creation_style
, 100, 100, 200, 200, 0, 0, 0, NULL
);
6628 ok(hwnd
!= 0, "CreateWindow failed\n");
6629 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)&expected_stylestruct
);
6631 old_style
= SetWindowLongA(hwnd
, GWL_STYLE
, tests
[i
].style
);
6632 ok(old_style
== tests
[i
].creation_style
, "expected old style %#x, got %#x\n",
6633 tests
[i
].creation_style
, old_style
);
6634 new_style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6635 ok(new_style
== expected_style
, "expected new style %#x, got %#x\n",
6636 expected_style
, new_style
);
6638 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0);
6639 DestroyWindow(hwnd
);
6642 UnregisterClassA(cls
.lpszClassName
, cls
.hInstance
);
6645 static void test_ShowWindow(void)
6649 RECT rcMain
, rc
, rcMinimized
, rcClient
, rcEmpty
, rcMaximized
, rcResized
, rcNonClient
;
6651 MONITORINFO mon_info
;
6653 SetRect(&rcClient
, 0, 0, 90, 90);
6655 OffsetRect(&rcMain
, 120, 120);
6656 AdjustWindowRect(&rcMain
, WS_CAPTION
, 0);
6657 SetRect(&rcMinimized
, -32000, -32000, -32000 + GetSystemMetrics(SM_CXMINIMIZED
),
6658 -32000 + GetSystemMetrics(SM_CYMINIMIZED
));
6659 SetRectEmpty(&rcEmpty
);
6661 hwnd
= CreateWindowExA(0, "MainWindowClass", NULL
,
6662 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
6663 WS_MAXIMIZEBOX
| WS_POPUP
,
6664 rcMain
.left
, rcMain
.top
,
6665 rcMain
.right
- rcMain
.left
, rcMain
.bottom
- rcMain
.top
,
6669 mon_info
.cbSize
= sizeof(mon_info
);
6670 GetMonitorInfoW(MonitorFromWindow(hwnd
, MONITOR_DEFAULTTOPRIMARY
), &mon_info
);
6671 rcMaximized
= mon_info
.rcWork
;
6672 AdjustWindowRectEx(&rcMaximized
, GetWindowLongA(hwnd
, GWL_STYLE
) & ~WS_BORDER
,
6673 0, GetWindowLongA(hwnd
, GWL_EXSTYLE
));
6675 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6676 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
6677 ok(!(style
& WS_VISIBLE
), "window should not be visible\n");
6678 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
6679 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6680 GetWindowRect(hwnd
, &rc
);
6681 ok(EqualRect(&rcMain
, &rc
), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain
),
6682 wine_dbgstr_rect(&rc
));
6683 GetClientRect(hwnd
, &rc
);
6684 ok(EqualRect(&rcClient
, &rc
), "expected %s, got %s\n",
6685 wine_dbgstr_rect(&rcClient
), wine_dbgstr_rect(&rc
));
6687 ret
= ShowWindow(hwnd
, SW_SHOW
);
6688 ok(!ret
, "not expected ret: %lu\n", ret
);
6689 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6690 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
6691 ok(style
& WS_VISIBLE
, "window should be visible\n");
6692 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
6693 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6694 GetWindowRect(hwnd
, &rc
);
6695 ok(EqualRect(&rcMain
, &rc
), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain
),
6696 wine_dbgstr_rect(&rc
));
6697 GetClientRect(hwnd
, &rc
);
6698 ok(EqualRect(&rcClient
, &rc
), "expected %s, got %s\n",
6699 wine_dbgstr_rect(&rcClient
), wine_dbgstr_rect(&rc
));
6701 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
6702 ok(ret
, "not expected ret: %lu\n", ret
);
6703 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6704 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
6705 ok(style
& WS_VISIBLE
, "window should be visible\n");
6706 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
6707 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6708 GetWindowRect(hwnd
, &rc
);
6709 ok(EqualRect(&rcMinimized
, &rc
), "expected %s, got %s\n",
6710 wine_dbgstr_rect(&rcMinimized
), wine_dbgstr_rect(&rc
));
6711 GetClientRect(hwnd
, &rc
);
6712 ok(EqualRect(&rcEmpty
, &rc
), "expected %s, got %s\n",
6713 wine_dbgstr_rect(&rcEmpty
), wine_dbgstr_rect(&rc
));
6714 /* shouldn't be able to resize minimized windows */
6715 ret
= SetWindowPos(hwnd
, 0, 0, 0,
6716 (rcMinimized
.right
- rcMinimized
.left
) * 2,
6717 (rcMinimized
.bottom
- rcMinimized
.top
) * 2,
6718 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
6719 ok(ret
, "not expected ret: %lu\n", ret
);
6720 GetWindowRect(hwnd
, &rc
);
6721 ok(EqualRect(&rcMinimized
, &rc
), "expected %s, got %s\n",
6722 wine_dbgstr_rect(&rcMinimized
), wine_dbgstr_rect(&rc
));
6723 GetClientRect(hwnd
, &rc
);
6724 ok(EqualRect(&rcEmpty
, &rc
), "expected %s, got %s\n",
6725 wine_dbgstr_rect(&rcEmpty
), wine_dbgstr_rect(&rc
));
6726 /* SetWindowPos shouldn't affect the client rect */
6727 ret
= SetWindowPos(hwnd
, 0, 0, 0, 0, 0,
6728 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
6729 ok(ret
, "not expected ret: %lu\n", ret
);
6730 GetWindowRect(hwnd
, &rc
);
6731 ok(EqualRect(&rcMinimized
, &rc
), "expected %s, got %s\n",
6732 wine_dbgstr_rect(&rcMinimized
), wine_dbgstr_rect(&rc
));
6733 GetClientRect(hwnd
, &rc
);
6734 ok(EqualRect(&rcEmpty
, &rc
), "expected %s, got %s\n",
6735 wine_dbgstr_rect(&rcEmpty
), wine_dbgstr_rect(&rc
));
6737 GetWindowRect(hwnd
, &rc
);
6738 SetRect(&rcNonClient
, rc
.left
, rc
.top
, rc
.left
, rc
.top
);
6739 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
6740 ok(EqualRect(&rc
, &rcNonClient
), "expected %s, got %s\n",
6741 wine_dbgstr_rect(&rcNonClient
), wine_dbgstr_rect(&rc
));
6743 ShowWindow(hwnd
, SW_RESTORE
);
6744 ok(ret
, "not expected ret: %lu\n", ret
);
6745 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6746 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
6747 ok(style
& WS_VISIBLE
, "window should be visible\n");
6748 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
6749 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6750 GetWindowRect(hwnd
, &rc
);
6751 ok(EqualRect(&rcMain
, &rc
), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain
),
6752 wine_dbgstr_rect(&rc
));
6753 GetClientRect(hwnd
, &rc
);
6754 ok(EqualRect(&rcClient
, &rc
), "expected %s, got %s\n",
6755 wine_dbgstr_rect(&rcClient
), wine_dbgstr_rect(&rc
));
6757 ShowWindow(hwnd
, SW_MAXIMIZE
);
6758 ok(ret
, "not expected ret: %lu\n", ret
);
6759 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6760 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
6761 ok(style
& WS_VISIBLE
, "window should be visible\n");
6762 ok(!(style
& WS_MINIMIZE
), "window should be minimized\n");
6763 ok(style
& WS_MAXIMIZE
, "window should not be maximized\n");
6764 GetWindowRect(hwnd
, &rc
);
6765 ok(EqualRect(&rcMaximized
, &rc
), "expected %s, got %s\n",
6766 wine_dbgstr_rect(&rcMaximized
), wine_dbgstr_rect(&rc
));
6767 /* maximized windows can be resized */
6768 ret
= SetWindowPos(hwnd
, 0, 300, 300, 200, 200, SWP_NOACTIVATE
| SWP_NOZORDER
);
6769 ok(ret
, "not expected ret: %lu\n", ret
);
6770 SetRect(&rcResized
, 300, 300, 500, 500);
6771 GetWindowRect(hwnd
, &rc
);
6772 ok(EqualRect(&rcResized
, &rc
), "expected %s, got %s\n",
6773 wine_dbgstr_rect(&rcResized
), wine_dbgstr_rect(&rc
));
6775 ShowWindow(hwnd
, SW_RESTORE
);
6776 ok(ret
, "not expected ret: %lu\n", ret
);
6777 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6778 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
6779 ok(style
& WS_VISIBLE
, "window should be visible\n");
6780 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
6781 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6782 GetWindowRect(hwnd
, &rc
);
6783 ok(EqualRect(&rcMain
, &rc
), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain
),
6784 wine_dbgstr_rect(&rc
));
6786 ret
= EnableWindow(hwnd
, FALSE
);
6787 ok(!ret
, "not expected ret: %lu\n", ret
);
6788 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6789 ok(style
& WS_DISABLED
, "window should be disabled\n");
6791 ret
= DefWindowProcA(hwnd
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
6792 ok(!ret
, "not expected ret: %lu\n", ret
);
6793 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6794 ok(style
& WS_DISABLED
, "window should be disabled\n");
6795 ok(style
& WS_VISIBLE
, "window should be visible\n");
6796 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
6797 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6798 GetWindowRect(hwnd
, &rc
);
6799 ok(EqualRect(&rcMain
, &rc
), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain
),
6800 wine_dbgstr_rect(&rc
));
6801 GetClientRect(hwnd
, &rc
);
6802 ok(EqualRect(&rcClient
, &rc
), "expected %s, got %s\n",
6803 wine_dbgstr_rect(&rcClient
), wine_dbgstr_rect(&rc
));
6805 ret
= DefWindowProcA(hwnd
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
6806 ok(!ret
, "not expected ret: %lu\n", ret
);
6807 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6808 ok(style
& WS_DISABLED
, "window should be disabled\n");
6809 ok(style
& WS_VISIBLE
, "window should be visible\n");
6810 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
6811 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6812 GetWindowRect(hwnd
, &rc
);
6813 ok(EqualRect(&rcMain
, &rc
), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain
),
6814 wine_dbgstr_rect(&rc
));
6815 GetClientRect(hwnd
, &rc
);
6816 ok(EqualRect(&rcClient
, &rc
), "expected %s, got %s\n",
6817 wine_dbgstr_rect(&rcClient
), wine_dbgstr_rect(&rc
));
6819 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
6820 ok(ret
, "not expected ret: %lu\n", ret
);
6821 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6822 ok(style
& WS_DISABLED
, "window should be disabled\n");
6823 ok(style
& WS_VISIBLE
, "window should be visible\n");
6824 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
6825 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6826 GetWindowRect(hwnd
, &rc
);
6827 ok(EqualRect(&rcMinimized
, &rc
), "expected %s, got %s\n",
6828 wine_dbgstr_rect(&rcMinimized
), wine_dbgstr_rect(&rc
));
6829 GetClientRect(hwnd
, &rc
);
6830 ok(EqualRect(&rcEmpty
, &rc
), "expected %s, got %s\n",
6831 wine_dbgstr_rect(&rcEmpty
), wine_dbgstr_rect(&rc
));
6833 ret
= DefWindowProcA(hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
6834 ok(!ret
, "not expected ret: %lu\n", ret
);
6835 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6836 ok(style
& WS_DISABLED
, "window should be disabled\n");
6837 ok(style
& WS_VISIBLE
, "window should be visible\n");
6838 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
6839 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6840 GetWindowRect(hwnd
, &rc
);
6841 ok(EqualRect(&rcMinimized
, &rc
), "expected %s, got %s\n",
6842 wine_dbgstr_rect(&rcMinimized
), wine_dbgstr_rect(&rc
));
6843 GetClientRect(hwnd
, &rc
);
6844 ok(EqualRect(&rcEmpty
, &rc
), "expected %s, got %s\n",
6845 wine_dbgstr_rect(&rcEmpty
), wine_dbgstr_rect(&rc
));
6847 ret
= ShowWindow(hwnd
, SW_RESTORE
);
6848 ok(ret
, "not expected ret: %lu\n", ret
);
6849 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6850 ok(style
& WS_DISABLED
, "window should be disabled\n");
6851 ok(style
& WS_VISIBLE
, "window should be visible\n");
6852 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
6853 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6854 GetWindowRect(hwnd
, &rc
);
6855 ok(EqualRect(&rcMain
, &rc
), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain
),
6856 wine_dbgstr_rect(&rc
));
6857 GetClientRect(hwnd
, &rc
);
6858 ok(EqualRect(&rcClient
, &rc
), "expected %s, got %s\n",
6859 wine_dbgstr_rect(&rcClient
), wine_dbgstr_rect(&rc
));
6861 ret
= DefWindowProcA(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
6862 ok(!ret
, "not expected ret: %lu\n", ret
);
6863 ok(IsWindow(hwnd
), "window should exist\n");
6865 ret
= EnableWindow(hwnd
, TRUE
);
6866 ok(ret
, "not expected ret: %lu\n", ret
);
6868 ret
= DefWindowProcA(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
6869 ok(!ret
, "not expected ret: %lu\n", ret
);
6870 ok(!IsWindow(hwnd
), "window should not exist\n");
6872 hwnd
= CreateWindowExA(0, "MainWindowClass", NULL
,
6873 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
6874 WS_MAXIMIZEBOX
| WS_POPUP
| WS_MINIMIZE
,
6875 rcMain
.left
, rcMain
.top
,
6876 rcMain
.right
- rcMain
.left
, rcMain
.bottom
- rcMain
.top
,
6878 ok(hwnd
!= NULL
, "failed to create window with error %u\n", GetLastError());
6879 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6880 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
6881 GetWindowRect(hwnd
, &rc
);
6883 ok(EqualRect(&rcMinimized
, &rc
), "expected %s, got %s\n",
6884 wine_dbgstr_rect(&rcMinimized
), wine_dbgstr_rect(&rc
));
6885 GetClientRect(hwnd
, &rc
);
6886 ok(EqualRect(&rcEmpty
, &rc
), "expected %s, got %s\n",
6887 wine_dbgstr_rect(&rcEmpty
), wine_dbgstr_rect(&rc
));
6888 DestroyWindow(hwnd
);
6890 hwnd
= CreateWindowExA(0, "MainWindowClass", NULL
,
6891 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
6892 WS_MAXIMIZEBOX
| WS_POPUP
| WS_MINIMIZE
| WS_VISIBLE
,
6893 rcMain
.left
, rcMain
.top
,
6894 rcMain
.right
- rcMain
.left
, rcMain
.bottom
- rcMain
.top
,
6896 ok(hwnd
!= NULL
, "failed to create window with error %u\n", GetLastError());
6897 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6898 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
6899 GetWindowRect(hwnd
, &rc
);
6900 ok(EqualRect(&rcMinimized
, &rc
), "expected %s, got %s\n",
6901 wine_dbgstr_rect(&rcMinimized
), wine_dbgstr_rect(&rc
));
6902 GetClientRect(hwnd
, &rc
);
6903 ok(EqualRect(&rcEmpty
, &rc
), "expected %s, got %s\n",
6904 wine_dbgstr_rect(&rcEmpty
), wine_dbgstr_rect(&rc
));
6905 DestroyWindow(hwnd
);
6910 static void test_ShowWindow_owned(HWND hwndMain
)
6912 MONITORINFO mon_info
= {sizeof(mon_info
)};
6913 RECT rect
, orig
, expect
, nc
;
6918 GetMonitorInfoW(MonitorFromWindow(hwndMain
, MONITOR_DEFAULTTOPRIMARY
), &mon_info
);
6919 SetRect(&orig
, 20, 20, 210, 110);
6920 hwnd
= CreateWindowA("MainWindowClass", "owned", WS_CAPTION
| WS_SYSMENU
|
6921 WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
,
6922 orig
.left
, orig
.top
, orig
.right
- orig
.left
,
6923 orig
.bottom
- orig
.top
, hwndMain
, 0, 0, NULL
);
6924 ok(!!hwnd
, "failed to create window, error %u\n", GetLastError());
6925 hwnd2
= CreateWindowA("MainWindowClass", "owned2", WS_CAPTION
| WS_SYSMENU
|
6926 WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_VISIBLE
,
6927 orig
.left
, orig
.top
, orig
.right
- orig
.left
,
6928 orig
.bottom
- orig
.top
, hwndMain
, 0, 0, NULL
);
6929 ok(!!hwnd2
, "failed to create window, error %u\n", GetLastError());
6931 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6932 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
6933 ok(!(style
& WS_VISIBLE
), "window should not be visible\n");
6934 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
6935 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6936 GetWindowRect(hwnd
, &rect
);
6937 ok(EqualRect(&orig
, &rect
), "expected %s, got %s\n",
6938 wine_dbgstr_rect(&orig
), wine_dbgstr_rect(&rect
));
6940 ret
= ShowWindow(hwnd
, SW_SHOW
);
6941 ok(!ret
, "wrong ret %d\n", ret
);
6942 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6943 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
6944 ok(style
& WS_VISIBLE
, "window should be visible\n");
6945 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
6946 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6947 GetWindowRect(hwnd
, &rect
);
6948 ok(EqualRect(&orig
, &rect
), "expected %s, got %s\n",
6949 wine_dbgstr_rect(&orig
), wine_dbgstr_rect(&rect
));
6951 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
6952 ok(ret
, "wrong ret %d\n", ret
);
6953 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6954 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
6955 ok(style
& WS_VISIBLE
, "window should be visible\n");
6956 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
6957 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6958 GetWindowRect(hwnd
, &rect
);
6959 SetRect(&expect
, 0, mon_info
.rcWork
.bottom
- GetSystemMetrics(SM_CYMINIMIZED
),
6960 GetSystemMetrics(SM_CXMINIMIZED
), mon_info
.rcWork
.bottom
);
6962 ok(EqualRect(&expect
, &rect
), "expected %s, got %s\n",
6963 wine_dbgstr_rect(&expect
), wine_dbgstr_rect(&rect
));
6964 /* shouldn't be able to resize minimized windows */
6965 ret
= SetWindowPos(hwnd
, 0, 0, 0, 200, 200, SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
6966 ok(ret
, "wrong ret %d\n", ret
);
6967 GetWindowRect(hwnd
, &rect
);
6969 ok(EqualRect(&expect
, &rect
), "expected %s, got %s\n",
6970 wine_dbgstr_rect(&expect
), wine_dbgstr_rect(&rect
));
6972 GetWindowRect(hwnd
, &rect
);
6973 SetRect(&nc
, rect
.left
, rect
.top
, rect
.left
, rect
.top
);
6974 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rect
);
6975 ok(EqualRect(&rect
, &nc
), "expected %s, got %s\n",
6976 wine_dbgstr_rect(&nc
), wine_dbgstr_rect(&rect
));
6978 /* multiple minimized owned windows stack next to each other (and eventually
6979 * on top of each other) */
6980 OffsetRect(&expect
, GetSystemMetrics(SM_CXMINIMIZED
), 0);
6981 ret
= ShowWindow(hwnd2
, SW_MINIMIZE
);
6982 ok(ret
, "wrong ret %d\n", ret
);
6983 style
= GetWindowLongA(hwnd2
, GWL_STYLE
);
6984 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
6985 ok(style
& WS_VISIBLE
, "window should be visible\n");
6986 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
6987 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6988 GetWindowRect(hwnd2
, &rect
);
6990 ok(EqualRect(&expect
, &rect
), "expected %s, got %s\n",
6991 wine_dbgstr_rect(&expect
), wine_dbgstr_rect(&rect
));
6993 ShowWindow(hwnd
, SW_RESTORE
);
6994 ok(ret
, "wrong ret %d\n", ret
);
6995 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6996 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
6997 ok(style
& WS_VISIBLE
, "window should be visible\n");
6998 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
6999 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
7000 GetWindowRect(hwnd
, &rect
);
7001 ok(EqualRect(&orig
, &rect
), "expected %s, got %s\n",
7002 wine_dbgstr_rect(&orig
), wine_dbgstr_rect(&rect
));
7004 ShowWindow(hwnd
, SW_MAXIMIZE
);
7005 ok(ret
, "wrong ret %d\n", ret
);
7006 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
7007 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
7008 ok(style
& WS_VISIBLE
, "window should be visible\n");
7009 ok(!(style
& WS_MINIMIZE
), "window should be minimized\n");
7010 ok(style
& WS_MAXIMIZE
, "window should not be maximized\n");
7011 GetWindowRect(hwnd
, &rect
);
7012 expect
= mon_info
.rcWork
;
7013 AdjustWindowRectEx(&expect
, GetWindowLongA(hwnd
, GWL_STYLE
) & ~WS_BORDER
,
7014 0, GetWindowLongA(hwnd
, GWL_EXSTYLE
));
7015 ok(EqualRect(&expect
, &rect
), "expected %s, got %s\n",
7016 wine_dbgstr_rect(&expect
), wine_dbgstr_rect(&rect
));
7017 /* maximized windows can be resized */
7018 ret
= SetWindowPos(hwnd
, 0, 300, 300, 200, 200, SWP_NOACTIVATE
| SWP_NOZORDER
);
7019 ok(ret
, "wrong ret %d\n", ret
);
7020 GetWindowRect(hwnd
, &rect
);
7021 SetRect(&expect
, 300, 300, 500, 500);
7022 ok(EqualRect(&expect
, &rect
), "expected %s, got %s\n",
7023 wine_dbgstr_rect(&expect
), wine_dbgstr_rect(&rect
));
7025 ShowWindow(hwnd
, SW_RESTORE
);
7026 ok(ret
, "wrong ret %d\n", ret
);
7027 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
7028 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
7029 ok(style
& WS_VISIBLE
, "window should be visible\n");
7030 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
7031 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
7032 GetWindowRect(hwnd
, &rect
);
7033 ok(EqualRect(&orig
, &rect
), "expected %s, got %s\n",
7034 wine_dbgstr_rect(&orig
), wine_dbgstr_rect(&rect
));
7036 DestroyWindow(hwnd2
);
7037 DestroyWindow(hwnd
);
7040 static void test_ShowWindow_child(HWND hwndMain
)
7042 RECT rect
, orig
, expect
, nc
;
7048 SetRect(&orig
, 20, 20, 210, 110);
7049 hwnd
= CreateWindowA("MainWindowClass", "child", WS_CAPTION
| WS_SYSMENU
|
7050 WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_CHILD
,
7051 orig
.left
, orig
.top
, orig
.right
- orig
.left
,
7052 orig
.bottom
- orig
.top
, hwndMain
, 0, 0, NULL
);
7053 ok(!!hwnd
, "failed to create window, error %u\n", GetLastError());
7054 hwnd2
= CreateWindowA("MainWindowClass", "child2", WS_CAPTION
| WS_SYSMENU
|
7055 WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_CHILD
| WS_VISIBLE
,
7056 orig
.left
, orig
.top
, orig
.right
- orig
.left
,
7057 orig
.bottom
- orig
.top
, hwndMain
, 0, 0, NULL
);
7058 ok(!!hwnd2
, "failed to create window, error %u\n", GetLastError());
7060 ClientToScreen(hwndMain
, &pt
);
7061 OffsetRect(&orig
, pt
.x
, pt
.y
);
7063 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
7064 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
7065 ok(!(style
& WS_VISIBLE
), "window should not be visible\n");
7066 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
7067 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
7068 GetWindowRect(hwnd
, &rect
);
7069 ok(EqualRect(&orig
, &rect
), "expected %s, got %s\n",
7070 wine_dbgstr_rect(&orig
), wine_dbgstr_rect(&rect
));
7072 ret
= ShowWindow(hwnd
, SW_SHOW
);
7073 ok(!ret
, "wrong ret %d\n", ret
);
7074 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
7075 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
7076 ok(style
& WS_VISIBLE
, "window should be visible\n");
7077 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
7078 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
7079 GetWindowRect(hwnd
, &rect
);
7080 ok(EqualRect(&orig
, &rect
), "expected %s, got %s\n",
7081 wine_dbgstr_rect(&orig
), wine_dbgstr_rect(&rect
));
7083 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
7084 ok(ret
, "wrong ret %d\n", ret
);
7085 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
7086 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
7087 ok(style
& WS_VISIBLE
, "window should be visible\n");
7088 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
7089 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
7090 GetWindowRect(hwnd
, &rect
);
7091 GetClientRect(hwndMain
, &expect
);
7092 SetRect(&expect
, 0, expect
.bottom
- GetSystemMetrics(SM_CYMINIMIZED
),
7093 GetSystemMetrics(SM_CXMINIMIZED
), expect
.bottom
);
7094 OffsetRect(&expect
, pt
.x
, pt
.y
);
7095 ok(EqualRect(&expect
, &rect
), "expected %s, got %s\n",
7096 wine_dbgstr_rect(&expect
), wine_dbgstr_rect(&rect
));
7097 /* shouldn't be able to resize minimized windows */
7098 ret
= SetWindowPos(hwnd
, 0, 0, 0, 200, 200, SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
7099 ok(ret
, "wrong ret %d\n", ret
);
7100 GetWindowRect(hwnd
, &rect
);
7101 ok(EqualRect(&expect
, &rect
), "expected %s, got %s\n",
7102 wine_dbgstr_rect(&expect
), wine_dbgstr_rect(&rect
));
7104 GetWindowRect(hwnd
, &rect
);
7105 SetRect(&nc
, rect
.left
, rect
.top
, rect
.left
, rect
.top
);
7106 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rect
);
7107 ok(EqualRect(&rect
, &nc
), "expected %s, got %s\n",
7108 wine_dbgstr_rect(&nc
), wine_dbgstr_rect(&rect
));
7110 /* multiple minimized children also stack; here the parent is too small to
7111 * fit more than one per row */
7112 OffsetRect(&expect
, 0, -GetSystemMetrics(SM_CYMINIMIZED
));
7113 ret
= ShowWindow(hwnd2
, SW_MINIMIZE
);
7114 ok(ret
, "wrong ret %d\n", ret
);
7115 style
= GetWindowLongA(hwnd2
, GWL_STYLE
);
7116 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
7117 ok(style
& WS_VISIBLE
, "window should be visible\n");
7118 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
7119 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
7120 GetWindowRect(hwnd2
, &rect
);
7121 ok(EqualRect(&expect
, &rect
), "expected %s, got %s\n",
7122 wine_dbgstr_rect(&expect
), wine_dbgstr_rect(&rect
));
7124 ShowWindow(hwnd
, SW_RESTORE
);
7125 ok(ret
, "wrong ret %d\n", ret
);
7126 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
7127 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
7128 ok(style
& WS_VISIBLE
, "window should be visible\n");
7129 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
7130 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
7131 GetWindowRect(hwnd
, &rect
);
7132 ok(EqualRect(&orig
, &rect
), "expected %s, got %s\n",
7133 wine_dbgstr_rect(&orig
), wine_dbgstr_rect(&rect
));
7135 ShowWindow(hwnd
, SW_MAXIMIZE
);
7136 ok(ret
, "wrong ret %d\n", ret
);
7137 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
7138 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
7139 ok(style
& WS_VISIBLE
, "window should be visible\n");
7140 ok(!(style
& WS_MINIMIZE
), "window should be minimized\n");
7141 ok(style
& WS_MAXIMIZE
, "window should not be maximized\n");
7142 GetWindowRect(hwnd
, &rect
);
7143 GetClientRect(hwndMain
, &expect
);
7144 AdjustWindowRectEx(&expect
, GetWindowLongA(hwnd
, GWL_STYLE
) & ~WS_BORDER
,
7145 0, GetWindowLongA(hwnd
, GWL_EXSTYLE
));
7146 OffsetRect(&expect
, pt
.x
, pt
.y
);
7147 ok(EqualRect(&expect
, &rect
), "expected %s, got %s\n",
7148 wine_dbgstr_rect(&expect
), wine_dbgstr_rect(&rect
));
7149 /* maximized windows can be resized */
7150 ret
= SetWindowPos(hwnd
, 0, 300, 300, 200, 200, SWP_NOACTIVATE
| SWP_NOZORDER
);
7151 ok(ret
, "wrong ret %d\n", ret
);
7152 GetWindowRect(hwnd
, &rect
);
7153 SetRect(&expect
, 300, 300, 500, 500);
7154 OffsetRect(&expect
, pt
.x
, pt
.y
);
7155 ok(EqualRect(&expect
, &rect
), "expected %s, got %s\n",
7156 wine_dbgstr_rect(&expect
), wine_dbgstr_rect(&rect
));
7158 ShowWindow(hwnd
, SW_RESTORE
);
7159 ok(ret
, "wrong ret %d\n", ret
);
7160 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
7161 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
7162 ok(style
& WS_VISIBLE
, "window should be visible\n");
7163 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
7164 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
7165 GetWindowRect(hwnd
, &rect
);
7166 ok(EqualRect(&orig
, &rect
), "expected %s, got %s\n",
7167 wine_dbgstr_rect(&orig
), wine_dbgstr_rect(&rect
));
7169 DestroyWindow(hwnd2
);
7170 DestroyWindow(hwnd
);
7173 static void test_ShowWindow_mdichild(HWND hwndMain
)
7175 RECT rect
, orig
, expect
, nc
;
7177 HWND mdiclient
, hwnd
, hwnd2
;
7180 CLIENTCREATESTRUCT mdi_client_cs
= {0,1};
7182 SetRect(&orig
, 20, 20, 210, 110);
7183 GetClientRect(hwndMain
, &rect
);
7184 mdiclient
= CreateWindowA("mdiclient", "MDI client", WS_CHILD
,
7185 rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
7186 hwndMain
, 0, 0, &mdi_client_cs
);
7187 ok(!!mdiclient
, "failed to create window, error %u\n", GetLastError());
7188 hwnd
= CreateWindowExA(WS_EX_MDICHILD
, "MainWindowClass", "MDI child",
7189 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
,
7190 orig
.left
, orig
.top
, orig
.right
- orig
.left
,
7191 orig
.bottom
- orig
.top
, mdiclient
, 0, 0, NULL
);
7192 ok(!!hwnd
, "failed to create window, error %u\n", GetLastError());
7193 hwnd2
= CreateWindowExA(WS_EX_MDICHILD
, "MainWindowClass", "MDI child 2",
7194 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
,
7195 orig
.left
, orig
.top
, orig
.right
- orig
.left
,
7196 orig
.bottom
- orig
.top
, mdiclient
, 0, 0, NULL
);
7197 ok(!!hwnd2
, "failed to create window, error %u\n", GetLastError());
7199 ClientToScreen(hwndMain
, &pt
);
7200 OffsetRect(&orig
, pt
.x
, pt
.y
);
7202 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
7203 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
7204 ok(style
& WS_VISIBLE
, "window should not be visible\n");
7205 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
7206 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
7207 GetWindowRect(hwnd
, &rect
);
7208 ok(EqualRect(&orig
, &rect
), "expected %s, got %s\n",
7209 wine_dbgstr_rect(&orig
), wine_dbgstr_rect(&rect
));
7211 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
7212 ok(ret
, "wrong ret %d\n", ret
);
7213 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
7214 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
7215 ok(style
& WS_VISIBLE
, "window should be visible\n");
7216 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
7217 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
7218 GetWindowRect(hwnd
, &rect
);
7219 GetClientRect(hwndMain
, &expect
);
7220 SetRect(&expect
, 0, expect
.bottom
- GetSystemMetrics(SM_CYMINIMIZED
),
7221 GetSystemMetrics(SM_CXMINIMIZED
), expect
.bottom
);
7222 OffsetRect(&expect
, pt
.x
, pt
.y
);
7223 ok(EqualRect(&expect
, &rect
), "expected %s, got %s\n",
7224 wine_dbgstr_rect(&expect
), wine_dbgstr_rect(&rect
));
7225 /* shouldn't be able to resize minimized windows */
7226 ret
= SetWindowPos(hwnd
, 0, 0, 0, 200, 200, SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
7227 ok(ret
, "wrong ret %d\n", ret
);
7228 GetWindowRect(hwnd
, &rect
);
7229 ok(EqualRect(&expect
, &rect
), "expected %s, got %s\n",
7230 wine_dbgstr_rect(&expect
), wine_dbgstr_rect(&rect
));
7232 GetWindowRect(hwnd
, &rect
);
7233 SetRect(&nc
, rect
.left
, rect
.top
, rect
.left
, rect
.top
);
7234 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rect
);
7235 ok(EqualRect(&rect
, &nc
), "expected %s, got %s\n",
7236 wine_dbgstr_rect(&nc
), wine_dbgstr_rect(&rect
));
7238 /* multiple minimized children also stack; here the parent is too small to
7239 * fit more than one per row */
7240 OffsetRect(&expect
, 0, -GetSystemMetrics(SM_CYMINIMIZED
));
7241 ret
= ShowWindow(hwnd2
, SW_MINIMIZE
);
7242 ok(ret
, "wrong ret %d\n", ret
);
7243 style
= GetWindowLongA(hwnd2
, GWL_STYLE
);
7244 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
7245 ok(style
& WS_VISIBLE
, "window should be visible\n");
7246 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
7247 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
7248 GetWindowRect(hwnd2
, &rect
);
7249 ok(EqualRect(&expect
, &rect
), "expected %s, got %s\n",
7250 wine_dbgstr_rect(&expect
), wine_dbgstr_rect(&rect
));
7252 ShowWindow(hwnd
, SW_RESTORE
);
7253 ok(ret
, "wrong ret %d\n", ret
);
7254 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
7255 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
7256 ok(style
& WS_VISIBLE
, "window should be visible\n");
7257 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
7258 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
7259 GetWindowRect(hwnd
, &rect
);
7260 ok(EqualRect(&orig
, &rect
), "expected %s, got %s\n",
7261 wine_dbgstr_rect(&orig
), wine_dbgstr_rect(&rect
));
7263 ShowWindow(hwnd
, SW_MAXIMIZE
);
7264 ok(ret
, "wrong ret %d\n", ret
);
7265 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
7266 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
7267 ok(style
& WS_VISIBLE
, "window should be visible\n");
7268 ok(!(style
& WS_MINIMIZE
), "window should be minimized\n");
7269 ok(style
& WS_MAXIMIZE
, "window should not be maximized\n");
7270 GetWindowRect(hwnd
, &rect
);
7271 GetClientRect(hwndMain
, &expect
);
7272 AdjustWindowRectEx(&expect
, GetWindowLongA(hwnd
, GWL_STYLE
) & ~WS_BORDER
,
7273 0, GetWindowLongA(hwnd
, GWL_EXSTYLE
));
7274 OffsetRect(&expect
, pt
.x
, pt
.y
);
7275 ok(EqualRect(&expect
, &rect
), "expected %s, got %s\n",
7276 wine_dbgstr_rect(&expect
), wine_dbgstr_rect(&rect
));
7277 /* maximized windows can be resized */
7278 ret
= SetWindowPos(hwnd
, 0, 300, 300, 200, 200, SWP_NOACTIVATE
| SWP_NOZORDER
);
7279 ok(ret
, "wrong ret %d\n", ret
);
7280 GetWindowRect(hwnd
, &rect
);
7281 SetRect(&expect
, 300, 300, 500, 500);
7282 OffsetRect(&expect
, pt
.x
, pt
.y
);
7283 ok(EqualRect(&expect
, &rect
), "expected %s, got %s\n",
7284 wine_dbgstr_rect(&expect
), wine_dbgstr_rect(&rect
));
7286 ShowWindow(hwnd
, SW_RESTORE
);
7287 ok(ret
, "wrong ret %d\n", ret
);
7288 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
7289 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
7290 ok(style
& WS_VISIBLE
, "window should be visible\n");
7291 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
7292 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
7293 GetWindowRect(hwnd
, &rect
);
7294 ok(EqualRect(&orig
, &rect
), "expected %s, got %s\n",
7295 wine_dbgstr_rect(&orig
), wine_dbgstr_rect(&rect
));
7297 DestroyWindow(hwnd2
);
7298 DestroyWindow(hwnd
);
7299 DestroyWindow(mdiclient
);
7302 static DWORD CALLBACK
enablewindow_thread(LPVOID arg
)
7305 EnableWindow(hwnd
, FALSE
);
7309 static LRESULT CALLBACK
enable_window_procA(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
7311 if (msg
== WM_CANCELMODE
)
7313 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
7316 static void test_EnableWindow(void)
7324 hwnd
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_OVERLAPPEDWINDOW
,
7325 0, 0, 100, 100, 0, 0, 0, NULL
);
7327 ok(IsWindowEnabled(hwnd
), "window should be enabled\n");
7331 EnableWindow(hwnd
, FALSE
);
7332 check_wnd_state(hwnd
, hwnd
, 0, 0);
7333 ok(!IsWindowEnabled(hwnd
), "window should not be enabled\n");
7337 check_wnd_state(hwnd
, hwnd
, 0, hwnd
);
7339 EnableWindow(hwnd
, TRUE
);
7341 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
7342 ok(IsWindowEnabled(hwnd
), "window should be enabled\n");
7344 /* test disabling from thread */
7345 hthread
= CreateThread(NULL
, 0, enablewindow_thread
, hwnd
, 0, &tid
);
7347 while (MsgWaitForMultipleObjects(1, &hthread
, FALSE
, INFINITE
, QS_SENDMESSAGE
) != WAIT_OBJECT_0
)
7349 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
))
7350 DispatchMessageA(&msg
);
7353 ok(!IsWindowEnabled(hwnd
), "window should not be enabled\n");
7354 check_active_state(hwnd
, hwnd
, hwnd
);
7355 ok(0 == GetCapture(), "GetCapture() = %p\n", GetCapture());
7357 CloseHandle(hthread
);
7358 DestroyWindow(hwnd
);
7360 /* test preventing release of capture */
7361 memset(&cls
, 0, sizeof(cls
));
7362 cls
.lpfnWndProc
= enable_window_procA
;
7363 cls
.hInstance
= GetModuleHandleA(0);
7364 cls
.lpszClassName
= "EnableWindowClass";
7365 ok(RegisterClassA(&cls
), "RegisterClass failed\n");
7367 hwnd
= CreateWindowExA(0, "EnableWindowClass", NULL
, WS_OVERLAPPEDWINDOW
,
7368 0, 0, 100, 100, 0, 0, 0, NULL
);
7373 EnableWindow(hwnd
, FALSE
);
7374 check_wnd_state(hwnd
, hwnd
, 0, hwnd
);
7376 DestroyWindow(hwnd
);
7379 static DWORD CALLBACK
gettext_msg_thread( LPVOID arg
)
7385 /* test GetWindowTextA */
7386 num_gettext_msgs
= 0;
7387 memset( buf
, 0, sizeof(buf
) );
7388 buf_len
= GetWindowTextA( hwnd
, buf
, sizeof(buf
) );
7389 ok( buf_len
!= 0, "expected a nonempty window text\n" );
7390 ok( !strcmp(buf
, "another_caption"), "got wrong window text '%s'\n", buf
);
7391 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
7396 static DWORD CALLBACK
settext_msg_thread( LPVOID arg
)
7401 /* test SetWindowTextA */
7402 num_settext_msgs
= 0;
7403 success
= SetWindowTextA( hwnd
, "thread_caption" );
7404 ok( success
, "SetWindowTextA failed\n" );
7405 ok( num_settext_msgs
== 1, "got %u WM_SETTEXT messages\n", num_settext_msgs
);
7410 static void test_gettext(void)
7412 static const WCHAR textW
[] = {'t','e','x','t'};
7413 DWORD tid
, num_msgs
;
7423 hwnd
= CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP
, 0, 0, 0, 0, 0, 0, 0, NULL
);
7424 ok( hwnd
!= 0, "CreateWindowExA error %d\n", GetLastError() );
7426 /* test GetWindowTextA */
7427 num_gettext_msgs
= 0;
7428 memset( buf
, 0, sizeof(buf
) );
7429 buf_len
= GetWindowTextA( hwnd
, buf
, sizeof(buf
) );
7430 ok( buf_len
!= 0, "expected a nonempty window text\n" );
7431 ok( !strcmp(buf
, "caption"), "got wrong window text '%s'\n", buf
);
7432 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
7434 /* other process window */
7436 buf_len
= GetWindowTextA( GetDesktopWindow(), buf
, sizeof(buf
) );
7437 ok( buf_len
== 0, "expected a nonempty window text\n" );
7438 ok( *buf
== 0, "got wrong window text '%s'\n", buf
);
7440 strcpy( buf
, "blah" );
7441 buf_len
= GetWindowTextA( GetDesktopWindow(), buf
, 0 );
7442 ok( buf_len
== 0, "expected a nonempty window text\n" );
7443 ok( !strcmp(buf
, "blah"), "got wrong window text '%s'\n", buf
);
7446 buf_len
= GetWindowTextW( GetDesktopWindow(), bufW
, 0 );
7447 ok( buf_len
== 0, "expected a nonempty window text\n" );
7448 ok( bufW
[0] == 0xcc, "got %x\n", bufW
[0] );
7450 g_wm_gettext_override
.enabled
= TRUE
;
7452 num_gettext_msgs
= 0;
7453 memset( buf
, 0xcc, sizeof(buf
) );
7454 g_wm_gettext_override
.buff
= buf
;
7455 buf_len
= GetWindowTextA( hwnd
, buf
, sizeof(buf
) );
7456 ok( buf_len
== 0, "got %d\n", buf_len
);
7457 ok( *buf
== 0, "got %x\n", *buf
);
7458 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
7460 num_gettext_msgs
= 0;
7461 strcpy( buf
, "blah" );
7462 g_wm_gettext_override
.buff
= buf
;
7463 buf_len
= GetWindowTextA( hwnd
, buf
, 0 );
7464 ok( buf_len
== 0, "got %d\n", buf_len
);
7465 ok( !strcmp(buf
, "blah"), "got %s\n", buf
);
7466 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
7468 g_wm_gettext_override
.enabled
= FALSE
;
7470 /* same for W window */
7471 hwnd2
= CreateWindowExW( 0, mainclassW
, NULL
, WS_POPUP
, 0, 0, 0, 0, 0, 0, 0, NULL
);
7472 ok( hwnd2
!= 0, "CreateWindowExA error %d\n", GetLastError() );
7474 g_wm_gettext_override
.enabled
= TRUE
;
7476 num_gettext_msgs
= 0;
7477 memset( bufW
, 0xcc, sizeof(bufW
) );
7478 g_wm_gettext_override
.buffW
= bufW
;
7479 buf_len
= GetWindowTextW( hwnd2
, bufW
, ARRAY_SIZE(bufW
));
7480 ok( buf_len
== 0, "got %d\n", buf_len
);
7481 ok( *bufW
== 0, "got %x\n", *bufW
);
7482 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
7484 num_gettext_msgs
= 0;
7485 memset( bufW
, 0xcc, sizeof(bufW
) );
7486 g_wm_gettext_override
.buffW
= bufW
;
7487 buf_len
= GetWindowTextW( hwnd2
, bufW
, 0 );
7488 ok( buf_len
== 0, "got %d\n", buf_len
);
7489 ok( *bufW
== 0xcccc, "got %x\n", *bufW
);
7490 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
7492 g_wm_gettext_override
.enabled
= FALSE
;
7494 DestroyWindow( hwnd2
);
7496 /* test WM_GETTEXT */
7497 num_gettext_msgs
= 0;
7498 memset( buf
, 0, sizeof(buf
) );
7499 r
= SendMessageA( hwnd
, WM_GETTEXT
, sizeof(buf
), (LONG_PTR
)buf
);
7500 ok( r
!= 0, "expected a nonempty window text\n" );
7501 ok( !strcmp(buf
, "caption"), "got wrong window text '%s'\n", buf
);
7502 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
7504 /* test SetWindowTextA */
7505 num_settext_msgs
= 0;
7506 success
= SetWindowTextA( hwnd
, "new_caption" );
7507 ok( success
, "SetWindowTextA failed\n" );
7508 ok( num_settext_msgs
== 1, "got %u WM_SETTEXT messages\n", num_settext_msgs
);
7510 num_gettext_msgs
= 0;
7511 memset( buf
, 0, sizeof(buf
) );
7512 buf_len
= GetWindowTextA( hwnd
, buf
, sizeof(buf
) );
7513 ok( buf_len
!= 0, "expected a nonempty window text\n" );
7514 ok( !strcmp(buf
, "new_caption"), "got wrong window text '%s'\n", buf
);
7515 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
7517 /* test WM_SETTEXT */
7518 num_settext_msgs
= 0;
7519 r
= SendMessageA( hwnd
, WM_SETTEXT
, 0, (ULONG_PTR
)"another_caption" );
7520 ok( r
!= 0, "WM_SETTEXT failed\n" );
7521 ok( num_settext_msgs
== 1, "got %u WM_SETTEXT messages\n", num_settext_msgs
);
7523 num_gettext_msgs
= 0;
7524 memset( buf
, 0, sizeof(buf
) );
7525 buf_len
= GetWindowTextA( hwnd
, buf
, sizeof(buf
) );
7526 ok( buf_len
!= 0, "expected a nonempty window text\n" );
7527 ok( !strcmp(buf
, "another_caption"), "got wrong window text '%s'\n", buf
);
7528 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
7530 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
))
7531 DispatchMessageA( &msg
);
7533 /* test interthread GetWindowTextA */
7535 thread
= CreateThread( NULL
, 0, gettext_msg_thread
, hwnd
, 0, &tid
);
7536 ok(thread
!= NULL
, "CreateThread failed, error %d\n", GetLastError());
7537 while (MsgWaitForMultipleObjects( 1, &thread
, FALSE
, INFINITE
, QS_SENDMESSAGE
) != WAIT_OBJECT_0
)
7539 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
))
7540 DispatchMessageA( &msg
);
7543 CloseHandle( thread
);
7544 ok( num_msgs
>= 1, "got %u wakeups from MsgWaitForMultipleObjects\n", num_msgs
);
7546 /* test interthread SetWindowText */
7548 thread
= CreateThread( NULL
, 0, settext_msg_thread
, hwnd
, 0, &tid
);
7549 ok(thread
!= NULL
, "CreateThread failed, error %d\n", GetLastError());
7550 while (MsgWaitForMultipleObjects( 1, &thread
, FALSE
, INFINITE
, QS_SENDMESSAGE
) != WAIT_OBJECT_0
)
7552 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
))
7553 DispatchMessageA( &msg
);
7556 CloseHandle( thread
);
7557 ok( num_msgs
>= 1, "got %u wakeups from MsgWaitForMultipleObjects\n", num_msgs
);
7559 num_gettext_msgs
= 0;
7560 memset( buf
, 0, sizeof(buf
) );
7561 buf_len
= GetWindowTextA( hwnd
, buf
, sizeof(buf
) );
7562 ok( buf_len
!= 0, "expected a nonempty window text\n" );
7563 ok( !strcmp(buf
, "thread_caption"), "got wrong window text '%s'\n", buf
);
7564 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
7566 /* WM_GETTEXT does not terminate returned string */
7567 memset( buf
, 0x1c, sizeof(buf
) );
7568 g_wm_gettext_override
.dont_terminate
= TRUE
;
7569 buf_len
= GetWindowTextA( hwnd
, buf
, sizeof(buf
) );
7570 ok( buf_len
== 4, "Unexpected text length, %d\n", buf_len
);
7571 ok( !memcmp(buf
, "text", 4), "Unexpected window text, '%s'\n", buf
);
7572 ok( buf
[4] == 0x1c, "Unexpected buffer contents\n" );
7573 g_wm_gettext_override
.dont_terminate
= FALSE
;
7575 memset( bufW
, 0x1c, sizeof(bufW
) );
7576 g_wm_gettext_override
.dont_terminate
= TRUE
;
7577 buf_len
= GetWindowTextW( hwnd
, bufW
, ARRAY_SIZE(bufW
));
7578 ok( buf_len
== 4, "Unexpected text length, %d\n", buf_len
);
7579 ok( !memcmp(bufW
, textW
, 4 * sizeof(WCHAR
)), "Unexpected window text, %s\n", wine_dbgstr_w(bufW
) );
7580 ok( bufW
[4] == 0, "Unexpected buffer contents, %#x\n", bufW
[4] );
7581 g_wm_gettext_override
.dont_terminate
= FALSE
;
7583 hwnd2
= CreateWindowExW( 0, mainclassW
, NULL
, WS_POPUP
, 0, 0, 0, 0, 0, 0, 0, NULL
);
7584 ok( hwnd2
!= 0, "CreateWindowExA error %d\n", GetLastError() );
7586 memset( buf
, 0x1c, sizeof(buf
) );
7587 g_wm_gettext_override
.dont_terminate
= TRUE
;
7588 buf_len
= GetWindowTextA( hwnd2
, buf
, sizeof(buf
) );
7589 ok( buf_len
== 4, "Unexpected text length, %d\n", buf_len
);
7590 ok( !memcmp(buf
, "text", 4), "Unexpected window text, '%s'\n", buf
);
7591 ok( buf
[4] == 0, "Unexpected buffer contents, %#x\n", buf
[4] );
7592 g_wm_gettext_override
.dont_terminate
= FALSE
;
7594 memset( bufW
, 0x1c, sizeof(bufW
) );
7595 g_wm_gettext_override
.dont_terminate
= TRUE
;
7596 buf_len
= GetWindowTextW( hwnd2
, bufW
, ARRAY_SIZE(bufW
));
7597 ok( buf_len
== 4, "Unexpected text length, %d\n", buf_len
);
7598 ok( !memcmp(bufW
, textW
, 4 * sizeof(WCHAR
)), "Unexpected window text, %s\n", wine_dbgstr_w(bufW
) );
7599 ok( bufW
[4] == 0x1c1c, "Unexpected buffer contents, %#x\n", bufW
[4] );
7600 g_wm_gettext_override
.dont_terminate
= FALSE
;
7602 DestroyWindow(hwnd2
);
7604 /* seems to crash on every modern Windows version */
7607 r
= SendMessageA( hwnd
, WM_GETTEXT
, 0x10, 0x1000);
7608 ok( r
== 0, "settext should return zero\n");
7610 r
= SendMessageA( hwnd
, WM_GETTEXT
, 0x10000, 0);
7611 ok( r
== 0, "settext should return zero (%ld)\n", r
);
7613 r
= SendMessageA( hwnd
, WM_GETTEXT
, 0xff000000, 0x1000);
7614 ok( r
== 0, "settext should return zero (%ld)\n", r
);
7616 r
= SendMessageA( hwnd
, WM_GETTEXT
, 0x1000, 0xff000000);
7617 ok( r
== 0, "settext should return zero (%ld)\n", r
);
7620 DestroyWindow(hwnd
);
7624 static void test_GetUpdateRect(void)
7627 BOOL ret
, parent_wm_paint
, grandparent_wm_paint
;
7629 HWND hgrandparent
, hparent
, hchild
;
7631 static const char classNameA
[] = "GetUpdateRectClass";
7633 hgrandparent
= CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW
,
7634 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
7636 hparent
= CreateWindowA("static", "parent", WS_CHILD
|WS_VISIBLE
,
7637 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
7639 hchild
= CreateWindowA("static", "child", WS_CHILD
|WS_VISIBLE
,
7640 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
7642 ShowWindow(hgrandparent
, SW_SHOW
);
7643 UpdateWindow(hgrandparent
);
7644 flush_events( TRUE
);
7646 ShowWindow(hchild
, SW_HIDE
);
7648 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
7649 ok(!ret
, "GetUpdateRect returned not empty region\n");
7650 ok(EqualRect(&rc1
, &rc2
), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1
),
7651 wine_dbgstr_rect(&rc2
));
7653 SetRect(&rc2
, 10, 10, 40, 40);
7654 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
7655 ok(ret
, "GetUpdateRect returned empty region\n");
7656 ok(EqualRect(&rc1
, &rc2
), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1
),
7657 wine_dbgstr_rect(&rc2
));
7659 parent_wm_paint
= FALSE
;
7660 grandparent_wm_paint
= FALSE
;
7661 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
7663 if (msg
.message
== WM_PAINT
)
7665 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
7666 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
7668 DispatchMessageA(&msg
);
7670 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
7671 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
7673 DestroyWindow(hgrandparent
);
7676 cls
.lpfnWndProc
= DefWindowProcA
;
7679 cls
.hInstance
= GetModuleHandleA(0);
7681 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
7682 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
7683 cls
.lpszMenuName
= NULL
;
7684 cls
.lpszClassName
= classNameA
;
7685 ret
= RegisterClassA(&cls
);
7686 ok(ret
, "Failed to register a test class.\n");
7688 hgrandparent
= CreateWindowA(classNameA
, "grandparent", WS_OVERLAPPEDWINDOW
,
7689 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
7691 hparent
= CreateWindowA(classNameA
, "parent", WS_CHILD
|WS_VISIBLE
,
7692 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
7694 hchild
= CreateWindowA(classNameA
, "child", WS_CHILD
|WS_VISIBLE
,
7695 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
7697 ShowWindow(hgrandparent
, SW_SHOW
);
7698 UpdateWindow(hgrandparent
);
7699 flush_events( TRUE
);
7701 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
7702 ok(!ret
, "GetUpdateRect returned not empty region\n");
7704 ShowWindow(hchild
, SW_HIDE
);
7707 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
7708 ok(!ret
, "GetUpdateRect returned not empty region\n");
7709 ok(EqualRect(&rc1
, &rc2
), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1
),
7710 wine_dbgstr_rect(&rc2
));
7712 SetRect(&rc2
, 10, 10, 40, 40);
7713 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
7714 ok(ret
, "GetUpdateRect returned empty region\n");
7715 ok(EqualRect(&rc1
, &rc2
), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1
),
7716 wine_dbgstr_rect(&rc2
));
7718 parent_wm_paint
= FALSE
;
7719 grandparent_wm_paint
= FALSE
;
7720 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
7722 if (msg
.message
== WM_PAINT
)
7724 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
7725 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
7727 DispatchMessageA(&msg
);
7729 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
7730 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
7732 DestroyWindow(hgrandparent
);
7736 static LRESULT CALLBACK
TestExposedRegion_WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
7744 const int waitTime
= 2000;
7746 BeginPaint(hwnd
, &ps
);
7748 /* create and destroy window to create an exposed region on this window */
7749 win
= CreateWindowA("static", "win", WS_VISIBLE
,
7750 10,10,50,50, NULL
, NULL
, 0, NULL
);
7753 waitResult
= MsgWaitForMultipleObjects( 0, NULL
, FALSE
, waitTime
, QS_PAINT
);
7755 ValidateRect(hwnd
, NULL
);
7756 EndPaint(hwnd
, &ps
);
7758 if(waitResult
!= WAIT_TIMEOUT
)
7760 GetUpdateRect(hwnd
, &updateRect
, FALSE
);
7761 ok(IsRectEmpty(&updateRect
), "Exposed rect should be empty\n");
7766 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
7769 static void test_Expose(void)
7774 memset(&cls
, 0, sizeof(WNDCLASSA
));
7775 cls
.lpfnWndProc
= TestExposedRegion_WndProc
;
7776 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
7777 cls
.lpszClassName
= "TestExposeClass";
7778 RegisterClassA(&cls
);
7780 mw
= CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE
|WS_OVERLAPPEDWINDOW
,
7781 0, 0, 200, 100, NULL
, NULL
, 0, NULL
);
7787 static LRESULT CALLBACK
TestNCRedraw_WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
7789 static UINT ncredrawflags
;
7795 ncredrawflags
= *(UINT
*) (((CREATESTRUCTA
*)lParam
)->lpCreateParams
);
7798 RedrawWindow(hwnd
, NULL
, NULL
, ncredrawflags
);
7801 BeginPaint(hwnd
, &ps
);
7802 EndPaint(hwnd
, &ps
);
7805 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
7808 static void run_NCRedrawLoop(UINT flags
)
7815 hwnd
= CreateWindowA("TestNCRedrawClass", "MainWindow",
7816 WS_OVERLAPPEDWINDOW
, 0, 0, 200, 100,
7817 NULL
, NULL
, 0, &flags
);
7818 ShowWindow(hwnd
, SW_SHOW
);
7820 flush_events( FALSE
);
7821 while (PeekMessageA(&msg
, hwnd
, 0, 0, PM_REMOVE
))
7823 if (msg
.message
== WM_PAINT
) loopcount
++;
7824 if (loopcount
>= 100) break;
7825 TranslateMessage(&msg
);
7826 DispatchMessageA(&msg
);
7827 MsgWaitForMultipleObjects(0, NULL
, FALSE
, 100, QS_ALLINPUT
);
7829 todo_wine_if (flags
== (RDW_INVALIDATE
| RDW_FRAME
))
7830 ok(loopcount
< 100, "Detected infinite WM_PAINT loop (%x).\n", flags
);
7831 DestroyWindow(hwnd
);
7834 static void test_NCRedraw(void)
7838 wndclass
.lpszClassName
= "TestNCRedrawClass";
7839 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
7840 wndclass
.lpfnWndProc
= TestNCRedraw_WndProc
;
7841 wndclass
.cbClsExtra
= 0;
7842 wndclass
.cbWndExtra
= 0;
7843 wndclass
.hInstance
= 0;
7844 wndclass
.hIcon
= LoadIconA(0, (LPCSTR
)IDI_APPLICATION
);
7845 wndclass
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
7846 wndclass
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
7847 wndclass
.lpszMenuName
= NULL
;
7849 RegisterClassA(&wndclass
);
7851 run_NCRedrawLoop(RDW_INVALIDATE
| RDW_FRAME
);
7852 run_NCRedrawLoop(RDW_INVALIDATE
);
7855 static void test_GetWindowModuleFileName(void)
7860 char buf1
[MAX_PATH
], buf2
[MAX_PATH
];
7862 if (!pGetWindowModuleFileNameA
)
7864 win_skip("GetWindowModuleFileNameA is not available\n");
7868 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0,0,0,0, 0, 0, 0, NULL
);
7871 hinst
= (HINSTANCE
)GetWindowLongPtrA(hwnd
, GWLP_HINSTANCE
);
7872 ok(hinst
== 0, "expected 0, got %p\n", hinst
);
7875 SetLastError(0xdeadbeef);
7876 ret1
= GetModuleFileNameA(hinst
, buf1
, sizeof(buf1
));
7877 ok(ret1
, "GetModuleFileName error %u\n", GetLastError());
7880 SetLastError(0xdeadbeef);
7881 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, sizeof(buf2
));
7882 ok(ret2
, "GetWindowModuleFileNameA error %u\n", GetLastError());
7886 ok(ret1
== ret2
, "%u != %u\n", ret1
, ret2
);
7887 ok(!strcmp(buf1
, buf2
), "%s != %s\n", buf1
, buf2
);
7889 hinst
= GetModuleHandleA(NULL
);
7891 SetLastError(0xdeadbeef);
7892 ret2
= GetModuleFileNameA(hinst
, buf2
, ret1
- 2);
7893 ok(ret2
== ret1
- 2, "expected %u, got %u\n", ret1
- 2, ret2
);
7894 ok(GetLastError() == 0xdeadbeef /* XP */ ||
7895 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
7896 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
7898 SetLastError(0xdeadbeef);
7899 ret2
= GetModuleFileNameA(hinst
, buf2
, 0);
7900 ok(!ret2
, "GetModuleFileName should return 0\n");
7901 ok(GetLastError() == 0xdeadbeef /* XP */ ||
7902 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
7903 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
7905 SetLastError(0xdeadbeef);
7906 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, ret1
- 2);
7907 ok(ret2
== ret1
- 2, "expected %u, got %u\n", ret1
- 2, ret2
);
7908 ok(GetLastError() == 0xdeadbeef /* XP */ ||
7909 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
7910 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
7912 SetLastError(0xdeadbeef);
7913 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, 0);
7914 ok(!ret2
, "expected 0, got %u\n", ret2
);
7915 ok(GetLastError() == 0xdeadbeef /* XP */ ||
7916 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
7917 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
7919 DestroyWindow(hwnd
);
7922 hwnd
= (HWND
)0xdeadbeef;
7923 SetLastError(0xdeadbeef);
7924 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
7925 ok(!ret1
, "expected 0, got %u\n", ret1
);
7926 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
,
7927 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
7929 hwnd
= FindWindowA("Shell_TrayWnd", NULL
);
7930 ok(IsWindow(hwnd
) || broken(!hwnd
), "got invalid tray window %p\n", hwnd
);
7931 SetLastError(0xdeadbeef);
7932 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
7933 ok(!ret1
, "expected 0, got %u\n", ret1
);
7934 ret1
= GetModuleFileNameA(0, buf1
, sizeof(buf1
));
7935 hwnd
= GetDesktopWindow();
7936 ok(IsWindow(hwnd
), "got invalid desktop window %p\n", hwnd
);
7937 SetLastError(0xdeadbeef);
7938 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, sizeof(buf2
));
7940 ret1
== ret2
, /* vista */
7941 "expected 0 or %u, got %u %s\n", ret1
, ret2
, buf2
);
7944 static void test_hwnd_message(void)
7946 static const WCHAR mainwindowclassW
[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
7947 static const WCHAR message_windowW
[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
7949 HWND parent
= 0, hwnd
, found
;
7959 { GWLP_USERDATA
, 0, 0 },
7960 { GWL_STYLE
, WS_POPUP
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, 0 },
7961 { GWL_EXSTYLE
, 0, 0 },
7963 /* GWLP_HWNDPARENT - returns random values */
7964 /* GWLP_HINSTANCE - not useful and not consistent between Windows versions */
7965 { GWLP_WNDPROC
, 0, ERROR_ACCESS_DENIED
},
7966 { DWLP_MSGRESULT
, 0, ERROR_INVALID_INDEX
}
7968 HWND root
, desktop
= GetDesktopWindow();
7973 hwnd
= CreateWindowExW(0, mainwindowclassW
, message_windowW
, WS_CAPTION
| WS_VISIBLE
,
7974 100, 100, 200, 200, HWND_MESSAGE
, 0, 0, NULL
);
7975 ok( hwnd
!= 0, "CreateWindowExW with parent HWND_MESSAGE failed\n" );
7976 ok( !GetParent(hwnd
), "GetParent should return 0 for message only windows\n" );
7978 parent
= GetAncestor(hwnd
, GA_PARENT
);
7979 ok(parent
!= 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
7980 ok(parent
!= desktop
, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
7981 root
= GetAncestor(hwnd
, GA_ROOT
);
7982 ok(root
== hwnd
, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
7983 ok( !GetAncestor(parent
, GA_PARENT
),
7984 "parent shouldn't have parent %p\n", GetAncestor(parent
, GA_PARENT
) );
7985 if (!GetClassNameA( parent
, buffer
, sizeof(buffer
) )) buffer
[0] = 0;
7986 ok( !lstrcmpiA( buffer
, "Message" ), "wrong parent class '%s'\n", buffer
);
7987 GetWindowRect( parent
, &rect
);
7988 ok( rect
.left
== 0 && rect
.right
== 100 && rect
.top
== 0 && rect
.bottom
== 100,
7989 "wrong parent rect %s\n", wine_dbgstr_rect( &rect
));
7990 GetWindowRect( hwnd
, &rect
);
7991 ok( rect
.left
== 100 && rect
.right
== 300 && rect
.top
== 100 && rect
.bottom
== 300,
7992 "wrong window rect %s\n", wine_dbgstr_rect( &rect
));
7994 /* test FindWindow behavior */
7996 found
= FindWindowExA( 0, 0, 0, "message window" );
7997 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
7998 SetLastError(0xdeadbeef);
7999 found
= FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
8000 ok( found
== 0, "found message window %p/%p\n", found
, hwnd
);
8001 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
8004 found
= FindWindowExA( parent
, 0, 0, "message window" );
8005 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
8008 /* test IsChild behavior */
8010 if (parent
) ok( !IsChild( parent
, hwnd
), "HWND_MESSAGE is child of top window\n" );
8012 /* test IsWindowVisible behavior */
8014 ok( !IsWindowVisible( hwnd
), "HWND_MESSAGE window is visible\n" );
8015 if (parent
) ok( !IsWindowVisible( parent
), "HWND_MESSAGE parent is visible\n" );
8018 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
8020 SetLastError( 0xdeadbeef );
8021 result
= GetWindowLongPtrW( parent
, tests
[i
].offset
);
8022 ok( result
== tests
[i
].expect
, "offset %d, got %08lx expect %08lx\n",
8023 tests
[i
].offset
, result
, tests
[i
].expect
);
8025 ok( GetLastError() == tests
[i
].error
, "offset %d: error %d expect %d\n",
8026 tests
[i
].offset
, GetLastError(), tests
[i
].error
);
8028 ok( GetLastError() == 0xdeadbeef, "offset %d: error %d expect unchanged\n",
8029 tests
[i
].offset
, GetLastError() );
8032 DestroyWindow(hwnd
);
8035 static void test_layered_window(void)
8041 POINT pt
= { 0, 0 };
8042 SIZE sz
= { 200, 200 };
8048 if (!pGetLayeredWindowAttributes
|| !pSetLayeredWindowAttributes
|| !pUpdateLayeredWindow
)
8050 win_skip( "layered windows not supported\n" );
8054 hdc
= CreateCompatibleDC( 0 );
8055 hbm
= CreateCompatibleBitmap( hdc
, 200, 200 );
8056 SelectObject( hdc
, hbm
);
8058 hwnd
= CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION
,
8059 100, 100, 200, 200, 0, 0, 0, NULL
);
8061 SetLastError( 0xdeadbeef );
8062 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
);
8063 ok( !ret
, "UpdateLayeredWindow should fail on non-layered window\n" );
8064 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
8065 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
8066 ok( !ret
, "GetLayeredWindowAttributes should fail on non-layered window\n" );
8067 ret
= pSetLayeredWindowAttributes( hwnd
, 0, 0, LWA_ALPHA
);
8068 ok( !ret
, "SetLayeredWindowAttributes should fail on non-layered window\n" );
8069 SetWindowLongA( hwnd
, GWL_EXSTYLE
, GetWindowLongA(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
8070 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
8071 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
8072 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
);
8073 ok( ret
, "UpdateLayeredWindow should succeed on layered window\n" );
8074 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
8075 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
8076 ret
= pSetLayeredWindowAttributes( hwnd
, 0x123456, 44, LWA_ALPHA
);
8077 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
8078 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
8079 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
8080 ok( key
== 0x123456 || key
== 0, "wrong color key %x\n", key
);
8081 ok( alpha
== 44, "wrong alpha %u\n", alpha
);
8082 ok( flags
== LWA_ALPHA
, "wrong flags %x\n", flags
);
8083 SetLastError( 0xdeadbeef );
8084 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
);
8085 ok( !ret
, "UpdateLayeredWindow should fail on layered but initialized window\n" );
8086 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
8088 /* clearing WS_EX_LAYERED resets attributes */
8089 SetWindowLongA( hwnd
, GWL_EXSTYLE
, GetWindowLongA(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
8090 SetLastError( 0xdeadbeef );
8091 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
);
8092 ok( !ret
, "UpdateLayeredWindow should fail on non-layered window\n" );
8093 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
8094 ok( !ret
, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
8095 SetWindowLongA( hwnd
, GWL_EXSTYLE
, GetWindowLongA(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
8096 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
8097 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
8098 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
);
8099 ok( ret
, "UpdateLayeredWindow should succeed on layered window\n" );
8100 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
| ULW_EX_NORESIZE
);
8101 ok( !ret
, "UpdateLayeredWindow should fail with ex flag\n" );
8102 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %u\n", GetLastError() );
8103 if (pUpdateLayeredWindowIndirect
)
8105 UPDATELAYEREDWINDOWINFO info
;
8106 info
.cbSize
= sizeof(info
);
8114 info
.dwFlags
= ULW_OPAQUE
| ULW_EX_NORESIZE
;
8115 info
.prcDirty
= NULL
;
8116 ret
= pUpdateLayeredWindowIndirect( hwnd
, &info
);
8117 ok( ret
, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
8120 ret
= pUpdateLayeredWindowIndirect( hwnd
, &info
);
8121 ok( !ret
, "UpdateLayeredWindowIndirect should fail\n" );
8122 /* particular error code differs from version to version, could be ERROR_INCORRECT_SIZE,
8123 ERROR_MR_MID_NOT_FOUND or ERROR_GEN_FAILURE (Win8/Win10) */
8124 ok( GetLastError() != 0, "wrong error %u\n", GetLastError() );
8125 info
.dwFlags
= ULW_OPAQUE
;
8126 ret
= pUpdateLayeredWindowIndirect( hwnd
, &info
);
8127 ok( ret
, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
8129 info
.dwFlags
= ULW_OPAQUE
| 0xf00;
8130 ret
= pUpdateLayeredWindowIndirect( hwnd
, &info
);
8131 ok( !ret
, "UpdateLayeredWindowIndirect should fail\n" );
8132 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %u\n", GetLastError() );
8134 info
.dwFlags
= ULW_OPAQUE
;
8135 ret
= pUpdateLayeredWindowIndirect( hwnd
, &info
);
8136 ok( !ret
, "UpdateLayeredWindowIndirect should fail\n" );
8137 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %u\n", GetLastError() );
8138 ret
= pUpdateLayeredWindowIndirect( hwnd
, NULL
);
8139 ok( !ret
, "UpdateLayeredWindowIndirect should fail\n" );
8140 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %u\n", GetLastError() );
8143 ret
= pSetLayeredWindowAttributes( hwnd
, 0x654321, 22, LWA_COLORKEY
| LWA_ALPHA
);
8144 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
8145 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
8146 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
8147 ok( key
== 0x654321, "wrong color key %x\n", key
);
8148 ok( alpha
== 22, "wrong alpha %u\n", alpha
);
8149 ok( flags
== (LWA_COLORKEY
| LWA_ALPHA
), "wrong flags %x\n", flags
);
8150 SetLastError( 0xdeadbeef );
8151 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
);
8152 ok( !ret
, "UpdateLayeredWindow should fail on layered but initialized window\n" );
8153 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
8155 ret
= pSetLayeredWindowAttributes( hwnd
, 0x888888, 33, LWA_COLORKEY
);
8156 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
8158 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
8159 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
8160 ok( key
== 0x888888, "wrong color key %x\n", key
);
8161 /* alpha not changed on vista if LWA_ALPHA is not set */
8162 ok( alpha
== 22 || alpha
== 33, "wrong alpha %u\n", alpha
);
8163 ok( flags
== LWA_COLORKEY
, "wrong flags %x\n", flags
);
8165 /* color key may or may not be changed without LWA_COLORKEY */
8166 ret
= pSetLayeredWindowAttributes( hwnd
, 0x999999, 44, 0 );
8167 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
8169 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
8170 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
8171 ok( key
== 0x888888 || key
== 0x999999, "wrong color key %x\n", key
);
8172 ok( alpha
== 22 || alpha
== 44, "wrong alpha %u\n", alpha
);
8173 ok( flags
== 0, "wrong flags %x\n", flags
);
8175 /* default alpha and color key is 0 */
8176 SetWindowLongA( hwnd
, GWL_EXSTYLE
, GetWindowLongA(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
8177 SetWindowLongA( hwnd
, GWL_EXSTYLE
, GetWindowLongA(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
8178 ret
= pSetLayeredWindowAttributes( hwnd
, 0x222222, 55, 0 );
8179 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
8180 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
8181 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
8182 ok( key
== 0 || key
== 0x222222, "wrong color key %x\n", key
);
8183 ok( alpha
== 0 || alpha
== 55, "wrong alpha %u\n", alpha
);
8184 ok( flags
== 0, "wrong flags %x\n", flags
);
8186 /* test layered window with WS_CLIPCHILDREN flag */
8187 SetWindowLongA( hwnd
, GWL_STYLE
, GetWindowLongA(hwnd
, GWL_STYLE
) | WS_CLIPCHILDREN
);
8188 SetWindowLongA( hwnd
, GWL_EXSTYLE
, GetWindowLongA(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
8189 SetWindowLongA( hwnd
, GWL_EXSTYLE
, GetWindowLongA(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
8190 child
= CreateWindowExA( 0, "button", "button", WS_VISIBLE
| WS_CHILD
,
8191 0, 0, 50, 50, hwnd
, 0, 0, NULL
);
8192 ok( child
!= NULL
, "CreateWindowEx error %u\n", GetLastError() );
8193 ShowWindow( hwnd
, SW_SHOW
);
8195 ret
= pSetLayeredWindowAttributes( hwnd
, 0, 255, LWA_ALPHA
);
8196 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
8197 while (GetMessageA(&msg
, 0, 0, 0))
8199 DispatchMessageA(&msg
);
8201 if (msg
.message
== WM_PAINT
&& msg
.hwnd
== child
)
8205 SetWindowLongA( hwnd
, GWL_EXSTYLE
, GetWindowLongA(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
8206 SetWindowLongA( hwnd
, GWL_EXSTYLE
, GetWindowLongA(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
8207 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
);
8208 ok( ret
, "UpdateLayeredWindow should succeed on layered window\n" );
8210 ret
= pSetLayeredWindowAttributes( hwnd
, 0, 255, LWA_ALPHA
);
8211 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
8212 while (GetMessageA(&msg
, 0, 0, 0))
8214 DispatchMessageA(&msg
);
8216 if (msg
.message
== WM_PAINT
&& msg
.hwnd
== child
)
8220 DestroyWindow( hwnd
);
8222 DeleteObject( hbm
);
8225 static MONITORINFO mi
;
8227 static LRESULT CALLBACK
fullscreen_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
8233 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
8234 ok(cs
->x
== mi
.rcMonitor
.left
&& cs
->y
== mi
.rcMonitor
.top
&&
8235 cs
->cx
== mi
.rcMonitor
.right
&& cs
->cy
== mi
.rcMonitor
.bottom
,
8236 "expected %s, got (%d,%d)-(%d,%d)\n", wine_dbgstr_rect(&mi
.rcMonitor
),
8237 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
8240 case WM_GETMINMAXINFO
:
8242 MINMAXINFO
*minmax
= (MINMAXINFO
*)lp
;
8243 ok(minmax
->ptMaxPosition
.x
<= mi
.rcMonitor
.left
, "%d <= %d\n", minmax
->ptMaxPosition
.x
, mi
.rcMonitor
.left
);
8244 ok(minmax
->ptMaxPosition
.y
<= mi
.rcMonitor
.top
, "%d <= %d\n", minmax
->ptMaxPosition
.y
, mi
.rcMonitor
.top
);
8245 ok(minmax
->ptMaxSize
.x
>= mi
.rcMonitor
.right
, "%d >= %d\n", minmax
->ptMaxSize
.x
, mi
.rcMonitor
.right
);
8246 ok(minmax
->ptMaxSize
.y
>= mi
.rcMonitor
.bottom
, "%d >= %d\n", minmax
->ptMaxSize
.y
, mi
.rcMonitor
.bottom
);
8250 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
8253 static void test_fullscreen(void)
8255 static const DWORD t_style
[] = {
8256 WS_OVERLAPPED
, WS_POPUP
, WS_CHILD
, WS_THICKFRAME
, WS_DLGFRAME
8258 static const DWORD t_ex_style
[] = {
8259 0, WS_EX_APPWINDOW
, WS_EX_TOOLWINDOW
8271 SetLastError(0xdeadbeef);
8272 hmon
= MonitorFromPoint(pt
, MONITOR_DEFAULTTOPRIMARY
);
8273 ok(hmon
!= 0, "MonitorFromPoint error %u\n", GetLastError());
8275 mi
.cbSize
= sizeof(mi
);
8276 SetLastError(0xdeadbeef);
8277 ret
= GetMonitorInfoA(hmon
, &mi
);
8278 ok(ret
, "GetMonitorInfo error %u\n", GetLastError());
8279 trace("monitor %s, work %s\n", wine_dbgstr_rect(&mi
.rcMonitor
), wine_dbgstr_rect(&mi
.rcWork
));
8282 cls
.lpfnWndProc
= fullscreen_wnd_proc
;
8285 cls
.hInstance
= GetModuleHandleA(NULL
);
8287 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
8288 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
8289 cls
.lpszMenuName
= NULL
;
8290 cls
.lpszClassName
= "fullscreen_class";
8291 RegisterClassA(&cls
);
8293 for (i
= 0; i
< ARRAY_SIZE(t_style
); i
++)
8295 DWORD style
, ex_style
;
8297 /* avoid a WM interaction */
8298 assert(!(t_style
[i
] & WS_VISIBLE
));
8300 for (j
= 0; j
< ARRAY_SIZE(t_ex_style
); j
++)
8305 ex_style
= t_ex_style
[j
];
8307 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
8308 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
8309 GetDesktopWindow(), 0, GetModuleHandleA(NULL
), NULL
);
8310 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
8311 GetWindowRect(hwnd
, &rc
);
8312 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
8313 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
8314 "%#x/%#x: window rect %s\n", ex_style
, style
, wine_dbgstr_rect(&rc
));
8315 DestroyWindow(hwnd
);
8317 style
= t_style
[i
] | WS_MAXIMIZE
;
8318 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
8319 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
8320 GetDesktopWindow(), 0, GetModuleHandleA(NULL
), NULL
);
8321 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
8322 GetWindowRect(hwnd
, &rc
);
8323 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
8324 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
8325 "%#x/%#x: window rect %s\n", ex_style
, style
, wine_dbgstr_rect(&rc
));
8326 DestroyWindow(hwnd
);
8328 style
= t_style
[i
] | WS_MAXIMIZE
| WS_CAPTION
;
8329 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
8330 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
8331 GetDesktopWindow(), 0, GetModuleHandleA(NULL
), NULL
);
8332 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
8333 GetWindowRect(hwnd
, &rc
);
8334 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
8335 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
8336 "%#x/%#x: window rect %s\n", ex_style
, style
, wine_dbgstr_rect(&rc
));
8337 DestroyWindow(hwnd
);
8339 style
= t_style
[i
] | WS_CAPTION
| WS_MAXIMIZEBOX
;
8340 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
8341 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
8342 GetDesktopWindow(), 0, GetModuleHandleA(NULL
), NULL
);
8343 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
8344 GetWindowRect(hwnd
, &rc
);
8345 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
8346 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
8347 "%#x/%#x: window rect %s\n", ex_style
, style
, wine_dbgstr_rect(&rc
));
8348 DestroyWindow(hwnd
);
8350 style
= t_style
[i
] | WS_MAXIMIZE
| WS_CAPTION
| WS_MAXIMIZEBOX
;
8351 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
8352 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
8353 GetDesktopWindow(), 0, GetModuleHandleA(NULL
), NULL
);
8354 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
8355 GetWindowRect(hwnd
, &rc
);
8356 /* Windows makes a maximized window slightly larger (to hide the borders?) */
8357 fixup
= min(abs(rc
.left
), abs(rc
.top
));
8358 InflateRect(&rc
, -fixup
, -fixup
);
8359 ok(rc
.left
>= mi
.rcMonitor
.left
&& rc
.top
>= mi
.rcMonitor
.top
&&
8360 rc
.right
<= mi
.rcMonitor
.right
&& rc
.bottom
<= mi
.rcMonitor
.bottom
,
8361 "%#x/%#x: window rect %s must be in %s\n", ex_style
, style
, wine_dbgstr_rect(&rc
),
8362 wine_dbgstr_rect(&mi
.rcMonitor
));
8363 DestroyWindow(hwnd
);
8365 style
= t_style
[i
] | WS_MAXIMIZE
| WS_MAXIMIZEBOX
;
8366 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
8367 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
8368 GetDesktopWindow(), 0, GetModuleHandleA(NULL
), NULL
);
8369 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
8370 GetWindowRect(hwnd
, &rc
);
8371 /* Windows makes a maximized window slightly larger (to hide the borders?) */
8372 fixup
= min(abs(rc
.left
), abs(rc
.top
));
8373 InflateRect(&rc
, -fixup
, -fixup
);
8374 if (style
& (WS_CHILD
| WS_POPUP
))
8375 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
8376 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
8377 "%#x/%#x: window rect %s\n", ex_style
, style
, wine_dbgstr_rect(&rc
));
8379 ok(rc
.left
>= mi
.rcMonitor
.left
&& rc
.top
>= mi
.rcMonitor
.top
&&
8380 rc
.right
<= mi
.rcMonitor
.right
&& rc
.bottom
<= mi
.rcMonitor
.bottom
,
8381 "%#x/%#x: window rect %s\n", ex_style
, style
, wine_dbgstr_rect(&rc
));
8382 DestroyWindow(hwnd
);
8386 /* Test restoring a full screen window with WS_THICKFRAME style to normal */
8387 /* Add WS_THICKFRAME style later so that the window can cover the entire monitor */
8388 hwnd
= CreateWindowA("fullscreen_class", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, mi
.rcMonitor
.right
,
8389 mi
.rcMonitor
.bottom
, NULL
, NULL
, GetModuleHandleA(NULL
), NULL
);
8390 ok(!!hwnd
, "CreateWindow failed, error %#x.\n", GetLastError());
8393 /* Add WS_THICKFRAME and exit full screen */
8394 SetWindowLongA(hwnd
, GWL_STYLE
, GetWindowLongA(hwnd
, GWL_STYLE
) | WS_THICKFRAME
);
8395 SetWindowPos(hwnd
, 0, 0, 0, 100, 100, SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOCOPYBITS
);
8398 /* TestBots need about 1000ms to exit full screen */
8404 GetWindowRect(hwnd
, &rc
);
8405 if (rc
.right
- rc
.left
== 100 && rc
.bottom
- rc
.top
== 100)
8408 ok(rc
.right
- rc
.left
== 100, "Expect width %d, got %d.\n", 100, rc
.right
- rc
.left
);
8409 ok(rc
.bottom
- rc
.top
== 100, "Expect height %d, got %d.\n", 100, rc
.bottom
- rc
.top
);
8410 DestroyWindow(hwnd
);
8412 UnregisterClassA("fullscreen_class", GetModuleHandleA(NULL
));
8415 static BOOL test_thick_child_got_minmax
;
8416 static const char * test_thick_child_name
;
8417 static LONG test_thick_child_style
;
8418 static LONG test_thick_child_exStyle
;
8420 static LRESULT WINAPI
test_thick_child_size_winproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
8423 int expectedMinTrackX
;
8424 int expectedMinTrackY
;
8425 int actualMinTrackX
;
8426 int actualMinTrackY
;
8427 int expectedMaxTrackX
;
8428 int expectedMaxTrackY
;
8429 int actualMaxTrackX
;
8430 int actualMaxTrackY
;
8431 int expectedMaxSizeX
;
8432 int expectedMaxSizeY
;
8443 case WM_GETMINMAXINFO
:
8445 minmax
= (MINMAXINFO
*)lparam
;
8446 if (winetest_debug
> 1)
8448 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
8449 dump_minmax_info( minmax
);
8451 test_thick_child_got_minmax
= TRUE
;
8454 adjustedStyle
= test_thick_child_style
;
8455 if ((adjustedStyle
& WS_CAPTION
) == WS_CAPTION
)
8456 adjustedStyle
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
8457 GetClientRect(GetParent(hwnd
), &rect
);
8458 AdjustWindowRectEx(&rect
, adjustedStyle
, FALSE
, test_thick_child_exStyle
);
8460 if (test_thick_child_style
& (WS_DLGFRAME
| WS_BORDER
))
8462 expectedMinTrackX
= GetSystemMetrics(SM_CXMINTRACK
);
8463 expectedMinTrackY
= GetSystemMetrics(SM_CYMINTRACK
);
8467 expectedMinTrackX
= -2 * rect
.left
;
8468 expectedMinTrackY
= -2 * rect
.top
;
8470 actualMinTrackX
= minmax
->ptMinTrackSize
.x
;
8471 actualMinTrackY
= minmax
->ptMinTrackSize
.y
;
8473 ok(actualMinTrackX
== expectedMinTrackX
&& actualMinTrackY
== expectedMinTrackY
,
8474 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
8475 expectedMinTrackX
, expectedMinTrackY
, actualMinTrackX
, actualMinTrackY
,
8476 test_thick_child_name
);
8478 actualMaxTrackX
= minmax
->ptMaxTrackSize
.x
;
8479 actualMaxTrackY
= minmax
->ptMaxTrackSize
.y
;
8480 expectedMaxTrackX
= GetSystemMetrics(SM_CXMAXTRACK
);
8481 expectedMaxTrackY
= GetSystemMetrics(SM_CYMAXTRACK
);
8482 ok(actualMaxTrackX
== expectedMaxTrackX
&& actualMaxTrackY
== expectedMaxTrackY
,
8483 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
8484 expectedMaxTrackX
, expectedMaxTrackY
, actualMaxTrackX
, actualMaxTrackY
,
8485 test_thick_child_name
);
8487 expectedMaxSizeX
= rect
.right
- rect
.left
;
8488 expectedMaxSizeY
= rect
.bottom
- rect
.top
;
8489 actualMaxSizeX
= minmax
->ptMaxSize
.x
;
8490 actualMaxSizeY
= minmax
->ptMaxSize
.y
;
8492 ok(actualMaxSizeX
== expectedMaxSizeX
&& actualMaxSizeY
== expectedMaxSizeY
,
8493 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
8494 expectedMaxSizeX
, expectedMaxSizeY
, actualMaxSizeX
, actualMaxSizeY
,
8495 test_thick_child_name
);
8498 expectedPosX
= rect
.left
;
8499 expectedPosY
= rect
.top
;
8500 actualPosX
= minmax
->ptMaxPosition
.x
;
8501 actualPosY
= minmax
->ptMaxPosition
.y
;
8502 ok(actualPosX
== expectedPosX
&& actualPosY
== expectedPosY
,
8503 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
8504 expectedPosX
, expectedPosY
, actualPosX
, actualPosY
, test_thick_child_name
);
8510 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
8513 #define NUMBER_OF_THICK_CHILD_TESTS 16
8514 static void test_thick_child_size(HWND parentWindow
)
8518 RECT adjustedParentRect
;
8523 LONG expectedHeight
;
8525 static const char className
[] = "THICK_CHILD_CLASS";
8528 static const LONG styles
[NUMBER_OF_THICK_CHILD_TESTS
] = {
8529 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
8530 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
8531 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
8532 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
8533 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
8534 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
8535 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
8536 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
8537 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
8538 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
8539 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
8540 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
8541 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
8542 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
8543 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
8544 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
8547 static const LONG exStyles
[NUMBER_OF_THICK_CHILD_TESTS
] = {
8552 WS_EX_DLGMODALFRAME
,
8553 WS_EX_DLGMODALFRAME
,
8554 WS_EX_DLGMODALFRAME
,
8555 WS_EX_DLGMODALFRAME
,
8560 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
8561 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
8562 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
8563 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
8565 static const char *styleName
[NUMBER_OF_THICK_CHILD_TESTS
] = {
8566 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
8567 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
8568 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
8569 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
8570 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
8571 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
8572 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
8573 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
8574 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
8575 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
8576 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
8577 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
8578 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
8579 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
8580 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
8581 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
8585 cls
.lpfnWndProc
= test_thick_child_size_winproc
;
8588 cls
.hInstance
= GetModuleHandleA(0);
8590 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
8591 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
8592 cls
.lpszMenuName
= NULL
;
8593 cls
.lpszClassName
= className
;
8594 SetLastError(0xdeadbeef);
8595 success
= RegisterClassA(&cls
);
8596 ok(success
,"RegisterClassA failed, error: %u\n", GetLastError());
8598 for(i
= 0; i
< NUMBER_OF_THICK_CHILD_TESTS
; i
++)
8600 test_thick_child_name
= styleName
[i
];
8601 test_thick_child_style
= styles
[i
];
8602 test_thick_child_exStyle
= exStyles
[i
];
8603 test_thick_child_got_minmax
= FALSE
;
8605 SetLastError(0xdeadbeef);
8606 childWindow
= CreateWindowExA( exStyles
[i
], className
, "", styles
[i
], 0, 0, 0, 0, parentWindow
, 0, GetModuleHandleA(0), NULL
);
8607 ok(childWindow
!= NULL
, "Failed to create child window, error: %u\n", GetLastError());
8609 ok(test_thick_child_got_minmax
, "Got no WM_GETMINMAXINFO\n");
8611 SetLastError(0xdeadbeef);
8612 success
= GetWindowRect(childWindow
, &childRect
);
8613 ok(success
,"GetWindowRect call failed, error: %u\n", GetLastError());
8614 childWidth
= childRect
.right
- childRect
.left
;
8615 childHeight
= childRect
.bottom
- childRect
.top
;
8617 adjustedStyle
= styles
[i
];
8618 if ((adjustedStyle
& WS_CAPTION
) == WS_CAPTION
)
8619 adjustedStyle
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
8620 GetClientRect(GetParent(childWindow
), &adjustedParentRect
);
8621 AdjustWindowRectEx(&adjustedParentRect
, adjustedStyle
, FALSE
, test_thick_child_exStyle
);
8624 if (test_thick_child_style
& (WS_DLGFRAME
| WS_BORDER
))
8626 expectedWidth
= GetSystemMetrics(SM_CXMINTRACK
);
8627 expectedHeight
= GetSystemMetrics(SM_CYMINTRACK
);
8631 expectedWidth
= -2 * adjustedParentRect
.left
;
8632 expectedHeight
= -2 * adjustedParentRect
.top
;
8635 ok((childWidth
== expectedWidth
) && (childHeight
== expectedHeight
),
8636 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
8637 test_thick_child_name
, expectedWidth
, expectedHeight
, childWidth
, childHeight
);
8639 SetLastError(0xdeadbeef);
8640 success
= DestroyWindow(childWindow
);
8641 ok(success
,"DestroyWindow call failed, error: %u\n", GetLastError());
8643 ok(UnregisterClassA(className
, GetModuleHandleA(NULL
)),"UnregisterClass call failed\n");
8646 static void test_handles( HWND full_hwnd
)
8648 HWND hwnd
= full_hwnd
;
8652 SetLastError( 0xdeadbeef );
8653 ret
= GetWindowRect( hwnd
, &rect
);
8654 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
8657 if ((ULONG_PTR
)full_hwnd
>> 32)
8658 hwnd
= (HWND
)((ULONG_PTR
)full_hwnd
& ~0u);
8660 hwnd
= (HWND
)((ULONG_PTR
)full_hwnd
| ((ULONG_PTR
)~0u << 32));
8661 SetLastError( 0xdeadbeef );
8662 ret
= GetWindowRect( hwnd
, &rect
);
8663 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
8665 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& ~0u) | ((ULONG_PTR
)0x1234 << 32));
8666 SetLastError( 0xdeadbeef );
8667 ret
= GetWindowRect( hwnd
, &rect
);
8668 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
8670 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& 0xffff) | ((ULONG_PTR
)0x9876 << 16));
8671 SetLastError( 0xdeadbeef );
8672 ret
= GetWindowRect( hwnd
, &rect
);
8673 ok( !ret
, "GetWindowRect succeeded for %p\n", hwnd
);
8674 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "wrong error %u\n", GetLastError() );
8676 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& 0xffff) | ((ULONG_PTR
)0x12345678 << 16));
8677 SetLastError( 0xdeadbeef );
8678 ret
= GetWindowRect( hwnd
, &rect
);
8679 ok( !ret
, "GetWindowRect succeeded for %p\n", hwnd
);
8680 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "wrong error %u\n", GetLastError() );
8684 static void test_winregion(void)
8691 if (!pGetWindowRgnBox
)
8693 win_skip("GetWindowRgnBox not supported\n");
8697 hwnd
= CreateWindowExA(0, "static", NULL
, WS_VISIBLE
, 10, 10, 10, 10, NULL
, 0, 0, NULL
);
8699 SetLastError(0xdeadbeef);
8700 ret
= pGetWindowRgnBox(hwnd
, NULL
);
8701 ok( ret
== ERROR
, "Expected ERROR, got %d\n", ret
);
8702 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
8704 hrgn
= CreateRectRgn(2, 3, 10, 15);
8705 ok( hrgn
!= NULL
, "Region creation failed\n");
8708 SetWindowRgn(hwnd
, hrgn
, FALSE
);
8710 SetLastError(0xdeadbeef);
8711 ret
= pGetWindowRgnBox(hwnd
, NULL
);
8712 ok( ret
== ERROR
, "Expected ERROR, got %d\n", ret
);
8713 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
8716 ret
= pGetWindowRgnBox(hwnd
, &r
);
8717 ok( ret
== SIMPLEREGION
, "Expected SIMPLEREGION, got %d\n", ret
);
8718 ok( r
.left
== 2 && r
.top
== 3 && r
.right
== 10 && r
.bottom
== 15,
8719 "Expected (2,3)-(10,15), got %s\n", wine_dbgstr_rect( &r
));
8722 hrgn
= CreateRectRgn(2, 3, 10, 15);
8723 ret
= pMirrorRgn( hwnd
, hrgn
);
8724 ok( ret
== TRUE
, "MirrorRgn failed %u\n", ret
);
8726 GetWindowRect( hwnd
, &r
);
8727 width
= r
.right
- r
.left
;
8729 ret
= GetRgnBox( hrgn
, &r
);
8730 ok( ret
== SIMPLEREGION
, "GetRgnBox failed %u\n", ret
);
8731 ok( r
.left
== width
- 10 && r
.top
== 3 && r
.right
== width
- 2 && r
.bottom
== 15,
8732 "Wrong rectangle %s for width %d\n", wine_dbgstr_rect( &r
), width
);
8734 else win_skip( "MirrorRgn not supported\n" );
8736 DestroyWindow(hwnd
);
8739 static void test_rtl_layout(void)
8745 if (!pSetProcessDefaultLayout
)
8747 win_skip( "SetProcessDefaultLayout not supported\n" );
8751 parent
= CreateWindowExA(WS_EX_LAYOUTRTL
, "static", NULL
, WS_POPUP
, 100, 100, 300, 300, NULL
, 0, 0, NULL
);
8752 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 10, 10, 20, 20, parent
, 0, 0, NULL
);
8754 GetWindowRect( parent
, &r
);
8755 ok( r
.left
== 100 && r
.right
== 400, "wrong rect %s\n", wine_dbgstr_rect( &r
));
8756 GetClientRect( parent
, &r
);
8757 ok( r
.left
== 0 && r
.right
== 300, "wrong rect %s\n", wine_dbgstr_rect( &r
));
8758 GetClientRect( child
, &r
);
8759 ok( r
.left
== 0 && r
.right
== 20, "wrong rect %s\n", wine_dbgstr_rect( &r
));
8760 MapWindowPoints( child
, parent
, (POINT
*)&r
, 2 );
8761 ok( r
.left
== 10 && r
.right
== 30, "wrong rect %s\n", wine_dbgstr_rect( &r
));
8762 GetWindowRect( child
, &r
);
8763 ok( r
.left
== 370 && r
.right
== 390, "wrong rect %s\n", wine_dbgstr_rect( &r
));
8764 MapWindowPoints( NULL
, parent
, (POINT
*)&r
, 2 );
8765 ok( r
.left
== 10 && r
.right
== 30, "wrong rect %s\n", wine_dbgstr_rect( &r
));
8766 GetWindowRect( child
, &r
);
8767 MapWindowPoints( NULL
, parent
, (POINT
*)&r
, 1 );
8768 MapWindowPoints( NULL
, parent
, (POINT
*)&r
+ 1, 1 );
8769 ok( r
.left
== 30 && r
.right
== 10, "wrong rect %s\n", wine_dbgstr_rect( &r
));
8771 MapWindowPoints( child
, parent
, &pt
, 1 );
8772 ok( pt
.x
== 22 && pt
.y
== 22, "wrong point %d,%d\n", pt
.x
, pt
.y
);
8773 SetWindowPos( parent
, 0, 0, 0, 250, 250, SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
8774 GetWindowRect( parent
, &r
);
8775 ok( r
.left
== 100 && r
.right
== 350, "wrong rect %s\n", wine_dbgstr_rect( &r
));
8776 GetWindowRect( child
, &r
);
8777 ok( r
.left
== 320 && r
.right
== 340, "wrong rect %s\n", wine_dbgstr_rect( &r
));
8778 SetWindowLongW( parent
, GWL_EXSTYLE
, 0 );
8779 GetWindowRect( child
, &r
);
8780 ok( r
.left
== 320 && r
.right
== 340, "wrong rect %s\n", wine_dbgstr_rect( &r
));
8781 MapWindowPoints( NULL
, parent
, (POINT
*)&r
, 2 );
8782 ok( r
.left
== 220 && r
.right
== 240, "wrong rect %s\n", wine_dbgstr_rect( &r
));
8783 SetWindowLongW( parent
, GWL_EXSTYLE
, WS_EX_LAYOUTRTL
);
8784 GetWindowRect( child
, &r
);
8785 ok( r
.left
== 320 && r
.right
== 340, "wrong rect %s\n", wine_dbgstr_rect( &r
));
8786 MapWindowPoints( NULL
, parent
, (POINT
*)&r
, 2 );
8787 ok( r
.left
== 10 && r
.right
== 30, "wrong rect %s\n", wine_dbgstr_rect( &r
));
8788 SetWindowPos( child
, 0, 0, 0, 30, 30, SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
8789 GetWindowRect( child
, &r
);
8790 ok( r
.left
== 310 && r
.right
== 340, "wrong rect %s\n", wine_dbgstr_rect( &r
));
8791 MapWindowPoints( NULL
, parent
, (POINT
*)&r
, 2 );
8792 ok( r
.left
== 10 && r
.right
== 40, "wrong rect %s\n", wine_dbgstr_rect( &r
));
8793 DestroyWindow( child
);
8794 DestroyWindow( parent
);
8797 static void test_FlashWindow(void)
8803 win_skip( "FlashWindow not supported\n" );
8807 hwnd
= CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_POPUP
,
8808 0, 0, 0, 0, 0, 0, 0, NULL
);
8809 ok( hwnd
!= 0, "CreateWindowExA error %d\n", GetLastError() );
8811 SetLastError( 0xdeadbeef );
8812 ret
= pFlashWindow( NULL
, TRUE
);
8813 ok( !ret
&& (GetLastError() == ERROR_INVALID_PARAMETER
||
8814 GetLastError() == ERROR_INVALID_WINDOW_HANDLE
),
8815 "FlashWindow returned with %d\n", GetLastError() );
8817 DestroyWindow( hwnd
);
8819 SetLastError( 0xdeadbeef );
8820 ret
= pFlashWindow( hwnd
, TRUE
);
8821 ok( !ret
&& (GetLastError() == ERROR_INVALID_PARAMETER
||
8822 GetLastError() == ERROR_INVALID_WINDOW_HANDLE
),
8823 "FlashWindow returned with %d\n", GetLastError() );
8826 static void test_FlashWindowEx(void)
8832 if (!pFlashWindowEx
)
8834 win_skip( "FlashWindowEx not supported\n" );
8838 hwnd
= CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_POPUP
,
8839 0, 0, 0, 0, 0, 0, 0, NULL
);
8840 ok( hwnd
!= 0, "CreateWindowExA error %d\n", GetLastError() );
8842 finfo
.cbSize
= sizeof(FLASHWINFO
);
8843 finfo
.dwFlags
= FLASHW_TIMER
;
8845 finfo
.dwTimeout
= 200;
8847 SetLastError(0xdeadbeef);
8848 ret
= pFlashWindowEx(&finfo
);
8849 ok(!ret
&& (GetLastError() == ERROR_INVALID_PARAMETER
||
8850 GetLastError() == ERROR_INVALID_WINDOW_HANDLE
),
8851 "FlashWindowEx returned with %d\n", GetLastError());
8854 SetLastError(0xdeadbeef);
8855 ret
= pFlashWindowEx(NULL
);
8856 ok(!ret
&& GetLastError() == ERROR_NOACCESS
,
8857 "FlashWindowEx returned with %d\n", GetLastError());
8859 SetLastError(0xdeadbeef);
8860 ret
= pFlashWindowEx(&finfo
);
8861 todo_wine
ok(!ret
, "previous window state should not be active\n");
8863 finfo
.cbSize
= sizeof(FLASHWINFO
) - 1;
8864 SetLastError(0xdeadbeef);
8865 ret
= pFlashWindowEx(&finfo
);
8866 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
8867 "FlashWindowEx succeeded\n");
8869 finfo
.cbSize
= sizeof(FLASHWINFO
) + 1;
8870 SetLastError(0xdeadbeef);
8871 ret
= pFlashWindowEx(&finfo
);
8872 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
8873 "FlashWindowEx succeeded\n");
8874 finfo
.cbSize
= sizeof(FLASHWINFO
);
8876 DestroyWindow( hwnd
);
8878 SetLastError(0xdeadbeef);
8879 ret
= pFlashWindowEx(&finfo
);
8880 ok(!ret
&& (GetLastError() == ERROR_INVALID_PARAMETER
||
8881 GetLastError() == ERROR_INVALID_WINDOW_HANDLE
),
8882 "FlashWindowEx returned with %d\n", GetLastError());
8884 ok(finfo
.cbSize
== sizeof(FLASHWINFO
), "FlashWindowEx modified cdSize to %x\n", finfo
.cbSize
);
8885 ok(finfo
.hwnd
== hwnd
, "FlashWindowEx modified hwnd to %p\n", finfo
.hwnd
);
8886 ok(finfo
.dwFlags
== FLASHW_TIMER
, "FlashWindowEx modified dwFlags to %x\n", finfo
.dwFlags
);
8887 ok(finfo
.uCount
== 3, "FlashWindowEx modified uCount to %x\n", finfo
.uCount
);
8888 ok(finfo
.dwTimeout
== 200, "FlashWindowEx modified dwTimeout to %x\n", finfo
.dwTimeout
);
8890 hwnd
= CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_VISIBLE
| WS_POPUPWINDOW
,
8891 0, 0, 0, 0, 0, 0, 0, NULL
);
8892 ok( hwnd
!= 0, "CreateWindowExA error %d\n", GetLastError() );
8895 SetLastError(0xdeadbeef);
8896 ret
= pFlashWindowEx(NULL
);
8897 ok(!ret
&& GetLastError() == ERROR_NOACCESS
,
8898 "FlashWindowEx returned with %d\n", GetLastError());
8900 SetLastError(0xdeadbeef);
8901 prev
= pFlashWindowEx(&finfo
);
8903 ok(finfo
.cbSize
== sizeof(FLASHWINFO
), "FlashWindowEx modified cdSize to %x\n", finfo
.cbSize
);
8904 ok(finfo
.hwnd
== hwnd
, "FlashWindowEx modified hwnd to %p\n", finfo
.hwnd
);
8905 ok(finfo
.dwFlags
== FLASHW_TIMER
, "FlashWindowEx modified dwFlags to %x\n", finfo
.dwFlags
);
8906 ok(finfo
.uCount
== 3, "FlashWindowEx modified uCount to %x\n", finfo
.uCount
);
8907 ok(finfo
.dwTimeout
== 200, "FlashWindowEx modified dwTimeout to %x\n", finfo
.dwTimeout
);
8909 finfo
.dwFlags
= FLASHW_STOP
;
8910 SetLastError(0xdeadbeef);
8911 ret
= pFlashWindowEx(&finfo
);
8912 ok(prev
!= ret
, "previous window state should be different\n");
8914 DestroyWindow( hwnd
);
8917 static void test_FindWindowEx(void)
8921 hwnd
= CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP
, 0,0,0,0, 0, 0, 0, NULL
);
8922 ok( hwnd
!= 0, "CreateWindowExA error %d\n", GetLastError() );
8924 num_gettext_msgs
= 0;
8925 found
= FindWindowExA( 0, 0, "ClassThatDoesntExist", "" );
8926 ok( found
== NULL
, "expected a NULL hwnd\n" );
8927 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
8929 num_gettext_msgs
= 0;
8930 found
= FindWindowExA( 0, 0, "ClassThatDoesntExist", NULL
);
8931 ok( found
== NULL
, "expected a NULL hwnd\n" );
8932 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
8934 num_gettext_msgs
= 0;
8935 found
= FindWindowExA( 0, 0, "MainWindowClass", "" );
8936 ok( found
== NULL
, "expected a NULL hwnd\n" );
8937 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
8939 num_gettext_msgs
= 0;
8940 found
= FindWindowExA( 0, 0, "MainWindowClass", NULL
);
8941 ok( found
== hwnd
, "found is %p, expected a valid hwnd\n", found
);
8942 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
8944 num_gettext_msgs
= 0;
8945 found
= FindWindowExA( 0, 0, "MainWindowClass", "caption" );
8946 ok( found
== hwnd
, "found is %p, expected a valid hwnd\n", found
);
8947 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
8949 DestroyWindow( hwnd
);
8951 hwnd
= CreateWindowExA( 0, "MainWindowClass", NULL
, WS_POPUP
, 0,0,0,0, 0, 0, 0, NULL
);
8952 ok( hwnd
!= 0, "CreateWindowExA error %d\n", GetLastError() );
8954 num_gettext_msgs
= 0;
8955 found
= FindWindowExA( 0, 0, "MainWindowClass", "" );
8956 ok( found
== hwnd
, "found is %p, expected a valid hwnd\n", found
);
8957 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
8959 num_gettext_msgs
= 0;
8960 found
= FindWindowExA( 0, 0, "MainWindowClass", NULL
);
8961 ok( found
== hwnd
, "found is %p, expected a valid hwnd\n", found
);
8962 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
8964 DestroyWindow( hwnd
);
8966 /* test behaviour with a window title that is an empty character */
8967 found
= FindWindowExA( 0, 0, "Shell_TrayWnd", "" );
8968 ok( found
!= NULL
, "found is NULL, expected a valid hwnd\n" );
8969 found
= FindWindowExA( 0, 0, "Shell_TrayWnd", NULL
);
8970 ok( found
!= NULL
, "found is NULL, expected a valid hwnd\n" );
8973 static void test_FindWindow(void)
8977 hwnd
= CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP
, 0,0,0,0, 0, 0, 0, NULL
);
8978 ok( hwnd
!= 0, "CreateWindowExA error %d\n", GetLastError() );
8980 num_gettext_msgs
= 0;
8981 found
= FindWindowA( "ClassThatDoesntExist", "" );
8982 ok( found
== NULL
, "expected a NULL hwnd\n" );
8983 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
8985 num_gettext_msgs
= 0;
8986 found
= FindWindowA( "ClassThatDoesntExist", NULL
);
8987 ok( found
== NULL
, "expected a NULL hwnd\n" );
8988 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
8990 num_gettext_msgs
= 0;
8991 found
= FindWindowA( "MainWindowClass", "" );
8992 ok( found
== NULL
, "expected a NULL hwnd\n" );
8993 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
8995 num_gettext_msgs
= 0;
8996 found
= FindWindowA( "MainWindowClass", NULL
);
8997 ok( found
== hwnd
, "found is %p, expected a valid hwnd\n", found
);
8998 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
9000 num_gettext_msgs
= 0;
9001 found
= FindWindowA( "MainWindowClass", "caption" );
9002 ok( found
== hwnd
, "found is %p, expected a valid hwnd\n", found
);
9003 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
9005 DestroyWindow( hwnd
);
9007 hwnd
= CreateWindowExA( 0, "MainWindowClass", NULL
, WS_POPUP
, 0,0,0,0, 0, 0, 0, NULL
);
9008 ok( hwnd
!= 0, "CreateWindowExA error %d\n", GetLastError() );
9010 num_gettext_msgs
= 0;
9011 found
= FindWindowA( "MainWindowClass", "" );
9012 ok( found
== hwnd
, "found is %p, expected a valid hwnd\n", found
);
9013 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
9015 num_gettext_msgs
= 0;
9016 found
= FindWindowA( "MainWindowClass", NULL
);
9017 ok( found
== hwnd
, "found is %p, expected a valid hwnd\n", found
);
9018 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
9020 DestroyWindow( hwnd
);
9022 /* test behaviour with a window title that is an empty character */
9023 found
= FindWindowA( "Shell_TrayWnd", "" );
9024 ok( found
!= NULL
, "found is NULL, expected a valid hwnd\n" );
9025 found
= FindWindowA( "Shell_TrayWnd", NULL
);
9026 ok( found
!= NULL
, "found is NULL, expected a valid hwnd\n" );
9029 static void test_GetLastActivePopup(void)
9031 HWND hwndOwner
, hwndPopup1
, hwndPopup2
;
9033 hwndOwner
= CreateWindowExA(0, "MainWindowClass", NULL
,
9034 WS_VISIBLE
| WS_POPUPWINDOW
,
9036 NULL
, 0, GetModuleHandleA(NULL
), NULL
);
9037 hwndPopup1
= CreateWindowExA(0, "MainWindowClass", NULL
,
9038 WS_VISIBLE
| WS_POPUPWINDOW
,
9040 hwndOwner
, 0, GetModuleHandleA(NULL
), NULL
);
9041 hwndPopup2
= CreateWindowExA(0, "MainWindowClass", NULL
,
9042 WS_VISIBLE
| WS_POPUPWINDOW
,
9044 hwndPopup1
, 0, GetModuleHandleA(NULL
), NULL
);
9045 ok( GetLastActivePopup(hwndOwner
) == hwndPopup2
, "wrong last active popup\n" );
9046 DestroyWindow( hwndPopup2
);
9047 DestroyWindow( hwndPopup1
);
9048 DestroyWindow( hwndOwner
);
9051 static LRESULT WINAPI
my_httrasparent_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
9053 if (msg
== WM_NCHITTEST
) return HTTRANSPARENT
;
9054 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
9057 static LRESULT WINAPI
my_window_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
9059 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
9062 static void create_window_tree(HWND parent
, HWND
*window
, int size
)
9064 static const DWORD style
[] = { 0, WS_VISIBLE
, WS_DISABLED
, WS_VISIBLE
| WS_DISABLED
};
9067 memset(window
, 0, size
* sizeof(window
[0]));
9070 for (i
= 0; i
< ARRAY_SIZE(style
); i
++)
9073 window
[pos
] = CreateWindowExA(0, "my_window", NULL
, style
[i
] | WS_CHILD
,
9074 0, 0, 100, 100, parent
, 0, 0, NULL
);
9075 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
9078 window
[pos
] = CreateWindowExA(WS_EX_TRANSPARENT
, "my_window", NULL
, style
[i
] | WS_CHILD
,
9079 0, 0, 100, 100, parent
, 0, 0, NULL
);
9080 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
9084 window
[pos
] = CreateWindowExA(0, "my_httrasparent", NULL
, style
[i
] | WS_CHILD
,
9085 0, 0, 100, 100, parent
, 0, 0, NULL
);
9086 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
9089 window
[pos
] = CreateWindowExA(WS_EX_TRANSPARENT
, "my_httrasparent", NULL
, style
[i
] | WS_CHILD
,
9090 0, 0, 100, 100, parent
, 0, 0, NULL
);
9091 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
9095 window
[pos
] = CreateWindowExA(0, "my_button", NULL
, style
[i
] | WS_CHILD
| BS_GROUPBOX
,
9096 0, 0, 100, 100, parent
, 0, 0, NULL
);
9097 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
9100 window
[pos
] = CreateWindowExA(WS_EX_TRANSPARENT
, "my_button", NULL
, style
[i
] | WS_CHILD
| BS_GROUPBOX
,
9101 0, 0, 100, 100, parent
, 0, 0, NULL
);
9102 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
9105 window
[pos
] = CreateWindowExA(0, "my_button", NULL
, style
[i
] | WS_CHILD
| BS_PUSHBUTTON
,
9106 0, 0, 100, 100, parent
, 0, 0, NULL
);
9107 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
9110 window
[pos
] = CreateWindowExA(WS_EX_TRANSPARENT
, "my_button", NULL
, style
[i
] | WS_CHILD
| BS_PUSHBUTTON
,
9111 0, 0, 100, 100, parent
, 0, 0, NULL
);
9112 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
9116 window
[pos
] = CreateWindowExA(0, "Button", NULL
, style
[i
] | WS_CHILD
| BS_GROUPBOX
,
9117 0, 0, 100, 100, parent
, 0, 0, NULL
);
9118 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
9121 window
[pos
] = CreateWindowExA(WS_EX_TRANSPARENT
, "Button", NULL
, style
[i
] | WS_CHILD
| BS_GROUPBOX
,
9122 0, 0, 100, 100, parent
, 0, 0, NULL
);
9123 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
9126 window
[pos
] = CreateWindowExA(0, "Button", NULL
, style
[i
] | WS_CHILD
| BS_PUSHBUTTON
,
9127 0, 0, 100, 100, parent
, 0, 0, NULL
);
9128 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
9131 window
[pos
] = CreateWindowExA(WS_EX_TRANSPARENT
, "Button", NULL
, style
[i
] | WS_CHILD
| BS_PUSHBUTTON
,
9132 0, 0, 100, 100, parent
, 0, 0, NULL
);
9133 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
9137 window
[pos
] = CreateWindowExA(0, "Static", NULL
, style
[i
] | WS_CHILD
,
9138 0, 0, 100, 100, parent
, 0, 0, NULL
);
9139 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
9142 window
[pos
] = CreateWindowExA(WS_EX_TRANSPARENT
, "Static", NULL
, style
[i
] | WS_CHILD
,
9143 0, 0, 100, 100, parent
, 0, 0, NULL
);
9144 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
9149 struct window_attributes
9151 char class_name
[128];
9152 BOOL is_visible
, is_enabled
, is_groupbox
, is_httransparent
, is_extransparent
;
9155 static void get_window_attributes(HWND hwnd
, struct window_attributes
*attrs
)
9157 DWORD style
, ex_style
, hittest
;
9159 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
9160 ex_style
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
9161 attrs
->class_name
[0] = 0;
9162 GetClassNameA(hwnd
, attrs
->class_name
, sizeof(attrs
->class_name
));
9163 hittest
= SendMessageA(hwnd
, WM_NCHITTEST
, 0, 0);
9165 attrs
->is_visible
= (style
& WS_VISIBLE
) != 0;
9166 attrs
->is_enabled
= (style
& WS_DISABLED
) == 0;
9167 attrs
->is_groupbox
= !lstrcmpiA(attrs
->class_name
, "Button") && (style
& BS_TYPEMASK
) == BS_GROUPBOX
;
9168 attrs
->is_httransparent
= hittest
== HTTRANSPARENT
;
9169 attrs
->is_extransparent
= (ex_style
& WS_EX_TRANSPARENT
) != 0;
9172 static int window_to_index(HWND hwnd
, HWND
*window
, int size
)
9176 for (i
= 0; i
< size
; i
++)
9178 if (!window
[i
]) break;
9179 if (window
[i
] == hwnd
) return i
;
9184 static void test_child_window_from_point(void)
9186 static const int real_child_pos
[] = { 14,15,16,17,18,19,20,21,24,25,26,27,42,43,
9187 44,45,46,47,48,49,52,53,54,55,51,50,23,22,-1 };
9189 HWND hwnd
, parent
, window
[100];
9191 int found_invisible
, found_disabled
, found_groupbox
, found_httransparent
, found_extransparent
;
9194 ret
= GetClassInfoA(0, "Button", &cls
);
9195 ok(ret
, "GetClassInfo(Button) failed\n");
9196 cls
.lpszClassName
= "my_button";
9197 ret
= RegisterClassA(&cls
);
9198 ok(ret
, "RegisterClass(my_button) failed\n");
9200 cls
.lpszClassName
= "my_httrasparent";
9201 cls
.lpfnWndProc
= my_httrasparent_proc
;
9202 ret
= RegisterClassA(&cls
);
9203 ok(ret
, "RegisterClass(my_httrasparent) failed\n");
9205 cls
.lpszClassName
= "my_window";
9206 cls
.lpfnWndProc
= my_window_proc
;
9207 ret
= RegisterClassA(&cls
);
9208 ok(ret
, "RegisterClass(my_window) failed\n");
9210 parent
= CreateWindowExA(0, "MainWindowClass", NULL
,
9211 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_POPUP
| WS_VISIBLE
,
9213 0, 0, GetModuleHandleA(NULL
), NULL
);
9214 ok(parent
!= 0, "CreateWindowEx failed\n");
9215 trace("parent %p\n", parent
);
9217 create_window_tree(parent
, window
, ARRAY_SIZE(window
));
9219 found_invisible
= 0;
9222 found_httransparent
= 0;
9223 found_extransparent
= 0;
9225 /* FIXME: also test WindowFromPoint, ChildWindowFromPoint, ChildWindowFromPointEx */
9226 for (i
= 0; i
< ARRAY_SIZE(real_child_pos
); i
++)
9228 struct window_attributes attrs
;
9231 hwnd
= RealChildWindowFromPoint(parent
, pt
);
9232 ok(hwnd
!= 0, "RealChildWindowFromPoint failed\n");
9233 ret
= window_to_index(hwnd
, window
, ARRAY_SIZE(window
));
9234 /* FIXME: remove once Wine is fixed */
9235 todo_wine_if (ret
!= real_child_pos
[i
])
9236 ok(ret
== real_child_pos
[i
], "expected %d, got %d\n", real_child_pos
[i
], ret
);
9238 get_window_attributes(hwnd
, &attrs
);
9239 if (!attrs
.is_visible
) found_invisible
++;
9240 if (!attrs
.is_enabled
) found_disabled
++;
9241 if (attrs
.is_groupbox
) found_groupbox
++;
9242 if (attrs
.is_httransparent
) found_httransparent
++;
9243 if (attrs
.is_extransparent
) found_extransparent
++;
9245 if (ret
!= real_child_pos
[i
] && ret
!= -1)
9247 trace("found hwnd %p (%s), is_visible %d, is_enabled %d, is_groupbox %d, is_httransparent %d, is_extransparent %d\n",
9248 hwnd
, attrs
.class_name
, attrs
.is_visible
, attrs
.is_enabled
, attrs
.is_groupbox
, attrs
.is_httransparent
, attrs
.is_extransparent
);
9249 get_window_attributes(window
[real_child_pos
[i
]], &attrs
);
9250 trace("expected hwnd %p (%s), is_visible %d, is_enabled %d, is_groupbox %d, is_httransparent %d, is_extransparent %d\n",
9251 window
[real_child_pos
[i
]], attrs
.class_name
, attrs
.is_visible
, attrs
.is_enabled
, attrs
.is_groupbox
, attrs
.is_httransparent
, attrs
.is_extransparent
);
9255 ok(hwnd
== parent
, "expected %p, got %p\n", parent
, hwnd
);
9258 DestroyWindow(hwnd
);
9261 DestroyWindow(parent
);
9263 ok(!found_invisible
, "found %d invisible windows\n", found_invisible
);
9264 ok(found_disabled
, "found %d disabled windows\n", found_disabled
);
9266 ok(found_groupbox
== 4, "found %d groupbox windows\n", found_groupbox
);
9267 ok(found_httransparent
, "found %d httransparent windows\n", found_httransparent
);
9269 ok(found_extransparent
, "found %d extransparent windows\n", found_extransparent
);
9271 ret
= UnregisterClassA("my_button", cls
.hInstance
);
9272 ok(ret
, "UnregisterClass(my_button) failed\n");
9273 ret
= UnregisterClassA("my_httrasparent", cls
.hInstance
);
9274 ok(ret
, "UnregisterClass(my_httrasparent) failed\n");
9275 ret
= UnregisterClassA("my_window", cls
.hInstance
);
9276 ok(ret
, "UnregisterClass(my_window) failed\n");
9279 static void simulate_click(int x
, int y
)
9285 memset(input
, 0, sizeof(input
));
9286 input
[0].type
= INPUT_MOUSE
;
9287 U(input
[0]).mi
.dx
= x
;
9288 U(input
[0]).mi
.dy
= y
;
9289 U(input
[0]).mi
.dwFlags
= MOUSEEVENTF_LEFTDOWN
;
9290 input
[1].type
= INPUT_MOUSE
;
9291 U(input
[1]).mi
.dx
= x
;
9292 U(input
[1]).mi
.dy
= y
;
9293 U(input
[1]).mi
.dwFlags
= MOUSEEVENTF_LEFTUP
;
9294 events_no
= SendInput(2, input
, sizeof(input
[0]));
9295 ok(events_no
== 2, "SendInput returned %d\n", events_no
);
9298 static WNDPROC def_static_proc
;
9299 static BOOL got_hittest
;
9300 static LRESULT WINAPI
static_hook_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
9302 if(msg
== WM_NCHITTEST
)
9304 if(msg
== WM_LBUTTONDOWN
)
9305 ok(0, "unexpected call\n");
9307 return def_static_proc(hwnd
, msg
, wp
, lp
);
9310 static void window_from_point_proc(HWND parent
)
9312 HANDLE start_event
, end_event
;
9313 HANDLE win
, child_static
, child_button
;
9319 start_event
= OpenEventA(EVENT_ALL_ACCESS
, FALSE
, "test_wfp_start");
9320 ok(start_event
!= 0, "OpenEvent failed\n");
9321 end_event
= OpenEventA(EVENT_ALL_ACCESS
, FALSE
, "test_wfp_end");
9322 ok(end_event
!= 0, "OpenEvent failed\n");
9324 child_static
= CreateWindowExA(0, "static", "static", WS_CHILD
| WS_VISIBLE
,
9325 0, 0, 100, 100, parent
, 0, NULL
, NULL
);
9326 ok(child_static
!= 0, "CreateWindowEx failed\n");
9328 win
= WindowFromPoint(pt
);
9329 ok(win
== parent
, "WindowFromPoint returned %p, expected %p\n", win
, parent
);
9331 child_button
= CreateWindowExA(0, "button", "button", WS_CHILD
| WS_VISIBLE
,
9332 100, 0, 100, 100, parent
, 0, NULL
, NULL
);
9333 ok(child_button
!= 0, "CreateWindowEx failed\n");
9335 win
= WindowFromPoint(pt
);
9336 ok(win
== child_button
, "WindowFromPoint returned %p, expected %p\n", win
, child_button
);
9338 /* without this window simulate click test keeps sending WM_NCHITTEST
9339 * message to child_static in an infinite loop */
9340 win
= CreateWindowExA(0, "button", "button", WS_CHILD
| WS_VISIBLE
,
9341 0, 0, 100, 100, parent
, 0, NULL
, NULL
);
9342 ok(win
!= 0, "CreateWindowEx failed\n");
9343 def_static_proc
= (void*)SetWindowLongPtrA(child_static
,
9344 GWLP_WNDPROC
, (LONG_PTR
)static_hook_proc
);
9346 SetEvent(start_event
);
9348 got_hittest
= FALSE
;
9350 while(!got_click
&& wait_for_message(&msg
)) {
9351 if(msg
.message
== WM_LBUTTONUP
) {
9352 ok(msg
.hwnd
== win
, "msg.hwnd = %p, expected %p\n", msg
.hwnd
, win
);
9355 DispatchMessageA(&msg
);
9357 ok(got_hittest
, "transparent window didn't get WM_NCHITTEST message\n");
9358 ok(got_click
, "button under static window didn't get WM_LBUTTONUP\n");
9360 ret
= WaitForSingleObject(end_event
, 5000);
9361 ok(ret
== WAIT_OBJECT_0
, "WaitForSingleObject returned %x\n", ret
);
9363 CloseHandle(start_event
);
9364 CloseHandle(end_event
);
9367 static void test_window_from_point(const char *argv0
)
9369 HWND hwnd
, child
, win
;
9371 PROCESS_INFORMATION info
;
9372 STARTUPINFOA startup
;
9374 HANDLE start_event
, end_event
;
9376 hwnd
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_POPUP
| WS_VISIBLE
,
9377 100, 100, 200, 100, 0, 0, NULL
, NULL
);
9378 ok(hwnd
!= 0, "CreateWindowEx failed\n");
9381 win
= WindowFromPoint(pt
);
9384 win
= WindowFromPoint(pt
);
9386 skip("there's another window covering test window\n");
9387 DestroyWindow(hwnd
);
9391 child
= CreateWindowExA(0, "static", "static", WS_CHILD
| WS_VISIBLE
,
9392 0, 0, 100, 100, hwnd
, 0, NULL
, NULL
);
9393 ok(child
!= 0, "CreateWindowEx failed\n");
9395 win
= WindowFromPoint(pt
);
9396 ok(win
== hwnd
, "WindowFromPoint returned %p, expected %p\n", win
, hwnd
);
9397 DestroyWindow(child
);
9399 child
= CreateWindowExA(0, "button", "button", WS_CHILD
| WS_VISIBLE
,
9400 0, 0, 100, 100, hwnd
, 0, NULL
, NULL
);
9401 ok(child
!= 0, "CreateWindowEx failed\n");
9402 win
= WindowFromPoint(pt
);
9403 ok(win
== child
, "WindowFromPoint returned %p, expected %p\n", win
, child
);
9404 DestroyWindow(child
);
9406 start_event
= CreateEventA(NULL
, FALSE
, FALSE
, "test_wfp_start");
9407 ok(start_event
!= 0, "CreateEvent failed\n");
9408 end_event
= CreateEventA(NULL
, FALSE
, FALSE
, "test_wfp_end");
9409 ok(start_event
!= 0, "CreateEvent failed\n");
9411 sprintf(cmd
, "%s win create_children %p\n", argv0
, hwnd
);
9412 memset(&startup
, 0, sizeof(startup
));
9413 startup
.cb
= sizeof(startup
);
9414 ok(CreateProcessA(NULL
, cmd
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
,
9415 &startup
, &info
), "CreateProcess failed.\n");
9416 ok(wait_for_event(start_event
, 1000), "didn't get start_event\n");
9418 child
= GetWindow(hwnd
, GW_CHILD
);
9419 win
= WindowFromPoint(pt
);
9420 ok(win
== child
, "WindowFromPoint returned %p, expected %p\n", win
, child
);
9422 simulate_click(150, 150);
9425 child
= GetWindow(child
, GW_HWNDNEXT
);
9427 win
= WindowFromPoint(pt
);
9428 ok(win
== child
, "WindowFromPoint returned %p, expected %p\n", win
, child
);
9430 SetEvent(end_event
);
9431 wait_child_process(info
.hProcess
);
9432 CloseHandle(start_event
);
9433 CloseHandle(end_event
);
9434 CloseHandle(info
.hProcess
);
9435 CloseHandle(info
.hThread
);
9437 DestroyWindow(hwnd
);
9440 static void test_map_points(void)
9444 HWND wnd
, wnd0
, dwnd
;
9447 POINT pos
= { 100, 200 };
9453 /* Create test windows */
9454 wnd
= CreateWindowA("static", "test1", WS_POPUP
, pos
.x
, pos
.y
, width
, height
, NULL
, NULL
, NULL
, NULL
);
9455 ok(wnd
!= NULL
, "Failed %p\n", wnd
);
9456 wnd0
= CreateWindowA("static", "test2", WS_POPUP
, 0, 0, width
, height
, NULL
, NULL
, NULL
, NULL
);
9457 ok(wnd0
!= NULL
, "Failed %p\n", wnd
);
9458 dwnd
= CreateWindowA("static", "test3", 0, 200, 300, 150, 150, NULL
, NULL
, NULL
, NULL
);
9459 DestroyWindow(dwnd
);
9460 ok(dwnd
!= NULL
, "Failed %p\n", dwnd
);
9462 /* Verify window rect and client rect (they should have the same width and height) */
9463 GetWindowRect(wnd
, &window_rect
);
9464 ok(window_rect
.left
== pos
.x
, "left is %d instead of %d\n", window_rect
.left
, pos
.x
);
9465 ok(window_rect
.top
== pos
.y
, "top is %d instead of %d\n", window_rect
.top
, pos
.y
);
9466 ok(window_rect
.right
== pos
.x
+ width
, "right is %d instead of %d\n", window_rect
.right
, pos
.x
+ width
);
9467 ok(window_rect
.bottom
== pos
.y
+ height
, "bottom is %d instead of %d\n", window_rect
.bottom
, pos
.y
+ height
);
9468 GetClientRect(wnd
, &client_rect
);
9469 ok(client_rect
.left
== 0, "left is %d instead of 0\n", client_rect
.left
);
9470 ok(client_rect
.top
== 0, "top is %d instead of 0\n", client_rect
.top
);
9471 ok(client_rect
.right
== width
, "right is %d instead of %d\n", client_rect
.right
, width
);
9472 ok(client_rect
.bottom
== height
, "bottom is %d instead of %d\n", client_rect
.bottom
, height
);
9474 /* Test MapWindowPoints */
9476 /* MapWindowPoints(NULL or wnd, NULL or wnd, NULL, 1); crashes on Windows */
9478 SetLastError(0xdeadbeef);
9479 n
= MapWindowPoints(NULL
, NULL
, NULL
, 0);
9480 err
= GetLastError();
9481 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
9482 ok(err
== 0xdeadbeef, "Got %x, expected %x\n", err
, 0xdeadbeef);
9484 SetLastError(0xdeadbeef);
9485 n
= MapWindowPoints(wnd
, wnd
, NULL
, 0);
9486 err
= GetLastError();
9487 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
9488 ok(err
== 0xdeadbeef, "Got %x, expected %x\n", err
, 0xdeadbeef);
9490 n
= MapWindowPoints(wnd
, NULL
, NULL
, 0);
9491 ok(n
== MAKELONG(window_rect
.left
, window_rect
.top
), "Got %x, expected %x\n",
9492 n
, MAKELONG(window_rect
.left
, window_rect
.top
));
9494 n
= MapWindowPoints(NULL
, wnd
, NULL
, 0);
9495 ok(n
== MAKELONG(-window_rect
.left
, -window_rect
.top
), "Got %x, expected %x\n",
9496 n
, MAKELONG(-window_rect
.left
, -window_rect
.top
));
9498 SetLastError(0xdeadbeef);
9500 n
= MapWindowPoints(dwnd
, NULL
, &p
, 1);
9501 err
= GetLastError();
9502 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
9503 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
9504 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
9506 SetLastError(0xdeadbeef);
9508 n
= MapWindowPoints(dwnd
, wnd
, &p
, 1);
9509 err
= GetLastError();
9510 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
9511 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
9512 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
9514 SetLastError(0xdeadbeef);
9516 n
= MapWindowPoints(NULL
, dwnd
, &p
, 1);
9517 err
= GetLastError();
9518 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
9519 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
9520 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
9522 SetLastError(0xdeadbeef);
9524 n
= MapWindowPoints(wnd
, dwnd
, &p
, 1);
9525 err
= GetLastError();
9526 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
9527 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
9528 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
9530 SetLastError(0xdeadbeef);
9532 n
= MapWindowPoints(dwnd
, dwnd
, &p
, 1);
9533 err
= GetLastError();
9534 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
9535 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
9536 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
9538 SetLastError(0xdeadbeef);
9540 n
= MapWindowPoints(NULL
, NULL
, &p
, 1);
9541 err
= GetLastError();
9542 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
9543 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
9544 ok(err
== 0xdeadbeef, "Got %x, expected %x\n", err
, 0xdeadbeef);
9546 SetLastError(0xdeadbeef);
9548 n
= MapWindowPoints(wnd
, wnd
, &p
, 1);
9549 err
= GetLastError();
9550 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
9551 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
9552 ok(err
== 0xdeadbeef, "Got %x, expected %x\n", err
, 0xdeadbeef);
9555 n
= MapWindowPoints(wnd
, NULL
, &p
, 1);
9556 ok(n
== MAKELONG(window_rect
.left
, window_rect
.top
), "Got %x, expected %x\n",
9557 n
, MAKELONG(window_rect
.left
, window_rect
.top
));
9558 ok((p
.x
== (window_rect
.left
+ 100)) && (p
.y
== (window_rect
.top
+ 100)), "Failed got (%d, %d), expected (%d, %d)\n",
9559 p
.x
, p
.y
, window_rect
.left
+ 100, window_rect
.top
+ 100);
9562 n
= MapWindowPoints(NULL
, wnd
, &p
, 1);
9563 ok(n
== MAKELONG(-window_rect
.left
, -window_rect
.top
), "Got %x, expected %x\n",
9564 n
, MAKELONG(-window_rect
.left
, -window_rect
.top
));
9565 ok((p
.x
== (-window_rect
.left
+ 100)) && (p
.y
== (-window_rect
.top
+ 100)), "Failed got (%d, %d), expected (%d, %d)\n",
9566 p
.x
, p
.y
, -window_rect
.left
+ 100, -window_rect
.top
+ 100);
9568 SetLastError(0xdeadbeef);
9570 n
= MapWindowPoints(wnd0
, NULL
, &p
, 1);
9571 err
= GetLastError();
9572 ok(n
== 0, "Got %x, expected 0\n", n
);
9573 ok((p
.x
== 0) && (p
.y
== 0), "Failed got (%d, %d), expected (0, 0)\n", p
.x
, p
.y
);
9574 ok(err
== 0xdeadbeef, "Got %x, expected %x\n", err
, 0xdeadbeef);
9576 SetLastError(0xdeadbeef);
9578 n
= MapWindowPoints(NULL
, wnd0
, &p
, 1);
9579 err
= GetLastError();
9580 ok(n
== 0, "Got %x, expected 0\n", n
);
9581 ok((p
.x
== 0) && (p
.y
== 0), "Failed got (%d, %d), expected (0, 0)\n", p
.x
, p
.y
);
9582 ok(err
== 0xdeadbeef, "Got %x, expected %x\n", err
, 0xdeadbeef);
9584 /* Test ClientToScreen */
9586 /* ClientToScreen(wnd, NULL); crashes on Windows */
9588 SetLastError(0xdeadbeef);
9589 ret
= ClientToScreen(NULL
, NULL
);
9590 err
= GetLastError();
9591 ok(!ret
, "Should fail\n");
9592 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
9594 SetLastError(0xdeadbeef);
9596 ret
= ClientToScreen(NULL
, &p
);
9597 err
= GetLastError();
9598 ok(!ret
, "Should fail\n");
9599 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
9600 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
9602 SetLastError(0xdeadbeef);
9604 ret
= ClientToScreen(dwnd
, &p
);
9605 err
= GetLastError();
9606 ok(!ret
, "Should fail\n");
9607 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
9608 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
9611 ret
= ClientToScreen(wnd
, &p
);
9612 ok(ret
, "Failed with error %u\n", GetLastError());
9613 ok((p
.x
== (window_rect
.left
+ 100)) && (p
.y
== (window_rect
.top
+ 100)), "Failed got (%d, %d), expected (%d, %d)\n",
9614 p
.x
, p
.y
, window_rect
.left
+ 100, window_rect
.top
+ 100);
9617 ret
= ClientToScreen(wnd0
, &p
);
9618 ok(ret
, "Failed with error %u\n", GetLastError());
9619 ok((p
.x
== 0) && (p
.y
== 0), "Failed got (%d, %d), expected (0, 0)\n", p
.x
, p
.y
);
9621 /* Test ScreenToClient */
9623 /* ScreenToClient(wnd, NULL); crashes on Windows */
9625 SetLastError(0xdeadbeef);
9626 ret
= ScreenToClient(NULL
, NULL
);
9627 err
= GetLastError();
9628 ok(!ret
, "Should fail\n");
9629 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
9631 SetLastError(0xdeadbeef);
9633 ret
= ScreenToClient(NULL
, &p
);
9634 err
= GetLastError();
9635 ok(!ret
, "Should fail\n");
9636 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
9637 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
9639 SetLastError(0xdeadbeef);
9641 ret
= ScreenToClient(dwnd
, &p
);
9642 err
= GetLastError();
9643 ok(!ret
, "Should fail\n");
9644 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
9645 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
9648 ret
= ScreenToClient(wnd
, &p
);
9649 ok(ret
, "Failed with error %u\n", GetLastError());
9650 ok((p
.x
== (-window_rect
.left
+ 100)) && (p
.y
== (-window_rect
.top
+ 100)), "Failed got(%d, %d), expected (%d, %d)\n",
9651 p
.x
, p
.y
, -window_rect
.left
+ 100, -window_rect
.top
+ 100);
9654 ret
= ScreenToClient(wnd0
, &p
);
9655 ok(ret
, "Failed with error %u\n", GetLastError());
9656 ok((p
.x
== 0) && (p
.y
== 0), "Failed got (%d, %d), expected (0, 0)\n", p
.x
, p
.y
);
9659 DestroyWindow(wnd0
);
9662 static void test_update_region(void)
9664 HWND hwnd
, parent
, child
;
9666 const RECT rc
= {15, 15, 40, 40};
9667 const POINT wnd_orig
= {30, 20};
9668 const POINT child_orig
= {10, 5};
9670 parent
= CreateWindowExA(0, "MainWindowClass", NULL
,
9671 WS_VISIBLE
| WS_CLIPCHILDREN
,
9672 0, 0, 300, 150, NULL
, NULL
, GetModuleHandleA(0), 0);
9673 hwnd
= CreateWindowExA(0, "MainWindowClass", NULL
,
9674 WS_VISIBLE
| WS_CLIPCHILDREN
| WS_CHILD
,
9675 0, 0, 200, 100, parent
, NULL
, GetModuleHandleA(0), 0);
9676 child
= CreateWindowExA(0, "MainWindowClass", NULL
,
9677 WS_VISIBLE
| WS_CHILD
,
9678 child_orig
.x
, child_orig
.y
, 100, 50,
9679 hwnd
, NULL
, GetModuleHandleA(0), 0);
9680 assert(parent
&& hwnd
&& child
);
9682 ValidateRgn(parent
, NULL
);
9683 ValidateRgn(hwnd
, NULL
);
9684 InvalidateRect(hwnd
, &rc
, FALSE
);
9685 ValidateRgn(child
, NULL
);
9687 rgn1
= CreateRectRgn(0, 0, 0, 0);
9688 ok(GetUpdateRgn(parent
, rgn1
, FALSE
) == NULLREGION
,
9689 "has invalid area after ValidateRgn(NULL)\n");
9690 GetUpdateRgn(hwnd
, rgn1
, FALSE
);
9691 rgn2
= CreateRectRgnIndirect(&rc
);
9692 ok(EqualRgn(rgn1
, rgn2
), "assigned and retrieved update regions are different\n");
9693 ok(GetUpdateRgn(child
, rgn2
, FALSE
) == NULLREGION
,
9694 "has invalid area after ValidateRgn(NULL)\n");
9696 SetWindowPos(hwnd
, 0, wnd_orig
.x
, wnd_orig
.y
, 0, 0,
9697 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOSIZE
);
9699 /* parent now has non-simple update region, it consist of
9700 * two rects, that was exposed after hwnd moving ... */
9701 SetRectRgn(rgn1
, 0, 0, 200, wnd_orig
.y
);
9702 SetRectRgn(rgn2
, 0, 0, wnd_orig
.x
, 100);
9703 CombineRgn(rgn1
, rgn1
, rgn2
, RGN_OR
);
9704 /* ... and mapped hwnd's invalid area, that hwnd has before moving */
9705 SetRectRgn(rgn2
, rc
.left
+ wnd_orig
.x
, rc
.top
+ wnd_orig
.y
,
9706 rc
.right
+ wnd_orig
.x
, rc
.bottom
+ wnd_orig
.y
);
9707 CombineRgn(rgn1
, rgn1
, rgn2
, RGN_OR
);
9708 GetUpdateRgn(parent
, rgn2
, FALSE
);
9710 ok(EqualRgn(rgn1
, rgn2
), "wrong update region\n");
9712 /* hwnd has the same invalid region as before moving */
9713 SetRectRgn(rgn1
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
9714 GetUpdateRgn(hwnd
, rgn2
, FALSE
);
9715 ok(EqualRgn(rgn1
, rgn2
), "wrong update region\n");
9717 /* hwnd's invalid area maps to child during moving */
9718 SetRectRgn(rgn1
, rc
.left
- child_orig
.x
, rc
.top
- child_orig
.y
,
9719 rc
.right
- child_orig
.x
, rc
.bottom
- child_orig
.y
);
9720 GetUpdateRgn(child
, rgn2
, FALSE
);
9722 ok(EqualRgn(rgn1
, rgn2
), "wrong update region\n");
9726 DestroyWindow(parent
);
9729 static void test_window_without_child_style(void)
9733 hwnd
= CreateWindowExA(0, "edit", NULL
, WS_VISIBLE
|WS_CHILD
,
9734 0, 0, 50, 50, hwndMain
, NULL
, 0, NULL
);
9735 ok(hwnd
!= NULL
, "CreateWindow failed\n");
9737 ok(SetWindowLongA(hwnd
, GWL_STYLE
, GetWindowLongA(hwnd
, GWL_STYLE
) & (~WS_CHILD
)),
9738 "can't remove WS_CHILD style\n");
9740 SetActiveWindow(hwndMain
);
9741 PostMessageW(hwnd
, WM_LBUTTONUP
, 0, 0);
9742 SendMessageW(hwnd
, WM_NCLBUTTONDOWN
, HTCAPTION
, 0);
9743 check_active_state(hwnd
, hwnd
, hwnd
);
9746 DestroyWindow(hwnd
);
9750 struct smresult_thread_data
9754 HANDLE thread_started
;
9755 HANDLE thread_got_wm_app
;
9756 HANDLE main_in_wm_app_1
;
9757 HANDLE thread_replied
;
9761 static LRESULT WINAPI
smresult_wndproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
9767 struct smresult_thread_data
*data
= (struct smresult_thread_data
*)lparam
;
9769 ok(hwnd
== data
->thread_hwnd
, "unexpected hwnd %p\n", hwnd
);
9771 SendNotifyMessageA(data
->main_hwnd
, WM_APP
+1, 0, lparam
);
9773 /* Don't return until the main thread is processing our sent message. */
9774 ok(WaitForSingleObject(data
->main_in_wm_app_1
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
9776 /* Break the PeekMessage loop so we can notify the main thread after we return. */
9777 SetEvent(data
->thread_got_wm_app
);
9783 struct smresult_thread_data
*data
= (struct smresult_thread_data
*)lparam
;
9786 ok(hwnd
== data
->main_hwnd
, "unexpected hwnd %p\n", hwnd
);
9788 /* Ask the thread to reply to our WM_APP message. */
9789 SetEvent(data
->main_in_wm_app_1
);
9791 /* Wait until the thread has sent a reply. */
9792 ok(WaitForSingleObject(data
->thread_replied
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
9794 /* Send another message while we have a reply queued for the current one. */
9795 res
= SendMessageA(data
->thread_hwnd
, WM_APP
+2, 0, lparam
);
9796 ok(res
== 0x449b0190, "unexpected result %lx\n", res
);
9802 struct smresult_thread_data
*data
= (struct smresult_thread_data
*)lparam
;
9804 ok(hwnd
== data
->thread_hwnd
, "unexpected hwnd %p\n", hwnd
);
9806 /* Don't return until we know the main thread is processing sent messages. */
9807 SendMessageA(data
->main_hwnd
, WM_NULL
, 0, 0);
9815 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
9818 static DWORD WINAPI
smresult_thread_proc(void *param
)
9821 struct smresult_thread_data
*data
= param
;
9823 data
->thread_hwnd
= CreateWindowExA(0, "SmresultClass", "window caption text", WS_OVERLAPPEDWINDOW
,
9824 100, 100, 200, 200, 0, 0, 0, NULL
);
9825 ok(data
->thread_hwnd
!= 0, "Failed to create overlapped window\n");
9827 SetEvent(data
->thread_started
);
9829 /* Loop until we've processed WM_APP. */
9830 while (WaitForSingleObject(data
->thread_got_wm_app
, 0) != WAIT_OBJECT_0
)
9832 if (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
9834 TranslateMessage(&msg
);
9835 DispatchMessageA(&msg
);
9839 MsgWaitForMultipleObjects(1, &data
->thread_got_wm_app
, FALSE
, INFINITE
, QS_SENDMESSAGE
);
9843 /* Notify the main thread that we replied to its WM_APP message. */
9844 SetEvent(data
->thread_replied
);
9846 while (GetMessageA(&msg
, 0, 0, 0))
9848 TranslateMessage(&msg
);
9849 DispatchMessageA(&msg
);
9855 static void test_smresult(void)
9860 struct smresult_thread_data data
;
9864 cls
.style
= CS_DBLCLKS
;
9865 cls
.lpfnWndProc
= smresult_wndproc
;
9868 cls
.hInstance
= GetModuleHandleA(0);
9870 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
9871 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
9872 cls
.lpszMenuName
= NULL
;
9873 cls
.lpszClassName
= "SmresultClass";
9875 ret
= RegisterClassA(&cls
);
9876 ok(ret
, "RegisterClassA failed\n");
9878 data
.thread_started
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
9879 ok(data
.thread_started
!= NULL
, "CreateEventA failed\n");
9881 data
.thread_got_wm_app
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
9882 ok(data
.thread_got_wm_app
!= NULL
, "CreateEventA failed\n");
9884 data
.main_in_wm_app_1
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
9885 ok(data
.main_in_wm_app_1
!= NULL
, "CreateEventA failed\n");
9887 data
.thread_replied
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
9888 ok(data
.thread_replied
!= NULL
, "CreateEventA failed\n");
9890 data
.main_hwnd
= CreateWindowExA(0, "SmresultClass", "window caption text", WS_OVERLAPPEDWINDOW
,
9891 100, 100, 200, 200, 0, 0, 0, NULL
);
9893 hThread
= CreateThread(NULL
, 0, smresult_thread_proc
, &data
, 0, &tid
);
9894 ok(hThread
!= NULL
, "CreateThread failed, error %d\n", GetLastError());
9896 ok(WaitForSingleObject(data
.thread_started
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
9898 res
= SendMessageA(data
.thread_hwnd
, WM_APP
, 0, (LPARAM
)&data
);
9899 ok(res
== 0x240408ea, "unexpected result %lx\n", res
);
9901 SendMessageA(data
.thread_hwnd
, WM_CLOSE
, 0, 0);
9903 DestroyWindow(data
.main_hwnd
);
9905 ok(WaitForSingleObject(hThread
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
9907 CloseHandle(data
.thread_started
);
9908 CloseHandle(data
.thread_got_wm_app
);
9909 CloseHandle(data
.main_in_wm_app_1
);
9910 CloseHandle(data
.thread_replied
);
9911 CloseHandle(hThread
);
9914 static void test_GetMessagePos(void)
9920 button
= CreateWindowExA(0, "button", "button", WS_VISIBLE
,
9921 100, 100, 100, 100, 0, 0, 0, NULL
);
9922 ok(button
!= 0, "CreateWindowExA failed\n");
9924 SetCursorPos(120, 140);
9926 pos
= GetMessagePos();
9927 ok(pos
== MAKELONG(120, 140), "pos = %08x\n", pos
);
9929 SetCursorPos(340, 320);
9930 pos
= GetMessagePos();
9931 ok(pos
== MAKELONG(120, 140), "pos = %08x\n", pos
);
9933 SendMessageW(button
, WM_APP
, 0, 0);
9934 pos
= GetMessagePos();
9935 ok(pos
== MAKELONG(120, 140), "pos = %08x\n", pos
);
9937 PostMessageA(button
, WM_APP
, 0, 0);
9938 GetMessageA(&msg
, button
, 0, 0);
9939 ok(msg
.message
== WM_APP
, "msg.message = %x\n", msg
.message
);
9940 pos
= GetMessagePos();
9941 ok(pos
== MAKELONG(340, 320), "pos = %08x\n", pos
);
9943 PostMessageA(button
, WM_APP
, 0, 0);
9944 SetCursorPos(350, 330);
9945 GetMessageA(&msg
, button
, 0, 0);
9946 ok(msg
.message
== WM_APP
, "msg.message = %x\n", msg
.message
);
9947 pos
= GetMessagePos();
9948 ok(pos
== MAKELONG(340, 320), "pos = %08x\n", pos
);
9950 PostMessageA(button
, WM_APP
, 0, 0);
9951 SetCursorPos(320, 340);
9952 PostMessageA(button
, WM_APP
+1, 0, 0);
9953 pos
= GetMessagePos();
9954 ok(pos
== MAKELONG(340, 320), "pos = %08x\n", pos
);
9955 GetMessageA(&msg
, button
, 0, 0);
9956 ok(msg
.message
== WM_APP
, "msg.message = %x\n", msg
.message
);
9957 pos
= GetMessagePos();
9958 ok(pos
== MAKELONG(350, 330), "pos = %08x\n", pos
);
9959 GetMessageA(&msg
, button
, 0, 0);
9960 ok(msg
.message
== WM_APP
+1, "msg.message = %x\n", msg
.message
);
9961 pos
= GetMessagePos();
9962 ok(pos
== MAKELONG(320, 340), "pos = %08x\n", pos
);
9964 SetTimer(button
, 1, 250, NULL
);
9965 SetCursorPos(330, 350);
9966 GetMessageA(&msg
, button
, 0, 0);
9967 while (msg
.message
== WM_PAINT
)
9969 UpdateWindow( button
);
9970 GetMessageA(&msg
, button
, 0, 0);
9972 ok(msg
.message
== WM_TIMER
, "msg.message = %x\n", msg
.message
);
9973 pos
= GetMessagePos();
9974 ok(pos
== MAKELONG(330, 350), "pos = %08x\n", pos
);
9975 KillTimer(button
, 1);
9977 DestroyWindow(button
);
9980 #define SET_FOREGROUND_STEAL_1 0x01
9981 #define SET_FOREGROUND_SET_1 0x02
9982 #define SET_FOREGROUND_STEAL_2 0x04
9983 #define SET_FOREGROUND_SET_2 0x08
9984 #define SET_FOREGROUND_INJECT 0x10
9986 struct set_foreground_thread_params
9988 UINT msg_quit
, msg_command
;
9989 HWND window1
, window2
, thread_window
;
9990 HANDLE command_executed
;
9993 static DWORD WINAPI
set_foreground_thread(void *params
)
9995 struct set_foreground_thread_params
*p
= params
;
9998 p
->thread_window
= CreateWindowExA(0, "static", "thread window", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
9999 0, 0, 10, 10, 0, 0, 0, NULL
);
10000 SetEvent(p
->command_executed
);
10002 while(GetMessageA(&msg
, 0, 0, 0))
10004 if (msg
.message
== p
->msg_quit
)
10007 if (msg
.message
== p
->msg_command
)
10009 if (msg
.wParam
& SET_FOREGROUND_STEAL_1
)
10011 SetForegroundWindow(p
->thread_window
);
10012 check_wnd_state(p
->thread_window
, p
->thread_window
, p
->thread_window
, 0);
10014 if (msg
.wParam
& SET_FOREGROUND_INJECT
)
10016 SendNotifyMessageA(p
->window1
, WM_ACTIVATEAPP
, 0, 0);
10018 if (msg
.wParam
& SET_FOREGROUND_SET_1
)
10020 SetForegroundWindow(p
->window1
);
10021 check_wnd_state(0, p
->window1
, 0, 0);
10023 if (msg
.wParam
& SET_FOREGROUND_STEAL_2
)
10025 SetForegroundWindow(p
->thread_window
);
10026 check_wnd_state(p
->thread_window
, p
->thread_window
, p
->thread_window
, 0);
10028 if (msg
.wParam
& SET_FOREGROUND_SET_2
)
10030 SetForegroundWindow(p
->window2
);
10031 check_wnd_state(0, p
->window2
, 0, 0);
10034 SetEvent(p
->command_executed
);
10038 TranslateMessage(&msg
);
10039 DispatchMessageA(&msg
);
10042 DestroyWindow(p
->thread_window
);
10046 static void test_activateapp(HWND window1
)
10048 HWND window2
, test_window
;
10050 struct set_foreground_thread_params thread_params
;
10054 window2
= CreateWindowExA(0, "static", "window 2", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
10055 300, 0, 10, 10, 0, 0, 0, NULL
);
10056 thread_params
.msg_quit
= WM_USER
;
10057 thread_params
.msg_command
= WM_USER
+ 1;
10058 thread_params
.window1
= window1
;
10059 thread_params
.window2
= window2
;
10060 thread_params
.command_executed
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
10062 thread
= CreateThread(NULL
, 0, set_foreground_thread
, &thread_params
, 0, &tid
);
10063 WaitForSingleObject(thread_params
.command_executed
, INFINITE
);
10065 SetForegroundWindow(window1
);
10066 check_wnd_state(window1
, window1
, window1
, 0);
10067 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
10069 /* Steal foreground: WM_ACTIVATEAPP(0) is delivered. */
10070 app_activated
= app_deactivated
= FALSE
;
10071 PostThreadMessageA(tid
, thread_params
.msg_command
, SET_FOREGROUND_STEAL_1
, 0);
10072 WaitForSingleObject(thread_params
.command_executed
, INFINITE
);
10073 test_window
= GetForegroundWindow();
10074 ok(test_window
== thread_params
.thread_window
, "Expected foreground window %p, got %p\n",
10075 thread_params
.thread_window
, test_window
);
10076 /* Active and Focus window are sometimes 0 on KDE. Ignore them.
10077 * check_wnd_state(window1, thread_params.thread_window, window1, 0); */
10078 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
10079 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
10080 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
10081 check_wnd_state(0, thread_params
.thread_window
, 0, 0);
10082 test_window
= GetForegroundWindow();
10083 ok(test_window
== thread_params
.thread_window
, "Expected foreground window %p, got %p\n",
10084 thread_params
.thread_window
, test_window
);
10085 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
10086 /* This message is reliable on Windows and inside a virtual desktop.
10087 * It is unreliable on KDE (50/50) and never arrives on FVWM.
10088 * ok(app_deactivated, "Expected WM_ACTIVATEAPP(0), did not receive it.\n"); */
10090 /* Set foreground: WM_ACTIVATEAPP (1) is delivered. */
10091 app_activated
= app_deactivated
= FALSE
;
10092 PostThreadMessageA(tid
, thread_params
.msg_command
, SET_FOREGROUND_SET_1
, 0);
10093 WaitForSingleObject(thread_params
.command_executed
, INFINITE
);
10094 check_wnd_state(0, 0, 0, 0);
10095 test_window
= GetForegroundWindow();
10096 ok(!test_window
, "Expected foreground window 0, got %p\n", test_window
);
10097 ok(!app_activated
, "Received WM_ACTIVATEAPP(!= 0), did not expect it.\n");
10098 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
10099 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
10100 check_wnd_state(window1
, window1
, window1
, 0);
10101 test_window
= GetForegroundWindow();
10102 ok(test_window
== window1
, "Expected foreground window %p, got %p\n",
10103 window1
, test_window
);
10104 ok(app_activated
, "Expected WM_ACTIVATEAPP(1), did not receive it.\n");
10105 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
10107 /* Steal foreground then set it back: No messages are delivered. */
10108 app_activated
= app_deactivated
= FALSE
;
10109 PostThreadMessageA(tid
, thread_params
.msg_command
, SET_FOREGROUND_STEAL_1
| SET_FOREGROUND_SET_1
, 0);
10110 WaitForSingleObject(thread_params
.command_executed
, INFINITE
);
10111 test_window
= GetForegroundWindow();
10112 ok(test_window
== window1
, "Expected foreground window %p, got %p\n",
10113 window1
, test_window
);
10114 check_wnd_state(window1
, window1
, window1
, 0);
10115 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
10116 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
10117 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
10118 test_window
= GetForegroundWindow();
10119 ok(test_window
== window1
, "Expected foreground window %p, got %p\n",
10120 window1
, test_window
);
10121 check_wnd_state(window1
, window1
, window1
, 0);
10122 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
10123 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
10125 /* This is not implemented with a plain WM_ACTIVATEAPP filter. */
10126 app_activated
= app_deactivated
= FALSE
;
10127 PostThreadMessageA(tid
, thread_params
.msg_command
, SET_FOREGROUND_STEAL_1
10128 | SET_FOREGROUND_INJECT
| SET_FOREGROUND_SET_1
, 0);
10129 WaitForSingleObject(thread_params
.command_executed
, INFINITE
);
10130 test_window
= GetForegroundWindow();
10131 ok(test_window
== window1
, "Expected foreground window %p, got %p\n",
10132 window1
, test_window
);
10133 check_wnd_state(window1
, window1
, window1
, 0);
10134 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
10135 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
10136 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
10137 test_window
= GetForegroundWindow();
10138 ok(test_window
== window1
, "Expected foreground window %p, got %p\n",
10139 window1
, test_window
);
10140 check_wnd_state(window1
, window1
, window1
, 0);
10141 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
10142 ok(app_deactivated
, "Expected WM_ACTIVATEAPP(0), did not receive it.\n");
10144 SetForegroundWindow(thread_params
.thread_window
);
10146 /* Set foreground then remove: Both messages are delivered. */
10147 app_activated
= app_deactivated
= FALSE
;
10148 PostThreadMessageA(tid
, thread_params
.msg_command
, SET_FOREGROUND_SET_1
| SET_FOREGROUND_STEAL_2
, 0);
10149 WaitForSingleObject(thread_params
.command_executed
, INFINITE
);
10150 test_window
= GetForegroundWindow();
10151 ok(test_window
== thread_params
.thread_window
, "Expected foreground window %p, got %p\n",
10152 thread_params
.thread_window
, test_window
);
10153 check_wnd_state(0, thread_params
.thread_window
, 0, 0);
10154 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
10155 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
10156 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
10157 test_window
= GetForegroundWindow();
10158 ok(test_window
== thread_params
.thread_window
, "Expected foreground window %p, got %p\n",
10159 thread_params
.thread_window
, test_window
);
10160 /* Active and focus are window1 on wine because the internal WM_WINE_SETACTIVEWINDOW(0)
10161 * message is never generated. GetCapture() returns 0 though, so we'd get a test success
10162 * in todo_wine in the line below.
10163 * todo_wine check_wnd_state(0, thread_params.thread_window, 0, 0); */
10164 ok(app_activated
, "Expected WM_ACTIVATEAPP(1), did not receive it.\n");
10165 todo_wine
ok(app_deactivated
, "Expected WM_ACTIVATEAPP(0), did not receive it.\n");
10167 SetForegroundWindow(window1
);
10168 test_window
= GetForegroundWindow();
10169 ok(test_window
== window1
, "Expected foreground window %p, got %p\n",
10170 window1
, test_window
);
10171 check_wnd_state(window1
, window1
, window1
, 0);
10173 /* Switch to a different window from the same thread? No messages. */
10174 app_activated
= app_deactivated
= FALSE
;
10175 PostThreadMessageA(tid
, thread_params
.msg_command
, SET_FOREGROUND_STEAL_1
| SET_FOREGROUND_SET_2
, 0);
10176 WaitForSingleObject(thread_params
.command_executed
, INFINITE
);
10177 test_window
= GetForegroundWindow();
10178 ok(test_window
== window1
, "Expected foreground window %p, got %p\n",
10179 window1
, test_window
);
10180 check_wnd_state(window1
, window1
, window1
, 0);
10181 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
10182 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
10183 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
10184 test_window
= GetForegroundWindow();
10185 ok(test_window
== window2
, "Expected foreground window %p, got %p\n",
10186 window2
, test_window
);
10187 check_wnd_state(window2
, window2
, window2
, 0);
10188 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
10189 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
10191 PostThreadMessageA(tid
, thread_params
.msg_quit
, 0, 0);
10192 WaitForSingleObject(thread
, INFINITE
);
10194 CloseHandle(thread_params
.command_executed
);
10195 DestroyWindow(window2
);
10198 static LRESULT WINAPI
winproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
10201 int *count
= (int*)lparam
;
10207 static LRESULT WINAPI
winproc_convA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
10209 if(msg
== WM_SETTEXT
)
10211 const char *text
= (const char*)lparam
;
10213 ok(!wparam
, "wparam = %08lx\n", wparam
);
10214 ok(!strcmp(text
, "text"), "WM_SETTEXT lparam = %s\n", text
);
10220 static const WCHAR textW
[] = {'t','e','x','t',0};
10221 static LRESULT WINAPI
winproc_convW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
10223 if(msg
== WM_SETTEXT
)
10225 const WCHAR
*text
= (const WCHAR
*)lparam
;
10227 ok(!wparam
, "wparam = %08lx\n", wparam
);
10228 ok(!lstrcmpW(text
, textW
), "WM_SETTEXT lparam = %s\n", wine_dbgstr_w(text
));
10234 static void test_winproc_handles(const char *argv0
)
10236 static const WCHAR winproc_testW
[] = {'w','i','n','p','r','o','c','_','t','e','s','t',0};
10238 HINSTANCE hinst
= GetModuleHandleA(NULL
);
10239 WNDCLASSA wnd_classA
;
10240 WNDCLASSW wnd_classW
;
10242 PROCESS_INFORMATION info
;
10243 STARTUPINFOA startup
;
10244 char cmd
[MAX_PATH
];
10246 memset(&wnd_classA
, 0, sizeof(wnd_classA
));
10247 wnd_classA
.lpszClassName
= "winproc_test";
10248 wnd_classA
.lpfnWndProc
= winproc
;
10249 ret
= RegisterClassA(&wnd_classA
);
10250 ok(ret
, "RegisterClass failed with error %d\n", GetLastError());
10252 ret
= GetClassInfoW(hinst
, winproc_testW
, &wnd_classW
);
10253 ok(ret
, "GetClassInfoW failed with error %d\n", GetLastError());
10254 ok(wnd_classA
.lpfnWndProc
!= wnd_classW
.lpfnWndProc
,
10255 "winproc pointers should not be identical\n");
10258 CallWindowProcA(wnd_classW
.lpfnWndProc
, 0, 0, 0, (LPARAM
)&count
);
10259 ok(count
== 1, "winproc should be called once (%d)\n", count
);
10261 CallWindowProcW(wnd_classW
.lpfnWndProc
, 0, 0, 0, (LPARAM
)&count
);
10262 ok(count
== 1, "winproc should be called once (%d)\n", count
);
10264 ret
= UnregisterClassW(winproc_testW
, hinst
);
10265 ok(ret
, "UnregisterClass failed with error %d\n", GetLastError());
10267 /* crashes on 64-bit windows because lpfnWndProc handle is already freed */
10268 if (sizeof(void*) == 4)
10271 CallWindowProcA(wnd_classW
.lpfnWndProc
, 0, 0, 0, (LPARAM
)&count
);
10272 todo_wine
ok(!count
, "winproc should not be called (%d)\n", count
);
10273 CallWindowProcW(wnd_classW
.lpfnWndProc
, 0, 0, 0, (LPARAM
)&count
);
10274 todo_wine
ok(!count
, "winproc should not be called (%d)\n", count
);
10277 sprintf(cmd
, "%s win winproc_limit", argv0
);
10278 memset(&startup
, 0, sizeof(startup
));
10279 startup
.cb
= sizeof(startup
);
10280 ok(CreateProcessA(NULL
, cmd
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
,
10281 &startup
, &info
), "CreateProcess failed.\n");
10282 wait_child_process(info
.hProcess
);
10283 CloseHandle(info
.hProcess
);
10284 CloseHandle(info
.hThread
);
10287 static void test_winproc_limit(void)
10289 WNDPROC winproc_handle
;
10294 hwnd
= CreateWindowExA(0, "static", "test", WS_POPUP
, 0, 0, 0, 0, 0, 0, 0, 0);
10295 ok(hwnd
!= 0, "CreateWindowEx failed\n");
10297 ok(SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)winproc
),
10298 "SetWindowLongPtr failed\n");
10299 winproc_handle
= (WNDPROC
)GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
);
10300 ok(winproc_handle
!= winproc
, "winproc pointers should not be identical\n");
10302 /* run out of winproc slots */
10303 for(i
= 2; i
<0xffff; i
++)
10305 ok(SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, i
), "SetWindowLongPtr failed (%d)\n", i
);
10306 if(GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == i
)
10309 ok(i
!= 0xffff, "unable to run out of winproc slots\n");
10311 ret
= SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)winproc_convA
);
10312 ok(ret
, "SetWindowLongPtr failed with error %d\n", GetLastError());
10313 ok(SendMessageA(hwnd
, WM_SETTEXT
, 0, (LPARAM
)"text"), "WM_SETTEXT failed\n");
10314 ok(SendMessageW(hwnd
, WM_SETTEXT
, 0, (LPARAM
)textW
), "WM_SETTEXT with conversion failed\n");
10316 ret
= SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)winproc_convW
);
10317 ok(ret
, "SetWindowLongPtr failed with error %d\n", GetLastError());
10318 ok(SendMessageA(hwnd
, WM_SETTEXT
, 0, (LPARAM
)"text"), "WM_SETTEXT failed\n");
10319 ok(SendMessageW(hwnd
, WM_SETTEXT
, 0, (LPARAM
)textW
), "WM_SETTEXT with conversion failed\n");
10321 /* Show that there's no message conversion when CallWindowProc is used */
10322 ok(CallWindowProcA(winproc_convW
, hwnd
, WM_SETTEXT
, 0, (LPARAM
)textW
) == 1,
10323 "winproc_convW returned error\n");
10324 ok(CallWindowProcW(winproc_convW
, hwnd
, WM_SETTEXT
, 0, (LPARAM
)textW
) == 1,
10325 "winproc_convW returned error\n");
10328 CallWindowProcA(winproc_handle
, 0, 0, 0, (LPARAM
)&i
);
10329 ok(i
== 1, "winproc should be called once (%d)\n", i
);
10331 CallWindowProcW(winproc_handle
, 0, 0, 0, (LPARAM
)&i
);
10332 ok(i
== 1, "winproc should be called once (%d)\n", i
);
10334 DestroyWindow(hwnd
);
10337 CallWindowProcA(winproc_handle
, 0, 0, 0, (LPARAM
)&i
);
10338 ok(i
== 1, "winproc should be called once (%d)\n", i
);
10340 CallWindowProcW(winproc_handle
, 0, 0, 0, (LPARAM
)&i
);
10341 ok(i
== 1, "winproc should be called once (%d)\n", i
);
10344 static void test_deferwindowpos(void)
10350 hdwp
= BeginDeferWindowPos(0);
10351 ok(hdwp
!= NULL
, "got %p\n", hdwp
);
10353 ret
= EndDeferWindowPos(NULL
);
10354 ok(!ret
, "got %d\n", ret
);
10356 hdwp2
= DeferWindowPos(NULL
, NULL
, NULL
, 0, 0, 10, 10, 0);
10358 ok(hdwp2
== NULL
&& ((GetLastError() == ERROR_INVALID_DWP_HANDLE
) ||
10359 broken(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
) /* before win8 */), "got %p, error %d\n", hdwp2
, GetLastError());
10361 hdwp2
= DeferWindowPos((HDWP
)0xdead, GetDesktopWindow(), NULL
, 0, 0, 10, 10, 0);
10363 ok(hdwp2
== NULL
&& ((GetLastError() == ERROR_INVALID_DWP_HANDLE
) ||
10364 broken(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
) /* before win8 */), "got %p, error %d\n", hdwp2
, GetLastError());
10366 hdwp2
= DeferWindowPos(hdwp
, NULL
, NULL
, 0, 0, 10, 10, 0);
10367 ok(hdwp2
== NULL
&& GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "got %p, error %d\n", hdwp2
, GetLastError());
10369 hdwp2
= DeferWindowPos(hdwp
, GetDesktopWindow(), NULL
, 0, 0, 10, 10, 0);
10370 ok(hdwp2
== NULL
&& GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "got %p, error %d\n", hdwp2
, GetLastError());
10372 hdwp2
= DeferWindowPos(hdwp
, (HWND
)0xdead, NULL
, 0, 0, 10, 10, 0);
10373 ok(hdwp2
== NULL
&& GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "got %p, error %d\n", hdwp2
, GetLastError());
10375 ret
= EndDeferWindowPos(hdwp
);
10376 ok(ret
, "got %d\n", ret
);
10377 hdwp
= BeginDeferWindowPos(0);
10378 ok(hdwp
!= NULL
, "got %p\n", hdwp
);
10380 hwnd
= create_tool_window(WS_POPUP
, 0);
10381 hdwp2
= DeferWindowPos(hdwp
, hwnd
, NULL
, 0, 0, 10, 10, 0);
10382 ok(hdwp2
!= NULL
, "got %p, error %d\n", hdwp2
, GetLastError());
10383 DestroyWindow(hwnd
);
10385 ret
= EndDeferWindowPos(hdwp
);
10386 ok(ret
, "got %d\n", ret
);
10389 static void test_LockWindowUpdate(HWND parent
)
10393 HWND hwnd_lock
, hwnd_draw
;
10394 BOOL allow_drawing
;
10399 HWND child
= CreateWindowA("static", 0, WS_CHILD
| WS_VISIBLE
, 0, 0, 20, 20, parent
, 0, 0, 0);
10402 {child
, child
, 0, 0},
10403 {child
, child
, 1, 1},
10404 {child
, parent
, 0, 1},
10405 {child
, parent
, 1, 1},
10406 {parent
, child
, 0, 0},
10407 {parent
, child
, 1, 1},
10408 {parent
, parent
, 0, 0},
10409 {parent
, parent
, 1, 1}
10414 skip("CreateWindow failed, skipping LockWindowUpdate tests\n");
10418 ShowWindow(parent
, SW_SHOW
);
10419 UpdateWindow(parent
);
10420 flush_events(TRUE
);
10422 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
10425 POINT p
= {10, 10};
10427 const DWORD dc_flags
= DCX_USESTYLE
| (tests
[i
].allow_drawing
? DCX_LOCKWINDOWUPDATE
: 0);
10428 const COLORREF c1
= 0x111100, c2
= 0x222200;
10430 hdc
= GetDCEx(tests
[i
].hwnd_draw
, 0, dc_flags
);
10432 #define TEST_PIXEL(c_valid, c_invalid) \
10434 COLORREF c = GetPixel(hdc, p.x, p.y); \
10435 COLORREF e = tests[i].expect_valid ? (c_valid) : (c_invalid); \
10436 todo_wine_if(!tests[i].expect_valid) \
10437 ok(c == e, "%u: GetPixel: got %08x, expected %08x\n", i, c, e); \
10440 SetPixel(hdc
, p
.x
, p
.y
, c1
);
10441 ret
= LockWindowUpdate(tests
[i
].hwnd_lock
);
10442 ok(ret
, "%u: LockWindowUpdate failed\n", i
);
10443 TEST_PIXEL(c1
, CLR_INVALID
);
10444 SetPixel(hdc
, p
.x
, p
.y
, c2
);
10445 TEST_PIXEL(c2
, CLR_INVALID
);
10446 LockWindowUpdate(0);
10447 TEST_PIXEL(c2
, c1
);
10448 ReleaseDC(tests
[i
].hwnd_draw
, hdc
);
10451 DestroyWindow(child
);
10454 static void test_hide_window(void)
10456 HWND hwnd
, hwnd2
, hwnd3
;
10458 hwnd
= CreateWindowExA(0, "MainWindowClass", "Main window", WS_POPUP
| WS_VISIBLE
,
10459 100, 100, 200, 200, 0, 0, GetModuleHandleA(NULL
), NULL
);
10460 hwnd2
= CreateWindowExA(0, "MainWindowClass", "Main window 2", WS_POPUP
| WS_VISIBLE
,
10461 100, 100, 200, 200, 0, 0, GetModuleHandleA(NULL
), NULL
);
10462 if (winetest_debug
> 1) trace("hwnd = %p, hwnd2 = %p\n", hwnd
, hwnd2
);
10463 check_active_state(hwnd2
, hwnd2
, hwnd2
);
10464 ok(GetWindow(hwnd2
, GW_HWNDNEXT
) == hwnd
, "expected %p, got %p\n", hwnd
, GetWindow(hwnd2
, GW_HWNDNEXT
));
10466 /* test hiding two normal windows */
10467 ShowWindow(hwnd2
, SW_HIDE
);
10468 check_active_state(hwnd
, hwnd
, hwnd
);
10470 ok(GetWindow(hwnd
, GW_HWNDNEXT
) == hwnd2
, "expected %p, got %p\n", hwnd2
, GetWindow(hwnd
, GW_HWNDNEXT
));
10472 ShowWindow(hwnd
, SW_HIDE
);
10473 check_active_state(hwndMain
, 0, hwndMain
);
10474 ok(GetWindow(hwnd
, GW_HWNDNEXT
) == hwnd2
, "expected %p, got %p\n", hwnd2
, GetWindow(hwnd
, GW_HWNDNEXT
));
10476 ShowWindow(hwnd
, SW_SHOW
);
10477 check_active_state(hwnd
, hwnd
, hwnd
);
10479 ShowWindow(hwnd2
, SW_SHOW
);
10480 check_active_state(hwnd2
, hwnd2
, hwnd2
);
10481 ok(GetWindow(hwnd2
, GW_HWNDNEXT
) == hwnd
, "expected %p, got %p\n", hwnd
, GetWindow(hwnd2
, GW_HWNDNEXT
));
10483 /* hide a non-active window */
10484 ShowWindow(hwnd
, SW_HIDE
);
10485 check_active_state(hwnd2
, hwnd2
, hwnd2
);
10487 ok(GetWindow(hwnd2
, GW_HWNDNEXT
) == hwnd
, "expected %p, got %p\n", hwnd
, GetWindow(hwnd2
, GW_HWNDNEXT
));
10489 /* hide a window in the middle */
10490 ShowWindow(hwnd
, SW_SHOW
);
10491 ShowWindow(hwnd2
, SW_SHOW
);
10492 hwnd3
= CreateWindowExA(0, "MainWindowClass", "Main window 3", WS_POPUP
| WS_VISIBLE
,
10493 100, 100, 200, 200, 0, 0, GetModuleHandleA(NULL
), NULL
);
10494 SetActiveWindow(hwnd2
);
10495 ShowWindow(hwnd2
, SW_HIDE
);
10496 check_active_state(hwnd3
, hwnd3
, hwnd3
);
10498 ok(GetWindow(hwnd3
, GW_HWNDNEXT
) == hwnd2
, "expected %p, got %p\n", hwnd2
, GetWindow(hwnd3
, GW_HWNDNEXT
));
10499 ok(GetWindow(hwnd2
, GW_HWNDNEXT
) == hwnd
, "expected %p, got %p\n", hwnd
, GetWindow(hwnd2
, GW_HWNDNEXT
));
10502 DestroyWindow(hwnd3
);
10504 /* hide a normal window when there is a topmost window */
10505 hwnd3
= CreateWindowExA(WS_EX_TOPMOST
, "MainWindowClass", "Topmost window 3", WS_POPUP
|WS_VISIBLE
,
10506 100, 100, 200, 200, 0, 0, GetModuleHandleA(NULL
), NULL
);
10507 ShowWindow(hwnd
, SW_SHOW
);
10508 ShowWindow(hwnd2
, SW_SHOW
);
10509 check_active_state(hwnd2
, hwnd2
, hwnd2
);
10510 ShowWindow(hwnd2
, SW_HIDE
);
10512 check_active_state(hwnd3
, hwnd3
, hwnd3
);
10513 ok(GetWindow(hwnd2
, GW_HWNDNEXT
) == hwnd
, "expected %p, got %p\n", hwnd
, GetWindow(hwnd2
, GW_HWNDNEXT
));
10515 /* hide a topmost window */
10516 ShowWindow(hwnd2
, SW_SHOW
);
10517 ShowWindow(hwnd3
, SW_SHOW
);
10518 ShowWindow(hwnd3
, SW_HIDE
);
10519 check_active_state(hwnd2
, hwnd2
, hwnd2
);
10520 ok(GetWindow(hwnd2
, GW_HWNDNEXT
) == hwnd
, "expected %p, got %p\n", hwnd
, GetWindow(hwnd2
, GW_HWNDNEXT
));
10522 DestroyWindow(hwnd3
);
10524 /* hiding an owned window activates its owner */
10525 ShowWindow(hwnd
, SW_SHOW
);
10526 ShowWindow(hwnd2
, SW_SHOW
);
10527 hwnd3
= CreateWindowExA(0, "MainWindowClass", "Owned window 3", WS_POPUP
|WS_VISIBLE
,
10528 100, 100, 200, 200, hwnd
, 0, GetModuleHandleA(NULL
), NULL
);
10529 ShowWindow(hwnd3
, SW_HIDE
);
10530 check_active_state(hwnd
, hwnd
, hwnd
);
10532 ok(GetWindow(hwnd3
, GW_HWNDNEXT
) == hwnd
, "expected %p, got %p\n", hwnd
, GetWindow(hwnd3
, GW_HWNDNEXT
));
10533 ok(GetWindow(hwnd
, GW_HWNDNEXT
) == hwnd2
, "expected %p, got %p\n", hwnd2
, GetWindow(hwnd
, GW_HWNDNEXT
));
10536 /* hide an owner window */
10537 ShowWindow(hwnd
, SW_SHOW
);
10538 ShowWindow(hwnd2
, SW_SHOW
);
10539 ShowWindow(hwnd3
, SW_SHOW
);
10540 ShowWindow(hwnd
, SW_HIDE
);
10541 check_active_state(hwnd3
, hwnd3
, hwnd3
);
10542 ok(GetWindow(hwnd3
, GW_HWNDNEXT
) == hwnd
, "expected %p, got %p\n", hwnd
, GetWindow(hwnd3
, GW_HWNDNEXT
));
10543 ok(GetWindow(hwnd
, GW_HWNDNEXT
) == hwnd2
, "expected %p, got %p\n", hwnd2
, GetWindow(hwnd
, GW_HWNDNEXT
));
10545 DestroyWindow(hwnd3
);
10546 DestroyWindow(hwnd2
);
10547 DestroyWindow(hwnd
);
10550 static void test_minimize_window(HWND hwndMain
)
10552 HWND hwnd
, hwnd2
, hwnd3
;
10554 hwnd
= CreateWindowExA(0, "MainWindowClass", "Main window", WS_POPUP
| WS_VISIBLE
,
10555 100, 100, 200, 200, 0, 0, GetModuleHandleA(NULL
), NULL
);
10556 hwnd2
= CreateWindowExA(0, "MainWindowClass", "Main window 2", WS_POPUP
| WS_VISIBLE
,
10557 100, 100, 200, 200, 0, 0, GetModuleHandleA(NULL
), NULL
);
10558 if (winetest_debug
> 1) trace("hwnd = %p, hwnd2 = %p\n", hwnd
, hwnd2
);
10559 check_active_state(hwnd2
, hwnd2
, hwnd2
);
10561 /* test hiding two normal windows */
10562 ShowWindow(hwnd2
, SW_MINIMIZE
);
10564 check_active_state(hwnd
, hwnd
, hwnd
);
10566 ShowWindow(hwnd
, SW_MINIMIZE
);
10568 if (GetActiveWindow() == 0)
10569 check_active_state(0, 0, 0);
10571 ShowWindow(hwnd
, SW_RESTORE
);
10572 check_active_state(hwnd
, hwnd
, hwnd
);
10574 ShowWindow(hwnd2
, SW_RESTORE
);
10575 check_active_state(hwnd2
, hwnd2
, hwnd2
);
10577 /* try SW_SHOWMINIMIZED */
10578 ShowWindow(hwnd2
, SW_SHOWMINIMIZED
);
10579 check_active_state(hwnd2
, hwnd2
, 0);
10581 ShowWindow(hwnd2
, SW_RESTORE
);
10582 check_active_state(hwnd2
, hwnd2
, hwnd2
);
10584 /* hide a non-active window */
10585 ShowWindow(hwnd
, SW_MINIMIZE
);
10586 check_active_state(hwnd2
, hwnd2
, hwnd2
);
10588 /* hide a window in the middle */
10589 ShowWindow(hwnd
, SW_RESTORE
);
10590 ShowWindow(hwnd2
, SW_RESTORE
);
10591 hwnd3
= CreateWindowExA(0, "MainWindowClass", "Main window 3", WS_POPUP
| WS_VISIBLE
,
10592 100, 100, 200, 200, 0, 0, GetModuleHandleA(NULL
), NULL
);
10593 SetActiveWindow(hwnd2
);
10594 ShowWindow(hwnd2
, SW_MINIMIZE
);
10596 check_active_state(hwnd3
, hwnd3
, hwnd3
);
10598 DestroyWindow(hwnd3
);
10600 /* hide a normal window when there is a topmost window */
10601 hwnd3
= CreateWindowExA(WS_EX_TOPMOST
, "MainWindowClass", "Topmost window 3", WS_POPUP
|WS_VISIBLE
,
10602 100, 100, 200, 200, 0, 0, GetModuleHandleA(NULL
), NULL
);
10603 ShowWindow(hwnd
, SW_RESTORE
);
10604 ShowWindow(hwnd2
, SW_RESTORE
);
10605 check_active_state(hwnd2
, hwnd2
, hwnd2
);
10606 ShowWindow(hwnd2
, SW_MINIMIZE
);
10608 check_active_state(hwnd3
, hwnd3
, hwnd3
);
10610 /* hide a topmost window */
10611 ShowWindow(hwnd2
, SW_RESTORE
);
10612 ShowWindow(hwnd3
, SW_RESTORE
);
10613 ShowWindow(hwnd3
, SW_MINIMIZE
);
10614 check_active_state(hwnd2
, hwnd2
, hwnd2
);
10616 DestroyWindow(hwnd3
);
10618 /* hide an owned window */
10619 ShowWindow(hwnd
, SW_RESTORE
);
10620 ShowWindow(hwnd2
, SW_RESTORE
);
10621 hwnd3
= CreateWindowExA(0, "MainWindowClass", "Owned window 3", WS_POPUP
|WS_VISIBLE
,
10622 100, 100, 200, 200, hwnd
, 0, GetModuleHandleA(NULL
), NULL
);
10623 ShowWindow(hwnd3
, SW_MINIMIZE
);
10625 check_active_state(hwnd2
, hwnd2
, hwnd2
);
10627 /* with SW_SHOWMINIMIZED */
10628 ShowWindow(hwnd3
, SW_RESTORE
);
10629 ShowWindow(hwnd3
, SW_SHOWMINIMIZED
);
10630 check_active_state(hwnd3
, hwnd3
, 0);
10632 /* hide an owner window */
10633 ShowWindow(hwnd
, SW_RESTORE
);
10634 ShowWindow(hwnd2
, SW_RESTORE
);
10635 ShowWindow(hwnd3
, SW_RESTORE
);
10636 ShowWindow(hwnd
, SW_MINIMIZE
);
10638 check_active_state(hwnd2
, hwnd2
, hwnd2
);
10640 DestroyWindow(hwnd3
);
10642 /* test a child window - focus should be yielded back to the parent */
10643 ShowWindow(hwnd
, SW_RESTORE
);
10644 hwnd3
= CreateWindowExA(0, "MainWindowClass", "Child window 3", WS_CHILD
|WS_VISIBLE
,
10645 100, 100, 200, 200, hwnd
, 0, GetModuleHandleA(NULL
), NULL
);
10647 check_active_state(hwnd
, hwnd
, hwnd3
);
10648 ShowWindow(hwnd3
, SW_MINIMIZE
);
10649 check_active_state(hwnd
, hwnd
, hwnd
);
10651 /* with SW_SHOWMINIMIZED */
10652 ShowWindow(hwnd3
, SW_RESTORE
);
10654 check_active_state(hwnd
, hwnd
, hwnd3
);
10655 ShowWindow(hwnd3
, SW_SHOWMINIMIZED
);
10656 check_active_state(hwnd
, hwnd
, hwnd
);
10658 DestroyWindow(hwnd3
);
10659 DestroyWindow(hwnd2
);
10660 DestroyWindow(hwnd
);
10663 static void test_desktop( void )
10665 HWND desktop
= GetDesktopWindow();
10666 /* GetWindowLong Desktop window tests */
10667 static const struct
10675 { GWLP_USERDATA
, 0, 0 },
10676 { GWL_STYLE
, WS_POPUP
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, 0 },
10677 { GWL_EXSTYLE
, 0, 0 },
10679 { GWLP_HWNDPARENT
, 0, 0 },
10680 /* GWLP_HINSTANCE - not useful and not consistent between Windows versions */
10681 { GWLP_WNDPROC
, 0, ERROR_ACCESS_DENIED
},
10682 { DWLP_MSGRESULT
, 0, ERROR_INVALID_INDEX
}
10687 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
10689 SetLastError( 0xdeadbeef );
10690 result
= GetWindowLongPtrW( desktop
, tests
[i
].offset
);
10691 ok( result
== tests
[i
].expect
, "offset %d, got %08lx expect %08lx\n",
10692 tests
[i
].offset
, result
, tests
[i
].expect
);
10693 if (tests
[i
].error
)
10694 ok( GetLastError() == tests
[i
].error
, "offset %d: error %d expect %d\n",
10695 tests
[i
].offset
, GetLastError(), tests
[i
].error
);
10697 ok( GetLastError() == 0xdeadbeef, "offset %d: error %d expect unchanged\n",
10698 tests
[i
].offset
, GetLastError() );
10702 static BOOL
is_topmost(HWND hwnd
)
10704 return (GetWindowLongA(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0;
10707 static void swp_after(HWND hwnd
, HWND after
)
10711 ret
= SetWindowPos(hwnd
, after
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
10712 ok(ret
, "SetWindowPos failed\n");
10713 flush_events( TRUE
);
10716 static void reset_window_state(HWND
*state
, int n
)
10720 for (i
= 0; i
< n
; i
++)
10724 swp_after(state
[i
], HWND_NOTOPMOST
);
10725 todo_wine_if(i
== 5) /* FIXME: remove once Wine is fixed */
10726 ok(!is_topmost(state
[i
]), "%d: hwnd %p is still topmost\n", i
, state
[i
]);
10727 swp_after(state
[i
], HWND_TOP
);
10732 static void test_topmost(void)
10734 HWND owner
, hwnd
, hwnd2
, hwnd_child
, hwnd_child2
, hwnd_grandchild
, state
[6] = { 0 };
10735 BOOL is_wine
= !strcmp(winetest_platform
, "wine");
10737 owner
= create_tool_window(WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
10738 WS_MAXIMIZEBOX
| WS_POPUP
| WS_VISIBLE
, 0);
10739 ok(owner
!= 0, "Failed to create owner window (%d)\n", GetLastError());
10741 /* Give current thread foreground state otherwise the tests may fail. */
10742 if (!SetForegroundWindow(owner
))
10744 DestroyWindow(owner
);
10745 skip("SetForegroundWindow not working\n");
10749 hwnd
= create_tool_window(WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
10750 WS_MAXIMIZEBOX
| WS_POPUP
| WS_VISIBLE
, owner
);
10751 ok(hwnd
!= 0, "Failed to create popup window (%d)\n", GetLastError());
10752 hwnd2
= create_tool_window(WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
10753 WS_MAXIMIZEBOX
| WS_POPUP
| WS_VISIBLE
, owner
);
10754 ok(hwnd2
!= 0, "Failed to create popup window (%d)\n", GetLastError());
10756 flush_events( TRUE
);
10758 if (winetest_debug
> 1) trace("owner %p, hwnd %p, hwnd2 %p\n", owner
, hwnd
, hwnd2
);
10763 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10764 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
10765 ok(!is_topmost(hwnd2
), "hwnd2 should NOT be topmost\n");
10766 check_z_order(hwnd
, 0, hwnd2
, owner
, FALSE
);
10768 swp_after(hwnd
, HWND_TOPMOST
);
10769 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10770 ok(is_topmost(hwnd
), "hwnd should be topmost\n");
10771 ok(!is_topmost(hwnd2
), "hwnd2 should NOT be topmost\n");
10772 check_z_order(hwnd
, hwnd2
, 0, owner
, TRUE
);
10773 swp_after(hwnd
, HWND_TOP
);
10774 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10775 ok(is_topmost(hwnd
), "hwnd should be topmost\n");
10776 ok(!is_topmost(hwnd2
), "hwnd2 should NOT be topmost\n");
10777 check_z_order(hwnd
, hwnd2
, 0, owner
, TRUE
);
10778 swp_after(hwnd
, HWND_NOTOPMOST
);
10779 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10780 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
10781 ok(!is_topmost(hwnd2
), "hwnd2 should NOT be topmost\n");
10782 check_z_order(hwnd
, hwnd2
, 0, owner
, FALSE
);
10783 reset_window_state(state
, ARRAY_SIZE(state
));
10785 swp_after(hwnd
, HWND_TOPMOST
);
10786 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10787 ok(is_topmost(hwnd
), "hwnd should be topmost\n");
10788 ok(!is_topmost(hwnd2
), "hwnd2 should NOT be topmost\n");
10789 check_z_order(hwnd
, hwnd2
, 0, owner
, TRUE
);
10790 swp_after(hwnd2
, hwnd
);
10791 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10792 ok(is_topmost(hwnd
), "hwnd should be topmost\n");
10793 ok(!is_topmost(hwnd2
), "hwnd2 should NOT be topmost\n");
10794 check_z_order(hwnd
, hwnd2
, 0, owner
, TRUE
);
10795 swp_after(hwnd
, hwnd2
);
10796 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10797 ok(is_topmost(hwnd
), "hwnd should be topmost\n");
10798 ok(!is_topmost(hwnd2
), "hwnd2 should NOT be topmost\n");
10799 check_z_order(hwnd
, hwnd2
, 0, owner
, TRUE
);
10800 swp_after(hwnd2
, HWND_TOP
);
10801 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10802 ok(is_topmost(hwnd
), "hwnd should be topmost\n");
10803 ok(!is_topmost(hwnd2
), "hwnd2 should NOT be topmost\n");
10804 check_z_order(hwnd
, hwnd2
, 0, owner
, TRUE
);
10805 swp_after(owner
, HWND_TOPMOST
);
10807 ok(is_topmost(owner
), "owner should be topmost\n");
10808 ok(is_topmost(hwnd
), "hwnd should be topmost\n");
10810 ok(is_topmost(hwnd2
), "hwnd2 should be topmost\n");
10811 swp_after(hwnd
, HWND_NOTOPMOST
);
10812 ok(!is_topmost(owner
) || broken(is_topmost(owner
)) /*win7 64-bit*/, "owner should NOT be topmost\n");
10813 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
10814 ok(!is_topmost(hwnd2
) || broken(is_topmost(hwnd2
)) /*win7 64-bit*/, "hwnd2 should NOT be topmost\n");
10815 if (0) /*win7 64-bit is broken*/
10816 check_z_order(hwnd
, hwnd2
, 0, owner
, FALSE
);
10817 swp_after(hwnd2
, HWND_NOTOPMOST
);
10818 ok(!is_topmost(owner
) || broken(is_topmost(owner
)) /*win7 64-bit*/, "owner should NOT be topmost\n");
10819 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
10820 ok(!is_topmost(hwnd2
), "hwnd2 should NOT be topmost\n");
10821 if (!is_wine
) /* FIXME: remove once Wine is fixed */
10822 check_z_order(hwnd
, 0, hwnd2
, owner
, FALSE
);
10823 reset_window_state(state
, ARRAY_SIZE(state
));
10825 swp_after(hwnd
, HWND_TOPMOST
);
10826 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10827 ok(is_topmost(hwnd
), "hwnd should be topmost\n");
10828 ok(!is_topmost(hwnd2
), "hwnd2 should NOT be topmost\n");
10829 check_z_order(hwnd
, hwnd2
, 0, owner
, TRUE
);
10830 swp_after(hwnd
, HWND_BOTTOM
);
10831 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10833 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
10834 ok(!is_topmost(hwnd2
), "hwnd2 should NOT be topmost\n");
10835 if (!is_wine
) /* FIXME: remove once Wine is fixed */
10836 check_z_order(hwnd
, 0, hwnd2
, owner
, FALSE
);
10837 reset_window_state(state
, ARRAY_SIZE(state
));
10839 swp_after(hwnd
, HWND_TOPMOST
);
10840 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10841 ok(is_topmost(hwnd
), "hwnd should be topmost\n");
10842 ok(!is_topmost(hwnd2
), "hwnd2 should NOT be topmost\n");
10843 check_z_order(hwnd
, hwnd2
, 0, owner
, TRUE
);
10844 swp_after(hwnd
, hwnd2
);
10845 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10847 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
10848 ok(!is_topmost(hwnd2
), "hwnd2 should NOT be topmost\n");
10849 if (!is_wine
) /* FIXME: remove once Wine is fixed */
10850 check_z_order(hwnd
, 0, hwnd2
, owner
, FALSE
);
10851 /* FIXME: compensate todo_wine above */
10852 swp_after(hwnd
, HWND_NOTOPMOST
);
10853 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10854 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
10855 ok(!is_topmost(hwnd2
), "hwnd2 should NOT be topmost\n");
10856 if (!is_wine
) /* FIXME: remove once Wine is fixed */
10857 check_z_order(hwnd
, 0, hwnd2
, owner
, FALSE
);
10858 reset_window_state(state
, ARRAY_SIZE(state
));
10860 hwnd_child2
= create_tool_window(WS_VISIBLE
|WS_POPUP
, hwnd
);
10861 ok(hwnd_child2
!= 0, "Failed to create popup window (%d)\n", GetLastError());
10862 hwnd_child
= create_tool_window(WS_VISIBLE
|WS_POPUP
, hwnd
);
10863 ok(hwnd_child
!= 0, "Failed to create popup window (%d)\n", GetLastError());
10864 hwnd_grandchild
= create_tool_window(WS_VISIBLE
|WS_POPUP
, hwnd_child
);
10865 ok(hwnd_grandchild
!= 0, "Failed to create popup window (%d)\n", GetLastError());
10867 flush_events( TRUE
);
10869 if (winetest_debug
> 1)
10870 trace("hwnd_child %p, hwnd_child2 %p, hwnd_grandchild %p\n", hwnd_child
, hwnd_child2
, hwnd_grandchild
);
10871 state
[3] = hwnd_child2
;
10872 state
[4] = hwnd_child
;
10873 state
[5] = hwnd_grandchild
;
10875 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10876 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
10877 ok(!is_topmost(hwnd2
), "hwnd2 should NOT be topmost\n");
10878 ok(!is_topmost(hwnd_child
), "child should NOT be topmost\n");
10879 ok(!is_topmost(hwnd_child2
), "child2 should NOT be topmost\n");
10880 ok(!is_topmost(hwnd_grandchild
), "grandchild should NOT be topmost\n");
10881 if (!is_wine
) /* FIXME: remove once Wine is fixed */
10882 check_z_order(hwnd
, hwnd2
, 0, owner
, FALSE
);
10883 check_z_order(hwnd_child
, hwnd_child2
, 0, hwnd
, FALSE
);
10885 swp_after(hwnd
, HWND_TOPMOST
);
10886 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10888 ok(is_topmost(hwnd
), "hwnd should be topmost\n");
10890 ok(is_topmost(hwnd_child
), "child should be topmost\n");
10892 ok(is_topmost(hwnd_child2
), "child2 should be topmost\n");
10893 ok(is_topmost(hwnd_grandchild
), "grandchild should be topmost\n");
10894 if (!is_wine
) /* FIXME: remove once Wine is fixed */
10895 check_z_order(hwnd
, hwnd2
, 0, owner
, TRUE
);
10896 if (!is_wine
) /* FIXME: remove once Wine is fixed */
10897 check_z_order(hwnd_child
, hwnd_child2
, 0, hwnd
, TRUE
);
10898 swp_after(hwnd
, HWND_NOTOPMOST
);
10899 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10900 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
10901 ok(!is_topmost(hwnd_child
), "child should NOT be topmost\n");
10902 ok(!is_topmost(hwnd_child2
), "child2 should NOT be topmost\n");
10904 ok(!is_topmost(hwnd_grandchild
), "grandchild should NOT be topmost\n");
10905 if (!is_wine
) /* FIXME: remove once Wine is fixed */
10906 check_z_order(hwnd
, hwnd2
, 0, owner
, FALSE
);
10907 check_z_order(hwnd_child
, hwnd_child2
, 0, hwnd
, FALSE
);
10908 reset_window_state(state
, ARRAY_SIZE(state
));
10910 swp_after(hwnd
, HWND_TOPMOST
);
10911 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10913 ok(is_topmost(hwnd
), "hwnd should be topmost\n");
10915 ok(is_topmost(hwnd_child
), "child should be topmost\n");
10917 ok(is_topmost(hwnd_child2
), "child2 should be topmost\n");
10918 ok(is_topmost(hwnd_grandchild
), "grandchild should be topmost\n");
10919 if (!is_wine
) /* FIXME: remove once Wine is fixed */
10920 check_z_order(hwnd
, hwnd2
, 0, owner
, TRUE
);
10921 if (!is_wine
) /* FIXME: remove once Wine is fixed */
10922 check_z_order(hwnd_child
, hwnd_child2
, 0, hwnd
, TRUE
);
10923 swp_after(hwnd_child
, HWND_NOTOPMOST
);
10924 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10925 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
10926 ok(!is_topmost(hwnd_child
), "child should NOT be topmost\n");
10927 ok(!is_topmost(hwnd_child2
), "child2 should NOT be topmost\n");
10929 ok(!is_topmost(hwnd_grandchild
), "grandchild should NOT be topmost\n");
10930 check_z_order(hwnd
, hwnd2
, 0, owner
, FALSE
);
10931 check_z_order(hwnd_child
, hwnd_child2
, 0, hwnd
, FALSE
);
10932 reset_window_state(state
, ARRAY_SIZE(state
));
10934 swp_after(hwnd
, HWND_TOPMOST
);
10935 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10937 ok(is_topmost(hwnd
), "hwnd should be topmost\n");
10939 ok(is_topmost(hwnd_child
), "child should be topmost\n");
10941 ok(is_topmost(hwnd_child2
), "child2 should be topmost\n");
10942 ok(is_topmost(hwnd_grandchild
), "grandchild should be topmost\n");
10943 if (!is_wine
) /* FIXME: remove once Wine is fixed */
10944 check_z_order(hwnd
, hwnd2
, 0, owner
, TRUE
);
10945 if (!is_wine
) /* FIXME: remove once Wine is fixed */
10946 check_z_order(hwnd_child
, hwnd_child2
, 0, hwnd
, TRUE
);
10947 swp_after(hwnd_grandchild
, HWND_NOTOPMOST
);
10948 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10949 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
10950 ok(!is_topmost(hwnd_child
), "child should NOT be topmost\n");
10951 ok(!is_topmost(hwnd_child2
), "child2 should NOT be topmost\n");
10953 ok(!is_topmost(hwnd_grandchild
), "grandchild should NOT be topmost\n");
10954 check_z_order(hwnd
, hwnd2
, 0, owner
, FALSE
);
10955 check_z_order(hwnd_child
, hwnd_child2
, 0, hwnd
, FALSE
);
10956 reset_window_state(state
, ARRAY_SIZE(state
));
10958 swp_after(hwnd_child
, HWND_TOPMOST
);
10959 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10960 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
10962 ok(is_topmost(hwnd_child
), "child should be topmost\n");
10963 ok(!is_topmost(hwnd_child2
), "child2 should NOT be topmost\n");
10964 ok(is_topmost(hwnd_grandchild
), "grandchild should be topmost\n");
10965 if (!is_wine
) /* FIXME: remove once Wine is fixed */
10966 check_z_order(hwnd
, hwnd2
, 0, owner
, FALSE
);
10967 if (!is_wine
) /* FIXME: remove once Wine is fixed */
10968 check_z_order(hwnd_child
, hwnd_child2
, 0, hwnd
, TRUE
);
10969 swp_after(hwnd_child
, HWND_TOP
);
10970 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10971 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
10973 ok(is_topmost(hwnd_child
), "child should be topmost\n");
10974 ok(!is_topmost(hwnd_child2
), "child2 should NOT be topmost\n");
10975 ok(is_topmost(hwnd_grandchild
), "grandchild should be topmost\n");
10976 if (!is_wine
) /* FIXME: remove once Wine is fixed */
10977 check_z_order(hwnd
, hwnd2
, 0, owner
, FALSE
);
10978 if (!is_wine
) /* FIXME: remove once Wine is fixed */
10979 check_z_order(hwnd_child
, hwnd_child2
, 0, hwnd
, TRUE
);
10980 swp_after(hwnd
, HWND_NOTOPMOST
);
10981 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10982 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
10983 ok(!is_topmost(hwnd_child
), "child should NOT be topmost\n");
10984 ok(!is_topmost(hwnd_child2
), "child2 should NOT be topmost\n");
10986 ok(!is_topmost(hwnd_grandchild
) || broken(is_topmost(hwnd_grandchild
))/*win2008 64-bit*/, "grandchild should NOT be topmost\n");
10987 if (!is_wine
) /* FIXME: remove once Wine is fixed */
10988 check_z_order(hwnd
, hwnd2
, 0, owner
, FALSE
);
10989 check_z_order(hwnd_child
, hwnd_child2
, 0, hwnd
, FALSE
);
10990 reset_window_state(state
, ARRAY_SIZE(state
));
10992 swp_after(hwnd_child
, HWND_TOPMOST
);
10993 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
10994 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
10996 ok(is_topmost(hwnd_child
), "child should be topmost\n");
10997 ok(!is_topmost(hwnd_child2
), "child2 should NOT be topmost\n");
10998 ok(is_topmost(hwnd_grandchild
), "grandchild should be topmost\n");
10999 if (!is_wine
) /* FIXME: remove once Wine is fixed */
11000 check_z_order(hwnd
, hwnd2
, 0, owner
, FALSE
);
11001 if (!is_wine
) /* FIXME: remove once Wine is fixed */
11002 check_z_order(hwnd_child
, hwnd_child2
, 0, hwnd
, TRUE
);
11003 swp_after(hwnd
, HWND_NOTOPMOST
);
11004 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
11005 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
11006 ok(!is_topmost(hwnd_child
), "child should NOT be topmost\n");
11007 ok(!is_topmost(hwnd_child2
), "child2 should NOT be topmost\n");
11009 ok(!is_topmost(hwnd_grandchild
), "grandchild should NOT be topmost\n");
11010 if (!is_wine
) /* FIXME: remove once Wine is fixed */
11011 check_z_order(hwnd
, hwnd2
, 0, owner
, FALSE
);
11012 check_z_order(hwnd_child
, hwnd_child2
, 0, hwnd
, FALSE
);
11013 reset_window_state(state
, ARRAY_SIZE(state
));
11015 swp_after(hwnd_grandchild
, HWND_TOPMOST
);
11016 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
11017 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
11018 ok(!is_topmost(hwnd_child
), "child should NOT be topmost\n");
11019 ok(!is_topmost(hwnd_child2
), "child2 should NOT be topmost\n");
11020 ok(is_topmost(hwnd_grandchild
), "grandchild should be topmost\n");
11021 if (!is_wine
) /* FIXME: remove once Wine is fixed */
11022 check_z_order(hwnd
, hwnd2
, 0, owner
, FALSE
);
11023 check_z_order(hwnd_child
, hwnd_child2
, 0, hwnd
, FALSE
);
11024 swp_after(hwnd_child2
, HWND_NOTOPMOST
);
11025 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
11026 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
11027 ok(!is_topmost(hwnd_child
), "child should NOT be topmost\n");
11028 ok(!is_topmost(hwnd_child2
), "child2 should NOT be topmost\n");
11029 ok(is_topmost(hwnd_grandchild
) || broken(!is_topmost(hwnd_grandchild
)) /* win8+ */, "grandchild should be topmost\n");
11030 if (!is_wine
) /* FIXME: remove once Wine is fixed */
11031 check_z_order(hwnd
, hwnd2
, 0, owner
, FALSE
);
11032 if (!is_wine
) /* FIXME: remove once Wine is fixed */
11033 check_z_order(hwnd_child
, 0, hwnd_child2
, hwnd
, FALSE
);
11034 reset_window_state(state
, ARRAY_SIZE(state
));
11036 swp_after(hwnd_child
, HWND_TOPMOST
);
11037 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
11038 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
11040 ok(is_topmost(hwnd_child
), "child should be topmost\n");
11041 ok(!is_topmost(hwnd_child2
), "child2 should NOT be topmost\n");
11042 ok(is_topmost(hwnd_grandchild
), "grandchild should be topmost\n");
11043 if (!is_wine
) /* FIXME: remove once Wine is fixed */
11044 check_z_order(hwnd
, hwnd2
, 0, owner
, FALSE
);
11045 if (!is_wine
) /* FIXME: remove once Wine is fixed */
11046 check_z_order(hwnd_child
, hwnd_child2
, 0, hwnd
, TRUE
);
11047 swp_after(hwnd_child
, HWND_BOTTOM
);
11048 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
11049 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
11050 ok(!is_topmost(hwnd_child
), "child should NOT be topmost\n");
11051 ok(!is_topmost(hwnd_child2
), "child2 should NOT be topmost\n");
11053 ok(!is_topmost(hwnd_grandchild
), "grandchild should NOT be topmost\n");
11054 if (!is_wine
) /* FIXME: remove once Wine is fixed */
11055 check_z_order(hwnd
, 0, hwnd2
, owner
, FALSE
);
11056 if (!is_wine
) /* FIXME: remove once Wine is fixed */
11057 check_z_order(hwnd_child
, 0, hwnd_child2
, hwnd
, FALSE
);
11058 reset_window_state(state
, ARRAY_SIZE(state
));
11060 swp_after(hwnd_child
, HWND_TOPMOST
);
11061 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
11062 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
11064 ok(is_topmost(hwnd_child
), "child should be topmost\n");
11065 ok(!is_topmost(hwnd_child2
), "child2 should NOT be topmost\n");
11066 ok(is_topmost(hwnd_grandchild
), "grandchild should be topmost\n");
11067 if (!is_wine
) /* FIXME: remove once Wine is fixed */
11068 check_z_order(hwnd
, hwnd2
, 0, owner
, FALSE
);
11069 if (!is_wine
) /* FIXME: remove once Wine is fixed */
11070 check_z_order(hwnd_child
, hwnd_child2
, 0, hwnd
, TRUE
);
11071 swp_after(hwnd_child
, hwnd_child2
);
11072 ok(!is_topmost(owner
), "owner should NOT be topmost\n");
11073 ok(!is_topmost(hwnd
), "hwnd should NOT be topmost\n");
11074 ok(!is_topmost(hwnd_child
), "child should NOT be topmost\n");
11075 ok(!is_topmost(hwnd_child2
), "child2 should NOT be topmost\n");
11077 ok(!is_topmost(hwnd_grandchild
), "grandchild should NOT be topmost\n");
11078 if (!is_wine
) /* FIXME: remove once Wine is fixed */
11079 check_z_order(hwnd
, hwnd2
, 0, owner
, FALSE
);
11080 if (!is_wine
) /* FIXME: remove once Wine is fixed */
11081 check_z_order(hwnd_child
, 0, hwnd_child2
, hwnd
, FALSE
);
11082 reset_window_state(state
, ARRAY_SIZE(state
));
11084 DestroyWindow(hwnd_grandchild
);
11085 DestroyWindow(hwnd_child
);
11086 DestroyWindow(hwnd_child2
);
11087 DestroyWindow(hwnd
);
11088 DestroyWindow(hwnd2
);
11089 DestroyWindow(owner
);
11092 static void test_display_affinity( HWND win
)
11098 if (!pGetWindowDisplayAffinity
|| !pSetWindowDisplayAffinity
)
11100 win_skip("GetWindowDisplayAffinity or SetWindowDisplayAffinity missing\n");
11104 ret
= pGetWindowDisplayAffinity(NULL
, NULL
);
11105 ok(!ret
, "GetWindowDisplayAffinity succeeded\n");
11106 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "Expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
11108 ret
= pGetWindowDisplayAffinity(NULL
, &affinity
);
11109 ok(!ret
, "GetWindowDisplayAffinity succeeded\n");
11110 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "Expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
11112 ret
= pGetWindowDisplayAffinity(win
, NULL
);
11113 ok(!ret
, "GetWindowDisplayAffinity succeeded\n");
11114 ok(GetLastError() == ERROR_NOACCESS
, "Expected ERROR_NOACCESS, got %u\n", GetLastError());
11116 styleex
= GetWindowLongW(win
, GWL_EXSTYLE
);
11117 SetWindowLongW(win
, GWL_EXSTYLE
, styleex
& ~WS_EX_LAYERED
);
11119 affinity
= 0xdeadbeef;
11120 ret
= pGetWindowDisplayAffinity(win
, &affinity
);
11121 ok(ret
, "GetWindowDisplayAffinity failed with %u\n", GetLastError());
11122 ok(affinity
== WDA_NONE
, "Expected WDA_NONE, got 0x%x\n", affinity
);
11124 /* Windows 7 fails with ERROR_NOT_ENOUGH_MEMORY when dwm compositing is disabled */
11125 ret
= pSetWindowDisplayAffinity(win
, WDA_MONITOR
);
11126 ok(ret
|| GetLastError() == ERROR_NOT_ENOUGH_MEMORY
,
11127 "SetWindowDisplayAffinity failed with %u\n", GetLastError());
11130 affinity
= 0xdeadbeef;
11131 ret
= pGetWindowDisplayAffinity(win
, &affinity
);
11132 ok(ret
, "GetWindowDisplayAffinity failed with %u\n", GetLastError());
11133 if (dwm
) ok(affinity
== WDA_MONITOR
, "Expected WDA_MONITOR, got 0x%x\n", affinity
);
11134 else ok(affinity
== WDA_NONE
, "Expected WDA_NONE, got 0x%x\n", affinity
);
11136 ret
= pSetWindowDisplayAffinity(win
, WDA_NONE
);
11137 ok(ret
|| GetLastError() == ERROR_NOT_ENOUGH_MEMORY
,
11138 "SetWindowDisplayAffinity failed with %u\n", GetLastError());
11140 affinity
= 0xdeadbeef;
11141 ret
= pGetWindowDisplayAffinity(win
, &affinity
);
11142 ok(ret
, "GetWindowDisplayAffinity failed with %u\n", GetLastError());
11143 ok(affinity
== WDA_NONE
, "Expected WDA_NONE, got 0x%x\n", affinity
);
11145 SetWindowLongW(win
, GWL_EXSTYLE
, styleex
| WS_EX_LAYERED
);
11147 affinity
= 0xdeadbeef;
11148 ret
= pGetWindowDisplayAffinity(win
, &affinity
);
11149 ok(ret
, "GetWindowDisplayAffinity failed with %u\n", GetLastError());
11150 ok(affinity
== WDA_NONE
, "Expected WDA_NONE, got 0x%x\n", affinity
);
11152 ret
= pSetWindowDisplayAffinity(win
, WDA_MONITOR
);
11153 ok(ret
|| GetLastError() == ERROR_NOT_ENOUGH_MEMORY
,
11154 "SetWindowDisplayAffinity failed with %u\n", GetLastError());
11156 affinity
= 0xdeadbeef;
11157 ret
= pGetWindowDisplayAffinity(win
, &affinity
);
11158 ok(ret
, "GetWindowDisplayAffinity failed with %u\n", GetLastError());
11159 if (dwm
) ok(affinity
== WDA_MONITOR
, "Expected WDA_MONITOR, got 0x%x\n", affinity
);
11160 else ok(affinity
== WDA_NONE
, "Expected WDA_NONE, got 0x%x\n", affinity
);
11162 ret
= pSetWindowDisplayAffinity(win
, WDA_NONE
);
11163 ok(ret
|| GetLastError() == ERROR_NOT_ENOUGH_MEMORY
,
11164 "SetWindowDisplayAffinity failed with %u\n", GetLastError());
11166 affinity
= 0xdeadbeef;
11167 ret
= pGetWindowDisplayAffinity(win
, &affinity
);
11168 ok(ret
, "GetWindowDisplayAffinity failed with %u\n", GetLastError());
11169 ok(affinity
== WDA_NONE
, "Expected WDA_NONE, got 0x%x\n", affinity
);
11171 SetWindowLongW(win
, GWL_EXSTYLE
, styleex
);
11174 static struct destroy_data
11181 DWORD destroy_count
;
11182 DWORD ncdestroy_count
;
11185 static LRESULT WINAPI
destroy_thread1_wndproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
11190 ok( destroy_data
.destroy_count
> 0, "parent didn't get WM_DESTROY\n" );
11191 PostQuitMessage(0);
11194 ok( destroy_data
.ncdestroy_count
> 0, "parent didn't get WM_NCDESTROY\n" );
11197 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
11200 static LRESULT WINAPI
destroy_thread2_wndproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
11205 ok( destroy_data
.destroy_count
> 0, "parent didn't get WM_DESTROY\n" );
11208 ok( destroy_data
.ncdestroy_count
> 0, "parent didn't get WM_NCDESTROY\n" );
11209 ok( WaitForSingleObject(destroy_data
.evt
, 10000) != WAIT_TIMEOUT
, "timeout\n" );
11210 PostQuitMessage(0);
11213 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
11216 static LRESULT WINAPI
destroy_main_wndproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
11221 destroy_data
.destroy_count
++;
11224 destroy_data
.ncdestroy_count
++;
11227 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
11230 static DWORD CALLBACK
destroy_thread1(void *user
)
11234 destroy_data
.thread1_wnd
= CreateWindowExA(0, "destroy_test_thread1",
11235 "destroy test thread", WS_CHILD
, 100, 100, 100, 100,
11236 destroy_data
.main_wnd
, 0, GetModuleHandleA(NULL
), NULL
);
11237 ok(destroy_data
.thread1_wnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
11238 PostThreadMessageW(destroy_data
.main_tid
, WM_USER
, 0, 0);
11240 while (GetMessageA(&msg
, 0, 0, 0))
11242 TranslateMessage(&msg
);
11243 DispatchMessageA(&msg
);
11245 PostThreadMessageW(destroy_data
.main_tid
, WM_USER
+ 2, 0, 0);
11246 ok( WaitForSingleObject(destroy_data
.evt
, 10000) != WAIT_TIMEOUT
, "timeout\n" );
11247 ok( IsWindow( destroy_data
.thread1_wnd
), "window destroyed\n" );
11251 static DWORD CALLBACK
destroy_thread2(void *user
)
11255 destroy_data
.thread2_wnd
= CreateWindowExA(0, "destroy_test_thread2",
11256 "destroy test thread", WS_CHILD
, 100, 100, 100, 100,
11257 destroy_data
.main_wnd
, 0, GetModuleHandleA(NULL
), NULL
);
11258 ok(destroy_data
.thread2_wnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
11260 PostThreadMessageW(destroy_data
.main_tid
, WM_USER
+ 1, 0, 0);
11263 while (GetMessageA(&msg
, 0, 0, 0))
11265 TranslateMessage(&msg
);
11266 DispatchMessageA(&msg
);
11268 ok( !IsWindow( destroy_data
.thread2_wnd
), "window not destroyed\n" );
11272 static void test_destroy_quit(void)
11275 WNDCLASSA wnd_classA
;
11277 HANDLE thread1
, thread2
;
11279 destroy_data
.main_tid
= GetCurrentThreadId();
11280 destroy_data
.evt
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
11281 destroy_data
.destroy_count
= 0;
11282 destroy_data
.ncdestroy_count
= 0;
11284 memset(&wnd_classA
, 0, sizeof(wnd_classA
));
11285 wnd_classA
.lpszClassName
= "destroy_test_main";
11286 wnd_classA
.lpfnWndProc
= destroy_main_wndproc
;
11287 ret
= RegisterClassA(&wnd_classA
);
11288 ok(ret
, "RegisterClass failed with error %d\n", GetLastError());
11290 wnd_classA
.lpszClassName
= "destroy_test_thread1";
11291 wnd_classA
.lpfnWndProc
= destroy_thread1_wndproc
;
11292 ret
= RegisterClassA(&wnd_classA
);
11293 ok(ret
, "RegisterClass failed with error %d\n", GetLastError());
11295 wnd_classA
.lpszClassName
= "destroy_test_thread2";
11296 wnd_classA
.lpfnWndProc
= destroy_thread2_wndproc
;
11297 ret
= RegisterClassA(&wnd_classA
);
11298 ok(ret
, "RegisterClass failed with error %d\n", GetLastError());
11300 destroy_data
.main_wnd
= CreateWindowExA(0, "destroy_test_main",
11301 "destroy test main", WS_OVERLAPPED
| WS_CAPTION
, 100, 100, 100, 100,
11302 0, 0, GetModuleHandleA(NULL
), NULL
);
11303 ok(destroy_data
.main_wnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
11304 if (!destroy_data
.main_wnd
)
11306 CloseHandle(destroy_data
.evt
);
11310 thread1
= CreateThread(NULL
, 0, destroy_thread1
, 0, 0, NULL
);
11312 while (GetMessageA(&msg
, 0, 0, 0))
11315 switch (msg
.message
)
11318 thread2
= CreateThread(NULL
, 0, destroy_thread2
, 0, 0, NULL
);
11319 CloseHandle( thread2
);
11322 DestroyWindow(destroy_data
.main_wnd
);
11325 SetEvent(destroy_data
.evt
);
11329 DispatchMessageA(&msg
);
11335 ok( WaitForSingleObject( thread1
, 10000 ) != WAIT_TIMEOUT
, "timeout\n" );
11336 ok( !IsWindow( destroy_data
.thread1_wnd
), "window not destroyed\n" );
11337 CloseHandle( thread1
);
11340 static void test_IsWindowEnabled(void)
11345 ret
= IsWindowEnabled(NULL
);
11346 ok(!ret
, "Expect IsWindowEnabled() return FALSE\n");
11348 hwnd
= GetDesktopWindow();
11349 ret
= IsWindowEnabled(hwnd
);
11350 ok(ret
, "Expect IsWindowEnabled() return TRUE\n");
11352 hwnd
= create_tool_window(WS_CHILD
| WS_VISIBLE
, hwndMain
);
11353 ret
= IsWindowEnabled(hwnd
);
11354 ok(ret
, "Expect IsWindowEnabled() return TRUE\n");
11355 EnableWindow(hwnd
, FALSE
);
11356 ret
= IsWindowEnabled(hwnd
);
11357 ok(!ret
, "Expect IsWindowEnabled() return FALSE\n");
11358 DestroyWindow(hwnd
);
11361 static void test_window_placement(void)
11363 RECT orig
= {100, 200, 300, 400}, orig2
= {200, 300, 400, 500}, rect
;
11364 WINDOWPLACEMENT wp
= {sizeof(wp
)};
11368 hwnd
= CreateWindowA("MainWindowClass", "wp", WS_OVERLAPPEDWINDOW
,
11369 orig
.left
, orig
.top
, orig
.right
- orig
.left
, orig
.bottom
- orig
.top
, 0, 0, 0, 0);
11370 ok(!!hwnd
, "failed to create window, error %u\n", GetLastError());
11372 ret
= GetWindowPlacement(hwnd
, &wp
);
11373 ok(ret
, "failed to get window placement, error %u\n", GetLastError());
11374 ok(wp
.showCmd
== SW_SHOWNORMAL
, "got show cmd %u\n", wp
.showCmd
);
11375 ok(wp
.ptMinPosition
.x
== -1 && wp
.ptMinPosition
.y
== -1,
11376 "got minimized pos (%d,%d)\n", wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
);
11377 ok(wp
.ptMaxPosition
.x
== -1 && wp
.ptMaxPosition
.y
== -1,
11378 "got maximized pos (%d,%d)\n", wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
);
11379 ok(EqualRect(&wp
.rcNormalPosition
, &orig
), "got normal pos %s\n",
11380 wine_dbgstr_rect(&wp
.rcNormalPosition
));
11382 ShowWindow(hwnd
, SW_MINIMIZE
);
11384 ret
= GetWindowPlacement(hwnd
, &wp
);
11385 ok(ret
, "failed to get window placement, error %u\n", GetLastError());
11386 ok(!wp
.flags
, "got flags %#x\n", wp
.flags
);
11387 ok(wp
.showCmd
== SW_SHOWMINIMIZED
, "got show cmd %u\n", wp
.showCmd
);
11388 ok(wp
.ptMinPosition
.x
== -32000 && wp
.ptMinPosition
.y
== -32000,
11389 "got minimized pos (%d,%d)\n", wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
);
11390 ok(wp
.ptMaxPosition
.x
== -1 && wp
.ptMaxPosition
.y
== -1,
11391 "got maximized pos (%d,%d)\n", wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
);
11392 ok(EqualRect(&wp
.rcNormalPosition
, &orig
), "got normal pos %s\n",
11393 wine_dbgstr_rect(&wp
.rcNormalPosition
));
11395 ShowWindow(hwnd
, SW_RESTORE
);
11397 ret
= GetWindowPlacement(hwnd
, &wp
);
11398 ok(ret
, "failed to get window placement, error %u\n", GetLastError());
11399 ok(wp
.showCmd
== SW_SHOWNORMAL
, "got show cmd %u\n", wp
.showCmd
);
11400 ok(wp
.ptMinPosition
.x
== -32000 && wp
.ptMinPosition
.y
== -32000,
11401 "got minimized pos (%d,%d)\n", wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
);
11402 ok(wp
.ptMaxPosition
.x
== -1 && wp
.ptMaxPosition
.y
== -1,
11403 "got maximized pos (%d,%d)\n", wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
);
11404 ok(EqualRect(&wp
.rcNormalPosition
, &orig
), "got normal pos %s\n",
11405 wine_dbgstr_rect(&wp
.rcNormalPosition
));
11407 ShowWindow(hwnd
, SW_MAXIMIZE
);
11409 ret
= GetWindowPlacement(hwnd
, &wp
);
11410 ok(ret
, "failed to get window placement, error %u\n", GetLastError());
11411 ok(wp
.showCmd
== SW_SHOWMAXIMIZED
, "got show cmd %u\n", wp
.showCmd
);
11412 ok(wp
.ptMinPosition
.x
== -32000 && wp
.ptMinPosition
.y
== -32000,
11413 "got minimized pos (%d,%d)\n", wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
);
11415 ok(wp
.ptMaxPosition
.x
== -1 && wp
.ptMaxPosition
.y
== -1,
11416 "got maximized pos (%d,%d)\n", wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
);
11417 ok(EqualRect(&wp
.rcNormalPosition
, &orig
), "got normal pos %s\n",
11418 wine_dbgstr_rect(&wp
.rcNormalPosition
));
11420 SetWindowPos(hwnd
, 0, 100, 100, 100, 100, SWP_NOZORDER
| SWP_NOACTIVATE
);
11422 ret
= GetWindowPlacement(hwnd
, &wp
);
11423 ok(ret
, "failed to get window placement, error %u\n", GetLastError());
11424 ok(wp
.showCmd
== SW_SHOWMAXIMIZED
, "got show cmd %u\n", wp
.showCmd
);
11425 ok(wp
.ptMinPosition
.x
== -32000 && wp
.ptMinPosition
.y
== -32000,
11426 "got minimized pos (%d,%d)\n", wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
);
11427 ok(wp
.ptMaxPosition
.x
== 100 && wp
.ptMaxPosition
.y
== 100,
11428 "got maximized pos (%d,%d)\n", wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
);
11429 ok(EqualRect(&wp
.rcNormalPosition
, &orig
), "got normal pos %s\n",
11430 wine_dbgstr_rect(&wp
.rcNormalPosition
));
11432 ShowWindow(hwnd
, SW_MINIMIZE
);
11434 ret
= GetWindowPlacement(hwnd
, &wp
);
11435 ok(ret
, "failed to get window placement, error %u\n", GetLastError());
11436 ok(wp
.flags
== WPF_RESTORETOMAXIMIZED
, "got flags %#x\n", wp
.flags
);
11437 ok(wp
.showCmd
== SW_SHOWMINIMIZED
, "got show cmd %u\n", wp
.showCmd
);
11438 ok(wp
.ptMinPosition
.x
== -32000 && wp
.ptMinPosition
.y
== -32000,
11439 "got minimized pos (%d,%d)\n", wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
);
11441 ok(wp
.ptMaxPosition
.x
== -1 && wp
.ptMaxPosition
.y
== -1,
11442 "got maximized pos (%d,%d)\n", wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
);
11443 ok(EqualRect(&wp
.rcNormalPosition
, &orig
), "got normal pos %s\n",
11444 wine_dbgstr_rect(&wp
.rcNormalPosition
));
11446 ShowWindow(hwnd
, SW_RESTORE
);
11448 ret
= GetWindowPlacement(hwnd
, &wp
);
11449 ok(ret
, "failed to get window placement, error %u\n", GetLastError());
11450 ok(wp
.showCmd
== SW_SHOWMAXIMIZED
, "got show cmd %u\n", wp
.showCmd
);
11451 ok(wp
.ptMinPosition
.x
== -32000 && wp
.ptMinPosition
.y
== -32000,
11452 "got minimized pos (%d,%d)\n", wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
);
11454 ok(wp
.ptMaxPosition
.x
== -1 && wp
.ptMaxPosition
.y
== -1,
11455 "got maximized pos (%d,%d)\n", wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
);
11456 ok(EqualRect(&wp
.rcNormalPosition
, &orig
), "got normal pos %s\n",
11457 wine_dbgstr_rect(&wp
.rcNormalPosition
));
11459 ShowWindow(hwnd
, SW_RESTORE
);
11461 ret
= GetWindowPlacement(hwnd
, &wp
);
11462 ok(ret
, "failed to get window placement, error %u\n", GetLastError());
11463 ok(wp
.showCmd
== SW_SHOWNORMAL
, "got show cmd %u\n", wp
.showCmd
);
11464 ok(wp
.ptMinPosition
.x
== -32000 && wp
.ptMinPosition
.y
== -32000,
11465 "got minimized pos (%d,%d)\n", wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
);
11467 ok(wp
.ptMaxPosition
.x
== -1 && wp
.ptMaxPosition
.y
== -1,
11468 "got maximized pos (%d,%d)\n", wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
);
11469 ok(EqualRect(&wp
.rcNormalPosition
, &orig
), "got normal pos %s\n",
11470 wine_dbgstr_rect(&wp
.rcNormalPosition
));
11472 wp
.flags
= WPF_SETMINPOSITION
;
11473 wp
.ptMinPosition
.x
= wp
.ptMinPosition
.y
= 100;
11474 wp
.ptMaxPosition
.x
= wp
.ptMaxPosition
.y
= 100;
11475 wp
.rcNormalPosition
= orig2
;
11476 ret
= SetWindowPlacement(hwnd
, &wp
);
11477 ok(ret
, "failed to set window placement, error %u\n", GetLastError());
11479 ret
= GetWindowPlacement(hwnd
, &wp
);
11480 ok(ret
, "failed to get window placement, error %u\n", GetLastError());
11481 ok(wp
.showCmd
== SW_SHOWNORMAL
, "got show cmd %u\n", wp
.showCmd
);
11482 ok(wp
.ptMinPosition
.x
== 100 && wp
.ptMinPosition
.y
== 100,
11483 "got minimized pos (%d,%d)\n", wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
);
11485 ok(wp
.ptMaxPosition
.x
== -1 && wp
.ptMaxPosition
.y
== -1,
11486 "got maximized pos (%d,%d)\n", wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
);
11487 ok(EqualRect(&wp
.rcNormalPosition
, &orig2
), "got normal pos %s\n",
11488 wine_dbgstr_rect(&wp
.rcNormalPosition
));
11489 GetWindowRect(hwnd
, &rect
);
11490 ok(EqualRect(&rect
, &orig2
), "got window rect %s\n", wine_dbgstr_rect(&rect
));
11492 ShowWindow(hwnd
, SW_MINIMIZE
);
11494 ret
= GetWindowPlacement(hwnd
, &wp
);
11495 ok(ret
, "failed to get window placement, error %u\n", GetLastError());
11496 ok(!wp
.flags
, "got flags %#x\n", wp
.flags
);
11497 ok(wp
.showCmd
== SW_SHOWMINIMIZED
, "got show cmd %u\n", wp
.showCmd
);
11498 ok(wp
.ptMinPosition
.x
== -32000 && wp
.ptMinPosition
.y
== -32000,
11499 "got minimized pos (%d,%d)\n", wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
);
11501 ok(wp
.ptMaxPosition
.x
== -1 && wp
.ptMaxPosition
.y
== -1,
11502 "got maximized pos (%d,%d)\n", wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
);
11503 ok(EqualRect(&wp
.rcNormalPosition
, &orig2
), "got normal pos %s\n",
11504 wine_dbgstr_rect(&wp
.rcNormalPosition
));
11506 ShowWindow(hwnd
, SW_RESTORE
);
11508 wp
.flags
= WPF_SETMINPOSITION
;
11509 wp
.showCmd
= SW_MINIMIZE
;
11510 wp
.ptMinPosition
.x
= wp
.ptMinPosition
.y
= 100;
11511 wp
.ptMaxPosition
.x
= wp
.ptMaxPosition
.y
= 100;
11512 wp
.rcNormalPosition
= orig
;
11513 ret
= SetWindowPlacement(hwnd
, &wp
);
11514 ok(ret
, "failed to set window placement, error %u\n", GetLastError());
11516 ret
= GetWindowPlacement(hwnd
, &wp
);
11517 ok(ret
, "failed to get window placement, error %u\n", GetLastError());
11518 ok(!wp
.flags
, "got flags %#x\n", wp
.flags
);
11519 ok(wp
.showCmd
== SW_SHOWMINIMIZED
, "got show cmd %u\n", wp
.showCmd
);
11520 ok(wp
.ptMinPosition
.x
== -32000 && wp
.ptMinPosition
.y
== -32000,
11521 "got minimized pos (%d,%d)\n", wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
);
11523 ok(wp
.ptMaxPosition
.x
== -1 && wp
.ptMaxPosition
.y
== -1,
11524 "got maximized pos (%d,%d)\n", wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
);
11525 ok(EqualRect(&wp
.rcNormalPosition
, &orig
), "got normal pos %s\n",
11526 wine_dbgstr_rect(&wp
.rcNormalPosition
));
11528 ShowWindow(hwnd
, SW_RESTORE
);
11530 wp
.flags
= WPF_SETMINPOSITION
;
11531 wp
.showCmd
= SW_MAXIMIZE
;
11532 wp
.ptMinPosition
.x
= wp
.ptMinPosition
.y
= 100;
11533 wp
.ptMaxPosition
.x
= wp
.ptMaxPosition
.y
= 100;
11534 wp
.rcNormalPosition
= orig
;
11535 ret
= SetWindowPlacement(hwnd
, &wp
);
11536 ok(ret
, "failed to set window placement, error %u\n", GetLastError());
11538 ret
= GetWindowPlacement(hwnd
, &wp
);
11539 ok(ret
, "failed to get window placement, error %u\n", GetLastError());
11540 ok(wp
.showCmd
== SW_SHOWMAXIMIZED
, "got show cmd %u\n", wp
.showCmd
);
11541 ok(wp
.ptMinPosition
.x
== 100 && wp
.ptMinPosition
.y
== 100,
11542 "got minimized pos (%d,%d)\n", wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
);
11544 ok(wp
.ptMaxPosition
.x
== -1 && wp
.ptMaxPosition
.y
== -1,
11545 "got maximized pos (%d,%d)\n", wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
);
11546 ok(EqualRect(&wp
.rcNormalPosition
, &orig
), "got normal pos %s\n",
11547 wine_dbgstr_rect(&wp
.rcNormalPosition
));
11549 wp
.flags
= WPF_SETMINPOSITION
;
11550 wp
.showCmd
= SW_NORMAL
;
11551 wp
.ptMinPosition
.x
= wp
.ptMinPosition
.y
= 100;
11552 wp
.ptMaxPosition
.x
= wp
.ptMaxPosition
.y
= 100;
11553 wp
.rcNormalPosition
= orig
;
11554 ret
= SetWindowPlacement(hwnd
, &wp
);
11555 ok(ret
, "failed to set window placement, error %u\n", GetLastError());
11557 ShowWindow(hwnd
, SW_MINIMIZE
);
11559 ret
= GetWindowPlacement(hwnd
, &wp
);
11560 ok(ret
, "failed to get window placement, error %u\n", GetLastError());
11561 ok(wp
.showCmd
== SW_SHOWMINIMIZED
, "got show cmd %u\n", wp
.showCmd
);
11562 ok(wp
.ptMinPosition
.x
== -32000 && wp
.ptMinPosition
.y
== -32000,
11563 "got minimized pos (%d,%d)\n", wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
);
11565 ok(wp
.ptMaxPosition
.x
== -1 && wp
.ptMaxPosition
.y
== -1,
11566 "got maximized pos (%d,%d)\n", wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
);
11567 ok(EqualRect(&wp
.rcNormalPosition
, &orig
), "got normal pos %s\n",
11568 wine_dbgstr_rect(&wp
.rcNormalPosition
));
11570 ret
= SetWindowPos(hwnd
, NULL
, 100, 100, 151, 151, SWP_NOACTIVATE
| SWP_NOZORDER
);
11571 ok(ret
, "failed to set window pos, error %u\n", GetLastError());
11573 ret
= GetWindowPlacement(hwnd
, &wp
);
11574 ok(ret
, "failed to get window placement, error %u\n", GetLastError());
11575 ok(wp
.showCmd
== SW_SHOWMINIMIZED
, "got show cmd %u\n", wp
.showCmd
);
11576 ok(wp
.ptMinPosition
.x
== -32000 && wp
.ptMinPosition
.y
== -32000,
11577 "got minimized pos (%d,%d)\n", wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
);
11579 ok(wp
.ptMaxPosition
.x
== -1 && wp
.ptMaxPosition
.y
== -1,
11580 "got maximized pos (%d,%d)\n", wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
);
11581 ok(EqualRect(&wp
.rcNormalPosition
, &orig
), "got normal pos %s\n",
11582 wine_dbgstr_rect(&wp
.rcNormalPosition
));
11583 GetWindowRect(hwnd
, &rect
);
11584 ok(rect
.left
== -32000 && rect
.top
== -32000, "got window rect %s\n", wine_dbgstr_rect(&rect
));
11586 ShowWindow(hwnd
, SW_SHOWNORMAL
);
11588 ret
= GetWindowPlacement(hwnd
, &wp
);
11589 ok(ret
, "failed to get window placement, error %u\n", GetLastError());
11590 ok(wp
.showCmd
== SW_NORMAL
, "got show cmd %u\n", wp
.showCmd
);
11591 ok(wp
.ptMinPosition
.x
== -32000 && wp
.ptMinPosition
.y
== -32000,
11592 "got minimized pos (%d,%d)\n", wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
);
11594 ok(wp
.ptMaxPosition
.x
== -1 && wp
.ptMaxPosition
.y
== -1,
11595 "got maximized pos (%d,%d)\n", wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
);
11596 ok(EqualRect(&wp
.rcNormalPosition
, &orig
), "got normal pos %s\n",
11597 wine_dbgstr_rect(&wp
.rcNormalPosition
));
11598 GetWindowRect(hwnd
, &rect
);
11599 ok(EqualRect(&rect
, &orig
), "got window rect %s\n", wine_dbgstr_rect(&rect
));
11601 DestroyWindow(hwnd
);
11604 static void test_arrange_iconic_windows(void)
11606 MINIMIZEDMETRICS mm
= {sizeof(mm
)}, oldmm
= {sizeof(oldmm
)};
11607 RECT orig
= {100, 200, 300, 400}, rect
, expect
, parent_rect
;
11609 HWND parent
, hwnds
[10];
11613 parent
= CreateWindowA("MainWindowClass", "parent", WS_OVERLAPPEDWINDOW
,
11614 100, 200, 500, 300, NULL
, 0, 0, NULL
);
11615 ok(!!parent
, "failed to create window, error %u\n", GetLastError());
11617 GetClientRect(parent
, &parent_rect
);
11618 ClientToScreen(parent
, &pt
);
11619 SystemParametersInfoA(SPI_GETMINIMIZEDMETRICS
, sizeof(oldmm
), &oldmm
, 0);
11624 mm
.iArrange
= ARW_TOPLEFT
| ARW_RIGHT
;
11625 ret
= SystemParametersInfoA(SPI_SETMINIMIZEDMETRICS
, sizeof(mm
), &mm
, 0);
11626 ok(ret
, "failed to set minimized metrics, error %u\n", GetLastError());
11628 SetLastError(0xdeadbeef);
11629 ret
= ArrangeIconicWindows(parent
);
11630 ok(!ret
, "wrong ret %u\n", ret
);
11631 ok(GetLastError() == 0xdeadbeef, "wrong error %u\n", GetLastError());
11633 for (i
= 0; i
< ARRAY_SIZE(hwnds
); ++i
)
11635 hwnds
[i
] = CreateWindowA("MainWindowClass", "child", WS_CHILD
|
11636 WS_OVERLAPPEDWINDOW
, orig
.left
, orig
.top
, orig
.right
- orig
.left
,
11637 orig
.bottom
- orig
.top
, parent
, 0, 0, NULL
);
11638 ok(!!hwnds
[i
], "failed to create window %u, error %u\n", i
, GetLastError());
11641 SetLastError(0xdeadbeef);
11642 ret
= ArrangeIconicWindows(parent
);
11643 ok(!ret
, "wrong ret %u\n", ret
);
11644 ok(GetLastError() == 0xdeadbeef, "wrong error %u\n", GetLastError());
11646 for (i
= 0; i
< ARRAY_SIZE(hwnds
); ++i
)
11648 GetWindowRect(hwnds
[i
], &rect
);
11650 OffsetRect(&expect
, pt
.x
, pt
.y
);
11651 ok(EqualRect(&rect
, &expect
), "hwnd %u: expected rect %s, got %s\n", i
,
11652 wine_dbgstr_rect(&expect
), wine_dbgstr_rect(&rect
));
11655 ShowWindow(hwnds
[0], SW_MINIMIZE
);
11657 for (i
= 0; i
< ARRAY_SIZE(hwnds
); ++i
)
11659 ret
= SetWindowPos(hwnds
[i
], 0, orig
.left
, orig
.top
, 0, 0,
11660 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
11661 ok(ret
, "hwnd %u: failed to move window, error %u\n", i
, GetLastError());
11664 ret
= ArrangeIconicWindows(parent
);
11665 ok(ret
== 1, "wrong ret %u\n", ret
);
11667 GetWindowRect(hwnds
[0], &rect
);
11668 SetRect(&expect
, 0, 0, GetSystemMetrics(SM_CXMINIMIZED
), GetSystemMetrics(SM_CYMINIMIZED
));
11669 OffsetRect(&expect
, mm
.iHorzGap
, mm
.iVertGap
);
11670 OffsetRect(&expect
, pt
.x
, pt
.y
);
11671 ok(EqualRect(&rect
, &expect
), "expected rect %s, got %s\n",
11672 wine_dbgstr_rect(&expect
), wine_dbgstr_rect(&rect
));
11674 for (i
= 1; i
< ARRAY_SIZE(hwnds
); ++i
)
11676 GetWindowRect(hwnds
[i
], &rect
);
11678 OffsetRect(&expect
, pt
.x
, pt
.y
);
11679 ok(EqualRect(&rect
, &expect
), "hwnd %u: expected rect %s, got %s\n", i
,
11680 wine_dbgstr_rect(&expect
), wine_dbgstr_rect(&rect
));
11683 for (i
= 0; i
< ARRAY_SIZE(hwnds
); ++i
)
11685 ShowWindow(hwnds
[i
], SW_MINIMIZE
);
11686 ret
= SetWindowPos(hwnds
[i
], 0, orig
.left
, orig
.top
, 0, 0,
11687 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
11688 ok(ret
, "hwnd %u: failed to move window, error %u\n", i
, GetLastError());
11691 ret
= ArrangeIconicWindows(parent
);
11692 ok(ret
== 10, "wrong ret %u\n", ret
);
11696 for (i
= 0; i
< ARRAY_SIZE(hwnds
); ++i
)
11698 if (col
+ GetSystemMetrics(SM_CXMINIMIZED
) > parent_rect
.right
- parent_rect
.left
)
11701 row
+= GetSystemMetrics(SM_CYMINIMIZED
) + mm
.iVertGap
;
11704 GetWindowRect(hwnds
[i
], &rect
);
11705 SetRect(&expect
, col
, row
, col
+ GetSystemMetrics(SM_CXMINIMIZED
),
11706 row
+ GetSystemMetrics(SM_CYMINIMIZED
));
11707 OffsetRect(&expect
, pt
.x
, pt
.y
);
11708 ok(EqualRect(&rect
, &expect
), "hwnd %u: expected rect %s, got %s\n", i
,
11709 wine_dbgstr_rect(&expect
), wine_dbgstr_rect(&rect
));
11711 col
+= GetSystemMetrics(SM_CXMINIMIZED
) + mm
.iHorzGap
;
11714 mm
.iArrange
= ARW_BOTTOMRIGHT
| ARW_UP
;
11716 ret
= SystemParametersInfoA(SPI_SETMINIMIZEDMETRICS
, sizeof(mm
), &mm
, 0);
11717 ok(ret
, "failed to set minimized metrics, error %u\n", GetLastError());
11719 for (i
= 0; i
< ARRAY_SIZE(hwnds
); ++i
)
11721 ret
= SetWindowPos(hwnds
[i
], 0, orig
.left
, orig
.top
, 0, 0,
11722 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
11723 ok(ret
, "hwnd %u: failed to move window, error %u\n", i
, GetLastError());
11726 ret
= ArrangeIconicWindows(parent
);
11727 ok(ret
== 10, "wrong ret %u\n", ret
);
11729 col
= parent_rect
.right
- mm
.iHorzGap
;
11730 row
= parent_rect
.bottom
- mm
.iVertGap
;
11731 for (i
= 0; i
< ARRAY_SIZE(hwnds
); ++i
)
11733 if (row
- GetSystemMetrics(SM_CYMINIMIZED
) < parent_rect
.top
)
11735 row
= parent_rect
.bottom
- mm
.iVertGap
;
11736 col
-= GetSystemMetrics(SM_CXMINIMIZED
) + mm
.iHorzGap
;
11739 GetWindowRect(hwnds
[i
], &rect
);
11740 SetRect(&expect
, col
- GetSystemMetrics(SM_CXMINIMIZED
),
11741 row
- GetSystemMetrics(SM_CYMINIMIZED
), col
, row
);
11742 OffsetRect(&expect
, pt
.x
, pt
.y
);
11743 ok(EqualRect(&rect
, &expect
), "hwnd %u: expected rect %s, got %s\n", i
,
11744 wine_dbgstr_rect(&expect
), wine_dbgstr_rect(&rect
));
11746 row
-= GetSystemMetrics(SM_CYMINIMIZED
) + mm
.iVertGap
;
11749 for (i
= 0; i
< ARRAY_SIZE(hwnds
); ++i
)
11750 DestroyWindow(hwnds
[i
]);
11751 DestroyWindow(parent
);
11753 ret
= SystemParametersInfoA(SPI_SETMINIMIZEDMETRICS
, sizeof(oldmm
), &oldmm
, 0);
11754 ok(ret
, "failed to restore minimized metrics, error %u\n", GetLastError());
11757 static void other_process_proc(HWND hwnd
)
11759 HANDLE window_ready_event
, test_done_event
;
11760 WINDOWPLACEMENT wp
;
11763 window_ready_event
= OpenEventA(EVENT_ALL_ACCESS
, FALSE
, "test_opw_window");
11764 ok(!!window_ready_event
, "OpenEvent failed.\n");
11765 test_done_event
= OpenEventA(EVENT_ALL_ACCESS
, FALSE
, "test_opw_test");
11766 ok(!!test_done_event
, "OpenEvent failed.\n");
11769 ret
= WaitForSingleObject(window_ready_event
, 5000);
11770 ok(ret
== WAIT_OBJECT_0
, "Unexpected ret %x.\n", ret
);
11771 ret
= GetWindowPlacement(hwnd
, &wp
);
11772 ok(ret
, "Unexpected ret %#x.\n", ret
);
11773 ok(wp
.showCmd
== SW_SHOWNORMAL
, "Unexpected showCmd %#x.\n", wp
.showCmd
);
11774 ok(!wp
.flags
, "Unexpected flags %#x.\n", wp
.flags
);
11775 SetEvent(test_done_event
);
11777 /* SW_SHOWMAXIMIZED */
11778 ret
= WaitForSingleObject(window_ready_event
, 5000);
11779 ok(ret
== WAIT_OBJECT_0
, "Unexpected ret %x.\n", ret
);
11780 ret
= GetWindowPlacement(hwnd
, &wp
);
11781 ok(ret
, "Unexpected ret %#x.\n", ret
);
11782 ok(wp
.showCmd
== SW_SHOWMAXIMIZED
, "Unexpected showCmd %#x.\n", wp
.showCmd
);
11783 todo_wine
ok(wp
.flags
== WPF_RESTORETOMAXIMIZED
, "Unexpected flags %#x.\n", wp
.flags
);
11784 SetEvent(test_done_event
);
11786 /* SW_SHOWMINIMIZED */
11787 ret
= WaitForSingleObject(window_ready_event
, 5000);
11788 ok(ret
== WAIT_OBJECT_0
, "Unexpected ret %x.\n", ret
);
11789 ret
= GetWindowPlacement(hwnd
, &wp
);
11790 ok(ret
, "Unexpected ret %#x.\n", ret
);
11791 ok(wp
.showCmd
== SW_SHOWMINIMIZED
, "Unexpected showCmd %#x.\n", wp
.showCmd
);
11792 todo_wine
ok(wp
.flags
== WPF_RESTORETOMAXIMIZED
, "Unexpected flags %#x.\n", wp
.flags
);
11793 SetEvent(test_done_event
);
11796 ret
= WaitForSingleObject(window_ready_event
, 5000);
11797 ok(ret
== WAIT_OBJECT_0
, "Unexpected ret %x.\n", ret
);
11798 ret
= GetWindowPlacement(hwnd
, &wp
);
11799 ok(ret
, "Unexpected ret %#x.\n", ret
);
11800 ok(wp
.showCmd
== SW_SHOWMAXIMIZED
, "Unexpected showCmd %#x.\n", wp
.showCmd
);
11801 todo_wine
ok(wp
.flags
== WPF_RESTORETOMAXIMIZED
, "Unexpected flags %#x.\n", wp
.flags
);
11802 SetEvent(test_done_event
);
11804 CloseHandle(window_ready_event
);
11805 CloseHandle(test_done_event
);
11808 static void test_SC_SIZE(void)
11814 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
| WS_VISIBLE
,
11815 100, 100, 100, 100, 0, 0, NULL
, NULL
);
11816 ok(!!hwnd
, "CreateWindowEx failed.\n");
11818 GetWindowRect(hwnd
, &rect
);
11819 ok(rect
.left
== 100, "rect.left = %d\n", rect
.left
);
11820 ok(rect
.top
== 100, "rect.top = %d\n", rect
.top
);
11821 ok(rect
.right
== 200, "rect.right = %d\n", rect
.right
);
11822 ok(rect
.bottom
== 200, "rect.bottom = %d\n", rect
.bottom
);
11824 SetCursorPos(100, 100);
11825 PostMessageA(hwnd
, WM_SYSCOMMAND
, SC_SIZE
| 9, MAKELONG(100, 100));
11826 SetCursorPos(110, 100);
11827 PostMessageA(hwnd
, WM_MOUSEMOVE
, 0, MAKELONG(110, 100));
11828 PostMessageA(hwnd
, WM_KEYDOWN
, VK_RETURN
, 0);
11830 while (GetMessageA(&msg
, 0, 0, 0))
11832 TranslateMessage(&msg
);
11833 DispatchMessageA(&msg
);
11835 if (msg
.message
== WM_SYSCOMMAND
) break;
11838 GetWindowRect(hwnd
, &rect
);
11839 ok(rect
.left
== 110, "rect.left = %d\n", rect
.left
);
11840 ok(rect
.top
== 100, "rect.top = %d\n", rect
.top
);
11841 ok(rect
.right
== 210, "rect.right = %d\n", rect
.right
);
11842 ok(rect
.bottom
== 200, "rect.bottom = %d\n", rect
.bottom
);
11844 DestroyWindow(hwnd
);
11847 static void test_other_process_window(const char *argv0
)
11849 HANDLE window_ready_event
, test_done_event
;
11850 PROCESS_INFORMATION info
;
11851 STARTUPINFOA startup
;
11852 char cmd
[MAX_PATH
];
11856 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
11857 100, 100, 100, 100, 0, 0, NULL
, NULL
);
11858 ok(!!hwnd
, "CreateWindowEx failed.\n");
11860 window_ready_event
= CreateEventA(NULL
, FALSE
, FALSE
, "test_opw_window");
11861 ok(!!window_ready_event
, "CreateEvent failed.\n");
11862 test_done_event
= CreateEventA(NULL
, FALSE
, FALSE
, "test_opw_test");
11863 ok(!!test_done_event
, "CreateEvent failed.\n");
11865 sprintf(cmd
, "%s win test_other_process_window %p", argv0
, hwnd
);
11866 memset(&startup
, 0, sizeof(startup
));
11867 startup
.cb
= sizeof(startup
);
11869 ok(CreateProcessA(NULL
, cmd
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
,
11870 &startup
, &info
), "CreateProcess failed.\n");
11872 ret
= ShowWindow(hwnd
, SW_SHOW
);
11873 ok(!ret
, "Unexpected ret %#x.\n", ret
);
11874 SetEvent(window_ready_event
);
11875 ret
= WaitForSingleObject(test_done_event
, 5000);
11876 ok(ret
== WAIT_OBJECT_0
, "Unexpected ret %x.\n", ret
);
11878 ret
= ShowWindow(hwnd
, SW_SHOWMAXIMIZED
);
11879 ok(ret
, "Unexpected ret %#x.\n", ret
);
11880 SetEvent(window_ready_event
);
11881 ret
= WaitForSingleObject(test_done_event
, 5000);
11882 ok(ret
== WAIT_OBJECT_0
, "Unexpected ret %x.\n", ret
);
11884 ret
= ShowWindow(hwnd
, SW_SHOWMINIMIZED
);
11885 ok(ret
, "Unexpected ret %#x.\n", ret
);
11886 SetEvent(window_ready_event
);
11887 ret
= WaitForSingleObject(test_done_event
, 5000);
11888 ok(ret
== WAIT_OBJECT_0
, "Unexpected ret %x.\n", ret
);
11890 ret
= ShowWindow(hwnd
, SW_RESTORE
);
11891 ok(ret
, "Unexpected ret %#x.\n", ret
);
11892 SetEvent(window_ready_event
);
11893 ret
= WaitForSingleObject(test_done_event
, 5000);
11894 ok(ret
== WAIT_OBJECT_0
, "Unexpected ret %x.\n", ret
);
11896 wait_child_process(info
.hProcess
);
11897 CloseHandle(window_ready_event
);
11898 CloseHandle(test_done_event
);
11899 CloseHandle(info
.hProcess
);
11900 CloseHandle(info
.hThread
);
11901 DestroyWindow(hwnd
);
11904 static void test_cancel_mode(void)
11906 HWND hwnd1
, hwnd2
, child
;
11909 hwnd1
= CreateWindowA("MainWindowClass", "window 1", WS_OVERLAPPEDWINDOW
,
11910 100, 200, 500, 300, NULL
, NULL
, NULL
, NULL
);
11911 hwnd2
= CreateWindowA("MainWindowClass", "window 2", WS_OVERLAPPEDWINDOW
,
11912 100, 200, 500, 300, NULL
, NULL
, NULL
, NULL
);
11913 flush_events(TRUE
);
11915 ok(GetCapture() == hwnd1
, "got capture %p\n", GetCapture());
11917 ret
= SendMessageA(hwnd2
, WM_CANCELMODE
, 0, 0);
11918 ok(!ret
, "got %ld\n", ret
);
11919 ok(GetCapture() == hwnd1
, "got capture %p\n", GetCapture());
11921 ret
= SendMessageA(hwnd1
, WM_CANCELMODE
, 0, 0);
11922 ok(!ret
, "got %ld\n", ret
);
11923 ok(!GetCapture(), "got capture %p\n", GetCapture());
11925 child
= CreateWindowA("MainWindowClass", "child", WS_CHILD
,
11926 0, 0, 100, 100, hwnd1
, NULL
, NULL
, NULL
);
11929 ok(GetCapture() == child
, "got capture %p\n", GetCapture());
11931 ret
= SendMessageA(hwnd2
, WM_CANCELMODE
, 0, 0);
11932 ok(!ret
, "got %ld\n", ret
);
11933 ok(GetCapture() == child
, "got capture %p\n", GetCapture());
11935 ret
= SendMessageA(hwnd1
, WM_CANCELMODE
, 0, 0);
11936 ok(!ret
, "got %ld\n", ret
);
11937 ok(GetCapture() == child
, "got capture %p\n", GetCapture());
11939 ret
= SendMessageA(child
, WM_CANCELMODE
, 0, 0);
11940 ok(!ret
, "got %ld\n", ret
);
11941 ok(!GetCapture(), "got capture %p\n", GetCapture());
11943 DestroyWindow(child
);
11944 DestroyWindow(hwnd1
);
11945 DestroyWindow(hwnd2
);
11951 int argc
= winetest_get_mainargs( &argv
);
11952 HMODULE user32
= GetModuleHandleA( "user32.dll" );
11953 HMODULE gdi32
= GetModuleHandleA("gdi32.dll");
11954 pGetWindowInfo
= (void *)GetProcAddress( user32
, "GetWindowInfo" );
11955 pGetWindowModuleFileNameA
= (void *)GetProcAddress( user32
, "GetWindowModuleFileNameA" );
11956 pGetLayeredWindowAttributes
= (void *)GetProcAddress( user32
, "GetLayeredWindowAttributes" );
11957 pSetLayeredWindowAttributes
= (void *)GetProcAddress( user32
, "SetLayeredWindowAttributes" );
11958 pUpdateLayeredWindow
= (void *)GetProcAddress( user32
, "UpdateLayeredWindow" );
11959 pUpdateLayeredWindowIndirect
= (void *)GetProcAddress( user32
, "UpdateLayeredWindowIndirect" );
11960 pGetWindowRgnBox
= (void *)GetProcAddress( user32
, "GetWindowRgnBox" );
11961 pGetGUIThreadInfo
= (void *)GetProcAddress( user32
, "GetGUIThreadInfo" );
11962 pGetProcessDefaultLayout
= (void *)GetProcAddress( user32
, "GetProcessDefaultLayout" );
11963 pSetProcessDefaultLayout
= (void *)GetProcAddress( user32
, "SetProcessDefaultLayout" );
11964 pFlashWindow
= (void *)GetProcAddress( user32
, "FlashWindow" );
11965 pFlashWindowEx
= (void *)GetProcAddress( user32
, "FlashWindowEx" );
11966 pMirrorRgn
= (void *)GetProcAddress( gdi32
, "MirrorRgn" );
11967 pGetWindowDisplayAffinity
= (void *)GetProcAddress( user32
, "GetWindowDisplayAffinity" );
11968 pSetWindowDisplayAffinity
= (void *)GetProcAddress( user32
, "SetWindowDisplayAffinity" );
11969 pAdjustWindowRectExForDpi
= (void *)GetProcAddress( user32
, "AdjustWindowRectExForDpi" );
11970 pSystemParametersInfoForDpi
= (void *)GetProcAddress( user32
, "SystemParametersInfoForDpi" );
11976 sscanf(argv
[3], "%p", &hwnd
);
11977 if (!strcmp(argv
[2], "create_children"))
11979 window_from_point_proc(hwnd
);
11982 else if (!strcmp(argv
[2], "test_other_process_window"))
11984 other_process_proc(hwnd
);
11989 if (argc
== 3 && !strcmp(argv
[2], "winproc_limit"))
11991 test_winproc_limit();
11995 if (!RegisterWindowClasses()) assert(0);
11997 hwndMain
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
11998 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
11999 WS_MAXIMIZEBOX
| WS_POPUP
| WS_VISIBLE
,
12000 100, 100, 200, 200,
12001 0, 0, GetModuleHandleA(NULL
), NULL
);
12002 assert( hwndMain
);
12004 if(!SetForegroundWindow(hwndMain
)) {
12005 /* workaround for foreground lock timeout */
12006 simulate_click(101, 101);
12007 ok(SetForegroundWindow(hwndMain
), "SetForegroundWindow failed\n");
12010 SetLastError(0xdeafbeef);
12011 GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC
);
12013 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
12014 if (!hhook
) win_skip( "Cannot set CBT hook, skipping some tests\n" );
12016 /* make sure that these tests are executed first */
12017 test_FindWindowEx();
12021 hwndMain2
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
12022 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
12023 WS_MAXIMIZEBOX
| WS_POPUP
,
12024 100, 100, 200, 200,
12025 0, 0, GetModuleHandleA(NULL
), NULL
);
12026 assert( hwndMain2
);
12028 our_pid
= GetWindowThreadProcessId(hwndMain
, NULL
);
12030 /* Add the tests below this line */
12031 test_child_window_from_point();
12032 test_window_from_point(argv
[0]);
12033 test_thick_child_size(hwndMain
);
12035 test_hwnd_message();
12036 test_nonclient_area(hwndMain
);
12038 test_GetWindowModuleFileName();
12041 test_capture_3(hwndMain
, hwndMain2
);
12044 test_FlashWindow();
12045 test_FlashWindowEx();
12047 test_CreateWindow();
12048 test_parent_owner();
12049 test_enum_thread_windows();
12053 test_SetWindowPos(hwndMain
, hwndMain2
);
12054 test_SetMenu(hwndMain
);
12055 test_SetFocus(hwndMain
);
12056 test_SetActiveWindow(hwndMain
);
12059 test_children_zorder(hwndMain
);
12060 test_popup_zorder(hwndMain2
, hwndMain
, WS_POPUP
);
12061 test_popup_zorder(hwndMain2
, hwndMain
, 0);
12062 test_GetLastActivePopup();
12063 test_keyboard_input(hwndMain
);
12064 test_mouse_input(hwndMain
);
12065 test_validatergn(hwndMain
);
12066 test_nccalcscroll( hwndMain
);
12067 test_scrollwindow( hwndMain
);
12068 test_scrollvalidate( hwndMain
);
12069 test_scrolldc( hwndMain
);
12071 test_IsWindowUnicode();
12072 test_vis_rgn(hwndMain
);
12074 test_AdjustWindowRect();
12075 test_window_styles();
12076 test_dialog_styles();
12077 test_dialog_parent();
12080 test_SetWindowLong();
12081 test_set_window_style();
12083 test_ShowWindow_owned(hwndMain
);
12084 test_ShowWindow_child(hwndMain
);
12085 test_ShowWindow_mdichild(hwndMain
);
12086 test_EnableWindow();
12088 test_GetUpdateRect();
12090 test_layered_window();
12092 test_SetForegroundWindow(hwndMain
);
12093 test_handles( hwndMain
);
12096 test_update_region();
12097 test_window_without_child_style();
12099 test_GetMessagePos();
12100 test_activateapp(hwndMain
);
12101 test_winproc_handles(argv
[0]);
12102 test_deferwindowpos();
12103 test_LockWindowUpdate(hwndMain
);
12105 test_display_affinity(hwndMain
);
12106 test_hide_window();
12107 test_minimize_window(hwndMain
);
12108 test_destroy_quit();
12109 test_IsWindowEnabled();
12110 test_window_placement();
12111 test_arrange_iconic_windows();
12112 test_other_process_window(argv
[0]);
12114 test_cancel_mode();
12116 /* add the tests above this line */
12117 if (hhook
) UnhookWindowsHookEx(hhook
);
12119 DestroyWindow(hwndMain2
);
12120 DestroyWindow(hwndMain
);
12122 /* Make sure that following tests are executed last, under Windows they
12123 * tend to break the tests which are sensitive to z-order and activation
12124 * state of hwndMain and hwndMain2 windows.
12128 test_shell_window();