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 */
383 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
384 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
385 check_parents( test
, desktop
, child
, desktop
, child
, test
, desktop
);
387 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
388 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
389 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
390 DestroyWindow( test
);
392 /* not owned top-level window */
393 test
= create_tool_window( 0, 0 );
394 trace( "created top-level %p\n", test
);
396 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
397 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
398 check_parents( test
, desktop
, hwndMain2
, 0, hwndMain2
, test
, test
);
400 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
401 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
402 check_parents( test
, desktop
, child
, 0, child
, test
, test
);
404 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
405 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
406 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
407 DestroyWindow( test
);
409 /* not owned popup */
410 test
= create_tool_window( WS_POPUP
, 0 );
411 trace( "created popup %p\n", test
);
413 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
414 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
415 check_parents( test
, desktop
, hwndMain2
, hwndMain2
, hwndMain2
, test
, hwndMain2
);
417 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
418 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
419 check_parents( test
, desktop
, child
, child
, child
, test
, hwndMain
);
421 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
422 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
423 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
424 DestroyWindow( test
);
426 /* normal child window */
427 test
= create_tool_window( WS_CHILD
, hwndMain
);
428 trace( "created child %p\n", test
);
430 ret
= SetParent( test
, desktop
);
431 ok( ret
== hwndMain
, "SetParent return value %p expected %p\n", ret
, hwndMain
);
432 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
434 ret
= SetParent( test
, child
);
435 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
436 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
438 ret
= SetParent( test
, hwndMain2
);
439 ok( ret
== child
, "SetParent return value %p expected %p\n", ret
, child
);
440 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
441 DestroyWindow( test
);
443 /* not owned top-level window */
444 test
= create_tool_window( 0, 0 );
445 trace( "created top-level %p\n", test
);
447 ret
= SetParent( test
, child
);
448 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
449 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
453 ShowWindow( test
, SW_SHOW
);
454 ret
= SetParent( test
, test
);
455 ok( ret
== NULL
, "SetParent return value %p expected %p\n", ret
, NULL
);
456 ok( GetWindowLongA( test
, GWL_STYLE
) & WS_VISIBLE
, "window is not visible after SetParent\n" );
457 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
460 win_skip( "Test crashes on Win9x/WinMe\n" );
461 DestroyWindow( test
);
464 test
= create_tool_window( WS_POPUP
, hwndMain2
);
465 trace( "created owned popup %p\n", test
);
467 ret
= SetParent( test
, child
);
468 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
469 check_parents( test
, child
, child
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
471 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)hwndMain
);
472 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
473 check_parents( test
, hwndMain
, hwndMain
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
474 DestroyWindow( test
);
476 /**************** test owner destruction *******************/
478 /* owned child popup */
479 owner
= create_tool_window( 0, 0 );
480 test
= create_tool_window( WS_POPUP
, owner
);
481 trace( "created owner %p and popup %p\n", owner
, test
);
482 ret
= SetParent( test
, child
);
483 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
484 check_parents( test
, child
, child
, owner
, owner
, hwndMain
, owner
);
485 /* window is now child of 'child' but owned by 'owner' */
486 DestroyWindow( owner
);
487 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
488 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
489 * while Win95, Win2k, WinXP do.
491 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
492 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
495 /* owned top-level popup */
496 owner
= create_tool_window( 0, 0 );
497 test
= create_tool_window( WS_POPUP
, owner
);
498 trace( "created owner %p and popup %p\n", owner
, test
);
499 check_parents( test
, desktop
, owner
, owner
, owner
, test
, owner
);
500 DestroyWindow( owner
);
501 ok( !IsWindow(test
), "Window %p not destroyed by owner destruction\n", test
);
503 /* top-level popup owned by child */
504 owner
= create_tool_window( WS_CHILD
, hwndMain2
);
505 test
= create_tool_window( WS_POPUP
, 0 );
506 trace( "created owner %p and popup %p\n", owner
, test
);
507 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)owner
);
508 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
509 check_parents( test
, desktop
, owner
, owner
, owner
, test
, hwndMain2
);
510 DestroyWindow( owner
);
511 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
512 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
513 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
514 * while Win95, Win2k, WinXP do.
516 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
520 DestroyWindow(child
);
523 owner
= create_tool_window( WS_OVERLAPPED
, 0 );
524 test
= create_tool_window( WS_POPUP
, desktop
);
526 ok( !GetWindow( test
, GW_OWNER
), "Wrong owner window\n" );
528 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
529 "EnumChildWindows should have returned FALSE\n" );
530 ok( numChildren
== 0, "numChildren should be 0 got %d\n", numChildren
);
532 SetWindowLongA( test
, GWL_STYLE
, (GetWindowLongA( test
, GWL_STYLE
) & ~WS_POPUP
) | WS_CHILD
);
533 ret
= SetParent( test
, owner
);
534 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
537 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
538 "EnumChildWindows should have returned TRUE\n" );
539 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
541 child
= create_tool_window( WS_CHILD
, owner
);
543 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
544 "EnumChildWindows should have returned FALSE\n" );
545 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
546 DestroyWindow( child
);
548 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, owner
);
549 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
551 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
552 "EnumChildWindows should have returned TRUE\n" );
553 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
555 ret
= SetParent( child
, owner
);
556 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
557 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
559 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
560 "EnumChildWindows should have returned FALSE\n" );
561 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
563 ret
= SetParent( child
, NULL
);
564 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
565 ok( ret
== owner
, "SetParent return value %p expected %p\n", ret
, owner
);
567 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
568 "EnumChildWindows should have returned TRUE\n" );
569 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
571 /* even GW_OWNER == owner it's still a desktop's child */
572 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
573 "EnumChildWindows should have found %p and returned FALSE\n", child
);
575 DestroyWindow( child
);
576 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, NULL
);
578 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
579 "EnumChildWindows should have found %p and returned FALSE\n", child
);
581 DestroyWindow( child
);
582 DestroyWindow( test
);
583 DestroyWindow( owner
);
586 static BOOL CALLBACK
enum_proc( HWND hwnd
, LPARAM lParam
)
589 if (*(LPINT
)lParam
> 2) return FALSE
;
592 static DWORD CALLBACK
enum_thread( void *arg
)
599 PeekMessage( &msg
, 0, 0, 0, PM_NOREMOVE
); /* make sure we have a message queue */
602 ret
= EnumThreadWindows( GetCurrentThreadId(), enum_proc
, (LPARAM
)&count
);
603 ok( ret
, "EnumThreadWindows should have returned TRUE\n" );
604 ok( count
== 0, "count should be 0 got %d\n", count
);
606 hwnd
[0] = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", WS_POPUP
,
607 0, 0, 100, 100, 0, 0, 0, NULL
);
609 ret
= EnumThreadWindows( GetCurrentThreadId(), enum_proc
, (LPARAM
)&count
);
610 ok( ret
, "EnumThreadWindows should have returned TRUE\n" );
611 if (count
!= 2) /* Vista gives us two windows for the price of one */
613 ok( count
== 1, "count should be 1 got %d\n", count
);
614 hwnd
[2] = CreateWindowExA(0, "ToolWindowClass", "Tool window 2", WS_POPUP
,
615 0, 0, 100, 100, 0, 0, 0, NULL
);
619 hwnd
[1] = CreateWindowExA(0, "ToolWindowClass", "Tool window 3", WS_POPUP
,
620 0, 0, 100, 100, 0, 0, 0, NULL
);
622 ret
= EnumThreadWindows( GetCurrentThreadId(), enum_proc
, (LPARAM
)&count
);
623 ok( !ret
, "EnumThreadWindows should have returned FALSE\n" );
624 ok( count
== 3, "count should be 3 got %d\n", count
);
626 if (hwnd
[2]) DestroyWindow(hwnd
[2]);
627 DestroyWindow(hwnd
[1]);
628 DestroyWindow(hwnd
[0]);
632 /* test EnumThreadWindows in a separate thread */
633 static void test_enum_thread_windows(void)
636 HANDLE handle
= CreateThread( NULL
, 0, enum_thread
, 0, 0, &id
);
637 ok( !WaitForSingleObject( handle
, 10000 ), "wait failed\n" );
638 CloseHandle( handle
);
641 static LRESULT WINAPI
main_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
645 case WM_GETMINMAXINFO
:
647 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
649 trace("WM_GETMINMAXINFO: hwnd %p, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
650 dump_minmax_info( minmax
);
651 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
654 case WM_WINDOWPOSCHANGING
:
656 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
657 trace("main: WM_WINDOWPOSCHANGING %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
658 winpos
->hwnd
, winpos
->hwndInsertAfter
,
659 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
660 if (!(winpos
->flags
& SWP_NOMOVE
))
662 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
663 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
665 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
666 if (!(winpos
->flags
& SWP_NOSIZE
) && !is_win9x
)
668 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
669 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
673 case WM_WINDOWPOSCHANGED
:
676 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
677 trace("main: WM_WINDOWPOSCHANGED %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
678 winpos
->hwnd
, winpos
->hwndInsertAfter
,
679 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
680 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
681 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
683 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
684 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
686 GetWindowRect(hwnd
, &rc1
);
687 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
688 /* note: winpos coordinates are relative to parent */
689 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
692 /* Uncomment this once the test succeeds in all cases */
693 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
694 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
696 GetClientRect(hwnd
, &rc2
);
697 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
698 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
699 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
700 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
706 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
707 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
709 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
710 if (got_getminmaxinfo
)
711 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
713 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
714 ok(got_getminmaxinfo
, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
716 ok(!got_getminmaxinfo
, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
720 if (test_lbuttondown_flag
)
722 ShowWindow((HWND
)wparam
, SW_SHOW
);
723 flush_events( FALSE
);
728 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
731 static LRESULT WINAPI
tool_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
735 case WM_GETMINMAXINFO
:
737 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
739 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
740 dump_minmax_info( minmax
);
741 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
746 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
747 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
749 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
750 if (got_getminmaxinfo
)
751 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
753 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
754 ok(got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
756 ok(!got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
761 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
764 static BOOL
RegisterWindowClasses(void)
768 cls
.style
= CS_DBLCLKS
;
769 cls
.lpfnWndProc
= main_window_procA
;
772 cls
.hInstance
= GetModuleHandleA(0);
774 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
775 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
776 cls
.lpszMenuName
= NULL
;
777 cls
.lpszClassName
= "MainWindowClass";
779 if(!RegisterClassA(&cls
)) return FALSE
;
782 cls
.lpfnWndProc
= tool_window_procA
;
785 cls
.hInstance
= GetModuleHandleA(0);
787 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
788 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
789 cls
.lpszMenuName
= NULL
;
790 cls
.lpszClassName
= "ToolWindowClass";
792 if(!RegisterClassA(&cls
)) return FALSE
;
797 static void verify_window_info(const char *hook
, HWND hwnd
, const WINDOWINFO
*info
)
799 RECT rcWindow
, rcClient
;
802 ok(IsWindow(hwnd
), "bad window handle %p in hook %s\n", hwnd
, hook
);
804 GetWindowRect(hwnd
, &rcWindow
);
805 ok(EqualRect(&rcWindow
, &info
->rcWindow
), "wrong rcWindow for %p in hook %s\n", hwnd
, hook
);
807 GetClientRect(hwnd
, &rcClient
);
808 /* translate to screen coordinates */
809 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rcClient
, 2);
810 ok(EqualRect(&rcClient
, &info
->rcClient
), "wrong rcClient for %p in hook %s\n", hwnd
, hook
);
812 ok(info
->dwStyle
== (DWORD
)GetWindowLongA(hwnd
, GWL_STYLE
),
813 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
814 info
->dwStyle
, GetWindowLongA(hwnd
, GWL_STYLE
), hwnd
, hook
);
815 /* Windows reports some undocumented exstyles in WINDOWINFO, but
816 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
818 ok((info
->dwExStyle
& ~0xe0000800) == (DWORD
)GetWindowLongA(hwnd
, GWL_EXSTYLE
),
819 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
820 info
->dwExStyle
, GetWindowLongA(hwnd
, GWL_EXSTYLE
), hwnd
, hook
);
821 status
= (GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0;
822 if (GetForegroundWindow())
823 ok(info
->dwWindowStatus
== status
, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
824 info
->dwWindowStatus
, status
, GetActiveWindow(), GetForegroundWindow(), hook
);
826 /* win2k and XP return broken border info in GetWindowInfo most of
827 * the time, so there is no point in testing it.
831 ok(info
->cxWindowBorders
== (unsigned)(rcClient
.left
- rcWindow
.left
),
832 "wrong cxWindowBorders %d != %d\n", info
->cxWindowBorders
, rcClient
.left
- rcWindow
.left
);
833 border
= min(rcWindow
.bottom
- rcClient
.bottom
, rcClient
.top
- rcWindow
.top
);
834 ok(info
->cyWindowBorders
== border
,
835 "wrong cyWindowBorders %d != %d\n", info
->cyWindowBorders
, border
);
837 ok(info
->atomWindowType
== GetClassLongA(hwnd
, GCW_ATOM
), "wrong atomWindowType for %p in hook %s\n",
839 ok(info
->wCreatorVersion
== 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
840 info
->wCreatorVersion
== 0x0500 /* Vista */,
841 "wrong wCreatorVersion %04x for %p in hook %s\n", info
->wCreatorVersion
, hwnd
, hook
);
844 static void FixedAdjustWindowRectEx(RECT
* rc
, LONG style
, BOOL menu
, LONG exstyle
)
846 AdjustWindowRectEx(rc
, style
, menu
, exstyle
);
847 /* AdjustWindowRectEx does not include scroll bars */
848 if (style
& WS_VSCROLL
)
850 if(exstyle
& WS_EX_LEFTSCROLLBAR
)
851 rc
->left
-= GetSystemMetrics(SM_CXVSCROLL
);
853 rc
->right
+= GetSystemMetrics(SM_CXVSCROLL
);
855 if (style
& WS_HSCROLL
)
856 rc
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
859 static void test_nonclient_area(HWND hwnd
)
861 DWORD style
, exstyle
;
862 RECT rc_window
, rc_client
, rc
;
866 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
867 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
868 menu
= !(style
& WS_CHILD
) && GetMenu(hwnd
) != 0;
870 GetWindowRect(hwnd
, &rc_window
);
871 GetClientRect(hwnd
, &rc_client
);
873 /* avoid some cases when things go wrong */
874 if (IsRectEmpty(&rc_window
) || IsRectEmpty(&rc_client
) ||
875 rc_window
.right
> 32768 || rc_window
.bottom
> 32768) return;
877 CopyRect(&rc
, &rc_client
);
878 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc
, 2);
879 FixedAdjustWindowRectEx(&rc
, style
, menu
, exstyle
);
881 ok(EqualRect(&rc
, &rc_window
),
882 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
883 style
, exstyle
, menu
, rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
,
884 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
887 CopyRect(&rc
, &rc_window
);
888 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
889 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
890 ok(EqualRect(&rc
, &rc_client
),
891 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
892 style
, exstyle
, menu
, rc_client
.left
, rc_client
.top
, rc_client
.right
, rc_client
.bottom
,
893 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
895 /* NULL rectangle shouldn't crash */
896 ret
= DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, 0);
897 ok(ret
== 0, "NULL rectangle returned %ld instead of 0\n", ret
);
899 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
903 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
904 SetRect(&rc_client
, 0, 0, 250, 150);
905 CopyRect(&rc_window
, &rc_client
);
906 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc_window
, 2);
907 FixedAdjustWindowRectEx(&rc_window
, style
, menu
, exstyle
);
909 CopyRect(&rc
, &rc_window
);
910 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
911 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
912 ok(EqualRect(&rc
, &rc_client
),
913 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
914 style
, exstyle
, menu
, rc_client
.left
, rc_client
.top
, rc_client
.right
, rc_client
.bottom
,
915 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
918 static LRESULT CALLBACK
cbt_hook_proc(int nCode
, WPARAM wParam
, LPARAM lParam
)
920 static const char *CBT_code_name
[10] = {
931 const char *code_name
= (nCode
>= 0 && nCode
<= HCBT_SETFOCUS
) ? CBT_code_name
[nCode
] : "Unknown";
932 HWND hwnd
= (HWND
)wParam
;
938 static const RECT rc_null
;
941 CBT_CREATEWNDA
*createwnd
= (CBT_CREATEWNDA
*)lParam
;
942 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
943 hwnd
, createwnd
->lpcs
->hwndParent
, createwnd
->lpcs
->style
);
944 ok(createwnd
->hwndInsertAfter
== HWND_TOP
, "hwndInsertAfter should be always HWND_TOP\n");
949 info
.cbSize
= sizeof(WINDOWINFO
);
950 ok(pGetWindowInfo(hwnd
, &info
), "GetWindowInfo should not fail\n");
951 verify_window_info(code_name
, hwnd
, &info
);
954 /* WS_VISIBLE should be turned off yet */
955 style
= createwnd
->lpcs
->style
& ~WS_VISIBLE
;
956 ok(style
== GetWindowLongA(hwnd
, GWL_STYLE
),
957 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
958 GetWindowLongA(hwnd
, GWL_STYLE
), style
);
962 /* Uncomment this once the test succeeds in all cases */
963 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
965 ok(GetParent(hwnd
) == hwndMessage
,
966 "wrong result from GetParent %p: message window %p\n",
967 GetParent(hwnd
), hwndMessage
);
970 ok(!GetParent(hwnd
), "GetParent should return 0 at this point\n");
972 ok(!GetWindow(hwnd
, GW_OWNER
), "GW_OWNER should be set to 0 at this point\n");
976 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
977 * Win9x still has them set to 0.
979 ok(GetWindow(hwnd
, GW_HWNDFIRST
) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
980 ok(GetWindow(hwnd
, GW_HWNDLAST
) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
982 ok(!GetWindow(hwnd
, GW_HWNDPREV
), "GW_HWNDPREV should be set to 0 at this point\n");
983 ok(!GetWindow(hwnd
, GW_HWNDNEXT
), "GW_HWNDNEXT should be set to 0 at this point\n");
987 /* Uncomment this once the test succeeds in all cases */
990 ok(pGetAncestor(hwnd
, GA_PARENT
) == hwndMessage
, "GA_PARENT should be set to hwndMessage at this point\n");
991 ok(pGetAncestor(hwnd
, GA_ROOT
) == hwnd
,
992 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd
, GA_ROOT
), hwnd
);
994 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
995 ok(pGetAncestor(hwnd
, GA_ROOTOWNER
) == hwndMessage
,
996 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
998 ok(pGetAncestor(hwnd
, GA_ROOTOWNER
) == hwnd
,
999 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd
, GA_ROOTOWNER
), hwnd
);
1002 ok(GetWindowRect(hwnd
, &rc
), "GetWindowRect failed\n");
1003 ok(EqualRect(&rc
, &rc_null
), "window rect should be set to 0 HCBT_CREATEWND\n");
1004 ok(GetClientRect(hwnd
, &rc
), "GetClientRect failed\n");
1005 ok(EqualRect(&rc
, &rc_null
), "client rect should be set to 0 on HCBT_CREATEWND\n");
1013 if (pGetWindowInfo
&& IsWindow(hwnd
))
1017 /* Win98 actually does check the info.cbSize and doesn't allow
1018 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
1019 * WinXP do not check it at all.
1021 info
.cbSize
= sizeof(WINDOWINFO
);
1022 ok(pGetWindowInfo(hwnd
, &info
), "GetWindowInfo should not fail\n");
1023 verify_window_info(code_name
, hwnd
, &info
);
1026 /* on HCBT_DESTROYWND window state is undefined */
1027 case HCBT_DESTROYWND
:
1028 trace( "HCBT_DESTROYWND: hwnd %p\n", hwnd
);
1034 return CallNextHookEx(hhook
, nCode
, wParam
, lParam
);
1037 static void test_shell_window(void)
1041 HMODULE hinst
, hUser32
;
1042 BOOL (WINAPI
*SetShellWindow
)(HWND
);
1043 HWND hwnd1
, hwnd2
, hwnd3
, hwnd4
, hwnd5
;
1044 HWND shellWindow
, nextWnd
;
1048 win_skip("Skipping shell window test on Win9x\n");
1052 shellWindow
= GetShellWindow();
1053 hinst
= GetModuleHandle(0);
1054 hUser32
= GetModuleHandleA("user32");
1056 SetShellWindow
= (void *)GetProcAddress(hUser32
, "SetShellWindow");
1058 trace("previous shell window: %p\n", shellWindow
);
1064 GetWindowThreadProcessId(shellWindow
, &pid
);
1065 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, pid
);
1068 skip( "cannot get access to shell process\n" );
1072 SetLastError(0xdeadbeef);
1073 ret
= DestroyWindow(shellWindow
);
1074 error
= GetLastError();
1076 ok(!ret
, "DestroyWindow(shellWindow)\n");
1077 /* passes on Win XP, but not on Win98 */
1078 ok(error
==ERROR_ACCESS_DENIED
|| error
== 0xdeadbeef,
1079 "got %u after DestroyWindow(shellWindow)\n", error
);
1081 /* close old shell instance */
1082 ret
= TerminateProcess(hProcess
, 0);
1083 ok(ret
, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1084 WaitForSingleObject(hProcess
, INFINITE
); /* wait for termination */
1085 CloseHandle(hProcess
);
1088 hwnd1
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst
, 0);
1089 trace("created window 1: %p\n", hwnd1
);
1091 ret
= SetShellWindow(hwnd1
);
1092 ok(ret
, "first call to SetShellWindow(hwnd1)\n");
1093 shellWindow
= GetShellWindow();
1094 ok(shellWindow
==hwnd1
, "wrong shell window: %p\n", shellWindow
);
1096 ret
= SetShellWindow(hwnd1
);
1097 ok(!ret
, "second call to SetShellWindow(hwnd1)\n");
1099 ret
= SetShellWindow(0);
1100 error
= GetLastError();
1101 /* passes on Win XP, but not on Win98
1102 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1103 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1105 ret
= SetShellWindow(hwnd1
);
1106 /* passes on Win XP, but not on Win98
1107 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1109 SetWindowLong(hwnd1
, GWL_EXSTYLE
, GetWindowLong(hwnd1
,GWL_EXSTYLE
)|WS_EX_TOPMOST
);
1110 ret
= GetWindowLong(hwnd1
,GWL_EXSTYLE
)&WS_EX_TOPMOST
? TRUE
: FALSE
;
1111 ok(!ret
, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1113 ret
= DestroyWindow(hwnd1
);
1114 ok(ret
, "DestroyWindow(hwnd1)\n");
1116 hwnd2
= CreateWindowEx(WS_EX_TOPMOST
, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst
, 0);
1117 trace("created window 2: %p\n", hwnd2
);
1118 ret
= SetShellWindow(hwnd2
);
1119 ok(!ret
, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1121 hwnd3
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst
, 0);
1122 trace("created window 3: %p\n", hwnd3
);
1124 hwnd4
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst
, 0);
1125 trace("created window 4: %p\n", hwnd4
);
1127 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1128 ok(nextWnd
==hwnd3
, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd
);
1130 ret
= SetShellWindow(hwnd4
);
1131 ok(ret
, "SetShellWindow(hwnd4)\n");
1132 shellWindow
= GetShellWindow();
1133 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1135 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1136 ok(nextWnd
==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd
);
1138 ret
= SetWindowPos(hwnd4
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1139 ok(ret
, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1141 ret
= SetWindowPos(hwnd4
, hwnd3
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1142 ok(ret
, "SetWindowPos(hwnd4, hwnd3\n");
1144 ret
= SetShellWindow(hwnd3
);
1145 ok(!ret
, "SetShellWindow(hwnd3)\n");
1146 shellWindow
= GetShellWindow();
1147 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1149 hwnd5
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst
, 0);
1150 trace("created window 5: %p\n", hwnd5
);
1151 ret
= SetWindowPos(hwnd4
, hwnd5
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1152 ok(ret
, "SetWindowPos(hwnd4, hwnd5)\n");
1156 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1157 ok(nextWnd
==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd
);
1160 /* destroy test windows */
1161 DestroyWindow(hwnd2
);
1162 DestroyWindow(hwnd3
);
1163 DestroyWindow(hwnd4
);
1164 DestroyWindow(hwnd5
);
1167 /************** MDI test ****************/
1169 static char mdi_lParam_test_message
[] = "just a test string";
1171 static void test_MDI_create(HWND parent
, HWND mdi_client
, INT_PTR first_id
)
1173 MDICREATESTRUCTA mdi_cs
;
1176 static const WCHAR classW
[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1177 static const WCHAR titleW
[] = {'M','D','I',' ','c','h','i','l','d',0};
1178 BOOL isWin9x
= FALSE
;
1180 mdi_cs
.szClass
= "MDI_child_Class_1";
1181 mdi_cs
.szTitle
= "MDI child";
1182 mdi_cs
.hOwner
= GetModuleHandle(0);
1183 mdi_cs
.x
= CW_USEDEFAULT
;
1184 mdi_cs
.y
= CW_USEDEFAULT
;
1185 mdi_cs
.cx
= CW_USEDEFAULT
;
1186 mdi_cs
.cy
= CW_USEDEFAULT
;
1188 mdi_cs
.lParam
= (LPARAM
)mdi_lParam_test_message
;
1189 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1190 ok(mdi_child
!= 0, "MDI child creation failed\n");
1191 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1192 ok(id
== first_id
, "wrong child id %ld\n", id
);
1193 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1194 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1196 mdi_cs
.style
= 0x7fffffff; /* without WS_POPUP */
1197 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1198 ok(mdi_child
!= 0, "MDI child creation failed\n");
1199 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1200 ok(id
== first_id
, "wrong child id %ld\n", id
);
1201 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1202 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1204 mdi_cs
.style
= 0xffffffff; /* with WS_POPUP */
1205 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1206 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1208 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1212 ok(mdi_child
!= 0, "MDI child creation failed\n");
1213 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1214 ok(id
== first_id
, "wrong child id %ld\n", id
);
1215 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1216 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1219 /* test MDICREATESTRUCT A<->W mapping */
1220 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1222 mdi_cs
.szClass
= (LPCSTR
)classW
;
1223 mdi_cs
.szTitle
= (LPCSTR
)titleW
;
1224 SetLastError(0xdeadbeef);
1225 mdi_child
= (HWND
)SendMessageW(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1228 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1231 ok(mdi_child
!= 0, "MDI child creation failed\n");
1235 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1236 ok(id
== first_id
, "wrong child id %ld\n", id
);
1237 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1238 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1241 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1243 CW_USEDEFAULT
, CW_USEDEFAULT
,
1244 CW_USEDEFAULT
, CW_USEDEFAULT
,
1245 mdi_client
, GetModuleHandle(0),
1246 (LPARAM
)mdi_lParam_test_message
);
1247 ok(mdi_child
!= 0, "MDI child creation failed\n");
1248 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1249 ok(id
== first_id
, "wrong child id %ld\n", id
);
1250 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1251 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1253 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1254 0x7fffffff, /* without WS_POPUP */
1255 CW_USEDEFAULT
, CW_USEDEFAULT
,
1256 CW_USEDEFAULT
, CW_USEDEFAULT
,
1257 mdi_client
, GetModuleHandle(0),
1258 (LPARAM
)mdi_lParam_test_message
);
1259 ok(mdi_child
!= 0, "MDI child creation failed\n");
1260 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1261 ok(id
== first_id
, "wrong child id %ld\n", id
);
1262 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1263 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1265 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1266 0xffffffff, /* with WS_POPUP */
1267 CW_USEDEFAULT
, CW_USEDEFAULT
,
1268 CW_USEDEFAULT
, CW_USEDEFAULT
,
1269 mdi_client
, GetModuleHandle(0),
1270 (LPARAM
)mdi_lParam_test_message
);
1271 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1273 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1277 ok(mdi_child
!= 0, "MDI child creation failed\n");
1278 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1279 ok(id
== first_id
, "wrong child id %ld\n", id
);
1280 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1281 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1284 /* test MDICREATESTRUCT A<->W mapping */
1285 SetLastError(0xdeadbeef);
1286 mdi_child
= CreateMDIWindowW(classW
, titleW
,
1288 CW_USEDEFAULT
, CW_USEDEFAULT
,
1289 CW_USEDEFAULT
, CW_USEDEFAULT
,
1290 mdi_client
, GetModuleHandle(0),
1291 (LPARAM
)mdi_lParam_test_message
);
1294 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1297 ok(mdi_child
!= 0, "MDI child creation failed\n");
1301 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1302 ok(id
== first_id
, "wrong child id %ld\n", id
);
1303 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1304 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1307 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1309 CW_USEDEFAULT
, CW_USEDEFAULT
,
1310 CW_USEDEFAULT
, CW_USEDEFAULT
,
1311 mdi_client
, 0, GetModuleHandle(0),
1312 mdi_lParam_test_message
);
1313 ok(mdi_child
!= 0, "MDI child creation failed\n");
1314 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1315 ok(id
== first_id
, "wrong child id %ld\n", id
);
1316 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1317 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1319 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1320 0x7fffffff, /* without WS_POPUP */
1321 CW_USEDEFAULT
, CW_USEDEFAULT
,
1322 CW_USEDEFAULT
, CW_USEDEFAULT
,
1323 mdi_client
, 0, GetModuleHandle(0),
1324 mdi_lParam_test_message
);
1325 ok(mdi_child
!= 0, "MDI child creation failed\n");
1326 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1327 ok(id
== first_id
, "wrong child id %ld\n", id
);
1328 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1329 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1331 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1332 0xffffffff, /* with WS_POPUP */
1333 CW_USEDEFAULT
, CW_USEDEFAULT
,
1334 CW_USEDEFAULT
, CW_USEDEFAULT
,
1335 mdi_client
, 0, GetModuleHandle(0),
1336 mdi_lParam_test_message
);
1337 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1339 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1343 ok(mdi_child
!= 0, "MDI child creation failed\n");
1344 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1345 ok(id
== first_id
, "wrong child id %ld\n", id
);
1346 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1347 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1350 /* test MDICREATESTRUCT A<->W mapping */
1351 SetLastError(0xdeadbeef);
1352 mdi_child
= CreateWindowExW(WS_EX_MDICHILD
, classW
, titleW
,
1354 CW_USEDEFAULT
, CW_USEDEFAULT
,
1355 CW_USEDEFAULT
, CW_USEDEFAULT
,
1356 mdi_client
, 0, GetModuleHandle(0),
1357 mdi_lParam_test_message
);
1360 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1363 ok(mdi_child
!= 0, "MDI child creation failed\n");
1367 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1368 ok(id
== first_id
, "wrong child id %ld\n", id
);
1369 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1370 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1373 /* This test fails on Win9x */
1376 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_2", "MDI child",
1378 CW_USEDEFAULT
, CW_USEDEFAULT
,
1379 CW_USEDEFAULT
, CW_USEDEFAULT
,
1380 parent
, 0, GetModuleHandle(0),
1381 mdi_lParam_test_message
);
1382 ok(!mdi_child
, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1385 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1386 WS_CHILD
, /* without WS_POPUP */
1387 CW_USEDEFAULT
, CW_USEDEFAULT
,
1388 CW_USEDEFAULT
, CW_USEDEFAULT
,
1389 mdi_client
, 0, GetModuleHandle(0),
1390 mdi_lParam_test_message
);
1391 ok(mdi_child
!= 0, "MDI child creation failed\n");
1392 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1393 ok(id
== 0, "wrong child id %ld\n", id
);
1394 DestroyWindow(mdi_child
);
1396 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1397 WS_CHILD
| WS_POPUP
, /* with WS_POPUP */
1398 CW_USEDEFAULT
, CW_USEDEFAULT
,
1399 CW_USEDEFAULT
, CW_USEDEFAULT
,
1400 mdi_client
, 0, GetModuleHandle(0),
1401 mdi_lParam_test_message
);
1402 ok(mdi_child
!= 0, "MDI child creation failed\n");
1403 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1404 ok(id
== 0, "wrong child id %ld\n", id
);
1405 DestroyWindow(mdi_child
);
1407 /* maximized child */
1408 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1409 WS_CHILD
| WS_MAXIMIZE
,
1410 CW_USEDEFAULT
, CW_USEDEFAULT
,
1411 CW_USEDEFAULT
, CW_USEDEFAULT
,
1412 mdi_client
, 0, GetModuleHandle(0),
1413 mdi_lParam_test_message
);
1414 ok(mdi_child
!= 0, "MDI child creation failed\n");
1415 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1416 ok(id
== 0, "wrong child id %ld\n", id
);
1417 DestroyWindow(mdi_child
);
1419 trace("Creating maximized child with a caption\n");
1420 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1421 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
,
1422 CW_USEDEFAULT
, CW_USEDEFAULT
,
1423 CW_USEDEFAULT
, CW_USEDEFAULT
,
1424 mdi_client
, 0, GetModuleHandle(0),
1425 mdi_lParam_test_message
);
1426 ok(mdi_child
!= 0, "MDI child creation failed\n");
1427 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1428 ok(id
== 0, "wrong child id %ld\n", id
);
1429 DestroyWindow(mdi_child
);
1431 trace("Creating maximized child with a caption and a thick frame\n");
1432 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1433 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
| WS_THICKFRAME
,
1434 CW_USEDEFAULT
, CW_USEDEFAULT
,
1435 CW_USEDEFAULT
, CW_USEDEFAULT
,
1436 mdi_client
, 0, GetModuleHandle(0),
1437 mdi_lParam_test_message
);
1438 ok(mdi_child
!= 0, "MDI child creation failed\n");
1439 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1440 ok(id
== 0, "wrong child id %ld\n", id
);
1441 DestroyWindow(mdi_child
);
1444 /**********************************************************************
1445 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1447 * Note: The rule here is that client rect of the maximized MDI child
1448 * is equal to the client rect of the MDI client window.
1450 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
1454 GetClientRect( client
, &rect
);
1455 AdjustWindowRectEx( &rect
, GetWindowLongA( hwnd
, GWL_STYLE
),
1456 0, GetWindowLongA( hwnd
, GWL_EXSTYLE
));
1458 rect
.right
-= rect
.left
;
1459 rect
.bottom
-= rect
.top
;
1460 lpMinMax
->ptMaxSize
.x
= rect
.right
;
1461 lpMinMax
->ptMaxSize
.y
= rect
.bottom
;
1463 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
1464 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
1466 trace("max rect (%d,%d - %d, %d)\n",
1467 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1470 static LRESULT WINAPI
mdi_child_wnd_proc_1(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1477 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1478 MDICREATESTRUCTA
*mdi_cs
= cs
->lpCreateParams
;
1480 ok(cs
->dwExStyle
& WS_EX_MDICHILD
, "WS_EX_MDICHILD should be set\n");
1481 ok(mdi_cs
->lParam
== (LPARAM
)mdi_lParam_test_message
, "wrong mdi_cs->lParam\n");
1483 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_1"), "wrong class name\n");
1484 ok(!lstrcmpA(cs
->lpszClass
, mdi_cs
->szClass
), "class name does not match\n");
1485 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1486 ok(!lstrcmpA(cs
->lpszName
, mdi_cs
->szTitle
), "title does not match\n");
1487 ok(cs
->hInstance
== mdi_cs
->hOwner
, "%p != %p\n", cs
->hInstance
, mdi_cs
->hOwner
);
1489 /* MDICREATESTRUCT should have original values */
1490 ok(mdi_cs
->style
== 0 || mdi_cs
->style
== 0x7fffffff || mdi_cs
->style
== 0xffffffff,
1491 "mdi_cs->style does not match (%08x)\n", mdi_cs
->style
);
1492 ok(mdi_cs
->x
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->x
);
1493 ok(mdi_cs
->y
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->y
);
1494 ok(mdi_cs
->cx
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cx
);
1495 ok(mdi_cs
->cy
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cy
);
1497 /* CREATESTRUCT should have fixed values */
1498 ok(cs
->x
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->x
);
1499 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1501 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1502 ok(cs
->cx
!= CW_USEDEFAULT
&& cs
->cx
!= 0, "%d == CW_USEDEFAULT\n", cs
->cx
);
1503 ok(cs
->cy
!= CW_USEDEFAULT
&& cs
->cy
!= 0, "%d == CW_USEDEFAULT\n", cs
->cy
);
1505 ok(!(cs
->style
& WS_POPUP
), "WS_POPUP is not allowed\n");
1507 if (GetWindowLongA(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1509 LONG style
= mdi_cs
->style
| WS_CHILD
| WS_CLIPSIBLINGS
;
1510 ok(cs
->style
== style
,
1511 "cs->style does not match (%08x)\n", cs
->style
);
1515 LONG style
= mdi_cs
->style
;
1517 style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1518 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1519 ok(cs
->style
== style
,
1520 "cs->style does not match (%08x)\n", cs
->style
);
1525 case WM_GETMINMAXINFO
:
1527 HWND client
= GetParent(hwnd
);
1529 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1530 MINMAXINFO my_minmax
;
1531 LONG style
, exstyle
;
1533 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1534 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1536 GetWindowRect(client
, &rc
);
1537 trace("MDI client %p window size = (%d x %d)\n", client
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1538 GetClientRect(client
, &rc
);
1539 trace("MDI client %p client size = (%d x %d)\n", client
, rc
.right
, rc
.bottom
);
1540 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN
),
1541 GetSystemMetrics(SM_CYSCREEN
));
1543 GetClientRect(client
, &rc
);
1544 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1545 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1546 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1547 trace("MDI child: calculated max window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1548 dump_minmax_info( minmax
);
1550 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1551 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1552 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1553 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1555 DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1557 trace("DefMDIChildProc returned:\n");
1558 dump_minmax_info( minmax
);
1560 MDI_ChildGetMinMaxInfo(client
, hwnd
, &my_minmax
);
1561 ok(minmax
->ptMaxSize
.x
== my_minmax
.ptMaxSize
.x
, "default width of maximized child %d != %d\n",
1562 minmax
->ptMaxSize
.x
, my_minmax
.ptMaxSize
.x
);
1563 ok(minmax
->ptMaxSize
.y
== my_minmax
.ptMaxSize
.y
, "default height of maximized child %d != %d\n",
1564 minmax
->ptMaxSize
.y
, my_minmax
.ptMaxSize
.y
);
1569 case WM_MDIACTIVATE
:
1571 HWND active
, client
= GetParent(hwnd
);
1572 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1573 active
= (HWND
)SendMessageA(client
, WM_MDIGETACTIVE
, 0, 0);
1574 if (hwnd
== (HWND
)lparam
) /* if we are being activated */
1575 ok (active
== (HWND
)lparam
, "new active %p != active %p\n", (HWND
)lparam
, active
);
1577 ok (active
== (HWND
)wparam
, "old active %p != active %p\n", (HWND
)wparam
, active
);
1581 return DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1584 static LRESULT WINAPI
mdi_child_wnd_proc_2(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1591 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1593 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg
== WM_NCCREATE
) ? "WM_NCCREATE" : "WM_CREATE",
1594 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
1596 ok(!(cs
->dwExStyle
& WS_EX_MDICHILD
), "WS_EX_MDICHILD should not be set\n");
1597 ok(cs
->lpCreateParams
== mdi_lParam_test_message
, "wrong cs->lpCreateParams\n");
1599 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_2"), "wrong class name\n");
1600 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1602 /* CREATESTRUCT should have fixed values */
1603 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1605 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1606 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1608 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1609 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1610 while Win95, Win2k, WinXP do. */
1611 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1612 ok(cs
->cy
== 0, "%d != 0\n", cs
->cy
);
1616 case WM_GETMINMAXINFO
:
1618 HWND parent
= GetParent(hwnd
);
1620 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1621 LONG style
, exstyle
;
1623 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1624 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1626 GetClientRect(parent
, &rc
);
1627 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent
, rc
.right
, rc
.bottom
);
1629 GetClientRect(parent
, &rc
);
1630 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1631 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1632 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1633 dump_minmax_info( minmax
);
1635 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1636 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1637 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1638 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1642 case WM_WINDOWPOSCHANGED
:
1644 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1647 GetWindowRect(hwnd
, &rc1
);
1648 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1649 /* note: winpos coordinates are relative to parent */
1650 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1651 ok(EqualRect(&rc1
, &rc2
), "rects do not match, window=(%d,%d)-(%d,%d) pos=(%d,%d)-(%d,%d)\n",
1652 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
1653 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1654 GetWindowRect(hwnd
, &rc1
);
1655 GetClientRect(hwnd
, &rc2
);
1656 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1657 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1658 ok(EqualRect(&rc1
, &rc2
), "rects do not match, window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1659 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
1660 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1663 case WM_WINDOWPOSCHANGING
:
1665 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1666 WINDOWPOS my_winpos
= *winpos
;
1668 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1669 (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
1670 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1671 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1673 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1675 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1676 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1677 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1678 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1683 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1686 static LRESULT WINAPI
mdi_main_wnd_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1688 static HWND mdi_client
;
1694 CLIENTCREATESTRUCT client_cs
;
1697 GetClientRect(hwnd
, &rc
);
1699 client_cs
.hWindowMenu
= 0;
1700 client_cs
.idFirstChild
= 1;
1702 /* MDIClient without MDIS_ALLCHILDSTYLES */
1703 mdi_client
= CreateWindowExA(0, "mdiclient",
1705 WS_CHILD
/*| WS_VISIBLE*/,
1706 /* tests depend on a not zero MDIClient size */
1707 0, 0, rc
.right
, rc
.bottom
,
1708 hwnd
, 0, GetModuleHandle(0),
1711 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1712 DestroyWindow(mdi_client
);
1714 /* MDIClient with MDIS_ALLCHILDSTYLES */
1715 mdi_client
= CreateWindowExA(0, "mdiclient",
1717 WS_CHILD
| MDIS_ALLCHILDSTYLES
/*| WS_VISIBLE*/,
1718 /* tests depend on a not zero MDIClient size */
1719 0, 0, rc
.right
, rc
.bottom
,
1720 hwnd
, 0, GetModuleHandle(0),
1723 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1724 DestroyWindow(mdi_client
);
1728 case WM_WINDOWPOSCHANGED
:
1730 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1733 GetWindowRect(hwnd
, &rc1
);
1734 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1735 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1736 /* note: winpos coordinates are relative to parent */
1737 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1738 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1739 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1741 GetWindowRect(hwnd
, &rc1
);
1742 GetClientRect(hwnd
, &rc2
);
1743 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1744 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1745 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1748 case WM_WINDOWPOSCHANGING
:
1750 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1751 WINDOWPOS my_winpos
= *winpos
;
1753 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1754 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1755 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1756 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1758 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1760 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1761 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1762 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1764 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1765 "DefWindowProc should not change WINDOWPOS values\n");
1774 return DefFrameProcA(hwnd
, mdi_client
, msg
, wparam
, lparam
);
1777 static BOOL
mdi_RegisterWindowClasses(void)
1782 cls
.lpfnWndProc
= mdi_main_wnd_procA
;
1785 cls
.hInstance
= GetModuleHandleA(0);
1787 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
1788 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1789 cls
.lpszMenuName
= NULL
;
1790 cls
.lpszClassName
= "MDI_parent_Class";
1791 if(!RegisterClassA(&cls
)) return FALSE
;
1793 cls
.lpfnWndProc
= mdi_child_wnd_proc_1
;
1794 cls
.lpszClassName
= "MDI_child_Class_1";
1795 if(!RegisterClassA(&cls
)) return FALSE
;
1797 cls
.lpfnWndProc
= mdi_child_wnd_proc_2
;
1798 cls
.lpszClassName
= "MDI_child_Class_2";
1799 if(!RegisterClassA(&cls
)) return FALSE
;
1804 static void test_mdi(void)
1809 if (!mdi_RegisterWindowClasses()) assert(0);
1811 mdi_hwndMain
= CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1812 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
1813 WS_MAXIMIZEBOX
/*| WS_VISIBLE*/,
1814 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1815 GetDesktopWindow(), 0,
1816 GetModuleHandle(0), NULL
);
1817 assert(mdi_hwndMain
);
1819 while(GetMessage(&msg, 0, 0, 0))
1821 TranslateMessage(&msg);
1822 DispatchMessage(&msg);
1825 DestroyWindow(mdi_hwndMain
);
1828 static void test_icons(void)
1832 HICON icon
= LoadIconA(0, IDI_APPLICATION
);
1833 HICON icon2
= LoadIconA(0, IDI_QUESTION
);
1834 HICON small_icon
= LoadImageA(0, IDI_APPLICATION
, IMAGE_ICON
,
1835 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
1838 cls
.cbSize
= sizeof(cls
);
1840 cls
.lpfnWndProc
= DefWindowProcA
;
1844 cls
.hIcon
= LoadIconA(0, IDI_HAND
);
1845 cls
.hIconSm
= small_icon
;
1846 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
1847 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1848 cls
.lpszMenuName
= NULL
;
1849 cls
.lpszClassName
= "IconWindowClass";
1851 RegisterClassExA(&cls
);
1853 hwnd
= CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1854 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, NULL
, NULL
);
1857 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1858 ok( res
== 0, "wrong big icon %p/0\n", res
);
1859 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon
);
1860 ok( res
== 0, "wrong previous big icon %p/0\n", res
);
1861 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1862 ok( res
== icon
, "wrong big icon after set %p/%p\n", res
, icon
);
1863 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon2
);
1864 ok( res
== icon
, "wrong previous big icon %p/%p\n", res
, icon
);
1865 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1866 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1868 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1869 ok( res
== 0, "wrong small icon %p/0\n", res
);
1870 /* this test is XP specific */
1871 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1872 ok( res != 0, "wrong small icon %p\n", res );*/
1873 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)icon
);
1874 ok( res
== 0, "wrong previous small icon %p/0\n", res
);
1875 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1876 ok( res
== icon
, "wrong small icon after set %p/%p\n", res
, icon
);
1877 /* this test is XP specific */
1878 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1879 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1880 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)small_icon
);
1881 ok( res
== icon
, "wrong previous small icon %p/%p\n", res
, icon
);
1882 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1883 ok( res
== small_icon
, "wrong small icon after set %p/%p\n", res
, small_icon
);
1884 /* this test is XP specific */
1885 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1886 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1888 /* make sure the big icon hasn't changed */
1889 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1890 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1892 DestroyWindow( hwnd
);
1895 static LRESULT WINAPI
nccalcsize_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1897 if (msg
== WM_NCCALCSIZE
)
1899 RECT
*rect
= (RECT
*)lparam
;
1900 /* first time around increase the rectangle, next time decrease it */
1901 if (rect
->left
== 100) InflateRect( rect
, 10, 10 );
1902 else InflateRect( rect
, -10, -10 );
1905 return DefWindowProc( hwnd
, msg
, wparam
, lparam
);
1908 static void test_SetWindowPos(HWND hwnd
)
1910 RECT orig_win_rc
, rect
;
1913 SetRect(&rect
, 111, 222, 333, 444);
1914 ok(!GetWindowRect(0, &rect
), "GetWindowRect succeeded\n");
1915 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1916 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1918 SetRect(&rect
, 111, 222, 333, 444);
1919 ok(!GetClientRect(0, &rect
), "GetClientRect succeeded\n");
1920 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1921 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1923 GetWindowRect(hwnd
, &orig_win_rc
);
1925 old_proc
= SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)nccalcsize_proc
);
1926 SetWindowPos(hwnd
, 0, 100, 100, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1927 GetWindowRect( hwnd
, &rect
);
1928 ok( rect
.left
== 100 && rect
.top
== 100 && rect
.right
== 100 && rect
.bottom
== 100,
1929 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1930 GetClientRect( hwnd
, &rect
);
1931 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1932 ok( rect
.left
== 90 && rect
.top
== 90 && rect
.right
== 110 && rect
.bottom
== 110,
1933 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1935 SetWindowPos(hwnd
, 0, 200, 200, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1936 GetWindowRect( hwnd
, &rect
);
1937 ok( rect
.left
== 200 && rect
.top
== 200 && rect
.right
== 200 && rect
.bottom
== 200,
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
== 210 && rect
.top
== 210 && rect
.right
== 190 && rect
.bottom
== 190,
1942 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1944 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1945 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1946 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, old_proc
);
1948 /* Win9x truncates coordinates to 16-bit irrespectively */
1951 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE
);
1952 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE
);
1954 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE
);
1955 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE
);
1958 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1959 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1961 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1962 SetWindowPos(hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1963 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1964 SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1965 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1966 SetWindowPos(hwnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1967 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1970 static void test_SetMenu(HWND parent
)
1977 hMenu
= CreateMenu();
1980 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1983 /* fails on (at least) Wine, NT4, XP SP2 */
1984 test_nonclient_area(parent
);
1986 ret
= GetMenu(parent
);
1987 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1988 /* test whether we can destroy a menu assigned to a window */
1989 retok
= DestroyMenu(hMenu
);
1990 ok( retok
, "DestroyMenu error %d\n", GetLastError());
1991 retok
= IsMenu(hMenu
);
1992 ok(!retok
|| broken(retok
) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
1993 ret
= GetMenu(parent
);
1994 /* This test fails on Win9x */
1996 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1997 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1998 test_nonclient_area(parent
);
2000 hMenu
= CreateMenu();
2004 ret
= GetMenu(parent
);
2005 ok(ret
== 0, "unexpected menu id %p\n", ret
);
2007 ok(!SetMenu(parent
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
2008 test_nonclient_area(parent
);
2009 ret
= GetMenu(parent
);
2010 ok(ret
== 0, "unexpected menu id %p\n", ret
);
2012 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
2015 /* fails on (at least) Wine, NT4, XP SP2 */
2016 test_nonclient_area(parent
);
2018 ret
= GetMenu(parent
);
2019 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
2021 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
2022 test_nonclient_area(parent
);
2023 ret
= GetMenu(parent
);
2024 ok(ret
== 0, "unexpected menu id %p\n", ret
);
2027 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, parent
, (HMENU
)10, 0, NULL
);
2030 ret
= GetMenu(child
);
2031 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2033 ok(!SetMenu(child
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
2034 test_nonclient_area(child
);
2035 ret
= GetMenu(child
);
2036 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2038 ok(!SetMenu(child
, hMenu
), "SetMenu on a child window should fail\n");
2039 test_nonclient_area(child
);
2040 ret
= GetMenu(child
);
2041 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2043 ok(!SetMenu(child
, 0), "SetMenu(0) on a child window should fail\n");
2044 test_nonclient_area(child
);
2045 ret
= GetMenu(child
);
2046 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2048 style
= GetWindowLong(child
, GWL_STYLE
);
2049 SetWindowLong(child
, GWL_STYLE
, style
| WS_POPUP
);
2050 ok(SetMenu(child
, hMenu
), "SetMenu on a popup child window should not fail\n");
2051 ok(SetMenu(child
, 0), "SetMenu on a popup child window should not fail\n");
2052 SetWindowLong(child
, GWL_STYLE
, style
);
2054 SetWindowLong(child
, GWL_STYLE
, style
| WS_OVERLAPPED
);
2055 ok(!SetMenu(child
, hMenu
), "SetMenu on a overlapped child window should fail\n");
2056 SetWindowLong(child
, GWL_STYLE
, style
);
2058 DestroyWindow(child
);
2062 static void test_window_tree(HWND parent
, const DWORD
*style
, const int *order
, int total
)
2064 HWND child
[5], hwnd
;
2069 hwnd
= GetWindow(parent
, GW_CHILD
);
2070 ok(!hwnd
, "have to start without children to perform the test\n");
2072 for (i
= 0; i
< total
; i
++)
2074 if (style
[i
] & DS_CONTROL
)
2076 child
[i
] = CreateWindowExA(0, MAKEINTATOM(32770), "", style
[i
] & ~WS_VISIBLE
,
2077 0,0,0,0, parent
, (HMENU
)i
, 0, NULL
);
2078 if (style
[i
] & WS_VISIBLE
)
2079 ShowWindow(child
[i
], SW_SHOW
);
2081 SetWindowPos(child
[i
], HWND_BOTTOM
, 0,0,10,10, SWP_NOACTIVATE
);
2084 child
[i
] = CreateWindowExA(0, "static", "", style
[i
], 0,0,10,10,
2085 parent
, (HMENU
)i
, 0, NULL
);
2086 trace("child[%ld] = %p\n", i
, child
[i
]);
2087 ok(child
[i
] != 0, "CreateWindowEx failed to create child window\n");
2090 hwnd
= GetWindow(parent
, GW_CHILD
);
2091 ok(hwnd
!= 0, "GetWindow(GW_CHILD) failed\n");
2092 ok(hwnd
== GetWindow(child
[total
- 1], GW_HWNDFIRST
), "GW_HWNDFIRST is wrong\n");
2093 ok(child
[order
[total
- 1]] == GetWindow(child
[0], GW_HWNDLAST
), "GW_HWNDLAST is wrong\n");
2095 for (i
= 0; i
< total
; i
++)
2097 trace("hwnd[%ld] = %p\n", i
, hwnd
);
2098 ok(child
[order
[i
]] == hwnd
, "Z order of child #%ld is wrong\n", i
);
2100 hwnd
= GetWindow(hwnd
, GW_HWNDNEXT
);
2103 for (i
= 0; i
< total
; i
++)
2104 ok(DestroyWindow(child
[i
]), "DestroyWindow failed\n");
2107 static void test_children_zorder(HWND parent
)
2109 const DWORD simple_style
[5] = { WS_CHILD
, WS_CHILD
, WS_CHILD
, WS_CHILD
,
2111 const int simple_order
[5] = { 0, 1, 2, 3, 4 };
2113 const DWORD complex_style
[5] = { WS_CHILD
, WS_CHILD
| WS_MAXIMIZE
,
2114 WS_CHILD
| WS_VISIBLE
, WS_CHILD
,
2115 WS_CHILD
| WS_MAXIMIZE
| WS_VISIBLE
};
2116 const int complex_order_1
[1] = { 0 };
2117 const int complex_order_2
[2] = { 1, 0 };
2118 const int complex_order_3
[3] = { 1, 0, 2 };
2119 const int complex_order_4
[4] = { 1, 0, 2, 3 };
2120 const int complex_order_5
[5] = { 4, 1, 0, 2, 3 };
2121 const DWORD complex_style_6
[3] = { WS_CHILD
| WS_VISIBLE
,
2122 WS_CHILD
| WS_CLIPSIBLINGS
| DS_CONTROL
| WS_VISIBLE
,
2123 WS_CHILD
| WS_VISIBLE
};
2124 const int complex_order_6
[3] = { 0, 1, 2 };
2126 /* simple WS_CHILD */
2127 test_window_tree(parent
, simple_style
, simple_order
, 5);
2129 /* complex children styles */
2130 test_window_tree(parent
, complex_style
, complex_order_1
, 1);
2131 test_window_tree(parent
, complex_style
, complex_order_2
, 2);
2132 test_window_tree(parent
, complex_style
, complex_order_3
, 3);
2133 test_window_tree(parent
, complex_style
, complex_order_4
, 4);
2134 test_window_tree(parent
, complex_style
, complex_order_5
, 5);
2136 /* another set of complex children styles */
2137 test_window_tree(parent
, complex_style_6
, complex_order_6
, 3);
2140 #define check_z_order(hwnd, next, prev, owner, topmost) \
2141 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2144 static void check_z_order_debug(HWND hwnd
, HWND next
, HWND prev
, HWND owner
,
2145 BOOL topmost
, const char *file
, int line
)
2150 test
= GetWindow(hwnd
, GW_HWNDNEXT
);
2151 /* skip foreign windows */
2152 while (test
&& test
!= next
&&
2153 (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2154 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0) ||
2155 GetWindow(test
, GW_OWNER
) == next
))
2157 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2158 test
= GetWindow(test
, GW_HWNDNEXT
);
2160 ok_(file
, line
)(next
== test
, "%p: expected next %p, got %p\n", hwnd
, next
, test
);
2162 test
= GetWindow(hwnd
, GW_HWNDPREV
);
2163 /* skip foreign windows */
2164 while (test
&& test
!= prev
&&
2165 (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2166 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0) ||
2167 GetWindow(test
, GW_OWNER
) == hwnd
))
2169 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2170 test
= GetWindow(test
, GW_HWNDPREV
);
2172 ok_(file
, line
)(prev
== test
, "%p: expected prev %p, got %p\n", hwnd
, prev
, test
);
2174 test
= GetWindow(hwnd
, GW_OWNER
);
2175 ok_(file
, line
)(owner
== test
, "%p: expected owner %p, got %p\n", hwnd
, owner
, test
);
2177 ex_style
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
2178 ok_(file
, line
)(!(ex_style
& WS_EX_TOPMOST
) == !topmost
, "%p: expected %stopmost\n",
2179 hwnd
, topmost
? "" : "NOT ");
2182 static void test_popup_zorder(HWND hwnd_D
, HWND hwnd_E
, DWORD style
)
2184 HWND hwnd_A
, hwnd_B
, hwnd_C
, hwnd_F
;
2186 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D
, hwnd_E
);
2188 SetWindowPos(hwnd_E
, hwnd_D
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2190 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2191 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2193 hwnd_F
= CreateWindowEx(0, "MainWindowClass", "Owner window",
2194 WS_OVERLAPPED
| WS_CAPTION
,
2196 0, 0, GetModuleHandle(0), NULL
);
2197 trace("hwnd_F %p\n", hwnd_F
);
2198 check_z_order(hwnd_F
, hwnd_D
, 0, 0, FALSE
);
2200 SetWindowPos(hwnd_F
, hwnd_E
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2201 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2202 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2203 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2205 hwnd_C
= CreateWindowEx(0, "MainWindowClass", NULL
,
2208 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2209 trace("hwnd_C %p\n", hwnd_C
);
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
, hwnd_C
, 0, FALSE
);
2213 check_z_order(hwnd_C
, hwnd_D
, 0, hwnd_F
, FALSE
);
2215 hwnd_B
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2218 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2219 trace("hwnd_B %p\n", hwnd_B
);
2220 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2221 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2222 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2223 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2224 check_z_order(hwnd_B
, hwnd_C
, 0, hwnd_F
, TRUE
);
2226 hwnd_A
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2229 0, 0, GetModuleHandle(0), NULL
);
2230 trace("hwnd_A %p\n", hwnd_A
);
2231 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2232 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2233 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2234 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2235 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2236 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2238 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
);
2240 /* move hwnd_F and its popups up */
2241 SetWindowPos(hwnd_F
, HWND_TOP
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2242 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2243 check_z_order(hwnd_D
, hwnd_E
, hwnd_F
, 0, FALSE
);
2244 check_z_order(hwnd_F
, hwnd_D
, hwnd_C
, 0, FALSE
);
2245 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2246 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2247 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2249 /* move hwnd_F and its popups down */
2250 #if 0 /* enable once Wine is fixed to pass this test */
2251 SetWindowPos(hwnd_F
, HWND_BOTTOM
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2252 check_z_order(hwnd_F
, 0, hwnd_C
, 0, FALSE
);
2253 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2254 check_z_order(hwnd_B
, hwnd_C
, hwnd_E
, hwnd_F
, FALSE
);
2255 check_z_order(hwnd_E
, hwnd_B
, hwnd_D
, 0, FALSE
);
2256 check_z_order(hwnd_D
, hwnd_E
, hwnd_A
, 0, FALSE
);
2257 check_z_order(hwnd_A
, hwnd_D
, 0, 0, TRUE
);
2260 /* make hwnd_C owned by a topmost window */
2261 DestroyWindow( hwnd_C
);
2262 hwnd_C
= CreateWindowEx(0, "MainWindowClass", NULL
,
2265 hwnd_A
, 0, GetModuleHandle(0), NULL
);
2266 trace("hwnd_C %p\n", hwnd_C
);
2267 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2268 check_z_order(hwnd_D
, hwnd_E
, hwnd_F
, 0, FALSE
);
2269 check_z_order(hwnd_F
, hwnd_D
, hwnd_B
, 0, FALSE
);
2270 check_z_order(hwnd_B
, hwnd_F
, hwnd_A
, hwnd_F
, TRUE
);
2271 check_z_order(hwnd_A
, hwnd_B
, hwnd_C
, 0, TRUE
);
2272 check_z_order(hwnd_C
, hwnd_A
, 0, hwnd_A
, TRUE
);
2274 DestroyWindow(hwnd_A
);
2275 DestroyWindow(hwnd_B
);
2276 DestroyWindow(hwnd_C
);
2277 DestroyWindow(hwnd_F
);
2280 static void test_vis_rgn( HWND hwnd
)
2282 RECT win_rect
, rgn_rect
;
2283 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2286 ShowWindow(hwnd
,SW_SHOW
);
2287 hdc
= GetDC( hwnd
);
2288 ok( GetRandomRgn( hdc
, hrgn
, SYSRGN
) != 0, "GetRandomRgn failed\n" );
2289 GetWindowRect( hwnd
, &win_rect
);
2290 GetRgnBox( hrgn
, &rgn_rect
);
2293 trace("win9x, mapping to screen coords\n");
2294 MapWindowPoints( hwnd
, 0, (POINT
*)&rgn_rect
, 2 );
2296 trace("win: %d,%d-%d,%d\n", win_rect
.left
, win_rect
.top
, win_rect
.right
, win_rect
.bottom
);
2297 trace("rgn: %d,%d-%d,%d\n", rgn_rect
.left
, rgn_rect
.top
, rgn_rect
.right
, rgn_rect
.bottom
);
2298 ok( win_rect
.left
<= rgn_rect
.left
, "rgn left %d not inside win rect %d\n",
2299 rgn_rect
.left
, win_rect
.left
);
2300 ok( win_rect
.top
<= rgn_rect
.top
, "rgn top %d not inside win rect %d\n",
2301 rgn_rect
.top
, win_rect
.top
);
2302 ok( win_rect
.right
>= rgn_rect
.right
, "rgn right %d not inside win rect %d\n",
2303 rgn_rect
.right
, win_rect
.right
);
2304 ok( win_rect
.bottom
>= rgn_rect
.bottom
, "rgn bottom %d not inside win rect %d\n",
2305 rgn_rect
.bottom
, win_rect
.bottom
);
2306 ReleaseDC( hwnd
, hdc
);
2309 static LRESULT WINAPI
set_focus_on_activate_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
2311 if (msg
== WM_ACTIVATE
&& LOWORD(wp
) == WA_ACTIVE
)
2313 HWND child
= GetWindow(hwnd
, GW_CHILD
);
2314 ok(child
!= 0, "couldn't find child window\n");
2316 ok(GetFocus() == child
, "Focus should be on child %p\n", child
);
2319 return DefWindowProc(hwnd
, msg
, wp
, lp
);
2322 static void test_SetFocus(HWND hwnd
)
2325 WNDPROC old_wnd_proc
;
2327 /* check if we can set focus to non-visible windows */
2329 ShowWindow(hwnd
, SW_SHOW
);
2332 ok( GetFocus() == hwnd
, "Failed to set focus to visible window %p\n", hwnd
);
2333 ok( GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
, "Window %p not visible\n", hwnd
);
2334 ShowWindow(hwnd
, SW_HIDE
);
2337 ok( GetFocus() == hwnd
, "Failed to set focus to invisible window %p\n", hwnd
);
2338 ok( !(GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
), "Window %p still visible\n", hwnd
);
2339 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2342 ok( GetFocus() == child
, "Failed to set focus to invisible child %p\n", child
);
2343 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2344 ShowWindow(child
, SW_SHOW
);
2345 ok( GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
, "Child %p is not visible\n", child
);
2346 ok( GetFocus() == child
, "Focus no longer on child %p\n", child
);
2347 ShowWindow(child
, SW_HIDE
);
2348 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2349 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2350 ShowWindow(child
, SW_SHOW
);
2351 child2
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, child
, 0, 0, NULL
);
2353 ShowWindow(child2
, SW_SHOW
);
2355 ShowWindow(child
, SW_HIDE
);
2356 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2357 ok( GetFocus() == child2
, "Focus should be on %p, not %p\n", child2
, GetFocus() );
2358 ShowWindow(child
, SW_SHOW
);
2360 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2361 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_HIDEWINDOW
);
2362 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2364 ShowWindow(child
, SW_HIDE
);
2366 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2367 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_SHOWWINDOW
);
2368 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2369 ShowWindow(child
, SW_HIDE
);
2370 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2372 ShowWindow(hwnd
, SW_SHOW
);
2373 ShowWindow(child
, SW_SHOW
);
2375 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2376 EnableWindow(hwnd
, FALSE
);
2377 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2378 EnableWindow(hwnd
, TRUE
);
2380 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2381 ShowWindow(hwnd
, SW_SHOWMINIMIZED
);
2382 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2384 ok( GetFocus() != child
, "Focus should not be on child %p\n", child
);
2385 ok( GetFocus() != hwnd
, "Focus should not be on parent %p\n", hwnd
);
2386 ShowWindow(hwnd
, SW_RESTORE
);
2387 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2388 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
2389 ShowWindow(hwnd
, SW_SHOWMINIMIZED
);
2390 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2391 ok( GetFocus() != child
, "Focus should not be on child %p\n", child
);
2393 ok( GetFocus() != hwnd
, "Focus should not be on parent %p\n", hwnd
);
2394 old_wnd_proc
= (WNDPROC
)SetWindowLongPtr(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)set_focus_on_activate_proc
);
2395 ShowWindow(hwnd
, SW_RESTORE
);
2396 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2398 ok( GetFocus() == child
, "Focus should be on child %p, not %p\n", child
, GetFocus() );
2400 SetWindowLongPtr(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)old_wnd_proc
);
2402 DestroyWindow( child2
);
2403 DestroyWindow( child
);
2406 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
2407 static void check_wnd_state_(const char *file
, int line
,
2408 HWND active
, HWND foreground
, HWND focus
, HWND capture
)
2410 ok_(file
, line
)(active
== GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2411 /* only check foreground if it belongs to the current thread */
2412 /* foreground can be moved to a different app pretty much at any time */
2413 if (foreground
&& GetForegroundWindow() &&
2414 GetWindowThreadProcessId(GetForegroundWindow(), NULL
) == GetCurrentThreadId())
2415 ok_(file
, line
)(foreground
== GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2416 ok_(file
, line
)(focus
== GetFocus(), "GetFocus() = %p\n", GetFocus());
2417 ok_(file
, line
)(capture
== GetCapture(), "GetCapture() = %p\n", GetCapture());
2420 static void test_SetActiveWindow(HWND hwnd
)
2424 flush_events( TRUE
);
2425 ShowWindow(hwnd
, SW_HIDE
);
2428 check_wnd_state(0, 0, 0, 0);
2430 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2432 ShowWindow(hwnd
, SW_SHOW
);
2433 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2435 hwnd2
= SetActiveWindow(0);
2436 ok(hwnd2
== hwnd
, "SetActiveWindow returned %p instead of %p\n", hwnd2
, hwnd
);
2437 if (!GetActiveWindow()) /* doesn't always work on vista */
2439 check_wnd_state(0, 0, 0, 0);
2440 hwnd2
= SetActiveWindow(hwnd
);
2441 ok(hwnd2
== 0, "SetActiveWindow returned %p instead of 0\n", hwnd2
);
2443 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2445 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2446 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2448 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2449 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2451 ShowWindow(hwnd
, SW_HIDE
);
2452 check_wnd_state(0, 0, 0, 0);
2454 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2455 SetActiveWindow(hwnd
);
2456 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2458 ShowWindow(hwnd
, SW_SHOW
);
2459 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2461 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2462 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2464 DestroyWindow(hwnd2
);
2465 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2467 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2468 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2470 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2471 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2473 DestroyWindow(hwnd2
);
2474 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2477 struct create_window_thread_params
2480 HANDLE window_created
;
2481 HANDLE test_finished
;
2484 static DWORD WINAPI
create_window_thread(void *param
)
2486 struct create_window_thread_params
*p
= param
;
2490 p
->window
= CreateWindowA("static", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 0, 0, 0, 0, 0, 0);
2492 ret
= SetEvent(p
->window_created
);
2493 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
2495 res
= WaitForSingleObject(p
->test_finished
, INFINITE
);
2496 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
2498 DestroyWindow(p
->window
);
2502 static void test_SetForegroundWindow(HWND hwnd
)
2504 struct create_window_thread_params thread_params
;
2511 flush_events( TRUE
);
2512 ShowWindow(hwnd
, SW_HIDE
);
2515 check_wnd_state(0, 0, 0, 0);
2517 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2519 ShowWindow(hwnd
, SW_SHOW
);
2520 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2522 hwnd2
= SetActiveWindow(0);
2523 ok(hwnd2
== hwnd
, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2
, hwnd
);
2524 if (GetActiveWindow() == hwnd
) /* doesn't always work on vista */
2525 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2527 check_wnd_state(0, 0, 0, 0);
2529 ret
= SetForegroundWindow(hwnd
);
2532 skip( "SetForegroundWindow not working\n" );
2535 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2537 SetLastError(0xdeadbeef);
2538 ret
= SetForegroundWindow(0);
2539 ok(!ret
, "SetForegroundWindow returned TRUE instead of FALSE\n");
2540 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
||
2541 broken(GetLastError() == 0xdeadbeef), /* win9x */
2542 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2543 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2545 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2546 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2548 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2549 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2551 hwnd2
= GetForegroundWindow();
2552 ok(hwnd2
== hwnd
, "Wrong foreground window %p\n", hwnd2
);
2553 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2554 hwnd2
= GetForegroundWindow();
2555 ok(hwnd2
!= hwnd
, "Wrong foreground window %p\n", hwnd2
);
2557 ShowWindow(hwnd
, SW_HIDE
);
2558 check_wnd_state(0, 0, 0, 0);
2560 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2561 ret
= SetForegroundWindow(hwnd
);
2562 ok(ret
|| broken(!ret
), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
2563 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2565 ShowWindow(hwnd
, SW_SHOW
);
2566 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2568 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2569 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2571 DestroyWindow(hwnd2
);
2572 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2574 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2575 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2577 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2578 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2580 DestroyWindow(hwnd2
);
2581 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2583 hwnd2
= CreateWindowA("static", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 0, 0, 0, 0, 0, 0);
2584 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2586 thread_params
.window_created
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
2587 ok(!!thread_params
.window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
2588 thread_params
.test_finished
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
2589 ok(!!thread_params
.test_finished
, "CreateEvent failed, last error %#x.\n", GetLastError());
2590 thread
= CreateThread(NULL
, 0, create_window_thread
, &thread_params
, 0, &tid
);
2591 ok(!!thread
, "Failed to create thread, last error %#x.\n", GetLastError());
2592 res
= WaitForSingleObject(thread_params
.window_created
, INFINITE
);
2593 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
2594 check_wnd_state(hwnd2
, thread_params
.window
, hwnd2
, 0);
2596 SetForegroundWindow(hwnd2
);
2597 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2599 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage(&msg
);
2600 if (0) check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2601 todo_wine
ok(GetActiveWindow() == hwnd2
, "Expected active window %p, got %p.\n", hwnd2
, GetActiveWindow());
2602 todo_wine
ok(GetFocus() == hwnd2
, "Expected focus window %p, got %p.\n", hwnd2
, GetFocus());
2604 SetEvent(thread_params
.test_finished
);
2605 WaitForSingleObject(thread
, INFINITE
);
2606 CloseHandle(thread_params
.test_finished
);
2607 CloseHandle(thread_params
.window_created
);
2608 CloseHandle(thread
);
2609 DestroyWindow(hwnd2
);
2612 static WNDPROC old_button_proc
;
2614 static LRESULT WINAPI
button_hook_proc(HWND button
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2619 key_state
= GetKeyState(VK_LBUTTON
);
2620 ok(!(key_state
& 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state
);
2622 ret
= CallWindowProcA(old_button_proc
, button
, msg
, wparam
, lparam
);
2624 if (msg
== WM_LBUTTONDOWN
)
2628 check_wnd_state(button
, button
, button
, button
);
2630 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2632 trace("hwnd %p\n", hwnd
);
2634 check_wnd_state(button
, button
, button
, button
);
2636 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2638 check_wnd_state(button
, button
, button
, button
);
2640 DestroyWindow(hwnd
);
2642 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2644 trace("hwnd %p\n", hwnd
);
2646 check_wnd_state(button
, button
, button
, button
);
2648 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2649 * match internal button state.
2651 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2652 check_wnd_state(button
, button
, button
, 0);
2654 ShowWindow(hwnd
, SW_SHOW
);
2655 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2657 capture
= SetCapture(hwnd
);
2658 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2660 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2662 DestroyWindow(hwnd
);
2664 check_wnd_state(button
, 0, button
, 0);
2670 static void test_capture_1(void)
2672 HWND button
, capture
, oldFocus
, oldActive
;
2674 oldFocus
= GetFocus();
2675 oldActive
= GetActiveWindow();
2677 capture
= GetCapture();
2678 ok(capture
== 0, "GetCapture() = %p\n", capture
);
2680 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2682 trace("button %p\n", button
);
2684 old_button_proc
= (WNDPROC
)SetWindowLongPtrA(button
, GWLP_WNDPROC
, (LONG_PTR
)button_hook_proc
);
2686 SendMessageA(button
, WM_LBUTTONDOWN
, 0, 0);
2688 capture
= SetCapture(button
);
2689 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2690 check_wnd_state(button
, 0, button
, button
);
2692 DestroyWindow(button
);
2693 check_wnd_state(oldActive
, 0, oldFocus
, 0);
2696 static void test_capture_2(void)
2698 HWND button
, hwnd
, capture
, oldFocus
, oldActive
;
2700 oldFocus
= GetFocus();
2701 oldActive
= GetActiveWindow();
2702 check_wnd_state(oldActive
, 0, oldFocus
, 0);
2704 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2706 trace("button %p\n", button
);
2708 check_wnd_state(button
, button
, button
, 0);
2710 capture
= SetCapture(button
);
2711 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2713 check_wnd_state(button
, button
, button
, button
);
2715 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2716 * internal button state.
2718 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2719 check_wnd_state(button
, button
, button
, button
);
2721 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2723 trace("hwnd %p\n", hwnd
);
2725 check_wnd_state(button
, button
, button
, button
);
2727 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2729 check_wnd_state(button
, button
, button
, button
);
2731 DestroyWindow(hwnd
);
2733 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2735 trace("hwnd %p\n", hwnd
);
2737 check_wnd_state(button
, button
, button
, button
);
2739 ShowWindow(hwnd
, SW_SHOW
);
2741 check_wnd_state(hwnd
, hwnd
, hwnd
, button
);
2743 capture
= SetCapture(hwnd
);
2744 ok(capture
== button
, "SetCapture() = %p\n", capture
);
2746 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2748 DestroyWindow(hwnd
);
2749 check_wnd_state(button
, button
, button
, 0);
2751 DestroyWindow(button
);
2752 check_wnd_state(oldActive
, 0, oldFocus
, 0);
2755 static void test_capture_3(HWND hwnd1
, HWND hwnd2
)
2759 ShowWindow(hwnd1
, SW_HIDE
);
2760 ShowWindow(hwnd2
, SW_HIDE
);
2762 ok(!IsWindowVisible(hwnd1
), "%p should be invisible\n", hwnd1
);
2763 ok(!IsWindowVisible(hwnd2
), "%p should be invisible\n", hwnd2
);
2766 check_wnd_state(0, 0, 0, hwnd1
);
2769 check_wnd_state(0, 0, 0, hwnd2
);
2771 ShowWindow(hwnd1
, SW_SHOW
);
2772 check_wnd_state(hwnd1
, hwnd1
, hwnd1
, hwnd2
);
2774 ret
= ReleaseCapture();
2775 ok (ret
, "releasecapture did not return TRUE.\n");
2776 ret
= ReleaseCapture();
2777 ok (ret
, "releasecapture did not return TRUE after second try.\n");
2780 static LRESULT CALLBACK
test_capture_4_proc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2783 HWND cap_wnd
, cap_wnd2
, set_cap_wnd
;
2787 case WM_CAPTURECHANGED
:
2789 /* now try to release capture from menu. this should fail */
2790 if (pGetGUIThreadInfo
)
2792 memset(>i
, 0, sizeof(GUITHREADINFO
));
2793 gti
.cbSize
= sizeof(GUITHREADINFO
);
2794 status
= pGetGUIThreadInfo(GetCurrentThreadId(), >i
);
2795 ok(status
, "GetGUIThreadInfo() failed!\n");
2796 ok(gti
.flags
& GUI_INMENUMODE
, "Thread info incorrect (flags=%08X)!\n", gti
.flags
);
2798 cap_wnd
= GetCapture();
2800 /* check that re-setting the capture for the menu fails */
2801 set_cap_wnd
= SetCapture(cap_wnd
);
2802 ok(!set_cap_wnd
|| broken(set_cap_wnd
== cap_wnd
), /* nt4 */
2803 "SetCapture should have failed!\n");
2806 DestroyWindow(hWnd
);
2810 /* check that SetCapture fails for another window and that it does not touch the error code */
2811 set_cap_wnd
= SetCapture(hWnd
);
2812 ok(!set_cap_wnd
, "SetCapture should have failed!\n");
2814 /* check that ReleaseCapture fails and does not touch the error code */
2815 status
= ReleaseCapture();
2816 ok(!status
, "ReleaseCapture should have failed!\n");
2818 /* check that thread info did not change */
2819 if (pGetGUIThreadInfo
)
2821 memset(>i
, 0, sizeof(GUITHREADINFO
));
2822 gti
.cbSize
= sizeof(GUITHREADINFO
);
2823 status
= pGetGUIThreadInfo(GetCurrentThreadId(), >i
);
2824 ok(status
, "GetGUIThreadInfo() failed!\n");
2825 ok(gti
.flags
& GUI_INMENUMODE
, "Thread info incorrect (flags=%08X)!\n", gti
.flags
);
2828 /* verify that no capture change took place */
2829 cap_wnd2
= GetCapture();
2830 ok(cap_wnd2
== cap_wnd
, "Capture changed!\n");
2832 /* we are done. kill the window */
2833 DestroyWindow(hWnd
);
2837 return( DefWindowProcA( hWnd
, msg
, wParam
, lParam
) );
2842 /* Test that no-one can mess around with the current capture while a menu is open */
2843 static void test_capture_4(void)
2849 HINSTANCE hInstance
= GetModuleHandleA( NULL
);
2851 if (!pGetGUIThreadInfo
)
2853 win_skip("GetGUIThreadInfo is not available\n");
2856 wclass
.lpszClassName
= "TestCapture4Class";
2857 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
2858 wclass
.lpfnWndProc
= test_capture_4_proc
;
2859 wclass
.hInstance
= hInstance
;
2860 wclass
.hIcon
= LoadIconA( 0, IDI_APPLICATION
);
2861 wclass
.hCursor
= LoadCursorA( NULL
, IDC_ARROW
);
2862 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
2863 wclass
.lpszMenuName
= 0;
2864 wclass
.cbClsExtra
= 0;
2865 wclass
.cbWndExtra
= 0;
2866 assert (RegisterClassA( &wclass
));
2867 assert (hwnd
= CreateWindowA( wclass
.lpszClassName
, "MenuTest",
2868 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0,
2869 400, 200, NULL
, NULL
, hInstance
, NULL
) );
2870 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
2872 hmenu
= CreatePopupMenu();
2874 ret
= AppendMenuA( hmenu
, MF_STRING
, 1, "winetest2");
2875 ok( ret
, "AppendMenuA has failed!\n");
2877 /* set main window to have initial capture */
2882 win_skip("TrackPopupMenu test crashes on Win9x/WinMe\n");
2886 /* create popup (it will self-destruct) */
2887 ret
= TrackPopupMenu(hmenu
, TPM_RETURNCMD
, 100, 100, 0, hwnd
, NULL
);
2888 ok( ret
== 0, "TrackPopupMenu returned %d expected zero\n", ret
);
2893 DestroyWindow(hwnd
);
2896 /* PeekMessage wrapper that ignores the messages we don't care about */
2897 static BOOL
peek_message( MSG
*msg
)
2902 ret
= PeekMessageA(msg
, 0, 0, 0, PM_REMOVE
);
2903 } while (ret
&& (msg
->message
== WM_TIMER
|| ignore_message(msg
->message
)));
2907 static void test_keyboard_input(HWND hwnd
)
2912 flush_events( TRUE
);
2913 SetWindowPos(hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_SHOWWINDOW
);
2915 flush_events( TRUE
);
2917 ok(GetActiveWindow() == hwnd
, "wrong active window %p\n", GetActiveWindow());
2920 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2922 flush_events( TRUE
);
2924 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2925 ret
= peek_message(&msg
);
2926 ok( ret
, "no message available\n");
2927 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2928 ret
= peek_message(&msg
);
2929 ok( !ret
, "message %04x available\n", msg
.message
);
2931 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2933 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2934 ret
= peek_message(&msg
);
2935 ok(ret
, "no message available\n");
2936 ok(!msg
.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 keybd_event(VK_SPACE
, 0, 0, 0);
2943 if (!peek_message(&msg
))
2945 skip( "keybd_event didn't work, skipping keyboard test\n" );
2948 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2949 ret
= peek_message(&msg
);
2950 ok( !ret
, "message %04x available\n", msg
.message
);
2953 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2955 flush_events( TRUE
);
2957 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2958 ret
= peek_message(&msg
);
2959 ok(ret
, "no message available\n");
2960 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2961 ret
= peek_message(&msg
);
2962 ok( !ret
, "message %04x available\n", msg
.message
);
2964 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2966 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2967 ret
= peek_message(&msg
);
2968 ok(ret
, "no message available\n");
2969 ok(!msg
.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 keybd_event(VK_SPACE
, 0, 0, 0);
2976 ret
= peek_message(&msg
);
2977 ok(ret
, "no message available\n");
2978 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_SYSKEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2979 ret
= peek_message(&msg
);
2980 ok( !ret
, "message %04x available\n", msg
.message
);
2983 static BOOL
wait_for_message( MSG
*msg
)
2989 ret
= peek_message(msg
);
2992 if (msg
->message
== WM_PAINT
) DispatchMessage(msg
);
2995 else if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, 100, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
2997 if (!ret
) msg
->message
= 0;
3001 static void test_mouse_input(HWND hwnd
)
3011 ShowWindow(hwnd
, SW_SHOWNORMAL
);
3013 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3015 GetWindowRect(hwnd
, &rc
);
3016 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3018 popup
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_POPUP
,
3019 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
,
3022 ShowWindow(popup
, SW_SHOW
);
3023 UpdateWindow(popup
);
3024 SetWindowPos( popup
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3026 GetWindowRect(popup
, &rc
);
3027 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3029 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
3030 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
3031 trace("setting cursor to (%d,%d)\n", x
, y
);
3035 if (x
!= pt
.x
|| y
!= pt
.y
)
3037 skip( "failed to set mouse position, skipping mouse input tests\n" );
3041 flush_events( TRUE
);
3043 /* Check that setting the same position may generate WM_MOUSEMOVE */
3046 ret
= peek_message(&msg
);
3049 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n",
3050 msg
.hwnd
, msg
.message
);
3051 ok(msg
.pt
.x
== x
&& msg
.pt
.y
== y
, "wrong message coords (%d,%d)/(%d,%d)\n",
3052 x
, y
, msg
.pt
.x
, msg
.pt
.y
);
3055 /* force the system to update its internal queue mouse position,
3056 * otherwise it won't generate relative mouse movements below.
3058 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
3059 flush_events( TRUE
);
3062 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
3063 flush_events( FALSE
);
3064 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
3065 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
3067 if (msg
.message
== WM_TIMER
|| ignore_message(msg
.message
)) continue;
3068 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
,
3069 "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3070 DispatchMessage(&msg
);
3072 ret
= peek_message(&msg
);
3073 ok( !ret
, "message %04x available\n", msg
.message
);
3075 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
3076 ShowWindow(popup
, SW_HIDE
);
3077 ret
= wait_for_message( &msg
);
3079 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
3080 flush_events( TRUE
);
3082 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
3083 ShowWindow(hwnd
, SW_HIDE
);
3084 ret
= wait_for_message( &msg
);
3085 ok( !ret
, "message %04x available\n", msg
.message
);
3086 flush_events( TRUE
);
3088 /* test mouse clicks */
3090 ShowWindow(hwnd
, SW_SHOW
);
3091 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3092 flush_events( TRUE
);
3093 ShowWindow(popup
, SW_SHOW
);
3094 SetWindowPos( popup
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3095 flush_events( TRUE
);
3097 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3098 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3099 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3100 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3102 ret
= wait_for_message( &msg
);
3105 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
3108 if (msg
.message
== WM_MOUSEMOVE
) /* win2k has an extra WM_MOUSEMOVE here */
3110 ret
= wait_for_message( &msg
);
3111 ok(ret
, "no message available\n");
3114 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
3115 msg
.hwnd
, popup
, msg
.message
);
3117 ret
= wait_for_message( &msg
);
3118 ok(ret
, "no message available\n");
3119 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
3120 msg
.hwnd
, popup
, msg
.message
);
3122 ret
= wait_for_message( &msg
);
3123 ok(ret
, "no message available\n");
3124 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p/%p message %04x\n",
3125 msg
.hwnd
, popup
, msg
.message
);
3127 ret
= wait_for_message( &msg
);
3128 ok(ret
, "no message available\n");
3129 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
3130 msg
.hwnd
, popup
, msg
.message
);
3132 ret
= peek_message(&msg
);
3133 ok(!ret
, "message %04x available\n", msg
.message
);
3135 ShowWindow(popup
, SW_HIDE
);
3136 flush_events( TRUE
);
3138 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3139 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3140 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
3141 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
3143 ret
= wait_for_message( &msg
);
3144 ok(ret
, "no message available\n");
3145 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
3146 msg
.hwnd
, hwnd
, msg
.message
);
3147 ret
= wait_for_message( &msg
);
3148 ok(ret
, "no message available\n");
3149 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
3150 msg
.hwnd
, hwnd
, msg
.message
);
3152 test_lbuttondown_flag
= TRUE
;
3153 SendMessageA(hwnd
, WM_COMMAND
, (WPARAM
)popup
, 0);
3154 test_lbuttondown_flag
= FALSE
;
3156 ret
= wait_for_message( &msg
);
3157 ok(ret
, "no message available\n");
3158 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
3159 msg
.hwnd
, popup
, msg
.message
);
3160 ok(peek_message(&msg
), "no message available\n");
3161 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
3162 msg
.hwnd
, popup
, msg
.message
);
3163 ok(peek_message(&msg
), "no message available\n");
3165 /* Test WM_MOUSEACTIVATE */
3166 #define TEST_MOUSEACTIVATE(A,B) \
3167 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
3168 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
3170 TEST_MOUSEACTIVATE(HTERROR
,MA_ACTIVATE
);
3171 TEST_MOUSEACTIVATE(HTTRANSPARENT
,MA_ACTIVATE
);
3172 TEST_MOUSEACTIVATE(HTNOWHERE
,MA_ACTIVATE
);
3173 TEST_MOUSEACTIVATE(HTCLIENT
,MA_ACTIVATE
);
3174 TEST_MOUSEACTIVATE(HTCAPTION
,MA_ACTIVATE
);
3175 TEST_MOUSEACTIVATE(HTSYSMENU
,MA_ACTIVATE
);
3176 TEST_MOUSEACTIVATE(HTSIZE
,MA_ACTIVATE
);
3177 TEST_MOUSEACTIVATE(HTMENU
,MA_ACTIVATE
);
3178 TEST_MOUSEACTIVATE(HTHSCROLL
,MA_ACTIVATE
);
3179 TEST_MOUSEACTIVATE(HTVSCROLL
,MA_ACTIVATE
);
3180 TEST_MOUSEACTIVATE(HTMINBUTTON
,MA_ACTIVATE
);
3181 TEST_MOUSEACTIVATE(HTMAXBUTTON
,MA_ACTIVATE
);
3182 TEST_MOUSEACTIVATE(HTLEFT
,MA_ACTIVATE
);
3183 TEST_MOUSEACTIVATE(HTRIGHT
,MA_ACTIVATE
);
3184 TEST_MOUSEACTIVATE(HTTOP
,MA_ACTIVATE
);
3185 TEST_MOUSEACTIVATE(HTTOPLEFT
,MA_ACTIVATE
);
3186 TEST_MOUSEACTIVATE(HTTOPRIGHT
,MA_ACTIVATE
);
3187 TEST_MOUSEACTIVATE(HTBOTTOM
,MA_ACTIVATE
);
3188 TEST_MOUSEACTIVATE(HTBOTTOMLEFT
,MA_ACTIVATE
);
3189 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT
,MA_ACTIVATE
);
3190 TEST_MOUSEACTIVATE(HTBORDER
,MA_ACTIVATE
);
3191 TEST_MOUSEACTIVATE(HTOBJECT
,MA_ACTIVATE
);
3192 TEST_MOUSEACTIVATE(HTCLOSE
,MA_ACTIVATE
);
3193 TEST_MOUSEACTIVATE(HTHELP
,MA_ACTIVATE
);
3196 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
3197 flush_events( TRUE
);
3199 DestroyWindow(popup
);
3202 static void test_validatergn(HWND hwnd
)
3208 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_VISIBLE
, 10, 10, 10, 10, hwnd
, 0, 0, NULL
);
3209 ShowWindow(hwnd
, SW_SHOW
);
3210 UpdateWindow( hwnd
);
3211 /* test that ValidateRect validates children*/
3212 InvalidateRect( child
, NULL
, 1);
3213 GetWindowRect( child
, &rc
);
3214 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
3215 ret
= GetUpdateRect( child
, &rc2
, 0);
3216 ok( rc2
.right
> rc2
.left
&& rc2
.bottom
> rc2
.top
,
3217 "Update rectangle is empty!\n");
3218 ValidateRect( hwnd
, &rc
);
3219 ret
= GetUpdateRect( child
, &rc2
, 0);
3220 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
3221 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
3222 rc2
.right
, rc2
.bottom
);
3224 /* now test ValidateRgn */
3225 InvalidateRect( child
, NULL
, 1);
3226 GetWindowRect( child
, &rc
);
3227 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
3228 rgn
= CreateRectRgnIndirect( &rc
);
3229 ValidateRgn( hwnd
, rgn
);
3230 ret
= GetUpdateRect( child
, &rc2
, 0);
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
);
3236 DestroyWindow( child
);
3239 static void nccalchelper(HWND hwnd
, INT x
, INT y
, RECT
*prc
)
3242 MoveWindow( hwnd
, 0, 0, x
, y
, 0);
3243 GetWindowRect( hwnd
, prc
);
3245 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)prc
);
3246 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
3247 rc
.left
,rc
.top
,rc
.right
,rc
.bottom
, prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
3250 static void test_nccalcscroll(HWND parent
)
3253 INT sbheight
= GetSystemMetrics( SM_CYHSCROLL
);
3254 INT sbwidth
= GetSystemMetrics( SM_CXVSCROLL
);
3255 HWND hwnd
= CreateWindowExA(0, "static", NULL
,
3256 WS_CHILD
| WS_VISIBLE
| WS_VSCROLL
| WS_HSCROLL
,
3257 10, 10, 200, 200, parent
, 0, 0, NULL
);
3258 ShowWindow( parent
, SW_SHOW
);
3259 UpdateWindow( parent
);
3261 /* test window too low for a horizontal scroll bar */
3262 nccalchelper( hwnd
, 100, sbheight
, &rc1
);
3263 ok( rc1
.bottom
- rc1
.top
== sbheight
, "Height should be %d size is %d,%d - %d,%d\n",
3264 sbheight
, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3266 /* test window just high enough for a horizontal scroll bar */
3267 nccalchelper( hwnd
, 100, sbheight
+ 1, &rc1
);
3268 ok( rc1
.bottom
- rc1
.top
== 1, "Height should be %d size is %d,%d - %d,%d\n",
3269 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3271 /* test window too narrow for a vertical scroll bar */
3272 nccalchelper( hwnd
, sbwidth
- 1, 100, &rc1
);
3273 ok( rc1
.right
- rc1
.left
== sbwidth
- 1 , "Width should be %d size is %d,%d - %d,%d\n",
3274 sbwidth
- 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3276 /* test window just wide enough for a vertical scroll bar */
3277 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
3278 ok( rc1
.right
- rc1
.left
== 0, "Width should be %d size is %d,%d - %d,%d\n",
3279 0, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3281 /* same test, but with client edge: not enough width */
3282 SetWindowLong( hwnd
, GWL_EXSTYLE
, WS_EX_CLIENTEDGE
| GetWindowLong( hwnd
, GWL_EXSTYLE
));
3283 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
3284 ok( rc1
.right
- rc1
.left
== sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
),
3285 "Width should be %d size is %d,%d - %d,%d\n",
3286 sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
), rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3288 DestroyWindow( hwnd
);
3291 static void test_SetParent(void)
3294 HWND desktop
= GetDesktopWindow();
3296 HWND parent
, child1
, child2
, child3
, child4
, sibling
;
3298 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
3299 100, 100, 200, 200, 0, 0, 0, NULL
);
3300 assert(parent
!= 0);
3301 child1
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
3302 0, 0, 50, 50, parent
, 0, 0, NULL
);
3303 assert(child1
!= 0);
3304 child2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
3305 0, 0, 50, 50, child1
, 0, 0, NULL
);
3306 assert(child2
!= 0);
3307 child3
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
3308 0, 0, 50, 50, child2
, 0, 0, NULL
);
3309 assert(child3
!= 0);
3310 child4
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
3311 0, 0, 50, 50, child3
, 0, 0, NULL
);
3312 assert(child4
!= 0);
3314 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
3315 parent
, child1
, child2
, child3
, child4
);
3317 check_parents(parent
, desktop
, 0, 0, 0, parent
, parent
);
3318 check_parents(child1
, parent
, parent
, parent
, 0, parent
, parent
);
3319 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
3320 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
3321 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
3323 ok(!IsChild(desktop
, parent
), "wrong parent/child %p/%p\n", desktop
, parent
);
3324 ok(!IsChild(desktop
, child1
), "wrong parent/child %p/%p\n", desktop
, child1
);
3325 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
3326 ok(!IsChild(desktop
, child3
), "wrong parent/child %p/%p\n", desktop
, child3
);
3327 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
3329 ok(IsChild(parent
, child1
), "wrong parent/child %p/%p\n", parent
, child1
);
3330 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
3331 ok(!IsChild(parent
, child2
), "wrong parent/child %p/%p\n", parent
, child2
);
3332 ok(!IsChild(child1
, child2
), "wrong parent/child %p/%p\n", child1
, child2
);
3333 ok(!IsChild(parent
, child3
), "wrong parent/child %p/%p\n", parent
, child3
);
3334 ok(IsChild(child2
, child3
), "wrong parent/child %p/%p\n", child2
, child3
);
3335 ok(!IsChild(parent
, child4
), "wrong parent/child %p/%p\n", parent
, child4
);
3336 ok(!IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
3337 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
3339 if (!is_win9x
) /* Win9x doesn't survive this test */
3343 ok(!SetParent(parent
, child1
), "SetParent should fail\n");
3344 ok(!SetParent(child2
, child3
), "SetParent should fail\n");
3345 ok(SetParent(child1
, parent
) != 0, "SetParent should not fail\n");
3346 ret
= SetParent(parent
, child2
);
3347 todo_wine
ok( !ret
|| broken( ret
!= 0 ), "SetParent should fail\n");
3348 if (ret
) /* nt4, win2k */
3350 ret
= SetParent(parent
, child3
);
3351 ok(ret
!= 0, "SetParent should not fail\n");
3352 ret
= SetParent(child2
, parent
);
3353 ok(!ret
, "SetParent should fail\n");
3354 ret
= SetParent(parent
, child4
);
3355 ok(ret
!= 0, "SetParent should not fail\n");
3356 check_parents(parent
, child4
, child4
, 0, 0, child4
, parent
);
3357 check_parents(child1
, parent
, parent
, parent
, 0, child4
, parent
);
3358 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
3359 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
3360 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
3364 ret
= SetParent(parent
, child3
);
3365 ok(ret
!= 0, "SetParent should not fail\n");
3366 ret
= SetParent(child2
, parent
);
3367 ok(!ret
, "SetParent should fail\n");
3368 ret
= SetParent(parent
, child4
);
3369 ok(!ret
, "SetParent should fail\n");
3370 check_parents(parent
, child3
, child3
, 0, 0, child2
, parent
);
3371 check_parents(child1
, parent
, parent
, parent
, 0, child2
, parent
);
3372 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
3373 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
3374 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
3378 skip("Win9x/WinMe crash\n");
3380 hMenu
= CreateMenu();
3381 sibling
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
3382 100, 100, 200, 200, 0, hMenu
, 0, NULL
);
3383 assert(sibling
!= 0);
3385 ok(SetParent(sibling
, parent
) != 0, "SetParent should not fail\n");
3386 ok(GetMenu(sibling
) == hMenu
, "SetParent should not remove menu\n");
3388 ret
= DestroyWindow(parent
);
3389 ok( ret
, "DestroyWindow() error %d\n", GetLastError());
3391 ok(!IsWindow(parent
), "parent still exists\n");
3392 ok(!IsWindow(sibling
), "sibling still exists\n");
3393 ok(!IsWindow(child1
), "child1 still exists\n");
3394 ok(!IsWindow(child2
), "child2 still exists\n");
3395 ok(!IsWindow(child3
), "child3 still exists\n");
3396 ok(!IsWindow(child4
), "child4 still exists\n");
3399 static LRESULT WINAPI
StyleCheckProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3401 LPCREATESTRUCT lpcs
;
3408 lpcs
= (LPCREATESTRUCT
)lparam
;
3409 lpss
= lpcs
->lpCreateParams
;
3412 if ((lpcs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
3413 ((!(lpcs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
3414 (lpcs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
3415 ok(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
, "Window should have WS_EX_WINDOWEDGE style\n");
3417 ok(!(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3419 ok((lpss
->styleOld
& ~WS_EX_WINDOWEDGE
) == (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
),
3420 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
3421 (lpss
->styleOld
& ~WS_EX_WINDOWEDGE
), (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
));
3423 ok(lpss
->styleNew
== lpcs
->style
,
3424 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3425 lpss
->styleNew
, lpcs
->style
);
3429 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3432 static ATOM atomStyleCheckClass
;
3434 static void register_style_check_class(void)
3442 GetModuleHandle(NULL
),
3444 LoadCursor(NULL
, IDC_ARROW
),
3445 (HBRUSH
)(COLOR_BTNFACE
+1),
3447 TEXT("WineStyleCheck"),
3450 atomStyleCheckClass
= RegisterClass(&wc
);
3453 static void check_window_style(DWORD dwStyleIn
, DWORD dwExStyleIn
, DWORD dwStyleOut
, DWORD dwExStyleOut
)
3455 DWORD dwActualStyle
;
3456 DWORD dwActualExStyle
;
3459 HWND hwndParent
= NULL
;
3461 ss
.styleNew
= dwStyleIn
;
3462 ss
.styleOld
= dwExStyleIn
;
3464 if (dwStyleIn
& WS_CHILD
)
3466 hwndParent
= CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3467 WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
3470 hwnd
= CreateWindowEx(dwExStyleIn
, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3471 dwStyleIn
, 0, 0, 0, 0, hwndParent
, NULL
, NULL
, &ss
);
3474 flush_events( TRUE
);
3476 dwActualStyle
= GetWindowLong(hwnd
, GWL_STYLE
);
3477 dwActualExStyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
3478 ok((dwActualStyle
== dwStyleOut
) && (dwActualExStyle
== dwExStyleOut
),
3479 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3480 dwActualStyle
, dwStyleOut
, dwActualExStyle
, dwExStyleOut
);
3482 DestroyWindow(hwnd
);
3483 if (hwndParent
) DestroyWindow(hwndParent
);
3486 /* tests what window styles the window manager automatically adds */
3487 static void test_window_styles(void)
3489 register_style_check_class();
3491 check_window_style(0, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
3492 check_window_style(WS_OVERLAPPEDWINDOW
, 0, WS_CLIPSIBLINGS
|WS_OVERLAPPEDWINDOW
, WS_EX_WINDOWEDGE
);
3493 check_window_style(WS_CHILD
, 0, WS_CHILD
, 0);
3494 check_window_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
3495 check_window_style(0, WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_TOOLWINDOW
);
3496 check_window_style(WS_POPUP
, 0, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3497 check_window_style(WS_POPUP
, WS_EX_WINDOWEDGE
, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3498 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
, WS_CHILD
, WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3499 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
|WS_EX_STATICEDGE
, WS_CHILD
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3500 check_window_style(WS_CAPTION
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
);
3501 check_window_style(0, WS_EX_APPWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_APPWINDOW
|WS_EX_WINDOWEDGE
);
3503 if (pGetLayeredWindowAttributes
)
3505 check_window_style(0, WS_EX_LAYERED
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_LAYERED
|WS_EX_WINDOWEDGE
);
3506 check_window_style(0, WS_EX_LAYERED
|WS_EX_TRANSPARENT
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_LAYERED
|WS_EX_TRANSPARENT
|WS_EX_WINDOWEDGE
);
3507 check_window_style(0, WS_EX_LAYERED
|WS_EX_TRANSPARENT
|WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
,
3508 WS_EX_LAYERED
|WS_EX_TRANSPARENT
|WS_EX_TOOLWINDOW
|WS_EX_WINDOWEDGE
);
3512 static void test_scrollwindow( HWND hwnd
)
3518 ShowWindow( hwnd
, SW_SHOW
);
3519 UpdateWindow( hwnd
);
3520 flush_events( TRUE
);
3521 GetClientRect( hwnd
, &rc
);
3523 /* test ScrollWindow(Ex) with no clip rectangle */
3524 /* paint the lower half of the window black */
3526 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
3527 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3528 /* paint the upper half of the window white */
3529 rc2
.bottom
= rc2
.top
;
3531 FillRect( hdc
, &rc2
, GetStockObject(WHITE_BRUSH
));
3532 /* scroll lower half up */
3534 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
3535 ScrollWindowEx( hwnd
, 0, - rc2
.top
, &rc2
, NULL
, NULL
, NULL
, SW_ERASE
);
3536 flush_events(FALSE
);
3537 /* expected: black should have scrolled to the upper half */
3538 colr
= GetPixel( hdc
, (rc2
.left
+rc2
.right
)/ 2, rc2
.bottom
/ 4 );
3539 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3540 /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
3541 /* paint the lower half of the window black */
3543 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
3544 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3545 /* paint the upper half of the window white */
3546 rc2
.bottom
= rc2
.top
;
3548 FillRect( hdc
, &rc2
, GetStockObject(WHITE_BRUSH
));
3549 /* scroll lower half up */
3551 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
3553 rc3
.left
= rc3
.right
/ 4;
3554 rc3
.right
-= rc3
.right
/ 4;
3555 ScrollWindowEx( hwnd
, 0, - rc2
.top
, &rc2
, &rc3
, NULL
, NULL
, SW_ERASE
);
3556 flush_events(FALSE
);
3557 /* expected: black should have scrolled to the upper half */
3558 colr
= GetPixel( hdc
, (rc2
.left
+rc2
.right
)/ 2, rc2
.bottom
/ 4 );
3559 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3562 ReleaseDC( hwnd
, hdc
);
3565 static void test_scrollvalidate( HWND parent
)
3568 HRGN hrgn
=CreateRectRgn(0,0,0,0);
3569 HRGN exprgn
, tmprgn
, clipping
;
3570 RECT rc
, rcu
, cliprc
;
3571 /* create two overlapping child windows. The visual region
3572 * of hwnd1 is clipped by the overlapping part of
3573 * hwnd2 because of the WS_CLIPSIBLING style */
3576 clipping
= CreateRectRgn(0,0,0,0);
3577 tmprgn
= CreateRectRgn(0,0,0,0);
3578 exprgn
= CreateRectRgn(0,0,0,0);
3579 hwnd2
= CreateWindowExA(0, "static", NULL
,
3580 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3581 75, 30, 100, 100, parent
, 0, 0, NULL
);
3582 hwnd1
= CreateWindowExA(0, "static", NULL
,
3583 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3584 25, 50, 100, 100, parent
, 0, 0, NULL
);
3585 ShowWindow( parent
, SW_SHOW
);
3586 UpdateWindow( parent
);
3587 GetClientRect( hwnd1
, &rc
);
3589 SetRectRgn( clipping
, 10, 10, 90, 90);
3590 hdc
= GetDC( hwnd1
);
3591 /* for a visual touch */
3592 TextOut( hdc
, 0,10, "0123456789", 10);
3593 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3594 if (winetest_debug
> 0) dump_region(hrgn
);
3595 /* create a region with what is expected */
3596 SetRectRgn( exprgn
, 39,0,49,74);
3597 SetRectRgn( tmprgn
, 88,79,98,93);
3598 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3599 SetRectRgn( tmprgn
, 0,93,98,98);
3600 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3601 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3602 trace("update rect is %d,%d - %d,%d\n",
3603 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3604 /* now with clipping region */
3605 SelectClipRgn( hdc
, clipping
);
3606 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3607 if (winetest_debug
> 0) dump_region(hrgn
);
3608 /* create a region with what is expected */
3609 SetRectRgn( exprgn
, 39,10,49,74);
3610 SetRectRgn( tmprgn
, 80,79,90,85);
3611 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3612 SetRectRgn( tmprgn
, 10,85,90,90);
3613 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3614 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3615 trace("update rect is %d,%d - %d,%d\n",
3616 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3617 ReleaseDC( hwnd1
, hdc
);
3619 /* test scrolling a window with an update region */
3620 DestroyWindow( hwnd2
);
3621 ValidateRect( hwnd1
, NULL
);
3622 SetRect( &rc
, 40,40, 50,50);
3623 InvalidateRect( hwnd1
, &rc
, 1);
3624 GetClientRect( hwnd1
, &rc
);
3626 ScrollWindowEx( hwnd1
, -10, 0, &rc
, &cliprc
, hrgn
, &rcu
,
3627 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3628 if (winetest_debug
> 0) dump_region(hrgn
);
3629 SetRectRgn( exprgn
, 88,0,98,98);
3630 SetRectRgn( tmprgn
, 30, 40, 50, 50);
3631 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3632 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3634 /* clear an update region */
3635 UpdateWindow( hwnd1
);
3637 SetRect( &rc
, 0,40, 100,60);
3638 SetRect( &cliprc
, 0,0, 100,100);
3639 ScrollWindowEx( hwnd1
, 0, -25, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3640 if (winetest_debug
> 0) dump_region( hrgn
);
3641 SetRectRgn( exprgn
, 0, 40, 98, 60 );
3642 ok( EqualRgn( exprgn
, hrgn
), "wrong update region in excessive scroll\n");
3644 /* now test ScrollWindowEx with a combination of
3645 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3646 /* make hwnd2 the child of hwnd1 */
3647 hwnd2
= CreateWindowExA(0, "static", NULL
,
3648 WS_CHILD
| WS_VISIBLE
| WS_BORDER
,
3649 50, 50, 100, 100, hwnd1
, 0, 0, NULL
);
3650 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPSIBLINGS
);
3651 GetClientRect( hwnd1
, &rc
);
3654 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3655 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3656 ValidateRect( hwnd1
, NULL
);
3657 ValidateRect( hwnd2
, NULL
);
3658 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
,
3659 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3660 if (winetest_debug
> 0) dump_region(hrgn
);
3661 SetRectRgn( exprgn
, 88,0,98,88);
3662 SetRectRgn( tmprgn
, 0,88,98,98);
3663 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3664 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3666 /* 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
, SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3671 if (winetest_debug
> 0) dump_region(hrgn
);
3672 /* expected region is the same as in previous test */
3673 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3675 /* no SW_SCROLLCHILDREN */
3676 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3677 ValidateRect( hwnd1
, NULL
);
3678 ValidateRect( hwnd2
, NULL
);
3679 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3680 if (winetest_debug
> 0) dump_region(hrgn
);
3681 /* expected region is the same as in previous test */
3682 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3684 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3685 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3686 ValidateRect( hwnd1
, NULL
);
3687 ValidateRect( hwnd2
, NULL
);
3688 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3689 if (winetest_debug
> 0) dump_region(hrgn
);
3690 SetRectRgn( exprgn
, 88,0,98,20);
3691 SetRectRgn( tmprgn
, 20,20,98,30);
3692 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3693 SetRectRgn( tmprgn
, 20,30,30,88);
3694 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3695 SetRectRgn( tmprgn
, 0,88,30,98);
3696 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3697 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3700 DeleteObject( hrgn
);
3701 DeleteObject( exprgn
);
3702 DeleteObject( tmprgn
);
3703 DestroyWindow( hwnd1
);
3704 DestroyWindow( hwnd2
);
3707 /* couple of tests of return values of scrollbar functions
3708 * called on a scrollbarless window */
3709 static void test_scroll(void)
3714 HWND hwnd
= CreateWindowExA(0, "Static", "Wine test window",
3715 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_POPUP
,
3716 100, 100, 200, 200, 0, 0, 0, NULL
);
3718 ret
= GetScrollRange( hwnd
, SB_HORZ
, &min
, &max
);
3719 if (!ret
) /* win9x */
3721 win_skip( "GetScrollRange doesn't work\n" );
3722 DestroyWindow( hwnd
);
3725 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3726 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3727 si
.cbSize
= sizeof( si
);
3728 si
.fMask
= SIF_PAGE
;
3729 si
.nPage
= 0xdeadbeef;
3730 ret
= GetScrollInfo( hwnd
, SB_HORZ
, &si
);
3731 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3732 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3734 ret
= GetScrollRange( hwnd
, SB_VERT
, &min
, &max
);
3735 ok( ret
, "GetScrollRange returns FALSE\n");
3736 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3737 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3738 si
.cbSize
= sizeof( si
);
3739 si
.fMask
= SIF_PAGE
;
3740 si
.nPage
= 0xdeadbeef;
3741 ret
= GetScrollInfo( hwnd
, SB_VERT
, &si
);
3742 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3743 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3745 DestroyWindow( hwnd
);
3748 static void test_scrolldc( HWND parent
)
3751 HRGN exprgn
, tmprgn
, hrgn
;
3752 RECT rc
, rc2
, rcu
, cliprc
;
3756 hrgn
= CreateRectRgn(0,0,0,0);
3757 tmprgn
= CreateRectRgn(0,0,0,0);
3758 exprgn
= CreateRectRgn(0,0,0,0);
3760 hwnd1
= CreateWindowExA(0, "static", NULL
,
3761 WS_CHILD
| WS_VISIBLE
,
3762 25, 50, 100, 100, parent
, 0, 0, NULL
);
3763 ShowWindow( parent
, SW_SHOW
);
3764 UpdateWindow( parent
);
3765 flush_events( TRUE
);
3766 GetClientRect( hwnd1
, &rc
);
3767 hdc
= GetDC( hwnd1
);
3768 /* paint the upper half of the window black */
3770 rc2
.bottom
= ( rc
.top
+ rc
.bottom
) /2;
3771 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3772 /* clip region is the lower half */
3774 cliprc
.top
= (rc
.top
+ rc
.bottom
) /2;
3775 /* test whether scrolled pixels are properly clipped */
3776 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3777 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3778 /* this scroll should not cause any visible changes */
3779 ScrollDC( hdc
, 5, -20, &rc
, &cliprc
, hrgn
, &rcu
);
3780 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3781 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3782 /* test with NULL clip rect */
3783 ScrollDC( hdc
, 20, -20, &rc
, NULL
, hrgn
, &rcu
);
3784 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3785 trace("update rect: %d,%d - %d,%d\n",
3786 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3787 if (winetest_debug
> 0) dump_region(hrgn
);
3788 SetRect(&rc2
, 0, 0, 100, 100);
3789 ok(EqualRect(&rcu
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3790 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
3792 SetRectRgn( exprgn
, 0, 0, 20, 80);
3793 SetRectRgn( tmprgn
, 0, 80, 100, 100);
3794 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3795 if (winetest_debug
> 0) dump_region(exprgn
);
3796 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3797 /* test clip rect > scroll rect */
3798 FillRect( hdc
, &rc
, GetStockObject(WHITE_BRUSH
));
3800 InflateRect( &rc2
, -(rc
.right
-rc
.left
)/4, -(rc
.bottom
-rc
.top
)/4);
3801 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3802 ScrollDC( hdc
, 10, 10, &rc2
, &rc
, hrgn
, &rcu
);
3803 SetRectRgn( exprgn
, 25, 25, 75, 35);
3804 SetRectRgn( tmprgn
, 25, 35, 35, 75);
3805 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3806 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3807 trace("update rect: %d,%d - %d,%d\n",
3808 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3809 if (winetest_debug
> 0) dump_region(hrgn
);
3813 DeleteObject(exprgn
);
3814 DeleteObject(tmprgn
);
3815 DestroyWindow(hwnd1
);
3818 static void test_params(void)
3823 /* Just a param check */
3824 if (pGetMonitorInfoA
)
3826 SetLastError(0xdeadbeef);
3827 rc
= GetWindowText(hwndMain2
, NULL
, 1024);
3828 ok( rc
==0, "GetWindowText: rc=%d err=%d\n",rc
,GetLastError());
3832 /* Skips actually on Win95 and NT4 */
3833 win_skip("Test would crash on Win95\n");
3836 SetLastError(0xdeadbeef);
3837 hwnd
=CreateWindow("LISTBOX", "TestList",
3838 (LBS_STANDARD
& ~LBS_SORT
),
3840 NULL
, (HMENU
)1, NULL
, 0);
3842 ok(!hwnd
|| broken(hwnd
!= NULL
), /* w2k3 sp2 */
3843 "CreateWindow with invalid menu handle should fail\n");
3845 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
|| /* NT */
3846 GetLastError() == 0xdeadbeef, /* Win9x */
3847 "wrong last error value %d\n", GetLastError());
3850 static void test_AWRwindow(LPCSTR
class, LONG style
, LONG exStyle
, BOOL menu
)
3854 hwnd
= CreateWindowEx(exStyle
, class, class, style
,
3861 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style
, exStyle
);
3864 ShowWindow(hwnd
, SW_SHOW
);
3866 test_nonclient_area(hwnd
);
3869 DestroyWindow(hwnd
);
3872 static BOOL
AWR_init(void)
3876 class.style
= CS_HREDRAW
| CS_VREDRAW
;
3877 class.lpfnWndProc
= DefWindowProcA
;
3878 class.cbClsExtra
= 0;
3879 class.cbWndExtra
= 0;
3880 class.hInstance
= 0;
3881 class.hIcon
= LoadIcon (0, IDI_APPLICATION
);
3882 class.hCursor
= LoadCursor (0, IDC_ARROW
);
3883 class.hbrBackground
= 0;
3884 class.lpszMenuName
= 0;
3885 class.lpszClassName
= szAWRClass
;
3887 if (!RegisterClass (&class)) {
3888 ok(FALSE
, "RegisterClass failed\n");
3892 hmenu
= CreateMenu();
3895 ok(hmenu
!= 0, "Failed to create menu\n");
3896 ok(AppendMenu(hmenu
, MF_STRING
, 1, "Test!"), "Failed to create menu item\n");
3902 static void test_AWR_window_size(BOOL menu
)
3906 WS_MAXIMIZE
, WS_BORDER
, WS_DLGFRAME
,
3909 WS_MINIMIZEBOX
, WS_MAXIMIZEBOX
,
3910 WS_HSCROLL
, WS_VSCROLL
3914 WS_EX_TOOLWINDOW
, WS_EX_WINDOWEDGE
,
3917 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3918 WS_EX_DLGMODALFRAME
,
3925 /* A exhaustive check of all the styles takes too long
3926 * so just do a (hopefully representative) sample
3928 for (i
= 0; i
< COUNTOF(styles
); ++i
)
3929 test_AWRwindow(szAWRClass
, styles
[i
], 0, menu
);
3930 for (i
= 0; i
< COUNTOF(exStyles
); ++i
) {
3931 test_AWRwindow(szAWRClass
, WS_POPUP
, exStyles
[i
], menu
);
3932 test_AWRwindow(szAWRClass
, WS_THICKFRAME
, exStyles
[i
], menu
);
3937 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3939 static void test_AdjustWindowRect(void)
3944 SHOWSYSMETRIC(SM_CYCAPTION
);
3945 SHOWSYSMETRIC(SM_CYSMCAPTION
);
3946 SHOWSYSMETRIC(SM_CYMENU
);
3947 SHOWSYSMETRIC(SM_CXEDGE
);
3948 SHOWSYSMETRIC(SM_CYEDGE
);
3949 SHOWSYSMETRIC(SM_CXVSCROLL
);
3950 SHOWSYSMETRIC(SM_CYHSCROLL
);
3951 SHOWSYSMETRIC(SM_CXFRAME
);
3952 SHOWSYSMETRIC(SM_CYFRAME
);
3953 SHOWSYSMETRIC(SM_CXDLGFRAME
);
3954 SHOWSYSMETRIC(SM_CYDLGFRAME
);
3955 SHOWSYSMETRIC(SM_CXBORDER
);
3956 SHOWSYSMETRIC(SM_CYBORDER
);
3958 test_AWR_window_size(FALSE
);
3959 test_AWR_window_size(TRUE
);
3963 #undef SHOWSYSMETRIC
3966 /* Global variables to trigger exit from loop */
3967 static int redrawComplete
, WMPAINT_count
;
3969 static LRESULT WINAPI
redraw_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3974 trace("doing WM_PAINT %d\n", WMPAINT_count
);
3976 if (WMPAINT_count
> 10 && redrawComplete
== 0) {
3978 BeginPaint(hwnd
, &ps
);
3979 EndPaint(hwnd
, &ps
);
3984 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3987 /* Ensure we exit from RedrawNow regardless of invalidated area */
3988 static void test_redrawnow(void)
3993 cls
.style
= CS_DBLCLKS
;
3994 cls
.lpfnWndProc
= redraw_window_procA
;
3997 cls
.hInstance
= GetModuleHandleA(0);
3999 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
4000 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4001 cls
.lpszMenuName
= NULL
;
4002 cls
.lpszClassName
= "RedrawWindowClass";
4004 if(!RegisterClassA(&cls
)) {
4005 trace("Register failed %d\n", GetLastError());
4009 hwndMain
= CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
4010 CW_USEDEFAULT
, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4012 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
4013 ShowWindow(hwndMain
, SW_SHOW
);
4014 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
4015 RedrawWindow(hwndMain
, NULL
,NULL
,RDW_UPDATENOW
| RDW_ALLCHILDREN
);
4016 ok( WMPAINT_count
== 1 || broken(WMPAINT_count
== 0), /* sometimes on win9x */
4017 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
4018 redrawComplete
= TRUE
;
4019 ok( WMPAINT_count
< 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count
);
4022 DestroyWindow( hwndMain
);
4025 struct parentdc_stat
{
4031 struct parentdc_test
{
4032 struct parentdc_stat main
, main_todo
;
4033 struct parentdc_stat child1
, child1_todo
;
4034 struct parentdc_stat child2
, child2_todo
;
4037 static LRESULT WINAPI
parentdc_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4042 struct parentdc_stat
*t
= (struct parentdc_stat
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
4047 GetClientRect(hwnd
, &rc
);
4048 CopyRect(&t
->client
, &rc
);
4049 GetWindowRect(hwnd
, &rc
);
4050 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd
,
4051 t
->client
.left
, t
->client
.top
, t
->client
.right
, t
->client
.bottom
,
4052 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4053 BeginPaint(hwnd
, &ps
);
4054 CopyRect(&t
->paint
, &ps
.rcPaint
);
4055 GetClipBox(ps
.hdc
, &rc
);
4056 CopyRect(&t
->clip
, &rc
);
4057 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
4058 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
4059 ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
4060 EndPaint(hwnd
, &ps
);
4063 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
4066 static void zero_parentdc_stat(struct parentdc_stat
*t
)
4068 SetRectEmpty(&t
->client
);
4069 SetRectEmpty(&t
->clip
);
4070 SetRectEmpty(&t
->paint
);
4073 static void zero_parentdc_test(struct parentdc_test
*t
)
4075 zero_parentdc_stat(&t
->main
);
4076 zero_parentdc_stat(&t
->child1
);
4077 zero_parentdc_stat(&t
->child2
);
4080 #define parentdc_field_ok(t, w, r, f, got) \
4081 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
4082 ": expected %d, got %d\n", \
4085 #define parentdc_todo_field_ok(t, w, r, f, got) \
4086 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
4087 else parentdc_field_ok(t, w, r, f, got)
4089 #define parentdc_rect_ok(t, w, r, got) \
4090 parentdc_todo_field_ok(t, w, r, left, got); \
4091 parentdc_todo_field_ok(t, w, r, top, got); \
4092 parentdc_todo_field_ok(t, w, r, right, got); \
4093 parentdc_todo_field_ok(t, w, r, bottom, got);
4095 #define parentdc_win_ok(t, w, got) \
4096 parentdc_rect_ok(t, w, client, got); \
4097 parentdc_rect_ok(t, w, clip, got); \
4098 parentdc_rect_ok(t, w, paint, got);
4100 #define parentdc_ok(t, got) \
4101 parentdc_win_ok(t, main, got); \
4102 parentdc_win_ok(t, child1, got); \
4103 parentdc_win_ok(t, child2, got);
4105 static void test_csparentdc(void)
4107 WNDCLASSA clsMain
, cls
;
4108 HWND hwndMain
, hwnd1
, hwnd2
;
4111 struct parentdc_test test_answer
;
4113 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
4114 const struct parentdc_test test1
=
4116 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo
,
4117 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4118 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4121 const struct parentdc_test test2
=
4123 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo
,
4124 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4125 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4128 const struct parentdc_test test3
=
4130 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
4131 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
4132 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
4135 const struct parentdc_test test4
=
4137 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo
,
4138 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo
,
4139 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
4142 const struct parentdc_test test5
=
4144 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo
,
4145 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4146 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4149 const struct parentdc_test test6
=
4151 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
4152 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
4153 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
4156 const struct parentdc_test test7
=
4158 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
4159 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4160 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
4164 clsMain
.style
= CS_DBLCLKS
;
4165 clsMain
.lpfnWndProc
= parentdc_window_procA
;
4166 clsMain
.cbClsExtra
= 0;
4167 clsMain
.cbWndExtra
= 0;
4168 clsMain
.hInstance
= GetModuleHandleA(0);
4170 clsMain
.hCursor
= LoadCursorA(0, IDC_ARROW
);
4171 clsMain
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4172 clsMain
.lpszMenuName
= NULL
;
4173 clsMain
.lpszClassName
= "ParentDcMainWindowClass";
4175 if(!RegisterClassA(&clsMain
)) {
4176 trace("Register failed %d\n", GetLastError());
4180 cls
.style
= CS_DBLCLKS
| CS_PARENTDC
;
4181 cls
.lpfnWndProc
= parentdc_window_procA
;
4184 cls
.hInstance
= GetModuleHandleA(0);
4186 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
4187 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4188 cls
.lpszMenuName
= NULL
;
4189 cls
.lpszClassName
= "ParentDcWindowClass";
4191 if(!RegisterClassA(&cls
)) {
4192 trace("Register failed %d\n", GetLastError());
4196 SetRect(&rc
, 0, 0, 150, 150);
4197 AdjustWindowRectEx(&rc
, WS_OVERLAPPEDWINDOW
, FALSE
, 0);
4198 hwndMain
= CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
4199 CW_USEDEFAULT
, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, NULL
, NULL
, 0, NULL
);
4200 SetWindowLongPtrA(hwndMain
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.main
);
4201 hwnd1
= CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD
,
4202 20, 20, 40, 40, hwndMain
, NULL
, 0, NULL
);
4203 SetWindowLongPtrA(hwnd1
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child1
);
4204 hwnd2
= CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD
,
4205 40, 40, 40, 40, hwndMain
, NULL
, 0, NULL
);
4206 SetWindowLongPtrA(hwnd2
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child2
);
4207 ShowWindow(hwndMain
, SW_SHOW
);
4208 ShowWindow(hwnd1
, SW_SHOW
);
4209 ShowWindow(hwnd2
, SW_SHOW
);
4210 SetWindowPos(hwndMain
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
4211 flush_events( TRUE
);
4213 zero_parentdc_test(&test_answer
);
4214 InvalidateRect(hwndMain
, NULL
, TRUE
);
4215 flush_events( TRUE
);
4216 parentdc_ok(test1
, test_answer
);
4218 zero_parentdc_test(&test_answer
);
4219 SetRect(&rc
, 0, 0, 50, 50);
4220 InvalidateRect(hwndMain
, &rc
, TRUE
);
4221 flush_events( TRUE
);
4222 parentdc_ok(test2
, test_answer
);
4224 zero_parentdc_test(&test_answer
);
4225 SetRect(&rc
, 0, 0, 10, 10);
4226 InvalidateRect(hwndMain
, &rc
, TRUE
);
4227 flush_events( TRUE
);
4228 parentdc_ok(test3
, test_answer
);
4230 zero_parentdc_test(&test_answer
);
4231 SetRect(&rc
, 40, 40, 50, 50);
4232 InvalidateRect(hwndMain
, &rc
, TRUE
);
4233 flush_events( TRUE
);
4234 parentdc_ok(test4
, test_answer
);
4236 zero_parentdc_test(&test_answer
);
4237 SetRect(&rc
, 20, 20, 60, 60);
4238 InvalidateRect(hwndMain
, &rc
, TRUE
);
4239 flush_events( TRUE
);
4240 parentdc_ok(test5
, test_answer
);
4242 zero_parentdc_test(&test_answer
);
4243 SetRect(&rc
, 0, 0, 10, 10);
4244 InvalidateRect(hwnd1
, &rc
, TRUE
);
4245 flush_events( TRUE
);
4246 parentdc_ok(test6
, test_answer
);
4248 zero_parentdc_test(&test_answer
);
4249 SetRect(&rc
, -5, -5, 65, 65);
4250 InvalidateRect(hwnd1
, &rc
, TRUE
);
4251 flush_events( TRUE
);
4252 parentdc_ok(test7
, test_answer
);
4254 DestroyWindow(hwndMain
);
4255 DestroyWindow(hwnd1
);
4256 DestroyWindow(hwnd2
);
4259 static LRESULT WINAPI
def_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4261 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
4264 static LRESULT WINAPI
def_window_procW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4266 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
4269 static void test_IsWindowUnicode(void)
4271 static const char ansi_class_nameA
[] = "ansi class name";
4272 static const WCHAR ansi_class_nameW
[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
4273 static const char unicode_class_nameA
[] = "unicode class name";
4274 static const WCHAR unicode_class_nameW
[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
4279 memset(&classW
, 0, sizeof(classW
));
4280 classW
.hInstance
= GetModuleHandleA(0);
4281 classW
.lpfnWndProc
= def_window_procW
;
4282 classW
.lpszClassName
= unicode_class_nameW
;
4283 if (!RegisterClassW(&classW
)) return; /* this catches Win9x as well */
4285 memset(&classA
, 0, sizeof(classA
));
4286 classA
.hInstance
= GetModuleHandleA(0);
4287 classA
.lpfnWndProc
= def_window_procA
;
4288 classA
.lpszClassName
= ansi_class_nameA
;
4289 assert(RegisterClassA(&classA
));
4291 /* unicode class: window proc */
4292 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
4293 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4296 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4297 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
4298 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4299 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
4300 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4302 DestroyWindow(hwnd
);
4304 hwnd
= CreateWindowExA(0, unicode_class_nameA
, 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 /* ansi class: window proc */
4317 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
4318 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4321 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4322 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
4323 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4324 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
4325 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4327 DestroyWindow(hwnd
);
4329 hwnd
= CreateWindowExA(0, ansi_class_nameA
, 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 /* unicode class: class proc */
4342 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
4343 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4346 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4347 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
4348 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4349 /* do not restore class window proc back to unicode */
4351 DestroyWindow(hwnd
);
4353 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
4354 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4357 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4358 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
4359 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4361 DestroyWindow(hwnd
);
4363 /* ansi class: class proc */
4364 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
4365 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4368 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4369 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
4370 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4371 /* do not restore class window proc back to ansi */
4373 DestroyWindow(hwnd
);
4375 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
4376 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4379 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4380 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
4381 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4383 DestroyWindow(hwnd
);
4386 static LRESULT CALLBACK
minmax_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
4390 if (msg
!= WM_GETMINMAXINFO
)
4391 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4393 minmax
= (MINMAXINFO
*)lp
;
4395 if ((GetWindowLong(hwnd
, GWL_STYLE
) & WS_CHILD
))
4397 minmax
->ptReserved
.x
= 0;
4398 minmax
->ptReserved
.y
= 0;
4399 minmax
->ptMaxSize
.x
= 400;
4400 minmax
->ptMaxSize
.y
= 400;
4401 minmax
->ptMaxPosition
.x
= 300;
4402 minmax
->ptMaxPosition
.y
= 300;
4403 minmax
->ptMaxTrackSize
.x
= 200;
4404 minmax
->ptMaxTrackSize
.y
= 200;
4405 minmax
->ptMinTrackSize
.x
= 100;
4406 minmax
->ptMinTrackSize
.y
= 100;
4409 DefWindowProc(hwnd
, msg
, wp
, lp
);
4413 static int expected_cx
, expected_cy
;
4414 static RECT expected_rect
, broken_rect
;
4416 static LRESULT CALLBACK
winsizes_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
4420 case WM_GETMINMAXINFO
:
4423 GetWindowRect( hwnd
, &rect
);
4424 ok( !rect
.left
&& !rect
.top
&& !rect
.right
&& !rect
.bottom
,
4425 "wrong rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4426 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4431 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
4433 GetWindowRect( hwnd
, &rect
);
4434 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
4435 hwnd
, msg
, cs
->cx
, cs
->cy
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4436 ok( cs
->cx
== expected_cx
|| broken(cs
->cx
== (short)expected_cx
),
4437 "wrong x size %d/%d\n", cs
->cx
, expected_cx
);
4438 ok( cs
->cy
== expected_cy
|| broken(cs
->cy
== (short)expected_cy
),
4439 "wrong y size %d/%d\n", cs
->cy
, expected_cy
);
4440 ok( (rect
.right
- rect
.left
== expected_rect
.right
- expected_rect
.left
&&
4441 rect
.bottom
- rect
.top
== expected_rect
.bottom
- expected_rect
.top
) ||
4442 broken( rect
.right
- rect
.left
== broken_rect
.right
- broken_rect
.left
&&
4443 rect
.bottom
- rect
.top
== broken_rect
.bottom
- broken_rect
.top
) ||
4444 broken( rect
.right
- rect
.left
== (short)broken_rect
.right
- (short)broken_rect
.left
&&
4445 rect
.bottom
- rect
.top
== (short)broken_rect
.bottom
- (short)broken_rect
.top
),
4446 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
4447 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
4448 expected_rect
.left
, expected_rect
.top
, expected_rect
.right
, expected_rect
.bottom
);
4449 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4453 RECT rect
, *r
= (RECT
*)lp
;
4454 GetWindowRect( hwnd
, &rect
);
4455 ok( !memcmp( &rect
, r
, sizeof(rect
) ),
4456 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
4457 r
->left
, r
->top
, r
->right
, r
->bottom
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4458 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4461 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4465 static void test_CreateWindow(void)
4473 #define expect_menu(window, menu) \
4474 SetLastError(0xdeadbeef); \
4475 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
4477 #define expect_style(window, style)\
4478 ok((ULONG)GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
4480 #define expect_ex_style(window, ex_style)\
4481 ok((ULONG)GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
4483 #define expect_gle_broken_9x(gle)\
4484 ok(GetLastError() == gle ||\
4485 broken(GetLastError() == 0xdeadbeef),\
4486 "IsMenu set error %d\n", GetLastError())
4488 hmenu
= CreateMenu();
4490 parent
= GetDesktopWindow();
4491 assert(parent
!= 0);
4493 SetLastError(0xdeadbeef);
4494 ok(IsMenu(hmenu
), "IsMenu error %d\n", GetLastError());
4497 SetLastError(0xdeadbeef);
4498 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
,
4499 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4500 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4501 expect_menu(hwnd
, 1);
4502 expect_style(hwnd
, WS_CHILD
);
4503 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4504 DestroyWindow(hwnd
);
4506 SetLastError(0xdeadbeef);
4507 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_CAPTION
,
4508 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4509 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4510 expect_menu(hwnd
, 1);
4511 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
4512 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4513 DestroyWindow(hwnd
);
4515 SetLastError(0xdeadbeef);
4516 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
,
4517 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4518 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4519 expect_menu(hwnd
, 1);
4520 expect_style(hwnd
, WS_CHILD
);
4521 expect_ex_style(hwnd
, 0);
4522 DestroyWindow(hwnd
);
4524 SetLastError(0xdeadbeef);
4525 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_CAPTION
,
4526 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4527 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4528 expect_menu(hwnd
, 1);
4529 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
4530 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4531 DestroyWindow(hwnd
);
4534 SetLastError(0xdeadbeef);
4535 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
4536 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4537 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4538 expect_menu(hwnd
, hmenu
);
4539 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4540 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4541 DestroyWindow(hwnd
);
4542 SetLastError(0xdeadbeef);
4543 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4544 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4546 hmenu
= CreateMenu();
4548 SetLastError(0xdeadbeef);
4549 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4550 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4551 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4552 expect_menu(hwnd
, hmenu
);
4553 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4554 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4555 DestroyWindow(hwnd
);
4556 SetLastError(0xdeadbeef);
4557 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4558 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4560 hmenu
= CreateMenu();
4562 SetLastError(0xdeadbeef);
4563 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
,
4564 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4565 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4566 expect_menu(hwnd
, hmenu
);
4567 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4568 expect_ex_style(hwnd
, 0);
4569 DestroyWindow(hwnd
);
4570 SetLastError(0xdeadbeef);
4571 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4572 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4574 hmenu
= CreateMenu();
4576 SetLastError(0xdeadbeef);
4577 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4578 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4579 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4580 expect_menu(hwnd
, hmenu
);
4581 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4582 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4583 DestroyWindow(hwnd
);
4584 SetLastError(0xdeadbeef);
4585 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4586 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4588 /* WS_CHILD | WS_POPUP */
4589 SetLastError(0xdeadbeef);
4590 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4591 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4592 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
4593 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4595 DestroyWindow(hwnd
);
4597 hmenu
= CreateMenu();
4599 SetLastError(0xdeadbeef);
4600 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4601 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4602 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4603 expect_menu(hwnd
, hmenu
);
4604 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4605 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4606 DestroyWindow(hwnd
);
4607 SetLastError(0xdeadbeef);
4608 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4609 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4611 SetLastError(0xdeadbeef);
4612 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4613 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4614 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
4615 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4617 DestroyWindow(hwnd
);
4619 hmenu
= CreateMenu();
4621 SetLastError(0xdeadbeef);
4622 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4623 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4624 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4625 expect_menu(hwnd
, hmenu
);
4626 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4627 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4628 DestroyWindow(hwnd
);
4629 SetLastError(0xdeadbeef);
4630 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4631 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4633 SetLastError(0xdeadbeef);
4634 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4635 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4636 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
4637 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4639 DestroyWindow(hwnd
);
4641 hmenu
= CreateMenu();
4643 SetLastError(0xdeadbeef);
4644 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4645 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4646 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4647 expect_menu(hwnd
, hmenu
);
4648 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4649 expect_ex_style(hwnd
, 0);
4650 DestroyWindow(hwnd
);
4651 SetLastError(0xdeadbeef);
4652 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4653 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4655 SetLastError(0xdeadbeef);
4656 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4657 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4658 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
4659 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4661 DestroyWindow(hwnd
);
4663 hmenu
= CreateMenu();
4665 SetLastError(0xdeadbeef);
4666 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4667 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4668 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4669 expect_menu(hwnd
, hmenu
);
4670 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4671 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4672 DestroyWindow(hwnd
);
4673 SetLastError(0xdeadbeef);
4674 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4675 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4677 /* test child window sizing */
4679 cls
.lpfnWndProc
= minmax_wnd_proc
;
4682 cls
.hInstance
= GetModuleHandle(0);
4684 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
4685 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4686 cls
.lpszMenuName
= NULL
;
4687 cls
.lpszClassName
= "MinMax_WndClass";
4688 RegisterClass(&cls
);
4690 SetLastError(0xdeadbeef);
4691 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4692 0, 0, 100, 100, 0, 0, 0, NULL
);
4693 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
4694 expect_menu(parent
, 0);
4695 expect_style(parent
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
| WS_CLIPSIBLINGS
);
4696 expect_ex_style(parent
, WS_EX_WINDOWEDGE
);
4698 memset(&minmax
, 0, sizeof(minmax
));
4699 SendMessage(parent
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4700 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxSize
.x
, minmax
.ptMaxSize
.y
);
4701 ok(IsRectEmpty(&rc_minmax
), "ptMaxSize is not empty\n");
4702 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4703 ok(IsRectEmpty(&rc_minmax
), "ptMaxTrackSize is not empty\n");
4705 GetWindowRect(parent
, &rc
);
4706 ok(!IsRectEmpty(&rc
), "parent window rect is empty\n");
4707 GetClientRect(parent
, &rc
);
4708 ok(!IsRectEmpty(&rc
), "parent client rect is empty\n");
4710 InflateRect(&rc
, 200, 200);
4711 trace("creating child with rect (%d,%d-%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4713 SetLastError(0xdeadbeef);
4714 hwnd
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4715 rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
4716 parent
, (HMENU
)1, 0, NULL
);
4717 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4718 expect_menu(hwnd
, 1);
4719 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
);
4720 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4722 memset(&minmax
, 0, sizeof(minmax
));
4723 SendMessage(hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4724 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4726 GetWindowRect(hwnd
, &rc
);
4727 OffsetRect(&rc
, -rc
.left
, -rc
.top
);
4728 ok(EqualRect(&rc
, &rc_minmax
), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4729 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
4730 rc_minmax
.left
, rc_minmax
.top
, rc_minmax
.right
, rc_minmax
.bottom
);
4731 DestroyWindow(hwnd
);
4733 cls
.lpfnWndProc
= winsizes_wnd_proc
;
4734 cls
.lpszClassName
= "Sizes_WndClass";
4735 RegisterClass(&cls
);
4737 expected_cx
= expected_cy
= 200000;
4738 SetRect( &expected_rect
, 0, 0, 200000, 200000 );
4739 broken_rect
= expected_rect
;
4740 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 300000, 300000, 200000, 200000, parent
, 0, 0, NULL
);
4741 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4742 GetClientRect( hwnd
, &rc
);
4743 ok( rc
.right
== 200000 || broken(rc
.right
== (short)200000), "invalid rect right %u\n", rc
.right
);
4744 ok( rc
.bottom
== 200000 || broken(rc
.bottom
== (short)200000), "invalid rect bottom %u\n", rc
.bottom
);
4745 DestroyWindow(hwnd
);
4747 expected_cx
= expected_cy
= -10;
4748 SetRect( &expected_rect
, 0, 0, 0, 0 );
4749 SetRect( &broken_rect
, 0, 0, -10, -10 );
4750 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -20, -20, -10, -10, parent
, 0, 0, NULL
);
4751 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4752 GetClientRect( hwnd
, &rc
);
4753 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4754 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4755 DestroyWindow(hwnd
);
4757 expected_cx
= expected_cy
= -200000;
4758 SetRect( &expected_rect
, 0, 0, 0, 0 );
4759 SetRect( &broken_rect
, 0, 0, -200000, -200000 );
4760 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -300000, -300000, -200000, -200000, parent
, 0, 0, NULL
);
4761 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4762 GetClientRect( hwnd
, &rc
);
4763 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4764 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4765 DestroyWindow(hwnd
);
4767 /* we need a parent at 0,0 so that child coordinates match */
4768 DestroyWindow(parent
);
4769 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_POPUP
, 0, 0, 100, 100, 0, 0, 0, NULL
);
4770 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
4773 expected_cy
= 0x7fffffff;
4774 SetRect( &expected_rect
, 10, 10, 110, 0x7fffffff );
4775 SetRect( &broken_rect
, 10, 10, 110, 0x7fffffffU
+ 10 );
4776 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 10, 10, 100, 0x7fffffff, parent
, 0, 0, NULL
);
4777 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4778 GetClientRect( hwnd
, &rc
);
4779 ok( rc
.right
== 100, "invalid rect right %u\n", rc
.right
);
4780 ok( rc
.bottom
== 0x7fffffff - 10 || broken(rc
.bottom
== 0), "invalid rect bottom %u\n", rc
.bottom
);
4781 DestroyWindow(hwnd
);
4783 expected_cx
= 0x7fffffff;
4784 expected_cy
= 0x7fffffff;
4785 SetRect( &expected_rect
, 20, 10, 0x7fffffff, 0x7fffffff );
4786 SetRect( &broken_rect
, 20, 10, 0x7fffffffU
+ 20, 0x7fffffffU
+ 10 );
4787 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 20, 10, 0x7fffffff, 0x7fffffff, parent
, 0, 0, NULL
);
4788 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4789 GetClientRect( hwnd
, &rc
);
4790 ok( rc
.right
== 0x7fffffff - 20 || broken(rc
.right
== 0), "invalid rect right %u\n", rc
.right
);
4791 ok( rc
.bottom
== 0x7fffffff - 10 || broken(rc
.bottom
== 0), "invalid rect bottom %u\n", rc
.bottom
);
4792 DestroyWindow(hwnd
);
4794 /* top level window */
4795 expected_cx
= expected_cy
= 200000;
4796 SetRect( &expected_rect
, 0, 0, GetSystemMetrics(SM_CXMAXTRACK
), GetSystemMetrics(SM_CYMAXTRACK
) );
4797 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_OVERLAPPEDWINDOW
, 300000, 300000, 200000, 200000, 0, 0, 0, NULL
);
4798 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4799 GetClientRect( hwnd
, &rc
);
4800 ok( rc
.right
<= expected_cx
, "invalid rect right %u\n", rc
.right
);
4801 ok( rc
.bottom
<= expected_cy
, "invalid rect bottom %u\n", rc
.bottom
);
4802 DestroyWindow(hwnd
);
4804 DestroyWindow(parent
);
4806 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4807 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4809 #undef expect_gle_broken_9x
4812 #undef expect_ex_style
4815 /* function that remembers whether the system the test is running on sets the
4816 * last error for user32 functions to make the tests stricter */
4817 static int check_error(DWORD actual
, DWORD expected
)
4819 static int sets_last_error
= -1;
4820 if (sets_last_error
== -1)
4821 sets_last_error
= (actual
!= 0xdeadbeef);
4822 return (!sets_last_error
&& (actual
== 0xdeadbeef)) || (actual
== expected
);
4825 static void test_SetWindowLong(void)
4828 WNDPROC old_window_procW
;
4830 SetLastError(0xdeadbeef);
4831 retval
= SetWindowLongPtr(NULL
, GWLP_WNDPROC
, 0);
4832 ok(!retval
, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval
);
4833 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE
),
4834 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4836 SetLastError(0xdeadbeef);
4837 retval
= SetWindowLongPtr(hwndMain
, 0xdeadbeef, 0);
4838 ok(!retval
, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval
);
4839 ok(check_error(GetLastError(), ERROR_INVALID_INDEX
),
4840 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4842 SetLastError(0xdeadbeef);
4843 retval
= SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4844 ok((WNDPROC
)retval
== main_window_procA
|| broken(!retval
), /* win9x */
4845 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval
);
4846 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4847 retval
= GetWindowLongPtr(hwndMain
, GWLP_WNDPROC
);
4848 ok((WNDPROC
)retval
== main_window_procA
,
4849 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4850 ok(!IsWindowUnicode(hwndMain
), "hwndMain shouldn't be Unicode\n");
4852 old_window_procW
= (WNDPROC
)GetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
);
4853 SetLastError(0xdeadbeef);
4854 retval
= SetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
, 0);
4855 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED
)
4857 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4858 ok(retval
!= 0, "SetWindowLongPtr error %d\n", GetLastError());
4859 ok((WNDPROC
)retval
== old_window_procW
,
4860 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4861 ok(IsWindowUnicode(hwndMain
), "hwndMain should now be Unicode\n");
4863 /* set it back to ANSI */
4864 SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4868 static void test_ShowWindow(void)
4875 SetRect(&rcMain
, 120, 120, 210, 210);
4877 hwnd
= CreateWindowEx(0, "MainWindowClass", NULL
,
4878 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4879 WS_MAXIMIZEBOX
| WS_POPUP
,
4880 rcMain
.left
, rcMain
.top
,
4881 rcMain
.right
- rcMain
.left
, rcMain
.bottom
- rcMain
.top
,
4885 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4886 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4887 ok(!(style
& WS_VISIBLE
), "window should not be visible\n");
4888 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4889 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4890 GetWindowRect(hwnd
, &rc
);
4891 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4892 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4893 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4895 ret
= ShowWindow(hwnd
, SW_SHOW
);
4896 ok(!ret
, "not expected ret: %lu\n", ret
);
4897 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4898 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4899 ok(style
& WS_VISIBLE
, "window should 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_MINIMIZE
);
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 be minimized\n");
4913 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4914 GetWindowRect(hwnd
, &rc
);
4915 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4917 ShowWindow(hwnd
, SW_RESTORE
);
4918 ok(ret
, "not expected ret: %lu\n", ret
);
4919 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4920 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4921 ok(style
& WS_VISIBLE
, "window should be visible\n");
4922 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4923 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4924 GetWindowRect(hwnd
, &rc
);
4925 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4926 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4927 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4929 ret
= EnableWindow(hwnd
, FALSE
);
4930 ok(!ret
, "not expected ret: %lu\n", ret
);
4931 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4932 ok(style
& WS_DISABLED
, "window should be disabled\n");
4934 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
4935 ok(!ret
, "not expected ret: %lu\n", ret
);
4936 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4937 ok(style
& WS_DISABLED
, "window should be disabled\n");
4938 ok(style
& WS_VISIBLE
, "window should be visible\n");
4939 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4940 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4941 GetWindowRect(hwnd
, &rc
);
4942 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4943 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4944 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4946 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
4947 ok(!ret
, "not expected ret: %lu\n", ret
);
4948 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4949 ok(style
& WS_DISABLED
, "window should be disabled\n");
4950 ok(style
& WS_VISIBLE
, "window should be visible\n");
4951 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4952 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4953 GetWindowRect(hwnd
, &rc
);
4954 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4955 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4956 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4958 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4959 ok(ret
, "not expected ret: %lu\n", ret
);
4960 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4961 ok(style
& WS_DISABLED
, "window should be disabled\n");
4962 ok(style
& WS_VISIBLE
, "window should be visible\n");
4963 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4964 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4965 GetWindowRect(hwnd
, &rc
);
4966 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4968 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
4969 ok(!ret
, "not expected ret: %lu\n", ret
);
4970 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4971 ok(style
& WS_DISABLED
, "window should be disabled\n");
4972 ok(style
& WS_VISIBLE
, "window should be visible\n");
4973 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4974 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4975 GetWindowRect(hwnd
, &rc
);
4976 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4978 ret
= ShowWindow(hwnd
, SW_RESTORE
);
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 not be minimized\n");
4984 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4985 GetWindowRect(hwnd
, &rc
);
4986 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4987 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4988 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4990 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4991 ok(!ret
, "not expected ret: %lu\n", ret
);
4992 ok(IsWindow(hwnd
), "window should exist\n");
4994 ret
= EnableWindow(hwnd
, TRUE
);
4995 ok(ret
, "not expected ret: %lu\n", ret
);
4997 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4998 ok(!ret
, "not expected ret: %lu\n", ret
);
4999 ok(!IsWindow(hwnd
), "window should not exist\n");
5002 static void test_gettext(void)
5005 LPCSTR clsname
= "gettexttest";
5009 memset( &cls
, 0, sizeof cls
);
5010 cls
.lpfnWndProc
= DefWindowProc
;
5011 cls
.lpszClassName
= clsname
;
5012 cls
.hInstance
= GetModuleHandle(NULL
);
5014 if (!RegisterClass( &cls
)) return;
5016 hwnd
= CreateWindow( clsname
, "test text", WS_OVERLAPPED
, 0, 0, 10, 10, 0, NULL
, NULL
, NULL
);
5017 ok( hwnd
!= NULL
, "window was null\n");
5019 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10, 0x1000);
5020 ok( r
== 0, "settext should return zero\n");
5022 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10000, 0);
5023 ok( r
== 0, "settext should return zero (%ld)\n", r
);
5025 r
= SendMessage( hwnd
, WM_GETTEXT
, 0xff000000, 0x1000);
5026 ok( r
== 0, "settext should return zero (%ld)\n", r
);
5028 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x1000, 0xff000000);
5029 ok( r
== 0, "settext should return zero (%ld)\n", r
);
5031 DestroyWindow(hwnd
);
5032 UnregisterClass( clsname
, NULL
);
5036 static void test_GetUpdateRect(void)
5039 BOOL ret
, parent_wm_paint
, grandparent_wm_paint
;
5041 HWND hgrandparent
, hparent
, hchild
;
5043 static const char classNameA
[] = "GetUpdateRectClass";
5045 hgrandparent
= CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW
,
5046 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
5048 hparent
= CreateWindowA("static", "parent", WS_CHILD
|WS_VISIBLE
,
5049 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
5051 hchild
= CreateWindowA("static", "child", WS_CHILD
|WS_VISIBLE
,
5052 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
5054 ShowWindow(hgrandparent
, SW_SHOW
);
5055 UpdateWindow(hgrandparent
);
5056 flush_events( TRUE
);
5058 ShowWindow(hchild
, SW_HIDE
);
5059 SetRect(&rc2
, 0, 0, 0, 0);
5060 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
5061 ok(!ret
, "GetUpdateRect returned not empty region\n");
5062 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5063 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
5064 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
5066 SetRect(&rc2
, 10, 10, 40, 40);
5067 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
5068 ok(ret
, "GetUpdateRect returned empty region\n");
5069 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5070 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
5071 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
5073 parent_wm_paint
= FALSE
;
5074 grandparent_wm_paint
= FALSE
;
5075 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
5077 if (msg
.message
== WM_PAINT
)
5079 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
5080 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
5082 DispatchMessage(&msg
);
5084 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
5085 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
5087 DestroyWindow(hgrandparent
);
5090 cls
.lpfnWndProc
= DefWindowProcA
;
5093 cls
.hInstance
= GetModuleHandleA(0);
5095 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
5096 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5097 cls
.lpszMenuName
= NULL
;
5098 cls
.lpszClassName
= classNameA
;
5100 if(!RegisterClassA(&cls
)) {
5101 trace("Register failed %d\n", GetLastError());
5105 hgrandparent
= CreateWindowA(classNameA
, "grandparent", WS_OVERLAPPEDWINDOW
,
5106 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
5108 hparent
= CreateWindowA(classNameA
, "parent", WS_CHILD
|WS_VISIBLE
,
5109 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
5111 hchild
= CreateWindowA(classNameA
, "child", WS_CHILD
|WS_VISIBLE
,
5112 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
5114 ShowWindow(hgrandparent
, SW_SHOW
);
5115 UpdateWindow(hgrandparent
);
5116 flush_events( TRUE
);
5118 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
5119 ok(!ret
, "GetUpdateRect returned not empty region\n");
5121 ShowWindow(hchild
, SW_HIDE
);
5123 SetRect(&rc2
, 0, 0, 0, 0);
5124 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
5125 ok(!ret
, "GetUpdateRect returned not empty region\n");
5126 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5127 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
5128 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
5130 SetRect(&rc2
, 10, 10, 40, 40);
5131 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
5132 ok(ret
, "GetUpdateRect returned empty region\n");
5133 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5134 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
5135 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
5137 parent_wm_paint
= FALSE
;
5138 grandparent_wm_paint
= FALSE
;
5139 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
5141 if (msg
.message
== WM_PAINT
)
5143 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
5144 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
5146 DispatchMessage(&msg
);
5148 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
5149 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
5151 DestroyWindow(hgrandparent
);
5155 static LRESULT CALLBACK
TestExposedRegion_WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
5163 const int waitTime
= 2000;
5165 BeginPaint(hwnd
, &ps
);
5167 /* create and destroy window to create an exposed region on this window */
5168 win
= CreateWindowA("static", "win", WS_VISIBLE
,
5169 10,10,50,50, NULL
, NULL
, 0, NULL
);
5172 waitResult
= MsgWaitForMultipleObjects( 0, NULL
, FALSE
, waitTime
, QS_PAINT
);
5174 ValidateRect(hwnd
, NULL
);
5175 EndPaint(hwnd
, &ps
);
5177 if(waitResult
!= WAIT_TIMEOUT
)
5179 GetUpdateRect(hwnd
, &updateRect
, FALSE
);
5180 ok(IsRectEmpty(&updateRect
), "Exposed rect should be empty\n");
5185 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
5188 static void test_Expose(void)
5193 memset(&cls
, 0, sizeof(WNDCLASSA
));
5194 cls
.lpfnWndProc
= TestExposedRegion_WndProc
;
5195 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5196 cls
.lpszClassName
= "TestExposeClass";
5197 RegisterClassA(&cls
);
5199 mw
= CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE
|WS_OVERLAPPEDWINDOW
,
5200 0, 0, 200, 100, NULL
, NULL
, 0, NULL
);
5206 static LRESULT CALLBACK
TestNCRedraw_WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
5208 static UINT ncredrawflags
;
5214 ncredrawflags
= *(UINT
*) (((CREATESTRUCT
*)lParam
)->lpCreateParams
);
5217 RedrawWindow(hwnd
, NULL
, NULL
, ncredrawflags
);
5220 BeginPaint(hwnd
, &ps
);
5221 EndPaint(hwnd
, &ps
);
5224 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
5227 static void run_NCRedrawLoop(UINT flags
)
5234 hwnd
= CreateWindowA("TestNCRedrawClass", "MainWindow",
5235 WS_OVERLAPPEDWINDOW
, 0, 0, 200, 100,
5236 NULL
, NULL
, 0, &flags
);
5237 ShowWindow(hwnd
, SW_SHOW
);
5239 flush_events( FALSE
);
5240 while(PeekMessage(&msg
, hwnd
, 0, 0, PM_REMOVE
) != 0)
5242 if (msg
.message
== WM_PAINT
) loopcount
++;
5243 if (loopcount
>= 100) break;
5244 TranslateMessage(&msg
);
5245 DispatchMessage(&msg
);
5246 MsgWaitForMultipleObjects(0, NULL
, FALSE
, 100, QS_ALLINPUT
);
5248 if (flags
== (RDW_INVALIDATE
| RDW_FRAME
))
5249 todo_wine
ok(loopcount
< 100, "Detected infinite WM_PAINT loop (%x).\n", flags
);
5251 ok(loopcount
< 100, "Detected infinite WM_PAINT loop (%x).\n", flags
);
5252 DestroyWindow(hwnd
);
5255 static void test_NCRedraw(void)
5259 wndclass
.lpszClassName
= "TestNCRedrawClass";
5260 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
5261 wndclass
.lpfnWndProc
= TestNCRedraw_WndProc
;
5262 wndclass
.cbClsExtra
= 0;
5263 wndclass
.cbWndExtra
= 0;
5264 wndclass
.hInstance
= 0;
5265 wndclass
.hIcon
= LoadIcon(NULL
, IDI_APPLICATION
);
5266 wndclass
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
5267 wndclass
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5268 wndclass
.lpszMenuName
= NULL
;
5270 RegisterClassA(&wndclass
);
5272 run_NCRedrawLoop(RDW_INVALIDATE
| RDW_FRAME
);
5273 run_NCRedrawLoop(RDW_INVALIDATE
);
5276 static void test_GetWindowModuleFileName(void)
5281 char buf1
[MAX_PATH
], buf2
[MAX_PATH
];
5283 if (!pGetWindowModuleFileNameA
)
5285 win_skip("GetWindowModuleFileNameA is not available\n");
5289 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0,0,0,0, 0, 0, 0, NULL
);
5292 hinst
= (HINSTANCE
)GetWindowLongPtr(hwnd
, GWLP_HINSTANCE
);
5293 ok(hinst
== 0 || broken(hinst
== GetModuleHandle(0)), /* win9x */ "expected 0, got %p\n", hinst
);
5296 SetLastError(0xdeadbeef);
5297 ret1
= GetModuleFileName(hinst
, buf1
, sizeof(buf1
));
5298 ok(ret1
, "GetModuleFileName error %u\n", GetLastError());
5301 SetLastError(0xdeadbeef);
5302 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, sizeof(buf2
));
5303 ok(ret2
|| broken(!ret2
), /* nt4 sp 3 */
5304 "GetWindowModuleFileNameA error %u\n", GetLastError());
5308 ok(ret1
== ret2
|| broken(ret2
== ret1
+ 1), /* win98 */ "%u != %u\n", ret1
, ret2
);
5309 ok(!strcmp(buf1
, buf2
), "%s != %s\n", buf1
, buf2
);
5311 hinst
= GetModuleHandle(0);
5313 SetLastError(0xdeadbeef);
5314 ret2
= GetModuleFileName(hinst
, buf2
, ret1
- 2);
5315 ok(ret2
== ret1
- 2 || broken(ret2
== ret1
- 3), /* win98 */
5316 "expected %u, got %u\n", ret1
- 2, ret2
);
5317 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5318 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
5319 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5321 SetLastError(0xdeadbeef);
5322 ret2
= GetModuleFileName(hinst
, buf2
, 0);
5323 ok(!ret2
, "GetModuleFileName should return 0\n");
5324 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5325 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
5326 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5328 SetLastError(0xdeadbeef);
5329 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, ret1
- 2);
5330 ok(ret2
== ret1
- 2 || broken(ret2
== ret1
- 3) /* win98 */ || broken(!ret2
), /* nt4 sp3 */
5331 "expected %u, got %u\n", ret1
- 2, ret2
);
5332 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5333 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
5334 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5336 SetLastError(0xdeadbeef);
5337 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, 0);
5338 ok(!ret2
, "expected 0, got %u\n", ret2
);
5339 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5340 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
5341 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5343 DestroyWindow(hwnd
);
5346 hwnd
= (HWND
)0xdeadbeef;
5347 SetLastError(0xdeadbeef);
5348 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
5349 ok(!ret1
, "expected 0, got %u\n", ret1
);
5350 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
|| broken(GetLastError() == 0xdeadbeef), /* win9x */
5351 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
5353 hwnd
= FindWindow("Shell_TrayWnd", NULL
);
5354 ok(IsWindow(hwnd
) || broken(!hwnd
), "got invalid tray window %p\n", hwnd
);
5355 SetLastError(0xdeadbeef);
5356 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
5357 ok(!ret1
|| broken(ret1
), /* win98 */ "expected 0, got %u\n", ret1
);
5359 if (!ret1
) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
5361 ret1
= GetModuleFileName(0, buf1
, sizeof(buf1
));
5362 hwnd
= GetDesktopWindow();
5363 ok(IsWindow(hwnd
), "got invalid desktop window %p\n", hwnd
);
5364 SetLastError(0xdeadbeef);
5365 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, sizeof(buf2
));
5367 ret1
== ret2
|| /* vista */
5368 broken(ret2
), /* some win98 return user.exe as file name */
5369 "expected 0 or %u, got %u %s\n", ret1
, ret2
, buf2
);
5373 static void test_hwnd_message(void)
5375 static const WCHAR mainwindowclassW
[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
5376 static const WCHAR message_windowW
[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
5378 HWND parent
= 0, hwnd
, found
;
5381 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
5382 on CreateWindowExA and crash later in the test.
5383 Use UNICODE here to fail on win9x */
5384 hwnd
= CreateWindowExW(0, mainwindowclassW
, message_windowW
, WS_CAPTION
| WS_VISIBLE
,
5385 100, 100, 200, 200, HWND_MESSAGE
, 0, 0, NULL
);
5388 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
5392 ok( !GetParent(hwnd
), "GetParent should return 0 for message only windows\n" );
5396 HWND root
, desktop
= GetDesktopWindow();
5398 parent
= pGetAncestor(hwnd
, GA_PARENT
);
5399 ok(parent
!= 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
5400 ok(parent
!= desktop
, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
5401 root
= pGetAncestor(hwnd
, GA_ROOT
);
5402 ok(root
== hwnd
, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
5403 ok( !pGetAncestor(parent
, GA_PARENT
) || broken(pGetAncestor(parent
, GA_PARENT
) != 0), /* win2k */
5404 "parent shouldn't have parent %p\n", pGetAncestor(parent
, GA_PARENT
) );
5405 trace("parent %p root %p desktop %p\n", parent
, root
, desktop
);
5406 if (!GetClassNameA( parent
, buffer
, sizeof(buffer
) )) buffer
[0] = 0;
5407 ok( !lstrcmpi( buffer
, "Message" ), "wrong parent class '%s'\n", buffer
);
5408 GetWindowRect( parent
, &rect
);
5409 ok( rect
.left
== 0 && rect
.right
== 100 && rect
.top
== 0 && rect
.bottom
== 100,
5410 "wrong parent rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
5412 GetWindowRect( hwnd
, &rect
);
5413 ok( rect
.left
== 100 && rect
.right
== 300 && rect
.top
== 100 && rect
.bottom
== 300,
5414 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
5416 /* test FindWindow behavior */
5418 found
= FindWindowExA( 0, 0, 0, "message window" );
5419 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
5420 SetLastError(0xdeadbeef);
5421 found
= FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
5422 ok( found
== 0, "found message window %p/%p\n", found
, hwnd
);
5423 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
5426 found
= FindWindowExA( parent
, 0, 0, "message window" );
5427 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
5430 /* test IsChild behavior */
5432 if (parent
) ok( !IsChild( parent
, hwnd
), "HWND_MESSAGE is child of top window\n" );
5434 /* test IsWindowVisible behavior */
5436 ok( !IsWindowVisible( hwnd
), "HWND_MESSAGE window is visible\n" );
5437 if (parent
) ok( !IsWindowVisible( parent
), "HWND_MESSAGE parent is visible\n" );
5439 DestroyWindow(hwnd
);
5442 static void test_layered_window(void)
5450 if (!pGetLayeredWindowAttributes
|| !pSetLayeredWindowAttributes
)
5452 win_skip( "layered windows not supported\n" );
5455 hwnd
= CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION
,
5456 100, 100, 200, 200, 0, 0, 0, NULL
);
5458 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5459 ok( !ret
, "GetLayeredWindowAttributes should fail on non-layered window\n" );
5460 ret
= pSetLayeredWindowAttributes( hwnd
, 0, 0, LWA_ALPHA
);
5461 ok( !ret
, "SetLayeredWindowAttributes should fail on non-layered window\n" );
5462 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
5463 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5464 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5465 ret
= pSetLayeredWindowAttributes( hwnd
, 0x123456, 44, LWA_ALPHA
);
5466 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5467 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5468 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5469 ok( key
== 0x123456 || key
== 0, "wrong color key %x\n", key
);
5470 ok( alpha
== 44, "wrong alpha %u\n", alpha
);
5471 ok( flags
== LWA_ALPHA
, "wrong flags %x\n", flags
);
5473 /* clearing WS_EX_LAYERED resets attributes */
5474 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
5475 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5476 ok( !ret
, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
5477 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
5478 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5479 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5480 ret
= pSetLayeredWindowAttributes( hwnd
, 0x654321, 22, LWA_COLORKEY
| LWA_ALPHA
);
5481 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5482 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5483 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5484 ok( key
== 0x654321, "wrong color key %x\n", key
);
5485 ok( alpha
== 22, "wrong alpha %u\n", alpha
);
5486 ok( flags
== (LWA_COLORKEY
| LWA_ALPHA
), "wrong flags %x\n", flags
);
5488 ret
= pSetLayeredWindowAttributes( hwnd
, 0x888888, 33, LWA_COLORKEY
);
5489 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5491 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5492 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5493 ok( key
== 0x888888, "wrong color key %x\n", key
);
5494 /* alpha not changed on vista if LWA_ALPHA is not set */
5495 ok( alpha
== 22 || alpha
== 33, "wrong alpha %u\n", alpha
);
5496 ok( flags
== LWA_COLORKEY
, "wrong flags %x\n", flags
);
5498 /* color key may or may not be changed without LWA_COLORKEY */
5499 ret
= pSetLayeredWindowAttributes( hwnd
, 0x999999, 44, 0 );
5500 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
== 0x888888 || key
== 0x999999, "wrong color key %x\n", key
);
5505 ok( alpha
== 22 || alpha
== 44, "wrong alpha %u\n", alpha
);
5506 ok( flags
== 0, "wrong flags %x\n", flags
);
5508 /* default alpha and color key is 0 */
5509 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
5510 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
5511 ret
= pSetLayeredWindowAttributes( hwnd
, 0x222222, 55, 0 );
5512 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5513 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5514 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5515 ok( key
== 0 || key
== 0x222222, "wrong color key %x\n", key
);
5516 ok( alpha
== 0 || alpha
== 55, "wrong alpha %u\n", alpha
);
5517 ok( flags
== 0, "wrong flags %x\n", flags
);
5519 DestroyWindow( hwnd
);
5522 static MONITORINFO mi
;
5524 static LRESULT CALLBACK
fullscreen_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
5530 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
5531 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
5532 ok(cs
->x
== mi
.rcMonitor
.left
&& cs
->y
== mi
.rcMonitor
.top
&&
5533 cs
->cx
== mi
.rcMonitor
.right
&& cs
->cy
== mi
.rcMonitor
.bottom
,
5534 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
5535 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5536 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
5539 case WM_GETMINMAXINFO
:
5541 MINMAXINFO
*minmax
= (MINMAXINFO
*)lp
;
5542 dump_minmax_info(minmax
);
5543 ok(minmax
->ptMaxPosition
.x
<= mi
.rcMonitor
.left
, "%d <= %d\n", minmax
->ptMaxPosition
.x
, mi
.rcMonitor
.left
);
5544 ok(minmax
->ptMaxPosition
.y
<= mi
.rcMonitor
.top
, "%d <= %d\n", minmax
->ptMaxPosition
.y
, mi
.rcMonitor
.top
);
5545 ok(minmax
->ptMaxSize
.x
>= mi
.rcMonitor
.right
, "%d >= %d\n", minmax
->ptMaxSize
.x
, mi
.rcMonitor
.right
);
5546 ok(minmax
->ptMaxSize
.y
>= mi
.rcMonitor
.bottom
, "%d >= %d\n", minmax
->ptMaxSize
.y
, mi
.rcMonitor
.bottom
);
5550 return DefWindowProc(hwnd
, msg
, wp
, lp
);
5553 static void test_fullscreen(void)
5555 static const DWORD t_style
[] = {
5556 WS_OVERLAPPED
, WS_POPUP
, WS_CHILD
, WS_THICKFRAME
, WS_DLGFRAME
5558 static const DWORD t_ex_style
[] = {
5559 0, WS_EX_APPWINDOW
, WS_EX_TOOLWINDOW
5569 if (!pGetMonitorInfoA
|| !pMonitorFromPoint
)
5571 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
5576 SetLastError(0xdeadbeef);
5577 hmon
= pMonitorFromPoint(pt
, MONITOR_DEFAULTTOPRIMARY
);
5578 ok(hmon
!= 0, "MonitorFromPoint error %u\n", GetLastError());
5580 mi
.cbSize
= sizeof(mi
);
5581 SetLastError(0xdeadbeef);
5582 ret
= pGetMonitorInfoA(hmon
, &mi
);
5583 ok(ret
, "GetMonitorInfo error %u\n", GetLastError());
5584 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
5585 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5586 mi
.rcWork
.left
, mi
.rcWork
.top
, mi
.rcWork
.right
, mi
.rcWork
.bottom
);
5589 cls
.lpfnWndProc
= fullscreen_wnd_proc
;
5592 cls
.hInstance
= GetModuleHandle(0);
5594 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
5595 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5596 cls
.lpszMenuName
= NULL
;
5597 cls
.lpszClassName
= "fullscreen_class";
5598 RegisterClass(&cls
);
5600 for (i
= 0; i
< sizeof(t_style
)/sizeof(t_style
[0]); i
++)
5602 DWORD style
, ex_style
;
5604 /* avoid a WM interaction */
5605 assert(!(t_style
[i
] & WS_VISIBLE
));
5607 for (j
= 0; j
< sizeof(t_ex_style
)/sizeof(t_ex_style
[0]); j
++)
5612 ex_style
= t_ex_style
[j
];
5614 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5615 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5616 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5617 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5618 GetWindowRect(hwnd
, &rc
);
5619 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5620 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5621 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5622 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5623 DestroyWindow(hwnd
);
5625 style
= t_style
[i
] | WS_MAXIMIZE
;
5626 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5627 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5628 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5629 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5630 GetWindowRect(hwnd
, &rc
);
5631 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5632 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5633 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5634 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5635 DestroyWindow(hwnd
);
5637 style
= t_style
[i
] | WS_MAXIMIZE
| WS_CAPTION
;
5638 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5639 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5640 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5641 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5642 GetWindowRect(hwnd
, &rc
);
5643 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5644 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5645 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5646 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5647 DestroyWindow(hwnd
);
5649 style
= t_style
[i
] | WS_CAPTION
| WS_MAXIMIZEBOX
;
5650 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5651 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5652 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5653 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5654 GetWindowRect(hwnd
, &rc
);
5655 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5656 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5657 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5658 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5659 DestroyWindow(hwnd
);
5661 style
= t_style
[i
] | WS_MAXIMIZE
| WS_CAPTION
| WS_MAXIMIZEBOX
;
5662 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5663 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5664 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5665 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5666 GetWindowRect(hwnd
, &rc
);
5667 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5668 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5669 fixup
= min(abs(rc
.left
), abs(rc
.top
));
5670 InflateRect(&rc
, -fixup
, -fixup
);
5671 ok(rc
.left
>= mi
.rcWork
.left
&& rc
.top
<= mi
.rcWork
.top
&&
5672 rc
.right
<= mi
.rcWork
.right
&& rc
.bottom
<= mi
.rcWork
.bottom
,
5673 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
5674 ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
5675 mi
.rcWork
.left
, mi
.rcWork
.top
, mi
.rcWork
.right
, mi
.rcWork
.bottom
);
5676 DestroyWindow(hwnd
);
5678 style
= t_style
[i
] | WS_MAXIMIZE
| WS_MAXIMIZEBOX
;
5679 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5680 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5681 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5682 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5683 GetWindowRect(hwnd
, &rc
);
5684 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5685 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5686 fixup
= min(abs(rc
.left
), abs(rc
.top
));
5687 InflateRect(&rc
, -fixup
, -fixup
);
5688 if (style
& (WS_CHILD
| WS_POPUP
))
5689 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5690 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5691 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5693 ok(rc
.left
>= mi
.rcWork
.left
&& rc
.top
<= mi
.rcWork
.top
&&
5694 rc
.right
<= mi
.rcWork
.right
&& rc
.bottom
<= mi
.rcWork
.bottom
,
5695 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5696 DestroyWindow(hwnd
);
5700 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5703 static BOOL test_thick_child_got_minmax
;
5704 static const char * test_thick_child_name
;
5705 static LONG test_thick_child_style
;
5706 static LONG test_thick_child_exStyle
;
5708 static LRESULT WINAPI
test_thick_child_size_winproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
5711 int expectedMinTrackX
;
5712 int expectedMinTrackY
;
5713 int actualMinTrackX
;
5714 int actualMinTrackY
;
5715 int expectedMaxTrackX
;
5716 int expectedMaxTrackY
;
5717 int actualMaxTrackX
;
5718 int actualMaxTrackY
;
5719 int expectedMaxSizeX
;
5720 int expectedMaxSizeY
;
5731 case WM_GETMINMAXINFO
:
5733 minmax
= (MINMAXINFO
*)lparam
;
5734 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
5735 dump_minmax_info( minmax
);
5737 test_thick_child_got_minmax
= TRUE
;
5740 adjustedStyle
= test_thick_child_style
;
5741 if ((adjustedStyle
& WS_CAPTION
) == WS_CAPTION
)
5742 adjustedStyle
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5743 GetClientRect(GetParent(hwnd
), &rect
);
5744 AdjustWindowRectEx(&rect
, adjustedStyle
, FALSE
, test_thick_child_exStyle
);
5746 if (test_thick_child_style
& (WS_DLGFRAME
| WS_BORDER
))
5748 expectedMinTrackX
= GetSystemMetrics(SM_CXMINTRACK
);
5749 expectedMinTrackY
= GetSystemMetrics(SM_CYMINTRACK
);
5753 expectedMinTrackX
= -2 * rect
.left
;
5754 expectedMinTrackY
= -2 * rect
.top
;
5756 actualMinTrackX
= minmax
->ptMinTrackSize
.x
;
5757 actualMinTrackY
= minmax
->ptMinTrackSize
.y
;
5759 ok(actualMinTrackX
== expectedMinTrackX
&& actualMinTrackY
== expectedMinTrackY
,
5760 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
5761 expectedMinTrackX
, expectedMinTrackY
, actualMinTrackX
, actualMinTrackY
,
5762 test_thick_child_name
);
5764 actualMaxTrackX
= minmax
->ptMaxTrackSize
.x
;
5765 actualMaxTrackY
= minmax
->ptMaxTrackSize
.y
;
5766 expectedMaxTrackX
= GetSystemMetrics(SM_CXMAXTRACK
);
5767 expectedMaxTrackY
= GetSystemMetrics(SM_CYMAXTRACK
);
5768 ok(actualMaxTrackX
== expectedMaxTrackX
&& actualMaxTrackY
== expectedMaxTrackY
,
5769 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
5770 expectedMaxTrackX
, expectedMaxTrackY
, actualMaxTrackX
, actualMaxTrackY
,
5771 test_thick_child_name
);
5773 expectedMaxSizeX
= rect
.right
- rect
.left
;
5774 expectedMaxSizeY
= rect
.bottom
- rect
.top
;
5775 actualMaxSizeX
= minmax
->ptMaxSize
.x
;
5776 actualMaxSizeY
= minmax
->ptMaxSize
.y
;
5778 ok(actualMaxSizeX
== expectedMaxSizeX
&& actualMaxSizeY
== expectedMaxSizeY
,
5779 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
5780 expectedMaxSizeX
, expectedMaxSizeY
, actualMaxSizeX
, actualMaxSizeY
,
5781 test_thick_child_name
);
5784 expectedPosX
= rect
.left
;
5785 expectedPosY
= rect
.top
;
5786 actualPosX
= minmax
->ptMaxPosition
.x
;
5787 actualPosY
= minmax
->ptMaxPosition
.y
;
5788 ok(actualPosX
== expectedPosX
&& actualPosY
== expectedPosY
,
5789 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
5790 expectedPosX
, expectedPosY
, actualPosX
, actualPosY
, test_thick_child_name
);
5796 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
5799 #define NUMBER_OF_THICK_CHILD_TESTS 16
5800 static void test_thick_child_size(HWND parentWindow
)
5804 RECT adjustedParentRect
;
5809 LONG expectedHeight
;
5811 LPCTSTR className
= "THICK_CHILD_CLASS";
5814 static const LONG styles
[NUMBER_OF_THICK_CHILD_TESTS
] = {
5815 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
5816 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
5817 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
5818 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
5819 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
5820 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
5821 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
5822 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
5823 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
5824 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
5825 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
5826 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
5827 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
5828 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
5829 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
5830 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
5833 static const LONG exStyles
[NUMBER_OF_THICK_CHILD_TESTS
] = {
5838 WS_EX_DLGMODALFRAME
,
5839 WS_EX_DLGMODALFRAME
,
5840 WS_EX_DLGMODALFRAME
,
5841 WS_EX_DLGMODALFRAME
,
5846 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
5847 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
5848 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
5849 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
5851 static const char *styleName
[NUMBER_OF_THICK_CHILD_TESTS
] = {
5852 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
5853 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
5854 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
5855 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
5856 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
5857 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
5858 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5859 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5860 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
5861 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
5862 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5863 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5864 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5865 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5866 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5867 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5871 cls
.lpfnWndProc
= test_thick_child_size_winproc
;
5874 cls
.hInstance
= GetModuleHandleA(0);
5876 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
5877 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5878 cls
.lpszMenuName
= NULL
;
5879 cls
.lpszClassName
= className
;
5880 SetLastError(0xdeadbeef);
5881 ok(RegisterClassA(&cls
),"RegisterClassA failed, error: %u\n", GetLastError());
5883 for(i
= 0; i
< NUMBER_OF_THICK_CHILD_TESTS
; i
++)
5885 test_thick_child_name
= styleName
[i
];
5886 test_thick_child_style
= styles
[i
];
5887 test_thick_child_exStyle
= exStyles
[i
];
5888 test_thick_child_got_minmax
= FALSE
;
5890 SetLastError(0xdeadbeef);
5891 childWindow
= CreateWindowEx( exStyles
[i
], className
, "", styles
[i
], 0, 0, 0, 0, parentWindow
, 0, GetModuleHandleA(0), NULL
);
5892 ok(childWindow
!= NULL
, "Failed to create child window, error: %u\n", GetLastError());
5894 ok(test_thick_child_got_minmax
, "Got no WM_GETMINMAXINFO\n");
5896 SetLastError(0xdeadbeef);
5897 success
= GetWindowRect(childWindow
, &childRect
);
5898 ok(success
,"GetWindowRect call failed, error: %u\n", GetLastError());
5899 childWidth
= childRect
.right
- childRect
.left
;
5900 childHeight
= childRect
.bottom
- childRect
.top
;
5902 adjustedStyle
= styles
[i
];
5903 if ((adjustedStyle
& WS_CAPTION
) == WS_CAPTION
)
5904 adjustedStyle
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5905 GetClientRect(GetParent(childWindow
), &adjustedParentRect
);
5906 AdjustWindowRectEx(&adjustedParentRect
, adjustedStyle
, FALSE
, test_thick_child_exStyle
);
5909 if (test_thick_child_style
& (WS_DLGFRAME
| WS_BORDER
))
5911 expectedWidth
= GetSystemMetrics(SM_CXMINTRACK
);
5912 expectedHeight
= GetSystemMetrics(SM_CYMINTRACK
);
5916 expectedWidth
= -2 * adjustedParentRect
.left
;
5917 expectedHeight
= -2 * adjustedParentRect
.top
;
5920 ok((childWidth
== expectedWidth
) && (childHeight
== expectedHeight
),
5921 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
5922 test_thick_child_name
, expectedWidth
, expectedHeight
, childWidth
, childHeight
);
5924 SetLastError(0xdeadbeef);
5925 success
= DestroyWindow(childWindow
);
5926 ok(success
,"DestroyWindow call failed, error: %u\n", GetLastError());
5928 ok(UnregisterClass(className
, GetModuleHandleA(0)),"UnregisterClass call failed\n");
5931 static void test_handles( HWND full_hwnd
)
5933 HWND hwnd
= full_hwnd
;
5937 SetLastError( 0xdeadbeef );
5938 ret
= GetWindowRect( hwnd
, &rect
);
5939 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
5942 if ((ULONG_PTR
)full_hwnd
>> 32)
5943 hwnd
= (HWND
)((ULONG_PTR
)full_hwnd
& ~0u);
5945 hwnd
= (HWND
)((ULONG_PTR
)full_hwnd
| ((ULONG_PTR
)~0u << 32));
5946 SetLastError( 0xdeadbeef );
5947 ret
= GetWindowRect( hwnd
, &rect
);
5948 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
5950 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& ~0u) | ((ULONG_PTR
)0x1234 << 32));
5951 SetLastError( 0xdeadbeef );
5952 ret
= GetWindowRect( hwnd
, &rect
);
5953 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
5955 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& 0xffff) | ((ULONG_PTR
)0x9876 << 16));
5956 SetLastError( 0xdeadbeef );
5957 ret
= GetWindowRect( hwnd
, &rect
);
5958 ok( !ret
, "GetWindowRect succeeded for %p\n", hwnd
);
5959 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "wrong error %u\n", GetLastError() );
5961 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& 0xffff) | ((ULONG_PTR
)0x12345678 << 16));
5962 SetLastError( 0xdeadbeef );
5963 ret
= GetWindowRect( hwnd
, &rect
);
5964 ok( !ret
, "GetWindowRect succeeded for %p\n", hwnd
);
5965 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "wrong error %u\n", GetLastError() );
5969 static void test_winregion(void)
5976 if (!pGetWindowRgnBox
)
5978 win_skip("GetWindowRgnBox not supported\n");
5982 hwnd
= CreateWindowExA(0, "static", NULL
, WS_VISIBLE
, 10, 10, 10, 10, NULL
, 0, 0, NULL
);
5984 SetLastError(0xdeadbeef);
5985 ret
= pGetWindowRgnBox(hwnd
, NULL
);
5986 ok( ret
== ERROR
, "Expected ERROR, got %d\n", ret
);
5987 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
5989 hrgn
= CreateRectRgn(2, 3, 10, 15);
5990 ok( hrgn
!= NULL
, "Region creation failed\n");
5993 SetWindowRgn(hwnd
, hrgn
, FALSE
);
5995 SetLastError(0xdeadbeef);
5996 ret
= pGetWindowRgnBox(hwnd
, NULL
);
5997 ok( ret
== ERROR
, "Expected ERROR, got %d\n", ret
);
5998 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
6000 r
.left
= r
.top
= r
.right
= r
.bottom
= 0;
6001 ret
= pGetWindowRgnBox(hwnd
, &r
);
6002 ok( ret
== SIMPLEREGION
, "Expected SIMPLEREGION, got %d\n", ret
);
6003 ok( r
.left
== 2 && r
.top
== 3 && r
.right
== 10 && r
.bottom
== 15,
6004 "Expected (2,3,10,15), got (%d,%d,%d,%d)\n", r
.left
, r
.top
,
6008 DestroyWindow(hwnd
);
6013 HMODULE user32
= GetModuleHandleA( "user32.dll" );
6014 pGetAncestor
= (void *)GetProcAddress( user32
, "GetAncestor" );
6015 pGetWindowInfo
= (void *)GetProcAddress( user32
, "GetWindowInfo" );
6016 pGetWindowModuleFileNameA
= (void *)GetProcAddress( user32
, "GetWindowModuleFileNameA" );
6017 pGetLayeredWindowAttributes
= (void *)GetProcAddress( user32
, "GetLayeredWindowAttributes" );
6018 pSetLayeredWindowAttributes
= (void *)GetProcAddress( user32
, "SetLayeredWindowAttributes" );
6019 pGetMonitorInfoA
= (void *)GetProcAddress( user32
, "GetMonitorInfoA" );
6020 pMonitorFromPoint
= (void *)GetProcAddress( user32
, "MonitorFromPoint" );
6021 pGetWindowRgnBox
= (void *)GetProcAddress( user32
, "GetWindowRgnBox" );
6022 pGetGUIThreadInfo
= (void *)GetProcAddress( user32
, "GetGUIThreadInfo" );
6024 if (!RegisterWindowClasses()) assert(0);
6026 SetLastError(0xdeafbeef);
6027 GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC
);
6028 is_win9x
= (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
);
6030 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
6031 if (!hhook
) win_skip( "Cannot set CBT hook, skipping some tests\n" );
6033 hwndMain
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
6034 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
6035 WS_MAXIMIZEBOX
| WS_POPUP
,
6037 0, 0, GetModuleHandle(0), NULL
);
6038 hwndMain2
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
6039 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
6040 WS_MAXIMIZEBOX
| WS_POPUP
,
6042 0, 0, GetModuleHandle(0), NULL
);
6044 assert( hwndMain2
);
6046 our_pid
= GetWindowThreadProcessId(hwndMain
, NULL
);
6048 /* Add the tests below this line */
6049 test_thick_child_size(hwndMain
);
6051 test_hwnd_message();
6052 test_nonclient_area(hwndMain
);
6054 test_GetWindowModuleFileName();
6057 test_capture_3(hwndMain
, hwndMain2
);
6060 test_CreateWindow();
6061 test_parent_owner();
6063 test_enum_thread_windows();
6067 test_SetWindowPos(hwndMain
);
6068 test_SetMenu(hwndMain
);
6069 test_SetFocus(hwndMain
);
6070 test_SetActiveWindow(hwndMain
);
6073 test_children_zorder(hwndMain
);
6074 test_popup_zorder(hwndMain2
, hwndMain
, WS_POPUP
);
6075 test_popup_zorder(hwndMain2
, hwndMain
, 0);
6076 test_keyboard_input(hwndMain
);
6077 test_mouse_input(hwndMain
);
6078 test_validatergn(hwndMain
);
6079 test_nccalcscroll( hwndMain
);
6080 test_scrollwindow( hwndMain
);
6081 test_scrollvalidate( hwndMain
);
6082 test_scrolldc( hwndMain
);
6084 test_IsWindowUnicode();
6085 test_vis_rgn(hwndMain
);
6087 test_AdjustWindowRect();
6088 test_window_styles();
6091 test_SetWindowLong();
6093 if (0) test_gettext(); /* crashes on NT4 */
6094 test_GetUpdateRect();
6096 test_layered_window();
6098 test_SetForegroundWindow(hwndMain
);
6099 test_shell_window();
6100 test_handles( hwndMain
);
6103 /* add the tests above this line */
6104 if (hhook
) UnhookWindowsHookEx(hhook
);
6106 DestroyWindow(hwndMain2
);
6107 DestroyWindow(hwndMain
);