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
42 #define LONG_PTR INT_PTR
43 #define ULONG_PTR UINT_PTR
45 void dump_region(HRGN hrgn
);
47 static HWND (WINAPI
*pGetAncestor
)(HWND
,UINT
);
48 static BOOL (WINAPI
*pGetWindowInfo
)(HWND
,WINDOWINFO
*);
49 static UINT (WINAPI
*pGetWindowModuleFileNameA
)(HWND
,LPSTR
,UINT
);
50 static BOOL (WINAPI
*pGetLayeredWindowAttributes
)(HWND
,COLORREF
*,BYTE
*,DWORD
*);
51 static BOOL (WINAPI
*pSetLayeredWindowAttributes
)(HWND
,COLORREF
,BYTE
,DWORD
);
52 static BOOL (WINAPI
*pUpdateLayeredWindow
)(HWND
,HDC
,POINT
*,SIZE
*,HDC
,POINT
*,COLORREF
,BLENDFUNCTION
*,DWORD
);
53 static BOOL (WINAPI
*pUpdateLayeredWindowIndirect
)(HWND
,const UPDATELAYEREDWINDOWINFO
*);
54 static BOOL (WINAPI
*pGetMonitorInfoA
)(HMONITOR
,LPMONITORINFO
);
55 static HMONITOR (WINAPI
*pMonitorFromPoint
)(POINT
,DWORD
);
56 static int (WINAPI
*pGetWindowRgnBox
)(HWND
,LPRECT
);
57 static BOOL (WINAPI
*pGetGUIThreadInfo
)(DWORD
, GUITHREADINFO
*);
58 static BOOL (WINAPI
*pGetProcessDefaultLayout
)( DWORD
*layout
);
59 static BOOL (WINAPI
*pSetProcessDefaultLayout
)( DWORD layout
);
60 static BOOL (WINAPI
*pFlashWindow
)( HWND hwnd
, BOOL bInvert
);
61 static BOOL (WINAPI
*pFlashWindowEx
)( PFLASHWINFO pfwi
);
62 static DWORD (WINAPI
*pSetLayout
)(HDC hdc
, DWORD layout
);
63 static DWORD (WINAPI
*pGetLayout
)(HDC hdc
);
64 static BOOL (WINAPI
*pMirrorRgn
)(HWND hwnd
, HRGN hrgn
);
66 static BOOL test_lbuttondown_flag
;
67 static DWORD num_gettext_msgs
;
68 static DWORD num_settext_msgs
;
69 static HWND hwndMessage
;
70 static HWND hwndMain
, hwndMain2
;
72 static BOOL app_activated
, app_deactivated
;
74 static const char* szAWRClass
= "Winsize";
78 static BOOL is_win9x
= FALSE
;
80 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
82 static void dump_minmax_info( const MINMAXINFO
*minmax
)
84 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
85 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
86 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
87 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
88 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
89 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
92 /* try to make sure pending X events have been processed before continuing */
93 static void flush_events( BOOL remove_messages
)
97 int min_timeout
= 100;
98 DWORD time
= GetTickCount() + diff
;
102 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
104 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
105 diff
= time
- GetTickCount();
110 static BOOL
wait_for_event(HANDLE event
, int timeout
)
112 DWORD end_time
= GetTickCount() + timeout
;
116 if(MsgWaitForMultipleObjects(1, &event
, FALSE
, timeout
, QS_ALLINPUT
) == WAIT_OBJECT_0
)
118 while(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
119 DispatchMessageA(&msg
);
120 timeout
= end_time
- GetTickCount();
126 /* check the values returned by the various parent/owner functions on a given window */
127 static void check_parents( HWND hwnd
, HWND ga_parent
, HWND gwl_parent
, HWND get_parent
,
128 HWND gw_owner
, HWND ga_root
, HWND ga_root_owner
)
134 res
= pGetAncestor( hwnd
, GA_PARENT
);
135 ok( res
== ga_parent
, "Wrong result for GA_PARENT %p expected %p\n", res
, ga_parent
);
137 res
= (HWND
)GetWindowLongPtrA( hwnd
, GWLP_HWNDPARENT
);
138 ok( res
== gwl_parent
, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res
, gwl_parent
);
139 res
= GetParent( hwnd
);
140 ok( res
== get_parent
, "Wrong result for GetParent %p expected %p\n", res
, get_parent
);
141 res
= GetWindow( hwnd
, GW_OWNER
);
142 ok( res
== gw_owner
, "Wrong result for GW_OWNER %p expected %p\n", res
, gw_owner
);
145 res
= pGetAncestor( hwnd
, GA_ROOT
);
146 ok( res
== ga_root
, "Wrong result for GA_ROOT %p expected %p\n", res
, ga_root
);
147 res
= pGetAncestor( hwnd
, GA_ROOTOWNER
);
148 ok( res
== ga_root_owner
, "Wrong result for GA_ROOTOWNER %p expected %p\n", res
, ga_root_owner
);
152 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
153 static void check_wnd_state_(const char *file
, int line
,
154 HWND active
, HWND foreground
, HWND focus
, HWND capture
)
156 ok_(file
, line
)(active
== GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
157 /* only check foreground if it belongs to the current thread */
158 /* foreground can be moved to a different app pretty much at any time */
159 if (foreground
&& GetForegroundWindow() &&
160 GetWindowThreadProcessId(GetForegroundWindow(), NULL
) == GetCurrentThreadId())
161 ok_(file
, line
)(foreground
== GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
162 ok_(file
, line
)(focus
== GetFocus(), "GetFocus() = %p\n", GetFocus());
163 ok_(file
, line
)(capture
== GetCapture(), "GetCapture() = %p\n", GetCapture());
166 /* same as above but without capture test */
167 #define check_active_state(a,b,c) check_active_state_(__FILE__,__LINE__,a,b,c)
168 static void check_active_state_(const char *file
, int line
,
169 HWND active
, HWND foreground
, HWND focus
)
171 ok_(file
, line
)(active
== GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
172 /* only check foreground if it belongs to the current thread */
173 /* foreground can be moved to a different app pretty much at any time */
174 if (foreground
&& GetForegroundWindow() &&
175 GetWindowThreadProcessId(GetForegroundWindow(), NULL
) == GetCurrentThreadId())
176 ok_(file
, line
)(foreground
== GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
177 ok_(file
, line
)(focus
== GetFocus(), "GetFocus() = %p\n", GetFocus());
180 static BOOL
ignore_message( UINT message
)
182 /* these are always ignored */
183 return (message
>= 0xc000 ||
184 message
== WM_GETICON
||
185 message
== WM_GETOBJECT
||
186 message
== WM_TIMECHANGE
||
187 message
== WM_DEVICECHANGE
);
190 static BOOL CALLBACK
EnumChildProc( HWND hwndChild
, LPARAM lParam
)
193 trace("EnumChildProc on %p\n", hwndChild
);
194 if (*(LPINT
)lParam
> 1) return FALSE
;
198 /* will search for the given window */
199 static BOOL CALLBACK
EnumChildProc1( HWND hwndChild
, LPARAM lParam
)
201 trace("EnumChildProc1 on %p\n", hwndChild
);
202 if ((HWND
)lParam
== hwndChild
) return FALSE
;
206 static HWND
create_tool_window( LONG style
, HWND parent
)
208 HWND ret
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style
,
209 0, 0, 100, 100, parent
, 0, 0, NULL
);
210 ok( ret
!= 0, "Creation failed\n" );
214 /* test parent and owner values for various combinations */
215 static void test_parent_owner(void)
218 HWND test
, owner
, ret
;
219 HWND desktop
= GetDesktopWindow();
220 HWND child
= create_tool_window( WS_CHILD
, hwndMain
);
223 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain
, hwndMain2
, desktop
, child
);
225 /* child without parent, should fail */
226 SetLastError(0xdeadbeef);
227 test
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
228 WS_CHILD
, 0, 0, 100, 100, 0, 0, 0, NULL
);
229 ok( !test
, "WS_CHILD without parent created\n" );
230 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD
||
231 broken(GetLastError() == 0xdeadbeef), /* win9x */
232 "CreateWindowExA error %u\n", GetLastError() );
235 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
236 style
= GetWindowLongA( desktop
, GWL_STYLE
);
237 ok( !SetWindowLongA( desktop
, GWL_STYLE
, WS_POPUP
), "Set GWL_STYLE on desktop succeeded\n" );
238 ok( !SetWindowLongA( desktop
, GWL_STYLE
, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
239 ok( GetWindowLongA( desktop
, GWL_STYLE
) == style
, "Desktop style changed\n" );
241 /* normal child window */
242 test
= create_tool_window( WS_CHILD
, hwndMain
);
243 trace( "created child %p\n", test
);
244 check_parents( test
, hwndMain
, hwndMain
, hwndMain
, 0, hwndMain
, hwndMain
);
245 SetWindowLongA( test
, GWL_STYLE
, 0 );
246 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
247 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
248 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
249 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
|WS_CHILD
);
250 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
251 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
252 DestroyWindow( test
);
254 /* normal child window with WS_MAXIMIZE */
255 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
256 DestroyWindow( test
);
258 /* normal child window with WS_THICKFRAME */
259 test
= create_tool_window( WS_CHILD
| WS_THICKFRAME
, hwndMain
);
260 DestroyWindow( test
);
262 /* popup window with WS_THICKFRAME */
263 test
= create_tool_window( WS_POPUP
| WS_THICKFRAME
, hwndMain
);
264 DestroyWindow( test
);
266 /* child of desktop */
267 test
= create_tool_window( WS_CHILD
, desktop
);
268 trace( "created child of desktop %p\n", test
);
269 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
270 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
271 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
272 SetWindowLongA( test
, GWL_STYLE
, 0 );
273 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
274 DestroyWindow( test
);
276 /* child of desktop with WS_MAXIMIZE */
277 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, desktop
);
278 DestroyWindow( test
);
280 /* child of desktop with WS_MINIMIZE */
281 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, desktop
);
282 DestroyWindow( test
);
285 test
= create_tool_window( WS_CHILD
, child
);
286 trace( "created child of child %p\n", test
);
287 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
288 SetWindowLongA( test
, GWL_STYLE
, 0 );
289 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
290 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
291 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
292 DestroyWindow( test
);
294 /* child of child with WS_MAXIMIZE */
295 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, child
);
296 DestroyWindow( test
);
298 /* child of child with WS_MINIMIZE */
299 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, child
);
300 DestroyWindow( test
);
302 /* not owned top-level window */
303 test
= create_tool_window( 0, 0 );
304 trace( "created top-level %p\n", test
);
305 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
306 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
307 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
308 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
309 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
310 DestroyWindow( test
);
312 /* not owned top-level window with WS_MAXIMIZE */
313 test
= create_tool_window( WS_MAXIMIZE
, 0 );
314 DestroyWindow( test
);
316 /* owned top-level window */
317 test
= create_tool_window( 0, hwndMain
);
318 trace( "created owned top-level %p\n", test
);
319 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
320 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
321 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
322 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
323 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
324 DestroyWindow( test
);
326 /* owned top-level window with WS_MAXIMIZE */
327 test
= create_tool_window( WS_MAXIMIZE
, hwndMain
);
328 DestroyWindow( test
);
330 /* not owned popup */
331 test
= create_tool_window( WS_POPUP
, 0 );
332 trace( "created popup %p\n", test
);
333 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
334 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
335 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
336 SetWindowLongA( test
, GWL_STYLE
, 0 );
337 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
338 DestroyWindow( test
);
340 /* not owned popup with WS_MAXIMIZE */
341 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, 0 );
342 DestroyWindow( test
);
345 test
= create_tool_window( WS_POPUP
, hwndMain
);
346 trace( "created owned popup %p\n", test
);
347 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
348 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
349 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
350 SetWindowLongA( test
, GWL_STYLE
, 0 );
351 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
352 DestroyWindow( test
);
354 /* owned popup with WS_MAXIMIZE */
355 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, hwndMain
);
356 DestroyWindow( test
);
358 /* top-level window owned by child (same as owned by top-level) */
359 test
= create_tool_window( 0, child
);
360 trace( "created top-level owned by child %p\n", test
);
361 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
362 DestroyWindow( test
);
364 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
365 test
= create_tool_window( WS_MAXIMIZE
, child
);
366 DestroyWindow( test
);
368 /* popup owned by desktop (same as not owned) */
369 test
= create_tool_window( WS_POPUP
, desktop
);
370 trace( "created popup owned by desktop %p\n", test
);
371 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
372 DestroyWindow( test
);
374 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
375 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, desktop
);
376 DestroyWindow( test
);
378 /* popup owned by child (same as owned by top-level) */
379 test
= create_tool_window( WS_POPUP
, child
);
380 trace( "created popup owned by child %p\n", test
);
381 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
382 DestroyWindow( test
);
384 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
385 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, child
);
386 DestroyWindow( test
);
388 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
389 test
= create_tool_window( WS_POPUP
| WS_CHILD
, 0 );
390 trace( "created WS_CHILD popup %p\n", test
);
391 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
392 DestroyWindow( test
);
394 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
395 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, 0 );
396 DestroyWindow( test
);
398 /* owned popup with WS_CHILD (same as WS_POPUP only) */
399 test
= create_tool_window( WS_POPUP
| WS_CHILD
, hwndMain
);
400 trace( "created owned WS_CHILD popup %p\n", test
);
401 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
402 DestroyWindow( test
);
404 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
405 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
406 DestroyWindow( test
);
408 /******************** parent changes *************************/
409 trace( "testing parent changes\n" );
412 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
415 /* this test succeeds on NT but crashes on win9x systems */
416 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
417 ok( !ret
, "Set GWL_HWNDPARENT succeeded on desktop\n" );
418 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
419 ok( !SetParent( desktop
, hwndMain
), "SetParent succeeded on desktop\n" );
420 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
422 /* normal child window */
423 test
= create_tool_window( WS_CHILD
, hwndMain
);
424 trace( "created child %p\n", test
);
426 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
427 ok( ret
== hwndMain
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain
);
428 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
430 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
431 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
432 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
434 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)desktop
);
435 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
436 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
438 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
441 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)test
);
442 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
443 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
446 win_skip("Test creates circular window tree under Win9x/WinMe\n" );
448 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
449 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
450 check_parents( test
, desktop
, child
, desktop
, child
, test
, desktop
);
452 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
453 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
454 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
455 DestroyWindow( test
);
457 /* not owned top-level window */
458 test
= create_tool_window( 0, 0 );
459 trace( "created top-level %p\n", test
);
461 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
462 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
463 check_parents( test
, desktop
, hwndMain2
, 0, hwndMain2
, test
, test
);
465 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
466 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
467 check_parents( test
, desktop
, child
, 0, child
, test
, test
);
469 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
470 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
471 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
472 DestroyWindow( test
);
474 /* not owned popup */
475 test
= create_tool_window( WS_POPUP
, 0 );
476 trace( "created popup %p\n", test
);
478 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
479 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
480 check_parents( test
, desktop
, hwndMain2
, hwndMain2
, hwndMain2
, test
, hwndMain2
);
482 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
483 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
484 check_parents( test
, desktop
, child
, child
, child
, test
, hwndMain
);
486 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
487 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
488 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
489 DestroyWindow( test
);
491 /* normal child window */
492 test
= create_tool_window( WS_CHILD
, hwndMain
);
493 trace( "created child %p\n", test
);
495 ret
= SetParent( test
, desktop
);
496 ok( ret
== hwndMain
, "SetParent return value %p expected %p\n", ret
, hwndMain
);
497 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
499 ret
= SetParent( test
, child
);
500 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
501 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
503 ret
= SetParent( test
, hwndMain2
);
504 ok( ret
== child
, "SetParent return value %p expected %p\n", ret
, child
);
505 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
506 DestroyWindow( test
);
508 /* not owned top-level window */
509 test
= create_tool_window( 0, 0 );
510 trace( "created top-level %p\n", test
);
512 ret
= SetParent( test
, child
);
513 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
514 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
518 ShowWindow( test
, SW_SHOW
);
519 ret
= SetParent( test
, test
);
520 ok( ret
== NULL
, "SetParent return value %p expected %p\n", ret
, NULL
);
521 ok( GetWindowLongA( test
, GWL_STYLE
) & WS_VISIBLE
, "window is not visible after SetParent\n" );
522 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
525 win_skip( "Test crashes on Win9x/WinMe\n" );
526 DestroyWindow( test
);
529 test
= create_tool_window( WS_POPUP
, hwndMain2
);
530 trace( "created owned popup %p\n", test
);
532 ret
= SetParent( test
, child
);
533 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
534 check_parents( test
, child
, child
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
536 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)hwndMain
);
537 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
538 check_parents( test
, hwndMain
, hwndMain
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
539 DestroyWindow( test
);
541 /**************** test owner destruction *******************/
543 /* owned child popup */
544 owner
= create_tool_window( 0, 0 );
545 test
= create_tool_window( WS_POPUP
, owner
);
546 trace( "created owner %p and popup %p\n", owner
, test
);
547 ret
= SetParent( test
, child
);
548 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
549 check_parents( test
, child
, child
, owner
, owner
, hwndMain
, owner
);
550 /* window is now child of 'child' but owned by 'owner' */
551 DestroyWindow( owner
);
552 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
553 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
554 * while Win95, Win2k, WinXP do.
556 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
557 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
560 /* owned top-level popup */
561 owner
= create_tool_window( 0, 0 );
562 test
= create_tool_window( WS_POPUP
, owner
);
563 trace( "created owner %p and popup %p\n", owner
, test
);
564 check_parents( test
, desktop
, owner
, owner
, owner
, test
, owner
);
565 DestroyWindow( owner
);
566 ok( !IsWindow(test
), "Window %p not destroyed by owner destruction\n", test
);
568 /* top-level popup owned by child */
569 owner
= create_tool_window( WS_CHILD
, hwndMain2
);
570 test
= create_tool_window( WS_POPUP
, 0 );
571 trace( "created owner %p and popup %p\n", owner
, test
);
572 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)owner
);
573 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
574 check_parents( test
, desktop
, owner
, owner
, owner
, test
, hwndMain2
);
575 DestroyWindow( owner
);
576 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
577 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
578 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
579 * while Win95, Win2k, WinXP do.
581 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
585 DestroyWindow(child
);
588 owner
= create_tool_window( WS_OVERLAPPED
, 0 );
589 test
= create_tool_window( WS_POPUP
, desktop
);
591 ok( !GetWindow( test
, GW_OWNER
), "Wrong owner window\n" );
593 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
594 "EnumChildWindows should have returned FALSE\n" );
595 ok( numChildren
== 0, "numChildren should be 0 got %d\n", numChildren
);
597 SetWindowLongA( test
, GWL_STYLE
, (GetWindowLongA( test
, GWL_STYLE
) & ~WS_POPUP
) | WS_CHILD
);
598 ret
= SetParent( test
, owner
);
599 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
602 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
603 "EnumChildWindows should have returned TRUE\n" );
604 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
606 child
= create_tool_window( WS_CHILD
, owner
);
608 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
609 "EnumChildWindows should have returned FALSE\n" );
610 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
611 DestroyWindow( child
);
613 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, owner
);
614 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
616 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
617 "EnumChildWindows should have returned TRUE\n" );
618 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
620 ret
= SetParent( child
, owner
);
621 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
622 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
624 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
625 "EnumChildWindows should have returned FALSE\n" );
626 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
628 ret
= SetParent( child
, NULL
);
629 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
630 ok( ret
== owner
, "SetParent return value %p expected %p\n", ret
, owner
);
632 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
633 "EnumChildWindows should have returned TRUE\n" );
634 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
636 /* even GW_OWNER == owner it's still a desktop's child */
637 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
638 "EnumChildWindows should have found %p and returned FALSE\n", child
);
640 DestroyWindow( child
);
641 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, NULL
);
643 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
644 "EnumChildWindows should have found %p and returned FALSE\n", child
);
646 DestroyWindow( child
);
647 DestroyWindow( test
);
648 DestroyWindow( owner
);
651 static BOOL CALLBACK
enum_proc( HWND hwnd
, LPARAM lParam
)
654 if (*(LPINT
)lParam
> 2) return FALSE
;
657 static DWORD CALLBACK
enum_thread( void *arg
)
664 if (pGetGUIThreadInfo
)
667 info
.cbSize
= sizeof(info
);
668 ret
= pGetGUIThreadInfo( GetCurrentThreadId(), &info
);
669 ok( ret
|| broken(!ret
), /* win9x */
670 "GetGUIThreadInfo failed without message queue\n" );
671 SetLastError( 0xdeadbeef );
672 info
.cbSize
= sizeof(info
) + 1;
673 ret
= pGetGUIThreadInfo( GetCurrentThreadId(), &info
);
674 ok( !ret
, "GetGUIThreadInfo succeeded with wrong size\n" );
675 ok( GetLastError() == ERROR_INVALID_PARAMETER
||
676 broken(GetLastError() == 0xdeadbeef), /* win9x */
677 "wrong error %u\n", GetLastError() );
680 PeekMessageA( &msg
, 0, 0, 0, PM_NOREMOVE
); /* make sure we have a message queue */
683 ret
= EnumThreadWindows( GetCurrentThreadId(), enum_proc
, (LPARAM
)&count
);
684 ok( ret
, "EnumThreadWindows should have returned TRUE\n" );
685 ok( count
== 0, "count should be 0 got %d\n", count
);
687 hwnd
[0] = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", WS_POPUP
,
688 0, 0, 100, 100, 0, 0, 0, NULL
);
690 ret
= EnumThreadWindows( GetCurrentThreadId(), enum_proc
, (LPARAM
)&count
);
691 ok( ret
, "EnumThreadWindows should have returned TRUE\n" );
692 if (count
!= 2) /* Vista gives us two windows for the price of one */
694 ok( count
== 1, "count should be 1 got %d\n", count
);
695 hwnd
[2] = CreateWindowExA(0, "ToolWindowClass", "Tool window 2", WS_POPUP
,
696 0, 0, 100, 100, 0, 0, 0, NULL
);
700 hwnd
[1] = CreateWindowExA(0, "ToolWindowClass", "Tool window 3", WS_POPUP
,
701 0, 0, 100, 100, 0, 0, 0, NULL
);
703 ret
= EnumThreadWindows( GetCurrentThreadId(), enum_proc
, (LPARAM
)&count
);
704 ok( !ret
, "EnumThreadWindows should have returned FALSE\n" );
705 ok( count
== 3, "count should be 3 got %d\n", count
);
707 if (hwnd
[2]) DestroyWindow(hwnd
[2]);
708 DestroyWindow(hwnd
[1]);
709 DestroyWindow(hwnd
[0]);
713 /* test EnumThreadWindows in a separate thread */
714 static void test_enum_thread_windows(void)
717 HANDLE handle
= CreateThread( NULL
, 0, enum_thread
, 0, 0, &id
);
718 ok( !WaitForSingleObject( handle
, 10000 ), "wait failed\n" );
719 CloseHandle( handle
);
722 static struct wm_gettext_override_data
724 BOOL enabled
; /* when 1 bypasses default procedure */
725 char *buff
; /* expected text buffer pointer */
726 WCHAR
*buffW
; /* same, for W test */
727 } g_wm_gettext_override
;
729 static LRESULT WINAPI
main_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
733 case WM_GETMINMAXINFO
:
735 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
738 case WM_WINDOWPOSCHANGING
:
740 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
741 if (!(winpos
->flags
& SWP_NOMOVE
))
743 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
744 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
746 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
747 if (!(winpos
->flags
& SWP_NOSIZE
) && !is_win9x
)
749 ok((winpos
->cx
>= 0 && winpos
->cx
<= 32767) ||
750 winpos
->cx
== 32768, /* win7 doesn't truncate */
751 "bad winpos->cx %d\n", winpos
->cx
);
752 ok((winpos
->cy
>= 0 && winpos
->cy
<= 32767) ||
753 winpos
->cy
== 40000, /* win7 doesn't truncate */
754 "bad winpos->cy %d\n", winpos
->cy
);
758 case WM_WINDOWPOSCHANGED
:
761 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
762 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
763 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
765 ok((winpos
->cx
>= 0 && winpos
->cx
<= 32767) ||
766 winpos
->cx
== 32768, /* win7 doesn't truncate */
767 "bad winpos->cx %d\n", winpos
->cx
);
768 ok((winpos
->cy
>= 0 && winpos
->cy
<= 32767) ||
769 winpos
->cy
== 40000, /* win7 doesn't truncate */
770 "bad winpos->cy %d\n", winpos
->cy
);
772 GetWindowRect(hwnd
, &rc1
);
773 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
774 /* note: winpos coordinates are relative to parent */
775 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
778 /* Uncomment this once the test succeeds in all cases */
779 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
780 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
782 GetClientRect(hwnd
, &rc2
);
783 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
784 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
785 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
786 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
792 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
793 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
795 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
796 ok(got_getminmaxinfo
, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
798 ok(!got_getminmaxinfo
, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
802 if (test_lbuttondown_flag
)
804 ShowWindow((HWND
)wparam
, SW_SHOW
);
805 flush_events( FALSE
);
810 if (g_wm_gettext_override
.enabled
)
812 char *text
= (char*)lparam
;
813 ok(g_wm_gettext_override
.buff
== text
, "expected buffer %p, got %p\n", g_wm_gettext_override
.buff
, text
);
814 ok(*text
== 0, "expected empty string buffer %x\n", *text
);
822 if (wparam
) app_activated
= TRUE
;
823 else app_deactivated
= TRUE
;
827 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
830 static LRESULT WINAPI
main_window_procW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
836 if (g_wm_gettext_override
.enabled
)
838 WCHAR
*text
= (WCHAR
*)lparam
;
839 ok(g_wm_gettext_override
.buffW
== text
, "expected buffer %p, got %p\n", g_wm_gettext_override
.buffW
, text
);
840 ok(*text
== 0, "expected empty string buffer %x\n", *text
);
846 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
849 static LRESULT WINAPI
tool_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
853 case WM_GETMINMAXINFO
:
855 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
860 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
861 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
863 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
864 ok(got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
866 ok(!got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
871 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
874 static const WCHAR mainclassW
[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s','W',0};
876 static BOOL
RegisterWindowClasses(void)
881 cls
.style
= CS_DBLCLKS
;
882 cls
.lpfnWndProc
= main_window_procA
;
885 cls
.hInstance
= GetModuleHandleA(0);
887 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
888 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
889 cls
.lpszMenuName
= NULL
;
890 cls
.lpszClassName
= "MainWindowClass";
892 if(!RegisterClassA(&cls
)) return FALSE
;
894 clsW
.style
= CS_DBLCLKS
;
895 clsW
.lpfnWndProc
= main_window_procW
;
898 clsW
.hInstance
= GetModuleHandleA(0);
900 clsW
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
901 clsW
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
902 clsW
.lpszMenuName
= NULL
;
903 clsW
.lpszClassName
= mainclassW
;
905 if(!RegisterClassW(&clsW
)) return FALSE
;
908 cls
.lpfnWndProc
= tool_window_procA
;
911 cls
.hInstance
= GetModuleHandleA(0);
913 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
914 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
915 cls
.lpszMenuName
= NULL
;
916 cls
.lpszClassName
= "ToolWindowClass";
918 if(!RegisterClassA(&cls
)) return FALSE
;
923 static void verify_window_info(const char *hook
, HWND hwnd
, const WINDOWINFO
*info
)
925 RECT rcWindow
, rcClient
;
928 ok(IsWindow(hwnd
), "bad window handle %p in hook %s\n", hwnd
, hook
);
930 GetWindowRect(hwnd
, &rcWindow
);
931 ok(EqualRect(&rcWindow
, &info
->rcWindow
), "wrong rcWindow for %p in hook %s\n", hwnd
, hook
);
933 GetClientRect(hwnd
, &rcClient
);
934 /* translate to screen coordinates */
935 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rcClient
, 2);
936 ok(EqualRect(&rcClient
, &info
->rcClient
), "wrong rcClient for %p in hook %s\n", hwnd
, hook
);
938 ok(info
->dwStyle
== (DWORD
)GetWindowLongA(hwnd
, GWL_STYLE
),
939 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
940 info
->dwStyle
, GetWindowLongA(hwnd
, GWL_STYLE
), hwnd
, hook
);
941 /* Windows reports some undocumented exstyles in WINDOWINFO, but
942 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
944 ok((info
->dwExStyle
& ~0xe0000800) == (DWORD
)GetWindowLongA(hwnd
, GWL_EXSTYLE
),
945 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
946 info
->dwExStyle
, GetWindowLongA(hwnd
, GWL_EXSTYLE
), hwnd
, hook
);
947 status
= (GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0;
948 if (GetForegroundWindow())
949 ok(info
->dwWindowStatus
== status
, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
950 info
->dwWindowStatus
, status
, GetActiveWindow(), GetForegroundWindow(), hook
);
952 /* win2k and XP return broken border info in GetWindowInfo most of
953 * the time, so there is no point in testing it.
958 ok(info
->cxWindowBorders
== (unsigned)(rcClient
.left
- rcWindow
.left
),
959 "wrong cxWindowBorders %d != %d\n", info
->cxWindowBorders
, rcClient
.left
- rcWindow
.left
);
960 border
= min(rcWindow
.bottom
- rcClient
.bottom
, rcClient
.top
- rcWindow
.top
);
961 ok(info
->cyWindowBorders
== border
,
962 "wrong cyWindowBorders %d != %d\n", info
->cyWindowBorders
, border
);
964 ok(info
->atomWindowType
== GetClassLongA(hwnd
, GCW_ATOM
), "wrong atomWindowType for %p in hook %s\n",
966 ok(info
->wCreatorVersion
== 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
967 info
->wCreatorVersion
== 0x0500 /* Vista */,
968 "wrong wCreatorVersion %04x for %p in hook %s\n", info
->wCreatorVersion
, hwnd
, hook
);
971 static void FixedAdjustWindowRectEx(RECT
* rc
, LONG style
, BOOL menu
, LONG exstyle
)
973 AdjustWindowRectEx(rc
, style
, menu
, exstyle
);
974 /* AdjustWindowRectEx does not include scroll bars */
975 if (style
& WS_VSCROLL
)
977 if(exstyle
& WS_EX_LEFTSCROLLBAR
)
978 rc
->left
-= GetSystemMetrics(SM_CXVSCROLL
);
980 rc
->right
+= GetSystemMetrics(SM_CXVSCROLL
);
982 if (style
& WS_HSCROLL
)
983 rc
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
986 static void test_nonclient_area(HWND hwnd
)
988 DWORD style
, exstyle
;
989 RECT rc_window
, rc_client
, rc
;
993 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
994 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
995 menu
= !(style
& WS_CHILD
) && GetMenu(hwnd
) != 0;
997 GetWindowRect(hwnd
, &rc_window
);
998 GetClientRect(hwnd
, &rc_client
);
1000 /* avoid some cases when things go wrong */
1001 if (IsRectEmpty(&rc_window
) || IsRectEmpty(&rc_client
) ||
1002 rc_window
.right
> 32768 || rc_window
.bottom
> 32768) return;
1004 CopyRect(&rc
, &rc_client
);
1005 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc
, 2);
1006 FixedAdjustWindowRectEx(&rc
, style
, menu
, exstyle
);
1008 ok(EqualRect(&rc
, &rc_window
),
1009 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
1010 style
, exstyle
, menu
, rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
,
1011 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1014 CopyRect(&rc
, &rc_window
);
1015 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
1016 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
1017 ok(EqualRect(&rc
, &rc_client
),
1018 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
1019 style
, exstyle
, menu
, rc_client
.left
, rc_client
.top
, rc_client
.right
, rc_client
.bottom
,
1020 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1022 /* NULL rectangle shouldn't crash */
1023 ret
= DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, 0);
1024 ok(ret
== 0, "NULL rectangle returned %ld instead of 0\n", ret
);
1026 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
1030 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
1031 SetRect(&rc_client
, 0, 0, 250, 150);
1032 CopyRect(&rc_window
, &rc_client
);
1033 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc_window
, 2);
1034 FixedAdjustWindowRectEx(&rc_window
, style
, menu
, exstyle
);
1036 CopyRect(&rc
, &rc_window
);
1037 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
1038 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
1039 ok(EqualRect(&rc
, &rc_client
),
1040 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
1041 style
, exstyle
, menu
, rc_client
.left
, rc_client
.top
, rc_client
.right
, rc_client
.bottom
,
1042 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1045 static LRESULT CALLBACK
cbt_hook_proc(int nCode
, WPARAM wParam
, LPARAM lParam
)
1047 static const char *CBT_code_name
[10] = {
1054 "HCBT_CLICKSKIPPED",
1058 const char *code_name
= (nCode
>= 0 && nCode
<= HCBT_SETFOCUS
) ? CBT_code_name
[nCode
] : "Unknown";
1059 HWND hwnd
= (HWND
)wParam
;
1063 case HCBT_CREATEWND
:
1065 static const RECT rc_null
;
1068 CBT_CREATEWNDA
*createwnd
= (CBT_CREATEWNDA
*)lParam
;
1069 ok(createwnd
->hwndInsertAfter
== HWND_TOP
, "hwndInsertAfter should be always HWND_TOP\n");
1074 info
.cbSize
= sizeof(WINDOWINFO
);
1075 ok(pGetWindowInfo(hwnd
, &info
), "GetWindowInfo should not fail\n");
1076 verify_window_info(code_name
, hwnd
, &info
);
1079 /* WS_VISIBLE should be turned off yet */
1080 style
= createwnd
->lpcs
->style
& ~WS_VISIBLE
;
1081 ok(style
== GetWindowLongA(hwnd
, GWL_STYLE
),
1082 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
1083 GetWindowLongA(hwnd
, GWL_STYLE
), style
);
1087 /* Uncomment this once the test succeeds in all cases */
1088 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1090 ok(GetParent(hwnd
) == hwndMessage
,
1091 "wrong result from GetParent %p: message window %p\n",
1092 GetParent(hwnd
), hwndMessage
);
1095 ok(!GetParent(hwnd
), "GetParent should return 0 at this point\n");
1097 ok(!GetWindow(hwnd
, GW_OWNER
), "GW_OWNER should be set to 0 at this point\n");
1101 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
1102 * Win9x still has them set to 0.
1104 ok(GetWindow(hwnd
, GW_HWNDFIRST
) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
1105 ok(GetWindow(hwnd
, GW_HWNDLAST
) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
1107 ok(!GetWindow(hwnd
, GW_HWNDPREV
), "GW_HWNDPREV should be set to 0 at this point\n");
1108 ok(!GetWindow(hwnd
, GW_HWNDNEXT
), "GW_HWNDNEXT should be set to 0 at this point\n");
1112 /* Uncomment this once the test succeeds in all cases */
1115 ok(pGetAncestor(hwnd
, GA_PARENT
) == hwndMessage
, "GA_PARENT should be set to hwndMessage at this point\n");
1116 ok(pGetAncestor(hwnd
, GA_ROOT
) == hwnd
,
1117 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd
, GA_ROOT
), hwnd
);
1119 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1120 ok(pGetAncestor(hwnd
, GA_ROOTOWNER
) == hwndMessage
,
1121 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
1123 ok(pGetAncestor(hwnd
, GA_ROOTOWNER
) == hwnd
,
1124 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd
, GA_ROOTOWNER
), hwnd
);
1127 ok(GetWindowRect(hwnd
, &rc
), "GetWindowRect failed\n");
1128 ok(EqualRect(&rc
, &rc_null
), "window rect should be set to 0 HCBT_CREATEWND\n");
1129 ok(GetClientRect(hwnd
, &rc
), "GetClientRect failed\n");
1130 ok(EqualRect(&rc
, &rc_null
), "client rect should be set to 0 on HCBT_CREATEWND\n");
1137 if (pGetWindowInfo
&& IsWindow(hwnd
))
1141 /* Win98 actually does check the info.cbSize and doesn't allow
1142 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
1143 * WinXP do not check it at all.
1145 info
.cbSize
= sizeof(WINDOWINFO
);
1146 ok(pGetWindowInfo(hwnd
, &info
), "GetWindowInfo should not fail\n");
1147 verify_window_info(code_name
, hwnd
, &info
);
1150 /* window state is undefined */
1152 case HCBT_DESTROYWND
:
1158 return CallNextHookEx(hhook
, nCode
, wParam
, lParam
);
1161 static void test_shell_window(void)
1165 HMODULE hinst
, hUser32
;
1166 BOOL (WINAPI
*SetShellWindow
)(HWND
);
1167 HWND hwnd1
, hwnd2
, hwnd3
, hwnd4
, hwnd5
;
1168 HWND shellWindow
, nextWnd
;
1172 win_skip("Skipping shell window test on Win9x\n");
1176 shellWindow
= GetShellWindow();
1177 hinst
= GetModuleHandleA(NULL
);
1178 hUser32
= GetModuleHandleA("user32");
1180 SetShellWindow
= (void *)GetProcAddress(hUser32
, "SetShellWindow");
1182 trace("previous shell window: %p\n", shellWindow
);
1188 GetWindowThreadProcessId(shellWindow
, &pid
);
1189 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, pid
);
1192 skip( "cannot get access to shell process\n" );
1196 SetLastError(0xdeadbeef);
1197 ret
= DestroyWindow(shellWindow
);
1198 error
= GetLastError();
1200 ok(!ret
, "DestroyWindow(shellWindow)\n");
1201 /* passes on Win XP, but not on Win98 */
1202 ok(error
==ERROR_ACCESS_DENIED
|| error
== 0xdeadbeef,
1203 "got %u after DestroyWindow(shellWindow)\n", error
);
1205 /* close old shell instance */
1206 ret
= TerminateProcess(hProcess
, 0);
1207 ok(ret
, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1208 WaitForSingleObject(hProcess
, INFINITE
); /* wait for termination */
1209 CloseHandle(hProcess
);
1212 hwnd1
= CreateWindowExA(0, "#32770", "TEST1", WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst
, 0);
1213 trace("created window 1: %p\n", hwnd1
);
1215 ret
= SetShellWindow(hwnd1
);
1216 ok(ret
, "first call to SetShellWindow(hwnd1)\n");
1217 shellWindow
= GetShellWindow();
1218 ok(shellWindow
==hwnd1
, "wrong shell window: %p\n", shellWindow
);
1220 ret
= SetShellWindow(hwnd1
);
1221 ok(!ret
, "second call to SetShellWindow(hwnd1)\n");
1223 ret
= SetShellWindow(0);
1224 error
= GetLastError();
1225 /* passes on Win XP, but not on Win98
1226 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1227 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1229 ret
= SetShellWindow(hwnd1
);
1230 /* passes on Win XP, but not on Win98
1231 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1233 SetWindowLongA(hwnd1
, GWL_EXSTYLE
, GetWindowLongA(hwnd1
,GWL_EXSTYLE
)|WS_EX_TOPMOST
);
1234 ret
= (GetWindowLongA(hwnd1
,GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0;
1235 ok(!ret
, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1237 ret
= DestroyWindow(hwnd1
);
1238 ok(ret
, "DestroyWindow(hwnd1)\n");
1240 hwnd2
= CreateWindowExA(WS_EX_TOPMOST
, "#32770", "TEST2", WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst
, 0);
1241 trace("created window 2: %p\n", hwnd2
);
1242 ret
= SetShellWindow(hwnd2
);
1243 ok(!ret
, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1245 hwnd3
= CreateWindowExA(0, "#32770", "TEST3", WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst
, 0);
1246 trace("created window 3: %p\n", hwnd3
);
1248 hwnd4
= CreateWindowExA(0, "#32770", "TEST4", WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst
, 0);
1249 trace("created window 4: %p\n", hwnd4
);
1251 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1252 ok(nextWnd
==hwnd3
, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd
);
1254 ret
= SetShellWindow(hwnd4
);
1255 ok(ret
, "SetShellWindow(hwnd4)\n");
1256 shellWindow
= GetShellWindow();
1257 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1259 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1260 ok(nextWnd
==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd
);
1262 ret
= SetWindowPos(hwnd4
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1263 ok(ret
, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1265 ret
= SetWindowPos(hwnd4
, hwnd3
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1266 ok(ret
, "SetWindowPos(hwnd4, hwnd3\n");
1268 ret
= SetShellWindow(hwnd3
);
1269 ok(!ret
, "SetShellWindow(hwnd3)\n");
1270 shellWindow
= GetShellWindow();
1271 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1273 hwnd5
= CreateWindowExA(0, "#32770", "TEST5", WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst
, 0);
1274 trace("created window 5: %p\n", hwnd5
);
1275 ret
= SetWindowPos(hwnd4
, hwnd5
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1276 ok(ret
, "SetWindowPos(hwnd4, hwnd5)\n");
1280 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1281 ok(nextWnd
==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd
);
1284 /* destroy test windows */
1285 DestroyWindow(hwnd2
);
1286 DestroyWindow(hwnd3
);
1287 DestroyWindow(hwnd4
);
1288 DestroyWindow(hwnd5
);
1291 /************** MDI test ****************/
1293 static char mdi_lParam_test_message
[] = "just a test string";
1295 static void test_MDI_create(HWND parent
, HWND mdi_client
, INT_PTR first_id
)
1297 MDICREATESTRUCTA mdi_cs
;
1298 HWND mdi_child
, hwnd
, exp_hwnd
;
1300 static const WCHAR classW
[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1301 static const WCHAR titleW
[] = {'M','D','I',' ','c','h','i','l','d',0};
1302 BOOL isWin9x
= FALSE
;
1304 mdi_cs
.szClass
= "MDI_child_Class_1";
1305 mdi_cs
.szTitle
= "MDI child";
1306 mdi_cs
.hOwner
= GetModuleHandleA(NULL
);
1307 mdi_cs
.x
= CW_USEDEFAULT
;
1308 mdi_cs
.y
= CW_USEDEFAULT
;
1309 mdi_cs
.cx
= CW_USEDEFAULT
;
1310 mdi_cs
.cy
= CW_USEDEFAULT
;
1312 mdi_cs
.lParam
= (LPARAM
)mdi_lParam_test_message
;
1313 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1314 ok(mdi_child
!= 0, "MDI child creation failed\n");
1315 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1316 ok(id
== first_id
, "wrong child id %ld\n", id
);
1317 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1318 exp_hwnd
= (GetWindowLongW(mdi_child
, GWL_STYLE
) & WS_VISIBLE
) ? mdi_child
: 0;
1319 ok(hwnd
== exp_hwnd
, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd
, hwnd
);
1320 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1321 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1323 mdi_cs
.style
= 0x7fffffff; /* without WS_POPUP */
1324 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1325 ok(mdi_child
!= 0, "MDI child creation failed\n");
1326 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1327 ok(id
== first_id
, "wrong child id %ld\n", id
);
1328 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1330 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1331 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1332 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1334 mdi_cs
.style
= 0xffffffff; /* with WS_POPUP */
1335 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1336 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1338 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1342 ok(mdi_child
!= 0, "MDI child creation failed\n");
1343 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1344 ok(id
== first_id
, "wrong child id %ld\n", id
);
1345 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1347 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1348 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1349 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1352 /* test MDICREATESTRUCT A<->W mapping */
1353 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1355 mdi_cs
.szClass
= (LPCSTR
)classW
;
1356 mdi_cs
.szTitle
= (LPCSTR
)titleW
;
1357 SetLastError(0xdeadbeef);
1358 mdi_child
= (HWND
)SendMessageW(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1361 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1364 ok(mdi_child
!= 0, "MDI child creation failed\n");
1368 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1369 ok(id
== first_id
, "wrong child id %ld\n", id
);
1370 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1371 exp_hwnd
= (GetWindowLongW(mdi_child
, GWL_STYLE
) & WS_VISIBLE
) ? mdi_child
: 0;
1372 ok(hwnd
== exp_hwnd
, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd
, hwnd
);
1373 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1374 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1377 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1379 CW_USEDEFAULT
, CW_USEDEFAULT
,
1380 CW_USEDEFAULT
, CW_USEDEFAULT
,
1381 mdi_client
, GetModuleHandleA(NULL
),
1382 (LPARAM
)mdi_lParam_test_message
);
1383 ok(mdi_child
!= 0, "MDI child creation failed\n");
1384 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1385 ok(id
== first_id
, "wrong child id %ld\n", id
);
1386 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1387 exp_hwnd
= (GetWindowLongW(mdi_child
, GWL_STYLE
) & WS_VISIBLE
) ? mdi_child
: 0;
1388 ok(hwnd
== exp_hwnd
, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd
, hwnd
);
1389 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1390 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1392 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1393 0x7fffffff, /* without WS_POPUP */
1394 CW_USEDEFAULT
, CW_USEDEFAULT
,
1395 CW_USEDEFAULT
, CW_USEDEFAULT
,
1396 mdi_client
, GetModuleHandleA(NULL
),
1397 (LPARAM
)mdi_lParam_test_message
);
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);
1403 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1404 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1405 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1407 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1408 0xffffffff, /* with WS_POPUP */
1409 CW_USEDEFAULT
, CW_USEDEFAULT
,
1410 CW_USEDEFAULT
, CW_USEDEFAULT
,
1411 mdi_client
, GetModuleHandleA(NULL
),
1412 (LPARAM
)mdi_lParam_test_message
);
1413 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1415 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1419 ok(mdi_child
!= 0, "MDI child creation failed\n");
1420 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1421 ok(id
== first_id
, "wrong child id %ld\n", id
);
1422 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1424 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1425 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1426 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1429 /* test MDICREATESTRUCT A<->W mapping */
1430 SetLastError(0xdeadbeef);
1431 mdi_child
= CreateMDIWindowW(classW
, titleW
,
1433 CW_USEDEFAULT
, CW_USEDEFAULT
,
1434 CW_USEDEFAULT
, CW_USEDEFAULT
,
1435 mdi_client
, GetModuleHandleA(NULL
),
1436 (LPARAM
)mdi_lParam_test_message
);
1439 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1442 ok(mdi_child
!= 0, "MDI child creation failed\n");
1446 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1447 ok(id
== first_id
, "wrong child id %ld\n", id
);
1448 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1449 exp_hwnd
= (GetWindowLongW(mdi_child
, GWL_STYLE
) & WS_VISIBLE
) ? mdi_child
: 0;
1450 ok(hwnd
== exp_hwnd
, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd
, hwnd
);
1451 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1452 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1455 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1457 CW_USEDEFAULT
, CW_USEDEFAULT
,
1458 CW_USEDEFAULT
, CW_USEDEFAULT
,
1459 mdi_client
, 0, GetModuleHandleA(NULL
),
1460 mdi_lParam_test_message
);
1461 ok(mdi_child
!= 0, "MDI child creation failed\n");
1462 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1463 ok(id
== first_id
, "wrong child id %ld\n", id
);
1464 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1465 exp_hwnd
= (GetWindowLongW(mdi_child
, GWL_STYLE
) & WS_VISIBLE
) ? mdi_child
: 0;
1466 ok(hwnd
== exp_hwnd
, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd
, hwnd
);
1467 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1468 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1470 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1471 0x7fffffff, /* without WS_POPUP */
1472 CW_USEDEFAULT
, CW_USEDEFAULT
,
1473 CW_USEDEFAULT
, CW_USEDEFAULT
,
1474 mdi_client
, 0, GetModuleHandleA(NULL
),
1475 mdi_lParam_test_message
);
1476 ok(mdi_child
!= 0, "MDI child creation failed\n");
1477 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1478 ok(id
== first_id
, "wrong child id %ld\n", id
);
1479 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1481 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1482 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1483 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1485 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1486 0xffffffff, /* with WS_POPUP */
1487 CW_USEDEFAULT
, CW_USEDEFAULT
,
1488 CW_USEDEFAULT
, CW_USEDEFAULT
,
1489 mdi_client
, 0, GetModuleHandleA(NULL
),
1490 mdi_lParam_test_message
);
1491 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1493 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1497 ok(mdi_child
!= 0, "MDI child creation failed\n");
1498 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1499 ok(id
== first_id
, "wrong child id %ld\n", id
);
1500 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1502 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1503 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1504 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1507 /* test MDICREATESTRUCT A<->W mapping */
1508 SetLastError(0xdeadbeef);
1509 mdi_child
= CreateWindowExW(WS_EX_MDICHILD
, classW
, titleW
,
1511 CW_USEDEFAULT
, CW_USEDEFAULT
,
1512 CW_USEDEFAULT
, CW_USEDEFAULT
,
1513 mdi_client
, 0, GetModuleHandleA(NULL
),
1514 mdi_lParam_test_message
);
1517 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1520 ok(mdi_child
!= 0, "MDI child creation failed\n");
1524 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1525 ok(id
== first_id
, "wrong child id %ld\n", id
);
1526 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1527 exp_hwnd
= (GetWindowLongW(mdi_child
, GWL_STYLE
) & WS_VISIBLE
) ? mdi_child
: 0;
1528 ok(hwnd
== exp_hwnd
, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd
, hwnd
);
1529 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1530 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1533 /* This test fails on Win9x */
1536 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_2", "MDI child",
1538 CW_USEDEFAULT
, CW_USEDEFAULT
,
1539 CW_USEDEFAULT
, CW_USEDEFAULT
,
1540 parent
, 0, GetModuleHandleA(NULL
),
1541 mdi_lParam_test_message
);
1542 ok(!mdi_child
, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1545 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1546 WS_CHILD
, /* without WS_POPUP */
1547 CW_USEDEFAULT
, CW_USEDEFAULT
,
1548 CW_USEDEFAULT
, CW_USEDEFAULT
,
1549 mdi_client
, 0, GetModuleHandleA(NULL
),
1550 mdi_lParam_test_message
);
1551 ok(mdi_child
!= 0, "MDI child creation failed\n");
1552 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1553 ok(id
== 0, "wrong child id %ld\n", id
);
1554 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1555 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1556 DestroyWindow(mdi_child
);
1558 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1559 WS_CHILD
| WS_POPUP
, /* with WS_POPUP */
1560 CW_USEDEFAULT
, CW_USEDEFAULT
,
1561 CW_USEDEFAULT
, CW_USEDEFAULT
,
1562 mdi_client
, 0, GetModuleHandleA(NULL
),
1563 mdi_lParam_test_message
);
1564 ok(mdi_child
!= 0, "MDI child creation failed\n");
1565 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1566 ok(id
== 0, "wrong child id %ld\n", id
);
1567 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1568 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1569 DestroyWindow(mdi_child
);
1571 /* maximized child */
1572 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1573 WS_CHILD
| WS_MAXIMIZE
,
1574 CW_USEDEFAULT
, CW_USEDEFAULT
,
1575 CW_USEDEFAULT
, CW_USEDEFAULT
,
1576 mdi_client
, 0, GetModuleHandleA(NULL
),
1577 mdi_lParam_test_message
);
1578 ok(mdi_child
!= 0, "MDI child creation failed\n");
1579 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1580 ok(id
== 0, "wrong child id %ld\n", id
);
1581 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1582 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1583 DestroyWindow(mdi_child
);
1585 trace("Creating maximized child with a caption\n");
1586 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1587 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
,
1588 CW_USEDEFAULT
, CW_USEDEFAULT
,
1589 CW_USEDEFAULT
, CW_USEDEFAULT
,
1590 mdi_client
, 0, GetModuleHandleA(NULL
),
1591 mdi_lParam_test_message
);
1592 ok(mdi_child
!= 0, "MDI child creation failed\n");
1593 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1594 ok(id
== 0, "wrong child id %ld\n", id
);
1595 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1596 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1597 DestroyWindow(mdi_child
);
1599 trace("Creating maximized child with a caption and a thick frame\n");
1600 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1601 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
| WS_THICKFRAME
,
1602 CW_USEDEFAULT
, CW_USEDEFAULT
,
1603 CW_USEDEFAULT
, CW_USEDEFAULT
,
1604 mdi_client
, 0, GetModuleHandleA(NULL
),
1605 mdi_lParam_test_message
);
1606 ok(mdi_child
!= 0, "MDI child creation failed\n");
1607 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1608 ok(id
== 0, "wrong child id %ld\n", id
);
1609 hwnd
= (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1610 ok(!hwnd
, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd
);
1611 DestroyWindow(mdi_child
);
1614 static void test_MDI_child_stack(HWND mdi_client
)
1616 HWND child_1
, child_2
, child_3
, child_4
;
1618 MDICREATESTRUCTA cs
;
1620 cs
.szClass
= "MDI_child_Class_1";
1621 cs
.szTitle
= "MDI child";
1622 cs
.hOwner
= GetModuleHandleA(0);
1623 cs
.x
= CW_USEDEFAULT
;
1624 cs
.y
= CW_USEDEFAULT
;
1625 cs
.cx
= CW_USEDEFAULT
;
1626 cs
.cy
= CW_USEDEFAULT
;
1628 cs
.lParam
= (LPARAM
)mdi_lParam_test_message
;
1630 child_1
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&cs
);
1631 ok(child_1
!= 0, "expected child_1 to be non NULL\n");
1632 child_2
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&cs
);
1633 ok(child_2
!= 0, "expected child_2 to be non NULL\n");
1634 child_3
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&cs
);
1635 ok(child_3
!= 0, "expected child_3 to be non NULL\n");
1636 child_4
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&cs
);
1637 ok(child_4
!= 0, "expected child_4 to be non NULL\n");
1639 stack
[0] = (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1640 stack
[1] = GetWindow(stack
[0], GW_HWNDNEXT
);
1641 stack
[2] = GetWindow(stack
[1], GW_HWNDNEXT
);
1642 stack
[3] = GetWindow(stack
[2], GW_HWNDNEXT
);
1643 trace("Initial MDI child stack: %p->%p->%p->%p\n", stack
[0], stack
[1], stack
[2], stack
[3]);
1644 ok(stack
[0] == child_4
&& stack
[1] == child_3
&&
1645 stack
[2] == child_2
&& stack
[3] == child_1
,
1646 "Unexpected initial order, should be: %p->%p->%p->%p\n",
1647 child_4
, child_3
, child_2
, child_1
);
1649 trace("Activate child next to %p\n", child_3
);
1650 SendMessageA(mdi_client
, WM_MDINEXT
, (WPARAM
)child_3
, 0);
1652 stack
[0] = (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1653 stack
[1] = GetWindow(stack
[0], GW_HWNDNEXT
);
1654 stack
[2] = GetWindow(stack
[1], GW_HWNDNEXT
);
1655 stack
[3] = GetWindow(stack
[2], GW_HWNDNEXT
);
1656 ok(stack
[0] == child_2
&& stack
[1] == child_4
&&
1657 stack
[2] == child_1
&& stack
[3] == child_3
,
1658 "Broken MDI child stack:\nexpected: %p->%p->%p->%p, but got: %p->%p->%p->%p\n",
1659 child_2
, child_4
, child_1
, child_3
, stack
[0], stack
[1], stack
[2], stack
[3]);
1661 trace("Activate child previous to %p\n", child_1
);
1662 SendMessageA(mdi_client
, WM_MDINEXT
, (WPARAM
)child_1
, 1);
1664 stack
[0] = (HWND
)SendMessageA(mdi_client
, WM_MDIGETACTIVE
, 0, 0);
1665 stack
[1] = GetWindow(stack
[0], GW_HWNDNEXT
);
1666 stack
[2] = GetWindow(stack
[1], GW_HWNDNEXT
);
1667 stack
[3] = GetWindow(stack
[2], GW_HWNDNEXT
);
1668 ok(stack
[0] == child_4
&& stack
[1] == child_2
&&
1669 stack
[2] == child_1
&& stack
[3] == child_3
,
1670 "Broken MDI child stack:\nexpected: %p->%p->%p->%p, but got: %p->%p->%p->%p\n",
1671 child_4
, child_2
, child_1
, child_3
, stack
[0], stack
[1], stack
[2], stack
[3]);
1673 DestroyWindow(child_1
);
1674 DestroyWindow(child_2
);
1675 DestroyWindow(child_3
);
1676 DestroyWindow(child_4
);
1679 /**********************************************************************
1680 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1682 * Note: The rule here is that client rect of the maximized MDI child
1683 * is equal to the client rect of the MDI client window.
1685 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
1689 GetClientRect( client
, &rect
);
1690 AdjustWindowRectEx( &rect
, GetWindowLongA( hwnd
, GWL_STYLE
),
1691 0, GetWindowLongA( hwnd
, GWL_EXSTYLE
));
1693 rect
.right
-= rect
.left
;
1694 rect
.bottom
-= rect
.top
;
1695 lpMinMax
->ptMaxSize
.x
= rect
.right
;
1696 lpMinMax
->ptMaxSize
.y
= rect
.bottom
;
1698 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
1699 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
1701 trace("max rect (%d,%d - %d, %d)\n",
1702 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1705 static LRESULT WINAPI
mdi_child_wnd_proc_1(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1712 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1713 MDICREATESTRUCTA
*mdi_cs
= cs
->lpCreateParams
;
1715 ok(cs
->dwExStyle
& WS_EX_MDICHILD
, "WS_EX_MDICHILD should be set\n");
1716 ok(mdi_cs
->lParam
== (LPARAM
)mdi_lParam_test_message
, "wrong mdi_cs->lParam\n");
1718 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_1"), "wrong class name\n");
1719 ok(!lstrcmpA(cs
->lpszClass
, mdi_cs
->szClass
), "class name does not match\n");
1720 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1721 ok(!lstrcmpA(cs
->lpszName
, mdi_cs
->szTitle
), "title does not match\n");
1722 ok(cs
->hInstance
== mdi_cs
->hOwner
, "%p != %p\n", cs
->hInstance
, mdi_cs
->hOwner
);
1724 /* MDICREATESTRUCT should have original values */
1725 ok(mdi_cs
->style
== 0 || mdi_cs
->style
== 0x7fffffff || mdi_cs
->style
== 0xffffffff,
1726 "mdi_cs->style does not match (%08x)\n", mdi_cs
->style
);
1727 ok(mdi_cs
->x
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->x
);
1728 ok(mdi_cs
->y
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->y
);
1729 ok(mdi_cs
->cx
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cx
);
1730 ok(mdi_cs
->cy
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cy
);
1732 /* CREATESTRUCT should have fixed values */
1733 ok(cs
->x
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->x
);
1734 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1736 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1737 ok(cs
->cx
!= CW_USEDEFAULT
&& cs
->cx
!= 0, "%d == CW_USEDEFAULT\n", cs
->cx
);
1738 ok(cs
->cy
!= CW_USEDEFAULT
&& cs
->cy
!= 0, "%d == CW_USEDEFAULT\n", cs
->cy
);
1740 ok(!(cs
->style
& WS_POPUP
), "WS_POPUP is not allowed\n");
1742 if (GetWindowLongA(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1744 LONG style
= mdi_cs
->style
| WS_CHILD
| WS_CLIPSIBLINGS
;
1745 ok(cs
->style
== style
,
1746 "cs->style does not match (%08x)\n", cs
->style
);
1750 LONG style
= mdi_cs
->style
;
1752 style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1753 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1754 ok(cs
->style
== style
,
1755 "cs->style does not match (%08x)\n", cs
->style
);
1760 case WM_GETMINMAXINFO
:
1762 HWND client
= GetParent(hwnd
);
1764 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1765 MINMAXINFO my_minmax
;
1766 LONG style
, exstyle
;
1768 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1769 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1771 GetClientRect(client
, &rc
);
1773 GetClientRect(client
, &rc
);
1774 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1775 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1776 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1777 trace("MDI child: calculated max window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1778 dump_minmax_info( minmax
);
1780 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1781 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1782 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1783 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1785 DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1787 trace("DefMDIChildProc returned:\n");
1788 dump_minmax_info( minmax
);
1790 MDI_ChildGetMinMaxInfo(client
, hwnd
, &my_minmax
);
1791 ok(minmax
->ptMaxSize
.x
== my_minmax
.ptMaxSize
.x
, "default width of maximized child %d != %d\n",
1792 minmax
->ptMaxSize
.x
, my_minmax
.ptMaxSize
.x
);
1793 ok(minmax
->ptMaxSize
.y
== my_minmax
.ptMaxSize
.y
, "default height of maximized child %d != %d\n",
1794 minmax
->ptMaxSize
.y
, my_minmax
.ptMaxSize
.y
);
1799 case WM_MDIACTIVATE
:
1801 HWND active
, client
= GetParent(hwnd
);
1802 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1803 active
= (HWND
)SendMessageA(client
, WM_MDIGETACTIVE
, 0, 0);
1804 if (hwnd
== (HWND
)lparam
) /* if we are being activated */
1805 ok (active
== (HWND
)lparam
, "new active %p != active %p\n", (HWND
)lparam
, active
);
1807 ok (active
== (HWND
)wparam
, "old active %p != active %p\n", (HWND
)wparam
, active
);
1811 return DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1814 static LRESULT WINAPI
mdi_child_wnd_proc_2(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1821 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1823 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg
== WM_NCCREATE
) ? "WM_NCCREATE" : "WM_CREATE",
1824 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
1826 ok(!(cs
->dwExStyle
& WS_EX_MDICHILD
), "WS_EX_MDICHILD should not be set\n");
1827 ok(cs
->lpCreateParams
== mdi_lParam_test_message
, "wrong cs->lpCreateParams\n");
1829 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_2"), "wrong class name\n");
1830 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1832 /* CREATESTRUCT should have fixed values */
1833 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1835 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1836 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1838 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1839 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1840 while Win95, Win2k, WinXP do. */
1841 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1842 ok(cs
->cy
== 0, "%d != 0\n", cs
->cy
);
1846 case WM_GETMINMAXINFO
:
1848 HWND parent
= GetParent(hwnd
);
1850 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1851 LONG style
, exstyle
;
1853 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1854 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1856 GetClientRect(parent
, &rc
);
1857 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent
, rc
.right
, rc
.bottom
);
1859 GetClientRect(parent
, &rc
);
1860 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1861 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1862 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1863 dump_minmax_info( minmax
);
1865 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1866 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1867 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1868 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1872 case WM_WINDOWPOSCHANGED
:
1874 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1877 GetWindowRect(hwnd
, &rc1
);
1878 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1879 /* note: winpos coordinates are relative to parent */
1880 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1881 ok(EqualRect(&rc1
, &rc2
), "rects do not match, window=(%d,%d)-(%d,%d) pos=(%d,%d)-(%d,%d)\n",
1882 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
1883 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1884 GetWindowRect(hwnd
, &rc1
);
1885 GetClientRect(hwnd
, &rc2
);
1886 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1887 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1888 ok(EqualRect(&rc1
, &rc2
), "rects do not match, window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1889 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
1890 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1893 case WM_WINDOWPOSCHANGING
:
1895 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1896 WINDOWPOS my_winpos
= *winpos
;
1898 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1899 (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
1900 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1901 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1903 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1905 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1906 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1907 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1908 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1913 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1916 static LRESULT WINAPI
mdi_main_wnd_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1918 static HWND mdi_client
;
1925 case WM_WINDOWPOSCHANGED
:
1927 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1930 GetWindowRect(hwnd
, &rc1
);
1931 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1932 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1933 /* note: winpos coordinates are relative to parent */
1934 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1935 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1936 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1938 GetWindowRect(hwnd
, &rc1
);
1939 GetClientRect(hwnd
, &rc2
);
1940 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1941 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1942 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1945 case WM_WINDOWPOSCHANGING
:
1947 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1948 WINDOWPOS my_winpos
= *winpos
;
1950 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1951 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1952 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1953 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1955 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1957 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1958 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1959 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1961 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1962 "DefWindowProc should not change WINDOWPOS values\n");
1971 return DefFrameProcA(hwnd
, mdi_client
, msg
, wparam
, lparam
);
1974 static BOOL
mdi_RegisterWindowClasses(void)
1979 cls
.lpfnWndProc
= mdi_main_wnd_procA
;
1982 cls
.hInstance
= GetModuleHandleA(0);
1984 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
1985 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1986 cls
.lpszMenuName
= NULL
;
1987 cls
.lpszClassName
= "MDI_parent_Class";
1988 if(!RegisterClassA(&cls
)) return FALSE
;
1990 cls
.lpfnWndProc
= mdi_child_wnd_proc_1
;
1991 cls
.lpszClassName
= "MDI_child_Class_1";
1992 if(!RegisterClassA(&cls
)) return FALSE
;
1994 cls
.lpfnWndProc
= mdi_child_wnd_proc_2
;
1995 cls
.lpszClassName
= "MDI_child_Class_2";
1996 if(!RegisterClassA(&cls
)) return FALSE
;
2001 static void test_mdi(void)
2003 HWND mdi_hwndMain
, mdi_client
;
2004 CLIENTCREATESTRUCT client_cs
;
2008 if (!mdi_RegisterWindowClasses()) assert(0);
2010 mdi_hwndMain
= CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
2011 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
2012 WS_MAXIMIZEBOX
/*| WS_VISIBLE*/,
2013 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
2014 GetDesktopWindow(), 0,
2015 GetModuleHandleA(NULL
), NULL
);
2016 assert(mdi_hwndMain
);
2018 GetClientRect(mdi_hwndMain
, &rc
);
2020 client_cs
.hWindowMenu
= 0;
2021 client_cs
.idFirstChild
= 1;
2023 /* MDIClient without MDIS_ALLCHILDSTYLES */
2024 mdi_client
= CreateWindowExA(0, "mdiclient",
2026 WS_CHILD
/*| WS_VISIBLE*/,
2027 /* tests depend on a not zero MDIClient size */
2028 0, 0, rc
.right
, rc
.bottom
,
2029 mdi_hwndMain
, 0, GetModuleHandleA(NULL
),
2032 test_MDI_create(mdi_hwndMain
, mdi_client
, client_cs
.idFirstChild
);
2033 DestroyWindow(mdi_client
);
2035 /* MDIClient with MDIS_ALLCHILDSTYLES */
2036 mdi_client
= CreateWindowExA(0, "mdiclient",
2038 WS_CHILD
| MDIS_ALLCHILDSTYLES
/*| WS_VISIBLE*/,
2039 /* tests depend on a not zero MDIClient size */
2040 0, 0, rc
.right
, rc
.bottom
,
2041 mdi_hwndMain
, 0, GetModuleHandleA(NULL
),
2044 test_MDI_create(mdi_hwndMain
, mdi_client
, client_cs
.idFirstChild
);
2045 DestroyWindow(mdi_client
);
2047 /* Test child window stack management */
2048 mdi_client
= CreateWindowExA(0, "mdiclient",
2051 0, 0, rc
.right
, rc
.bottom
,
2052 mdi_hwndMain
, 0, GetModuleHandleA(NULL
),
2055 test_MDI_child_stack(mdi_client
);
2056 DestroyWindow(mdi_client
);
2058 while(GetMessage(&msg, 0, 0, 0))
2060 TranslateMessage(&msg);
2061 DispatchMessage(&msg);
2064 DestroyWindow(mdi_hwndMain
);
2067 static void test_icons(void)
2071 HICON icon
= LoadIconA(0, (LPCSTR
)IDI_APPLICATION
);
2072 HICON icon2
= LoadIconA(0, (LPCSTR
)IDI_QUESTION
);
2073 HICON small_icon
= LoadImageA(0, (LPCSTR
)IDI_APPLICATION
, IMAGE_ICON
,
2074 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
2077 cls
.cbSize
= sizeof(cls
);
2079 cls
.lpfnWndProc
= DefWindowProcA
;
2083 cls
.hIcon
= LoadIconA(0, (LPCSTR
)IDI_HAND
);
2084 cls
.hIconSm
= small_icon
;
2085 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
2086 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
2087 cls
.lpszMenuName
= NULL
;
2088 cls
.lpszClassName
= "IconWindowClass";
2090 RegisterClassExA(&cls
);
2092 hwnd
= CreateWindowExA(0, "IconWindowClass", "icon test", 0,
2093 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, NULL
, NULL
);
2096 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
2097 ok( res
== 0, "wrong big icon %p/0\n", res
);
2098 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon
);
2099 ok( res
== 0, "wrong previous big icon %p/0\n", res
);
2100 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
2101 ok( res
== icon
, "wrong big icon after set %p/%p\n", res
, icon
);
2102 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon2
);
2103 ok( res
== icon
, "wrong previous big icon %p/%p\n", res
, icon
);
2104 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
2105 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
2107 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
2108 ok( res
== 0, "wrong small icon %p/0\n", res
);
2109 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL2
, 0 );
2110 ok( (res
&& res
!= small_icon
&& res
!= icon2
) || broken(!res
), "wrong small2 icon %p\n", res
);
2111 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)icon
);
2112 ok( res
== 0, "wrong previous small icon %p/0\n", res
);
2113 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
2114 ok( res
== icon
, "wrong small icon after set %p/%p\n", res
, icon
);
2115 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL2
, 0 );
2116 ok( res
== icon
|| broken(!res
), "wrong small2 icon after set %p/%p\n", res
, icon
);
2117 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)small_icon
);
2118 ok( res
== icon
, "wrong previous small icon %p/%p\n", res
, icon
);
2119 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
2120 ok( res
== small_icon
, "wrong small icon after set %p/%p\n", res
, small_icon
);
2121 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL2
, 0 );
2122 ok( res
== small_icon
|| broken(!res
), "wrong small2 icon after set %p/%p\n", res
, small_icon
);
2124 /* make sure the big icon hasn't changed */
2125 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
2126 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
2128 DestroyWindow( hwnd
);
2131 static LRESULT WINAPI
nccalcsize_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2133 if (msg
== WM_NCCALCSIZE
)
2135 RECT
*rect
= (RECT
*)lparam
;
2136 /* first time around increase the rectangle, next time decrease it */
2137 if (rect
->left
== 100) InflateRect( rect
, 10, 10 );
2138 else InflateRect( rect
, -10, -10 );
2141 return DefWindowProcA( hwnd
, msg
, wparam
, lparam
);
2144 static void test_SetWindowPos(HWND hwnd
, HWND hwnd2
)
2146 RECT orig_win_rc
, rect
;
2148 HWND hwnd_grandchild
, hwnd_child
, hwnd_child2
;
2153 SetRect(&rect
, 111, 222, 333, 444);
2154 ok(!GetWindowRect(0, &rect
), "GetWindowRect succeeded\n");
2155 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
2156 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
2158 SetRect(&rect
, 111, 222, 333, 444);
2159 ok(!GetClientRect(0, &rect
), "GetClientRect succeeded\n");
2160 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
2161 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
2163 GetWindowRect(hwnd
, &orig_win_rc
);
2165 old_proc
= SetWindowLongPtrA( hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)nccalcsize_proc
);
2166 ret
= SetWindowPos(hwnd
, 0, 100, 100, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
2167 ok(ret
, "Got %d\n", ret
);
2168 GetWindowRect( hwnd
, &rect
);
2169 ok( rect
.left
== 100 && rect
.top
== 100 && rect
.right
== 100 && rect
.bottom
== 100,
2170 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
2171 GetClientRect( hwnd
, &rect
);
2172 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
2173 ok( rect
.left
== 90 && rect
.top
== 90 && rect
.right
== 110 && rect
.bottom
== 110,
2174 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
2176 ret
= SetWindowPos(hwnd
, 0, 200, 200, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
2177 ok(ret
, "Got %d\n", ret
);
2178 GetWindowRect( hwnd
, &rect
);
2179 ok( rect
.left
== 200 && rect
.top
== 200 && rect
.right
== 200 && rect
.bottom
== 200,
2180 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
2181 GetClientRect( hwnd
, &rect
);
2182 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
2183 ok( rect
.left
== 210 && rect
.top
== 210 && rect
.right
== 190 && rect
.bottom
== 190,
2184 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
2186 ret
= SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
2187 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
2188 ok(ret
, "Got %d\n", ret
);
2189 SetWindowLongPtrA( hwnd
, GWLP_WNDPROC
, old_proc
);
2191 /* Win9x truncates coordinates to 16-bit irrespectively */
2194 ret
= SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE
);
2195 ok(ret
, "Got %d\n", ret
);
2196 ret
= SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE
);
2197 ok(ret
, "Got %d\n", ret
);
2199 ret
= SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE
);
2200 ok(ret
, "Got %d\n", ret
);
2201 ret
= SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE
);
2202 ok(ret
, "Got %d\n", ret
);
2205 ret
= SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
2206 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
2207 ok(ret
, "Got %d\n", ret
);
2209 ok(!(GetWindowLongA(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
2210 ret
= SetWindowPos(hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
2211 ok(ret
, "Got %d\n", ret
);
2212 ok(GetWindowLongA(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
2213 ret
= SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
2214 ok(ret
, "Got %d\n", ret
);
2215 ok(GetWindowLongA(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
2216 ret
= SetWindowPos(hwnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
2217 ok(ret
, "Got %d\n", ret
);
2218 ok(!(GetWindowLongA(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
2220 hwnd_desktop
= GetDesktopWindow();
2221 ok(!!hwnd_desktop
, "Failed to get hwnd_desktop window (%d).\n", GetLastError());
2222 hwnd_child
= create_tool_window(WS_VISIBLE
|WS_CHILD
, hwnd
);
2223 ok(!!hwnd_child
, "Failed to create child window (%d)\n", GetLastError());
2224 hwnd_grandchild
= create_tool_window(WS_VISIBLE
|WS_CHILD
, hwnd_child
);
2225 ok(!!hwnd_child
, "Failed to create child window (%d)\n", GetLastError());
2226 hwnd_child2
= create_tool_window(WS_VISIBLE
|WS_CHILD
, hwnd
);
2227 ok(!!hwnd_child2
, "Failed to create second child window (%d)\n", GetLastError());
2229 ret
= SetWindowPos(hwnd
, hwnd2
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2230 ok(ret
, "Got %d\n", ret
);
2231 check_active_state(hwnd
, hwnd
, hwnd
);
2233 ret
= SetWindowPos(hwnd2
, hwnd
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2234 ok(ret
, "Got %d\n", ret
);
2235 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2237 /* Returns TRUE also for windows that are not siblings */
2238 ret
= SetWindowPos(hwnd_child
, hwnd2
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2239 ok(ret
, "Got %d\n", ret
);
2240 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2242 ret
= SetWindowPos(hwnd2
, hwnd_child
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2243 ok(ret
, "Got %d\n", ret
);
2244 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2246 /* Does not seem to do anything even without passing flags, still returns TRUE */
2247 GetWindowRect(hwnd_child
, &rc1
);
2248 ret
= SetWindowPos(hwnd_child
, hwnd2
, 1, 2, 3, 4, 0);
2249 ok(ret
, "Got %d\n", ret
);
2250 GetWindowRect(hwnd_child
, &rc2
);
2251 ok(rc1
.left
== rc2
.left
&& rc1
.top
== rc2
.top
&&
2252 rc1
.right
== rc2
.right
&& rc1
.bottom
== rc2
.bottom
,
2253 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2254 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
2255 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2257 /* Same thing the other way around. */
2258 GetWindowRect(hwnd2
, &rc1
);
2259 ret
= SetWindowPos(hwnd2
, hwnd_child
, 1, 2, 3, 4, 0);
2260 ok(ret
, "Got %d\n", ret
);
2261 GetWindowRect(hwnd2
, &rc2
);
2262 ok(rc1
.left
== rc2
.left
&& rc1
.top
== rc2
.top
&&
2263 rc1
.right
== rc2
.right
&& rc1
.bottom
== rc2
.bottom
,
2264 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2265 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
2266 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2268 /* .. and with these windows. */
2269 GetWindowRect(hwnd_grandchild
, &rc1
);
2270 ret
= SetWindowPos(hwnd_grandchild
, hwnd_child2
, 1, 2, 3, 4, 0);
2271 ok(ret
, "Got %d\n", ret
);
2272 GetWindowRect(hwnd_grandchild
, &rc2
);
2273 ok(rc1
.left
== rc2
.left
&& rc1
.top
== rc2
.top
&&
2274 rc1
.right
== rc2
.right
&& rc1
.bottom
== rc2
.bottom
,
2275 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2276 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
2277 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2279 /* Add SWP_NOZORDER and it will be properly resized. */
2280 GetWindowRect(hwnd_grandchild
, &rc1
);
2281 ret
= SetWindowPos(hwnd_grandchild
, hwnd_child2
, 1, 2, 3, 4, SWP_NOZORDER
);
2282 ok(ret
, "Got %d\n", ret
);
2283 GetWindowRect(hwnd_grandchild
, &rc2
);
2284 ok((rc1
.left
+1) == rc2
.left
&& (rc1
.top
+2) == rc2
.top
&&
2285 (rc1
.left
+4) == rc2
.right
&& (rc1
.top
+6) == rc2
.bottom
,
2286 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2287 rc1
.left
+1, rc1
.top
+2, rc1
.left
+4, rc1
.top
+6, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
2288 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2290 /* Given a sibling window, the window is properly resized. */
2291 GetWindowRect(hwnd_child
, &rc1
);
2292 ret
= SetWindowPos(hwnd_child
, hwnd_child2
, 1, 2, 3, 4, 0);
2293 ok(ret
, "Got %d\n", ret
);
2294 GetWindowRect(hwnd_child
, &rc2
);
2295 ok((rc1
.left
+1) == rc2
.left
&& (rc1
.top
+2) == rc2
.top
&&
2296 (rc1
.left
+4) == rc2
.right
&& (rc1
.top
+6) == rc2
.bottom
,
2297 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2298 rc1
.left
+1, rc1
.top
+2, rc1
.left
+4, rc1
.top
+6, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
2299 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2301 /* Involving the desktop window changes things. */
2302 ret
= SetWindowPos(hwnd_child
, hwnd_desktop
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2303 ok(!ret
, "Got %d\n", ret
);
2304 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2306 GetWindowRect(hwnd_child
, &rc1
);
2307 ret
= SetWindowPos(hwnd_child
, hwnd_desktop
, 0, 0, 0, 0, 0);
2308 ok(!ret
, "Got %d\n", ret
);
2309 GetWindowRect(hwnd_child
, &rc2
);
2310 ok(rc1
.top
== rc2
.top
&& rc1
.left
== rc2
.left
&&
2311 rc1
.bottom
== rc2
.bottom
&& rc1
.right
== rc2
.right
,
2312 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2313 rc1
.top
, rc1
.left
, rc1
.bottom
, rc1
.right
, rc2
.top
, rc2
.left
, rc2
.bottom
, rc2
.right
);
2314 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2316 ret
= SetWindowPos(hwnd_desktop
, hwnd_child
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2317 ok(!ret
, "Got %d\n", ret
);
2318 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2320 ret
= SetWindowPos(hwnd_desktop
, hwnd
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2321 ok(!ret
, "Got %d\n", ret
);
2322 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2324 ret
= SetWindowPos(hwnd
, hwnd_desktop
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
2325 ok(!ret
, "Got %d\n", ret
);
2326 check_active_state(hwnd2
, hwnd2
, hwnd2
);
2328 DestroyWindow(hwnd_grandchild
);
2329 DestroyWindow(hwnd_child
);
2330 DestroyWindow(hwnd_child2
);
2332 hwnd_child
= create_tool_window(WS_CHILD
|WS_POPUP
|WS_SYSMENU
, hwnd2
);
2333 ok(!!hwnd_child
, "Failed to create child window (%d)\n", GetLastError());
2334 ret
= SetWindowPos(hwnd_child
, NULL
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2335 ok(ret
, "Got %d\n", ret
);
2336 flush_events( TRUE
);
2337 todo_wine
check_active_state(hwnd2
, hwnd2
, hwnd2
);
2338 DestroyWindow(hwnd_child
);
2341 static void test_SetMenu(HWND parent
)
2348 hMenu
= CreateMenu();
2351 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
2354 /* fails on (at least) Wine, NT4, XP SP2 */
2355 test_nonclient_area(parent
);
2357 ret
= GetMenu(parent
);
2358 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
2359 /* test whether we can destroy a menu assigned to a window */
2360 retok
= DestroyMenu(hMenu
);
2361 ok( retok
, "DestroyMenu error %d\n", GetLastError());
2362 retok
= IsMenu(hMenu
);
2363 ok(!retok
|| broken(retok
) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
2364 ret
= GetMenu(parent
);
2365 /* This test fails on Win9x */
2367 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
2368 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
2369 test_nonclient_area(parent
);
2371 hMenu
= CreateMenu();
2375 ret
= GetMenu(parent
);
2376 ok(ret
== 0, "unexpected menu id %p\n", ret
);
2378 ok(!SetMenu(parent
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
2379 test_nonclient_area(parent
);
2380 ret
= GetMenu(parent
);
2381 ok(ret
== 0, "unexpected menu id %p\n", ret
);
2383 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
2386 /* fails on (at least) Wine, NT4, XP SP2 */
2387 test_nonclient_area(parent
);
2389 ret
= GetMenu(parent
);
2390 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
2392 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
2393 test_nonclient_area(parent
);
2394 ret
= GetMenu(parent
);
2395 ok(ret
== 0, "unexpected menu id %p\n", ret
);
2398 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, parent
, (HMENU
)10, 0, NULL
);
2401 ret
= GetMenu(child
);
2402 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2404 ok(!SetMenu(child
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
2405 test_nonclient_area(child
);
2406 ret
= GetMenu(child
);
2407 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2409 ok(!SetMenu(child
, hMenu
), "SetMenu on a child window should fail\n");
2410 test_nonclient_area(child
);
2411 ret
= GetMenu(child
);
2412 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2414 ok(!SetMenu(child
, 0), "SetMenu(0) on a child window should fail\n");
2415 test_nonclient_area(child
);
2416 ret
= GetMenu(child
);
2417 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2419 style
= GetWindowLongA(child
, GWL_STYLE
);
2420 SetWindowLongA(child
, GWL_STYLE
, style
| WS_POPUP
);
2421 ok(SetMenu(child
, hMenu
), "SetMenu on a popup child window should not fail\n");
2422 ok(SetMenu(child
, 0), "SetMenu on a popup child window should not fail\n");
2423 SetWindowLongA(child
, GWL_STYLE
, style
);
2425 SetWindowLongA(child
, GWL_STYLE
, style
| WS_OVERLAPPED
);
2426 ok(!SetMenu(child
, hMenu
), "SetMenu on an overlapped child window should fail\n");
2427 SetWindowLongA(child
, GWL_STYLE
, style
);
2429 DestroyWindow(child
);
2433 static void test_window_tree(HWND parent
, const DWORD
*style
, const int *order
, int total
)
2435 HWND child
[5], hwnd
;
2440 hwnd
= GetWindow(parent
, GW_CHILD
);
2441 ok(!hwnd
, "have to start without children to perform the test\n");
2443 for (i
= 0; i
< total
; i
++)
2445 if (style
[i
] & DS_CONTROL
)
2447 child
[i
] = CreateWindowExA(0, (LPCSTR
)MAKEINTATOM(32770), "", style
[i
] & ~WS_VISIBLE
,
2448 0,0,0,0, parent
, (HMENU
)i
, 0, NULL
);
2449 if (style
[i
] & WS_VISIBLE
)
2450 ShowWindow(child
[i
], SW_SHOW
);
2452 SetWindowPos(child
[i
], HWND_BOTTOM
, 0,0,10,10, SWP_NOACTIVATE
);
2455 child
[i
] = CreateWindowExA(0, "static", "", style
[i
], 0,0,10,10,
2456 parent
, (HMENU
)i
, 0, NULL
);
2457 trace("child[%ld] = %p\n", i
, child
[i
]);
2458 ok(child
[i
] != 0, "CreateWindowEx failed to create child window\n");
2461 hwnd
= GetWindow(parent
, GW_CHILD
);
2462 ok(hwnd
!= 0, "GetWindow(GW_CHILD) failed\n");
2463 ok(hwnd
== GetWindow(child
[total
- 1], GW_HWNDFIRST
), "GW_HWNDFIRST is wrong\n");
2464 ok(child
[order
[total
- 1]] == GetWindow(child
[0], GW_HWNDLAST
), "GW_HWNDLAST is wrong\n");
2466 for (i
= 0; i
< total
; i
++)
2468 trace("hwnd[%ld] = %p\n", i
, hwnd
);
2469 ok(child
[order
[i
]] == hwnd
, "Z order of child #%ld is wrong\n", i
);
2471 hwnd
= GetWindow(hwnd
, GW_HWNDNEXT
);
2474 for (i
= 0; i
< total
; i
++)
2475 ok(DestroyWindow(child
[i
]), "DestroyWindow failed\n");
2478 static void test_children_zorder(HWND parent
)
2480 const DWORD simple_style
[5] = { WS_CHILD
, WS_CHILD
, WS_CHILD
, WS_CHILD
,
2482 const int simple_order
[5] = { 0, 1, 2, 3, 4 };
2484 const DWORD complex_style
[5] = { WS_CHILD
, WS_CHILD
| WS_MAXIMIZE
,
2485 WS_CHILD
| WS_VISIBLE
, WS_CHILD
,
2486 WS_CHILD
| WS_MAXIMIZE
| WS_VISIBLE
};
2487 const int complex_order_1
[1] = { 0 };
2488 const int complex_order_2
[2] = { 1, 0 };
2489 const int complex_order_3
[3] = { 1, 0, 2 };
2490 const int complex_order_4
[4] = { 1, 0, 2, 3 };
2491 const int complex_order_5
[5] = { 4, 1, 0, 2, 3 };
2492 const DWORD complex_style_6
[3] = { WS_CHILD
| WS_VISIBLE
,
2493 WS_CHILD
| WS_CLIPSIBLINGS
| DS_CONTROL
| WS_VISIBLE
,
2494 WS_CHILD
| WS_VISIBLE
};
2495 const int complex_order_6
[3] = { 0, 1, 2 };
2497 /* simple WS_CHILD */
2498 test_window_tree(parent
, simple_style
, simple_order
, 5);
2500 /* complex children styles */
2501 test_window_tree(parent
, complex_style
, complex_order_1
, 1);
2502 test_window_tree(parent
, complex_style
, complex_order_2
, 2);
2503 test_window_tree(parent
, complex_style
, complex_order_3
, 3);
2504 test_window_tree(parent
, complex_style
, complex_order_4
, 4);
2505 test_window_tree(parent
, complex_style
, complex_order_5
, 5);
2507 /* another set of complex children styles */
2508 test_window_tree(parent
, complex_style_6
, complex_order_6
, 3);
2511 #define check_z_order(hwnd, next, prev, owner, topmost) \
2512 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2515 static void check_z_order_debug(HWND hwnd
, HWND next
, HWND prev
, HWND owner
,
2516 BOOL topmost
, const char *file
, int line
)
2521 test
= GetWindow(hwnd
, GW_HWNDNEXT
);
2522 /* skip foreign windows */
2523 while (test
&& test
!= next
&&
2524 (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2525 UlongToHandle(GetWindowLongPtrA(test
, GWLP_HINSTANCE
)) != GetModuleHandleA(NULL
) ||
2526 GetWindow(test
, GW_OWNER
) == next
))
2528 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2529 test
= GetWindow(test
, GW_HWNDNEXT
);
2531 ok_(file
, line
)(next
== test
, "%p: expected next %p, got %p\n", hwnd
, next
, test
);
2533 test
= GetWindow(hwnd
, GW_HWNDPREV
);
2534 /* skip foreign windows */
2535 while (test
&& test
!= prev
&&
2536 (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2537 UlongToHandle(GetWindowLongPtrA(test
, GWLP_HINSTANCE
)) != GetModuleHandleA(NULL
) ||
2538 GetWindow(test
, GW_OWNER
) == hwnd
))
2540 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2541 test
= GetWindow(test
, GW_HWNDPREV
);
2543 ok_(file
, line
)(prev
== test
, "%p: expected prev %p, got %p\n", hwnd
, prev
, test
);
2545 test
= GetWindow(hwnd
, GW_OWNER
);
2546 ok_(file
, line
)(owner
== test
, "%p: expected owner %p, got %p\n", hwnd
, owner
, test
);
2548 ex_style
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
2549 ok_(file
, line
)(!(ex_style
& WS_EX_TOPMOST
) == !topmost
, "%p: expected %stopmost\n",
2550 hwnd
, topmost
? "" : "NOT ");
2553 static void test_popup_zorder(HWND hwnd_D
, HWND hwnd_E
, DWORD style
)
2555 HWND hwnd_A
, hwnd_B
, hwnd_C
, hwnd_F
;
2557 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D
, hwnd_E
);
2559 SetWindowPos(hwnd_E
, hwnd_D
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2561 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2562 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2564 hwnd_F
= CreateWindowExA(0, "MainWindowClass", "Owner window",
2565 WS_OVERLAPPED
| WS_CAPTION
,
2567 0, 0, GetModuleHandleA(NULL
), NULL
);
2568 trace("hwnd_F %p\n", hwnd_F
);
2569 check_z_order(hwnd_F
, hwnd_D
, 0, 0, FALSE
);
2571 SetWindowPos(hwnd_F
, hwnd_E
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2572 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2573 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2574 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2576 hwnd_C
= CreateWindowExA(0, "MainWindowClass", NULL
,
2579 hwnd_F
, 0, GetModuleHandleA(NULL
), NULL
);
2580 trace("hwnd_C %p\n", hwnd_C
);
2581 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2582 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2583 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2584 check_z_order(hwnd_C
, hwnd_D
, 0, hwnd_F
, FALSE
);
2586 hwnd_B
= CreateWindowExA(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2589 hwnd_F
, 0, GetModuleHandleA(NULL
), NULL
);
2590 trace("hwnd_B %p\n", hwnd_B
);
2591 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2592 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2593 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2594 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2595 check_z_order(hwnd_B
, hwnd_C
, 0, hwnd_F
, TRUE
);
2597 hwnd_A
= CreateWindowExA(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2600 0, 0, GetModuleHandleA(NULL
), NULL
);
2601 trace("hwnd_A %p\n", hwnd_A
);
2602 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2603 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2604 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2605 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2606 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2607 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2609 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
);
2611 /* move hwnd_F and its popups up */
2612 SetWindowPos(hwnd_F
, HWND_TOP
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2613 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2614 check_z_order(hwnd_D
, hwnd_E
, hwnd_F
, 0, FALSE
);
2615 check_z_order(hwnd_F
, hwnd_D
, hwnd_C
, 0, FALSE
);
2616 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2617 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2618 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2620 /* move hwnd_F and its popups down */
2621 #if 0 /* enable once Wine is fixed to pass this test */
2622 SetWindowPos(hwnd_F
, HWND_BOTTOM
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2623 check_z_order(hwnd_F
, 0, hwnd_C
, 0, FALSE
);
2624 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2625 check_z_order(hwnd_B
, hwnd_C
, hwnd_E
, hwnd_F
, FALSE
);
2626 check_z_order(hwnd_E
, hwnd_B
, hwnd_D
, 0, FALSE
);
2627 check_z_order(hwnd_D
, hwnd_E
, hwnd_A
, 0, FALSE
);
2628 check_z_order(hwnd_A
, hwnd_D
, 0, 0, TRUE
);
2631 /* make hwnd_C owned by a topmost window */
2632 DestroyWindow( hwnd_C
);
2633 hwnd_C
= CreateWindowExA(0, "MainWindowClass", NULL
,
2636 hwnd_A
, 0, GetModuleHandleA(NULL
), NULL
);
2637 trace("hwnd_C %p\n", hwnd_C
);
2638 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2639 check_z_order(hwnd_D
, hwnd_E
, hwnd_F
, 0, FALSE
);
2640 check_z_order(hwnd_F
, hwnd_D
, hwnd_B
, 0, FALSE
);
2641 check_z_order(hwnd_B
, hwnd_F
, hwnd_A
, hwnd_F
, TRUE
);
2642 check_z_order(hwnd_A
, hwnd_B
, hwnd_C
, 0, TRUE
);
2643 check_z_order(hwnd_C
, hwnd_A
, 0, hwnd_A
, TRUE
);
2645 DestroyWindow(hwnd_A
);
2646 DestroyWindow(hwnd_B
);
2647 DestroyWindow(hwnd_C
);
2648 DestroyWindow(hwnd_F
);
2651 static void test_vis_rgn( HWND hwnd
)
2653 RECT win_rect
, rgn_rect
;
2654 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2657 ShowWindow(hwnd
,SW_SHOW
);
2658 hdc
= GetDC( hwnd
);
2659 ok( GetRandomRgn( hdc
, hrgn
, SYSRGN
) != 0, "GetRandomRgn failed\n" );
2660 GetWindowRect( hwnd
, &win_rect
);
2661 GetRgnBox( hrgn
, &rgn_rect
);
2664 trace("win9x, mapping to screen coords\n");
2665 MapWindowPoints( hwnd
, 0, (POINT
*)&rgn_rect
, 2 );
2667 trace("win: %d,%d-%d,%d\n", win_rect
.left
, win_rect
.top
, win_rect
.right
, win_rect
.bottom
);
2668 trace("rgn: %d,%d-%d,%d\n", rgn_rect
.left
, rgn_rect
.top
, rgn_rect
.right
, rgn_rect
.bottom
);
2669 ok( win_rect
.left
<= rgn_rect
.left
, "rgn left %d not inside win rect %d\n",
2670 rgn_rect
.left
, win_rect
.left
);
2671 ok( win_rect
.top
<= rgn_rect
.top
, "rgn top %d not inside win rect %d\n",
2672 rgn_rect
.top
, win_rect
.top
);
2673 ok( win_rect
.right
>= rgn_rect
.right
, "rgn right %d not inside win rect %d\n",
2674 rgn_rect
.right
, win_rect
.right
);
2675 ok( win_rect
.bottom
>= rgn_rect
.bottom
, "rgn bottom %d not inside win rect %d\n",
2676 rgn_rect
.bottom
, win_rect
.bottom
);
2677 ReleaseDC( hwnd
, hdc
);
2680 static LRESULT WINAPI
set_focus_on_activate_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
2682 if (msg
== WM_ACTIVATE
&& LOWORD(wp
) == WA_ACTIVE
)
2684 HWND child
= GetWindow(hwnd
, GW_CHILD
);
2685 ok(child
!= 0, "couldn't find child window\n");
2687 ok(GetFocus() == child
, "Focus should be on child %p\n", child
);
2690 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
2693 static void test_SetFocus(HWND hwnd
)
2695 HWND child
, child2
, ret
;
2696 WNDPROC old_wnd_proc
;
2698 /* check if we can set focus to non-visible windows */
2700 ShowWindow(hwnd
, SW_SHOW
);
2703 ok( GetFocus() == hwnd
, "Failed to set focus to visible window %p\n", hwnd
);
2704 ok( GetWindowLongA(hwnd
,GWL_STYLE
) & WS_VISIBLE
, "Window %p not visible\n", hwnd
);
2705 ShowWindow(hwnd
, SW_HIDE
);
2708 ok( GetFocus() == hwnd
, "Failed to set focus to invisible window %p\n", hwnd
);
2709 ok( !(GetWindowLongA(hwnd
,GWL_STYLE
) & WS_VISIBLE
), "Window %p still visible\n", hwnd
);
2710 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2713 ok( GetFocus() == child
, "Failed to set focus to invisible child %p\n", child
);
2714 ok( !(GetWindowLongA(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2715 ShowWindow(child
, SW_SHOW
);
2716 ok( GetWindowLongA(child
,GWL_STYLE
) & WS_VISIBLE
, "Child %p is not visible\n", child
);
2717 ok( GetFocus() == child
, "Focus no longer on child %p\n", child
);
2718 ShowWindow(child
, SW_HIDE
);
2719 ok( !(GetWindowLongA(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2720 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2721 ShowWindow(child
, SW_SHOW
);
2722 child2
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, child
, 0, 0, NULL
);
2724 ShowWindow(child2
, SW_SHOW
);
2726 ShowWindow(child
, SW_HIDE
);
2727 ok( !(GetWindowLongA(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2728 ok( GetFocus() == child2
, "Focus should be on %p, not %p\n", child2
, GetFocus() );
2729 ShowWindow(child
, SW_SHOW
);
2731 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2732 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_HIDEWINDOW
);
2733 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2735 ShowWindow(child
, SW_HIDE
);
2737 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2738 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_SHOWWINDOW
);
2739 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2740 ShowWindow(child
, SW_HIDE
);
2741 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2743 ShowWindow(hwnd
, SW_SHOW
);
2744 ShowWindow(child
, SW_SHOW
);
2746 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2747 EnableWindow(hwnd
, FALSE
);
2748 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2749 EnableWindow(hwnd
, TRUE
);
2751 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2752 ShowWindow(hwnd
, SW_SHOWMINIMIZED
);
2753 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2755 ok( GetFocus() != child
, "Focus should not be on child %p\n", child
);
2756 ok( GetFocus() != hwnd
, "Focus should not be on parent %p\n", hwnd
);
2757 ShowWindow(hwnd
, SW_RESTORE
);
2758 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2759 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
2760 ShowWindow(hwnd
, SW_SHOWMINIMIZED
);
2761 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2762 ok( GetFocus() != child
, "Focus should not be on child %p\n", child
);
2764 ok( GetFocus() != hwnd
, "Focus should not be on parent %p\n", hwnd
);
2765 old_wnd_proc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)set_focus_on_activate_proc
);
2766 ShowWindow(hwnd
, SW_RESTORE
);
2767 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2769 ok( GetFocus() == child
, "Focus should be on child %p, not %p\n", child
, GetFocus() );
2770 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)old_wnd_proc
);
2773 SetParent( child
, GetDesktopWindow());
2774 SetParent( child2
, child
);
2775 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2776 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
2777 ret
= SetFocus( child2
);
2778 ok( ret
== 0, "SetFocus %p should fail\n", child2
);
2779 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2780 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
2781 ret
= SetFocus( child
);
2782 ok( ret
== 0, "SetFocus %p should fail\n", child
);
2783 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2784 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
2785 SetWindowLongW( child
, GWL_STYLE
, WS_POPUP
|WS_CHILD
);
2787 ok( GetActiveWindow() == child
, "child window %p should be active\n", child
);
2788 ok( GetFocus() == child2
, "Focus should be on child2 %p\n", child2
);
2790 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2791 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
2793 ok( GetActiveWindow() == child
, "child window %p should be active\n", child
);
2794 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2796 DestroyWindow( child2
);
2797 DestroyWindow( child
);
2800 static void test_SetActiveWindow(HWND hwnd
)
2804 flush_events( TRUE
);
2805 ShowWindow(hwnd
, SW_HIDE
);
2808 check_wnd_state(0, 0, 0, 0);
2810 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2812 ShowWindow(hwnd
, SW_SHOW
);
2813 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2815 hwnd2
= SetActiveWindow(0);
2816 ok(hwnd2
== hwnd
, "SetActiveWindow returned %p instead of %p\n", hwnd2
, hwnd
);
2817 if (!GetActiveWindow()) /* doesn't always work on vista */
2819 check_wnd_state(0, 0, 0, 0);
2820 hwnd2
= SetActiveWindow(hwnd
);
2821 ok(hwnd2
== 0, "SetActiveWindow returned %p instead of 0\n", hwnd2
);
2823 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2825 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2826 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2828 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2829 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2831 ShowWindow(hwnd
, SW_HIDE
);
2832 check_wnd_state(0, 0, 0, 0);
2834 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2835 SetActiveWindow(hwnd
);
2836 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2838 ShowWindow(hwnd
, SW_SHOW
);
2839 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2841 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2842 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2844 DestroyWindow(hwnd2
);
2845 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2847 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2848 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2850 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2851 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2853 DestroyWindow(hwnd2
);
2854 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2857 struct create_window_thread_params
2860 HANDLE window_created
;
2861 HANDLE test_finished
;
2864 static DWORD WINAPI
create_window_thread(void *param
)
2866 struct create_window_thread_params
*p
= param
;
2870 p
->window
= CreateWindowA("static", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 0, 0, 0, 0, 0, 0);
2872 ret
= SetEvent(p
->window_created
);
2873 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
2875 res
= WaitForSingleObject(p
->test_finished
, INFINITE
);
2876 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
2878 DestroyWindow(p
->window
);
2882 static void test_SetForegroundWindow(HWND hwnd
)
2884 struct create_window_thread_params thread_params
;
2892 flush_events( TRUE
);
2893 ShowWindow(hwnd
, SW_HIDE
);
2896 check_wnd_state(0, 0, 0, 0);
2898 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2900 ShowWindow(hwnd
, SW_SHOW
);
2901 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2903 hwnd2
= SetActiveWindow(0);
2904 ok(hwnd2
== hwnd
, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2
, hwnd
);
2905 if (GetActiveWindow() == hwnd
) /* doesn't always work on vista */
2906 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2908 check_wnd_state(0, 0, 0, 0);
2910 ret
= SetForegroundWindow(hwnd
);
2913 skip( "SetForegroundWindow not working\n" );
2916 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2918 SetLastError(0xdeadbeef);
2919 ret
= SetForegroundWindow(0);
2920 ok(!ret
, "SetForegroundWindow returned TRUE instead of FALSE\n");
2921 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
||
2922 broken(GetLastError() == 0xdeadbeef), /* win9x */
2923 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2924 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2926 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2927 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2929 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2930 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2932 hwnd2
= GetForegroundWindow();
2933 ok(hwnd2
== hwnd
, "Wrong foreground window %p\n", hwnd2
);
2934 ret
= SetForegroundWindow( GetDesktopWindow() );
2935 ok(ret
, "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2936 hwnd2
= GetForegroundWindow();
2937 ok(hwnd2
!= hwnd
, "Wrong foreground window %p\n", hwnd2
);
2939 ShowWindow(hwnd
, SW_HIDE
);
2940 check_wnd_state(0, 0, 0, 0);
2942 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2943 ret
= SetForegroundWindow(hwnd
);
2944 ok(ret
|| broken(!ret
), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
2945 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2947 ShowWindow(hwnd
, SW_SHOW
);
2948 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2950 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2951 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2953 DestroyWindow(hwnd2
);
2954 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2956 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2957 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2959 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2960 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2962 DestroyWindow(hwnd2
);
2963 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2965 hwnd2
= CreateWindowA("static", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 0, 0, 0, 0, 0, 0);
2966 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2968 thread_params
.window_created
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2969 ok(!!thread_params
.window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
2970 thread_params
.test_finished
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2971 ok(!!thread_params
.test_finished
, "CreateEvent failed, last error %#x.\n", GetLastError());
2972 thread
= CreateThread(NULL
, 0, create_window_thread
, &thread_params
, 0, &tid
);
2973 ok(!!thread
, "Failed to create thread, last error %#x.\n", GetLastError());
2974 res
= WaitForSingleObject(thread_params
.window_created
, INFINITE
);
2975 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
2976 check_wnd_state(hwnd2
, thread_params
.window
, hwnd2
, 0);
2978 SetForegroundWindow(hwnd2
);
2979 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2981 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2982 if (0) check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2983 todo_wine
ok(GetActiveWindow() == hwnd2
, "Expected active window %p, got %p.\n", hwnd2
, GetActiveWindow());
2984 todo_wine
ok(GetFocus() == hwnd2
, "Expected focus window %p, got %p.\n", hwnd2
, GetFocus());
2986 SetForegroundWindow(hwnd
);
2987 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2988 style
= GetWindowLongA(hwnd2
, GWL_STYLE
) | WS_CHILD
;
2989 ok(SetWindowLongA(hwnd2
, GWL_STYLE
, style
), "SetWindowLong failed\n");
2990 ok(SetForegroundWindow(hwnd2
), "SetForegroundWindow failed\n");
2991 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2993 SetForegroundWindow(hwnd
);
2994 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2995 ok(SetWindowLongA(hwnd2
, GWL_STYLE
, style
& (~WS_POPUP
)), "SetWindowLong failed\n");
2996 ok(!SetForegroundWindow(hwnd2
), "SetForegroundWindow failed\n");
2997 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2999 SetEvent(thread_params
.test_finished
);
3000 WaitForSingleObject(thread
, INFINITE
);
3001 CloseHandle(thread_params
.test_finished
);
3002 CloseHandle(thread_params
.window_created
);
3003 CloseHandle(thread
);
3004 DestroyWindow(hwnd2
);
3007 static WNDPROC old_button_proc
;
3009 static LRESULT WINAPI
button_hook_proc(HWND button
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3014 key_state
= GetKeyState(VK_LBUTTON
);
3015 ok(!(key_state
& 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state
);
3017 ret
= CallWindowProcA(old_button_proc
, button
, msg
, wparam
, lparam
);
3019 if (msg
== WM_LBUTTONDOWN
)
3023 check_wnd_state(button
, button
, button
, button
);
3025 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
3027 trace("hwnd %p\n", hwnd
);
3029 check_wnd_state(button
, button
, button
, button
);
3031 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
3033 check_wnd_state(button
, button
, button
, button
);
3035 DestroyWindow(hwnd
);
3037 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
3039 trace("hwnd %p\n", hwnd
);
3041 check_wnd_state(button
, button
, button
, button
);
3043 /* button wnd proc should release capture on WM_KILLFOCUS if it does
3044 * match internal button state.
3046 SendMessageA(button
, WM_KILLFOCUS
, 0, 0);
3047 check_wnd_state(button
, button
, button
, 0);
3049 ShowWindow(hwnd
, SW_SHOW
);
3050 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
3052 capture
= SetCapture(hwnd
);
3053 ok(capture
== 0, "SetCapture() = %p\n", capture
);
3055 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
3057 DestroyWindow(hwnd
);
3059 check_wnd_state(button
, 0, button
, 0);
3065 static void test_capture_1(void)
3067 HWND button
, capture
;
3069 capture
= GetCapture();
3070 ok(capture
== 0, "GetCapture() = %p\n", capture
);
3072 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
3074 trace("button %p\n", button
);
3076 old_button_proc
= (WNDPROC
)SetWindowLongPtrA(button
, GWLP_WNDPROC
, (LONG_PTR
)button_hook_proc
);
3078 SendMessageA(button
, WM_LBUTTONDOWN
, 0, 0);
3080 capture
= SetCapture(button
);
3081 ok(capture
== 0, "SetCapture() = %p\n", capture
);
3082 check_wnd_state(button
, 0, button
, button
);
3084 DestroyWindow(button
);
3085 /* old active window test depends on previously executed window
3086 * activation tests, and fails under NT4.
3087 check_wnd_state(oldActive, 0, oldFocus, 0);*/
3090 static void test_capture_2(void)
3092 HWND button
, hwnd
, capture
, oldFocus
, oldActive
;
3094 oldFocus
= GetFocus();
3095 oldActive
= GetActiveWindow();
3096 check_wnd_state(oldActive
, 0, oldFocus
, 0);
3098 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
3100 trace("button %p\n", button
);
3102 check_wnd_state(button
, button
, button
, 0);
3104 capture
= SetCapture(button
);
3105 ok(capture
== 0, "SetCapture() = %p\n", capture
);
3107 check_wnd_state(button
, button
, button
, button
);
3109 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
3110 * internal button state.
3112 SendMessageA(button
, WM_KILLFOCUS
, 0, 0);
3113 check_wnd_state(button
, button
, button
, button
);
3115 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
3117 trace("hwnd %p\n", hwnd
);
3119 check_wnd_state(button
, button
, button
, button
);
3121 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
3123 check_wnd_state(button
, button
, button
, button
);
3125 DestroyWindow(hwnd
);
3127 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
3129 trace("hwnd %p\n", hwnd
);
3131 check_wnd_state(button
, button
, button
, button
);
3133 ShowWindow(hwnd
, SW_SHOW
);
3135 check_wnd_state(hwnd
, hwnd
, hwnd
, button
);
3137 capture
= SetCapture(hwnd
);
3138 ok(capture
== button
, "SetCapture() = %p\n", capture
);
3140 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
3142 DestroyWindow(hwnd
);
3143 check_wnd_state(button
, button
, button
, 0);
3145 DestroyWindow(button
);
3146 check_wnd_state(oldActive
, 0, oldFocus
, 0);
3149 static void test_capture_3(HWND hwnd1
, HWND hwnd2
)
3153 ShowWindow(hwnd1
, SW_HIDE
);
3154 ShowWindow(hwnd2
, SW_HIDE
);
3156 ok(!IsWindowVisible(hwnd1
), "%p should be invisible\n", hwnd1
);
3157 ok(!IsWindowVisible(hwnd2
), "%p should be invisible\n", hwnd2
);
3160 check_wnd_state(0, 0, 0, hwnd1
);
3163 check_wnd_state(0, 0, 0, hwnd2
);
3165 ShowWindow(hwnd1
, SW_SHOW
);
3166 check_wnd_state(hwnd1
, hwnd1
, hwnd1
, hwnd2
);
3168 ret
= ReleaseCapture();
3169 ok (ret
, "releasecapture did not return TRUE.\n");
3170 ret
= ReleaseCapture();
3171 ok (ret
, "releasecapture did not return TRUE after second try.\n");
3174 static LRESULT CALLBACK
test_capture_4_proc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
3177 HWND cap_wnd
, cap_wnd2
, set_cap_wnd
;
3181 case WM_CAPTURECHANGED
:
3183 /* now try to release capture from menu. this should fail */
3184 if (pGetGUIThreadInfo
)
3186 memset(>i
, 0, sizeof(GUITHREADINFO
));
3187 gti
.cbSize
= sizeof(GUITHREADINFO
);
3188 status
= pGetGUIThreadInfo(GetCurrentThreadId(), >i
);
3189 ok(status
, "GetGUIThreadInfo() failed!\n");
3190 ok(gti
.flags
& GUI_INMENUMODE
, "Thread info incorrect (flags=%08X)!\n", gti
.flags
);
3192 cap_wnd
= GetCapture();
3194 ok(cap_wnd
== (HWND
)lParam
, "capture window %p does not match lparam %lx\n", cap_wnd
, lParam
);
3195 todo_wine
ok(cap_wnd
== hWnd
, "capture window %p does not match hwnd %p\n", cap_wnd
, hWnd
);
3197 /* check that re-setting the capture for the menu fails */
3198 set_cap_wnd
= SetCapture(cap_wnd
);
3199 ok(!set_cap_wnd
|| broken(set_cap_wnd
== cap_wnd
), /* nt4 */
3200 "SetCapture should have failed!\n");
3203 DestroyWindow(hWnd
);
3207 /* check that SetCapture fails for another window and that it does not touch the error code */
3208 set_cap_wnd
= SetCapture(hWnd
);
3209 ok(!set_cap_wnd
, "SetCapture should have failed!\n");
3211 /* check that ReleaseCapture fails and does not touch the error code */
3212 status
= ReleaseCapture();
3213 ok(!status
, "ReleaseCapture should have failed!\n");
3215 /* check that thread info did not change */
3216 if (pGetGUIThreadInfo
)
3218 memset(>i
, 0, sizeof(GUITHREADINFO
));
3219 gti
.cbSize
= sizeof(GUITHREADINFO
);
3220 status
= pGetGUIThreadInfo(GetCurrentThreadId(), >i
);
3221 ok(status
, "GetGUIThreadInfo() failed!\n");
3222 ok(gti
.flags
& GUI_INMENUMODE
, "Thread info incorrect (flags=%08X)!\n", gti
.flags
);
3225 /* verify that no capture change took place */
3226 cap_wnd2
= GetCapture();
3227 ok(cap_wnd2
== cap_wnd
, "Capture changed!\n");
3229 /* we are done. kill the window */
3230 DestroyWindow(hWnd
);
3234 return( DefWindowProcA( hWnd
, msg
, wParam
, lParam
) );
3239 /* Test that no-one can mess around with the current capture while a menu is open */
3240 static void test_capture_4(void)
3246 HINSTANCE hInstance
= GetModuleHandleA( NULL
);
3249 if (!pGetGUIThreadInfo
)
3251 win_skip("GetGUIThreadInfo is not available\n");
3254 wclass
.lpszClassName
= "TestCapture4Class";
3255 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
3256 wclass
.lpfnWndProc
= test_capture_4_proc
;
3257 wclass
.hInstance
= hInstance
;
3258 wclass
.hIcon
= LoadIconA( 0, (LPCSTR
)IDI_APPLICATION
);
3259 wclass
.hCursor
= LoadCursorA( 0, (LPCSTR
)IDC_ARROW
);
3260 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
3261 wclass
.lpszMenuName
= 0;
3262 wclass
.cbClsExtra
= 0;
3263 wclass
.cbWndExtra
= 0;
3264 aclass
= RegisterClassA( &wclass
);
3265 ok( aclass
, "RegisterClassA failed with error %d\n", GetLastError());
3266 hwnd
= CreateWindowA( wclass
.lpszClassName
, "MenuTest",
3267 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0,
3268 400, 200, NULL
, NULL
, hInstance
, NULL
);
3269 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
3271 hmenu
= CreatePopupMenu();
3273 ret
= AppendMenuA( hmenu
, MF_STRING
, 1, "winetest2");
3274 ok( ret
, "AppendMenuA has failed!\n");
3276 /* set main window to have initial capture */
3281 win_skip("TrackPopupMenu test crashes on Win9x/WinMe\n");
3285 /* create popup (it will self-destruct) */
3286 ret
= TrackPopupMenu(hmenu
, TPM_RETURNCMD
, 100, 100, 0, hwnd
, NULL
);
3287 ok( ret
== 0, "TrackPopupMenu returned %d expected zero\n", ret
);
3292 DestroyWindow(hwnd
);
3295 /* PeekMessage wrapper that ignores the messages we don't care about */
3296 static BOOL
peek_message( MSG
*msg
)
3301 ret
= PeekMessageA(msg
, 0, 0, 0, PM_REMOVE
);
3302 } while (ret
&& (msg
->message
== WM_TIMER
|| ignore_message(msg
->message
)));
3306 static void test_keyboard_input(HWND hwnd
)
3311 flush_events( TRUE
);
3312 SetWindowPos(hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_SHOWWINDOW
);
3314 flush_events( TRUE
);
3316 ok(GetActiveWindow() == hwnd
, "wrong active window %p\n", GetActiveWindow());
3319 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
3321 flush_events( TRUE
);
3323 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
3324 ret
= peek_message(&msg
);
3325 ok( ret
, "no message available\n");
3326 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3327 ret
= peek_message(&msg
);
3328 ok( !ret
, "message %04x available\n", msg
.message
);
3330 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
3332 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
3333 ret
= peek_message(&msg
);
3334 ok(ret
, "no message available\n");
3335 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3336 ret
= peek_message(&msg
);
3337 ok( !ret
, "message %04x available\n", msg
.message
);
3339 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
3341 keybd_event(VK_SPACE
, 0, 0, 0);
3342 if (!peek_message(&msg
))
3344 skip( "keybd_event didn't work, skipping keyboard test\n" );
3347 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3348 ret
= peek_message(&msg
);
3349 ok( !ret
, "message %04x available\n", msg
.message
);
3352 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3354 flush_events( TRUE
);
3356 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
3357 ret
= peek_message(&msg
);
3358 ok(ret
, "no message available\n");
3359 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3360 ret
= peek_message(&msg
);
3361 ok( !ret
, "message %04x available\n", msg
.message
);
3363 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3365 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
3366 ret
= peek_message(&msg
);
3367 ok(ret
, "no message available\n");
3368 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3369 ret
= peek_message(&msg
);
3370 ok( !ret
, "message %04x available\n", msg
.message
);
3372 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3374 keybd_event(VK_SPACE
, 0, 0, 0);
3375 ret
= peek_message(&msg
);
3376 ok(ret
, "no message available\n");
3377 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_SYSKEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3378 ret
= peek_message(&msg
);
3379 ok( !ret
, "message %04x available\n", msg
.message
);
3382 static BOOL
wait_for_message( MSG
*msg
)
3388 ret
= peek_message(msg
);
3391 if (msg
->message
== WM_PAINT
) DispatchMessageA(msg
);
3394 else if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, 100, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
3396 if (!ret
) msg
->message
= 0;
3400 static void test_mouse_input(HWND hwnd
)
3410 ShowWindow(hwnd
, SW_SHOWNORMAL
);
3412 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3414 GetWindowRect(hwnd
, &rc
);
3415 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3417 popup
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_POPUP
,
3418 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
,
3421 ShowWindow(popup
, SW_SHOW
);
3422 UpdateWindow(popup
);
3423 SetWindowPos( popup
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3425 GetWindowRect(popup
, &rc
);
3426 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3428 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
3429 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
3430 trace("setting cursor to (%d,%d)\n", x
, y
);
3434 if (x
!= pt
.x
|| y
!= pt
.y
)
3436 skip( "failed to set mouse position, skipping mouse input tests\n" );
3440 flush_events( TRUE
);
3442 /* Check that setting the same position may generate WM_MOUSEMOVE */
3445 ret
= peek_message(&msg
);
3448 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n",
3449 msg
.hwnd
, msg
.message
);
3450 ok(msg
.pt
.x
== x
&& msg
.pt
.y
== y
, "wrong message coords (%d,%d)/(%d,%d)\n",
3451 x
, y
, msg
.pt
.x
, msg
.pt
.y
);
3454 /* force the system to update its internal queue mouse position,
3455 * otherwise it won't generate relative mouse movements below.
3457 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
3458 flush_events( TRUE
);
3461 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
3462 flush_events( FALSE
);
3463 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
3464 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
3466 if (msg
.message
== WM_TIMER
|| ignore_message(msg
.message
)) continue;
3467 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
,
3468 "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3469 DispatchMessageA(&msg
);
3471 ret
= peek_message(&msg
);
3472 ok( !ret
, "message %04x available\n", msg
.message
);
3474 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
3475 ShowWindow(popup
, SW_HIDE
);
3476 ret
= wait_for_message( &msg
);
3478 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3479 flush_events( TRUE
);
3481 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
3482 ShowWindow(hwnd
, SW_HIDE
);
3483 ret
= wait_for_message( &msg
);
3484 ok( !ret
, "message %04x available\n", msg
.message
);
3485 flush_events( TRUE
);
3487 /* test mouse clicks */
3489 ShowWindow(hwnd
, SW_SHOW
);
3490 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3491 flush_events( TRUE
);
3492 ShowWindow(popup
, SW_SHOW
);
3493 SetWindowPos( popup
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3494 flush_events( TRUE
);
3496 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3497 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3498 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3499 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3501 ret
= wait_for_message( &msg
);
3504 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
3507 if (msg
.message
== WM_MOUSEMOVE
) /* win2k has an extra WM_MOUSEMOVE here */
3509 ret
= wait_for_message( &msg
);
3510 ok(ret
, "no message available\n");
3513 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
3514 msg
.hwnd
, popup
, msg
.message
);
3516 ret
= wait_for_message( &msg
);
3517 ok(ret
, "no message available\n");
3518 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
3519 msg
.hwnd
, popup
, msg
.message
);
3521 ret
= wait_for_message( &msg
);
3522 ok(ret
, "no message available\n");
3523 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p/%p message %04x\n",
3524 msg
.hwnd
, popup
, msg
.message
);
3526 ret
= wait_for_message( &msg
);
3527 ok(ret
, "no message available\n");
3528 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
3529 msg
.hwnd
, popup
, msg
.message
);
3531 ret
= peek_message(&msg
);
3532 ok(!ret
, "message %04x available\n", msg
.message
);
3534 ShowWindow(popup
, SW_HIDE
);
3535 flush_events( TRUE
);
3537 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3538 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3539 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3540 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3542 ret
= wait_for_message( &msg
);
3543 ok(ret
, "no message available\n");
3544 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
3545 msg
.hwnd
, hwnd
, msg
.message
);
3546 ret
= wait_for_message( &msg
);
3547 ok(ret
, "no message available\n");
3548 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
3549 msg
.hwnd
, hwnd
, msg
.message
);
3551 test_lbuttondown_flag
= TRUE
;
3552 SendMessageA(hwnd
, WM_COMMAND
, (WPARAM
)popup
, 0);
3553 test_lbuttondown_flag
= FALSE
;
3555 ret
= wait_for_message( &msg
);
3556 ok(ret
, "no message available\n");
3557 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
3558 msg
.hwnd
, popup
, msg
.message
);
3559 ok(peek_message(&msg
), "no message available\n");
3560 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
3561 msg
.hwnd
, popup
, msg
.message
);
3562 ok(peek_message(&msg
), "no message available\n");
3564 /* Test WM_MOUSEACTIVATE */
3565 #define TEST_MOUSEACTIVATE(A,B) \
3566 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
3567 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
3569 TEST_MOUSEACTIVATE(HTERROR
,MA_ACTIVATE
);
3570 TEST_MOUSEACTIVATE(HTTRANSPARENT
,MA_ACTIVATE
);
3571 TEST_MOUSEACTIVATE(HTNOWHERE
,MA_ACTIVATE
);
3572 TEST_MOUSEACTIVATE(HTCLIENT
,MA_ACTIVATE
);
3573 TEST_MOUSEACTIVATE(HTCAPTION
,MA_ACTIVATE
);
3574 TEST_MOUSEACTIVATE(HTSYSMENU
,MA_ACTIVATE
);
3575 TEST_MOUSEACTIVATE(HTSIZE
,MA_ACTIVATE
);
3576 TEST_MOUSEACTIVATE(HTMENU
,MA_ACTIVATE
);
3577 TEST_MOUSEACTIVATE(HTHSCROLL
,MA_ACTIVATE
);
3578 TEST_MOUSEACTIVATE(HTVSCROLL
,MA_ACTIVATE
);
3579 TEST_MOUSEACTIVATE(HTMINBUTTON
,MA_ACTIVATE
);
3580 TEST_MOUSEACTIVATE(HTMAXBUTTON
,MA_ACTIVATE
);
3581 TEST_MOUSEACTIVATE(HTLEFT
,MA_ACTIVATE
);
3582 TEST_MOUSEACTIVATE(HTRIGHT
,MA_ACTIVATE
);
3583 TEST_MOUSEACTIVATE(HTTOP
,MA_ACTIVATE
);
3584 TEST_MOUSEACTIVATE(HTTOPLEFT
,MA_ACTIVATE
);
3585 TEST_MOUSEACTIVATE(HTTOPRIGHT
,MA_ACTIVATE
);
3586 TEST_MOUSEACTIVATE(HTBOTTOM
,MA_ACTIVATE
);
3587 TEST_MOUSEACTIVATE(HTBOTTOMLEFT
,MA_ACTIVATE
);
3588 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT
,MA_ACTIVATE
);
3589 TEST_MOUSEACTIVATE(HTBORDER
,MA_ACTIVATE
);
3590 TEST_MOUSEACTIVATE(HTOBJECT
,MA_ACTIVATE
);
3591 TEST_MOUSEACTIVATE(HTCLOSE
,MA_ACTIVATE
);
3592 TEST_MOUSEACTIVATE(HTHELP
,MA_ACTIVATE
);
3595 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
3596 flush_events( TRUE
);
3598 DestroyWindow(popup
);
3601 static void test_validatergn(HWND hwnd
)
3607 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_VISIBLE
, 10, 10, 10, 10, hwnd
, 0, 0, NULL
);
3608 ShowWindow(hwnd
, SW_SHOW
);
3609 UpdateWindow( hwnd
);
3610 /* test that ValidateRect validates children*/
3611 InvalidateRect( child
, NULL
, 1);
3612 GetWindowRect( child
, &rc
);
3613 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
3614 ret
= GetUpdateRect( child
, &rc2
, 0);
3615 ok( ret
== 1, "Expected GetUpdateRect to return non-zero, got %d\n", ret
);
3616 ok( rc2
.right
> rc2
.left
&& rc2
.bottom
> rc2
.top
,
3617 "Update rectangle is empty!\n");
3618 ValidateRect( hwnd
, &rc
);
3619 ret
= GetUpdateRect( child
, &rc2
, 0);
3620 ok( !ret
, "Expected GetUpdateRect to return zero, got %d\n", ret
);
3621 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
3622 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
3623 rc2
.right
, rc2
.bottom
);
3625 /* now test ValidateRgn */
3626 InvalidateRect( child
, NULL
, 1);
3627 GetWindowRect( child
, &rc
);
3628 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
3629 rgn
= CreateRectRgnIndirect( &rc
);
3630 ValidateRgn( hwnd
, rgn
);
3631 ret
= GetUpdateRect( child
, &rc2
, 0);
3632 ok( !ret
, "Expected GetUpdateRect to return zero, got %d\n", ret
);
3633 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
3634 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
3635 rc2
.right
, rc2
.bottom
);
3638 DestroyWindow( child
);
3641 static void nccalchelper(HWND hwnd
, INT x
, INT y
, RECT
*prc
)
3644 MoveWindow( hwnd
, 0, 0, x
, y
, 0);
3645 GetWindowRect( hwnd
, prc
);
3647 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)prc
);
3648 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
3649 rc
.left
,rc
.top
,rc
.right
,rc
.bottom
, prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
3652 static void test_nccalcscroll(HWND parent
)
3655 INT sbheight
= GetSystemMetrics( SM_CYHSCROLL
);
3656 INT sbwidth
= GetSystemMetrics( SM_CXVSCROLL
);
3657 HWND hwnd
= CreateWindowExA(0, "static", NULL
,
3658 WS_CHILD
| WS_VISIBLE
| WS_VSCROLL
| WS_HSCROLL
,
3659 10, 10, 200, 200, parent
, 0, 0, NULL
);
3660 ShowWindow( parent
, SW_SHOW
);
3661 UpdateWindow( parent
);
3663 /* test window too low for a horizontal scroll bar */
3664 nccalchelper( hwnd
, 100, sbheight
, &rc1
);
3665 ok( rc1
.bottom
- rc1
.top
== sbheight
, "Height should be %d size is %d,%d - %d,%d\n",
3666 sbheight
, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3668 /* test window just high enough for a horizontal scroll bar */
3669 nccalchelper( hwnd
, 100, sbheight
+ 1, &rc1
);
3670 ok( rc1
.bottom
- rc1
.top
== 1, "Height should be %d size is %d,%d - %d,%d\n",
3671 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3673 /* test window too narrow for a vertical scroll bar */
3674 nccalchelper( hwnd
, sbwidth
- 1, 100, &rc1
);
3675 ok( rc1
.right
- rc1
.left
== sbwidth
- 1 , "Width should be %d size is %d,%d - %d,%d\n",
3676 sbwidth
- 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3678 /* test window just wide enough for a vertical scroll bar */
3679 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
3680 ok( rc1
.right
- rc1
.left
== 0, "Width should be %d size is %d,%d - %d,%d\n",
3681 0, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3683 /* same test, but with client edge: not enough width */
3684 SetWindowLongA( hwnd
, GWL_EXSTYLE
, WS_EX_CLIENTEDGE
| GetWindowLongA( hwnd
, GWL_EXSTYLE
));
3685 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
3686 ok( rc1
.right
- rc1
.left
== sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
),
3687 "Width should be %d size is %d,%d - %d,%d\n",
3688 sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
), rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3690 DestroyWindow( hwnd
);
3693 static void test_SetParent(void)
3695 HWND desktop
= GetDesktopWindow();
3697 HWND ret
, parent
, child1
, child2
, child3
, child4
, sibling
, popup
;
3700 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
3701 100, 100, 200, 200, 0, 0, 0, NULL
);
3702 assert(parent
!= 0);
3703 child1
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
3704 0, 0, 50, 50, parent
, 0, 0, NULL
);
3705 assert(child1
!= 0);
3706 child2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
3707 0, 0, 50, 50, child1
, 0, 0, NULL
);
3708 assert(child2
!= 0);
3709 child3
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
3710 0, 0, 50, 50, child2
, 0, 0, NULL
);
3711 assert(child3
!= 0);
3712 child4
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
3713 0, 0, 50, 50, child3
, 0, 0, NULL
);
3714 assert(child4
!= 0);
3716 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
3717 parent
, child1
, child2
, child3
, child4
);
3719 check_parents(parent
, desktop
, 0, 0, 0, parent
, parent
);
3720 check_parents(child1
, parent
, parent
, parent
, 0, parent
, parent
);
3721 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
3722 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
3723 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
3725 ok(!IsChild(desktop
, parent
), "wrong parent/child %p/%p\n", desktop
, parent
);
3726 ok(!IsChild(desktop
, child1
), "wrong parent/child %p/%p\n", desktop
, child1
);
3727 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
3728 ok(!IsChild(desktop
, child3
), "wrong parent/child %p/%p\n", desktop
, child3
);
3729 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
3731 ok(IsChild(parent
, child1
), "wrong parent/child %p/%p\n", parent
, child1
);
3732 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
3733 ok(!IsChild(parent
, child2
), "wrong parent/child %p/%p\n", parent
, child2
);
3734 ok(!IsChild(child1
, child2
), "wrong parent/child %p/%p\n", child1
, child2
);
3735 ok(!IsChild(parent
, child3
), "wrong parent/child %p/%p\n", parent
, child3
);
3736 ok(IsChild(child2
, child3
), "wrong parent/child %p/%p\n", child2
, child3
);
3737 ok(!IsChild(parent
, child4
), "wrong parent/child %p/%p\n", parent
, child4
);
3738 ok(!IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
3739 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
3741 if (!is_win9x
) /* Win9x doesn't survive this test */
3743 ok(!SetParent(parent
, child1
), "SetParent should fail\n");
3744 ok(!SetParent(child2
, child3
), "SetParent should fail\n");
3745 ok(SetParent(child1
, parent
) != 0, "SetParent should not fail\n");
3746 ret
= SetParent(parent
, child2
);
3747 todo_wine
ok( !ret
|| broken( ret
!= 0 ), "SetParent should fail\n");
3748 if (ret
) /* nt4, win2k */
3750 ret
= SetParent(parent
, child3
);
3751 ok(ret
!= 0, "SetParent should not fail\n");
3752 ret
= SetParent(child2
, parent
);
3753 ok(!ret
, "SetParent should fail\n");
3754 ret
= SetParent(parent
, child4
);
3755 ok(ret
!= 0, "SetParent should not fail\n");
3756 check_parents(parent
, child4
, child4
, 0, 0, child4
, parent
);
3757 check_parents(child1
, parent
, parent
, parent
, 0, child4
, parent
);
3758 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
3759 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
3760 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
3764 ret
= SetParent(parent
, child3
);
3765 ok(ret
!= 0, "SetParent should not fail\n");
3766 ret
= SetParent(child2
, parent
);
3767 ok(!ret
, "SetParent should fail\n");
3768 ret
= SetParent(parent
, child4
);
3769 ok(!ret
, "SetParent should fail\n");
3770 check_parents(parent
, child3
, child3
, 0, 0, child2
, parent
);
3771 check_parents(child1
, parent
, parent
, parent
, 0, child2
, parent
);
3772 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
3773 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
3774 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
3778 skip("Win9x/WinMe crash\n");
3780 hMenu
= CreateMenu();
3781 sibling
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
3782 100, 100, 200, 200, 0, hMenu
, 0, NULL
);
3783 assert(sibling
!= 0);
3785 ok(SetParent(sibling
, parent
) != 0, "SetParent should not fail\n");
3786 ok(GetMenu(sibling
) == hMenu
, "SetParent should not remove menu\n");
3788 ok(SetParent(parent
, desktop
) != 0, "SetParent should not fail\n");
3789 ok(SetParent(child4
, child3
) != 0, "SetParent should not fail\n");
3790 ok(SetParent(child3
, child2
) != 0, "SetParent should not fail\n");
3791 ok(SetParent(child2
, child1
) != 0, "SetParent should not fail\n");
3792 ok(!IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
3793 SetWindowLongW(child4
, GWL_STYLE
, WS_CHILD
);
3794 ok(IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
3795 ok(IsChild(child2
, child4
), "wrong parent/child %p/%p\n", child2
, child4
);
3796 ok(!IsChild(child1
, child4
), "wrong parent/child %p/%p\n", child1
, child4
);
3797 SetWindowLongW(child2
, GWL_STYLE
, WS_CHILD
);
3798 ok(IsChild(child1
, child4
), "wrong parent/child %p/%p\n", child1
, child4
);
3799 ok(IsChild(parent
, child4
), "wrong parent/child %p/%p\n", parent
, child4
);
3801 ok(DestroyWindow(parent
), "DestroyWindow() failed\n");
3803 ok(!IsWindow(parent
), "parent still exists\n");
3804 ok(!IsWindow(sibling
), "sibling still exists\n");
3805 ok(!IsWindow(child1
), "child1 still exists\n");
3806 ok(!IsWindow(child2
), "child2 still exists\n");
3807 ok(!IsWindow(child3
), "child3 still exists\n");
3808 ok(!IsWindow(child4
), "child4 still exists\n");
3810 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
3811 100, 100, 200, 200, 0, 0, 0, NULL
);
3812 assert(parent
!= 0);
3813 child1
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
3814 0, 0, 50, 50, parent
, 0, 0, NULL
);
3815 assert(child1
!= 0);
3816 popup
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
3817 0, 0, 50, 50, 0, 0, 0, NULL
);
3820 trace("parent %p, child %p, popup %p\n", parent
, child1
, popup
);
3822 check_parents(parent
, desktop
, 0, 0, 0, parent
, parent
);
3823 check_parents(child1
, parent
, parent
, parent
, 0, parent
, parent
);
3824 check_parents(popup
, desktop
, 0, 0, 0, popup
, popup
);
3826 SetActiveWindow(parent
);
3828 check_active_state(parent
, 0, parent
);
3830 ret
= SetParent(popup
, child1
);
3831 ok(ret
== desktop
, "expected %p, got %p\n", desktop
, ret
);
3832 check_parents(popup
, child1
, child1
, 0, 0, parent
, popup
);
3833 check_active_state(popup
, 0, popup
);
3835 SetActiveWindow(parent
);
3837 check_active_state(popup
, 0, popup
);
3839 EnableWindow(child1
, FALSE
);
3840 check_active_state(popup
, 0, popup
);
3842 check_active_state(parent
, 0, parent
);
3844 check_active_state(popup
, 0, popup
);
3845 EnableWindow(child1
, TRUE
);
3847 ShowWindow(child1
, SW_MINIMIZE
);
3849 check_active_state(parent
, 0, parent
);
3851 check_active_state(popup
, 0, popup
);
3852 ShowWindow(child1
, SW_HIDE
);
3854 SetActiveWindow(parent
);
3856 check_active_state(parent
, 0, parent
);
3858 bret
= SetForegroundWindow(popup
);
3859 ok(bret
, "SetForegroundWindow() failed\n");
3860 check_active_state(popup
, popup
, popup
);
3862 ShowWindow(parent
, SW_SHOW
);
3863 SetActiveWindow(popup
);
3864 ok(DestroyWindow(popup
), "DestroyWindow() failed\n");
3865 check_active_state(parent
, parent
, parent
);
3867 ok(DestroyWindow(parent
), "DestroyWindow() failed\n");
3869 ok(!IsWindow(parent
), "parent still exists\n");
3870 ok(!IsWindow(child1
), "child1 still exists\n");
3871 ok(!IsWindow(popup
), "popup still exists\n");
3874 static LRESULT WINAPI
StyleCheckProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3876 LPCREATESTRUCTA lpcs
;
3883 lpcs
= (LPCREATESTRUCTA
)lparam
;
3884 lpss
= lpcs
->lpCreateParams
;
3887 if ((lpcs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
3888 ((!(lpcs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
3889 (lpcs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
3890 ok(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
, "Window should have WS_EX_WINDOWEDGE style\n");
3892 ok(!(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3894 ok((lpss
->styleOld
& ~WS_EX_WINDOWEDGE
) == (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
),
3895 "Ex style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3896 lpss
->styleOld
, lpcs
->dwExStyle
);
3898 ok(lpss
->styleNew
== lpcs
->style
,
3899 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3900 lpss
->styleNew
, lpcs
->style
);
3904 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
3907 static ATOM atomStyleCheckClass
;
3909 static void register_style_check_class(void)
3917 GetModuleHandleA(NULL
),
3919 LoadCursorA(0, (LPCSTR
)IDC_ARROW
),
3920 (HBRUSH
)(COLOR_BTNFACE
+1),
3925 atomStyleCheckClass
= RegisterClassA(&wc
);
3926 assert(atomStyleCheckClass
);
3929 static void check_window_style(DWORD dwStyleIn
, DWORD dwExStyleIn
, DWORD dwStyleOut
, DWORD dwExStyleOut
)
3931 DWORD dwActualStyle
;
3932 DWORD dwActualExStyle
;
3935 HWND hwndParent
= NULL
;
3937 ss
.styleNew
= dwStyleIn
;
3938 ss
.styleOld
= dwExStyleIn
;
3940 if (dwStyleIn
& WS_CHILD
)
3942 hwndParent
= CreateWindowExA(0, (LPCSTR
)MAKEINTATOM(atomStyleCheckClass
), NULL
,
3943 WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
3946 hwnd
= CreateWindowExA(dwExStyleIn
, (LPCSTR
)MAKEINTATOM(atomStyleCheckClass
), NULL
,
3947 dwStyleIn
, 0, 0, 0, 0, hwndParent
, NULL
, NULL
, &ss
);
3950 flush_events( TRUE
);
3952 dwActualStyle
= GetWindowLongA(hwnd
, GWL_STYLE
);
3953 dwActualExStyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
3954 ok(dwActualStyle
== dwStyleOut
, "expected style %#x, got %#x\n", dwStyleOut
, dwActualStyle
);
3955 ok(dwActualExStyle
== dwExStyleOut
, "expected ex_style %#x, got %#x\n", dwExStyleOut
, dwActualExStyle
);
3957 /* try setting the styles explicitly */
3958 SetWindowLongA( hwnd
, GWL_EXSTYLE
, dwExStyleIn
);
3959 dwActualStyle
= GetWindowLongA(hwnd
, GWL_STYLE
);
3960 dwActualExStyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
3961 /* WS_EX_WINDOWEDGE can't always be changed */
3962 if (dwExStyleIn
& WS_EX_DLGMODALFRAME
)
3963 dwExStyleOut
= dwExStyleIn
| WS_EX_WINDOWEDGE
;
3964 else if ((dwActualStyle
& (WS_DLGFRAME
| WS_THICKFRAME
)) && !(dwExStyleIn
& WS_EX_STATICEDGE
))
3965 dwExStyleOut
= dwExStyleIn
| WS_EX_WINDOWEDGE
;
3967 dwExStyleOut
= dwExStyleIn
& ~WS_EX_WINDOWEDGE
;
3968 ok(dwActualStyle
== dwStyleOut
, "expected style %#x, got %#x\n", dwStyleOut
, dwActualStyle
);
3969 ok(dwActualExStyle
== dwExStyleOut
, "expected ex_style %#x, got %#x\n", dwExStyleOut
, dwActualExStyle
);
3971 SetWindowLongA( hwnd
, GWL_STYLE
, dwStyleIn
);
3972 dwActualStyle
= GetWindowLongA(hwnd
, GWL_STYLE
);
3973 dwActualExStyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
3974 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3975 if ((dwStyleIn
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
) dwStyleOut
= dwStyleIn
;
3976 else dwStyleOut
= dwStyleIn
| WS_CLIPSIBLINGS
;
3977 /* WS_EX_WINDOWEDGE can't always be changed */
3978 if (dwExStyleIn
& WS_EX_DLGMODALFRAME
)
3979 dwExStyleOut
= dwExStyleIn
| WS_EX_WINDOWEDGE
;
3980 else if ((dwActualStyle
& (WS_DLGFRAME
| WS_THICKFRAME
)) && !(dwExStyleIn
& WS_EX_STATICEDGE
))
3981 dwExStyleOut
= dwExStyleIn
| WS_EX_WINDOWEDGE
;
3983 dwExStyleOut
= dwExStyleIn
& ~WS_EX_WINDOWEDGE
;
3984 ok(dwActualStyle
== dwStyleOut
, "expected style %#x, got %#x\n", dwStyleOut
, dwActualStyle
);
3985 /* FIXME: Remove the condition below once Wine is fixed */
3986 if (dwActualExStyle
!= dwExStyleOut
)
3987 todo_wine
ok(dwActualExStyle
== dwExStyleOut
, "expected ex_style %#x, got %#x\n", dwExStyleOut
, dwActualExStyle
);
3989 ok(dwActualExStyle
== dwExStyleOut
, "expected ex_style %#x, got %#x\n", dwExStyleOut
, dwActualExStyle
);
3991 DestroyWindow(hwnd
);
3992 if (hwndParent
) DestroyWindow(hwndParent
);
3995 /* tests what window styles the window manager automatically adds */
3996 static void test_window_styles(void)
3998 register_style_check_class();
4000 check_window_style(0, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
4001 check_window_style(WS_DLGFRAME
, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
4002 check_window_style(WS_THICKFRAME
, 0, WS_THICKFRAME
|WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
4003 check_window_style(WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_STATICEDGE
);
4004 check_window_style(WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_THICKFRAME
|WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_STATICEDGE
);
4005 check_window_style(WS_OVERLAPPEDWINDOW
, 0, WS_CLIPSIBLINGS
|WS_OVERLAPPEDWINDOW
, WS_EX_WINDOWEDGE
);
4006 check_window_style(WS_CHILD
, 0, WS_CHILD
, 0);
4007 check_window_style(WS_CHILD
|WS_DLGFRAME
, 0, WS_CHILD
|WS_DLGFRAME
, WS_EX_WINDOWEDGE
);
4008 check_window_style(WS_CHILD
|WS_THICKFRAME
, 0, WS_CHILD
|WS_THICKFRAME
, WS_EX_WINDOWEDGE
);
4009 check_window_style(WS_CHILD
|WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_DLGFRAME
, WS_EX_STATICEDGE
);
4010 check_window_style(WS_CHILD
|WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_THICKFRAME
, WS_EX_STATICEDGE
);
4011 check_window_style(WS_CHILD
|WS_CAPTION
, 0, WS_CHILD
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
4012 check_window_style(WS_CHILD
|WS_CAPTION
|WS_SYSMENU
, 0, WS_CHILD
|WS_CAPTION
|WS_SYSMENU
, WS_EX_WINDOWEDGE
);
4013 check_window_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
4014 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
, WS_CHILD
, WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
4015 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
|WS_EX_STATICEDGE
, WS_CHILD
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
4016 check_window_style(WS_CHILD
|WS_POPUP
, 0, WS_CHILD
|WS_POPUP
|WS_CLIPSIBLINGS
, 0);
4017 check_window_style(WS_CHILD
|WS_POPUP
|WS_DLGFRAME
, 0, WS_CHILD
|WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4018 check_window_style(WS_CHILD
|WS_POPUP
|WS_THICKFRAME
, 0, WS_CHILD
|WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4019 check_window_style(WS_CHILD
|WS_POPUP
|WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
);
4020 check_window_style(WS_CHILD
|WS_POPUP
|WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
);
4021 check_window_style(WS_CHILD
|WS_POPUP
, WS_EX_APPWINDOW
, WS_CHILD
|WS_POPUP
|WS_CLIPSIBLINGS
, WS_EX_APPWINDOW
);
4022 check_window_style(WS_CHILD
|WS_POPUP
, WS_EX_WINDOWEDGE
, WS_CHILD
|WS_POPUP
|WS_CLIPSIBLINGS
, 0);
4023 check_window_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
4024 check_window_style(0, WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_TOOLWINDOW
);
4025 check_window_style(WS_POPUP
, 0, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
4026 check_window_style(WS_POPUP
, WS_EX_WINDOWEDGE
, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
4027 check_window_style(WS_POPUP
|WS_DLGFRAME
, 0, WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4028 check_window_style(WS_POPUP
|WS_THICKFRAME
, 0, WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4029 check_window_style(WS_POPUP
|WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
);
4030 check_window_style(WS_POPUP
|WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
);
4031 check_window_style(WS_CAPTION
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
);
4032 check_window_style(0, WS_EX_APPWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_APPWINDOW
|WS_EX_WINDOWEDGE
);
4034 if (pGetLayeredWindowAttributes
)
4036 check_window_style(0, WS_EX_LAYERED
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_LAYERED
|WS_EX_WINDOWEDGE
);
4037 check_window_style(0, WS_EX_LAYERED
|WS_EX_TRANSPARENT
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_LAYERED
|WS_EX_TRANSPARENT
|WS_EX_WINDOWEDGE
);
4038 check_window_style(0, WS_EX_LAYERED
|WS_EX_TRANSPARENT
|WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
,
4039 WS_EX_LAYERED
|WS_EX_TRANSPARENT
|WS_EX_TOOLWINDOW
|WS_EX_WINDOWEDGE
);
4043 static INT_PTR WINAPI
empty_dlg_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4048 static void check_dialog_style(DWORD style_in
, DWORD ex_style_in
, DWORD style_out
, DWORD ex_style_out
)
4058 DWORD style
, ex_style
;
4059 HWND hwnd
, parent
= 0;
4061 if (style_in
& WS_CHILD
)
4062 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
4063 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
4065 dlg_data
.dt
.style
= style_in
;
4066 dlg_data
.dt
.dwExtendedStyle
= ex_style_in
;
4067 dlg_data
.dt
.cdit
= 0;
4070 dlg_data
.dt
.cx
= 100;
4071 dlg_data
.dt
.cy
= 100;
4072 dlg_data
.menu_name
= 0;
4073 dlg_data
.class_id
= 0;
4074 dlg_data
.class_atom
= 0;
4075 dlg_data
.caption
[0] = 0;
4077 hwnd
= CreateDialogIndirectParamA(GetModuleHandleA(NULL
), &dlg_data
.dt
, parent
, empty_dlg_proc
, 0);
4078 ok(hwnd
!= 0, "dialog creation failed, style %#x, exstyle %#x\n", style_in
, ex_style_in
);
4080 flush_events( TRUE
);
4082 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4083 ex_style
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
4084 ok(style
== (style_out
| DS_3DLOOK
), "got %#x\n", style
);
4085 ok(ex_style
== ex_style_out
, "expected ex_style %#x, got %#x\n", ex_style_out
, ex_style
);
4087 /* try setting the styles explicitly */
4088 SetWindowLongA(hwnd
, GWL_EXSTYLE
, ex_style_in
);
4089 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4090 ex_style
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
4091 ok(style
== (style_out
| DS_3DLOOK
), "got %#x\n", style
);
4092 /* WS_EX_WINDOWEDGE can't always be changed */
4093 if (ex_style_in
& WS_EX_DLGMODALFRAME
)
4094 ex_style_out
= ex_style_in
| WS_EX_WINDOWEDGE
;
4095 else if ((style
& (WS_DLGFRAME
| WS_THICKFRAME
)) && !(ex_style_in
& WS_EX_STATICEDGE
))
4096 ex_style_out
= ex_style_in
| WS_EX_WINDOWEDGE
;
4098 ex_style_out
= ex_style_in
& ~WS_EX_WINDOWEDGE
;
4099 ok(ex_style
== ex_style_out
, "expected ex_style %#x, got %#x\n", ex_style_out
, ex_style
);
4101 SetWindowLongA(hwnd
, GWL_STYLE
, style_in
);
4102 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4103 ex_style
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
4104 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
4105 if ((style_in
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
) style_out
= style_in
;
4106 else style_out
= style_in
| WS_CLIPSIBLINGS
;
4107 ok(style
== style_out
, "expected style %#x, got %#x\n", style_out
, style
);
4108 /* WS_EX_WINDOWEDGE can't always be changed */
4109 if (ex_style_in
& WS_EX_DLGMODALFRAME
)
4110 ex_style_out
= ex_style_in
| WS_EX_WINDOWEDGE
;
4111 else if ((style
& (WS_DLGFRAME
| WS_THICKFRAME
)) && !(ex_style_in
& WS_EX_STATICEDGE
))
4112 ex_style_out
= ex_style_in
| WS_EX_WINDOWEDGE
;
4114 ex_style_out
= ex_style_in
& ~WS_EX_WINDOWEDGE
;
4115 /* FIXME: Remove the condition below once Wine is fixed */
4116 if (ex_style
!= ex_style_out
)
4117 todo_wine
ok(ex_style
== ex_style_out
, "expected ex_style %#x, got %#x\n", ex_style_out
, ex_style
);
4119 ok(ex_style
== ex_style_out
, "expected ex_style %#x, got %#x\n", ex_style_out
, ex_style
);
4121 DestroyWindow(hwnd
);
4122 DestroyWindow(parent
);
4125 static void test_dialog_styles(void)
4127 check_dialog_style(0, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4128 check_dialog_style(WS_DLGFRAME
, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4129 check_dialog_style(WS_THICKFRAME
, 0, WS_THICKFRAME
|WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4130 check_dialog_style(WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_STATICEDGE
|WS_EX_CONTROLPARENT
);
4131 check_dialog_style(WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_THICKFRAME
|WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_STATICEDGE
|WS_EX_CONTROLPARENT
);
4132 check_dialog_style(DS_CONTROL
, 0, WS_CLIPSIBLINGS
|WS_CAPTION
|DS_CONTROL
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4133 check_dialog_style(WS_CAPTION
, 0, WS_CAPTION
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4134 check_dialog_style(WS_BORDER
, 0, WS_CAPTION
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4135 check_dialog_style(WS_DLGFRAME
, 0, WS_CAPTION
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4136 check_dialog_style(WS_BORDER
|DS_CONTROL
, 0, WS_CAPTION
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4137 check_dialog_style(WS_DLGFRAME
|DS_CONTROL
, 0, WS_CAPTION
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4138 check_dialog_style(WS_CAPTION
|WS_SYSMENU
, 0, WS_CAPTION
|WS_SYSMENU
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4139 check_dialog_style(WS_SYSMENU
, 0, WS_CAPTION
|WS_SYSMENU
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4140 check_dialog_style(WS_CAPTION
|DS_CONTROL
, 0, WS_CAPTION
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4141 check_dialog_style(WS_SYSMENU
|DS_CONTROL
, 0, WS_CAPTION
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4142 check_dialog_style(WS_CAPTION
|WS_SYSMENU
|DS_CONTROL
, 0, WS_CAPTION
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4143 check_dialog_style(WS_OVERLAPPEDWINDOW
, 0, WS_CLIPSIBLINGS
|WS_OVERLAPPEDWINDOW
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4144 check_dialog_style(WS_CHILD
, 0, WS_CHILD
, 0);
4145 check_dialog_style(WS_CHILD
|WS_DLGFRAME
, 0, WS_CHILD
|WS_DLGFRAME
, WS_EX_WINDOWEDGE
);
4146 check_dialog_style(WS_CHILD
|WS_THICKFRAME
, 0, WS_CHILD
|WS_THICKFRAME
, WS_EX_WINDOWEDGE
);
4147 check_dialog_style(WS_CHILD
|WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_DLGFRAME
, WS_EX_STATICEDGE
);
4148 check_dialog_style(WS_CHILD
|WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_THICKFRAME
, WS_EX_STATICEDGE
);
4149 check_dialog_style(WS_CHILD
|DS_CONTROL
, 0, WS_CHILD
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4150 check_dialog_style(WS_CHILD
|WS_CAPTION
, 0, WS_CHILD
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
4151 check_dialog_style(WS_CHILD
|WS_BORDER
, 0, WS_CHILD
|WS_BORDER
, 0);
4152 check_dialog_style(WS_CHILD
|WS_DLGFRAME
, 0, WS_CHILD
|WS_DLGFRAME
, WS_EX_WINDOWEDGE
);
4153 check_dialog_style(WS_CHILD
|WS_BORDER
|DS_CONTROL
, 0, WS_CHILD
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4154 check_dialog_style(WS_CHILD
|WS_DLGFRAME
|DS_CONTROL
, 0, WS_CHILD
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4155 check_dialog_style(WS_CHILD
|WS_CAPTION
|WS_SYSMENU
, 0, WS_CHILD
|WS_CAPTION
|WS_SYSMENU
, WS_EX_WINDOWEDGE
);
4156 check_dialog_style(WS_CHILD
|WS_SYSMENU
, 0, WS_CHILD
|WS_SYSMENU
, 0);
4157 check_dialog_style(WS_CHILD
|WS_CAPTION
|DS_CONTROL
, 0, WS_CHILD
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4158 check_dialog_style(WS_CHILD
|WS_SYSMENU
|DS_CONTROL
, 0, WS_CHILD
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4159 check_dialog_style(WS_CHILD
|WS_CAPTION
|WS_SYSMENU
|DS_CONTROL
, 0, WS_CHILD
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4160 check_dialog_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
4161 check_dialog_style(WS_CHILD
, WS_EX_DLGMODALFRAME
, WS_CHILD
, WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
4162 check_dialog_style(WS_CHILD
, WS_EX_DLGMODALFRAME
|WS_EX_STATICEDGE
, WS_CHILD
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
4163 check_dialog_style(WS_CHILD
|WS_POPUP
, 0, WS_CHILD
|WS_POPUP
|WS_CLIPSIBLINGS
, 0);
4164 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_DLGFRAME
, 0, WS_CHILD
|WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4165 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_THICKFRAME
, 0, WS_CHILD
|WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4166 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
);
4167 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_CHILD
|WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
);
4168 check_dialog_style(WS_CHILD
|WS_POPUP
|DS_CONTROL
, 0, WS_CHILD
|WS_POPUP
|WS_CLIPSIBLINGS
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4169 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_CAPTION
, 0, WS_CHILD
|WS_POPUP
|WS_CAPTION
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4170 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_BORDER
, 0, WS_CHILD
|WS_POPUP
|WS_BORDER
|WS_CLIPSIBLINGS
, 0);
4171 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_DLGFRAME
, 0, WS_CHILD
|WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
);
4172 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_BORDER
|DS_CONTROL
, 0, WS_CHILD
|WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4173 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_DLGFRAME
|DS_CONTROL
, 0, WS_CHILD
|WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4174 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
);
4175 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_SYSMENU
, 0, WS_CHILD
|WS_POPUP
|WS_SYSMENU
|WS_CLIPSIBLINGS
, 0);
4176 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_CAPTION
|DS_CONTROL
, 0, WS_CHILD
|WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4177 check_dialog_style(WS_CHILD
|WS_POPUP
|WS_SYSMENU
|DS_CONTROL
, 0, WS_CHILD
|WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4178 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
);
4179 check_dialog_style(WS_CHILD
|WS_POPUP
, WS_EX_APPWINDOW
, WS_CHILD
|WS_POPUP
|WS_CLIPSIBLINGS
, WS_EX_APPWINDOW
);
4180 check_dialog_style(WS_CHILD
|WS_POPUP
, WS_EX_WINDOWEDGE
, WS_CHILD
|WS_POPUP
|WS_CLIPSIBLINGS
, 0);
4181 check_dialog_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
4182 check_dialog_style(0, WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_TOOLWINDOW
|WS_EX_CONTROLPARENT
);
4183 check_dialog_style(WS_POPUP
, 0, WS_POPUP
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4184 check_dialog_style(WS_POPUP
, WS_EX_WINDOWEDGE
, WS_POPUP
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4185 check_dialog_style(WS_POPUP
|WS_DLGFRAME
, 0, WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4186 check_dialog_style(WS_POPUP
|WS_THICKFRAME
, 0, WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4187 check_dialog_style(WS_POPUP
|WS_DLGFRAME
, WS_EX_STATICEDGE
, WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
|WS_EX_CONTROLPARENT
);
4188 check_dialog_style(WS_POPUP
|WS_THICKFRAME
, WS_EX_STATICEDGE
, WS_POPUP
|WS_THICKFRAME
|WS_CLIPSIBLINGS
, WS_EX_STATICEDGE
|WS_EX_CONTROLPARENT
);
4189 check_dialog_style(WS_POPUP
|DS_CONTROL
, 0, WS_POPUP
|WS_CLIPSIBLINGS
|DS_CONTROL
, WS_EX_CONTROLPARENT
);
4190 check_dialog_style(WS_POPUP
|WS_CAPTION
, 0, WS_POPUP
|WS_CAPTION
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4191 check_dialog_style(WS_POPUP
|WS_BORDER
, 0, WS_POPUP
|WS_BORDER
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4192 check_dialog_style(WS_POPUP
|WS_DLGFRAME
, 0, WS_POPUP
|WS_DLGFRAME
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4193 check_dialog_style(WS_POPUP
|WS_BORDER
|DS_CONTROL
, 0, WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4194 check_dialog_style(WS_POPUP
|WS_DLGFRAME
|DS_CONTROL
, 0, WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4195 check_dialog_style(WS_POPUP
|WS_CAPTION
|WS_SYSMENU
, 0, WS_POPUP
|WS_CAPTION
|WS_SYSMENU
|WS_CLIPSIBLINGS
, WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4196 check_dialog_style(WS_POPUP
|WS_SYSMENU
, 0, WS_POPUP
|WS_SYSMENU
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4197 check_dialog_style(WS_POPUP
|WS_CAPTION
|DS_CONTROL
, 0, WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4198 check_dialog_style(WS_POPUP
|WS_SYSMENU
|DS_CONTROL
, 0, WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4199 check_dialog_style(WS_POPUP
|WS_CAPTION
|WS_SYSMENU
|DS_CONTROL
, 0, WS_POPUP
|DS_CONTROL
|WS_CLIPSIBLINGS
, WS_EX_CONTROLPARENT
);
4200 check_dialog_style(WS_CAPTION
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4201 check_dialog_style(0, WS_EX_APPWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_APPWINDOW
|WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4203 if (pGetLayeredWindowAttributes
)
4205 check_dialog_style(0, WS_EX_LAYERED
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_LAYERED
|WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4206 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
);
4207 check_dialog_style(0, WS_EX_LAYERED
|WS_EX_TRANSPARENT
|WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
,
4208 WS_EX_LAYERED
|WS_EX_TRANSPARENT
|WS_EX_TOOLWINDOW
|WS_EX_WINDOWEDGE
|WS_EX_CONTROLPARENT
);
4212 static void test_scrollwindow( HWND hwnd
)
4218 ShowWindow( hwnd
, SW_SHOW
);
4219 UpdateWindow( hwnd
);
4220 flush_events( TRUE
);
4221 GetClientRect( hwnd
, &rc
);
4223 /* test ScrollWindow(Ex) with no clip rectangle */
4224 /* paint the lower half of the window black */
4226 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
4227 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
4228 /* paint the upper half of the window white */
4229 rc2
.bottom
= rc2
.top
;
4231 FillRect( hdc
, &rc2
, GetStockObject(WHITE_BRUSH
));
4232 /* scroll lower half up */
4234 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
4235 ScrollWindowEx( hwnd
, 0, - rc2
.top
, &rc2
, NULL
, NULL
, NULL
, SW_ERASE
);
4236 flush_events(FALSE
);
4237 /* expected: black should have scrolled to the upper half */
4238 colr
= GetPixel( hdc
, (rc2
.left
+rc2
.right
)/ 2, rc2
.bottom
/ 4 );
4239 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
4240 /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
4241 /* paint the lower half of the window black */
4243 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
4244 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
4245 /* paint the upper half of the window white */
4246 rc2
.bottom
= rc2
.top
;
4248 FillRect( hdc
, &rc2
, GetStockObject(WHITE_BRUSH
));
4249 /* scroll lower half up */
4251 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
4253 rc3
.left
= rc3
.right
/ 4;
4254 rc3
.right
-= rc3
.right
/ 4;
4255 ScrollWindowEx( hwnd
, 0, - rc2
.top
, &rc2
, &rc3
, NULL
, NULL
, SW_ERASE
);
4256 flush_events(FALSE
);
4257 /* expected: black should have scrolled to the upper half */
4258 colr
= GetPixel( hdc
, (rc2
.left
+rc2
.right
)/ 2, rc2
.bottom
/ 4 );
4259 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
4262 ReleaseDC( hwnd
, hdc
);
4265 static void test_scrollvalidate( HWND parent
)
4268 HRGN hrgn
=CreateRectRgn(0,0,0,0);
4269 HRGN exprgn
, tmprgn
, clipping
;
4270 RECT rc
, rcu
, cliprc
;
4271 /* create two overlapping child windows. The visual region
4272 * of hwnd1 is clipped by the overlapping part of
4273 * hwnd2 because of the WS_CLIPSIBLING style */
4276 clipping
= CreateRectRgn(0,0,0,0);
4277 tmprgn
= CreateRectRgn(0,0,0,0);
4278 exprgn
= CreateRectRgn(0,0,0,0);
4279 hwnd2
= CreateWindowExA(0, "static", NULL
,
4280 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
4281 75, 30, 100, 100, parent
, 0, 0, NULL
);
4282 hwnd1
= CreateWindowExA(0, "static", NULL
,
4283 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
4284 25, 50, 100, 100, parent
, 0, 0, NULL
);
4285 ShowWindow( parent
, SW_SHOW
);
4286 UpdateWindow( parent
);
4287 GetClientRect( hwnd1
, &rc
);
4289 SetRectRgn( clipping
, 10, 10, 90, 90);
4290 hdc
= GetDC( hwnd1
);
4291 /* for a visual touch */
4292 TextOutA( hdc
, 0,10, "0123456789", 10);
4293 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
4294 if (winetest_debug
> 0) dump_region(hrgn
);
4295 /* create a region with what is expected */
4296 SetRectRgn( exprgn
, 39,0,49,74);
4297 SetRectRgn( tmprgn
, 88,79,98,93);
4298 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
4299 SetRectRgn( tmprgn
, 0,93,98,98);
4300 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
4301 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
4302 trace("update rect is %d,%d - %d,%d\n",
4303 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
4304 /* now with clipping region */
4305 SelectClipRgn( hdc
, clipping
);
4306 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
4307 if (winetest_debug
> 0) dump_region(hrgn
);
4308 /* create a region with what is expected */
4309 SetRectRgn( exprgn
, 39,10,49,74);
4310 SetRectRgn( tmprgn
, 80,79,90,85);
4311 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
4312 SetRectRgn( tmprgn
, 10,85,90,90);
4313 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
4314 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
4315 trace("update rect is %d,%d - %d,%d\n",
4316 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
4317 ReleaseDC( hwnd1
, hdc
);
4319 /* test scrolling a window with an update region */
4320 DestroyWindow( hwnd2
);
4321 ValidateRect( hwnd1
, NULL
);
4322 SetRect( &rc
, 40,40, 50,50);
4323 InvalidateRect( hwnd1
, &rc
, 1);
4324 GetClientRect( hwnd1
, &rc
);
4326 ScrollWindowEx( hwnd1
, -10, 0, &rc
, &cliprc
, hrgn
, &rcu
,
4327 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
4328 if (winetest_debug
> 0) dump_region(hrgn
);
4329 SetRectRgn( exprgn
, 88,0,98,98);
4330 SetRectRgn( tmprgn
, 30, 40, 50, 50);
4331 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
4332 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
4334 /* clear an update region */
4335 UpdateWindow( hwnd1
);
4337 SetRect( &rc
, 0,40, 100,60);
4338 SetRect( &cliprc
, 0,0, 100,100);
4339 ScrollWindowEx( hwnd1
, 0, -25, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
4340 if (winetest_debug
> 0) dump_region( hrgn
);
4341 SetRectRgn( exprgn
, 0, 40, 98, 60 );
4342 ok( EqualRgn( exprgn
, hrgn
), "wrong update region in excessive scroll\n");
4344 /* now test ScrollWindowEx with a combination of
4345 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
4346 /* make hwnd2 the child of hwnd1 */
4347 hwnd2
= CreateWindowExA(0, "static", NULL
,
4348 WS_CHILD
| WS_VISIBLE
| WS_BORDER
,
4349 50, 50, 100, 100, hwnd1
, 0, 0, NULL
);
4350 SetWindowLongA( hwnd1
, GWL_STYLE
, GetWindowLongA( hwnd1
, GWL_STYLE
) & ~WS_CLIPSIBLINGS
);
4351 GetClientRect( hwnd1
, &rc
);
4354 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
4355 SetWindowLongA( hwnd1
, GWL_STYLE
, GetWindowLongA( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
4356 ValidateRect( hwnd1
, NULL
);
4357 ValidateRect( hwnd2
, NULL
);
4358 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
,
4359 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
4360 if (winetest_debug
> 0) dump_region(hrgn
);
4361 SetRectRgn( exprgn
, 88,0,98,88);
4362 SetRectRgn( tmprgn
, 0,88,98,98);
4363 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
4364 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
4366 /* SW_SCROLLCHILDREN */
4367 SetWindowLongA( hwnd1
, GWL_STYLE
, GetWindowLongA( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
4368 ValidateRect( hwnd1
, NULL
);
4369 ValidateRect( hwnd2
, NULL
);
4370 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_SCROLLCHILDREN
| SW_INVALIDATE
);
4371 if (winetest_debug
> 0) dump_region(hrgn
);
4372 /* expected region is the same as in previous test */
4373 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
4375 /* no SW_SCROLLCHILDREN */
4376 SetWindowLongA( hwnd1
, GWL_STYLE
, GetWindowLongA( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
4377 ValidateRect( hwnd1
, NULL
);
4378 ValidateRect( hwnd2
, NULL
);
4379 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
4380 if (winetest_debug
> 0) dump_region(hrgn
);
4381 /* expected region is the same as in previous test */
4382 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
4384 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
4385 SetWindowLongA( hwnd1
, GWL_STYLE
, GetWindowLongA( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
4386 ValidateRect( hwnd1
, NULL
);
4387 ValidateRect( hwnd2
, NULL
);
4388 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
4389 if (winetest_debug
> 0) dump_region(hrgn
);
4390 SetRectRgn( exprgn
, 88,0,98,20);
4391 SetRectRgn( tmprgn
, 20,20,98,30);
4392 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
4393 SetRectRgn( tmprgn
, 20,30,30,88);
4394 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
4395 SetRectRgn( tmprgn
, 0,88,30,98);
4396 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
4397 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
4400 DeleteObject( hrgn
);
4401 DeleteObject( exprgn
);
4402 DeleteObject( tmprgn
);
4403 DestroyWindow( hwnd1
);
4404 DestroyWindow( hwnd2
);
4407 /* couple of tests of return values of scrollbar functions
4408 * called on a scrollbarless window */
4409 static void test_scroll(void)
4414 HWND hwnd
= CreateWindowExA(0, "Static", "Wine test window",
4415 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_POPUP
,
4416 100, 100, 200, 200, 0, 0, 0, NULL
);
4418 ret
= GetScrollRange( hwnd
, SB_HORZ
, &min
, &max
);
4419 if (!ret
) /* win9x */
4421 win_skip( "GetScrollRange doesn't work\n" );
4422 DestroyWindow( hwnd
);
4425 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
4426 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
4427 si
.cbSize
= sizeof( si
);
4428 si
.fMask
= SIF_PAGE
;
4429 si
.nPage
= 0xdeadbeef;
4430 ret
= GetScrollInfo( hwnd
, SB_HORZ
, &si
);
4431 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
4432 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
4434 ret
= GetScrollRange( hwnd
, SB_VERT
, &min
, &max
);
4435 ok( ret
, "GetScrollRange returns FALSE\n");
4436 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
4437 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
4438 si
.cbSize
= sizeof( si
);
4439 si
.fMask
= SIF_PAGE
;
4440 si
.nPage
= 0xdeadbeef;
4441 ret
= GetScrollInfo( hwnd
, SB_VERT
, &si
);
4442 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
4443 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
4445 DestroyWindow( hwnd
);
4448 static void test_scrolldc( HWND parent
)
4451 HRGN exprgn
, tmprgn
, hrgn
;
4452 RECT rc
, rc2
, rcu
, cliprc
;
4456 hrgn
= CreateRectRgn(0,0,0,0);
4457 tmprgn
= CreateRectRgn(0,0,0,0);
4458 exprgn
= CreateRectRgn(0,0,0,0);
4460 hwnd1
= CreateWindowExA(0, "static", NULL
,
4461 WS_CHILD
| WS_VISIBLE
,
4462 25, 50, 100, 100, parent
, 0, 0, NULL
);
4463 ShowWindow( parent
, SW_SHOW
);
4464 UpdateWindow( parent
);
4465 flush_events( TRUE
);
4466 GetClientRect( hwnd1
, &rc
);
4467 hdc
= GetDC( hwnd1
);
4468 /* paint the upper half of the window black */
4470 rc2
.bottom
= ( rc
.top
+ rc
.bottom
) /2;
4471 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
4472 /* clip region is the lower half */
4474 cliprc
.top
= (rc
.top
+ rc
.bottom
) /2;
4475 /* test whether scrolled pixels are properly clipped */
4476 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
4477 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
4478 /* this scroll should not cause any visible changes */
4479 ScrollDC( hdc
, 5, -20, &rc
, &cliprc
, hrgn
, &rcu
);
4480 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
4481 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
4482 /* test with NULL clip rect */
4483 ScrollDC( hdc
, 20, -20, &rc
, NULL
, hrgn
, &rcu
);
4484 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
4485 trace("update rect: %d,%d - %d,%d\n",
4486 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
4487 if (winetest_debug
> 0) dump_region(hrgn
);
4488 SetRect(&rc2
, 0, 0, 100, 100);
4489 ok(EqualRect(&rcu
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
4490 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4492 SetRectRgn( exprgn
, 0, 0, 20, 80);
4493 SetRectRgn( tmprgn
, 0, 80, 100, 100);
4494 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
4495 if (winetest_debug
> 0) dump_region(exprgn
);
4496 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
4497 /* test clip rect > scroll rect */
4498 FillRect( hdc
, &rc
, GetStockObject(WHITE_BRUSH
));
4500 InflateRect( &rc2
, -(rc
.right
-rc
.left
)/4, -(rc
.bottom
-rc
.top
)/4);
4501 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
4502 ScrollDC( hdc
, 10, 10, &rc2
, &rc
, hrgn
, &rcu
);
4503 SetRectRgn( exprgn
, 25, 25, 75, 35);
4504 SetRectRgn( tmprgn
, 25, 35, 35, 75);
4505 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
4506 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
4507 trace("update rect: %d,%d - %d,%d\n",
4508 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
4509 if (winetest_debug
> 0) dump_region(hrgn
);
4513 DeleteObject(exprgn
);
4514 DeleteObject(tmprgn
);
4515 DestroyWindow(hwnd1
);
4518 static void test_params(void)
4523 ok(!IsWindow(0), "IsWindow(0)\n");
4524 ok(!IsWindow(HWND_BROADCAST
), "IsWindow(HWND_BROADCAST)\n");
4525 ok(!IsWindow(HWND_TOPMOST
), "IsWindow(HWND_TOPMOST)\n");
4527 /* Just a param check */
4528 if (pGetMonitorInfoA
)
4530 SetLastError(0xdeadbeef);
4531 rc
= GetWindowTextA(hwndMain2
, NULL
, 1024);
4532 ok( rc
==0, "GetWindowText: rc=%d err=%d\n",rc
,GetLastError());
4536 /* Skips actually on Win95 and NT4 */
4537 win_skip("Test would crash on Win95\n");
4540 SetLastError(0xdeadbeef);
4541 hwnd
=CreateWindowA("LISTBOX", "TestList",
4542 (LBS_STANDARD
& ~LBS_SORT
),
4544 NULL
, (HMENU
)1, NULL
, 0);
4546 ok(!hwnd
|| broken(hwnd
!= NULL
), /* w2k3 sp2 */
4547 "CreateWindow with invalid menu handle should fail\n");
4549 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
|| /* NT */
4550 GetLastError() == 0xdeadbeef, /* Win9x */
4551 "wrong last error value %d\n", GetLastError());
4554 static void test_AWRwindow(LPCSTR
class, LONG style
, LONG exStyle
, BOOL menu
)
4558 hwnd
= CreateWindowExA(exStyle
, class, class, style
,
4565 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style
, exStyle
);
4568 ShowWindow(hwnd
, SW_SHOW
);
4570 test_nonclient_area(hwnd
);
4573 DestroyWindow(hwnd
);
4576 static BOOL
AWR_init(void)
4580 class.style
= CS_HREDRAW
| CS_VREDRAW
;
4581 class.lpfnWndProc
= DefWindowProcA
;
4582 class.cbClsExtra
= 0;
4583 class.cbWndExtra
= 0;
4584 class.hInstance
= 0;
4585 class.hIcon
= LoadIconA(0, (LPCSTR
)IDI_APPLICATION
);
4586 class.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
4587 class.hbrBackground
= 0;
4588 class.lpszMenuName
= 0;
4589 class.lpszClassName
= szAWRClass
;
4591 if (!RegisterClassA(&class)) {
4592 ok(FALSE
, "RegisterClass failed\n");
4596 hmenu
= CreateMenu();
4599 ok(hmenu
!= 0, "Failed to create menu\n");
4600 ok(AppendMenuA(hmenu
, MF_STRING
, 1, "Test!"), "Failed to create menu item\n");
4606 static void test_AWR_window_size(BOOL menu
)
4610 WS_MAXIMIZE
, WS_BORDER
, WS_DLGFRAME
,
4613 WS_MINIMIZEBOX
, WS_MAXIMIZEBOX
,
4614 WS_HSCROLL
, WS_VSCROLL
4618 WS_EX_TOOLWINDOW
, WS_EX_WINDOWEDGE
,
4621 /* These styles have problems on (at least) WinXP (SP2) and Wine */
4622 WS_EX_DLGMODALFRAME
,
4629 /* A exhaustive check of all the styles takes too long
4630 * so just do a (hopefully representative) sample
4632 for (i
= 0; i
< COUNTOF(styles
); ++i
)
4633 test_AWRwindow(szAWRClass
, styles
[i
], 0, menu
);
4634 for (i
= 0; i
< COUNTOF(exStyles
); ++i
) {
4635 test_AWRwindow(szAWRClass
, WS_POPUP
, exStyles
[i
], menu
);
4636 test_AWRwindow(szAWRClass
, WS_THICKFRAME
, exStyles
[i
], menu
);
4641 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
4643 static void test_AdjustWindowRect(void)
4648 SHOWSYSMETRIC(SM_CYCAPTION
);
4649 SHOWSYSMETRIC(SM_CYSMCAPTION
);
4650 SHOWSYSMETRIC(SM_CYMENU
);
4651 SHOWSYSMETRIC(SM_CXEDGE
);
4652 SHOWSYSMETRIC(SM_CYEDGE
);
4653 SHOWSYSMETRIC(SM_CXVSCROLL
);
4654 SHOWSYSMETRIC(SM_CYHSCROLL
);
4655 SHOWSYSMETRIC(SM_CXFRAME
);
4656 SHOWSYSMETRIC(SM_CYFRAME
);
4657 SHOWSYSMETRIC(SM_CXDLGFRAME
);
4658 SHOWSYSMETRIC(SM_CYDLGFRAME
);
4659 SHOWSYSMETRIC(SM_CXBORDER
);
4660 SHOWSYSMETRIC(SM_CYBORDER
);
4662 test_AWR_window_size(FALSE
);
4663 test_AWR_window_size(TRUE
);
4667 #undef SHOWSYSMETRIC
4670 /* Global variables to trigger exit from loop */
4671 static int redrawComplete
, WMPAINT_count
;
4673 static LRESULT WINAPI
redraw_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4678 trace("doing WM_PAINT %d\n", WMPAINT_count
);
4680 if (WMPAINT_count
> 10 && redrawComplete
== 0) {
4682 BeginPaint(hwnd
, &ps
);
4683 EndPaint(hwnd
, &ps
);
4688 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
4691 /* Ensure we exit from RedrawNow regardless of invalidated area */
4692 static void test_redrawnow(void)
4697 cls
.style
= CS_DBLCLKS
;
4698 cls
.lpfnWndProc
= redraw_window_procA
;
4701 cls
.hInstance
= GetModuleHandleA(0);
4703 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
4704 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4705 cls
.lpszMenuName
= NULL
;
4706 cls
.lpszClassName
= "RedrawWindowClass";
4708 if(!RegisterClassA(&cls
)) {
4709 trace("Register failed %d\n", GetLastError());
4713 hwndMain
= CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
4714 CW_USEDEFAULT
, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4716 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
4717 ShowWindow(hwndMain
, SW_SHOW
);
4718 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
4719 RedrawWindow(hwndMain
, NULL
,NULL
,RDW_UPDATENOW
| RDW_ALLCHILDREN
);
4720 ok( WMPAINT_count
== 1 || broken(WMPAINT_count
== 0), /* sometimes on win9x */
4721 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
4722 redrawComplete
= TRUE
;
4723 ok( WMPAINT_count
< 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count
);
4726 DestroyWindow( hwndMain
);
4729 struct parentdc_stat
{
4735 struct parentdc_test
{
4736 struct parentdc_stat main
, main_todo
;
4737 struct parentdc_stat child1
, child1_todo
;
4738 struct parentdc_stat child2
, child2_todo
;
4741 static LRESULT WINAPI
parentdc_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4746 struct parentdc_stat
*t
= (struct parentdc_stat
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
4751 GetClientRect(hwnd
, &rc
);
4752 CopyRect(&t
->client
, &rc
);
4753 GetWindowRect(hwnd
, &rc
);
4754 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd
,
4755 t
->client
.left
, t
->client
.top
, t
->client
.right
, t
->client
.bottom
,
4756 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4757 BeginPaint(hwnd
, &ps
);
4758 CopyRect(&t
->paint
, &ps
.rcPaint
);
4759 GetClipBox(ps
.hdc
, &rc
);
4760 CopyRect(&t
->clip
, &rc
);
4761 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
4762 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
4763 ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
4764 EndPaint(hwnd
, &ps
);
4767 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
4770 static void zero_parentdc_stat(struct parentdc_stat
*t
)
4772 SetRectEmpty(&t
->client
);
4773 SetRectEmpty(&t
->clip
);
4774 SetRectEmpty(&t
->paint
);
4777 static void zero_parentdc_test(struct parentdc_test
*t
)
4779 zero_parentdc_stat(&t
->main
);
4780 zero_parentdc_stat(&t
->child1
);
4781 zero_parentdc_stat(&t
->child2
);
4784 #define parentdc_field_ok(t, w, r, f, got) \
4785 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
4786 ": expected %d, got %d\n", \
4789 #define parentdc_todo_field_ok(t, w, r, f, got) \
4790 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
4791 else parentdc_field_ok(t, w, r, f, got)
4793 #define parentdc_rect_ok(t, w, r, got) \
4794 parentdc_todo_field_ok(t, w, r, left, got); \
4795 parentdc_todo_field_ok(t, w, r, top, got); \
4796 parentdc_todo_field_ok(t, w, r, right, got); \
4797 parentdc_todo_field_ok(t, w, r, bottom, got);
4799 #define parentdc_win_ok(t, w, got) \
4800 parentdc_rect_ok(t, w, client, got); \
4801 parentdc_rect_ok(t, w, clip, got); \
4802 parentdc_rect_ok(t, w, paint, got);
4804 #define parentdc_ok(t, got) \
4805 parentdc_win_ok(t, main, got); \
4806 parentdc_win_ok(t, child1, got); \
4807 parentdc_win_ok(t, child2, got);
4809 static void test_csparentdc(void)
4811 WNDCLASSA clsMain
, cls
;
4812 HWND hwndMain
, hwnd1
, hwnd2
;
4815 struct parentdc_test test_answer
;
4817 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
4818 const struct parentdc_test test1
=
4820 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo
,
4821 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4822 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4825 const struct parentdc_test test2
=
4827 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo
,
4828 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4829 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4832 const struct parentdc_test test3
=
4834 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
4835 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
4836 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
4839 const struct parentdc_test test4
=
4841 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo
,
4842 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo
,
4843 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
4846 const struct parentdc_test test5
=
4848 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo
,
4849 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4850 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4853 const struct parentdc_test test6
=
4855 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
4856 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
4857 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
4860 const struct parentdc_test test7
=
4862 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
4863 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4864 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
4868 clsMain
.style
= CS_DBLCLKS
;
4869 clsMain
.lpfnWndProc
= parentdc_window_procA
;
4870 clsMain
.cbClsExtra
= 0;
4871 clsMain
.cbWndExtra
= 0;
4872 clsMain
.hInstance
= GetModuleHandleA(0);
4874 clsMain
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
4875 clsMain
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4876 clsMain
.lpszMenuName
= NULL
;
4877 clsMain
.lpszClassName
= "ParentDcMainWindowClass";
4879 if(!RegisterClassA(&clsMain
)) {
4880 trace("Register failed %d\n", GetLastError());
4884 cls
.style
= CS_DBLCLKS
| CS_PARENTDC
;
4885 cls
.lpfnWndProc
= parentdc_window_procA
;
4888 cls
.hInstance
= GetModuleHandleA(0);
4890 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
4891 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4892 cls
.lpszMenuName
= NULL
;
4893 cls
.lpszClassName
= "ParentDcWindowClass";
4895 if(!RegisterClassA(&cls
)) {
4896 trace("Register failed %d\n", GetLastError());
4900 SetRect(&rc
, 0, 0, 150, 150);
4901 AdjustWindowRectEx(&rc
, WS_OVERLAPPEDWINDOW
, FALSE
, 0);
4902 hwndMain
= CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
4903 CW_USEDEFAULT
, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, NULL
, NULL
, 0, NULL
);
4904 SetWindowLongPtrA(hwndMain
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.main
);
4905 hwnd1
= CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD
,
4906 20, 20, 40, 40, hwndMain
, NULL
, 0, NULL
);
4907 SetWindowLongPtrA(hwnd1
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child1
);
4908 hwnd2
= CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD
,
4909 40, 40, 40, 40, hwndMain
, NULL
, 0, NULL
);
4910 SetWindowLongPtrA(hwnd2
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child2
);
4911 ShowWindow(hwndMain
, SW_SHOW
);
4912 ShowWindow(hwnd1
, SW_SHOW
);
4913 ShowWindow(hwnd2
, SW_SHOW
);
4914 SetWindowPos(hwndMain
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
4915 flush_events( TRUE
);
4917 zero_parentdc_test(&test_answer
);
4918 InvalidateRect(hwndMain
, NULL
, TRUE
);
4919 flush_events( TRUE
);
4920 parentdc_ok(test1
, test_answer
);
4922 zero_parentdc_test(&test_answer
);
4923 SetRect(&rc
, 0, 0, 50, 50);
4924 InvalidateRect(hwndMain
, &rc
, TRUE
);
4925 flush_events( TRUE
);
4926 parentdc_ok(test2
, test_answer
);
4928 zero_parentdc_test(&test_answer
);
4929 SetRect(&rc
, 0, 0, 10, 10);
4930 InvalidateRect(hwndMain
, &rc
, TRUE
);
4931 flush_events( TRUE
);
4932 parentdc_ok(test3
, test_answer
);
4934 zero_parentdc_test(&test_answer
);
4935 SetRect(&rc
, 40, 40, 50, 50);
4936 InvalidateRect(hwndMain
, &rc
, TRUE
);
4937 flush_events( TRUE
);
4938 parentdc_ok(test4
, test_answer
);
4940 zero_parentdc_test(&test_answer
);
4941 SetRect(&rc
, 20, 20, 60, 60);
4942 InvalidateRect(hwndMain
, &rc
, TRUE
);
4943 flush_events( TRUE
);
4944 parentdc_ok(test5
, test_answer
);
4946 zero_parentdc_test(&test_answer
);
4947 SetRect(&rc
, 0, 0, 10, 10);
4948 InvalidateRect(hwnd1
, &rc
, TRUE
);
4949 flush_events( TRUE
);
4950 parentdc_ok(test6
, test_answer
);
4952 zero_parentdc_test(&test_answer
);
4953 SetRect(&rc
, -5, -5, 65, 65);
4954 InvalidateRect(hwnd1
, &rc
, TRUE
);
4955 flush_events( TRUE
);
4956 parentdc_ok(test7
, test_answer
);
4958 DestroyWindow(hwndMain
);
4959 DestroyWindow(hwnd1
);
4960 DestroyWindow(hwnd2
);
4963 static LRESULT WINAPI
def_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4965 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
4968 static LRESULT WINAPI
def_window_procW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4970 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
4973 static void test_IsWindowUnicode(void)
4975 static const char ansi_class_nameA
[] = "ansi class name";
4976 static const WCHAR ansi_class_nameW
[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
4977 static const char unicode_class_nameA
[] = "unicode class name";
4978 static const WCHAR unicode_class_nameW
[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
4984 memset(&classW
, 0, sizeof(classW
));
4985 classW
.hInstance
= GetModuleHandleA(0);
4986 classW
.lpfnWndProc
= def_window_procW
;
4987 classW
.lpszClassName
= unicode_class_nameW
;
4988 if (!RegisterClassW(&classW
)) return; /* this catches Win9x as well */
4990 memset(&classA
, 0, sizeof(classA
));
4991 classA
.hInstance
= GetModuleHandleA(0);
4992 classA
.lpfnWndProc
= def_window_procA
;
4993 classA
.lpszClassName
= ansi_class_nameA
;
4994 atom
= RegisterClassA(&classA
);
4997 /* unicode class: window proc */
4998 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
4999 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5002 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5003 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
5004 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5005 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
5006 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5008 DestroyWindow(hwnd
);
5010 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
5011 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5014 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5015 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
5016 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5017 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
5018 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5020 DestroyWindow(hwnd
);
5022 /* ansi class: window proc */
5023 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
5024 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5027 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5028 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
5029 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5030 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
5031 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5033 DestroyWindow(hwnd
);
5035 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
5036 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5039 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5040 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
5041 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5042 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
5043 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5045 DestroyWindow(hwnd
);
5047 /* unicode class: class proc */
5048 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
5049 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5052 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5053 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
5054 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5055 /* do not restore class window proc back to unicode */
5057 DestroyWindow(hwnd
);
5059 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
5060 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5063 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5064 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
5065 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5067 DestroyWindow(hwnd
);
5069 /* ansi class: class proc */
5070 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
5071 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5074 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5075 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
5076 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
5077 /* do not restore class window proc back to ansi */
5079 DestroyWindow(hwnd
);
5081 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
5082 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
5085 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5086 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
5087 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
5089 DestroyWindow(hwnd
);
5092 static LRESULT CALLBACK
minmax_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
5096 if (msg
!= WM_GETMINMAXINFO
)
5097 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
5099 minmax
= (MINMAXINFO
*)lp
;
5101 if ((GetWindowLongA(hwnd
, GWL_STYLE
) & WS_CHILD
))
5103 minmax
->ptReserved
.x
= 0;
5104 minmax
->ptReserved
.y
= 0;
5105 minmax
->ptMaxSize
.x
= 400;
5106 minmax
->ptMaxSize
.y
= 400;
5107 minmax
->ptMaxPosition
.x
= 300;
5108 minmax
->ptMaxPosition
.y
= 300;
5109 minmax
->ptMaxTrackSize
.x
= 200;
5110 minmax
->ptMaxTrackSize
.y
= 200;
5111 minmax
->ptMinTrackSize
.x
= 100;
5112 minmax
->ptMinTrackSize
.y
= 100;
5115 DefWindowProcA(hwnd
, msg
, wp
, lp
);
5119 static int expected_cx
, expected_cy
;
5120 static RECT expected_rect
, broken_rect
;
5122 static LRESULT CALLBACK
winsizes_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
5126 case WM_GETMINMAXINFO
:
5129 GetWindowRect( hwnd
, &rect
);
5130 ok( !rect
.left
&& !rect
.top
&& !rect
.right
&& !rect
.bottom
,
5131 "wrong rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
5132 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
5137 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
5139 GetWindowRect( hwnd
, &rect
);
5140 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
5141 hwnd
, msg
, cs
->cx
, cs
->cy
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
5142 ok( cs
->cx
== expected_cx
|| broken(cs
->cx
== (short)expected_cx
),
5143 "wrong x size %d/%d\n", cs
->cx
, expected_cx
);
5144 ok( cs
->cy
== expected_cy
|| broken(cs
->cy
== (short)expected_cy
),
5145 "wrong y size %d/%d\n", cs
->cy
, expected_cy
);
5146 ok( (rect
.right
- rect
.left
== expected_rect
.right
- expected_rect
.left
&&
5147 rect
.bottom
- rect
.top
== expected_rect
.bottom
- expected_rect
.top
) ||
5148 (rect
.right
- rect
.left
== min( 65535, expected_rect
.right
- expected_rect
.left
) &&
5149 rect
.bottom
- rect
.top
== min( 65535, expected_rect
.bottom
- expected_rect
.top
)) ||
5150 broken( rect
.right
- rect
.left
== broken_rect
.right
- broken_rect
.left
&&
5151 rect
.bottom
- rect
.top
== broken_rect
.bottom
- broken_rect
.top
) ||
5152 broken( rect
.right
- rect
.left
== (short)broken_rect
.right
- (short)broken_rect
.left
&&
5153 rect
.bottom
- rect
.top
== (short)broken_rect
.bottom
- (short)broken_rect
.top
),
5154 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
5155 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
5156 expected_rect
.left
, expected_rect
.top
, expected_rect
.right
, expected_rect
.bottom
);
5157 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
5161 RECT rect
, *r
= (RECT
*)lp
;
5162 GetWindowRect( hwnd
, &rect
);
5163 ok( !memcmp( &rect
, r
, sizeof(rect
) ),
5164 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
5165 r
->left
, r
->top
, r
->right
, r
->bottom
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
5166 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
5169 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
5173 static void test_CreateWindow(void)
5182 #define expect_menu(window, menu) \
5183 SetLastError(0xdeadbeef); \
5184 res = (GetMenu(window) == (HMENU)menu); \
5185 ok(res, "GetMenu error %d\n", GetLastError())
5187 #define expect_style(window, style)\
5188 ok((ULONG)GetWindowLongA(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLongA(window, GWL_STYLE))
5190 #define expect_ex_style(window, ex_style)\
5191 ok((ULONG)GetWindowLongA(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLongA(window, GWL_EXSTYLE))
5193 #define expect_gle_broken_9x(gle)\
5194 ok(GetLastError() == gle ||\
5195 broken(GetLastError() == 0xdeadbeef),\
5196 "IsMenu set error %d\n", GetLastError())
5198 hmenu
= CreateMenu();
5200 parent
= GetDesktopWindow();
5201 assert(parent
!= 0);
5203 SetLastError(0xdeadbeef);
5204 res
= IsMenu(hmenu
);
5205 ok(res
, "IsMenu error %d\n", GetLastError());
5208 SetLastError(0xdeadbeef);
5209 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
,
5210 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
5211 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5212 expect_menu(hwnd
, 1);
5213 expect_style(hwnd
, WS_CHILD
);
5214 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
5215 DestroyWindow(hwnd
);
5217 SetLastError(0xdeadbeef);
5218 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_CAPTION
,
5219 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
5220 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5221 expect_menu(hwnd
, 1);
5222 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
5223 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
5224 DestroyWindow(hwnd
);
5226 SetLastError(0xdeadbeef);
5227 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
5228 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
5229 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5230 expect_menu(hwnd
, 1);
5231 expect_style(hwnd
, WS_CHILD
);
5232 expect_ex_style(hwnd
, 0);
5233 DestroyWindow(hwnd
);
5235 SetLastError(0xdeadbeef);
5236 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_CAPTION
,
5237 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
5238 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5239 expect_menu(hwnd
, 1);
5240 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
5241 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
5242 DestroyWindow(hwnd
);
5245 SetLastError(0xdeadbeef);
5246 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
5247 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
5248 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5249 expect_menu(hwnd
, hmenu
);
5250 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
5251 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
5252 DestroyWindow(hwnd
);
5253 SetLastError(0xdeadbeef);
5254 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
5255 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
5257 hmenu
= CreateMenu();
5259 SetLastError(0xdeadbeef);
5260 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
| WS_CAPTION
,
5261 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
5262 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5263 expect_menu(hwnd
, hmenu
);
5264 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
5265 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
5266 DestroyWindow(hwnd
);
5267 SetLastError(0xdeadbeef);
5268 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
5269 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
5271 hmenu
= CreateMenu();
5273 SetLastError(0xdeadbeef);
5274 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
5275 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
5276 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5277 expect_menu(hwnd
, hmenu
);
5278 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
5279 expect_ex_style(hwnd
, 0);
5280 DestroyWindow(hwnd
);
5281 SetLastError(0xdeadbeef);
5282 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
5283 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
5285 hmenu
= CreateMenu();
5287 SetLastError(0xdeadbeef);
5288 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
| WS_CAPTION
,
5289 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
5290 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5291 expect_menu(hwnd
, hmenu
);
5292 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
5293 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
5294 DestroyWindow(hwnd
);
5295 SetLastError(0xdeadbeef);
5296 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
5297 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
5299 /* WS_CHILD | WS_POPUP */
5300 SetLastError(0xdeadbeef);
5301 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
5302 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
5303 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
5304 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
5306 DestroyWindow(hwnd
);
5308 hmenu
= CreateMenu();
5310 SetLastError(0xdeadbeef);
5311 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
5312 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
5313 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5314 expect_menu(hwnd
, hmenu
);
5315 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
5316 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
5317 DestroyWindow(hwnd
);
5318 SetLastError(0xdeadbeef);
5319 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
5320 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
5322 SetLastError(0xdeadbeef);
5323 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
5324 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
5325 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
5326 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
5328 DestroyWindow(hwnd
);
5330 hmenu
= CreateMenu();
5332 SetLastError(0xdeadbeef);
5333 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
5334 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
5335 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5336 expect_menu(hwnd
, hmenu
);
5337 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
5338 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
5339 DestroyWindow(hwnd
);
5340 SetLastError(0xdeadbeef);
5341 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
5342 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
5344 SetLastError(0xdeadbeef);
5345 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
5346 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
5347 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
5348 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
5350 DestroyWindow(hwnd
);
5352 hmenu
= CreateMenu();
5354 SetLastError(0xdeadbeef);
5355 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
5356 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
5357 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5358 expect_menu(hwnd
, hmenu
);
5359 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
5360 expect_ex_style(hwnd
, 0);
5361 DestroyWindow(hwnd
);
5362 SetLastError(0xdeadbeef);
5363 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
5364 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
5366 SetLastError(0xdeadbeef);
5367 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
5368 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
5369 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
5370 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
5372 DestroyWindow(hwnd
);
5374 hmenu
= CreateMenu();
5376 SetLastError(0xdeadbeef);
5377 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
5378 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
5379 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5380 expect_menu(hwnd
, hmenu
);
5381 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
5382 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
5383 DestroyWindow(hwnd
);
5384 SetLastError(0xdeadbeef);
5385 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
5386 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
5388 /* test child window sizing */
5390 cls
.lpfnWndProc
= minmax_wnd_proc
;
5393 cls
.hInstance
= GetModuleHandleA(NULL
);
5395 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
5396 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5397 cls
.lpszMenuName
= NULL
;
5398 cls
.lpszClassName
= "MinMax_WndClass";
5399 RegisterClassA(&cls
);
5401 SetLastError(0xdeadbeef);
5402 parent
= CreateWindowExA(0, "MinMax_WndClass", NULL
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
5403 0, 0, 100, 100, 0, 0, 0, NULL
);
5404 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
5405 expect_menu(parent
, 0);
5406 expect_style(parent
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
| WS_CLIPSIBLINGS
);
5407 expect_ex_style(parent
, WS_EX_WINDOWEDGE
);
5409 memset(&minmax
, 0, sizeof(minmax
));
5410 SendMessageA(parent
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
5411 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxSize
.x
, minmax
.ptMaxSize
.y
);
5412 ok(IsRectEmpty(&rc_minmax
), "ptMaxSize is not empty\n");
5413 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
5414 ok(IsRectEmpty(&rc_minmax
), "ptMaxTrackSize is not empty\n");
5416 GetWindowRect(parent
, &rc
);
5417 ok(!IsRectEmpty(&rc
), "parent window rect is empty\n");
5418 GetClientRect(parent
, &rc
);
5419 ok(!IsRectEmpty(&rc
), "parent client rect is empty\n");
5421 InflateRect(&rc
, 200, 200);
5422 trace("creating child with rect (%d,%d-%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5424 SetLastError(0xdeadbeef);
5425 hwnd
= CreateWindowExA(0, "MinMax_WndClass", NULL
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
5426 rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
5427 parent
, (HMENU
)1, 0, NULL
);
5428 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
5429 expect_menu(hwnd
, 1);
5430 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
);
5431 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
5433 memset(&minmax
, 0, sizeof(minmax
));
5434 SendMessageA(hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
5435 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
5437 GetWindowRect(hwnd
, &rc
);
5438 OffsetRect(&rc
, -rc
.left
, -rc
.top
);
5439 ok(EqualRect(&rc
, &rc_minmax
), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
5440 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
5441 rc_minmax
.left
, rc_minmax
.top
, rc_minmax
.right
, rc_minmax
.bottom
);
5442 DestroyWindow(hwnd
);
5444 cls
.lpfnWndProc
= winsizes_wnd_proc
;
5445 cls
.lpszClassName
= "Sizes_WndClass";
5446 RegisterClassA(&cls
);
5448 expected_cx
= expected_cy
= 200000;
5449 SetRect( &expected_rect
, 0, 0, 200000, 200000 );
5450 broken_rect
= expected_rect
;
5451 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 300000, 300000, 200000, 200000, parent
, 0, 0, NULL
);
5452 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
5453 GetClientRect( hwnd
, &rc
);
5454 ok( rc
.right
== 200000 || rc
.right
== 65535 || broken(rc
.right
== (short)200000),
5455 "invalid rect right %u\n", rc
.right
);
5456 ok( rc
.bottom
== 200000 || rc
.bottom
== 65535 || broken(rc
.bottom
== (short)200000),
5457 "invalid rect bottom %u\n", rc
.bottom
);
5458 DestroyWindow(hwnd
);
5460 expected_cx
= expected_cy
= -10;
5461 SetRect( &expected_rect
, 0, 0, 0, 0 );
5462 SetRect( &broken_rect
, 0, 0, -10, -10 );
5463 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -20, -20, -10, -10, parent
, 0, 0, NULL
);
5464 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
5465 GetClientRect( hwnd
, &rc
);
5466 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
5467 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
5468 DestroyWindow(hwnd
);
5470 expected_cx
= expected_cy
= -200000;
5471 SetRect( &expected_rect
, 0, 0, 0, 0 );
5472 SetRect( &broken_rect
, 0, 0, -200000, -200000 );
5473 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -300000, -300000, -200000, -200000, parent
, 0, 0, NULL
);
5474 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
5475 GetClientRect( hwnd
, &rc
);
5476 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
5477 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
5478 DestroyWindow(hwnd
);
5480 /* we need a parent at 0,0 so that child coordinates match */
5481 DestroyWindow(parent
);
5482 parent
= CreateWindowExA(0, "MinMax_WndClass", NULL
, WS_POPUP
, 0, 0, 100, 100, 0, 0, 0, NULL
);
5483 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
5486 expected_cy
= 0x7fffffff;
5487 SetRect( &expected_rect
, 10, 10, 110, 0x7fffffff );
5488 SetRect( &broken_rect
, 10, 10, 110, 0x7fffffffU
+ 10 );
5489 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 10, 10, 100, 0x7fffffff, parent
, 0, 0, NULL
);
5490 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
5491 GetClientRect( hwnd
, &rc
);
5492 ok( rc
.right
== 100, "invalid rect right %u\n", rc
.right
);
5493 ok( rc
.bottom
== 0x7fffffff - 10 || rc
.bottom
==65535 || broken(rc
.bottom
== 0),
5494 "invalid rect bottom %u\n", rc
.bottom
);
5495 DestroyWindow(hwnd
);
5497 expected_cx
= 0x7fffffff;
5498 expected_cy
= 0x7fffffff;
5499 SetRect( &expected_rect
, 20, 10, 0x7fffffff, 0x7fffffff );
5500 SetRect( &broken_rect
, 20, 10, 0x7fffffffU
+ 20, 0x7fffffffU
+ 10 );
5501 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 20, 10, 0x7fffffff, 0x7fffffff, parent
, 0, 0, NULL
);
5502 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
5503 GetClientRect( hwnd
, &rc
);
5504 ok( rc
.right
== 0x7fffffff - 20 || rc
.right
== 65535 || broken(rc
.right
== 0),
5505 "invalid rect right %u\n", rc
.right
);
5506 ok( rc
.bottom
== 0x7fffffff - 10 || rc
.right
== 65535 || broken(rc
.bottom
== 0),
5507 "invalid rect bottom %u\n", rc
.bottom
);
5508 DestroyWindow(hwnd
);
5510 /* top level window */
5511 expected_cx
= expected_cy
= 200000;
5512 SetRect( &expected_rect
, 0, 0, GetSystemMetrics(SM_CXMAXTRACK
), GetSystemMetrics(SM_CYMAXTRACK
) );
5513 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_OVERLAPPEDWINDOW
, 300000, 300000, 200000, 200000, 0, 0, 0, NULL
);
5514 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
5515 GetClientRect( hwnd
, &rc
);
5516 ok( rc
.right
<= expected_cx
, "invalid rect right %u\n", rc
.right
);
5517 ok( rc
.bottom
<= expected_cy
, "invalid rect bottom %u\n", rc
.bottom
);
5518 DestroyWindow(hwnd
);
5520 if (pGetLayout
&& pSetLayout
)
5522 HDC hdc
= GetDC( parent
);
5523 pSetLayout( hdc
, LAYOUT_RTL
);
5524 if (pGetLayout( hdc
))
5526 ReleaseDC( parent
, hdc
);
5527 DestroyWindow( parent
);
5528 SetLastError( 0xdeadbeef );
5529 parent
= CreateWindowExA(WS_EX_APPWINDOW
| WS_EX_LAYOUTRTL
, "static", NULL
, WS_POPUP
,
5530 0, 0, 100, 100, 0, 0, 0, NULL
);
5531 ok( parent
!= 0, "creation failed err %u\n", GetLastError());
5532 expect_ex_style( parent
, WS_EX_APPWINDOW
| WS_EX_LAYOUTRTL
);
5533 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 20, 20, parent
, 0, 0, NULL
);
5534 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
5535 expect_ex_style( hwnd
, WS_EX_LAYOUTRTL
);
5536 DestroyWindow( hwnd
);
5537 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 20, 20, parent
, 0, 0, NULL
);
5538 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
5539 expect_ex_style( hwnd
, 0 );
5540 DestroyWindow( hwnd
);
5541 SetWindowLongW( parent
, GWL_EXSTYLE
, WS_EX_APPWINDOW
| WS_EX_LAYOUTRTL
| WS_EX_NOINHERITLAYOUT
);
5542 hwnd
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 20, 20, parent
, 0, 0, NULL
);
5543 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
5544 expect_ex_style( hwnd
, 0 );
5545 DestroyWindow( hwnd
);
5547 if (pGetProcessDefaultLayout
&& pSetProcessDefaultLayout
)
5551 SetLastError( 0xdeadbeef );
5552 ok( !pGetProcessDefaultLayout( NULL
), "GetProcessDefaultLayout succeeded\n" );
5553 ok( GetLastError() == ERROR_NOACCESS
, "wrong error %u\n", GetLastError() );
5554 SetLastError( 0xdeadbeef );
5555 res
= pGetProcessDefaultLayout( &layout
);
5556 ok( res
, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
5557 ok( layout
== 0, "GetProcessDefaultLayout wrong layout %x\n", layout
);
5558 SetLastError( 0xdeadbeef );
5559 res
= pSetProcessDefaultLayout( 7 );
5560 ok( res
, "SetProcessDefaultLayout failed err %u\n", GetLastError ());
5561 res
= pGetProcessDefaultLayout( &layout
);
5562 ok( res
, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
5563 ok( layout
== 7, "GetProcessDefaultLayout wrong layout %x\n", layout
);
5564 SetLastError( 0xdeadbeef );
5565 res
= pSetProcessDefaultLayout( LAYOUT_RTL
);
5566 ok( res
, "SetProcessDefaultLayout failed err %u\n", GetLastError ());
5567 res
= pGetProcessDefaultLayout( &layout
);
5568 ok( res
, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
5569 ok( layout
== LAYOUT_RTL
, "GetProcessDefaultLayout wrong layout %x\n", layout
);
5570 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
5571 0, 0, 100, 100, 0, 0, 0, NULL
);
5572 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
5573 expect_ex_style( hwnd
, WS_EX_APPWINDOW
| WS_EX_LAYOUTRTL
);
5574 DestroyWindow( hwnd
);
5575 hwnd
= CreateWindowExA(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
5576 0, 0, 100, 100, parent
, 0, 0, NULL
);
5577 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
5578 expect_ex_style( hwnd
, WS_EX_APPWINDOW
);
5579 DestroyWindow( hwnd
);
5580 pSetProcessDefaultLayout( 0 );
5582 else win_skip( "SetProcessDefaultLayout not supported\n" );
5584 else win_skip( "SetLayout not supported\n" );
5586 else win_skip( "SetLayout not available\n" );
5588 DestroyWindow(parent
);
5590 UnregisterClassA("MinMax_WndClass", GetModuleHandleA(NULL
));
5591 UnregisterClassA("Sizes_WndClass", GetModuleHandleA(NULL
));
5593 #undef expect_gle_broken_9x
5596 #undef expect_ex_style
5599 /* function that remembers whether the system the test is running on sets the
5600 * last error for user32 functions to make the tests stricter */
5601 static int check_error(DWORD actual
, DWORD expected
)
5603 static int sets_last_error
= -1;
5604 if (sets_last_error
== -1)
5605 sets_last_error
= (actual
!= 0xdeadbeef);
5606 return (!sets_last_error
&& (actual
== 0xdeadbeef)) || (actual
== expected
);
5609 static void test_SetWindowLong(void)
5612 WNDPROC old_window_procW
;
5614 SetLastError(0xdeadbeef);
5615 retval
= SetWindowLongPtrA(NULL
, GWLP_WNDPROC
, 0);
5616 ok(!retval
, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval
);
5617 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE
),
5618 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instead of %d\n", GetLastError());
5620 SetLastError(0xdeadbeef);
5621 retval
= SetWindowLongPtrA(hwndMain
, 0xdeadbeef, 0);
5622 ok(!retval
, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval
);
5623 ok(check_error(GetLastError(), ERROR_INVALID_INDEX
),
5624 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instead of %d\n", GetLastError());
5626 SetLastError(0xdeadbeef);
5627 retval
= SetWindowLongPtrA(hwndMain
, GWLP_WNDPROC
, 0);
5628 ok((WNDPROC
)retval
== main_window_procA
|| broken(!retval
), /* win9x */
5629 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval
);
5630 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
5631 retval
= GetWindowLongPtrA(hwndMain
, GWLP_WNDPROC
);
5632 ok((WNDPROC
)retval
== main_window_procA
,
5633 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
5634 ok(!IsWindowUnicode(hwndMain
), "hwndMain shouldn't be Unicode\n");
5636 old_window_procW
= (WNDPROC
)GetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
);
5637 SetLastError(0xdeadbeef);
5638 retval
= SetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
, 0);
5639 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED
)
5641 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
5642 ok(retval
!= 0, "SetWindowLongPtr error %d\n", GetLastError());
5643 ok((WNDPROC
)retval
== old_window_procW
,
5644 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
5645 ok(IsWindowUnicode(hwndMain
), "hwndMain should now be Unicode\n");
5647 /* set it back to ANSI */
5648 SetWindowLongPtrA(hwndMain
, GWLP_WNDPROC
, 0);
5652 static void test_ShowWindow(void)
5656 RECT rcMain
, rc
, rcMinimized
;
5659 SetRect(&rcMain
, 120, 120, 210, 210);
5661 hwnd
= CreateWindowExA(0, "MainWindowClass", NULL
,
5662 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
5663 WS_MAXIMIZEBOX
| WS_POPUP
,
5664 rcMain
.left
, rcMain
.top
,
5665 rcMain
.right
- rcMain
.left
, rcMain
.bottom
- rcMain
.top
,
5669 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
5670 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
5671 ok(!(style
& WS_VISIBLE
), "window should not be visible\n");
5672 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
5673 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
5674 GetWindowRect(hwnd
, &rc
);
5675 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5676 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
5677 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5679 ret
= ShowWindow(hwnd
, SW_SHOW
);
5680 ok(!ret
, "not expected ret: %lu\n", ret
);
5681 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
5682 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
5683 ok(style
& WS_VISIBLE
, "window should be visible\n");
5684 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
5685 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
5686 GetWindowRect(hwnd
, &rc
);
5687 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5688 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
5689 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5691 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
5692 ok(ret
, "not expected ret: %lu\n", ret
);
5693 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
5694 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
5695 ok(style
& WS_VISIBLE
, "window should be visible\n");
5696 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
5697 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
5698 GetWindowRect(hwnd
, &rcMinimized
);
5699 ok(!EqualRect(&rcMain
, &rcMinimized
), "rects shouldn't match\n");
5700 /* shouldn't be able to resize minimized windows */
5701 ret
= SetWindowPos(hwnd
, 0, 0, 0,
5702 (rcMinimized
.right
- rcMinimized
.left
) * 2,
5703 (rcMinimized
.bottom
- rcMinimized
.top
) * 2,
5704 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
5705 ok(ret
, "not expected ret: %lu\n", ret
);
5706 GetWindowRect(hwnd
, &rc
);
5707 ok(EqualRect(&rc
, &rcMinimized
), "rects should match\n");
5709 ShowWindow(hwnd
, SW_RESTORE
);
5710 ok(ret
, "not expected ret: %lu\n", ret
);
5711 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
5712 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
5713 ok(style
& WS_VISIBLE
, "window should be visible\n");
5714 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
5715 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
5716 GetWindowRect(hwnd
, &rc
);
5717 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5718 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
5719 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5721 ret
= EnableWindow(hwnd
, FALSE
);
5722 ok(!ret
, "not expected ret: %lu\n", ret
);
5723 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
5724 ok(style
& WS_DISABLED
, "window should be disabled\n");
5726 ret
= DefWindowProcA(hwnd
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
5727 ok(!ret
, "not expected ret: %lu\n", ret
);
5728 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
5729 ok(style
& WS_DISABLED
, "window should be disabled\n");
5730 ok(style
& WS_VISIBLE
, "window should be visible\n");
5731 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
5732 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
5733 GetWindowRect(hwnd
, &rc
);
5734 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5735 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
5736 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5738 ret
= DefWindowProcA(hwnd
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
5739 ok(!ret
, "not expected ret: %lu\n", ret
);
5740 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
5741 ok(style
& WS_DISABLED
, "window should be disabled\n");
5742 ok(style
& WS_VISIBLE
, "window should be visible\n");
5743 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
5744 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
5745 GetWindowRect(hwnd
, &rc
);
5746 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5747 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
5748 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5750 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
5751 ok(ret
, "not expected ret: %lu\n", ret
);
5752 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
5753 ok(style
& WS_DISABLED
, "window should be disabled\n");
5754 ok(style
& WS_VISIBLE
, "window should be visible\n");
5755 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
5756 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
5757 GetWindowRect(hwnd
, &rc
);
5758 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
5760 ret
= DefWindowProcA(hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
5761 ok(!ret
, "not expected ret: %lu\n", ret
);
5762 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
5763 ok(style
& WS_DISABLED
, "window should be disabled\n");
5764 ok(style
& WS_VISIBLE
, "window should be visible\n");
5765 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
5766 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
5767 GetWindowRect(hwnd
, &rc
);
5768 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
5770 ret
= ShowWindow(hwnd
, SW_RESTORE
);
5771 ok(ret
, "not expected ret: %lu\n", ret
);
5772 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
5773 ok(style
& WS_DISABLED
, "window should be disabled\n");
5774 ok(style
& WS_VISIBLE
, "window should be visible\n");
5775 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
5776 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
5777 GetWindowRect(hwnd
, &rc
);
5778 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5779 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
5780 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5782 ret
= DefWindowProcA(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
5783 ok(!ret
, "not expected ret: %lu\n", ret
);
5784 ok(IsWindow(hwnd
), "window should exist\n");
5786 ret
= EnableWindow(hwnd
, TRUE
);
5787 ok(ret
, "not expected ret: %lu\n", ret
);
5789 ret
= DefWindowProcA(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
5790 ok(!ret
, "not expected ret: %lu\n", ret
);
5791 ok(!IsWindow(hwnd
), "window should not exist\n");
5794 static DWORD CALLBACK
gettext_msg_thread( LPVOID arg
)
5800 /* test GetWindowTextA */
5801 num_gettext_msgs
= 0;
5802 memset( buf
, 0, sizeof(buf
) );
5803 buf_len
= GetWindowTextA( hwnd
, buf
, sizeof(buf
) );
5804 ok( buf_len
!= 0, "expected a nonempty window text\n" );
5805 ok( !strcmp(buf
, "another_caption"), "got wrong window text '%s'\n", buf
);
5806 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
5811 static DWORD CALLBACK
settext_msg_thread( LPVOID arg
)
5816 /* test SetWindowTextA */
5817 num_settext_msgs
= 0;
5818 success
= SetWindowTextA( hwnd
, "thread_caption" );
5819 ok( success
, "SetWindowTextA failed\n" );
5820 ok( num_settext_msgs
== 1, "got %u WM_SETTEXT messages\n", num_settext_msgs
);
5825 static void test_gettext(void)
5827 DWORD tid
, num_msgs
;
5837 hwnd
= CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP
, 0, 0, 0, 0, 0, 0, 0, NULL
);
5838 ok( hwnd
!= 0, "CreateWindowExA error %d\n", GetLastError() );
5840 /* test GetWindowTextA */
5841 num_gettext_msgs
= 0;
5842 memset( buf
, 0, sizeof(buf
) );
5843 buf_len
= GetWindowTextA( hwnd
, buf
, sizeof(buf
) );
5844 ok( buf_len
!= 0, "expected a nonempty window text\n" );
5845 ok( !strcmp(buf
, "caption"), "got wrong window text '%s'\n", buf
);
5846 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
5848 /* other process window */
5850 buf_len
= GetWindowTextA( GetDesktopWindow(), buf
, sizeof(buf
) );
5851 ok( buf_len
== 0, "expected a nonempty window text\n" );
5852 ok( *buf
== 0, "got wrong window text '%s'\n", buf
);
5854 strcpy( buf
, "blah" );
5855 buf_len
= GetWindowTextA( GetDesktopWindow(), buf
, 0 );
5856 ok( buf_len
== 0, "expected a nonempty window text\n" );
5857 ok( !strcmp(buf
, "blah"), "got wrong window text '%s'\n", buf
);
5860 buf_len
= GetWindowTextW( GetDesktopWindow(), bufW
, 0 );
5861 ok( buf_len
== 0, "expected a nonempty window text\n" );
5862 ok( bufW
[0] == 0xcc, "got %x\n", bufW
[0] );
5864 g_wm_gettext_override
.enabled
= TRUE
;
5866 num_gettext_msgs
= 0;
5867 memset( buf
, 0xcc, sizeof(buf
) );
5868 g_wm_gettext_override
.buff
= buf
;
5869 buf_len
= GetWindowTextA( hwnd
, buf
, sizeof(buf
) );
5870 ok( buf_len
== 0, "got %d\n", buf_len
);
5871 ok( *buf
== 0, "got %x\n", *buf
);
5872 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
5874 num_gettext_msgs
= 0;
5875 strcpy( buf
, "blah" );
5876 g_wm_gettext_override
.buff
= buf
;
5877 buf_len
= GetWindowTextA( hwnd
, buf
, 0 );
5878 ok( buf_len
== 0, "got %d\n", buf_len
);
5879 ok( !strcmp(buf
, "blah"), "got %s\n", buf
);
5880 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
5882 g_wm_gettext_override
.enabled
= FALSE
;
5884 /* same for W window */
5885 hwnd2
= CreateWindowExW( 0, mainclassW
, NULL
, WS_POPUP
, 0, 0, 0, 0, 0, 0, 0, NULL
);
5886 ok( hwnd2
!= 0, "CreateWindowExA error %d\n", GetLastError() );
5888 g_wm_gettext_override
.enabled
= TRUE
;
5890 num_gettext_msgs
= 0;
5891 memset( bufW
, 0xcc, sizeof(bufW
) );
5892 g_wm_gettext_override
.buffW
= bufW
;
5893 buf_len
= GetWindowTextW( hwnd2
, bufW
, sizeof(bufW
)/sizeof(WCHAR
) );
5894 ok( buf_len
== 0, "got %d\n", buf_len
);
5895 ok( *bufW
== 0, "got %x\n", *bufW
);
5896 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
5898 num_gettext_msgs
= 0;
5899 memset( bufW
, 0xcc, sizeof(bufW
) );
5900 g_wm_gettext_override
.buffW
= bufW
;
5901 buf_len
= GetWindowTextW( hwnd2
, bufW
, 0 );
5902 ok( buf_len
== 0, "got %d\n", buf_len
);
5903 ok( *bufW
== 0xcccc, "got %x\n", *bufW
);
5904 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
5906 g_wm_gettext_override
.enabled
= FALSE
;
5908 DestroyWindow( hwnd2
);
5910 /* test WM_GETTEXT */
5911 num_gettext_msgs
= 0;
5912 memset( buf
, 0, sizeof(buf
) );
5913 r
= SendMessageA( hwnd
, WM_GETTEXT
, sizeof(buf
), (LONG_PTR
)buf
);
5914 ok( r
!= 0, "expected a nonempty window text\n" );
5915 ok( !strcmp(buf
, "caption"), "got wrong window text '%s'\n", buf
);
5916 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
5918 /* test SetWindowTextA */
5919 num_settext_msgs
= 0;
5920 success
= SetWindowTextA( hwnd
, "new_caption" );
5921 ok( success
, "SetWindowTextA failed\n" );
5922 ok( num_settext_msgs
== 1, "got %u WM_SETTEXT messages\n", num_settext_msgs
);
5924 num_gettext_msgs
= 0;
5925 memset( buf
, 0, sizeof(buf
) );
5926 buf_len
= GetWindowTextA( hwnd
, buf
, sizeof(buf
) );
5927 ok( buf_len
!= 0, "expected a nonempty window text\n" );
5928 ok( !strcmp(buf
, "new_caption"), "got wrong window text '%s'\n", buf
);
5929 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
5931 /* test WM_SETTEXT */
5932 num_settext_msgs
= 0;
5933 r
= SendMessageA( hwnd
, WM_SETTEXT
, 0, (ULONG_PTR
)"another_caption" );
5934 ok( r
!= 0, "WM_SETTEXT failed\n" );
5935 ok( num_settext_msgs
== 1, "got %u WM_SETTEXT messages\n", num_settext_msgs
);
5937 num_gettext_msgs
= 0;
5938 memset( buf
, 0, sizeof(buf
) );
5939 buf_len
= GetWindowTextA( hwnd
, buf
, sizeof(buf
) );
5940 ok( buf_len
!= 0, "expected a nonempty window text\n" );
5941 ok( !strcmp(buf
, "another_caption"), "got wrong window text '%s'\n", buf
);
5942 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
5944 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
))
5945 DispatchMessageA( &msg
);
5947 /* test interthread GetWindowTextA */
5949 thread
= CreateThread( NULL
, 0, gettext_msg_thread
, hwnd
, 0, &tid
);
5950 ok(thread
!= NULL
, "CreateThread failed, error %d\n", GetLastError());
5951 while (MsgWaitForMultipleObjects( 1, &thread
, FALSE
, INFINITE
, QS_SENDMESSAGE
) != WAIT_OBJECT_0
)
5953 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
))
5954 DispatchMessageA( &msg
);
5957 CloseHandle( thread
);
5958 ok( num_msgs
>= 1, "got %u wakeups from MsgWaitForMultipleObjects\n", num_msgs
);
5960 /* test interthread SetWindowText */
5962 thread
= CreateThread( NULL
, 0, settext_msg_thread
, hwnd
, 0, &tid
);
5963 ok(thread
!= NULL
, "CreateThread failed, error %d\n", GetLastError());
5964 while (MsgWaitForMultipleObjects( 1, &thread
, FALSE
, INFINITE
, QS_SENDMESSAGE
) != WAIT_OBJECT_0
)
5966 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
))
5967 DispatchMessageA( &msg
);
5970 CloseHandle( thread
);
5971 ok( num_msgs
>= 1, "got %u wakeups from MsgWaitForMultipleObjects\n", num_msgs
);
5973 num_gettext_msgs
= 0;
5974 memset( buf
, 0, sizeof(buf
) );
5975 buf_len
= GetWindowTextA( hwnd
, buf
, sizeof(buf
) );
5976 ok( buf_len
!= 0, "expected a nonempty window text\n" );
5977 ok( !strcmp(buf
, "thread_caption"), "got wrong window text '%s'\n", buf
);
5978 ok( num_gettext_msgs
== 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
5980 /* seems to crash on every modern Windows version */
5983 r
= SendMessageA( hwnd
, WM_GETTEXT
, 0x10, 0x1000);
5984 ok( r
== 0, "settext should return zero\n");
5986 r
= SendMessageA( hwnd
, WM_GETTEXT
, 0x10000, 0);
5987 ok( r
== 0, "settext should return zero (%ld)\n", r
);
5989 r
= SendMessageA( hwnd
, WM_GETTEXT
, 0xff000000, 0x1000);
5990 ok( r
== 0, "settext should return zero (%ld)\n", r
);
5992 r
= SendMessageA( hwnd
, WM_GETTEXT
, 0x1000, 0xff000000);
5993 ok( r
== 0, "settext should return zero (%ld)\n", r
);
5996 DestroyWindow(hwnd
);
6000 static void test_GetUpdateRect(void)
6003 BOOL ret
, parent_wm_paint
, grandparent_wm_paint
;
6005 HWND hgrandparent
, hparent
, hchild
;
6007 static const char classNameA
[] = "GetUpdateRectClass";
6009 hgrandparent
= CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW
,
6010 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
6012 hparent
= CreateWindowA("static", "parent", WS_CHILD
|WS_VISIBLE
,
6013 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
6015 hchild
= CreateWindowA("static", "child", WS_CHILD
|WS_VISIBLE
,
6016 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
6018 ShowWindow(hgrandparent
, SW_SHOW
);
6019 UpdateWindow(hgrandparent
);
6020 flush_events( TRUE
);
6022 ShowWindow(hchild
, SW_HIDE
);
6023 SetRect(&rc2
, 0, 0, 0, 0);
6024 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
6025 ok(!ret
, "GetUpdateRect returned not empty region\n");
6026 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
6027 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
6028 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
6030 SetRect(&rc2
, 10, 10, 40, 40);
6031 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
6032 ok(ret
, "GetUpdateRect returned empty region\n");
6033 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
6034 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
6035 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
6037 parent_wm_paint
= FALSE
;
6038 grandparent_wm_paint
= FALSE
;
6039 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
6041 if (msg
.message
== WM_PAINT
)
6043 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
6044 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
6046 DispatchMessageA(&msg
);
6048 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
6049 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
6051 DestroyWindow(hgrandparent
);
6054 cls
.lpfnWndProc
= DefWindowProcA
;
6057 cls
.hInstance
= GetModuleHandleA(0);
6059 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
6060 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
6061 cls
.lpszMenuName
= NULL
;
6062 cls
.lpszClassName
= classNameA
;
6064 if(!RegisterClassA(&cls
)) {
6065 trace("Register failed %d\n", GetLastError());
6069 hgrandparent
= CreateWindowA(classNameA
, "grandparent", WS_OVERLAPPEDWINDOW
,
6070 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
6072 hparent
= CreateWindowA(classNameA
, "parent", WS_CHILD
|WS_VISIBLE
,
6073 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
6075 hchild
= CreateWindowA(classNameA
, "child", WS_CHILD
|WS_VISIBLE
,
6076 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
6078 ShowWindow(hgrandparent
, SW_SHOW
);
6079 UpdateWindow(hgrandparent
);
6080 flush_events( TRUE
);
6082 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
6083 ok(!ret
, "GetUpdateRect returned not empty region\n");
6085 ShowWindow(hchild
, SW_HIDE
);
6087 SetRect(&rc2
, 0, 0, 0, 0);
6088 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
6089 ok(!ret
, "GetUpdateRect returned not empty region\n");
6090 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
6091 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
6092 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
6094 SetRect(&rc2
, 10, 10, 40, 40);
6095 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
6096 ok(ret
, "GetUpdateRect returned empty region\n");
6097 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
6098 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
6099 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
6101 parent_wm_paint
= FALSE
;
6102 grandparent_wm_paint
= FALSE
;
6103 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
6105 if (msg
.message
== WM_PAINT
)
6107 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
6108 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
6110 DispatchMessageA(&msg
);
6112 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
6113 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
6115 DestroyWindow(hgrandparent
);
6119 static LRESULT CALLBACK
TestExposedRegion_WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
6127 const int waitTime
= 2000;
6129 BeginPaint(hwnd
, &ps
);
6131 /* create and destroy window to create an exposed region on this window */
6132 win
= CreateWindowA("static", "win", WS_VISIBLE
,
6133 10,10,50,50, NULL
, NULL
, 0, NULL
);
6136 waitResult
= MsgWaitForMultipleObjects( 0, NULL
, FALSE
, waitTime
, QS_PAINT
);
6138 ValidateRect(hwnd
, NULL
);
6139 EndPaint(hwnd
, &ps
);
6141 if(waitResult
!= WAIT_TIMEOUT
)
6143 GetUpdateRect(hwnd
, &updateRect
, FALSE
);
6144 ok(IsRectEmpty(&updateRect
), "Exposed rect should be empty\n");
6149 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
6152 static void test_Expose(void)
6157 memset(&cls
, 0, sizeof(WNDCLASSA
));
6158 cls
.lpfnWndProc
= TestExposedRegion_WndProc
;
6159 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
6160 cls
.lpszClassName
= "TestExposeClass";
6161 RegisterClassA(&cls
);
6163 mw
= CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE
|WS_OVERLAPPEDWINDOW
,
6164 0, 0, 200, 100, NULL
, NULL
, 0, NULL
);
6170 static LRESULT CALLBACK
TestNCRedraw_WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
6172 static UINT ncredrawflags
;
6178 ncredrawflags
= *(UINT
*) (((CREATESTRUCTA
*)lParam
)->lpCreateParams
);
6181 RedrawWindow(hwnd
, NULL
, NULL
, ncredrawflags
);
6184 BeginPaint(hwnd
, &ps
);
6185 EndPaint(hwnd
, &ps
);
6188 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
6191 static void run_NCRedrawLoop(UINT flags
)
6198 hwnd
= CreateWindowA("TestNCRedrawClass", "MainWindow",
6199 WS_OVERLAPPEDWINDOW
, 0, 0, 200, 100,
6200 NULL
, NULL
, 0, &flags
);
6201 ShowWindow(hwnd
, SW_SHOW
);
6203 flush_events( FALSE
);
6204 while (PeekMessageA(&msg
, hwnd
, 0, 0, PM_REMOVE
))
6206 if (msg
.message
== WM_PAINT
) loopcount
++;
6207 if (loopcount
>= 100) break;
6208 TranslateMessage(&msg
);
6209 DispatchMessageA(&msg
);
6210 MsgWaitForMultipleObjects(0, NULL
, FALSE
, 100, QS_ALLINPUT
);
6212 if (flags
== (RDW_INVALIDATE
| RDW_FRAME
))
6213 todo_wine
ok(loopcount
< 100, "Detected infinite WM_PAINT loop (%x).\n", flags
);
6215 ok(loopcount
< 100, "Detected infinite WM_PAINT loop (%x).\n", flags
);
6216 DestroyWindow(hwnd
);
6219 static void test_NCRedraw(void)
6223 wndclass
.lpszClassName
= "TestNCRedrawClass";
6224 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
6225 wndclass
.lpfnWndProc
= TestNCRedraw_WndProc
;
6226 wndclass
.cbClsExtra
= 0;
6227 wndclass
.cbWndExtra
= 0;
6228 wndclass
.hInstance
= 0;
6229 wndclass
.hIcon
= LoadIconA(0, (LPCSTR
)IDI_APPLICATION
);
6230 wndclass
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
6231 wndclass
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
6232 wndclass
.lpszMenuName
= NULL
;
6234 RegisterClassA(&wndclass
);
6236 run_NCRedrawLoop(RDW_INVALIDATE
| RDW_FRAME
);
6237 run_NCRedrawLoop(RDW_INVALIDATE
);
6240 static void test_GetWindowModuleFileName(void)
6245 char buf1
[MAX_PATH
], buf2
[MAX_PATH
];
6247 if (!pGetWindowModuleFileNameA
)
6249 win_skip("GetWindowModuleFileNameA is not available\n");
6253 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0,0,0,0, 0, 0, 0, NULL
);
6256 hinst
= (HINSTANCE
)GetWindowLongPtrA(hwnd
, GWLP_HINSTANCE
);
6257 ok(hinst
== 0 || broken(hinst
== GetModuleHandleA(NULL
)), /* win9x */ "expected 0, got %p\n", hinst
);
6260 SetLastError(0xdeadbeef);
6261 ret1
= GetModuleFileNameA(hinst
, buf1
, sizeof(buf1
));
6262 ok(ret1
, "GetModuleFileName error %u\n", GetLastError());
6265 SetLastError(0xdeadbeef);
6266 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, sizeof(buf2
));
6267 ok(ret2
|| broken(!ret2
), /* nt4 sp 3 */
6268 "GetWindowModuleFileNameA error %u\n", GetLastError());
6272 ok(ret1
== ret2
|| broken(ret2
== ret1
+ 1), /* win98 */ "%u != %u\n", ret1
, ret2
);
6273 ok(!strcmp(buf1
, buf2
), "%s != %s\n", buf1
, buf2
);
6275 hinst
= GetModuleHandleA(NULL
);
6277 SetLastError(0xdeadbeef);
6278 ret2
= GetModuleFileNameA(hinst
, buf2
, ret1
- 2);
6279 ok(ret2
== ret1
- 2 || broken(ret2
== ret1
- 3), /* win98 */
6280 "expected %u, got %u\n", ret1
- 2, ret2
);
6281 ok(GetLastError() == 0xdeadbeef /* XP */ ||
6282 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
6283 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
6285 SetLastError(0xdeadbeef);
6286 ret2
= GetModuleFileNameA(hinst
, buf2
, 0);
6287 ok(!ret2
, "GetModuleFileName should return 0\n");
6288 ok(GetLastError() == 0xdeadbeef /* XP */ ||
6289 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
6290 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
6292 SetLastError(0xdeadbeef);
6293 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, ret1
- 2);
6294 ok(ret2
== ret1
- 2 || broken(ret2
== ret1
- 3) /* win98 */ || broken(!ret2
), /* nt4 sp3 */
6295 "expected %u, got %u\n", ret1
- 2, ret2
);
6296 ok(GetLastError() == 0xdeadbeef /* XP */ ||
6297 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
6298 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
6300 SetLastError(0xdeadbeef);
6301 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, 0);
6302 ok(!ret2
, "expected 0, got %u\n", ret2
);
6303 ok(GetLastError() == 0xdeadbeef /* XP */ ||
6304 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
6305 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
6307 DestroyWindow(hwnd
);
6310 hwnd
= (HWND
)0xdeadbeef;
6311 SetLastError(0xdeadbeef);
6312 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
6313 ok(!ret1
, "expected 0, got %u\n", ret1
);
6314 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
|| broken(GetLastError() == 0xdeadbeef), /* win9x */
6315 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
6317 hwnd
= FindWindowA("Shell_TrayWnd", NULL
);
6318 ok(IsWindow(hwnd
) || broken(!hwnd
), "got invalid tray window %p\n", hwnd
);
6319 SetLastError(0xdeadbeef);
6320 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
6321 ok(!ret1
|| broken(ret1
), /* win98 */ "expected 0, got %u\n", ret1
);
6323 if (!ret1
) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
6325 ret1
= GetModuleFileNameA(0, buf1
, sizeof(buf1
));
6326 hwnd
= GetDesktopWindow();
6327 ok(IsWindow(hwnd
), "got invalid desktop window %p\n", hwnd
);
6328 SetLastError(0xdeadbeef);
6329 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, sizeof(buf2
));
6331 ret1
== ret2
|| /* vista */
6332 broken(ret2
), /* some win98 return user.exe as file name */
6333 "expected 0 or %u, got %u %s\n", ret1
, ret2
, buf2
);
6337 static void test_hwnd_message(void)
6339 static const WCHAR mainwindowclassW
[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
6340 static const WCHAR message_windowW
[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
6342 HWND parent
= 0, hwnd
, found
;
6345 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
6346 on CreateWindowExA and crash later in the test.
6347 Use UNICODE here to fail on win9x */
6348 hwnd
= CreateWindowExW(0, mainwindowclassW
, message_windowW
, WS_CAPTION
| WS_VISIBLE
,
6349 100, 100, 200, 200, HWND_MESSAGE
, 0, 0, NULL
);
6352 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
6356 ok( !GetParent(hwnd
), "GetParent should return 0 for message only windows\n" );
6360 HWND root
, desktop
= GetDesktopWindow();
6362 parent
= pGetAncestor(hwnd
, GA_PARENT
);
6363 ok(parent
!= 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
6364 ok(parent
!= desktop
, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
6365 root
= pGetAncestor(hwnd
, GA_ROOT
);
6366 ok(root
== hwnd
, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
6367 ok( !pGetAncestor(parent
, GA_PARENT
) || broken(pGetAncestor(parent
, GA_PARENT
) != 0), /* win2k */
6368 "parent shouldn't have parent %p\n", pGetAncestor(parent
, GA_PARENT
) );
6369 trace("parent %p root %p desktop %p\n", parent
, root
, desktop
);
6370 if (!GetClassNameA( parent
, buffer
, sizeof(buffer
) )) buffer
[0] = 0;
6371 ok( !lstrcmpiA( buffer
, "Message" ), "wrong parent class '%s'\n", buffer
);
6372 GetWindowRect( parent
, &rect
);
6373 ok( rect
.left
== 0 && rect
.right
== 100 && rect
.top
== 0 && rect
.bottom
== 100,
6374 "wrong parent rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
6376 GetWindowRect( hwnd
, &rect
);
6377 ok( rect
.left
== 100 && rect
.right
== 300 && rect
.top
== 100 && rect
.bottom
== 300,
6378 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
6380 /* test FindWindow behavior */
6382 found
= FindWindowExA( 0, 0, 0, "message window" );
6383 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
6384 SetLastError(0xdeadbeef);
6385 found
= FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
6386 ok( found
== 0, "found message window %p/%p\n", found
, hwnd
);
6387 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
6390 found
= FindWindowExA( parent
, 0, 0, "message window" );
6391 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
6394 /* test IsChild behavior */
6396 if (parent
) ok( !IsChild( parent
, hwnd
), "HWND_MESSAGE is child of top window\n" );
6398 /* test IsWindowVisible behavior */
6400 ok( !IsWindowVisible( hwnd
), "HWND_MESSAGE window is visible\n" );
6401 if (parent
) ok( !IsWindowVisible( parent
), "HWND_MESSAGE parent is visible\n" );
6403 DestroyWindow(hwnd
);
6406 static void test_layered_window(void)
6412 POINT pt
= { 0, 0 };
6413 SIZE sz
= { 200, 200 };
6418 if (!pGetLayeredWindowAttributes
|| !pSetLayeredWindowAttributes
|| !pUpdateLayeredWindow
)
6420 win_skip( "layered windows not supported\n" );
6424 hdc
= CreateCompatibleDC( 0 );
6425 hbm
= CreateCompatibleBitmap( hdc
, 200, 200 );
6426 SelectObject( hdc
, hbm
);
6428 hwnd
= CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION
,
6429 100, 100, 200, 200, 0, 0, 0, NULL
);
6431 SetLastError( 0xdeadbeef );
6432 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
);
6433 ok( !ret
, "UpdateLayeredWindow should fail on non-layered window\n" );
6434 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
6435 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
6436 ok( !ret
, "GetLayeredWindowAttributes should fail on non-layered window\n" );
6437 ret
= pSetLayeredWindowAttributes( hwnd
, 0, 0, LWA_ALPHA
);
6438 ok( !ret
, "SetLayeredWindowAttributes should fail on non-layered window\n" );
6439 SetWindowLongA( hwnd
, GWL_EXSTYLE
, GetWindowLongA(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
6440 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
6441 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
6442 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
);
6443 ok( ret
, "UpdateLayeredWindow should succeed on layered window\n" );
6444 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
6445 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
6446 ret
= pSetLayeredWindowAttributes( hwnd
, 0x123456, 44, LWA_ALPHA
);
6447 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
6448 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
6449 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
6450 ok( key
== 0x123456 || key
== 0, "wrong color key %x\n", key
);
6451 ok( alpha
== 44, "wrong alpha %u\n", alpha
);
6452 ok( flags
== LWA_ALPHA
, "wrong flags %x\n", flags
);
6453 SetLastError( 0xdeadbeef );
6454 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
);
6455 ok( !ret
, "UpdateLayeredWindow should fail on layered but initialized window\n" );
6456 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
6458 /* clearing WS_EX_LAYERED resets attributes */
6459 SetWindowLongA( hwnd
, GWL_EXSTYLE
, GetWindowLongA(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
6460 SetLastError( 0xdeadbeef );
6461 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
);
6462 ok( !ret
, "UpdateLayeredWindow should fail on non-layered window\n" );
6463 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
6464 ok( !ret
, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
6465 SetWindowLongA( hwnd
, GWL_EXSTYLE
, GetWindowLongA(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
6466 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
6467 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
6468 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
);
6469 ok( ret
, "UpdateLayeredWindow should succeed on layered window\n" );
6470 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
| ULW_EX_NORESIZE
);
6471 ok( !ret
, "UpdateLayeredWindow should fail with ex flag\n" );
6472 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %u\n", GetLastError() );
6473 if (pUpdateLayeredWindowIndirect
)
6475 UPDATELAYEREDWINDOWINFO info
;
6476 info
.cbSize
= sizeof(info
);
6484 info
.dwFlags
= ULW_OPAQUE
| ULW_EX_NORESIZE
;
6485 info
.prcDirty
= NULL
;
6486 ret
= pUpdateLayeredWindowIndirect( hwnd
, &info
);
6487 ok( ret
, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
6490 ret
= pUpdateLayeredWindowIndirect( hwnd
, &info
);
6491 ok( !ret
, "UpdateLayeredWindowIndirect should fail\n" );
6492 /* particular error code differs from version to version, could be ERROR_INCORRECT_SIZE,
6493 ERROR_MR_MID_NOT_FOUND or ERROR_GEN_FAILURE (Win8/Win10) */
6494 ok( GetLastError() != 0, "wrong error %u\n", GetLastError() );
6495 info
.dwFlags
= ULW_OPAQUE
;
6496 ret
= pUpdateLayeredWindowIndirect( hwnd
, &info
);
6497 ok( ret
, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
6499 info
.dwFlags
= ULW_OPAQUE
| 0xf00;
6500 ret
= pUpdateLayeredWindowIndirect( hwnd
, &info
);
6501 ok( !ret
, "UpdateLayeredWindowIndirect should fail\n" );
6502 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %u\n", GetLastError() );
6504 info
.dwFlags
= ULW_OPAQUE
;
6505 ret
= pUpdateLayeredWindowIndirect( hwnd
, &info
);
6506 ok( !ret
, "UpdateLayeredWindowIndirect should fail\n" );
6507 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %u\n", GetLastError() );
6508 ret
= pUpdateLayeredWindowIndirect( hwnd
, NULL
);
6509 ok( !ret
, "UpdateLayeredWindowIndirect should fail\n" );
6510 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %u\n", GetLastError() );
6513 ret
= pSetLayeredWindowAttributes( hwnd
, 0x654321, 22, LWA_COLORKEY
| LWA_ALPHA
);
6514 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
6515 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
6516 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
6517 ok( key
== 0x654321, "wrong color key %x\n", key
);
6518 ok( alpha
== 22, "wrong alpha %u\n", alpha
);
6519 ok( flags
== (LWA_COLORKEY
| LWA_ALPHA
), "wrong flags %x\n", flags
);
6520 SetLastError( 0xdeadbeef );
6521 ret
= pUpdateLayeredWindow( hwnd
, 0, NULL
, &sz
, hdc
, &pt
, 0, NULL
, ULW_OPAQUE
);
6522 ok( !ret
, "UpdateLayeredWindow should fail on layered but initialized window\n" );
6523 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
6525 ret
= pSetLayeredWindowAttributes( hwnd
, 0x888888, 33, LWA_COLORKEY
);
6526 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
6528 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
6529 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
6530 ok( key
== 0x888888, "wrong color key %x\n", key
);
6531 /* alpha not changed on vista if LWA_ALPHA is not set */
6532 ok( alpha
== 22 || alpha
== 33, "wrong alpha %u\n", alpha
);
6533 ok( flags
== LWA_COLORKEY
, "wrong flags %x\n", flags
);
6535 /* color key may or may not be changed without LWA_COLORKEY */
6536 ret
= pSetLayeredWindowAttributes( hwnd
, 0x999999, 44, 0 );
6537 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
6539 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
6540 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
6541 ok( key
== 0x888888 || key
== 0x999999, "wrong color key %x\n", key
);
6542 ok( alpha
== 22 || alpha
== 44, "wrong alpha %u\n", alpha
);
6543 ok( flags
== 0, "wrong flags %x\n", flags
);
6545 /* default alpha and color key is 0 */
6546 SetWindowLongA( hwnd
, GWL_EXSTYLE
, GetWindowLongA(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
6547 SetWindowLongA( hwnd
, GWL_EXSTYLE
, GetWindowLongA(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
6548 ret
= pSetLayeredWindowAttributes( hwnd
, 0x222222, 55, 0 );
6549 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
6550 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
6551 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
6552 ok( key
== 0 || key
== 0x222222, "wrong color key %x\n", key
);
6553 ok( alpha
== 0 || alpha
== 55, "wrong alpha %u\n", alpha
);
6554 ok( flags
== 0, "wrong flags %x\n", flags
);
6556 DestroyWindow( hwnd
);
6558 DeleteObject( hbm
);
6561 static MONITORINFO mi
;
6563 static LRESULT CALLBACK
fullscreen_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
6569 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
6570 ok(cs
->x
== mi
.rcMonitor
.left
&& cs
->y
== mi
.rcMonitor
.top
&&
6571 cs
->cx
== mi
.rcMonitor
.right
&& cs
->cy
== mi
.rcMonitor
.bottom
,
6572 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
6573 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
6574 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
6577 case WM_GETMINMAXINFO
:
6579 MINMAXINFO
*minmax
= (MINMAXINFO
*)lp
;
6580 ok(minmax
->ptMaxPosition
.x
<= mi
.rcMonitor
.left
, "%d <= %d\n", minmax
->ptMaxPosition
.x
, mi
.rcMonitor
.left
);
6581 ok(minmax
->ptMaxPosition
.y
<= mi
.rcMonitor
.top
, "%d <= %d\n", minmax
->ptMaxPosition
.y
, mi
.rcMonitor
.top
);
6582 ok(minmax
->ptMaxSize
.x
>= mi
.rcMonitor
.right
, "%d >= %d\n", minmax
->ptMaxSize
.x
, mi
.rcMonitor
.right
);
6583 ok(minmax
->ptMaxSize
.y
>= mi
.rcMonitor
.bottom
, "%d >= %d\n", minmax
->ptMaxSize
.y
, mi
.rcMonitor
.bottom
);
6587 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
6590 static void test_fullscreen(void)
6592 static const DWORD t_style
[] = {
6593 WS_OVERLAPPED
, WS_POPUP
, WS_CHILD
, WS_THICKFRAME
, WS_DLGFRAME
6595 static const DWORD t_ex_style
[] = {
6596 0, WS_EX_APPWINDOW
, WS_EX_TOOLWINDOW
6606 if (!pGetMonitorInfoA
|| !pMonitorFromPoint
)
6608 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
6613 SetLastError(0xdeadbeef);
6614 hmon
= pMonitorFromPoint(pt
, MONITOR_DEFAULTTOPRIMARY
);
6615 ok(hmon
!= 0, "MonitorFromPoint error %u\n", GetLastError());
6617 mi
.cbSize
= sizeof(mi
);
6618 SetLastError(0xdeadbeef);
6619 ret
= pGetMonitorInfoA(hmon
, &mi
);
6620 ok(ret
, "GetMonitorInfo error %u\n", GetLastError());
6621 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
6622 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
6623 mi
.rcWork
.left
, mi
.rcWork
.top
, mi
.rcWork
.right
, mi
.rcWork
.bottom
);
6626 cls
.lpfnWndProc
= fullscreen_wnd_proc
;
6629 cls
.hInstance
= GetModuleHandleA(NULL
);
6631 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
6632 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
6633 cls
.lpszMenuName
= NULL
;
6634 cls
.lpszClassName
= "fullscreen_class";
6635 RegisterClassA(&cls
);
6637 for (i
= 0; i
< sizeof(t_style
)/sizeof(t_style
[0]); i
++)
6639 DWORD style
, ex_style
;
6641 /* avoid a WM interaction */
6642 assert(!(t_style
[i
] & WS_VISIBLE
));
6644 for (j
= 0; j
< sizeof(t_ex_style
)/sizeof(t_ex_style
[0]); j
++)
6649 ex_style
= t_ex_style
[j
];
6651 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
6652 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
6653 GetDesktopWindow(), 0, GetModuleHandleA(NULL
), NULL
);
6654 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
6655 GetWindowRect(hwnd
, &rc
);
6656 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
6657 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
6658 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
6659 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
6660 DestroyWindow(hwnd
);
6662 style
= t_style
[i
] | WS_MAXIMIZE
;
6663 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
6664 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
6665 GetDesktopWindow(), 0, GetModuleHandleA(NULL
), NULL
);
6666 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
6667 GetWindowRect(hwnd
, &rc
);
6668 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
6669 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
6670 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
6671 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
6672 DestroyWindow(hwnd
);
6674 style
= t_style
[i
] | WS_MAXIMIZE
| WS_CAPTION
;
6675 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
6676 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
6677 GetDesktopWindow(), 0, GetModuleHandleA(NULL
), NULL
);
6678 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
6679 GetWindowRect(hwnd
, &rc
);
6680 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
6681 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
6682 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
6683 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
6684 DestroyWindow(hwnd
);
6686 style
= t_style
[i
] | WS_CAPTION
| WS_MAXIMIZEBOX
;
6687 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
6688 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
6689 GetDesktopWindow(), 0, GetModuleHandleA(NULL
), NULL
);
6690 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
6691 GetWindowRect(hwnd
, &rc
);
6692 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
6693 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
6694 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
6695 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
6696 DestroyWindow(hwnd
);
6698 style
= t_style
[i
] | WS_MAXIMIZE
| WS_CAPTION
| WS_MAXIMIZEBOX
;
6699 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
6700 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
6701 GetDesktopWindow(), 0, GetModuleHandleA(NULL
), NULL
);
6702 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
6703 GetWindowRect(hwnd
, &rc
);
6704 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
6705 /* Windows makes a maximized window slightly larger (to hide the borders?) */
6706 fixup
= min(abs(rc
.left
), abs(rc
.top
));
6707 InflateRect(&rc
, -fixup
, -fixup
);
6708 ok(rc
.left
>= mi
.rcWork
.left
&& rc
.top
<= mi
.rcWork
.top
&&
6709 rc
.right
<= mi
.rcWork
.right
&& rc
.bottom
<= mi
.rcWork
.bottom
,
6710 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
6711 ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
6712 mi
.rcWork
.left
, mi
.rcWork
.top
, mi
.rcWork
.right
, mi
.rcWork
.bottom
);
6713 DestroyWindow(hwnd
);
6715 style
= t_style
[i
] | WS_MAXIMIZE
| WS_MAXIMIZEBOX
;
6716 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
6717 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
6718 GetDesktopWindow(), 0, GetModuleHandleA(NULL
), NULL
);
6719 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
6720 GetWindowRect(hwnd
, &rc
);
6721 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
6722 /* Windows makes a maximized window slightly larger (to hide the borders?) */
6723 fixup
= min(abs(rc
.left
), abs(rc
.top
));
6724 InflateRect(&rc
, -fixup
, -fixup
);
6725 if (style
& (WS_CHILD
| WS_POPUP
))
6726 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
6727 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
6728 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
6730 ok(rc
.left
>= mi
.rcWork
.left
&& rc
.top
<= mi
.rcWork
.top
&&
6731 rc
.right
<= mi
.rcWork
.right
&& rc
.bottom
<= mi
.rcWork
.bottom
,
6732 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
6733 DestroyWindow(hwnd
);
6737 UnregisterClassA("fullscreen_class", GetModuleHandleA(NULL
));
6740 static BOOL test_thick_child_got_minmax
;
6741 static const char * test_thick_child_name
;
6742 static LONG test_thick_child_style
;
6743 static LONG test_thick_child_exStyle
;
6745 static LRESULT WINAPI
test_thick_child_size_winproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
6748 int expectedMinTrackX
;
6749 int expectedMinTrackY
;
6750 int actualMinTrackX
;
6751 int actualMinTrackY
;
6752 int expectedMaxTrackX
;
6753 int expectedMaxTrackY
;
6754 int actualMaxTrackX
;
6755 int actualMaxTrackY
;
6756 int expectedMaxSizeX
;
6757 int expectedMaxSizeY
;
6768 case WM_GETMINMAXINFO
:
6770 minmax
= (MINMAXINFO
*)lparam
;
6771 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
6772 dump_minmax_info( minmax
);
6774 test_thick_child_got_minmax
= TRUE
;
6777 adjustedStyle
= test_thick_child_style
;
6778 if ((adjustedStyle
& WS_CAPTION
) == WS_CAPTION
)
6779 adjustedStyle
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
6780 GetClientRect(GetParent(hwnd
), &rect
);
6781 AdjustWindowRectEx(&rect
, adjustedStyle
, FALSE
, test_thick_child_exStyle
);
6783 if (test_thick_child_style
& (WS_DLGFRAME
| WS_BORDER
))
6785 expectedMinTrackX
= GetSystemMetrics(SM_CXMINTRACK
);
6786 expectedMinTrackY
= GetSystemMetrics(SM_CYMINTRACK
);
6790 expectedMinTrackX
= -2 * rect
.left
;
6791 expectedMinTrackY
= -2 * rect
.top
;
6793 actualMinTrackX
= minmax
->ptMinTrackSize
.x
;
6794 actualMinTrackY
= minmax
->ptMinTrackSize
.y
;
6796 ok(actualMinTrackX
== expectedMinTrackX
&& actualMinTrackY
== expectedMinTrackY
,
6797 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
6798 expectedMinTrackX
, expectedMinTrackY
, actualMinTrackX
, actualMinTrackY
,
6799 test_thick_child_name
);
6801 actualMaxTrackX
= minmax
->ptMaxTrackSize
.x
;
6802 actualMaxTrackY
= minmax
->ptMaxTrackSize
.y
;
6803 expectedMaxTrackX
= GetSystemMetrics(SM_CXMAXTRACK
);
6804 expectedMaxTrackY
= GetSystemMetrics(SM_CYMAXTRACK
);
6805 ok(actualMaxTrackX
== expectedMaxTrackX
&& actualMaxTrackY
== expectedMaxTrackY
,
6806 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
6807 expectedMaxTrackX
, expectedMaxTrackY
, actualMaxTrackX
, actualMaxTrackY
,
6808 test_thick_child_name
);
6810 expectedMaxSizeX
= rect
.right
- rect
.left
;
6811 expectedMaxSizeY
= rect
.bottom
- rect
.top
;
6812 actualMaxSizeX
= minmax
->ptMaxSize
.x
;
6813 actualMaxSizeY
= minmax
->ptMaxSize
.y
;
6815 ok(actualMaxSizeX
== expectedMaxSizeX
&& actualMaxSizeY
== expectedMaxSizeY
,
6816 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
6817 expectedMaxSizeX
, expectedMaxSizeY
, actualMaxSizeX
, actualMaxSizeY
,
6818 test_thick_child_name
);
6821 expectedPosX
= rect
.left
;
6822 expectedPosY
= rect
.top
;
6823 actualPosX
= minmax
->ptMaxPosition
.x
;
6824 actualPosY
= minmax
->ptMaxPosition
.y
;
6825 ok(actualPosX
== expectedPosX
&& actualPosY
== expectedPosY
,
6826 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
6827 expectedPosX
, expectedPosY
, actualPosX
, actualPosY
, test_thick_child_name
);
6833 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
6836 #define NUMBER_OF_THICK_CHILD_TESTS 16
6837 static void test_thick_child_size(HWND parentWindow
)
6841 RECT adjustedParentRect
;
6846 LONG expectedHeight
;
6848 static const char className
[] = "THICK_CHILD_CLASS";
6851 static const LONG styles
[NUMBER_OF_THICK_CHILD_TESTS
] = {
6852 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
6853 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
6854 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
6855 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
6856 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
6857 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
6858 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
6859 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
6860 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
6861 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
6862 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
6863 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
6864 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
6865 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
6866 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
6867 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
6870 static const LONG exStyles
[NUMBER_OF_THICK_CHILD_TESTS
] = {
6875 WS_EX_DLGMODALFRAME
,
6876 WS_EX_DLGMODALFRAME
,
6877 WS_EX_DLGMODALFRAME
,
6878 WS_EX_DLGMODALFRAME
,
6883 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
6884 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
6885 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
6886 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
6888 static const char *styleName
[NUMBER_OF_THICK_CHILD_TESTS
] = {
6889 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
6890 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
6891 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
6892 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
6893 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
6894 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
6895 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
6896 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
6897 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
6898 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
6899 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
6900 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
6901 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6902 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6903 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6904 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6908 cls
.lpfnWndProc
= test_thick_child_size_winproc
;
6911 cls
.hInstance
= GetModuleHandleA(0);
6913 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
6914 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
6915 cls
.lpszMenuName
= NULL
;
6916 cls
.lpszClassName
= className
;
6917 SetLastError(0xdeadbeef);
6918 success
= RegisterClassA(&cls
);
6919 ok(success
,"RegisterClassA failed, error: %u\n", GetLastError());
6921 for(i
= 0; i
< NUMBER_OF_THICK_CHILD_TESTS
; i
++)
6923 test_thick_child_name
= styleName
[i
];
6924 test_thick_child_style
= styles
[i
];
6925 test_thick_child_exStyle
= exStyles
[i
];
6926 test_thick_child_got_minmax
= FALSE
;
6928 SetLastError(0xdeadbeef);
6929 childWindow
= CreateWindowExA( exStyles
[i
], className
, "", styles
[i
], 0, 0, 0, 0, parentWindow
, 0, GetModuleHandleA(0), NULL
);
6930 ok(childWindow
!= NULL
, "Failed to create child window, error: %u\n", GetLastError());
6932 ok(test_thick_child_got_minmax
, "Got no WM_GETMINMAXINFO\n");
6934 SetLastError(0xdeadbeef);
6935 success
= GetWindowRect(childWindow
, &childRect
);
6936 ok(success
,"GetWindowRect call failed, error: %u\n", GetLastError());
6937 childWidth
= childRect
.right
- childRect
.left
;
6938 childHeight
= childRect
.bottom
- childRect
.top
;
6940 adjustedStyle
= styles
[i
];
6941 if ((adjustedStyle
& WS_CAPTION
) == WS_CAPTION
)
6942 adjustedStyle
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
6943 GetClientRect(GetParent(childWindow
), &adjustedParentRect
);
6944 AdjustWindowRectEx(&adjustedParentRect
, adjustedStyle
, FALSE
, test_thick_child_exStyle
);
6947 if (test_thick_child_style
& (WS_DLGFRAME
| WS_BORDER
))
6949 expectedWidth
= GetSystemMetrics(SM_CXMINTRACK
);
6950 expectedHeight
= GetSystemMetrics(SM_CYMINTRACK
);
6954 expectedWidth
= -2 * adjustedParentRect
.left
;
6955 expectedHeight
= -2 * adjustedParentRect
.top
;
6958 ok((childWidth
== expectedWidth
) && (childHeight
== expectedHeight
),
6959 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
6960 test_thick_child_name
, expectedWidth
, expectedHeight
, childWidth
, childHeight
);
6962 SetLastError(0xdeadbeef);
6963 success
= DestroyWindow(childWindow
);
6964 ok(success
,"DestroyWindow call failed, error: %u\n", GetLastError());
6966 ok(UnregisterClassA(className
, GetModuleHandleA(NULL
)),"UnregisterClass call failed\n");
6969 static void test_handles( HWND full_hwnd
)
6971 HWND hwnd
= full_hwnd
;
6975 SetLastError( 0xdeadbeef );
6976 ret
= GetWindowRect( hwnd
, &rect
);
6977 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
6980 if ((ULONG_PTR
)full_hwnd
>> 32)
6981 hwnd
= (HWND
)((ULONG_PTR
)full_hwnd
& ~0u);
6983 hwnd
= (HWND
)((ULONG_PTR
)full_hwnd
| ((ULONG_PTR
)~0u << 32));
6984 SetLastError( 0xdeadbeef );
6985 ret
= GetWindowRect( hwnd
, &rect
);
6986 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
6988 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& ~0u) | ((ULONG_PTR
)0x1234 << 32));
6989 SetLastError( 0xdeadbeef );
6990 ret
= GetWindowRect( hwnd
, &rect
);
6991 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
6993 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& 0xffff) | ((ULONG_PTR
)0x9876 << 16));
6994 SetLastError( 0xdeadbeef );
6995 ret
= GetWindowRect( hwnd
, &rect
);
6996 ok( !ret
, "GetWindowRect succeeded for %p\n", hwnd
);
6997 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "wrong error %u\n", GetLastError() );
6999 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& 0xffff) | ((ULONG_PTR
)0x12345678 << 16));
7000 SetLastError( 0xdeadbeef );
7001 ret
= GetWindowRect( hwnd
, &rect
);
7002 ok( !ret
, "GetWindowRect succeeded for %p\n", hwnd
);
7003 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "wrong error %u\n", GetLastError() );
7007 static void test_winregion(void)
7014 if (!pGetWindowRgnBox
)
7016 win_skip("GetWindowRgnBox not supported\n");
7020 hwnd
= CreateWindowExA(0, "static", NULL
, WS_VISIBLE
, 10, 10, 10, 10, NULL
, 0, 0, NULL
);
7022 SetLastError(0xdeadbeef);
7023 ret
= pGetWindowRgnBox(hwnd
, NULL
);
7024 ok( ret
== ERROR
, "Expected ERROR, got %d\n", ret
);
7025 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
7027 hrgn
= CreateRectRgn(2, 3, 10, 15);
7028 ok( hrgn
!= NULL
, "Region creation failed\n");
7031 SetWindowRgn(hwnd
, hrgn
, FALSE
);
7033 SetLastError(0xdeadbeef);
7034 ret
= pGetWindowRgnBox(hwnd
, NULL
);
7035 ok( ret
== ERROR
, "Expected ERROR, got %d\n", ret
);
7036 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
7038 r
.left
= r
.top
= r
.right
= r
.bottom
= 0;
7039 ret
= pGetWindowRgnBox(hwnd
, &r
);
7040 ok( ret
== SIMPLEREGION
, "Expected SIMPLEREGION, got %d\n", ret
);
7041 ok( r
.left
== 2 && r
.top
== 3 && r
.right
== 10 && r
.bottom
== 15,
7042 "Expected (2,3,10,15), got (%d,%d,%d,%d)\n", r
.left
, r
.top
,
7046 hrgn
= CreateRectRgn(2, 3, 10, 15);
7047 ret
= pMirrorRgn( hwnd
, hrgn
);
7048 ok( ret
== TRUE
, "MirrorRgn failed %u\n", ret
);
7049 r
.left
= r
.top
= r
.right
= r
.bottom
= 0;
7050 GetWindowRect( hwnd
, &r
);
7051 width
= r
.right
- r
.left
;
7052 r
.left
= r
.top
= r
.right
= r
.bottom
= 0;
7053 ret
= GetRgnBox( hrgn
, &r
);
7054 ok( ret
== SIMPLEREGION
, "GetRgnBox failed %u\n", ret
);
7055 ok( r
.left
== width
- 10 && r
.top
== 3 && r
.right
== width
- 2 && r
.bottom
== 15,
7056 "Wrong rectangle (%d,%d,%d,%d) for width %d\n", r
.left
, r
.top
, r
.right
, r
.bottom
, width
);
7058 else win_skip( "MirrorRgn not supported\n" );
7060 DestroyWindow(hwnd
);
7063 static void test_rtl_layout(void)
7069 if (!pSetProcessDefaultLayout
)
7071 win_skip( "SetProcessDefaultLayout not supported\n" );
7075 parent
= CreateWindowExA(WS_EX_LAYOUTRTL
, "static", NULL
, WS_POPUP
, 100, 100, 300, 300, NULL
, 0, 0, NULL
);
7076 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 10, 10, 20, 20, parent
, 0, 0, NULL
);
7078 GetWindowRect( parent
, &r
);
7079 ok( r
.left
== 100 && r
.right
== 400, "wrong rect %d,%d - %d,%d\n", r
.left
, r
.top
, r
.right
, r
.bottom
);
7080 GetClientRect( parent
, &r
);
7081 ok( r
.left
== 0 && r
.right
== 300, "wrong rect %d,%d - %d,%d\n", r
.left
, r
.top
, r
.right
, r
.bottom
);
7082 GetClientRect( child
, &r
);
7083 ok( r
.left
== 0 && r
.right
== 20, "wrong rect %d,%d - %d,%d\n", r
.left
, r
.top
, r
.right
, r
.bottom
);
7084 MapWindowPoints( child
, parent
, (POINT
*)&r
, 2 );
7085 ok( r
.left
== 10 && r
.right
== 30, "wrong rect %d,%d - %d,%d\n", r
.left
, r
.top
, r
.right
, r
.bottom
);
7086 GetWindowRect( child
, &r
);
7087 ok( r
.left
== 370 && r
.right
== 390, "wrong rect %d,%d - %d,%d\n", r
.left
, r
.top
, r
.right
, r
.bottom
);
7088 MapWindowPoints( NULL
, parent
, (POINT
*)&r
, 2 );
7089 ok( r
.left
== 10 && r
.right
== 30, "wrong rect %d,%d - %d,%d\n", r
.left
, r
.top
, r
.right
, r
.bottom
);
7090 GetWindowRect( child
, &r
);
7091 MapWindowPoints( NULL
, parent
, (POINT
*)&r
, 1 );
7092 MapWindowPoints( NULL
, parent
, (POINT
*)&r
+ 1, 1 );
7093 ok( r
.left
== 30 && r
.right
== 10, "wrong rect %d,%d - %d,%d\n", r
.left
, r
.top
, r
.right
, r
.bottom
);
7095 MapWindowPoints( child
, parent
, &pt
, 1 );
7096 ok( pt
.x
== 22 && pt
.y
== 22, "wrong point %d,%d\n", pt
.x
, pt
.y
);
7097 SetWindowPos( parent
, 0, 0, 0, 250, 250, SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
7098 GetWindowRect( parent
, &r
);
7099 ok( r
.left
== 100 && r
.right
== 350, "wrong rect %d,%d - %d,%d\n", r
.left
, r
.top
, r
.right
, r
.bottom
);
7100 GetWindowRect( child
, &r
);
7101 ok( r
.left
== 320 && r
.right
== 340, "wrong rect %d,%d - %d,%d\n", r
.left
, r
.top
, r
.right
, r
.bottom
);
7102 SetWindowLongW( parent
, GWL_EXSTYLE
, 0 );
7103 GetWindowRect( child
, &r
);
7104 ok( r
.left
== 320 && r
.right
== 340, "wrong rect %d,%d - %d,%d\n", r
.left
, r
.top
, r
.right
, r
.bottom
);
7105 MapWindowPoints( NULL
, parent
, (POINT
*)&r
, 2 );
7106 ok( r
.left
== 220 && r
.right
== 240, "wrong rect %d,%d - %d,%d\n", r
.left
, r
.top
, r
.right
, r
.bottom
);
7107 SetWindowLongW( parent
, GWL_EXSTYLE
, WS_EX_LAYOUTRTL
);
7108 GetWindowRect( child
, &r
);
7109 ok( r
.left
== 320 && r
.right
== 340, "wrong rect %d,%d - %d,%d\n", r
.left
, r
.top
, r
.right
, r
.bottom
);
7110 MapWindowPoints( NULL
, parent
, (POINT
*)&r
, 2 );
7111 ok( r
.left
== 10 && r
.right
== 30, "wrong rect %d,%d - %d,%d\n", r
.left
, r
.top
, r
.right
, r
.bottom
);
7112 SetWindowPos( child
, 0, 0, 0, 30, 30, SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
7113 GetWindowRect( child
, &r
);
7114 ok( r
.left
== 310 && r
.right
== 340, "wrong rect %d,%d - %d,%d\n", r
.left
, r
.top
, r
.right
, r
.bottom
);
7115 MapWindowPoints( NULL
, parent
, (POINT
*)&r
, 2 );
7116 ok( r
.left
== 10 && r
.right
== 40, "wrong rect %d,%d - %d,%d\n", r
.left
, r
.top
, r
.right
, r
.bottom
);
7117 DestroyWindow( child
);
7118 DestroyWindow( parent
);
7121 static void test_FlashWindow(void)
7127 win_skip( "FlashWindow not supported\n" );
7131 hwnd
= CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_POPUP
,
7132 0, 0, 0, 0, 0, 0, 0, NULL
);
7133 ok( hwnd
!= 0, "CreateWindowExA error %d\n", GetLastError() );
7135 SetLastError( 0xdeadbeef );
7136 ret
= pFlashWindow( NULL
, TRUE
);
7137 ok( !ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
7138 "FlashWindow returned with %d\n", GetLastError() );
7140 DestroyWindow( hwnd
);
7142 SetLastError( 0xdeadbeef );
7143 ret
= pFlashWindow( hwnd
, TRUE
);
7144 ok( !ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
7145 "FlashWindow returned with %d\n", GetLastError() );
7148 static void test_FlashWindowEx(void)
7154 if (!pFlashWindowEx
)
7156 win_skip( "FlashWindowEx not supported\n" );
7160 hwnd
= CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_POPUP
,
7161 0, 0, 0, 0, 0, 0, 0, NULL
);
7162 ok( hwnd
!= 0, "CreateWindowExA error %d\n", GetLastError() );
7164 finfo
.cbSize
= sizeof(FLASHWINFO
);
7165 finfo
.dwFlags
= FLASHW_TIMER
;
7167 finfo
.dwTimeout
= 200;
7169 SetLastError(0xdeadbeef);
7170 ret
= pFlashWindowEx(&finfo
);
7171 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
7172 "FlashWindowEx returned with %d\n", GetLastError());
7175 SetLastError(0xdeadbeef);
7176 ret
= pFlashWindowEx(NULL
);
7177 ok(!ret
&& GetLastError() == ERROR_NOACCESS
,
7178 "FlashWindowEx returned with %d\n", GetLastError());
7180 SetLastError(0xdeadbeef);
7181 ret
= pFlashWindowEx(&finfo
);
7182 todo_wine
ok(!ret
, "previous window state should not be active\n");
7184 finfo
.cbSize
= sizeof(FLASHWINFO
) - 1;
7185 SetLastError(0xdeadbeef);
7186 ret
= pFlashWindowEx(&finfo
);
7187 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
7188 "FlashWindowEx succeeded\n");
7190 finfo
.cbSize
= sizeof(FLASHWINFO
) + 1;
7191 SetLastError(0xdeadbeef);
7192 ret
= pFlashWindowEx(&finfo
);
7193 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
7194 "FlashWindowEx succeeded\n");
7195 finfo
.cbSize
= sizeof(FLASHWINFO
);
7197 DestroyWindow( hwnd
);
7199 SetLastError(0xdeadbeef);
7200 ret
= pFlashWindowEx(&finfo
);
7201 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
7202 "FlashWindowEx returned with %d\n", GetLastError());
7204 ok(finfo
.cbSize
== sizeof(FLASHWINFO
), "FlashWindowEx modified cdSize to %x\n", finfo
.cbSize
);
7205 ok(finfo
.hwnd
== hwnd
, "FlashWindowEx modified hwnd to %p\n", finfo
.hwnd
);
7206 ok(finfo
.dwFlags
== FLASHW_TIMER
, "FlashWindowEx modified dwFlags to %x\n", finfo
.dwFlags
);
7207 ok(finfo
.uCount
== 3, "FlashWindowEx modified uCount to %x\n", finfo
.uCount
);
7208 ok(finfo
.dwTimeout
== 200, "FlashWindowEx modified dwTimeout to %x\n", finfo
.dwTimeout
);
7210 hwnd
= CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_VISIBLE
| WS_POPUPWINDOW
,
7211 0, 0, 0, 0, 0, 0, 0, NULL
);
7212 ok( hwnd
!= 0, "CreateWindowExA error %d\n", GetLastError() );
7215 SetLastError(0xdeadbeef);
7216 ret
= pFlashWindowEx(NULL
);
7217 ok(!ret
&& GetLastError() == ERROR_NOACCESS
,
7218 "FlashWindowEx returned with %d\n", GetLastError());
7220 SetLastError(0xdeadbeef);
7221 prev
= pFlashWindowEx(&finfo
);
7223 ok(finfo
.cbSize
== sizeof(FLASHWINFO
), "FlashWindowEx modified cdSize to %x\n", finfo
.cbSize
);
7224 ok(finfo
.hwnd
== hwnd
, "FlashWindowEx modified hwnd to %p\n", finfo
.hwnd
);
7225 ok(finfo
.dwFlags
== FLASHW_TIMER
, "FlashWindowEx modified dwFlags to %x\n", finfo
.dwFlags
);
7226 ok(finfo
.uCount
== 3, "FlashWindowEx modified uCount to %x\n", finfo
.uCount
);
7227 ok(finfo
.dwTimeout
== 200, "FlashWindowEx modified dwTimeout to %x\n", finfo
.dwTimeout
);
7229 finfo
.dwFlags
= FLASHW_STOP
;
7230 SetLastError(0xdeadbeef);
7231 ret
= pFlashWindowEx(&finfo
);
7232 ok(prev
!= ret
, "previous window state should be different\n");
7234 DestroyWindow( hwnd
);
7237 static void test_FindWindowEx(void)
7241 hwnd
= CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP
, 0,0,0,0, 0, 0, 0, NULL
);
7242 ok( hwnd
!= 0, "CreateWindowExA error %d\n", GetLastError() );
7244 num_gettext_msgs
= 0;
7245 found
= FindWindowExA( 0, 0, "MainWindowClass", "" );
7246 ok( found
== NULL
, "expected a NULL hwnd\n" );
7247 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
7249 num_gettext_msgs
= 0;
7250 found
= FindWindowExA( 0, 0, "MainWindowClass", NULL
);
7251 ok( found
== hwnd
, "found is %p, expected a valid hwnd\n", found
);
7252 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
7254 num_gettext_msgs
= 0;
7255 found
= FindWindowExA( 0, 0, "MainWindowClass", "caption" );
7256 ok( found
== hwnd
, "found is %p, expected a valid hwnd\n", found
);
7257 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
7259 DestroyWindow( hwnd
);
7261 hwnd
= CreateWindowExA( 0, "MainWindowClass", NULL
, WS_POPUP
, 0,0,0,0, 0, 0, 0, NULL
);
7262 ok( hwnd
!= 0, "CreateWindowExA error %d\n", GetLastError() );
7264 num_gettext_msgs
= 0;
7265 found
= FindWindowExA( 0, 0, "MainWindowClass", "" );
7266 ok( found
== hwnd
, "found is %p, expected a valid hwnd\n", found
);
7267 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
7269 num_gettext_msgs
= 0;
7270 found
= FindWindowExA( 0, 0, "MainWindowClass", NULL
);
7271 ok( found
== hwnd
, "found is %p, expected a valid hwnd\n", found
);
7272 ok( num_gettext_msgs
== 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs
);
7274 DestroyWindow( hwnd
);
7276 /* test behaviour with a window title that is an empty character */
7277 found
= FindWindowExA( 0, 0, "Shell_TrayWnd", "" );
7278 ok( found
!= NULL
, "found is NULL, expected a valid hwnd\n" );
7279 found
= FindWindowExA( 0, 0, "Shell_TrayWnd", NULL
);
7280 ok( found
!= NULL
, "found is NULL, expected a valid hwnd\n" );
7283 static void test_GetLastActivePopup(void)
7285 HWND hwndOwner
, hwndPopup1
, hwndPopup2
;
7287 hwndOwner
= CreateWindowExA(0, "MainWindowClass", NULL
,
7288 WS_VISIBLE
| WS_POPUPWINDOW
,
7290 NULL
, 0, GetModuleHandleA(NULL
), NULL
);
7291 hwndPopup1
= CreateWindowExA(0, "MainWindowClass", NULL
,
7292 WS_VISIBLE
| WS_POPUPWINDOW
,
7294 hwndOwner
, 0, GetModuleHandleA(NULL
), NULL
);
7295 hwndPopup2
= CreateWindowExA(0, "MainWindowClass", NULL
,
7296 WS_VISIBLE
| WS_POPUPWINDOW
,
7298 hwndPopup1
, 0, GetModuleHandleA(NULL
), NULL
);
7299 ok( GetLastActivePopup(hwndOwner
) == hwndPopup2
, "wrong last active popup\n" );
7300 DestroyWindow( hwndPopup2
);
7301 DestroyWindow( hwndPopup1
);
7302 DestroyWindow( hwndOwner
);
7305 static LRESULT WINAPI
my_httrasparent_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
7307 if (msg
== WM_NCHITTEST
) return HTTRANSPARENT
;
7308 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
7311 static LRESULT WINAPI
my_window_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
7313 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
7316 static void create_window_tree(HWND parent
, HWND
*window
, int size
)
7318 static const DWORD style
[] = { 0, WS_VISIBLE
, WS_DISABLED
, WS_VISIBLE
| WS_DISABLED
};
7321 memset(window
, 0, size
* sizeof(window
[0]));
7324 for (i
= 0; i
< sizeof(style
)/sizeof(style
[0]); i
++)
7327 window
[pos
] = CreateWindowExA(0, "my_window", NULL
, style
[i
] | WS_CHILD
,
7328 0, 0, 100, 100, parent
, 0, 0, NULL
);
7329 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
7332 window
[pos
] = CreateWindowExA(WS_EX_TRANSPARENT
, "my_window", NULL
, style
[i
] | WS_CHILD
,
7333 0, 0, 100, 100, parent
, 0, 0, NULL
);
7334 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
7338 window
[pos
] = CreateWindowExA(0, "my_httrasparent", NULL
, style
[i
] | WS_CHILD
,
7339 0, 0, 100, 100, parent
, 0, 0, NULL
);
7340 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
7343 window
[pos
] = CreateWindowExA(WS_EX_TRANSPARENT
, "my_httrasparent", NULL
, style
[i
] | WS_CHILD
,
7344 0, 0, 100, 100, parent
, 0, 0, NULL
);
7345 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
7349 window
[pos
] = CreateWindowExA(0, "my_button", NULL
, style
[i
] | WS_CHILD
| BS_GROUPBOX
,
7350 0, 0, 100, 100, parent
, 0, 0, NULL
);
7351 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
7354 window
[pos
] = CreateWindowExA(WS_EX_TRANSPARENT
, "my_button", NULL
, style
[i
] | WS_CHILD
| BS_GROUPBOX
,
7355 0, 0, 100, 100, parent
, 0, 0, NULL
);
7356 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
7359 window
[pos
] = CreateWindowExA(0, "my_button", NULL
, style
[i
] | WS_CHILD
| BS_PUSHBUTTON
,
7360 0, 0, 100, 100, parent
, 0, 0, NULL
);
7361 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
7364 window
[pos
] = CreateWindowExA(WS_EX_TRANSPARENT
, "my_button", NULL
, style
[i
] | WS_CHILD
| BS_PUSHBUTTON
,
7365 0, 0, 100, 100, parent
, 0, 0, NULL
);
7366 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
7370 window
[pos
] = CreateWindowExA(0, "Button", NULL
, style
[i
] | WS_CHILD
| BS_GROUPBOX
,
7371 0, 0, 100, 100, parent
, 0, 0, NULL
);
7372 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
7375 window
[pos
] = CreateWindowExA(WS_EX_TRANSPARENT
, "Button", NULL
, style
[i
] | WS_CHILD
| BS_GROUPBOX
,
7376 0, 0, 100, 100, parent
, 0, 0, NULL
);
7377 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
7380 window
[pos
] = CreateWindowExA(0, "Button", NULL
, style
[i
] | WS_CHILD
| BS_PUSHBUTTON
,
7381 0, 0, 100, 100, parent
, 0, 0, NULL
);
7382 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
7385 window
[pos
] = CreateWindowExA(WS_EX_TRANSPARENT
, "Button", NULL
, style
[i
] | WS_CHILD
| BS_PUSHBUTTON
,
7386 0, 0, 100, 100, parent
, 0, 0, NULL
);
7387 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
7391 window
[pos
] = CreateWindowExA(0, "Static", NULL
, style
[i
] | WS_CHILD
,
7392 0, 0, 100, 100, parent
, 0, 0, NULL
);
7393 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
7396 window
[pos
] = CreateWindowExA(WS_EX_TRANSPARENT
, "Static", NULL
, style
[i
] | WS_CHILD
,
7397 0, 0, 100, 100, parent
, 0, 0, NULL
);
7398 ok(window
[pos
] != 0, "CreateWindowEx failed\n");
7403 struct window_attributes
7405 char class_name
[128];
7406 BOOL is_visible
, is_enabled
, is_groupbox
, is_httransparent
, is_extransparent
;
7409 static void get_window_attributes(HWND hwnd
, struct window_attributes
*attrs
)
7411 DWORD style
, ex_style
, hittest
;
7413 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
7414 ex_style
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
7415 attrs
->class_name
[0] = 0;
7416 GetClassNameA(hwnd
, attrs
->class_name
, sizeof(attrs
->class_name
));
7417 hittest
= SendMessageA(hwnd
, WM_NCHITTEST
, 0, 0);
7419 attrs
->is_visible
= (style
& WS_VISIBLE
) != 0;
7420 attrs
->is_enabled
= (style
& WS_DISABLED
) == 0;
7421 attrs
->is_groupbox
= !lstrcmpiA(attrs
->class_name
, "Button") && (style
& BS_TYPEMASK
) == BS_GROUPBOX
;
7422 attrs
->is_httransparent
= hittest
== HTTRANSPARENT
;
7423 attrs
->is_extransparent
= (ex_style
& WS_EX_TRANSPARENT
) != 0;
7426 static int window_to_index(HWND hwnd
, HWND
*window
, int size
)
7430 for (i
= 0; i
< size
; i
++)
7432 if (!window
[i
]) break;
7433 if (window
[i
] == hwnd
) return i
;
7438 static void test_child_window_from_point(void)
7440 static const int real_child_pos
[] = { 14,15,16,17,18,19,20,21,24,25,26,27,42,43,
7441 44,45,46,47,48,49,52,53,54,55,51,50,23,22,-1 };
7442 static const int real_child_pos_nt4
[] = { 14,15,16,17,20,21,24,25,26,27,42,43,44,45,
7443 48,49,52,53,54,55,51,50,47,46,23,22,19,18,-1 };
7445 HWND hwnd
, parent
, window
[100];
7447 int found_invisible
, found_disabled
, found_groupbox
, found_httransparent
, found_extransparent
;
7450 ret
= GetClassInfoA(0, "Button", &cls
);
7451 ok(ret
, "GetClassInfo(Button) failed\n");
7452 cls
.lpszClassName
= "my_button";
7453 ret
= RegisterClassA(&cls
);
7454 ok(ret
, "RegisterClass(my_button) failed\n");
7456 cls
.lpszClassName
= "my_httrasparent";
7457 cls
.lpfnWndProc
= my_httrasparent_proc
;
7458 ret
= RegisterClassA(&cls
);
7459 ok(ret
, "RegisterClass(my_httrasparent) failed\n");
7461 cls
.lpszClassName
= "my_window";
7462 cls
.lpfnWndProc
= my_window_proc
;
7463 ret
= RegisterClassA(&cls
);
7464 ok(ret
, "RegisterClass(my_window) failed\n");
7466 parent
= CreateWindowExA(0, "MainWindowClass", NULL
,
7467 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_POPUP
| WS_VISIBLE
,
7469 0, 0, GetModuleHandleA(NULL
), NULL
);
7470 ok(parent
!= 0, "CreateWindowEx failed\n");
7471 trace("parent %p\n", parent
);
7473 create_window_tree(parent
, window
, sizeof(window
)/sizeof(window
[0]));
7475 found_invisible
= 0;
7478 found_httransparent
= 0;
7479 found_extransparent
= 0;
7481 /* FIXME: also test WindowFromPoint, ChildWindowFromPoint, ChildWindowFromPointEx */
7482 for (i
= 0; i
< sizeof(real_child_pos
)/sizeof(real_child_pos
[0]); i
++)
7484 struct window_attributes attrs
;
7487 hwnd
= RealChildWindowFromPoint(parent
, pt
);
7488 ok(hwnd
!= 0, "RealChildWindowFromPoint failed\n");
7489 ret
= window_to_index(hwnd
, window
, sizeof(window
)/sizeof(window
[0]));
7490 /* FIXME: remove once Wine is fixed */
7491 if (ret
!= real_child_pos
[i
])
7492 todo_wine
ok(ret
== real_child_pos
[i
] || broken(ret
== real_child_pos_nt4
[i
]), "expected %d, got %d\n", real_child_pos
[i
], ret
);
7494 ok(ret
== real_child_pos
[i
] || broken(ret
== real_child_pos_nt4
[i
]), "expected %d, got %d\n", real_child_pos
[i
], ret
);
7496 get_window_attributes(hwnd
, &attrs
);
7497 if (!attrs
.is_visible
) found_invisible
++;
7498 if (!attrs
.is_enabled
) found_disabled
++;
7499 if (attrs
.is_groupbox
) found_groupbox
++;
7500 if (attrs
.is_httransparent
) found_httransparent
++;
7501 if (attrs
.is_extransparent
) found_extransparent
++;
7503 if (ret
!= real_child_pos
[i
] && ret
!= -1)
7505 trace("found hwnd %p (%s), is_visible %d, is_enabled %d, is_groupbox %d, is_httransparent %d, is_extransparent %d\n",
7506 hwnd
, attrs
.class_name
, attrs
.is_visible
, attrs
.is_enabled
, attrs
.is_groupbox
, attrs
.is_httransparent
, attrs
.is_extransparent
);
7507 get_window_attributes(window
[real_child_pos
[i
]], &attrs
);
7508 trace("expected hwnd %p (%s), is_visible %d, is_enabled %d, is_groupbox %d, is_httransparent %d, is_extransparent %d\n",
7509 window
[real_child_pos
[i
]], attrs
.class_name
, attrs
.is_visible
, attrs
.is_enabled
, attrs
.is_groupbox
, attrs
.is_httransparent
, attrs
.is_extransparent
);
7513 ok(hwnd
== parent
, "expected %p, got %p\n", parent
, hwnd
);
7516 DestroyWindow(hwnd
);
7519 DestroyWindow(parent
);
7521 ok(!found_invisible
, "found %d invisible windows\n", found_invisible
);
7522 ok(found_disabled
, "found %d disabled windows\n", found_disabled
);
7524 ok(found_groupbox
== 4, "found %d groupbox windows\n", found_groupbox
);
7525 ok(found_httransparent
, "found %d httransparent windows\n", found_httransparent
);
7527 ok(found_extransparent
, "found %d extransparent windows\n", found_extransparent
);
7529 ret
= UnregisterClassA("my_button", cls
.hInstance
);
7530 ok(ret
, "UnregisterClass(my_button) failed\n");
7531 ret
= UnregisterClassA("my_httrasparent", cls
.hInstance
);
7532 ok(ret
, "UnregisterClass(my_httrasparent) failed\n");
7533 ret
= UnregisterClassA("my_window", cls
.hInstance
);
7534 ok(ret
, "UnregisterClass(my_window) failed\n");
7537 static void simulate_click(int x
, int y
)
7543 memset(input
, 0, sizeof(input
));
7544 input
[0].type
= INPUT_MOUSE
;
7545 U(input
[0]).mi
.dx
= x
;
7546 U(input
[0]).mi
.dy
= y
;
7547 U(input
[0]).mi
.dwFlags
= MOUSEEVENTF_LEFTDOWN
;
7548 input
[1].type
= INPUT_MOUSE
;
7549 U(input
[1]).mi
.dx
= x
;
7550 U(input
[1]).mi
.dy
= y
;
7551 U(input
[1]).mi
.dwFlags
= MOUSEEVENTF_LEFTUP
;
7552 events_no
= SendInput(2, input
, sizeof(input
[0]));
7553 ok(events_no
== 2, "SendInput returned %d\n", events_no
);
7556 static WNDPROC def_static_proc
;
7557 static BOOL got_hittest
;
7558 static LRESULT WINAPI
static_hook_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
7560 if(msg
== WM_NCHITTEST
)
7562 if(msg
== WM_LBUTTONDOWN
)
7563 ok(0, "unexpected call\n");
7565 return def_static_proc(hwnd
, msg
, wp
, lp
);
7568 static void window_from_point_proc(HWND parent
)
7570 HANDLE start_event
, end_event
;
7571 HANDLE win
, child_static
, child_button
;
7577 start_event
= OpenEventA(EVENT_ALL_ACCESS
, FALSE
, "test_wfp_start");
7578 ok(start_event
!= 0, "OpenEvent failed\n");
7579 end_event
= OpenEventA(EVENT_ALL_ACCESS
, FALSE
, "test_wfp_end");
7580 ok(end_event
!= 0, "OpenEvent failed\n");
7582 child_static
= CreateWindowExA(0, "static", "static", WS_CHILD
| WS_VISIBLE
,
7583 0, 0, 100, 100, parent
, 0, NULL
, NULL
);
7584 ok(child_static
!= 0, "CreateWindowEx failed\n");
7586 win
= WindowFromPoint(pt
);
7587 ok(win
== parent
, "WindowFromPoint returned %p, expected %p\n", win
, parent
);
7589 child_button
= CreateWindowExA(0, "button", "button", WS_CHILD
| WS_VISIBLE
,
7590 100, 0, 100, 100, parent
, 0, NULL
, NULL
);
7591 ok(child_button
!= 0, "CreateWindowEx failed\n");
7593 win
= WindowFromPoint(pt
);
7594 ok(win
== child_button
, "WindowFromPoint returned %p, expected %p\n", win
, child_button
);
7596 /* without this window simulate click test keeps sending WM_NCHITTEST
7597 * message to child_static in an infinite loop */
7598 win
= CreateWindowExA(0, "button", "button", WS_CHILD
| WS_VISIBLE
,
7599 0, 0, 100, 100, parent
, 0, NULL
, NULL
);
7600 ok(win
!= 0, "CreateWindowEx failed\n");
7601 def_static_proc
= (void*)SetWindowLongPtrA(child_static
,
7602 GWLP_WNDPROC
, (LONG_PTR
)static_hook_proc
);
7604 SetEvent(start_event
);
7606 got_hittest
= FALSE
;
7608 while(!got_click
&& wait_for_message(&msg
)) {
7609 if(msg
.message
== WM_LBUTTONUP
) {
7610 ok(msg
.hwnd
== win
, "msg.hwnd = %p, expected %p\n", msg
.hwnd
, win
);
7613 DispatchMessageA(&msg
);
7615 ok(got_hittest
, "transparent window didn't get WM_NCHITTEST message\n");
7616 ok(got_click
, "button under static window didn't get WM_LBUTTONUP\n");
7618 ret
= WaitForSingleObject(end_event
, 5000);
7619 ok(ret
== WAIT_OBJECT_0
, "WaitForSingleObject returned %x\n", ret
);
7621 CloseHandle(start_event
);
7622 CloseHandle(end_event
);
7625 static void test_window_from_point(const char *argv0
)
7627 HWND hwnd
, child
, win
;
7629 PROCESS_INFORMATION info
;
7630 STARTUPINFOA startup
;
7632 HANDLE start_event
, end_event
;
7634 hwnd
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_POPUP
| WS_VISIBLE
,
7635 100, 100, 200, 100, 0, 0, NULL
, NULL
);
7636 ok(hwnd
!= 0, "CreateWindowEx failed\n");
7639 win
= WindowFromPoint(pt
);
7642 win
= WindowFromPoint(pt
);
7644 skip("there's another window covering test window\n");
7645 DestroyWindow(hwnd
);
7649 child
= CreateWindowExA(0, "static", "static", WS_CHILD
| WS_VISIBLE
,
7650 0, 0, 100, 100, hwnd
, 0, NULL
, NULL
);
7651 ok(child
!= 0, "CreateWindowEx failed\n");
7653 win
= WindowFromPoint(pt
);
7654 ok(win
== hwnd
, "WindowFromPoint returned %p, expected %p\n", win
, hwnd
);
7655 DestroyWindow(child
);
7657 child
= CreateWindowExA(0, "button", "button", WS_CHILD
| WS_VISIBLE
,
7658 0, 0, 100, 100, hwnd
, 0, NULL
, NULL
);
7659 ok(child
!= 0, "CreateWindowEx failed\n");
7660 win
= WindowFromPoint(pt
);
7661 ok(win
== child
, "WindowFromPoint returned %p, expected %p\n", win
, child
);
7662 DestroyWindow(child
);
7664 start_event
= CreateEventA(NULL
, FALSE
, FALSE
, "test_wfp_start");
7665 ok(start_event
!= 0, "CreateEvent failed\n");
7666 end_event
= CreateEventA(NULL
, FALSE
, FALSE
, "test_wfp_end");
7667 ok(start_event
!= 0, "CreateEvent failed\n");
7669 sprintf(cmd
, "%s win create_children %p\n", argv0
, hwnd
);
7670 memset(&startup
, 0, sizeof(startup
));
7671 startup
.cb
= sizeof(startup
);
7672 ok(CreateProcessA(NULL
, cmd
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
,
7673 &startup
, &info
), "CreateProcess failed.\n");
7674 ok(wait_for_event(start_event
, 1000), "didn't get start_event\n");
7676 child
= GetWindow(hwnd
, GW_CHILD
);
7677 win
= WindowFromPoint(pt
);
7678 ok(win
== child
, "WindowFromPoint returned %p, expected %p\n", win
, child
);
7680 simulate_click(150, 150);
7683 child
= GetWindow(child
, GW_HWNDNEXT
);
7685 win
= WindowFromPoint(pt
);
7686 ok(win
== child
, "WindowFromPoint returned %p, expected %p\n", win
, child
);
7688 SetEvent(end_event
);
7689 winetest_wait_child_process(info
.hProcess
);
7690 CloseHandle(start_event
);
7691 CloseHandle(end_event
);
7692 CloseHandle(info
.hProcess
);
7693 CloseHandle(info
.hThread
);
7695 DestroyWindow(hwnd
);
7698 static void test_map_points(void)
7702 HWND wnd
, wnd0
, dwnd
;
7705 POINT pos
= { 100, 200 };
7711 /* Create test windows */
7712 wnd
= CreateWindowA("static", "test1", WS_POPUP
, pos
.x
, pos
.y
, width
, height
, NULL
, NULL
, NULL
, NULL
);
7713 ok(wnd
!= NULL
, "Failed %p\n", wnd
);
7714 wnd0
= CreateWindowA("static", "test2", WS_POPUP
, 0, 0, width
, height
, NULL
, NULL
, NULL
, NULL
);
7715 ok(wnd0
!= NULL
, "Failed %p\n", wnd
);
7716 dwnd
= CreateWindowA("static", "test3", 0, 200, 300, 150, 150, NULL
, NULL
, NULL
, NULL
);
7717 DestroyWindow(dwnd
);
7718 ok(dwnd
!= NULL
, "Failed %p\n", dwnd
);
7720 /* Verify window rect and client rect (they should have the same width and height) */
7721 GetWindowRect(wnd
, &window_rect
);
7722 ok(window_rect
.left
== pos
.x
, "left is %d instead of %d\n", window_rect
.left
, pos
.x
);
7723 ok(window_rect
.top
== pos
.y
, "top is %d instead of %d\n", window_rect
.top
, pos
.y
);
7724 ok(window_rect
.right
== pos
.x
+ width
, "right is %d instead of %d\n", window_rect
.right
, pos
.x
+ width
);
7725 ok(window_rect
.bottom
== pos
.y
+ height
, "bottom is %d instead of %d\n", window_rect
.bottom
, pos
.y
+ height
);
7726 GetClientRect(wnd
, &client_rect
);
7727 ok(client_rect
.left
== 0, "left is %d instead of 0\n", client_rect
.left
);
7728 ok(client_rect
.top
== 0, "top is %d instead of 0\n", client_rect
.top
);
7729 ok(client_rect
.right
== width
, "right is %d instead of %d\n", client_rect
.right
, width
);
7730 ok(client_rect
.bottom
== height
, "bottom is %d instead of %d\n", client_rect
.bottom
, height
);
7732 /* Test MapWindowPoints */
7734 /* MapWindowPoints(NULL or wnd, NULL or wnd, NULL, 1); crashes on Windows */
7736 SetLastError(0xdeadbeef);
7737 n
= MapWindowPoints(NULL
, NULL
, NULL
, 0);
7738 err
= GetLastError();
7739 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
7740 ok(err
== 0xdeadbeef, "Got %x, expected %x\n", err
, 0xdeadbeef);
7742 SetLastError(0xdeadbeef);
7743 n
= MapWindowPoints(wnd
, wnd
, NULL
, 0);
7744 err
= GetLastError();
7745 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
7746 ok(err
== 0xdeadbeef, "Got %x, expected %x\n", err
, 0xdeadbeef);
7748 n
= MapWindowPoints(wnd
, NULL
, NULL
, 0);
7749 ok(n
== MAKELONG(window_rect
.left
, window_rect
.top
), "Got %x, expected %x\n",
7750 n
, MAKELONG(window_rect
.left
, window_rect
.top
));
7752 n
= MapWindowPoints(NULL
, wnd
, NULL
, 0);
7753 ok(n
== MAKELONG(-window_rect
.left
, -window_rect
.top
), "Got %x, expected %x\n",
7754 n
, MAKELONG(-window_rect
.left
, -window_rect
.top
));
7756 SetLastError(0xdeadbeef);
7758 n
= MapWindowPoints(dwnd
, NULL
, &p
, 1);
7759 err
= GetLastError();
7760 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
7761 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
7762 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
7764 SetLastError(0xdeadbeef);
7766 n
= MapWindowPoints(dwnd
, wnd
, &p
, 1);
7767 err
= GetLastError();
7768 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
7769 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
7770 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
7772 SetLastError(0xdeadbeef);
7774 n
= MapWindowPoints(NULL
, dwnd
, &p
, 1);
7775 err
= GetLastError();
7776 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
7777 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
7778 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
7780 SetLastError(0xdeadbeef);
7782 n
= MapWindowPoints(wnd
, dwnd
, &p
, 1);
7783 err
= GetLastError();
7784 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
7785 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
7786 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
7788 SetLastError(0xdeadbeef);
7790 n
= MapWindowPoints(dwnd
, dwnd
, &p
, 1);
7791 err
= GetLastError();
7792 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
7793 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
7794 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
7796 SetLastError(0xdeadbeef);
7798 n
= MapWindowPoints(NULL
, NULL
, &p
, 1);
7799 err
= GetLastError();
7800 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
7801 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
7802 ok(err
== 0xdeadbeef, "Got %x, expected %x\n", err
, 0xdeadbeef);
7804 SetLastError(0xdeadbeef);
7806 n
= MapWindowPoints(wnd
, wnd
, &p
, 1);
7807 err
= GetLastError();
7808 ok(n
== 0, "Got %d, expected %d\n", n
, 0);
7809 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
7810 ok(err
== 0xdeadbeef, "Got %x, expected %x\n", err
, 0xdeadbeef);
7813 n
= MapWindowPoints(wnd
, NULL
, &p
, 1);
7814 ok(n
== MAKELONG(window_rect
.left
, window_rect
.top
), "Got %x, expected %x\n",
7815 n
, MAKELONG(window_rect
.left
, window_rect
.top
));
7816 ok((p
.x
== (window_rect
.left
+ 100)) && (p
.y
== (window_rect
.top
+ 100)), "Failed got (%d, %d), expected (%d, %d)\n",
7817 p
.x
, p
.y
, window_rect
.left
+ 100, window_rect
.top
+ 100);
7820 n
= MapWindowPoints(NULL
, wnd
, &p
, 1);
7821 ok(n
== MAKELONG(-window_rect
.left
, -window_rect
.top
), "Got %x, expected %x\n",
7822 n
, MAKELONG(-window_rect
.left
, -window_rect
.top
));
7823 ok((p
.x
== (-window_rect
.left
+ 100)) && (p
.y
== (-window_rect
.top
+ 100)), "Failed got (%d, %d), expected (%d, %d)\n",
7824 p
.x
, p
.y
, -window_rect
.left
+ 100, -window_rect
.top
+ 100);
7826 SetLastError(0xdeadbeef);
7828 n
= MapWindowPoints(wnd0
, NULL
, &p
, 1);
7829 err
= GetLastError();
7830 ok(n
== 0, "Got %x, expected 0\n", n
);
7831 ok((p
.x
== 0) && (p
.y
== 0), "Failed got (%d, %d), expected (0, 0)\n", p
.x
, p
.y
);
7832 ok(err
== 0xdeadbeef, "Got %x, expected %x\n", err
, 0xdeadbeef);
7834 SetLastError(0xdeadbeef);
7836 n
= MapWindowPoints(NULL
, wnd0
, &p
, 1);
7837 err
= GetLastError();
7838 ok(n
== 0, "Got %x, expected 0\n", n
);
7839 ok((p
.x
== 0) && (p
.y
== 0), "Failed got (%d, %d), expected (0, 0)\n", p
.x
, p
.y
);
7840 ok(err
== 0xdeadbeef, "Got %x, expected %x\n", err
, 0xdeadbeef);
7842 /* Test ClientToScreen */
7844 /* ClientToScreen(wnd, NULL); crashes on Windows */
7846 SetLastError(0xdeadbeef);
7847 ret
= ClientToScreen(NULL
, NULL
);
7848 err
= GetLastError();
7849 ok(!ret
, "Should fail\n");
7850 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
7852 SetLastError(0xdeadbeef);
7854 ret
= ClientToScreen(NULL
, &p
);
7855 err
= GetLastError();
7856 ok(!ret
, "Should fail\n");
7857 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
7858 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
7860 SetLastError(0xdeadbeef);
7862 ret
= ClientToScreen(dwnd
, &p
);
7863 err
= GetLastError();
7864 ok(!ret
, "Should fail\n");
7865 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
7866 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
7869 ret
= ClientToScreen(wnd
, &p
);
7870 ok(ret
, "Failed with error %u\n", GetLastError());
7871 ok((p
.x
== (window_rect
.left
+ 100)) && (p
.y
== (window_rect
.top
+ 100)), "Failed got (%d, %d), expected (%d, %d)\n",
7872 p
.x
, p
.y
, window_rect
.left
+ 100, window_rect
.top
+ 100);
7875 ret
= ClientToScreen(wnd0
, &p
);
7876 ok(ret
, "Failed with error %u\n", GetLastError());
7877 ok((p
.x
== 0) && (p
.y
== 0), "Failed got (%d, %d), expected (0, 0)\n", p
.x
, p
.y
);
7879 /* Test ScreenToClient */
7881 /* ScreenToClient(wnd, NULL); crashes on Windows */
7883 SetLastError(0xdeadbeef);
7884 ret
= ScreenToClient(NULL
, NULL
);
7885 err
= GetLastError();
7886 ok(!ret
, "Should fail\n");
7887 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
7889 SetLastError(0xdeadbeef);
7891 ret
= ScreenToClient(NULL
, &p
);
7892 err
= GetLastError();
7893 ok(!ret
, "Should fail\n");
7894 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
7895 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
7897 SetLastError(0xdeadbeef);
7899 ret
= ScreenToClient(dwnd
, &p
);
7900 err
= GetLastError();
7901 ok(!ret
, "Should fail\n");
7902 ok(p
.x
== 100 && p
.y
== 100, "Failed got(%d, %d), expected (%d, %d)\n", p
.x
, p
.y
, 100, 100);
7903 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "Got %x, expected %x\n", err
, ERROR_INVALID_WINDOW_HANDLE
);
7906 ret
= ScreenToClient(wnd
, &p
);
7907 ok(ret
, "Failed with error %u\n", GetLastError());
7908 ok((p
.x
== (-window_rect
.left
+ 100)) && (p
.y
== (-window_rect
.top
+ 100)), "Failed got(%d, %d), expected (%d, %d)\n",
7909 p
.x
, p
.y
, -window_rect
.left
+ 100, -window_rect
.top
+ 100);
7912 ret
= ScreenToClient(wnd0
, &p
);
7913 ok(ret
, "Failed with error %u\n", GetLastError());
7914 ok((p
.x
== 0) && (p
.y
== 0), "Failed got (%d, %d), expected (0, 0)\n", p
.x
, p
.y
);
7917 DestroyWindow(wnd0
);
7920 static void test_update_region(void)
7922 HWND hwnd
, parent
, child
;
7924 const RECT rc
= {15, 15, 40, 40};
7925 const POINT wnd_orig
= {30, 20};
7926 const POINT child_orig
= {10, 5};
7928 parent
= CreateWindowExA(0, "MainWindowClass", NULL
,
7929 WS_VISIBLE
| WS_CLIPCHILDREN
,
7930 0, 0, 300, 150, NULL
, NULL
, GetModuleHandleA(0), 0);
7931 hwnd
= CreateWindowExA(0, "MainWindowClass", NULL
,
7932 WS_VISIBLE
| WS_CLIPCHILDREN
| WS_CHILD
,
7933 0, 0, 200, 100, parent
, NULL
, GetModuleHandleA(0), 0);
7934 child
= CreateWindowExA(0, "MainWindowClass", NULL
,
7935 WS_VISIBLE
| WS_CHILD
,
7936 child_orig
.x
, child_orig
.y
, 100, 50,
7937 hwnd
, NULL
, GetModuleHandleA(0), 0);
7938 assert(parent
&& hwnd
&& child
);
7940 ValidateRgn(parent
, NULL
);
7941 ValidateRgn(hwnd
, NULL
);
7942 InvalidateRect(hwnd
, &rc
, FALSE
);
7943 ValidateRgn(child
, NULL
);
7945 rgn1
= CreateRectRgn(0, 0, 0, 0);
7946 ok(GetUpdateRgn(parent
, rgn1
, FALSE
) == NULLREGION
,
7947 "has invalid area after ValidateRgn(NULL)\n");
7948 GetUpdateRgn(hwnd
, rgn1
, FALSE
);
7949 rgn2
= CreateRectRgnIndirect(&rc
);
7950 ok(EqualRgn(rgn1
, rgn2
), "assigned and retrieved update regions are different\n");
7951 ok(GetUpdateRgn(child
, rgn2
, FALSE
) == NULLREGION
,
7952 "has invalid area after ValidateRgn(NULL)\n");
7954 SetWindowPos(hwnd
, 0, wnd_orig
.x
, wnd_orig
.y
, 0, 0,
7955 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOSIZE
);
7957 /* parent now has non-simple update region, it consist of
7958 * two rects, that was exposed after hwnd moving ... */
7959 SetRectRgn(rgn1
, 0, 0, 200, wnd_orig
.y
);
7960 SetRectRgn(rgn2
, 0, 0, wnd_orig
.x
, 100);
7961 CombineRgn(rgn1
, rgn1
, rgn2
, RGN_OR
);
7962 /* ... and mapped hwnd's invalid area, that hwnd has before moving */
7963 SetRectRgn(rgn2
, rc
.left
+ wnd_orig
.x
, rc
.top
+ wnd_orig
.y
,
7964 rc
.right
+ wnd_orig
.x
, rc
.bottom
+ wnd_orig
.y
);
7965 CombineRgn(rgn1
, rgn1
, rgn2
, RGN_OR
);
7966 GetUpdateRgn(parent
, rgn2
, FALSE
);
7968 ok(EqualRgn(rgn1
, rgn2
), "wrong update region\n");
7970 /* hwnd has the same invalid region as before moving */
7971 SetRectRgn(rgn1
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
7972 GetUpdateRgn(hwnd
, rgn2
, FALSE
);
7973 ok(EqualRgn(rgn1
, rgn2
), "wrong update region\n");
7975 /* hwnd's invalid area maps to child during moving */
7976 SetRectRgn(rgn1
, rc
.left
- child_orig
.x
, rc
.top
- child_orig
.y
,
7977 rc
.right
- child_orig
.x
, rc
.bottom
- child_orig
.y
);
7978 GetUpdateRgn(child
, rgn2
, FALSE
);
7980 ok(EqualRgn(rgn1
, rgn2
), "wrong update region\n");
7984 DestroyWindow(parent
);
7987 static void test_window_without_child_style(void)
7991 hwnd
= CreateWindowExA(0, "edit", NULL
, WS_VISIBLE
|WS_CHILD
,
7992 0, 0, 50, 50, hwndMain
, NULL
, 0, NULL
);
7993 ok(hwnd
!= NULL
, "CreateWindow failed\n");
7995 ok(SetWindowLongA(hwnd
, GWL_STYLE
, GetWindowLongA(hwnd
, GWL_STYLE
) & (~WS_CHILD
)),
7996 "can't remove WS_CHILD style\n");
7998 SetActiveWindow(hwndMain
);
7999 PostMessageW(hwnd
, WM_LBUTTONUP
, 0, 0);
8000 SendMessageW(hwnd
, WM_NCLBUTTONDOWN
, HTCAPTION
, 0);
8001 check_active_state(hwnd
, hwnd
, hwnd
);
8004 DestroyWindow(hwnd
);
8008 struct smresult_thread_data
8012 HANDLE thread_started
;
8013 HANDLE thread_got_wm_app
;
8014 HANDLE main_in_wm_app_1
;
8015 HANDLE thread_replied
;
8019 static LRESULT WINAPI
smresult_wndproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
8025 struct smresult_thread_data
*data
= (struct smresult_thread_data
*)lparam
;
8027 ok(hwnd
== data
->thread_hwnd
, "unexpected hwnd %p\n", hwnd
);
8029 SendNotifyMessageA(data
->main_hwnd
, WM_APP
+1, 0, lparam
);
8031 /* Don't return until the main thread is processing our sent message. */
8032 ok(WaitForSingleObject(data
->main_in_wm_app_1
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
8034 /* Break the PeekMessage loop so we can notify the main thread after we return. */
8035 SetEvent(data
->thread_got_wm_app
);
8041 struct smresult_thread_data
*data
= (struct smresult_thread_data
*)lparam
;
8044 ok(hwnd
== data
->main_hwnd
, "unexpected hwnd %p\n", hwnd
);
8046 /* Ask the thread to reply to our WM_APP message. */
8047 SetEvent(data
->main_in_wm_app_1
);
8049 /* Wait until the thread has sent a reply. */
8050 ok(WaitForSingleObject(data
->thread_replied
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
8052 /* Send another message while we have a reply queued for the current one. */
8053 res
= SendMessageA(data
->thread_hwnd
, WM_APP
+2, 0, lparam
);
8054 ok(res
== 0x449b0190, "unexpected result %lx\n", res
);
8060 struct smresult_thread_data
*data
= (struct smresult_thread_data
*)lparam
;
8062 ok(hwnd
== data
->thread_hwnd
, "unexpected hwnd %p\n", hwnd
);
8064 /* Don't return until we know the main thread is processing sent messages. */
8065 SendMessageA(data
->main_hwnd
, WM_NULL
, 0, 0);
8073 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
8076 static DWORD WINAPI
smresult_thread_proc(void *param
)
8079 struct smresult_thread_data
*data
= param
;
8081 data
->thread_hwnd
= CreateWindowExA(0, "SmresultClass", "window caption text", WS_OVERLAPPEDWINDOW
,
8082 100, 100, 200, 200, 0, 0, 0, NULL
);
8083 ok(data
->thread_hwnd
!= 0, "Failed to create overlapped window\n");
8085 SetEvent(data
->thread_started
);
8087 /* Loop until we've processed WM_APP. */
8088 while (WaitForSingleObject(data
->thread_got_wm_app
, 0) != WAIT_OBJECT_0
)
8090 if (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
8092 TranslateMessage(&msg
);
8093 DispatchMessageA(&msg
);
8097 MsgWaitForMultipleObjects(1, &data
->thread_got_wm_app
, FALSE
, INFINITE
, QS_SENDMESSAGE
);
8101 /* Notify the main thread that we replied to its WM_APP message. */
8102 SetEvent(data
->thread_replied
);
8104 while (GetMessageA(&msg
, 0, 0, 0))
8106 TranslateMessage(&msg
);
8107 DispatchMessageA(&msg
);
8113 static void test_smresult(void)
8118 struct smresult_thread_data data
;
8122 cls
.style
= CS_DBLCLKS
;
8123 cls
.lpfnWndProc
= smresult_wndproc
;
8126 cls
.hInstance
= GetModuleHandleA(0);
8128 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
8129 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
8130 cls
.lpszMenuName
= NULL
;
8131 cls
.lpszClassName
= "SmresultClass";
8133 ret
= RegisterClassA(&cls
);
8134 ok(ret
, "RegisterClassA failed\n");
8136 data
.thread_started
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
8137 ok(data
.thread_started
!= NULL
, "CreateEventA failed\n");
8139 data
.thread_got_wm_app
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
8140 ok(data
.thread_got_wm_app
!= NULL
, "CreateEventA failed\n");
8142 data
.main_in_wm_app_1
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
8143 ok(data
.main_in_wm_app_1
!= NULL
, "CreateEventA failed\n");
8145 data
.thread_replied
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
8146 ok(data
.thread_replied
!= NULL
, "CreateEventA failed\n");
8148 data
.main_hwnd
= CreateWindowExA(0, "SmresultClass", "window caption text", WS_OVERLAPPEDWINDOW
,
8149 100, 100, 200, 200, 0, 0, 0, NULL
);
8151 hThread
= CreateThread(NULL
, 0, smresult_thread_proc
, &data
, 0, &tid
);
8152 ok(hThread
!= NULL
, "CreateThread failed, error %d\n", GetLastError());
8154 ok(WaitForSingleObject(data
.thread_started
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
8156 res
= SendMessageA(data
.thread_hwnd
, WM_APP
, 0, (LPARAM
)&data
);
8157 ok(res
== 0x240408ea, "unexpected result %lx\n", res
);
8159 SendMessageA(data
.thread_hwnd
, WM_CLOSE
, 0, 0);
8161 DestroyWindow(data
.main_hwnd
);
8163 ok(WaitForSingleObject(hThread
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
8165 CloseHandle(data
.thread_started
);
8166 CloseHandle(data
.thread_got_wm_app
);
8167 CloseHandle(data
.main_in_wm_app_1
);
8168 CloseHandle(data
.thread_replied
);
8171 static void test_GetMessagePos(void)
8177 button
= CreateWindowExA(0, "button", "button", WS_VISIBLE
,
8178 100, 100, 100, 100, 0, 0, 0, NULL
);
8179 ok(button
!= 0, "CreateWindowExA failed\n");
8181 SetCursorPos(120, 140);
8183 pos
= GetMessagePos();
8184 ok(pos
== MAKELONG(120, 140), "pos = %08x\n", pos
);
8186 SetCursorPos(340, 320);
8187 pos
= GetMessagePos();
8188 ok(pos
== MAKELONG(120, 140), "pos = %08x\n", pos
);
8190 SendMessageW(button
, WM_APP
, 0, 0);
8191 pos
= GetMessagePos();
8192 ok(pos
== MAKELONG(120, 140), "pos = %08x\n", pos
);
8194 PostMessageA(button
, WM_APP
, 0, 0);
8195 GetMessageA(&msg
, button
, 0, 0);
8196 ok(msg
.message
== WM_APP
, "msg.message = %x\n", msg
.message
);
8197 pos
= GetMessagePos();
8198 ok(pos
== MAKELONG(340, 320), "pos = %08x\n", pos
);
8200 PostMessageA(button
, WM_APP
, 0, 0);
8201 SetCursorPos(350, 330);
8202 GetMessageA(&msg
, button
, 0, 0);
8203 ok(msg
.message
== WM_APP
, "msg.message = %x\n", msg
.message
);
8204 pos
= GetMessagePos();
8205 ok(pos
== MAKELONG(340, 320), "pos = %08x\n", pos
);
8207 PostMessageA(button
, WM_APP
, 0, 0);
8208 SetCursorPos(320, 340);
8209 PostMessageA(button
, WM_APP
+1, 0, 0);
8210 pos
= GetMessagePos();
8211 ok(pos
== MAKELONG(340, 320), "pos = %08x\n", pos
);
8212 GetMessageA(&msg
, button
, 0, 0);
8213 ok(msg
.message
== WM_APP
, "msg.message = %x\n", msg
.message
);
8214 pos
= GetMessagePos();
8215 ok(pos
== MAKELONG(350, 330), "pos = %08x\n", pos
);
8216 GetMessageA(&msg
, button
, 0, 0);
8217 ok(msg
.message
== WM_APP
+1, "msg.message = %x\n", msg
.message
);
8218 pos
= GetMessagePos();
8219 ok(pos
== MAKELONG(320, 340), "pos = %08x\n", pos
);
8221 SetTimer(button
, 1, 250, NULL
);
8222 SetCursorPos(330, 350);
8223 GetMessageA(&msg
, button
, 0, 0);
8224 while (msg
.message
== WM_PAINT
)
8226 UpdateWindow( button
);
8227 GetMessageA(&msg
, button
, 0, 0);
8229 ok(msg
.message
== WM_TIMER
, "msg.message = %x\n", msg
.message
);
8230 pos
= GetMessagePos();
8231 ok(pos
== MAKELONG(330, 350), "pos = %08x\n", pos
);
8232 KillTimer(button
, 1);
8234 DestroyWindow(button
);
8237 #define SET_FOREGROUND_STEAL_1 0x01
8238 #define SET_FOREGROUND_SET_1 0x02
8239 #define SET_FOREGROUND_STEAL_2 0x04
8240 #define SET_FOREGROUND_SET_2 0x08
8241 #define SET_FOREGROUND_INJECT 0x10
8243 struct set_foreground_thread_params
8245 UINT msg_quit
, msg_command
;
8246 HWND window1
, window2
, thread_window
;
8247 HANDLE command_executed
;
8250 static DWORD WINAPI
set_foreground_thread(void *params
)
8252 struct set_foreground_thread_params
*p
= params
;
8255 p
->thread_window
= CreateWindowExA(0, "static", "thread window", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
8256 0, 0, 10, 10, 0, 0, 0, NULL
);
8257 SetEvent(p
->command_executed
);
8259 while(GetMessageA(&msg
, 0, 0, 0))
8261 if (msg
.message
== p
->msg_quit
)
8264 if (msg
.message
== p
->msg_command
)
8266 if (msg
.wParam
& SET_FOREGROUND_STEAL_1
)
8268 SetForegroundWindow(p
->thread_window
);
8269 check_wnd_state(p
->thread_window
, p
->thread_window
, p
->thread_window
, 0);
8271 if (msg
.wParam
& SET_FOREGROUND_INJECT
)
8273 SendNotifyMessageA(p
->window1
, WM_ACTIVATEAPP
, 0, 0);
8275 if (msg
.wParam
& SET_FOREGROUND_SET_1
)
8277 SetForegroundWindow(p
->window1
);
8278 check_wnd_state(0, p
->window1
, 0, 0);
8280 if (msg
.wParam
& SET_FOREGROUND_STEAL_2
)
8282 SetForegroundWindow(p
->thread_window
);
8283 check_wnd_state(p
->thread_window
, p
->thread_window
, p
->thread_window
, 0);
8285 if (msg
.wParam
& SET_FOREGROUND_SET_2
)
8287 SetForegroundWindow(p
->window2
);
8288 check_wnd_state(0, p
->window2
, 0, 0);
8291 SetEvent(p
->command_executed
);
8295 TranslateMessage(&msg
);
8296 DispatchMessageA(&msg
);
8299 DestroyWindow(p
->thread_window
);
8303 static void test_activateapp(HWND window1
)
8305 HWND window2
, test_window
;
8307 struct set_foreground_thread_params thread_params
;
8311 window2
= CreateWindowExA(0, "static", "window 2", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
8312 300, 0, 10, 10, 0, 0, 0, NULL
);
8313 thread_params
.msg_quit
= WM_USER
;
8314 thread_params
.msg_command
= WM_USER
+ 1;
8315 thread_params
.window1
= window1
;
8316 thread_params
.window2
= window2
;
8317 thread_params
.command_executed
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
8319 thread
= CreateThread(NULL
, 0, set_foreground_thread
, &thread_params
, 0, &tid
);
8320 WaitForSingleObject(thread_params
.command_executed
, INFINITE
);
8322 SetForegroundWindow(window1
);
8323 check_wnd_state(window1
, window1
, window1
, 0);
8324 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
8326 /* Steal foreground: WM_ACTIVATEAPP(0) is delivered. */
8327 app_activated
= app_deactivated
= FALSE
;
8328 PostThreadMessageA(tid
, thread_params
.msg_command
, SET_FOREGROUND_STEAL_1
, 0);
8329 WaitForSingleObject(thread_params
.command_executed
, INFINITE
);
8330 test_window
= GetForegroundWindow();
8331 ok(test_window
== thread_params
.thread_window
, "Expected foreground window %p, got %p\n",
8332 thread_params
.thread_window
, test_window
);
8333 /* Active and Focus window are sometimes 0 on KDE. Ignore them.
8334 * check_wnd_state(window1, thread_params.thread_window, window1, 0); */
8335 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
8336 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
8337 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
8338 check_wnd_state(0, thread_params
.thread_window
, 0, 0);
8339 test_window
= GetForegroundWindow();
8340 ok(test_window
== thread_params
.thread_window
, "Expected foreground window %p, got %p\n",
8341 thread_params
.thread_window
, test_window
);
8342 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
8343 /* This message is reliable on Windows and inside a virtual desktop.
8344 * It is unreliable on KDE (50/50) and never arrives on FVWM.
8345 * ok(app_deactivated, "Expected WM_ACTIVATEAPP(0), did not receive it.\n"); */
8347 /* Set foreground: WM_ACTIVATEAPP (1) is delivered. */
8348 app_activated
= app_deactivated
= FALSE
;
8349 PostThreadMessageA(tid
, thread_params
.msg_command
, SET_FOREGROUND_SET_1
, 0);
8350 WaitForSingleObject(thread_params
.command_executed
, INFINITE
);
8351 check_wnd_state(0, 0, 0, 0);
8352 test_window
= GetForegroundWindow();
8353 ok(!test_window
, "Expected foreground window 0, got %p\n", test_window
);
8354 ok(!app_activated
, "Received WM_ACTIVATEAPP(!= 0), did not expect it.\n");
8355 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
8356 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
8357 check_wnd_state(window1
, window1
, window1
, 0);
8358 test_window
= GetForegroundWindow();
8359 ok(test_window
== window1
, "Expected foreground window %p, got %p\n",
8360 window1
, test_window
);
8361 ok(app_activated
, "Expected WM_ACTIVATEAPP(1), did not receive it.\n");
8362 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
8364 /* Steal foreground then set it back: No messages are delivered. */
8365 app_activated
= app_deactivated
= FALSE
;
8366 PostThreadMessageA(tid
, thread_params
.msg_command
, SET_FOREGROUND_STEAL_1
| SET_FOREGROUND_SET_1
, 0);
8367 WaitForSingleObject(thread_params
.command_executed
, INFINITE
);
8368 test_window
= GetForegroundWindow();
8369 ok(test_window
== window1
, "Expected foreground window %p, got %p\n",
8370 window1
, test_window
);
8371 check_wnd_state(window1
, window1
, window1
, 0);
8372 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
8373 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
8374 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
8375 test_window
= GetForegroundWindow();
8376 ok(test_window
== window1
, "Expected foreground window %p, got %p\n",
8377 window1
, test_window
);
8378 check_wnd_state(window1
, window1
, window1
, 0);
8379 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
8380 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
8382 /* This is not implemented with a plain WM_ACTIVATEAPP filter. */
8383 app_activated
= app_deactivated
= FALSE
;
8384 PostThreadMessageA(tid
, thread_params
.msg_command
, SET_FOREGROUND_STEAL_1
8385 | SET_FOREGROUND_INJECT
| SET_FOREGROUND_SET_1
, 0);
8386 WaitForSingleObject(thread_params
.command_executed
, INFINITE
);
8387 test_window
= GetForegroundWindow();
8388 ok(test_window
== window1
, "Expected foreground window %p, got %p\n",
8389 window1
, test_window
);
8390 check_wnd_state(window1
, window1
, window1
, 0);
8391 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
8392 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
8393 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
8394 test_window
= GetForegroundWindow();
8395 ok(test_window
== window1
, "Expected foreground window %p, got %p\n",
8396 window1
, test_window
);
8397 check_wnd_state(window1
, window1
, window1
, 0);
8398 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
8399 ok(app_deactivated
, "Expected WM_ACTIVATEAPP(0), did not receive it.\n");
8401 SetForegroundWindow(thread_params
.thread_window
);
8403 /* Set foreground then remove: Both messages are delivered. */
8404 app_activated
= app_deactivated
= FALSE
;
8405 PostThreadMessageA(tid
, thread_params
.msg_command
, SET_FOREGROUND_SET_1
| SET_FOREGROUND_STEAL_2
, 0);
8406 WaitForSingleObject(thread_params
.command_executed
, INFINITE
);
8407 test_window
= GetForegroundWindow();
8408 ok(test_window
== thread_params
.thread_window
, "Expected foreground window %p, got %p\n",
8409 thread_params
.thread_window
, test_window
);
8410 check_wnd_state(0, thread_params
.thread_window
, 0, 0);
8411 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
8412 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
8413 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
8414 test_window
= GetForegroundWindow();
8415 ok(test_window
== thread_params
.thread_window
, "Expected foreground window %p, got %p\n",
8416 thread_params
.thread_window
, test_window
);
8417 /* Active and focus are window1 on wine because the internal WM_WINE_SETACTIVEWINDOW(0)
8418 * message is never generated. GetCapture() returns 0 though, so we'd get a test success
8419 * in todo_wine in the line below.
8420 * todo_wine check_wnd_state(0, thread_params.thread_window, 0, 0); */
8421 ok(app_activated
, "Expected WM_ACTIVATEAPP(1), did not receive it.\n");
8422 todo_wine
ok(app_deactivated
, "Expected WM_ACTIVATEAPP(0), did not receive it.\n");
8424 SetForegroundWindow(window1
);
8425 test_window
= GetForegroundWindow();
8426 ok(test_window
== window1
, "Expected foreground window %p, got %p\n",
8427 window1
, test_window
);
8428 check_wnd_state(window1
, window1
, window1
, 0);
8430 /* Switch to a different window from the same thread? No messages. */
8431 app_activated
= app_deactivated
= FALSE
;
8432 PostThreadMessageA(tid
, thread_params
.msg_command
, SET_FOREGROUND_STEAL_1
| SET_FOREGROUND_SET_2
, 0);
8433 WaitForSingleObject(thread_params
.command_executed
, INFINITE
);
8434 test_window
= GetForegroundWindow();
8435 ok(test_window
== window1
, "Expected foreground window %p, got %p\n",
8436 window1
, test_window
);
8437 check_wnd_state(window1
, window1
, window1
, 0);
8438 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
8439 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
8440 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
8441 test_window
= GetForegroundWindow();
8442 ok(test_window
== window2
, "Expected foreground window %p, got %p\n",
8443 window2
, test_window
);
8444 check_wnd_state(window2
, window2
, window2
, 0);
8445 ok(!app_activated
, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
8446 ok(!app_deactivated
, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
8448 PostThreadMessageA(tid
, thread_params
.msg_quit
, 0, 0);
8449 WaitForSingleObject(thread
, INFINITE
);
8451 CloseHandle(thread_params
.command_executed
);
8452 DestroyWindow(window2
);
8458 int argc
= winetest_get_mainargs( &argv
);
8459 HMODULE user32
= GetModuleHandleA( "user32.dll" );
8460 HMODULE gdi32
= GetModuleHandleA("gdi32.dll");
8461 pGetAncestor
= (void *)GetProcAddress( user32
, "GetAncestor" );
8462 pGetWindowInfo
= (void *)GetProcAddress( user32
, "GetWindowInfo" );
8463 pGetWindowModuleFileNameA
= (void *)GetProcAddress( user32
, "GetWindowModuleFileNameA" );
8464 pGetLayeredWindowAttributes
= (void *)GetProcAddress( user32
, "GetLayeredWindowAttributes" );
8465 pSetLayeredWindowAttributes
= (void *)GetProcAddress( user32
, "SetLayeredWindowAttributes" );
8466 pUpdateLayeredWindow
= (void *)GetProcAddress( user32
, "UpdateLayeredWindow" );
8467 pUpdateLayeredWindowIndirect
= (void *)GetProcAddress( user32
, "UpdateLayeredWindowIndirect" );
8468 pGetMonitorInfoA
= (void *)GetProcAddress( user32
, "GetMonitorInfoA" );
8469 pMonitorFromPoint
= (void *)GetProcAddress( user32
, "MonitorFromPoint" );
8470 pGetWindowRgnBox
= (void *)GetProcAddress( user32
, "GetWindowRgnBox" );
8471 pGetGUIThreadInfo
= (void *)GetProcAddress( user32
, "GetGUIThreadInfo" );
8472 pGetProcessDefaultLayout
= (void *)GetProcAddress( user32
, "GetProcessDefaultLayout" );
8473 pSetProcessDefaultLayout
= (void *)GetProcAddress( user32
, "SetProcessDefaultLayout" );
8474 pFlashWindow
= (void *)GetProcAddress( user32
, "FlashWindow" );
8475 pFlashWindowEx
= (void *)GetProcAddress( user32
, "FlashWindowEx" );
8476 pGetLayout
= (void *)GetProcAddress( gdi32
, "GetLayout" );
8477 pSetLayout
= (void *)GetProcAddress( gdi32
, "SetLayout" );
8478 pMirrorRgn
= (void *)GetProcAddress( gdi32
, "MirrorRgn" );
8480 if (argc
==4 && !strcmp(argv
[2], "create_children"))
8484 sscanf(argv
[3], "%p", &hwnd
);
8485 window_from_point_proc(hwnd
);
8489 if (!RegisterWindowClasses()) assert(0);
8491 hwndMain
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
8492 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
8493 WS_MAXIMIZEBOX
| WS_POPUP
| WS_VISIBLE
,
8495 0, 0, GetModuleHandleA(NULL
), NULL
);
8498 if(!SetForegroundWindow(hwndMain
)) {
8499 /* workaround for foreground lock timeout */
8500 simulate_click(101, 101);
8501 ok(SetForegroundWindow(hwndMain
), "SetForegroundWindow failed\n");
8504 SetLastError(0xdeafbeef);
8505 GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC
);
8506 is_win9x
= (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
);
8508 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
8509 if (!hhook
) win_skip( "Cannot set CBT hook, skipping some tests\n" );
8511 /* make sure that these tests are executed first */
8512 test_FindWindowEx();
8515 hwndMain2
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
8516 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
8517 WS_MAXIMIZEBOX
| WS_POPUP
,
8519 0, 0, GetModuleHandleA(NULL
), NULL
);
8520 assert( hwndMain2
);
8522 our_pid
= GetWindowThreadProcessId(hwndMain
, NULL
);
8524 /* Add the tests below this line */
8525 test_child_window_from_point();
8526 test_window_from_point(argv
[0]);
8527 test_thick_child_size(hwndMain
);
8529 test_hwnd_message();
8530 test_nonclient_area(hwndMain
);
8532 test_GetWindowModuleFileName();
8535 test_capture_3(hwndMain
, hwndMain2
);
8539 test_FlashWindowEx();
8541 test_CreateWindow();
8542 test_parent_owner();
8543 test_enum_thread_windows();
8547 test_SetWindowPos(hwndMain
, hwndMain2
);
8548 test_SetMenu(hwndMain
);
8549 test_SetFocus(hwndMain
);
8550 test_SetActiveWindow(hwndMain
);
8553 test_children_zorder(hwndMain
);
8554 test_popup_zorder(hwndMain2
, hwndMain
, WS_POPUP
);
8555 test_popup_zorder(hwndMain2
, hwndMain
, 0);
8556 test_GetLastActivePopup();
8557 test_keyboard_input(hwndMain
);
8558 test_mouse_input(hwndMain
);
8559 test_validatergn(hwndMain
);
8560 test_nccalcscroll( hwndMain
);
8561 test_scrollwindow( hwndMain
);
8562 test_scrollvalidate( hwndMain
);
8563 test_scrolldc( hwndMain
);
8565 test_IsWindowUnicode();
8566 test_vis_rgn(hwndMain
);
8568 test_AdjustWindowRect();
8569 test_window_styles();
8570 test_dialog_styles();
8573 test_SetWindowLong();
8576 test_GetUpdateRect();
8578 test_layered_window();
8580 test_SetForegroundWindow(hwndMain
);
8581 test_shell_window();
8582 test_handles( hwndMain
);
8585 test_update_region();
8586 test_window_without_child_style();
8588 test_GetMessagePos();
8589 test_activateapp(hwndMain
);
8591 /* add the tests above this line */
8592 if (hhook
) UnhookWindowsHookEx(hhook
);
8594 DestroyWindow(hwndMain2
);
8595 DestroyWindow(hwndMain
);