2 * Unit tests for window handling
4 * Copyright 2002 Bill Medland
5 * Copyright 2002 Alexandre Julliard
6 * Copyright 2003 Dmitry Timoshkov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 /* To get ICON_SMALL2 with the MSVC headers */
24 //#define _WIN32_WINNT 0x0501
36 #include "wine/test.h"
38 #ifndef SPI_GETDESKWALLPAPER
39 #define SPI_GETDESKWALLPAPER 0x0073
43 #define WM_SYSTIMER 0x0118
46 #define LONG_PTR INT_PTR
47 #define ULONG_PTR UINT_PTR
49 void dump_region(HRGN hrgn
);
51 static HWND (WINAPI
*pGetAncestor
)(HWND
,UINT
);
52 static BOOL (WINAPI
*pGetWindowInfo
)(HWND
,WINDOWINFO
*);
53 static UINT (WINAPI
*pGetWindowModuleFileNameA
)(HWND
,LPSTR
,UINT
);
54 static BOOL (WINAPI
*pGetLayeredWindowAttributes
)(HWND
,COLORREF
*,BYTE
*,DWORD
*);
55 static BOOL (WINAPI
*pSetLayeredWindowAttributes
)(HWND
,COLORREF
,BYTE
,DWORD
);
56 static BOOL (WINAPI
*pUpdateLayeredWindow
)(HWND
,HDC
,POINT
*,SIZE
*,HDC
,POINT
*,COLORREF
,BLENDFUNCTION
*,DWORD
);
57 static BOOL (WINAPI
*pUpdateLayeredWindowIndirect
)(HWND
,const UPDATELAYEREDWINDOWINFO
*);
58 static BOOL (WINAPI
*pGetMonitorInfoA
)(HMONITOR
,LPMONITORINFO
);
59 static HMONITOR (WINAPI
*pMonitorFromPoint
)(POINT
,DWORD
);
60 static int (WINAPI
*pGetWindowRgnBox
)(HWND
,LPRECT
);
61 static BOOL (WINAPI
*pGetGUIThreadInfo
)(DWORD
, GUITHREADINFO
*);
62 static BOOL (WINAPI
*pGetProcessDefaultLayout
)( DWORD
*layout
);
63 static BOOL (WINAPI
*pSetProcessDefaultLayout
)( DWORD layout
);
64 static BOOL (WINAPI
*pFlashWindow
)( HWND hwnd
, BOOL bInvert
);
65 static BOOL (WINAPI
*pFlashWindowEx
)( PFLASHWINFO pfwi
);
66 static DWORD (WINAPI
*pSetLayout
)(HDC hdc
, DWORD layout
);
67 static DWORD (WINAPI
*pGetLayout
)(HDC hdc
);
68 static BOOL (WINAPI
*pMirrorRgn
)(HWND hwnd
, HRGN hrgn
);
70 static BOOL test_lbuttondown_flag
;
71 static DWORD num_gettext_msgs
;
72 static DWORD num_settext_msgs
;
73 static HWND hwndMessage
;
74 static HWND hwndMain
, hwndMain2
;
76 static BOOL app_activated
, app_deactivated
;
78 static const char* szAWRClass
= "Winsize";
82 static BOOL is_win9x
= FALSE
;
84 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
86 static void dump_minmax_info( const MINMAXINFO
*minmax
)
88 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
89 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
90 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
91 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
92 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
93 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
96 /* try to make sure pending X events have been processed before continuing */
97 static void flush_events( BOOL remove_messages
)
101 int min_timeout
= 100;
102 DWORD time
= GetTickCount() + diff
;
106 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
108 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
109 diff
= time
- GetTickCount();
114 static BOOL
wait_for_event(HANDLE event
, int timeout
)
116 DWORD end_time
= GetTickCount() + timeout
;
120 if(MsgWaitForMultipleObjects(1, &event
, FALSE
, timeout
, QS_ALLINPUT
) == WAIT_OBJECT_0
)
122 while(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
123 DispatchMessageA(&msg
);
124 timeout
= end_time
- GetTickCount();
130 /* check the values returned by the various parent/owner functions on a given window */
131 static void check_parents( HWND hwnd
, HWND ga_parent
, HWND gwl_parent
, HWND get_parent
,
132 HWND gw_owner
, HWND ga_root
, HWND ga_root_owner
)
138 res
= pGetAncestor( hwnd
, GA_PARENT
);
139 ok( res
== ga_parent
, "Wrong result for GA_PARENT %p expected %p\n", res
, ga_parent
);
141 res
= (HWND
)GetWindowLongPtrA( hwnd
, GWLP_HWNDPARENT
);
142 ok( res
== gwl_parent
, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res
, gwl_parent
);
143 res
= GetParent( hwnd
);
144 ok( res
== get_parent
, "Wrong result for GetParent %p expected %p\n", res
, get_parent
);
145 res
= GetWindow( hwnd
, GW_OWNER
);
146 ok( res
== gw_owner
, "Wrong result for GW_OWNER %p expected %p\n", res
, gw_owner
);
149 res
= pGetAncestor( hwnd
, GA_ROOT
);
150 ok( res
== ga_root
, "Wrong result for GA_ROOT %p expected %p\n", res
, ga_root
);
151 res
= pGetAncestor( hwnd
, GA_ROOTOWNER
);
152 ok( res
== ga_root_owner
, "Wrong result for GA_ROOTOWNER %p expected %p\n", res
, ga_root_owner
);
156 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
157 static void check_wnd_state_(const char *file
, int line
,
158 HWND active
, HWND foreground
, HWND focus
, HWND capture
)
160 ok_(file
, line
)(active
== GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
161 /* only check foreground if it belongs to the current thread */
162 /* foreground can be moved to a different app pretty much at any time */
163 if (foreground
&& GetForegroundWindow() &&
164 GetWindowThreadProcessId(GetForegroundWindow(), NULL
) == GetCurrentThreadId())
165 ok_(file
, line
)(foreground
== GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
166 ok_(file
, line
)(focus
== GetFocus(), "GetFocus() = %p\n", GetFocus());
167 ok_(file
, line
)(capture
== GetCapture(), "GetCapture() = %p\n", GetCapture());
170 /* same as above but without capture test */
171 #define check_active_state(a,b,c) check_active_state_(__FILE__,__LINE__,a,b,c)
172 static void check_active_state_(const char *file
, int line
,
173 HWND active
, HWND foreground
, HWND focus
)
175 ok_(file
, line
)(active
== GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
176 /* only check foreground if it belongs to the current thread */
177 /* foreground can be moved to a different app pretty much at any time */
178 if (foreground
&& GetForegroundWindow() &&
179 GetWindowThreadProcessId(GetForegroundWindow(), NULL
) == GetCurrentThreadId())
180 ok_(file
, line
)(foreground
== GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
181 ok_(file
, line
)(focus
== GetFocus(), "GetFocus() = %p\n", GetFocus());
184 static BOOL
ignore_message( UINT message
)
186 /* these are always ignored */
187 return (message
>= 0xc000 ||
188 message
== WM_GETICON
||
189 message
== WM_GETOBJECT
||
190 message
== WM_TIMER
||
191 message
== WM_SYSTIMER
||
192 message
== WM_TIMECHANGE
||
193 message
== WM_DEVICECHANGE
);
196 static BOOL CALLBACK
EnumChildProc( HWND hwndChild
, LPARAM lParam
)
199 trace("EnumChildProc on %p\n", hwndChild
);
200 if (*(LPINT
)lParam
> 1) return FALSE
;
204 /* will search for the given window */
205 static BOOL CALLBACK
EnumChildProc1( HWND hwndChild
, LPARAM lParam
)
207 trace("EnumChildProc1 on %p\n", hwndChild
);
208 if ((HWND
)lParam
== hwndChild
) return FALSE
;
212 static HWND
create_tool_window( LONG style
, HWND parent
)
214 HWND ret
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style
,
215 0, 0, 100, 100, parent
, 0, 0, NULL
);
216 ok( ret
!= 0, "Creation failed\n" );
220 /* test parent and owner values for various combinations */
221 static void test_parent_owner(void)
224 HWND test
, owner
, ret
;
225 HWND desktop
= GetDesktopWindow();
226 HWND child
= create_tool_window( WS_CHILD
, hwndMain
);
229 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain
, hwndMain2
, desktop
, child
);
231 /* child without parent, should fail */
232 SetLastError(0xdeadbeef);
233 test
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
234 WS_CHILD
, 0, 0, 100, 100, 0, 0, 0, NULL
);
235 ok( !test
, "WS_CHILD without parent created\n" );
236 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD
||
237 broken(GetLastError() == 0xdeadbeef), /* win9x */
238 "CreateWindowExA error %u\n", GetLastError() );
241 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
242 style
= GetWindowLongA( desktop
, GWL_STYLE
);
243 ok( !SetWindowLongA( desktop
, GWL_STYLE
, WS_POPUP
), "Set GWL_STYLE on desktop succeeded\n" );
244 ok( !SetWindowLongA( desktop
, GWL_STYLE
, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
245 ok( GetWindowLongA( desktop
, GWL_STYLE
) == style
, "Desktop style changed\n" );
247 /* normal child window */
248 test
= create_tool_window( WS_CHILD
, hwndMain
);
249 trace( "created child %p\n", test
);
250 check_parents( test
, hwndMain
, hwndMain
, hwndMain
, 0, hwndMain
, hwndMain
);
251 SetWindowLongA( test
, GWL_STYLE
, 0 );
252 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
253 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
254 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
255 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
|WS_CHILD
);
256 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
257 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
258 DestroyWindow( test
);
260 /* normal child window with WS_MAXIMIZE */
261 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
262 DestroyWindow( test
);
264 /* normal child window with WS_THICKFRAME */
265 test
= create_tool_window( WS_CHILD
| WS_THICKFRAME
, hwndMain
);
266 DestroyWindow( test
);
268 /* popup window with WS_THICKFRAME */
269 test
= create_tool_window( WS_POPUP
| WS_THICKFRAME
, hwndMain
);
270 DestroyWindow( test
);
272 /* child of desktop */
273 test
= create_tool_window( WS_CHILD
, desktop
);
274 trace( "created child of desktop %p\n", test
);
275 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
276 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
277 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
278 SetWindowLongA( test
, GWL_STYLE
, 0 );
279 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
280 DestroyWindow( test
);
282 /* child of desktop with WS_MAXIMIZE */
283 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, desktop
);
284 DestroyWindow( test
);
286 /* child of desktop with WS_MINIMIZE */
287 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, desktop
);
288 DestroyWindow( test
);
291 test
= create_tool_window( WS_CHILD
, child
);
292 trace( "created child of child %p\n", test
);
293 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
294 SetWindowLongA( test
, GWL_STYLE
, 0 );
295 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
296 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
297 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
298 DestroyWindow( test
);
300 /* child of child with WS_MAXIMIZE */
301 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, child
);
302 DestroyWindow( test
);
304 /* child of child with WS_MINIMIZE */
305 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, child
);
306 DestroyWindow( test
);
308 /* not owned top-level window */
309 test
= create_tool_window( 0, 0 );
310 trace( "created top-level %p\n", test
);
311 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
312 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
313 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
314 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
315 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
316 DestroyWindow( test
);
318 /* not owned top-level window with WS_MAXIMIZE */
319 test
= create_tool_window( WS_MAXIMIZE
, 0 );
320 DestroyWindow( test
);
322 /* owned top-level window */
323 test
= create_tool_window( 0, hwndMain
);
324 trace( "created owned top-level %p\n", test
);
325 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
326 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
327 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
328 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
329 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
330 DestroyWindow( test
);
332 /* owned top-level window with WS_MAXIMIZE */
333 test
= create_tool_window( WS_MAXIMIZE
, hwndMain
);
334 DestroyWindow( test
);
336 /* not owned popup */
337 test
= create_tool_window( WS_POPUP
, 0 );
338 trace( "created popup %p\n", test
);
339 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
340 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
341 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
342 SetWindowLongA( test
, GWL_STYLE
, 0 );
343 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
344 DestroyWindow( test
);
346 /* not owned popup with WS_MAXIMIZE */
347 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, 0 );
348 DestroyWindow( test
);
351 test
= create_tool_window( WS_POPUP
, hwndMain
);
352 trace( "created owned popup %p\n", test
);
353 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
354 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
355 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
356 SetWindowLongA( test
, GWL_STYLE
, 0 );
357 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
358 DestroyWindow( test
);
360 /* owned popup with WS_MAXIMIZE */
361 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, hwndMain
);
362 DestroyWindow( test
);
364 /* top-level window owned by child (same as owned by top-level) */
365 test
= create_tool_window( 0, child
);
366 trace( "created top-level owned by child %p\n", test
);
367 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
368 DestroyWindow( test
);
370 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
371 test
= create_tool_window( WS_MAXIMIZE
, child
);
372 DestroyWindow( test
);
374 /* popup owned by desktop (same as not owned) */
375 test
= create_tool_window( WS_POPUP
, desktop
);
376 trace( "created popup owned by desktop %p\n", test
);
377 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
378 DestroyWindow( test
);
380 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
381 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, desktop
);
382 DestroyWindow( test
);
384 /* popup owned by child (same as owned by top-level) */
385 test
= create_tool_window( WS_POPUP
, child
);
386 trace( "created popup owned by child %p\n", test
);
387 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
388 DestroyWindow( test
);
390 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
391 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, child
);
392 DestroyWindow( test
);
394 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
395 test
= create_tool_window( WS_POPUP
| WS_CHILD
, 0 );
396 trace( "created WS_CHILD popup %p\n", test
);
397 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
398 DestroyWindow( test
);
400 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
401 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, 0 );
402 DestroyWindow( test
);
404 /* owned popup with WS_CHILD (same as WS_POPUP only) */
405 test
= create_tool_window( WS_POPUP
| WS_CHILD
, hwndMain
);
406 trace( "created owned WS_CHILD popup %p\n", test
);
407 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
408 DestroyWindow( test
);
410 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
411 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
412 DestroyWindow( test
);
414 /******************** parent changes *************************/
415 trace( "testing parent changes\n" );
418 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
421 /* this test succeeds on NT but crashes on win9x systems */
422 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
423 ok( !ret
, "Set GWL_HWNDPARENT succeeded on desktop\n" );
424 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
425 ok( !SetParent( desktop
, hwndMain
), "SetParent succeeded on desktop\n" );
426 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
428 /* normal child window */
429 test
= create_tool_window( WS_CHILD
, hwndMain
);
430 trace( "created child %p\n", test
);
432 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
433 ok( ret
== hwndMain
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain
);
434 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
436 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
437 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
438 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
440 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)desktop
);
441 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
442 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
444 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
447 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)test
);
448 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
449 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
452 win_skip("Test creates circular window tree under Win9x/WinMe\n" );
454 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
455 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
456 check_parents( test
, desktop
, child
, desktop
, child
, test
, desktop
);
458 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
459 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
460 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
461 DestroyWindow( test
);
463 /* not owned top-level window */
464 test
= create_tool_window( 0, 0 );
465 trace( "created top-level %p\n", test
);
467 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
468 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
469 check_parents( test
, desktop
, hwndMain2
, 0, hwndMain2
, test
, test
);
471 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
472 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
473 check_parents( test
, desktop
, child
, 0, child
, test
, test
);
475 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
476 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
477 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
478 DestroyWindow( test
);
480 /* not owned popup */
481 test
= create_tool_window( WS_POPUP
, 0 );
482 trace( "created popup %p\n", test
);
484 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
485 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
486 check_parents( test
, desktop
, hwndMain2
, hwndMain2
, hwndMain2
, test
, hwndMain2
);
488 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
489 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
490 check_parents( test
, desktop
, child
, child
, child
, test
, hwndMain
);
492 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
493 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
494 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
495 DestroyWindow( test
);
497 /* normal child window */
498 test
= create_tool_window( WS_CHILD
, hwndMain
);
499 trace( "created child %p\n", test
);
501 ret
= SetParent( test
, desktop
);
502 ok( ret
== hwndMain
, "SetParent return value %p expected %p\n", ret
, hwndMain
);
503 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
505 ret
= SetParent( test
, child
);
506 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
507 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
509 ret
= SetParent( test
, hwndMain2
);
510 ok( ret
== child
, "SetParent return value %p expected %p\n", ret
, child
);
511 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
512 DestroyWindow( test
);
514 /* not owned top-level window */
515 test
= create_tool_window( 0, 0 );
516 trace( "created top-level %p\n", test
);
518 ret
= SetParent( test
, child
);
519 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
520 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
524 ShowWindow( test
, SW_SHOW
);
525 ret
= SetParent( test
, test
);
526 ok( ret
== NULL
, "SetParent return value %p expected %p\n", ret
, NULL
);
527 ok( GetWindowLongA( test
, GWL_STYLE
) & WS_VISIBLE
, "window is not visible after SetParent\n" );
528 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
531 win_skip( "Test crashes on Win9x/WinMe\n" );
532 DestroyWindow( test
);
535 test
= create_tool_window( WS_POPUP
, hwndMain2
);
536 trace( "created owned popup %p\n", test
);
538 ret
= SetParent( test
, child
);
539 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
540 check_parents( test
, child
, child
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
542 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)hwndMain
);
543 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
544 check_parents( test
, hwndMain
, hwndMain
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
545 DestroyWindow( test
);
547 /**************** test owner destruction *******************/
549 /* owned child popup */
550 owner
= create_tool_window( 0, 0 );
551 test
= create_tool_window( WS_POPUP
, owner
);
552 trace( "created owner %p and popup %p\n", owner
, test
);
553 ret
= SetParent( test
, child
);
554 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
555 check_parents( test
, child
, child
, owner
, owner
, hwndMain
, owner
);
556 /* window is now child of 'child' but owned by 'owner' */
557 DestroyWindow( owner
);
558 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
559 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
560 * while Win95, Win2k, WinXP do.
562 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
563 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
566 /* owned top-level popup */
567 owner
= create_tool_window( 0, 0 );
568 test
= create_tool_window( WS_POPUP
, owner
);
569 trace( "created owner %p and popup %p\n", owner
, test
);
570 check_parents( test
, desktop
, owner
, owner
, owner
, test
, owner
);
571 DestroyWindow( owner
);
572 ok( !IsWindow(test
), "Window %p not destroyed by owner destruction\n", test
);
574 /* top-level popup owned by child */
575 owner
= create_tool_window( WS_CHILD
, hwndMain2
);
576 test
= create_tool_window( WS_POPUP
, 0 );
577 trace( "created owner %p and popup %p\n", owner
, test
);
578 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)owner
);
579 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
580 check_parents( test
, desktop
, owner
, owner
, owner
, test
, hwndMain2
);
581 DestroyWindow( owner
);
582 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
583 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
584 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
585 * while Win95, Win2k, WinXP do.
587 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
591 DestroyWindow(child
);
594 owner
= create_tool_window( WS_OVERLAPPED
, 0 );
595 test
= create_tool_window( WS_POPUP
, desktop
);
597 ok( !GetWindow( test
, GW_OWNER
), "Wrong owner window\n" );
599 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
600 "EnumChildWindows should have returned FALSE\n" );
601 ok( numChildren
== 0, "numChildren should be 0 got %d\n", numChildren
);
603 SetWindowLongA( test
, GWL_STYLE
, (GetWindowLongA( test
, GWL_STYLE
) & ~WS_POPUP
) | WS_CHILD
);
604 ret
= SetParent( test
, owner
);
605 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
608 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
609 "EnumChildWindows should have returned TRUE\n" );
610 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
612 child
= create_tool_window( WS_CHILD
, owner
);
614 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
615 "EnumChildWindows should have returned FALSE\n" );
616 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
617 DestroyWindow( child
);
619 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, owner
);
620 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
622 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
623 "EnumChildWindows should have returned TRUE\n" );
624 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
626 ret
= SetParent( child
, owner
);
627 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
628 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
630 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
631 "EnumChildWindows should have returned FALSE\n" );
632 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
634 ret
= SetParent( child
, NULL
);
635 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
636 ok( ret
== owner
, "SetParent return value %p expected %p\n", ret
, owner
);
638 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
639 "EnumChildWindows should have returned TRUE\n" );
640 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
642 /* even GW_OWNER == owner it's still a desktop's child */
643 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
644 "EnumChildWindows should have found %p and returned FALSE\n", child
);
646 DestroyWindow( child
);
647 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, NULL
);
649 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
650 "EnumChildWindows should have found %p and returned FALSE\n", child
);
652 DestroyWindow( child
);
653 DestroyWindow( test
);
654 DestroyWindow( owner
);
656 /* Test that owner window takes into account WS_CHILD flag even if parent is set by SetParent. */
657 owner
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, desktop
);
658 SetParent(owner
, hwndMain
);
659 check_parents( owner
, hwndMain
, hwndMain
, NULL
, NULL
, hwndMain
, owner
);
660 test
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, owner
);
661 check_parents( test
, desktop
, owner
, NULL
, owner
, test
, test
);
662 DestroyWindow( owner
);
663 DestroyWindow( test
);
665 owner
= create_tool_window( WS_VISIBLE
| WS_CHILD
, desktop
);
666 SetParent(owner
, hwndMain
);
667 check_parents( owner
, hwndMain
, hwndMain
, hwndMain
, NULL
, hwndMain
, hwndMain
);
668 test
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, owner
);
669 check_parents( test
, desktop
, hwndMain
, NULL
, hwndMain
, test
, test
);
670 DestroyWindow( owner
);
671 DestroyWindow( test
);
673 owner
= create_tool_window( WS_VISIBLE
| WS_POPUP
| WS_CHILD
, desktop
);
674 SetParent(owner
, hwndMain
);
675 check_parents( owner
, hwndMain
, hwndMain
, NULL
, NULL
, hwndMain
, owner
);
676 test
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, owner
);
677 check_parents( test
, desktop
, owner
, NULL
, owner
, test
, test
);
678 DestroyWindow( owner
);
679 DestroyWindow( test
);
682 static BOOL CALLBACK
enum_proc( HWND hwnd
, LPARAM lParam
)
685 if (*(LPINT
)lParam
> 2) return FALSE
;
688 static DWORD CALLBACK
enum_thread( void *arg
)
695 if (pGetGUIThreadInfo
)
698 info
.cbSize
= sizeof(info
);
699 ret
= pGetGUIThreadInfo( GetCurrentThreadId(), &info
);
700 ok( ret
|| broken(!ret
), /* win9x */
701 "GetGUIThreadInfo failed without message queue\n" );
702 SetLastError( 0xdeadbeef );
703 info
.cbSize
= sizeof(info
) + 1;
704 ret
= pGetGUIThreadInfo( GetCurrentThreadId(), &info
);
705 ok( !ret
, "GetGUIThreadInfo succeeded with wrong size\n" );
706 ok( GetLastError() == ERROR_INVALID_PARAMETER
||
707 broken(GetLastError() == 0xdeadbeef), /* win9x */
708 "wrong error %u\n", GetLastError() );
711 PeekMessageA( &msg
, 0, 0, 0, PM_NOREMOVE
); /* make sure we have a message queue */
714 ret
= EnumThreadWindows( GetCurrentThreadId(), enum_proc
, (LPARAM
)&count
);
715 ok( ret
, "EnumThreadWindows should have returned TRUE\n" );
716 ok( count
== 0, "count should be 0 got %d\n", count
);
718 hwnd
[0] = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", WS_POPUP
,
719 0, 0, 100, 100, 0, 0, 0, NULL
);
721 ret
= EnumThreadWindows( GetCurrentThreadId(), enum_proc
, (LPARAM
)&count
);
722 ok( ret
, "EnumThreadWindows should have returned TRUE\n" );
723 if (count
!= 2) /* Vista gives us two windows for the price of one */
725 ok( count
== 1, "count should be 1 got %d\n", count
);
726 hwnd
[2] = CreateWindowExA(0, "ToolWindowClass", "Tool window 2", WS_POPUP
,
727 0, 0, 100, 100, 0, 0, 0, NULL
);
731 hwnd
[1] = CreateWindowExA(0, "ToolWindowClass", "Tool window 3", WS_POPUP
,
732 0, 0, 100, 100, 0, 0, 0, NULL
);
734 ret
= EnumThreadWindows( GetCurrentThreadId(), enum_proc
, (LPARAM
)&count
);
735 ok( !ret
, "EnumThreadWindows should have returned FALSE\n" );
736 ok( count
== 3, "count should be 3 got %d\n", count
);
738 if (hwnd
[2]) DestroyWindow(hwnd
[2]);
739 DestroyWindow(hwnd
[1]);
740 DestroyWindow(hwnd
[0]);
744 /* test EnumThreadWindows in a separate thread */
745 static void test_enum_thread_windows(void)
748 HANDLE handle
= CreateThread( NULL
, 0, enum_thread
, 0, 0, &id
);
749 ok( !WaitForSingleObject( handle
, 10000 ), "wait failed\n" );
750 CloseHandle( handle
);
753 static struct wm_gettext_override_data
755 BOOL enabled
; /* when 1 bypasses default procedure */
756 char *buff
; /* expected text buffer pointer */
757 WCHAR
*buffW
; /* same, for W test */
758 } g_wm_gettext_override
;
760 static LRESULT WINAPI
main_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
764 case WM_GETMINMAXINFO
:
766 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
769 case WM_WINDOWPOSCHANGING
:
771 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
772 if (!(winpos
->flags
& SWP_NOMOVE
))
774 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
775 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
777 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
778 if (!(winpos
->flags
& SWP_NOSIZE
) && !is_win9x
)
780 ok((winpos
->cx
>= 0 && winpos
->cx
<= 32767) ||
781 winpos
->cx
== 32768, /* win7 doesn't truncate */
782 "bad winpos->cx %d\n", winpos
->cx
);
783 ok((winpos
->cy
>= 0 && winpos
->cy
<= 32767) ||
784 winpos
->cy
== 40000, /* win7 doesn't truncate */
785 "bad winpos->cy %d\n", winpos
->cy
);
789 case WM_WINDOWPOSCHANGED
:
792 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
793 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
794 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
796 ok((winpos
->cx
>= 0 && winpos
->cx
<= 32767) ||
797 winpos
->cx
== 32768, /* win7 doesn't truncate */
798 "bad winpos->cx %d\n", winpos
->cx
);
799 ok((winpos
->cy
>= 0 && winpos
->cy
<= 32767) ||
800 winpos
->cy
== 40000, /* win7 doesn't truncate */
801 "bad winpos->cy %d\n", winpos
->cy
);
803 GetWindowRect(hwnd
, &rc1
);
804 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
805 /* note: winpos coordinates are relative to parent */
806 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
809 /* Uncomment this once the test succeeds in all cases */
810 ok(EqualRect(&rc1
, &rc2
), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1
),
811 wine_dbgstr_rect(&rc2
));
813 GetClientRect(hwnd
, &rc2
);
814 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
815 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
816 ok(EqualRect(&rc1
, &rc2
), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1
),
817 wine_dbgstr_rect(&rc2
));
823 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
824 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
826 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
827 ok(got_getminmaxinfo
, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
829 ok(!got_getminmaxinfo
, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
833 if (test_lbuttondown_flag
)
835 ShowWindow((HWND
)wparam
, SW_SHOW
);
836 flush_events( FALSE
);
841 if (g_wm_gettext_override
.enabled
)
843 char *text
= (char*)lparam
;
844 ok(g_wm_gettext_override
.buff
== text
, "expected buffer %p, got %p\n", g_wm_gettext_override
.buff
, text
);
845 ok(*text
== 0, "expected empty string buffer %x\n", *text
);
853 if (wparam
) app_activated
= TRUE
;
854 else app_deactivated
= TRUE
;
858 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
861 static LRESULT WINAPI
main_window_procW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
867 if (g_wm_gettext_override
.enabled
)
869 WCHAR
*text
= (WCHAR
*)lparam
;
870 ok(g_wm_gettext_override
.buffW
== text
, "expected buffer %p, got %p\n", g_wm_gettext_override
.buffW
, text
);
871 ok(*text
== 0, "expected empty string buffer %x\n", *text
);
877 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
880 static LRESULT WINAPI
tool_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
884 case WM_GETMINMAXINFO
:
886 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
891 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
892 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
894 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
895 ok(got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
897 ok(!got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
902 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
905 static const WCHAR mainclassW
[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s','W',0};
907 static BOOL
RegisterWindowClasses(void)
912 cls
.style
= CS_DBLCLKS
;
913 cls
.lpfnWndProc
= main_window_procA
;
916 cls
.hInstance
= GetModuleHandleA(0);
918 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
919 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
920 cls
.lpszMenuName
= NULL
;
921 cls
.lpszClassName
= "MainWindowClass";
923 if(!RegisterClassA(&cls
)) return FALSE
;
925 clsW
.style
= CS_DBLCLKS
;
926 clsW
.lpfnWndProc
= main_window_procW
;
929 clsW
.hInstance
= GetModuleHandleA(0);
931 clsW
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
932 clsW
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
933 clsW
.lpszMenuName
= NULL
;
934 clsW
.lpszClassName
= mainclassW
;
936 if(!RegisterClassW(&clsW
)) return FALSE
;
939 cls
.lpfnWndProc
= tool_window_procA
;
942 cls
.hInstance
= GetModuleHandleA(0);
944 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
945 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
946 cls
.lpszMenuName
= NULL
;
947 cls
.lpszClassName
= "ToolWindowClass";
949 if(!RegisterClassA(&cls
)) return FALSE
;
954 static void verify_window_info(const char *hook
, HWND hwnd
, const WINDOWINFO
*info
)
956 RECT rcWindow
, rcClient
;
959 ok(IsWindow(hwnd
), "bad window handle %p in hook %s\n", hwnd
, hook
);
961 GetWindowRect(hwnd
, &rcWindow
);
962 ok(EqualRect(&rcWindow
, &info
->rcWindow
), "wrong rcWindow for %p in hook %s\n", hwnd
, hook
);
964 GetClientRect(hwnd
, &rcClient
);
965 /* translate to screen coordinates */
966 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rcClient
, 2);
967 ok(EqualRect(&rcClient
, &info
->rcClient
), "wrong rcClient for %p in hook %s\n", hwnd
, hook
);
969 ok(info
->dwStyle
== (DWORD
)GetWindowLongA(hwnd
, GWL_STYLE
),
970 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
971 info
->dwStyle
, GetWindowLongA(hwnd
, GWL_STYLE
), hwnd
, hook
);
972 /* Windows reports some undocumented exstyles in WINDOWINFO, but
973 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
975 ok((info
->dwExStyle
& ~0xe0000800) == (DWORD
)GetWindowLongA(hwnd
, GWL_EXSTYLE
),
976 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
977 info
->dwExStyle
, GetWindowLongA(hwnd
, GWL_EXSTYLE
), hwnd
, hook
);
978 status
= (GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0;
979 if (GetForegroundWindow())
980 ok(info
->dwWindowStatus
== status
, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
981 info
->dwWindowStatus
, status
, GetActiveWindow(), GetForegroundWindow(), hook
);
983 /* win2k and XP return broken border info in GetWindowInfo most of
984 * the time, so there is no point in testing it.
989 ok(info
->cxWindowBorders
== (unsigned)(rcClient
.left
- rcWindow
.left
),
990 "wrong cxWindowBorders %d != %d\n", info
->cxWindowBorders
, rcClient
.left
- rcWindow
.left
);
991 border
= min(rcWindow
.bottom
- rcClient
.bottom
, rcClient
.top
- rcWindow
.top
);
992 ok(info
->cyWindowBorders
== border
,
993 "wrong cyWindowBorders %d != %d\n", info
->cyWindowBorders
, border
);
995 ok(info
->atomWindowType
== GetClassLongA(hwnd
, GCW_ATOM
), "wrong atomWindowType for %p in hook %s\n",
997 ok(info
->wCreatorVersion
== 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
998 info
->wCreatorVersion
== 0x0500 /* Vista */,
999 "wrong wCreatorVersion %04x for %p in hook %s\n", info
->wCreatorVersion
, hwnd
, hook
);
1002 static void FixedAdjustWindowRectEx(RECT
* rc
, LONG style
, BOOL menu
, LONG exstyle
)
1004 AdjustWindowRectEx(rc
, style
, menu
, exstyle
);
1005 /* AdjustWindowRectEx does not include scroll bars */
1006 if (style
& WS_VSCROLL
)
1008 if(exstyle
& WS_EX_LEFTSCROLLBAR
)
1009 rc
->left
-= GetSystemMetrics(SM_CXVSCROLL
);
1011 rc
->right
+= GetSystemMetrics(SM_CXVSCROLL
);
1013 if (style
& WS_HSCROLL
)
1014 rc
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
1017 /* reimplement it to check that the Wine algorithm gives the correct result */
1018 static void wine_AdjustWindowRectEx( RECT
*rect
, LONG style
, BOOL menu
, LONG exStyle
)
1022 if ((exStyle
& (WS_EX_STATICEDGE
|WS_EX_DLGMODALFRAME
)) ==
1025 adjust
= 1; /* for the outer frame always present */
1030 if ((exStyle
& WS_EX_DLGMODALFRAME
) ||
1031 (style
& (WS_THICKFRAME
|WS_DLGFRAME
))) adjust
= 2; /* outer */
1033 if (style
& WS_THICKFRAME
)
1034 adjust
+= GetSystemMetrics(SM_CXFRAME
) - GetSystemMetrics(SM_CXDLGFRAME
); /* The resize border */
1035 if ((style
& (WS_BORDER
|WS_DLGFRAME
)) ||
1036 (exStyle
& WS_EX_DLGMODALFRAME
))
1037 adjust
++; /* The other border */
1039 InflateRect (rect
, adjust
, adjust
);
1041 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1043 if (exStyle
& WS_EX_TOOLWINDOW
)
1044 rect
->top
-= GetSystemMetrics(SM_CYSMCAPTION
);
1046 rect
->top
-= GetSystemMetrics(SM_CYCAPTION
);
1048 if (menu
) rect
->top
-= GetSystemMetrics(SM_CYMENU
);
1050 if (exStyle
& WS_EX_CLIENTEDGE
)
1051 InflateRect(rect
, GetSystemMetrics(SM_CXEDGE
), GetSystemMetrics(SM_CYEDGE
));
1053 if (style
& WS_VSCROLL
)
1055 if((exStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
1056 rect
->left
-= GetSystemMetrics(SM_CXVSCROLL
);
1058 rect
->right
+= GetSystemMetrics(SM_CXVSCROLL
);
1060 if (style
& WS_HSCROLL
) rect
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
1063 static void test_nonclient_area(HWND hwnd
)
1065 DWORD style
, exstyle
;
1066 RECT rc_window
, rc_client
, rc
;
1070 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1071 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1072 menu
= !(style
& WS_CHILD
) && GetMenu(hwnd
) != 0;
1074 GetWindowRect(hwnd
, &rc_window
);
1075 GetClientRect(hwnd
, &rc_client
);
1077 /* avoid some cases when things go wrong */
1078 if (IsRectEmpty(&rc_window
) || IsRectEmpty(&rc_client
) ||
1079 rc_window
.right
> 32768 || rc_window
.bottom
> 32768) return;
1082 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc
, 2);
1083 FixedAdjustWindowRectEx(&rc
, style
, menu
, exstyle
);
1085 ok(EqualRect(&rc
, &rc_window
),
1086 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=%s, calc=%s\n",
1087 style
, exstyle
, menu
, wine_dbgstr_rect(&rc_window
), wine_dbgstr_rect(&rc
));
1090 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc
, 2);
1091 wine_AdjustWindowRectEx(&rc
, style
, menu
, exstyle
);
1092 ok(EqualRect(&rc
, &rc_window
),
1093 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=%s, calc=%s\n",
1094 style
, exstyle
, menu
, wine_dbgstr_rect(&rc_window
), wine_dbgstr_rect(&rc
));
1098 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
1099 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
1100 ok(EqualRect(&rc
, &rc_client
),
1101 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=%s, calc=%s\n",
1102 style
, exstyle
, menu
, wine_dbgstr_rect(&rc_client
), wine_dbgstr_rect(&rc
));
1104 /* NULL rectangle shouldn't crash */
1105 ret
= DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, 0);
1106 ok(ret
== 0, "NULL rectangle returned %ld instead of 0\n", ret
);
1108 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
1112 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
1113 SetRect(&rc_client
, 0, 0, 250, 150);
1114 rc_window
= rc_client
;
1115 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc_window
, 2);
1116 FixedAdjustWindowRectEx(&rc_window
, style
, menu
, exstyle
);
1119 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
1120 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
1121 ok(EqualRect(&rc
, &rc_client
),
1122 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=%s, calc=%s\n",
1123 style
, exstyle
, menu
, wine_dbgstr_rect(&rc_client
), wine_dbgstr_rect(&rc
));
1126 static LRESULT CALLBACK
cbt_hook_proc(int nCode
, WPARAM wParam
, LPARAM lParam
)
1128 static const char *CBT_code_name
[10] = {
1135 "HCBT_CLICKSKIPPED",
1139 const char *code_name
= (nCode
>= 0 && nCode
<= HCBT_SETFOCUS
) ? CBT_code_name
[nCode
] : "Unknown";
1140 HWND hwnd
= (HWND
)wParam
;
1144 case HCBT_CREATEWND
:
1146 static const RECT rc_null
;
1149 CBT_CREATEWNDA
*createwnd
= (CBT_CREATEWNDA
*)lParam
;
1150 ok(createwnd
->hwndInsertAfter
== HWND_TOP
, "hwndInsertAfter should be always HWND_TOP\n");
1155 info
.cbSize
= sizeof(WINDOWINFO
);
1156 ok(pGetWindowInfo(hwnd
, &info
), "GetWindowInfo should not fail\n");
1157 verify_window_info(code_name
, hwnd
, &info
);
1160 /* WS_VISIBLE should be turned off yet */
1161 style
= createwnd
->lpcs
->style
& ~WS_VISIBLE
;
1162 ok(style
== GetWindowLongA(hwnd
, GWL_STYLE
),
1163 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
1164 GetWindowLongA(hwnd
, GWL_STYLE
), style
);
1168 /* Uncomment this once the test succeeds in all cases */
1169 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1171 ok(GetParent(hwnd
) == hwndMessage
,
1172 "wrong result from GetParent %p: message window %p\n",
1173 GetParent(hwnd
), hwndMessage
);
1176 ok(!GetParent(hwnd
), "GetParent should return 0 at this point\n");
1178 ok(!GetWindow(hwnd
, GW_OWNER
), "GW_OWNER should be set to 0 at this point\n");
1182 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
1183 * Win9x still has them set to 0.
1185 ok(GetWindow(hwnd
, GW_HWNDFIRST
) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
1186 ok(GetWindow(hwnd
, GW_HWNDLAST
) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
1188 ok(!GetWindow(hwnd
, GW_HWNDPREV
), "GW_HWNDPREV should be set to 0 at this point\n");
1189 ok(!GetWindow(hwnd
, GW_HWNDNEXT
), "GW_HWNDNEXT should be set to 0 at this point\n");
1193 /* Uncomment this once the test succeeds in all cases */
1196 ok(pGetAncestor(hwnd
, GA_PARENT
) == hwndMessage
, "GA_PARENT should be set to hwndMessage at this point\n");
1197 ok(pGetAncestor(hwnd
, GA_ROOT
) == hwnd
,
1198 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd
, GA_ROOT
), hwnd
);
1200 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1201 ok(pGetAncestor(hwnd
, GA_ROOTOWNER
) == hwndMessage
,
1202 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
1204 ok(pGetAncestor(hwnd
, GA_ROOTOWNER
) == hwnd
,
1205 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd
, GA_ROOTOWNER
), hwnd
);
1208 ok(GetWindowRect(hwnd
, &rc
), "GetWindowRect failed\n");
1209 ok(EqualRect(&rc
, &rc_null
), "window rect should be set to 0 HCBT_CREATEWND\n");
1210 ok(GetClientRect(hwnd
, &rc
), "GetClientRect failed\n");
1211 ok(EqualRect(&rc
, &rc_null
), "client rect should be set to 0 on HCBT_CREATEWND\n");
1218 if (pGetWindowInfo
&& IsWindow(hwnd
))
1222 /* Win98 actually does check the info.cbSize and doesn't allow
1223 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
1224 * WinXP do not check it at all.
1226 info
.cbSize
= sizeof(WINDOWINFO
);
1227 ok(pGetWindowInfo(hwnd
, &info
), "GetWindowInfo should not fail\n");
1228 verify_window_info(code_name
, hwnd
, &info
);
1231 /* window state is undefined */
1233 case HCBT_DESTROYWND
:
1239 return CallNextHookEx(hhook
, nCode
, wParam
, lParam
);
1242 static void test_shell_window(void)
1246 HMODULE hinst
, hUser32
;
1247 BOOL (WINAPI
*SetShellWindow
)(HWND
);
1248 HWND hwnd1
, hwnd2
, hwnd3
, hwnd4
, hwnd5
;
1249 HWND shellWindow
, nextWnd
;
1253 win_skip("Skipping shell window test on Win9x\n");
1257 shellWindow
= GetShellWindow();
1258 hinst
= GetModuleHandleA(NULL
);
1259 hUser32
= GetModuleHandleA("user32");
1261 SetShellWindow
= (void *)GetProcAddress(hUser32
, "SetShellWindow");
1263 trace("previous shell window: %p\n", shellWindow
);
1269 GetWindowThreadProcessId(shellWindow
, &pid
);
1270 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, pid
);
1273 skip( "cannot get access to shell process\n" );
1277 SetLastError(0xdeadbeef);
1278 ret
= DestroyWindow(shellWindow
);
1279 error
= GetLastError();
1281 ok(!ret
, "DestroyWindow(shellWindow)\n");
1282 /* passes on Win XP, but not on Win98 */
1283 ok(error
==ERROR_ACCESS_DENIED
|| error
== 0xdeadbeef,
1284 "got %u after DestroyWindow(shellWindow)\n", error
);
1286 /* close old shell instance */
1287 ret
= TerminateProcess(hProcess
, 0);
1288 ok(ret
, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1289 WaitForSingleObject(hProcess
, INFINITE
); /* wait for termination */
1290 CloseHandle(hProcess
);
1293 hwnd1
= CreateWindowExA(0, "#32770", "TEST1", WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst
, 0);
1294 trace("created window 1: %p\n", hwnd1
);
1296 ret
= SetShellWindow(hwnd1
);
1297 ok(ret
, "first call to SetShellWindow(hwnd1)\n");
1298 shellWindow
= GetShellWindow();
1299 ok(shellWindow
==hwnd1
, "wrong shell window: %p\n", shellWindow
);
1301 ret
= SetShellWindow(hwnd1
);
1302 ok(!ret
, "second call to SetShellWindow(hwnd1)\n");
1304 ret
= SetShellWindow(0);
1305 error
= GetLastError();
1306 /* passes on Win XP, but not on Win98
1307 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1308 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1310 ret
= SetShellWindow(hwnd1
);
1311 /* passes on Win XP, but not on Win98
1312 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1314 SetWindowLongA(hwnd1
, GWL_EXSTYLE
, GetWindowLongA(hwnd1
,GWL_EXSTYLE
)|WS_EX_TOPMOST
);
1315 ret
= (GetWindowLongA(hwnd1
,GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0;
1316 ok(!ret
, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1318 ret
= DestroyWindow(hwnd1
);
1319 ok(ret
, "DestroyWindow(hwnd1)\n");
1321 hwnd2
= CreateWindowExA(WS_EX_TOPMOST
, "#32770", "TEST2", WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst
, 0);
1322 trace("created window 2: %p\n", hwnd2
);
1323 ret
= SetShellWindow(hwnd2
);
1324 ok(!ret
, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1326 hwnd3
= CreateWindowExA(0, "#32770", "TEST3", WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst
, 0);
1327 trace("created window 3: %p\n", hwnd3
);
1329 hwnd4
= CreateWindowExA(0, "#32770", "TEST4", WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst
, 0);
1330 trace("created window 4: %p\n", hwnd4
);
1332 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1333 ok(nextWnd
==hwnd3
, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd
);
1335 ret
= SetShellWindow(hwnd4
);
1336 ok(ret
, "SetShellWindow(hwnd4)\n");
1337 shellWindow
= GetShellWindow();
1338 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1340 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1341 ok(nextWnd
==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd
);
1343 ret
= SetWindowPos(hwnd4
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1344 ok(ret
, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1346 ret
= SetWindowPos(hwnd4
, hwnd3
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1347 ok(ret
, "SetWindowPos(hwnd4, hwnd3\n");
1349 ret
= SetShellWindow(hwnd3
);
1350 ok(!ret
, "SetShellWindow(hwnd3)\n");
1351 shellWindow
= GetShellWindow();
1352 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1354 hwnd5
= CreateWindowExA(0, "#32770", "TEST5", WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst
, 0);
1355 trace("created window 5: %p\n", hwnd5
);
1356 ret
= SetWindowPos(hwnd4
, hwnd5
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1357 ok(ret
, "SetWindowPos(hwnd4, hwnd5)\n");
1361 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1362 ok(nextWnd
==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd
);
1365 /* destroy test windows */
1366 DestroyWindow(hwnd2
);
1367 DestroyWindow(hwnd3
);
1368 DestroyWindow(hwnd4
);
1369 DestroyWindow(hwnd5
);
1372 /************** MDI test ****************/
1374 static char mdi_lParam_test_message
[] = "just a test string";
1376 static void test_MDI_create(HWND parent
, HWND mdi_client
, INT_PTR first_id
)
1378 MDICREATESTRUCTA mdi_cs
;
1379 HWND mdi_child
, hwnd
, exp_hwnd
;
1381 static const WCHAR classW
[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1382 static const WCHAR titleW
[] = {'M','D','I',' ','c','h','i','l','d',0};
1383 BOOL isWin9x
= FALSE
;
1384 HMENU frame_menu
= GetMenu(parent
);
1386 ok(frame_menu
!= NULL
, "Frame window didn't have a menu\n");
1388 mdi_cs
.szClass
= "MDI_child_Class_1";
1389 mdi_cs
.szTitle
= "MDI child";
1390 mdi_cs
.hOwner
= GetModuleHandleA(NULL
);
1391 mdi_cs
.x
= CW_USEDEFAULT
;
1392 mdi_cs
.y
= CW_USEDEFAULT
;
1393 mdi_cs
.cx
= CW_USEDEFAULT
;
1394 mdi_cs
.cy
= CW_USEDEFAULT
;
1396 mdi_cs
.lParam
= (LPARAM
)mdi_lParam_test_message
;
1397 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1398 ok(mdi_child
!= 0, "MDI child creation failed\n");
1399 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1400 ok(id
== first_id
, "wrong child id %ld\n", id
);
1401 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1402 exp_hwnd
= (GetWindowLongW(mdi_child
, GWL_STYLE
) & WS_VISIBLE
) ? mdi_child
: 0;
1403 ok(hwnd
== exp_hwnd
, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd
, hwnd
);
1404 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1405 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1407 mdi_cs
.style
= 0x7fffffff; /* without WS_POPUP */
1408 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1409 ok(mdi_child
!= 0, "MDI child creation failed\n");
1410 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1411 ok(id
== first_id
, "wrong child id %ld\n", id
);
1412 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1413 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1414 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1415 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1417 mdi_cs
.style
= 0xffffffff; /* with WS_POPUP */
1418 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1419 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1421 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1425 ok(mdi_child
!= 0, "MDI child creation failed\n");
1426 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1427 ok(id
== first_id
, "wrong child id %ld\n", id
);
1428 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1429 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1430 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1431 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1432 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1435 /* test MDICREATESTRUCT A<->W mapping */
1436 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1438 mdi_cs
.szClass
= (LPCSTR
)classW
;
1439 mdi_cs
.szTitle
= (LPCSTR
)titleW
;
1440 SetLastError(0xdeadbeef);
1441 mdi_child
= (HWND
)SendMessageW(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1444 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1447 ok(mdi_child
!= 0, "MDI child creation failed\n");
1451 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1452 ok(id
== first_id
, "wrong child id %ld\n", id
);
1453 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1454 exp_hwnd
= (GetWindowLongW(mdi_child
, GWL_STYLE
) & WS_VISIBLE
) ? mdi_child
: 0;
1455 ok(hwnd
== exp_hwnd
, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd
, hwnd
);
1456 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1457 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1458 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1461 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1463 CW_USEDEFAULT
, CW_USEDEFAULT
,
1464 CW_USEDEFAULT
, CW_USEDEFAULT
,
1465 mdi_client
, GetModuleHandleA(NULL
),
1466 (LPARAM
)mdi_lParam_test_message
);
1467 ok(mdi_child
!= 0, "MDI child creation failed\n");
1468 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1469 ok(id
== first_id
, "wrong child id %ld\n", id
);
1470 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1471 exp_hwnd
= (GetWindowLongW(mdi_child
, GWL_STYLE
) & WS_VISIBLE
) ? mdi_child
: 0;
1472 ok(hwnd
== exp_hwnd
, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd
, hwnd
);
1473 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1474 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1475 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1477 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1478 0x7fffffff, /* without WS_POPUP */
1479 CW_USEDEFAULT
, CW_USEDEFAULT
,
1480 CW_USEDEFAULT
, CW_USEDEFAULT
,
1481 mdi_client
, GetModuleHandleA(NULL
),
1482 (LPARAM
)mdi_lParam_test_message
);
1483 ok(mdi_child
!= 0, "MDI child creation failed\n");
1484 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1485 ok(id
== first_id
, "wrong child id %ld\n", id
);
1486 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1487 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1488 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1489 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1490 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1492 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1493 0xffffffff, /* with WS_POPUP */
1494 CW_USEDEFAULT
, CW_USEDEFAULT
,
1495 CW_USEDEFAULT
, CW_USEDEFAULT
,
1496 mdi_client
, GetModuleHandleA(NULL
),
1497 (LPARAM
)mdi_lParam_test_message
);
1498 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1500 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1504 ok(mdi_child
!= 0, "MDI child creation failed\n");
1505 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1506 ok(id
== first_id
, "wrong child id %ld\n", id
);
1507 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1508 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1509 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1510 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1511 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1514 /* test MDICREATESTRUCT A<->W mapping */
1515 SetLastError(0xdeadbeef);
1516 mdi_child
= CreateMDIWindowW(classW
, titleW
,
1518 CW_USEDEFAULT
, CW_USEDEFAULT
,
1519 CW_USEDEFAULT
, CW_USEDEFAULT
,
1520 mdi_client
, GetModuleHandleA(NULL
),
1521 (LPARAM
)mdi_lParam_test_message
);
1524 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1527 ok(mdi_child
!= 0, "MDI child creation failed\n");
1531 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1532 ok(id
== first_id
, "wrong child id %ld\n", id
);
1533 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1534 exp_hwnd
= (GetWindowLongW(mdi_child
, GWL_STYLE
) & WS_VISIBLE
) ? mdi_child
: 0;
1535 ok(hwnd
== exp_hwnd
, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd
, hwnd
);
1536 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1537 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1538 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1541 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1543 CW_USEDEFAULT
, CW_USEDEFAULT
,
1544 CW_USEDEFAULT
, CW_USEDEFAULT
,
1545 mdi_client
, 0, GetModuleHandleA(NULL
),
1546 mdi_lParam_test_message
);
1547 ok(mdi_child
!= 0, "MDI child creation failed\n");
1548 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1549 ok(id
== first_id
, "wrong child id %ld\n", id
);
1550 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1551 exp_hwnd
= (GetWindowLongW(mdi_child
, GWL_STYLE
) & WS_VISIBLE
) ? mdi_child
: 0;
1552 ok(hwnd
== exp_hwnd
, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd
, hwnd
);
1553 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1554 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1555 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1557 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1559 CW_USEDEFAULT
, CW_USEDEFAULT
,
1560 CW_USEDEFAULT
, CW_USEDEFAULT
,
1561 mdi_client
, 0, GetModuleHandleA(NULL
),
1562 mdi_lParam_test_message
);
1563 ok(mdi_child
!= 0, "MDI child creation failed\n");
1564 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1565 ok(id
== first_id
, "wrong child id %ld\n", id
);
1566 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1567 exp_hwnd
= (GetWindowLongW(mdi_child
, GWL_STYLE
) & WS_VISIBLE
) ? mdi_child
: 0;
1568 ok(hwnd
== exp_hwnd
, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd
, hwnd
);
1569 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1570 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1572 ok(GetMenuItemCount(frame_menu
) == 4, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1573 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1574 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1576 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1577 0x7fffffff, /* without WS_POPUP */
1578 CW_USEDEFAULT
, CW_USEDEFAULT
,
1579 CW_USEDEFAULT
, CW_USEDEFAULT
,
1580 mdi_client
, 0, GetModuleHandleA(NULL
),
1581 mdi_lParam_test_message
);
1582 ok(mdi_child
!= 0, "MDI child creation failed\n");
1583 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1584 ok(id
== first_id
, "wrong child id %ld\n", id
);
1585 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1586 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1587 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1588 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1589 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1591 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1592 0xffffffff, /* with WS_POPUP */
1593 CW_USEDEFAULT
, CW_USEDEFAULT
,
1594 CW_USEDEFAULT
, CW_USEDEFAULT
,
1595 mdi_client
, 0, GetModuleHandleA(NULL
),
1596 mdi_lParam_test_message
);
1597 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1599 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1603 ok(mdi_child
!= 0, "MDI child creation failed\n");
1604 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1605 ok(id
== first_id
, "wrong child id %ld\n", id
);
1606 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1607 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1608 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1609 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1610 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1613 /* test MDICREATESTRUCT A<->W mapping */
1614 SetLastError(0xdeadbeef);
1615 mdi_child
= CreateWindowExW(WS_EX_MDICHILD
, classW
, titleW
,
1617 CW_USEDEFAULT
, CW_USEDEFAULT
,
1618 CW_USEDEFAULT
, CW_USEDEFAULT
,
1619 mdi_client
, 0, GetModuleHandleA(NULL
),
1620 mdi_lParam_test_message
);
1623 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1626 ok(mdi_child
!= 0, "MDI child creation failed\n");
1630 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1631 ok(id
== first_id
, "wrong child id %ld\n", id
);
1632 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1633 exp_hwnd
= (GetWindowLongW(mdi_child
, GWL_STYLE
) & WS_VISIBLE
) ? mdi_child
: 0;
1634 ok(hwnd
== exp_hwnd
, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd
, hwnd
);
1635 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1636 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1637 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1640 /* This test fails on Win9x */
1643 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_2", "MDI child",
1645 CW_USEDEFAULT
, CW_USEDEFAULT
,
1646 CW_USEDEFAULT
, CW_USEDEFAULT
,
1647 parent
, 0, GetModuleHandleA(NULL
),
1648 mdi_lParam_test_message
);
1649 ok(!mdi_child
, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1652 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1653 WS_CHILD
, /* without WS_POPUP */
1654 CW_USEDEFAULT
, CW_USEDEFAULT
,
1655 CW_USEDEFAULT
, CW_USEDEFAULT
,
1656 mdi_client
, 0, GetModuleHandleA(NULL
),
1657 mdi_lParam_test_message
);
1658 ok(mdi_child
!= 0, "MDI child creation failed\n");
1659 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1660 ok(id
== 0, "wrong child id %ld\n", id
);
1661 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1662 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1663 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1664 DestroyWindow(mdi_child
);
1666 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1667 WS_CHILD
| WS_POPUP
, /* with WS_POPUP */
1668 CW_USEDEFAULT
, CW_USEDEFAULT
,
1669 CW_USEDEFAULT
, CW_USEDEFAULT
,
1670 mdi_client
, 0, GetModuleHandleA(NULL
),
1671 mdi_lParam_test_message
);
1672 ok(mdi_child
!= 0, "MDI child creation failed\n");
1673 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1674 ok(id
== 0, "wrong child id %ld\n", id
);
1675 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1676 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1677 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1678 DestroyWindow(mdi_child
);
1680 /* maximized child */
1681 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1682 WS_CHILD
| WS_MAXIMIZE
,
1683 CW_USEDEFAULT
, CW_USEDEFAULT
,
1684 CW_USEDEFAULT
, CW_USEDEFAULT
,
1685 mdi_client
, 0, GetModuleHandleA(NULL
),
1686 mdi_lParam_test_message
);
1687 ok(mdi_child
!= 0, "MDI child creation failed\n");
1688 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1689 ok(id
== 0, "wrong child id %ld\n", id
);
1690 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1691 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1692 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1693 DestroyWindow(mdi_child
);
1695 trace("Creating maximized child with a caption\n");
1696 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1697 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
,
1698 CW_USEDEFAULT
, CW_USEDEFAULT
,
1699 CW_USEDEFAULT
, CW_USEDEFAULT
,
1700 mdi_client
, 0, GetModuleHandleA(NULL
),
1701 mdi_lParam_test_message
);
1702 ok(mdi_child
!= 0, "MDI child creation failed\n");
1703 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1704 ok(id
== 0, "wrong child id %ld\n", id
);
1705 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1706 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1707 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1708 DestroyWindow(mdi_child
);
1710 trace("Creating maximized child with a caption and a thick frame\n");
1711 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1712 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
| WS_THICKFRAME
,
1713 CW_USEDEFAULT
, CW_USEDEFAULT
,
1714 CW_USEDEFAULT
, CW_USEDEFAULT
,
1715 mdi_client
, 0, GetModuleHandleA(NULL
),
1716 mdi_lParam_test_message
);
1717 ok(mdi_child
!= 0, "MDI child creation failed\n");
1718 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1719 ok(id
== 0, "wrong child id %ld\n", id
);
1720 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1721 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1722 ok(GetMenuItemCount(frame_menu
) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu
));
1723 DestroyWindow(mdi_child
);
1726 static void test_MDI_child_stack(HWND mdi_client
)
1728 HWND child_1
, child_2
, child_3
, child_4
;
1730 MDICREATESTRUCTA cs
;
1732 cs
.szClass
= "MDI_child_Class_1";
1733 cs
.szTitle
= "MDI child";
1734 cs
.hOwner
= GetModuleHandleA(0);
1735 cs
.x
= CW_USEDEFAULT
;
1736 cs
.y
= CW_USEDEFAULT
;
1737 cs
.cx
= CW_USEDEFAULT
;
1738 cs
.cy
= CW_USEDEFAULT
;
1740 cs
.lParam
= (LPARAM
)mdi_lParam_test_message
;
1742 child_1
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&cs
);
1743 ok(child_1
!= 0, "expected child_1 to be non NULL\n");
1744 child_2
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&cs
);
1745 ok(child_2
!= 0, "expected child_2 to be non NULL\n");
1746 child_3
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&cs
);
1747 ok(child_3
!= 0, "expected child_3 to be non NULL\n");
1748 child_4
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&cs
);
1749 ok(child_4
!= 0, "expected child_4 to be non NULL\n");
1751 stack
[0] = (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1752 stack
[1] = GetWindow(stack
[0], GW_HWNDNEXT
);
1753 stack
[2] = GetWindow(stack
[1], GW_HWNDNEXT
);
1754 stack
[3] = GetWindow(stack
[2], GW_HWNDNEXT
);
1755 trace("Initial MDI child stack: %p->%p->%p->%p\n", stack
[0], stack
[1], stack
[2], stack
[3]);
1756 ok(stack
[0] == child_4
&& stack
[1] == child_3
&&
1757 stack
[2] == child_2
&& stack
[3] == child_1
,
1758 "Unexpected initial order, should be: %p->%p->%p->%p\n",
1759 child_4
, child_3
, child_2
, child_1
);
1761 trace("Activate child next to %p\n", child_3
);
1762 SendMessageA(mdi_client
, WM_MDINEXT
, (WPARAM
)child_3
, 0);
1764 stack
[0] = (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1765 stack
[1] = GetWindow(stack
[0], GW_HWNDNEXT
);
1766 stack
[2] = GetWindow(stack
[1], GW_HWNDNEXT
);
1767 stack
[3] = GetWindow(stack
[2], GW_HWNDNEXT
);
1768 ok(stack
[0] == child_2
&& stack
[1] == child_4
&&
1769 stack
[2] == child_1
&& stack
[3] == child_3
,
1770 "Broken MDI child stack:\nexpected: %p->%p->%p->%p, but got: %p->%p->%p->%p\n",
1771 child_2
, child_4
, child_1
, child_3
, stack
[0], stack
[1], stack
[2], stack
[3]);
1773 trace("Activate child previous to %p\n", child_1
);
1774 SendMessageA(mdi_client
, WM_MDINEXT
, (WPARAM
)child_1
, 1);
1776 stack
[0] = (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1777 stack
[1] = GetWindow(stack
[0], GW_HWNDNEXT
);
1778 stack
[2] = GetWindow(stack
[1], GW_HWNDNEXT
);
1779 stack
[3] = GetWindow(stack
[2], GW_HWNDNEXT
);
1780 ok(stack
[0] == child_4
&& stack
[1] == child_2
&&
1781 stack
[2] == child_1
&& stack
[3] == child_3
,
1782 "Broken MDI child stack:\nexpected: %p->%p->%p->%p, but got: %p->%p->%p->%p\n",
1783 child_4
, child_2
, child_1
, child_3
, stack
[0], stack
[1], stack
[2], stack
[3]);
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
;
1813 trace("max rect %s\n", wine_dbgstr_rect(&rect
));
1816 static LRESULT WINAPI
mdi_child_wnd_proc_1(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1823 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1824 MDICREATESTRUCTA
*mdi_cs
= cs
->lpCreateParams
;
1826 ok(cs
->dwExStyle
& WS_EX_MDICHILD
, "WS_EX_MDICHILD should be set\n");
1827 ok(mdi_cs
->lParam
== (LPARAM
)mdi_lParam_test_message
, "wrong mdi_cs->lParam\n");
1829 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_1"), "wrong class name\n");
1830 ok(!lstrcmpA(cs
->lpszClass
, mdi_cs
->szClass
), "class name does not match\n");
1831 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1832 ok(!lstrcmpA(cs
->lpszName
, mdi_cs
->szTitle
), "title does not match\n");
1833 ok(cs
->hInstance
== mdi_cs
->hOwner
, "%p != %p\n", cs
->hInstance
, mdi_cs
->hOwner
);
1835 /* MDICREATESTRUCT should have original values */
1836 ok(mdi_cs
->style
== 0 || mdi_cs
->style
== 0x7fffffff || mdi_cs
->style
== 0xffffffff || mdi_cs
->style
== WS_MAXIMIZE
,
1837 "mdi_cs->style does not match (%08x)\n", mdi_cs
->style
);
1838 ok(mdi_cs
->x
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->x
);
1839 ok(mdi_cs
->y
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->y
);
1840 ok(mdi_cs
->cx
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cx
);
1841 ok(mdi_cs
->cy
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cy
);
1843 /* CREATESTRUCT should have fixed values */
1844 ok(cs
->x
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->x
);
1845 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1847 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1848 ok(cs
->cx
!= CW_USEDEFAULT
&& cs
->cx
!= 0, "%d == CW_USEDEFAULT\n", cs
->cx
);
1849 ok(cs
->cy
!= CW_USEDEFAULT
&& cs
->cy
!= 0, "%d == CW_USEDEFAULT\n", cs
->cy
);
1851 ok(!(cs
->style
& WS_POPUP
), "WS_POPUP is not allowed\n");
1853 if (GetWindowLongA(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1855 LONG style
= mdi_cs
->style
| WS_CHILD
| WS_CLIPSIBLINGS
;
1856 ok(cs
->style
== style
,
1857 "cs->style does not match (%08x)\n", cs
->style
);
1861 LONG style
= mdi_cs
->style
;
1863 style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1864 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1865 ok(cs
->style
== style
,
1866 "cs->style does not match (%08x)\n", cs
->style
);
1871 case WM_GETMINMAXINFO
:
1873 HWND client
= GetParent(hwnd
);
1875 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1876 MINMAXINFO my_minmax
;
1877 LONG style
, exstyle
;
1879 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1880 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1882 GetClientRect(client
, &rc
);
1884 GetClientRect(client
, &rc
);
1885 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1886 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1887 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
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
);
1891 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1892 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1893 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1894 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1896 DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1898 trace("DefMDIChildProc returned:\n");
1899 dump_minmax_info( minmax
);
1901 MDI_ChildGetMinMaxInfo(client
, hwnd
, &my_minmax
);
1902 ok(minmax
->ptMaxSize
.x
== my_minmax
.ptMaxSize
.x
, "default width of maximized child %d != %d\n",
1903 minmax
->ptMaxSize
.x
, my_minmax
.ptMaxSize
.x
);
1904 ok(minmax
->ptMaxSize
.y
== my_minmax
.ptMaxSize
.y
, "default height of maximized child %d != %d\n",
1905 minmax
->ptMaxSize
.y
, my_minmax
.ptMaxSize
.y
);
1910 case WM_MDIACTIVATE
:
1912 HWND active
, client
= GetParent(hwnd
);
1913 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1914 active
= (HWND
)SendMessageA(client
, WM_MDIGETACTIVE
, 0, 0);
1915 if (hwnd
== (HWND
)lparam
) /* if we are being activated */
1916 ok (active
== (HWND
)lparam
, "new active %p != active %p\n", (HWND
)lparam
, active
);
1918 ok (active
== (HWND
)wparam
, "old active %p != active %p\n", (HWND
)wparam
, active
);
1922 return DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1925 static LRESULT WINAPI
mdi_child_wnd_proc_2(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1932 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1934 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg
== WM_NCCREATE
) ? "WM_NCCREATE" : "WM_CREATE",
1935 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
1937 ok(!(cs
->dwExStyle
& WS_EX_MDICHILD
), "WS_EX_MDICHILD should not be set\n");
1938 ok(cs
->lpCreateParams
== mdi_lParam_test_message
, "wrong cs->lpCreateParams\n");
1940 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_2"), "wrong class name\n");
1941 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1943 /* CREATESTRUCT should have fixed values */
1944 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1946 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1947 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1949 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1950 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1951 while Win95, Win2k, WinXP do. */
1952 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1953 ok(cs
->cy
== 0, "%d != 0\n", cs
->cy
);
1957 case WM_GETMINMAXINFO
:
1959 HWND parent
= GetParent(hwnd
);
1961 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1962 LONG style
, exstyle
;
1964 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1965 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1967 GetClientRect(parent
, &rc
);
1968 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent
, rc
.right
, rc
.bottom
);
1970 GetClientRect(parent
, &rc
);
1971 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1972 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1973 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1974 dump_minmax_info( minmax
);
1976 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1977 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1978 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1979 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1983 case WM_WINDOWPOSCHANGED
:
1985 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1988 GetWindowRect(hwnd
, &rc1
);
1989 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1990 /* note: winpos coordinates are relative to parent */
1991 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1992 ok(EqualRect(&rc1
, &rc2
), "rects do not match, window=%s pos=%s\n",
1993 wine_dbgstr_rect(&rc1
), wine_dbgstr_rect(&rc2
));
1994 GetWindowRect(hwnd
, &rc1
);
1995 GetClientRect(hwnd
, &rc2
);
1996 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1997 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1998 ok(EqualRect(&rc1
, &rc2
), "rects do not match, window=%s client=%s\n",
1999 wine_dbgstr_rect(&rc1
), wine_dbgstr_rect(&rc2
));
2002 case WM_WINDOWPOSCHANGING
:
2004 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
2005 WINDOWPOS my_winpos
= *winpos
;
2007 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2008 (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
2009 winpos
->hwnd
, winpos
->hwndInsertAfter
,
2010 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
2012 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
2014 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
2015 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2016 winpos
->hwnd
, winpos
->hwndInsertAfter
,
2017 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
2022 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
2025 static LRESULT WINAPI
mdi_main_wnd_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2027 static HWND mdi_client
;
2034 case WM_WINDOWPOSCHANGED
:
2036 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
2039 GetWindowRect(hwnd
, &rc1
);
2040 trace("window: %s\n", wine_dbgstr_rect(&rc1
));
2041 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
2042 /* note: winpos coordinates are relative to parent */
2043 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
2044 trace("pos: %s\n", wine_dbgstr_rect(&rc2
));
2045 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
2047 GetWindowRect(hwnd
, &rc1
);
2048 GetClientRect(hwnd
, &rc2
);
2049 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
2050 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
2051 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
2054 case WM_WINDOWPOSCHANGING
:
2056 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
2057 WINDOWPOS my_winpos
= *winpos
;
2059 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2060 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2061 winpos
->hwnd
, winpos
->hwndInsertAfter
,
2062 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
2064 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
2066 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2067 winpos
->hwnd
, winpos
->hwndInsertAfter
,
2068 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
2070 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
2071 "DefWindowProc should not change WINDOWPOS values\n");
2080 return DefFrameProcA(hwnd
, mdi_client
, msg
, wparam
, lparam
);
2083 static BOOL
mdi_RegisterWindowClasses(void)
2088 cls
.lpfnWndProc
= mdi_main_wnd_procA
;
2091 cls
.hInstance
= GetModuleHandleA(0);
2093 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
2094 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
2095 cls
.lpszMenuName
= NULL
;
2096 cls
.lpszClassName
= "MDI_parent_Class";
2097 if(!RegisterClassA(&cls
)) return FALSE
;
2099 cls
.lpfnWndProc
= mdi_child_wnd_proc_1
;
2100 cls
.lpszClassName
= "MDI_child_Class_1";
2101 if(!RegisterClassA(&cls
)) return FALSE
;
2103 cls
.lpfnWndProc
= mdi_child_wnd_proc_2
;
2104 cls
.lpszClassName
= "MDI_child_Class_2";
2105 if(!RegisterClassA(&cls
)) return FALSE
;
2110 static void test_mdi(void)
2112 static const DWORD style
[] = { 0, WS_HSCROLL
, WS_VSCROLL
, WS_HSCROLL
| WS_VSCROLL
};
2113 HWND mdi_hwndMain
, mdi_client
, mdi_child
;
2114 CLIENTCREATESTRUCT client_cs
;
2118 HMENU frame_menu
, child_menu
;
2120 if (!mdi_RegisterWindowClasses()) assert(0);
2122 mdi_hwndMain
= CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
2123 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
2124 WS_MAXIMIZEBOX
/*| WS_VISIBLE*/,
2125 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
2126 GetDesktopWindow(), 0,
2127 GetModuleHandleA(NULL
), NULL
);
2128 assert(mdi_hwndMain
);
2130 frame_menu
= CreateMenu();
2132 GetClientRect(mdi_hwndMain
, &rc
);
2134 client_cs
.hWindowMenu
= 0;
2135 client_cs
.idFirstChild
= 1;
2137 for (i
= 0; i
< sizeof(style
)/sizeof(style
[0]); i
++)
2142 mdi_client
= CreateWindowExA(0, "mdiclient", NULL
,
2143 WS_CHILD
| style
[i
],
2144 0, 0, rc
.right
, rc
.bottom
,
2145 mdi_hwndMain
, 0, 0, &client_cs
);
2146 ok(mdi_client
!= 0, "MDI client creation failed\n");
2148 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
2150 CW_USEDEFAULT
, CW_USEDEFAULT
,
2151 CW_USEDEFAULT
, CW_USEDEFAULT
,
2153 mdi_lParam_test_message
);
2154 ok(mdi_child
!= 0, "MDI child creation failed\n");
2156 SendMessageW(mdi_child
, WM_SIZE
, SIZE_MAXIMIZED
, 0);
2157 SetMenu(mdi_hwndMain
, frame_menu
);
2159 ok(GetMenuItemCount(frame_menu
) == 0, "Frame menu should be empty after child maximize, but has %u\n",
2160 GetMenuItemCount(frame_menu
));
2162 child_menu
= CreateMenu();
2163 SendMessageW(mdi_client
, WM_MDISETMENU
, 0, (LPARAM
)child_menu
);
2165 ok(GetMenuItemCount(frame_menu
) == 0, "Frame menu should be empty after WM_MDISETMENU, but has %u\n",
2166 GetMenuItemCount(frame_menu
));
2168 SendMessageW(mdi_child
, WM_SIZE
, SIZE_RESTORED
, 0);
2170 ok(GetMenuItemCount(frame_menu
) == 0, "Frame menu should be empty after child restored, but has %u items\n",
2171 GetMenuItemCount(frame_menu
));
2173 SetMenu(mdi_hwndMain
, NULL
);
2175 si
.cbSize
= sizeof(si
);
2177 ret
= GetScrollInfo(mdi_client
, SB_HORZ
, &si
);
2178 if (style
[i
] & (WS_HSCROLL
| WS_VSCROLL
))
2180 ok(ret
, "style %#x: GetScrollInfo(SB_HORZ) failed\n", style
[i
]);
2181 ok(si
.nPage
== 0, "expected 0\n");
2182 ok(si
.nPos
== 0, "expected 0\n");
2183 ok(si
.nTrackPos
== 0, "expected 0\n");
2184 ok(si
.nMin
== 0, "expected 0\n");
2185 ok(si
.nMax
== 100, "expected 100\n");
2188 ok(!ret
, "style %#x: GetScrollInfo(SB_HORZ) should fail\n", style
[i
]);
2190 ret
= GetScrollInfo(mdi_client
, SB_VERT
, &si
);
2191 if (style
[i
] & (WS_HSCROLL
| WS_VSCROLL
))
2193 ok(ret
, "style %#x: GetScrollInfo(SB_VERT) failed\n", style
[i
]);
2194 ok(si
.nPage
== 0, "expected 0\n");
2195 ok(si
.nPos
== 0, "expected 0\n");
2196 ok(si
.nTrackPos
== 0, "expected 0\n");
2197 ok(si
.nMin
== 0, "expected 0\n");
2198 ok(si
.nMax
== 100, "expected 100\n");
2201 ok(!ret
, "style %#x: GetScrollInfo(SB_VERT) should fail\n", style
[i
]);
2203 SetWindowPos(mdi_child
, 0, -100, -100, 0, 0, SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOSIZE
);
2205 si
.cbSize
= sizeof(si
);
2207 ret
= GetScrollInfo(mdi_client
, SB_HORZ
, &si
);
2208 if (style
[i
] & (WS_HSCROLL
| WS_VSCROLL
))
2210 ok(ret
, "style %#x: GetScrollInfo(SB_HORZ) failed\n", style
[i
]);
2211 ok(si
.nPage
== 0, "expected 0\n");
2212 ok(si
.nPos
== 0, "expected 0\n");
2213 ok(si
.nTrackPos
== 0, "expected 0\n");
2214 ok(si
.nMin
== 0, "expected 0\n");
2215 ok(si
.nMax
== 100, "expected 100\n");
2218 ok(!ret
, "style %#x: GetScrollInfo(SB_HORZ) should fail\n", style
[i
]);
2220 ret
= GetScrollInfo(mdi_client
, SB_VERT
, &si
);
2221 if (style
[i
] & (WS_HSCROLL
| WS_VSCROLL
))
2223 ok(ret
, "style %#x: GetScrollInfo(SB_VERT) failed\n", style
[i
]);
2224 ok(si
.nPage
== 0, "expected 0\n");
2225 ok(si
.nPos
== 0, "expected 0\n");
2226 ok(si
.nTrackPos
== 0, "expected 0\n");
2227 ok(si
.nMin
== 0, "expected 0\n");
2228 ok(si
.nMax
== 100, "expected 100\n");
2231 ok(!ret
, "style %#x: GetScrollInfo(SB_VERT) should fail\n", style
[i
]);
2234 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
2236 if (msg
.message
== WM_MOUSEMOVE
|| msg
.message
== WM_PAINT
)
2238 DispatchMessageA(&msg
);
2242 if (msg
.message
== 0x003f) /* WM_MDICALCCHILDSCROLL ??? */
2244 ok(msg
.hwnd
== mdi_client
, "message 0x003f should be posted to mdiclient\n");
2248 ok(msg
.hwnd
!= mdi_client
, "message %04x should not be posted to mdiclient\n", msg
.message
);
2249 DispatchMessageA(&msg
);
2251 ok(gotit
, "message 0x003f should appear after SetWindowPos\n");
2253 si
.cbSize
= sizeof(si
);
2255 ret
= GetScrollInfo(mdi_client
, SB_HORZ
, &si
);
2256 if (style
[i
] & (WS_HSCROLL
| WS_VSCROLL
))
2258 ok(ret
, "style %#x: GetScrollInfo(SB_HORZ) failed\n", style
[i
]);
2260 ok(si
.nPage
!= 0, "expected !0\n");
2261 ok(si
.nPos
== 0, "expected 0\n");
2262 ok(si
.nTrackPos
== 0, "expected 0\n");
2263 ok(si
.nMin
!= 0, "expected !0\n");
2264 ok(si
.nMax
!= 100, "expected !100\n");
2267 ok(!ret
, "style %#x: GetScrollInfo(SB_HORZ) should fail\n", style
[i
]);
2269 ret
= GetScrollInfo(mdi_client
, SB_VERT
, &si
);
2270 if (style
[i
] & (WS_HSCROLL
| WS_VSCROLL
))
2272 ok(ret
, "style %#x: GetScrollInfo(SB_VERT) failed\n", style
[i
]);
2274 ok(si
.nPage
!= 0, "expected !0\n");
2275 ok(si
.nPos
== 0, "expected 0\n");
2276 ok(si
.nTrackPos
== 0, "expected 0\n");
2277 ok(si
.nMin
!= 0, "expected !0\n");
2278 ok(si
.nMax
!= 100, "expected !100\n");
2281 ok(!ret
, "style %#x: GetScrollInfo(SB_VERT) should fail\n", style
[i
]);
2283 DestroyMenu(child_menu
);
2284 DestroyWindow(mdi_child
);
2285 DestroyWindow(mdi_client
);
2288 SetMenu(mdi_hwndMain
, frame_menu
);
2290 mdi_client
= CreateWindowExA(0, "mdiclient", NULL
,
2292 0, 0, rc
.right
, rc
.bottom
,
2293 mdi_hwndMain
, 0, 0, &client_cs
);
2294 ok(mdi_client
!= 0, "MDI client creation failed\n");
2296 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
2298 CW_USEDEFAULT
, CW_USEDEFAULT
,
2299 CW_USEDEFAULT
, CW_USEDEFAULT
,
2301 mdi_lParam_test_message
);
2302 ok(mdi_child
!= 0, "MDI child creation failed\n");
2304 SendMessageW(mdi_child
, WM_SIZE
, SIZE_MAXIMIZED
, 0);
2305 ok(GetMenuItemCount(frame_menu
) == 4, "Frame menu should have 4 items after child maximize, but has %u\n",
2306 GetMenuItemCount(frame_menu
));
2308 child_menu
= CreateMenu();
2309 SendMessageW(mdi_client
, WM_MDISETMENU
, 0, (LPARAM
)child_menu
);
2311 ok(GetMenuItemCount(frame_menu
) == 4, "Frame menu should have 4 items after WM_MDISETMENU, but has %u\n",
2312 GetMenuItemCount(frame_menu
));
2314 SendMessageW(mdi_child
, WM_SIZE
, SIZE_RESTORED
, 0);
2316 ok(GetMenuItemCount(frame_menu
) == 0, "Frame menu should be empty after child restored, but has %u items\n",
2317 GetMenuItemCount(frame_menu
));
2319 DestroyMenu(child_menu
);
2320 DestroyWindow(mdi_child
);
2321 DestroyWindow(mdi_client
);
2323 /* MDIClient without MDIS_ALLCHILDSTYLES */
2324 mdi_client
= CreateWindowExA(0, "mdiclient",
2326 WS_CHILD
/*| WS_VISIBLE*/,
2327 /* tests depend on a not zero MDIClient size */
2328 0, 0, rc
.right
, rc
.bottom
,
2329 mdi_hwndMain
, 0, GetModuleHandleA(NULL
),
2332 test_MDI_create(mdi_hwndMain
, mdi_client
, client_cs
.idFirstChild
);
2333 DestroyWindow(mdi_client
);
2335 /* MDIClient with MDIS_ALLCHILDSTYLES */
2336 mdi_client
= CreateWindowExA(0, "mdiclient",
2338 WS_CHILD
| MDIS_ALLCHILDSTYLES
/*| WS_VISIBLE*/,
2339 /* tests depend on a not zero MDIClient size */
2340 0, 0, rc
.right
, rc
.bottom
,
2341 mdi_hwndMain
, 0, GetModuleHandleA(NULL
),
2344 test_MDI_create(mdi_hwndMain
, mdi_client
, client_cs
.idFirstChild
);
2345 DestroyWindow(mdi_client
);
2347 /* Test child window stack management */
2348 mdi_client
= CreateWindowExA(0, "mdiclient",
2351 0, 0, rc
.right
, rc
.bottom
,
2352 mdi_hwndMain
, 0, GetModuleHandleA(NULL
),
2355 test_MDI_child_stack(mdi_client
);
2356 DestroyWindow(mdi_client
);
2358 while(GetMessage(&msg, 0, 0, 0))
2360 TranslateMessage(&msg);
2361 DispatchMessage(&msg);
2364 DestroyWindow(mdi_hwndMain
);
2367 static void test_icons(void)
2371 HICON icon
= LoadIconA(0, (LPCSTR
)IDI_APPLICATION
);
2372 HICON icon2
= LoadIconA(0, (LPCSTR
)IDI_QUESTION
);
2373 HICON small_icon
= LoadImageA(0, (LPCSTR
)IDI_APPLICATION
, IMAGE_ICON
,
2374 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
2377 cls
.cbSize
= sizeof(cls
);
2379 cls
.lpfnWndProc
= DefWindowProcA
;
2383 cls
.hIcon
= LoadIconA(0, (LPCSTR
)IDI_HAND
);
2384 cls
.hIconSm
= small_icon
;
2385 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
2386 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
2387 cls
.lpszMenuName
= NULL
;
2388 cls
.lpszClassName
= "IconWindowClass";
2390 RegisterClassExA(&cls
);
2392 hwnd
= CreateWindowExA(0, "IconWindowClass", "icon test", 0,
2393 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, NULL
, NULL
);
2396 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
2397 ok( res
== 0, "wrong big icon %p/0\n", res
);
2398 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon
);
2399 ok( res
== 0, "wrong previous big icon %p/0\n", res
);
2400 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
2401 ok( res
== icon
, "wrong big icon after set %p/%p\n", res
, icon
);
2402 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon2
);
2403 ok( res
== icon
, "wrong previous big icon %p/%p\n", res
, icon
);
2404 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
2405 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
2407 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
2408 ok( res
== 0, "wrong small icon %p/0\n", res
);
2409 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL2
, 0 );
2410 ok( (res
&& res
!= small_icon
&& res
!= icon2
) || broken(!res
), "wrong small2 icon %p\n", res
);
2411 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)icon
);
2412 ok( res
== 0, "wrong previous small icon %p/0\n", res
);
2413 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
2414 ok( res
== icon
, "wrong small icon after set %p/%p\n", res
, icon
);
2415 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL2
, 0 );
2416 ok( res
== icon
|| broken(!res
), "wrong small2 icon after set %p/%p\n", res
, icon
);
2417 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)small_icon
);
2418 ok( res
== icon
, "wrong previous small icon %p/%p\n", res
, icon
);
2419 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
2420 ok( res
== small_icon
, "wrong small icon after set %p/%p\n", res
, small_icon
);
2421 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL2
, 0 );
2422 ok( res
== small_icon
|| broken(!res
), "wrong small2 icon after set %p/%p\n", res
, small_icon
);
2424 /* make sure the big icon hasn't changed */
2425 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
2426 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
2428 DestroyWindow( hwnd
);
2431 static LRESULT WINAPI
nccalcsize_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2433 if (msg
== WM_NCCALCSIZE
)
2435 RECT
*rect
= (RECT
*)lparam
;
2436 /* first time around increase the rectangle, next time decrease it */
2437 if (rect
->left
== 100) InflateRect( rect
, 10, 10 );
2438 else InflateRect( rect
, -10, -10 );
2441 return DefWindowProcA( hwnd
, msg
, wparam
, lparam
);
2444 static void test_SetWindowPos(HWND hwnd
, HWND hwnd2
)
2446 RECT orig_win_rc
, rect
;
2448 HWND hwnd_grandchild
, hwnd_child
, hwnd_child2
;
2453 SetRect(&rect
, 111, 222, 333, 444);
2454 ok(!GetWindowRect(0, &rect
), "GetWindowRect succeeded\n");
2455 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
2456 "wrong window rect %s\n", wine_dbgstr_rect(&rect
));
2458 SetRect(&rect
, 111, 222, 333, 444);
2459 ok(!GetClientRect(0, &rect
), "GetClientRect succeeded\n");
2460 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
2461 "wrong window rect %s\n", wine_dbgstr_rect(&rect
));
2463 GetWindowRect(hwnd
, &orig_win_rc
);
2465 old_proc
= SetWindowLongPtrA( hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)nccalcsize_proc
);
2466 ret
= SetWindowPos(hwnd
, 0, 100, 100, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
2467 ok(ret
, "Got %d\n", ret
);
2468 GetWindowRect( hwnd
, &rect
);
2469 ok( rect
.left
== 100 && rect
.top
== 100 && rect
.right
== 100 && rect
.bottom
== 100,
2470 "invalid window rect %s\n", wine_dbgstr_rect(&rect
));
2471 GetClientRect( hwnd
, &rect
);
2472 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
2473 ok( rect
.left
== 90 && rect
.top
== 90 && rect
.right
== 110 && rect
.bottom
== 110,
2474 "invalid client rect %s\n", wine_dbgstr_rect(&rect
));
2476 ret
= SetWindowPos(hwnd
, 0, 200, 200, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
2477 ok(ret
, "Got %d\n", ret
);
2478 GetWindowRect( hwnd
, &rect
);
2479 ok( rect
.left
== 200 && rect
.top
== 200 && rect
.right
== 200 && rect
.bottom
== 200,
2480 "invalid window rect %s\n", wine_dbgstr_rect(&rect
));
2481 GetClientRect( hwnd
, &rect
);
2482 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
2483 ok( rect
.left
== 210 && rect
.top
== 210 && rect
.right
== 190 && rect
.bottom
== 190,
2484 "invalid client rect %s\n", wine_dbgstr_rect(&rect
));
2486 ret
= SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
2487 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
2488 ok(ret
, "Got %d\n", ret
);
2489 SetWindowLongPtrA( hwnd
, GWLP_WNDPROC
, old_proc
);
2491 /* Win9x truncates coordinates to 16-bit irrespectively */
2494 ret
= SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE
);
2495 ok(ret
, "Got %d\n", ret
);
2496 ret
= SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE
);
2497 ok(ret
, "Got %d\n", ret
);
2499 ret
= SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE
);
2500 ok(ret
, "Got %d\n", ret
);
2501 ret
= SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE
);
2502 ok(ret
, "Got %d\n", ret
);
2505 ret
= SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
2506 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
2507 ok(ret
, "Got %d\n", ret
);
2509 ok(!(GetWindowLongA(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
2510 ret
= SetWindowPos(hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
2511 ok(ret
, "Got %d\n", ret
);
2512 ok(GetWindowLongA(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
2513 ret
= SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
2514 ok(ret
, "Got %d\n", ret
);
2515 ok(GetWindowLongA(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
2516 ret
= SetWindowPos(hwnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
2517 ok(ret
, "Got %d\n", ret
);
2518 ok(!(GetWindowLongA(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
2520 hwnd_desktop
= GetDesktopWindow();
2521 ok(!!hwnd_desktop
, "Failed to get hwnd_desktop window (%d).\n", GetLastError());
2522 hwnd_child
= create_tool_window(WS_VISIBLE
|WS_CHILD
, hwnd
);
2523 ok(!!hwnd_child
, "Failed to create child window (%d)\n", GetLastError());
2524 hwnd_grandchild
= create_tool_window(WS_VISIBLE
|WS_CHILD
, hwnd_child
);
2525 ok(!!hwnd_child
, "Failed to create child window (%d)\n", GetLastError());
2526 hwnd_child2
= create_tool_window(WS_VISIBLE
|WS_CHILD
, hwnd
);
2527 ok(!!hwnd_child2
, "Failed to create second child window (%d)\n", GetLastError());
2529 ret
= SetWindowPos(hwnd
, hwnd2
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2530 ok(ret
, "Got %d\n", ret
);
2531 check_active_state(hwnd
, hwnd
, hwnd
);
2533 ret
= SetWindowPos(hwnd2
, hwnd
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2534 ok(ret
, "Got %d\n", ret
);
2535 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2537 /* Returns TRUE also for windows that are not siblings */
2538 ret
= SetWindowPos(hwnd_child
, hwnd2
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2539 ok(ret
, "Got %d\n", ret
);
2540 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2542 ret
= SetWindowPos(hwnd2
, hwnd_child
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2543 ok(ret
, "Got %d\n", ret
);
2544 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2546 /* Does not seem to do anything even without passing flags, still returns TRUE */
2547 GetWindowRect(hwnd_child
, &rc1
);
2548 ret
= SetWindowPos(hwnd_child
, hwnd2
, 1, 2, 3, 4, 0);
2549 ok(ret
, "Got %d\n", ret
);
2550 GetWindowRect(hwnd_child
, &rc2
);
2551 ok(EqualRect(&rc1
, &rc2
), "%s != %s\n", wine_dbgstr_rect(&rc1
), wine_dbgstr_rect(&rc2
));
2552 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2554 /* Same thing the other way around. */
2555 GetWindowRect(hwnd2
, &rc1
);
2556 ret
= SetWindowPos(hwnd2
, hwnd_child
, 1, 2, 3, 4, 0);
2557 ok(ret
, "Got %d\n", ret
);
2558 GetWindowRect(hwnd2
, &rc2
);
2559 ok(EqualRect(&rc1
, &rc2
), "%s != %s\n", wine_dbgstr_rect(&rc1
), wine_dbgstr_rect(&rc2
));
2560 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2562 /* .. and with these windows. */
2563 GetWindowRect(hwnd_grandchild
, &rc1
);
2564 ret
= SetWindowPos(hwnd_grandchild
, hwnd_child2
, 1, 2, 3, 4, 0);
2565 ok(ret
, "Got %d\n", ret
);
2566 GetWindowRect(hwnd_grandchild
, &rc2
);
2567 ok(EqualRect(&rc1
, &rc2
), "%s != %s\n", wine_dbgstr_rect(&rc1
), wine_dbgstr_rect(&rc2
));
2568 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2570 /* Add SWP_NOZORDER and it will be properly resized. */
2571 GetWindowRect(hwnd_grandchild
, &rc1
);
2572 ret
= SetWindowPos(hwnd_grandchild
, hwnd_child2
, 1, 2, 3, 4, SWP_NOZORDER
);
2573 ok(ret
, "Got %d\n", ret
);
2574 GetWindowRect(hwnd_grandchild
, &rc2
);
2575 ok((rc1
.left
+1) == rc2
.left
&& (rc1
.top
+2) == rc2
.top
&&
2576 (rc1
.left
+4) == rc2
.right
&& (rc1
.top
+6) == rc2
.bottom
,
2577 "(%d,%d)-(%d,%d) != %s\n", rc1
.left
+1, rc1
.top
+2, rc1
.left
+4, rc1
.top
+6,
2578 wine_dbgstr_rect(&rc2
));
2579 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2581 /* Given a sibling window, the window is properly resized. */
2582 GetWindowRect(hwnd_child
, &rc1
);
2583 ret
= SetWindowPos(hwnd_child
, hwnd_child2
, 1, 2, 3, 4, 0);
2584 ok(ret
, "Got %d\n", ret
);
2585 GetWindowRect(hwnd_child
, &rc2
);
2586 ok((rc1
.left
+1) == rc2
.left
&& (rc1
.top
+2) == rc2
.top
&&
2587 (rc1
.left
+4) == rc2
.right
&& (rc1
.top
+6) == rc2
.bottom
,
2588 "(%d,%d)-(%d,%d) != %s\n", rc1
.left
+1, rc1
.top
+2, rc1
.left
+4, rc1
.top
+6,
2589 wine_dbgstr_rect(&rc2
));
2590 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2592 /* Involving the desktop window changes things. */
2593 ret
= SetWindowPos(hwnd_child
, hwnd_desktop
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2594 ok(!ret
, "Got %d\n", ret
);
2595 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2597 GetWindowRect(hwnd_child
, &rc1
);
2598 ret
= SetWindowPos(hwnd_child
, hwnd_desktop
, 0, 0, 0, 0, 0);
2599 ok(!ret
, "Got %d\n", ret
);
2600 GetWindowRect(hwnd_child
, &rc2
);
2601 ok(EqualRect(&rc1
, &rc2
), "%s != %s\n", wine_dbgstr_rect(&rc1
), wine_dbgstr_rect(&rc2
));
2602 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2604 ret
= SetWindowPos(hwnd_desktop
, hwnd_child
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2605 ok(!ret
, "Got %d\n", ret
);
2606 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2608 ret
= SetWindowPos(hwnd_desktop
, hwnd
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2609 ok(!ret
, "Got %d\n", ret
);
2610 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2612 ret
= SetWindowPos(hwnd
, hwnd_desktop
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2613 ok(!ret
, "Got %d\n", ret
);
2614 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2616 DestroyWindow(hwnd_grandchild
);
2617 DestroyWindow(hwnd_child
);
2618 DestroyWindow(hwnd_child2
);
2620 hwnd_child
= create_tool_window(WS_CHILD
|WS_POPUP
|WS_SYSMENU
, hwnd2
);
2621 ok(!!hwnd_child
, "Failed to create child window (%d)\n", GetLastError());
2622 ret
= SetWindowPos(hwnd_child
, NULL
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2623 ok(ret
, "Got %d\n", ret
);
2624 flush_events( TRUE
);
2625 todo_wine
check_active_state(hwnd2
, hwnd2
, hwnd2
);
2626 DestroyWindow(hwnd_child
);
2629 static void test_SetMenu(HWND parent
)
2636 hMenu
= CreateMenu();
2639 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
2642 /* fails on (at least) Wine, NT4, XP SP2 */
2643 test_nonclient_area(parent
);
2645 ret
= GetMenu(parent
);
2646 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
2647 /* test whether we can destroy a menu assigned to a window */
2648 retok
= DestroyMenu(hMenu
);
2649 ok( retok
, "DestroyMenu error %d\n", GetLastError());
2650 retok
= IsMenu(hMenu
);
2651 ok(!retok
|| broken(retok
) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
2652 ret
= GetMenu(parent
);
2653 /* This test fails on Win9x */
2655 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
2656 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
2657 test_nonclient_area(parent
);
2659 hMenu
= CreateMenu();
2663 ret
= GetMenu(parent
);
2664 ok(ret
== 0, "unexpected menu id %p\n", ret
);
2666 ok(!SetMenu(parent
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
2667 test_nonclient_area(parent
);
2668 ret
= GetMenu(parent
);
2669 ok(ret
== 0, "unexpected menu id %p\n", ret
);
2671 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
2674 /* fails on (at least) Wine, NT4, XP SP2 */
2675 test_nonclient_area(parent
);
2677 ret
= GetMenu(parent
);
2678 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
2680 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
2681 test_nonclient_area(parent
);
2682 ret
= GetMenu(parent
);
2683 ok(ret
== 0, "unexpected menu id %p\n", ret
);
2686 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, parent
, (HMENU
)10, 0, NULL
);
2689 ret
= GetMenu(child
);
2690 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2692 ok(!SetMenu(child
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
2693 test_nonclient_area(child
);
2694 ret
= GetMenu(child
);
2695 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2697 ok(!SetMenu(child
, hMenu
), "SetMenu on a child window should fail\n");
2698 test_nonclient_area(child
);
2699 ret
= GetMenu(child
);
2700 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2702 ok(!SetMenu(child
, 0), "SetMenu(0) on a child window should fail\n");
2703 test_nonclient_area(child
);
2704 ret
= GetMenu(child
);
2705 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2707 style
= GetWindowLongA(child
, GWL_STYLE
);
2708 SetWindowLongA(child
, GWL_STYLE
, style
| WS_POPUP
);
2709 ok(SetMenu(child
, hMenu
), "SetMenu on a popup child window should not fail\n");
2710 ok(SetMenu(child
, 0), "SetMenu on a popup child window should not fail\n");
2711 SetWindowLongA(child
, GWL_STYLE
, style
);
2713 SetWindowLongA(child
, GWL_STYLE
, style
| WS_OVERLAPPED
);
2714 ok(!SetMenu(child
, hMenu
), "SetMenu on an overlapped child window should fail\n");
2715 SetWindowLongA(child
, GWL_STYLE
, style
);
2717 DestroyWindow(child
);
2721 static void test_window_tree(HWND parent
, const DWORD
*style
, const int *order
, int total
)
2723 HWND child
[5], hwnd
;
2728 hwnd
= GetWindow(parent
, GW_CHILD
);
2729 ok(!hwnd
, "have to start without children to perform the test\n");
2731 for (i
= 0; i
< total
; i
++)
2733 if (style
[i
] & DS_CONTROL
)
2735 child
[i
] = CreateWindowExA(0, (LPCSTR
)MAKEINTATOM(32770), "", style
[i
] & ~WS_VISIBLE
,
2736 0,0,0,0, parent
, (HMENU
)i
, 0, NULL
);
2737 if (style
[i
] & WS_VISIBLE
)
2738 ShowWindow(child
[i
], SW_SHOW
);
2740 SetWindowPos(child
[i
], HWND_BOTTOM
, 0,0,10,10, SWP_NOACTIVATE
);
2743 child
[i
] = CreateWindowExA(0, "static", "", style
[i
], 0,0,10,10,
2744 parent
, (HMENU
)i
, 0, NULL
);
2745 trace("child[%ld] = %p\n", i
, child
[i
]);
2746 ok(child
[i
] != 0, "CreateWindowEx failed to create child window\n");
2749 hwnd
= GetWindow(parent
, GW_CHILD
);
2750 ok(hwnd
!= 0, "GetWindow(GW_CHILD) failed\n");
2751 ok(hwnd
== GetWindow(child
[total
- 1], GW_HWNDFIRST
), "GW_HWNDFIRST is wrong\n");
2752 ok(child
[order
[total
- 1]] == GetWindow(child
[0], GW_HWNDLAST
), "GW_HWNDLAST is wrong\n");
2754 for (i
= 0; i
< total
; i
++)
2756 trace("hwnd[%ld] = %p\n", i
, hwnd
);
2757 ok(child
[order
[i
]] == hwnd
, "Z order of child #%ld is wrong\n", i
);
2759 hwnd
= GetWindow(hwnd
, GW_HWNDNEXT
);
2762 for (i
= 0; i
< total
; i
++)
2763 ok(DestroyWindow(child
[i
]), "DestroyWindow failed\n");
2766 static void test_children_zorder(HWND parent
)
2768 const DWORD simple_style
[5] = { WS_CHILD
, WS_CHILD
, WS_CHILD
, WS_CHILD
,
2770 const int simple_order
[5] = { 0, 1, 2, 3, 4 };
2772 const DWORD complex_style
[5] = { WS_CHILD
, WS_CHILD
| WS_MAXIMIZE
,
2773 WS_CHILD
| WS_VISIBLE
, WS_CHILD
,
2774 WS_CHILD
| WS_MAXIMIZE
| WS_VISIBLE
};
2775 const int complex_order_1
[1] = { 0 };
2776 const int complex_order_2
[2] = { 1, 0 };
2777 const int complex_order_3
[3] = { 1, 0, 2 };
2778 const int complex_order_4
[4] = { 1, 0, 2, 3 };
2779 const int complex_order_5
[5] = { 4, 1, 0, 2, 3 };
2780 const DWORD complex_style_6
[3] = { WS_CHILD
| WS_VISIBLE
,
2781 WS_CHILD
| WS_CLIPSIBLINGS
| DS_CONTROL
| WS_VISIBLE
,
2782 WS_CHILD
| WS_VISIBLE
};
2783 const int complex_order_6
[3] = { 0, 1, 2 };
2785 /* simple WS_CHILD */
2786 test_window_tree(parent
, simple_style
, simple_order
, 5);
2788 /* complex children styles */
2789 test_window_tree(parent
, complex_style
, complex_order_1
, 1);
2790 test_window_tree(parent
, complex_style
, complex_order_2
, 2);
2791 test_window_tree(parent
, complex_style
, complex_order_3
, 3);
2792 test_window_tree(parent
, complex_style
, complex_order_4
, 4);
2793 test_window_tree(parent
, complex_style
, complex_order_5
, 5);
2795 /* another set of complex children styles */
2796 test_window_tree(parent
, complex_style_6
, complex_order_6
, 3);
2799 #define check_z_order(hwnd, next, prev, owner, topmost) \
2800 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2803 static void check_z_order_debug(HWND hwnd
, HWND next
, HWND prev
, HWND owner
,
2804 BOOL topmost
, const char *file
, int line
)
2809 test
= GetWindow(hwnd
, GW_HWNDNEXT
);
2810 /* skip foreign windows */
2811 while (test
&& test
!= next
&&
2812 (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2813 UlongToHandle(GetWindowLongPtrA(test
, GWLP_HINSTANCE
)) != GetModuleHandleA(NULL
) ||
2814 GetWindow(test
, GW_OWNER
) == next
))
2816 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2817 test
= GetWindow(test
, GW_HWNDNEXT
);
2819 ok_(file
, line
)(next
== test
, "%p: expected next %p, got %p\n", hwnd
, next
, test
);
2821 test
= GetWindow(hwnd
, GW_HWNDPREV
);
2822 /* skip foreign windows */
2823 while (test
&& test
!= prev
&&
2824 (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2825 UlongToHandle(GetWindowLongPtrA(test
, GWLP_HINSTANCE
)) != GetModuleHandleA(NULL
) ||
2826 GetWindow(test
, GW_OWNER
) == hwnd
))
2828 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2829 test
= GetWindow(test
, GW_HWNDPREV
);
2831 ok_(file
, line
)(prev
== test
, "%p: expected prev %p, got %p\n", hwnd
, prev
, test
);
2833 test
= GetWindow(hwnd
, GW_OWNER
);
2834 ok_(file
, line
)(owner
== test
, "%p: expected owner %p, got %p\n", hwnd
, owner
, test
);
2836 ex_style
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
2837 ok_(file
, line
)(!(ex_style
& WS_EX_TOPMOST
) == !topmost
, "%p: expected %stopmost\n",
2838 hwnd
, topmost
? "" : "NOT ");
2841 static void test_popup_zorder(HWND hwnd_D
, HWND hwnd_E
, DWORD style
)
2843 HWND hwnd_A
, hwnd_B
, hwnd_C
, hwnd_F
;
2845 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D
, hwnd_E
);
2847 SetWindowPos(hwnd_E
, hwnd_D
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2849 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2850 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2852 hwnd_F
= CreateWindowExA(0, "MainWindowClass", "Owner window",
2853 WS_OVERLAPPED
| WS_CAPTION
,
2855 0, 0, GetModuleHandleA(NULL
), NULL
);
2856 trace("hwnd_F %p\n", hwnd_F
);
2857 check_z_order(hwnd_F
, hwnd_D
, 0, 0, FALSE
);
2859 SetWindowPos(hwnd_F
, hwnd_E
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2860 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2861 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2862 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2864 hwnd_C
= CreateWindowExA(0, "MainWindowClass", NULL
,
2867 hwnd_F
, 0, GetModuleHandleA(NULL
), NULL
);
2868 trace("hwnd_C %p\n", hwnd_C
);
2869 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2870 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2871 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2872 check_z_order(hwnd_C
, hwnd_D
, 0, hwnd_F
, FALSE
);
2874 hwnd_B
= CreateWindowExA(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2877 hwnd_F
, 0, GetModuleHandleA(NULL
), NULL
);
2878 trace("hwnd_B %p\n", hwnd_B
);
2879 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2880 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2881 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2882 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2883 check_z_order(hwnd_B
, hwnd_C
, 0, hwnd_F
, TRUE
);
2885 hwnd_A
= CreateWindowExA(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2888 0, 0, GetModuleHandleA(NULL
), NULL
);
2889 trace("hwnd_A %p\n", hwnd_A
);
2890 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2891 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2892 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2893 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2894 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2895 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2897 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
);
2899 /* move hwnd_F and its popups up */
2900 SetWindowPos(hwnd_F
, HWND_TOP
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2901 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2902 check_z_order(hwnd_D
, hwnd_E
, hwnd_F
, 0, FALSE
);
2903 check_z_order(hwnd_F
, hwnd_D
, hwnd_C
, 0, FALSE
);
2904 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2905 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2906 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2908 /* move hwnd_F and its popups down */
2909 #if 0 /* enable once Wine is fixed to pass this test */
2910 SetWindowPos(hwnd_F
, HWND_BOTTOM
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2911 check_z_order(hwnd_F
, 0, hwnd_C
, 0, FALSE
);
2912 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2913 check_z_order(hwnd_B
, hwnd_C
, hwnd_E
, hwnd_F
, FALSE
);
2914 check_z_order(hwnd_E
, hwnd_B
, hwnd_D
, 0, FALSE
);
2915 check_z_order(hwnd_D
, hwnd_E
, hwnd_A
, 0, FALSE
);
2916 check_z_order(hwnd_A
, hwnd_D
, 0, 0, TRUE
);
2919 /* make hwnd_C owned by a topmost window */
2920 DestroyWindow( hwnd_C
);
2921 hwnd_C
= CreateWindowExA(0, "MainWindowClass", NULL
,
2924 hwnd_A
, 0, GetModuleHandleA(NULL
), NULL
);
2925 trace("hwnd_C %p\n", hwnd_C
);
2926 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2927 check_z_order(hwnd_D
, hwnd_E
, hwnd_F
, 0, FALSE
);
2928 check_z_order(hwnd_F
, hwnd_D
, hwnd_B
, 0, FALSE
);
2929 check_z_order(hwnd_B
, hwnd_F
, hwnd_A
, hwnd_F
, TRUE
);
2930 check_z_order(hwnd_A
, hwnd_B
, hwnd_C
, 0, TRUE
);
2931 check_z_order(hwnd_C
, hwnd_A
, 0, hwnd_A
, TRUE
);
2933 DestroyWindow(hwnd_A
);
2934 DestroyWindow(hwnd_B
);
2935 DestroyWindow(hwnd_C
);
2936 DestroyWindow(hwnd_F
);
2939 static void test_vis_rgn( HWND hwnd
)
2941 RECT win_rect
, rgn_rect
;
2942 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2945 ShowWindow(hwnd
,SW_SHOW
);
2946 hdc
= GetDC( hwnd
);
2947 ok( GetRandomRgn( hdc
, hrgn
, SYSRGN
) != 0, "GetRandomRgn failed\n" );
2948 GetWindowRect( hwnd
, &win_rect
);
2949 GetRgnBox( hrgn
, &rgn_rect
);
2952 trace("win9x, mapping to screen coords\n");
2953 MapWindowPoints( hwnd
, 0, (POINT
*)&rgn_rect
, 2 );
2955 trace("win: %s\n", wine_dbgstr_rect(&win_rect
));
2956 trace("rgn: %s\n", wine_dbgstr_rect(&rgn_rect
));
2957 ok( win_rect
.left
<= rgn_rect
.left
, "rgn left %d not inside win rect %d\n",
2958 rgn_rect
.left
, win_rect
.left
);
2959 ok( win_rect
.top
<= rgn_rect
.top
, "rgn top %d not inside win rect %d\n",
2960 rgn_rect
.top
, win_rect
.top
);
2961 ok( win_rect
.right
>= rgn_rect
.right
, "rgn right %d not inside win rect %d\n",
2962 rgn_rect
.right
, win_rect
.right
);
2963 ok( win_rect
.bottom
>= rgn_rect
.bottom
, "rgn bottom %d not inside win rect %d\n",
2964 rgn_rect
.bottom
, win_rect
.bottom
);
2965 ReleaseDC( hwnd
, hdc
);
2968 static LRESULT WINAPI
set_focus_on_activate_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
2970 if (msg
== WM_ACTIVATE
&& LOWORD(wp
) == WA_ACTIVE
)
2972 HWND child
= GetWindow(hwnd
, GW_CHILD
);
2973 ok(child
!= 0, "couldn't find child window\n");
2975 ok(GetFocus() == child
, "Focus should be on child %p\n", child
);
2978 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
2981 static void test_SetFocus(HWND hwnd
)
2983 HWND child
, child2
, ret
;
2984 WNDPROC old_wnd_proc
;
2986 /* check if we can set focus to non-visible windows */
2988 ShowWindow(hwnd
, SW_SHOW
);
2991 ok( GetFocus() == hwnd
, "Failed to set focus to visible window %p\n", hwnd
);
2992 ok( GetWindowLongA(hwnd
,GWL_STYLE
) & WS_VISIBLE
, "Window %p not visible\n", hwnd
);
2993 ShowWindow(hwnd
, SW_HIDE
);
2996 ok( GetFocus() == hwnd
, "Failed to set focus to invisible window %p\n", hwnd
);
2997 ok( !(GetWindowLongA(hwnd
,GWL_STYLE
) & WS_VISIBLE
), "Window %p still visible\n", hwnd
);
2998 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
3001 ok( GetFocus() == child
, "Failed to set focus to invisible child %p\n", child
);
3002 ok( !(GetWindowLongA(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
3003 ShowWindow(child
, SW_SHOW
);
3004 ok( GetWindowLongA(child
,GWL_STYLE
) & WS_VISIBLE
, "Child %p is not visible\n", child
);
3005 ok( GetFocus() == child
, "Focus no longer on child %p\n", child
);
3006 ShowWindow(child
, SW_HIDE
);
3007 ok( !(GetWindowLongA(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
3008 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
3009 ShowWindow(child
, SW_SHOW
);
3010 child2
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, child
, 0, 0, NULL
);
3012 ShowWindow(child2
, SW_SHOW
);
3014 ShowWindow(child
, SW_HIDE
);
3015 ok( !(GetWindowLongA(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
3016 ok( GetFocus() == child2
, "Focus should be on %p, not %p\n", child2
, GetFocus() );
3017 ShowWindow(child
, SW_SHOW
);
3019 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
3020 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_HIDEWINDOW
);
3021 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
3023 ShowWindow(child
, SW_HIDE
);
3025 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
3026 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_SHOWWINDOW
);
3027 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
3028 ShowWindow(child
, SW_HIDE
);
3029 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
3031 ShowWindow(hwnd
, SW_SHOW
);
3032 ShowWindow(child
, SW_SHOW
);
3034 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
3035 EnableWindow(hwnd
, FALSE
);
3036 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
3037 EnableWindow(hwnd
, TRUE
);
3039 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
3040 ShowWindow(hwnd
, SW_SHOWMINIMIZED
);
3041 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
3043 ok( GetFocus() != child
, "Focus should not be on child %p\n", child
);
3044 ok( GetFocus() != hwnd
, "Focus should not be on parent %p\n", hwnd
);
3045 ShowWindow(hwnd
, SW_RESTORE
);
3046 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
3047 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
3048 ShowWindow(hwnd
, SW_SHOWMINIMIZED
);
3049 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
3050 ok( GetFocus() != child
, "Focus should not be on child %p\n", child
);
3052 ok( GetFocus() != hwnd
, "Focus should not be on parent %p\n", hwnd
);
3053 old_wnd_proc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)set_focus_on_activate_proc
);
3054 ShowWindow(hwnd
, SW_RESTORE
);
3055 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
3057 ok( GetFocus() == child
, "Focus should be on child %p, not %p\n", child
, GetFocus() );
3058 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)old_wnd_proc
);
3061 SetParent( child
, GetDesktopWindow());
3062 SetParent( child2
, child
);
3063 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
3064 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
3065 ret
= SetFocus( child2
);
3066 ok( ret
== 0, "SetFocus %p should fail\n", child2
);
3067 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
3068 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
3069 ret
= SetFocus( child
);
3070 ok( ret
== 0, "SetFocus %p should fail\n", child
);
3071 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
3072 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
3073 SetWindowLongW( child
, GWL_STYLE
, WS_POPUP
|WS_CHILD
);
3075 ok( GetActiveWindow() == child
, "child window %p should be active\n", child
);
3076 ok( GetFocus() == child2
, "Focus should be on child2 %p\n", child2
);
3078 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
3079 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
3081 ok( GetActiveWindow() == child
, "child window %p should be active\n", child
);
3082 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
3084 DestroyWindow( child2
);
3085 DestroyWindow( child
);
3088 static void test_SetActiveWindow(HWND hwnd
)
3092 flush_events( TRUE
);
3093 ShowWindow(hwnd
, SW_HIDE
);
3096 check_wnd_state(0, 0, 0, 0);
3098 /*trace("testing SetActiveWindow %p\n", hwnd);*/
3100 ShowWindow(hwnd
, SW_SHOW
);
3101 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3103 hwnd2
= SetActiveWindow(0);
3104 ok(hwnd2
== hwnd
, "SetActiveWindow returned %p instead of %p\n", hwnd2
, hwnd
);
3105 if (!GetActiveWindow()) /* doesn't always work on vista */
3107 check_wnd_state(0, 0, 0, 0);
3108 hwnd2
= SetActiveWindow(hwnd
);
3109 ok(hwnd2
== 0, "SetActiveWindow returned %p instead of 0\n", hwnd2
);
3111 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3113 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
3114 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3116 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
3117 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3119 ShowWindow(hwnd
, SW_HIDE
);
3120 check_wnd_state(0, 0, 0, 0);
3122 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
3123 SetActiveWindow(hwnd
);
3124 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3126 ShowWindow(hwnd
, SW_SHOW
);
3127 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3129 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
3130 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
3132 DestroyWindow(hwnd2
);
3133 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3135 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
3136 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
3138 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
3139 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
3141 DestroyWindow(hwnd2
);
3142 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3145 struct create_window_thread_params
3148 HANDLE window_created
;
3149 HANDLE test_finished
;
3152 static DWORD WINAPI
create_window_thread(void *param
)
3154 struct create_window_thread_params
*p
= param
;
3158 p
->window
= CreateWindowA("static", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 0, 0, 0, 0, 0, 0);
3160 ret
= SetEvent(p
->window_created
);
3161 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
3163 res
= WaitForSingleObject(p
->test_finished
, INFINITE
);
3164 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
3166 DestroyWindow(p
->window
);
3170 static void test_SetForegroundWindow(HWND hwnd
)
3172 struct create_window_thread_params thread_params
;
3180 flush_events( TRUE
);
3181 ShowWindow(hwnd
, SW_HIDE
);
3184 check_wnd_state(0, 0, 0, 0);
3186 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
3188 ShowWindow(hwnd
, SW_SHOW
);
3189 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3191 hwnd2
= SetActiveWindow(0);
3192 ok(hwnd2
== hwnd
, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2
, hwnd
);
3193 if (GetActiveWindow() == hwnd
) /* doesn't always work on vista */
3194 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3196 check_wnd_state(0, 0, 0, 0);
3198 ret
= SetForegroundWindow(hwnd
);
3201 skip( "SetForegroundWindow not working\n" );
3204 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3206 SetLastError(0xdeadbeef);
3207 ret
= SetForegroundWindow(0);
3208 ok(!ret
, "SetForegroundWindow returned TRUE instead of FALSE\n");
3209 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
||
3210 broken(GetLastError() == 0xdeadbeef), /* win9x */
3211 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
3212 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3214 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
3215 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3217 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
3218 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3220 hwnd2
= GetForegroundWindow();
3221 ok(hwnd2
== hwnd
, "Wrong foreground window %p\n", hwnd2
);
3222 ret
= SetForegroundWindow( GetDesktopWindow() );
3223 ok(ret
, "SetForegroundWindow(desktop) error: %d\n", GetLastError());
3224 hwnd2
= GetForegroundWindow();
3225 ok(hwnd2
!= hwnd
, "Wrong foreground window %p\n", hwnd2
);
3227 ShowWindow(hwnd
, SW_HIDE
);
3228 check_wnd_state(0, 0, 0, 0);
3230 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
3231 ret
= SetForegroundWindow(hwnd
);
3232 ok(ret
|| broken(!ret
), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
3233 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3235 ShowWindow(hwnd
, SW_SHOW
);
3236 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3238 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
3239 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
3241 DestroyWindow(hwnd2
);
3242 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3244 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
3245 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
3247 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
3248 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
3250 DestroyWindow(hwnd2
);
3251 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3253 hwnd2
= CreateWindowA("static", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 0, 0, 0, 0, 0, 0);
3254 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
3256 thread_params
.window_created
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3257 ok(!!thread_params
.window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
3258 thread_params
.test_finished
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3259 ok(!!thread_params
.test_finished
, "CreateEvent failed, last error %#x.\n", GetLastError());
3260 thread
= CreateThread(NULL
, 0, create_window_thread
, &thread_params
, 0, &tid
);
3261 ok(!!thread
, "Failed to create thread, last error %#x.\n", GetLastError());
3262 res
= WaitForSingleObject(thread_params
.window_created
, INFINITE
);
3263 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
3264 check_wnd_state(hwnd2
, thread_params
.window
, hwnd2
, 0);
3266 SetForegroundWindow(hwnd2
);
3267 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
3269 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
3270 if (0) check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
3271 todo_wine
ok(GetActiveWindow() == hwnd2
, "Expected active window %p, got %p.\n", hwnd2
, GetActiveWindow());
3272 todo_wine
ok(GetFocus() == hwnd2
, "Expected focus window %p, got %p.\n", hwnd2
, GetFocus());
3274 SetForegroundWindow(hwnd
);
3275 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3276 style
= GetWindowLongA(hwnd2
, GWL_STYLE
) | WS_CHILD
;
3277 ok(SetWindowLongA(hwnd2
, GWL_STYLE
, style
), "SetWindowLong failed\n");
3278 ok(SetForegroundWindow(hwnd2
), "SetForegroundWindow failed\n");
3279 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
3281 SetForegroundWindow(hwnd
);
3282 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3283 ok(SetWindowLongA(hwnd2
, GWL_STYLE
, style
& (~WS_POPUP
)), "SetWindowLong failed\n");
3284 ok(!SetForegroundWindow(hwnd2
), "SetForegroundWindow failed\n");
3285 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3287 SetEvent(thread_params
.test_finished
);
3288 WaitForSingleObject(thread
, INFINITE
);
3289 CloseHandle(thread_params
.test_finished
);
3290 CloseHandle(thread_params
.window_created
);
3291 CloseHandle(thread
);
3292 DestroyWindow(hwnd2
);
3295 static WNDPROC old_button_proc
;
3297 static LRESULT WINAPI
button_hook_proc(HWND button
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3302 key_state
= GetKeyState(VK_LBUTTON
);
3303 ok(!(key_state
& 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state
);
3305 ret
= CallWindowProcA(old_button_proc
, button
, msg
, wparam
, lparam
);
3307 if (msg
== WM_LBUTTONDOWN
)
3311 check_wnd_state(button
, button
, button
, button
);
3313 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
3315 trace("hwnd %p\n", hwnd
);
3317 check_wnd_state(button
, button
, button
, button
);
3319 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
3321 check_wnd_state(button
, button
, button
, button
);
3323 DestroyWindow(hwnd
);
3325 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
3327 trace("hwnd %p\n", hwnd
);
3329 check_wnd_state(button
, button
, button
, button
);
3331 /* button wnd proc should release capture on WM_KILLFOCUS if it does
3332 * match internal button state.
3334 SendMessageA(button
, WM_KILLFOCUS
, 0, 0);
3335 check_wnd_state(button
, button
, button
, 0);
3337 ShowWindow(hwnd
, SW_SHOW
);
3338 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3340 capture
= SetCapture(hwnd
);
3341 ok(capture
== 0, "SetCapture() = %p\n", capture
);
3343 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
3345 DestroyWindow(hwnd
);
3347 check_wnd_state(button
, 0, button
, 0);
3353 static void test_capture_1(void)
3355 HWND button
, capture
;
3357 capture
= GetCapture();
3358 ok(capture
== 0, "GetCapture() = %p\n", capture
);
3360 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
3362 trace("button %p\n", button
);
3364 old_button_proc
= (WNDPROC
)SetWindowLongPtrA(button
, GWLP_WNDPROC
, (LONG_PTR
)button_hook_proc
);
3366 SendMessageA(button
, WM_LBUTTONDOWN
, 0, 0);
3368 capture
= SetCapture(button
);
3369 ok(capture
== 0, "SetCapture() = %p\n", capture
);
3370 check_wnd_state(button
, 0, button
, button
);
3372 DestroyWindow(button
);
3373 /* old active window test depends on previously executed window
3374 * activation tests, and fails under NT4.
3375 check_wnd_state(oldActive, 0, oldFocus, 0);*/
3378 static void test_capture_2(void)
3380 HWND button
, hwnd
, capture
, oldFocus
, oldActive
;
3382 oldFocus
= GetFocus();
3383 oldActive
= GetActiveWindow();
3384 check_wnd_state(oldActive
, 0, oldFocus
, 0);
3386 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
3388 trace("button %p\n", button
);
3390 check_wnd_state(button
, button
, button
, 0);
3392 capture
= SetCapture(button
);
3393 ok(capture
== 0, "SetCapture() = %p\n", capture
);
3395 check_wnd_state(button
, button
, button
, button
);
3397 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
3398 * internal button state.
3400 SendMessageA(button
, WM_KILLFOCUS
, 0, 0);
3401 check_wnd_state(button
, button
, button
, button
);
3403 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
3405 trace("hwnd %p\n", hwnd
);
3407 check_wnd_state(button
, button
, button
, button
);
3409 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
3411 check_wnd_state(button
, button
, button
, button
);
3413 DestroyWindow(hwnd
);
3415 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
3417 trace("hwnd %p\n", hwnd
);
3419 check_wnd_state(button
, button
, button
, button
);
3421 ShowWindow(hwnd
, SW_SHOW
);
3423 check_wnd_state(hwnd
, hwnd
, hwnd
, button
);
3425 capture
= SetCapture(hwnd
);
3426 ok(capture
== button
, "SetCapture() = %p\n", capture
);
3428 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
3430 DestroyWindow(hwnd
);
3431 check_wnd_state(button
, button
, button
, 0);
3433 DestroyWindow(button
);
3434 check_wnd_state(oldActive
, 0, oldFocus
, 0);
3437 static void test_capture_3(HWND hwnd1
, HWND hwnd2
)
3441 ShowWindow(hwnd1
, SW_HIDE
);
3442 ShowWindow(hwnd2
, SW_HIDE
);
3444 ok(!IsWindowVisible(hwnd1
), "%p should be invisible\n", hwnd1
);
3445 ok(!IsWindowVisible(hwnd2
), "%p should be invisible\n", hwnd2
);
3448 check_wnd_state(0, 0, 0, hwnd1
);
3451 check_wnd_state(0, 0, 0, hwnd2
);
3453 ShowWindow(hwnd1
, SW_SHOW
);
3454 check_wnd_state(hwnd1
, hwnd1
, hwnd1
, hwnd2
);
3456 ret
= ReleaseCapture();
3457 ok (ret
, "releasecapture did not return TRUE.\n");
3458 ret
= ReleaseCapture();
3459 ok (ret
, "releasecapture did not return TRUE after second try.\n");
3462 static LRESULT CALLBACK
test_capture_4_proc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
3465 HWND cap_wnd
, cap_wnd2
, set_cap_wnd
;
3469 case WM_CAPTURECHANGED
:
3471 /* now try to release capture from menu. this should fail */
3472 if (pGetGUIThreadInfo
)
3474 memset(>i
, 0, sizeof(GUITHREADINFO
));
3475 gti
.cbSize
= sizeof(GUITHREADINFO
);
3476 status
= pGetGUIThreadInfo(GetCurrentThreadId(), >i
);
3477 ok(status
, "GetGUIThreadInfo() failed!\n");
3478 ok(gti
.flags
& GUI_INMENUMODE
, "Thread info incorrect (flags=%08X)!\n", gti
.flags
);
3480 cap_wnd
= GetCapture();
3482 ok(cap_wnd
== (HWND
)lParam
, "capture window %p does not match lparam %lx\n", cap_wnd
, lParam
);
3483 todo_wine
ok(cap_wnd
== hWnd
, "capture window %p does not match hwnd %p\n", cap_wnd
, hWnd
);
3485 /* check that re-setting the capture for the menu fails */
3486 set_cap_wnd
= SetCapture(cap_wnd
);
3487 ok(!set_cap_wnd
|| broken(set_cap_wnd
== cap_wnd
), /* nt4 */
3488 "SetCapture should have failed!\n");
3491 DestroyWindow(hWnd
);
3495 /* check that SetCapture fails for another window and that it does not touch the error code */
3496 set_cap_wnd
= SetCapture(hWnd
);
3497 ok(!set_cap_wnd
, "SetCapture should have failed!\n");
3499 /* check that ReleaseCapture fails and does not touch the error code */
3500 status
= ReleaseCapture();
3501 ok(!status
, "ReleaseCapture should have failed!\n");
3503 /* check that thread info did not change */
3504 if (pGetGUIThreadInfo
)
3506 memset(>i
, 0, sizeof(GUITHREADINFO
));
3507 gti
.cbSize
= sizeof(GUITHREADINFO
);
3508 status
= pGetGUIThreadInfo(GetCurrentThreadId(), >i
);
3509 ok(status
, "GetGUIThreadInfo() failed!\n");
3510 ok(gti
.flags
& GUI_INMENUMODE
, "Thread info incorrect (flags=%08X)!\n", gti
.flags
);
3513 /* verify that no capture change took place */
3514 cap_wnd2
= GetCapture();
3515 ok(cap_wnd2
== cap_wnd
, "Capture changed!\n");
3517 /* we are done. kill the window */
3518 DestroyWindow(hWnd
);
3522 return( DefWindowProcA( hWnd
, msg
, wParam
, lParam
) );
3527 /* Test that no-one can mess around with the current capture while a menu is open */
3528 static void test_capture_4(void)
3534 HINSTANCE hInstance
= GetModuleHandleA( NULL
);
3537 if (!pGetGUIThreadInfo
)
3539 win_skip("GetGUIThreadInfo is not available\n");
3542 wclass
.lpszClassName
= "TestCapture4Class";
3543 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
3544 wclass
.lpfnWndProc
= test_capture_4_proc
;
3545 wclass
.hInstance
= hInstance
;
3546 wclass
.hIcon
= LoadIconA( 0, (LPCSTR
)IDI_APPLICATION
);
3547 wclass
.hCursor
= LoadCursorA( 0, (LPCSTR
)IDC_ARROW
);
3548 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
3549 wclass
.lpszMenuName
= 0;
3550 wclass
.cbClsExtra
= 0;
3551 wclass
.cbWndExtra
= 0;
3552 aclass
= RegisterClassA( &wclass
);
3553 ok( aclass
, "RegisterClassA failed with error %d\n", GetLastError());
3554 hwnd
= CreateWindowA( wclass
.lpszClassName
, "MenuTest",
3555 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0,
3556 400, 200, NULL
, NULL
, hInstance
, NULL
);
3557 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
3559 hmenu
= CreatePopupMenu();
3561 ret
= AppendMenuA( hmenu
, MF_STRING
, 1, "winetest2");
3562 ok( ret
, "AppendMenuA has failed!\n");
3564 /* set main window to have initial capture */
3569 win_skip("TrackPopupMenu test crashes on Win9x/WinMe\n");
3573 /* create popup (it will self-destruct) */
3574 ret
= TrackPopupMenu(hmenu
, TPM_RETURNCMD
, 100, 100, 0, hwnd
, NULL
);
3575 ok( ret
== 0, "TrackPopupMenu returned %d expected zero\n", ret
);
3580 DestroyWindow(hwnd
);
3583 /* PeekMessage wrapper that ignores the messages we don't care about */
3584 static BOOL
peek_message( MSG
*msg
)
3589 ret
= PeekMessageA(msg
, 0, 0, 0, PM_REMOVE
);
3590 } while (ret
&& ignore_message(msg
->message
));
3594 static void test_keyboard_input(HWND hwnd
)
3599 flush_events( TRUE
);
3600 SetWindowPos(hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_SHOWWINDOW
);
3602 flush_events( TRUE
);
3604 ok(GetActiveWindow() == hwnd
, "wrong active window %p\n", GetActiveWindow());
3607 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
3609 flush_events( TRUE
);
3611 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
3612 ret
= peek_message(&msg
);
3613 ok( ret
, "no message available\n");
3614 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3615 ret
= peek_message(&msg
);
3616 ok( !ret
, "message %04x available\n", msg
.message
);
3618 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
3620 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
3621 ret
= peek_message(&msg
);
3622 ok(ret
, "no message available\n");
3623 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3624 ret
= peek_message(&msg
);
3625 ok( !ret
, "message %04x available\n", msg
.message
);
3627 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
3629 keybd_event(VK_SPACE
, 0, 0, 0);
3630 if (!peek_message(&msg
))
3632 skip( "keybd_event didn't work, skipping keyboard test\n" );
3635 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3636 ret
= peek_message(&msg
);
3637 ok( !ret
, "message %04x available\n", msg
.message
);
3640 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3642 flush_events( TRUE
);
3644 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
3645 ret
= peek_message(&msg
);
3646 ok(ret
, "no message available\n");
3647 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3648 ret
= peek_message(&msg
);
3649 ok( !ret
, "message %04x available\n", msg
.message
);
3651 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3653 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
3654 ret
= peek_message(&msg
);
3655 ok(ret
, "no message available\n");
3656 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3657 ret
= peek_message(&msg
);
3658 ok( !ret
, "message %04x available\n", msg
.message
);
3660 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3662 keybd_event(VK_SPACE
, 0, 0, 0);
3663 ret
= peek_message(&msg
);
3664 ok(ret
, "no message available\n");
3665 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_SYSKEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3666 ret
= peek_message(&msg
);
3667 ok( !ret
, "message %04x available\n", msg
.message
);
3670 static BOOL
wait_for_message( MSG
*msg
)
3676 ret
= peek_message(msg
);
3679 if (msg
->message
== WM_PAINT
) DispatchMessageA(msg
);
3682 else if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, 100, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
3684 if (!ret
) msg
->message
= 0;
3688 static void test_mouse_input(HWND hwnd
)
3698 ShowWindow(hwnd
, SW_SHOWNORMAL
);
3700 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3702 GetWindowRect(hwnd
, &rc
);
3703 trace("main window %p: %s\n", hwnd
, wine_dbgstr_rect(&rc
));
3705 popup
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_POPUP
,
3706 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
,
3709 ShowWindow(popup
, SW_SHOW
);
3710 UpdateWindow(popup
);
3711 SetWindowPos( popup
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3713 GetWindowRect(popup
, &rc
);
3714 trace("popup window %p: %s\n", popup
, wine_dbgstr_rect(&rc
));
3716 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
3717 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
3718 trace("setting cursor to (%d,%d)\n", x
, y
);
3722 if (x
!= pt
.x
|| y
!= pt
.y
)
3724 skip( "failed to set mouse position, skipping mouse input tests\n" );
3728 flush_events( TRUE
);
3730 /* Check that setting the same position may generate WM_MOUSEMOVE */
3733 ret
= peek_message(&msg
);
3736 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n",
3737 msg
.hwnd
, msg
.message
);
3738 ok(msg
.pt
.x
== x
&& msg
.pt
.y
== y
, "wrong message coords (%d,%d)/(%d,%d)\n",
3739 x
, y
, msg
.pt
.x
, msg
.pt
.y
);
3742 /* force the system to update its internal queue mouse position,
3743 * otherwise it won't generate relative mouse movements below.
3745 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
3746 flush_events( TRUE
);
3749 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
3750 flush_events( FALSE
);
3751 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
3752 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
3754 if (ignore_message(msg
.message
)) continue;
3755 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
,
3756 "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3757 DispatchMessageA(&msg
);
3759 ret
= peek_message(&msg
);
3760 ok( !ret
, "message %04x available\n", msg
.message
);
3762 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
3763 ShowWindow(popup
, SW_HIDE
);
3764 ret
= wait_for_message( &msg
);
3766 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3767 flush_events( TRUE
);
3769 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
3770 ShowWindow(hwnd
, SW_HIDE
);
3771 ret
= wait_for_message( &msg
);
3772 ok( !ret
, "message %04x available\n", msg
.message
);
3773 flush_events( TRUE
);
3775 /* test mouse clicks */
3777 ShowWindow(hwnd
, SW_SHOW
);
3778 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3779 flush_events( TRUE
);
3780 ShowWindow(popup
, SW_SHOW
);
3781 SetWindowPos( popup
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3782 flush_events( TRUE
);
3784 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3785 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3786 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3787 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3789 ret
= wait_for_message( &msg
);
3792 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
3795 if (msg
.message
== WM_MOUSEMOVE
) /* win2k has an extra WM_MOUSEMOVE here */
3797 ret
= wait_for_message( &msg
);
3798 ok(ret
, "no message available\n");
3801 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
3802 msg
.hwnd
, popup
, msg
.message
);
3804 ret
= wait_for_message( &msg
);
3805 ok(ret
, "no message available\n");
3806 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
3807 msg
.hwnd
, popup
, msg
.message
);
3809 ret
= wait_for_message( &msg
);
3810 ok(ret
, "no message available\n");
3811 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p/%p message %04x\n",
3812 msg
.hwnd
, popup
, msg
.message
);
3814 ret
= wait_for_message( &msg
);
3815 ok(ret
, "no message available\n");
3816 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
3817 msg
.hwnd
, popup
, msg
.message
);
3819 ret
= peek_message(&msg
);
3820 ok(!ret
, "message %04x available\n", msg
.message
);
3822 ShowWindow(popup
, SW_HIDE
);
3823 flush_events( TRUE
);
3825 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3826 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3827 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3828 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3830 ret
= wait_for_message( &msg
);
3831 ok(ret
, "no message available\n");
3832 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
3833 msg
.hwnd
, hwnd
, msg
.message
);
3834 ret
= wait_for_message( &msg
);
3835 ok(ret
, "no message available\n");
3836 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
3837 msg
.hwnd
, hwnd
, msg
.message
);
3839 test_lbuttondown_flag
= TRUE
;
3840 SendMessageA(hwnd
, WM_COMMAND
, (WPARAM
)popup
, 0);
3841 test_lbuttondown_flag
= FALSE
;
3843 ret
= wait_for_message( &msg
);
3844 ok(ret
, "no message available\n");
3845 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
3846 msg
.hwnd
, popup
, msg
.message
);
3847 ok(peek_message(&msg
), "no message available\n");
3848 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
3849 msg
.hwnd
, popup
, msg
.message
);
3850 ok(peek_message(&msg
), "no message available\n");
3852 /* Test WM_MOUSEACTIVATE */
3853 #define TEST_MOUSEACTIVATE(A,B) \
3854 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
3855 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
3857 TEST_MOUSEACTIVATE(HTERROR
,MA_ACTIVATE
);
3858 TEST_MOUSEACTIVATE(HTTRANSPARENT
,MA_ACTIVATE
);
3859 TEST_MOUSEACTIVATE(HTNOWHERE
,MA_ACTIVATE
);
3860 TEST_MOUSEACTIVATE(HTCLIENT
,MA_ACTIVATE
);
3861 TEST_MOUSEACTIVATE(HTCAPTION
,MA_ACTIVATE
);
3862 TEST_MOUSEACTIVATE(HTSYSMENU
,MA_ACTIVATE
);
3863 TEST_MOUSEACTIVATE(HTSIZE
,MA_ACTIVATE
);
3864 TEST_MOUSEACTIVATE(HTMENU
,MA_ACTIVATE
);
3865 TEST_MOUSEACTIVATE(HTHSCROLL
,MA_ACTIVATE
);
3866 TEST_MOUSEACTIVATE(HTVSCROLL
,MA_ACTIVATE
);
3867 TEST_MOUSEACTIVATE(HTMINBUTTON
,MA_ACTIVATE
);
3868 TEST_MOUSEACTIVATE(HTMAXBUTTON
,MA_ACTIVATE
);
3869 TEST_MOUSEACTIVATE(HTLEFT
,MA_ACTIVATE
);
3870 TEST_MOUSEACTIVATE(HTRIGHT
,MA_ACTIVATE
);
3871 TEST_MOUSEACTIVATE(HTTOP
,MA_ACTIVATE
);
3872 TEST_MOUSEACTIVATE(HTTOPLEFT
,MA_ACTIVATE
);
3873 TEST_MOUSEACTIVATE(HTTOPRIGHT
,MA_ACTIVATE
);
3874 TEST_MOUSEACTIVATE(HTBOTTOM
,MA_ACTIVATE
);
3875 TEST_MOUSEACTIVATE(HTBOTTOMLEFT
,MA_ACTIVATE
);
3876 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT
,MA_ACTIVATE
);
3877 TEST_MOUSEACTIVATE(HTBORDER
,MA_ACTIVATE
);
3878 TEST_MOUSEACTIVATE(HTOBJECT
,MA_ACTIVATE
);
3879 TEST_MOUSEACTIVATE(HTCLOSE
,MA_ACTIVATE
);
3880 TEST_MOUSEACTIVATE(HTHELP
,MA_ACTIVATE
);
3883 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
3884 flush_events( TRUE
);
3886 DestroyWindow(popup
);
3889 static void test_validatergn(HWND hwnd
)
3895 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_VISIBLE
, 10, 10, 10, 10, hwnd
, 0, 0, NULL
);
3896 ShowWindow(hwnd
, SW_SHOW
);
3897 UpdateWindow( hwnd
);
3898 /* test that ValidateRect validates children*/
3899 InvalidateRect( child
, NULL
, 1);
3900 GetWindowRect( child
, &rc
);
3901 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
3902 ret
= GetUpdateRect( child
, &rc2
, 0);
3903 ok( ret
== 1, "Expected GetUpdateRect to return non-zero, got %d\n", ret
);
3904 ok( rc2
.right
> rc2
.left
&& rc2
.bottom
> rc2
.top
,
3905 "Update rectangle is empty!\n");
3906 ValidateRect( hwnd
, &rc
);
3907 ret
= GetUpdateRect( child
, &rc2
, 0);
3908 ok( !ret
, "Expected GetUpdateRect to return zero, got %d\n", ret
);
3909 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
3910 "Update rectangle %s is not empty!\n", wine_dbgstr_rect(&rc2
));
3912 /* now test ValidateRgn */
3913 InvalidateRect( child
, NULL
, 1);
3914 GetWindowRect( child
, &rc
);
3915 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
3916 rgn
= CreateRectRgnIndirect( &rc
);
3917 ValidateRgn( hwnd
, rgn
);
3918 ret
= GetUpdateRect( child
, &rc2
, 0);
3919 ok( !ret
, "Expected GetUpdateRect to return zero, got %d\n", ret
);
3920 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
3921 "Update rectangle %s is not empty!\n", wine_dbgstr_rect(&rc2
));
3924 DestroyWindow( child
);
3927 static void nccalchelper(HWND hwnd
, INT x
, INT y
, RECT
*prc
)
3930 MoveWindow( hwnd
, 0, 0, x
, y
, 0);
3931 GetWindowRect( hwnd
, prc
);
3933 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)prc
);
3934 trace("window rect is %s, nccalc rect is %s\n", wine_dbgstr_rect(&rc
), wine_dbgstr_rect(prc
));
3937 static void test_nccalcscroll(HWND parent
)
3940 INT sbheight
= GetSystemMetrics( SM_CYHSCROLL
);
3941 INT sbwidth
= GetSystemMetrics( SM_CXVSCROLL
);
3942 HWND hwnd
= CreateWindowExA(0, "static", NULL
,
3943 WS_CHILD
| WS_VISIBLE
| WS_VSCROLL
| WS_HSCROLL
,
3944 10, 10, 200, 200, parent
, 0, 0, NULL
);
3945 ShowWindow( parent
, SW_SHOW
);
3946 UpdateWindow( parent
);
3948 /* test window too low for a horizontal scroll bar */
3949 nccalchelper( hwnd
, 100, sbheight
, &rc1
);
3950 ok( rc1
.bottom
- rc1
.top
== sbheight
, "Height should be %d size is %s\n", sbheight
,
3951 wine_dbgstr_rect(&rc1
));
3953 /* test window just high enough for a horizontal scroll bar */
3954 nccalchelper( hwnd
, 100, sbheight
+ 1, &rc1
);
3955 ok( rc1
.bottom
- rc1
.top
== 1, "Height should be 1 size is %s\n", wine_dbgstr_rect(&rc1
));
3957 /* test window too narrow for a vertical scroll bar */
3958 nccalchelper( hwnd
, sbwidth
- 1, 100, &rc1
);
3959 ok( rc1
.right
- rc1
.left
== sbwidth
- 1 , "Width should be %d size is %s\n", sbwidth
- 1,
3960 wine_dbgstr_rect(&rc1
));
3962 /* test window just wide enough for a vertical scroll bar */
3963 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
3964 ok( rc1
.right
- rc1
.left
== 0, "Width should be 0 size is %s\n", wine_dbgstr_rect(&rc1
));
3966 /* same test, but with client edge: not enough width */
3967 SetWindowLongA( hwnd
, GWL_EXSTYLE
, WS_EX_CLIENTEDGE
| GetWindowLongA( hwnd
, GWL_EXSTYLE
));
3968 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
3969 ok( rc1
.right
- rc1
.left
== sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
),
3970 "Width should be %d size is %s\n", sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
),
3971 wine_dbgstr_rect(&rc1
));
3973 DestroyWindow( hwnd
);
3976 static void test_SetParent(void)
3978 HWND desktop
= GetDesktopWindow();
3980 HWND ret
, parent
, child1
, child2
, child3
, child4
, sibling
, popup
;
3983 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
3984 100, 100, 200, 200, 0, 0, 0, NULL
);
3985 assert(parent
!= 0);
3986 child1
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
3987 0, 0, 50, 50, parent
, 0, 0, NULL
);
3988 assert(child1
!= 0);
3989 child2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
3990 0, 0, 50, 50, child1
, 0, 0, NULL
);
3991 assert(child2
!= 0);
3992 child3
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
3993 0, 0, 50, 50, child2
, 0, 0, NULL
);
3994 assert(child3
!= 0);
3995 child4
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
3996 0, 0, 50, 50, child3
, 0, 0, NULL
);
3997 assert(child4
!= 0);
3999 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
4000 parent
, child1
, child2
, child3
, child4
);
4002 check_parents(parent
, desktop
, 0, 0, 0, parent
, parent
);
4003 check_parents(child1
, parent
, parent
, parent
, 0, parent
, parent
);
4004 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
4005 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
4006 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
4008 ok(!IsChild(desktop
, parent
), "wrong parent/child %p/%p\n", desktop
, parent
);
4009 ok(!IsChild(desktop
, child1
), "wrong parent/child %p/%p\n", desktop
, child1
);
4010 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
4011 ok(!IsChild(desktop
, child3
), "wrong parent/child %p/%p\n", desktop
, child3
);
4012 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
4014 ok(IsChild(parent
, child1
), "wrong parent/child %p/%p\n", parent
, child1
);
4015 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
4016 ok(!IsChild(parent
, child2
), "wrong parent/child %p/%p\n", parent
, child2
);
4017 ok(!IsChild(child1
, child2
), "wrong parent/child %p/%p\n", child1
, child2
);
4018 ok(!IsChild(parent
, child3
), "wrong parent/child %p/%p\n", parent
, child3
);
4019 ok(IsChild(child2
, child3
), "wrong parent/child %p/%p\n", child2
, child3
);
4020 ok(!IsChild(parent
, child4
), "wrong parent/child %p/%p\n", parent
, child4
);
4021 ok(!IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
4022 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
4024 if (!is_win9x
) /* Win9x doesn't survive this test */
4026 ok(!SetParent(parent
, child1
), "SetParent should fail\n");
4027 ok(!SetParent(child2
, child3
), "SetParent should fail\n");
4028 ok(SetParent(child1
, parent
) != 0, "SetParent should not fail\n");
4029 ret
= SetParent(parent
, child2
);
4030 todo_wine
ok( !ret
|| broken( ret
!= 0 ), "SetParent should fail\n");
4031 if (ret
) /* nt4, win2k */
4033 ret
= SetParent(parent
, child3
);
4034 ok(ret
!= 0, "SetParent should not fail\n");
4035 ret
= SetParent(child2
, parent
);
4036 ok(!ret
, "SetParent should fail\n");
4037 ret
= SetParent(parent
, child4
);
4038 ok(ret
!= 0, "SetParent should not fail\n");
4039 check_parents(parent
, child4
, child4
, 0, 0, child4
, parent
);
4040 check_parents(child1
, parent
, parent
, parent
, 0, child4
, parent
);
4041 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
4042 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
4043 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
4047 ret
= SetParent(parent
, child3
);
4048 ok(ret
!= 0, "SetParent should not fail\n");
4049 ret
= SetParent(child2
, parent
);
4050 ok(!ret
, "SetParent should fail\n");
4051 ret
= SetParent(parent
, child4
);
4052 ok(!ret
, "SetParent should fail\n");
4053 check_parents(parent
, child3
, child3
, 0, 0, child2
, parent
);
4054 check_parents(child1
, parent
, parent
, parent
, 0, child2
, parent
);
4055 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
4056 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
4057 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
4061 skip("Win9x/WinMe crash\n");
4063 hMenu
= CreateMenu();
4064 sibling
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
4065 100, 100, 200, 200, 0, hMenu
, 0, NULL
);
4066 assert(sibling
!= 0);
4068 ok(SetParent(sibling
, parent
) != 0, "SetParent should not fail\n");
4069 ok(GetMenu(sibling
) == hMenu
, "SetParent should not remove menu\n");
4071 ok(SetParent(parent
, desktop
) != 0, "SetParent should not fail\n");
4072 ok(SetParent(child4
, child3
) != 0, "SetParent should not fail\n");
4073 ok(SetParent(child3
, child2
) != 0, "SetParent should not fail\n");
4074 ok(SetParent(child2
, child1
) != 0, "SetParent should not fail\n");
4075 ok(!IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
4076 SetWindowLongW(child4
, GWL_STYLE
, WS_CHILD
);
4077 ok(IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
4078 ok(IsChild(child2
, child4
), "wrong parent/child %p/%p\n", child2
, child4
);
4079 ok(!IsChild(child1
, child4
), "wrong parent/child %p/%p\n", child1
, child4
);
4080 SetWindowLongW(child2
, GWL_STYLE
, WS_CHILD
);
4081 ok(IsChild(child1
, child4
), "wrong parent/child %p/%p\n", child1
, child4
);
4082 ok(IsChild(parent
, child4
), "wrong parent/child %p/%p\n", parent
, child4
);
4084 ok(DestroyWindow(parent
), "DestroyWindow() failed\n");
4086 ok(!IsWindow(parent
), "parent still exists\n");
4087 ok(!IsWindow(sibling
), "sibling still exists\n");
4088 ok(!IsWindow(child1
), "child1 still exists\n");
4089 ok(!IsWindow(child2
), "child2 still exists\n");
4090 ok(!IsWindow(child3
), "child3 still exists\n");
4091 ok(!IsWindow(child4
), "child4 still exists\n");
4093 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
4094 100, 100, 200, 200, 0, 0, 0, NULL
);
4095 assert(parent
!= 0);
4096 child1
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
4097 0, 0, 50, 50, parent
, 0, 0, NULL
);
4098 assert(child1
!= 0);
4099 popup
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
4100 0, 0, 50, 50, 0, 0, 0, NULL
);
4103 trace("parent %p, child %p, popup %p\n", parent
, child1
, popup
);
4105 check_parents(parent
, desktop
, 0, 0, 0, parent
, parent
);
4106 check_parents(child1
, parent
, parent
, parent
, 0, parent
, parent
);
4107 check_parents(popup
, desktop
, 0, 0, 0, popup
, popup
);
4109 SetActiveWindow(parent
);
4111 check_active_state(parent
, 0, parent
);
4113 ret
= SetParent(popup
, child1
);
4114 ok(ret
== desktop
, "expected %p, got %p\n", desktop
, ret
);
4115 check_parents(popup
, child1
, child1
, 0, 0, parent
, popup
);
4116 check_active_state(popup
, 0, popup
);
4118 SetActiveWindow(parent
);
4120 check_active_state(popup
, 0, popup
);
4122 EnableWindow(child1
, FALSE
);
4123 check_active_state(popup
, 0, popup
);
4125 check_active_state(parent
, 0, parent
);
4127 check_active_state(popup
, 0, popup
);
4128 EnableWindow(child1
, TRUE
);
4130 ShowWindow(child1
, SW_MINIMIZE
);
4132 check_active_state(parent
, 0, parent
);
4134 check_active_state(popup
, 0, popup
);
4135 ShowWindow(child1
, SW_HIDE
);
4137 SetActiveWindow(parent
);
4139 check_active_state(parent
, 0, parent
);
4141 bret
= SetForegroundWindow(popup
);
4142 ok(bret
, "SetForegroundWindow() failed\n");
4143 check_active_state(popup
, popup
, popup
);
4145 ShowWindow(parent
, SW_SHOW
);
4146 SetActiveWindow(popup
);
4147 ok(DestroyWindow(popup
), "DestroyWindow() failed\n");
4148 check_active_state(parent
, parent
, parent
);
4150 ok(DestroyWindow(parent
), "DestroyWindow() failed\n");
4152 ok(!IsWindow(parent
), "parent still exists\n");
4153 ok(!IsWindow(child1
), "child1 still exists\n");
4154 ok(!IsWindow(popup
), "popup still exists\n");
4157 static LRESULT WINAPI
StyleCheckProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4159 LPCREATESTRUCTA lpcs
;
4166 lpcs
= (LPCREATESTRUCTA
)lparam
;
4167 lpss
= lpcs
->lpCreateParams
;
4170 if ((lpcs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
4171 ((!(lpcs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
4172 (lpcs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
4173 ok(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
, "Window should have WS_EX_WINDOWEDGE style\n");
4175 ok(!(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
4177 ok((lpss
->styleOld
& ~WS_EX_WINDOWEDGE
) == (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
),
4178 "Ex style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
4179 lpss
->styleOld
, lpcs
->dwExStyle
);
4181 ok(lpss
->styleNew
== lpcs
->style
,
4182 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
4183 lpss
->styleNew
, lpcs
->style
);
4187 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
4190 static ATOM atomStyleCheckClass
;
4192 static void register_style_check_class(void)
4200 GetModuleHandleA(NULL
),
4202 LoadCursorA(0, (LPCSTR
)IDC_ARROW
),
4203 (HBRUSH
)(COLOR_BTNFACE
+1),
4208 atomStyleCheckClass
= RegisterClassA(&wc
);
4209 assert(atomStyleCheckClass
);
4212 static void check_window_style(DWORD dwStyleIn
, DWORD dwExStyleIn
, DWORD dwStyleOut
, DWORD dwExStyleOut
)
4214 DWORD dwActualStyle
;
4215 DWORD dwActualExStyle
;
4218 HWND hwndParent
= NULL
;
4220 ss
.styleNew
= dwStyleIn
;
4221 ss
.styleOld
= dwExStyleIn
;
4223 if (dwStyleIn
& WS_CHILD
)
4225 hwndParent
= CreateWindowExA(0, (LPCSTR
)MAKEINTATOM(atomStyleCheckClass
), NULL
,
4226 WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
4229 hwnd
= CreateWindowExA(dwExStyleIn
, (LPCSTR
)MAKEINTATOM(atomStyleCheckClass
), NULL
,
4230 dwStyleIn
, 0, 0, 0, 0, hwndParent
, NULL
, NULL
, &ss
);
4233 flush_events( TRUE
);
4235 dwActualStyle
= GetWindowLongA(hwnd
, GWL_STYLE
);
4236 dwActualExStyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
4237 ok(dwActualStyle
== dwStyleOut
, "expected style %#x, got %#x\n", dwStyleOut
, dwActualStyle
);
4238 ok(dwActualExStyle
== dwExStyleOut
, "expected ex_style %#x, got %#x\n", dwExStyleOut
, dwActualExStyle
);
4240 /* try setting the styles explicitly */
4241 SetWindowLongA( hwnd
, GWL_EXSTYLE
, dwExStyleIn
);
4242 dwActualStyle
= GetWindowLongA(hwnd
, GWL_STYLE
);
4243 dwActualExStyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
4244 /* WS_EX_WINDOWEDGE can't always be changed */
4245 if (dwExStyleIn
& WS_EX_DLGMODALFRAME
)
4246 dwExStyleOut
= dwExStyleIn
| WS_EX_WINDOWEDGE
;
4247 else if ((dwActualStyle
& (WS_DLGFRAME
| WS_THICKFRAME
)) && !(dwExStyleIn
& WS_EX_STATICEDGE
))
4248 dwExStyleOut
= dwExStyleIn
| WS_EX_WINDOWEDGE
;
4250 dwExStyleOut
= dwExStyleIn
& ~WS_EX_WINDOWEDGE
;
4251 ok(dwActualStyle
== dwStyleOut
, "expected style %#x, got %#x\n", dwStyleOut
, dwActualStyle
);
4252 ok(dwActualExStyle
== dwExStyleOut
, "expected ex_style %#x, got %#x\n", dwExStyleOut
, dwActualExStyle
);
4254 SetWindowLongA( hwnd
, GWL_STYLE
, dwStyleIn
);
4255 dwActualStyle
= GetWindowLongA(hwnd
, GWL_STYLE
);
4256 dwActualExStyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
4257 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
4258 if ((dwStyleIn
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
) dwStyleOut
= dwStyleIn
;
4259 else dwStyleOut
= dwStyleIn
| WS_CLIPSIBLINGS
;
4260 /* WS_EX_WINDOWEDGE can't always be changed */
4261 if (dwExStyleIn
& WS_EX_DLGMODALFRAME
)
4262 dwExStyleOut
= dwExStyleIn
| WS_EX_WINDOWEDGE
;
4263 else if ((dwActualStyle
& (WS_DLGFRAME
| WS_THICKFRAME
)) && !(dwExStyleIn
& WS_EX_STATICEDGE
))
4264 dwExStyleOut
= dwExStyleIn
| WS_EX_WINDOWEDGE
;
4266 dwExStyleOut
= dwExStyleIn
& ~WS_EX_WINDOWEDGE
;
4267 ok(dwActualStyle
== dwStyleOut
, "expected style %#x, got %#x\n", dwStyleOut
, dwActualStyle
);
4268 /* FIXME: Remove the condition below once Wine is fixed */
4269 todo_wine_if (dwActualExStyle
!= dwExStyleOut
)
4270 ok(dwActualExStyle
== dwExStyleOut
, "expected ex_style %#x, got %#x\n", dwExStyleOut
, dwActualExStyle
);
4272 DestroyWindow(hwnd
);
4273 if (hwndParent
) DestroyWindow(hwndParent
);
4276 /* tests what window styles the window manager automatically adds */
4277 static void test_window_styles(void)
4279 register_style_check_class();
4281 check_window_style(0, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
4282 check_window_style(WS_DLGFRAME
, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
4283 check_window_style(WS_THICKFRAME
, 0, WS_THICKFRAME
|WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
4284 check_window_style(WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_STATICEDGE
);
4285 check_window_style(WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_THICKFRAME
|WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_STATICEDGE
);
4286 check_window_style(WS_OVERLAPPEDWINDOW
, 0, WS_CLIPSIBLINGS
|WS_OVERLAPPEDWINDOW
, WS_EX_WINDOWEDGE
);
4287 check_window_style(WS_CHILD
, 0, WS_CHILD
, 0);
4288 check_window_style(WS_CHILD
|WS_DLGFRAME
, 0, WS_CHILD
|WS_DLGFRAME
, WS_EX_WINDOWEDGE
);
4289 check_window_style(WS_CHILD
|WS_THICKFRAME
, 0, WS_CHILD
|WS_THICKFRAME
, WS_EX_WINDOWEDGE
);
4290 check_window_style(WS_CHILD
|WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_DLGFRAME
, WS_EX_STATICEDGE
);
4291 check_window_style(WS_CHILD
|WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_THICKFRAME
, WS_EX_STATICEDGE
);
4292 check_window_style(WS_CHILD
|WS_CAPTION
, 0, WS_CHILD
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
4293 check_window_style(WS_CHILD
|WS_CAPTION
|WS_SYSMENU
, 0, WS_CHILD
|WS_CAPTION
|WS_SYSMENU
, WS_EX_WINDOWEDGE
);
4294 check_window_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
4295 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
, WS_CHILD
, WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
4296 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
|WS_EX_STATICEDGE
, WS_CHILD
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
4297 check_window_style(WS_CHILD
|WS_POPUP
, 0, WS_CHILD
|WS_POPUP
|WS_CLIPSIBLINGS
, 0);
4298 check_window_style(WS_CHILD
|WS_POPUP
|WS_DLGFRAME
, 0, WS_CHILD
|WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4299 check_window_style(WS_CHILD
|WS_POPUP
|WS_THICKFRAME
, 0, WS_CHILD
|WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4300 check_window_style(WS_CHILD
|WS_POPUP
|WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
);
4301 check_window_style(WS_CHILD
|WS_POPUP
|WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
);
4302 check_window_style(WS_CHILD
|WS_POPUP
, WS_EX_APPWINDOW
, WS_CHILD
|WS_POPUP
|WS_CLIPSIBLINGS
, WS_EX_APPWINDOW
);
4303 check_window_style(WS_CHILD
|WS_POPUP
, WS_EX_WINDOWEDGE
, WS_CHILD
|WS_POPUP
|WS_CLIPSIBLINGS
, 0);
4304 check_window_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
4305 check_window_style(0, WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_TOOLWINDOW
);
4306 check_window_style(WS_POPUP
, 0, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
4307 check_window_style(WS_POPUP
, WS_EX_WINDOWEDGE
, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
4308 check_window_style(WS_POPUP
|WS_DLGFRAME
, 0, WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4309 check_window_style(WS_POPUP
|WS_THICKFRAME
, 0, WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4310 check_window_style(WS_POPUP
|WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
);
4311 check_window_style(WS_POPUP
|WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
);
4312 check_window_style(WS_CAPTION
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
);
4313 check_window_style(0, WS_EX_APPWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_APPWINDOW
|WS_EX_WINDOWEDGE
);
4315 if (pGetLayeredWindowAttributes
)
4317 check_window_style(0, WS_EX_LAYERED
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_LAYERED
|WS_EX_WINDOWEDGE
);
4318 check_window_style(0, WS_EX_LAYERED
|WS_EX_TRANSPARENT
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_LAYERED
|WS_EX_TRANSPARENT
|WS_EX_WINDOWEDGE
);
4319 check_window_style(0, WS_EX_LAYERED
|WS_EX_TRANSPARENT
|WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
,
4320 WS_EX_LAYERED
|WS_EX_TRANSPARENT
|WS_EX_TOOLWINDOW
|WS_EX_WINDOWEDGE
);
4324 static HWND
root_dialog(HWND hwnd
)
4326 while ((GetWindowLongA(hwnd
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
) &&
4327 (GetWindowLongA(hwnd
, GWL_STYLE
) & (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
4329 HWND parent
= GetParent(hwnd
);
4331 /* simple detector for a window being a dialog */
4332 if (!DefDlgProcA(parent
, DM_GETDEFID
, 0, 0))
4337 if (!(GetWindowLongA(hwnd
, GWL_STYLE
) & DS_CONTROL
))
4344 static INT_PTR WINAPI
empty_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4349 static LRESULT expected_id
;
4351 static INT_PTR WINAPI
empty_dlg_proc3(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4353 if (msg
== WM_INITDIALOG
)
4355 HWND parent
= GetParent(hwnd
);
4358 id
= DefDlgProcA(parent
, DM_GETDEFID
, 0, 0);
4359 if (!id
|| root_dialog(hwnd
) == hwnd
)
4362 id
= DefDlgProcA(hwnd
, DM_GETDEFID
, 0, 0);
4364 ok(id
== MAKELONG(IDOK
,DC_HASDEFID
), "expected (IDOK,DC_HASDEFID), got %08lx\n", id
);
4366 ok(id
== expected_id
, "expected %08lx, got %08lx\n", expected_id
, id
);
4368 ret
= DefDlgProcA(hwnd
, DM_SETDEFID
, 0x3333, 0);
4369 ok(ret
, "DefDlgProc(DM_SETDEFID) failed\n");
4370 id
= DefDlgProcA(hwnd
, DM_GETDEFID
, 0, 0);
4371 ok(id
== MAKELONG(0x3333,DC_HASDEFID
), "expected (0x3333,DC_HASDEFID), got %08lx\n", id
);
4375 id
= DefDlgProcA(parent
, DM_GETDEFID
, 0, 0);
4376 ok(id
== MAKELONG(0x3333,DC_HASDEFID
), "expected (0x3333,DC_HASDEFID), got %08lx\n", id
);
4378 expected_id
= MAKELONG(0x3333,DC_HASDEFID
);
4389 HWND parent
, grand_parent
;
4390 DLGTEMPLATE
*dlg_data
;
4393 static INT_PTR WINAPI
empty_dlg_proc2(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4395 if (msg
== WM_INITDIALOG
)
4397 DWORD style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4398 struct dialog_param
*param
= (struct dialog_param
*)lparam
;
4399 BOOL parent_is_child
;
4403 id
= DefDlgProcA(hwnd
, DM_GETDEFID
, 0, 0);
4404 ok(id
== MAKELONG(IDOK
,DC_HASDEFID
), "expected (IDOK,DC_HASDEFID), got %08lx\n", id
);
4405 ret
= DefDlgProcA(hwnd
, DM_SETDEFID
, 0x2222, 0);
4406 ok(ret
, "DefDlgProc(DM_SETDEFID) failed\n");
4407 id
= DefDlgProcA(hwnd
, DM_GETDEFID
, 0, 0);
4408 ok(id
== MAKELONG(0x2222,DC_HASDEFID
), "expected (0x2222,DC_HASDEFID), got %08lx\n", id
);
4410 expected_id
= MAKELONG(0x2222,DC_HASDEFID
);
4412 parent_is_child
= (GetWindowLongA(param
->parent
, GWL_STYLE
) & (WS_POPUP
| WS_CHILD
)) == WS_CHILD
;
4414 ok(IsWindowEnabled(hwnd
), "wrong state for %p\n", hwnd
);
4415 if (parent_is_child
)
4417 ok(IsWindowEnabled(param
->parent
), "wrong state for %08x\n", style
);
4418 disabled_hwnd
= param
->grand_parent
;
4422 ok(!IsWindowEnabled(param
->parent
), "wrong state for %08x\n", style
);
4423 disabled_hwnd
= param
->parent
;
4426 if (param
->grand_parent
)
4428 if (parent_is_child
)
4429 ok(!IsWindowEnabled(param
->grand_parent
), "wrong state for %08x\n", style
);
4431 ok(IsWindowEnabled(param
->grand_parent
), "wrong state for %08x\n", style
);
4434 DialogBoxIndirectParamA(GetModuleHandleA(NULL
), param
->dlg_data
, disabled_hwnd
, empty_dlg_proc3
, 0);
4435 ok(IsWindowEnabled(disabled_hwnd
), "wrong state for %08x\n", style
);
4437 ok(IsWindowEnabled(hwnd
), "wrong state for %p\n", hwnd
);
4438 ok(IsWindowEnabled(param
->parent
), "wrong state for %p\n", param
->parent
);
4439 if (param
->grand_parent
)
4440 ok(IsWindowEnabled(param
->grand_parent
), "wrong state for %p (%08x)\n", param
->grand_parent
, style
);
4442 DialogBoxIndirectParamA(GetModuleHandleA(NULL
), param
->dlg_data
, hwnd
, empty_dlg_proc3
, 0);
4443 ok(IsWindowEnabled(hwnd
), "wrong state for %p\n", hwnd
);
4444 ok(IsWindowEnabled(param
->parent
), "wrong state for %p\n", param
->parent
);
4445 if (param
->grand_parent
)
4446 ok(IsWindowEnabled(param
->grand_parent
), "wrong state for %p (%08x)\n", param
->grand_parent
, style
);
4448 param
->dlg_data
->style
|= WS_CHILD
;
4449 DialogBoxIndirectParamA(GetModuleHandleA(NULL
), param
->dlg_data
, hwnd
, empty_dlg_proc3
, 0);
4450 ok(IsWindowEnabled(hwnd
), "wrong state for %p (%08x)\n", hwnd
, style
);
4452 param
->dlg_data
->style
|= DS_CONTROL
;
4453 DialogBoxIndirectParamA(GetModuleHandleA(NULL
), param
->dlg_data
, hwnd
, empty_dlg_proc3
, 0);
4454 ok(IsWindowEnabled(hwnd
), "wrong state for %p (%08x)\n", hwnd
, style
);
4456 param
->dlg_data
->dwExtendedStyle
|= WS_EX_CONTROLPARENT
;
4457 SetWindowLongA(hwnd
, GWL_EXSTYLE
, GetWindowLongA(hwnd
, GWL_EXSTYLE
) | WS_EX_CONTROLPARENT
);
4458 SetWindowLongA(hwnd
, GWL_STYLE
, style
& ~DS_CONTROL
);
4459 param
->dlg_data
->style
&= ~DS_CONTROL
;
4460 DialogBoxIndirectParamA(GetModuleHandleA(NULL
), param
->dlg_data
, hwnd
, empty_dlg_proc3
, 0);
4461 ok(IsWindowEnabled(hwnd
), "wrong state for %p (%08x)\n", hwnd
, style
);
4463 SetWindowLongA(hwnd
, GWL_STYLE
, style
| DS_CONTROL
);
4464 DialogBoxIndirectParamA(GetModuleHandleA(NULL
), param
->dlg_data
, hwnd
, empty_dlg_proc3
, 0);
4465 ok(IsWindowEnabled(hwnd
), "wrong state for %p (%08x)\n", hwnd
, style
);
4467 param
->dlg_data
->style
|= DS_CONTROL
;
4468 DialogBoxIndirectParamA(GetModuleHandleA(NULL
), param
->dlg_data
, hwnd
, empty_dlg_proc3
, 0);
4469 ok(IsWindowEnabled(hwnd
), "wrong state for %p (%08x)\n", hwnd
, style
);
4476 static void check_dialog_style(DWORD style_in
, DWORD ex_style_in
, DWORD style_out
, DWORD ex_style_out
)
4486 DWORD style
, ex_style
;
4487 HWND hwnd
, grand_parent
= 0, parent
= 0;
4488 struct dialog_param param
;
4491 if (style_in
& WS_CHILD
)
4493 grand_parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
4494 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
4495 ok(grand_parent
!= 0, "grand_parent creation failed\n");
4498 parent
= CreateWindowExA(0, "static", NULL
, style_in
,
4499 0, 0, 0, 0, grand_parent
, NULL
, NULL
, NULL
);
4500 ok(parent
!= 0, "parent creation failed, style %#x\n", style_in
);
4502 dlg_data
.dt
.style
= style_in
;
4503 dlg_data
.dt
.dwExtendedStyle
= ex_style_in
;
4504 dlg_data
.dt
.cdit
= 0;
4507 dlg_data
.dt
.cx
= 100;
4508 dlg_data
.dt
.cy
= 100;
4509 dlg_data
.menu_name
= 0;
4510 dlg_data
.class_id
= 0;
4511 dlg_data
.class_atom
= 0;
4512 dlg_data
.caption
[0] = 0;
4514 hwnd
= CreateDialogIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, parent
, empty_dlg_proc
, 0);
4515 ok(hwnd
!= 0, "dialog creation failed, style %#x, exstyle %#x\n", style_in
, ex_style_in
);
4517 id
= DefDlgProcA(hwnd
, DM_GETDEFID
, 0, 0);
4518 ok(id
== MAKELONG(IDOK
,DC_HASDEFID
), "expected (IDOK,DC_HASDEFID), got %08lx\n", id
);
4519 ret
= DefDlgProcA(hwnd
, DM_SETDEFID
, 0x1111, 0);
4520 ok(ret
, "DefDlgProc(DM_SETDEFID) failed\n");
4521 id
= DefDlgProcA(hwnd
, DM_GETDEFID
, 0, 0);
4522 ok(id
== MAKELONG(0x1111,DC_HASDEFID
), "expected (0x1111,DC_HASDEFID), got %08lx\n", id
);
4524 flush_events( TRUE
);
4526 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4527 ex_style
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
4528 ok(style
== (style_out
| DS_3DLOOK
), "got %#x\n", style
);
4529 ok(ex_style
== ex_style_out
, "expected ex_style %#x, got %#x\n", ex_style_out
, ex_style
);
4531 ok(IsWindowEnabled(parent
), "wrong parent state (dialog style %#x)\n", style_in
);
4533 /* try setting the styles explicitly */
4534 SetWindowLongA(hwnd
, GWL_EXSTYLE
, ex_style_in
);
4535 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4536 ex_style
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
4537 ok(style
== (style_out
| DS_3DLOOK
), "got %#x\n", style
);
4538 /* WS_EX_WINDOWEDGE can't always be changed */
4539 if (ex_style_in
& WS_EX_DLGMODALFRAME
)
4540 ex_style_out
= ex_style_in
| WS_EX_WINDOWEDGE
;
4541 else if ((style
& (WS_DLGFRAME
| WS_THICKFRAME
)) && !(ex_style_in
& WS_EX_STATICEDGE
))
4542 ex_style_out
= ex_style_in
| WS_EX_WINDOWEDGE
;
4544 ex_style_out
= ex_style_in
& ~WS_EX_WINDOWEDGE
;
4545 ok(ex_style
== ex_style_out
, "expected ex_style %#x, got %#x\n", ex_style_out
, ex_style
);
4547 SetWindowLongA(hwnd
, GWL_STYLE
, style_in
);
4548 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4549 ex_style
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
4550 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
4551 if ((style_in
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
) style_out
= style_in
;
4552 else style_out
= style_in
| WS_CLIPSIBLINGS
;
4553 ok(style
== style_out
, "expected style %#x, got %#x\n", style_out
, style
);
4554 /* WS_EX_WINDOWEDGE can't always be changed */
4555 if (ex_style_in
& WS_EX_DLGMODALFRAME
)
4556 ex_style_out
= ex_style_in
| WS_EX_WINDOWEDGE
;
4557 else if ((style
& (WS_DLGFRAME
| WS_THICKFRAME
)) && !(ex_style_in
& WS_EX_STATICEDGE
))
4558 ex_style_out
= ex_style_in
| WS_EX_WINDOWEDGE
;
4560 ex_style_out
= ex_style_in
& ~WS_EX_WINDOWEDGE
;
4561 /* FIXME: Remove the condition below once Wine is fixed */
4562 todo_wine_if (ex_style
!= ex_style_out
)
4563 ok(ex_style
== ex_style_out
, "expected ex_style %#x, got %#x\n", ex_style_out
, ex_style
);
4565 DestroyWindow(hwnd
);
4567 param
.parent
= parent
;
4568 param
.grand_parent
= grand_parent
;
4569 param
.dlg_data
= &dlg_data
.dt
;
4570 DialogBoxIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, parent
, empty_dlg_proc2
, (LPARAM
)¶m
);
4572 ok(IsWindowEnabled(parent
), "wrong parent state (dialog style %#x)\n", style_in
);
4574 ok(IsWindowEnabled(grand_parent
), "wrong grand parent state (dialog style %#x)\n", style_in
);
4576 DestroyWindow(parent
);
4577 DestroyWindow(grand_parent
);
4580 static void test_dialog_styles(void)
4582 check_dialog_style(0, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4583 check_dialog_style(WS_DLGFRAME
, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4584 check_dialog_style(WS_THICKFRAME
, 0, WS_THICKFRAME
|WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4585 check_dialog_style(WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_STATICEDGE
|WS_EX_CONTROLPARENT
);
4586 check_dialog_style(WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_THICKFRAME
|WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_STATICEDGE
|WS_EX_CONTROLPARENT
);
4587 check_dialog_style(DS_CONTROL
, 0, WS_CLIPSIBLINGS
|WS_CAPTION
|DS_CONTROL
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4588 check_dialog_style(WS_CAPTION
, 0, WS_CAPTION
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4589 check_dialog_style(WS_BORDER
, 0, WS_CAPTION
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4590 check_dialog_style(WS_DLGFRAME
, 0, WS_CAPTION
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4591 check_dialog_style(WS_BORDER
|DS_CONTROL
, 0, WS_CAPTION
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4592 check_dialog_style(WS_DLGFRAME
|DS_CONTROL
, 0, WS_CAPTION
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4593 check_dialog_style(WS_CAPTION
|WS_SYSMENU
, 0, WS_CAPTION
|WS_SYSMENU
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4594 check_dialog_style(WS_SYSMENU
, 0, WS_CAPTION
|WS_SYSMENU
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4595 check_dialog_style(WS_CAPTION
|DS_CONTROL
, 0, WS_CAPTION
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4596 check_dialog_style(WS_SYSMENU
|DS_CONTROL
, 0, WS_CAPTION
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4597 check_dialog_style(WS_CAPTION
|WS_SYSMENU
|DS_CONTROL
, 0, WS_CAPTION
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4598 check_dialog_style(WS_OVERLAPPEDWINDOW
, 0, WS_CLIPSIBLINGS
|WS_OVERLAPPEDWINDOW
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4599 check_dialog_style(WS_CHILD
, 0, WS_CHILD
, 0);
4600 check_dialog_style(WS_CHILD
|WS_DLGFRAME
, 0, WS_CHILD
|WS_DLGFRAME
, WS_EX_WINDOWEDGE
);
4601 check_dialog_style(WS_CHILD
|WS_THICKFRAME
, 0, WS_CHILD
|WS_THICKFRAME
, WS_EX_WINDOWEDGE
);
4602 check_dialog_style(WS_CHILD
|WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_DLGFRAME
, WS_EX_STATICEDGE
);
4603 check_dialog_style(WS_CHILD
|WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_THICKFRAME
, WS_EX_STATICEDGE
);
4604 check_dialog_style(WS_CHILD
|DS_CONTROL
, 0, WS_CHILD
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4605 check_dialog_style(WS_CHILD
|WS_CAPTION
, 0, WS_CHILD
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
4606 check_dialog_style(WS_CHILD
|WS_BORDER
, 0, WS_CHILD
|WS_BORDER
, 0);
4607 check_dialog_style(WS_CHILD
|WS_DLGFRAME
, 0, WS_CHILD
|WS_DLGFRAME
, WS_EX_WINDOWEDGE
);
4608 check_dialog_style(WS_CHILD
|WS_BORDER
|DS_CONTROL
, 0, WS_CHILD
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4609 check_dialog_style(WS_CHILD
|WS_DLGFRAME
|DS_CONTROL
, 0, WS_CHILD
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4610 check_dialog_style(WS_CHILD
|WS_CAPTION
|WS_SYSMENU
, 0, WS_CHILD
|WS_CAPTION
|WS_SYSMENU
, WS_EX_WINDOWEDGE
);
4611 check_dialog_style(WS_CHILD
|WS_SYSMENU
, 0, WS_CHILD
|WS_SYSMENU
, 0);
4612 check_dialog_style(WS_CHILD
|WS_CAPTION
|DS_CONTROL
, 0, WS_CHILD
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4613 check_dialog_style(WS_CHILD
|WS_SYSMENU
|DS_CONTROL
, 0, WS_CHILD
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4614 check_dialog_style(WS_CHILD
|WS_CAPTION
|WS_SYSMENU
|DS_CONTROL
, 0, WS_CHILD
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4615 check_dialog_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
4616 check_dialog_style(WS_CHILD
, WS_EX_DLGMODALFRAME
, WS_CHILD
, WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
4617 check_dialog_style(WS_CHILD
, WS_EX_DLGMODALFRAME
|WS_EX_STATICEDGE
, WS_CHILD
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
4618 check_dialog_style(WS_CHILD
|WS_POPUP
, 0, WS_CHILD
|WS_POPUP
|WS_CLIPSIBLINGS
, 0);
4619 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_DLGFRAME
, 0, WS_CHILD
|WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4620 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_THICKFRAME
, 0, WS_CHILD
|WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4621 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
);
4622 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
);
4623 check_dialog_style(WS_CHILD
|WS_POPUP
|DS_CONTROL
, 0, WS_CHILD
|WS_POPUP
|WS_CLIPSIBLINGS
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4624 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_CAPTION
, 0, WS_CHILD
|WS_POPUP
|WS_CAPTION
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4625 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_BORDER
, 0, WS_CHILD
|WS_POPUP
|WS_BORDER
|WS_CLIPSIBLINGS
, 0);
4626 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_DLGFRAME
, 0, WS_CHILD
|WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4627 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_BORDER
|DS_CONTROL
, 0, WS_CHILD
|WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4628 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_DLGFRAME
|DS_CONTROL
, 0, WS_CHILD
|WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4629 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
);
4630 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_SYSMENU
, 0, WS_CHILD
|WS_POPUP
|WS_SYSMENU
|WS_CLIPSIBLINGS
, 0);
4631 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_CAPTION
|DS_CONTROL
, 0, WS_CHILD
|WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4632 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_SYSMENU
|DS_CONTROL
, 0, WS_CHILD
|WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4633 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
);
4634 check_dialog_style(WS_CHILD
|WS_POPUP
, WS_EX_APPWINDOW
, WS_CHILD
|WS_POPUP
|WS_CLIPSIBLINGS
, WS_EX_APPWINDOW
);
4635 check_dialog_style(WS_CHILD
|WS_POPUP
, WS_EX_WINDOWEDGE
, WS_CHILD
|WS_POPUP
|WS_CLIPSIBLINGS
, 0);
4636 check_dialog_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
4637 check_dialog_style(0, WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_TOOLWINDOW
|WS_EX_CONTROLPARENT
);
4638 check_dialog_style(WS_POPUP
, 0, WS_POPUP
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4639 check_dialog_style(WS_POPUP
, WS_EX_WINDOWEDGE
, WS_POPUP
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4640 check_dialog_style(WS_POPUP
|WS_DLGFRAME
, 0, WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4641 check_dialog_style(WS_POPUP
|WS_THICKFRAME
, 0, WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4642 check_dialog_style(WS_POPUP
|WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
|WS_EX_CONTROLPARENT
);
4643 check_dialog_style(WS_POPUP
|WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
|WS_EX_CONTROLPARENT
);
4644 check_dialog_style(WS_POPUP
|DS_CONTROL
, 0, WS_POPUP
|WS_CLIPSIBLINGS
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4645 check_dialog_style(WS_POPUP
|WS_CAPTION
, 0, WS_POPUP
|WS_CAPTION
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4646 check_dialog_style(WS_POPUP
|WS_BORDER
, 0, WS_POPUP
|WS_BORDER
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4647 check_dialog_style(WS_POPUP
|WS_DLGFRAME
, 0, WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4648 check_dialog_style(WS_POPUP
|WS_BORDER
|DS_CONTROL
, 0, WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4649 check_dialog_style(WS_POPUP
|WS_DLGFRAME
|DS_CONTROL
, 0, WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4650 check_dialog_style(WS_POPUP
|WS_CAPTION
|WS_SYSMENU
, 0, WS_POPUP
|WS_CAPTION
|WS_SYSMENU
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4651 check_dialog_style(WS_POPUP
|WS_SYSMENU
, 0, WS_POPUP
|WS_SYSMENU
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4652 check_dialog_style(WS_POPUP
|WS_CAPTION
|DS_CONTROL
, 0, WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4653 check_dialog_style(WS_POPUP
|WS_SYSMENU
|DS_CONTROL
, 0, WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4654 check_dialog_style(WS_POPUP
|WS_CAPTION
|WS_SYSMENU
|DS_CONTROL
, 0, WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4655 check_dialog_style(WS_CAPTION
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4656 check_dialog_style(0, WS_EX_APPWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_APPWINDOW
|WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4658 if (pGetLayeredWindowAttributes
)
4660 check_dialog_style(0, WS_EX_LAYERED
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_LAYERED
|WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4661 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
);
4662 check_dialog_style(0, WS_EX_LAYERED
|WS_EX_TRANSPARENT
|WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
,
4663 WS_EX_LAYERED
|WS_EX_TRANSPARENT
|WS_EX_TOOLWINDOW
|WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4667 struct dlg_parent_param
4677 static INT_PTR WINAPI
parent_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4679 if (msg
== WM_INITDIALOG
) {
4680 struct dlg_parent_param
*param
= (void*)lparam
;
4681 check_parents(hwnd
, param
->ga_parent
, param
->gwl_parent
, param
->get_parent
, param
->owner
,
4682 param
->root
? param
->root
: hwnd
, param
->ga_root_owner
? param
->ga_root_owner
: hwnd
);
4684 ok(!IsWindowEnabled(param
->gwl_parent
), "parent is not disabled\n");
4686 ok(IsWindowEnabled(param
->gwl_parent
), "parent is not enabled\n");
4692 static INT_PTR WINAPI
reparent_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4694 if (msg
== WM_INITDIALOG
) {
4695 ok(!IsWindowEnabled(GetParent(hwnd
)), "parent is not disabled\n");
4696 SetParent(hwnd
, (HWND
)lparam
);
4702 static INT_PTR WINAPI
reparent_owned_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4704 if (msg
== WM_INITDIALOG
) {
4705 HWND new_parent
= (HWND
)lparam
;
4706 HWND owner
= GetWindow(hwnd
, GW_OWNER
);
4707 ok(!IsWindowEnabled(owner
), "owner is not disabled\n");
4708 SetWindowLongA(hwnd
, GWL_STYLE
, GetWindowLongA(hwnd
, GWL_STYLE
) | WS_CHILD
);
4709 SetParent(hwnd
, new_parent
);
4710 ok(GetParent(hwnd
) == new_parent
, "GetParent(hwnd) = %p, expected %p\n", GetParent(hwnd
), new_parent
);
4711 PostMessageA(hwnd
, WM_QUIT
, 0, 0);
4717 static LRESULT WINAPI
reparent_dialog_owner_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4719 if (msg
== WM_ENTERIDLE
) {
4720 HWND dialog
= (HWND
)lparam
;
4721 HWND owner
= GetParent(dialog
);
4722 /* EndDialog will enable owner */
4723 EnableWindow(owner
, FALSE
);
4724 EndDialog(dialog
, 2);
4725 ok(IsWindowEnabled(owner
), "owner is not enabled\n");
4726 /* ...but it won't be enabled on dialog exit */
4727 EnableWindow(owner
, FALSE
);
4729 return DefWindowProcA( hwnd
, msg
, wparam
, lparam
);
4732 static LRESULT WINAPI
post_quit_dialog_owner_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4734 if (msg
== WM_ENTERIDLE
) {
4735 HWND dialog
= (HWND
)lparam
;
4736 PostMessageA(dialog
, WM_QUIT
, 0, 0);
4738 return DefWindowProcA( hwnd
, msg
, wparam
, lparam
);
4741 static LRESULT WINAPI
destroy_dialog_owner_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4743 if (msg
== WM_ENTERIDLE
) {
4744 HWND dialog
= (HWND
)lparam
;
4745 DestroyWindow(dialog
);
4747 return DefWindowProcA( hwnd
, msg
, wparam
, lparam
);
4750 static void test_dialog_parent(void)
4752 HWND dialog
, parent
, child
, child2
, other
, desktop
= GetDesktopWindow();
4753 struct dlg_parent_param param
;
4764 dlg_data
.dt
.dwExtendedStyle
= 0;
4765 dlg_data
.dt
.cdit
= 0;
4768 dlg_data
.dt
.cx
= 100;
4769 dlg_data
.dt
.cy
= 100;
4770 dlg_data
.menu_name
= 0;
4771 dlg_data
.class_id
= 0;
4772 dlg_data
.class_atom
= 0;
4773 dlg_data
.caption
[0] = 0;
4775 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
4776 /* Create a child without WS_CHILD flag. It's a valid owner window. */
4777 child
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
4778 SetParent(child
, parent
);
4779 /* Regular child. If passed as an owner, its parent will be true owner window. */
4780 child2
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, child
, NULL
, NULL
, NULL
);
4782 trace("parent %p child %p child2 %p desktop %p\n", parent
, child
, child2
, desktop
);
4784 /* When dialog is created with WS_CHILD style, its parent depends on function used to create it. */
4785 dlg_data
.dt
.style
= WS_CHILD
;
4787 /* CreateDialogIndirectParam uses passed parent as dialog parent. */
4788 dialog
= CreateDialogIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, child2
, empty_dlg_proc
, 0);
4789 ok(dialog
!= 0, "dialog creation failed\n");
4790 check_parents(dialog
, child2
, child2
, child2
, NULL
, parent
, child
);
4792 ok(IsWindowEnabled(child2
), "child2 is disabled\n");
4793 EnableWindow(child2
, FALSE
);
4794 EndDialog(dialog
, 0);
4795 ok(IsWindowEnabled(child2
), "child2 is not enabled\n");
4796 DestroyWindow(dialog
);
4798 /* DialogBoxIndirectParam uses the first parent of passed owner that's not a child window as dialog
4799 * parent (like in case of dialog with owner). */
4800 param
.ga_parent
= param
.gwl_parent
= param
.get_parent
= child
;
4802 param
.root
= parent
;
4803 param
.ga_root_owner
= child
;
4804 ret
= DialogBoxIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, child2
, parent_dlg_proc
, (LPARAM
)¶m
);
4805 ok(ret
== 2, "DialogBoxIndirectParam returned %ld\n", ret
);
4807 /* Dialogs without WS_CHILD behave as expected, they use passed owner just like CreateWindow does. */
4808 dlg_data
.dt
.style
= WS_OVERLAPPEDWINDOW
;
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
, NULL
, child
, dialog
, dialog
);
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
= child
;
4822 param
.get_parent
= NULL
;
4823 param
.owner
= child
;
4824 param
.root
= param
.ga_root_owner
= NULL
;
4825 ret
= DialogBoxIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, child2
, parent_dlg_proc
, (LPARAM
)¶m
);
4826 ok(ret
== 2, "DialogBoxIndirectParam returned %ld\n", ret
);
4828 other
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
4829 SetWindowLongPtrA(child
, GWLP_WNDPROC
, (ULONG_PTR
)reparent_dialog_owner_proc
);
4831 /* When dialog is created with WS_CHILD|WS_POPUP style, we have an owner. */
4832 dlg_data
.dt
.style
= WS_CHILD
|WS_POPUP
;
4834 dialog
= CreateDialogIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, child2
, empty_dlg_proc
, 0);
4835 ok(dialog
!= 0, "dialog creation failed\n");
4836 check_parents(dialog
, desktop
, child
, child
, child
, dialog
, child
);
4838 ok(IsWindowEnabled(child
), "child is disabled\n");
4839 EnableWindow(child
, FALSE
);
4840 EndDialog(dialog
, 0);
4841 ok(IsWindowEnabled(child
), "child is not enabled\n");
4842 DestroyWindow(dialog
);
4844 param
.ga_parent
= desktop
;
4845 param
.gwl_parent
= param
.get_parent
= child
;
4846 param
.owner
= child
;
4848 param
.ga_root_owner
= child
;
4849 ret
= DialogBoxIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, child2
, parent_dlg_proc
, (LPARAM
)¶m
);
4850 ok(ret
== 2, "DialogBoxIndirectParam returned %ld\n", ret
);
4852 /* If we change parent in WM_INITDIALOG for WS_CHILD dialog WM_ENTERIDLE is still sent to the original
4853 * parent. EndDialog will enable the new parent. */
4854 EnableWindow(child
, TRUE
);
4855 EnableWindow(other
, FALSE
);
4856 dlg_data
.dt
.style
= WS_CHILD
;
4857 ret
= DialogBoxIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, child2
, reparent_dlg_proc
, (LPARAM
)other
);
4858 ok(ret
== 2, "DialogBoxIndirectParam returned %ld\n", ret
);
4859 ok(!IsWindowEnabled(other
), "other is not disabled\n");
4860 ok(!IsWindowEnabled(child
), "child is not disabled\n");
4861 ok(IsWindowEnabled(child2
), "child2 is not enabled\n");
4862 EnableWindow(child
, TRUE
);
4864 /* If we change parent and style in WM_INITDIALOG for dialog with an owner to make it true child
4865 * (thus GetParent() will return the new parent instead of an owner), WM_ENTERIDLE is still sent
4866 * to the original parent. EndDialog will enable the new parent. */
4867 EnableWindow(other
, FALSE
);
4868 dlg_data
.dt
.style
= WS_OVERLAPPED
;
4869 ret
= DialogBoxIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, child2
, reparent_owned_dlg_proc
, (LPARAM
)other
);
4870 ok(ret
== 1, "DialogBoxIndirectParam returned %ld\n", ret
);
4871 ok(!IsWindowEnabled(other
), "other is not disabled\n");
4872 ok(!IsWindowEnabled(child
), "child is not disabled\n");
4873 ok(IsWindowEnabled(child2
), "child2 is not enabled\n");
4874 EnableWindow(child
, TRUE
);
4875 EnableWindow(other
, TRUE
);
4877 /* Quit dialog message loop by sending WM_QUIT message. Dialog owner is not enabled. */
4878 SetWindowLongPtrA(child
, GWLP_WNDPROC
, (ULONG_PTR
)post_quit_dialog_owner_proc
);
4879 ret
= DialogBoxIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, other
, empty_dlg_proc
, 0);
4880 ok(ret
== 1, "DialogBoxIndirectParam returned %ld\n", ret
);
4881 ok(!IsWindowEnabled(other
), "other is enabled\n");
4882 EnableWindow(other
, TRUE
);
4884 /* Quit dialog message loop by destroying the window. Dialog owner is not enabled. */
4885 SetWindowLongPtrA(child
, GWLP_WNDPROC
, (ULONG_PTR
)destroy_dialog_owner_proc
);
4886 ret
= DialogBoxIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, other
, empty_dlg_proc
, 0);
4887 ok(ret
== 1, "DialogBoxIndirectParam returned %ld\n", ret
);
4888 ok(!IsWindowEnabled(other
), "other is enabled\n");
4889 EnableWindow(other
, TRUE
);
4891 DestroyWindow(parent
);
4894 static void test_scrollwindow( HWND hwnd
)
4900 ShowWindow( hwnd
, SW_SHOW
);
4901 UpdateWindow( hwnd
);
4902 flush_events( TRUE
);
4903 GetClientRect( hwnd
, &rc
);
4905 /* test ScrollWindow(Ex) with no clip rectangle */
4906 /* paint the lower half of the window black */
4908 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
4909 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
4910 /* paint the upper half of the window white */
4911 rc2
.bottom
= rc2
.top
;
4913 FillRect( hdc
, &rc2
, GetStockObject(WHITE_BRUSH
));
4914 /* scroll lower half up */
4916 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
4917 ScrollWindowEx( hwnd
, 0, - rc2
.top
, &rc2
, NULL
, NULL
, NULL
, SW_ERASE
);
4918 flush_events(FALSE
);
4919 /* expected: black should have scrolled to the upper half */
4920 colr
= GetPixel( hdc
, (rc2
.left
+rc2
.right
)/ 2, rc2
.bottom
/ 4 );
4921 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
4922 /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
4923 /* paint the lower half of the window black */
4925 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
4926 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
4927 /* paint the upper half of the window white */
4928 rc2
.bottom
= rc2
.top
;
4930 FillRect( hdc
, &rc2
, GetStockObject(WHITE_BRUSH
));
4931 /* scroll lower half up */
4933 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
4935 rc3
.left
= rc3
.right
/ 4;
4936 rc3
.right
-= rc3
.right
/ 4;
4937 ScrollWindowEx( hwnd
, 0, - rc2
.top
, &rc2
, &rc3
, NULL
, NULL
, SW_ERASE
);
4938 flush_events(FALSE
);
4939 /* expected: black should have scrolled to the upper half */
4940 colr
= GetPixel( hdc
, (rc2
.left
+rc2
.right
)/ 2, rc2
.bottom
/ 4 );
4941 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
4944 ReleaseDC( hwnd
, hdc
);
4947 static void test_scrollvalidate( HWND parent
)
4950 HRGN hrgn
=CreateRectRgn(0,0,0,0);
4951 HRGN exprgn
, tmprgn
, clipping
;
4952 RECT rc
, rcu
, cliprc
;
4953 /* create two overlapping child windows. The visual region
4954 * of hwnd1 is clipped by the overlapping part of
4955 * hwnd2 because of the WS_CLIPSIBLING style */
4958 clipping
= CreateRectRgn(0,0,0,0);
4959 tmprgn
= CreateRectRgn(0,0,0,0);
4960 exprgn
= CreateRectRgn(0,0,0,0);
4961 hwnd2
= CreateWindowExA(0, "static", NULL
,
4962 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
4963 75, 30, 100, 100, parent
, 0, 0, NULL
);
4964 hwnd1
= CreateWindowExA(0, "static", NULL
,
4965 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
4966 25, 50, 100, 100, parent
, 0, 0, NULL
);
4967 ShowWindow( parent
, SW_SHOW
);
4968 UpdateWindow( parent
);
4969 GetClientRect( hwnd1
, &rc
);
4971 SetRectRgn( clipping
, 10, 10, 90, 90);
4972 hdc
= GetDC( hwnd1
);
4973 /* for a visual touch */
4974 TextOutA( hdc
, 0,10, "0123456789", 10);
4975 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
4976 if (winetest_debug
> 0) dump_region(hrgn
);
4977 /* create a region with what is expected */
4978 SetRectRgn( exprgn
, 39,0,49,74);
4979 SetRectRgn( tmprgn
, 88,79,98,93);
4980 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
4981 SetRectRgn( tmprgn
, 0,93,98,98);
4982 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
4983 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
4984 trace("update rect is %s\n", wine_dbgstr_rect(&rcu
));
4985 /* now with clipping region */
4986 SelectClipRgn( hdc
, clipping
);
4987 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
4988 if (winetest_debug
> 0) dump_region(hrgn
);
4989 /* create a region with what is expected */
4990 SetRectRgn( exprgn
, 39,10,49,74);
4991 SetRectRgn( tmprgn
, 80,79,90,85);
4992 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
4993 SetRectRgn( tmprgn
, 10,85,90,90);
4994 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
4995 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
4996 trace("update rect is %s\n", wine_dbgstr_rect(&rcu
));
4997 ReleaseDC( hwnd1
, hdc
);
4999 /* test scrolling a rect by more than its size */
5000 DestroyWindow( hwnd2
);
5001 ValidateRect( hwnd1
, NULL
);
5002 SetRect( &rc
, 40,40, 50,50);
5003 InvalidateRect( hwnd1
, &rc
, 1);
5004 ScrollWindowEx( hwnd1
, -20, 0, &rc
, NULL
, hrgn
, &rcu
,
5005 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
5006 if (winetest_debug
> 0) dump_region(hrgn
);
5007 SetRectRgn( exprgn
, 20, 40, 30, 50);
5008 SetRectRgn( tmprgn
, 40, 40, 50, 50);
5009 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
5010 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
5011 ok( rcu
.left
== 20 && rcu
.top
== 40 && rcu
.right
== 50 && rcu
.bottom
== 50,
5012 "unexpected update rect: %s\n", wine_dbgstr_rect(&rcu
));
5014 /* test scrolling a window with an update region */
5015 ValidateRect( hwnd1
, NULL
);
5016 SetRect( &rc
, 40,40, 50,50);
5017 InvalidateRect( hwnd1
, &rc
, 1);
5018 GetClientRect( hwnd1
, &rc
);
5020 ScrollWindowEx( hwnd1
, -10, 0, &rc
, &cliprc
, hrgn
, &rcu
,
5021 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
5022 if (winetest_debug
> 0) dump_region(hrgn
);
5023 SetRectRgn( exprgn
, 88,0,98,98);
5024 SetRectRgn( tmprgn
, 30, 40, 50, 50);
5025 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
5026 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
5028 /* clear an update region */
5029 UpdateWindow( hwnd1
);
5031 SetRect( &rc
, 0,40, 100,60);
5032 SetRect( &cliprc
, 0,0, 100,100);
5033 ScrollWindowEx( hwnd1
, 0, -25, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
5034 if (winetest_debug
> 0) dump_region( hrgn
);
5035 SetRectRgn( exprgn
, 0, 40, 98, 60 );
5036 ok( EqualRgn( exprgn
, hrgn
), "wrong update region in excessive scroll\n");
5038 /* now test ScrollWindowEx with a combination of
5039 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
5040 /* make hwnd2 the child of hwnd1 */
5041 hwnd2
= CreateWindowExA(0, "static", NULL
,
5042 WS_CHILD
| WS_VISIBLE
| WS_BORDER
,
5043 50, 50, 100, 100, hwnd1
, 0, 0, NULL
);
5044 SetWindowLongA( hwnd1
, GWL_STYLE
, GetWindowLongA( hwnd1
, GWL_STYLE
) & ~WS_CLIPSIBLINGS
);
5045 GetClientRect( hwnd1
, &rc
);
5048 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
5049 SetWindowLongA( hwnd1
, GWL_STYLE
, GetWindowLongA( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
5050 ValidateRect( hwnd1
, NULL
);
5051 ValidateRect( hwnd2
, NULL
);
5052 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
,
5053 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
5054 if (winetest_debug
> 0) dump_region(hrgn
);
5055 SetRectRgn( exprgn
, 88,0,98,88);
5056 SetRectRgn( tmprgn
, 0,88,98,98);
5057 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
5058 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
5060 /* SW_SCROLLCHILDREN */
5061 SetWindowLongA( hwnd1
, GWL_STYLE
, GetWindowLongA( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
5062 ValidateRect( hwnd1
, NULL
);
5063 ValidateRect( hwnd2
, NULL
);
5064 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_SCROLLCHILDREN
| SW_INVALIDATE
);
5065 if (winetest_debug
> 0) dump_region(hrgn
);
5066 /* expected region is the same as in previous test */
5067 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
5069 /* no SW_SCROLLCHILDREN */
5070 SetWindowLongA( hwnd1
, GWL_STYLE
, GetWindowLongA( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
5071 ValidateRect( hwnd1
, NULL
);
5072 ValidateRect( hwnd2
, NULL
);
5073 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
5074 if (winetest_debug
> 0) dump_region(hrgn
);
5075 /* expected region is the same as in previous test */
5076 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
5078 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
5079 SetWindowLongA( hwnd1
, GWL_STYLE
, GetWindowLongA( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
5080 ValidateRect( hwnd1
, NULL
);
5081 ValidateRect( hwnd2
, NULL
);
5082 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
5083 if (winetest_debug
> 0) dump_region(hrgn
);
5084 SetRectRgn( exprgn
, 88,0,98,20);
5085 SetRectRgn( tmprgn
, 20,20,98,30);
5086 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
5087 SetRectRgn( tmprgn
, 20,30,30,88);
5088 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
5089 SetRectRgn( tmprgn
, 0,88,30,98);
5090 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
5091 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
5094 DeleteObject( hrgn
);
5095 DeleteObject( exprgn
);
5096 DeleteObject( tmprgn
);
5097 DestroyWindow( hwnd1
);
5098 DestroyWindow( hwnd2
);
5101 /* couple of tests of return values of scrollbar functions
5102 * called on a scrollbarless window */
5103 static void test_scroll(void)
5108 HWND hwnd
= CreateWindowExA(0, "Static", "Wine test window",
5109 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_POPUP
,
5110 100, 100, 200, 200, 0, 0, 0, NULL
);
5112 ret
= GetScrollRange( hwnd
, SB_HORZ
, &min
, &max
);
5113 if (!ret
) /* win9x */
5115 win_skip( "GetScrollRange doesn't work\n" );
5116 DestroyWindow( hwnd
);
5119 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
5120 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
5121 si
.cbSize
= sizeof( si
);
5122 si
.fMask
= SIF_PAGE
;
5123 si
.nPage
= 0xdeadbeef;
5124 ret
= GetScrollInfo( hwnd
, SB_HORZ
, &si
);
5125 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
5126 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
5128 ret
= GetScrollRange( hwnd
, SB_VERT
, &min
, &max
);
5129 ok( ret
, "GetScrollRange returns FALSE\n");
5130 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
5131 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
5132 si
.cbSize
= sizeof( si
);
5133 si
.fMask
= SIF_PAGE
;
5134 si
.nPage
= 0xdeadbeef;
5135 ret
= GetScrollInfo( hwnd
, SB_VERT
, &si
);
5136 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
5137 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
5139 DestroyWindow( hwnd
);
5142 static void test_scrolldc( HWND parent
)
5145 HRGN exprgn
, tmprgn
, hrgn
;
5146 RECT rc
, rc2
, rcu
, cliprc
;
5150 hrgn
= CreateRectRgn(0,0,0,0);
5151 tmprgn
= CreateRectRgn(0,0,0,0);
5152 exprgn
= CreateRectRgn(0,0,0,0);
5154 hwnd1
= CreateWindowExA(0, "static", NULL
,
5155 WS_CHILD
| WS_VISIBLE
,
5156 25, 50, 100, 100, parent
, 0, 0, NULL
);
5157 ShowWindow( parent
, SW_SHOW
);
5158 UpdateWindow( parent
);
5159 flush_events( TRUE
);
5160 GetClientRect( hwnd1
, &rc
);
5161 hdc
= GetDC( hwnd1
);
5162 /* paint the upper half of the window black */
5164 rc2
.bottom
= ( rc
.top
+ rc
.bottom
) /2;
5165 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
5166 /* clip region is the lower half */
5168 cliprc
.top
= (rc
.top
+ rc
.bottom
) /2;
5169 /* test whether scrolled pixels are properly clipped */
5170 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
5171 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
5172 /* this scroll should not cause any visible changes */
5173 ScrollDC( hdc
, 5, -20, &rc
, &cliprc
, hrgn
, &rcu
);
5174 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
5175 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
5176 /* test with NULL clip rect */
5177 ScrollDC( hdc
, 20, -20, &rc
, NULL
, hrgn
, &rcu
);
5178 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
5179 trace("update rect: %s\n", wine_dbgstr_rect(&rcu
));
5180 if (winetest_debug
> 0) dump_region(hrgn
);
5181 SetRect(&rc2
, 0, 0, 100, 100);
5182 ok(EqualRect(&rcu
, &rc2
), "rects do not match %s / %s\n", wine_dbgstr_rect(&rcu
),
5183 wine_dbgstr_rect(&rc2
));
5185 SetRectRgn( exprgn
, 0, 0, 20, 80);
5186 SetRectRgn( tmprgn
, 0, 80, 100, 100);
5187 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
5188 if (winetest_debug
> 0) dump_region(exprgn
);
5189 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
5190 /* test clip rect > scroll rect */
5191 FillRect( hdc
, &rc
, GetStockObject(WHITE_BRUSH
));
5193 InflateRect( &rc2
, -(rc
.right
-rc
.left
)/4, -(rc
.bottom
-rc
.top
)/4);
5194 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
5195 ScrollDC( hdc
, 10, 10, &rc2
, &rc
, hrgn
, &rcu
);
5196 SetRectRgn( exprgn
, 25, 25, 75, 35);
5197 SetRectRgn( tmprgn
, 25, 35, 35, 75);
5198 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
5199 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
5200 trace("update rect: %s\n", wine_dbgstr_rect(&rcu
));
5201 if (winetest_debug
> 0) dump_region(hrgn
);
5205 DeleteObject(exprgn
);
5206 DeleteObject(tmprgn
);
5207 DestroyWindow(hwnd1
);
5210 static void test_params(void)
5215 ok(!IsWindow(0), "IsWindow(0)\n");
5216 ok(!IsWindow(HWND_BROADCAST
), "IsWindow(HWND_BROADCAST)\n");
5217 ok(!IsWindow(HWND_TOPMOST
), "IsWindow(HWND_TOPMOST)\n");
5219 /* Just a param check */
5220 if (pGetMonitorInfoA
)
5222 SetLastError(0xdeadbeef);
5223 rc
= GetWindowTextA(hwndMain2
, NULL
, 1024);
5224 ok( rc
==0, "GetWindowText: rc=%d err=%d\n",rc
,GetLastError());
5228 /* Skips actually on Win95 and NT4 */
5229 win_skip("Test would crash on Win95\n");
5232 SetLastError(0xdeadbeef);
5233 hwnd
=CreateWindowA("LISTBOX", "TestList",
5234 (LBS_STANDARD
& ~LBS_SORT
),
5236 NULL
, (HMENU
)1, NULL
, 0);
5238 ok(!hwnd
|| broken(hwnd
!= NULL
), /* w2k3 sp2 */
5239 "CreateWindow with invalid menu handle should fail\n");
5241 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
|| /* NT */
5242 GetLastError() == 0xdeadbeef, /* Win9x */
5243 "wrong last error value %d\n", GetLastError());
5246 static void test_AWRwindow(LPCSTR
class, LONG style
, LONG exStyle
, BOOL menu
)
5250 hwnd
= CreateWindowExA(exStyle
, class, class, style
,
5257 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style
, exStyle
);
5260 ShowWindow(hwnd
, SW_SHOW
);
5262 test_nonclient_area(hwnd
);
5265 DestroyWindow(hwnd
);
5268 static BOOL
AWR_init(void)
5272 class.style
= CS_HREDRAW
| CS_VREDRAW
;
5273 class.lpfnWndProc
= DefWindowProcA
;
5274 class.cbClsExtra
= 0;
5275 class.cbWndExtra
= 0;
5276 class.hInstance
= 0;
5277 class.hIcon
= LoadIconA(0, (LPCSTR
)IDI_APPLICATION
);
5278 class.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
5279 class.hbrBackground
= 0;
5280 class.lpszMenuName
= 0;
5281 class.lpszClassName
= szAWRClass
;
5283 if (!RegisterClassA(&class)) {
5284 ok(FALSE
, "RegisterClass failed\n");
5288 hmenu
= CreateMenu();
5291 ok(hmenu
!= 0, "Failed to create menu\n");
5292 ok(AppendMenuA(hmenu
, MF_STRING
, 1, "Test!"), "Failed to create menu item\n");
5298 static void test_AWR_window_size(BOOL menu
)
5300 static const DWORD styles
[] = {
5301 WS_POPUP
, WS_MAXIMIZE
, WS_BORDER
, WS_DLGFRAME
, WS_CAPTION
, WS_SYSMENU
,
5302 WS_THICKFRAME
, WS_MINIMIZEBOX
, WS_MAXIMIZEBOX
, WS_HSCROLL
, WS_VSCROLL
5304 static const DWORD exStyles
[] = {
5305 WS_EX_CLIENTEDGE
, WS_EX_TOOLWINDOW
, WS_EX_WINDOWEDGE
, WS_EX_APPWINDOW
,
5306 WS_EX_DLGMODALFRAME
, WS_EX_DLGMODALFRAME
| WS_EX_STATICEDGE
5311 /* A exhaustive check of all the styles takes too long
5312 * so just do a (hopefully representative) sample
5314 for (i
= 0; i
< COUNTOF(styles
); ++i
)
5315 test_AWRwindow(szAWRClass
, styles
[i
], 0, menu
);
5316 for (i
= 0; i
< COUNTOF(exStyles
); ++i
) {
5317 test_AWRwindow(szAWRClass
, WS_POPUP
, exStyles
[i
], menu
);
5318 test_AWRwindow(szAWRClass
, WS_THICKFRAME
, exStyles
[i
], menu
);
5322 static void test_AWR_flags(void)
5324 static const DWORD styles
[] = { WS_POPUP
, WS_BORDER
, WS_DLGFRAME
, WS_THICKFRAME
};
5325 static const DWORD exStyles
[] = { WS_EX_CLIENTEDGE
, WS_EX_TOOLWINDOW
, WS_EX_WINDOWEDGE
,
5326 WS_EX_APPWINDOW
, WS_EX_DLGMODALFRAME
, WS_EX_STATICEDGE
};
5328 DWORD i
, j
, k
, style
, exstyle
;
5331 for (i
= 0; i
< (1 << COUNTOF(styles
)); i
++)
5333 for (k
= style
= 0; k
< COUNTOF(styles
); k
++) if (i
& (1 << k
)) style
|= styles
[k
];
5335 for (j
= 0; j
< (1 << COUNTOF(exStyles
)); j
++)
5337 for (k
= exstyle
= 0; k
< COUNTOF(exStyles
); k
++) if (j
& (1 << k
)) exstyle
|= exStyles
[k
];
5338 SetRect( &rect
, 100, 100, 200, 200 );
5340 AdjustWindowRectEx( &rect
, style
, FALSE
, exstyle
);
5341 wine_AdjustWindowRectEx( &rect2
, style
, FALSE
, exstyle
);
5342 ok( EqualRect( &rect
, &rect2
), "rects do not match: win %s wine %s\n",
5343 wine_dbgstr_rect( &rect
), wine_dbgstr_rect( &rect2
));
5349 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
5351 static void test_AdjustWindowRect(void)
5356 SHOWSYSMETRIC(SM_CYCAPTION
);
5357 SHOWSYSMETRIC(SM_CYSMCAPTION
);
5358 SHOWSYSMETRIC(SM_CYMENU
);
5359 SHOWSYSMETRIC(SM_CXEDGE
);
5360 SHOWSYSMETRIC(SM_CYEDGE
);
5361 SHOWSYSMETRIC(SM_CXVSCROLL
);
5362 SHOWSYSMETRIC(SM_CYHSCROLL
);
5363 SHOWSYSMETRIC(SM_CXFRAME
);
5364 SHOWSYSMETRIC(SM_CYFRAME
);
5365 SHOWSYSMETRIC(SM_CXDLGFRAME
);
5366 SHOWSYSMETRIC(SM_CYDLGFRAME
);
5367 SHOWSYSMETRIC(SM_CXBORDER
);
5368 SHOWSYSMETRIC(SM_CYBORDER
);
5370 test_AWR_window_size(FALSE
);
5371 test_AWR_window_size(TRUE
);
5376 #undef SHOWSYSMETRIC
5379 /* Global variables to trigger exit from loop */
5380 static int redrawComplete
, WMPAINT_count
;
5382 static LRESULT WINAPI
redraw_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
5387 trace("doing WM_PAINT %d\n", WMPAINT_count
);
5389 if (WMPAINT_count
> 10 && redrawComplete
== 0) {
5391 BeginPaint(hwnd
, &ps
);
5392 EndPaint(hwnd
, &ps
);
5397 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
5400 /* Ensure we exit from RedrawNow regardless of invalidated area */
5401 static void test_redrawnow(void)
5406 cls
.style
= CS_DBLCLKS
;
5407 cls
.lpfnWndProc
= redraw_window_procA
;
5410 cls
.hInstance
= GetModuleHandleA(0);
5412 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
5413 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5414 cls
.lpszMenuName
= NULL
;
5415 cls
.lpszClassName
= "RedrawWindowClass";
5417 if(!RegisterClassA(&cls
)) {
5418 trace("Register failed %d\n", GetLastError());
5422 hwndMain
= CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
5423 CW_USEDEFAULT
, 0, 100, 100, NULL
, NULL
, 0, NULL
);
5425 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
5426 ShowWindow(hwndMain
, SW_SHOW
);
5427 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
5428 RedrawWindow(hwndMain
, NULL
,NULL
,RDW_UPDATENOW
| RDW_ALLCHILDREN
);
5429 ok( WMPAINT_count
== 1 || broken(WMPAINT_count
== 0), /* sometimes on win9x */
5430 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
5431 redrawComplete
= TRUE
;
5432 ok( WMPAINT_count
< 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count
);
5435 DestroyWindow( hwndMain
);
5438 struct parentdc_stat
{
5444 struct parentdc_test
{
5445 struct parentdc_stat main
, main_todo
;
5446 struct parentdc_stat child1
, child1_todo
;
5447 struct parentdc_stat child2
, child2_todo
;
5450 static LRESULT WINAPI
parentdc_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
5455 struct parentdc_stat
*t
= (struct parentdc_stat
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
5460 GetClientRect(hwnd
, &rc
);
5462 GetWindowRect(hwnd
, &rc
);
5463 trace("WM_PAINT: hwnd %p, client rect %s, window rect %s\n", hwnd
,
5464 wine_dbgstr_rect(&t
->client
), wine_dbgstr_rect(&rc
));
5465 BeginPaint(hwnd
, &ps
);
5466 t
->paint
= ps
.rcPaint
;
5467 GetClipBox(ps
.hdc
, &rc
);
5469 trace("clip rect %s, paint rect %s\n", wine_dbgstr_rect(&rc
),
5470 wine_dbgstr_rect(&ps
.rcPaint
));
5471 EndPaint(hwnd
, &ps
);
5474 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
5477 static void zero_parentdc_stat(struct parentdc_stat
*t
)
5479 SetRectEmpty(&t
->client
);
5480 SetRectEmpty(&t
->clip
);
5481 SetRectEmpty(&t
->paint
);
5484 static void zero_parentdc_test(struct parentdc_test
*t
)
5486 zero_parentdc_stat(&t
->main
);
5487 zero_parentdc_stat(&t
->child1
);
5488 zero_parentdc_stat(&t
->child2
);
5491 #define parentdc_field_ok(t, w, r, f, got) \
5492 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
5493 ": expected %d, got %d\n", \
5496 #define parentdc_todo_field_ok(t, w, r, f, got) \
5497 todo_wine_if (t.w##_todo.r.f) \
5498 parentdc_field_ok(t, w, r, f, got);
5500 #define parentdc_rect_ok(t, w, r, got) \
5501 parentdc_todo_field_ok(t, w, r, left, got); \
5502 parentdc_todo_field_ok(t, w, r, top, got); \
5503 parentdc_todo_field_ok(t, w, r, right, got); \
5504 parentdc_todo_field_ok(t, w, r, bottom, got);
5506 #define parentdc_win_ok(t, w, got) \
5507 parentdc_rect_ok(t, w, client, got); \
5508 parentdc_rect_ok(t, w, clip, got); \
5509 parentdc_rect_ok(t, w, paint, got);
5511 #define parentdc_ok(t, got) \
5512 parentdc_win_ok(t, main, got); \
5513 parentdc_win_ok(t, child1, got); \
5514 parentdc_win_ok(t, child2, got);
5516 static void test_csparentdc(void)
5518 WNDCLASSA clsMain
, cls
;
5519 HWND hwndMain
, hwnd1
, hwnd2
;
5522 struct parentdc_test test_answer
;
5524 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
5525 const struct parentdc_test test1
=
5527 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo
,
5528 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
5529 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
5532 const struct parentdc_test test2
=
5534 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo
,
5535 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
5536 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
5539 const struct parentdc_test test3
=
5541 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
5542 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
5543 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
5546 const struct parentdc_test test4
=
5548 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo
,
5549 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo
,
5550 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
5553 const struct parentdc_test test5
=
5555 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo
,
5556 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
5557 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
5560 const struct parentdc_test test6
=
5562 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
5563 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
5564 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
5567 const struct parentdc_test test7
=
5569 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
5570 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
5571 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
5575 clsMain
.style
= CS_DBLCLKS
;
5576 clsMain
.lpfnWndProc
= parentdc_window_procA
;
5577 clsMain
.cbClsExtra
= 0;
5578 clsMain
.cbWndExtra
= 0;
5579 clsMain
.hInstance
= GetModuleHandleA(0);
5581 clsMain
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
5582 clsMain
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5583 clsMain
.lpszMenuName
= NULL
;
5584 clsMain
.lpszClassName
= "ParentDcMainWindowClass";
5586 if(!RegisterClassA(&clsMain
)) {
5587 trace("Register failed %d\n", GetLastError());
5591 cls
.style
= CS_DBLCLKS
| CS_PARENTDC
;
5592 cls
.lpfnWndProc
= parentdc_window_procA
;
5595 cls
.hInstance
= GetModuleHandleA(0);
5597 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
5598 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5599 cls
.lpszMenuName
= NULL
;
5600 cls
.lpszClassName
= "ParentDcWindowClass";
5602 if(!RegisterClassA(&cls
)) {
5603 trace("Register failed %d\n", GetLastError());
5607 SetRect(&rc
, 0, 0, 150, 150);
5608 AdjustWindowRectEx(&rc
, WS_OVERLAPPEDWINDOW
, FALSE
, 0);
5609 hwndMain
= CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
5610 CW_USEDEFAULT
, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, NULL
, NULL
, 0, NULL
);
5611 SetWindowLongPtrA(hwndMain
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.main
);
5612 hwnd1
= CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD
,
5613 20, 20, 40, 40, hwndMain
, NULL
, 0, NULL
);
5614 SetWindowLongPtrA(hwnd1
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child1
);
5615 hwnd2
= CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD
,
5616 40, 40, 40, 40, hwndMain
, NULL
, 0, NULL
);
5617 SetWindowLongPtrA(hwnd2
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child2
);
5618 ShowWindow(hwndMain
, SW_SHOW
);
5619 ShowWindow(hwnd1
, SW_SHOW
);
5620 ShowWindow(hwnd2
, SW_SHOW
);
5621 SetWindowPos(hwndMain
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
5622 flush_events( TRUE
);
5624 zero_parentdc_test(&test_answer
);
5625 InvalidateRect(hwndMain
, NULL
, TRUE
);
5626 flush_events( TRUE
);
5627 parentdc_ok(test1
, test_answer
);
5629 zero_parentdc_test(&test_answer
);
5630 SetRect(&rc
, 0, 0, 50, 50);
5631 InvalidateRect(hwndMain
, &rc
, TRUE
);
5632 flush_events( TRUE
);
5633 parentdc_ok(test2
, test_answer
);
5635 zero_parentdc_test(&test_answer
);
5636 SetRect(&rc
, 0, 0, 10, 10);
5637 InvalidateRect(hwndMain
, &rc
, TRUE
);
5638 flush_events( TRUE
);
5639 parentdc_ok(test3
, test_answer
);
5641 zero_parentdc_test(&test_answer
);
5642 SetRect(&rc
, 40, 40, 50, 50);
5643 InvalidateRect(hwndMain
, &rc
, TRUE
);
5644 flush_events( TRUE
);
5645 parentdc_ok(test4
, test_answer
);
5647 zero_parentdc_test(&test_answer
);
5648 SetRect(&rc
, 20, 20, 60, 60);
5649 InvalidateRect(hwndMain
, &rc
, TRUE
);
5650 flush_events( TRUE
);
5651 parentdc_ok(test5
, test_answer
);
5653 zero_parentdc_test(&test_answer
);
5654 SetRect(&rc
, 0, 0, 10, 10);
5655 InvalidateRect(hwnd1
, &rc
, TRUE
);
5656 flush_events( TRUE
);
5657 parentdc_ok(test6
, test_answer
);
5659 zero_parentdc_test(&test_answer
);
5660 SetRect(&rc
, -5, -5, 65, 65);
5661 InvalidateRect(hwnd1
, &rc
, TRUE
);
5662 flush_events( TRUE
);
5663 parentdc_ok(test7
, test_answer
);
5665 DestroyWindow(hwndMain
);
5666 DestroyWindow(hwnd1
);
5667 DestroyWindow(hwnd2
);
5670 static LRESULT WINAPI
def_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
5672 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
5675 static LRESULT WINAPI
def_window_procW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
5677 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
5680 static void test_IsWindowUnicode(void)
5682 static const char ansi_class_nameA
[] = "ansi class name";
5683 static const WCHAR ansi_class_nameW
[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
5684 static const char unicode_class_nameA
[] = "unicode class name";
5685 static const WCHAR unicode_class_nameW
[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
5691 memset(&classW
, 0, sizeof(classW
));
5692 classW
.hInstance
= GetModuleHandleA(0);
5693 classW
.lpfnWndProc
= def_window_procW
;
5694 classW
.lpszClassName
= unicode_class_nameW
;
5695 if (!RegisterClassW(&classW
)) return; /* this catches Win9x as well */
5697 memset(&classA
, 0, sizeof(classA
));
5698 classA
.hInstance
= GetModuleHandleA(0);
5699 classA
.lpfnWndProc
= def_window_procA
;
5700 classA
.lpszClassName
= ansi_class_nameA
;
5701 atom
= RegisterClassA(&classA
);
5704 /* unicode class: window proc */
5705 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
5706 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5709 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5710 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
5711 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5712 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
5713 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5715 DestroyWindow(hwnd
);
5717 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
5718 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5721 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5722 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
5723 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5724 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
5725 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5727 DestroyWindow(hwnd
);
5729 /* ansi class: window proc */
5730 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
5731 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5734 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5735 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
5736 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5737 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
5738 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5740 DestroyWindow(hwnd
);
5742 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
5743 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5746 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5747 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
5748 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5749 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
5750 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5752 DestroyWindow(hwnd
);
5754 /* unicode class: class proc */
5755 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
5756 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5759 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5760 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
5761 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5762 /* do not restore class window proc back to unicode */
5764 DestroyWindow(hwnd
);
5766 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
5767 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5770 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5771 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
5772 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5774 DestroyWindow(hwnd
);
5776 /* ansi class: class proc */
5777 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
5778 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5781 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5782 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
5783 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5784 /* do not restore class window proc back to ansi */
5786 DestroyWindow(hwnd
);
5788 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
5789 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5792 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5793 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
5794 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5796 DestroyWindow(hwnd
);
5799 static LRESULT CALLBACK
minmax_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
5803 if (msg
!= WM_GETMINMAXINFO
)
5804 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
5806 minmax
= (MINMAXINFO
*)lp
;
5808 if ((GetWindowLongA(hwnd
, GWL_STYLE
) & WS_CHILD
))
5810 minmax
->ptReserved
.x
= 0;
5811 minmax
->ptReserved
.y
= 0;
5812 minmax
->ptMaxSize
.x
= 400;
5813 minmax
->ptMaxSize
.y
= 400;
5814 minmax
->ptMaxPosition
.x
= 300;
5815 minmax
->ptMaxPosition
.y
= 300;
5816 minmax
->ptMaxTrackSize
.x
= 200;
5817 minmax
->ptMaxTrackSize
.y
= 200;
5818 minmax
->ptMinTrackSize
.x
= 100;
5819 minmax
->ptMinTrackSize
.y
= 100;
5822 DefWindowProcA(hwnd
, msg
, wp
, lp
);
5826 static int expected_cx
, expected_cy
;
5827 static RECT expected_rect
, broken_rect
;
5829 static LRESULT CALLBACK
winsizes_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
5833 case WM_GETMINMAXINFO
:
5836 GetWindowRect( hwnd
, &rect
);
5837 ok( !rect
.left
&& !rect
.top
&& !rect
.right
&& !rect
.bottom
, "wrong rect %s\n",
5838 wine_dbgstr_rect( &rect
));
5839 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
5844 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
5846 GetWindowRect( hwnd
, &rect
);
5847 trace( "hwnd %p msg %x size %dx%d rect %s\n", hwnd
, msg
, cs
->cx
, cs
->cy
,
5848 wine_dbgstr_rect( &rect
));
5849 ok( cs
->cx
== expected_cx
|| broken(cs
->cx
== (short)expected_cx
),
5850 "wrong x size %d/%d\n", cs
->cx
, expected_cx
);
5851 ok( cs
->cy
== expected_cy
|| broken(cs
->cy
== (short)expected_cy
),
5852 "wrong y size %d/%d\n", cs
->cy
, expected_cy
);
5853 ok( (rect
.right
- rect
.left
== expected_rect
.right
- expected_rect
.left
&&
5854 rect
.bottom
- rect
.top
== expected_rect
.bottom
- expected_rect
.top
) ||
5855 (rect
.right
- rect
.left
== min( 65535, expected_rect
.right
- expected_rect
.left
) &&
5856 rect
.bottom
- rect
.top
== min( 65535, expected_rect
.bottom
- expected_rect
.top
)) ||
5857 broken( rect
.right
- rect
.left
== broken_rect
.right
- broken_rect
.left
&&
5858 rect
.bottom
- rect
.top
== broken_rect
.bottom
- broken_rect
.top
) ||
5859 broken( rect
.right
- rect
.left
== (short)broken_rect
.right
- (short)broken_rect
.left
&&
5860 rect
.bottom
- rect
.top
== (short)broken_rect
.bottom
- (short)broken_rect
.top
),
5861 "wrong rect %s / %s\n", wine_dbgstr_rect( &rect
), wine_dbgstr_rect( &expected_rect
));
5862 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
5866 RECT rect
, *r
= (RECT
*)lp
;
5867 GetWindowRect( hwnd
, &rect
);
5868 ok( EqualRect( &rect
, r
), "passed rect %s doesn't match window rect %s\n",
5869 wine_dbgstr_rect( r
), wine_dbgstr_rect( &rect
));
5870 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
5873 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
5877 static void test_CreateWindow(void)
5886 #define expect_menu(window, menu) \
5887 SetLastError(0xdeadbeef); \
5888 res = (GetMenu(window) == (HMENU)menu); \
5889 ok(res, "GetMenu error %d\n", GetLastError())
5891 #define expect_style(window, style)\
5892 ok((ULONG)GetWindowLongA(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLongA(window, GWL_STYLE))
5894 #define expect_ex_style(window, ex_style)\
5895 ok((ULONG)GetWindowLongA(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLongA(window, GWL_EXSTYLE))
5897 #define expect_gle_broken_9x(gle)\
5898 ok(GetLastError() == gle ||\
5899 broken(GetLastError() == 0xdeadbeef),\
5900 "IsMenu set error %d\n", GetLastError())
5902 hmenu
= CreateMenu();
5904 parent
= GetDesktopWindow();
5905 assert(parent
!= 0);
5907 SetLastError(0xdeadbeef);
5908 res
= IsMenu(hmenu
);
5909 ok(res
, "IsMenu error %d\n", GetLastError());
5912 SetLastError(0xdeadbeef);
5913 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
,
5914 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
5915 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5916 expect_menu(hwnd
, 1);
5917 expect_style(hwnd
, WS_CHILD
);
5918 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
5919 DestroyWindow(hwnd
);
5921 SetLastError(0xdeadbeef);
5922 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_CAPTION
,
5923 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
5924 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5925 expect_menu(hwnd
, 1);
5926 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
5927 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
5928 DestroyWindow(hwnd
);
5930 SetLastError(0xdeadbeef);
5931 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
5932 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
5933 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5934 expect_menu(hwnd
, 1);
5935 expect_style(hwnd
, WS_CHILD
);
5936 expect_ex_style(hwnd
, 0);
5937 DestroyWindow(hwnd
);
5939 SetLastError(0xdeadbeef);
5940 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_CAPTION
,
5941 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
5942 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5943 expect_menu(hwnd
, 1);
5944 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
5945 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
5946 DestroyWindow(hwnd
);
5949 SetLastError(0xdeadbeef);
5950 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
5951 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
5952 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5953 expect_menu(hwnd
, hmenu
);
5954 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
5955 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
5956 DestroyWindow(hwnd
);
5957 SetLastError(0xdeadbeef);
5958 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
5959 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
5961 hmenu
= CreateMenu();
5963 SetLastError(0xdeadbeef);
5964 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
| WS_CAPTION
,
5965 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
5966 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5967 expect_menu(hwnd
, hmenu
);
5968 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
5969 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
5970 DestroyWindow(hwnd
);
5971 SetLastError(0xdeadbeef);
5972 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
5973 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
5975 hmenu
= CreateMenu();
5977 SetLastError(0xdeadbeef);
5978 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
5979 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
5980 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5981 expect_menu(hwnd
, hmenu
);
5982 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
5983 expect_ex_style(hwnd
, 0);
5984 DestroyWindow(hwnd
);
5985 SetLastError(0xdeadbeef);
5986 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
5987 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
5989 hmenu
= CreateMenu();
5991 SetLastError(0xdeadbeef);
5992 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
| WS_CAPTION
,
5993 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
5994 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5995 expect_menu(hwnd
, hmenu
);
5996 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
5997 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
5998 DestroyWindow(hwnd
);
5999 SetLastError(0xdeadbeef);
6000 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
6001 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
6003 /* WS_CHILD | WS_POPUP */
6004 SetLastError(0xdeadbeef);
6005 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
6006 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
6007 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
6008 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
6010 DestroyWindow(hwnd
);
6012 hmenu
= CreateMenu();
6014 SetLastError(0xdeadbeef);
6015 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
6016 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
6017 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
6018 expect_menu(hwnd
, hmenu
);
6019 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
6020 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
6021 DestroyWindow(hwnd
);
6022 SetLastError(0xdeadbeef);
6023 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
6024 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
6026 SetLastError(0xdeadbeef);
6027 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
6028 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
6029 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
6030 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
6032 DestroyWindow(hwnd
);
6034 hmenu
= CreateMenu();
6036 SetLastError(0xdeadbeef);
6037 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
6038 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
6039 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
6040 expect_menu(hwnd
, hmenu
);
6041 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
6042 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
6043 DestroyWindow(hwnd
);
6044 SetLastError(0xdeadbeef);
6045 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
6046 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
6048 SetLastError(0xdeadbeef);
6049 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
6050 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
6051 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
6052 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
6054 DestroyWindow(hwnd
);
6056 hmenu
= CreateMenu();
6058 SetLastError(0xdeadbeef);
6059 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
6060 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
6061 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
6062 expect_menu(hwnd
, hmenu
);
6063 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
6064 expect_ex_style(hwnd
, 0);
6065 DestroyWindow(hwnd
);
6066 SetLastError(0xdeadbeef);
6067 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
6068 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
6070 SetLastError(0xdeadbeef);
6071 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
6072 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
6073 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
6074 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
6076 DestroyWindow(hwnd
);
6078 hmenu
= CreateMenu();
6080 SetLastError(0xdeadbeef);
6081 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
6082 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
6083 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
6084 expect_menu(hwnd
, hmenu
);
6085 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
6086 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
6087 DestroyWindow(hwnd
);
6088 SetLastError(0xdeadbeef);
6089 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
6090 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
6092 /* test child window sizing */
6094 cls
.lpfnWndProc
= minmax_wnd_proc
;
6097 cls
.hInstance
= GetModuleHandleA(NULL
);
6099 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
6100 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
6101 cls
.lpszMenuName
= NULL
;
6102 cls
.lpszClassName
= "MinMax_WndClass";
6103 RegisterClassA(&cls
);
6105 SetLastError(0xdeadbeef);
6106 parent
= CreateWindowExA(0, "MinMax_WndClass", NULL
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
6107 0, 0, 100, 100, 0, 0, 0, NULL
);
6108 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
6109 expect_menu(parent
, 0);
6110 expect_style(parent
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
| WS_CLIPSIBLINGS
);
6111 expect_ex_style(parent
, WS_EX_WINDOWEDGE
);
6113 memset(&minmax
, 0, sizeof(minmax
));
6114 SendMessageA(parent
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
6115 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxSize
.x
, minmax
.ptMaxSize
.y
);
6116 ok(IsRectEmpty(&rc_minmax
), "ptMaxSize is not empty\n");
6117 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
6118 ok(IsRectEmpty(&rc_minmax
), "ptMaxTrackSize is not empty\n");
6120 GetWindowRect(parent
, &rc
);
6121 ok(!IsRectEmpty(&rc
), "parent window rect is empty\n");
6122 GetClientRect(parent
, &rc
);
6123 ok(!IsRectEmpty(&rc
), "parent client rect is empty\n");
6125 InflateRect(&rc
, 200, 200);
6126 trace("creating child with rect %s\n", wine_dbgstr_rect(&rc
));
6128 SetLastError(0xdeadbeef);
6129 hwnd
= CreateWindowExA(0, "MinMax_WndClass", NULL
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
6130 rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
6131 parent
, (HMENU
)1, 0, NULL
);
6132 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
6133 expect_menu(hwnd
, 1);
6134 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
);
6135 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
6137 memset(&minmax
, 0, sizeof(minmax
));
6138 SendMessageA(hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
6139 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
6141 GetWindowRect(hwnd
, &rc
);
6142 OffsetRect(&rc
, -rc
.left
, -rc
.top
);
6143 ok(EqualRect(&rc
, &rc_minmax
), "rects don't match: %s and %s\n", wine_dbgstr_rect(&rc
),
6144 wine_dbgstr_rect(&rc_minmax
));
6145 DestroyWindow(hwnd
);
6147 cls
.lpfnWndProc
= winsizes_wnd_proc
;
6148 cls
.lpszClassName
= "Sizes_WndClass";
6149 RegisterClassA(&cls
);
6151 expected_cx
= expected_cy
= 200000;
6152 SetRect( &expected_rect
, 0, 0, 200000, 200000 );
6153 broken_rect
= expected_rect
;
6154 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 300000, 300000, 200000, 200000, parent
, 0, 0, NULL
);
6155 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6156 GetClientRect( hwnd
, &rc
);
6157 ok( rc
.right
== 200000 || rc
.right
== 65535 || broken(rc
.right
== (short)200000),
6158 "invalid rect right %u\n", rc
.right
);
6159 ok( rc
.bottom
== 200000 || rc
.bottom
== 65535 || broken(rc
.bottom
== (short)200000),
6160 "invalid rect bottom %u\n", rc
.bottom
);
6161 DestroyWindow(hwnd
);
6163 expected_cx
= expected_cy
= -10;
6164 SetRectEmpty(&expected_rect
);
6165 SetRect( &broken_rect
, 0, 0, -10, -10 );
6166 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -20, -20, -10, -10, parent
, 0, 0, NULL
);
6167 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6168 GetClientRect( hwnd
, &rc
);
6169 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
6170 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
6171 DestroyWindow(hwnd
);
6173 expected_cx
= expected_cy
= -200000;
6174 SetRectEmpty(&expected_rect
);
6175 SetRect( &broken_rect
, 0, 0, -200000, -200000 );
6176 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -300000, -300000, -200000, -200000, parent
, 0, 0, NULL
);
6177 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6178 GetClientRect( hwnd
, &rc
);
6179 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
6180 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
6181 DestroyWindow(hwnd
);
6183 /* we need a parent at 0,0 so that child coordinates match */
6184 DestroyWindow(parent
);
6185 parent
= CreateWindowExA(0, "MinMax_WndClass", NULL
, WS_POPUP
, 0, 0, 100, 100, 0, 0, 0, NULL
);
6186 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
6189 expected_cy
= 0x7fffffff;
6190 SetRect( &expected_rect
, 10, 10, 110, 0x7fffffff );
6191 SetRect( &broken_rect
, 10, 10, 110, 0x7fffffffU
+ 10 );
6192 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 10, 10, 100, 0x7fffffff, parent
, 0, 0, NULL
);
6193 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6194 GetClientRect( hwnd
, &rc
);
6195 ok( rc
.right
== 100, "invalid rect right %u\n", rc
.right
);
6196 ok( rc
.bottom
== 0x7fffffff - 10 || rc
.bottom
==65535 || broken(rc
.bottom
== 0),
6197 "invalid rect bottom %u\n", rc
.bottom
);
6198 DestroyWindow(hwnd
);
6200 expected_cx
= 0x7fffffff;
6201 expected_cy
= 0x7fffffff;
6202 SetRect( &expected_rect
, 20, 10, 0x7fffffff, 0x7fffffff );
6203 SetRect( &broken_rect
, 20, 10, 0x7fffffffU
+ 20, 0x7fffffffU
+ 10 );
6204 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 20, 10, 0x7fffffff, 0x7fffffff, parent
, 0, 0, NULL
);
6205 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6206 GetClientRect( hwnd
, &rc
);
6207 ok( rc
.right
== 0x7fffffff - 20 || rc
.right
== 65535 || broken(rc
.right
== 0),
6208 "invalid rect right %u\n", rc
.right
);
6209 ok( rc
.bottom
== 0x7fffffff - 10 || rc
.right
== 65535 || broken(rc
.bottom
== 0),
6210 "invalid rect bottom %u\n", rc
.bottom
);
6211 DestroyWindow(hwnd
);
6213 /* top level window */
6214 expected_cx
= expected_cy
= 200000;
6215 SetRect( &expected_rect
, 0, 0, GetSystemMetrics(SM_CXMAXTRACK
), GetSystemMetrics(SM_CYMAXTRACK
) );
6216 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_OVERLAPPEDWINDOW
, 300000, 300000, 200000, 200000, 0, 0, 0, NULL
);
6217 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6218 GetClientRect( hwnd
, &rc
);
6219 ok( rc
.right
<= expected_cx
, "invalid rect right %u\n", rc
.right
);
6220 ok( rc
.bottom
<= expected_cy
, "invalid rect bottom %u\n", rc
.bottom
);
6221 DestroyWindow(hwnd
);
6223 if (pGetLayout
&& pSetLayout
)
6225 HDC hdc
= GetDC( parent
);
6226 pSetLayout( hdc
, LAYOUT_RTL
);
6227 if (pGetLayout( hdc
))
6229 ReleaseDC( parent
, hdc
);
6230 DestroyWindow( parent
);
6231 SetLastError( 0xdeadbeef );
6232 parent
= CreateWindowExA(WS_EX_APPWINDOW
| WS_EX_LAYOUTRTL
, "static", NULL
, WS_POPUP
,
6233 0, 0, 100, 100, 0, 0, 0, NULL
);
6234 ok( parent
!= 0, "creation failed err %u\n", GetLastError());
6235 expect_ex_style( parent
, WS_EX_APPWINDOW
| WS_EX_LAYOUTRTL
);
6236 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 20, 20, parent
, 0, 0, NULL
);
6237 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6238 expect_ex_style( hwnd
, WS_EX_LAYOUTRTL
);
6239 DestroyWindow( hwnd
);
6240 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 20, 20, parent
, 0, 0, NULL
);
6241 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6242 expect_ex_style( hwnd
, 0 );
6243 DestroyWindow( hwnd
);
6244 SetWindowLongW( parent
, GWL_EXSTYLE
, WS_EX_APPWINDOW
| WS_EX_LAYOUTRTL
| WS_EX_NOINHERITLAYOUT
);
6245 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 20, 20, parent
, 0, 0, NULL
);
6246 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6247 expect_ex_style( hwnd
, 0 );
6248 DestroyWindow( hwnd
);
6250 if (pGetProcessDefaultLayout
&& pSetProcessDefaultLayout
)
6254 SetLastError( 0xdeadbeef );
6255 ok( !pGetProcessDefaultLayout( NULL
), "GetProcessDefaultLayout succeeded\n" );
6256 ok( GetLastError() == ERROR_NOACCESS
, "wrong error %u\n", GetLastError() );
6257 SetLastError( 0xdeadbeef );
6258 res
= pGetProcessDefaultLayout( &layout
);
6259 ok( res
, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
6260 ok( layout
== 0, "GetProcessDefaultLayout wrong layout %x\n", layout
);
6261 SetLastError( 0xdeadbeef );
6262 res
= pSetProcessDefaultLayout( 7 );
6263 ok( res
, "SetProcessDefaultLayout failed err %u\n", GetLastError ());
6264 res
= pGetProcessDefaultLayout( &layout
);
6265 ok( res
, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
6266 ok( layout
== 7, "GetProcessDefaultLayout wrong layout %x\n", layout
);
6267 SetLastError( 0xdeadbeef );
6268 res
= pSetProcessDefaultLayout( LAYOUT_RTL
);
6269 ok( res
, "SetProcessDefaultLayout failed err %u\n", GetLastError ());
6270 res
= pGetProcessDefaultLayout( &layout
);
6271 ok( res
, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
6272 ok( layout
== LAYOUT_RTL
, "GetProcessDefaultLayout wrong layout %x\n", layout
);
6273 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
6274 0, 0, 100, 100, 0, 0, 0, NULL
);
6275 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6276 expect_ex_style( hwnd
, WS_EX_APPWINDOW
| WS_EX_LAYOUTRTL
);
6277 DestroyWindow( hwnd
);
6278 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
6279 0, 0, 100, 100, parent
, 0, 0, NULL
);
6280 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
6281 expect_ex_style( hwnd
, WS_EX_APPWINDOW
);
6282 DestroyWindow( hwnd
);
6283 pSetProcessDefaultLayout( 0 );
6285 else win_skip( "SetProcessDefaultLayout not supported\n" );
6287 else win_skip( "SetLayout not supported\n" );
6289 else win_skip( "SetLayout not available\n" );
6291 DestroyWindow(parent
);
6293 UnregisterClassA("MinMax_WndClass", GetModuleHandleA(NULL
));
6294 UnregisterClassA("Sizes_WndClass", GetModuleHandleA(NULL
));
6296 #undef expect_gle_broken_9x
6299 #undef expect_ex_style
6302 /* function that remembers whether the system the test is running on sets the
6303 * last error for user32 functions to make the tests stricter */
6304 static int check_error(DWORD actual
, DWORD expected
)
6306 static int sets_last_error
= -1;
6307 if (sets_last_error
== -1)
6308 sets_last_error
= (actual
!= 0xdeadbeef);
6309 return (!sets_last_error
&& (actual
== 0xdeadbeef)) || (actual
== expected
);
6312 static void test_SetWindowLong(void)
6315 WNDPROC old_window_procW
;
6317 SetLastError(0xdeadbeef);
6318 retval
= SetWindowLongPtrA(NULL
, GWLP_WNDPROC
, 0);
6319 ok(!retval
, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval
);
6320 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE
),
6321 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instead of %d\n", GetLastError());
6323 SetLastError(0xdeadbeef);
6324 retval
= SetWindowLongPtrA(hwndMain
, 0xdeadbeef, 0);
6325 ok(!retval
, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval
);
6326 ok(check_error(GetLastError(), ERROR_INVALID_INDEX
),
6327 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instead of %d\n", GetLastError());
6329 SetLastError(0xdeadbeef);
6330 retval
= SetWindowLongPtrA(hwndMain
, GWLP_WNDPROC
, 0);
6331 ok((WNDPROC
)retval
== main_window_procA
|| broken(!retval
), /* win9x */
6332 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval
);
6333 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
6334 retval
= GetWindowLongPtrA(hwndMain
, GWLP_WNDPROC
);
6335 ok((WNDPROC
)retval
== main_window_procA
,
6336 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
6337 ok(!IsWindowUnicode(hwndMain
), "hwndMain shouldn't be Unicode\n");
6339 old_window_procW
= (WNDPROC
)GetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
);
6340 SetLastError(0xdeadbeef);
6341 retval
= SetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
, 0);
6342 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED
)
6344 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
6345 ok(retval
!= 0, "SetWindowLongPtr error %d\n", GetLastError());
6346 ok((WNDPROC
)retval
== old_window_procW
,
6347 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
6348 ok(IsWindowUnicode(hwndMain
), "hwndMain should now be Unicode\n");
6350 /* set it back to ANSI */
6351 SetWindowLongPtrA(hwndMain
, GWLP_WNDPROC
, 0);
6355 static LRESULT WINAPI
check_style_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
6357 const STYLESTRUCT
*expected
= (STYLESTRUCT
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
6358 const STYLESTRUCT
*got
= (STYLESTRUCT
*)lParam
;
6360 if (message
== WM_STYLECHANGING
&& wParam
== GWL_STYLE
)
6362 ok(got
->styleOld
== expected
[0].styleOld
, "expected old style %#x, got %#x\n",
6363 expected
[0].styleOld
, got
->styleOld
);
6364 ok(got
->styleNew
== expected
[0].styleNew
, "expected new style %#x, got %#x\n",
6365 expected
[0].styleNew
, got
->styleNew
);
6367 else if (message
== WM_STYLECHANGED
&& wParam
== GWL_STYLE
)
6369 ok(got
->styleOld
== expected
[1].styleOld
, "expected old style %#x, got %#x\n",
6370 expected
[1].styleOld
, got
->styleOld
);
6371 ok(got
->styleNew
== expected
[1].styleNew
, "expected new style %#x, got %#x\n",
6372 expected
[1].styleNew
, got
->styleNew
);
6375 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
6378 static void test_set_window_style(void)
6380 LONG expected_style
, new_style
, old_style
;
6381 STYLESTRUCT expected_stylestruct
[2];
6388 LONG creation_style
;
6393 { WS_MINIMIZE
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
,
6394 WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
},
6395 { WS_MINIMIZE
| WS_CLIPSIBLINGS
| WS_CAPTION
,
6396 WS_CLIPSIBLINGS
| WS_CAPTION
},
6397 { WS_MAXIMIZE
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
,
6398 WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
},
6399 { WS_MAXIMIZE
| WS_CLIPSIBLINGS
| WS_CAPTION
,
6400 WS_CLIPSIBLINGS
| WS_CAPTION
},
6401 { WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
,
6402 WS_MINIMIZE
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
},
6403 { WS_CLIPSIBLINGS
| WS_CAPTION
,
6404 WS_MINIMIZE
| WS_CLIPSIBLINGS
| WS_CAPTION
},
6405 { WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
,
6406 WS_MAXIMIZE
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
},
6407 { WS_CLIPSIBLINGS
| WS_CAPTION
,
6408 WS_MAXIMIZE
| WS_CLIPSIBLINGS
| WS_CAPTION
},
6411 memset(&cls
, 0, sizeof(cls
));
6412 cls
.lpfnWndProc
= check_style_wnd_proc
;
6413 cls
.hInstance
= GetModuleHandleA(0);
6414 cls
.lpszClassName
= "TestSetWindowStylesClass";
6415 ok(RegisterClassA(&cls
), "RegisterClass failed\n");
6417 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
6419 expected_style
= tests
[i
].style
;
6420 if (tests
[i
].creation_style
& WS_MINIMIZE
)
6421 expected_style
|= WS_MINIMIZE
;
6423 expected_stylestruct
[0].styleOld
= tests
[i
].creation_style
;
6424 expected_stylestruct
[0].styleNew
= tests
[i
].style
;
6425 expected_stylestruct
[1].styleOld
= tests
[i
].creation_style
;
6426 expected_stylestruct
[1].styleNew
= expected_style
;
6428 hwnd
= CreateWindowA(cls
.lpszClassName
, "Test set styles",
6429 tests
[i
].creation_style
, 100, 100, 200, 200, 0, 0, 0, NULL
);
6430 ok(hwnd
!= 0, "CreateWindow failed\n");
6431 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)&expected_stylestruct
);
6433 old_style
= SetWindowLongA(hwnd
, GWL_STYLE
, tests
[i
].style
);
6434 ok(old_style
== tests
[i
].creation_style
, "expected old style %#x, got %#x\n",
6435 tests
[i
].creation_style
, old_style
);
6436 new_style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6437 ok(new_style
== expected_style
, "expected new style %#x, got %#x\n",
6438 expected_style
, new_style
);
6440 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0);
6441 DestroyWindow(hwnd
);
6444 UnregisterClassA(cls
.lpszClassName
, cls
.hInstance
);
6447 static void test_ShowWindow(void)
6451 RECT rcMain
, rc
, rcMinimized
;
6454 SetRect(&rcMain
, 120, 120, 210, 210);
6456 hwnd
= CreateWindowExA(0, "MainWindowClass", NULL
,
6457 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
6458 WS_MAXIMIZEBOX
| WS_POPUP
,
6459 rcMain
.left
, rcMain
.top
,
6460 rcMain
.right
- rcMain
.left
, rcMain
.bottom
- rcMain
.top
,
6464 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6465 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
6466 ok(!(style
& WS_VISIBLE
), "window should not be visible\n");
6467 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
6468 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6469 GetWindowRect(hwnd
, &rc
);
6470 ok(EqualRect(&rcMain
, &rc
), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain
),
6471 wine_dbgstr_rect(&rc
));
6473 ret
= ShowWindow(hwnd
, SW_SHOW
);
6474 ok(!ret
, "not expected ret: %lu\n", ret
);
6475 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6476 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
6477 ok(style
& WS_VISIBLE
, "window should be visible\n");
6478 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
6479 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6480 GetWindowRect(hwnd
, &rc
);
6481 ok(EqualRect(&rcMain
, &rc
), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain
),
6482 wine_dbgstr_rect(&rc
));
6484 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
6485 ok(ret
, "not expected ret: %lu\n", ret
);
6486 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6487 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
6488 ok(style
& WS_VISIBLE
, "window should be visible\n");
6489 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
6490 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6491 GetWindowRect(hwnd
, &rcMinimized
);
6492 ok(!EqualRect(&rcMain
, &rcMinimized
), "rects shouldn't match\n");
6493 /* shouldn't be able to resize minimized windows */
6494 ret
= SetWindowPos(hwnd
, 0, 0, 0,
6495 (rcMinimized
.right
- rcMinimized
.left
) * 2,
6496 (rcMinimized
.bottom
- rcMinimized
.top
) * 2,
6497 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
6498 ok(ret
, "not expected ret: %lu\n", ret
);
6499 GetWindowRect(hwnd
, &rc
);
6500 ok(EqualRect(&rc
, &rcMinimized
), "rects should match\n");
6502 ShowWindow(hwnd
, SW_RESTORE
);
6503 ok(ret
, "not expected ret: %lu\n", ret
);
6504 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6505 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
6506 ok(style
& WS_VISIBLE
, "window should be visible\n");
6507 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
6508 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6509 GetWindowRect(hwnd
, &rc
);
6510 ok(EqualRect(&rcMain
, &rc
), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain
),
6511 wine_dbgstr_rect(&rc
));
6513 ret
= EnableWindow(hwnd
, FALSE
);
6514 ok(!ret
, "not expected ret: %lu\n", ret
);
6515 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6516 ok(style
& WS_DISABLED
, "window should be disabled\n");
6518 ret
= DefWindowProcA(hwnd
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
6519 ok(!ret
, "not expected ret: %lu\n", ret
);
6520 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6521 ok(style
& WS_DISABLED
, "window should be disabled\n");
6522 ok(style
& WS_VISIBLE
, "window should be visible\n");
6523 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
6524 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6525 GetWindowRect(hwnd
, &rc
);
6526 ok(EqualRect(&rcMain
, &rc
), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain
),
6527 wine_dbgstr_rect(&rc
));
6529 ret
= DefWindowProcA(hwnd
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
6530 ok(!ret
, "not expected ret: %lu\n", ret
);
6531 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6532 ok(style
& WS_DISABLED
, "window should be disabled\n");
6533 ok(style
& WS_VISIBLE
, "window should be visible\n");
6534 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
6535 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6536 GetWindowRect(hwnd
, &rc
);
6537 ok(EqualRect(&rcMain
, &rc
), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain
),
6538 wine_dbgstr_rect(&rc
));
6540 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
6541 ok(ret
, "not expected ret: %lu\n", ret
);
6542 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6543 ok(style
& WS_DISABLED
, "window should be disabled\n");
6544 ok(style
& WS_VISIBLE
, "window should be visible\n");
6545 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
6546 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6547 GetWindowRect(hwnd
, &rc
);
6548 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
6550 ret
= DefWindowProcA(hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
6551 ok(!ret
, "not expected ret: %lu\n", ret
);
6552 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6553 ok(style
& WS_DISABLED
, "window should be disabled\n");
6554 ok(style
& WS_VISIBLE
, "window should be visible\n");
6555 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
6556 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6557 GetWindowRect(hwnd
, &rc
);
6558 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
6560 ret
= ShowWindow(hwnd
, SW_RESTORE
);
6561 ok(ret
, "not expected ret: %lu\n", ret
);
6562 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
6563 ok(style
& WS_DISABLED
, "window should be disabled\n");
6564 ok(style
& WS_VISIBLE
, "window should be visible\n");
6565 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
6566 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
6567 GetWindowRect(hwnd
, &rc
);
6568 ok(EqualRect(&rcMain
, &rc
), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain
),
6569 wine_dbgstr_rect(&rc
));
6571 ret
= DefWindowProcA(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
6572 ok(!ret
, "not expected ret: %lu\n", ret
);
6573 ok(IsWindow(hwnd
), "window should exist\n");
6575 ret
= EnableWindow(hwnd
, TRUE
);
6576 ok(ret
, "not expected ret: %lu\n", ret
);
6578 ret
= DefWindowProcA(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
6579 ok(!ret
, "not expected ret: %lu\n", ret
);
6580 ok(!IsWindow(hwnd
), "window should not exist\n");
6583 static DWORD CALLBACK
gettext_msg_thread( LPVOID arg
)
6589 /* test GetWindowTextA */
6590 num_gettext_msgs
= 0;
6591 memset( buf
, 0, sizeof(buf
) );
6592 buf_len
= GetWindowTextA( hwnd
, buf
, sizeof(buf
) );
6593 ok( buf_len
!= 0, "expected a nonempty window text\n" );
6594 ok( !strcmp(buf
, "another_caption"), "got wrong window text '%s'\n", buf
);
6595 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
6600 static DWORD CALLBACK
settext_msg_thread( LPVOID arg
)
6605 /* test SetWindowTextA */
6606 num_settext_msgs
= 0;
6607 success
= SetWindowTextA( hwnd
, "thread_caption" );
6608 ok( success
, "SetWindowTextA failed\n" );
6609 ok( num_settext_msgs
== 1, "got %u WM_SETTEXT messages\n", num_settext_msgs
);
6614 static void test_gettext(void)
6616 DWORD tid
, num_msgs
;
6626 hwnd
= CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP
, 0, 0, 0, 0, 0, 0, 0, NULL
);
6627 ok( hwnd
!= 0, "CreateWindowExA error %d\n", GetLastError() );
6629 /* test GetWindowTextA */
6630 num_gettext_msgs
= 0;
6631 memset( buf
, 0, sizeof(buf
) );
6632 buf_len
= GetWindowTextA( hwnd
, buf
, sizeof(buf
) );
6633 ok( buf_len
!= 0, "expected a nonempty window text\n" );
6634 ok( !strcmp(buf
, "caption"), "got wrong window text '%s'\n", buf
);
6635 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
6637 /* other process window */
6639 buf_len
= GetWindowTextA( GetDesktopWindow(), buf
, sizeof(buf
) );
6640 ok( buf_len
== 0, "expected a nonempty window text\n" );
6641 ok( *buf
== 0, "got wrong window text '%s'\n", buf
);
6643 strcpy( buf
, "blah" );
6644 buf_len
= GetWindowTextA( GetDesktopWindow(), buf
, 0 );
6645 ok( buf_len
== 0, "expected a nonempty window text\n" );
6646 ok( !strcmp(buf
, "blah"), "got wrong window text '%s'\n", buf
);
6649 buf_len
= GetWindowTextW( GetDesktopWindow(), bufW
, 0 );
6650 ok( buf_len
== 0, "expected a nonempty window text\n" );
6651 ok( bufW
[0] == 0xcc, "got %x\n", bufW
[0] );
6653 g_wm_gettext_override
.enabled
= TRUE
;
6655 num_gettext_msgs
= 0;
6656 memset( buf
, 0xcc, sizeof(buf
) );
6657 g_wm_gettext_override
.buff
= buf
;
6658 buf_len
= GetWindowTextA( hwnd
, buf
, sizeof(buf
) );
6659 ok( buf_len
== 0, "got %d\n", buf_len
);
6660 ok( *buf
== 0, "got %x\n", *buf
);
6661 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
6663 num_gettext_msgs
= 0;
6664 strcpy( buf
, "blah" );
6665 g_wm_gettext_override
.buff
= buf
;
6666 buf_len
= GetWindowTextA( hwnd
, buf
, 0 );
6667 ok( buf_len
== 0, "got %d\n", buf_len
);
6668 ok( !strcmp(buf
, "blah"), "got %s\n", buf
);
6669 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
6671 g_wm_gettext_override
.enabled
= FALSE
;
6673 /* same for W window */
6674 hwnd2
= CreateWindowExW( 0, mainclassW
, NULL
, WS_POPUP
, 0, 0, 0, 0, 0, 0, 0, NULL
);
6675 ok( hwnd2
!= 0, "CreateWindowExA error %d\n", GetLastError() );
6677 g_wm_gettext_override
.enabled
= TRUE
;
6679 num_gettext_msgs
= 0;
6680 memset( bufW
, 0xcc, sizeof(bufW
) );
6681 g_wm_gettext_override
.buffW
= bufW
;
6682 buf_len
= GetWindowTextW( hwnd2
, bufW
, sizeof(bufW
)/sizeof(WCHAR
) );
6683 ok( buf_len
== 0, "got %d\n", buf_len
);
6684 ok( *bufW
== 0, "got %x\n", *bufW
);
6685 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
6687 num_gettext_msgs
= 0;
6688 memset( bufW
, 0xcc, sizeof(bufW
) );
6689 g_wm_gettext_override
.buffW
= bufW
;
6690 buf_len
= GetWindowTextW( hwnd2
, bufW
, 0 );
6691 ok( buf_len
== 0, "got %d\n", buf_len
);
6692 ok( *bufW
== 0xcccc, "got %x\n", *bufW
);
6693 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
6695 g_wm_gettext_override
.enabled
= FALSE
;
6697 DestroyWindow( hwnd2
);
6699 /* test WM_GETTEXT */
6700 num_gettext_msgs
= 0;
6701 memset( buf
, 0, sizeof(buf
) );
6702 r
= SendMessageA( hwnd
, WM_GETTEXT
, sizeof(buf
), (LONG_PTR
)buf
);
6703 ok( r
!= 0, "expected a nonempty window text\n" );
6704 ok( !strcmp(buf
, "caption"), "got wrong window text '%s'\n", buf
);
6705 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
6707 /* test SetWindowTextA */
6708 num_settext_msgs
= 0;
6709 success
= SetWindowTextA( hwnd
, "new_caption" );
6710 ok( success
, "SetWindowTextA failed\n" );
6711 ok( num_settext_msgs
== 1, "got %u WM_SETTEXT messages\n", num_settext_msgs
);
6713 num_gettext_msgs
= 0;
6714 memset( buf
, 0, sizeof(buf
) );
6715 buf_len
= GetWindowTextA( hwnd
, buf
, sizeof(buf
) );
6716 ok( buf_len
!= 0, "expected a nonempty window text\n" );
6717 ok( !strcmp(buf
, "new_caption"), "got wrong window text '%s'\n", buf
);
6718 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
6720 /* test WM_SETTEXT */
6721 num_settext_msgs
= 0;
6722 r
= SendMessageA( hwnd
, WM_SETTEXT
, 0, (ULONG_PTR
)"another_caption" );
6723 ok( r
!= 0, "WM_SETTEXT failed\n" );
6724 ok( num_settext_msgs
== 1, "got %u WM_SETTEXT messages\n", num_settext_msgs
);
6726 num_gettext_msgs
= 0;
6727 memset( buf
, 0, sizeof(buf
) );
6728 buf_len
= GetWindowTextA( hwnd
, buf
, sizeof(buf
) );
6729 ok( buf_len
!= 0, "expected a nonempty window text\n" );
6730 ok( !strcmp(buf
, "another_caption"), "got wrong window text '%s'\n", buf
);
6731 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
6733 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
))
6734 DispatchMessageA( &msg
);
6736 /* test interthread GetWindowTextA */
6738 thread
= CreateThread( NULL
, 0, gettext_msg_thread
, hwnd
, 0, &tid
);
6739 ok(thread
!= NULL
, "CreateThread failed, error %d\n", GetLastError());
6740 while (MsgWaitForMultipleObjects( 1, &thread
, FALSE
, INFINITE
, QS_SENDMESSAGE
) != WAIT_OBJECT_0
)
6742 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
))
6743 DispatchMessageA( &msg
);
6746 CloseHandle( thread
);
6747 ok( num_msgs
>= 1, "got %u wakeups from MsgWaitForMultipleObjects\n", num_msgs
);
6749 /* test interthread SetWindowText */
6751 thread
= CreateThread( NULL
, 0, settext_msg_thread
, hwnd
, 0, &tid
);
6752 ok(thread
!= NULL
, "CreateThread failed, error %d\n", GetLastError());
6753 while (MsgWaitForMultipleObjects( 1, &thread
, FALSE
, INFINITE
, QS_SENDMESSAGE
) != WAIT_OBJECT_0
)
6755 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
))
6756 DispatchMessageA( &msg
);
6759 CloseHandle( thread
);
6760 ok( num_msgs
>= 1, "got %u wakeups from MsgWaitForMultipleObjects\n", num_msgs
);
6762 num_gettext_msgs
= 0;
6763 memset( buf
, 0, sizeof(buf
) );
6764 buf_len
= GetWindowTextA( hwnd
, buf
, sizeof(buf
) );
6765 ok( buf_len
!= 0, "expected a nonempty window text\n" );
6766 ok( !strcmp(buf
, "thread_caption"), "got wrong window text '%s'\n", buf
);
6767 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
6769 /* seems to crash on every modern Windows version */
6772 r
= SendMessageA( hwnd
, WM_GETTEXT
, 0x10, 0x1000);
6773 ok( r
== 0, "settext should return zero\n");
6775 r
= SendMessageA( hwnd
, WM_GETTEXT
, 0x10000, 0);
6776 ok( r
== 0, "settext should return zero (%ld)\n", r
);
6778 r
= SendMessageA( hwnd
, WM_GETTEXT
, 0xff000000, 0x1000);
6779 ok( r
== 0, "settext should return zero (%ld)\n", r
);
6781 r
= SendMessageA( hwnd
, WM_GETTEXT
, 0x1000, 0xff000000);
6782 ok( r
== 0, "settext should return zero (%ld)\n", r
);
6785 DestroyWindow(hwnd
);
6789 static void test_GetUpdateRect(void)
6792 BOOL ret
, parent_wm_paint
, grandparent_wm_paint
;
6794 HWND hgrandparent
, hparent
, hchild
;
6796 static const char classNameA
[] = "GetUpdateRectClass";
6798 hgrandparent
= CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW
,
6799 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
6801 hparent
= CreateWindowA("static", "parent", WS_CHILD
|WS_VISIBLE
,
6802 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
6804 hchild
= CreateWindowA("static", "child", WS_CHILD
|WS_VISIBLE
,
6805 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
6807 ShowWindow(hgrandparent
, SW_SHOW
);
6808 UpdateWindow(hgrandparent
);
6809 flush_events( TRUE
);
6811 ShowWindow(hchild
, SW_HIDE
);
6813 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
6814 ok(!ret
, "GetUpdateRect returned not empty region\n");
6815 ok(EqualRect(&rc1
, &rc2
), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1
),
6816 wine_dbgstr_rect(&rc2
));
6818 SetRect(&rc2
, 10, 10, 40, 40);
6819 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
6820 ok(ret
, "GetUpdateRect returned empty region\n");
6821 ok(EqualRect(&rc1
, &rc2
), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1
),
6822 wine_dbgstr_rect(&rc2
));
6824 parent_wm_paint
= FALSE
;
6825 grandparent_wm_paint
= FALSE
;
6826 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
6828 if (msg
.message
== WM_PAINT
)
6830 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
6831 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
6833 DispatchMessageA(&msg
);
6835 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
6836 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
6838 DestroyWindow(hgrandparent
);
6841 cls
.lpfnWndProc
= DefWindowProcA
;
6844 cls
.hInstance
= GetModuleHandleA(0);
6846 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
6847 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
6848 cls
.lpszMenuName
= NULL
;
6849 cls
.lpszClassName
= classNameA
;
6851 if(!RegisterClassA(&cls
)) {
6852 trace("Register failed %d\n", GetLastError());
6856 hgrandparent
= CreateWindowA(classNameA
, "grandparent", WS_OVERLAPPEDWINDOW
,
6857 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
6859 hparent
= CreateWindowA(classNameA
, "parent", WS_CHILD
|WS_VISIBLE
,
6860 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
6862 hchild
= CreateWindowA(classNameA
, "child", WS_CHILD
|WS_VISIBLE
,
6863 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
6865 ShowWindow(hgrandparent
, SW_SHOW
);
6866 UpdateWindow(hgrandparent
);
6867 flush_events( TRUE
);
6869 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
6870 ok(!ret
, "GetUpdateRect returned not empty region\n");
6872 ShowWindow(hchild
, SW_HIDE
);
6875 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
6876 ok(!ret
, "GetUpdateRect returned not empty region\n");
6877 ok(EqualRect(&rc1
, &rc2
), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1
),
6878 wine_dbgstr_rect(&rc2
));
6880 SetRect(&rc2
, 10, 10, 40, 40);
6881 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
6882 ok(ret
, "GetUpdateRect returned empty region\n");
6883 ok(EqualRect(&rc1
, &rc2
), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1
),
6884 wine_dbgstr_rect(&rc2
));
6886 parent_wm_paint
= FALSE
;
6887 grandparent_wm_paint
= FALSE
;
6888 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
6890 if (msg
.message
== WM_PAINT
)
6892 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
6893 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
6895 DispatchMessageA(&msg
);
6897 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
6898 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
6900 DestroyWindow(hgrandparent
);
6904 static LRESULT CALLBACK
TestExposedRegion_WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
6912 const int waitTime
= 2000;
6914 BeginPaint(hwnd
, &ps
);
6916 /* create and destroy window to create an exposed region on this window */
6917 win
= CreateWindowA("static", "win", WS_VISIBLE
,
6918 10,10,50,50, NULL
, NULL
, 0, NULL
);
6921 waitResult
= MsgWaitForMultipleObjects( 0, NULL
, FALSE
, waitTime
, QS_PAINT
);
6923 ValidateRect(hwnd
, NULL
);
6924 EndPaint(hwnd
, &ps
);
6926 if(waitResult
!= WAIT_TIMEOUT
)
6928 GetUpdateRect(hwnd
, &updateRect
, FALSE
);
6929 ok(IsRectEmpty(&updateRect
), "Exposed rect should be empty\n");
6934 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
6937 static void test_Expose(void)
6942 memset(&cls
, 0, sizeof(WNDCLASSA
));
6943 cls
.lpfnWndProc
= TestExposedRegion_WndProc
;
6944 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
6945 cls
.lpszClassName
= "TestExposeClass";
6946 RegisterClassA(&cls
);
6948 mw
= CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE
|WS_OVERLAPPEDWINDOW
,
6949 0, 0, 200, 100, NULL
, NULL
, 0, NULL
);
6955 static LRESULT CALLBACK
TestNCRedraw_WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
6957 static UINT ncredrawflags
;
6963 ncredrawflags
= *(UINT
*) (((CREATESTRUCTA
*)lParam
)->lpCreateParams
);
6966 RedrawWindow(hwnd
, NULL
, NULL
, ncredrawflags
);
6969 BeginPaint(hwnd
, &ps
);
6970 EndPaint(hwnd
, &ps
);
6973 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
6976 static void run_NCRedrawLoop(UINT flags
)
6983 hwnd
= CreateWindowA("TestNCRedrawClass", "MainWindow",
6984 WS_OVERLAPPEDWINDOW
, 0, 0, 200, 100,
6985 NULL
, NULL
, 0, &flags
);
6986 ShowWindow(hwnd
, SW_SHOW
);
6988 flush_events( FALSE
);
6989 while (PeekMessageA(&msg
, hwnd
, 0, 0, PM_REMOVE
))
6991 if (msg
.message
== WM_PAINT
) loopcount
++;
6992 if (loopcount
>= 100) break;
6993 TranslateMessage(&msg
);
6994 DispatchMessageA(&msg
);
6995 MsgWaitForMultipleObjects(0, NULL
, FALSE
, 100, QS_ALLINPUT
);
6997 todo_wine_if (flags
== (RDW_INVALIDATE
| RDW_FRAME
))
6998 ok(loopcount
< 100, "Detected infinite WM_PAINT loop (%x).\n", flags
);
6999 DestroyWindow(hwnd
);
7002 static void test_NCRedraw(void)
7006 wndclass
.lpszClassName
= "TestNCRedrawClass";
7007 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
7008 wndclass
.lpfnWndProc
= TestNCRedraw_WndProc
;
7009 wndclass
.cbClsExtra
= 0;
7010 wndclass
.cbWndExtra
= 0;
7011 wndclass
.hInstance
= 0;
7012 wndclass
.hIcon
= LoadIconA(0, (LPCSTR
)IDI_APPLICATION
);
7013 wndclass
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
7014 wndclass
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
7015 wndclass
.lpszMenuName
= NULL
;
7017 RegisterClassA(&wndclass
);
7019 run_NCRedrawLoop(RDW_INVALIDATE
| RDW_FRAME
);
7020 run_NCRedrawLoop(RDW_INVALIDATE
);
7023 static void test_GetWindowModuleFileName(void)
7028 char buf1
[MAX_PATH
], buf2
[MAX_PATH
];
7030 if (!pGetWindowModuleFileNameA
)
7032 win_skip("GetWindowModuleFileNameA is not available\n");
7036 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0,0,0,0, 0, 0, 0, NULL
);
7039 hinst
= (HINSTANCE
)GetWindowLongPtrA(hwnd
, GWLP_HINSTANCE
);
7040 ok(hinst
== 0 || broken(hinst
== GetModuleHandleA(NULL
)), /* win9x */ "expected 0, got %p\n", hinst
);
7043 SetLastError(0xdeadbeef);
7044 ret1
= GetModuleFileNameA(hinst
, buf1
, sizeof(buf1
));
7045 ok(ret1
, "GetModuleFileName error %u\n", GetLastError());
7048 SetLastError(0xdeadbeef);
7049 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, sizeof(buf2
));
7050 ok(ret2
|| broken(!ret2
), /* nt4 sp 3 */
7051 "GetWindowModuleFileNameA error %u\n", GetLastError());
7055 ok(ret1
== ret2
|| broken(ret2
== ret1
+ 1), /* win98 */ "%u != %u\n", ret1
, ret2
);
7056 ok(!strcmp(buf1
, buf2
), "%s != %s\n", buf1
, buf2
);
7058 hinst
= GetModuleHandleA(NULL
);
7060 SetLastError(0xdeadbeef);
7061 ret2
= GetModuleFileNameA(hinst
, buf2
, ret1
- 2);
7062 ok(ret2
== ret1
- 2 || broken(ret2
== ret1
- 3), /* win98 */
7063 "expected %u, got %u\n", ret1
- 2, ret2
);
7064 ok(GetLastError() == 0xdeadbeef /* XP */ ||
7065 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
7066 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
7068 SetLastError(0xdeadbeef);
7069 ret2
= GetModuleFileNameA(hinst
, buf2
, 0);
7070 ok(!ret2
, "GetModuleFileName should return 0\n");
7071 ok(GetLastError() == 0xdeadbeef /* XP */ ||
7072 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
7073 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
7075 SetLastError(0xdeadbeef);
7076 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, ret1
- 2);
7077 ok(ret2
== ret1
- 2 || broken(ret2
== ret1
- 3) /* win98 */ || broken(!ret2
), /* nt4 sp3 */
7078 "expected %u, got %u\n", ret1
- 2, ret2
);
7079 ok(GetLastError() == 0xdeadbeef /* XP */ ||
7080 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
7081 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
7083 SetLastError(0xdeadbeef);
7084 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, 0);
7085 ok(!ret2
, "expected 0, got %u\n", ret2
);
7086 ok(GetLastError() == 0xdeadbeef /* XP */ ||
7087 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
7088 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
7090 DestroyWindow(hwnd
);
7093 hwnd
= (HWND
)0xdeadbeef;
7094 SetLastError(0xdeadbeef);
7095 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
7096 ok(!ret1
, "expected 0, got %u\n", ret1
);
7097 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
|| broken(GetLastError() == 0xdeadbeef), /* win9x */
7098 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
7100 hwnd
= FindWindowA("Shell_TrayWnd", NULL
);
7101 ok(IsWindow(hwnd
) || broken(!hwnd
), "got invalid tray window %p\n", hwnd
);
7102 SetLastError(0xdeadbeef);
7103 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
7104 ok(!ret1
|| broken(ret1
), /* win98 */ "expected 0, got %u\n", ret1
);
7106 if (!ret1
) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
7108 ret1
= GetModuleFileNameA(0, buf1
, sizeof(buf1
));
7109 hwnd
= GetDesktopWindow();
7110 ok(IsWindow(hwnd
), "got invalid desktop window %p\n", hwnd
);
7111 SetLastError(0xdeadbeef);
7112 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, sizeof(buf2
));
7114 ret1
== ret2
|| /* vista */
7115 broken(ret2
), /* some win98 return user.exe as file name */
7116 "expected 0 or %u, got %u %s\n", ret1
, ret2
, buf2
);
7120 static void test_hwnd_message(void)
7122 static const WCHAR mainwindowclassW
[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
7123 static const WCHAR message_windowW
[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
7125 HWND parent
= 0, hwnd
, found
;
7128 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
7129 on CreateWindowExA and crash later in the test.
7130 Use UNICODE here to fail on win9x */
7131 hwnd
= CreateWindowExW(0, mainwindowclassW
, message_windowW
, WS_CAPTION
| WS_VISIBLE
,
7132 100, 100, 200, 200, HWND_MESSAGE
, 0, 0, NULL
);
7135 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
7139 ok( !GetParent(hwnd
), "GetParent should return 0 for message only windows\n" );
7143 HWND root
, desktop
= GetDesktopWindow();
7145 parent
= pGetAncestor(hwnd
, GA_PARENT
);
7146 ok(parent
!= 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
7147 ok(parent
!= desktop
, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
7148 root
= pGetAncestor(hwnd
, GA_ROOT
);
7149 ok(root
== hwnd
, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
7150 ok( !pGetAncestor(parent
, GA_PARENT
) || broken(pGetAncestor(parent
, GA_PARENT
) != 0), /* win2k */
7151 "parent shouldn't have parent %p\n", pGetAncestor(parent
, GA_PARENT
) );
7152 trace("parent %p root %p desktop %p\n", parent
, root
, desktop
);
7153 if (!GetClassNameA( parent
, buffer
, sizeof(buffer
) )) buffer
[0] = 0;
7154 ok( !lstrcmpiA( buffer
, "Message" ), "wrong parent class '%s'\n", buffer
);
7155 GetWindowRect( parent
, &rect
);
7156 ok( rect
.left
== 0 && rect
.right
== 100 && rect
.top
== 0 && rect
.bottom
== 100,
7157 "wrong parent rect %s\n", wine_dbgstr_rect( &rect
));
7159 GetWindowRect( hwnd
, &rect
);
7160 ok( rect
.left
== 100 && rect
.right
== 300 && rect
.top
== 100 && rect
.bottom
== 300,
7161 "wrong window rect %s\n", wine_dbgstr_rect( &rect
));
7163 /* test FindWindow behavior */
7165 found
= FindWindowExA( 0, 0, 0, "message window" );
7166 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
7167 SetLastError(0xdeadbeef);
7168 found
= FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
7169 ok( found
== 0, "found message window %p/%p\n", found
, hwnd
);
7170 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
7173 found
= FindWindowExA( parent
, 0, 0, "message window" );
7174 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
7177 /* test IsChild behavior */
7179 if (parent
) ok( !IsChild( parent
, hwnd
), "HWND_MESSAGE is child of top window\n" );
7181 /* test IsWindowVisible behavior */
7183 ok( !IsWindowVisible( hwnd
), "HWND_MESSAGE window is visible\n" );
7184 if (parent
) ok( !IsWindowVisible( parent
), "HWND_MESSAGE parent is visible\n" );
7186 DestroyWindow(hwnd
);
7189 static void test_layered_window(void)
7195 POINT pt
= { 0, 0 };
7196 SIZE sz
= { 200, 200 };
7201 if (!pGetLayeredWindowAttributes
|| !pSetLayeredWindowAttributes
|| !pUpdateLayeredWindow
)
7203 win_skip( "layered windows not supported\n" );
7207 hdc
= CreateCompatibleDC( 0 );
7208 hbm
= CreateCompatibleBitmap( hdc
, 200, 200 );
7209 SelectObject( hdc
, hbm
);
7211 hwnd
= CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION
,
7212 100, 100, 200, 200, 0, 0, 0, NULL
);
7214 SetLastError( 0xdeadbeef );
7215 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
);
7216 ok( !ret
, "UpdateLayeredWindow should fail on non-layered window\n" );
7217 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
7218 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
7219 ok( !ret
, "GetLayeredWindowAttributes should fail on non-layered window\n" );
7220 ret
= pSetLayeredWindowAttributes( hwnd
, 0, 0, LWA_ALPHA
);
7221 ok( !ret
, "SetLayeredWindowAttributes should fail on non-layered window\n" );
7222 SetWindowLongA( hwnd
, GWL_EXSTYLE
, GetWindowLongA(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
7223 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
7224 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
7225 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
);
7226 ok( ret
, "UpdateLayeredWindow should succeed on layered window\n" );
7227 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
7228 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
7229 ret
= pSetLayeredWindowAttributes( hwnd
, 0x123456, 44, LWA_ALPHA
);
7230 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
7231 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
7232 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
7233 ok( key
== 0x123456 || key
== 0, "wrong color key %x\n", key
);
7234 ok( alpha
== 44, "wrong alpha %u\n", alpha
);
7235 ok( flags
== LWA_ALPHA
, "wrong flags %x\n", flags
);
7236 SetLastError( 0xdeadbeef );
7237 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
);
7238 ok( !ret
, "UpdateLayeredWindow should fail on layered but initialized window\n" );
7239 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
7241 /* clearing WS_EX_LAYERED resets attributes */
7242 SetWindowLongA( hwnd
, GWL_EXSTYLE
, GetWindowLongA(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
7243 SetLastError( 0xdeadbeef );
7244 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
);
7245 ok( !ret
, "UpdateLayeredWindow should fail on non-layered window\n" );
7246 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
7247 ok( !ret
, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
7248 SetWindowLongA( hwnd
, GWL_EXSTYLE
, GetWindowLongA(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
7249 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
7250 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
7251 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
);
7252 ok( ret
, "UpdateLayeredWindow should succeed on layered window\n" );
7253 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
| ULW_EX_NORESIZE
);
7254 ok( !ret
, "UpdateLayeredWindow should fail with ex flag\n" );
7255 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %u\n", GetLastError() );
7256 if (pUpdateLayeredWindowIndirect
)
7258 UPDATELAYEREDWINDOWINFO info
;
7259 info
.cbSize
= sizeof(info
);
7267 info
.dwFlags
= ULW_OPAQUE
| ULW_EX_NORESIZE
;
7268 info
.prcDirty
= NULL
;
7269 ret
= pUpdateLayeredWindowIndirect( hwnd
, &info
);
7270 ok( ret
, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
7273 ret
= pUpdateLayeredWindowIndirect( hwnd
, &info
);
7274 ok( !ret
, "UpdateLayeredWindowIndirect should fail\n" );
7275 /* particular error code differs from version to version, could be ERROR_INCORRECT_SIZE,
7276 ERROR_MR_MID_NOT_FOUND or ERROR_GEN_FAILURE (Win8/Win10) */
7277 ok( GetLastError() != 0, "wrong error %u\n", GetLastError() );
7278 info
.dwFlags
= ULW_OPAQUE
;
7279 ret
= pUpdateLayeredWindowIndirect( hwnd
, &info
);
7280 ok( ret
, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
7282 info
.dwFlags
= ULW_OPAQUE
| 0xf00;
7283 ret
= pUpdateLayeredWindowIndirect( hwnd
, &info
);
7284 ok( !ret
, "UpdateLayeredWindowIndirect should fail\n" );
7285 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %u\n", GetLastError() );
7287 info
.dwFlags
= ULW_OPAQUE
;
7288 ret
= pUpdateLayeredWindowIndirect( hwnd
, &info
);
7289 ok( !ret
, "UpdateLayeredWindowIndirect should fail\n" );
7290 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %u\n", GetLastError() );
7291 ret
= pUpdateLayeredWindowIndirect( hwnd
, NULL
);
7292 ok( !ret
, "UpdateLayeredWindowIndirect should fail\n" );
7293 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %u\n", GetLastError() );
7296 ret
= pSetLayeredWindowAttributes( hwnd
, 0x654321, 22, LWA_COLORKEY
| LWA_ALPHA
);
7297 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
7298 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
7299 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
7300 ok( key
== 0x654321, "wrong color key %x\n", key
);
7301 ok( alpha
== 22, "wrong alpha %u\n", alpha
);
7302 ok( flags
== (LWA_COLORKEY
| LWA_ALPHA
), "wrong flags %x\n", flags
);
7303 SetLastError( 0xdeadbeef );
7304 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
);
7305 ok( !ret
, "UpdateLayeredWindow should fail on layered but initialized window\n" );
7306 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
7308 ret
= pSetLayeredWindowAttributes( hwnd
, 0x888888, 33, LWA_COLORKEY
);
7309 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
7311 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
7312 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
7313 ok( key
== 0x888888, "wrong color key %x\n", key
);
7314 /* alpha not changed on vista if LWA_ALPHA is not set */
7315 ok( alpha
== 22 || alpha
== 33, "wrong alpha %u\n", alpha
);
7316 ok( flags
== LWA_COLORKEY
, "wrong flags %x\n", flags
);
7318 /* color key may or may not be changed without LWA_COLORKEY */
7319 ret
= pSetLayeredWindowAttributes( hwnd
, 0x999999, 44, 0 );
7320 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
7322 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
7323 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
7324 ok( key
== 0x888888 || key
== 0x999999, "wrong color key %x\n", key
);
7325 ok( alpha
== 22 || alpha
== 44, "wrong alpha %u\n", alpha
);
7326 ok( flags
== 0, "wrong flags %x\n", flags
);
7328 /* default alpha and color key is 0 */
7329 SetWindowLongA( hwnd
, GWL_EXSTYLE
, GetWindowLongA(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
7330 SetWindowLongA( hwnd
, GWL_EXSTYLE
, GetWindowLongA(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
7331 ret
= pSetLayeredWindowAttributes( hwnd
, 0x222222, 55, 0 );
7332 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
7333 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
7334 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
7335 ok( key
== 0 || key
== 0x222222, "wrong color key %x\n", key
);
7336 ok( alpha
== 0 || alpha
== 55, "wrong alpha %u\n", alpha
);
7337 ok( flags
== 0, "wrong flags %x\n", flags
);
7339 DestroyWindow( hwnd
);
7341 DeleteObject( hbm
);
7344 static MONITORINFO mi
;
7346 static LRESULT CALLBACK
fullscreen_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
7352 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
7353 ok(cs
->x
== mi
.rcMonitor
.left
&& cs
->y
== mi
.rcMonitor
.top
&&
7354 cs
->cx
== mi
.rcMonitor
.right
&& cs
->cy
== mi
.rcMonitor
.bottom
,
7355 "expected %s, got (%d,%d)-(%d,%d)\n", wine_dbgstr_rect(&mi
.rcMonitor
),
7356 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
7359 case WM_GETMINMAXINFO
:
7361 MINMAXINFO
*minmax
= (MINMAXINFO
*)lp
;
7362 ok(minmax
->ptMaxPosition
.x
<= mi
.rcMonitor
.left
, "%d <= %d\n", minmax
->ptMaxPosition
.x
, mi
.rcMonitor
.left
);
7363 ok(minmax
->ptMaxPosition
.y
<= mi
.rcMonitor
.top
, "%d <= %d\n", minmax
->ptMaxPosition
.y
, mi
.rcMonitor
.top
);
7364 ok(minmax
->ptMaxSize
.x
>= mi
.rcMonitor
.right
, "%d >= %d\n", minmax
->ptMaxSize
.x
, mi
.rcMonitor
.right
);
7365 ok(minmax
->ptMaxSize
.y
>= mi
.rcMonitor
.bottom
, "%d >= %d\n", minmax
->ptMaxSize
.y
, mi
.rcMonitor
.bottom
);
7369 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
7372 static void test_fullscreen(void)
7374 static const DWORD t_style
[] = {
7375 WS_OVERLAPPED
, WS_POPUP
, WS_CHILD
, WS_THICKFRAME
, WS_DLGFRAME
7377 static const DWORD t_ex_style
[] = {
7378 0, WS_EX_APPWINDOW
, WS_EX_TOOLWINDOW
7388 if (!pGetMonitorInfoA
|| !pMonitorFromPoint
)
7390 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
7395 SetLastError(0xdeadbeef);
7396 hmon
= pMonitorFromPoint(pt
, MONITOR_DEFAULTTOPRIMARY
);
7397 ok(hmon
!= 0, "MonitorFromPoint error %u\n", GetLastError());
7399 mi
.cbSize
= sizeof(mi
);
7400 SetLastError(0xdeadbeef);
7401 ret
= pGetMonitorInfoA(hmon
, &mi
);
7402 ok(ret
, "GetMonitorInfo error %u\n", GetLastError());
7403 trace("monitor %s, work %s\n", wine_dbgstr_rect(&mi
.rcMonitor
), wine_dbgstr_rect(&mi
.rcWork
));
7406 cls
.lpfnWndProc
= fullscreen_wnd_proc
;
7409 cls
.hInstance
= GetModuleHandleA(NULL
);
7411 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
7412 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
7413 cls
.lpszMenuName
= NULL
;
7414 cls
.lpszClassName
= "fullscreen_class";
7415 RegisterClassA(&cls
);
7417 for (i
= 0; i
< sizeof(t_style
)/sizeof(t_style
[0]); i
++)
7419 DWORD style
, ex_style
;
7421 /* avoid a WM interaction */
7422 assert(!(t_style
[i
] & WS_VISIBLE
));
7424 for (j
= 0; j
< sizeof(t_ex_style
)/sizeof(t_ex_style
[0]); j
++)
7429 ex_style
= t_ex_style
[j
];
7431 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
7432 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
7433 GetDesktopWindow(), 0, GetModuleHandleA(NULL
), NULL
);
7434 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
7435 GetWindowRect(hwnd
, &rc
);
7436 trace("%#x/%#x: window rect %s\n", ex_style
, style
, wine_dbgstr_rect(&rc
));
7437 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
7438 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
7439 "%#x/%#x: window rect %s\n", ex_style
, style
, wine_dbgstr_rect(&rc
));
7440 DestroyWindow(hwnd
);
7442 style
= t_style
[i
] | WS_MAXIMIZE
;
7443 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
7444 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
7445 GetDesktopWindow(), 0, GetModuleHandleA(NULL
), NULL
);
7446 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
7447 GetWindowRect(hwnd
, &rc
);
7448 trace("%#x/%#x: window rect %s\n", ex_style
, style
, wine_dbgstr_rect(&rc
));
7449 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
7450 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
7451 "%#x/%#x: window rect %s\n", ex_style
, style
, wine_dbgstr_rect(&rc
));
7452 DestroyWindow(hwnd
);
7454 style
= t_style
[i
] | WS_MAXIMIZE
| WS_CAPTION
;
7455 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
7456 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
7457 GetDesktopWindow(), 0, GetModuleHandleA(NULL
), NULL
);
7458 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
7459 GetWindowRect(hwnd
, &rc
);
7460 trace("%#x/%#x: window rect %s\n", ex_style
, style
, wine_dbgstr_rect(&rc
));
7461 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
7462 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
7463 "%#x/%#x: window rect %s\n", ex_style
, style
, wine_dbgstr_rect(&rc
));
7464 DestroyWindow(hwnd
);
7466 style
= t_style
[i
] | WS_CAPTION
| WS_MAXIMIZEBOX
;
7467 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
7468 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
7469 GetDesktopWindow(), 0, GetModuleHandleA(NULL
), NULL
);
7470 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
7471 GetWindowRect(hwnd
, &rc
);
7472 trace("%#x/%#x: window rect %s\n", ex_style
, style
, wine_dbgstr_rect(&rc
));
7473 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
7474 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
7475 "%#x/%#x: window rect %s\n", ex_style
, style
, wine_dbgstr_rect(&rc
));
7476 DestroyWindow(hwnd
);
7478 style
= t_style
[i
] | WS_MAXIMIZE
| WS_CAPTION
| WS_MAXIMIZEBOX
;
7479 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
7480 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
7481 GetDesktopWindow(), 0, GetModuleHandleA(NULL
), NULL
);
7482 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
7483 GetWindowRect(hwnd
, &rc
);
7484 trace("%#x/%#x: window rect %s\n", ex_style
, style
, wine_dbgstr_rect(&rc
));
7485 /* Windows makes a maximized window slightly larger (to hide the borders?) */
7486 fixup
= min(abs(rc
.left
), abs(rc
.top
));
7487 InflateRect(&rc
, -fixup
, -fixup
);
7488 ok(rc
.left
>= mi
.rcMonitor
.left
&& rc
.top
>= mi
.rcMonitor
.top
&&
7489 rc
.right
<= mi
.rcMonitor
.right
&& rc
.bottom
<= mi
.rcMonitor
.bottom
,
7490 "%#x/%#x: window rect %s must be in %s\n", ex_style
, style
, wine_dbgstr_rect(&rc
),
7491 wine_dbgstr_rect(&mi
.rcMonitor
));
7492 DestroyWindow(hwnd
);
7494 style
= t_style
[i
] | WS_MAXIMIZE
| WS_MAXIMIZEBOX
;
7495 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
7496 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
7497 GetDesktopWindow(), 0, GetModuleHandleA(NULL
), NULL
);
7498 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
7499 GetWindowRect(hwnd
, &rc
);
7500 trace("%#x/%#x: window rect %s\n", ex_style
, style
, wine_dbgstr_rect(&rc
));
7501 /* Windows makes a maximized window slightly larger (to hide the borders?) */
7502 fixup
= min(abs(rc
.left
), abs(rc
.top
));
7503 InflateRect(&rc
, -fixup
, -fixup
);
7504 if (style
& (WS_CHILD
| WS_POPUP
))
7505 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
7506 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
7507 "%#x/%#x: window rect %s\n", ex_style
, style
, wine_dbgstr_rect(&rc
));
7509 ok(rc
.left
>= mi
.rcMonitor
.left
&& rc
.top
>= mi
.rcMonitor
.top
&&
7510 rc
.right
<= mi
.rcMonitor
.right
&& rc
.bottom
<= mi
.rcMonitor
.bottom
,
7511 "%#x/%#x: window rect %s\n", ex_style
, style
, wine_dbgstr_rect(&rc
));
7512 DestroyWindow(hwnd
);
7516 UnregisterClassA("fullscreen_class", GetModuleHandleA(NULL
));
7519 static BOOL test_thick_child_got_minmax
;
7520 static const char * test_thick_child_name
;
7521 static LONG test_thick_child_style
;
7522 static LONG test_thick_child_exStyle
;
7524 static LRESULT WINAPI
test_thick_child_size_winproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
7527 int expectedMinTrackX
;
7528 int expectedMinTrackY
;
7529 int actualMinTrackX
;
7530 int actualMinTrackY
;
7531 int expectedMaxTrackX
;
7532 int expectedMaxTrackY
;
7533 int actualMaxTrackX
;
7534 int actualMaxTrackY
;
7535 int expectedMaxSizeX
;
7536 int expectedMaxSizeY
;
7547 case WM_GETMINMAXINFO
:
7549 minmax
= (MINMAXINFO
*)lparam
;
7550 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
7551 dump_minmax_info( minmax
);
7553 test_thick_child_got_minmax
= TRUE
;
7556 adjustedStyle
= test_thick_child_style
;
7557 if ((adjustedStyle
& WS_CAPTION
) == WS_CAPTION
)
7558 adjustedStyle
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
7559 GetClientRect(GetParent(hwnd
), &rect
);
7560 AdjustWindowRectEx(&rect
, adjustedStyle
, FALSE
, test_thick_child_exStyle
);
7562 if (test_thick_child_style
& (WS_DLGFRAME
| WS_BORDER
))
7564 expectedMinTrackX
= GetSystemMetrics(SM_CXMINTRACK
);
7565 expectedMinTrackY
= GetSystemMetrics(SM_CYMINTRACK
);
7569 expectedMinTrackX
= -2 * rect
.left
;
7570 expectedMinTrackY
= -2 * rect
.top
;
7572 actualMinTrackX
= minmax
->ptMinTrackSize
.x
;
7573 actualMinTrackY
= minmax
->ptMinTrackSize
.y
;
7575 ok(actualMinTrackX
== expectedMinTrackX
&& actualMinTrackY
== expectedMinTrackY
,
7576 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
7577 expectedMinTrackX
, expectedMinTrackY
, actualMinTrackX
, actualMinTrackY
,
7578 test_thick_child_name
);
7580 actualMaxTrackX
= minmax
->ptMaxTrackSize
.x
;
7581 actualMaxTrackY
= minmax
->ptMaxTrackSize
.y
;
7582 expectedMaxTrackX
= GetSystemMetrics(SM_CXMAXTRACK
);
7583 expectedMaxTrackY
= GetSystemMetrics(SM_CYMAXTRACK
);
7584 ok(actualMaxTrackX
== expectedMaxTrackX
&& actualMaxTrackY
== expectedMaxTrackY
,
7585 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
7586 expectedMaxTrackX
, expectedMaxTrackY
, actualMaxTrackX
, actualMaxTrackY
,
7587 test_thick_child_name
);
7589 expectedMaxSizeX
= rect
.right
- rect
.left
;
7590 expectedMaxSizeY
= rect
.bottom
- rect
.top
;
7591 actualMaxSizeX
= minmax
->ptMaxSize
.x
;
7592 actualMaxSizeY
= minmax
->ptMaxSize
.y
;
7594 ok(actualMaxSizeX
== expectedMaxSizeX
&& actualMaxSizeY
== expectedMaxSizeY
,
7595 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
7596 expectedMaxSizeX
, expectedMaxSizeY
, actualMaxSizeX
, actualMaxSizeY
,
7597 test_thick_child_name
);
7600 expectedPosX
= rect
.left
;
7601 expectedPosY
= rect
.top
;
7602 actualPosX
= minmax
->ptMaxPosition
.x
;
7603 actualPosY
= minmax
->ptMaxPosition
.y
;
7604 ok(actualPosX
== expectedPosX
&& actualPosY
== expectedPosY
,
7605 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
7606 expectedPosX
, expectedPosY
, actualPosX
, actualPosY
, test_thick_child_name
);
7612 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
7615 #define NUMBER_OF_THICK_CHILD_TESTS 16
7616 static void test_thick_child_size(HWND parentWindow
)
7620 RECT adjustedParentRect
;
7625 LONG expectedHeight
;
7627 static const char className
[] = "THICK_CHILD_CLASS";
7630 static const LONG styles
[NUMBER_OF_THICK_CHILD_TESTS
] = {
7631 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
7632 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
7633 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
7634 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
7635 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
7636 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
7637 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
7638 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
7639 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
7640 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
7641 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
7642 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
7643 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
7644 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
7645 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
7646 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
7649 static const LONG exStyles
[NUMBER_OF_THICK_CHILD_TESTS
] = {
7654 WS_EX_DLGMODALFRAME
,
7655 WS_EX_DLGMODALFRAME
,
7656 WS_EX_DLGMODALFRAME
,
7657 WS_EX_DLGMODALFRAME
,
7662 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
7663 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
7664 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
7665 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
7667 static const char *styleName
[NUMBER_OF_THICK_CHILD_TESTS
] = {
7668 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
7669 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
7670 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
7671 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
7672 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
7673 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
7674 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
7675 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
7676 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
7677 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
7678 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
7679 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
7680 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
7681 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
7682 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
7683 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
7687 cls
.lpfnWndProc
= test_thick_child_size_winproc
;
7690 cls
.hInstance
= GetModuleHandleA(0);
7692 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
7693 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
7694 cls
.lpszMenuName
= NULL
;
7695 cls
.lpszClassName
= className
;
7696 SetLastError(0xdeadbeef);
7697 success
= RegisterClassA(&cls
);
7698 ok(success
,"RegisterClassA failed, error: %u\n", GetLastError());
7700 for(i
= 0; i
< NUMBER_OF_THICK_CHILD_TESTS
; i
++)
7702 test_thick_child_name
= styleName
[i
];
7703 test_thick_child_style
= styles
[i
];
7704 test_thick_child_exStyle
= exStyles
[i
];
7705 test_thick_child_got_minmax
= FALSE
;
7707 SetLastError(0xdeadbeef);
7708 childWindow
= CreateWindowExA( exStyles
[i
], className
, "", styles
[i
], 0, 0, 0, 0, parentWindow
, 0, GetModuleHandleA(0), NULL
);
7709 ok(childWindow
!= NULL
, "Failed to create child window, error: %u\n", GetLastError());
7711 ok(test_thick_child_got_minmax
, "Got no WM_GETMINMAXINFO\n");
7713 SetLastError(0xdeadbeef);
7714 success
= GetWindowRect(childWindow
, &childRect
);
7715 ok(success
,"GetWindowRect call failed, error: %u\n", GetLastError());
7716 childWidth
= childRect
.right
- childRect
.left
;
7717 childHeight
= childRect
.bottom
- childRect
.top
;
7719 adjustedStyle
= styles
[i
];
7720 if ((adjustedStyle
& WS_CAPTION
) == WS_CAPTION
)
7721 adjustedStyle
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
7722 GetClientRect(GetParent(childWindow
), &adjustedParentRect
);
7723 AdjustWindowRectEx(&adjustedParentRect
, adjustedStyle
, FALSE
, test_thick_child_exStyle
);
7726 if (test_thick_child_style
& (WS_DLGFRAME
| WS_BORDER
))
7728 expectedWidth
= GetSystemMetrics(SM_CXMINTRACK
);
7729 expectedHeight
= GetSystemMetrics(SM_CYMINTRACK
);
7733 expectedWidth
= -2 * adjustedParentRect
.left
;
7734 expectedHeight
= -2 * adjustedParentRect
.top
;
7737 ok((childWidth
== expectedWidth
) && (childHeight
== expectedHeight
),
7738 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
7739 test_thick_child_name
, expectedWidth
, expectedHeight
, childWidth
, childHeight
);
7741 SetLastError(0xdeadbeef);
7742 success
= DestroyWindow(childWindow
);
7743 ok(success
,"DestroyWindow call failed, error: %u\n", GetLastError());
7745 ok(UnregisterClassA(className
, GetModuleHandleA(NULL
)),"UnregisterClass call failed\n");
7748 static void test_handles( HWND full_hwnd
)
7750 HWND hwnd
= full_hwnd
;
7754 SetLastError( 0xdeadbeef );
7755 ret
= GetWindowRect( hwnd
, &rect
);
7756 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
7759 if ((ULONG_PTR
)full_hwnd
>> 32)
7760 hwnd
= (HWND
)((ULONG_PTR
)full_hwnd
& ~0u);
7762 hwnd
= (HWND
)((ULONG_PTR
)full_hwnd
| ((ULONG_PTR
)~0u << 32));
7763 SetLastError( 0xdeadbeef );
7764 ret
= GetWindowRect( hwnd
, &rect
);
7765 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
7767 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& ~0u) | ((ULONG_PTR
)0x1234 << 32));
7768 SetLastError( 0xdeadbeef );
7769 ret
= GetWindowRect( hwnd
, &rect
);
7770 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
7772 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& 0xffff) | ((ULONG_PTR
)0x9876 << 16));
7773 SetLastError( 0xdeadbeef );
7774 ret
= GetWindowRect( hwnd
, &rect
);
7775 ok( !ret
, "GetWindowRect succeeded for %p\n", hwnd
);
7776 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "wrong error %u\n", GetLastError() );
7778 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& 0xffff) | ((ULONG_PTR
)0x12345678 << 16));
7779 SetLastError( 0xdeadbeef );
7780 ret
= GetWindowRect( hwnd
, &rect
);
7781 ok( !ret
, "GetWindowRect succeeded for %p\n", hwnd
);
7782 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "wrong error %u\n", GetLastError() );
7786 static void test_winregion(void)
7793 if (!pGetWindowRgnBox
)
7795 win_skip("GetWindowRgnBox not supported\n");
7799 hwnd
= CreateWindowExA(0, "static", NULL
, WS_VISIBLE
, 10, 10, 10, 10, NULL
, 0, 0, NULL
);
7801 SetLastError(0xdeadbeef);
7802 ret
= pGetWindowRgnBox(hwnd
, NULL
);
7803 ok( ret
== ERROR
, "Expected ERROR, got %d\n", ret
);
7804 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
7806 hrgn
= CreateRectRgn(2, 3, 10, 15);
7807 ok( hrgn
!= NULL
, "Region creation failed\n");
7810 SetWindowRgn(hwnd
, hrgn
, FALSE
);
7812 SetLastError(0xdeadbeef);
7813 ret
= pGetWindowRgnBox(hwnd
, NULL
);
7814 ok( ret
== ERROR
, "Expected ERROR, got %d\n", ret
);
7815 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
7818 ret
= pGetWindowRgnBox(hwnd
, &r
);
7819 ok( ret
== SIMPLEREGION
, "Expected SIMPLEREGION, got %d\n", ret
);
7820 ok( r
.left
== 2 && r
.top
== 3 && r
.right
== 10 && r
.bottom
== 15,
7821 "Expected (2,3)-(10,15), got %s\n", wine_dbgstr_rect( &r
));
7824 hrgn
= CreateRectRgn(2, 3, 10, 15);
7825 ret
= pMirrorRgn( hwnd
, hrgn
);
7826 ok( ret
== TRUE
, "MirrorRgn failed %u\n", ret
);
7828 GetWindowRect( hwnd
, &r
);
7829 width
= r
.right
- r
.left
;
7831 ret
= GetRgnBox( hrgn
, &r
);
7832 ok( ret
== SIMPLEREGION
, "GetRgnBox failed %u\n", ret
);
7833 ok( r
.left
== width
- 10 && r
.top
== 3 && r
.right
== width
- 2 && r
.bottom
== 15,
7834 "Wrong rectangle %s for width %d\n", wine_dbgstr_rect( &r
), width
);
7836 else win_skip( "MirrorRgn not supported\n" );
7838 DestroyWindow(hwnd
);
7841 static void test_rtl_layout(void)
7847 if (!pSetProcessDefaultLayout
)
7849 win_skip( "SetProcessDefaultLayout not supported\n" );
7853 parent
= CreateWindowExA(WS_EX_LAYOUTRTL
, "static", NULL
, WS_POPUP
, 100, 100, 300, 300, NULL
, 0, 0, NULL
);
7854 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 10, 10, 20, 20, parent
, 0, 0, NULL
);
7856 GetWindowRect( parent
, &r
);
7857 ok( r
.left
== 100 && r
.right
== 400, "wrong rect %s\n", wine_dbgstr_rect( &r
));
7858 GetClientRect( parent
, &r
);
7859 ok( r
.left
== 0 && r
.right
== 300, "wrong rect %s\n", wine_dbgstr_rect( &r
));
7860 GetClientRect( child
, &r
);
7861 ok( r
.left
== 0 && r
.right
== 20, "wrong rect %s\n", wine_dbgstr_rect( &r
));
7862 MapWindowPoints( child
, parent
, (POINT
*)&r
, 2 );
7863 ok( r
.left
== 10 && r
.right
== 30, "wrong rect %s\n", wine_dbgstr_rect( &r
));
7864 GetWindowRect( child
, &r
);
7865 ok( r
.left
== 370 && r
.right
== 390, "wrong rect %s\n", wine_dbgstr_rect( &r
));
7866 MapWindowPoints( NULL
, parent
, (POINT
*)&r
, 2 );
7867 ok( r
.left
== 10 && r
.right
== 30, "wrong rect %s\n", wine_dbgstr_rect( &r
));
7868 GetWindowRect( child
, &r
);
7869 MapWindowPoints( NULL
, parent
, (POINT
*)&r
, 1 );
7870 MapWindowPoints( NULL
, parent
, (POINT
*)&r
+ 1, 1 );
7871 ok( r
.left
== 30 && r
.right
== 10, "wrong rect %s\n", wine_dbgstr_rect( &r
));
7873 MapWindowPoints( child
, parent
, &pt
, 1 );
7874 ok( pt
.x
== 22 && pt
.y
== 22, "wrong point %d,%d\n", pt
.x
, pt
.y
);
7875 SetWindowPos( parent
, 0, 0, 0, 250, 250, SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
7876 GetWindowRect( parent
, &r
);
7877 ok( r
.left
== 100 && r
.right
== 350, "wrong rect %s\n", wine_dbgstr_rect( &r
));
7878 GetWindowRect( child
, &r
);
7879 ok( r
.left
== 320 && r
.right
== 340, "wrong rect %s\n", wine_dbgstr_rect( &r
));
7880 SetWindowLongW( parent
, GWL_EXSTYLE
, 0 );
7881 GetWindowRect( child
, &r
);
7882 ok( r
.left
== 320 && r
.right
== 340, "wrong rect %s\n", wine_dbgstr_rect( &r
));
7883 MapWindowPoints( NULL
, parent
, (POINT
*)&r
, 2 );
7884 ok( r
.left
== 220 && r
.right
== 240, "wrong rect %s\n", wine_dbgstr_rect( &r
));
7885 SetWindowLongW( parent
, GWL_EXSTYLE
, WS_EX_LAYOUTRTL
);
7886 GetWindowRect( child
, &r
);
7887 ok( r
.left
== 320 && r
.right
== 340, "wrong rect %s\n", wine_dbgstr_rect( &r
));
7888 MapWindowPoints( NULL
, parent
, (POINT
*)&r
, 2 );
7889 ok( r
.left
== 10 && r
.right
== 30, "wrong rect %s\n", wine_dbgstr_rect( &r
));
7890 SetWindowPos( child
, 0, 0, 0, 30, 30, SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
7891 GetWindowRect( child
, &r
);
7892 ok( r
.left
== 310 && r
.right
== 340, "wrong rect %s\n", wine_dbgstr_rect( &r
));
7893 MapWindowPoints( NULL
, parent
, (POINT
*)&r
, 2 );
7894 ok( r
.left
== 10 && r
.right
== 40, "wrong rect %s\n", wine_dbgstr_rect( &r
));
7895 DestroyWindow( child
);
7896 DestroyWindow( parent
);
7899 static void test_FlashWindow(void)
7905 win_skip( "FlashWindow not supported\n" );
7909 hwnd
= CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_POPUP
,
7910 0, 0, 0, 0, 0, 0, 0, NULL
);
7911 ok( hwnd
!= 0, "CreateWindowExA error %d\n", GetLastError() );
7913 SetLastError( 0xdeadbeef );
7914 ret
= pFlashWindow( NULL
, TRUE
);
7915 ok( !ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
7916 "FlashWindow returned with %d\n", GetLastError() );
7918 DestroyWindow( hwnd
);
7920 SetLastError( 0xdeadbeef );
7921 ret
= pFlashWindow( hwnd
, TRUE
);
7922 ok( !ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
7923 "FlashWindow returned with %d\n", GetLastError() );
7926 static void test_FlashWindowEx(void)
7932 if (!pFlashWindowEx
)
7934 win_skip( "FlashWindowEx not supported\n" );
7938 hwnd
= CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_POPUP
,
7939 0, 0, 0, 0, 0, 0, 0, NULL
);
7940 ok( hwnd
!= 0, "CreateWindowExA error %d\n", GetLastError() );
7942 finfo
.cbSize
= sizeof(FLASHWINFO
);
7943 finfo
.dwFlags
= FLASHW_TIMER
;
7945 finfo
.dwTimeout
= 200;
7947 SetLastError(0xdeadbeef);
7948 ret
= pFlashWindowEx(&finfo
);
7949 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
7950 "FlashWindowEx returned with %d\n", GetLastError());
7953 SetLastError(0xdeadbeef);
7954 ret
= pFlashWindowEx(NULL
);
7955 ok(!ret
&& GetLastError() == ERROR_NOACCESS
,
7956 "FlashWindowEx returned with %d\n", GetLastError());
7958 SetLastError(0xdeadbeef);
7959 ret
= pFlashWindowEx(&finfo
);
7960 todo_wine
ok(!ret
, "previous window state should not be active\n");
7962 finfo
.cbSize
= sizeof(FLASHWINFO
) - 1;
7963 SetLastError(0xdeadbeef);
7964 ret
= pFlashWindowEx(&finfo
);
7965 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
7966 "FlashWindowEx succeeded\n");
7968 finfo
.cbSize
= sizeof(FLASHWINFO
) + 1;
7969 SetLastError(0xdeadbeef);
7970 ret
= pFlashWindowEx(&finfo
);
7971 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
7972 "FlashWindowEx succeeded\n");
7973 finfo
.cbSize
= sizeof(FLASHWINFO
);
7975 DestroyWindow( hwnd
);
7977 SetLastError(0xdeadbeef);
7978 ret
= pFlashWindowEx(&finfo
);
7979 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
7980 "FlashWindowEx returned with %d\n", GetLastError());
7982 ok(finfo
.cbSize
== sizeof(FLASHWINFO
), "FlashWindowEx modified cdSize to %x\n", finfo
.cbSize
);
7983 ok(finfo
.hwnd
== hwnd
, "FlashWindowEx modified hwnd to %p\n", finfo
.hwnd
);
7984 ok(finfo
.dwFlags
== FLASHW_TIMER
, "FlashWindowEx modified dwFlags to %x\n", finfo
.dwFlags
);
7985 ok(finfo
.uCount
== 3, "FlashWindowEx modified uCount to %x\n", finfo
.uCount
);
7986 ok(finfo
.dwTimeout
== 200, "FlashWindowEx modified dwTimeout to %x\n", finfo
.dwTimeout
);
7988 hwnd
= CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_VISIBLE
| WS_POPUPWINDOW
,
7989 0, 0, 0, 0, 0, 0, 0, NULL
);
7990 ok( hwnd
!= 0, "CreateWindowExA error %d\n", GetLastError() );
7993 SetLastError(0xdeadbeef);
7994 ret
= pFlashWindowEx(NULL
);
7995 ok(!ret
&& GetLastError() == ERROR_NOACCESS
,
7996 "FlashWindowEx returned with %d\n", GetLastError());
7998 SetLastError(0xdeadbeef);
7999 prev
= pFlashWindowEx(&finfo
);
8001 ok(finfo
.cbSize
== sizeof(FLASHWINFO
), "FlashWindowEx modified cdSize to %x\n", finfo
.cbSize
);
8002 ok(finfo
.hwnd
== hwnd
, "FlashWindowEx modified hwnd to %p\n", finfo
.hwnd
);
8003 ok(finfo
.dwFlags
== FLASHW_TIMER
, "FlashWindowEx modified dwFlags to %x\n", finfo
.dwFlags
);
8004 ok(finfo
.uCount
== 3, "FlashWindowEx modified uCount to %x\n", finfo
.uCount
);
8005 ok(finfo
.dwTimeout
== 200, "FlashWindowEx modified dwTimeout to %x\n", finfo
.dwTimeout
);
8007 finfo
.dwFlags
= FLASHW_STOP
;
8008 SetLastError(0xdeadbeef);
8009 ret
= pFlashWindowEx(&finfo
);
8010 ok(prev
!= ret
, "previous window state should be different\n");
8012 DestroyWindow( hwnd
);
8015 static void test_FindWindowEx(void)
8019 hwnd
= CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP
, 0,0,0,0, 0, 0, 0, NULL
);
8020 ok( hwnd
!= 0, "CreateWindowExA error %d\n", GetLastError() );
8022 num_gettext_msgs
= 0;
8023 found
= FindWindowExA( 0, 0, "MainWindowClass", "" );
8024 ok( found
== NULL
, "expected a NULL hwnd\n" );
8025 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
8027 num_gettext_msgs
= 0;
8028 found
= FindWindowExA( 0, 0, "MainWindowClass", NULL
);
8029 ok( found
== hwnd
, "found is %p, expected a valid hwnd\n", found
);
8030 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
8032 num_gettext_msgs
= 0;
8033 found
= FindWindowExA( 0, 0, "MainWindowClass", "caption" );
8034 ok( found
== hwnd
, "found is %p, expected a valid hwnd\n", found
);
8035 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
8037 DestroyWindow( hwnd
);
8039 hwnd
= CreateWindowExA( 0, "MainWindowClass", NULL
, WS_POPUP
, 0,0,0,0, 0, 0, 0, NULL
);
8040 ok( hwnd
!= 0, "CreateWindowExA error %d\n", GetLastError() );
8042 num_gettext_msgs
= 0;
8043 found
= FindWindowExA( 0, 0, "MainWindowClass", "" );
8044 ok( found
== hwnd
, "found is %p, expected a valid hwnd\n", found
);
8045 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
8047 num_gettext_msgs
= 0;
8048 found
= FindWindowExA( 0, 0, "MainWindowClass", NULL
);
8049 ok( found
== hwnd
, "found is %p, expected a valid hwnd\n", found
);
8050 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
8052 DestroyWindow( hwnd
);
8054 /* test behaviour with a window title that is an empty character */
8055 found
= FindWindowExA( 0, 0, "Shell_TrayWnd", "" );
8056 ok( found
!= NULL
, "found is NULL, expected a valid hwnd\n" );
8057 found
= FindWindowExA( 0, 0, "Shell_TrayWnd", NULL
);
8058 ok( found
!= NULL
, "found is NULL, expected a valid hwnd\n" );
8061 static void test_GetLastActivePopup(void)
8063 HWND hwndOwner
, hwndPopup1
, hwndPopup2
;
8065 hwndOwner
= CreateWindowExA(0, "MainWindowClass", NULL
,
8066 WS_VISIBLE
| WS_POPUPWINDOW
,
8068 NULL
, 0, GetModuleHandleA(NULL
), NULL
);
8069 hwndPopup1
= CreateWindowExA(0, "MainWindowClass", NULL
,
8070 WS_VISIBLE
| WS_POPUPWINDOW
,
8072 hwndOwner
, 0, GetModuleHandleA(NULL
), NULL
);
8073 hwndPopup2
= CreateWindowExA(0, "MainWindowClass", NULL
,
8074 WS_VISIBLE
| WS_POPUPWINDOW
,
8076 hwndPopup1
, 0, GetModuleHandleA(NULL
), NULL
);
8077 ok( GetLastActivePopup(hwndOwner
) == hwndPopup2
, "wrong last active popup\n" );
8078 DestroyWindow( hwndPopup2
);
8079 DestroyWindow( hwndPopup1
);
8080 DestroyWindow( hwndOwner
);
8083 static LRESULT WINAPI
my_httrasparent_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
8085 if (msg
== WM_NCHITTEST
) return HTTRANSPARENT
;
8086 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
8089 static LRESULT WINAPI
my_window_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
8091 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
8094 static void create_window_tree(HWND parent
, HWND
*window
, int size
)
8096 static const DWORD style
[] = { 0, WS_VISIBLE
, WS_DISABLED
, WS_VISIBLE
| WS_DISABLED
};
8099 memset(window
, 0, size
* sizeof(window
[0]));
8102 for (i
= 0; i
< sizeof(style
)/sizeof(style
[0]); i
++)
8105 window
[pos
] = CreateWindowExA(0, "my_window", NULL
, style
[i
] | WS_CHILD
,
8106 0, 0, 100, 100, parent
, 0, 0, NULL
);
8107 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
8110 window
[pos
] = CreateWindowExA(WS_EX_TRANSPARENT
, "my_window", NULL
, style
[i
] | WS_CHILD
,
8111 0, 0, 100, 100, parent
, 0, 0, NULL
);
8112 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
8116 window
[pos
] = CreateWindowExA(0, "my_httrasparent", NULL
, style
[i
] | WS_CHILD
,
8117 0, 0, 100, 100, parent
, 0, 0, NULL
);
8118 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
8121 window
[pos
] = CreateWindowExA(WS_EX_TRANSPARENT
, "my_httrasparent", NULL
, style
[i
] | WS_CHILD
,
8122 0, 0, 100, 100, parent
, 0, 0, NULL
);
8123 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
8127 window
[pos
] = CreateWindowExA(0, "my_button", NULL
, style
[i
] | WS_CHILD
| BS_GROUPBOX
,
8128 0, 0, 100, 100, parent
, 0, 0, NULL
);
8129 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
8132 window
[pos
] = CreateWindowExA(WS_EX_TRANSPARENT
, "my_button", NULL
, style
[i
] | WS_CHILD
| BS_GROUPBOX
,
8133 0, 0, 100, 100, parent
, 0, 0, NULL
);
8134 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
8137 window
[pos
] = CreateWindowExA(0, "my_button", NULL
, style
[i
] | WS_CHILD
| BS_PUSHBUTTON
,
8138 0, 0, 100, 100, parent
, 0, 0, NULL
);
8139 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
8142 window
[pos
] = CreateWindowExA(WS_EX_TRANSPARENT
, "my_button", NULL
, style
[i
] | WS_CHILD
| BS_PUSHBUTTON
,
8143 0, 0, 100, 100, parent
, 0, 0, NULL
);
8144 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
8148 window
[pos
] = CreateWindowExA(0, "Button", NULL
, style
[i
] | WS_CHILD
| BS_GROUPBOX
,
8149 0, 0, 100, 100, parent
, 0, 0, NULL
);
8150 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
8153 window
[pos
] = CreateWindowExA(WS_EX_TRANSPARENT
, "Button", NULL
, style
[i
] | WS_CHILD
| BS_GROUPBOX
,
8154 0, 0, 100, 100, parent
, 0, 0, NULL
);
8155 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
8158 window
[pos
] = CreateWindowExA(0, "Button", NULL
, style
[i
] | WS_CHILD
| BS_PUSHBUTTON
,
8159 0, 0, 100, 100, parent
, 0, 0, NULL
);
8160 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
8163 window
[pos
] = CreateWindowExA(WS_EX_TRANSPARENT
, "Button", NULL
, style
[i
] | WS_CHILD
| BS_PUSHBUTTON
,
8164 0, 0, 100, 100, parent
, 0, 0, NULL
);
8165 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
8169 window
[pos
] = CreateWindowExA(0, "Static", NULL
, style
[i
] | WS_CHILD
,
8170 0, 0, 100, 100, parent
, 0, 0, NULL
);
8171 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
8174 window
[pos
] = CreateWindowExA(WS_EX_TRANSPARENT
, "Static", NULL
, style
[i
] | WS_CHILD
,
8175 0, 0, 100, 100, parent
, 0, 0, NULL
);
8176 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
8181 struct window_attributes
8183 char class_name
[128];
8184 BOOL is_visible
, is_enabled
, is_groupbox
, is_httransparent
, is_extransparent
;
8187 static void get_window_attributes(HWND hwnd
, struct window_attributes
*attrs
)
8189 DWORD style
, ex_style
, hittest
;
8191 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
8192 ex_style
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
8193 attrs
->class_name
[0] = 0;
8194 GetClassNameA(hwnd
, attrs
->class_name
, sizeof(attrs
->class_name
));
8195 hittest
= SendMessageA(hwnd
, WM_NCHITTEST
, 0, 0);
8197 attrs
->is_visible
= (style
& WS_VISIBLE
) != 0;
8198 attrs
->is_enabled
= (style
& WS_DISABLED
) == 0;
8199 attrs
->is_groupbox
= !lstrcmpiA(attrs
->class_name
, "Button") && (style
& BS_TYPEMASK
) == BS_GROUPBOX
;
8200 attrs
->is_httransparent
= hittest
== HTTRANSPARENT
;
8201 attrs
->is_extransparent
= (ex_style
& WS_EX_TRANSPARENT
) != 0;
8204 static int window_to_index(HWND hwnd
, HWND
*window
, int size
)
8208 for (i
= 0; i
< size
; i
++)
8210 if (!window
[i
]) break;
8211 if (window
[i
] == hwnd
) return i
;
8216 static void test_child_window_from_point(void)
8218 static const int real_child_pos
[] = { 14,15,16,17,18,19,20,21,24,25,26,27,42,43,
8219 44,45,46,47,48,49,52,53,54,55,51,50,23,22,-1 };
8220 static const int real_child_pos_nt4
[] = { 14,15,16,17,20,21,24,25,26,27,42,43,44,45,
8221 48,49,52,53,54,55,51,50,47,46,23,22,19,18,-1 };
8223 HWND hwnd
, parent
, window
[100];
8225 int found_invisible
, found_disabled
, found_groupbox
, found_httransparent
, found_extransparent
;
8228 ret
= GetClassInfoA(0, "Button", &cls
);
8229 ok(ret
, "GetClassInfo(Button) failed\n");
8230 cls
.lpszClassName
= "my_button";
8231 ret
= RegisterClassA(&cls
);
8232 ok(ret
, "RegisterClass(my_button) failed\n");
8234 cls
.lpszClassName
= "my_httrasparent";
8235 cls
.lpfnWndProc
= my_httrasparent_proc
;
8236 ret
= RegisterClassA(&cls
);
8237 ok(ret
, "RegisterClass(my_httrasparent) failed\n");
8239 cls
.lpszClassName
= "my_window";
8240 cls
.lpfnWndProc
= my_window_proc
;
8241 ret
= RegisterClassA(&cls
);
8242 ok(ret
, "RegisterClass(my_window) failed\n");
8244 parent
= CreateWindowExA(0, "MainWindowClass", NULL
,
8245 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_POPUP
| WS_VISIBLE
,
8247 0, 0, GetModuleHandleA(NULL
), NULL
);
8248 ok(parent
!= 0, "CreateWindowEx failed\n");
8249 trace("parent %p\n", parent
);
8251 create_window_tree(parent
, window
, sizeof(window
)/sizeof(window
[0]));
8253 found_invisible
= 0;
8256 found_httransparent
= 0;
8257 found_extransparent
= 0;
8259 /* FIXME: also test WindowFromPoint, ChildWindowFromPoint, ChildWindowFromPointEx */
8260 for (i
= 0; i
< sizeof(real_child_pos
)/sizeof(real_child_pos
[0]); i
++)
8262 struct window_attributes attrs
;
8265 hwnd
= RealChildWindowFromPoint(parent
, pt
);
8266 ok(hwnd
!= 0, "RealChildWindowFromPoint failed\n");
8267 ret
= window_to_index(hwnd
, window
, sizeof(window
)/sizeof(window
[0]));
8268 /* FIXME: remove once Wine is fixed */
8269 todo_wine_if (ret
!= real_child_pos
[i
])
8270 ok(ret
== real_child_pos
[i
] || broken(ret
== real_child_pos_nt4
[i
]), "expected %d, got %d\n", real_child_pos
[i
], ret
);
8272 get_window_attributes(hwnd
, &attrs
);
8273 if (!attrs
.is_visible
) found_invisible
++;
8274 if (!attrs
.is_enabled
) found_disabled
++;
8275 if (attrs
.is_groupbox
) found_groupbox
++;
8276 if (attrs
.is_httransparent
) found_httransparent
++;
8277 if (attrs
.is_extransparent
) found_extransparent
++;
8279 if (ret
!= real_child_pos
[i
] && ret
!= -1)
8281 trace("found hwnd %p (%s), is_visible %d, is_enabled %d, is_groupbox %d, is_httransparent %d, is_extransparent %d\n",
8282 hwnd
, attrs
.class_name
, attrs
.is_visible
, attrs
.is_enabled
, attrs
.is_groupbox
, attrs
.is_httransparent
, attrs
.is_extransparent
);
8283 get_window_attributes(window
[real_child_pos
[i
]], &attrs
);
8284 trace("expected hwnd %p (%s), is_visible %d, is_enabled %d, is_groupbox %d, is_httransparent %d, is_extransparent %d\n",
8285 window
[real_child_pos
[i
]], attrs
.class_name
, attrs
.is_visible
, attrs
.is_enabled
, attrs
.is_groupbox
, attrs
.is_httransparent
, attrs
.is_extransparent
);
8289 ok(hwnd
== parent
, "expected %p, got %p\n", parent
, hwnd
);
8292 DestroyWindow(hwnd
);
8295 DestroyWindow(parent
);
8297 ok(!found_invisible
, "found %d invisible windows\n", found_invisible
);
8298 ok(found_disabled
, "found %d disabled windows\n", found_disabled
);
8300 ok(found_groupbox
== 4, "found %d groupbox windows\n", found_groupbox
);
8301 ok(found_httransparent
, "found %d httransparent windows\n", found_httransparent
);
8303 ok(found_extransparent
, "found %d extransparent windows\n", found_extransparent
);
8305 ret
= UnregisterClassA("my_button", cls
.hInstance
);
8306 ok(ret
, "UnregisterClass(my_button) failed\n");
8307 ret
= UnregisterClassA("my_httrasparent", cls
.hInstance
);
8308 ok(ret
, "UnregisterClass(my_httrasparent) failed\n");
8309 ret
= UnregisterClassA("my_window", cls
.hInstance
);
8310 ok(ret
, "UnregisterClass(my_window) failed\n");
8313 static void simulate_click(int x
, int y
)
8319 memset(input
, 0, sizeof(input
));
8320 input
[0].type
= INPUT_MOUSE
;
8321 U(input
[0]).mi
.dx
= x
;
8322 U(input
[0]).mi
.dy
= y
;
8323 U(input
[0]).mi
.dwFlags
= MOUSEEVENTF_LEFTDOWN
;
8324 input
[1].type
= INPUT_MOUSE
;
8325 U(input
[1]).mi
.dx
= x
;
8326 U(input
[1]).mi
.dy
= y
;
8327 U(input
[1]).mi
.dwFlags
= MOUSEEVENTF_LEFTUP
;
8328 events_no
= SendInput(2, input
, sizeof(input
[0]));
8329 ok(events_no
== 2, "SendInput returned %d\n", events_no
);
8332 static WNDPROC def_static_proc
;
8333 static BOOL got_hittest
;
8334 static LRESULT WINAPI
static_hook_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
8336 if(msg
== WM_NCHITTEST
)
8338 if(msg
== WM_LBUTTONDOWN
)
8339 ok(0, "unexpected call\n");
8341 return def_static_proc(hwnd
, msg
, wp
, lp
);
8344 static void window_from_point_proc(HWND parent
)
8346 HANDLE start_event
, end_event
;
8347 HANDLE win
, child_static
, child_button
;
8353 start_event
= OpenEventA(EVENT_ALL_ACCESS
, FALSE
, "test_wfp_start");
8354 ok(start_event
!= 0, "OpenEvent failed\n");
8355 end_event
= OpenEventA(EVENT_ALL_ACCESS
, FALSE
, "test_wfp_end");
8356 ok(end_event
!= 0, "OpenEvent failed\n");
8358 child_static
= CreateWindowExA(0, "static", "static", WS_CHILD
| WS_VISIBLE
,
8359 0, 0, 100, 100, parent
, 0, NULL
, NULL
);
8360 ok(child_static
!= 0, "CreateWindowEx failed\n");
8362 win
= WindowFromPoint(pt
);
8363 ok(win
== parent
, "WindowFromPoint returned %p, expected %p\n", win
, parent
);
8365 child_button
= CreateWindowExA(0, "button", "button", WS_CHILD
| WS_VISIBLE
,
8366 100, 0, 100, 100, parent
, 0, NULL
, NULL
);
8367 ok(child_button
!= 0, "CreateWindowEx failed\n");
8369 win
= WindowFromPoint(pt
);
8370 ok(win
== child_button
, "WindowFromPoint returned %p, expected %p\n", win
, child_button
);
8372 /* without this window simulate click test keeps sending WM_NCHITTEST
8373 * message to child_static in an infinite loop */
8374 win
= CreateWindowExA(0, "button", "button", WS_CHILD
| WS_VISIBLE
,
8375 0, 0, 100, 100, parent
, 0, NULL
, NULL
);
8376 ok(win
!= 0, "CreateWindowEx failed\n");
8377 def_static_proc
= (void*)SetWindowLongPtrA(child_static
,
8378 GWLP_WNDPROC
, (LONG_PTR
)static_hook_proc
);
8380 SetEvent(start_event
);
8382 got_hittest
= FALSE
;
8384 while(!got_click
&& wait_for_message(&msg
)) {
8385 if(msg
.message
== WM_LBUTTONUP
) {
8386 ok(msg
.hwnd
== win
, "msg.hwnd = %p, expected %p\n", msg
.hwnd
, win
);
8389 DispatchMessageA(&msg
);
8391 ok(got_hittest
, "transparent window didn't get WM_NCHITTEST message\n");
8392 ok(got_click
, "button under static window didn't get WM_LBUTTONUP\n");
8394 ret
= WaitForSingleObject(end_event
, 5000);
8395 ok(ret
== WAIT_OBJECT_0
, "WaitForSingleObject returned %x\n", ret
);
8397 CloseHandle(start_event
);
8398 CloseHandle(end_event
);
8401 static void test_window_from_point(const char *argv0
)
8403 HWND hwnd
, child
, win
;
8405 PROCESS_INFORMATION info
;
8406 STARTUPINFOA startup
;
8408 HANDLE start_event
, end_event
;
8410 hwnd
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_POPUP
| WS_VISIBLE
,
8411 100, 100, 200, 100, 0, 0, NULL
, NULL
);
8412 ok(hwnd
!= 0, "CreateWindowEx failed\n");
8415 win
= WindowFromPoint(pt
);
8418 win
= WindowFromPoint(pt
);
8420 skip("there's another window covering test window\n");
8421 DestroyWindow(hwnd
);
8425 child
= CreateWindowExA(0, "static", "static", WS_CHILD
| WS_VISIBLE
,
8426 0, 0, 100, 100, hwnd
, 0, NULL
, NULL
);
8427 ok(child
!= 0, "CreateWindowEx failed\n");
8429 win
= WindowFromPoint(pt
);
8430 ok(win
== hwnd
, "WindowFromPoint returned %p, expected %p\n", win
, hwnd
);
8431 DestroyWindow(child
);
8433 child
= CreateWindowExA(0, "button", "button", WS_CHILD
| WS_VISIBLE
,
8434 0, 0, 100, 100, hwnd
, 0, NULL
, NULL
);
8435 ok(child
!= 0, "CreateWindowEx failed\n");
8436 win
= WindowFromPoint(pt
);
8437 ok(win
== child
, "WindowFromPoint returned %p, expected %p\n", win
, child
);
8438 DestroyWindow(child
);
8440 start_event
= CreateEventA(NULL
, FALSE
, FALSE
, "test_wfp_start");
8441 ok(start_event
!= 0, "CreateEvent failed\n");
8442 end_event
= CreateEventA(NULL
, FALSE
, FALSE
, "test_wfp_end");
8443 ok(start_event
!= 0, "CreateEvent failed\n");
8445 sprintf(cmd
, "%s win create_children %p\n", argv0
, hwnd
);
8446 memset(&startup
, 0, sizeof(startup
));
8447 startup
.cb
= sizeof(startup
);
8448 ok(CreateProcessA(NULL
, cmd
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
,
8449 &startup
, &info
), "CreateProcess failed.\n");
8450 ok(wait_for_event(start_event
, 1000), "didn't get start_event\n");
8452 child
= GetWindow(hwnd
, GW_CHILD
);
8453 win
= WindowFromPoint(pt
);
8454 ok(win
== child
, "WindowFromPoint returned %p, expected %p\n", win
, child
);
8456 simulate_click(150, 150);
8459 child
= GetWindow(child
, GW_HWNDNEXT
);
8461 win
= WindowFromPoint(pt
);
8462 ok(win
== child
, "WindowFromPoint returned %p, expected %p\n", win
, child
);
8464 SetEvent(end_event
);
8465 winetest_wait_child_process(info
.hProcess
);
8466 CloseHandle(start_event
);
8467 CloseHandle(end_event
);
8468 CloseHandle(info
.hProcess
);
8469 CloseHandle(info
.hThread
);
8471 DestroyWindow(hwnd
);
8474 static void test_map_points(void)
8478 HWND wnd
, wnd0
, dwnd
;
8481 POINT pos
= { 100, 200 };
8487 /* Create test windows */
8488 wnd
= CreateWindowA("static", "test1", WS_POPUP
, pos
.x
, pos
.y
, width
, height
, NULL
, NULL
, NULL
, NULL
);
8489 ok(wnd
!= NULL
, "Failed %p\n", wnd
);
8490 wnd0
= CreateWindowA("static", "test2", WS_POPUP
, 0, 0, width
, height
, NULL
, NULL
, NULL
, NULL
);
8491 ok(wnd0
!= NULL
, "Failed %p\n", wnd
);
8492 dwnd
= CreateWindowA("static", "test3", 0, 200, 300, 150, 150, NULL
, NULL
, NULL
, NULL
);
8493 DestroyWindow(dwnd
);
8494 ok(dwnd
!= NULL
, "Failed %p\n", dwnd
);
8496 /* Verify window rect and client rect (they should have the same width and height) */
8497 GetWindowRect(wnd
, &window_rect
);
8498 ok(window_rect
.left
== pos
.x
, "left is %d instead of %d\n", window_rect
.left
, pos
.x
);
8499 ok(window_rect
.top
== pos
.y
, "top is %d instead of %d\n", window_rect
.top
, pos
.y
);
8500 ok(window_rect
.right
== pos
.x
+ width
, "right is %d instead of %d\n", window_rect
.right
, pos
.x
+ width
);
8501 ok(window_rect
.bottom
== pos
.y
+ height
, "bottom is %d instead of %d\n", window_rect
.bottom
, pos
.y
+ height
);
8502 GetClientRect(wnd
, &client_rect
);
8503 ok(client_rect
.left
== 0, "left is %d instead of 0\n", client_rect
.left
);
8504 ok(client_rect
.top
== 0, "top is %d instead of 0\n", client_rect
.top
);
8505 ok(client_rect
.right
== width
, "right is %d instead of %d\n", client_rect
.right
, width
);
8506 ok(client_rect
.bottom
== height
, "bottom is %d instead of %d\n", client_rect
.bottom
, height
);
8508 /* Test MapWindowPoints */
8510 /* MapWindowPoints(NULL or wnd, NULL or wnd, NULL, 1); crashes on Windows */
8512 SetLastError(0xdeadbeef);
8513 n
= MapWindowPoints(NULL
, NULL
, NULL
, 0);
8514 err
= GetLastError();
8515 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
8516 ok(err
== 0xdeadbeef, "Got %x, expected %x\n", err
, 0xdeadbeef);
8518 SetLastError(0xdeadbeef);
8519 n
= MapWindowPoints(wnd
, wnd
, NULL
, 0);
8520 err
= GetLastError();
8521 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
8522 ok(err
== 0xdeadbeef, "Got %x, expected %x\n", err
, 0xdeadbeef);
8524 n
= MapWindowPoints(wnd
, NULL
, NULL
, 0);
8525 ok(n
== MAKELONG(window_rect
.left
, window_rect
.top
), "Got %x, expected %x\n",
8526 n
, MAKELONG(window_rect
.left
, window_rect
.top
));
8528 n
= MapWindowPoints(NULL
, wnd
, NULL
, 0);
8529 ok(n
== MAKELONG(-window_rect
.left
, -window_rect
.top
), "Got %x, expected %x\n",
8530 n
, MAKELONG(-window_rect
.left
, -window_rect
.top
));
8532 SetLastError(0xdeadbeef);
8534 n
= MapWindowPoints(dwnd
, NULL
, &p
, 1);
8535 err
= GetLastError();
8536 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
8537 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
8538 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
8540 SetLastError(0xdeadbeef);
8542 n
= MapWindowPoints(dwnd
, wnd
, &p
, 1);
8543 err
= GetLastError();
8544 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
8545 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
8546 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
8548 SetLastError(0xdeadbeef);
8550 n
= MapWindowPoints(NULL
, dwnd
, &p
, 1);
8551 err
= GetLastError();
8552 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
8553 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
8554 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
8556 SetLastError(0xdeadbeef);
8558 n
= MapWindowPoints(wnd
, dwnd
, &p
, 1);
8559 err
= GetLastError();
8560 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
8561 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
8562 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
8564 SetLastError(0xdeadbeef);
8566 n
= MapWindowPoints(dwnd
, dwnd
, &p
, 1);
8567 err
= GetLastError();
8568 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
8569 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
8570 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
8572 SetLastError(0xdeadbeef);
8574 n
= MapWindowPoints(NULL
, NULL
, &p
, 1);
8575 err
= GetLastError();
8576 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
8577 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
8578 ok(err
== 0xdeadbeef, "Got %x, expected %x\n", err
, 0xdeadbeef);
8580 SetLastError(0xdeadbeef);
8582 n
= MapWindowPoints(wnd
, wnd
, &p
, 1);
8583 err
= GetLastError();
8584 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
8585 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
8586 ok(err
== 0xdeadbeef, "Got %x, expected %x\n", err
, 0xdeadbeef);
8589 n
= MapWindowPoints(wnd
, NULL
, &p
, 1);
8590 ok(n
== MAKELONG(window_rect
.left
, window_rect
.top
), "Got %x, expected %x\n",
8591 n
, MAKELONG(window_rect
.left
, window_rect
.top
));
8592 ok((p
.x
== (window_rect
.left
+ 100)) && (p
.y
== (window_rect
.top
+ 100)), "Failed got (%d, %d), expected (%d, %d)\n",
8593 p
.x
, p
.y
, window_rect
.left
+ 100, window_rect
.top
+ 100);
8596 n
= MapWindowPoints(NULL
, wnd
, &p
, 1);
8597 ok(n
== MAKELONG(-window_rect
.left
, -window_rect
.top
), "Got %x, expected %x\n",
8598 n
, MAKELONG(-window_rect
.left
, -window_rect
.top
));
8599 ok((p
.x
== (-window_rect
.left
+ 100)) && (p
.y
== (-window_rect
.top
+ 100)), "Failed got (%d, %d), expected (%d, %d)\n",
8600 p
.x
, p
.y
, -window_rect
.left
+ 100, -window_rect
.top
+ 100);
8602 SetLastError(0xdeadbeef);
8604 n
= MapWindowPoints(wnd0
, NULL
, &p
, 1);
8605 err
= GetLastError();
8606 ok(n
== 0, "Got %x, expected 0\n", n
);
8607 ok((p
.x
== 0) && (p
.y
== 0), "Failed got (%d, %d), expected (0, 0)\n", p
.x
, p
.y
);
8608 ok(err
== 0xdeadbeef, "Got %x, expected %x\n", err
, 0xdeadbeef);
8610 SetLastError(0xdeadbeef);
8612 n
= MapWindowPoints(NULL
, wnd0
, &p
, 1);
8613 err
= GetLastError();
8614 ok(n
== 0, "Got %x, expected 0\n", n
);
8615 ok((p
.x
== 0) && (p
.y
== 0), "Failed got (%d, %d), expected (0, 0)\n", p
.x
, p
.y
);
8616 ok(err
== 0xdeadbeef, "Got %x, expected %x\n", err
, 0xdeadbeef);
8618 /* Test ClientToScreen */
8620 /* ClientToScreen(wnd, NULL); crashes on Windows */
8622 SetLastError(0xdeadbeef);
8623 ret
= ClientToScreen(NULL
, NULL
);
8624 err
= GetLastError();
8625 ok(!ret
, "Should fail\n");
8626 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
8628 SetLastError(0xdeadbeef);
8630 ret
= ClientToScreen(NULL
, &p
);
8631 err
= GetLastError();
8632 ok(!ret
, "Should fail\n");
8633 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
8634 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
8636 SetLastError(0xdeadbeef);
8638 ret
= ClientToScreen(dwnd
, &p
);
8639 err
= GetLastError();
8640 ok(!ret
, "Should fail\n");
8641 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
8642 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
8645 ret
= ClientToScreen(wnd
, &p
);
8646 ok(ret
, "Failed with error %u\n", GetLastError());
8647 ok((p
.x
== (window_rect
.left
+ 100)) && (p
.y
== (window_rect
.top
+ 100)), "Failed got (%d, %d), expected (%d, %d)\n",
8648 p
.x
, p
.y
, window_rect
.left
+ 100, window_rect
.top
+ 100);
8651 ret
= ClientToScreen(wnd0
, &p
);
8652 ok(ret
, "Failed with error %u\n", GetLastError());
8653 ok((p
.x
== 0) && (p
.y
== 0), "Failed got (%d, %d), expected (0, 0)\n", p
.x
, p
.y
);
8655 /* Test ScreenToClient */
8657 /* ScreenToClient(wnd, NULL); crashes on Windows */
8659 SetLastError(0xdeadbeef);
8660 ret
= ScreenToClient(NULL
, NULL
);
8661 err
= GetLastError();
8662 ok(!ret
, "Should fail\n");
8663 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
8665 SetLastError(0xdeadbeef);
8667 ret
= ScreenToClient(NULL
, &p
);
8668 err
= GetLastError();
8669 ok(!ret
, "Should fail\n");
8670 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
8671 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
8673 SetLastError(0xdeadbeef);
8675 ret
= ScreenToClient(dwnd
, &p
);
8676 err
= GetLastError();
8677 ok(!ret
, "Should fail\n");
8678 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
8679 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
8682 ret
= ScreenToClient(wnd
, &p
);
8683 ok(ret
, "Failed with error %u\n", GetLastError());
8684 ok((p
.x
== (-window_rect
.left
+ 100)) && (p
.y
== (-window_rect
.top
+ 100)), "Failed got(%d, %d), expected (%d, %d)\n",
8685 p
.x
, p
.y
, -window_rect
.left
+ 100, -window_rect
.top
+ 100);
8688 ret
= ScreenToClient(wnd0
, &p
);
8689 ok(ret
, "Failed with error %u\n", GetLastError());
8690 ok((p
.x
== 0) && (p
.y
== 0), "Failed got (%d, %d), expected (0, 0)\n", p
.x
, p
.y
);
8693 DestroyWindow(wnd0
);
8696 static void test_update_region(void)
8698 HWND hwnd
, parent
, child
;
8700 const RECT rc
= {15, 15, 40, 40};
8701 const POINT wnd_orig
= {30, 20};
8702 const POINT child_orig
= {10, 5};
8704 parent
= CreateWindowExA(0, "MainWindowClass", NULL
,
8705 WS_VISIBLE
| WS_CLIPCHILDREN
,
8706 0, 0, 300, 150, NULL
, NULL
, GetModuleHandleA(0), 0);
8707 hwnd
= CreateWindowExA(0, "MainWindowClass", NULL
,
8708 WS_VISIBLE
| WS_CLIPCHILDREN
| WS_CHILD
,
8709 0, 0, 200, 100, parent
, NULL
, GetModuleHandleA(0), 0);
8710 child
= CreateWindowExA(0, "MainWindowClass", NULL
,
8711 WS_VISIBLE
| WS_CHILD
,
8712 child_orig
.x
, child_orig
.y
, 100, 50,
8713 hwnd
, NULL
, GetModuleHandleA(0), 0);
8714 assert(parent
&& hwnd
&& child
);
8716 ValidateRgn(parent
, NULL
);
8717 ValidateRgn(hwnd
, NULL
);
8718 InvalidateRect(hwnd
, &rc
, FALSE
);
8719 ValidateRgn(child
, NULL
);
8721 rgn1
= CreateRectRgn(0, 0, 0, 0);
8722 ok(GetUpdateRgn(parent
, rgn1
, FALSE
) == NULLREGION
,
8723 "has invalid area after ValidateRgn(NULL)\n");
8724 GetUpdateRgn(hwnd
, rgn1
, FALSE
);
8725 rgn2
= CreateRectRgnIndirect(&rc
);
8726 ok(EqualRgn(rgn1
, rgn2
), "assigned and retrieved update regions are different\n");
8727 ok(GetUpdateRgn(child
, rgn2
, FALSE
) == NULLREGION
,
8728 "has invalid area after ValidateRgn(NULL)\n");
8730 SetWindowPos(hwnd
, 0, wnd_orig
.x
, wnd_orig
.y
, 0, 0,
8731 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOSIZE
);
8733 /* parent now has non-simple update region, it consist of
8734 * two rects, that was exposed after hwnd moving ... */
8735 SetRectRgn(rgn1
, 0, 0, 200, wnd_orig
.y
);
8736 SetRectRgn(rgn2
, 0, 0, wnd_orig
.x
, 100);
8737 CombineRgn(rgn1
, rgn1
, rgn2
, RGN_OR
);
8738 /* ... and mapped hwnd's invalid area, that hwnd has before moving */
8739 SetRectRgn(rgn2
, rc
.left
+ wnd_orig
.x
, rc
.top
+ wnd_orig
.y
,
8740 rc
.right
+ wnd_orig
.x
, rc
.bottom
+ wnd_orig
.y
);
8741 CombineRgn(rgn1
, rgn1
, rgn2
, RGN_OR
);
8742 GetUpdateRgn(parent
, rgn2
, FALSE
);
8744 ok(EqualRgn(rgn1
, rgn2
), "wrong update region\n");
8746 /* hwnd has the same invalid region as before moving */
8747 SetRectRgn(rgn1
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
8748 GetUpdateRgn(hwnd
, rgn2
, FALSE
);
8749 ok(EqualRgn(rgn1
, rgn2
), "wrong update region\n");
8751 /* hwnd's invalid area maps to child during moving */
8752 SetRectRgn(rgn1
, rc
.left
- child_orig
.x
, rc
.top
- child_orig
.y
,
8753 rc
.right
- child_orig
.x
, rc
.bottom
- child_orig
.y
);
8754 GetUpdateRgn(child
, rgn2
, FALSE
);
8756 ok(EqualRgn(rgn1
, rgn2
), "wrong update region\n");
8760 DestroyWindow(parent
);
8763 static void test_window_without_child_style(void)
8767 hwnd
= CreateWindowExA(0, "edit", NULL
, WS_VISIBLE
|WS_CHILD
,
8768 0, 0, 50, 50, hwndMain
, NULL
, 0, NULL
);
8769 ok(hwnd
!= NULL
, "CreateWindow failed\n");
8771 ok(SetWindowLongA(hwnd
, GWL_STYLE
, GetWindowLongA(hwnd
, GWL_STYLE
) & (~WS_CHILD
)),
8772 "can't remove WS_CHILD style\n");
8774 SetActiveWindow(hwndMain
);
8775 PostMessageW(hwnd
, WM_LBUTTONUP
, 0, 0);
8776 SendMessageW(hwnd
, WM_NCLBUTTONDOWN
, HTCAPTION
, 0);
8777 check_active_state(hwnd
, hwnd
, hwnd
);
8780 DestroyWindow(hwnd
);
8784 struct smresult_thread_data
8788 HANDLE thread_started
;
8789 HANDLE thread_got_wm_app
;
8790 HANDLE main_in_wm_app_1
;
8791 HANDLE thread_replied
;
8795 static LRESULT WINAPI
smresult_wndproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
8801 struct smresult_thread_data
*data
= (struct smresult_thread_data
*)lparam
;
8803 ok(hwnd
== data
->thread_hwnd
, "unexpected hwnd %p\n", hwnd
);
8805 SendNotifyMessageA(data
->main_hwnd
, WM_APP
+1, 0, lparam
);
8807 /* Don't return until the main thread is processing our sent message. */
8808 ok(WaitForSingleObject(data
->main_in_wm_app_1
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
8810 /* Break the PeekMessage loop so we can notify the main thread after we return. */
8811 SetEvent(data
->thread_got_wm_app
);
8817 struct smresult_thread_data
*data
= (struct smresult_thread_data
*)lparam
;
8820 ok(hwnd
== data
->main_hwnd
, "unexpected hwnd %p\n", hwnd
);
8822 /* Ask the thread to reply to our WM_APP message. */
8823 SetEvent(data
->main_in_wm_app_1
);
8825 /* Wait until the thread has sent a reply. */
8826 ok(WaitForSingleObject(data
->thread_replied
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
8828 /* Send another message while we have a reply queued for the current one. */
8829 res
= SendMessageA(data
->thread_hwnd
, WM_APP
+2, 0, lparam
);
8830 ok(res
== 0x449b0190, "unexpected result %lx\n", res
);
8836 struct smresult_thread_data
*data
= (struct smresult_thread_data
*)lparam
;
8838 ok(hwnd
== data
->thread_hwnd
, "unexpected hwnd %p\n", hwnd
);
8840 /* Don't return until we know the main thread is processing sent messages. */
8841 SendMessageA(data
->main_hwnd
, WM_NULL
, 0, 0);
8849 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
8852 static DWORD WINAPI
smresult_thread_proc(void *param
)
8855 struct smresult_thread_data
*data
= param
;
8857 data
->thread_hwnd
= CreateWindowExA(0, "SmresultClass", "window caption text", WS_OVERLAPPEDWINDOW
,
8858 100, 100, 200, 200, 0, 0, 0, NULL
);
8859 ok(data
->thread_hwnd
!= 0, "Failed to create overlapped window\n");
8861 SetEvent(data
->thread_started
);
8863 /* Loop until we've processed WM_APP. */
8864 while (WaitForSingleObject(data
->thread_got_wm_app
, 0) != WAIT_OBJECT_0
)
8866 if (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
8868 TranslateMessage(&msg
);
8869 DispatchMessageA(&msg
);
8873 MsgWaitForMultipleObjects(1, &data
->thread_got_wm_app
, FALSE
, INFINITE
, QS_SENDMESSAGE
);
8877 /* Notify the main thread that we replied to its WM_APP message. */
8878 SetEvent(data
->thread_replied
);
8880 while (GetMessageA(&msg
, 0, 0, 0))
8882 TranslateMessage(&msg
);
8883 DispatchMessageA(&msg
);
8889 static void test_smresult(void)
8894 struct smresult_thread_data data
;
8898 cls
.style
= CS_DBLCLKS
;
8899 cls
.lpfnWndProc
= smresult_wndproc
;
8902 cls
.hInstance
= GetModuleHandleA(0);
8904 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
8905 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
8906 cls
.lpszMenuName
= NULL
;
8907 cls
.lpszClassName
= "SmresultClass";
8909 ret
= RegisterClassA(&cls
);
8910 ok(ret
, "RegisterClassA failed\n");
8912 data
.thread_started
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
8913 ok(data
.thread_started
!= NULL
, "CreateEventA failed\n");
8915 data
.thread_got_wm_app
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
8916 ok(data
.thread_got_wm_app
!= NULL
, "CreateEventA failed\n");
8918 data
.main_in_wm_app_1
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
8919 ok(data
.main_in_wm_app_1
!= NULL
, "CreateEventA failed\n");
8921 data
.thread_replied
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
8922 ok(data
.thread_replied
!= NULL
, "CreateEventA failed\n");
8924 data
.main_hwnd
= CreateWindowExA(0, "SmresultClass", "window caption text", WS_OVERLAPPEDWINDOW
,
8925 100, 100, 200, 200, 0, 0, 0, NULL
);
8927 hThread
= CreateThread(NULL
, 0, smresult_thread_proc
, &data
, 0, &tid
);
8928 ok(hThread
!= NULL
, "CreateThread failed, error %d\n", GetLastError());
8930 ok(WaitForSingleObject(data
.thread_started
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
8932 res
= SendMessageA(data
.thread_hwnd
, WM_APP
, 0, (LPARAM
)&data
);
8933 ok(res
== 0x240408ea, "unexpected result %lx\n", res
);
8935 SendMessageA(data
.thread_hwnd
, WM_CLOSE
, 0, 0);
8937 DestroyWindow(data
.main_hwnd
);
8939 ok(WaitForSingleObject(hThread
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
8941 CloseHandle(data
.thread_started
);
8942 CloseHandle(data
.thread_got_wm_app
);
8943 CloseHandle(data
.main_in_wm_app_1
);
8944 CloseHandle(data
.thread_replied
);
8947 static void test_GetMessagePos(void)
8953 button
= CreateWindowExA(0, "button", "button", WS_VISIBLE
,
8954 100, 100, 100, 100, 0, 0, 0, NULL
);
8955 ok(button
!= 0, "CreateWindowExA failed\n");
8957 SetCursorPos(120, 140);
8959 pos
= GetMessagePos();
8960 ok(pos
== MAKELONG(120, 140), "pos = %08x\n", pos
);
8962 SetCursorPos(340, 320);
8963 pos
= GetMessagePos();
8964 ok(pos
== MAKELONG(120, 140), "pos = %08x\n", pos
);
8966 SendMessageW(button
, WM_APP
, 0, 0);
8967 pos
= GetMessagePos();
8968 ok(pos
== MAKELONG(120, 140), "pos = %08x\n", pos
);
8970 PostMessageA(button
, WM_APP
, 0, 0);
8971 GetMessageA(&msg
, button
, 0, 0);
8972 ok(msg
.message
== WM_APP
, "msg.message = %x\n", msg
.message
);
8973 pos
= GetMessagePos();
8974 ok(pos
== MAKELONG(340, 320), "pos = %08x\n", pos
);
8976 PostMessageA(button
, WM_APP
, 0, 0);
8977 SetCursorPos(350, 330);
8978 GetMessageA(&msg
, button
, 0, 0);
8979 ok(msg
.message
== WM_APP
, "msg.message = %x\n", msg
.message
);
8980 pos
= GetMessagePos();
8981 ok(pos
== MAKELONG(340, 320), "pos = %08x\n", pos
);
8983 PostMessageA(button
, WM_APP
, 0, 0);
8984 SetCursorPos(320, 340);
8985 PostMessageA(button
, WM_APP
+1, 0, 0);
8986 pos
= GetMessagePos();
8987 ok(pos
== MAKELONG(340, 320), "pos = %08x\n", pos
);
8988 GetMessageA(&msg
, button
, 0, 0);
8989 ok(msg
.message
== WM_APP
, "msg.message = %x\n", msg
.message
);
8990 pos
= GetMessagePos();
8991 ok(pos
== MAKELONG(350, 330), "pos = %08x\n", pos
);
8992 GetMessageA(&msg
, button
, 0, 0);
8993 ok(msg
.message
== WM_APP
+1, "msg.message = %x\n", msg
.message
);
8994 pos
= GetMessagePos();
8995 ok(pos
== MAKELONG(320, 340), "pos = %08x\n", pos
);
8997 SetTimer(button
, 1, 250, NULL
);
8998 SetCursorPos(330, 350);
8999 GetMessageA(&msg
, button
, 0, 0);
9000 while (msg
.message
== WM_PAINT
)
9002 UpdateWindow( button
);
9003 GetMessageA(&msg
, button
, 0, 0);
9005 ok(msg
.message
== WM_TIMER
, "msg.message = %x\n", msg
.message
);
9006 pos
= GetMessagePos();
9007 ok(pos
== MAKELONG(330, 350), "pos = %08x\n", pos
);
9008 KillTimer(button
, 1);
9010 DestroyWindow(button
);
9013 #define SET_FOREGROUND_STEAL_1 0x01
9014 #define SET_FOREGROUND_SET_1 0x02
9015 #define SET_FOREGROUND_STEAL_2 0x04
9016 #define SET_FOREGROUND_SET_2 0x08
9017 #define SET_FOREGROUND_INJECT 0x10
9019 struct set_foreground_thread_params
9021 UINT msg_quit
, msg_command
;
9022 HWND window1
, window2
, thread_window
;
9023 HANDLE command_executed
;
9026 static DWORD WINAPI
set_foreground_thread(void *params
)
9028 struct set_foreground_thread_params
*p
= params
;
9031 p
->thread_window
= CreateWindowExA(0, "static", "thread window", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
9032 0, 0, 10, 10, 0, 0, 0, NULL
);
9033 SetEvent(p
->command_executed
);
9035 while(GetMessageA(&msg
, 0, 0, 0))
9037 if (msg
.message
== p
->msg_quit
)
9040 if (msg
.message
== p
->msg_command
)
9042 if (msg
.wParam
& SET_FOREGROUND_STEAL_1
)
9044 SetForegroundWindow(p
->thread_window
);
9045 check_wnd_state(p
->thread_window
, p
->thread_window
, p
->thread_window
, 0);
9047 if (msg
.wParam
& SET_FOREGROUND_INJECT
)
9049 SendNotifyMessageA(p
->window1
, WM_ACTIVATEAPP
, 0, 0);
9051 if (msg
.wParam
& SET_FOREGROUND_SET_1
)
9053 SetForegroundWindow(p
->window1
);
9054 check_wnd_state(0, p
->window1
, 0, 0);
9056 if (msg
.wParam
& SET_FOREGROUND_STEAL_2
)
9058 SetForegroundWindow(p
->thread_window
);
9059 check_wnd_state(p
->thread_window
, p
->thread_window
, p
->thread_window
, 0);
9061 if (msg
.wParam
& SET_FOREGROUND_SET_2
)
9063 SetForegroundWindow(p
->window2
);
9064 check_wnd_state(0, p
->window2
, 0, 0);
9067 SetEvent(p
->command_executed
);
9071 TranslateMessage(&msg
);
9072 DispatchMessageA(&msg
);
9075 DestroyWindow(p
->thread_window
);
9079 static void test_activateapp(HWND window1
)
9081 HWND window2
, test_window
;
9083 struct set_foreground_thread_params thread_params
;
9087 window2
= CreateWindowExA(0, "static", "window 2", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
9088 300, 0, 10, 10, 0, 0, 0, NULL
);
9089 thread_params
.msg_quit
= WM_USER
;
9090 thread_params
.msg_command
= WM_USER
+ 1;
9091 thread_params
.window1
= window1
;
9092 thread_params
.window2
= window2
;
9093 thread_params
.command_executed
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
9095 thread
= CreateThread(NULL
, 0, set_foreground_thread
, &thread_params
, 0, &tid
);
9096 WaitForSingleObject(thread_params
.command_executed
, INFINITE
);
9098 SetForegroundWindow(window1
);
9099 check_wnd_state(window1
, window1
, window1
, 0);
9100 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
9102 /* Steal foreground: WM_ACTIVATEAPP(0) is delivered. */
9103 app_activated
= app_deactivated
= FALSE
;
9104 PostThreadMessageA(tid
, thread_params
.msg_command
, SET_FOREGROUND_STEAL_1
, 0);
9105 WaitForSingleObject(thread_params
.command_executed
, INFINITE
);
9106 test_window
= GetForegroundWindow();
9107 ok(test_window
== thread_params
.thread_window
, "Expected foreground window %p, got %p\n",
9108 thread_params
.thread_window
, test_window
);
9109 /* Active and Focus window are sometimes 0 on KDE. Ignore them.
9110 * check_wnd_state(window1, thread_params.thread_window, window1, 0); */
9111 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9112 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9113 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
9114 check_wnd_state(0, thread_params
.thread_window
, 0, 0);
9115 test_window
= GetForegroundWindow();
9116 ok(test_window
== thread_params
.thread_window
, "Expected foreground window %p, got %p\n",
9117 thread_params
.thread_window
, test_window
);
9118 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9119 /* This message is reliable on Windows and inside a virtual desktop.
9120 * It is unreliable on KDE (50/50) and never arrives on FVWM.
9121 * ok(app_deactivated, "Expected WM_ACTIVATEAPP(0), did not receive it.\n"); */
9123 /* Set foreground: WM_ACTIVATEAPP (1) is delivered. */
9124 app_activated
= app_deactivated
= FALSE
;
9125 PostThreadMessageA(tid
, thread_params
.msg_command
, SET_FOREGROUND_SET_1
, 0);
9126 WaitForSingleObject(thread_params
.command_executed
, INFINITE
);
9127 check_wnd_state(0, 0, 0, 0);
9128 test_window
= GetForegroundWindow();
9129 ok(!test_window
, "Expected foreground window 0, got %p\n", test_window
);
9130 ok(!app_activated
, "Received WM_ACTIVATEAPP(!= 0), did not expect it.\n");
9131 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9132 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
9133 check_wnd_state(window1
, window1
, window1
, 0);
9134 test_window
= GetForegroundWindow();
9135 ok(test_window
== window1
, "Expected foreground window %p, got %p\n",
9136 window1
, test_window
);
9137 ok(app_activated
, "Expected WM_ACTIVATEAPP(1), did not receive it.\n");
9138 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9140 /* Steal foreground then set it back: No messages are delivered. */
9141 app_activated
= app_deactivated
= FALSE
;
9142 PostThreadMessageA(tid
, thread_params
.msg_command
, SET_FOREGROUND_STEAL_1
| SET_FOREGROUND_SET_1
, 0);
9143 WaitForSingleObject(thread_params
.command_executed
, INFINITE
);
9144 test_window
= GetForegroundWindow();
9145 ok(test_window
== window1
, "Expected foreground window %p, got %p\n",
9146 window1
, test_window
);
9147 check_wnd_state(window1
, window1
, window1
, 0);
9148 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9149 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9150 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
9151 test_window
= GetForegroundWindow();
9152 ok(test_window
== window1
, "Expected foreground window %p, got %p\n",
9153 window1
, test_window
);
9154 check_wnd_state(window1
, window1
, window1
, 0);
9155 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9156 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9158 /* This is not implemented with a plain WM_ACTIVATEAPP filter. */
9159 app_activated
= app_deactivated
= FALSE
;
9160 PostThreadMessageA(tid
, thread_params
.msg_command
, SET_FOREGROUND_STEAL_1
9161 | SET_FOREGROUND_INJECT
| SET_FOREGROUND_SET_1
, 0);
9162 WaitForSingleObject(thread_params
.command_executed
, INFINITE
);
9163 test_window
= GetForegroundWindow();
9164 ok(test_window
== window1
, "Expected foreground window %p, got %p\n",
9165 window1
, test_window
);
9166 check_wnd_state(window1
, window1
, window1
, 0);
9167 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9168 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9169 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
9170 test_window
= GetForegroundWindow();
9171 ok(test_window
== window1
, "Expected foreground window %p, got %p\n",
9172 window1
, test_window
);
9173 check_wnd_state(window1
, window1
, window1
, 0);
9174 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9175 ok(app_deactivated
, "Expected WM_ACTIVATEAPP(0), did not receive it.\n");
9177 SetForegroundWindow(thread_params
.thread_window
);
9179 /* Set foreground then remove: Both messages are delivered. */
9180 app_activated
= app_deactivated
= FALSE
;
9181 PostThreadMessageA(tid
, thread_params
.msg_command
, SET_FOREGROUND_SET_1
| SET_FOREGROUND_STEAL_2
, 0);
9182 WaitForSingleObject(thread_params
.command_executed
, INFINITE
);
9183 test_window
= GetForegroundWindow();
9184 ok(test_window
== thread_params
.thread_window
, "Expected foreground window %p, got %p\n",
9185 thread_params
.thread_window
, test_window
);
9186 check_wnd_state(0, thread_params
.thread_window
, 0, 0);
9187 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9188 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9189 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
9190 test_window
= GetForegroundWindow();
9191 ok(test_window
== thread_params
.thread_window
, "Expected foreground window %p, got %p\n",
9192 thread_params
.thread_window
, test_window
);
9193 /* Active and focus are window1 on wine because the internal WM_WINE_SETACTIVEWINDOW(0)
9194 * message is never generated. GetCapture() returns 0 though, so we'd get a test success
9195 * in todo_wine in the line below.
9196 * todo_wine check_wnd_state(0, thread_params.thread_window, 0, 0); */
9197 ok(app_activated
, "Expected WM_ACTIVATEAPP(1), did not receive it.\n");
9198 todo_wine
ok(app_deactivated
, "Expected WM_ACTIVATEAPP(0), did not receive it.\n");
9200 SetForegroundWindow(window1
);
9201 test_window
= GetForegroundWindow();
9202 ok(test_window
== window1
, "Expected foreground window %p, got %p\n",
9203 window1
, test_window
);
9204 check_wnd_state(window1
, window1
, window1
, 0);
9206 /* Switch to a different window from the same thread? No messages. */
9207 app_activated
= app_deactivated
= FALSE
;
9208 PostThreadMessageA(tid
, thread_params
.msg_command
, SET_FOREGROUND_STEAL_1
| SET_FOREGROUND_SET_2
, 0);
9209 WaitForSingleObject(thread_params
.command_executed
, INFINITE
);
9210 test_window
= GetForegroundWindow();
9211 ok(test_window
== window1
, "Expected foreground window %p, got %p\n",
9212 window1
, test_window
);
9213 check_wnd_state(window1
, window1
, window1
, 0);
9214 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9215 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9216 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
9217 test_window
= GetForegroundWindow();
9218 ok(test_window
== window2
, "Expected foreground window %p, got %p\n",
9219 window2
, test_window
);
9220 check_wnd_state(window2
, window2
, window2
, 0);
9221 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9222 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9224 PostThreadMessageA(tid
, thread_params
.msg_quit
, 0, 0);
9225 WaitForSingleObject(thread
, INFINITE
);
9227 CloseHandle(thread_params
.command_executed
);
9228 DestroyWindow(window2
);
9231 static LRESULT WINAPI
winproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
9234 int *count
= (int*)lparam
;
9240 static LRESULT WINAPI
winproc_convA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
9242 if(msg
== WM_SETTEXT
)
9244 const char *text
= (const char*)lparam
;
9246 ok(!wparam
, "wparam = %08lx\n", wparam
);
9247 ok(!strcmp(text
, "text"), "WM_SETTEXT lparam = %s\n", text
);
9253 static const WCHAR textW
[] = {'t','e','x','t',0};
9254 static LRESULT WINAPI
winproc_convW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
9256 if(msg
== WM_SETTEXT
)
9258 const WCHAR
*text
= (const WCHAR
*)lparam
;
9260 ok(!wparam
, "wparam = %08lx\n", wparam
);
9261 ok(!lstrcmpW(text
, textW
), "WM_SETTEXT lparam = %s\n", wine_dbgstr_w(text
));
9267 static void test_winproc_handles(const char *argv0
)
9269 static const WCHAR winproc_testW
[] = {'w','i','n','p','r','o','c','_','t','e','s','t',0};
9271 HINSTANCE hinst
= GetModuleHandleA(NULL
);
9272 WNDCLASSA wnd_classA
;
9273 WNDCLASSW wnd_classW
;
9275 PROCESS_INFORMATION info
;
9276 STARTUPINFOA startup
;
9279 memset(&wnd_classA
, 0, sizeof(wnd_classA
));
9280 wnd_classA
.lpszClassName
= "winproc_test";
9281 wnd_classA
.lpfnWndProc
= winproc
;
9282 ret
= RegisterClassA(&wnd_classA
);
9283 ok(ret
, "RegisterClass failed with error %d\n", GetLastError());
9285 ret
= GetClassInfoW(hinst
, winproc_testW
, &wnd_classW
);
9286 ok(ret
, "GetClassInfoW failed with error %d\n", GetLastError());
9287 ok(wnd_classA
.lpfnWndProc
!= wnd_classW
.lpfnWndProc
,
9288 "winproc pointers should not be identical\n");
9291 CallWindowProcA(wnd_classW
.lpfnWndProc
, 0, 0, 0, (LPARAM
)&count
);
9292 ok(count
== 1, "winproc should be called once (%d)\n", count
);
9294 CallWindowProcW(wnd_classW
.lpfnWndProc
, 0, 0, 0, (LPARAM
)&count
);
9295 ok(count
== 1, "winproc should be called once (%d)\n", count
);
9297 ret
= UnregisterClassW(winproc_testW
, hinst
);
9298 ok(ret
, "UnregisterClass failed with error %d\n", GetLastError());
9300 /* crashes on 64-bit windows because lpfnWndProc handle is already freed */
9301 if (sizeof(void*) == 4)
9304 CallWindowProcA(wnd_classW
.lpfnWndProc
, 0, 0, 0, (LPARAM
)&count
);
9305 todo_wine
ok(!count
, "winproc should not be called (%d)\n", count
);
9306 CallWindowProcW(wnd_classW
.lpfnWndProc
, 0, 0, 0, (LPARAM
)&count
);
9307 todo_wine
ok(!count
, "winproc should not be called (%d)\n", count
);
9310 sprintf(cmd
, "%s win winproc_limit", argv0
);
9311 memset(&startup
, 0, sizeof(startup
));
9312 startup
.cb
= sizeof(startup
);
9313 ok(CreateProcessA(NULL
, cmd
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
,
9314 &startup
, &info
), "CreateProcess failed.\n");
9315 winetest_wait_child_process(info
.hProcess
);
9316 CloseHandle(info
.hProcess
);
9317 CloseHandle(info
.hThread
);
9320 static void test_winproc_limit(void)
9322 WNDPROC winproc_handle
;
9327 hwnd
= CreateWindowExA(0, "static", "test", WS_POPUP
, 0, 0, 0, 0, 0, 0, 0, 0);
9328 ok(hwnd
!= 0, "CreateWindowEx failed\n");
9330 ok(SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)winproc
),
9331 "SetWindowLongPtr failed\n");
9332 winproc_handle
= (WNDPROC
)GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
);
9333 ok(winproc_handle
!= winproc
, "winproc pointers should not be identical\n");
9335 /* run out of winproc slots */
9336 for(i
= 2; i
<0xffff; i
++)
9338 ok(SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, i
), "SetWindowLongPtr failed (%d)\n", i
);
9339 if(GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == i
)
9342 ok(i
!= 0xffff, "unable to run out of winproc slots\n");
9344 ret
= SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)winproc_convA
);
9345 ok(ret
, "SetWindowLongPtr failed with error %d\n", GetLastError());
9346 ok(SendMessageA(hwnd
, WM_SETTEXT
, 0, (LPARAM
)"text"), "WM_SETTEXT failed\n");
9347 ok(SendMessageW(hwnd
, WM_SETTEXT
, 0, (LPARAM
)textW
), "WM_SETTEXT with conversion failed\n");
9349 ret
= SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)winproc_convW
);
9350 ok(ret
, "SetWindowLongPtr failed with error %d\n", GetLastError());
9351 ok(SendMessageA(hwnd
, WM_SETTEXT
, 0, (LPARAM
)"text"), "WM_SETTEXT failed\n");
9352 ok(SendMessageW(hwnd
, WM_SETTEXT
, 0, (LPARAM
)textW
), "WM_SETTEXT with conversion failed\n");
9354 /* Show that there's no message conversion when CallWindowProc is used */
9355 ok(CallWindowProcA(winproc_convW
, hwnd
, WM_SETTEXT
, 0, (LPARAM
)textW
) == 1,
9356 "winproc_convW returned error\n");
9357 ok(CallWindowProcW(winproc_convW
, hwnd
, WM_SETTEXT
, 0, (LPARAM
)textW
) == 1,
9358 "winproc_convW returned error\n");
9361 CallWindowProcA(winproc_handle
, 0, 0, 0, (LPARAM
)&i
);
9362 ok(i
== 1, "winproc should be called once (%d)\n", i
);
9364 CallWindowProcW(winproc_handle
, 0, 0, 0, (LPARAM
)&i
);
9365 ok(i
== 1, "winproc should be called once (%d)\n", i
);
9367 DestroyWindow(hwnd
);
9370 CallWindowProcA(winproc_handle
, 0, 0, 0, (LPARAM
)&i
);
9371 ok(i
== 1, "winproc should be called once (%d)\n", i
);
9373 CallWindowProcW(winproc_handle
, 0, 0, 0, (LPARAM
)&i
);
9374 ok(i
== 1, "winproc should be called once (%d)\n", i
);
9377 static void test_deferwindowpos(void)
9382 hdwp
= BeginDeferWindowPos(0);
9383 ok(hdwp
!= NULL
, "got %p\n", hdwp
);
9385 ret
= EndDeferWindowPos(NULL
);
9386 ok(!ret
, "got %d\n", ret
);
9388 hdwp2
= DeferWindowPos(NULL
, NULL
, NULL
, 0, 0, 10, 10, 0);
9390 ok(hdwp2
== NULL
&& ((GetLastError() == ERROR_INVALID_DWP_HANDLE
) ||
9391 broken(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
) /* before win8 */), "got %p, error %d\n", hdwp2
, GetLastError());
9393 hdwp2
= DeferWindowPos((HDWP
)0xdead, GetDesktopWindow(), NULL
, 0, 0, 10, 10, 0);
9395 ok(hdwp2
== NULL
&& ((GetLastError() == ERROR_INVALID_DWP_HANDLE
) ||
9396 broken(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
) /* before win8 */), "got %p, error %d\n", hdwp2
, GetLastError());
9398 hdwp2
= DeferWindowPos(hdwp
, NULL
, NULL
, 0, 0, 10, 10, 0);
9399 ok(hdwp2
== NULL
&& GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "got %p, error %d\n", hdwp2
, GetLastError());
9401 hdwp2
= DeferWindowPos(hdwp
, GetDesktopWindow(), NULL
, 0, 0, 10, 10, 0);
9402 ok(hdwp2
== NULL
&& GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "got %p, error %d\n", hdwp2
, GetLastError());
9404 hdwp2
= DeferWindowPos(hdwp
, (HWND
)0xdead, NULL
, 0, 0, 10, 10, 0);
9405 ok(hdwp2
== NULL
&& GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "got %p, error %d\n", hdwp2
, GetLastError());
9407 ret
= EndDeferWindowPos(hdwp
);
9408 ok(ret
, "got %d\n", ret
);
9414 int argc
= winetest_get_mainargs( &argv
);
9415 HMODULE user32
= GetModuleHandleA( "user32.dll" );
9416 HMODULE gdi32
= GetModuleHandleA("gdi32.dll");
9417 pGetAncestor
= (void *)GetProcAddress( user32
, "GetAncestor" );
9418 pGetWindowInfo
= (void *)GetProcAddress( user32
, "GetWindowInfo" );
9419 pGetWindowModuleFileNameA
= (void *)GetProcAddress( user32
, "GetWindowModuleFileNameA" );
9420 pGetLayeredWindowAttributes
= (void *)GetProcAddress( user32
, "GetLayeredWindowAttributes" );
9421 pSetLayeredWindowAttributes
= (void *)GetProcAddress( user32
, "SetLayeredWindowAttributes" );
9422 pUpdateLayeredWindow
= (void *)GetProcAddress( user32
, "UpdateLayeredWindow" );
9423 pUpdateLayeredWindowIndirect
= (void *)GetProcAddress( user32
, "UpdateLayeredWindowIndirect" );
9424 pGetMonitorInfoA
= (void *)GetProcAddress( user32
, "GetMonitorInfoA" );
9425 pMonitorFromPoint
= (void *)GetProcAddress( user32
, "MonitorFromPoint" );
9426 pGetWindowRgnBox
= (void *)GetProcAddress( user32
, "GetWindowRgnBox" );
9427 pGetGUIThreadInfo
= (void *)GetProcAddress( user32
, "GetGUIThreadInfo" );
9428 pGetProcessDefaultLayout
= (void *)GetProcAddress( user32
, "GetProcessDefaultLayout" );
9429 pSetProcessDefaultLayout
= (void *)GetProcAddress( user32
, "SetProcessDefaultLayout" );
9430 pFlashWindow
= (void *)GetProcAddress( user32
, "FlashWindow" );
9431 pFlashWindowEx
= (void *)GetProcAddress( user32
, "FlashWindowEx" );
9432 pGetLayout
= (void *)GetProcAddress( gdi32
, "GetLayout" );
9433 pSetLayout
= (void *)GetProcAddress( gdi32
, "SetLayout" );
9434 pMirrorRgn
= (void *)GetProcAddress( gdi32
, "MirrorRgn" );
9436 if (argc
==4 && !strcmp(argv
[2], "create_children"))
9440 sscanf(argv
[3], "%p", &hwnd
);
9441 window_from_point_proc(hwnd
);
9445 if (argc
==3 && !strcmp(argv
[2], "winproc_limit"))
9447 test_winproc_limit();
9451 if (!RegisterWindowClasses()) assert(0);
9453 hwndMain
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
9454 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
9455 WS_MAXIMIZEBOX
| WS_POPUP
| WS_VISIBLE
,
9457 0, 0, GetModuleHandleA(NULL
), NULL
);
9460 if(!SetForegroundWindow(hwndMain
)) {
9461 /* workaround for foreground lock timeout */
9462 simulate_click(101, 101);
9463 ok(SetForegroundWindow(hwndMain
), "SetForegroundWindow failed\n");
9466 SetLastError(0xdeafbeef);
9467 GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC
);
9468 is_win9x
= (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
);
9470 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
9471 if (!hhook
) win_skip( "Cannot set CBT hook, skipping some tests\n" );
9473 /* make sure that these tests are executed first */
9474 test_FindWindowEx();
9477 hwndMain2
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
9478 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
9479 WS_MAXIMIZEBOX
| WS_POPUP
,
9481 0, 0, GetModuleHandleA(NULL
), NULL
);
9482 assert( hwndMain2
);
9484 our_pid
= GetWindowThreadProcessId(hwndMain
, NULL
);
9486 /* Add the tests below this line */
9487 test_child_window_from_point();
9488 test_window_from_point(argv
[0]);
9489 test_thick_child_size(hwndMain
);
9491 test_hwnd_message();
9492 test_nonclient_area(hwndMain
);
9494 test_GetWindowModuleFileName();
9497 test_capture_3(hwndMain
, hwndMain2
);
9501 test_FlashWindowEx();
9503 test_CreateWindow();
9504 test_parent_owner();
9505 test_enum_thread_windows();
9509 test_SetWindowPos(hwndMain
, hwndMain2
);
9510 test_SetMenu(hwndMain
);
9511 test_SetFocus(hwndMain
);
9512 test_SetActiveWindow(hwndMain
);
9515 test_children_zorder(hwndMain
);
9516 test_popup_zorder(hwndMain2
, hwndMain
, WS_POPUP
);
9517 test_popup_zorder(hwndMain2
, hwndMain
, 0);
9518 test_GetLastActivePopup();
9519 test_keyboard_input(hwndMain
);
9520 test_mouse_input(hwndMain
);
9521 test_validatergn(hwndMain
);
9522 test_nccalcscroll( hwndMain
);
9523 test_scrollwindow( hwndMain
);
9524 test_scrollvalidate( hwndMain
);
9525 test_scrolldc( hwndMain
);
9527 test_IsWindowUnicode();
9528 test_vis_rgn(hwndMain
);
9530 test_AdjustWindowRect();
9531 test_window_styles();
9532 test_dialog_styles();
9533 test_dialog_parent();
9536 test_SetWindowLong();
9537 test_set_window_style();
9540 test_GetUpdateRect();
9542 test_layered_window();
9544 test_SetForegroundWindow(hwndMain
);
9545 test_shell_window();
9546 test_handles( hwndMain
);
9549 test_update_region();
9550 test_window_without_child_style();
9552 test_GetMessagePos();
9554 test_activateapp(hwndMain
);
9555 test_winproc_handles(argv
[0]);
9556 test_deferwindowpos();
9558 /* add the tests above this line */
9559 if (hhook
) UnhookWindowsHookEx(hhook
);
9561 DestroyWindow(hwndMain2
);
9562 DestroyWindow(hwndMain
);