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
*pGetMonitorInfoA
)(HMONITOR
,LPMONITORINFO
);
53 static HMONITOR (WINAPI
*pMonitorFromPoint
)(POINT
,DWORD
);
54 static int (WINAPI
*pGetWindowRgnBox
)(HWND
,LPRECT
);
55 static BOOL (WINAPI
*pGetGUIThreadInfo
)(DWORD
, GUITHREADINFO
*);
57 static BOOL test_lbuttondown_flag
;
58 static HWND hwndMessage
;
59 static HWND hwndMain
, hwndMain2
;
62 static const char* szAWRClass
= "Winsize";
66 static BOOL is_win9x
= FALSE
;
68 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
70 static void dump_minmax_info( const MINMAXINFO
*minmax
)
72 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
73 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
74 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
75 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
76 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
77 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
80 /* try to make sure pending X events have been processed before continuing */
81 static void flush_events( BOOL remove_messages
)
85 int min_timeout
= 100;
86 DWORD time
= GetTickCount() + diff
;
90 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
92 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
93 diff
= time
- GetTickCount();
98 /* check the values returned by the various parent/owner functions on a given window */
99 static void check_parents( HWND hwnd
, HWND ga_parent
, HWND gwl_parent
, HWND get_parent
,
100 HWND gw_owner
, HWND ga_root
, HWND ga_root_owner
)
106 res
= pGetAncestor( hwnd
, GA_PARENT
);
107 ok( res
== ga_parent
, "Wrong result for GA_PARENT %p expected %p\n", res
, ga_parent
);
109 res
= (HWND
)GetWindowLongPtrA( hwnd
, GWLP_HWNDPARENT
);
110 ok( res
== gwl_parent
, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res
, gwl_parent
);
111 res
= GetParent( hwnd
);
112 ok( res
== get_parent
, "Wrong result for GetParent %p expected %p\n", res
, get_parent
);
113 res
= GetWindow( hwnd
, GW_OWNER
);
114 ok( res
== gw_owner
, "Wrong result for GW_OWNER %p expected %p\n", res
, gw_owner
);
117 res
= pGetAncestor( hwnd
, GA_ROOT
);
118 ok( res
== ga_root
, "Wrong result for GA_ROOT %p expected %p\n", res
, ga_root
);
119 res
= pGetAncestor( hwnd
, GA_ROOTOWNER
);
120 ok( res
== ga_root_owner
, "Wrong result for GA_ROOTOWNER %p expected %p\n", res
, ga_root_owner
);
124 static BOOL
ignore_message( UINT message
)
126 /* these are always ignored */
127 return (message
>= 0xc000 ||
128 message
== WM_GETICON
||
129 message
== WM_GETOBJECT
||
130 message
== WM_TIMECHANGE
||
131 message
== WM_DEVICECHANGE
);
134 static BOOL CALLBACK
EnumChildProc( HWND hwndChild
, LPARAM lParam
)
137 trace("EnumChildProc on %p\n", hwndChild
);
138 if (*(LPINT
)lParam
> 1) return FALSE
;
142 /* will search for the given window */
143 static BOOL CALLBACK
EnumChildProc1( HWND hwndChild
, LPARAM lParam
)
145 trace("EnumChildProc1 on %p\n", hwndChild
);
146 if ((HWND
)lParam
== hwndChild
) return FALSE
;
150 static HWND
create_tool_window( LONG style
, HWND parent
)
152 HWND ret
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style
,
153 0, 0, 100, 100, parent
, 0, 0, NULL
);
154 ok( ret
!= 0, "Creation failed\n" );
158 /* test parent and owner values for various combinations */
159 static void test_parent_owner(void)
162 HWND test
, owner
, ret
;
163 HWND desktop
= GetDesktopWindow();
164 HWND child
= create_tool_window( WS_CHILD
, hwndMain
);
167 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain
, hwndMain2
, desktop
, child
);
169 /* child without parent, should fail */
170 SetLastError(0xdeadbeef);
171 test
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
172 WS_CHILD
, 0, 0, 100, 100, 0, 0, 0, NULL
);
173 ok( !test
, "WS_CHILD without parent created\n" );
174 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD
||
175 broken(GetLastError() == 0xdeadbeef), /* win9x */
176 "CreateWindowExA error %u\n", GetLastError() );
179 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
180 style
= GetWindowLongA( desktop
, GWL_STYLE
);
181 ok( !SetWindowLongA( desktop
, GWL_STYLE
, WS_POPUP
), "Set GWL_STYLE on desktop succeeded\n" );
182 ok( !SetWindowLongA( desktop
, GWL_STYLE
, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
183 ok( GetWindowLongA( desktop
, GWL_STYLE
) == style
, "Desktop style changed\n" );
185 /* normal child window */
186 test
= create_tool_window( WS_CHILD
, hwndMain
);
187 trace( "created child %p\n", test
);
188 check_parents( test
, hwndMain
, hwndMain
, hwndMain
, 0, hwndMain
, hwndMain
);
189 SetWindowLongA( test
, GWL_STYLE
, 0 );
190 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
191 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
192 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
193 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
|WS_CHILD
);
194 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
195 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
196 DestroyWindow( test
);
198 /* normal child window with WS_MAXIMIZE */
199 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
200 DestroyWindow( test
);
202 /* normal child window with WS_THICKFRAME */
203 test
= create_tool_window( WS_CHILD
| WS_THICKFRAME
, hwndMain
);
204 DestroyWindow( test
);
206 /* popup window with WS_THICKFRAME */
207 test
= create_tool_window( WS_POPUP
| WS_THICKFRAME
, hwndMain
);
208 DestroyWindow( test
);
210 /* child of desktop */
211 test
= create_tool_window( WS_CHILD
, desktop
);
212 trace( "created child of desktop %p\n", test
);
213 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
214 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
215 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
216 SetWindowLongA( test
, GWL_STYLE
, 0 );
217 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
218 DestroyWindow( test
);
220 /* child of desktop with WS_MAXIMIZE */
221 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, desktop
);
222 DestroyWindow( test
);
224 /* child of desktop with WS_MINIMIZE */
225 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, desktop
);
226 DestroyWindow( test
);
229 test
= create_tool_window( WS_CHILD
, child
);
230 trace( "created child of child %p\n", test
);
231 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
232 SetWindowLongA( test
, GWL_STYLE
, 0 );
233 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
234 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
235 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
236 DestroyWindow( test
);
238 /* child of child with WS_MAXIMIZE */
239 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, child
);
240 DestroyWindow( test
);
242 /* child of child with WS_MINIMIZE */
243 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, child
);
244 DestroyWindow( test
);
246 /* not owned top-level window */
247 test
= create_tool_window( 0, 0 );
248 trace( "created top-level %p\n", test
);
249 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
250 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
251 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
252 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
253 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
254 DestroyWindow( test
);
256 /* not owned top-level window with WS_MAXIMIZE */
257 test
= create_tool_window( WS_MAXIMIZE
, 0 );
258 DestroyWindow( test
);
260 /* owned top-level window */
261 test
= create_tool_window( 0, hwndMain
);
262 trace( "created owned top-level %p\n", test
);
263 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
264 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
265 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
266 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
267 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
268 DestroyWindow( test
);
270 /* owned top-level window with WS_MAXIMIZE */
271 test
= create_tool_window( WS_MAXIMIZE
, hwndMain
);
272 DestroyWindow( test
);
274 /* not owned popup */
275 test
= create_tool_window( WS_POPUP
, 0 );
276 trace( "created popup %p\n", test
);
277 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
278 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
279 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
280 SetWindowLongA( test
, GWL_STYLE
, 0 );
281 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
282 DestroyWindow( test
);
284 /* not owned popup with WS_MAXIMIZE */
285 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, 0 );
286 DestroyWindow( test
);
289 test
= create_tool_window( WS_POPUP
, hwndMain
);
290 trace( "created owned popup %p\n", test
);
291 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
292 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
293 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
294 SetWindowLongA( test
, GWL_STYLE
, 0 );
295 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
296 DestroyWindow( test
);
298 /* owned popup with WS_MAXIMIZE */
299 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, hwndMain
);
300 DestroyWindow( test
);
302 /* top-level window owned by child (same as owned by top-level) */
303 test
= create_tool_window( 0, child
);
304 trace( "created top-level owned by child %p\n", test
);
305 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
306 DestroyWindow( test
);
308 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
309 test
= create_tool_window( WS_MAXIMIZE
, child
);
310 DestroyWindow( test
);
312 /* popup owned by desktop (same as not owned) */
313 test
= create_tool_window( WS_POPUP
, desktop
);
314 trace( "created popup owned by desktop %p\n", test
);
315 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
316 DestroyWindow( test
);
318 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
319 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, desktop
);
320 DestroyWindow( test
);
322 /* popup owned by child (same as owned by top-level) */
323 test
= create_tool_window( WS_POPUP
, child
);
324 trace( "created popup owned by child %p\n", test
);
325 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
326 DestroyWindow( test
);
328 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
329 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, child
);
330 DestroyWindow( test
);
332 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
333 test
= create_tool_window( WS_POPUP
| WS_CHILD
, 0 );
334 trace( "created WS_CHILD popup %p\n", test
);
335 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
336 DestroyWindow( test
);
338 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
339 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, 0 );
340 DestroyWindow( test
);
342 /* owned popup with WS_CHILD (same as WS_POPUP only) */
343 test
= create_tool_window( WS_POPUP
| WS_CHILD
, hwndMain
);
344 trace( "created owned WS_CHILD popup %p\n", test
);
345 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
346 DestroyWindow( test
);
348 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
349 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
350 DestroyWindow( test
);
352 /******************** parent changes *************************/
353 trace( "testing parent changes\n" );
356 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
359 /* this test succeeds on NT but crashes on win9x systems */
360 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
361 ok( !ret
, "Set GWL_HWNDPARENT succeeded on desktop\n" );
362 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
363 ok( !SetParent( desktop
, hwndMain
), "SetParent succeeded on desktop\n" );
364 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
366 /* normal child window */
367 test
= create_tool_window( WS_CHILD
, hwndMain
);
368 trace( "created child %p\n", test
);
370 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
371 ok( ret
== hwndMain
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain
);
372 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
374 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
375 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
376 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
378 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)desktop
);
379 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
380 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
382 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
385 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)test
);
386 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
387 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
390 win_skip("Test creates circular window tree under Win9x/WinMe\n" );
392 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
393 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
394 check_parents( test
, desktop
, child
, desktop
, child
, test
, desktop
);
396 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
397 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
398 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
399 DestroyWindow( test
);
401 /* not owned top-level window */
402 test
= create_tool_window( 0, 0 );
403 trace( "created top-level %p\n", test
);
405 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
406 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
407 check_parents( test
, desktop
, hwndMain2
, 0, hwndMain2
, test
, test
);
409 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
410 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
411 check_parents( test
, desktop
, child
, 0, child
, test
, test
);
413 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
414 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
415 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
416 DestroyWindow( test
);
418 /* not owned popup */
419 test
= create_tool_window( WS_POPUP
, 0 );
420 trace( "created popup %p\n", test
);
422 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
423 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
424 check_parents( test
, desktop
, hwndMain2
, hwndMain2
, hwndMain2
, test
, hwndMain2
);
426 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
427 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
428 check_parents( test
, desktop
, child
, child
, child
, test
, hwndMain
);
430 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
431 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
432 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
433 DestroyWindow( test
);
435 /* normal child window */
436 test
= create_tool_window( WS_CHILD
, hwndMain
);
437 trace( "created child %p\n", test
);
439 ret
= SetParent( test
, desktop
);
440 ok( ret
== hwndMain
, "SetParent return value %p expected %p\n", ret
, hwndMain
);
441 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
443 ret
= SetParent( test
, child
);
444 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
445 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
447 ret
= SetParent( test
, hwndMain2
);
448 ok( ret
== child
, "SetParent return value %p expected %p\n", ret
, child
);
449 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
450 DestroyWindow( test
);
452 /* not owned top-level window */
453 test
= create_tool_window( 0, 0 );
454 trace( "created top-level %p\n", test
);
456 ret
= SetParent( test
, child
);
457 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
458 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
462 ShowWindow( test
, SW_SHOW
);
463 ret
= SetParent( test
, test
);
464 ok( ret
== NULL
, "SetParent return value %p expected %p\n", ret
, NULL
);
465 ok( GetWindowLongA( test
, GWL_STYLE
) & WS_VISIBLE
, "window is not visible after SetParent\n" );
466 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
469 win_skip( "Test crashes on Win9x/WinMe\n" );
470 DestroyWindow( test
);
473 test
= create_tool_window( WS_POPUP
, hwndMain2
);
474 trace( "created owned popup %p\n", test
);
476 ret
= SetParent( test
, child
);
477 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
478 check_parents( test
, child
, child
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
480 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)hwndMain
);
481 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
482 check_parents( test
, hwndMain
, hwndMain
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
483 DestroyWindow( test
);
485 /**************** test owner destruction *******************/
487 /* owned child popup */
488 owner
= create_tool_window( 0, 0 );
489 test
= create_tool_window( WS_POPUP
, owner
);
490 trace( "created owner %p and popup %p\n", owner
, test
);
491 ret
= SetParent( test
, child
);
492 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
493 check_parents( test
, child
, child
, owner
, owner
, hwndMain
, owner
);
494 /* window is now child of 'child' but owned by 'owner' */
495 DestroyWindow( owner
);
496 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
497 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
498 * while Win95, Win2k, WinXP do.
500 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
501 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
504 /* owned top-level popup */
505 owner
= create_tool_window( 0, 0 );
506 test
= create_tool_window( WS_POPUP
, owner
);
507 trace( "created owner %p and popup %p\n", owner
, test
);
508 check_parents( test
, desktop
, owner
, owner
, owner
, test
, owner
);
509 DestroyWindow( owner
);
510 ok( !IsWindow(test
), "Window %p not destroyed by owner destruction\n", test
);
512 /* top-level popup owned by child */
513 owner
= create_tool_window( WS_CHILD
, hwndMain2
);
514 test
= create_tool_window( WS_POPUP
, 0 );
515 trace( "created owner %p and popup %p\n", owner
, test
);
516 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)owner
);
517 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
518 check_parents( test
, desktop
, owner
, owner
, owner
, test
, hwndMain2
);
519 DestroyWindow( owner
);
520 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
521 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
522 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
523 * while Win95, Win2k, WinXP do.
525 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
529 DestroyWindow(child
);
532 owner
= create_tool_window( WS_OVERLAPPED
, 0 );
533 test
= create_tool_window( WS_POPUP
, desktop
);
535 ok( !GetWindow( test
, GW_OWNER
), "Wrong owner window\n" );
537 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
538 "EnumChildWindows should have returned FALSE\n" );
539 ok( numChildren
== 0, "numChildren should be 0 got %d\n", numChildren
);
541 SetWindowLongA( test
, GWL_STYLE
, (GetWindowLongA( test
, GWL_STYLE
) & ~WS_POPUP
) | WS_CHILD
);
542 ret
= SetParent( test
, owner
);
543 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
546 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
547 "EnumChildWindows should have returned TRUE\n" );
548 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
550 child
= create_tool_window( WS_CHILD
, owner
);
552 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
553 "EnumChildWindows should have returned FALSE\n" );
554 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
555 DestroyWindow( child
);
557 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, owner
);
558 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
560 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
561 "EnumChildWindows should have returned TRUE\n" );
562 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
564 ret
= SetParent( child
, owner
);
565 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
566 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
568 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
569 "EnumChildWindows should have returned FALSE\n" );
570 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
572 ret
= SetParent( child
, NULL
);
573 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
574 ok( ret
== owner
, "SetParent return value %p expected %p\n", ret
, owner
);
576 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
577 "EnumChildWindows should have returned TRUE\n" );
578 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
580 /* even GW_OWNER == owner it's still a desktop's child */
581 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
582 "EnumChildWindows should have found %p and returned FALSE\n", child
);
584 DestroyWindow( child
);
585 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, NULL
);
587 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
588 "EnumChildWindows should have found %p and returned FALSE\n", child
);
590 DestroyWindow( child
);
591 DestroyWindow( test
);
592 DestroyWindow( owner
);
595 static BOOL CALLBACK
enum_proc( HWND hwnd
, LPARAM lParam
)
598 if (*(LPINT
)lParam
> 2) return FALSE
;
601 static DWORD CALLBACK
enum_thread( void *arg
)
608 PeekMessage( &msg
, 0, 0, 0, PM_NOREMOVE
); /* make sure we have a message queue */
611 ret
= EnumThreadWindows( GetCurrentThreadId(), enum_proc
, (LPARAM
)&count
);
612 ok( ret
, "EnumThreadWindows should have returned TRUE\n" );
613 ok( count
== 0, "count should be 0 got %d\n", count
);
615 hwnd
[0] = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", WS_POPUP
,
616 0, 0, 100, 100, 0, 0, 0, NULL
);
618 ret
= EnumThreadWindows( GetCurrentThreadId(), enum_proc
, (LPARAM
)&count
);
619 ok( ret
, "EnumThreadWindows should have returned TRUE\n" );
620 if (count
!= 2) /* Vista gives us two windows for the price of one */
622 ok( count
== 1, "count should be 1 got %d\n", count
);
623 hwnd
[2] = CreateWindowExA(0, "ToolWindowClass", "Tool window 2", WS_POPUP
,
624 0, 0, 100, 100, 0, 0, 0, NULL
);
628 hwnd
[1] = CreateWindowExA(0, "ToolWindowClass", "Tool window 3", WS_POPUP
,
629 0, 0, 100, 100, 0, 0, 0, NULL
);
631 ret
= EnumThreadWindows( GetCurrentThreadId(), enum_proc
, (LPARAM
)&count
);
632 ok( !ret
, "EnumThreadWindows should have returned FALSE\n" );
633 ok( count
== 3, "count should be 3 got %d\n", count
);
635 if (hwnd
[2]) DestroyWindow(hwnd
[2]);
636 DestroyWindow(hwnd
[1]);
637 DestroyWindow(hwnd
[0]);
641 /* test EnumThreadWindows in a separate thread */
642 static void test_enum_thread_windows(void)
645 HANDLE handle
= CreateThread( NULL
, 0, enum_thread
, 0, 0, &id
);
646 ok( !WaitForSingleObject( handle
, 10000 ), "wait failed\n" );
647 CloseHandle( handle
);
650 static LRESULT WINAPI
main_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
654 case WM_GETMINMAXINFO
:
656 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
658 trace("WM_GETMINMAXINFO: hwnd %p, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
659 dump_minmax_info( minmax
);
660 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
663 case WM_WINDOWPOSCHANGING
:
665 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
666 trace("main: WM_WINDOWPOSCHANGING %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
667 winpos
->hwnd
, winpos
->hwndInsertAfter
,
668 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
669 if (!(winpos
->flags
& SWP_NOMOVE
))
671 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
672 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
674 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
675 if (!(winpos
->flags
& SWP_NOSIZE
) && !is_win9x
)
677 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
678 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
682 case WM_WINDOWPOSCHANGED
:
685 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
686 trace("main: WM_WINDOWPOSCHANGED %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
687 winpos
->hwnd
, winpos
->hwndInsertAfter
,
688 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
689 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
690 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
692 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
693 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
695 GetWindowRect(hwnd
, &rc1
);
696 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
697 /* note: winpos coordinates are relative to parent */
698 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
701 /* Uncomment this once the test succeeds in all cases */
702 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
703 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
705 GetClientRect(hwnd
, &rc2
);
706 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
707 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
708 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
709 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
715 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
716 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
718 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
719 if (got_getminmaxinfo
)
720 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
722 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
723 ok(got_getminmaxinfo
, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
725 ok(!got_getminmaxinfo
, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
729 if (test_lbuttondown_flag
)
731 ShowWindow((HWND
)wparam
, SW_SHOW
);
732 flush_events( FALSE
);
737 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
740 static LRESULT WINAPI
tool_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
744 case WM_GETMINMAXINFO
:
746 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
748 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
749 dump_minmax_info( minmax
);
750 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
755 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
756 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
758 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
759 if (got_getminmaxinfo
)
760 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
762 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
763 ok(got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
765 ok(!got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
770 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
773 static BOOL
RegisterWindowClasses(void)
777 cls
.style
= CS_DBLCLKS
;
778 cls
.lpfnWndProc
= main_window_procA
;
781 cls
.hInstance
= GetModuleHandleA(0);
783 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
784 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
785 cls
.lpszMenuName
= NULL
;
786 cls
.lpszClassName
= "MainWindowClass";
788 if(!RegisterClassA(&cls
)) return FALSE
;
791 cls
.lpfnWndProc
= tool_window_procA
;
794 cls
.hInstance
= GetModuleHandleA(0);
796 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
797 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
798 cls
.lpszMenuName
= NULL
;
799 cls
.lpszClassName
= "ToolWindowClass";
801 if(!RegisterClassA(&cls
)) return FALSE
;
806 static void verify_window_info(const char *hook
, HWND hwnd
, const WINDOWINFO
*info
)
808 RECT rcWindow
, rcClient
;
811 ok(IsWindow(hwnd
), "bad window handle %p in hook %s\n", hwnd
, hook
);
813 GetWindowRect(hwnd
, &rcWindow
);
814 ok(EqualRect(&rcWindow
, &info
->rcWindow
), "wrong rcWindow for %p in hook %s\n", hwnd
, hook
);
816 GetClientRect(hwnd
, &rcClient
);
817 /* translate to screen coordinates */
818 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rcClient
, 2);
819 ok(EqualRect(&rcClient
, &info
->rcClient
), "wrong rcClient for %p in hook %s\n", hwnd
, hook
);
821 ok(info
->dwStyle
== (DWORD
)GetWindowLongA(hwnd
, GWL_STYLE
),
822 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
823 info
->dwStyle
, GetWindowLongA(hwnd
, GWL_STYLE
), hwnd
, hook
);
824 /* Windows reports some undocumented exstyles in WINDOWINFO, but
825 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
827 ok((info
->dwExStyle
& ~0xe0000800) == (DWORD
)GetWindowLongA(hwnd
, GWL_EXSTYLE
),
828 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
829 info
->dwExStyle
, GetWindowLongA(hwnd
, GWL_EXSTYLE
), hwnd
, hook
);
830 status
= (GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0;
831 if (GetForegroundWindow())
832 ok(info
->dwWindowStatus
== status
, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
833 info
->dwWindowStatus
, status
, GetActiveWindow(), GetForegroundWindow(), hook
);
835 /* win2k and XP return broken border info in GetWindowInfo most of
836 * the time, so there is no point in testing it.
840 ok(info
->cxWindowBorders
== (unsigned)(rcClient
.left
- rcWindow
.left
),
841 "wrong cxWindowBorders %d != %d\n", info
->cxWindowBorders
, rcClient
.left
- rcWindow
.left
);
842 border
= min(rcWindow
.bottom
- rcClient
.bottom
, rcClient
.top
- rcWindow
.top
);
843 ok(info
->cyWindowBorders
== border
,
844 "wrong cyWindowBorders %d != %d\n", info
->cyWindowBorders
, border
);
846 ok(info
->atomWindowType
== GetClassLongA(hwnd
, GCW_ATOM
), "wrong atomWindowType for %p in hook %s\n",
848 ok(info
->wCreatorVersion
== 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
849 info
->wCreatorVersion
== 0x0500 /* Vista */,
850 "wrong wCreatorVersion %04x for %p in hook %s\n", info
->wCreatorVersion
, hwnd
, hook
);
853 static void FixedAdjustWindowRectEx(RECT
* rc
, LONG style
, BOOL menu
, LONG exstyle
)
855 AdjustWindowRectEx(rc
, style
, menu
, exstyle
);
856 /* AdjustWindowRectEx does not include scroll bars */
857 if (style
& WS_VSCROLL
)
859 if(exstyle
& WS_EX_LEFTSCROLLBAR
)
860 rc
->left
-= GetSystemMetrics(SM_CXVSCROLL
);
862 rc
->right
+= GetSystemMetrics(SM_CXVSCROLL
);
864 if (style
& WS_HSCROLL
)
865 rc
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
868 static void test_nonclient_area(HWND hwnd
)
870 DWORD style
, exstyle
;
871 RECT rc_window
, rc_client
, rc
;
875 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
876 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
877 menu
= !(style
& WS_CHILD
) && GetMenu(hwnd
) != 0;
879 GetWindowRect(hwnd
, &rc_window
);
880 GetClientRect(hwnd
, &rc_client
);
882 /* avoid some cases when things go wrong */
883 if (IsRectEmpty(&rc_window
) || IsRectEmpty(&rc_client
) ||
884 rc_window
.right
> 32768 || rc_window
.bottom
> 32768) return;
886 CopyRect(&rc
, &rc_client
);
887 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc
, 2);
888 FixedAdjustWindowRectEx(&rc
, style
, menu
, exstyle
);
890 ok(EqualRect(&rc
, &rc_window
),
891 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
892 style
, exstyle
, menu
, rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
,
893 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
896 CopyRect(&rc
, &rc_window
);
897 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
898 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
899 ok(EqualRect(&rc
, &rc_client
),
900 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
901 style
, exstyle
, menu
, rc_client
.left
, rc_client
.top
, rc_client
.right
, rc_client
.bottom
,
902 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
904 /* NULL rectangle shouldn't crash */
905 ret
= DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, 0);
906 ok(ret
== 0, "NULL rectangle returned %ld instead of 0\n", ret
);
908 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
912 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
913 SetRect(&rc_client
, 0, 0, 250, 150);
914 CopyRect(&rc_window
, &rc_client
);
915 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc_window
, 2);
916 FixedAdjustWindowRectEx(&rc_window
, style
, menu
, exstyle
);
918 CopyRect(&rc
, &rc_window
);
919 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
920 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
921 ok(EqualRect(&rc
, &rc_client
),
922 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
923 style
, exstyle
, menu
, rc_client
.left
, rc_client
.top
, rc_client
.right
, rc_client
.bottom
,
924 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
927 static LRESULT CALLBACK
cbt_hook_proc(int nCode
, WPARAM wParam
, LPARAM lParam
)
929 static const char *CBT_code_name
[10] = {
940 const char *code_name
= (nCode
>= 0 && nCode
<= HCBT_SETFOCUS
) ? CBT_code_name
[nCode
] : "Unknown";
941 HWND hwnd
= (HWND
)wParam
;
947 static const RECT rc_null
;
950 CBT_CREATEWNDA
*createwnd
= (CBT_CREATEWNDA
*)lParam
;
951 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
952 hwnd
, createwnd
->lpcs
->hwndParent
, createwnd
->lpcs
->style
);
953 ok(createwnd
->hwndInsertAfter
== HWND_TOP
, "hwndInsertAfter should be always HWND_TOP\n");
958 info
.cbSize
= sizeof(WINDOWINFO
);
959 ok(pGetWindowInfo(hwnd
, &info
), "GetWindowInfo should not fail\n");
960 verify_window_info(code_name
, hwnd
, &info
);
963 /* WS_VISIBLE should be turned off yet */
964 style
= createwnd
->lpcs
->style
& ~WS_VISIBLE
;
965 ok(style
== GetWindowLongA(hwnd
, GWL_STYLE
),
966 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
967 GetWindowLongA(hwnd
, GWL_STYLE
), style
);
971 /* Uncomment this once the test succeeds in all cases */
972 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
974 ok(GetParent(hwnd
) == hwndMessage
,
975 "wrong result from GetParent %p: message window %p\n",
976 GetParent(hwnd
), hwndMessage
);
979 ok(!GetParent(hwnd
), "GetParent should return 0 at this point\n");
981 ok(!GetWindow(hwnd
, GW_OWNER
), "GW_OWNER should be set to 0 at this point\n");
985 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
986 * Win9x still has them set to 0.
988 ok(GetWindow(hwnd
, GW_HWNDFIRST
) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
989 ok(GetWindow(hwnd
, GW_HWNDLAST
) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
991 ok(!GetWindow(hwnd
, GW_HWNDPREV
), "GW_HWNDPREV should be set to 0 at this point\n");
992 ok(!GetWindow(hwnd
, GW_HWNDNEXT
), "GW_HWNDNEXT should be set to 0 at this point\n");
996 /* Uncomment this once the test succeeds in all cases */
999 ok(pGetAncestor(hwnd
, GA_PARENT
) == hwndMessage
, "GA_PARENT should be set to hwndMessage at this point\n");
1000 ok(pGetAncestor(hwnd
, GA_ROOT
) == hwnd
,
1001 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd
, GA_ROOT
), hwnd
);
1003 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1004 ok(pGetAncestor(hwnd
, GA_ROOTOWNER
) == hwndMessage
,
1005 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
1007 ok(pGetAncestor(hwnd
, GA_ROOTOWNER
) == hwnd
,
1008 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd
, GA_ROOTOWNER
), hwnd
);
1011 ok(GetWindowRect(hwnd
, &rc
), "GetWindowRect failed\n");
1012 ok(EqualRect(&rc
, &rc_null
), "window rect should be set to 0 HCBT_CREATEWND\n");
1013 ok(GetClientRect(hwnd
, &rc
), "GetClientRect failed\n");
1014 ok(EqualRect(&rc
, &rc_null
), "client rect should be set to 0 on HCBT_CREATEWND\n");
1022 if (pGetWindowInfo
&& IsWindow(hwnd
))
1026 /* Win98 actually does check the info.cbSize and doesn't allow
1027 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
1028 * WinXP do not check it at all.
1030 info
.cbSize
= sizeof(WINDOWINFO
);
1031 ok(pGetWindowInfo(hwnd
, &info
), "GetWindowInfo should not fail\n");
1032 verify_window_info(code_name
, hwnd
, &info
);
1035 /* on HCBT_DESTROYWND window state is undefined */
1036 case HCBT_DESTROYWND
:
1037 trace( "HCBT_DESTROYWND: hwnd %p\n", hwnd
);
1043 return CallNextHookEx(hhook
, nCode
, wParam
, lParam
);
1046 static void test_shell_window(void)
1050 HMODULE hinst
, hUser32
;
1051 BOOL (WINAPI
*SetShellWindow
)(HWND
);
1052 HWND hwnd1
, hwnd2
, hwnd3
, hwnd4
, hwnd5
;
1053 HWND shellWindow
, nextWnd
;
1057 win_skip("Skipping shell window test on Win9x\n");
1061 shellWindow
= GetShellWindow();
1062 hinst
= GetModuleHandle(0);
1063 hUser32
= GetModuleHandleA("user32");
1065 SetShellWindow
= (void *)GetProcAddress(hUser32
, "SetShellWindow");
1067 trace("previous shell window: %p\n", shellWindow
);
1073 GetWindowThreadProcessId(shellWindow
, &pid
);
1074 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, pid
);
1077 skip( "cannot get access to shell process\n" );
1081 SetLastError(0xdeadbeef);
1082 ret
= DestroyWindow(shellWindow
);
1083 error
= GetLastError();
1085 ok(!ret
, "DestroyWindow(shellWindow)\n");
1086 /* passes on Win XP, but not on Win98 */
1087 ok(error
==ERROR_ACCESS_DENIED
|| error
== 0xdeadbeef,
1088 "got %u after DestroyWindow(shellWindow)\n", error
);
1090 /* close old shell instance */
1091 ret
= TerminateProcess(hProcess
, 0);
1092 ok(ret
, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1093 WaitForSingleObject(hProcess
, INFINITE
); /* wait for termination */
1094 CloseHandle(hProcess
);
1097 hwnd1
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst
, 0);
1098 trace("created window 1: %p\n", hwnd1
);
1100 ret
= SetShellWindow(hwnd1
);
1101 ok(ret
, "first call to SetShellWindow(hwnd1)\n");
1102 shellWindow
= GetShellWindow();
1103 ok(shellWindow
==hwnd1
, "wrong shell window: %p\n", shellWindow
);
1105 ret
= SetShellWindow(hwnd1
);
1106 ok(!ret
, "second call to SetShellWindow(hwnd1)\n");
1108 ret
= SetShellWindow(0);
1109 error
= GetLastError();
1110 /* passes on Win XP, but not on Win98
1111 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1112 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1114 ret
= SetShellWindow(hwnd1
);
1115 /* passes on Win XP, but not on Win98
1116 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1118 SetWindowLong(hwnd1
, GWL_EXSTYLE
, GetWindowLong(hwnd1
,GWL_EXSTYLE
)|WS_EX_TOPMOST
);
1119 ret
= GetWindowLong(hwnd1
,GWL_EXSTYLE
)&WS_EX_TOPMOST
? TRUE
: FALSE
;
1120 ok(!ret
, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1122 ret
= DestroyWindow(hwnd1
);
1123 ok(ret
, "DestroyWindow(hwnd1)\n");
1125 hwnd2
= CreateWindowEx(WS_EX_TOPMOST
, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst
, 0);
1126 trace("created window 2: %p\n", hwnd2
);
1127 ret
= SetShellWindow(hwnd2
);
1128 ok(!ret
, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1130 hwnd3
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst
, 0);
1131 trace("created window 3: %p\n", hwnd3
);
1133 hwnd4
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst
, 0);
1134 trace("created window 4: %p\n", hwnd4
);
1136 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1137 ok(nextWnd
==hwnd3
, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd
);
1139 ret
= SetShellWindow(hwnd4
);
1140 ok(ret
, "SetShellWindow(hwnd4)\n");
1141 shellWindow
= GetShellWindow();
1142 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1144 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1145 ok(nextWnd
==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd
);
1147 ret
= SetWindowPos(hwnd4
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1148 ok(ret
, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1150 ret
= SetWindowPos(hwnd4
, hwnd3
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1151 ok(ret
, "SetWindowPos(hwnd4, hwnd3\n");
1153 ret
= SetShellWindow(hwnd3
);
1154 ok(!ret
, "SetShellWindow(hwnd3)\n");
1155 shellWindow
= GetShellWindow();
1156 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1158 hwnd5
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst
, 0);
1159 trace("created window 5: %p\n", hwnd5
);
1160 ret
= SetWindowPos(hwnd4
, hwnd5
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1161 ok(ret
, "SetWindowPos(hwnd4, hwnd5)\n");
1165 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1166 ok(nextWnd
==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd
);
1169 /* destroy test windows */
1170 DestroyWindow(hwnd2
);
1171 DestroyWindow(hwnd3
);
1172 DestroyWindow(hwnd4
);
1173 DestroyWindow(hwnd5
);
1176 /************** MDI test ****************/
1178 static char mdi_lParam_test_message
[] = "just a test string";
1180 static void test_MDI_create(HWND parent
, HWND mdi_client
, INT_PTR first_id
)
1182 MDICREATESTRUCTA mdi_cs
;
1185 static const WCHAR classW
[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1186 static const WCHAR titleW
[] = {'M','D','I',' ','c','h','i','l','d',0};
1187 BOOL isWin9x
= FALSE
;
1189 mdi_cs
.szClass
= "MDI_child_Class_1";
1190 mdi_cs
.szTitle
= "MDI child";
1191 mdi_cs
.hOwner
= GetModuleHandle(0);
1192 mdi_cs
.x
= CW_USEDEFAULT
;
1193 mdi_cs
.y
= CW_USEDEFAULT
;
1194 mdi_cs
.cx
= CW_USEDEFAULT
;
1195 mdi_cs
.cy
= CW_USEDEFAULT
;
1197 mdi_cs
.lParam
= (LPARAM
)mdi_lParam_test_message
;
1198 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1199 ok(mdi_child
!= 0, "MDI child creation failed\n");
1200 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1201 ok(id
== first_id
, "wrong child id %ld\n", id
);
1202 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1203 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1205 mdi_cs
.style
= 0x7fffffff; /* without WS_POPUP */
1206 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1207 ok(mdi_child
!= 0, "MDI child creation failed\n");
1208 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1209 ok(id
== first_id
, "wrong child id %ld\n", id
);
1210 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1211 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1213 mdi_cs
.style
= 0xffffffff; /* with WS_POPUP */
1214 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1215 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1217 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1221 ok(mdi_child
!= 0, "MDI child creation failed\n");
1222 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1223 ok(id
== first_id
, "wrong child id %ld\n", id
);
1224 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1225 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1228 /* test MDICREATESTRUCT A<->W mapping */
1229 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1231 mdi_cs
.szClass
= (LPCSTR
)classW
;
1232 mdi_cs
.szTitle
= (LPCSTR
)titleW
;
1233 SetLastError(0xdeadbeef);
1234 mdi_child
= (HWND
)SendMessageW(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1237 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1240 ok(mdi_child
!= 0, "MDI child creation failed\n");
1244 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1245 ok(id
== first_id
, "wrong child id %ld\n", id
);
1246 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1247 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1250 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1252 CW_USEDEFAULT
, CW_USEDEFAULT
,
1253 CW_USEDEFAULT
, CW_USEDEFAULT
,
1254 mdi_client
, GetModuleHandle(0),
1255 (LPARAM
)mdi_lParam_test_message
);
1256 ok(mdi_child
!= 0, "MDI child creation failed\n");
1257 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1258 ok(id
== first_id
, "wrong child id %ld\n", id
);
1259 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1260 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1262 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1263 0x7fffffff, /* without WS_POPUP */
1264 CW_USEDEFAULT
, CW_USEDEFAULT
,
1265 CW_USEDEFAULT
, CW_USEDEFAULT
,
1266 mdi_client
, GetModuleHandle(0),
1267 (LPARAM
)mdi_lParam_test_message
);
1268 ok(mdi_child
!= 0, "MDI child creation failed\n");
1269 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1270 ok(id
== first_id
, "wrong child id %ld\n", id
);
1271 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1272 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1274 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1275 0xffffffff, /* with WS_POPUP */
1276 CW_USEDEFAULT
, CW_USEDEFAULT
,
1277 CW_USEDEFAULT
, CW_USEDEFAULT
,
1278 mdi_client
, GetModuleHandle(0),
1279 (LPARAM
)mdi_lParam_test_message
);
1280 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1282 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1286 ok(mdi_child
!= 0, "MDI child creation failed\n");
1287 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1288 ok(id
== first_id
, "wrong child id %ld\n", id
);
1289 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1290 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1293 /* test MDICREATESTRUCT A<->W mapping */
1294 SetLastError(0xdeadbeef);
1295 mdi_child
= CreateMDIWindowW(classW
, titleW
,
1297 CW_USEDEFAULT
, CW_USEDEFAULT
,
1298 CW_USEDEFAULT
, CW_USEDEFAULT
,
1299 mdi_client
, GetModuleHandle(0),
1300 (LPARAM
)mdi_lParam_test_message
);
1303 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1306 ok(mdi_child
!= 0, "MDI child creation failed\n");
1310 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1311 ok(id
== first_id
, "wrong child id %ld\n", id
);
1312 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1313 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1316 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1318 CW_USEDEFAULT
, CW_USEDEFAULT
,
1319 CW_USEDEFAULT
, CW_USEDEFAULT
,
1320 mdi_client
, 0, GetModuleHandle(0),
1321 mdi_lParam_test_message
);
1322 ok(mdi_child
!= 0, "MDI child creation failed\n");
1323 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1324 ok(id
== first_id
, "wrong child id %ld\n", id
);
1325 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1326 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1328 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1329 0x7fffffff, /* without WS_POPUP */
1330 CW_USEDEFAULT
, CW_USEDEFAULT
,
1331 CW_USEDEFAULT
, CW_USEDEFAULT
,
1332 mdi_client
, 0, GetModuleHandle(0),
1333 mdi_lParam_test_message
);
1334 ok(mdi_child
!= 0, "MDI child creation failed\n");
1335 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1336 ok(id
== first_id
, "wrong child id %ld\n", id
);
1337 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1338 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1340 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1341 0xffffffff, /* with WS_POPUP */
1342 CW_USEDEFAULT
, CW_USEDEFAULT
,
1343 CW_USEDEFAULT
, CW_USEDEFAULT
,
1344 mdi_client
, 0, GetModuleHandle(0),
1345 mdi_lParam_test_message
);
1346 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1348 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1352 ok(mdi_child
!= 0, "MDI child creation failed\n");
1353 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1354 ok(id
== first_id
, "wrong child id %ld\n", id
);
1355 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1356 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1359 /* test MDICREATESTRUCT A<->W mapping */
1360 SetLastError(0xdeadbeef);
1361 mdi_child
= CreateWindowExW(WS_EX_MDICHILD
, classW
, titleW
,
1363 CW_USEDEFAULT
, CW_USEDEFAULT
,
1364 CW_USEDEFAULT
, CW_USEDEFAULT
,
1365 mdi_client
, 0, GetModuleHandle(0),
1366 mdi_lParam_test_message
);
1369 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1372 ok(mdi_child
!= 0, "MDI child creation failed\n");
1376 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1377 ok(id
== first_id
, "wrong child id %ld\n", id
);
1378 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1379 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1382 /* This test fails on Win9x */
1385 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_2", "MDI child",
1387 CW_USEDEFAULT
, CW_USEDEFAULT
,
1388 CW_USEDEFAULT
, CW_USEDEFAULT
,
1389 parent
, 0, GetModuleHandle(0),
1390 mdi_lParam_test_message
);
1391 ok(!mdi_child
, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1394 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1395 WS_CHILD
, /* without WS_POPUP */
1396 CW_USEDEFAULT
, CW_USEDEFAULT
,
1397 CW_USEDEFAULT
, CW_USEDEFAULT
,
1398 mdi_client
, 0, GetModuleHandle(0),
1399 mdi_lParam_test_message
);
1400 ok(mdi_child
!= 0, "MDI child creation failed\n");
1401 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1402 ok(id
== 0, "wrong child id %ld\n", id
);
1403 DestroyWindow(mdi_child
);
1405 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1406 WS_CHILD
| WS_POPUP
, /* with WS_POPUP */
1407 CW_USEDEFAULT
, CW_USEDEFAULT
,
1408 CW_USEDEFAULT
, CW_USEDEFAULT
,
1409 mdi_client
, 0, GetModuleHandle(0),
1410 mdi_lParam_test_message
);
1411 ok(mdi_child
!= 0, "MDI child creation failed\n");
1412 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1413 ok(id
== 0, "wrong child id %ld\n", id
);
1414 DestroyWindow(mdi_child
);
1416 /* maximized child */
1417 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1418 WS_CHILD
| WS_MAXIMIZE
,
1419 CW_USEDEFAULT
, CW_USEDEFAULT
,
1420 CW_USEDEFAULT
, CW_USEDEFAULT
,
1421 mdi_client
, 0, GetModuleHandle(0),
1422 mdi_lParam_test_message
);
1423 ok(mdi_child
!= 0, "MDI child creation failed\n");
1424 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1425 ok(id
== 0, "wrong child id %ld\n", id
);
1426 DestroyWindow(mdi_child
);
1428 trace("Creating maximized child with a caption\n");
1429 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1430 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
,
1431 CW_USEDEFAULT
, CW_USEDEFAULT
,
1432 CW_USEDEFAULT
, CW_USEDEFAULT
,
1433 mdi_client
, 0, GetModuleHandle(0),
1434 mdi_lParam_test_message
);
1435 ok(mdi_child
!= 0, "MDI child creation failed\n");
1436 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1437 ok(id
== 0, "wrong child id %ld\n", id
);
1438 DestroyWindow(mdi_child
);
1440 trace("Creating maximized child with a caption and a thick frame\n");
1441 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1442 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
| WS_THICKFRAME
,
1443 CW_USEDEFAULT
, CW_USEDEFAULT
,
1444 CW_USEDEFAULT
, CW_USEDEFAULT
,
1445 mdi_client
, 0, GetModuleHandle(0),
1446 mdi_lParam_test_message
);
1447 ok(mdi_child
!= 0, "MDI child creation failed\n");
1448 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1449 ok(id
== 0, "wrong child id %ld\n", id
);
1450 DestroyWindow(mdi_child
);
1453 /**********************************************************************
1454 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1456 * Note: The rule here is that client rect of the maximized MDI child
1457 * is equal to the client rect of the MDI client window.
1459 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
1463 GetClientRect( client
, &rect
);
1464 AdjustWindowRectEx( &rect
, GetWindowLongA( hwnd
, GWL_STYLE
),
1465 0, GetWindowLongA( hwnd
, GWL_EXSTYLE
));
1467 rect
.right
-= rect
.left
;
1468 rect
.bottom
-= rect
.top
;
1469 lpMinMax
->ptMaxSize
.x
= rect
.right
;
1470 lpMinMax
->ptMaxSize
.y
= rect
.bottom
;
1472 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
1473 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
1475 trace("max rect (%d,%d - %d, %d)\n",
1476 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1479 static LRESULT WINAPI
mdi_child_wnd_proc_1(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1486 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1487 MDICREATESTRUCTA
*mdi_cs
= cs
->lpCreateParams
;
1489 ok(cs
->dwExStyle
& WS_EX_MDICHILD
, "WS_EX_MDICHILD should be set\n");
1490 ok(mdi_cs
->lParam
== (LPARAM
)mdi_lParam_test_message
, "wrong mdi_cs->lParam\n");
1492 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_1"), "wrong class name\n");
1493 ok(!lstrcmpA(cs
->lpszClass
, mdi_cs
->szClass
), "class name does not match\n");
1494 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1495 ok(!lstrcmpA(cs
->lpszName
, mdi_cs
->szTitle
), "title does not match\n");
1496 ok(cs
->hInstance
== mdi_cs
->hOwner
, "%p != %p\n", cs
->hInstance
, mdi_cs
->hOwner
);
1498 /* MDICREATESTRUCT should have original values */
1499 ok(mdi_cs
->style
== 0 || mdi_cs
->style
== 0x7fffffff || mdi_cs
->style
== 0xffffffff,
1500 "mdi_cs->style does not match (%08x)\n", mdi_cs
->style
);
1501 ok(mdi_cs
->x
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->x
);
1502 ok(mdi_cs
->y
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->y
);
1503 ok(mdi_cs
->cx
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cx
);
1504 ok(mdi_cs
->cy
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cy
);
1506 /* CREATESTRUCT should have fixed values */
1507 ok(cs
->x
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->x
);
1508 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1510 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1511 ok(cs
->cx
!= CW_USEDEFAULT
&& cs
->cx
!= 0, "%d == CW_USEDEFAULT\n", cs
->cx
);
1512 ok(cs
->cy
!= CW_USEDEFAULT
&& cs
->cy
!= 0, "%d == CW_USEDEFAULT\n", cs
->cy
);
1514 ok(!(cs
->style
& WS_POPUP
), "WS_POPUP is not allowed\n");
1516 if (GetWindowLongA(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1518 LONG style
= mdi_cs
->style
| WS_CHILD
| WS_CLIPSIBLINGS
;
1519 ok(cs
->style
== style
,
1520 "cs->style does not match (%08x)\n", cs
->style
);
1524 LONG style
= mdi_cs
->style
;
1526 style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1527 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1528 ok(cs
->style
== style
,
1529 "cs->style does not match (%08x)\n", cs
->style
);
1534 case WM_GETMINMAXINFO
:
1536 HWND client
= GetParent(hwnd
);
1538 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1539 MINMAXINFO my_minmax
;
1540 LONG style
, exstyle
;
1542 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1543 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1545 GetWindowRect(client
, &rc
);
1546 trace("MDI client %p window size = (%d x %d)\n", client
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1547 GetClientRect(client
, &rc
);
1548 trace("MDI client %p client size = (%d x %d)\n", client
, rc
.right
, rc
.bottom
);
1549 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN
),
1550 GetSystemMetrics(SM_CYSCREEN
));
1552 GetClientRect(client
, &rc
);
1553 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1554 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1555 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1556 trace("MDI child: calculated max window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1557 dump_minmax_info( minmax
);
1559 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1560 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1561 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1562 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1564 DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1566 trace("DefMDIChildProc returned:\n");
1567 dump_minmax_info( minmax
);
1569 MDI_ChildGetMinMaxInfo(client
, hwnd
, &my_minmax
);
1570 ok(minmax
->ptMaxSize
.x
== my_minmax
.ptMaxSize
.x
, "default width of maximized child %d != %d\n",
1571 minmax
->ptMaxSize
.x
, my_minmax
.ptMaxSize
.x
);
1572 ok(minmax
->ptMaxSize
.y
== my_minmax
.ptMaxSize
.y
, "default height of maximized child %d != %d\n",
1573 minmax
->ptMaxSize
.y
, my_minmax
.ptMaxSize
.y
);
1578 case WM_MDIACTIVATE
:
1580 HWND active
, client
= GetParent(hwnd
);
1581 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1582 active
= (HWND
)SendMessageA(client
, WM_MDIGETACTIVE
, 0, 0);
1583 if (hwnd
== (HWND
)lparam
) /* if we are being activated */
1584 ok (active
== (HWND
)lparam
, "new active %p != active %p\n", (HWND
)lparam
, active
);
1586 ok (active
== (HWND
)wparam
, "old active %p != active %p\n", (HWND
)wparam
, active
);
1590 return DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1593 static LRESULT WINAPI
mdi_child_wnd_proc_2(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1600 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1602 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg
== WM_NCCREATE
) ? "WM_NCCREATE" : "WM_CREATE",
1603 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
1605 ok(!(cs
->dwExStyle
& WS_EX_MDICHILD
), "WS_EX_MDICHILD should not be set\n");
1606 ok(cs
->lpCreateParams
== mdi_lParam_test_message
, "wrong cs->lpCreateParams\n");
1608 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_2"), "wrong class name\n");
1609 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1611 /* CREATESTRUCT should have fixed values */
1612 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1614 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1615 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1617 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1618 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1619 while Win95, Win2k, WinXP do. */
1620 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1621 ok(cs
->cy
== 0, "%d != 0\n", cs
->cy
);
1625 case WM_GETMINMAXINFO
:
1627 HWND parent
= GetParent(hwnd
);
1629 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1630 LONG style
, exstyle
;
1632 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1633 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1635 GetClientRect(parent
, &rc
);
1636 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent
, rc
.right
, rc
.bottom
);
1638 GetClientRect(parent
, &rc
);
1639 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1640 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1641 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1642 dump_minmax_info( minmax
);
1644 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1645 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1646 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1647 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1651 case WM_WINDOWPOSCHANGED
:
1653 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1656 GetWindowRect(hwnd
, &rc1
);
1657 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1658 /* note: winpos coordinates are relative to parent */
1659 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1660 ok(EqualRect(&rc1
, &rc2
), "rects do not match, window=(%d,%d)-(%d,%d) pos=(%d,%d)-(%d,%d)\n",
1661 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
1662 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1663 GetWindowRect(hwnd
, &rc1
);
1664 GetClientRect(hwnd
, &rc2
);
1665 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1666 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1667 ok(EqualRect(&rc1
, &rc2
), "rects do not match, window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1668 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
1669 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1672 case WM_WINDOWPOSCHANGING
:
1674 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1675 WINDOWPOS my_winpos
= *winpos
;
1677 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1678 (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
1679 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1680 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1682 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1684 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1685 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1686 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1687 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1692 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1695 static LRESULT WINAPI
mdi_main_wnd_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1697 static HWND mdi_client
;
1703 CLIENTCREATESTRUCT client_cs
;
1706 GetClientRect(hwnd
, &rc
);
1708 client_cs
.hWindowMenu
= 0;
1709 client_cs
.idFirstChild
= 1;
1711 /* MDIClient without MDIS_ALLCHILDSTYLES */
1712 mdi_client
= CreateWindowExA(0, "mdiclient",
1714 WS_CHILD
/*| WS_VISIBLE*/,
1715 /* tests depend on a not zero MDIClient size */
1716 0, 0, rc
.right
, rc
.bottom
,
1717 hwnd
, 0, GetModuleHandle(0),
1720 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1721 DestroyWindow(mdi_client
);
1723 /* MDIClient with MDIS_ALLCHILDSTYLES */
1724 mdi_client
= CreateWindowExA(0, "mdiclient",
1726 WS_CHILD
| MDIS_ALLCHILDSTYLES
/*| WS_VISIBLE*/,
1727 /* tests depend on a not zero MDIClient size */
1728 0, 0, rc
.right
, rc
.bottom
,
1729 hwnd
, 0, GetModuleHandle(0),
1732 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1733 DestroyWindow(mdi_client
);
1737 case WM_WINDOWPOSCHANGED
:
1739 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1742 GetWindowRect(hwnd
, &rc1
);
1743 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1744 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1745 /* note: winpos coordinates are relative to parent */
1746 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1747 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1748 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1750 GetWindowRect(hwnd
, &rc1
);
1751 GetClientRect(hwnd
, &rc2
);
1752 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1753 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1754 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1757 case WM_WINDOWPOSCHANGING
:
1759 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1760 WINDOWPOS my_winpos
= *winpos
;
1762 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1763 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1764 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1765 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1767 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1769 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1770 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1771 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1773 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1774 "DefWindowProc should not change WINDOWPOS values\n");
1783 return DefFrameProcA(hwnd
, mdi_client
, msg
, wparam
, lparam
);
1786 static BOOL
mdi_RegisterWindowClasses(void)
1791 cls
.lpfnWndProc
= mdi_main_wnd_procA
;
1794 cls
.hInstance
= GetModuleHandleA(0);
1796 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
1797 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1798 cls
.lpszMenuName
= NULL
;
1799 cls
.lpszClassName
= "MDI_parent_Class";
1800 if(!RegisterClassA(&cls
)) return FALSE
;
1802 cls
.lpfnWndProc
= mdi_child_wnd_proc_1
;
1803 cls
.lpszClassName
= "MDI_child_Class_1";
1804 if(!RegisterClassA(&cls
)) return FALSE
;
1806 cls
.lpfnWndProc
= mdi_child_wnd_proc_2
;
1807 cls
.lpszClassName
= "MDI_child_Class_2";
1808 if(!RegisterClassA(&cls
)) return FALSE
;
1813 static void test_mdi(void)
1818 if (!mdi_RegisterWindowClasses()) assert(0);
1820 mdi_hwndMain
= CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1821 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
1822 WS_MAXIMIZEBOX
/*| WS_VISIBLE*/,
1823 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1824 GetDesktopWindow(), 0,
1825 GetModuleHandle(0), NULL
);
1826 assert(mdi_hwndMain
);
1828 while(GetMessage(&msg, 0, 0, 0))
1830 TranslateMessage(&msg);
1831 DispatchMessage(&msg);
1834 DestroyWindow(mdi_hwndMain
);
1837 static void test_icons(void)
1841 HICON icon
= LoadIconA(0, IDI_APPLICATION
);
1842 HICON icon2
= LoadIconA(0, IDI_QUESTION
);
1843 HICON small_icon
= LoadImageA(0, IDI_APPLICATION
, IMAGE_ICON
,
1844 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
1847 cls
.cbSize
= sizeof(cls
);
1849 cls
.lpfnWndProc
= DefWindowProcA
;
1853 cls
.hIcon
= LoadIconA(0, IDI_HAND
);
1854 cls
.hIconSm
= small_icon
;
1855 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
1856 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1857 cls
.lpszMenuName
= NULL
;
1858 cls
.lpszClassName
= "IconWindowClass";
1860 RegisterClassExA(&cls
);
1862 hwnd
= CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1863 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, NULL
, NULL
);
1866 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1867 ok( res
== 0, "wrong big icon %p/0\n", res
);
1868 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon
);
1869 ok( res
== 0, "wrong previous big icon %p/0\n", res
);
1870 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1871 ok( res
== icon
, "wrong big icon after set %p/%p\n", res
, icon
);
1872 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon2
);
1873 ok( res
== icon
, "wrong previous big icon %p/%p\n", res
, icon
);
1874 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1875 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1877 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1878 ok( res
== 0, "wrong small icon %p/0\n", res
);
1879 /* this test is XP specific */
1880 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1881 ok( res != 0, "wrong small icon %p\n", res );*/
1882 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)icon
);
1883 ok( res
== 0, "wrong previous small icon %p/0\n", res
);
1884 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1885 ok( res
== icon
, "wrong small icon after set %p/%p\n", res
, icon
);
1886 /* this test is XP specific */
1887 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1888 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1889 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)small_icon
);
1890 ok( res
== icon
, "wrong previous small icon %p/%p\n", res
, icon
);
1891 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1892 ok( res
== small_icon
, "wrong small icon after set %p/%p\n", res
, small_icon
);
1893 /* this test is XP specific */
1894 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1895 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1897 /* make sure the big icon hasn't changed */
1898 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1899 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1901 DestroyWindow( hwnd
);
1904 static LRESULT WINAPI
nccalcsize_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1906 if (msg
== WM_NCCALCSIZE
)
1908 RECT
*rect
= (RECT
*)lparam
;
1909 /* first time around increase the rectangle, next time decrease it */
1910 if (rect
->left
== 100) InflateRect( rect
, 10, 10 );
1911 else InflateRect( rect
, -10, -10 );
1914 return DefWindowProc( hwnd
, msg
, wparam
, lparam
);
1917 static void test_SetWindowPos(HWND hwnd
)
1919 RECT orig_win_rc
, rect
;
1922 SetRect(&rect
, 111, 222, 333, 444);
1923 ok(!GetWindowRect(0, &rect
), "GetWindowRect succeeded\n");
1924 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1925 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1927 SetRect(&rect
, 111, 222, 333, 444);
1928 ok(!GetClientRect(0, &rect
), "GetClientRect succeeded\n");
1929 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1930 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1932 GetWindowRect(hwnd
, &orig_win_rc
);
1934 old_proc
= SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)nccalcsize_proc
);
1935 SetWindowPos(hwnd
, 0, 100, 100, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1936 GetWindowRect( hwnd
, &rect
);
1937 ok( rect
.left
== 100 && rect
.top
== 100 && rect
.right
== 100 && rect
.bottom
== 100,
1938 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1939 GetClientRect( hwnd
, &rect
);
1940 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1941 ok( rect
.left
== 90 && rect
.top
== 90 && rect
.right
== 110 && rect
.bottom
== 110,
1942 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1944 SetWindowPos(hwnd
, 0, 200, 200, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1945 GetWindowRect( hwnd
, &rect
);
1946 ok( rect
.left
== 200 && rect
.top
== 200 && rect
.right
== 200 && rect
.bottom
== 200,
1947 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1948 GetClientRect( hwnd
, &rect
);
1949 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1950 ok( rect
.left
== 210 && rect
.top
== 210 && rect
.right
== 190 && rect
.bottom
== 190,
1951 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1953 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1954 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1955 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, old_proc
);
1957 /* Win9x truncates coordinates to 16-bit irrespectively */
1960 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE
);
1961 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE
);
1963 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE
);
1964 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE
);
1967 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1968 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1970 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1971 SetWindowPos(hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1972 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1973 SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1974 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1975 SetWindowPos(hwnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1976 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1979 static void test_SetMenu(HWND parent
)
1986 hMenu
= CreateMenu();
1989 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1992 /* fails on (at least) Wine, NT4, XP SP2 */
1993 test_nonclient_area(parent
);
1995 ret
= GetMenu(parent
);
1996 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1997 /* test whether we can destroy a menu assigned to a window */
1998 retok
= DestroyMenu(hMenu
);
1999 ok( retok
, "DestroyMenu error %d\n", GetLastError());
2000 retok
= IsMenu(hMenu
);
2001 ok(!retok
|| broken(retok
) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
2002 ret
= GetMenu(parent
);
2003 /* This test fails on Win9x */
2005 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
2006 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
2007 test_nonclient_area(parent
);
2009 hMenu
= CreateMenu();
2013 ret
= GetMenu(parent
);
2014 ok(ret
== 0, "unexpected menu id %p\n", ret
);
2016 ok(!SetMenu(parent
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
2017 test_nonclient_area(parent
);
2018 ret
= GetMenu(parent
);
2019 ok(ret
== 0, "unexpected menu id %p\n", ret
);
2021 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
2024 /* fails on (at least) Wine, NT4, XP SP2 */
2025 test_nonclient_area(parent
);
2027 ret
= GetMenu(parent
);
2028 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
2030 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
2031 test_nonclient_area(parent
);
2032 ret
= GetMenu(parent
);
2033 ok(ret
== 0, "unexpected menu id %p\n", ret
);
2036 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, parent
, (HMENU
)10, 0, NULL
);
2039 ret
= GetMenu(child
);
2040 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2042 ok(!SetMenu(child
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
2043 test_nonclient_area(child
);
2044 ret
= GetMenu(child
);
2045 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2047 ok(!SetMenu(child
, hMenu
), "SetMenu on a child window should fail\n");
2048 test_nonclient_area(child
);
2049 ret
= GetMenu(child
);
2050 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2052 ok(!SetMenu(child
, 0), "SetMenu(0) on a child window should fail\n");
2053 test_nonclient_area(child
);
2054 ret
= GetMenu(child
);
2055 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2057 style
= GetWindowLong(child
, GWL_STYLE
);
2058 SetWindowLong(child
, GWL_STYLE
, style
| WS_POPUP
);
2059 ok(SetMenu(child
, hMenu
), "SetMenu on a popup child window should not fail\n");
2060 ok(SetMenu(child
, 0), "SetMenu on a popup child window should not fail\n");
2061 SetWindowLong(child
, GWL_STYLE
, style
);
2063 SetWindowLong(child
, GWL_STYLE
, style
| WS_OVERLAPPED
);
2064 ok(!SetMenu(child
, hMenu
), "SetMenu on a overlapped child window should fail\n");
2065 SetWindowLong(child
, GWL_STYLE
, style
);
2067 DestroyWindow(child
);
2071 static void test_window_tree(HWND parent
, const DWORD
*style
, const int *order
, int total
)
2073 HWND child
[5], hwnd
;
2078 hwnd
= GetWindow(parent
, GW_CHILD
);
2079 ok(!hwnd
, "have to start without children to perform the test\n");
2081 for (i
= 0; i
< total
; i
++)
2083 if (style
[i
] & DS_CONTROL
)
2085 child
[i
] = CreateWindowExA(0, MAKEINTATOM(32770), "", style
[i
] & ~WS_VISIBLE
,
2086 0,0,0,0, parent
, (HMENU
)i
, 0, NULL
);
2087 if (style
[i
] & WS_VISIBLE
)
2088 ShowWindow(child
[i
], SW_SHOW
);
2090 SetWindowPos(child
[i
], HWND_BOTTOM
, 0,0,10,10, SWP_NOACTIVATE
);
2093 child
[i
] = CreateWindowExA(0, "static", "", style
[i
], 0,0,10,10,
2094 parent
, (HMENU
)i
, 0, NULL
);
2095 trace("child[%ld] = %p\n", i
, child
[i
]);
2096 ok(child
[i
] != 0, "CreateWindowEx failed to create child window\n");
2099 hwnd
= GetWindow(parent
, GW_CHILD
);
2100 ok(hwnd
!= 0, "GetWindow(GW_CHILD) failed\n");
2101 ok(hwnd
== GetWindow(child
[total
- 1], GW_HWNDFIRST
), "GW_HWNDFIRST is wrong\n");
2102 ok(child
[order
[total
- 1]] == GetWindow(child
[0], GW_HWNDLAST
), "GW_HWNDLAST is wrong\n");
2104 for (i
= 0; i
< total
; i
++)
2106 trace("hwnd[%ld] = %p\n", i
, hwnd
);
2107 ok(child
[order
[i
]] == hwnd
, "Z order of child #%ld is wrong\n", i
);
2109 hwnd
= GetWindow(hwnd
, GW_HWNDNEXT
);
2112 for (i
= 0; i
< total
; i
++)
2113 ok(DestroyWindow(child
[i
]), "DestroyWindow failed\n");
2116 static void test_children_zorder(HWND parent
)
2118 const DWORD simple_style
[5] = { WS_CHILD
, WS_CHILD
, WS_CHILD
, WS_CHILD
,
2120 const int simple_order
[5] = { 0, 1, 2, 3, 4 };
2122 const DWORD complex_style
[5] = { WS_CHILD
, WS_CHILD
| WS_MAXIMIZE
,
2123 WS_CHILD
| WS_VISIBLE
, WS_CHILD
,
2124 WS_CHILD
| WS_MAXIMIZE
| WS_VISIBLE
};
2125 const int complex_order_1
[1] = { 0 };
2126 const int complex_order_2
[2] = { 1, 0 };
2127 const int complex_order_3
[3] = { 1, 0, 2 };
2128 const int complex_order_4
[4] = { 1, 0, 2, 3 };
2129 const int complex_order_5
[5] = { 4, 1, 0, 2, 3 };
2130 const DWORD complex_style_6
[3] = { WS_CHILD
| WS_VISIBLE
,
2131 WS_CHILD
| WS_CLIPSIBLINGS
| DS_CONTROL
| WS_VISIBLE
,
2132 WS_CHILD
| WS_VISIBLE
};
2133 const int complex_order_6
[3] = { 0, 1, 2 };
2135 /* simple WS_CHILD */
2136 test_window_tree(parent
, simple_style
, simple_order
, 5);
2138 /* complex children styles */
2139 test_window_tree(parent
, complex_style
, complex_order_1
, 1);
2140 test_window_tree(parent
, complex_style
, complex_order_2
, 2);
2141 test_window_tree(parent
, complex_style
, complex_order_3
, 3);
2142 test_window_tree(parent
, complex_style
, complex_order_4
, 4);
2143 test_window_tree(parent
, complex_style
, complex_order_5
, 5);
2145 /* another set of complex children styles */
2146 test_window_tree(parent
, complex_style_6
, complex_order_6
, 3);
2149 #define check_z_order(hwnd, next, prev, owner, topmost) \
2150 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2153 static void check_z_order_debug(HWND hwnd
, HWND next
, HWND prev
, HWND owner
,
2154 BOOL topmost
, const char *file
, int line
)
2159 test
= GetWindow(hwnd
, GW_HWNDNEXT
);
2160 /* skip foreign windows */
2161 while (test
&& test
!= next
&&
2162 (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2163 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0) ||
2164 GetWindow(test
, GW_OWNER
) == next
))
2166 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2167 test
= GetWindow(test
, GW_HWNDNEXT
);
2169 ok_(file
, line
)(next
== test
, "%p: expected next %p, got %p\n", hwnd
, next
, test
);
2171 test
= GetWindow(hwnd
, GW_HWNDPREV
);
2172 /* skip foreign windows */
2173 while (test
&& test
!= prev
&&
2174 (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2175 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0) ||
2176 GetWindow(test
, GW_OWNER
) == hwnd
))
2178 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2179 test
= GetWindow(test
, GW_HWNDPREV
);
2181 ok_(file
, line
)(prev
== test
, "%p: expected prev %p, got %p\n", hwnd
, prev
, test
);
2183 test
= GetWindow(hwnd
, GW_OWNER
);
2184 ok_(file
, line
)(owner
== test
, "%p: expected owner %p, got %p\n", hwnd
, owner
, test
);
2186 ex_style
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
2187 ok_(file
, line
)(!(ex_style
& WS_EX_TOPMOST
) == !topmost
, "%p: expected %stopmost\n",
2188 hwnd
, topmost
? "" : "NOT ");
2191 static void test_popup_zorder(HWND hwnd_D
, HWND hwnd_E
, DWORD style
)
2193 HWND hwnd_A
, hwnd_B
, hwnd_C
, hwnd_F
;
2195 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D
, hwnd_E
);
2197 SetWindowPos(hwnd_E
, hwnd_D
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2199 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2200 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2202 hwnd_F
= CreateWindowEx(0, "MainWindowClass", "Owner window",
2203 WS_OVERLAPPED
| WS_CAPTION
,
2205 0, 0, GetModuleHandle(0), NULL
);
2206 trace("hwnd_F %p\n", hwnd_F
);
2207 check_z_order(hwnd_F
, hwnd_D
, 0, 0, FALSE
);
2209 SetWindowPos(hwnd_F
, hwnd_E
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2210 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2211 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2212 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2214 hwnd_C
= CreateWindowEx(0, "MainWindowClass", NULL
,
2217 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2218 trace("hwnd_C %p\n", hwnd_C
);
2219 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2220 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2221 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2222 check_z_order(hwnd_C
, hwnd_D
, 0, hwnd_F
, FALSE
);
2224 hwnd_B
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2227 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2228 trace("hwnd_B %p\n", hwnd_B
);
2229 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2230 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2231 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2232 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2233 check_z_order(hwnd_B
, hwnd_C
, 0, hwnd_F
, TRUE
);
2235 hwnd_A
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2238 0, 0, GetModuleHandle(0), NULL
);
2239 trace("hwnd_A %p\n", hwnd_A
);
2240 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2241 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2242 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2243 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2244 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2245 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2247 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
);
2249 /* move hwnd_F and its popups up */
2250 SetWindowPos(hwnd_F
, HWND_TOP
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2251 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2252 check_z_order(hwnd_D
, hwnd_E
, hwnd_F
, 0, FALSE
);
2253 check_z_order(hwnd_F
, hwnd_D
, hwnd_C
, 0, FALSE
);
2254 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2255 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2256 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2258 /* move hwnd_F and its popups down */
2259 #if 0 /* enable once Wine is fixed to pass this test */
2260 SetWindowPos(hwnd_F
, HWND_BOTTOM
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2261 check_z_order(hwnd_F
, 0, hwnd_C
, 0, FALSE
);
2262 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2263 check_z_order(hwnd_B
, hwnd_C
, hwnd_E
, hwnd_F
, FALSE
);
2264 check_z_order(hwnd_E
, hwnd_B
, hwnd_D
, 0, FALSE
);
2265 check_z_order(hwnd_D
, hwnd_E
, hwnd_A
, 0, FALSE
);
2266 check_z_order(hwnd_A
, hwnd_D
, 0, 0, TRUE
);
2269 /* make hwnd_C owned by a topmost window */
2270 DestroyWindow( hwnd_C
);
2271 hwnd_C
= CreateWindowEx(0, "MainWindowClass", NULL
,
2274 hwnd_A
, 0, GetModuleHandle(0), NULL
);
2275 trace("hwnd_C %p\n", hwnd_C
);
2276 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2277 check_z_order(hwnd_D
, hwnd_E
, hwnd_F
, 0, FALSE
);
2278 check_z_order(hwnd_F
, hwnd_D
, hwnd_B
, 0, FALSE
);
2279 check_z_order(hwnd_B
, hwnd_F
, hwnd_A
, hwnd_F
, TRUE
);
2280 check_z_order(hwnd_A
, hwnd_B
, hwnd_C
, 0, TRUE
);
2281 check_z_order(hwnd_C
, hwnd_A
, 0, hwnd_A
, TRUE
);
2283 DestroyWindow(hwnd_A
);
2284 DestroyWindow(hwnd_B
);
2285 DestroyWindow(hwnd_C
);
2286 DestroyWindow(hwnd_F
);
2289 static void test_vis_rgn( HWND hwnd
)
2291 RECT win_rect
, rgn_rect
;
2292 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2295 ShowWindow(hwnd
,SW_SHOW
);
2296 hdc
= GetDC( hwnd
);
2297 ok( GetRandomRgn( hdc
, hrgn
, SYSRGN
) != 0, "GetRandomRgn failed\n" );
2298 GetWindowRect( hwnd
, &win_rect
);
2299 GetRgnBox( hrgn
, &rgn_rect
);
2302 trace("win9x, mapping to screen coords\n");
2303 MapWindowPoints( hwnd
, 0, (POINT
*)&rgn_rect
, 2 );
2305 trace("win: %d,%d-%d,%d\n", win_rect
.left
, win_rect
.top
, win_rect
.right
, win_rect
.bottom
);
2306 trace("rgn: %d,%d-%d,%d\n", rgn_rect
.left
, rgn_rect
.top
, rgn_rect
.right
, rgn_rect
.bottom
);
2307 ok( win_rect
.left
<= rgn_rect
.left
, "rgn left %d not inside win rect %d\n",
2308 rgn_rect
.left
, win_rect
.left
);
2309 ok( win_rect
.top
<= rgn_rect
.top
, "rgn top %d not inside win rect %d\n",
2310 rgn_rect
.top
, win_rect
.top
);
2311 ok( win_rect
.right
>= rgn_rect
.right
, "rgn right %d not inside win rect %d\n",
2312 rgn_rect
.right
, win_rect
.right
);
2313 ok( win_rect
.bottom
>= rgn_rect
.bottom
, "rgn bottom %d not inside win rect %d\n",
2314 rgn_rect
.bottom
, win_rect
.bottom
);
2315 ReleaseDC( hwnd
, hdc
);
2318 static LRESULT WINAPI
set_focus_on_activate_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
2320 if (msg
== WM_ACTIVATE
&& LOWORD(wp
) == WA_ACTIVE
)
2322 HWND child
= GetWindow(hwnd
, GW_CHILD
);
2323 ok(child
!= 0, "couldn't find child window\n");
2325 ok(GetFocus() == child
, "Focus should be on child %p\n", child
);
2328 return DefWindowProc(hwnd
, msg
, wp
, lp
);
2331 static void test_SetFocus(HWND hwnd
)
2334 WNDPROC old_wnd_proc
;
2336 /* check if we can set focus to non-visible windows */
2338 ShowWindow(hwnd
, SW_SHOW
);
2341 ok( GetFocus() == hwnd
, "Failed to set focus to visible window %p\n", hwnd
);
2342 ok( GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
, "Window %p not visible\n", hwnd
);
2343 ShowWindow(hwnd
, SW_HIDE
);
2346 ok( GetFocus() == hwnd
, "Failed to set focus to invisible window %p\n", hwnd
);
2347 ok( !(GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
), "Window %p still visible\n", hwnd
);
2348 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2351 ok( GetFocus() == child
, "Failed to set focus to invisible child %p\n", child
);
2352 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2353 ShowWindow(child
, SW_SHOW
);
2354 ok( GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
, "Child %p is not visible\n", child
);
2355 ok( GetFocus() == child
, "Focus no longer on child %p\n", child
);
2356 ShowWindow(child
, SW_HIDE
);
2357 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2358 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2359 ShowWindow(child
, SW_SHOW
);
2360 child2
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, child
, 0, 0, NULL
);
2362 ShowWindow(child2
, SW_SHOW
);
2364 ShowWindow(child
, SW_HIDE
);
2365 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2366 ok( GetFocus() == child2
, "Focus should be on %p, not %p\n", child2
, GetFocus() );
2367 ShowWindow(child
, SW_SHOW
);
2369 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2370 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_HIDEWINDOW
);
2371 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2373 ShowWindow(child
, SW_HIDE
);
2375 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2376 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_SHOWWINDOW
);
2377 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2378 ShowWindow(child
, SW_HIDE
);
2379 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2381 ShowWindow(hwnd
, SW_SHOW
);
2382 ShowWindow(child
, SW_SHOW
);
2384 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2385 EnableWindow(hwnd
, FALSE
);
2386 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2387 EnableWindow(hwnd
, TRUE
);
2389 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2390 ShowWindow(hwnd
, SW_SHOWMINIMIZED
);
2391 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2393 ok( GetFocus() != child
, "Focus should not be on child %p\n", child
);
2394 ok( GetFocus() != hwnd
, "Focus should not be on parent %p\n", hwnd
);
2395 ShowWindow(hwnd
, SW_RESTORE
);
2396 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2397 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
2398 ShowWindow(hwnd
, SW_SHOWMINIMIZED
);
2399 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2400 ok( GetFocus() != child
, "Focus should not be on child %p\n", child
);
2402 ok( GetFocus() != hwnd
, "Focus should not be on parent %p\n", hwnd
);
2403 old_wnd_proc
= (WNDPROC
)SetWindowLongPtr(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)set_focus_on_activate_proc
);
2404 ShowWindow(hwnd
, SW_RESTORE
);
2405 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2407 ok( GetFocus() == child
, "Focus should be on child %p, not %p\n", child
, GetFocus() );
2409 SetWindowLongPtr(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)old_wnd_proc
);
2411 DestroyWindow( child2
);
2412 DestroyWindow( child
);
2415 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
2416 static void check_wnd_state_(const char *file
, int line
,
2417 HWND active
, HWND foreground
, HWND focus
, HWND capture
)
2419 ok_(file
, line
)(active
== GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2420 /* only check foreground if it belongs to the current thread */
2421 /* foreground can be moved to a different app pretty much at any time */
2422 if (foreground
&& GetForegroundWindow() &&
2423 GetWindowThreadProcessId(GetForegroundWindow(), NULL
) == GetCurrentThreadId())
2424 ok_(file
, line
)(foreground
== GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2425 ok_(file
, line
)(focus
== GetFocus(), "GetFocus() = %p\n", GetFocus());
2426 ok_(file
, line
)(capture
== GetCapture(), "GetCapture() = %p\n", GetCapture());
2429 static void test_SetActiveWindow(HWND hwnd
)
2433 flush_events( TRUE
);
2434 ShowWindow(hwnd
, SW_HIDE
);
2437 check_wnd_state(0, 0, 0, 0);
2439 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2441 ShowWindow(hwnd
, SW_SHOW
);
2442 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2444 hwnd2
= SetActiveWindow(0);
2445 ok(hwnd2
== hwnd
, "SetActiveWindow returned %p instead of %p\n", hwnd2
, hwnd
);
2446 if (!GetActiveWindow()) /* doesn't always work on vista */
2448 check_wnd_state(0, 0, 0, 0);
2449 hwnd2
= SetActiveWindow(hwnd
);
2450 ok(hwnd2
== 0, "SetActiveWindow returned %p instead of 0\n", hwnd2
);
2452 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2454 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2455 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2457 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2458 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2460 ShowWindow(hwnd
, SW_HIDE
);
2461 check_wnd_state(0, 0, 0, 0);
2463 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2464 SetActiveWindow(hwnd
);
2465 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2467 ShowWindow(hwnd
, SW_SHOW
);
2468 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2470 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2471 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2473 DestroyWindow(hwnd2
);
2474 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2476 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2477 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2479 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2480 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2482 DestroyWindow(hwnd2
);
2483 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2486 struct create_window_thread_params
2489 HANDLE window_created
;
2490 HANDLE test_finished
;
2493 static DWORD WINAPI
create_window_thread(void *param
)
2495 struct create_window_thread_params
*p
= param
;
2499 p
->window
= CreateWindowA("static", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 0, 0, 0, 0, 0, 0);
2501 ret
= SetEvent(p
->window_created
);
2502 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
2504 res
= WaitForSingleObject(p
->test_finished
, INFINITE
);
2505 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
2507 DestroyWindow(p
->window
);
2511 static void test_SetForegroundWindow(HWND hwnd
)
2513 struct create_window_thread_params thread_params
;
2520 flush_events( TRUE
);
2521 ShowWindow(hwnd
, SW_HIDE
);
2524 check_wnd_state(0, 0, 0, 0);
2526 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2528 ShowWindow(hwnd
, SW_SHOW
);
2529 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2531 hwnd2
= SetActiveWindow(0);
2532 ok(hwnd2
== hwnd
, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2
, hwnd
);
2533 if (GetActiveWindow() == hwnd
) /* doesn't always work on vista */
2534 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2536 check_wnd_state(0, 0, 0, 0);
2538 ret
= SetForegroundWindow(hwnd
);
2541 skip( "SetForegroundWindow not working\n" );
2544 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2546 SetLastError(0xdeadbeef);
2547 ret
= SetForegroundWindow(0);
2548 ok(!ret
, "SetForegroundWindow returned TRUE instead of FALSE\n");
2549 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
||
2550 broken(GetLastError() == 0xdeadbeef), /* win9x */
2551 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2552 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2554 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2555 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2557 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2558 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2560 hwnd2
= GetForegroundWindow();
2561 ok(hwnd2
== hwnd
, "Wrong foreground window %p\n", hwnd2
);
2562 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2563 hwnd2
= GetForegroundWindow();
2564 ok(hwnd2
!= hwnd
, "Wrong foreground window %p\n", hwnd2
);
2566 ShowWindow(hwnd
, SW_HIDE
);
2567 check_wnd_state(0, 0, 0, 0);
2569 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2570 ret
= SetForegroundWindow(hwnd
);
2571 ok(ret
|| broken(!ret
), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
2572 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2574 ShowWindow(hwnd
, SW_SHOW
);
2575 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2577 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2578 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2580 DestroyWindow(hwnd2
);
2581 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2583 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2584 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2586 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2587 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2589 DestroyWindow(hwnd2
);
2590 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2592 hwnd2
= CreateWindowA("static", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 0, 0, 0, 0, 0, 0);
2593 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2595 thread_params
.window_created
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
2596 ok(!!thread_params
.window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
2597 thread_params
.test_finished
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
2598 ok(!!thread_params
.test_finished
, "CreateEvent failed, last error %#x.\n", GetLastError());
2599 thread
= CreateThread(NULL
, 0, create_window_thread
, &thread_params
, 0, &tid
);
2600 ok(!!thread
, "Failed to create thread, last error %#x.\n", GetLastError());
2601 res
= WaitForSingleObject(thread_params
.window_created
, INFINITE
);
2602 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
2603 check_wnd_state(hwnd2
, thread_params
.window
, hwnd2
, 0);
2605 SetForegroundWindow(hwnd2
);
2606 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2608 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage(&msg
);
2609 if (0) check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2610 todo_wine
ok(GetActiveWindow() == hwnd2
, "Expected active window %p, got %p.\n", hwnd2
, GetActiveWindow());
2611 todo_wine
ok(GetFocus() == hwnd2
, "Expected focus window %p, got %p.\n", hwnd2
, GetFocus());
2613 SetEvent(thread_params
.test_finished
);
2614 WaitForSingleObject(thread
, INFINITE
);
2615 CloseHandle(thread_params
.test_finished
);
2616 CloseHandle(thread_params
.window_created
);
2617 CloseHandle(thread
);
2618 DestroyWindow(hwnd2
);
2621 static WNDPROC old_button_proc
;
2623 static LRESULT WINAPI
button_hook_proc(HWND button
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2628 key_state
= GetKeyState(VK_LBUTTON
);
2629 ok(!(key_state
& 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state
);
2631 ret
= CallWindowProcA(old_button_proc
, button
, msg
, wparam
, lparam
);
2633 if (msg
== WM_LBUTTONDOWN
)
2637 check_wnd_state(button
, button
, button
, button
);
2639 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2641 trace("hwnd %p\n", hwnd
);
2643 check_wnd_state(button
, button
, button
, button
);
2645 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2647 check_wnd_state(button
, button
, button
, button
);
2649 DestroyWindow(hwnd
);
2651 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2653 trace("hwnd %p\n", hwnd
);
2655 check_wnd_state(button
, button
, button
, button
);
2657 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2658 * match internal button state.
2660 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2661 check_wnd_state(button
, button
, button
, 0);
2663 ShowWindow(hwnd
, SW_SHOW
);
2664 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2666 capture
= SetCapture(hwnd
);
2667 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2669 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2671 DestroyWindow(hwnd
);
2673 check_wnd_state(button
, 0, button
, 0);
2679 static void test_capture_1(void)
2681 HWND button
, capture
, oldFocus
, oldActive
;
2683 oldFocus
= GetFocus();
2684 oldActive
= GetActiveWindow();
2686 capture
= GetCapture();
2687 ok(capture
== 0, "GetCapture() = %p\n", capture
);
2689 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2691 trace("button %p\n", button
);
2693 old_button_proc
= (WNDPROC
)SetWindowLongPtrA(button
, GWLP_WNDPROC
, (LONG_PTR
)button_hook_proc
);
2695 SendMessageA(button
, WM_LBUTTONDOWN
, 0, 0);
2697 capture
= SetCapture(button
);
2698 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2699 check_wnd_state(button
, 0, button
, button
);
2701 DestroyWindow(button
);
2702 check_wnd_state(oldActive
, 0, oldFocus
, 0);
2705 static void test_capture_2(void)
2707 HWND button
, hwnd
, capture
, oldFocus
, oldActive
;
2709 oldFocus
= GetFocus();
2710 oldActive
= GetActiveWindow();
2711 check_wnd_state(oldActive
, 0, oldFocus
, 0);
2713 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2715 trace("button %p\n", button
);
2717 check_wnd_state(button
, button
, button
, 0);
2719 capture
= SetCapture(button
);
2720 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2722 check_wnd_state(button
, button
, button
, button
);
2724 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2725 * internal button state.
2727 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2728 check_wnd_state(button
, button
, button
, button
);
2730 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2732 trace("hwnd %p\n", hwnd
);
2734 check_wnd_state(button
, button
, button
, button
);
2736 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2738 check_wnd_state(button
, button
, button
, button
);
2740 DestroyWindow(hwnd
);
2742 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2744 trace("hwnd %p\n", hwnd
);
2746 check_wnd_state(button
, button
, button
, button
);
2748 ShowWindow(hwnd
, SW_SHOW
);
2750 check_wnd_state(hwnd
, hwnd
, hwnd
, button
);
2752 capture
= SetCapture(hwnd
);
2753 ok(capture
== button
, "SetCapture() = %p\n", capture
);
2755 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2757 DestroyWindow(hwnd
);
2758 check_wnd_state(button
, button
, button
, 0);
2760 DestroyWindow(button
);
2761 check_wnd_state(oldActive
, 0, oldFocus
, 0);
2764 static void test_capture_3(HWND hwnd1
, HWND hwnd2
)
2768 ShowWindow(hwnd1
, SW_HIDE
);
2769 ShowWindow(hwnd2
, SW_HIDE
);
2771 ok(!IsWindowVisible(hwnd1
), "%p should be invisible\n", hwnd1
);
2772 ok(!IsWindowVisible(hwnd2
), "%p should be invisible\n", hwnd2
);
2775 check_wnd_state(0, 0, 0, hwnd1
);
2778 check_wnd_state(0, 0, 0, hwnd2
);
2780 ShowWindow(hwnd1
, SW_SHOW
);
2781 check_wnd_state(hwnd1
, hwnd1
, hwnd1
, hwnd2
);
2783 ret
= ReleaseCapture();
2784 ok (ret
, "releasecapture did not return TRUE.\n");
2785 ret
= ReleaseCapture();
2786 ok (ret
, "releasecapture did not return TRUE after second try.\n");
2789 static LRESULT CALLBACK
test_capture_4_proc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2792 HWND cap_wnd
, cap_wnd2
, set_cap_wnd
;
2796 case WM_CAPTURECHANGED
:
2798 /* now try to release capture from menu. this should fail */
2799 if (pGetGUIThreadInfo
)
2801 memset(>i
, 0, sizeof(GUITHREADINFO
));
2802 gti
.cbSize
= sizeof(GUITHREADINFO
);
2803 status
= pGetGUIThreadInfo(GetCurrentThreadId(), >i
);
2804 ok(status
, "GetGUIThreadInfo() failed!\n");
2805 ok(gti
.flags
& GUI_INMENUMODE
, "Thread info incorrect (flags=%08X)!\n", gti
.flags
);
2807 cap_wnd
= GetCapture();
2809 /* check that re-setting the capture for the menu fails */
2810 set_cap_wnd
= SetCapture(cap_wnd
);
2811 ok(!set_cap_wnd
|| broken(set_cap_wnd
== cap_wnd
), /* nt4 */
2812 "SetCapture should have failed!\n");
2815 DestroyWindow(hWnd
);
2819 /* check that SetCapture fails for another window and that it does not touch the error code */
2820 set_cap_wnd
= SetCapture(hWnd
);
2821 ok(!set_cap_wnd
, "SetCapture should have failed!\n");
2823 /* check that ReleaseCapture fails and does not touch the error code */
2824 status
= ReleaseCapture();
2825 ok(!status
, "ReleaseCapture should have failed!\n");
2827 /* check that thread info did not change */
2828 if (pGetGUIThreadInfo
)
2830 memset(>i
, 0, sizeof(GUITHREADINFO
));
2831 gti
.cbSize
= sizeof(GUITHREADINFO
);
2832 status
= pGetGUIThreadInfo(GetCurrentThreadId(), >i
);
2833 ok(status
, "GetGUIThreadInfo() failed!\n");
2834 ok(gti
.flags
& GUI_INMENUMODE
, "Thread info incorrect (flags=%08X)!\n", gti
.flags
);
2837 /* verify that no capture change took place */
2838 cap_wnd2
= GetCapture();
2839 ok(cap_wnd2
== cap_wnd
, "Capture changed!\n");
2841 /* we are done. kill the window */
2842 DestroyWindow(hWnd
);
2846 return( DefWindowProcA( hWnd
, msg
, wParam
, lParam
) );
2851 /* Test that no-one can mess around with the current capture while a menu is open */
2852 static void test_capture_4(void)
2858 HINSTANCE hInstance
= GetModuleHandleA( NULL
);
2860 if (!pGetGUIThreadInfo
)
2862 win_skip("GetGUIThreadInfo is not available\n");
2865 wclass
.lpszClassName
= "TestCapture4Class";
2866 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
2867 wclass
.lpfnWndProc
= test_capture_4_proc
;
2868 wclass
.hInstance
= hInstance
;
2869 wclass
.hIcon
= LoadIconA( 0, IDI_APPLICATION
);
2870 wclass
.hCursor
= LoadCursorA( NULL
, IDC_ARROW
);
2871 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
2872 wclass
.lpszMenuName
= 0;
2873 wclass
.cbClsExtra
= 0;
2874 wclass
.cbWndExtra
= 0;
2875 assert (RegisterClassA( &wclass
));
2876 assert (hwnd
= CreateWindowA( wclass
.lpszClassName
, "MenuTest",
2877 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0,
2878 400, 200, NULL
, NULL
, hInstance
, NULL
) );
2879 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
2881 hmenu
= CreatePopupMenu();
2883 ret
= AppendMenuA( hmenu
, MF_STRING
, 1, "winetest2");
2884 ok( ret
, "AppendMenuA has failed!\n");
2886 /* set main window to have initial capture */
2891 win_skip("TrackPopupMenu test crashes on Win9x/WinMe\n");
2895 /* create popup (it will self-destruct) */
2896 ret
= TrackPopupMenu(hmenu
, TPM_RETURNCMD
, 100, 100, 0, hwnd
, NULL
);
2897 ok( ret
== 0, "TrackPopupMenu returned %d expected zero\n", ret
);
2902 DestroyWindow(hwnd
);
2905 /* PeekMessage wrapper that ignores the messages we don't care about */
2906 static BOOL
peek_message( MSG
*msg
)
2911 ret
= PeekMessageA(msg
, 0, 0, 0, PM_REMOVE
);
2912 } while (ret
&& (msg
->message
== WM_TIMER
|| ignore_message(msg
->message
)));
2916 static void test_keyboard_input(HWND hwnd
)
2921 flush_events( TRUE
);
2922 SetWindowPos(hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_SHOWWINDOW
);
2924 flush_events( TRUE
);
2926 ok(GetActiveWindow() == hwnd
, "wrong active window %p\n", GetActiveWindow());
2929 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2931 flush_events( TRUE
);
2933 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2934 ret
= peek_message(&msg
);
2935 ok( ret
, "no message available\n");
2936 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2937 ret
= peek_message(&msg
);
2938 ok( !ret
, "message %04x available\n", msg
.message
);
2940 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2942 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2943 ret
= peek_message(&msg
);
2944 ok(ret
, "no message available\n");
2945 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2946 ret
= peek_message(&msg
);
2947 ok( !ret
, "message %04x available\n", msg
.message
);
2949 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2951 keybd_event(VK_SPACE
, 0, 0, 0);
2952 if (!peek_message(&msg
))
2954 skip( "keybd_event didn't work, skipping keyboard test\n" );
2957 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2958 ret
= peek_message(&msg
);
2959 ok( !ret
, "message %04x available\n", msg
.message
);
2962 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2964 flush_events( TRUE
);
2966 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2967 ret
= peek_message(&msg
);
2968 ok(ret
, "no message available\n");
2969 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2970 ret
= peek_message(&msg
);
2971 ok( !ret
, "message %04x available\n", msg
.message
);
2973 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2975 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2976 ret
= peek_message(&msg
);
2977 ok(ret
, "no message available\n");
2978 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2979 ret
= peek_message(&msg
);
2980 ok( !ret
, "message %04x available\n", msg
.message
);
2982 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2984 keybd_event(VK_SPACE
, 0, 0, 0);
2985 ret
= peek_message(&msg
);
2986 ok(ret
, "no message available\n");
2987 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_SYSKEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2988 ret
= peek_message(&msg
);
2989 ok( !ret
, "message %04x available\n", msg
.message
);
2992 static BOOL
wait_for_message( MSG
*msg
)
2998 ret
= peek_message(msg
);
3001 if (msg
->message
== WM_PAINT
) DispatchMessage(msg
);
3004 else if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, 100, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
3006 if (!ret
) msg
->message
= 0;
3010 static void test_mouse_input(HWND hwnd
)
3020 ShowWindow(hwnd
, SW_SHOWNORMAL
);
3022 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3024 GetWindowRect(hwnd
, &rc
);
3025 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3027 popup
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_POPUP
,
3028 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
,
3031 ShowWindow(popup
, SW_SHOW
);
3032 UpdateWindow(popup
);
3033 SetWindowPos( popup
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3035 GetWindowRect(popup
, &rc
);
3036 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3038 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
3039 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
3040 trace("setting cursor to (%d,%d)\n", x
, y
);
3044 if (x
!= pt
.x
|| y
!= pt
.y
)
3046 skip( "failed to set mouse position, skipping mouse input tests\n" );
3050 flush_events( TRUE
);
3052 /* Check that setting the same position may generate WM_MOUSEMOVE */
3055 ret
= peek_message(&msg
);
3058 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n",
3059 msg
.hwnd
, msg
.message
);
3060 ok(msg
.pt
.x
== x
&& msg
.pt
.y
== y
, "wrong message coords (%d,%d)/(%d,%d)\n",
3061 x
, y
, msg
.pt
.x
, msg
.pt
.y
);
3064 /* force the system to update its internal queue mouse position,
3065 * otherwise it won't generate relative mouse movements below.
3067 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
3068 flush_events( TRUE
);
3071 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
3072 flush_events( FALSE
);
3073 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
3074 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
3076 if (msg
.message
== WM_TIMER
|| ignore_message(msg
.message
)) continue;
3077 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
,
3078 "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3079 DispatchMessage(&msg
);
3081 ret
= peek_message(&msg
);
3082 ok( !ret
, "message %04x available\n", msg
.message
);
3084 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
3085 ShowWindow(popup
, SW_HIDE
);
3086 ret
= wait_for_message( &msg
);
3088 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3089 flush_events( TRUE
);
3091 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
3092 ShowWindow(hwnd
, SW_HIDE
);
3093 ret
= wait_for_message( &msg
);
3094 ok( !ret
, "message %04x available\n", msg
.message
);
3095 flush_events( TRUE
);
3097 /* test mouse clicks */
3099 ShowWindow(hwnd
, SW_SHOW
);
3100 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3101 flush_events( TRUE
);
3102 ShowWindow(popup
, SW_SHOW
);
3103 SetWindowPos( popup
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3104 flush_events( TRUE
);
3106 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3107 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3108 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3109 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3111 ret
= wait_for_message( &msg
);
3114 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
3117 if (msg
.message
== WM_MOUSEMOVE
) /* win2k has an extra WM_MOUSEMOVE here */
3119 ret
= wait_for_message( &msg
);
3120 ok(ret
, "no message available\n");
3123 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
3124 msg
.hwnd
, popup
, msg
.message
);
3126 ret
= wait_for_message( &msg
);
3127 ok(ret
, "no message available\n");
3128 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
3129 msg
.hwnd
, popup
, msg
.message
);
3131 ret
= wait_for_message( &msg
);
3132 ok(ret
, "no message available\n");
3133 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p/%p message %04x\n",
3134 msg
.hwnd
, popup
, msg
.message
);
3136 ret
= wait_for_message( &msg
);
3137 ok(ret
, "no message available\n");
3138 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
3139 msg
.hwnd
, popup
, msg
.message
);
3141 ret
= peek_message(&msg
);
3142 ok(!ret
, "message %04x available\n", msg
.message
);
3144 ShowWindow(popup
, SW_HIDE
);
3145 flush_events( TRUE
);
3147 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3148 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3149 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3150 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3152 ret
= wait_for_message( &msg
);
3153 ok(ret
, "no message available\n");
3154 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
3155 msg
.hwnd
, hwnd
, msg
.message
);
3156 ret
= wait_for_message( &msg
);
3157 ok(ret
, "no message available\n");
3158 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
3159 msg
.hwnd
, hwnd
, msg
.message
);
3161 test_lbuttondown_flag
= TRUE
;
3162 SendMessageA(hwnd
, WM_COMMAND
, (WPARAM
)popup
, 0);
3163 test_lbuttondown_flag
= FALSE
;
3165 ret
= wait_for_message( &msg
);
3166 ok(ret
, "no message available\n");
3167 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
3168 msg
.hwnd
, popup
, msg
.message
);
3169 ok(peek_message(&msg
), "no message available\n");
3170 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
3171 msg
.hwnd
, popup
, msg
.message
);
3172 ok(peek_message(&msg
), "no message available\n");
3174 /* Test WM_MOUSEACTIVATE */
3175 #define TEST_MOUSEACTIVATE(A,B) \
3176 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
3177 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
3179 TEST_MOUSEACTIVATE(HTERROR
,MA_ACTIVATE
);
3180 TEST_MOUSEACTIVATE(HTTRANSPARENT
,MA_ACTIVATE
);
3181 TEST_MOUSEACTIVATE(HTNOWHERE
,MA_ACTIVATE
);
3182 TEST_MOUSEACTIVATE(HTCLIENT
,MA_ACTIVATE
);
3183 TEST_MOUSEACTIVATE(HTCAPTION
,MA_ACTIVATE
);
3184 TEST_MOUSEACTIVATE(HTSYSMENU
,MA_ACTIVATE
);
3185 TEST_MOUSEACTIVATE(HTSIZE
,MA_ACTIVATE
);
3186 TEST_MOUSEACTIVATE(HTMENU
,MA_ACTIVATE
);
3187 TEST_MOUSEACTIVATE(HTHSCROLL
,MA_ACTIVATE
);
3188 TEST_MOUSEACTIVATE(HTVSCROLL
,MA_ACTIVATE
);
3189 TEST_MOUSEACTIVATE(HTMINBUTTON
,MA_ACTIVATE
);
3190 TEST_MOUSEACTIVATE(HTMAXBUTTON
,MA_ACTIVATE
);
3191 TEST_MOUSEACTIVATE(HTLEFT
,MA_ACTIVATE
);
3192 TEST_MOUSEACTIVATE(HTRIGHT
,MA_ACTIVATE
);
3193 TEST_MOUSEACTIVATE(HTTOP
,MA_ACTIVATE
);
3194 TEST_MOUSEACTIVATE(HTTOPLEFT
,MA_ACTIVATE
);
3195 TEST_MOUSEACTIVATE(HTTOPRIGHT
,MA_ACTIVATE
);
3196 TEST_MOUSEACTIVATE(HTBOTTOM
,MA_ACTIVATE
);
3197 TEST_MOUSEACTIVATE(HTBOTTOMLEFT
,MA_ACTIVATE
);
3198 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT
,MA_ACTIVATE
);
3199 TEST_MOUSEACTIVATE(HTBORDER
,MA_ACTIVATE
);
3200 TEST_MOUSEACTIVATE(HTOBJECT
,MA_ACTIVATE
);
3201 TEST_MOUSEACTIVATE(HTCLOSE
,MA_ACTIVATE
);
3202 TEST_MOUSEACTIVATE(HTHELP
,MA_ACTIVATE
);
3205 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
3206 flush_events( TRUE
);
3208 DestroyWindow(popup
);
3211 static void test_validatergn(HWND hwnd
)
3217 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_VISIBLE
, 10, 10, 10, 10, hwnd
, 0, 0, NULL
);
3218 ShowWindow(hwnd
, SW_SHOW
);
3219 UpdateWindow( hwnd
);
3220 /* test that ValidateRect validates children*/
3221 InvalidateRect( child
, NULL
, 1);
3222 GetWindowRect( child
, &rc
);
3223 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
3224 ret
= GetUpdateRect( child
, &rc2
, 0);
3225 ok( ret
== 1, "Expected GetUpdateRect to return non-zero, got %d\n", ret
);
3226 ok( rc2
.right
> rc2
.left
&& rc2
.bottom
> rc2
.top
,
3227 "Update rectangle is empty!\n");
3228 ValidateRect( hwnd
, &rc
);
3229 ret
= GetUpdateRect( child
, &rc2
, 0);
3230 ok( !ret
, "Expected GetUpdateRect to return zero, got %d\n", ret
);
3231 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
3232 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
3233 rc2
.right
, rc2
.bottom
);
3235 /* now test ValidateRgn */
3236 InvalidateRect( child
, NULL
, 1);
3237 GetWindowRect( child
, &rc
);
3238 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
3239 rgn
= CreateRectRgnIndirect( &rc
);
3240 ValidateRgn( hwnd
, rgn
);
3241 ret
= GetUpdateRect( child
, &rc2
, 0);
3242 ok( !ret
, "Expected GetUpdateRect to return zero, got %d\n", ret
);
3243 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
3244 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
3245 rc2
.right
, rc2
.bottom
);
3248 DestroyWindow( child
);
3251 static void nccalchelper(HWND hwnd
, INT x
, INT y
, RECT
*prc
)
3254 MoveWindow( hwnd
, 0, 0, x
, y
, 0);
3255 GetWindowRect( hwnd
, prc
);
3257 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)prc
);
3258 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
3259 rc
.left
,rc
.top
,rc
.right
,rc
.bottom
, prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
3262 static void test_nccalcscroll(HWND parent
)
3265 INT sbheight
= GetSystemMetrics( SM_CYHSCROLL
);
3266 INT sbwidth
= GetSystemMetrics( SM_CXVSCROLL
);
3267 HWND hwnd
= CreateWindowExA(0, "static", NULL
,
3268 WS_CHILD
| WS_VISIBLE
| WS_VSCROLL
| WS_HSCROLL
,
3269 10, 10, 200, 200, parent
, 0, 0, NULL
);
3270 ShowWindow( parent
, SW_SHOW
);
3271 UpdateWindow( parent
);
3273 /* test window too low for a horizontal scroll bar */
3274 nccalchelper( hwnd
, 100, sbheight
, &rc1
);
3275 ok( rc1
.bottom
- rc1
.top
== sbheight
, "Height should be %d size is %d,%d - %d,%d\n",
3276 sbheight
, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3278 /* test window just high enough for a horizontal scroll bar */
3279 nccalchelper( hwnd
, 100, sbheight
+ 1, &rc1
);
3280 ok( rc1
.bottom
- rc1
.top
== 1, "Height should be %d size is %d,%d - %d,%d\n",
3281 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3283 /* test window too narrow for a vertical scroll bar */
3284 nccalchelper( hwnd
, sbwidth
- 1, 100, &rc1
);
3285 ok( rc1
.right
- rc1
.left
== sbwidth
- 1 , "Width should be %d size is %d,%d - %d,%d\n",
3286 sbwidth
- 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3288 /* test window just wide enough for a vertical scroll bar */
3289 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
3290 ok( rc1
.right
- rc1
.left
== 0, "Width should be %d size is %d,%d - %d,%d\n",
3291 0, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3293 /* same test, but with client edge: not enough width */
3294 SetWindowLong( hwnd
, GWL_EXSTYLE
, WS_EX_CLIENTEDGE
| GetWindowLong( hwnd
, GWL_EXSTYLE
));
3295 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
3296 ok( rc1
.right
- rc1
.left
== sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
),
3297 "Width should be %d size is %d,%d - %d,%d\n",
3298 sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
), rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3300 DestroyWindow( hwnd
);
3303 static void test_SetParent(void)
3306 HWND desktop
= GetDesktopWindow();
3308 HWND parent
, child1
, child2
, child3
, child4
, sibling
;
3310 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
3311 100, 100, 200, 200, 0, 0, 0, NULL
);
3312 assert(parent
!= 0);
3313 child1
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
3314 0, 0, 50, 50, parent
, 0, 0, NULL
);
3315 assert(child1
!= 0);
3316 child2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
3317 0, 0, 50, 50, child1
, 0, 0, NULL
);
3318 assert(child2
!= 0);
3319 child3
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
3320 0, 0, 50, 50, child2
, 0, 0, NULL
);
3321 assert(child3
!= 0);
3322 child4
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
3323 0, 0, 50, 50, child3
, 0, 0, NULL
);
3324 assert(child4
!= 0);
3326 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
3327 parent
, child1
, child2
, child3
, child4
);
3329 check_parents(parent
, desktop
, 0, 0, 0, parent
, parent
);
3330 check_parents(child1
, parent
, parent
, parent
, 0, parent
, parent
);
3331 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
3332 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
3333 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
3335 ok(!IsChild(desktop
, parent
), "wrong parent/child %p/%p\n", desktop
, parent
);
3336 ok(!IsChild(desktop
, child1
), "wrong parent/child %p/%p\n", desktop
, child1
);
3337 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
3338 ok(!IsChild(desktop
, child3
), "wrong parent/child %p/%p\n", desktop
, child3
);
3339 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
3341 ok(IsChild(parent
, child1
), "wrong parent/child %p/%p\n", parent
, child1
);
3342 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
3343 ok(!IsChild(parent
, child2
), "wrong parent/child %p/%p\n", parent
, child2
);
3344 ok(!IsChild(child1
, child2
), "wrong parent/child %p/%p\n", child1
, child2
);
3345 ok(!IsChild(parent
, child3
), "wrong parent/child %p/%p\n", parent
, child3
);
3346 ok(IsChild(child2
, child3
), "wrong parent/child %p/%p\n", child2
, child3
);
3347 ok(!IsChild(parent
, child4
), "wrong parent/child %p/%p\n", parent
, child4
);
3348 ok(!IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
3349 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
3351 if (!is_win9x
) /* Win9x doesn't survive this test */
3355 ok(!SetParent(parent
, child1
), "SetParent should fail\n");
3356 ok(!SetParent(child2
, child3
), "SetParent should fail\n");
3357 ok(SetParent(child1
, parent
) != 0, "SetParent should not fail\n");
3358 ret
= SetParent(parent
, child2
);
3359 todo_wine
ok( !ret
|| broken( ret
!= 0 ), "SetParent should fail\n");
3360 if (ret
) /* nt4, win2k */
3362 ret
= SetParent(parent
, child3
);
3363 ok(ret
!= 0, "SetParent should not fail\n");
3364 ret
= SetParent(child2
, parent
);
3365 ok(!ret
, "SetParent should fail\n");
3366 ret
= SetParent(parent
, child4
);
3367 ok(ret
!= 0, "SetParent should not fail\n");
3368 check_parents(parent
, child4
, child4
, 0, 0, child4
, parent
);
3369 check_parents(child1
, parent
, parent
, parent
, 0, child4
, parent
);
3370 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
3371 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
3372 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
3376 ret
= SetParent(parent
, child3
);
3377 ok(ret
!= 0, "SetParent should not fail\n");
3378 ret
= SetParent(child2
, parent
);
3379 ok(!ret
, "SetParent should fail\n");
3380 ret
= SetParent(parent
, child4
);
3381 ok(!ret
, "SetParent should fail\n");
3382 check_parents(parent
, child3
, child3
, 0, 0, child2
, parent
);
3383 check_parents(child1
, parent
, parent
, parent
, 0, child2
, parent
);
3384 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
3385 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
3386 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
3390 skip("Win9x/WinMe crash\n");
3392 hMenu
= CreateMenu();
3393 sibling
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
3394 100, 100, 200, 200, 0, hMenu
, 0, NULL
);
3395 assert(sibling
!= 0);
3397 ok(SetParent(sibling
, parent
) != 0, "SetParent should not fail\n");
3398 ok(GetMenu(sibling
) == hMenu
, "SetParent should not remove menu\n");
3400 ret
= DestroyWindow(parent
);
3401 ok( ret
, "DestroyWindow() error %d\n", GetLastError());
3403 ok(!IsWindow(parent
), "parent still exists\n");
3404 ok(!IsWindow(sibling
), "sibling still exists\n");
3405 ok(!IsWindow(child1
), "child1 still exists\n");
3406 ok(!IsWindow(child2
), "child2 still exists\n");
3407 ok(!IsWindow(child3
), "child3 still exists\n");
3408 ok(!IsWindow(child4
), "child4 still exists\n");
3411 static LRESULT WINAPI
StyleCheckProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3413 LPCREATESTRUCT lpcs
;
3420 lpcs
= (LPCREATESTRUCT
)lparam
;
3421 lpss
= lpcs
->lpCreateParams
;
3424 if ((lpcs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
3425 ((!(lpcs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
3426 (lpcs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
3427 ok(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
, "Window should have WS_EX_WINDOWEDGE style\n");
3429 ok(!(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3431 ok((lpss
->styleOld
& ~WS_EX_WINDOWEDGE
) == (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
),
3432 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
3433 (lpss
->styleOld
& ~WS_EX_WINDOWEDGE
), (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
));
3435 ok(lpss
->styleNew
== lpcs
->style
,
3436 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3437 lpss
->styleNew
, lpcs
->style
);
3441 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3444 static ATOM atomStyleCheckClass
;
3446 static void register_style_check_class(void)
3454 GetModuleHandle(NULL
),
3456 LoadCursor(NULL
, IDC_ARROW
),
3457 (HBRUSH
)(COLOR_BTNFACE
+1),
3459 TEXT("WineStyleCheck"),
3462 atomStyleCheckClass
= RegisterClass(&wc
);
3465 static void check_window_style(DWORD dwStyleIn
, DWORD dwExStyleIn
, DWORD dwStyleOut
, DWORD dwExStyleOut
)
3467 DWORD dwActualStyle
;
3468 DWORD dwActualExStyle
;
3471 HWND hwndParent
= NULL
;
3473 ss
.styleNew
= dwStyleIn
;
3474 ss
.styleOld
= dwExStyleIn
;
3476 if (dwStyleIn
& WS_CHILD
)
3478 hwndParent
= CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3479 WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
3482 hwnd
= CreateWindowEx(dwExStyleIn
, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3483 dwStyleIn
, 0, 0, 0, 0, hwndParent
, NULL
, NULL
, &ss
);
3486 flush_events( TRUE
);
3488 dwActualStyle
= GetWindowLong(hwnd
, GWL_STYLE
);
3489 dwActualExStyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
3490 ok((dwActualStyle
== dwStyleOut
) && (dwActualExStyle
== dwExStyleOut
),
3491 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3492 dwActualStyle
, dwStyleOut
, dwActualExStyle
, dwExStyleOut
);
3494 DestroyWindow(hwnd
);
3495 if (hwndParent
) DestroyWindow(hwndParent
);
3498 /* tests what window styles the window manager automatically adds */
3499 static void test_window_styles(void)
3501 register_style_check_class();
3503 check_window_style(0, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
3504 check_window_style(WS_OVERLAPPEDWINDOW
, 0, WS_CLIPSIBLINGS
|WS_OVERLAPPEDWINDOW
, WS_EX_WINDOWEDGE
);
3505 check_window_style(WS_CHILD
, 0, WS_CHILD
, 0);
3506 check_window_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
3507 check_window_style(0, WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_TOOLWINDOW
);
3508 check_window_style(WS_POPUP
, 0, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3509 check_window_style(WS_POPUP
, WS_EX_WINDOWEDGE
, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3510 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
, WS_CHILD
, WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3511 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
|WS_EX_STATICEDGE
, WS_CHILD
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3512 check_window_style(WS_CAPTION
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
);
3513 check_window_style(0, WS_EX_APPWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_APPWINDOW
|WS_EX_WINDOWEDGE
);
3515 if (pGetLayeredWindowAttributes
)
3517 check_window_style(0, WS_EX_LAYERED
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_LAYERED
|WS_EX_WINDOWEDGE
);
3518 check_window_style(0, WS_EX_LAYERED
|WS_EX_TRANSPARENT
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_LAYERED
|WS_EX_TRANSPARENT
|WS_EX_WINDOWEDGE
);
3519 check_window_style(0, WS_EX_LAYERED
|WS_EX_TRANSPARENT
|WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
,
3520 WS_EX_LAYERED
|WS_EX_TRANSPARENT
|WS_EX_TOOLWINDOW
|WS_EX_WINDOWEDGE
);
3524 static void test_scrollwindow( HWND hwnd
)
3530 ShowWindow( hwnd
, SW_SHOW
);
3531 UpdateWindow( hwnd
);
3532 flush_events( TRUE
);
3533 GetClientRect( hwnd
, &rc
);
3535 /* test ScrollWindow(Ex) with no clip rectangle */
3536 /* paint the lower half of the window black */
3538 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
3539 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3540 /* paint the upper half of the window white */
3541 rc2
.bottom
= rc2
.top
;
3543 FillRect( hdc
, &rc2
, GetStockObject(WHITE_BRUSH
));
3544 /* scroll lower half up */
3546 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
3547 ScrollWindowEx( hwnd
, 0, - rc2
.top
, &rc2
, NULL
, NULL
, NULL
, SW_ERASE
);
3548 flush_events(FALSE
);
3549 /* expected: black should have scrolled to the upper half */
3550 colr
= GetPixel( hdc
, (rc2
.left
+rc2
.right
)/ 2, rc2
.bottom
/ 4 );
3551 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3552 /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
3553 /* paint the lower half of the window black */
3555 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
3556 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3557 /* paint the upper half of the window white */
3558 rc2
.bottom
= rc2
.top
;
3560 FillRect( hdc
, &rc2
, GetStockObject(WHITE_BRUSH
));
3561 /* scroll lower half up */
3563 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
3565 rc3
.left
= rc3
.right
/ 4;
3566 rc3
.right
-= rc3
.right
/ 4;
3567 ScrollWindowEx( hwnd
, 0, - rc2
.top
, &rc2
, &rc3
, NULL
, NULL
, SW_ERASE
);
3568 flush_events(FALSE
);
3569 /* expected: black should have scrolled to the upper half */
3570 colr
= GetPixel( hdc
, (rc2
.left
+rc2
.right
)/ 2, rc2
.bottom
/ 4 );
3571 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3574 ReleaseDC( hwnd
, hdc
);
3577 static void test_scrollvalidate( HWND parent
)
3580 HRGN hrgn
=CreateRectRgn(0,0,0,0);
3581 HRGN exprgn
, tmprgn
, clipping
;
3582 RECT rc
, rcu
, cliprc
;
3583 /* create two overlapping child windows. The visual region
3584 * of hwnd1 is clipped by the overlapping part of
3585 * hwnd2 because of the WS_CLIPSIBLING style */
3588 clipping
= CreateRectRgn(0,0,0,0);
3589 tmprgn
= CreateRectRgn(0,0,0,0);
3590 exprgn
= CreateRectRgn(0,0,0,0);
3591 hwnd2
= CreateWindowExA(0, "static", NULL
,
3592 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3593 75, 30, 100, 100, parent
, 0, 0, NULL
);
3594 hwnd1
= CreateWindowExA(0, "static", NULL
,
3595 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3596 25, 50, 100, 100, parent
, 0, 0, NULL
);
3597 ShowWindow( parent
, SW_SHOW
);
3598 UpdateWindow( parent
);
3599 GetClientRect( hwnd1
, &rc
);
3601 SetRectRgn( clipping
, 10, 10, 90, 90);
3602 hdc
= GetDC( hwnd1
);
3603 /* for a visual touch */
3604 TextOut( hdc
, 0,10, "0123456789", 10);
3605 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3606 if (winetest_debug
> 0) dump_region(hrgn
);
3607 /* create a region with what is expected */
3608 SetRectRgn( exprgn
, 39,0,49,74);
3609 SetRectRgn( tmprgn
, 88,79,98,93);
3610 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3611 SetRectRgn( tmprgn
, 0,93,98,98);
3612 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3613 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3614 trace("update rect is %d,%d - %d,%d\n",
3615 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3616 /* now with clipping region */
3617 SelectClipRgn( hdc
, clipping
);
3618 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3619 if (winetest_debug
> 0) dump_region(hrgn
);
3620 /* create a region with what is expected */
3621 SetRectRgn( exprgn
, 39,10,49,74);
3622 SetRectRgn( tmprgn
, 80,79,90,85);
3623 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3624 SetRectRgn( tmprgn
, 10,85,90,90);
3625 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3626 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3627 trace("update rect is %d,%d - %d,%d\n",
3628 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3629 ReleaseDC( hwnd1
, hdc
);
3631 /* test scrolling a window with an update region */
3632 DestroyWindow( hwnd2
);
3633 ValidateRect( hwnd1
, NULL
);
3634 SetRect( &rc
, 40,40, 50,50);
3635 InvalidateRect( hwnd1
, &rc
, 1);
3636 GetClientRect( hwnd1
, &rc
);
3638 ScrollWindowEx( hwnd1
, -10, 0, &rc
, &cliprc
, hrgn
, &rcu
,
3639 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3640 if (winetest_debug
> 0) dump_region(hrgn
);
3641 SetRectRgn( exprgn
, 88,0,98,98);
3642 SetRectRgn( tmprgn
, 30, 40, 50, 50);
3643 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3644 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3646 /* clear an update region */
3647 UpdateWindow( hwnd1
);
3649 SetRect( &rc
, 0,40, 100,60);
3650 SetRect( &cliprc
, 0,0, 100,100);
3651 ScrollWindowEx( hwnd1
, 0, -25, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3652 if (winetest_debug
> 0) dump_region( hrgn
);
3653 SetRectRgn( exprgn
, 0, 40, 98, 60 );
3654 ok( EqualRgn( exprgn
, hrgn
), "wrong update region in excessive scroll\n");
3656 /* now test ScrollWindowEx with a combination of
3657 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3658 /* make hwnd2 the child of hwnd1 */
3659 hwnd2
= CreateWindowExA(0, "static", NULL
,
3660 WS_CHILD
| WS_VISIBLE
| WS_BORDER
,
3661 50, 50, 100, 100, hwnd1
, 0, 0, NULL
);
3662 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPSIBLINGS
);
3663 GetClientRect( hwnd1
, &rc
);
3666 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3667 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3668 ValidateRect( hwnd1
, NULL
);
3669 ValidateRect( hwnd2
, NULL
);
3670 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
,
3671 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3672 if (winetest_debug
> 0) dump_region(hrgn
);
3673 SetRectRgn( exprgn
, 88,0,98,88);
3674 SetRectRgn( tmprgn
, 0,88,98,98);
3675 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3676 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3678 /* SW_SCROLLCHILDREN */
3679 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3680 ValidateRect( hwnd1
, NULL
);
3681 ValidateRect( hwnd2
, NULL
);
3682 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3683 if (winetest_debug
> 0) dump_region(hrgn
);
3684 /* expected region is the same as in previous test */
3685 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3687 /* no SW_SCROLLCHILDREN */
3688 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3689 ValidateRect( hwnd1
, NULL
);
3690 ValidateRect( hwnd2
, NULL
);
3691 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3692 if (winetest_debug
> 0) dump_region(hrgn
);
3693 /* expected region is the same as in previous test */
3694 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3696 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3697 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3698 ValidateRect( hwnd1
, NULL
);
3699 ValidateRect( hwnd2
, NULL
);
3700 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3701 if (winetest_debug
> 0) dump_region(hrgn
);
3702 SetRectRgn( exprgn
, 88,0,98,20);
3703 SetRectRgn( tmprgn
, 20,20,98,30);
3704 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3705 SetRectRgn( tmprgn
, 20,30,30,88);
3706 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3707 SetRectRgn( tmprgn
, 0,88,30,98);
3708 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3709 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3712 DeleteObject( hrgn
);
3713 DeleteObject( exprgn
);
3714 DeleteObject( tmprgn
);
3715 DestroyWindow( hwnd1
);
3716 DestroyWindow( hwnd2
);
3719 /* couple of tests of return values of scrollbar functions
3720 * called on a scrollbarless window */
3721 static void test_scroll(void)
3726 HWND hwnd
= CreateWindowExA(0, "Static", "Wine test window",
3727 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_POPUP
,
3728 100, 100, 200, 200, 0, 0, 0, NULL
);
3730 ret
= GetScrollRange( hwnd
, SB_HORZ
, &min
, &max
);
3731 if (!ret
) /* win9x */
3733 win_skip( "GetScrollRange doesn't work\n" );
3734 DestroyWindow( hwnd
);
3737 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3738 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3739 si
.cbSize
= sizeof( si
);
3740 si
.fMask
= SIF_PAGE
;
3741 si
.nPage
= 0xdeadbeef;
3742 ret
= GetScrollInfo( hwnd
, SB_HORZ
, &si
);
3743 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3744 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3746 ret
= GetScrollRange( hwnd
, SB_VERT
, &min
, &max
);
3747 ok( ret
, "GetScrollRange returns FALSE\n");
3748 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3749 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3750 si
.cbSize
= sizeof( si
);
3751 si
.fMask
= SIF_PAGE
;
3752 si
.nPage
= 0xdeadbeef;
3753 ret
= GetScrollInfo( hwnd
, SB_VERT
, &si
);
3754 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3755 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3757 DestroyWindow( hwnd
);
3760 static void test_scrolldc( HWND parent
)
3763 HRGN exprgn
, tmprgn
, hrgn
;
3764 RECT rc
, rc2
, rcu
, cliprc
;
3768 hrgn
= CreateRectRgn(0,0,0,0);
3769 tmprgn
= CreateRectRgn(0,0,0,0);
3770 exprgn
= CreateRectRgn(0,0,0,0);
3772 hwnd1
= CreateWindowExA(0, "static", NULL
,
3773 WS_CHILD
| WS_VISIBLE
,
3774 25, 50, 100, 100, parent
, 0, 0, NULL
);
3775 ShowWindow( parent
, SW_SHOW
);
3776 UpdateWindow( parent
);
3777 flush_events( TRUE
);
3778 GetClientRect( hwnd1
, &rc
);
3779 hdc
= GetDC( hwnd1
);
3780 /* paint the upper half of the window black */
3782 rc2
.bottom
= ( rc
.top
+ rc
.bottom
) /2;
3783 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3784 /* clip region is the lower half */
3786 cliprc
.top
= (rc
.top
+ rc
.bottom
) /2;
3787 /* test whether scrolled pixels are properly clipped */
3788 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3789 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3790 /* this scroll should not cause any visible changes */
3791 ScrollDC( hdc
, 5, -20, &rc
, &cliprc
, hrgn
, &rcu
);
3792 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3793 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3794 /* test with NULL clip rect */
3795 ScrollDC( hdc
, 20, -20, &rc
, NULL
, hrgn
, &rcu
);
3796 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3797 trace("update rect: %d,%d - %d,%d\n",
3798 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3799 if (winetest_debug
> 0) dump_region(hrgn
);
3800 SetRect(&rc2
, 0, 0, 100, 100);
3801 ok(EqualRect(&rcu
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3802 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
3804 SetRectRgn( exprgn
, 0, 0, 20, 80);
3805 SetRectRgn( tmprgn
, 0, 80, 100, 100);
3806 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3807 if (winetest_debug
> 0) dump_region(exprgn
);
3808 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3809 /* test clip rect > scroll rect */
3810 FillRect( hdc
, &rc
, GetStockObject(WHITE_BRUSH
));
3812 InflateRect( &rc2
, -(rc
.right
-rc
.left
)/4, -(rc
.bottom
-rc
.top
)/4);
3813 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3814 ScrollDC( hdc
, 10, 10, &rc2
, &rc
, hrgn
, &rcu
);
3815 SetRectRgn( exprgn
, 25, 25, 75, 35);
3816 SetRectRgn( tmprgn
, 25, 35, 35, 75);
3817 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3818 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3819 trace("update rect: %d,%d - %d,%d\n",
3820 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3821 if (winetest_debug
> 0) dump_region(hrgn
);
3825 DeleteObject(exprgn
);
3826 DeleteObject(tmprgn
);
3827 DestroyWindow(hwnd1
);
3830 static void test_params(void)
3835 /* Just a param check */
3836 if (pGetMonitorInfoA
)
3838 SetLastError(0xdeadbeef);
3839 rc
= GetWindowText(hwndMain2
, NULL
, 1024);
3840 ok( rc
==0, "GetWindowText: rc=%d err=%d\n",rc
,GetLastError());
3844 /* Skips actually on Win95 and NT4 */
3845 win_skip("Test would crash on Win95\n");
3848 SetLastError(0xdeadbeef);
3849 hwnd
=CreateWindow("LISTBOX", "TestList",
3850 (LBS_STANDARD
& ~LBS_SORT
),
3852 NULL
, (HMENU
)1, NULL
, 0);
3854 ok(!hwnd
|| broken(hwnd
!= NULL
), /* w2k3 sp2 */
3855 "CreateWindow with invalid menu handle should fail\n");
3857 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
|| /* NT */
3858 GetLastError() == 0xdeadbeef, /* Win9x */
3859 "wrong last error value %d\n", GetLastError());
3862 static void test_AWRwindow(LPCSTR
class, LONG style
, LONG exStyle
, BOOL menu
)
3866 hwnd
= CreateWindowEx(exStyle
, class, class, style
,
3873 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style
, exStyle
);
3876 ShowWindow(hwnd
, SW_SHOW
);
3878 test_nonclient_area(hwnd
);
3881 DestroyWindow(hwnd
);
3884 static BOOL
AWR_init(void)
3888 class.style
= CS_HREDRAW
| CS_VREDRAW
;
3889 class.lpfnWndProc
= DefWindowProcA
;
3890 class.cbClsExtra
= 0;
3891 class.cbWndExtra
= 0;
3892 class.hInstance
= 0;
3893 class.hIcon
= LoadIcon (0, IDI_APPLICATION
);
3894 class.hCursor
= LoadCursor (0, IDC_ARROW
);
3895 class.hbrBackground
= 0;
3896 class.lpszMenuName
= 0;
3897 class.lpszClassName
= szAWRClass
;
3899 if (!RegisterClass (&class)) {
3900 ok(FALSE
, "RegisterClass failed\n");
3904 hmenu
= CreateMenu();
3907 ok(hmenu
!= 0, "Failed to create menu\n");
3908 ok(AppendMenu(hmenu
, MF_STRING
, 1, "Test!"), "Failed to create menu item\n");
3914 static void test_AWR_window_size(BOOL menu
)
3918 WS_MAXIMIZE
, WS_BORDER
, WS_DLGFRAME
,
3921 WS_MINIMIZEBOX
, WS_MAXIMIZEBOX
,
3922 WS_HSCROLL
, WS_VSCROLL
3926 WS_EX_TOOLWINDOW
, WS_EX_WINDOWEDGE
,
3929 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3930 WS_EX_DLGMODALFRAME
,
3937 /* A exhaustive check of all the styles takes too long
3938 * so just do a (hopefully representative) sample
3940 for (i
= 0; i
< COUNTOF(styles
); ++i
)
3941 test_AWRwindow(szAWRClass
, styles
[i
], 0, menu
);
3942 for (i
= 0; i
< COUNTOF(exStyles
); ++i
) {
3943 test_AWRwindow(szAWRClass
, WS_POPUP
, exStyles
[i
], menu
);
3944 test_AWRwindow(szAWRClass
, WS_THICKFRAME
, exStyles
[i
], menu
);
3949 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3951 static void test_AdjustWindowRect(void)
3956 SHOWSYSMETRIC(SM_CYCAPTION
);
3957 SHOWSYSMETRIC(SM_CYSMCAPTION
);
3958 SHOWSYSMETRIC(SM_CYMENU
);
3959 SHOWSYSMETRIC(SM_CXEDGE
);
3960 SHOWSYSMETRIC(SM_CYEDGE
);
3961 SHOWSYSMETRIC(SM_CXVSCROLL
);
3962 SHOWSYSMETRIC(SM_CYHSCROLL
);
3963 SHOWSYSMETRIC(SM_CXFRAME
);
3964 SHOWSYSMETRIC(SM_CYFRAME
);
3965 SHOWSYSMETRIC(SM_CXDLGFRAME
);
3966 SHOWSYSMETRIC(SM_CYDLGFRAME
);
3967 SHOWSYSMETRIC(SM_CXBORDER
);
3968 SHOWSYSMETRIC(SM_CYBORDER
);
3970 test_AWR_window_size(FALSE
);
3971 test_AWR_window_size(TRUE
);
3975 #undef SHOWSYSMETRIC
3978 /* Global variables to trigger exit from loop */
3979 static int redrawComplete
, WMPAINT_count
;
3981 static LRESULT WINAPI
redraw_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3986 trace("doing WM_PAINT %d\n", WMPAINT_count
);
3988 if (WMPAINT_count
> 10 && redrawComplete
== 0) {
3990 BeginPaint(hwnd
, &ps
);
3991 EndPaint(hwnd
, &ps
);
3996 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3999 /* Ensure we exit from RedrawNow regardless of invalidated area */
4000 static void test_redrawnow(void)
4005 cls
.style
= CS_DBLCLKS
;
4006 cls
.lpfnWndProc
= redraw_window_procA
;
4009 cls
.hInstance
= GetModuleHandleA(0);
4011 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
4012 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4013 cls
.lpszMenuName
= NULL
;
4014 cls
.lpszClassName
= "RedrawWindowClass";
4016 if(!RegisterClassA(&cls
)) {
4017 trace("Register failed %d\n", GetLastError());
4021 hwndMain
= CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
4022 CW_USEDEFAULT
, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4024 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
4025 ShowWindow(hwndMain
, SW_SHOW
);
4026 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
4027 RedrawWindow(hwndMain
, NULL
,NULL
,RDW_UPDATENOW
| RDW_ALLCHILDREN
);
4028 ok( WMPAINT_count
== 1 || broken(WMPAINT_count
== 0), /* sometimes on win9x */
4029 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
4030 redrawComplete
= TRUE
;
4031 ok( WMPAINT_count
< 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count
);
4034 DestroyWindow( hwndMain
);
4037 struct parentdc_stat
{
4043 struct parentdc_test
{
4044 struct parentdc_stat main
, main_todo
;
4045 struct parentdc_stat child1
, child1_todo
;
4046 struct parentdc_stat child2
, child2_todo
;
4049 static LRESULT WINAPI
parentdc_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4054 struct parentdc_stat
*t
= (struct parentdc_stat
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
4059 GetClientRect(hwnd
, &rc
);
4060 CopyRect(&t
->client
, &rc
);
4061 GetWindowRect(hwnd
, &rc
);
4062 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd
,
4063 t
->client
.left
, t
->client
.top
, t
->client
.right
, t
->client
.bottom
,
4064 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4065 BeginPaint(hwnd
, &ps
);
4066 CopyRect(&t
->paint
, &ps
.rcPaint
);
4067 GetClipBox(ps
.hdc
, &rc
);
4068 CopyRect(&t
->clip
, &rc
);
4069 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
4070 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
4071 ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
4072 EndPaint(hwnd
, &ps
);
4075 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
4078 static void zero_parentdc_stat(struct parentdc_stat
*t
)
4080 SetRectEmpty(&t
->client
);
4081 SetRectEmpty(&t
->clip
);
4082 SetRectEmpty(&t
->paint
);
4085 static void zero_parentdc_test(struct parentdc_test
*t
)
4087 zero_parentdc_stat(&t
->main
);
4088 zero_parentdc_stat(&t
->child1
);
4089 zero_parentdc_stat(&t
->child2
);
4092 #define parentdc_field_ok(t, w, r, f, got) \
4093 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
4094 ": expected %d, got %d\n", \
4097 #define parentdc_todo_field_ok(t, w, r, f, got) \
4098 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
4099 else parentdc_field_ok(t, w, r, f, got)
4101 #define parentdc_rect_ok(t, w, r, got) \
4102 parentdc_todo_field_ok(t, w, r, left, got); \
4103 parentdc_todo_field_ok(t, w, r, top, got); \
4104 parentdc_todo_field_ok(t, w, r, right, got); \
4105 parentdc_todo_field_ok(t, w, r, bottom, got);
4107 #define parentdc_win_ok(t, w, got) \
4108 parentdc_rect_ok(t, w, client, got); \
4109 parentdc_rect_ok(t, w, clip, got); \
4110 parentdc_rect_ok(t, w, paint, got);
4112 #define parentdc_ok(t, got) \
4113 parentdc_win_ok(t, main, got); \
4114 parentdc_win_ok(t, child1, got); \
4115 parentdc_win_ok(t, child2, got);
4117 static void test_csparentdc(void)
4119 WNDCLASSA clsMain
, cls
;
4120 HWND hwndMain
, hwnd1
, hwnd2
;
4123 struct parentdc_test test_answer
;
4125 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
4126 const struct parentdc_test test1
=
4128 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo
,
4129 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4130 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4133 const struct parentdc_test test2
=
4135 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo
,
4136 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4137 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4140 const struct parentdc_test test3
=
4142 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
4143 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
4144 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
4147 const struct parentdc_test test4
=
4149 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo
,
4150 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo
,
4151 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
4154 const struct parentdc_test test5
=
4156 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo
,
4157 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4158 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4161 const struct parentdc_test test6
=
4163 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
4164 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
4165 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
4168 const struct parentdc_test test7
=
4170 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
4171 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4172 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
4176 clsMain
.style
= CS_DBLCLKS
;
4177 clsMain
.lpfnWndProc
= parentdc_window_procA
;
4178 clsMain
.cbClsExtra
= 0;
4179 clsMain
.cbWndExtra
= 0;
4180 clsMain
.hInstance
= GetModuleHandleA(0);
4182 clsMain
.hCursor
= LoadCursorA(0, IDC_ARROW
);
4183 clsMain
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4184 clsMain
.lpszMenuName
= NULL
;
4185 clsMain
.lpszClassName
= "ParentDcMainWindowClass";
4187 if(!RegisterClassA(&clsMain
)) {
4188 trace("Register failed %d\n", GetLastError());
4192 cls
.style
= CS_DBLCLKS
| CS_PARENTDC
;
4193 cls
.lpfnWndProc
= parentdc_window_procA
;
4196 cls
.hInstance
= GetModuleHandleA(0);
4198 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
4199 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4200 cls
.lpszMenuName
= NULL
;
4201 cls
.lpszClassName
= "ParentDcWindowClass";
4203 if(!RegisterClassA(&cls
)) {
4204 trace("Register failed %d\n", GetLastError());
4208 SetRect(&rc
, 0, 0, 150, 150);
4209 AdjustWindowRectEx(&rc
, WS_OVERLAPPEDWINDOW
, FALSE
, 0);
4210 hwndMain
= CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
4211 CW_USEDEFAULT
, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, NULL
, NULL
, 0, NULL
);
4212 SetWindowLongPtrA(hwndMain
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.main
);
4213 hwnd1
= CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD
,
4214 20, 20, 40, 40, hwndMain
, NULL
, 0, NULL
);
4215 SetWindowLongPtrA(hwnd1
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child1
);
4216 hwnd2
= CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD
,
4217 40, 40, 40, 40, hwndMain
, NULL
, 0, NULL
);
4218 SetWindowLongPtrA(hwnd2
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child2
);
4219 ShowWindow(hwndMain
, SW_SHOW
);
4220 ShowWindow(hwnd1
, SW_SHOW
);
4221 ShowWindow(hwnd2
, SW_SHOW
);
4222 SetWindowPos(hwndMain
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
4223 flush_events( TRUE
);
4225 zero_parentdc_test(&test_answer
);
4226 InvalidateRect(hwndMain
, NULL
, TRUE
);
4227 flush_events( TRUE
);
4228 parentdc_ok(test1
, test_answer
);
4230 zero_parentdc_test(&test_answer
);
4231 SetRect(&rc
, 0, 0, 50, 50);
4232 InvalidateRect(hwndMain
, &rc
, TRUE
);
4233 flush_events( TRUE
);
4234 parentdc_ok(test2
, test_answer
);
4236 zero_parentdc_test(&test_answer
);
4237 SetRect(&rc
, 0, 0, 10, 10);
4238 InvalidateRect(hwndMain
, &rc
, TRUE
);
4239 flush_events( TRUE
);
4240 parentdc_ok(test3
, test_answer
);
4242 zero_parentdc_test(&test_answer
);
4243 SetRect(&rc
, 40, 40, 50, 50);
4244 InvalidateRect(hwndMain
, &rc
, TRUE
);
4245 flush_events( TRUE
);
4246 parentdc_ok(test4
, test_answer
);
4248 zero_parentdc_test(&test_answer
);
4249 SetRect(&rc
, 20, 20, 60, 60);
4250 InvalidateRect(hwndMain
, &rc
, TRUE
);
4251 flush_events( TRUE
);
4252 parentdc_ok(test5
, test_answer
);
4254 zero_parentdc_test(&test_answer
);
4255 SetRect(&rc
, 0, 0, 10, 10);
4256 InvalidateRect(hwnd1
, &rc
, TRUE
);
4257 flush_events( TRUE
);
4258 parentdc_ok(test6
, test_answer
);
4260 zero_parentdc_test(&test_answer
);
4261 SetRect(&rc
, -5, -5, 65, 65);
4262 InvalidateRect(hwnd1
, &rc
, TRUE
);
4263 flush_events( TRUE
);
4264 parentdc_ok(test7
, test_answer
);
4266 DestroyWindow(hwndMain
);
4267 DestroyWindow(hwnd1
);
4268 DestroyWindow(hwnd2
);
4271 static LRESULT WINAPI
def_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4273 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
4276 static LRESULT WINAPI
def_window_procW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4278 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
4281 static void test_IsWindowUnicode(void)
4283 static const char ansi_class_nameA
[] = "ansi class name";
4284 static const WCHAR ansi_class_nameW
[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
4285 static const char unicode_class_nameA
[] = "unicode class name";
4286 static const WCHAR unicode_class_nameW
[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
4291 memset(&classW
, 0, sizeof(classW
));
4292 classW
.hInstance
= GetModuleHandleA(0);
4293 classW
.lpfnWndProc
= def_window_procW
;
4294 classW
.lpszClassName
= unicode_class_nameW
;
4295 if (!RegisterClassW(&classW
)) return; /* this catches Win9x as well */
4297 memset(&classA
, 0, sizeof(classA
));
4298 classA
.hInstance
= GetModuleHandleA(0);
4299 classA
.lpfnWndProc
= def_window_procA
;
4300 classA
.lpszClassName
= ansi_class_nameA
;
4301 assert(RegisterClassA(&classA
));
4303 /* unicode class: window proc */
4304 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
4305 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4308 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4309 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
4310 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4311 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
4312 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4314 DestroyWindow(hwnd
);
4316 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
4317 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4320 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4321 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
4322 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4323 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
4324 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4326 DestroyWindow(hwnd
);
4328 /* ansi class: window proc */
4329 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
4330 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4333 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4334 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
4335 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4336 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
4337 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4339 DestroyWindow(hwnd
);
4341 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
4342 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4345 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4346 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
4347 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4348 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
4349 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4351 DestroyWindow(hwnd
);
4353 /* unicode class: class proc */
4354 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
4355 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4358 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4359 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
4360 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4361 /* do not restore class window proc back to unicode */
4363 DestroyWindow(hwnd
);
4365 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
4366 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4369 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4370 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
4371 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4373 DestroyWindow(hwnd
);
4375 /* ansi class: class proc */
4376 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
4377 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4380 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4381 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
4382 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4383 /* do not restore class window proc back to ansi */
4385 DestroyWindow(hwnd
);
4387 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
4388 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4391 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4392 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
4393 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4395 DestroyWindow(hwnd
);
4398 static LRESULT CALLBACK
minmax_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
4402 if (msg
!= WM_GETMINMAXINFO
)
4403 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4405 minmax
= (MINMAXINFO
*)lp
;
4407 if ((GetWindowLong(hwnd
, GWL_STYLE
) & WS_CHILD
))
4409 minmax
->ptReserved
.x
= 0;
4410 minmax
->ptReserved
.y
= 0;
4411 minmax
->ptMaxSize
.x
= 400;
4412 minmax
->ptMaxSize
.y
= 400;
4413 minmax
->ptMaxPosition
.x
= 300;
4414 minmax
->ptMaxPosition
.y
= 300;
4415 minmax
->ptMaxTrackSize
.x
= 200;
4416 minmax
->ptMaxTrackSize
.y
= 200;
4417 minmax
->ptMinTrackSize
.x
= 100;
4418 minmax
->ptMinTrackSize
.y
= 100;
4421 DefWindowProc(hwnd
, msg
, wp
, lp
);
4425 static int expected_cx
, expected_cy
;
4426 static RECT expected_rect
, broken_rect
;
4428 static LRESULT CALLBACK
winsizes_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
4432 case WM_GETMINMAXINFO
:
4435 GetWindowRect( hwnd
, &rect
);
4436 ok( !rect
.left
&& !rect
.top
&& !rect
.right
&& !rect
.bottom
,
4437 "wrong rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4438 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4443 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
4445 GetWindowRect( hwnd
, &rect
);
4446 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
4447 hwnd
, msg
, cs
->cx
, cs
->cy
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4448 ok( cs
->cx
== expected_cx
|| broken(cs
->cx
== (short)expected_cx
),
4449 "wrong x size %d/%d\n", cs
->cx
, expected_cx
);
4450 ok( cs
->cy
== expected_cy
|| broken(cs
->cy
== (short)expected_cy
),
4451 "wrong y size %d/%d\n", cs
->cy
, expected_cy
);
4452 ok( (rect
.right
- rect
.left
== expected_rect
.right
- expected_rect
.left
&&
4453 rect
.bottom
- rect
.top
== expected_rect
.bottom
- expected_rect
.top
) ||
4454 broken( rect
.right
- rect
.left
== broken_rect
.right
- broken_rect
.left
&&
4455 rect
.bottom
- rect
.top
== broken_rect
.bottom
- broken_rect
.top
) ||
4456 broken( rect
.right
- rect
.left
== (short)broken_rect
.right
- (short)broken_rect
.left
&&
4457 rect
.bottom
- rect
.top
== (short)broken_rect
.bottom
- (short)broken_rect
.top
),
4458 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
4459 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
4460 expected_rect
.left
, expected_rect
.top
, expected_rect
.right
, expected_rect
.bottom
);
4461 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4465 RECT rect
, *r
= (RECT
*)lp
;
4466 GetWindowRect( hwnd
, &rect
);
4467 ok( !memcmp( &rect
, r
, sizeof(rect
) ),
4468 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
4469 r
->left
, r
->top
, r
->right
, r
->bottom
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4470 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4473 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4477 static void test_CreateWindow(void)
4485 #define expect_menu(window, menu) \
4486 SetLastError(0xdeadbeef); \
4487 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
4489 #define expect_style(window, style)\
4490 ok((ULONG)GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
4492 #define expect_ex_style(window, ex_style)\
4493 ok((ULONG)GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
4495 #define expect_gle_broken_9x(gle)\
4496 ok(GetLastError() == gle ||\
4497 broken(GetLastError() == 0xdeadbeef),\
4498 "IsMenu set error %d\n", GetLastError())
4500 hmenu
= CreateMenu();
4502 parent
= GetDesktopWindow();
4503 assert(parent
!= 0);
4505 SetLastError(0xdeadbeef);
4506 ok(IsMenu(hmenu
), "IsMenu error %d\n", GetLastError());
4509 SetLastError(0xdeadbeef);
4510 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
,
4511 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4512 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4513 expect_menu(hwnd
, 1);
4514 expect_style(hwnd
, WS_CHILD
);
4515 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4516 DestroyWindow(hwnd
);
4518 SetLastError(0xdeadbeef);
4519 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_CAPTION
,
4520 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4521 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4522 expect_menu(hwnd
, 1);
4523 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
4524 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4525 DestroyWindow(hwnd
);
4527 SetLastError(0xdeadbeef);
4528 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
,
4529 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4530 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4531 expect_menu(hwnd
, 1);
4532 expect_style(hwnd
, WS_CHILD
);
4533 expect_ex_style(hwnd
, 0);
4534 DestroyWindow(hwnd
);
4536 SetLastError(0xdeadbeef);
4537 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_CAPTION
,
4538 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4539 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4540 expect_menu(hwnd
, 1);
4541 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
4542 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4543 DestroyWindow(hwnd
);
4546 SetLastError(0xdeadbeef);
4547 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
4548 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4549 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4550 expect_menu(hwnd
, hmenu
);
4551 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4552 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4553 DestroyWindow(hwnd
);
4554 SetLastError(0xdeadbeef);
4555 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4556 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4558 hmenu
= CreateMenu();
4560 SetLastError(0xdeadbeef);
4561 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4562 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4563 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4564 expect_menu(hwnd
, hmenu
);
4565 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4566 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4567 DestroyWindow(hwnd
);
4568 SetLastError(0xdeadbeef);
4569 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4570 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4572 hmenu
= CreateMenu();
4574 SetLastError(0xdeadbeef);
4575 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
,
4576 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4577 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4578 expect_menu(hwnd
, hmenu
);
4579 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4580 expect_ex_style(hwnd
, 0);
4581 DestroyWindow(hwnd
);
4582 SetLastError(0xdeadbeef);
4583 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4584 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4586 hmenu
= CreateMenu();
4588 SetLastError(0xdeadbeef);
4589 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4590 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4591 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4592 expect_menu(hwnd
, hmenu
);
4593 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4594 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4595 DestroyWindow(hwnd
);
4596 SetLastError(0xdeadbeef);
4597 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4598 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4600 /* WS_CHILD | WS_POPUP */
4601 SetLastError(0xdeadbeef);
4602 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4603 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4604 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
4605 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4607 DestroyWindow(hwnd
);
4609 hmenu
= CreateMenu();
4611 SetLastError(0xdeadbeef);
4612 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4613 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4614 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4615 expect_menu(hwnd
, hmenu
);
4616 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4617 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4618 DestroyWindow(hwnd
);
4619 SetLastError(0xdeadbeef);
4620 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4621 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4623 SetLastError(0xdeadbeef);
4624 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4625 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4626 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
4627 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4629 DestroyWindow(hwnd
);
4631 hmenu
= CreateMenu();
4633 SetLastError(0xdeadbeef);
4634 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4635 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4636 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4637 expect_menu(hwnd
, hmenu
);
4638 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4639 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4640 DestroyWindow(hwnd
);
4641 SetLastError(0xdeadbeef);
4642 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4643 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4645 SetLastError(0xdeadbeef);
4646 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4647 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4648 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
4649 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4651 DestroyWindow(hwnd
);
4653 hmenu
= CreateMenu();
4655 SetLastError(0xdeadbeef);
4656 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4657 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4658 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4659 expect_menu(hwnd
, hmenu
);
4660 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4661 expect_ex_style(hwnd
, 0);
4662 DestroyWindow(hwnd
);
4663 SetLastError(0xdeadbeef);
4664 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4665 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4667 SetLastError(0xdeadbeef);
4668 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4669 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4670 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
4671 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4673 DestroyWindow(hwnd
);
4675 hmenu
= CreateMenu();
4677 SetLastError(0xdeadbeef);
4678 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4679 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4680 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4681 expect_menu(hwnd
, hmenu
);
4682 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4683 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4684 DestroyWindow(hwnd
);
4685 SetLastError(0xdeadbeef);
4686 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4687 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4689 /* test child window sizing */
4691 cls
.lpfnWndProc
= minmax_wnd_proc
;
4694 cls
.hInstance
= GetModuleHandle(0);
4696 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
4697 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4698 cls
.lpszMenuName
= NULL
;
4699 cls
.lpszClassName
= "MinMax_WndClass";
4700 RegisterClass(&cls
);
4702 SetLastError(0xdeadbeef);
4703 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4704 0, 0, 100, 100, 0, 0, 0, NULL
);
4705 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
4706 expect_menu(parent
, 0);
4707 expect_style(parent
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
| WS_CLIPSIBLINGS
);
4708 expect_ex_style(parent
, WS_EX_WINDOWEDGE
);
4710 memset(&minmax
, 0, sizeof(minmax
));
4711 SendMessage(parent
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4712 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxSize
.x
, minmax
.ptMaxSize
.y
);
4713 ok(IsRectEmpty(&rc_minmax
), "ptMaxSize is not empty\n");
4714 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4715 ok(IsRectEmpty(&rc_minmax
), "ptMaxTrackSize is not empty\n");
4717 GetWindowRect(parent
, &rc
);
4718 ok(!IsRectEmpty(&rc
), "parent window rect is empty\n");
4719 GetClientRect(parent
, &rc
);
4720 ok(!IsRectEmpty(&rc
), "parent client rect is empty\n");
4722 InflateRect(&rc
, 200, 200);
4723 trace("creating child with rect (%d,%d-%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4725 SetLastError(0xdeadbeef);
4726 hwnd
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4727 rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
4728 parent
, (HMENU
)1, 0, NULL
);
4729 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4730 expect_menu(hwnd
, 1);
4731 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
);
4732 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4734 memset(&minmax
, 0, sizeof(minmax
));
4735 SendMessage(hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4736 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4738 GetWindowRect(hwnd
, &rc
);
4739 OffsetRect(&rc
, -rc
.left
, -rc
.top
);
4740 ok(EqualRect(&rc
, &rc_minmax
), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4741 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
4742 rc_minmax
.left
, rc_minmax
.top
, rc_minmax
.right
, rc_minmax
.bottom
);
4743 DestroyWindow(hwnd
);
4745 cls
.lpfnWndProc
= winsizes_wnd_proc
;
4746 cls
.lpszClassName
= "Sizes_WndClass";
4747 RegisterClass(&cls
);
4749 expected_cx
= expected_cy
= 200000;
4750 SetRect( &expected_rect
, 0, 0, 200000, 200000 );
4751 broken_rect
= expected_rect
;
4752 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 300000, 300000, 200000, 200000, parent
, 0, 0, NULL
);
4753 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4754 GetClientRect( hwnd
, &rc
);
4755 ok( rc
.right
== 200000 || broken(rc
.right
== (short)200000), "invalid rect right %u\n", rc
.right
);
4756 ok( rc
.bottom
== 200000 || broken(rc
.bottom
== (short)200000), "invalid rect bottom %u\n", rc
.bottom
);
4757 DestroyWindow(hwnd
);
4759 expected_cx
= expected_cy
= -10;
4760 SetRect( &expected_rect
, 0, 0, 0, 0 );
4761 SetRect( &broken_rect
, 0, 0, -10, -10 );
4762 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -20, -20, -10, -10, parent
, 0, 0, NULL
);
4763 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4764 GetClientRect( hwnd
, &rc
);
4765 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4766 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4767 DestroyWindow(hwnd
);
4769 expected_cx
= expected_cy
= -200000;
4770 SetRect( &expected_rect
, 0, 0, 0, 0 );
4771 SetRect( &broken_rect
, 0, 0, -200000, -200000 );
4772 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -300000, -300000, -200000, -200000, parent
, 0, 0, NULL
);
4773 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4774 GetClientRect( hwnd
, &rc
);
4775 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4776 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4777 DestroyWindow(hwnd
);
4779 /* we need a parent at 0,0 so that child coordinates match */
4780 DestroyWindow(parent
);
4781 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_POPUP
, 0, 0, 100, 100, 0, 0, 0, NULL
);
4782 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
4785 expected_cy
= 0x7fffffff;
4786 SetRect( &expected_rect
, 10, 10, 110, 0x7fffffff );
4787 SetRect( &broken_rect
, 10, 10, 110, 0x7fffffffU
+ 10 );
4788 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 10, 10, 100, 0x7fffffff, parent
, 0, 0, NULL
);
4789 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4790 GetClientRect( hwnd
, &rc
);
4791 ok( rc
.right
== 100, "invalid rect right %u\n", rc
.right
);
4792 ok( rc
.bottom
== 0x7fffffff - 10 || broken(rc
.bottom
== 0), "invalid rect bottom %u\n", rc
.bottom
);
4793 DestroyWindow(hwnd
);
4795 expected_cx
= 0x7fffffff;
4796 expected_cy
= 0x7fffffff;
4797 SetRect( &expected_rect
, 20, 10, 0x7fffffff, 0x7fffffff );
4798 SetRect( &broken_rect
, 20, 10, 0x7fffffffU
+ 20, 0x7fffffffU
+ 10 );
4799 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 20, 10, 0x7fffffff, 0x7fffffff, parent
, 0, 0, NULL
);
4800 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4801 GetClientRect( hwnd
, &rc
);
4802 ok( rc
.right
== 0x7fffffff - 20 || broken(rc
.right
== 0), "invalid rect right %u\n", rc
.right
);
4803 ok( rc
.bottom
== 0x7fffffff - 10 || broken(rc
.bottom
== 0), "invalid rect bottom %u\n", rc
.bottom
);
4804 DestroyWindow(hwnd
);
4806 /* top level window */
4807 expected_cx
= expected_cy
= 200000;
4808 SetRect( &expected_rect
, 0, 0, GetSystemMetrics(SM_CXMAXTRACK
), GetSystemMetrics(SM_CYMAXTRACK
) );
4809 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_OVERLAPPEDWINDOW
, 300000, 300000, 200000, 200000, 0, 0, 0, NULL
);
4810 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4811 GetClientRect( hwnd
, &rc
);
4812 ok( rc
.right
<= expected_cx
, "invalid rect right %u\n", rc
.right
);
4813 ok( rc
.bottom
<= expected_cy
, "invalid rect bottom %u\n", rc
.bottom
);
4814 DestroyWindow(hwnd
);
4816 DestroyWindow(parent
);
4818 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4819 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4821 #undef expect_gle_broken_9x
4824 #undef expect_ex_style
4827 /* function that remembers whether the system the test is running on sets the
4828 * last error for user32 functions to make the tests stricter */
4829 static int check_error(DWORD actual
, DWORD expected
)
4831 static int sets_last_error
= -1;
4832 if (sets_last_error
== -1)
4833 sets_last_error
= (actual
!= 0xdeadbeef);
4834 return (!sets_last_error
&& (actual
== 0xdeadbeef)) || (actual
== expected
);
4837 static void test_SetWindowLong(void)
4840 WNDPROC old_window_procW
;
4842 SetLastError(0xdeadbeef);
4843 retval
= SetWindowLongPtr(NULL
, GWLP_WNDPROC
, 0);
4844 ok(!retval
, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval
);
4845 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE
),
4846 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4848 SetLastError(0xdeadbeef);
4849 retval
= SetWindowLongPtr(hwndMain
, 0xdeadbeef, 0);
4850 ok(!retval
, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval
);
4851 ok(check_error(GetLastError(), ERROR_INVALID_INDEX
),
4852 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4854 SetLastError(0xdeadbeef);
4855 retval
= SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4856 ok((WNDPROC
)retval
== main_window_procA
|| broken(!retval
), /* win9x */
4857 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval
);
4858 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4859 retval
= GetWindowLongPtr(hwndMain
, GWLP_WNDPROC
);
4860 ok((WNDPROC
)retval
== main_window_procA
,
4861 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4862 ok(!IsWindowUnicode(hwndMain
), "hwndMain shouldn't be Unicode\n");
4864 old_window_procW
= (WNDPROC
)GetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
);
4865 SetLastError(0xdeadbeef);
4866 retval
= SetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
, 0);
4867 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED
)
4869 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4870 ok(retval
!= 0, "SetWindowLongPtr error %d\n", GetLastError());
4871 ok((WNDPROC
)retval
== old_window_procW
,
4872 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4873 ok(IsWindowUnicode(hwndMain
), "hwndMain should now be Unicode\n");
4875 /* set it back to ANSI */
4876 SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4880 static void test_ShowWindow(void)
4884 RECT rcMain
, rc
, rcMinimized
;
4887 SetRect(&rcMain
, 120, 120, 210, 210);
4889 hwnd
= CreateWindowEx(0, "MainWindowClass", NULL
,
4890 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4891 WS_MAXIMIZEBOX
| WS_POPUP
,
4892 rcMain
.left
, rcMain
.top
,
4893 rcMain
.right
- rcMain
.left
, rcMain
.bottom
- rcMain
.top
,
4897 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4898 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4899 ok(!(style
& WS_VISIBLE
), "window should not be visible\n");
4900 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4901 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4902 GetWindowRect(hwnd
, &rc
);
4903 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4904 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4905 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4907 ret
= ShowWindow(hwnd
, SW_SHOW
);
4908 ok(!ret
, "not expected ret: %lu\n", ret
);
4909 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4910 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4911 ok(style
& WS_VISIBLE
, "window should be visible\n");
4912 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4913 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4914 GetWindowRect(hwnd
, &rc
);
4915 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4916 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4917 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4919 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4920 ok(ret
, "not expected ret: %lu\n", ret
);
4921 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4922 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4923 ok(style
& WS_VISIBLE
, "window should be visible\n");
4924 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4925 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4926 GetWindowRect(hwnd
, &rcMinimized
);
4927 ok(!EqualRect(&rcMain
, &rcMinimized
), "rects shouldn't match\n");
4928 /* shouldn't be able to resize minized windows */
4929 ret
= SetWindowPos(hwnd
, 0, 0, 0,
4930 (rcMinimized
.right
- rcMinimized
.left
) * 2,
4931 (rcMinimized
.bottom
- rcMinimized
.top
) * 2,
4932 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
4933 ok(ret
, "not expected ret: %lu\n", ret
);
4934 GetWindowRect(hwnd
, &rc
);
4935 ok(EqualRect(&rc
, &rcMinimized
), "rects should match\n");
4937 ShowWindow(hwnd
, SW_RESTORE
);
4938 ok(ret
, "not expected ret: %lu\n", ret
);
4939 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4940 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4941 ok(style
& WS_VISIBLE
, "window should be visible\n");
4942 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4943 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4944 GetWindowRect(hwnd
, &rc
);
4945 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4946 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4947 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4949 ret
= EnableWindow(hwnd
, FALSE
);
4950 ok(!ret
, "not expected ret: %lu\n", ret
);
4951 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4952 ok(style
& WS_DISABLED
, "window should be disabled\n");
4954 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
4955 ok(!ret
, "not expected ret: %lu\n", ret
);
4956 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4957 ok(style
& WS_DISABLED
, "window should be disabled\n");
4958 ok(style
& WS_VISIBLE
, "window should be visible\n");
4959 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4960 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4961 GetWindowRect(hwnd
, &rc
);
4962 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4963 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4964 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4966 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
4967 ok(!ret
, "not expected ret: %lu\n", ret
);
4968 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4969 ok(style
& WS_DISABLED
, "window should be disabled\n");
4970 ok(style
& WS_VISIBLE
, "window should be visible\n");
4971 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4972 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4973 GetWindowRect(hwnd
, &rc
);
4974 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4975 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4976 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4978 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4979 ok(ret
, "not expected ret: %lu\n", ret
);
4980 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4981 ok(style
& WS_DISABLED
, "window should be disabled\n");
4982 ok(style
& WS_VISIBLE
, "window should be visible\n");
4983 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4984 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4985 GetWindowRect(hwnd
, &rc
);
4986 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4988 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
4989 ok(!ret
, "not expected ret: %lu\n", ret
);
4990 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4991 ok(style
& WS_DISABLED
, "window should be disabled\n");
4992 ok(style
& WS_VISIBLE
, "window should be visible\n");
4993 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4994 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4995 GetWindowRect(hwnd
, &rc
);
4996 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4998 ret
= ShowWindow(hwnd
, SW_RESTORE
);
4999 ok(ret
, "not expected ret: %lu\n", ret
);
5000 style
= GetWindowLong(hwnd
, GWL_STYLE
);
5001 ok(style
& WS_DISABLED
, "window should be disabled\n");
5002 ok(style
& WS_VISIBLE
, "window should be visible\n");
5003 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
5004 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
5005 GetWindowRect(hwnd
, &rc
);
5006 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5007 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
5008 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5010 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
5011 ok(!ret
, "not expected ret: %lu\n", ret
);
5012 ok(IsWindow(hwnd
), "window should exist\n");
5014 ret
= EnableWindow(hwnd
, TRUE
);
5015 ok(ret
, "not expected ret: %lu\n", ret
);
5017 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
5018 ok(!ret
, "not expected ret: %lu\n", ret
);
5019 ok(!IsWindow(hwnd
), "window should not exist\n");
5022 static void test_gettext(void)
5025 LPCSTR clsname
= "gettexttest";
5029 memset( &cls
, 0, sizeof cls
);
5030 cls
.lpfnWndProc
= DefWindowProc
;
5031 cls
.lpszClassName
= clsname
;
5032 cls
.hInstance
= GetModuleHandle(NULL
);
5034 if (!RegisterClass( &cls
)) return;
5036 hwnd
= CreateWindow( clsname
, "test text", WS_OVERLAPPED
, 0, 0, 10, 10, 0, NULL
, NULL
, NULL
);
5037 ok( hwnd
!= NULL
, "window was null\n");
5039 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10, 0x1000);
5040 ok( r
== 0, "settext should return zero\n");
5042 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10000, 0);
5043 ok( r
== 0, "settext should return zero (%ld)\n", r
);
5045 r
= SendMessage( hwnd
, WM_GETTEXT
, 0xff000000, 0x1000);
5046 ok( r
== 0, "settext should return zero (%ld)\n", r
);
5048 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x1000, 0xff000000);
5049 ok( r
== 0, "settext should return zero (%ld)\n", r
);
5051 DestroyWindow(hwnd
);
5052 UnregisterClass( clsname
, NULL
);
5056 static void test_GetUpdateRect(void)
5059 BOOL ret
, parent_wm_paint
, grandparent_wm_paint
;
5061 HWND hgrandparent
, hparent
, hchild
;
5063 static const char classNameA
[] = "GetUpdateRectClass";
5065 hgrandparent
= CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW
,
5066 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
5068 hparent
= CreateWindowA("static", "parent", WS_CHILD
|WS_VISIBLE
,
5069 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
5071 hchild
= CreateWindowA("static", "child", WS_CHILD
|WS_VISIBLE
,
5072 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
5074 ShowWindow(hgrandparent
, SW_SHOW
);
5075 UpdateWindow(hgrandparent
);
5076 flush_events( TRUE
);
5078 ShowWindow(hchild
, SW_HIDE
);
5079 SetRect(&rc2
, 0, 0, 0, 0);
5080 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
5081 ok(!ret
, "GetUpdateRect returned not empty region\n");
5082 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5083 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
5084 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
5086 SetRect(&rc2
, 10, 10, 40, 40);
5087 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
5088 ok(ret
, "GetUpdateRect returned empty region\n");
5089 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5090 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
5091 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
5093 parent_wm_paint
= FALSE
;
5094 grandparent_wm_paint
= FALSE
;
5095 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
5097 if (msg
.message
== WM_PAINT
)
5099 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
5100 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
5102 DispatchMessage(&msg
);
5104 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
5105 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
5107 DestroyWindow(hgrandparent
);
5110 cls
.lpfnWndProc
= DefWindowProcA
;
5113 cls
.hInstance
= GetModuleHandleA(0);
5115 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
5116 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5117 cls
.lpszMenuName
= NULL
;
5118 cls
.lpszClassName
= classNameA
;
5120 if(!RegisterClassA(&cls
)) {
5121 trace("Register failed %d\n", GetLastError());
5125 hgrandparent
= CreateWindowA(classNameA
, "grandparent", WS_OVERLAPPEDWINDOW
,
5126 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
5128 hparent
= CreateWindowA(classNameA
, "parent", WS_CHILD
|WS_VISIBLE
,
5129 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
5131 hchild
= CreateWindowA(classNameA
, "child", WS_CHILD
|WS_VISIBLE
,
5132 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
5134 ShowWindow(hgrandparent
, SW_SHOW
);
5135 UpdateWindow(hgrandparent
);
5136 flush_events( TRUE
);
5138 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
5139 ok(!ret
, "GetUpdateRect returned not empty region\n");
5141 ShowWindow(hchild
, SW_HIDE
);
5143 SetRect(&rc2
, 0, 0, 0, 0);
5144 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
5145 ok(!ret
, "GetUpdateRect returned not empty region\n");
5146 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5147 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
5148 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
5150 SetRect(&rc2
, 10, 10, 40, 40);
5151 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
5152 ok(ret
, "GetUpdateRect returned empty region\n");
5153 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5154 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
5155 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
5157 parent_wm_paint
= FALSE
;
5158 grandparent_wm_paint
= FALSE
;
5159 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
5161 if (msg
.message
== WM_PAINT
)
5163 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
5164 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
5166 DispatchMessage(&msg
);
5168 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
5169 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
5171 DestroyWindow(hgrandparent
);
5175 static LRESULT CALLBACK
TestExposedRegion_WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
5183 const int waitTime
= 2000;
5185 BeginPaint(hwnd
, &ps
);
5187 /* create and destroy window to create an exposed region on this window */
5188 win
= CreateWindowA("static", "win", WS_VISIBLE
,
5189 10,10,50,50, NULL
, NULL
, 0, NULL
);
5192 waitResult
= MsgWaitForMultipleObjects( 0, NULL
, FALSE
, waitTime
, QS_PAINT
);
5194 ValidateRect(hwnd
, NULL
);
5195 EndPaint(hwnd
, &ps
);
5197 if(waitResult
!= WAIT_TIMEOUT
)
5199 GetUpdateRect(hwnd
, &updateRect
, FALSE
);
5200 ok(IsRectEmpty(&updateRect
), "Exposed rect should be empty\n");
5205 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
5208 static void test_Expose(void)
5213 memset(&cls
, 0, sizeof(WNDCLASSA
));
5214 cls
.lpfnWndProc
= TestExposedRegion_WndProc
;
5215 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5216 cls
.lpszClassName
= "TestExposeClass";
5217 RegisterClassA(&cls
);
5219 mw
= CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE
|WS_OVERLAPPEDWINDOW
,
5220 0, 0, 200, 100, NULL
, NULL
, 0, NULL
);
5226 static LRESULT CALLBACK
TestNCRedraw_WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
5228 static UINT ncredrawflags
;
5234 ncredrawflags
= *(UINT
*) (((CREATESTRUCT
*)lParam
)->lpCreateParams
);
5237 RedrawWindow(hwnd
, NULL
, NULL
, ncredrawflags
);
5240 BeginPaint(hwnd
, &ps
);
5241 EndPaint(hwnd
, &ps
);
5244 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
5247 static void run_NCRedrawLoop(UINT flags
)
5254 hwnd
= CreateWindowA("TestNCRedrawClass", "MainWindow",
5255 WS_OVERLAPPEDWINDOW
, 0, 0, 200, 100,
5256 NULL
, NULL
, 0, &flags
);
5257 ShowWindow(hwnd
, SW_SHOW
);
5259 flush_events( FALSE
);
5260 while(PeekMessage(&msg
, hwnd
, 0, 0, PM_REMOVE
) != 0)
5262 if (msg
.message
== WM_PAINT
) loopcount
++;
5263 if (loopcount
>= 100) break;
5264 TranslateMessage(&msg
);
5265 DispatchMessage(&msg
);
5266 MsgWaitForMultipleObjects(0, NULL
, FALSE
, 100, QS_ALLINPUT
);
5268 if (flags
== (RDW_INVALIDATE
| RDW_FRAME
))
5269 todo_wine
ok(loopcount
< 100, "Detected infinite WM_PAINT loop (%x).\n", flags
);
5271 ok(loopcount
< 100, "Detected infinite WM_PAINT loop (%x).\n", flags
);
5272 DestroyWindow(hwnd
);
5275 static void test_NCRedraw(void)
5279 wndclass
.lpszClassName
= "TestNCRedrawClass";
5280 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
5281 wndclass
.lpfnWndProc
= TestNCRedraw_WndProc
;
5282 wndclass
.cbClsExtra
= 0;
5283 wndclass
.cbWndExtra
= 0;
5284 wndclass
.hInstance
= 0;
5285 wndclass
.hIcon
= LoadIcon(NULL
, IDI_APPLICATION
);
5286 wndclass
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
5287 wndclass
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5288 wndclass
.lpszMenuName
= NULL
;
5290 RegisterClassA(&wndclass
);
5292 run_NCRedrawLoop(RDW_INVALIDATE
| RDW_FRAME
);
5293 run_NCRedrawLoop(RDW_INVALIDATE
);
5296 static void test_GetWindowModuleFileName(void)
5301 char buf1
[MAX_PATH
], buf2
[MAX_PATH
];
5303 if (!pGetWindowModuleFileNameA
)
5305 win_skip("GetWindowModuleFileNameA is not available\n");
5309 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0,0,0,0, 0, 0, 0, NULL
);
5312 hinst
= (HINSTANCE
)GetWindowLongPtr(hwnd
, GWLP_HINSTANCE
);
5313 ok(hinst
== 0 || broken(hinst
== GetModuleHandle(0)), /* win9x */ "expected 0, got %p\n", hinst
);
5316 SetLastError(0xdeadbeef);
5317 ret1
= GetModuleFileName(hinst
, buf1
, sizeof(buf1
));
5318 ok(ret1
, "GetModuleFileName error %u\n", GetLastError());
5321 SetLastError(0xdeadbeef);
5322 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, sizeof(buf2
));
5323 ok(ret2
|| broken(!ret2
), /* nt4 sp 3 */
5324 "GetWindowModuleFileNameA error %u\n", GetLastError());
5328 ok(ret1
== ret2
|| broken(ret2
== ret1
+ 1), /* win98 */ "%u != %u\n", ret1
, ret2
);
5329 ok(!strcmp(buf1
, buf2
), "%s != %s\n", buf1
, buf2
);
5331 hinst
= GetModuleHandle(0);
5333 SetLastError(0xdeadbeef);
5334 ret2
= GetModuleFileName(hinst
, buf2
, ret1
- 2);
5335 ok(ret2
== ret1
- 2 || broken(ret2
== ret1
- 3), /* win98 */
5336 "expected %u, got %u\n", ret1
- 2, ret2
);
5337 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5338 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
5339 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5341 SetLastError(0xdeadbeef);
5342 ret2
= GetModuleFileName(hinst
, buf2
, 0);
5343 ok(!ret2
, "GetModuleFileName should return 0\n");
5344 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5345 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
5346 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5348 SetLastError(0xdeadbeef);
5349 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, ret1
- 2);
5350 ok(ret2
== ret1
- 2 || broken(ret2
== ret1
- 3) /* win98 */ || broken(!ret2
), /* nt4 sp3 */
5351 "expected %u, got %u\n", ret1
- 2, ret2
);
5352 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5353 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
5354 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5356 SetLastError(0xdeadbeef);
5357 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, 0);
5358 ok(!ret2
, "expected 0, got %u\n", ret2
);
5359 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5360 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
5361 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5363 DestroyWindow(hwnd
);
5366 hwnd
= (HWND
)0xdeadbeef;
5367 SetLastError(0xdeadbeef);
5368 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
5369 ok(!ret1
, "expected 0, got %u\n", ret1
);
5370 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
|| broken(GetLastError() == 0xdeadbeef), /* win9x */
5371 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
5373 hwnd
= FindWindow("Shell_TrayWnd", NULL
);
5374 ok(IsWindow(hwnd
) || broken(!hwnd
), "got invalid tray window %p\n", hwnd
);
5375 SetLastError(0xdeadbeef);
5376 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
5377 ok(!ret1
|| broken(ret1
), /* win98 */ "expected 0, got %u\n", ret1
);
5379 if (!ret1
) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
5381 ret1
= GetModuleFileName(0, buf1
, sizeof(buf1
));
5382 hwnd
= GetDesktopWindow();
5383 ok(IsWindow(hwnd
), "got invalid desktop window %p\n", hwnd
);
5384 SetLastError(0xdeadbeef);
5385 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, sizeof(buf2
));
5387 ret1
== ret2
|| /* vista */
5388 broken(ret2
), /* some win98 return user.exe as file name */
5389 "expected 0 or %u, got %u %s\n", ret1
, ret2
, buf2
);
5393 static void test_hwnd_message(void)
5395 static const WCHAR mainwindowclassW
[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
5396 static const WCHAR message_windowW
[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
5398 HWND parent
= 0, hwnd
, found
;
5401 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
5402 on CreateWindowExA and crash later in the test.
5403 Use UNICODE here to fail on win9x */
5404 hwnd
= CreateWindowExW(0, mainwindowclassW
, message_windowW
, WS_CAPTION
| WS_VISIBLE
,
5405 100, 100, 200, 200, HWND_MESSAGE
, 0, 0, NULL
);
5408 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
5412 ok( !GetParent(hwnd
), "GetParent should return 0 for message only windows\n" );
5416 HWND root
, desktop
= GetDesktopWindow();
5418 parent
= pGetAncestor(hwnd
, GA_PARENT
);
5419 ok(parent
!= 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
5420 ok(parent
!= desktop
, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
5421 root
= pGetAncestor(hwnd
, GA_ROOT
);
5422 ok(root
== hwnd
, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
5423 ok( !pGetAncestor(parent
, GA_PARENT
) || broken(pGetAncestor(parent
, GA_PARENT
) != 0), /* win2k */
5424 "parent shouldn't have parent %p\n", pGetAncestor(parent
, GA_PARENT
) );
5425 trace("parent %p root %p desktop %p\n", parent
, root
, desktop
);
5426 if (!GetClassNameA( parent
, buffer
, sizeof(buffer
) )) buffer
[0] = 0;
5427 ok( !lstrcmpi( buffer
, "Message" ), "wrong parent class '%s'\n", buffer
);
5428 GetWindowRect( parent
, &rect
);
5429 ok( rect
.left
== 0 && rect
.right
== 100 && rect
.top
== 0 && rect
.bottom
== 100,
5430 "wrong parent rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
5432 GetWindowRect( hwnd
, &rect
);
5433 ok( rect
.left
== 100 && rect
.right
== 300 && rect
.top
== 100 && rect
.bottom
== 300,
5434 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
5436 /* test FindWindow behavior */
5438 found
= FindWindowExA( 0, 0, 0, "message window" );
5439 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
5440 SetLastError(0xdeadbeef);
5441 found
= FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
5442 ok( found
== 0, "found message window %p/%p\n", found
, hwnd
);
5443 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
5446 found
= FindWindowExA( parent
, 0, 0, "message window" );
5447 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
5450 /* test IsChild behavior */
5452 if (parent
) ok( !IsChild( parent
, hwnd
), "HWND_MESSAGE is child of top window\n" );
5454 /* test IsWindowVisible behavior */
5456 ok( !IsWindowVisible( hwnd
), "HWND_MESSAGE window is visible\n" );
5457 if (parent
) ok( !IsWindowVisible( parent
), "HWND_MESSAGE parent is visible\n" );
5459 DestroyWindow(hwnd
);
5462 static void test_layered_window(void)
5470 if (!pGetLayeredWindowAttributes
|| !pSetLayeredWindowAttributes
)
5472 win_skip( "layered windows not supported\n" );
5475 hwnd
= CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION
,
5476 100, 100, 200, 200, 0, 0, 0, NULL
);
5478 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5479 ok( !ret
, "GetLayeredWindowAttributes should fail on non-layered window\n" );
5480 ret
= pSetLayeredWindowAttributes( hwnd
, 0, 0, LWA_ALPHA
);
5481 ok( !ret
, "SetLayeredWindowAttributes should fail on non-layered window\n" );
5482 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
5483 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5484 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5485 ret
= pSetLayeredWindowAttributes( hwnd
, 0x123456, 44, LWA_ALPHA
);
5486 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5487 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5488 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5489 ok( key
== 0x123456 || key
== 0, "wrong color key %x\n", key
);
5490 ok( alpha
== 44, "wrong alpha %u\n", alpha
);
5491 ok( flags
== LWA_ALPHA
, "wrong flags %x\n", flags
);
5493 /* clearing WS_EX_LAYERED resets attributes */
5494 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
5495 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5496 ok( !ret
, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
5497 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
5498 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5499 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5500 ret
= pSetLayeredWindowAttributes( hwnd
, 0x654321, 22, LWA_COLORKEY
| LWA_ALPHA
);
5501 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5502 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5503 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5504 ok( key
== 0x654321, "wrong color key %x\n", key
);
5505 ok( alpha
== 22, "wrong alpha %u\n", alpha
);
5506 ok( flags
== (LWA_COLORKEY
| LWA_ALPHA
), "wrong flags %x\n", flags
);
5508 ret
= pSetLayeredWindowAttributes( hwnd
, 0x888888, 33, LWA_COLORKEY
);
5509 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5511 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5512 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5513 ok( key
== 0x888888, "wrong color key %x\n", key
);
5514 /* alpha not changed on vista if LWA_ALPHA is not set */
5515 ok( alpha
== 22 || alpha
== 33, "wrong alpha %u\n", alpha
);
5516 ok( flags
== LWA_COLORKEY
, "wrong flags %x\n", flags
);
5518 /* color key may or may not be changed without LWA_COLORKEY */
5519 ret
= pSetLayeredWindowAttributes( hwnd
, 0x999999, 44, 0 );
5520 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5522 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5523 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5524 ok( key
== 0x888888 || key
== 0x999999, "wrong color key %x\n", key
);
5525 ok( alpha
== 22 || alpha
== 44, "wrong alpha %u\n", alpha
);
5526 ok( flags
== 0, "wrong flags %x\n", flags
);
5528 /* default alpha and color key is 0 */
5529 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
5530 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
5531 ret
= pSetLayeredWindowAttributes( hwnd
, 0x222222, 55, 0 );
5532 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5533 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5534 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5535 ok( key
== 0 || key
== 0x222222, "wrong color key %x\n", key
);
5536 ok( alpha
== 0 || alpha
== 55, "wrong alpha %u\n", alpha
);
5537 ok( flags
== 0, "wrong flags %x\n", flags
);
5539 DestroyWindow( hwnd
);
5542 static MONITORINFO mi
;
5544 static LRESULT CALLBACK
fullscreen_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
5550 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
5551 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
5552 ok(cs
->x
== mi
.rcMonitor
.left
&& cs
->y
== mi
.rcMonitor
.top
&&
5553 cs
->cx
== mi
.rcMonitor
.right
&& cs
->cy
== mi
.rcMonitor
.bottom
,
5554 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
5555 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5556 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
5559 case WM_GETMINMAXINFO
:
5561 MINMAXINFO
*minmax
= (MINMAXINFO
*)lp
;
5562 dump_minmax_info(minmax
);
5563 ok(minmax
->ptMaxPosition
.x
<= mi
.rcMonitor
.left
, "%d <= %d\n", minmax
->ptMaxPosition
.x
, mi
.rcMonitor
.left
);
5564 ok(minmax
->ptMaxPosition
.y
<= mi
.rcMonitor
.top
, "%d <= %d\n", minmax
->ptMaxPosition
.y
, mi
.rcMonitor
.top
);
5565 ok(minmax
->ptMaxSize
.x
>= mi
.rcMonitor
.right
, "%d >= %d\n", minmax
->ptMaxSize
.x
, mi
.rcMonitor
.right
);
5566 ok(minmax
->ptMaxSize
.y
>= mi
.rcMonitor
.bottom
, "%d >= %d\n", minmax
->ptMaxSize
.y
, mi
.rcMonitor
.bottom
);
5570 return DefWindowProc(hwnd
, msg
, wp
, lp
);
5573 static void test_fullscreen(void)
5575 static const DWORD t_style
[] = {
5576 WS_OVERLAPPED
, WS_POPUP
, WS_CHILD
, WS_THICKFRAME
, WS_DLGFRAME
5578 static const DWORD t_ex_style
[] = {
5579 0, WS_EX_APPWINDOW
, WS_EX_TOOLWINDOW
5589 if (!pGetMonitorInfoA
|| !pMonitorFromPoint
)
5591 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
5596 SetLastError(0xdeadbeef);
5597 hmon
= pMonitorFromPoint(pt
, MONITOR_DEFAULTTOPRIMARY
);
5598 ok(hmon
!= 0, "MonitorFromPoint error %u\n", GetLastError());
5600 mi
.cbSize
= sizeof(mi
);
5601 SetLastError(0xdeadbeef);
5602 ret
= pGetMonitorInfoA(hmon
, &mi
);
5603 ok(ret
, "GetMonitorInfo error %u\n", GetLastError());
5604 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
5605 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5606 mi
.rcWork
.left
, mi
.rcWork
.top
, mi
.rcWork
.right
, mi
.rcWork
.bottom
);
5609 cls
.lpfnWndProc
= fullscreen_wnd_proc
;
5612 cls
.hInstance
= GetModuleHandle(0);
5614 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
5615 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5616 cls
.lpszMenuName
= NULL
;
5617 cls
.lpszClassName
= "fullscreen_class";
5618 RegisterClass(&cls
);
5620 for (i
= 0; i
< sizeof(t_style
)/sizeof(t_style
[0]); i
++)
5622 DWORD style
, ex_style
;
5624 /* avoid a WM interaction */
5625 assert(!(t_style
[i
] & WS_VISIBLE
));
5627 for (j
= 0; j
< sizeof(t_ex_style
)/sizeof(t_ex_style
[0]); j
++)
5632 ex_style
= t_ex_style
[j
];
5634 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5635 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5636 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5637 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5638 GetWindowRect(hwnd
, &rc
);
5639 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5640 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5641 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5642 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5643 DestroyWindow(hwnd
);
5645 style
= t_style
[i
] | WS_MAXIMIZE
;
5646 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5647 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5648 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5649 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5650 GetWindowRect(hwnd
, &rc
);
5651 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5652 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5653 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5654 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5655 DestroyWindow(hwnd
);
5657 style
= t_style
[i
] | WS_MAXIMIZE
| WS_CAPTION
;
5658 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5659 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5660 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5661 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5662 GetWindowRect(hwnd
, &rc
);
5663 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5664 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5665 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5666 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5667 DestroyWindow(hwnd
);
5669 style
= t_style
[i
] | WS_CAPTION
| WS_MAXIMIZEBOX
;
5670 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5671 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5672 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5673 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5674 GetWindowRect(hwnd
, &rc
);
5675 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5676 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5677 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5678 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5679 DestroyWindow(hwnd
);
5681 style
= t_style
[i
] | WS_MAXIMIZE
| WS_CAPTION
| WS_MAXIMIZEBOX
;
5682 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5683 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5684 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5685 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5686 GetWindowRect(hwnd
, &rc
);
5687 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5688 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5689 fixup
= min(abs(rc
.left
), abs(rc
.top
));
5690 InflateRect(&rc
, -fixup
, -fixup
);
5691 ok(rc
.left
>= mi
.rcWork
.left
&& rc
.top
<= mi
.rcWork
.top
&&
5692 rc
.right
<= mi
.rcWork
.right
&& rc
.bottom
<= mi
.rcWork
.bottom
,
5693 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
5694 ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
5695 mi
.rcWork
.left
, mi
.rcWork
.top
, mi
.rcWork
.right
, mi
.rcWork
.bottom
);
5696 DestroyWindow(hwnd
);
5698 style
= t_style
[i
] | WS_MAXIMIZE
| WS_MAXIMIZEBOX
;
5699 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5700 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5701 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5702 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5703 GetWindowRect(hwnd
, &rc
);
5704 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5705 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5706 fixup
= min(abs(rc
.left
), abs(rc
.top
));
5707 InflateRect(&rc
, -fixup
, -fixup
);
5708 if (style
& (WS_CHILD
| WS_POPUP
))
5709 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5710 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5711 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5713 ok(rc
.left
>= mi
.rcWork
.left
&& rc
.top
<= mi
.rcWork
.top
&&
5714 rc
.right
<= mi
.rcWork
.right
&& rc
.bottom
<= mi
.rcWork
.bottom
,
5715 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5716 DestroyWindow(hwnd
);
5720 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5723 static BOOL test_thick_child_got_minmax
;
5724 static const char * test_thick_child_name
;
5725 static LONG test_thick_child_style
;
5726 static LONG test_thick_child_exStyle
;
5728 static LRESULT WINAPI
test_thick_child_size_winproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
5731 int expectedMinTrackX
;
5732 int expectedMinTrackY
;
5733 int actualMinTrackX
;
5734 int actualMinTrackY
;
5735 int expectedMaxTrackX
;
5736 int expectedMaxTrackY
;
5737 int actualMaxTrackX
;
5738 int actualMaxTrackY
;
5739 int expectedMaxSizeX
;
5740 int expectedMaxSizeY
;
5751 case WM_GETMINMAXINFO
:
5753 minmax
= (MINMAXINFO
*)lparam
;
5754 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
5755 dump_minmax_info( minmax
);
5757 test_thick_child_got_minmax
= TRUE
;
5760 adjustedStyle
= test_thick_child_style
;
5761 if ((adjustedStyle
& WS_CAPTION
) == WS_CAPTION
)
5762 adjustedStyle
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5763 GetClientRect(GetParent(hwnd
), &rect
);
5764 AdjustWindowRectEx(&rect
, adjustedStyle
, FALSE
, test_thick_child_exStyle
);
5766 if (test_thick_child_style
& (WS_DLGFRAME
| WS_BORDER
))
5768 expectedMinTrackX
= GetSystemMetrics(SM_CXMINTRACK
);
5769 expectedMinTrackY
= GetSystemMetrics(SM_CYMINTRACK
);
5773 expectedMinTrackX
= -2 * rect
.left
;
5774 expectedMinTrackY
= -2 * rect
.top
;
5776 actualMinTrackX
= minmax
->ptMinTrackSize
.x
;
5777 actualMinTrackY
= minmax
->ptMinTrackSize
.y
;
5779 ok(actualMinTrackX
== expectedMinTrackX
&& actualMinTrackY
== expectedMinTrackY
,
5780 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
5781 expectedMinTrackX
, expectedMinTrackY
, actualMinTrackX
, actualMinTrackY
,
5782 test_thick_child_name
);
5784 actualMaxTrackX
= minmax
->ptMaxTrackSize
.x
;
5785 actualMaxTrackY
= minmax
->ptMaxTrackSize
.y
;
5786 expectedMaxTrackX
= GetSystemMetrics(SM_CXMAXTRACK
);
5787 expectedMaxTrackY
= GetSystemMetrics(SM_CYMAXTRACK
);
5788 ok(actualMaxTrackX
== expectedMaxTrackX
&& actualMaxTrackY
== expectedMaxTrackY
,
5789 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
5790 expectedMaxTrackX
, expectedMaxTrackY
, actualMaxTrackX
, actualMaxTrackY
,
5791 test_thick_child_name
);
5793 expectedMaxSizeX
= rect
.right
- rect
.left
;
5794 expectedMaxSizeY
= rect
.bottom
- rect
.top
;
5795 actualMaxSizeX
= minmax
->ptMaxSize
.x
;
5796 actualMaxSizeY
= minmax
->ptMaxSize
.y
;
5798 ok(actualMaxSizeX
== expectedMaxSizeX
&& actualMaxSizeY
== expectedMaxSizeY
,
5799 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
5800 expectedMaxSizeX
, expectedMaxSizeY
, actualMaxSizeX
, actualMaxSizeY
,
5801 test_thick_child_name
);
5804 expectedPosX
= rect
.left
;
5805 expectedPosY
= rect
.top
;
5806 actualPosX
= minmax
->ptMaxPosition
.x
;
5807 actualPosY
= minmax
->ptMaxPosition
.y
;
5808 ok(actualPosX
== expectedPosX
&& actualPosY
== expectedPosY
,
5809 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
5810 expectedPosX
, expectedPosY
, actualPosX
, actualPosY
, test_thick_child_name
);
5816 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
5819 #define NUMBER_OF_THICK_CHILD_TESTS 16
5820 static void test_thick_child_size(HWND parentWindow
)
5824 RECT adjustedParentRect
;
5829 LONG expectedHeight
;
5831 LPCTSTR className
= "THICK_CHILD_CLASS";
5834 static const LONG styles
[NUMBER_OF_THICK_CHILD_TESTS
] = {
5835 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
5836 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
5837 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
5838 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
5839 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
5840 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
5841 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
5842 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
5843 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
5844 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
5845 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
5846 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
5847 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
5848 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
5849 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
5850 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
5853 static const LONG exStyles
[NUMBER_OF_THICK_CHILD_TESTS
] = {
5858 WS_EX_DLGMODALFRAME
,
5859 WS_EX_DLGMODALFRAME
,
5860 WS_EX_DLGMODALFRAME
,
5861 WS_EX_DLGMODALFRAME
,
5866 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
5867 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
5868 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
5869 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
5871 static const char *styleName
[NUMBER_OF_THICK_CHILD_TESTS
] = {
5872 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
5873 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
5874 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
5875 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
5876 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
5877 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
5878 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5879 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5880 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
5881 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
5882 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5883 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5884 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5885 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5886 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5887 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5891 cls
.lpfnWndProc
= test_thick_child_size_winproc
;
5894 cls
.hInstance
= GetModuleHandleA(0);
5896 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
5897 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5898 cls
.lpszMenuName
= NULL
;
5899 cls
.lpszClassName
= className
;
5900 SetLastError(0xdeadbeef);
5901 ok(RegisterClassA(&cls
),"RegisterClassA failed, error: %u\n", GetLastError());
5903 for(i
= 0; i
< NUMBER_OF_THICK_CHILD_TESTS
; i
++)
5905 test_thick_child_name
= styleName
[i
];
5906 test_thick_child_style
= styles
[i
];
5907 test_thick_child_exStyle
= exStyles
[i
];
5908 test_thick_child_got_minmax
= FALSE
;
5910 SetLastError(0xdeadbeef);
5911 childWindow
= CreateWindowEx( exStyles
[i
], className
, "", styles
[i
], 0, 0, 0, 0, parentWindow
, 0, GetModuleHandleA(0), NULL
);
5912 ok(childWindow
!= NULL
, "Failed to create child window, error: %u\n", GetLastError());
5914 ok(test_thick_child_got_minmax
, "Got no WM_GETMINMAXINFO\n");
5916 SetLastError(0xdeadbeef);
5917 success
= GetWindowRect(childWindow
, &childRect
);
5918 ok(success
,"GetWindowRect call failed, error: %u\n", GetLastError());
5919 childWidth
= childRect
.right
- childRect
.left
;
5920 childHeight
= childRect
.bottom
- childRect
.top
;
5922 adjustedStyle
= styles
[i
];
5923 if ((adjustedStyle
& WS_CAPTION
) == WS_CAPTION
)
5924 adjustedStyle
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5925 GetClientRect(GetParent(childWindow
), &adjustedParentRect
);
5926 AdjustWindowRectEx(&adjustedParentRect
, adjustedStyle
, FALSE
, test_thick_child_exStyle
);
5929 if (test_thick_child_style
& (WS_DLGFRAME
| WS_BORDER
))
5931 expectedWidth
= GetSystemMetrics(SM_CXMINTRACK
);
5932 expectedHeight
= GetSystemMetrics(SM_CYMINTRACK
);
5936 expectedWidth
= -2 * adjustedParentRect
.left
;
5937 expectedHeight
= -2 * adjustedParentRect
.top
;
5940 ok((childWidth
== expectedWidth
) && (childHeight
== expectedHeight
),
5941 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
5942 test_thick_child_name
, expectedWidth
, expectedHeight
, childWidth
, childHeight
);
5944 SetLastError(0xdeadbeef);
5945 success
= DestroyWindow(childWindow
);
5946 ok(success
,"DestroyWindow call failed, error: %u\n", GetLastError());
5948 ok(UnregisterClass(className
, GetModuleHandleA(0)),"UnregisterClass call failed\n");
5951 static void test_handles( HWND full_hwnd
)
5953 HWND hwnd
= full_hwnd
;
5957 SetLastError( 0xdeadbeef );
5958 ret
= GetWindowRect( hwnd
, &rect
);
5959 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
5962 if ((ULONG_PTR
)full_hwnd
>> 32)
5963 hwnd
= (HWND
)((ULONG_PTR
)full_hwnd
& ~0u);
5965 hwnd
= (HWND
)((ULONG_PTR
)full_hwnd
| ((ULONG_PTR
)~0u << 32));
5966 SetLastError( 0xdeadbeef );
5967 ret
= GetWindowRect( hwnd
, &rect
);
5968 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
5970 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& ~0u) | ((ULONG_PTR
)0x1234 << 32));
5971 SetLastError( 0xdeadbeef );
5972 ret
= GetWindowRect( hwnd
, &rect
);
5973 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
5975 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& 0xffff) | ((ULONG_PTR
)0x9876 << 16));
5976 SetLastError( 0xdeadbeef );
5977 ret
= GetWindowRect( hwnd
, &rect
);
5978 ok( !ret
, "GetWindowRect succeeded for %p\n", hwnd
);
5979 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "wrong error %u\n", GetLastError() );
5981 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& 0xffff) | ((ULONG_PTR
)0x12345678 << 16));
5982 SetLastError( 0xdeadbeef );
5983 ret
= GetWindowRect( hwnd
, &rect
);
5984 ok( !ret
, "GetWindowRect succeeded for %p\n", hwnd
);
5985 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "wrong error %u\n", GetLastError() );
5989 static void test_winregion(void)
5996 if (!pGetWindowRgnBox
)
5998 win_skip("GetWindowRgnBox not supported\n");
6002 hwnd
= CreateWindowExA(0, "static", NULL
, WS_VISIBLE
, 10, 10, 10, 10, NULL
, 0, 0, NULL
);
6004 SetLastError(0xdeadbeef);
6005 ret
= pGetWindowRgnBox(hwnd
, NULL
);
6006 ok( ret
== ERROR
, "Expected ERROR, got %d\n", ret
);
6007 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
6009 hrgn
= CreateRectRgn(2, 3, 10, 15);
6010 ok( hrgn
!= NULL
, "Region creation failed\n");
6013 SetWindowRgn(hwnd
, hrgn
, FALSE
);
6015 SetLastError(0xdeadbeef);
6016 ret
= pGetWindowRgnBox(hwnd
, NULL
);
6017 ok( ret
== ERROR
, "Expected ERROR, got %d\n", ret
);
6018 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
6020 r
.left
= r
.top
= r
.right
= r
.bottom
= 0;
6021 ret
= pGetWindowRgnBox(hwnd
, &r
);
6022 ok( ret
== SIMPLEREGION
, "Expected SIMPLEREGION, got %d\n", ret
);
6023 ok( r
.left
== 2 && r
.top
== 3 && r
.right
== 10 && r
.bottom
== 15,
6024 "Expected (2,3,10,15), got (%d,%d,%d,%d)\n", r
.left
, r
.top
,
6028 DestroyWindow(hwnd
);
6033 HMODULE user32
= GetModuleHandleA( "user32.dll" );
6034 pGetAncestor
= (void *)GetProcAddress( user32
, "GetAncestor" );
6035 pGetWindowInfo
= (void *)GetProcAddress( user32
, "GetWindowInfo" );
6036 pGetWindowModuleFileNameA
= (void *)GetProcAddress( user32
, "GetWindowModuleFileNameA" );
6037 pGetLayeredWindowAttributes
= (void *)GetProcAddress( user32
, "GetLayeredWindowAttributes" );
6038 pSetLayeredWindowAttributes
= (void *)GetProcAddress( user32
, "SetLayeredWindowAttributes" );
6039 pGetMonitorInfoA
= (void *)GetProcAddress( user32
, "GetMonitorInfoA" );
6040 pMonitorFromPoint
= (void *)GetProcAddress( user32
, "MonitorFromPoint" );
6041 pGetWindowRgnBox
= (void *)GetProcAddress( user32
, "GetWindowRgnBox" );
6042 pGetGUIThreadInfo
= (void *)GetProcAddress( user32
, "GetGUIThreadInfo" );
6044 if (!RegisterWindowClasses()) assert(0);
6046 SetLastError(0xdeafbeef);
6047 GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC
);
6048 is_win9x
= (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
);
6050 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
6051 if (!hhook
) win_skip( "Cannot set CBT hook, skipping some tests\n" );
6053 hwndMain
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
6054 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
6055 WS_MAXIMIZEBOX
| WS_POPUP
,
6057 0, 0, GetModuleHandle(0), NULL
);
6058 hwndMain2
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
6059 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
6060 WS_MAXIMIZEBOX
| WS_POPUP
,
6062 0, 0, GetModuleHandle(0), NULL
);
6064 assert( hwndMain2
);
6066 our_pid
= GetWindowThreadProcessId(hwndMain
, NULL
);
6068 /* Add the tests below this line */
6069 test_thick_child_size(hwndMain
);
6071 test_hwnd_message();
6072 test_nonclient_area(hwndMain
);
6074 test_GetWindowModuleFileName();
6077 test_capture_3(hwndMain
, hwndMain2
);
6080 test_CreateWindow();
6081 test_parent_owner();
6083 test_enum_thread_windows();
6087 test_SetWindowPos(hwndMain
);
6088 test_SetMenu(hwndMain
);
6089 test_SetFocus(hwndMain
);
6090 test_SetActiveWindow(hwndMain
);
6093 test_children_zorder(hwndMain
);
6094 test_popup_zorder(hwndMain2
, hwndMain
, WS_POPUP
);
6095 test_popup_zorder(hwndMain2
, hwndMain
, 0);
6096 test_keyboard_input(hwndMain
);
6097 test_mouse_input(hwndMain
);
6098 test_validatergn(hwndMain
);
6099 test_nccalcscroll( hwndMain
);
6100 test_scrollwindow( hwndMain
);
6101 test_scrollvalidate( hwndMain
);
6102 test_scrolldc( hwndMain
);
6104 test_IsWindowUnicode();
6105 test_vis_rgn(hwndMain
);
6107 test_AdjustWindowRect();
6108 test_window_styles();
6111 test_SetWindowLong();
6113 if (0) test_gettext(); /* crashes on NT4 */
6114 test_GetUpdateRect();
6116 test_layered_window();
6118 test_SetForegroundWindow(hwndMain
);
6119 test_shell_window();
6120 test_handles( hwndMain
);
6123 /* add the tests above this line */
6124 if (hhook
) UnhookWindowsHookEx(hhook
);
6126 DestroyWindow(hwndMain2
);
6127 DestroyWindow(hwndMain
);