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
);
56 static BOOL test_lbuttondown_flag
;
57 static HWND hwndMessage
;
58 static HWND hwndMain
, hwndMain2
;
61 static const char* szAWRClass
= "Winsize";
65 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
67 static void dump_minmax_info( const MINMAXINFO
*minmax
)
69 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
70 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
71 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
72 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
73 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
74 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
77 /* try to make sure pending X events have been processed before continuing */
78 static void flush_events( BOOL remove_messages
)
82 int min_timeout
= 100;
83 DWORD time
= GetTickCount() + diff
;
87 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
89 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
90 diff
= time
- GetTickCount();
95 /* check the values returned by the various parent/owner functions on a given window */
96 static void check_parents( HWND hwnd
, HWND ga_parent
, HWND gwl_parent
, HWND get_parent
,
97 HWND gw_owner
, HWND ga_root
, HWND ga_root_owner
)
103 res
= pGetAncestor( hwnd
, GA_PARENT
);
104 ok( res
== ga_parent
, "Wrong result for GA_PARENT %p expected %p\n", res
, ga_parent
);
106 res
= (HWND
)GetWindowLongPtrA( hwnd
, GWLP_HWNDPARENT
);
107 ok( res
== gwl_parent
, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res
, gwl_parent
);
108 res
= GetParent( hwnd
);
109 ok( res
== get_parent
, "Wrong result for GetParent %p expected %p\n", res
, get_parent
);
110 res
= GetWindow( hwnd
, GW_OWNER
);
111 ok( res
== gw_owner
, "Wrong result for GW_OWNER %p expected %p\n", res
, gw_owner
);
114 res
= pGetAncestor( hwnd
, GA_ROOT
);
115 ok( res
== ga_root
, "Wrong result for GA_ROOT %p expected %p\n", res
, ga_root
);
116 res
= pGetAncestor( hwnd
, GA_ROOTOWNER
);
117 ok( res
== ga_root_owner
, "Wrong result for GA_ROOTOWNER %p expected %p\n", res
, ga_root_owner
);
121 static BOOL
ignore_message( UINT message
)
123 /* these are always ignored */
124 return (message
>= 0xc000 ||
125 message
== WM_GETICON
||
126 message
== WM_GETOBJECT
||
127 message
== WM_TIMECHANGE
||
128 message
== WM_DEVICECHANGE
);
131 static BOOL CALLBACK
EnumChildProc( HWND hwndChild
, LPARAM lParam
)
134 trace("EnumChildProc on %p\n", hwndChild
);
135 if (*(LPINT
)lParam
> 1) return FALSE
;
139 /* will search for the given window */
140 static BOOL CALLBACK
EnumChildProc1( HWND hwndChild
, LPARAM lParam
)
142 trace("EnumChildProc1 on %p\n", hwndChild
);
143 if ((HWND
)lParam
== hwndChild
) return FALSE
;
147 static HWND
create_tool_window( LONG style
, HWND parent
)
149 HWND ret
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style
,
150 0, 0, 100, 100, parent
, 0, 0, NULL
);
151 ok( ret
!= 0, "Creation failed\n" );
155 /* test parent and owner values for various combinations */
156 static void test_parent_owner(void)
159 HWND test
, owner
, ret
;
160 HWND desktop
= GetDesktopWindow();
161 HWND child
= create_tool_window( WS_CHILD
, hwndMain
);
164 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain
, hwndMain2
, desktop
, child
);
166 /* child without parent, should fail */
167 SetLastError(0xdeadbeef);
168 test
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
169 WS_CHILD
, 0, 0, 100, 100, 0, 0, 0, NULL
);
170 ok( !test
, "WS_CHILD without parent created\n" );
171 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD
||
172 broken(GetLastError() == 0xdeadbeef), /* win9x */
173 "CreateWindowExA error %u\n", GetLastError() );
176 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
177 style
= GetWindowLongA( desktop
, GWL_STYLE
);
178 ok( !SetWindowLongA( desktop
, GWL_STYLE
, WS_POPUP
), "Set GWL_STYLE on desktop succeeded\n" );
179 ok( !SetWindowLongA( desktop
, GWL_STYLE
, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
180 ok( GetWindowLongA( desktop
, GWL_STYLE
) == style
, "Desktop style changed\n" );
182 /* normal child window */
183 test
= create_tool_window( WS_CHILD
, hwndMain
);
184 trace( "created child %p\n", test
);
185 check_parents( test
, hwndMain
, hwndMain
, hwndMain
, 0, hwndMain
, hwndMain
);
186 SetWindowLongA( test
, GWL_STYLE
, 0 );
187 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
188 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
189 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
190 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
|WS_CHILD
);
191 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
192 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
193 DestroyWindow( test
);
195 /* normal child window with WS_MAXIMIZE */
196 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
197 DestroyWindow( test
);
199 /* normal child window with WS_THICKFRAME */
200 test
= create_tool_window( WS_CHILD
| WS_THICKFRAME
, hwndMain
);
201 DestroyWindow( test
);
203 /* popup window with WS_THICKFRAME */
204 test
= create_tool_window( WS_POPUP
| WS_THICKFRAME
, hwndMain
);
205 DestroyWindow( test
);
207 /* child of desktop */
208 test
= create_tool_window( WS_CHILD
, desktop
);
209 trace( "created child of desktop %p\n", test
);
210 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
211 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
212 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
213 SetWindowLongA( test
, GWL_STYLE
, 0 );
214 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
215 DestroyWindow( test
);
217 /* child of desktop with WS_MAXIMIZE */
218 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, desktop
);
219 DestroyWindow( test
);
221 /* child of desktop with WS_MINIMIZE */
222 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, desktop
);
223 DestroyWindow( test
);
226 test
= create_tool_window( WS_CHILD
, child
);
227 trace( "created child of child %p\n", test
);
228 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
229 SetWindowLongA( test
, GWL_STYLE
, 0 );
230 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
231 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
232 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
233 DestroyWindow( test
);
235 /* child of child with WS_MAXIMIZE */
236 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, child
);
237 DestroyWindow( test
);
239 /* child of child with WS_MINIMIZE */
240 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, child
);
241 DestroyWindow( test
);
243 /* not owned top-level window */
244 test
= create_tool_window( 0, 0 );
245 trace( "created top-level %p\n", test
);
246 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
247 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
248 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
249 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
250 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
251 DestroyWindow( test
);
253 /* not owned top-level window with WS_MAXIMIZE */
254 test
= create_tool_window( WS_MAXIMIZE
, 0 );
255 DestroyWindow( test
);
257 /* owned top-level window */
258 test
= create_tool_window( 0, hwndMain
);
259 trace( "created owned top-level %p\n", test
);
260 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
261 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
262 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
263 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
264 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
265 DestroyWindow( test
);
267 /* owned top-level window with WS_MAXIMIZE */
268 test
= create_tool_window( WS_MAXIMIZE
, hwndMain
);
269 DestroyWindow( test
);
271 /* not owned popup */
272 test
= create_tool_window( WS_POPUP
, 0 );
273 trace( "created popup %p\n", test
);
274 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
275 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
276 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
277 SetWindowLongA( test
, GWL_STYLE
, 0 );
278 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
279 DestroyWindow( test
);
281 /* not owned popup with WS_MAXIMIZE */
282 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, 0 );
283 DestroyWindow( test
);
286 test
= create_tool_window( WS_POPUP
, hwndMain
);
287 trace( "created owned popup %p\n", test
);
288 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
289 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
290 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
291 SetWindowLongA( test
, GWL_STYLE
, 0 );
292 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
293 DestroyWindow( test
);
295 /* owned popup with WS_MAXIMIZE */
296 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, hwndMain
);
297 DestroyWindow( test
);
299 /* top-level window owned by child (same as owned by top-level) */
300 test
= create_tool_window( 0, child
);
301 trace( "created top-level owned by child %p\n", test
);
302 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
303 DestroyWindow( test
);
305 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
306 test
= create_tool_window( WS_MAXIMIZE
, child
);
307 DestroyWindow( test
);
309 /* popup owned by desktop (same as not owned) */
310 test
= create_tool_window( WS_POPUP
, desktop
);
311 trace( "created popup owned by desktop %p\n", test
);
312 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
313 DestroyWindow( test
);
315 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
316 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, desktop
);
317 DestroyWindow( test
);
319 /* popup owned by child (same as owned by top-level) */
320 test
= create_tool_window( WS_POPUP
, child
);
321 trace( "created popup owned by child %p\n", test
);
322 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
323 DestroyWindow( test
);
325 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
326 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, child
);
327 DestroyWindow( test
);
329 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
330 test
= create_tool_window( WS_POPUP
| WS_CHILD
, 0 );
331 trace( "created WS_CHILD popup %p\n", test
);
332 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
333 DestroyWindow( test
);
335 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
336 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, 0 );
337 DestroyWindow( test
);
339 /* owned popup with WS_CHILD (same as WS_POPUP only) */
340 test
= create_tool_window( WS_POPUP
| WS_CHILD
, hwndMain
);
341 trace( "created owned WS_CHILD popup %p\n", test
);
342 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
343 DestroyWindow( test
);
345 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
346 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
347 DestroyWindow( test
);
349 /******************** parent changes *************************/
350 trace( "testing parent changes\n" );
353 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
356 /* this test succeeds on NT but crashes on win9x systems */
357 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
358 ok( !ret
, "Set GWL_HWNDPARENT succeeded on desktop\n" );
359 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
360 ok( !SetParent( desktop
, hwndMain
), "SetParent succeeded on desktop\n" );
361 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
363 /* normal child window */
364 test
= create_tool_window( WS_CHILD
, hwndMain
);
365 trace( "created child %p\n", test
);
367 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
368 ok( ret
== hwndMain
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain
);
369 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
371 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
372 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
373 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
375 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)desktop
);
376 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
377 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
379 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
380 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
381 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
382 check_parents( test
, desktop
, child
, desktop
, child
, test
, desktop
);
384 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
385 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
386 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
387 DestroyWindow( test
);
389 /* not owned top-level window */
390 test
= create_tool_window( 0, 0 );
391 trace( "created top-level %p\n", test
);
393 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
394 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
395 check_parents( test
, desktop
, hwndMain2
, 0, hwndMain2
, test
, test
);
397 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
398 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
399 check_parents( test
, desktop
, child
, 0, child
, test
, test
);
401 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
402 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
403 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
404 DestroyWindow( test
);
406 /* not owned popup */
407 test
= create_tool_window( WS_POPUP
, 0 );
408 trace( "created popup %p\n", test
);
410 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
411 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
412 check_parents( test
, desktop
, hwndMain2
, hwndMain2
, hwndMain2
, test
, hwndMain2
);
414 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
415 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
416 check_parents( test
, desktop
, child
, child
, child
, test
, hwndMain
);
418 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
419 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
420 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
421 DestroyWindow( test
);
423 /* normal child window */
424 test
= create_tool_window( WS_CHILD
, hwndMain
);
425 trace( "created child %p\n", test
);
427 ret
= SetParent( test
, desktop
);
428 ok( ret
== hwndMain
, "SetParent return value %p expected %p\n", ret
, hwndMain
);
429 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
431 ret
= SetParent( test
, child
);
432 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
433 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
435 ret
= SetParent( test
, hwndMain2
);
436 ok( ret
== child
, "SetParent return value %p expected %p\n", ret
, child
);
437 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
438 DestroyWindow( test
);
440 /* not owned top-level window */
441 test
= create_tool_window( 0, 0 );
442 trace( "created top-level %p\n", test
);
444 ret
= SetParent( test
, child
);
445 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
446 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
447 DestroyWindow( test
);
450 test
= create_tool_window( WS_POPUP
, hwndMain2
);
451 trace( "created owned popup %p\n", test
);
453 ret
= SetParent( test
, child
);
454 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
455 check_parents( test
, child
, child
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
457 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)hwndMain
);
458 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
459 check_parents( test
, hwndMain
, hwndMain
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
460 DestroyWindow( test
);
462 /**************** test owner destruction *******************/
464 /* owned child popup */
465 owner
= create_tool_window( 0, 0 );
466 test
= create_tool_window( WS_POPUP
, owner
);
467 trace( "created owner %p and popup %p\n", owner
, test
);
468 ret
= SetParent( test
, child
);
469 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
470 check_parents( test
, child
, child
, owner
, owner
, hwndMain
, owner
);
471 /* window is now child of 'child' but owned by 'owner' */
472 DestroyWindow( owner
);
473 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
474 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
475 * while Win95, Win2k, WinXP do.
477 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
478 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
481 /* owned top-level popup */
482 owner
= create_tool_window( 0, 0 );
483 test
= create_tool_window( WS_POPUP
, owner
);
484 trace( "created owner %p and popup %p\n", owner
, test
);
485 check_parents( test
, desktop
, owner
, owner
, owner
, test
, owner
);
486 DestroyWindow( owner
);
487 ok( !IsWindow(test
), "Window %p not destroyed by owner destruction\n", test
);
489 /* top-level popup owned by child */
490 owner
= create_tool_window( WS_CHILD
, hwndMain2
);
491 test
= create_tool_window( WS_POPUP
, 0 );
492 trace( "created owner %p and popup %p\n", owner
, test
);
493 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)owner
);
494 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
495 check_parents( test
, desktop
, owner
, owner
, owner
, test
, hwndMain2
);
496 DestroyWindow( owner
);
497 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
498 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
499 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
500 * while Win95, Win2k, WinXP do.
502 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
506 DestroyWindow(child
);
509 owner
= create_tool_window( WS_OVERLAPPED
, 0 );
510 test
= create_tool_window( WS_POPUP
, desktop
);
512 ok( !GetWindow( test
, GW_OWNER
), "Wrong owner window\n" );
514 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
515 "EnumChildWindows should have returned FALSE\n" );
516 ok( numChildren
== 0, "numChildren should be 0 got %d\n", numChildren
);
518 SetWindowLongA( test
, GWL_STYLE
, (GetWindowLongA( test
, GWL_STYLE
) & ~WS_POPUP
) | WS_CHILD
);
519 ret
= SetParent( test
, owner
);
520 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
523 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
524 "EnumChildWindows should have returned TRUE\n" );
525 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
527 child
= create_tool_window( WS_CHILD
, owner
);
529 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
530 "EnumChildWindows should have returned FALSE\n" );
531 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
532 DestroyWindow( child
);
534 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, owner
);
535 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
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 ret
= SetParent( child
, owner
);
542 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
543 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
545 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
546 "EnumChildWindows should have returned FALSE\n" );
547 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
549 ret
= SetParent( child
, NULL
);
550 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
551 ok( ret
== owner
, "SetParent return value %p expected %p\n", ret
, owner
);
553 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
554 "EnumChildWindows should have returned TRUE\n" );
555 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
557 /* even GW_OWNER == owner it's still a desktop's child */
558 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
559 "EnumChildWindows should have found %p and returned FALSE\n", child
);
561 DestroyWindow( child
);
562 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, NULL
);
564 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
565 "EnumChildWindows should have found %p and returned FALSE\n", child
);
567 DestroyWindow( child
);
568 DestroyWindow( test
);
569 DestroyWindow( owner
);
572 static BOOL CALLBACK
enum_proc( HWND hwnd
, LPARAM lParam
)
575 if (*(LPINT
)lParam
> 2) return FALSE
;
578 static DWORD CALLBACK
enum_thread( void *arg
)
585 PeekMessage( &msg
, 0, 0, 0, PM_NOREMOVE
); /* make sure we have a message queue */
588 ret
= EnumThreadWindows( GetCurrentThreadId(), enum_proc
, (LPARAM
)&count
);
589 ok( ret
, "EnumThreadWindows should have returned TRUE\n" );
590 ok( count
== 0, "count should be 0 got %d\n", count
);
592 hwnd
[0] = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", WS_POPUP
,
593 0, 0, 100, 100, 0, 0, 0, NULL
);
595 ret
= EnumThreadWindows( GetCurrentThreadId(), enum_proc
, (LPARAM
)&count
);
596 ok( ret
, "EnumThreadWindows should have returned TRUE\n" );
597 if (count
!= 2) /* Vista gives us two windows for the price of one */
599 ok( count
== 1, "count should be 1 got %d\n", count
);
600 hwnd
[2] = CreateWindowExA(0, "ToolWindowClass", "Tool window 2", WS_POPUP
,
601 0, 0, 100, 100, 0, 0, 0, NULL
);
605 hwnd
[1] = CreateWindowExA(0, "ToolWindowClass", "Tool window 3", WS_POPUP
,
606 0, 0, 100, 100, 0, 0, 0, NULL
);
608 ret
= EnumThreadWindows( GetCurrentThreadId(), enum_proc
, (LPARAM
)&count
);
609 ok( !ret
, "EnumThreadWindows should have returned FALSE\n" );
610 ok( count
== 3, "count should be 3 got %d\n", count
);
612 if (hwnd
[2]) DestroyWindow(hwnd
[2]);
613 DestroyWindow(hwnd
[1]);
614 DestroyWindow(hwnd
[0]);
618 /* test EnumThreadWindows in a separate thread */
619 static void test_enum_thread_windows(void)
622 HANDLE handle
= CreateThread( NULL
, 0, enum_thread
, 0, 0, &id
);
623 ok( !WaitForSingleObject( handle
, 10000 ), "wait failed\n" );
624 CloseHandle( handle
);
627 static LRESULT WINAPI
main_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
631 case WM_GETMINMAXINFO
:
633 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
635 trace("WM_GETMINMAXINFO: hwnd %p, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
636 dump_minmax_info( minmax
);
637 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
640 case WM_WINDOWPOSCHANGING
:
642 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
643 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
644 trace("main: WM_WINDOWPOSCHANGING %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
645 winpos
->hwnd
, winpos
->hwndInsertAfter
,
646 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
647 if (!(winpos
->flags
& SWP_NOMOVE
))
649 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
650 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
652 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
653 if (!(winpos
->flags
& SWP_NOSIZE
) && !is_win9x
)
655 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
656 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
660 case WM_WINDOWPOSCHANGED
:
663 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
664 trace("main: WM_WINDOWPOSCHANGED %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
665 winpos
->hwnd
, winpos
->hwndInsertAfter
,
666 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
667 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
668 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
670 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
671 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
673 GetWindowRect(hwnd
, &rc1
);
674 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
675 /* note: winpos coordinates are relative to parent */
676 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
679 /* Uncomment this once the test succeeds in all cases */
680 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
681 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
683 GetClientRect(hwnd
, &rc2
);
684 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
685 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
686 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
687 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
693 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
694 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
696 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
697 if (got_getminmaxinfo
)
698 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
700 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
701 ok(got_getminmaxinfo
, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
703 ok(!got_getminmaxinfo
, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
707 if (test_lbuttondown_flag
)
709 ShowWindow((HWND
)wparam
, SW_SHOW
);
710 flush_events( FALSE
);
715 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
718 static LRESULT WINAPI
tool_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
722 case WM_GETMINMAXINFO
:
724 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
726 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
727 dump_minmax_info( minmax
);
728 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
733 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
734 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
736 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
737 if (got_getminmaxinfo
)
738 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
740 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
741 ok(got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
743 ok(!got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
748 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
751 static BOOL
RegisterWindowClasses(void)
755 cls
.style
= CS_DBLCLKS
;
756 cls
.lpfnWndProc
= main_window_procA
;
759 cls
.hInstance
= GetModuleHandleA(0);
761 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
762 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
763 cls
.lpszMenuName
= NULL
;
764 cls
.lpszClassName
= "MainWindowClass";
766 if(!RegisterClassA(&cls
)) return FALSE
;
769 cls
.lpfnWndProc
= tool_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
= "ToolWindowClass";
779 if(!RegisterClassA(&cls
)) return FALSE
;
784 static void verify_window_info(const char *hook
, HWND hwnd
, const WINDOWINFO
*info
)
786 RECT rcWindow
, rcClient
;
789 ok(IsWindow(hwnd
), "bad window handle %p in hook %s\n", hwnd
, hook
);
791 GetWindowRect(hwnd
, &rcWindow
);
792 ok(EqualRect(&rcWindow
, &info
->rcWindow
), "wrong rcWindow for %p in hook %s\n", hwnd
, hook
);
794 GetClientRect(hwnd
, &rcClient
);
795 /* translate to screen coordinates */
796 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rcClient
, 2);
797 ok(EqualRect(&rcClient
, &info
->rcClient
), "wrong rcClient for %p in hook %s\n", hwnd
, hook
);
799 ok(info
->dwStyle
== (DWORD
)GetWindowLongA(hwnd
, GWL_STYLE
),
800 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
801 info
->dwStyle
, GetWindowLongA(hwnd
, GWL_STYLE
), hwnd
, hook
);
802 /* Windows reports some undocumented exstyles in WINDOWINFO, but
803 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
805 ok((info
->dwExStyle
& ~0xe0000800) == (DWORD
)GetWindowLongA(hwnd
, GWL_EXSTYLE
),
806 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
807 info
->dwExStyle
, GetWindowLongA(hwnd
, GWL_EXSTYLE
), hwnd
, hook
);
808 status
= (GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0;
809 if (GetForegroundWindow())
810 ok(info
->dwWindowStatus
== status
, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
811 info
->dwWindowStatus
, status
, GetActiveWindow(), GetForegroundWindow(), hook
);
813 /* win2k and XP return broken border info in GetWindowInfo most of
814 * the time, so there is no point in testing it.
818 ok(info
->cxWindowBorders
== (unsigned)(rcClient
.left
- rcWindow
.left
),
819 "wrong cxWindowBorders %d != %d\n", info
->cxWindowBorders
, rcClient
.left
- rcWindow
.left
);
820 border
= min(rcWindow
.bottom
- rcClient
.bottom
, rcClient
.top
- rcWindow
.top
);
821 ok(info
->cyWindowBorders
== border
,
822 "wrong cyWindowBorders %d != %d\n", info
->cyWindowBorders
, border
);
824 ok(info
->atomWindowType
== GetClassLongA(hwnd
, GCW_ATOM
), "wrong atomWindowType for %p in hook %s\n",
826 ok(info
->wCreatorVersion
== 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
827 info
->wCreatorVersion
== 0x0500 /* Vista */,
828 "wrong wCreatorVersion %04x for %p in hook %s\n", info
->wCreatorVersion
, hwnd
, hook
);
831 static void FixedAdjustWindowRectEx(RECT
* rc
, LONG style
, BOOL menu
, LONG exstyle
)
833 AdjustWindowRectEx(rc
, style
, menu
, exstyle
);
834 /* AdjustWindowRectEx does not include scroll bars */
835 if (style
& WS_VSCROLL
)
837 if(exstyle
& WS_EX_LEFTSCROLLBAR
)
838 rc
->left
-= GetSystemMetrics(SM_CXVSCROLL
);
840 rc
->right
+= GetSystemMetrics(SM_CXVSCROLL
);
842 if (style
& WS_HSCROLL
)
843 rc
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
846 static void test_nonclient_area(HWND hwnd
)
848 DWORD style
, exstyle
;
849 RECT rc_window
, rc_client
, rc
;
851 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
854 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
855 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
856 menu
= !(style
& WS_CHILD
) && GetMenu(hwnd
) != 0;
858 GetWindowRect(hwnd
, &rc_window
);
859 GetClientRect(hwnd
, &rc_client
);
861 /* avoid some cases when things go wrong */
862 if (IsRectEmpty(&rc_window
) || IsRectEmpty(&rc_client
) ||
863 rc_window
.right
> 32768 || rc_window
.bottom
> 32768) return;
865 CopyRect(&rc
, &rc_client
);
866 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc
, 2);
867 FixedAdjustWindowRectEx(&rc
, style
, menu
, exstyle
);
869 ok(EqualRect(&rc
, &rc_window
),
870 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
871 style
, exstyle
, menu
, rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
,
872 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
875 CopyRect(&rc
, &rc_window
);
876 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
877 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
878 ok(EqualRect(&rc
, &rc_client
),
879 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
880 style
, exstyle
, menu
, rc_client
.left
, rc_client
.top
, rc_client
.right
, rc_client
.bottom
,
881 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
883 /* NULL rectangle shouldn't crash */
884 ret
= DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, 0);
885 ok(ret
== 0, "NULL rectangle returned %ld instead of 0\n", ret
);
887 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
891 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
892 SetRect(&rc_client
, 0, 0, 250, 150);
893 CopyRect(&rc_window
, &rc_client
);
894 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc_window
, 2);
895 FixedAdjustWindowRectEx(&rc_window
, style
, menu
, exstyle
);
897 CopyRect(&rc
, &rc_window
);
898 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
899 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
900 ok(EqualRect(&rc
, &rc_client
),
901 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
902 style
, exstyle
, menu
, rc_client
.left
, rc_client
.top
, rc_client
.right
, rc_client
.bottom
,
903 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
906 static LRESULT CALLBACK
cbt_hook_proc(int nCode
, WPARAM wParam
, LPARAM lParam
)
908 static const char *CBT_code_name
[10] = {
919 const char *code_name
= (nCode
>= 0 && nCode
<= HCBT_SETFOCUS
) ? CBT_code_name
[nCode
] : "Unknown";
920 HWND hwnd
= (HWND
)wParam
;
926 static const RECT rc_null
;
929 CBT_CREATEWNDA
*createwnd
= (CBT_CREATEWNDA
*)lParam
;
930 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
931 hwnd
, createwnd
->lpcs
->hwndParent
, createwnd
->lpcs
->style
);
932 ok(createwnd
->hwndInsertAfter
== HWND_TOP
, "hwndInsertAfter should be always HWND_TOP\n");
937 info
.cbSize
= sizeof(WINDOWINFO
);
938 ok(pGetWindowInfo(hwnd
, &info
), "GetWindowInfo should not fail\n");
939 verify_window_info(code_name
, hwnd
, &info
);
942 /* WS_VISIBLE should be turned off yet */
943 style
= createwnd
->lpcs
->style
& ~WS_VISIBLE
;
944 ok(style
== GetWindowLongA(hwnd
, GWL_STYLE
),
945 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
946 GetWindowLongA(hwnd
, GWL_STYLE
), style
);
950 /* Uncomment this once the test succeeds in all cases */
951 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
953 ok(GetParent(hwnd
) == hwndMessage
,
954 "wrong result from GetParent %p: message window %p\n",
955 GetParent(hwnd
), hwndMessage
);
958 ok(!GetParent(hwnd
), "GetParent should return 0 at this point\n");
960 ok(!GetWindow(hwnd
, GW_OWNER
), "GW_OWNER should be set to 0 at this point\n");
964 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
965 * Win9x still has them set to 0.
967 ok(GetWindow(hwnd
, GW_HWNDFIRST
) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
968 ok(GetWindow(hwnd
, GW_HWNDLAST
) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
970 ok(!GetWindow(hwnd
, GW_HWNDPREV
), "GW_HWNDPREV should be set to 0 at this point\n");
971 ok(!GetWindow(hwnd
, GW_HWNDNEXT
), "GW_HWNDNEXT should be set to 0 at this point\n");
975 /* Uncomment this once the test succeeds in all cases */
978 ok(pGetAncestor(hwnd
, GA_PARENT
) == hwndMessage
, "GA_PARENT should be set to hwndMessage at this point\n");
979 ok(pGetAncestor(hwnd
, GA_ROOT
) == hwnd
,
980 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd
, GA_ROOT
), hwnd
);
982 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
983 ok(pGetAncestor(hwnd
, GA_ROOTOWNER
) == hwndMessage
,
984 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
986 ok(pGetAncestor(hwnd
, GA_ROOTOWNER
) == hwnd
,
987 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd
, GA_ROOTOWNER
), hwnd
);
990 ok(GetWindowRect(hwnd
, &rc
), "GetWindowRect failed\n");
991 ok(EqualRect(&rc
, &rc_null
), "window rect should be set to 0 HCBT_CREATEWND\n");
992 ok(GetClientRect(hwnd
, &rc
), "GetClientRect failed\n");
993 ok(EqualRect(&rc
, &rc_null
), "client rect should be set to 0 on HCBT_CREATEWND\n");
1001 if (pGetWindowInfo
&& IsWindow(hwnd
))
1005 /* Win98 actually does check the info.cbSize and doesn't allow
1006 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
1007 * WinXP do not check it at all.
1009 info
.cbSize
= sizeof(WINDOWINFO
);
1010 ok(pGetWindowInfo(hwnd
, &info
), "GetWindowInfo should not fail\n");
1011 verify_window_info(code_name
, hwnd
, &info
);
1014 /* on HCBT_DESTROYWND window state is undefined */
1015 case HCBT_DESTROYWND
:
1016 trace( "HCBT_DESTROYWND: hwnd %p\n", hwnd
);
1022 return CallNextHookEx(hhook
, nCode
, wParam
, lParam
);
1025 static void test_shell_window(void)
1029 HMODULE hinst
, hUser32
;
1030 BOOL (WINAPI
*SetShellWindow
)(HWND
);
1031 BOOL (WINAPI
*SetShellWindowEx
)(HWND
, HWND
);
1032 HWND hwnd1
, hwnd2
, hwnd3
, hwnd4
, hwnd5
;
1033 HWND shellWindow
, nextWnd
;
1035 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE
))
1037 trace("Skipping shell window test on Win9x\n");
1041 shellWindow
= GetShellWindow();
1042 hinst
= GetModuleHandle(0);
1043 hUser32
= GetModuleHandleA("user32");
1045 SetShellWindow
= (void *)GetProcAddress(hUser32
, "SetShellWindow");
1046 SetShellWindowEx
= (void *)GetProcAddress(hUser32
, "SetShellWindowEx");
1048 trace("previous shell window: %p\n", shellWindow
);
1054 GetWindowThreadProcessId(shellWindow
, &pid
);
1055 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, pid
);
1058 skip( "cannot get access to shell process\n" );
1062 SetLastError(0xdeadbeef);
1063 ret
= DestroyWindow(shellWindow
);
1064 error
= GetLastError();
1066 ok(!ret
, "DestroyWindow(shellWindow)\n");
1067 /* passes on Win XP, but not on Win98 */
1068 ok(error
==ERROR_ACCESS_DENIED
|| error
== 0xdeadbeef,
1069 "got %u after DestroyWindow(shellWindow)\n", error
);
1071 /* close old shell instance */
1072 ret
= TerminateProcess(hProcess
, 0);
1073 ok(ret
, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1074 WaitForSingleObject(hProcess
, INFINITE
); /* wait for termination */
1075 CloseHandle(hProcess
);
1078 hwnd1
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst
, 0);
1079 trace("created window 1: %p\n", hwnd1
);
1081 ret
= SetShellWindow(hwnd1
);
1082 ok(ret
, "first call to SetShellWindow(hwnd1)\n");
1083 shellWindow
= GetShellWindow();
1084 ok(shellWindow
==hwnd1
, "wrong shell window: %p\n", shellWindow
);
1086 ret
= SetShellWindow(hwnd1
);
1087 ok(!ret
, "second call to SetShellWindow(hwnd1)\n");
1089 ret
= SetShellWindow(0);
1090 error
= GetLastError();
1091 /* passes on Win XP, but not on Win98
1092 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1093 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1095 ret
= SetShellWindow(hwnd1
);
1096 /* passes on Win XP, but not on Win98
1097 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1099 SetWindowLong(hwnd1
, GWL_EXSTYLE
, GetWindowLong(hwnd1
,GWL_EXSTYLE
)|WS_EX_TOPMOST
);
1100 ret
= GetWindowLong(hwnd1
,GWL_EXSTYLE
)&WS_EX_TOPMOST
? TRUE
: FALSE
;
1101 ok(!ret
, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1103 ret
= DestroyWindow(hwnd1
);
1104 ok(ret
, "DestroyWindow(hwnd1)\n");
1106 hwnd2
= CreateWindowEx(WS_EX_TOPMOST
, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst
, 0);
1107 trace("created window 2: %p\n", hwnd2
);
1108 ret
= SetShellWindow(hwnd2
);
1109 ok(!ret
, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1111 hwnd3
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst
, 0);
1112 trace("created window 3: %p\n", hwnd3
);
1114 hwnd4
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst
, 0);
1115 trace("created window 4: %p\n", hwnd4
);
1117 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1118 ok(nextWnd
==hwnd3
, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd
);
1120 ret
= SetShellWindow(hwnd4
);
1121 ok(ret
, "SetShellWindow(hwnd4)\n");
1122 shellWindow
= GetShellWindow();
1123 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1125 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1126 ok(nextWnd
==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd
);
1128 ret
= SetWindowPos(hwnd4
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1129 ok(ret
, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1131 ret
= SetWindowPos(hwnd4
, hwnd3
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1132 ok(ret
, "SetWindowPos(hwnd4, hwnd3\n");
1134 ret
= SetShellWindow(hwnd3
);
1135 ok(!ret
, "SetShellWindow(hwnd3)\n");
1136 shellWindow
= GetShellWindow();
1137 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1139 hwnd5
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst
, 0);
1140 trace("created window 5: %p\n", hwnd5
);
1141 ret
= SetWindowPos(hwnd4
, hwnd5
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1142 ok(ret
, "SetWindowPos(hwnd4, hwnd5)\n");
1146 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1147 ok(nextWnd
==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd
);
1150 /* destroy test windows */
1151 DestroyWindow(hwnd2
);
1152 DestroyWindow(hwnd3
);
1153 DestroyWindow(hwnd4
);
1154 DestroyWindow(hwnd5
);
1157 /************** MDI test ****************/
1159 static char mdi_lParam_test_message
[] = "just a test string";
1161 static void test_MDI_create(HWND parent
, HWND mdi_client
, INT_PTR first_id
)
1163 MDICREATESTRUCTA mdi_cs
;
1166 static const WCHAR classW
[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1167 static const WCHAR titleW
[] = {'M','D','I',' ','c','h','i','l','d',0};
1168 BOOL isWin9x
= FALSE
;
1170 mdi_cs
.szClass
= "MDI_child_Class_1";
1171 mdi_cs
.szTitle
= "MDI child";
1172 mdi_cs
.hOwner
= GetModuleHandle(0);
1173 mdi_cs
.x
= CW_USEDEFAULT
;
1174 mdi_cs
.y
= CW_USEDEFAULT
;
1175 mdi_cs
.cx
= CW_USEDEFAULT
;
1176 mdi_cs
.cy
= CW_USEDEFAULT
;
1178 mdi_cs
.lParam
= (LPARAM
)mdi_lParam_test_message
;
1179 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1180 ok(mdi_child
!= 0, "MDI child creation failed\n");
1181 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1182 ok(id
== first_id
, "wrong child id %ld\n", id
);
1183 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1184 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1186 mdi_cs
.style
= 0x7fffffff; /* without WS_POPUP */
1187 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1188 ok(mdi_child
!= 0, "MDI child creation failed\n");
1189 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1190 ok(id
== first_id
, "wrong child id %ld\n", id
);
1191 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1192 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1194 mdi_cs
.style
= 0xffffffff; /* with WS_POPUP */
1195 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1196 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1198 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1202 ok(mdi_child
!= 0, "MDI child creation failed\n");
1203 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1204 ok(id
== first_id
, "wrong child id %ld\n", id
);
1205 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1206 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1209 /* test MDICREATESTRUCT A<->W mapping */
1210 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1212 mdi_cs
.szClass
= (LPCSTR
)classW
;
1213 mdi_cs
.szTitle
= (LPCSTR
)titleW
;
1214 SetLastError(0xdeadbeef);
1215 mdi_child
= (HWND
)SendMessageW(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1218 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1221 ok(mdi_child
!= 0, "MDI child creation failed\n");
1225 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1226 ok(id
== first_id
, "wrong child id %ld\n", id
);
1227 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1228 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1231 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1233 CW_USEDEFAULT
, CW_USEDEFAULT
,
1234 CW_USEDEFAULT
, CW_USEDEFAULT
,
1235 mdi_client
, GetModuleHandle(0),
1236 (LPARAM
)mdi_lParam_test_message
);
1237 ok(mdi_child
!= 0, "MDI child creation failed\n");
1238 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1239 ok(id
== first_id
, "wrong child id %ld\n", id
);
1240 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1241 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1243 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1244 0x7fffffff, /* without WS_POPUP */
1245 CW_USEDEFAULT
, CW_USEDEFAULT
,
1246 CW_USEDEFAULT
, CW_USEDEFAULT
,
1247 mdi_client
, GetModuleHandle(0),
1248 (LPARAM
)mdi_lParam_test_message
);
1249 ok(mdi_child
!= 0, "MDI child creation failed\n");
1250 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1251 ok(id
== first_id
, "wrong child id %ld\n", id
);
1252 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1253 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1255 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1256 0xffffffff, /* with WS_POPUP */
1257 CW_USEDEFAULT
, CW_USEDEFAULT
,
1258 CW_USEDEFAULT
, CW_USEDEFAULT
,
1259 mdi_client
, GetModuleHandle(0),
1260 (LPARAM
)mdi_lParam_test_message
);
1261 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1263 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1267 ok(mdi_child
!= 0, "MDI child creation failed\n");
1268 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1269 ok(id
== first_id
, "wrong child id %ld\n", id
);
1270 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1271 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1274 /* test MDICREATESTRUCT A<->W mapping */
1275 SetLastError(0xdeadbeef);
1276 mdi_child
= CreateMDIWindowW(classW
, titleW
,
1278 CW_USEDEFAULT
, CW_USEDEFAULT
,
1279 CW_USEDEFAULT
, CW_USEDEFAULT
,
1280 mdi_client
, GetModuleHandle(0),
1281 (LPARAM
)mdi_lParam_test_message
);
1284 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1287 ok(mdi_child
!= 0, "MDI child creation failed\n");
1291 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1292 ok(id
== first_id
, "wrong child id %ld\n", id
);
1293 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1294 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1297 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1299 CW_USEDEFAULT
, CW_USEDEFAULT
,
1300 CW_USEDEFAULT
, CW_USEDEFAULT
,
1301 mdi_client
, 0, GetModuleHandle(0),
1302 mdi_lParam_test_message
);
1303 ok(mdi_child
!= 0, "MDI child creation failed\n");
1304 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1305 ok(id
== first_id
, "wrong child id %ld\n", id
);
1306 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1307 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1309 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1310 0x7fffffff, /* without WS_POPUP */
1311 CW_USEDEFAULT
, CW_USEDEFAULT
,
1312 CW_USEDEFAULT
, CW_USEDEFAULT
,
1313 mdi_client
, 0, GetModuleHandle(0),
1314 mdi_lParam_test_message
);
1315 ok(mdi_child
!= 0, "MDI child creation failed\n");
1316 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1317 ok(id
== first_id
, "wrong child id %ld\n", id
);
1318 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1319 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1321 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1322 0xffffffff, /* with WS_POPUP */
1323 CW_USEDEFAULT
, CW_USEDEFAULT
,
1324 CW_USEDEFAULT
, CW_USEDEFAULT
,
1325 mdi_client
, 0, GetModuleHandle(0),
1326 mdi_lParam_test_message
);
1327 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1329 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1333 ok(mdi_child
!= 0, "MDI child creation failed\n");
1334 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1335 ok(id
== first_id
, "wrong child id %ld\n", id
);
1336 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1337 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1340 /* test MDICREATESTRUCT A<->W mapping */
1341 SetLastError(0xdeadbeef);
1342 mdi_child
= CreateWindowExW(WS_EX_MDICHILD
, classW
, titleW
,
1344 CW_USEDEFAULT
, CW_USEDEFAULT
,
1345 CW_USEDEFAULT
, CW_USEDEFAULT
,
1346 mdi_client
, 0, GetModuleHandle(0),
1347 mdi_lParam_test_message
);
1350 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1353 ok(mdi_child
!= 0, "MDI child creation failed\n");
1357 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1358 ok(id
== first_id
, "wrong child id %ld\n", id
);
1359 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1360 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1363 /* This test fails on Win9x */
1366 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_2", "MDI child",
1368 CW_USEDEFAULT
, CW_USEDEFAULT
,
1369 CW_USEDEFAULT
, CW_USEDEFAULT
,
1370 parent
, 0, GetModuleHandle(0),
1371 mdi_lParam_test_message
);
1372 ok(!mdi_child
, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1375 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1376 WS_CHILD
, /* without WS_POPUP */
1377 CW_USEDEFAULT
, CW_USEDEFAULT
,
1378 CW_USEDEFAULT
, CW_USEDEFAULT
,
1379 mdi_client
, 0, GetModuleHandle(0),
1380 mdi_lParam_test_message
);
1381 ok(mdi_child
!= 0, "MDI child creation failed\n");
1382 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1383 ok(id
== 0, "wrong child id %ld\n", id
);
1384 DestroyWindow(mdi_child
);
1386 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1387 WS_CHILD
| WS_POPUP
, /* with WS_POPUP */
1388 CW_USEDEFAULT
, CW_USEDEFAULT
,
1389 CW_USEDEFAULT
, CW_USEDEFAULT
,
1390 mdi_client
, 0, GetModuleHandle(0),
1391 mdi_lParam_test_message
);
1392 ok(mdi_child
!= 0, "MDI child creation failed\n");
1393 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1394 ok(id
== 0, "wrong child id %ld\n", id
);
1395 DestroyWindow(mdi_child
);
1397 /* maximized child */
1398 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1399 WS_CHILD
| WS_MAXIMIZE
,
1400 CW_USEDEFAULT
, CW_USEDEFAULT
,
1401 CW_USEDEFAULT
, CW_USEDEFAULT
,
1402 mdi_client
, 0, GetModuleHandle(0),
1403 mdi_lParam_test_message
);
1404 ok(mdi_child
!= 0, "MDI child creation failed\n");
1405 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1406 ok(id
== 0, "wrong child id %ld\n", id
);
1407 DestroyWindow(mdi_child
);
1409 trace("Creating maximized child with a caption\n");
1410 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1411 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
,
1412 CW_USEDEFAULT
, CW_USEDEFAULT
,
1413 CW_USEDEFAULT
, CW_USEDEFAULT
,
1414 mdi_client
, 0, GetModuleHandle(0),
1415 mdi_lParam_test_message
);
1416 ok(mdi_child
!= 0, "MDI child creation failed\n");
1417 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1418 ok(id
== 0, "wrong child id %ld\n", id
);
1419 DestroyWindow(mdi_child
);
1421 trace("Creating maximized child with a caption and a thick frame\n");
1422 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1423 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
| WS_THICKFRAME
,
1424 CW_USEDEFAULT
, CW_USEDEFAULT
,
1425 CW_USEDEFAULT
, CW_USEDEFAULT
,
1426 mdi_client
, 0, GetModuleHandle(0),
1427 mdi_lParam_test_message
);
1428 ok(mdi_child
!= 0, "MDI child creation failed\n");
1429 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1430 ok(id
== 0, "wrong child id %ld\n", id
);
1431 DestroyWindow(mdi_child
);
1434 /**********************************************************************
1435 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1437 * Note: The rule here is that client rect of the maximized MDI child
1438 * is equal to the client rect of the MDI client window.
1440 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
1444 GetClientRect( client
, &rect
);
1445 AdjustWindowRectEx( &rect
, GetWindowLongA( hwnd
, GWL_STYLE
),
1446 0, GetWindowLongA( hwnd
, GWL_EXSTYLE
));
1448 rect
.right
-= rect
.left
;
1449 rect
.bottom
-= rect
.top
;
1450 lpMinMax
->ptMaxSize
.x
= rect
.right
;
1451 lpMinMax
->ptMaxSize
.y
= rect
.bottom
;
1453 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
1454 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
1456 trace("max rect (%d,%d - %d, %d)\n",
1457 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1460 static LRESULT WINAPI
mdi_child_wnd_proc_1(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1467 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1468 MDICREATESTRUCTA
*mdi_cs
= cs
->lpCreateParams
;
1470 ok(cs
->dwExStyle
& WS_EX_MDICHILD
, "WS_EX_MDICHILD should be set\n");
1471 ok(mdi_cs
->lParam
== (LPARAM
)mdi_lParam_test_message
, "wrong mdi_cs->lParam\n");
1473 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_1"), "wrong class name\n");
1474 ok(!lstrcmpA(cs
->lpszClass
, mdi_cs
->szClass
), "class name does not match\n");
1475 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1476 ok(!lstrcmpA(cs
->lpszName
, mdi_cs
->szTitle
), "title does not match\n");
1477 ok(cs
->hInstance
== mdi_cs
->hOwner
, "%p != %p\n", cs
->hInstance
, mdi_cs
->hOwner
);
1479 /* MDICREATESTRUCT should have original values */
1480 ok(mdi_cs
->style
== 0 || mdi_cs
->style
== 0x7fffffff || mdi_cs
->style
== 0xffffffff,
1481 "mdi_cs->style does not match (%08x)\n", mdi_cs
->style
);
1482 ok(mdi_cs
->x
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->x
);
1483 ok(mdi_cs
->y
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->y
);
1484 ok(mdi_cs
->cx
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cx
);
1485 ok(mdi_cs
->cy
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cy
);
1487 /* CREATESTRUCT should have fixed values */
1488 ok(cs
->x
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->x
);
1489 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1491 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1492 ok(cs
->cx
!= CW_USEDEFAULT
&& cs
->cx
!= 0, "%d == CW_USEDEFAULT\n", cs
->cx
);
1493 ok(cs
->cy
!= CW_USEDEFAULT
&& cs
->cy
!= 0, "%d == CW_USEDEFAULT\n", cs
->cy
);
1495 ok(!(cs
->style
& WS_POPUP
), "WS_POPUP is not allowed\n");
1497 if (GetWindowLongA(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1499 LONG style
= mdi_cs
->style
| WS_CHILD
| WS_CLIPSIBLINGS
;
1500 ok(cs
->style
== style
,
1501 "cs->style does not match (%08x)\n", cs
->style
);
1505 LONG style
= mdi_cs
->style
;
1507 style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1508 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1509 ok(cs
->style
== style
,
1510 "cs->style does not match (%08x)\n", cs
->style
);
1515 case WM_GETMINMAXINFO
:
1517 HWND client
= GetParent(hwnd
);
1519 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1520 MINMAXINFO my_minmax
;
1521 LONG style
, exstyle
;
1523 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1524 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1526 GetWindowRect(client
, &rc
);
1527 trace("MDI client %p window size = (%d x %d)\n", client
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1528 GetClientRect(client
, &rc
);
1529 trace("MDI client %p client size = (%d x %d)\n", client
, rc
.right
, rc
.bottom
);
1530 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN
),
1531 GetSystemMetrics(SM_CYSCREEN
));
1533 GetClientRect(client
, &rc
);
1534 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1535 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1536 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1537 trace("MDI child: calculated max window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1538 dump_minmax_info( minmax
);
1540 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1541 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1542 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1543 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1545 DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1547 trace("DefMDIChildProc returned:\n");
1548 dump_minmax_info( minmax
);
1550 MDI_ChildGetMinMaxInfo(client
, hwnd
, &my_minmax
);
1551 ok(minmax
->ptMaxSize
.x
== my_minmax
.ptMaxSize
.x
, "default width of maximized child %d != %d\n",
1552 minmax
->ptMaxSize
.x
, my_minmax
.ptMaxSize
.x
);
1553 ok(minmax
->ptMaxSize
.y
== my_minmax
.ptMaxSize
.y
, "default height of maximized child %d != %d\n",
1554 minmax
->ptMaxSize
.y
, my_minmax
.ptMaxSize
.y
);
1559 case WM_MDIACTIVATE
:
1561 HWND active
, client
= GetParent(hwnd
);
1562 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1563 active
= (HWND
)SendMessageA(client
, WM_MDIGETACTIVE
, 0, 0);
1564 if (hwnd
== (HWND
)lparam
) /* if we are being activated */
1565 ok (active
== (HWND
)lparam
, "new active %p != active %p\n", (HWND
)lparam
, active
);
1567 ok (active
== (HWND
)wparam
, "old active %p != active %p\n", (HWND
)wparam
, active
);
1571 return DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1574 static LRESULT WINAPI
mdi_child_wnd_proc_2(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1581 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1583 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg
== WM_NCCREATE
) ? "WM_NCCREATE" : "WM_CREATE",
1584 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
1586 ok(!(cs
->dwExStyle
& WS_EX_MDICHILD
), "WS_EX_MDICHILD should not be set\n");
1587 ok(cs
->lpCreateParams
== mdi_lParam_test_message
, "wrong cs->lpCreateParams\n");
1589 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_2"), "wrong class name\n");
1590 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1592 /* CREATESTRUCT should have fixed values */
1593 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1595 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1596 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1598 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1599 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1600 while Win95, Win2k, WinXP do. */
1601 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1602 ok(cs
->cy
== 0, "%d != 0\n", cs
->cy
);
1606 case WM_GETMINMAXINFO
:
1608 HWND parent
= GetParent(hwnd
);
1610 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1611 LONG style
, exstyle
;
1613 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1614 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1616 GetClientRect(parent
, &rc
);
1617 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent
, rc
.right
, rc
.bottom
);
1619 GetClientRect(parent
, &rc
);
1620 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1621 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1622 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1623 dump_minmax_info( minmax
);
1625 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1626 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1627 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1628 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1632 case WM_WINDOWPOSCHANGED
:
1634 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1637 GetWindowRect(hwnd
, &rc1
);
1638 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1639 /* note: winpos coordinates are relative to parent */
1640 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1641 ok(EqualRect(&rc1
, &rc2
), "rects do not match, window=(%d,%d)-(%d,%d) pos=(%d,%d)-(%d,%d)\n",
1642 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
1643 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1644 GetWindowRect(hwnd
, &rc1
);
1645 GetClientRect(hwnd
, &rc2
);
1646 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1647 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1648 ok(EqualRect(&rc1
, &rc2
), "rects do not match, window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1649 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
1650 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1653 case WM_WINDOWPOSCHANGING
:
1655 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1656 WINDOWPOS my_winpos
= *winpos
;
1658 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1659 (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
1660 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1661 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1663 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1665 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1666 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1667 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1668 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1673 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1676 static LRESULT WINAPI
mdi_main_wnd_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1678 static HWND mdi_client
;
1684 CLIENTCREATESTRUCT client_cs
;
1687 GetClientRect(hwnd
, &rc
);
1689 client_cs
.hWindowMenu
= 0;
1690 client_cs
.idFirstChild
= 1;
1692 /* MDIClient without MDIS_ALLCHILDSTYLES */
1693 mdi_client
= CreateWindowExA(0, "mdiclient",
1695 WS_CHILD
/*| WS_VISIBLE*/,
1696 /* tests depend on a not zero MDIClient size */
1697 0, 0, rc
.right
, rc
.bottom
,
1698 hwnd
, 0, GetModuleHandle(0),
1701 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1702 DestroyWindow(mdi_client
);
1704 /* MDIClient with MDIS_ALLCHILDSTYLES */
1705 mdi_client
= CreateWindowExA(0, "mdiclient",
1707 WS_CHILD
| MDIS_ALLCHILDSTYLES
/*| WS_VISIBLE*/,
1708 /* tests depend on a not zero MDIClient size */
1709 0, 0, rc
.right
, rc
.bottom
,
1710 hwnd
, 0, GetModuleHandle(0),
1713 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1714 DestroyWindow(mdi_client
);
1718 case WM_WINDOWPOSCHANGED
:
1720 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1723 GetWindowRect(hwnd
, &rc1
);
1724 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1725 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1726 /* note: winpos coordinates are relative to parent */
1727 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1728 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1729 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1731 GetWindowRect(hwnd
, &rc1
);
1732 GetClientRect(hwnd
, &rc2
);
1733 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1734 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1735 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1738 case WM_WINDOWPOSCHANGING
:
1740 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1741 WINDOWPOS my_winpos
= *winpos
;
1743 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1744 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1745 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1746 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1748 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1750 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1751 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1752 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1754 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1755 "DefWindowProc should not change WINDOWPOS values\n");
1764 return DefFrameProcA(hwnd
, mdi_client
, msg
, wparam
, lparam
);
1767 static BOOL
mdi_RegisterWindowClasses(void)
1772 cls
.lpfnWndProc
= mdi_main_wnd_procA
;
1775 cls
.hInstance
= GetModuleHandleA(0);
1777 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
1778 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1779 cls
.lpszMenuName
= NULL
;
1780 cls
.lpszClassName
= "MDI_parent_Class";
1781 if(!RegisterClassA(&cls
)) return FALSE
;
1783 cls
.lpfnWndProc
= mdi_child_wnd_proc_1
;
1784 cls
.lpszClassName
= "MDI_child_Class_1";
1785 if(!RegisterClassA(&cls
)) return FALSE
;
1787 cls
.lpfnWndProc
= mdi_child_wnd_proc_2
;
1788 cls
.lpszClassName
= "MDI_child_Class_2";
1789 if(!RegisterClassA(&cls
)) return FALSE
;
1794 static void test_mdi(void)
1799 if (!mdi_RegisterWindowClasses()) assert(0);
1801 mdi_hwndMain
= CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1802 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
1803 WS_MAXIMIZEBOX
/*| WS_VISIBLE*/,
1804 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1805 GetDesktopWindow(), 0,
1806 GetModuleHandle(0), NULL
);
1807 assert(mdi_hwndMain
);
1809 while(GetMessage(&msg, 0, 0, 0))
1811 TranslateMessage(&msg);
1812 DispatchMessage(&msg);
1815 DestroyWindow(mdi_hwndMain
);
1818 static void test_icons(void)
1822 HICON icon
= LoadIconA(0, IDI_APPLICATION
);
1823 HICON icon2
= LoadIconA(0, IDI_QUESTION
);
1824 HICON small_icon
= LoadImageA(0, IDI_APPLICATION
, IMAGE_ICON
,
1825 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
1828 cls
.cbSize
= sizeof(cls
);
1830 cls
.lpfnWndProc
= DefWindowProcA
;
1834 cls
.hIcon
= LoadIconA(0, IDI_HAND
);
1835 cls
.hIconSm
= small_icon
;
1836 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
1837 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1838 cls
.lpszMenuName
= NULL
;
1839 cls
.lpszClassName
= "IconWindowClass";
1841 RegisterClassExA(&cls
);
1843 hwnd
= CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1844 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, NULL
, NULL
);
1847 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1848 ok( res
== 0, "wrong big icon %p/0\n", res
);
1849 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon
);
1850 ok( res
== 0, "wrong previous big icon %p/0\n", res
);
1851 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1852 ok( res
== icon
, "wrong big icon after set %p/%p\n", res
, icon
);
1853 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon2
);
1854 ok( res
== icon
, "wrong previous big icon %p/%p\n", res
, icon
);
1855 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1856 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1858 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1859 ok( res
== 0, "wrong small icon %p/0\n", res
);
1860 /* this test is XP specific */
1861 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1862 ok( res != 0, "wrong small icon %p\n", res );*/
1863 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)icon
);
1864 ok( res
== 0, "wrong previous small icon %p/0\n", res
);
1865 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1866 ok( res
== icon
, "wrong small icon after set %p/%p\n", res
, icon
);
1867 /* this test is XP specific */
1868 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1869 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1870 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)small_icon
);
1871 ok( res
== icon
, "wrong previous small icon %p/%p\n", res
, icon
);
1872 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1873 ok( res
== small_icon
, "wrong small icon after set %p/%p\n", res
, small_icon
);
1874 /* this test is XP specific */
1875 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1876 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1878 /* make sure the big icon hasn't changed */
1879 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1880 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1882 DestroyWindow( hwnd
);
1885 static LRESULT WINAPI
nccalcsize_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1887 if (msg
== WM_NCCALCSIZE
)
1889 RECT
*rect
= (RECT
*)lparam
;
1890 /* first time around increase the rectangle, next time decrease it */
1891 if (rect
->left
== 100) InflateRect( rect
, 10, 10 );
1892 else InflateRect( rect
, -10, -10 );
1895 return DefWindowProc( hwnd
, msg
, wparam
, lparam
);
1898 static void test_SetWindowPos(HWND hwnd
)
1900 RECT orig_win_rc
, rect
;
1902 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
1904 SetRect(&rect
, 111, 222, 333, 444);
1905 ok(!GetWindowRect(0, &rect
), "GetWindowRect succeeded\n");
1906 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1907 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1909 SetRect(&rect
, 111, 222, 333, 444);
1910 ok(!GetClientRect(0, &rect
), "GetClientRect succeeded\n");
1911 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1912 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1914 GetWindowRect(hwnd
, &orig_win_rc
);
1916 old_proc
= SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)nccalcsize_proc
);
1917 SetWindowPos(hwnd
, 0, 100, 100, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1918 GetWindowRect( hwnd
, &rect
);
1919 ok( rect
.left
== 100 && rect
.top
== 100 && rect
.right
== 100 && rect
.bottom
== 100,
1920 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1921 GetClientRect( hwnd
, &rect
);
1922 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1923 ok( rect
.left
== 90 && rect
.top
== 90 && rect
.right
== 110 && rect
.bottom
== 110,
1924 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1926 SetWindowPos(hwnd
, 0, 200, 200, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1927 GetWindowRect( hwnd
, &rect
);
1928 ok( rect
.left
== 200 && rect
.top
== 200 && rect
.right
== 200 && rect
.bottom
== 200,
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
== 210 && rect
.top
== 210 && rect
.right
== 190 && rect
.bottom
== 190,
1933 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1935 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1936 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1937 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, old_proc
);
1939 /* Win9x truncates coordinates to 16-bit irrespectively */
1942 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE
);
1943 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE
);
1945 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE
);
1946 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE
);
1949 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1950 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1952 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1953 SetWindowPos(hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1954 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1955 SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1956 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1957 SetWindowPos(hwnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1958 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1961 static void test_SetMenu(HWND parent
)
1965 BOOL is_win9x
= GetWindowLongPtrW(parent
, GWLP_WNDPROC
) == 0;
1969 hMenu
= CreateMenu();
1972 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1975 /* fails on (at least) Wine, NT4, XP SP2 */
1976 test_nonclient_area(parent
);
1978 ret
= GetMenu(parent
);
1979 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1980 /* test whether we can destroy a menu assigned to a window */
1981 retok
= DestroyMenu(hMenu
);
1982 ok( retok
, "DestroyMenu error %d\n", GetLastError());
1983 retok
= IsMenu(hMenu
);
1984 ok(!retok
|| broken(retok
) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
1985 ret
= GetMenu(parent
);
1986 /* This test fails on Win9x */
1988 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1989 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1990 test_nonclient_area(parent
);
1992 hMenu
= CreateMenu();
1996 ret
= GetMenu(parent
);
1997 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1999 ok(!SetMenu(parent
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
2000 test_nonclient_area(parent
);
2001 ret
= GetMenu(parent
);
2002 ok(ret
== 0, "unexpected menu id %p\n", ret
);
2004 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
2007 /* fails on (at least) Wine, NT4, XP SP2 */
2008 test_nonclient_area(parent
);
2010 ret
= GetMenu(parent
);
2011 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
2013 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
2014 test_nonclient_area(parent
);
2015 ret
= GetMenu(parent
);
2016 ok(ret
== 0, "unexpected menu id %p\n", ret
);
2019 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, parent
, (HMENU
)10, 0, NULL
);
2022 ret
= GetMenu(child
);
2023 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2025 ok(!SetMenu(child
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
2026 test_nonclient_area(child
);
2027 ret
= GetMenu(child
);
2028 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2030 ok(!SetMenu(child
, hMenu
), "SetMenu on a child window should fail\n");
2031 test_nonclient_area(child
);
2032 ret
= GetMenu(child
);
2033 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2035 ok(!SetMenu(child
, 0), "SetMenu(0) on a child window should fail\n");
2036 test_nonclient_area(child
);
2037 ret
= GetMenu(child
);
2038 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
2040 style
= GetWindowLong(child
, GWL_STYLE
);
2041 SetWindowLong(child
, GWL_STYLE
, style
| WS_POPUP
);
2042 ok(SetMenu(child
, hMenu
), "SetMenu on a popup child window should not fail\n");
2043 ok(SetMenu(child
, 0), "SetMenu on a popup child window should not fail\n");
2044 SetWindowLong(child
, GWL_STYLE
, style
);
2046 SetWindowLong(child
, GWL_STYLE
, style
| WS_OVERLAPPED
);
2047 ok(!SetMenu(child
, hMenu
), "SetMenu on a overlapped child window should fail\n");
2048 SetWindowLong(child
, GWL_STYLE
, style
);
2050 DestroyWindow(child
);
2054 static void test_window_tree(HWND parent
, const DWORD
*style
, const int *order
, int total
)
2056 HWND child
[5], hwnd
;
2061 hwnd
= GetWindow(parent
, GW_CHILD
);
2062 ok(!hwnd
, "have to start without children to perform the test\n");
2064 for (i
= 0; i
< total
; i
++)
2066 if (style
[i
] & DS_CONTROL
)
2068 child
[i
] = CreateWindowExA(0, MAKEINTATOM(32770), "", style
[i
] & ~WS_VISIBLE
,
2069 0,0,0,0, parent
, (HMENU
)i
, 0, NULL
);
2070 if (style
[i
] & WS_VISIBLE
)
2071 ShowWindow(child
[i
], SW_SHOW
);
2073 SetWindowPos(child
[i
], HWND_BOTTOM
, 0,0,10,10, SWP_NOACTIVATE
);
2076 child
[i
] = CreateWindowExA(0, "static", "", style
[i
], 0,0,10,10,
2077 parent
, (HMENU
)i
, 0, NULL
);
2078 trace("child[%ld] = %p\n", i
, child
[i
]);
2079 ok(child
[i
] != 0, "CreateWindowEx failed to create child window\n");
2082 hwnd
= GetWindow(parent
, GW_CHILD
);
2083 ok(hwnd
!= 0, "GetWindow(GW_CHILD) failed\n");
2084 ok(hwnd
== GetWindow(child
[total
- 1], GW_HWNDFIRST
), "GW_HWNDFIRST is wrong\n");
2085 ok(child
[order
[total
- 1]] == GetWindow(child
[0], GW_HWNDLAST
), "GW_HWNDLAST is wrong\n");
2087 for (i
= 0; i
< total
; i
++)
2089 trace("hwnd[%ld] = %p\n", i
, hwnd
);
2090 ok(child
[order
[i
]] == hwnd
, "Z order of child #%ld is wrong\n", i
);
2092 hwnd
= GetWindow(hwnd
, GW_HWNDNEXT
);
2095 for (i
= 0; i
< total
; i
++)
2096 ok(DestroyWindow(child
[i
]), "DestroyWindow failed\n");
2099 static void test_children_zorder(HWND parent
)
2101 const DWORD simple_style
[5] = { WS_CHILD
, WS_CHILD
, WS_CHILD
, WS_CHILD
,
2103 const int simple_order
[5] = { 0, 1, 2, 3, 4 };
2105 const DWORD complex_style
[5] = { WS_CHILD
, WS_CHILD
| WS_MAXIMIZE
,
2106 WS_CHILD
| WS_VISIBLE
, WS_CHILD
,
2107 WS_CHILD
| WS_MAXIMIZE
| WS_VISIBLE
};
2108 const int complex_order_1
[1] = { 0 };
2109 const int complex_order_2
[2] = { 1, 0 };
2110 const int complex_order_3
[3] = { 1, 0, 2 };
2111 const int complex_order_4
[4] = { 1, 0, 2, 3 };
2112 const int complex_order_5
[5] = { 4, 1, 0, 2, 3 };
2113 const DWORD complex_style_6
[3] = { WS_CHILD
| WS_VISIBLE
,
2114 WS_CHILD
| WS_CLIPSIBLINGS
| DS_CONTROL
| WS_VISIBLE
,
2115 WS_CHILD
| WS_VISIBLE
};
2116 const int complex_order_6
[3] = { 0, 1, 2 };
2118 /* simple WS_CHILD */
2119 test_window_tree(parent
, simple_style
, simple_order
, 5);
2121 /* complex children styles */
2122 test_window_tree(parent
, complex_style
, complex_order_1
, 1);
2123 test_window_tree(parent
, complex_style
, complex_order_2
, 2);
2124 test_window_tree(parent
, complex_style
, complex_order_3
, 3);
2125 test_window_tree(parent
, complex_style
, complex_order_4
, 4);
2126 test_window_tree(parent
, complex_style
, complex_order_5
, 5);
2128 /* another set of complex children styles */
2129 test_window_tree(parent
, complex_style_6
, complex_order_6
, 3);
2132 #define check_z_order(hwnd, next, prev, owner, topmost) \
2133 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2136 static void check_z_order_debug(HWND hwnd
, HWND next
, HWND prev
, HWND owner
,
2137 BOOL topmost
, const char *file
, int line
)
2142 test
= GetWindow(hwnd
, GW_HWNDNEXT
);
2143 /* skip foreign windows */
2144 while (test
&& test
!= next
&&
2145 (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2146 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0) ||
2147 GetWindow(test
, GW_OWNER
) == next
))
2149 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2150 test
= GetWindow(test
, GW_HWNDNEXT
);
2152 ok_(file
, line
)(next
== test
, "expected next %p, got %p\n", next
, test
);
2154 test
= GetWindow(hwnd
, GW_HWNDPREV
);
2155 /* skip foreign windows */
2156 while (test
&& test
!= prev
&&
2157 (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2158 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0) ||
2159 GetWindow(test
, GW_OWNER
) == hwnd
))
2161 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2162 test
= GetWindow(test
, GW_HWNDPREV
);
2164 ok_(file
, line
)(prev
== test
, "expected prev %p, got %p\n", prev
, test
);
2166 test
= GetWindow(hwnd
, GW_OWNER
);
2167 ok_(file
, line
)(owner
== test
, "expected owner %p, got %p\n", owner
, test
);
2169 ex_style
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
2170 ok_(file
, line
)(!(ex_style
& WS_EX_TOPMOST
) == !topmost
, "expected %stopmost\n", topmost
? "" : "NOT ");
2173 static void test_popup_zorder(HWND hwnd_D
, HWND hwnd_E
)
2175 HWND hwnd_A
, hwnd_B
, hwnd_C
, hwnd_F
;
2177 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D
, hwnd_E
);
2179 SetWindowPos(hwnd_E
, hwnd_D
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2181 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2182 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2184 hwnd_F
= CreateWindowEx(0, "MainWindowClass", "Owner window",
2185 WS_OVERLAPPED
| WS_CAPTION
,
2187 0, 0, GetModuleHandle(0), NULL
);
2188 trace("hwnd_F %p\n", hwnd_F
);
2189 check_z_order(hwnd_F
, hwnd_D
, 0, 0, FALSE
);
2191 SetWindowPos(hwnd_F
, hwnd_E
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2192 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2193 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2194 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2196 hwnd_C
= CreateWindowEx(0, "MainWindowClass", NULL
,
2199 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2200 trace("hwnd_C %p\n", hwnd_C
);
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
, hwnd_C
, 0, FALSE
);
2204 check_z_order(hwnd_C
, hwnd_D
, 0, hwnd_F
, FALSE
);
2206 hwnd_B
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2209 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2210 trace("hwnd_B %p\n", hwnd_B
);
2211 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2212 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2213 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2214 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2215 check_z_order(hwnd_B
, hwnd_C
, 0, hwnd_F
, TRUE
);
2217 hwnd_A
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2220 0, 0, GetModuleHandle(0), NULL
);
2221 trace("hwnd_A %p\n", hwnd_A
);
2222 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2223 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2224 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2225 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2226 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2227 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2229 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
);
2231 /* move hwnd_F and its popups up */
2232 SetWindowPos(hwnd_F
, HWND_TOP
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2233 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2234 check_z_order(hwnd_D
, hwnd_E
, hwnd_F
, 0, FALSE
);
2235 check_z_order(hwnd_F
, hwnd_D
, hwnd_C
, 0, FALSE
);
2236 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2237 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2238 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2240 /* move hwnd_F and its popups down */
2241 #if 0 /* enable once Wine is fixed to pass this test */
2242 SetWindowPos(hwnd_F
, HWND_BOTTOM
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2243 check_z_order(hwnd_F
, 0, hwnd_C
, 0, FALSE
);
2244 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2245 check_z_order(hwnd_B
, hwnd_C
, hwnd_E
, hwnd_F
, FALSE
);
2246 check_z_order(hwnd_E
, hwnd_B
, hwnd_D
, 0, FALSE
);
2247 check_z_order(hwnd_D
, hwnd_E
, hwnd_A
, 0, FALSE
);
2248 check_z_order(hwnd_A
, hwnd_D
, 0, 0, TRUE
);
2251 DestroyWindow(hwnd_A
);
2252 DestroyWindow(hwnd_B
);
2253 DestroyWindow(hwnd_C
);
2254 DestroyWindow(hwnd_F
);
2257 static void test_vis_rgn( HWND hwnd
)
2259 RECT win_rect
, rgn_rect
;
2260 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2263 ShowWindow(hwnd
,SW_SHOW
);
2264 hdc
= GetDC( hwnd
);
2265 ok( GetRandomRgn( hdc
, hrgn
, SYSRGN
) != 0, "GetRandomRgn failed\n" );
2266 GetWindowRect( hwnd
, &win_rect
);
2267 GetRgnBox( hrgn
, &rgn_rect
);
2268 if (GetVersion() & 0x80000000)
2270 trace("win9x, mapping to screen coords\n");
2271 MapWindowPoints( hwnd
, 0, (POINT
*)&rgn_rect
, 2 );
2273 trace("win: %d,%d-%d,%d\n", win_rect
.left
, win_rect
.top
, win_rect
.right
, win_rect
.bottom
);
2274 trace("rgn: %d,%d-%d,%d\n", rgn_rect
.left
, rgn_rect
.top
, rgn_rect
.right
, rgn_rect
.bottom
);
2275 ok( win_rect
.left
<= rgn_rect
.left
, "rgn left %d not inside win rect %d\n",
2276 rgn_rect
.left
, win_rect
.left
);
2277 ok( win_rect
.top
<= rgn_rect
.top
, "rgn top %d not inside win rect %d\n",
2278 rgn_rect
.top
, win_rect
.top
);
2279 ok( win_rect
.right
>= rgn_rect
.right
, "rgn right %d not inside win rect %d\n",
2280 rgn_rect
.right
, win_rect
.right
);
2281 ok( win_rect
.bottom
>= rgn_rect
.bottom
, "rgn bottom %d not inside win rect %d\n",
2282 rgn_rect
.bottom
, win_rect
.bottom
);
2283 ReleaseDC( hwnd
, hdc
);
2286 static LRESULT WINAPI
set_focus_on_activate_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
2288 if (msg
== WM_ACTIVATE
&& LOWORD(wp
) == WA_ACTIVE
)
2290 HWND child
= GetWindow(hwnd
, GW_CHILD
);
2291 ok(child
!= 0, "couldn't find child window\n");
2293 ok(GetFocus() == child
, "Focus should be on child %p\n", child
);
2296 return DefWindowProc(hwnd
, msg
, wp
, lp
);
2299 static void test_SetFocus(HWND hwnd
)
2302 WNDPROC old_wnd_proc
;
2304 /* check if we can set focus to non-visible windows */
2306 ShowWindow(hwnd
, SW_SHOW
);
2309 ok( GetFocus() == hwnd
, "Failed to set focus to visible window %p\n", hwnd
);
2310 ok( GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
, "Window %p not visible\n", hwnd
);
2311 ShowWindow(hwnd
, SW_HIDE
);
2314 ok( GetFocus() == hwnd
, "Failed to set focus to invisible window %p\n", hwnd
);
2315 ok( !(GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
), "Window %p still visible\n", hwnd
);
2316 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2319 ok( GetFocus() == child
, "Failed to set focus to invisible child %p\n", child
);
2320 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2321 ShowWindow(child
, SW_SHOW
);
2322 ok( GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
, "Child %p is not visible\n", child
);
2323 ok( GetFocus() == child
, "Focus no longer on child %p\n", child
);
2324 ShowWindow(child
, SW_HIDE
);
2325 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2326 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2327 ShowWindow(child
, SW_SHOW
);
2329 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2330 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_HIDEWINDOW
);
2331 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2333 ShowWindow(child
, SW_HIDE
);
2335 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2336 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_SHOWWINDOW
);
2337 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2338 ShowWindow(child
, SW_HIDE
);
2339 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2341 ShowWindow(hwnd
, SW_SHOW
);
2342 ShowWindow(child
, SW_SHOW
);
2344 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2345 EnableWindow(hwnd
, FALSE
);
2346 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2347 EnableWindow(hwnd
, TRUE
);
2349 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2350 ShowWindow(hwnd
, SW_SHOWMINIMIZED
);
2351 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2353 ok( GetFocus() != child
, "Focus should not be on child %p\n", child
);
2354 ok( GetFocus() != hwnd
, "Focus should not be on parent %p\n", hwnd
);
2355 ShowWindow(hwnd
, SW_RESTORE
);
2356 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2357 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
2358 ShowWindow(hwnd
, SW_SHOWMINIMIZED
);
2359 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2360 ok( GetFocus() != child
, "Focus should not be on child %p\n", child
);
2362 ok( GetFocus() != hwnd
, "Focus should not be on parent %p\n", hwnd
);
2363 old_wnd_proc
= (WNDPROC
)SetWindowLongPtr(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)set_focus_on_activate_proc
);
2364 ShowWindow(hwnd
, SW_RESTORE
);
2365 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2367 ok( GetFocus() == child
, "Focus should be on child %p, not %p\n", child
, GetFocus() );
2369 SetWindowLongPtr(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)old_wnd_proc
);
2371 DestroyWindow( child
);
2374 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
2375 static void check_wnd_state_(const char *file
, int line
,
2376 HWND active
, HWND foreground
, HWND focus
, HWND capture
)
2378 ok_(file
, line
)(active
== GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2379 /* only check foreground if it belongs to the current thread */
2380 /* foreground can be moved to a different app pretty much at any time */
2381 if (foreground
&& GetForegroundWindow() &&
2382 GetWindowThreadProcessId(GetForegroundWindow(), NULL
) == GetCurrentThreadId())
2383 ok_(file
, line
)(foreground
== GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2384 ok_(file
, line
)(focus
== GetFocus(), "GetFocus() = %p\n", GetFocus());
2385 ok_(file
, line
)(capture
== GetCapture(), "GetCapture() = %p\n", GetCapture());
2388 static void test_SetActiveWindow(HWND hwnd
)
2392 flush_events( TRUE
);
2393 ShowWindow(hwnd
, SW_HIDE
);
2396 check_wnd_state(0, 0, 0, 0);
2398 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2400 ShowWindow(hwnd
, SW_SHOW
);
2401 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2403 hwnd2
= SetActiveWindow(0);
2404 ok(hwnd2
== hwnd
, "SetActiveWindow returned %p instead of %p\n", hwnd2
, hwnd
);
2405 if (!GetActiveWindow()) /* doesn't always work on vista */
2407 check_wnd_state(0, 0, 0, 0);
2408 hwnd2
= SetActiveWindow(hwnd
);
2409 ok(hwnd2
== 0, "SetActiveWindow returned %p instead of 0\n", hwnd2
);
2411 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2413 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2414 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2416 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2417 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2419 ShowWindow(hwnd
, SW_HIDE
);
2420 check_wnd_state(0, 0, 0, 0);
2422 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2423 SetActiveWindow(hwnd
);
2424 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2426 ShowWindow(hwnd
, SW_SHOW
);
2427 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2429 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2430 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2432 DestroyWindow(hwnd2
);
2433 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2435 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2436 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2438 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2439 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2441 DestroyWindow(hwnd2
);
2442 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2445 static void test_SetForegroundWindow(HWND hwnd
)
2450 flush_events( TRUE
);
2451 ShowWindow(hwnd
, SW_HIDE
);
2454 check_wnd_state(0, 0, 0, 0);
2456 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2458 ShowWindow(hwnd
, SW_SHOW
);
2459 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2461 hwnd2
= SetActiveWindow(0);
2462 ok(hwnd2
== hwnd
, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2
, hwnd
);
2463 if (GetActiveWindow() == hwnd
) /* doesn't always work on vista */
2464 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2466 check_wnd_state(0, 0, 0, 0);
2468 ret
= SetForegroundWindow(hwnd
);
2471 skip( "SetForegroundWindow not working\n" );
2474 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2476 SetLastError(0xdeadbeef);
2477 ret
= SetForegroundWindow(0);
2478 ok(!ret
, "SetForegroundWindow returned TRUE instead of FALSE\n");
2479 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
||
2480 broken(GetLastError() == 0xdeadbeef), /* win9x */
2481 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2482 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2484 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2485 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2487 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2488 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2490 hwnd2
= GetForegroundWindow();
2491 ok(hwnd2
== hwnd
, "Wrong foreground window %p\n", hwnd2
);
2492 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2493 hwnd2
= GetForegroundWindow();
2494 ok(hwnd2
!= hwnd
, "Wrong foreground window %p\n", hwnd2
);
2496 ShowWindow(hwnd
, SW_HIDE
);
2497 check_wnd_state(0, 0, 0, 0);
2499 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2500 ret
= SetForegroundWindow(hwnd
);
2501 ok(ret
|| broken(!ret
), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
2502 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2504 ShowWindow(hwnd
, SW_SHOW
);
2505 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2507 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2508 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2510 DestroyWindow(hwnd2
);
2511 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2513 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2514 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2516 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2517 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2519 DestroyWindow(hwnd2
);
2520 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2523 static WNDPROC old_button_proc
;
2525 static LRESULT WINAPI
button_hook_proc(HWND button
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2530 key_state
= GetKeyState(VK_LBUTTON
);
2531 ok(!(key_state
& 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state
);
2533 ret
= CallWindowProcA(old_button_proc
, button
, msg
, wparam
, lparam
);
2535 if (msg
== WM_LBUTTONDOWN
)
2539 check_wnd_state(button
, button
, button
, button
);
2541 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2543 trace("hwnd %p\n", hwnd
);
2545 check_wnd_state(button
, button
, button
, button
);
2547 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2549 check_wnd_state(button
, button
, button
, button
);
2551 DestroyWindow(hwnd
);
2553 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2555 trace("hwnd %p\n", hwnd
);
2557 check_wnd_state(button
, button
, button
, button
);
2559 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2560 * match internal button state.
2562 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2563 check_wnd_state(button
, button
, button
, 0);
2565 ShowWindow(hwnd
, SW_SHOW
);
2566 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2568 capture
= SetCapture(hwnd
);
2569 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2571 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2573 DestroyWindow(hwnd
);
2575 check_wnd_state(button
, 0, button
, 0);
2581 static void test_capture_1(void)
2583 HWND button
, capture
, oldFocus
, oldActive
;
2585 oldFocus
= GetFocus();
2586 oldActive
= GetActiveWindow();
2588 capture
= GetCapture();
2589 ok(capture
== 0, "GetCapture() = %p\n", capture
);
2591 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2593 trace("button %p\n", button
);
2595 old_button_proc
= (WNDPROC
)SetWindowLongPtrA(button
, GWLP_WNDPROC
, (LONG_PTR
)button_hook_proc
);
2597 SendMessageA(button
, WM_LBUTTONDOWN
, 0, 0);
2599 capture
= SetCapture(button
);
2600 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2601 check_wnd_state(button
, 0, button
, button
);
2603 DestroyWindow(button
);
2604 check_wnd_state(oldActive
, 0, oldFocus
, 0);
2607 static void test_capture_2(void)
2609 HWND button
, hwnd
, capture
, oldFocus
, oldActive
;
2611 oldFocus
= GetFocus();
2612 oldActive
= GetActiveWindow();
2613 check_wnd_state(oldActive
, 0, oldFocus
, 0);
2615 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2617 trace("button %p\n", button
);
2619 check_wnd_state(button
, button
, button
, 0);
2621 capture
= SetCapture(button
);
2622 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2624 check_wnd_state(button
, button
, button
, button
);
2626 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2627 * internal button state.
2629 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2630 check_wnd_state(button
, button
, button
, button
);
2632 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2634 trace("hwnd %p\n", hwnd
);
2636 check_wnd_state(button
, button
, button
, button
);
2638 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2640 check_wnd_state(button
, button
, button
, button
);
2642 DestroyWindow(hwnd
);
2644 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2646 trace("hwnd %p\n", hwnd
);
2648 check_wnd_state(button
, button
, button
, button
);
2650 ShowWindow(hwnd
, SW_SHOW
);
2652 check_wnd_state(hwnd
, hwnd
, hwnd
, button
);
2654 capture
= SetCapture(hwnd
);
2655 ok(capture
== button
, "SetCapture() = %p\n", capture
);
2657 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2659 DestroyWindow(hwnd
);
2660 check_wnd_state(button
, button
, button
, 0);
2662 DestroyWindow(button
);
2663 check_wnd_state(oldActive
, 0, oldFocus
, 0);
2666 static void test_capture_3(HWND hwnd1
, HWND hwnd2
)
2670 ShowWindow(hwnd1
, SW_HIDE
);
2671 ShowWindow(hwnd2
, SW_HIDE
);
2673 ok(!IsWindowVisible(hwnd1
), "%p should be invisible\n", hwnd1
);
2674 ok(!IsWindowVisible(hwnd2
), "%p should be invisible\n", hwnd2
);
2677 check_wnd_state(0, 0, 0, hwnd1
);
2680 check_wnd_state(0, 0, 0, hwnd2
);
2682 ShowWindow(hwnd1
, SW_SHOW
);
2683 check_wnd_state(hwnd1
, hwnd1
, hwnd1
, hwnd2
);
2685 ret
= ReleaseCapture();
2686 ok (ret
, "releasecapture did not return TRUE.\n");
2687 ret
= ReleaseCapture();
2688 ok (ret
, "releasecapture did not return TRUE after second try.\n");
2691 /* PeekMessage wrapper that ignores the messages we don't care about */
2692 static BOOL
peek_message( MSG
*msg
)
2697 ret
= PeekMessageA(msg
, 0, 0, 0, PM_REMOVE
);
2698 } while (ret
&& (msg
->message
== WM_TIMER
|| ignore_message(msg
->message
)));
2702 static void test_keyboard_input(HWND hwnd
)
2707 flush_events( TRUE
);
2708 SetWindowPos(hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_SHOWWINDOW
);
2710 flush_events( TRUE
);
2712 ok(GetActiveWindow() == hwnd
, "wrong active window %p\n", GetActiveWindow());
2715 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2717 flush_events( TRUE
);
2719 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2720 ret
= peek_message(&msg
);
2721 ok( ret
, "no message available\n");
2722 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2723 ret
= peek_message(&msg
);
2724 ok( !ret
, "message %04x available\n", msg
.message
);
2726 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2728 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2729 ret
= peek_message(&msg
);
2730 ok(ret
, "no message available\n");
2731 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2732 ret
= peek_message(&msg
);
2733 ok( !ret
, "message %04x available\n", msg
.message
);
2735 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2737 keybd_event(VK_SPACE
, 0, 0, 0);
2738 if (!peek_message(&msg
))
2740 skip( "keybd_event didn't work, skipping keyboard test\n" );
2743 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2744 ret
= peek_message(&msg
);
2745 ok( !ret
, "message %04x available\n", msg
.message
);
2748 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2750 flush_events( TRUE
);
2752 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2753 ret
= peek_message(&msg
);
2754 ok(ret
, "no message available\n");
2755 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2756 ret
= peek_message(&msg
);
2757 ok( !ret
, "message %04x available\n", msg
.message
);
2759 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2761 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2762 ret
= peek_message(&msg
);
2763 ok(ret
, "no message available\n");
2764 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2765 ret
= peek_message(&msg
);
2766 ok( !ret
, "message %04x available\n", msg
.message
);
2768 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2770 keybd_event(VK_SPACE
, 0, 0, 0);
2771 ret
= peek_message(&msg
);
2772 ok(ret
, "no message available\n");
2773 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_SYSKEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2774 ret
= peek_message(&msg
);
2775 ok( !ret
, "message %04x available\n", msg
.message
);
2778 static BOOL
wait_for_message( MSG
*msg
)
2784 ret
= peek_message(msg
);
2787 if (msg
->message
== WM_PAINT
) DispatchMessage(msg
);
2790 else if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, 100, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
2792 if (!ret
) msg
->message
= 0;
2796 static void test_mouse_input(HWND hwnd
)
2806 ShowWindow(hwnd
, SW_SHOW
);
2808 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
2810 GetWindowRect(hwnd
, &rc
);
2811 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2813 popup
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_POPUP
,
2814 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
,
2817 ShowWindow(popup
, SW_SHOW
);
2818 UpdateWindow(popup
);
2819 SetWindowPos( popup
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
2821 GetWindowRect(popup
, &rc
);
2822 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2824 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
2825 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
2826 trace("setting cursor to (%d,%d)\n", x
, y
);
2830 if (x
!= pt
.x
|| y
!= pt
.y
)
2832 skip( "failed to set mouse position, skipping mouse input tests\n" );
2836 flush_events( TRUE
);
2838 /* Check that setting the same position may generate WM_MOUSEMOVE */
2841 ret
= peek_message(&msg
);
2844 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n",
2845 msg
.hwnd
, msg
.message
);
2846 ok(msg
.pt
.x
== x
&& msg
.pt
.y
== y
, "wrong message coords (%d,%d)/(%d,%d)\n",
2847 x
, y
, msg
.pt
.x
, msg
.pt
.y
);
2850 /* force the system to update its internal queue mouse position,
2851 * otherwise it won't generate relative mouse movements below.
2853 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2854 flush_events( TRUE
);
2857 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2858 flush_events( FALSE
);
2859 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2860 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
2862 if (msg
.message
== WM_TIMER
|| ignore_message(msg
.message
)) continue;
2863 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
,
2864 "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2866 ret
= peek_message(&msg
);
2867 ok( !ret
, "message %04x available\n", msg
.message
);
2869 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2870 ShowWindow(popup
, SW_HIDE
);
2871 ret
= wait_for_message( &msg
);
2873 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2874 flush_events( TRUE
);
2876 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2877 ShowWindow(hwnd
, SW_HIDE
);
2878 ret
= wait_for_message( &msg
);
2879 ok( !ret
, "message %04x available\n", msg
.message
);
2880 flush_events( TRUE
);
2882 /* test mouse clicks */
2884 ShowWindow(hwnd
, SW_SHOW
);
2885 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
2886 flush_events( TRUE
);
2887 ShowWindow(popup
, SW_SHOW
);
2888 SetWindowPos( popup
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
2889 flush_events( TRUE
);
2891 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2892 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2893 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2894 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2896 ret
= wait_for_message( &msg
);
2899 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
2902 if (msg
.message
== WM_MOUSEMOVE
) /* win2k has an extra WM_MOUSEMOVE here */
2904 ret
= wait_for_message( &msg
);
2905 ok(ret
, "no message available\n");
2908 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2909 msg
.hwnd
, popup
, msg
.message
);
2911 ret
= wait_for_message( &msg
);
2912 ok(ret
, "no message available\n");
2913 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2914 msg
.hwnd
, popup
, msg
.message
);
2916 ret
= wait_for_message( &msg
);
2917 ok(ret
, "no message available\n");
2918 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p/%p message %04x\n",
2919 msg
.hwnd
, popup
, msg
.message
);
2921 ret
= wait_for_message( &msg
);
2922 ok(ret
, "no message available\n");
2923 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2924 msg
.hwnd
, popup
, msg
.message
);
2926 ret
= peek_message(&msg
);
2927 ok(!ret
, "message %04x available\n", msg
.message
);
2929 ShowWindow(popup
, SW_HIDE
);
2930 flush_events( TRUE
);
2932 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2933 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2934 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2935 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2937 ret
= wait_for_message( &msg
);
2938 ok(ret
, "no message available\n");
2939 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2940 msg
.hwnd
, hwnd
, msg
.message
);
2941 ret
= wait_for_message( &msg
);
2942 ok(ret
, "no message available\n");
2943 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2944 msg
.hwnd
, hwnd
, msg
.message
);
2946 test_lbuttondown_flag
= TRUE
;
2947 SendMessageA(hwnd
, WM_COMMAND
, (WPARAM
)popup
, 0);
2948 test_lbuttondown_flag
= FALSE
;
2950 ret
= wait_for_message( &msg
);
2951 ok(ret
, "no message available\n");
2952 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2953 msg
.hwnd
, popup
, msg
.message
);
2954 ok(peek_message(&msg
), "no message available\n");
2955 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2956 msg
.hwnd
, popup
, msg
.message
);
2957 ok(peek_message(&msg
), "no message available\n");
2959 /* Test WM_MOUSEACTIVATE */
2960 #define TEST_MOUSEACTIVATE(A,B) \
2961 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2962 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2964 TEST_MOUSEACTIVATE(HTERROR
,MA_ACTIVATE
);
2965 TEST_MOUSEACTIVATE(HTTRANSPARENT
,MA_ACTIVATE
);
2966 TEST_MOUSEACTIVATE(HTNOWHERE
,MA_ACTIVATE
);
2967 TEST_MOUSEACTIVATE(HTCLIENT
,MA_ACTIVATE
);
2968 TEST_MOUSEACTIVATE(HTCAPTION
,MA_ACTIVATE
);
2969 TEST_MOUSEACTIVATE(HTSYSMENU
,MA_ACTIVATE
);
2970 TEST_MOUSEACTIVATE(HTSIZE
,MA_ACTIVATE
);
2971 TEST_MOUSEACTIVATE(HTMENU
,MA_ACTIVATE
);
2972 TEST_MOUSEACTIVATE(HTHSCROLL
,MA_ACTIVATE
);
2973 TEST_MOUSEACTIVATE(HTVSCROLL
,MA_ACTIVATE
);
2974 TEST_MOUSEACTIVATE(HTMINBUTTON
,MA_ACTIVATE
);
2975 TEST_MOUSEACTIVATE(HTMAXBUTTON
,MA_ACTIVATE
);
2976 TEST_MOUSEACTIVATE(HTLEFT
,MA_ACTIVATE
);
2977 TEST_MOUSEACTIVATE(HTRIGHT
,MA_ACTIVATE
);
2978 TEST_MOUSEACTIVATE(HTTOP
,MA_ACTIVATE
);
2979 TEST_MOUSEACTIVATE(HTTOPLEFT
,MA_ACTIVATE
);
2980 TEST_MOUSEACTIVATE(HTTOPRIGHT
,MA_ACTIVATE
);
2981 TEST_MOUSEACTIVATE(HTBOTTOM
,MA_ACTIVATE
);
2982 TEST_MOUSEACTIVATE(HTBOTTOMLEFT
,MA_ACTIVATE
);
2983 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT
,MA_ACTIVATE
);
2984 TEST_MOUSEACTIVATE(HTBORDER
,MA_ACTIVATE
);
2985 TEST_MOUSEACTIVATE(HTOBJECT
,MA_ACTIVATE
);
2986 TEST_MOUSEACTIVATE(HTCLOSE
,MA_ACTIVATE
);
2987 TEST_MOUSEACTIVATE(HTHELP
,MA_ACTIVATE
);
2990 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2991 flush_events( TRUE
);
2993 DestroyWindow(popup
);
2996 static void test_validatergn(HWND hwnd
)
3002 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_VISIBLE
, 10, 10, 10, 10, hwnd
, 0, 0, NULL
);
3003 ShowWindow(hwnd
, SW_SHOW
);
3004 UpdateWindow( hwnd
);
3005 /* test that ValidateRect validates children*/
3006 InvalidateRect( child
, NULL
, 1);
3007 GetWindowRect( child
, &rc
);
3008 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
3009 ret
= GetUpdateRect( child
, &rc2
, 0);
3010 ok( rc2
.right
> rc2
.left
&& rc2
.bottom
> rc2
.top
,
3011 "Update rectangle is empty!\n");
3012 ValidateRect( hwnd
, &rc
);
3013 ret
= GetUpdateRect( child
, &rc2
, 0);
3014 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
3015 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
3016 rc2
.right
, rc2
.bottom
);
3018 /* now test ValidateRgn */
3019 InvalidateRect( child
, NULL
, 1);
3020 GetWindowRect( child
, &rc
);
3021 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
3022 rgn
= CreateRectRgnIndirect( &rc
);
3023 ValidateRgn( hwnd
, rgn
);
3024 ret
= GetUpdateRect( child
, &rc2
, 0);
3025 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
3026 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
3027 rc2
.right
, rc2
.bottom
);
3030 DestroyWindow( child
);
3033 static void nccalchelper(HWND hwnd
, INT x
, INT y
, RECT
*prc
)
3036 MoveWindow( hwnd
, 0, 0, x
, y
, 0);
3037 GetWindowRect( hwnd
, prc
);
3039 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)prc
);
3040 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
3041 rc
.left
,rc
.top
,rc
.right
,rc
.bottom
, prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
3044 static void test_nccalcscroll(HWND parent
)
3047 INT sbheight
= GetSystemMetrics( SM_CYHSCROLL
);
3048 INT sbwidth
= GetSystemMetrics( SM_CXVSCROLL
);
3049 HWND hwnd
= CreateWindowExA(0, "static", NULL
,
3050 WS_CHILD
| WS_VISIBLE
| WS_VSCROLL
| WS_HSCROLL
,
3051 10, 10, 200, 200, parent
, 0, 0, NULL
);
3052 ShowWindow( parent
, SW_SHOW
);
3053 UpdateWindow( parent
);
3055 /* test window too low for a horizontal scroll bar */
3056 nccalchelper( hwnd
, 100, sbheight
, &rc1
);
3057 ok( rc1
.bottom
- rc1
.top
== sbheight
, "Height should be %d size is %d,%d - %d,%d\n",
3058 sbheight
, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3060 /* test window just high enough for a horizontal scroll bar */
3061 nccalchelper( hwnd
, 100, sbheight
+ 1, &rc1
);
3062 ok( rc1
.bottom
- rc1
.top
== 1, "Height should be %d size is %d,%d - %d,%d\n",
3063 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3065 /* test window too narrow for a vertical scroll bar */
3066 nccalchelper( hwnd
, sbwidth
- 1, 100, &rc1
);
3067 ok( rc1
.right
- rc1
.left
== sbwidth
- 1 , "Width should be %d size is %d,%d - %d,%d\n",
3068 sbwidth
- 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3070 /* test window just wide enough for a vertical scroll bar */
3071 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
3072 ok( rc1
.right
- rc1
.left
== 0, "Width should be %d size is %d,%d - %d,%d\n",
3073 0, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3075 /* same test, but with client edge: not enough width */
3076 SetWindowLong( hwnd
, GWL_EXSTYLE
, WS_EX_CLIENTEDGE
| GetWindowLong( hwnd
, GWL_EXSTYLE
));
3077 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
3078 ok( rc1
.right
- rc1
.left
== sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
),
3079 "Width should be %d size is %d,%d - %d,%d\n",
3080 sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
), rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3082 DestroyWindow( hwnd
);
3085 static void test_SetParent(void)
3088 HWND desktop
= GetDesktopWindow();
3090 BOOL is_win9x
= GetWindowLongPtrW(desktop
, GWLP_WNDPROC
) == 0;
3091 HWND parent
, child1
, child2
, child3
, child4
, sibling
;
3093 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
3094 100, 100, 200, 200, 0, 0, 0, NULL
);
3095 assert(parent
!= 0);
3096 child1
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
3097 0, 0, 50, 50, parent
, 0, 0, NULL
);
3098 assert(child1
!= 0);
3099 child2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
3100 0, 0, 50, 50, child1
, 0, 0, NULL
);
3101 assert(child2
!= 0);
3102 child3
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
3103 0, 0, 50, 50, child2
, 0, 0, NULL
);
3104 assert(child3
!= 0);
3105 child4
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
3106 0, 0, 50, 50, child3
, 0, 0, NULL
);
3107 assert(child4
!= 0);
3109 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
3110 parent
, child1
, child2
, child3
, child4
);
3112 check_parents(parent
, desktop
, 0, 0, 0, parent
, parent
);
3113 check_parents(child1
, parent
, parent
, parent
, 0, parent
, parent
);
3114 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
3115 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
3116 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
3118 ok(!IsChild(desktop
, parent
), "wrong parent/child %p/%p\n", desktop
, parent
);
3119 ok(!IsChild(desktop
, child1
), "wrong parent/child %p/%p\n", desktop
, child1
);
3120 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
3121 ok(!IsChild(desktop
, child3
), "wrong parent/child %p/%p\n", desktop
, child3
);
3122 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
3124 ok(IsChild(parent
, child1
), "wrong parent/child %p/%p\n", parent
, child1
);
3125 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
3126 ok(!IsChild(parent
, child2
), "wrong parent/child %p/%p\n", parent
, child2
);
3127 ok(!IsChild(child1
, child2
), "wrong parent/child %p/%p\n", child1
, child2
);
3128 ok(!IsChild(parent
, child3
), "wrong parent/child %p/%p\n", parent
, child3
);
3129 ok(IsChild(child2
, child3
), "wrong parent/child %p/%p\n", child2
, child3
);
3130 ok(!IsChild(parent
, child4
), "wrong parent/child %p/%p\n", parent
, child4
);
3131 ok(!IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
3132 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
3134 if (!is_win9x
) /* Win9x doesn't survive this test */
3136 ok(!SetParent(parent
, child1
), "SetParent should fail\n");
3137 ok(!SetParent(child2
, child3
), "SetParent should fail\n");
3138 ok(SetParent(child1
, parent
) != 0, "SetParent should not fail\n");
3139 ok(SetParent(parent
, child2
) != 0, "SetParent should not fail\n");
3140 ok(SetParent(parent
, child3
) != 0, "SetParent should not fail\n");
3141 ok(!SetParent(child2
, parent
), "SetParent should fail\n");
3142 ok(SetParent(parent
, child4
) != 0, "SetParent should not fail\n");
3144 check_parents(parent
, child4
, child4
, 0, 0, child4
, parent
);
3145 check_parents(child1
, parent
, parent
, parent
, 0, child4
, parent
);
3146 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
3147 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
3148 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
3151 hMenu
= CreateMenu();
3152 sibling
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
3153 100, 100, 200, 200, 0, hMenu
, 0, NULL
);
3154 assert(sibling
!= 0);
3156 ok(SetParent(sibling
, parent
) != 0, "SetParent should not fail\n");
3157 ok(GetMenu(sibling
) == hMenu
, "SetParent should not remove menu\n");
3159 ret
= DestroyWindow(parent
);
3160 ok( ret
, "DestroyWindow() error %d\n", GetLastError());
3162 ok(!IsWindow(parent
), "parent still exists\n");
3163 ok(!IsWindow(sibling
), "sibling still exists\n");
3164 ok(!IsWindow(child1
), "child1 still exists\n");
3165 ok(!IsWindow(child2
), "child2 still exists\n");
3166 ok(!IsWindow(child3
), "child3 still exists\n");
3167 ok(!IsWindow(child4
), "child4 still exists\n");
3170 static LRESULT WINAPI
StyleCheckProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3172 LPCREATESTRUCT lpcs
;
3179 lpcs
= (LPCREATESTRUCT
)lparam
;
3180 lpss
= lpcs
->lpCreateParams
;
3183 if ((lpcs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
3184 ((!(lpcs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
3185 (lpcs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
3186 ok(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
, "Window should have WS_EX_WINDOWEDGE style\n");
3188 ok(!(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3190 ok((lpss
->styleOld
& ~WS_EX_WINDOWEDGE
) == (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
),
3191 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
3192 (lpss
->styleOld
& ~WS_EX_WINDOWEDGE
), (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
));
3194 ok(lpss
->styleNew
== lpcs
->style
,
3195 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3196 lpss
->styleNew
, lpcs
->style
);
3200 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3203 static ATOM atomStyleCheckClass
;
3205 static void register_style_check_class(void)
3213 GetModuleHandle(NULL
),
3215 LoadCursor(NULL
, IDC_ARROW
),
3216 (HBRUSH
)(COLOR_BTNFACE
+1),
3218 TEXT("WineStyleCheck"),
3221 atomStyleCheckClass
= RegisterClass(&wc
);
3224 static void check_window_style(DWORD dwStyleIn
, DWORD dwExStyleIn
, DWORD dwStyleOut
, DWORD dwExStyleOut
)
3226 DWORD dwActualStyle
;
3227 DWORD dwActualExStyle
;
3230 HWND hwndParent
= NULL
;
3232 ss
.styleNew
= dwStyleIn
;
3233 ss
.styleOld
= dwExStyleIn
;
3235 if (dwStyleIn
& WS_CHILD
)
3237 hwndParent
= CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3238 WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
3241 hwnd
= CreateWindowEx(dwExStyleIn
, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3242 dwStyleIn
, 0, 0, 0, 0, hwndParent
, NULL
, NULL
, &ss
);
3245 flush_events( TRUE
);
3247 dwActualStyle
= GetWindowLong(hwnd
, GWL_STYLE
);
3248 dwActualExStyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
3249 ok((dwActualStyle
== dwStyleOut
) && (dwActualExStyle
== dwExStyleOut
),
3250 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3251 dwActualStyle
, dwStyleOut
, dwActualExStyle
, dwExStyleOut
);
3253 DestroyWindow(hwnd
);
3254 if (hwndParent
) DestroyWindow(hwndParent
);
3257 /* tests what window styles the window manager automatically adds */
3258 static void test_window_styles(void)
3260 register_style_check_class();
3262 check_window_style(0, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
3263 check_window_style(WS_OVERLAPPEDWINDOW
, 0, WS_CLIPSIBLINGS
|WS_OVERLAPPEDWINDOW
, WS_EX_WINDOWEDGE
);
3264 check_window_style(WS_CHILD
, 0, WS_CHILD
, 0);
3265 check_window_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
3266 check_window_style(0, WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_TOOLWINDOW
);
3267 check_window_style(WS_POPUP
, 0, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3268 check_window_style(WS_POPUP
, WS_EX_WINDOWEDGE
, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3269 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
, WS_CHILD
, WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3270 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
|WS_EX_STATICEDGE
, WS_CHILD
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3271 check_window_style(WS_CAPTION
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
);
3272 check_window_style(0, WS_EX_APPWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_APPWINDOW
|WS_EX_WINDOWEDGE
);
3275 static void test_scrollwindow( HWND hwnd
)
3281 ShowWindow( hwnd
, SW_SHOW
);
3282 UpdateWindow( hwnd
);
3283 flush_events( TRUE
);
3284 GetClientRect( hwnd
, &rc
);
3286 /* test ScrollWindow(Ex) with no clip rectangle */
3287 /* paint the lower half of the window black */
3289 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
3290 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3291 /* paint the upper half of the window white */
3292 rc2
.bottom
= rc2
.top
;
3294 FillRect( hdc
, &rc2
, GetStockObject(WHITE_BRUSH
));
3295 /* scroll lower half up */
3297 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
3298 ScrollWindowEx( hwnd
, 0, - rc2
.top
, &rc2
, NULL
, NULL
, NULL
, SW_ERASE
);
3299 flush_events(FALSE
);
3300 /* expected: black should have scrolled to the upper half */
3301 colr
= GetPixel( hdc
, (rc2
.left
+rc2
.right
)/ 2, rc2
.bottom
/ 4 );
3302 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3303 /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
3304 /* paint the lower half of the window black */
3306 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
3307 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3308 /* paint the upper half of the window white */
3309 rc2
.bottom
= rc2
.top
;
3311 FillRect( hdc
, &rc2
, GetStockObject(WHITE_BRUSH
));
3312 /* scroll lower half up */
3314 rc2
.top
= ( rc2
.top
+ rc2
.bottom
) / 2;
3316 rc3
.left
= rc3
.right
/ 4;
3317 rc3
.right
-= rc3
.right
/ 4;
3318 ScrollWindowEx( hwnd
, 0, - rc2
.top
, &rc2
, &rc3
, NULL
, NULL
, SW_ERASE
);
3319 flush_events(FALSE
);
3320 /* expected: black should have scrolled to the upper half */
3321 colr
= GetPixel( hdc
, (rc2
.left
+rc2
.right
)/ 2, rc2
.bottom
/ 4 );
3322 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3325 ReleaseDC( hwnd
, hdc
);
3328 static void test_scrollvalidate( HWND parent
)
3331 HRGN hrgn
=CreateRectRgn(0,0,0,0);
3332 HRGN exprgn
, tmprgn
, clipping
;
3333 RECT rc
, rcu
, cliprc
;
3334 /* create two overlapping child windows. The visual region
3335 * of hwnd1 is clipped by the overlapping part of
3336 * hwnd2 because of the WS_CLIPSIBLING style */
3339 clipping
= CreateRectRgn(0,0,0,0);
3340 tmprgn
= CreateRectRgn(0,0,0,0);
3341 exprgn
= CreateRectRgn(0,0,0,0);
3342 hwnd2
= CreateWindowExA(0, "static", NULL
,
3343 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3344 75, 30, 100, 100, parent
, 0, 0, NULL
);
3345 hwnd1
= CreateWindowExA(0, "static", NULL
,
3346 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3347 25, 50, 100, 100, parent
, 0, 0, NULL
);
3348 ShowWindow( parent
, SW_SHOW
);
3349 UpdateWindow( parent
);
3350 GetClientRect( hwnd1
, &rc
);
3352 SetRectRgn( clipping
, 10, 10, 90, 90);
3353 hdc
= GetDC( hwnd1
);
3354 /* for a visual touch */
3355 TextOut( hdc
, 0,10, "0123456789", 10);
3356 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3357 if (winetest_debug
> 0) dump_region(hrgn
);
3358 /* create a region with what is expected */
3359 SetRectRgn( exprgn
, 39,0,49,74);
3360 SetRectRgn( tmprgn
, 88,79,98,93);
3361 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3362 SetRectRgn( tmprgn
, 0,93,98,98);
3363 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3364 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3365 trace("update rect is %d,%d - %d,%d\n",
3366 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3367 /* now with clipping region */
3368 SelectClipRgn( hdc
, clipping
);
3369 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3370 if (winetest_debug
> 0) dump_region(hrgn
);
3371 /* create a region with what is expected */
3372 SetRectRgn( exprgn
, 39,10,49,74);
3373 SetRectRgn( tmprgn
, 80,79,90,85);
3374 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3375 SetRectRgn( tmprgn
, 10,85,90,90);
3376 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3377 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3378 trace("update rect is %d,%d - %d,%d\n",
3379 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3380 ReleaseDC( hwnd1
, hdc
);
3382 /* test scrolling a window with an update region */
3383 DestroyWindow( hwnd2
);
3384 ValidateRect( hwnd1
, NULL
);
3385 SetRect( &rc
, 40,40, 50,50);
3386 InvalidateRect( hwnd1
, &rc
, 1);
3387 GetClientRect( hwnd1
, &rc
);
3389 ScrollWindowEx( hwnd1
, -10, 0, &rc
, &cliprc
, hrgn
, &rcu
,
3390 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3391 if (winetest_debug
> 0) dump_region(hrgn
);
3392 SetRectRgn( exprgn
, 88,0,98,98);
3393 SetRectRgn( tmprgn
, 30, 40, 50, 50);
3394 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3395 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3397 /* clear an update region */
3398 UpdateWindow( hwnd1
);
3400 SetRect( &rc
, 0,40, 100,60);
3401 SetRect( &cliprc
, 0,0, 100,100);
3402 ScrollWindowEx( hwnd1
, 0, -25, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3403 if (winetest_debug
> 0) dump_region( hrgn
);
3404 SetRectRgn( exprgn
, 0, 40, 98, 60 );
3405 ok( EqualRgn( exprgn
, hrgn
), "wrong update region in excessive scroll\n");
3407 /* now test ScrollWindowEx with a combination of
3408 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3409 /* make hwnd2 the child of hwnd1 */
3410 hwnd2
= CreateWindowExA(0, "static", NULL
,
3411 WS_CHILD
| WS_VISIBLE
| WS_BORDER
,
3412 50, 50, 100, 100, hwnd1
, 0, 0, NULL
);
3413 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPSIBLINGS
);
3414 GetClientRect( hwnd1
, &rc
);
3417 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3418 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3419 ValidateRect( hwnd1
, NULL
);
3420 ValidateRect( hwnd2
, NULL
);
3421 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
,
3422 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3423 if (winetest_debug
> 0) dump_region(hrgn
);
3424 SetRectRgn( exprgn
, 88,0,98,88);
3425 SetRectRgn( tmprgn
, 0,88,98,98);
3426 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3427 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3429 /* SW_SCROLLCHILDREN */
3430 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3431 ValidateRect( hwnd1
, NULL
);
3432 ValidateRect( hwnd2
, NULL
);
3433 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3434 if (winetest_debug
> 0) dump_region(hrgn
);
3435 /* expected region is the same as in previous test */
3436 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3438 /* no SW_SCROLLCHILDREN */
3439 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3440 ValidateRect( hwnd1
, NULL
);
3441 ValidateRect( hwnd2
, NULL
);
3442 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3443 if (winetest_debug
> 0) dump_region(hrgn
);
3444 /* expected region is the same as in previous test */
3445 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3447 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3448 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3449 ValidateRect( hwnd1
, NULL
);
3450 ValidateRect( hwnd2
, NULL
);
3451 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3452 if (winetest_debug
> 0) dump_region(hrgn
);
3453 SetRectRgn( exprgn
, 88,0,98,20);
3454 SetRectRgn( tmprgn
, 20,20,98,30);
3455 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3456 SetRectRgn( tmprgn
, 20,30,30,88);
3457 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3458 SetRectRgn( tmprgn
, 0,88,30,98);
3459 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3460 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3463 DeleteObject( hrgn
);
3464 DeleteObject( exprgn
);
3465 DeleteObject( tmprgn
);
3466 DestroyWindow( hwnd1
);
3467 DestroyWindow( hwnd2
);
3470 /* couple of tests of return values of scrollbar functions
3471 * called on a scrollbarless window */
3472 static void test_scroll(void)
3477 HWND hwnd
= CreateWindowExA(0, "Static", "Wine test window",
3478 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_POPUP
,
3479 100, 100, 200, 200, 0, 0, 0, NULL
);
3481 ret
= GetScrollRange( hwnd
, SB_HORZ
, &min
, &max
);
3482 if (!ret
) /* win9x */
3484 win_skip( "GetScrollRange doesn't work\n" );
3485 DestroyWindow( hwnd
);
3488 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3489 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3490 si
.cbSize
= sizeof( si
);
3491 si
.fMask
= SIF_PAGE
;
3492 si
.nPage
= 0xdeadbeef;
3493 ret
= GetScrollInfo( hwnd
, SB_HORZ
, &si
);
3494 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3495 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3497 ret
= GetScrollRange( hwnd
, SB_VERT
, &min
, &max
);
3498 ok( ret
, "GetScrollRange returns FALSE\n");
3499 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3500 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3501 si
.cbSize
= sizeof( si
);
3502 si
.fMask
= SIF_PAGE
;
3503 si
.nPage
= 0xdeadbeef;
3504 ret
= GetScrollInfo( hwnd
, SB_VERT
, &si
);
3505 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3506 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3508 DestroyWindow( hwnd
);
3511 static void test_scrolldc( HWND parent
)
3514 HRGN exprgn
, tmprgn
, hrgn
;
3515 RECT rc
, rc2
, rcu
, cliprc
;
3519 hrgn
= CreateRectRgn(0,0,0,0);
3520 tmprgn
= CreateRectRgn(0,0,0,0);
3521 exprgn
= CreateRectRgn(0,0,0,0);
3523 hwnd1
= CreateWindowExA(0, "static", NULL
,
3524 WS_CHILD
| WS_VISIBLE
,
3525 25, 50, 100, 100, parent
, 0, 0, NULL
);
3526 ShowWindow( parent
, SW_SHOW
);
3527 UpdateWindow( parent
);
3528 flush_events( TRUE
);
3529 GetClientRect( hwnd1
, &rc
);
3530 hdc
= GetDC( hwnd1
);
3531 /* paint the upper half of the window black */
3533 rc2
.bottom
= ( rc
.top
+ rc
.bottom
) /2;
3534 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3535 /* clip region is the lower half */
3537 cliprc
.top
= (rc
.top
+ rc
.bottom
) /2;
3538 /* test whether scrolled pixels are properly clipped */
3539 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3540 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3541 /* this scroll should not cause any visible changes */
3542 ScrollDC( hdc
, 5, -20, &rc
, &cliprc
, hrgn
, &rcu
);
3543 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3544 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3545 /* test with NULL clip rect */
3546 ScrollDC( hdc
, 20, -20, &rc
, NULL
, hrgn
, &rcu
);
3547 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3548 trace("update rect: %d,%d - %d,%d\n",
3549 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3550 if (winetest_debug
> 0) dump_region(hrgn
);
3551 SetRect(&rc2
, 0, 0, 100, 100);
3552 ok(EqualRect(&rcu
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3553 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
3555 SetRectRgn( exprgn
, 0, 0, 20, 80);
3556 SetRectRgn( tmprgn
, 0, 80, 100, 100);
3557 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3558 if (winetest_debug
> 0) dump_region(exprgn
);
3559 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3560 /* test clip rect > scroll rect */
3561 FillRect( hdc
, &rc
, GetStockObject(WHITE_BRUSH
));
3563 InflateRect( &rc2
, -(rc
.right
-rc
.left
)/4, -(rc
.bottom
-rc
.top
)/4);
3564 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3565 ScrollDC( hdc
, 10, 10, &rc2
, &rc
, hrgn
, &rcu
);
3566 SetRectRgn( exprgn
, 25, 25, 75, 35);
3567 SetRectRgn( tmprgn
, 25, 35, 35, 75);
3568 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3569 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3570 trace("update rect: %d,%d - %d,%d\n",
3571 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3572 if (winetest_debug
> 0) dump_region(hrgn
);
3576 DeleteObject(exprgn
);
3577 DeleteObject(tmprgn
);
3578 DestroyWindow(hwnd1
);
3581 static void test_params(void)
3586 /* Just a param check */
3587 if (pGetMonitorInfoA
)
3589 SetLastError(0xdeadbeef);
3590 rc
= GetWindowText(hwndMain2
, NULL
, 1024);
3591 ok( rc
==0, "GetWindowText: rc=%d err=%d\n",rc
,GetLastError());
3595 /* Skips actually on Win95 and NT4 */
3596 win_skip("Test would crash on Win95\n");
3599 SetLastError(0xdeadbeef);
3600 hwnd
=CreateWindow("LISTBOX", "TestList",
3601 (LBS_STANDARD
& ~LBS_SORT
),
3603 NULL
, (HMENU
)1, NULL
, 0);
3605 ok(!hwnd
|| broken(hwnd
!= NULL
), /* w2k3 sp2 */
3606 "CreateWindow with invalid menu handle should fail\n");
3608 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
|| /* NT */
3609 GetLastError() == 0xdeadbeef, /* Win9x */
3610 "wrong last error value %d\n", GetLastError());
3613 static void test_AWRwindow(LPCSTR
class, LONG style
, LONG exStyle
, BOOL menu
)
3617 hwnd
= CreateWindowEx(exStyle
, class, class, style
,
3624 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style
, exStyle
);
3627 ShowWindow(hwnd
, SW_SHOW
);
3629 test_nonclient_area(hwnd
);
3632 DestroyWindow(hwnd
);
3635 static BOOL
AWR_init(void)
3639 class.style
= CS_HREDRAW
| CS_VREDRAW
;
3640 class.lpfnWndProc
= DefWindowProcA
;
3641 class.cbClsExtra
= 0;
3642 class.cbWndExtra
= 0;
3643 class.hInstance
= 0;
3644 class.hIcon
= LoadIcon (0, IDI_APPLICATION
);
3645 class.hCursor
= LoadCursor (0, IDC_ARROW
);
3646 class.hbrBackground
= 0;
3647 class.lpszMenuName
= 0;
3648 class.lpszClassName
= szAWRClass
;
3650 if (!RegisterClass (&class)) {
3651 ok(FALSE
, "RegisterClass failed\n");
3655 hmenu
= CreateMenu();
3658 ok(hmenu
!= 0, "Failed to create menu\n");
3659 ok(AppendMenu(hmenu
, MF_STRING
, 1, "Test!"), "Failed to create menu item\n");
3665 static void test_AWR_window_size(BOOL menu
)
3669 WS_MAXIMIZE
, WS_BORDER
, WS_DLGFRAME
,
3672 WS_MINIMIZEBOX
, WS_MAXIMIZEBOX
,
3673 WS_HSCROLL
, WS_VSCROLL
3677 WS_EX_TOOLWINDOW
, WS_EX_WINDOWEDGE
,
3680 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3681 WS_EX_DLGMODALFRAME
,
3688 /* A exhaustive check of all the styles takes too long
3689 * so just do a (hopefully representative) sample
3691 for (i
= 0; i
< COUNTOF(styles
); ++i
)
3692 test_AWRwindow(szAWRClass
, styles
[i
], 0, menu
);
3693 for (i
= 0; i
< COUNTOF(exStyles
); ++i
) {
3694 test_AWRwindow(szAWRClass
, WS_POPUP
, exStyles
[i
], menu
);
3695 test_AWRwindow(szAWRClass
, WS_THICKFRAME
, exStyles
[i
], menu
);
3700 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3702 static void test_AdjustWindowRect(void)
3707 SHOWSYSMETRIC(SM_CYCAPTION
);
3708 SHOWSYSMETRIC(SM_CYSMCAPTION
);
3709 SHOWSYSMETRIC(SM_CYMENU
);
3710 SHOWSYSMETRIC(SM_CXEDGE
);
3711 SHOWSYSMETRIC(SM_CYEDGE
);
3712 SHOWSYSMETRIC(SM_CXVSCROLL
);
3713 SHOWSYSMETRIC(SM_CYHSCROLL
);
3714 SHOWSYSMETRIC(SM_CXFRAME
);
3715 SHOWSYSMETRIC(SM_CYFRAME
);
3716 SHOWSYSMETRIC(SM_CXDLGFRAME
);
3717 SHOWSYSMETRIC(SM_CYDLGFRAME
);
3718 SHOWSYSMETRIC(SM_CXBORDER
);
3719 SHOWSYSMETRIC(SM_CYBORDER
);
3721 test_AWR_window_size(FALSE
);
3722 test_AWR_window_size(TRUE
);
3726 #undef SHOWSYSMETRIC
3729 /* Global variables to trigger exit from loop */
3730 static int redrawComplete
, WMPAINT_count
;
3732 static LRESULT WINAPI
redraw_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3737 trace("doing WM_PAINT %d\n", WMPAINT_count
);
3739 if (WMPAINT_count
> 10 && redrawComplete
== 0) {
3741 BeginPaint(hwnd
, &ps
);
3742 EndPaint(hwnd
, &ps
);
3747 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3750 /* Ensure we exit from RedrawNow regardless of invalidated area */
3751 static void test_redrawnow(void)
3756 cls
.style
= CS_DBLCLKS
;
3757 cls
.lpfnWndProc
= redraw_window_procA
;
3760 cls
.hInstance
= GetModuleHandleA(0);
3762 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
3763 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3764 cls
.lpszMenuName
= NULL
;
3765 cls
.lpszClassName
= "RedrawWindowClass";
3767 if(!RegisterClassA(&cls
)) {
3768 trace("Register failed %d\n", GetLastError());
3772 hwndMain
= CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3773 CW_USEDEFAULT
, 0, 100, 100, NULL
, NULL
, 0, NULL
);
3775 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3776 ShowWindow(hwndMain
, SW_SHOW
);
3777 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3778 RedrawWindow(hwndMain
, NULL
,NULL
,RDW_UPDATENOW
| RDW_ALLCHILDREN
);
3779 ok( WMPAINT_count
== 1 || broken(WMPAINT_count
== 0), /* sometimes on win9x */
3780 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3781 redrawComplete
= TRUE
;
3782 ok( WMPAINT_count
< 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count
);
3785 DestroyWindow( hwndMain
);
3788 struct parentdc_stat
{
3794 struct parentdc_test
{
3795 struct parentdc_stat main
, main_todo
;
3796 struct parentdc_stat child1
, child1_todo
;
3797 struct parentdc_stat child2
, child2_todo
;
3800 static LRESULT WINAPI
parentdc_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3805 struct parentdc_stat
*t
= (struct parentdc_stat
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
3810 GetClientRect(hwnd
, &rc
);
3811 CopyRect(&t
->client
, &rc
);
3812 GetWindowRect(hwnd
, &rc
);
3813 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd
,
3814 t
->client
.left
, t
->client
.top
, t
->client
.right
, t
->client
.bottom
,
3815 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3816 BeginPaint(hwnd
, &ps
);
3817 CopyRect(&t
->paint
, &ps
.rcPaint
);
3818 GetClipBox(ps
.hdc
, &rc
);
3819 CopyRect(&t
->clip
, &rc
);
3820 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
3821 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
3822 ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
3823 EndPaint(hwnd
, &ps
);
3826 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3829 static void zero_parentdc_stat(struct parentdc_stat
*t
)
3831 SetRectEmpty(&t
->client
);
3832 SetRectEmpty(&t
->clip
);
3833 SetRectEmpty(&t
->paint
);
3836 static void zero_parentdc_test(struct parentdc_test
*t
)
3838 zero_parentdc_stat(&t
->main
);
3839 zero_parentdc_stat(&t
->child1
);
3840 zero_parentdc_stat(&t
->child2
);
3843 #define parentdc_field_ok(t, w, r, f, got) \
3844 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3845 ": expected %d, got %d\n", \
3848 #define parentdc_todo_field_ok(t, w, r, f, got) \
3849 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3850 else parentdc_field_ok(t, w, r, f, got)
3852 #define parentdc_rect_ok(t, w, r, got) \
3853 parentdc_todo_field_ok(t, w, r, left, got); \
3854 parentdc_todo_field_ok(t, w, r, top, got); \
3855 parentdc_todo_field_ok(t, w, r, right, got); \
3856 parentdc_todo_field_ok(t, w, r, bottom, got);
3858 #define parentdc_win_ok(t, w, got) \
3859 parentdc_rect_ok(t, w, client, got); \
3860 parentdc_rect_ok(t, w, clip, got); \
3861 parentdc_rect_ok(t, w, paint, got);
3863 #define parentdc_ok(t, got) \
3864 parentdc_win_ok(t, main, got); \
3865 parentdc_win_ok(t, child1, got); \
3866 parentdc_win_ok(t, child2, got);
3868 static void test_csparentdc(void)
3870 WNDCLASSA clsMain
, cls
;
3871 HWND hwndMain
, hwnd1
, hwnd2
;
3874 struct parentdc_test test_answer
;
3876 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3877 const struct parentdc_test test1
=
3879 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo
,
3880 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3881 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3884 const struct parentdc_test test2
=
3886 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo
,
3887 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3888 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3891 const struct parentdc_test test3
=
3893 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3894 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3895 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3898 const struct parentdc_test test4
=
3900 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo
,
3901 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo
,
3902 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3905 const struct parentdc_test test5
=
3907 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo
,
3908 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3909 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3912 const struct parentdc_test test6
=
3914 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3915 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3916 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3919 const struct parentdc_test test7
=
3921 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3922 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3923 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3927 clsMain
.style
= CS_DBLCLKS
;
3928 clsMain
.lpfnWndProc
= parentdc_window_procA
;
3929 clsMain
.cbClsExtra
= 0;
3930 clsMain
.cbWndExtra
= 0;
3931 clsMain
.hInstance
= GetModuleHandleA(0);
3933 clsMain
.hCursor
= LoadCursorA(0, IDC_ARROW
);
3934 clsMain
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3935 clsMain
.lpszMenuName
= NULL
;
3936 clsMain
.lpszClassName
= "ParentDcMainWindowClass";
3938 if(!RegisterClassA(&clsMain
)) {
3939 trace("Register failed %d\n", GetLastError());
3943 cls
.style
= CS_DBLCLKS
| CS_PARENTDC
;
3944 cls
.lpfnWndProc
= parentdc_window_procA
;
3947 cls
.hInstance
= GetModuleHandleA(0);
3949 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
3950 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3951 cls
.lpszMenuName
= NULL
;
3952 cls
.lpszClassName
= "ParentDcWindowClass";
3954 if(!RegisterClassA(&cls
)) {
3955 trace("Register failed %d\n", GetLastError());
3959 SetRect(&rc
, 0, 0, 150, 150);
3960 AdjustWindowRectEx(&rc
, WS_OVERLAPPEDWINDOW
, FALSE
, 0);
3961 hwndMain
= CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3962 CW_USEDEFAULT
, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, NULL
, NULL
, 0, NULL
);
3963 SetWindowLongPtrA(hwndMain
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.main
);
3964 hwnd1
= CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD
,
3965 20, 20, 40, 40, hwndMain
, NULL
, 0, NULL
);
3966 SetWindowLongPtrA(hwnd1
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child1
);
3967 hwnd2
= CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD
,
3968 40, 40, 40, 40, hwndMain
, NULL
, 0, NULL
);
3969 SetWindowLongPtrA(hwnd2
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child2
);
3970 ShowWindow(hwndMain
, SW_SHOW
);
3971 ShowWindow(hwnd1
, SW_SHOW
);
3972 ShowWindow(hwnd2
, SW_SHOW
);
3973 SetWindowPos(hwndMain
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3974 flush_events( TRUE
);
3976 zero_parentdc_test(&test_answer
);
3977 InvalidateRect(hwndMain
, NULL
, TRUE
);
3978 flush_events( TRUE
);
3979 parentdc_ok(test1
, test_answer
);
3981 zero_parentdc_test(&test_answer
);
3982 SetRect(&rc
, 0, 0, 50, 50);
3983 InvalidateRect(hwndMain
, &rc
, TRUE
);
3984 flush_events( TRUE
);
3985 parentdc_ok(test2
, test_answer
);
3987 zero_parentdc_test(&test_answer
);
3988 SetRect(&rc
, 0, 0, 10, 10);
3989 InvalidateRect(hwndMain
, &rc
, TRUE
);
3990 flush_events( TRUE
);
3991 parentdc_ok(test3
, test_answer
);
3993 zero_parentdc_test(&test_answer
);
3994 SetRect(&rc
, 40, 40, 50, 50);
3995 InvalidateRect(hwndMain
, &rc
, TRUE
);
3996 flush_events( TRUE
);
3997 parentdc_ok(test4
, test_answer
);
3999 zero_parentdc_test(&test_answer
);
4000 SetRect(&rc
, 20, 20, 60, 60);
4001 InvalidateRect(hwndMain
, &rc
, TRUE
);
4002 flush_events( TRUE
);
4003 parentdc_ok(test5
, test_answer
);
4005 zero_parentdc_test(&test_answer
);
4006 SetRect(&rc
, 0, 0, 10, 10);
4007 InvalidateRect(hwnd1
, &rc
, TRUE
);
4008 flush_events( TRUE
);
4009 parentdc_ok(test6
, test_answer
);
4011 zero_parentdc_test(&test_answer
);
4012 SetRect(&rc
, -5, -5, 65, 65);
4013 InvalidateRect(hwnd1
, &rc
, TRUE
);
4014 flush_events( TRUE
);
4015 parentdc_ok(test7
, test_answer
);
4017 DestroyWindow(hwndMain
);
4018 DestroyWindow(hwnd1
);
4019 DestroyWindow(hwnd2
);
4022 static LRESULT WINAPI
def_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4024 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
4027 static LRESULT WINAPI
def_window_procW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
4029 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
4032 static void test_IsWindowUnicode(void)
4034 static const char ansi_class_nameA
[] = "ansi class name";
4035 static const WCHAR ansi_class_nameW
[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
4036 static const char unicode_class_nameA
[] = "unicode class name";
4037 static const WCHAR unicode_class_nameW
[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
4042 memset(&classW
, 0, sizeof(classW
));
4043 classW
.hInstance
= GetModuleHandleA(0);
4044 classW
.lpfnWndProc
= def_window_procW
;
4045 classW
.lpszClassName
= unicode_class_nameW
;
4046 if (!RegisterClassW(&classW
)) return; /* this catches Win9x as well */
4048 memset(&classA
, 0, sizeof(classA
));
4049 classA
.hInstance
= GetModuleHandleA(0);
4050 classA
.lpfnWndProc
= def_window_procA
;
4051 classA
.lpszClassName
= ansi_class_nameA
;
4052 assert(RegisterClassA(&classA
));
4054 /* unicode class: window proc */
4055 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
4056 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4059 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4060 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
4061 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4062 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
4063 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4065 DestroyWindow(hwnd
);
4067 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
4068 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4071 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4072 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
4073 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4074 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
4075 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4077 DestroyWindow(hwnd
);
4079 /* ansi class: window proc */
4080 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
4081 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4084 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4085 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
4086 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4087 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
4088 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4090 DestroyWindow(hwnd
);
4092 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
4093 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4096 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4097 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
4098 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4099 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
4100 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4102 DestroyWindow(hwnd
);
4104 /* unicode class: class proc */
4105 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
4106 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4109 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4110 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
4111 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4112 /* do not restore class window proc back to unicode */
4114 DestroyWindow(hwnd
);
4116 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
4117 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4120 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4121 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
4122 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4124 DestroyWindow(hwnd
);
4126 /* ansi class: class proc */
4127 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
4128 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4131 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4132 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
4133 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4134 /* do not restore class window proc back to ansi */
4136 DestroyWindow(hwnd
);
4138 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
4139 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4142 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4143 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
4144 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4146 DestroyWindow(hwnd
);
4149 static LRESULT CALLBACK
minmax_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
4153 if (msg
!= WM_GETMINMAXINFO
)
4154 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4156 minmax
= (MINMAXINFO
*)lp
;
4158 if ((GetWindowLong(hwnd
, GWL_STYLE
) & WS_CHILD
))
4160 minmax
->ptReserved
.x
= 0;
4161 minmax
->ptReserved
.y
= 0;
4162 minmax
->ptMaxSize
.x
= 400;
4163 minmax
->ptMaxSize
.y
= 400;
4164 minmax
->ptMaxPosition
.x
= 300;
4165 minmax
->ptMaxPosition
.y
= 300;
4166 minmax
->ptMaxTrackSize
.x
= 200;
4167 minmax
->ptMaxTrackSize
.y
= 200;
4168 minmax
->ptMinTrackSize
.x
= 100;
4169 minmax
->ptMinTrackSize
.y
= 100;
4172 DefWindowProc(hwnd
, msg
, wp
, lp
);
4176 static int expected_cx
, expected_cy
;
4177 static RECT expected_rect
, broken_rect
;
4179 static LRESULT CALLBACK
winsizes_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
4183 case WM_GETMINMAXINFO
:
4186 GetWindowRect( hwnd
, &rect
);
4187 ok( !rect
.left
&& !rect
.top
&& !rect
.right
&& !rect
.bottom
,
4188 "wrong rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4189 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4194 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
4196 GetWindowRect( hwnd
, &rect
);
4197 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
4198 hwnd
, msg
, cs
->cx
, cs
->cy
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4199 ok( cs
->cx
== expected_cx
|| broken(cs
->cx
== (short)expected_cx
),
4200 "wrong x size %d/%d\n", cs
->cx
, expected_cx
);
4201 ok( cs
->cy
== expected_cy
|| broken(cs
->cy
== (short)expected_cy
),
4202 "wrong y size %d/%d\n", cs
->cy
, expected_cy
);
4203 ok( (rect
.right
- rect
.left
== expected_rect
.right
- expected_rect
.left
&&
4204 rect
.bottom
- rect
.top
== expected_rect
.bottom
- expected_rect
.top
) ||
4205 broken( rect
.right
- rect
.left
== broken_rect
.right
- broken_rect
.left
&&
4206 rect
.bottom
- rect
.top
== broken_rect
.bottom
- broken_rect
.top
) ||
4207 broken( rect
.right
- rect
.left
== (short)broken_rect
.right
- (short)broken_rect
.left
&&
4208 rect
.bottom
- rect
.top
== (short)broken_rect
.bottom
- (short)broken_rect
.top
),
4209 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
4210 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
4211 expected_rect
.left
, expected_rect
.top
, expected_rect
.right
, expected_rect
.bottom
);
4212 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4216 RECT rect
, *r
= (RECT
*)lp
;
4217 GetWindowRect( hwnd
, &rect
);
4218 ok( !memcmp( &rect
, r
, sizeof(rect
) ),
4219 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
4220 r
->left
, r
->top
, r
->right
, r
->bottom
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4221 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4224 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4228 static void test_CreateWindow(void)
4236 #define expect_menu(window, menu) \
4237 SetLastError(0xdeadbeef); \
4238 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
4240 #define expect_style(window, style)\
4241 ok((ULONG)GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
4243 #define expect_ex_style(window, ex_style)\
4244 ok((ULONG)GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
4246 #define expect_gle_broken_9x(gle)\
4247 ok(GetLastError() == gle ||\
4248 broken(GetLastError() == 0xdeadbeef),\
4249 "IsMenu set error %d\n", GetLastError())
4251 hmenu
= CreateMenu();
4253 parent
= GetDesktopWindow();
4254 assert(parent
!= 0);
4256 SetLastError(0xdeadbeef);
4257 ok(IsMenu(hmenu
), "IsMenu error %d\n", GetLastError());
4260 SetLastError(0xdeadbeef);
4261 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
,
4262 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4263 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4264 expect_menu(hwnd
, 1);
4265 expect_style(hwnd
, WS_CHILD
);
4266 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4267 DestroyWindow(hwnd
);
4269 SetLastError(0xdeadbeef);
4270 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_CAPTION
,
4271 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4272 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4273 expect_menu(hwnd
, 1);
4274 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
4275 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4276 DestroyWindow(hwnd
);
4278 SetLastError(0xdeadbeef);
4279 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
,
4280 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4281 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4282 expect_menu(hwnd
, 1);
4283 expect_style(hwnd
, WS_CHILD
);
4284 expect_ex_style(hwnd
, 0);
4285 DestroyWindow(hwnd
);
4287 SetLastError(0xdeadbeef);
4288 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_CAPTION
,
4289 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4290 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4291 expect_menu(hwnd
, 1);
4292 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
4293 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4294 DestroyWindow(hwnd
);
4297 SetLastError(0xdeadbeef);
4298 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
4299 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4300 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4301 expect_menu(hwnd
, hmenu
);
4302 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4303 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4304 DestroyWindow(hwnd
);
4305 SetLastError(0xdeadbeef);
4306 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4307 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4309 hmenu
= CreateMenu();
4311 SetLastError(0xdeadbeef);
4312 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4313 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4314 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4315 expect_menu(hwnd
, hmenu
);
4316 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4317 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4318 DestroyWindow(hwnd
);
4319 SetLastError(0xdeadbeef);
4320 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4321 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4323 hmenu
= CreateMenu();
4325 SetLastError(0xdeadbeef);
4326 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
,
4327 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4328 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4329 expect_menu(hwnd
, hmenu
);
4330 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4331 expect_ex_style(hwnd
, 0);
4332 DestroyWindow(hwnd
);
4333 SetLastError(0xdeadbeef);
4334 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4335 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4337 hmenu
= CreateMenu();
4339 SetLastError(0xdeadbeef);
4340 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4341 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4342 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4343 expect_menu(hwnd
, hmenu
);
4344 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4345 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4346 DestroyWindow(hwnd
);
4347 SetLastError(0xdeadbeef);
4348 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4349 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4351 /* WS_CHILD | WS_POPUP */
4352 SetLastError(0xdeadbeef);
4353 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4354 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4355 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
4356 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4358 DestroyWindow(hwnd
);
4360 hmenu
= CreateMenu();
4362 SetLastError(0xdeadbeef);
4363 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4364 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4365 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4366 expect_menu(hwnd
, hmenu
);
4367 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4368 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4369 DestroyWindow(hwnd
);
4370 SetLastError(0xdeadbeef);
4371 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4372 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4374 SetLastError(0xdeadbeef);
4375 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4376 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4377 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
4378 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4380 DestroyWindow(hwnd
);
4382 hmenu
= CreateMenu();
4384 SetLastError(0xdeadbeef);
4385 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4386 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4387 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4388 expect_menu(hwnd
, hmenu
);
4389 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4390 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4391 DestroyWindow(hwnd
);
4392 SetLastError(0xdeadbeef);
4393 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4394 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4396 SetLastError(0xdeadbeef);
4397 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4398 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4399 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
4400 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4402 DestroyWindow(hwnd
);
4404 hmenu
= CreateMenu();
4406 SetLastError(0xdeadbeef);
4407 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4408 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4409 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4410 expect_menu(hwnd
, hmenu
);
4411 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4412 expect_ex_style(hwnd
, 0);
4413 DestroyWindow(hwnd
);
4414 SetLastError(0xdeadbeef);
4415 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4416 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4418 SetLastError(0xdeadbeef);
4419 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4420 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4421 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
4422 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4424 DestroyWindow(hwnd
);
4426 hmenu
= CreateMenu();
4428 SetLastError(0xdeadbeef);
4429 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4430 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4431 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4432 expect_menu(hwnd
, hmenu
);
4433 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4434 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4435 DestroyWindow(hwnd
);
4436 SetLastError(0xdeadbeef);
4437 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4438 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4440 /* test child window sizing */
4442 cls
.lpfnWndProc
= minmax_wnd_proc
;
4445 cls
.hInstance
= GetModuleHandle(0);
4447 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
4448 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4449 cls
.lpszMenuName
= NULL
;
4450 cls
.lpszClassName
= "MinMax_WndClass";
4451 RegisterClass(&cls
);
4453 SetLastError(0xdeadbeef);
4454 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4455 0, 0, 100, 100, 0, 0, 0, NULL
);
4456 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
4457 expect_menu(parent
, 0);
4458 expect_style(parent
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
| WS_CLIPSIBLINGS
);
4459 expect_ex_style(parent
, WS_EX_WINDOWEDGE
);
4461 memset(&minmax
, 0, sizeof(minmax
));
4462 SendMessage(parent
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4463 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxSize
.x
, minmax
.ptMaxSize
.y
);
4464 ok(IsRectEmpty(&rc_minmax
), "ptMaxSize is not empty\n");
4465 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4466 ok(IsRectEmpty(&rc_minmax
), "ptMaxTrackSize is not empty\n");
4468 GetWindowRect(parent
, &rc
);
4469 ok(!IsRectEmpty(&rc
), "parent window rect is empty\n");
4470 GetClientRect(parent
, &rc
);
4471 ok(!IsRectEmpty(&rc
), "parent client rect is empty\n");
4473 InflateRect(&rc
, 200, 200);
4474 trace("creating child with rect (%d,%d-%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4476 SetLastError(0xdeadbeef);
4477 hwnd
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4478 rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
4479 parent
, (HMENU
)1, 0, NULL
);
4480 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4481 expect_menu(hwnd
, 1);
4482 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
);
4483 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4485 memset(&minmax
, 0, sizeof(minmax
));
4486 SendMessage(hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4487 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4489 GetWindowRect(hwnd
, &rc
);
4490 OffsetRect(&rc
, -rc
.left
, -rc
.top
);
4491 ok(EqualRect(&rc
, &rc_minmax
), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4492 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
4493 rc_minmax
.left
, rc_minmax
.top
, rc_minmax
.right
, rc_minmax
.bottom
);
4494 DestroyWindow(hwnd
);
4496 cls
.lpfnWndProc
= winsizes_wnd_proc
;
4497 cls
.lpszClassName
= "Sizes_WndClass";
4498 RegisterClass(&cls
);
4500 expected_cx
= expected_cy
= 200000;
4501 SetRect( &expected_rect
, 0, 0, 200000, 200000 );
4502 broken_rect
= expected_rect
;
4503 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 300000, 300000, 200000, 200000, parent
, 0, 0, NULL
);
4504 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4505 GetClientRect( hwnd
, &rc
);
4506 ok( rc
.right
== 200000 || broken(rc
.right
== (short)200000), "invalid rect right %u\n", rc
.right
);
4507 ok( rc
.bottom
== 200000 || broken(rc
.bottom
== (short)200000), "invalid rect bottom %u\n", rc
.bottom
);
4508 DestroyWindow(hwnd
);
4510 expected_cx
= expected_cy
= -10;
4511 SetRect( &expected_rect
, 0, 0, 0, 0 );
4512 SetRect( &broken_rect
, 0, 0, -10, -10 );
4513 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -20, -20, -10, -10, parent
, 0, 0, NULL
);
4514 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4515 GetClientRect( hwnd
, &rc
);
4516 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4517 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4518 DestroyWindow(hwnd
);
4520 expected_cx
= expected_cy
= -200000;
4521 SetRect( &expected_rect
, 0, 0, 0, 0 );
4522 SetRect( &broken_rect
, 0, 0, -200000, -200000 );
4523 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -300000, -300000, -200000, -200000, parent
, 0, 0, NULL
);
4524 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4525 GetClientRect( hwnd
, &rc
);
4526 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4527 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4528 DestroyWindow(hwnd
);
4530 /* we need a parent at 0,0 so that child coordinates match */
4531 DestroyWindow(parent
);
4532 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_POPUP
, 0, 0, 100, 100, 0, 0, 0, NULL
);
4533 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
4536 expected_cy
= 0x7fffffff;
4537 SetRect( &expected_rect
, 10, 10, 110, 0x7fffffff );
4538 SetRect( &broken_rect
, 10, 10, 110, 0x7fffffffU
+ 10 );
4539 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 10, 10, 100, 0x7fffffff, parent
, 0, 0, NULL
);
4540 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4541 GetClientRect( hwnd
, &rc
);
4542 ok( rc
.right
== 100, "invalid rect right %u\n", rc
.right
);
4543 ok( rc
.bottom
== 0x7fffffff - 10 || broken(rc
.bottom
== 0), "invalid rect bottom %u\n", rc
.bottom
);
4544 DestroyWindow(hwnd
);
4546 expected_cx
= 0x7fffffff;
4547 expected_cy
= 0x7fffffff;
4548 SetRect( &expected_rect
, 20, 10, 0x7fffffff, 0x7fffffff );
4549 SetRect( &broken_rect
, 20, 10, 0x7fffffffU
+ 20, 0x7fffffffU
+ 10 );
4550 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 20, 10, 0x7fffffff, 0x7fffffff, parent
, 0, 0, NULL
);
4551 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4552 GetClientRect( hwnd
, &rc
);
4553 ok( rc
.right
== 0x7fffffff - 20 || broken(rc
.right
== 0), "invalid rect right %u\n", rc
.right
);
4554 ok( rc
.bottom
== 0x7fffffff - 10 || broken(rc
.bottom
== 0), "invalid rect bottom %u\n", rc
.bottom
);
4555 DestroyWindow(hwnd
);
4557 /* top level window */
4558 expected_cx
= expected_cy
= 200000;
4559 SetRect( &expected_rect
, 0, 0, GetSystemMetrics(SM_CXMAXTRACK
), GetSystemMetrics(SM_CYMAXTRACK
) );
4560 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_OVERLAPPEDWINDOW
, 300000, 300000, 200000, 200000, 0, 0, 0, NULL
);
4561 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4562 GetClientRect( hwnd
, &rc
);
4563 ok( rc
.right
<= expected_cx
, "invalid rect right %u\n", rc
.right
);
4564 ok( rc
.bottom
<= expected_cy
, "invalid rect bottom %u\n", rc
.bottom
);
4565 DestroyWindow(hwnd
);
4567 DestroyWindow(parent
);
4569 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4570 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4572 #undef expect_gle_broken_9x
4575 #undef expect_ex_style
4578 /* function that remembers whether the system the test is running on sets the
4579 * last error for user32 functions to make the tests stricter */
4580 static int check_error(DWORD actual
, DWORD expected
)
4582 static int sets_last_error
= -1;
4583 if (sets_last_error
== -1)
4584 sets_last_error
= (actual
!= 0xdeadbeef);
4585 return (!sets_last_error
&& (actual
== 0xdeadbeef)) || (actual
== expected
);
4588 static void test_SetWindowLong(void)
4591 WNDPROC old_window_procW
;
4593 SetLastError(0xdeadbeef);
4594 retval
= SetWindowLongPtr(NULL
, GWLP_WNDPROC
, 0);
4595 ok(!retval
, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval
);
4596 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE
),
4597 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4599 SetLastError(0xdeadbeef);
4600 retval
= SetWindowLongPtr(hwndMain
, 0xdeadbeef, 0);
4601 ok(!retval
, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval
);
4602 ok(check_error(GetLastError(), ERROR_INVALID_INDEX
),
4603 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4605 SetLastError(0xdeadbeef);
4606 retval
= SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4607 ok((WNDPROC
)retval
== main_window_procA
|| broken(!retval
), /* win9x */
4608 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval
);
4609 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4610 retval
= GetWindowLongPtr(hwndMain
, GWLP_WNDPROC
);
4611 ok((WNDPROC
)retval
== main_window_procA
,
4612 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4613 ok(!IsWindowUnicode(hwndMain
), "hwndMain shouldn't be Unicode\n");
4615 old_window_procW
= (WNDPROC
)GetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
);
4616 SetLastError(0xdeadbeef);
4617 retval
= SetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
, 0);
4618 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED
)
4620 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4621 ok(retval
!= 0, "SetWindowLongPtr error %d\n", GetLastError());
4622 ok((WNDPROC
)retval
== old_window_procW
,
4623 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4624 ok(IsWindowUnicode(hwndMain
), "hwndMain should now be Unicode\n");
4626 /* set it back to ANSI */
4627 SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4631 static void test_ShowWindow(void)
4638 SetRect(&rcMain
, 120, 120, 210, 210);
4640 hwnd
= CreateWindowEx(0, "MainWindowClass", NULL
,
4641 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4642 WS_MAXIMIZEBOX
| WS_POPUP
,
4643 rcMain
.left
, rcMain
.top
,
4644 rcMain
.right
- rcMain
.left
, rcMain
.bottom
- rcMain
.top
,
4648 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4649 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4650 ok(!(style
& WS_VISIBLE
), "window should not be visible\n");
4651 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4652 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4653 GetWindowRect(hwnd
, &rc
);
4654 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4655 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4656 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4658 ret
= ShowWindow(hwnd
, SW_SHOW
);
4659 ok(!ret
, "not expected ret: %lu\n", ret
);
4660 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4661 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4662 ok(style
& WS_VISIBLE
, "window should be visible\n");
4663 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4664 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4665 GetWindowRect(hwnd
, &rc
);
4666 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4667 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4668 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4670 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4671 ok(ret
, "not expected ret: %lu\n", ret
);
4672 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4673 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4674 ok(style
& WS_VISIBLE
, "window should be visible\n");
4675 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4676 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4677 GetWindowRect(hwnd
, &rc
);
4678 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4680 ShowWindow(hwnd
, SW_RESTORE
);
4681 ok(ret
, "not expected ret: %lu\n", ret
);
4682 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4683 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4684 ok(style
& WS_VISIBLE
, "window should be visible\n");
4685 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4686 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4687 GetWindowRect(hwnd
, &rc
);
4688 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4689 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4690 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4692 ret
= EnableWindow(hwnd
, FALSE
);
4693 ok(!ret
, "not expected ret: %lu\n", ret
);
4694 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4695 ok(style
& WS_DISABLED
, "window should be disabled\n");
4697 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
4698 ok(!ret
, "not expected ret: %lu\n", ret
);
4699 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4700 ok(style
& WS_DISABLED
, "window should be disabled\n");
4701 ok(style
& WS_VISIBLE
, "window should be visible\n");
4702 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4703 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4704 GetWindowRect(hwnd
, &rc
);
4705 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4706 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4707 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4709 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
4710 ok(!ret
, "not expected ret: %lu\n", ret
);
4711 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4712 ok(style
& WS_DISABLED
, "window should be disabled\n");
4713 ok(style
& WS_VISIBLE
, "window should be visible\n");
4714 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4715 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4716 GetWindowRect(hwnd
, &rc
);
4717 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4718 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4719 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4721 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4722 ok(ret
, "not expected ret: %lu\n", ret
);
4723 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4724 ok(style
& WS_DISABLED
, "window should be disabled\n");
4725 ok(style
& WS_VISIBLE
, "window should be visible\n");
4726 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4727 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4728 GetWindowRect(hwnd
, &rc
);
4729 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4731 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
4732 ok(!ret
, "not expected ret: %lu\n", ret
);
4733 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4734 ok(style
& WS_DISABLED
, "window should be disabled\n");
4735 ok(style
& WS_VISIBLE
, "window should be visible\n");
4736 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4737 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4738 GetWindowRect(hwnd
, &rc
);
4739 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4741 ret
= ShowWindow(hwnd
, SW_RESTORE
);
4742 ok(ret
, "not expected ret: %lu\n", ret
);
4743 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4744 ok(style
& WS_DISABLED
, "window should be disabled\n");
4745 ok(style
& WS_VISIBLE
, "window should be visible\n");
4746 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4747 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4748 GetWindowRect(hwnd
, &rc
);
4749 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4750 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4751 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4753 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4754 ok(!ret
, "not expected ret: %lu\n", ret
);
4755 ok(IsWindow(hwnd
), "window should exist\n");
4757 ret
= EnableWindow(hwnd
, TRUE
);
4758 ok(ret
, "not expected ret: %lu\n", ret
);
4760 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4761 ok(!ret
, "not expected ret: %lu\n", ret
);
4762 ok(!IsWindow(hwnd
), "window should not exist\n");
4765 static void test_gettext(void)
4768 LPCSTR clsname
= "gettexttest";
4772 memset( &cls
, 0, sizeof cls
);
4773 cls
.lpfnWndProc
= DefWindowProc
;
4774 cls
.lpszClassName
= clsname
;
4775 cls
.hInstance
= GetModuleHandle(NULL
);
4777 if (!RegisterClass( &cls
)) return;
4779 hwnd
= CreateWindow( clsname
, "test text", WS_OVERLAPPED
, 0, 0, 10, 10, 0, NULL
, NULL
, NULL
);
4780 ok( hwnd
!= NULL
, "window was null\n");
4782 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10, 0x1000);
4783 ok( r
== 0, "settext should return zero\n");
4785 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10000, 0);
4786 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4788 r
= SendMessage( hwnd
, WM_GETTEXT
, 0xff000000, 0x1000);
4789 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4791 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x1000, 0xff000000);
4792 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4794 DestroyWindow(hwnd
);
4795 UnregisterClass( clsname
, NULL
);
4799 static void test_GetUpdateRect(void)
4802 BOOL ret
, parent_wm_paint
, grandparent_wm_paint
;
4804 HWND hgrandparent
, hparent
, hchild
;
4806 static const char classNameA
[] = "GetUpdateRectClass";
4808 hgrandparent
= CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW
,
4809 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4811 hparent
= CreateWindowA("static", "parent", WS_CHILD
|WS_VISIBLE
,
4812 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4814 hchild
= CreateWindowA("static", "child", WS_CHILD
|WS_VISIBLE
,
4815 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4817 ShowWindow(hgrandparent
, SW_SHOW
);
4818 UpdateWindow(hgrandparent
);
4819 flush_events( TRUE
);
4821 ShowWindow(hchild
, SW_HIDE
);
4822 SetRect(&rc2
, 0, 0, 0, 0);
4823 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4824 ok(!ret
, "GetUpdateRect returned not empty region\n");
4825 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4826 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4827 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4829 SetRect(&rc2
, 10, 10, 40, 40);
4830 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
4831 ok(ret
, "GetUpdateRect returned empty region\n");
4832 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4833 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4834 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4836 parent_wm_paint
= FALSE
;
4837 grandparent_wm_paint
= FALSE
;
4838 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
4840 if (msg
.message
== WM_PAINT
)
4842 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
4843 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
4845 DispatchMessage(&msg
);
4847 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
4848 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
4850 DestroyWindow(hgrandparent
);
4853 cls
.lpfnWndProc
= DefWindowProcA
;
4856 cls
.hInstance
= GetModuleHandleA(0);
4858 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
4859 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4860 cls
.lpszMenuName
= NULL
;
4861 cls
.lpszClassName
= classNameA
;
4863 if(!RegisterClassA(&cls
)) {
4864 trace("Register failed %d\n", GetLastError());
4868 hgrandparent
= CreateWindowA(classNameA
, "grandparent", WS_OVERLAPPEDWINDOW
,
4869 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4871 hparent
= CreateWindowA(classNameA
, "parent", WS_CHILD
|WS_VISIBLE
,
4872 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4874 hchild
= CreateWindowA(classNameA
, "child", WS_CHILD
|WS_VISIBLE
,
4875 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4877 ShowWindow(hgrandparent
, SW_SHOW
);
4878 UpdateWindow(hgrandparent
);
4879 flush_events( TRUE
);
4881 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4882 ok(!ret
, "GetUpdateRect returned not empty region\n");
4884 ShowWindow(hchild
, SW_HIDE
);
4886 SetRect(&rc2
, 0, 0, 0, 0);
4887 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4888 ok(!ret
, "GetUpdateRect returned not empty region\n");
4889 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4890 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4891 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4893 SetRect(&rc2
, 10, 10, 40, 40);
4894 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
4895 ok(ret
, "GetUpdateRect returned empty region\n");
4896 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4897 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4898 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4900 parent_wm_paint
= FALSE
;
4901 grandparent_wm_paint
= FALSE
;
4902 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
4904 if (msg
.message
== WM_PAINT
)
4906 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
4907 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
4909 DispatchMessage(&msg
);
4911 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
4912 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
4914 DestroyWindow(hgrandparent
);
4918 static LRESULT CALLBACK
TestExposedRegion_WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4926 const int waitTime
= 2000;
4928 BeginPaint(hwnd
, &ps
);
4930 /* create and destroy window to create an exposed region on this window */
4931 win
= CreateWindowA("static", "win", WS_VISIBLE
,
4932 10,10,50,50, NULL
, NULL
, 0, NULL
);
4935 waitResult
= MsgWaitForMultipleObjects( 0, NULL
, FALSE
, waitTime
, QS_PAINT
);
4937 ValidateRect(hwnd
, NULL
);
4938 EndPaint(hwnd
, &ps
);
4940 if(waitResult
!= WAIT_TIMEOUT
)
4942 GetUpdateRect(hwnd
, &updateRect
, FALSE
);
4943 ok(IsRectEmpty(&updateRect
), "Exposed rect should be empty\n");
4948 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
4951 static void test_Expose(void)
4956 memset(&cls
, 0, sizeof(WNDCLASSA
));
4957 cls
.lpfnWndProc
= TestExposedRegion_WndProc
;
4958 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4959 cls
.lpszClassName
= "TestExposeClass";
4960 atom
= RegisterClassA(&cls
);
4962 mw
= CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE
|WS_OVERLAPPEDWINDOW
,
4963 0, 0, 200, 100, NULL
, NULL
, 0, NULL
);
4969 static LRESULT CALLBACK
TestNCRedraw_WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4971 static UINT ncredrawflags
;
4977 ncredrawflags
= *(UINT
*) (((CREATESTRUCT
*)lParam
)->lpCreateParams
);
4980 RedrawWindow(hwnd
, NULL
, NULL
, ncredrawflags
);
4983 BeginPaint(hwnd
, &ps
);
4984 EndPaint(hwnd
, &ps
);
4987 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
4990 static void run_NCRedrawLoop(UINT flags
)
4997 hwnd
= CreateWindowA("TestNCRedrawClass", "MainWindow",
4998 WS_OVERLAPPEDWINDOW
, 0, 0, 200, 100,
4999 NULL
, NULL
, 0, &flags
);
5000 ShowWindow(hwnd
, SW_SHOW
);
5002 while(PeekMessage(&msg
, hwnd
, 0, 0, PM_REMOVE
) != 0)
5004 if (msg
.message
== WM_PAINT
) loopcount
++;
5005 if (loopcount
>= 100) break;
5006 TranslateMessage(&msg
);
5007 DispatchMessage(&msg
);
5008 MsgWaitForMultipleObjects(0, NULL
, FALSE
, 100, QS_ALLINPUT
);
5010 if (flags
== (RDW_INVALIDATE
| RDW_FRAME
))
5011 todo_wine
ok(loopcount
< 100, "Detected infinite WM_PAINT loop (%x).\n", flags
);
5013 ok(loopcount
< 100, "Detected infinite WM_PAINT loop (%x).\n", flags
);
5014 DestroyWindow(hwnd
);
5017 static void test_NCRedraw(void)
5021 wndclass
.lpszClassName
= "TestNCRedrawClass";
5022 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
5023 wndclass
.lpfnWndProc
= TestNCRedraw_WndProc
;
5024 wndclass
.cbClsExtra
= 0;
5025 wndclass
.cbWndExtra
= 0;
5026 wndclass
.hInstance
= 0;
5027 wndclass
.hIcon
= LoadIcon(NULL
, IDI_APPLICATION
);
5028 wndclass
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
5029 wndclass
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5030 wndclass
.lpszMenuName
= NULL
;
5032 RegisterClassA(&wndclass
);
5034 run_NCRedrawLoop(RDW_INVALIDATE
| RDW_FRAME
);
5035 run_NCRedrawLoop(RDW_INVALIDATE
);
5038 static void test_GetWindowModuleFileName(void)
5043 char buf1
[MAX_PATH
], buf2
[MAX_PATH
];
5045 if (!pGetWindowModuleFileNameA
)
5047 win_skip("GetWindowModuleFileNameA is not available\n");
5051 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0,0,0,0, 0, 0, 0, NULL
);
5054 hinst
= (HINSTANCE
)GetWindowLongPtr(hwnd
, GWLP_HINSTANCE
);
5055 ok(hinst
== 0 || broken(hinst
== GetModuleHandle(0)), /* win9x */ "expected 0, got %p\n", hinst
);
5058 SetLastError(0xdeadbeef);
5059 ret1
= GetModuleFileName(hinst
, buf1
, sizeof(buf1
));
5060 ok(ret1
, "GetModuleFileName error %u\n", GetLastError());
5063 SetLastError(0xdeadbeef);
5064 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, sizeof(buf2
));
5065 ok(ret2
|| broken(!ret2
), /* nt4 sp 3 */
5066 "GetWindowModuleFileNameA error %u\n", GetLastError());
5070 ok(ret1
== ret2
|| broken(ret2
== ret1
+ 1), /* win98 */ "%u != %u\n", ret1
, ret2
);
5071 ok(!strcmp(buf1
, buf2
), "%s != %s\n", buf1
, buf2
);
5073 hinst
= GetModuleHandle(0);
5075 SetLastError(0xdeadbeef);
5076 ret2
= GetModuleFileName(hinst
, buf2
, ret1
- 2);
5077 ok(ret2
== ret1
- 2 || broken(ret2
== ret1
- 3), /* win98 */
5078 "expected %u, got %u\n", ret1
- 2, ret2
);
5079 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5080 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
5081 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5083 SetLastError(0xdeadbeef);
5084 ret2
= GetModuleFileName(hinst
, buf2
, 0);
5085 ok(!ret2
, "GetModuleFileName should return 0\n");
5086 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5087 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
5088 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5090 SetLastError(0xdeadbeef);
5091 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, ret1
- 2);
5092 ok(ret2
== ret1
- 2 || broken(ret2
== ret1
- 3) /* win98 */ || broken(!ret2
), /* nt4 sp3 */
5093 "expected %u, got %u\n", ret1
- 2, ret2
);
5094 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5095 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
5096 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5098 SetLastError(0xdeadbeef);
5099 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, 0);
5100 ok(!ret2
, "expected 0, got %u\n", ret2
);
5101 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5102 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
5103 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5105 DestroyWindow(hwnd
);
5108 hwnd
= (HWND
)0xdeadbeef;
5109 SetLastError(0xdeadbeef);
5110 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
5111 ok(!ret1
, "expected 0, got %u\n", ret1
);
5112 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
|| broken(GetLastError() == 0xdeadbeef), /* win9x */
5113 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
5115 hwnd
= FindWindow("Shell_TrayWnd", NULL
);
5116 ok(IsWindow(hwnd
) || broken(!hwnd
), "got invalid tray window %p\n", hwnd
);
5117 SetLastError(0xdeadbeef);
5118 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
5119 ok(!ret1
|| broken(ret1
), /* win98 */ "expected 0, got %u\n", ret1
);
5121 if (!ret1
) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
5123 ret1
= GetModuleFileName(0, buf1
, sizeof(buf1
));
5124 hwnd
= GetDesktopWindow();
5125 ok(IsWindow(hwnd
), "got invalid desktop window %p\n", hwnd
);
5126 SetLastError(0xdeadbeef);
5127 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, sizeof(buf2
));
5129 ret1
== ret2
|| /* vista */
5130 broken(ret2
), /* some win98 return user.exe as file name */
5131 "expected 0 or %u, got %u %s\n", ret1
, ret2
, buf2
);
5135 static void test_hwnd_message(void)
5137 static const WCHAR mainwindowclassW
[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
5138 static const WCHAR message_windowW
[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
5140 HWND parent
= 0, hwnd
, found
;
5143 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
5144 on CreateWindowExA and crash later in the test.
5145 Use UNICODE here to fail on win9x */
5146 hwnd
= CreateWindowExW(0, mainwindowclassW
, message_windowW
, WS_CAPTION
| WS_VISIBLE
,
5147 100, 100, 200, 200, HWND_MESSAGE
, 0, 0, NULL
);
5150 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
5154 ok( !GetParent(hwnd
), "GetParent should return 0 for message only windows\n" );
5158 HWND root
, desktop
= GetDesktopWindow();
5160 parent
= pGetAncestor(hwnd
, GA_PARENT
);
5161 ok(parent
!= 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
5162 ok(parent
!= desktop
, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
5163 root
= pGetAncestor(hwnd
, GA_ROOT
);
5164 ok(root
== hwnd
, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
5165 ok( !pGetAncestor(parent
, GA_PARENT
) || broken(pGetAncestor(parent
, GA_PARENT
) != 0), /* win2k */
5166 "parent shouldn't have parent %p\n", pGetAncestor(parent
, GA_PARENT
) );
5167 trace("parent %p root %p desktop %p\n", parent
, root
, desktop
);
5168 if (!GetClassNameA( parent
, buffer
, sizeof(buffer
) )) buffer
[0] = 0;
5169 ok( !lstrcmpi( buffer
, "Message" ), "wrong parent class '%s'\n", buffer
);
5170 GetWindowRect( parent
, &rect
);
5171 ok( rect
.left
== 0 && rect
.right
== 100 && rect
.top
== 0 && rect
.bottom
== 100,
5172 "wrong parent rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
5174 GetWindowRect( hwnd
, &rect
);
5175 ok( rect
.left
== 100 && rect
.right
== 300 && rect
.top
== 100 && rect
.bottom
== 300,
5176 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
5178 /* test FindWindow behavior */
5180 found
= FindWindowExA( 0, 0, 0, "message window" );
5181 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
5182 SetLastError(0xdeadbeef);
5183 found
= FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
5184 ok( found
== 0, "found message window %p/%p\n", found
, hwnd
);
5185 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
5188 found
= FindWindowExA( parent
, 0, 0, "message window" );
5189 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
5192 /* test IsChild behavior */
5194 if (parent
) ok( !IsChild( parent
, hwnd
), "HWND_MESSAGE is child of top window\n" );
5196 /* test IsWindowVisible behavior */
5198 ok( !IsWindowVisible( hwnd
), "HWND_MESSAGE window is visible\n" );
5199 if (parent
) ok( !IsWindowVisible( parent
), "HWND_MESSAGE parent is visible\n" );
5201 DestroyWindow(hwnd
);
5204 static void test_layered_window(void)
5212 if (!pGetLayeredWindowAttributes
|| !pSetLayeredWindowAttributes
)
5214 win_skip( "layered windows not supported\n" );
5217 hwnd
= CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION
,
5218 100, 100, 200, 200, 0, 0, 0, NULL
);
5220 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5221 ok( !ret
, "GetLayeredWindowAttributes should fail on non-layered window\n" );
5222 ret
= pSetLayeredWindowAttributes( hwnd
, 0, 0, LWA_ALPHA
);
5223 ok( !ret
, "SetLayeredWindowAttributes should fail on non-layered window\n" );
5224 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
5225 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5226 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5227 ret
= pSetLayeredWindowAttributes( hwnd
, 0x123456, 44, LWA_ALPHA
);
5228 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5229 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5230 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5231 ok( key
== 0x123456 || key
== 0, "wrong color key %x\n", key
);
5232 ok( alpha
== 44, "wrong alpha %u\n", alpha
);
5233 ok( flags
== LWA_ALPHA
, "wrong flags %x\n", flags
);
5235 /* clearing WS_EX_LAYERED resets attributes */
5236 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
5237 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5238 ok( !ret
, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
5239 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
5240 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5241 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5242 ret
= pSetLayeredWindowAttributes( hwnd
, 0x654321, 22, LWA_COLORKEY
| LWA_ALPHA
);
5243 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5244 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5245 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5246 ok( key
== 0x654321, "wrong color key %x\n", key
);
5247 ok( alpha
== 22, "wrong alpha %u\n", alpha
);
5248 ok( flags
== (LWA_COLORKEY
| LWA_ALPHA
), "wrong flags %x\n", flags
);
5250 ret
= pSetLayeredWindowAttributes( hwnd
, 0x888888, 33, LWA_COLORKEY
);
5251 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5253 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5254 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5255 ok( key
== 0x888888, "wrong color key %x\n", key
);
5256 /* alpha not changed on vista if LWA_ALPHA is not set */
5257 ok( alpha
== 22 || alpha
== 33, "wrong alpha %u\n", alpha
);
5258 ok( flags
== LWA_COLORKEY
, "wrong flags %x\n", flags
);
5260 /* color key may or may not be changed without LWA_COLORKEY */
5261 ret
= pSetLayeredWindowAttributes( hwnd
, 0x999999, 44, 0 );
5262 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5264 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5265 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5266 ok( key
== 0x888888 || key
== 0x999999, "wrong color key %x\n", key
);
5267 ok( alpha
== 22 || alpha
== 44, "wrong alpha %u\n", alpha
);
5268 ok( flags
== 0, "wrong flags %x\n", flags
);
5270 /* default alpha and color key is 0 */
5271 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
5272 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
5273 ret
= pSetLayeredWindowAttributes( hwnd
, 0x222222, 55, 0 );
5274 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5275 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5276 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5277 ok( key
== 0 || key
== 0x222222, "wrong color key %x\n", key
);
5278 ok( alpha
== 0 || alpha
== 55, "wrong alpha %u\n", alpha
);
5279 ok( flags
== 0, "wrong flags %x\n", flags
);
5281 DestroyWindow( hwnd
);
5284 static MONITORINFO mi
;
5286 static LRESULT CALLBACK
fullscreen_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
5292 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
5293 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
5294 ok(cs
->x
== mi
.rcMonitor
.left
&& cs
->y
== mi
.rcMonitor
.top
&&
5295 cs
->cx
== mi
.rcMonitor
.right
&& cs
->cy
== mi
.rcMonitor
.bottom
,
5296 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
5297 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5298 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
5301 case WM_GETMINMAXINFO
:
5303 MINMAXINFO
*minmax
= (MINMAXINFO
*)lp
;
5304 dump_minmax_info(minmax
);
5305 ok(minmax
->ptMaxPosition
.x
<= mi
.rcMonitor
.left
, "%d <= %d\n", minmax
->ptMaxPosition
.x
, mi
.rcMonitor
.left
);
5306 ok(minmax
->ptMaxPosition
.y
<= mi
.rcMonitor
.top
, "%d <= %d\n", minmax
->ptMaxPosition
.y
, mi
.rcMonitor
.top
);
5307 ok(minmax
->ptMaxSize
.x
>= mi
.rcMonitor
.right
, "%d >= %d\n", minmax
->ptMaxSize
.x
, mi
.rcMonitor
.right
);
5308 ok(minmax
->ptMaxSize
.y
>= mi
.rcMonitor
.bottom
, "%d >= %d\n", minmax
->ptMaxSize
.y
, mi
.rcMonitor
.bottom
);
5312 return DefWindowProc(hwnd
, msg
, wp
, lp
);
5315 static void test_fullscreen(void)
5317 static const DWORD t_style
[] = {
5318 WS_OVERLAPPED
, WS_POPUP
, WS_CHILD
, WS_THICKFRAME
, WS_DLGFRAME
5320 static const DWORD t_ex_style
[] = {
5321 0, WS_EX_APPWINDOW
, WS_EX_TOOLWINDOW
5331 if (!pGetMonitorInfoA
|| !pMonitorFromPoint
)
5333 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
5338 SetLastError(0xdeadbeef);
5339 hmon
= pMonitorFromPoint(pt
, MONITOR_DEFAULTTOPRIMARY
);
5340 ok(hmon
!= 0, "MonitorFromPoint error %u\n", GetLastError());
5342 mi
.cbSize
= sizeof(mi
);
5343 SetLastError(0xdeadbeef);
5344 ret
= pGetMonitorInfoA(hmon
, &mi
);
5345 ok(ret
, "GetMonitorInfo error %u\n", GetLastError());
5346 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
5347 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5348 mi
.rcWork
.left
, mi
.rcWork
.top
, mi
.rcWork
.right
, mi
.rcWork
.bottom
);
5351 cls
.lpfnWndProc
= fullscreen_wnd_proc
;
5354 cls
.hInstance
= GetModuleHandle(0);
5356 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
5357 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5358 cls
.lpszMenuName
= NULL
;
5359 cls
.lpszClassName
= "fullscreen_class";
5360 RegisterClass(&cls
);
5362 for (i
= 0; i
< sizeof(t_style
)/sizeof(t_style
[0]); i
++)
5364 DWORD style
, ex_style
;
5366 /* avoid a WM interaction */
5367 assert(!(t_style
[i
] & WS_VISIBLE
));
5369 for (j
= 0; j
< sizeof(t_ex_style
)/sizeof(t_ex_style
[0]); j
++)
5374 ex_style
= t_ex_style
[j
];
5376 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5377 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5378 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5379 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5380 GetWindowRect(hwnd
, &rc
);
5381 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5382 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5383 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5384 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5385 DestroyWindow(hwnd
);
5387 style
= t_style
[i
] | WS_MAXIMIZE
;
5388 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5389 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5390 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5391 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5392 GetWindowRect(hwnd
, &rc
);
5393 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5394 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5395 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5396 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5397 DestroyWindow(hwnd
);
5399 style
= t_style
[i
] | WS_MAXIMIZE
| WS_CAPTION
;
5400 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5401 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5402 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5403 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5404 GetWindowRect(hwnd
, &rc
);
5405 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5406 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5407 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5408 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5409 DestroyWindow(hwnd
);
5411 style
= t_style
[i
] | WS_CAPTION
| WS_MAXIMIZEBOX
;
5412 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5413 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5414 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5415 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5416 GetWindowRect(hwnd
, &rc
);
5417 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5418 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5419 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5420 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5421 DestroyWindow(hwnd
);
5423 style
= t_style
[i
] | WS_MAXIMIZE
| WS_CAPTION
| WS_MAXIMIZEBOX
;
5424 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5425 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5426 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5427 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5428 GetWindowRect(hwnd
, &rc
);
5429 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5430 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5431 fixup
= min(abs(rc
.left
), abs(rc
.top
));
5432 InflateRect(&rc
, -fixup
, -fixup
);
5433 ok(rc
.left
>= mi
.rcWork
.left
&& rc
.top
<= mi
.rcWork
.top
&&
5434 rc
.right
<= mi
.rcWork
.right
&& rc
.bottom
<= mi
.rcWork
.bottom
,
5435 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
5436 ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
5437 mi
.rcWork
.left
, mi
.rcWork
.top
, mi
.rcWork
.right
, mi
.rcWork
.bottom
);
5438 DestroyWindow(hwnd
);
5440 style
= t_style
[i
] | WS_MAXIMIZE
| WS_MAXIMIZEBOX
;
5441 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5442 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5443 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5444 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5445 GetWindowRect(hwnd
, &rc
);
5446 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5447 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5448 fixup
= min(abs(rc
.left
), abs(rc
.top
));
5449 InflateRect(&rc
, -fixup
, -fixup
);
5450 if (style
& (WS_CHILD
| WS_POPUP
))
5451 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5452 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5453 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5455 ok(rc
.left
>= mi
.rcWork
.left
&& rc
.top
<= mi
.rcWork
.top
&&
5456 rc
.right
<= mi
.rcWork
.right
&& rc
.bottom
<= mi
.rcWork
.bottom
,
5457 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5458 DestroyWindow(hwnd
);
5462 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5465 static BOOL test_thick_child_got_minmax
;
5466 static const char * test_thick_child_name
;
5467 static LONG test_thick_child_style
;
5468 static LONG test_thick_child_exStyle
;
5470 static LRESULT WINAPI
test_thick_child_size_winproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
5473 int expectedMinTrackX
;
5474 int expectedMinTrackY
;
5475 int actualMinTrackX
;
5476 int actualMinTrackY
;
5477 int expectedMaxTrackX
;
5478 int expectedMaxTrackY
;
5479 int actualMaxTrackX
;
5480 int actualMaxTrackY
;
5481 int expectedMaxSizeX
;
5482 int expectedMaxSizeY
;
5493 case WM_GETMINMAXINFO
:
5495 minmax
= (MINMAXINFO
*)lparam
;
5496 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
5497 dump_minmax_info( minmax
);
5499 test_thick_child_got_minmax
= TRUE
;
5502 adjustedStyle
= test_thick_child_style
;
5503 if ((adjustedStyle
& WS_CAPTION
) == WS_CAPTION
)
5504 adjustedStyle
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5505 GetClientRect(GetParent(hwnd
), &rect
);
5506 AdjustWindowRectEx(&rect
, adjustedStyle
, FALSE
, test_thick_child_exStyle
);
5508 if (test_thick_child_style
& (WS_DLGFRAME
| WS_BORDER
))
5510 expectedMinTrackX
= GetSystemMetrics(SM_CXMINTRACK
);
5511 expectedMinTrackY
= GetSystemMetrics(SM_CYMINTRACK
);
5515 expectedMinTrackX
= -2 * rect
.left
;
5516 expectedMinTrackY
= -2 * rect
.top
;
5518 actualMinTrackX
= minmax
->ptMinTrackSize
.x
;
5519 actualMinTrackY
= minmax
->ptMinTrackSize
.y
;
5521 ok(actualMinTrackX
== expectedMinTrackX
&& actualMinTrackY
== expectedMinTrackY
,
5522 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
5523 expectedMinTrackX
, expectedMinTrackY
, actualMinTrackX
, actualMinTrackY
,
5524 test_thick_child_name
);
5526 actualMaxTrackX
= minmax
->ptMaxTrackSize
.x
;
5527 actualMaxTrackY
= minmax
->ptMaxTrackSize
.y
;
5528 expectedMaxTrackX
= GetSystemMetrics(SM_CXMAXTRACK
);
5529 expectedMaxTrackY
= GetSystemMetrics(SM_CYMAXTRACK
);
5530 ok(actualMaxTrackX
== expectedMaxTrackX
&& actualMaxTrackY
== expectedMaxTrackY
,
5531 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
5532 expectedMaxTrackX
, expectedMaxTrackY
, actualMaxTrackX
, actualMaxTrackY
,
5533 test_thick_child_name
);
5535 expectedMaxSizeX
= rect
.right
- rect
.left
;
5536 expectedMaxSizeY
= rect
.bottom
- rect
.top
;
5537 actualMaxSizeX
= minmax
->ptMaxSize
.x
;
5538 actualMaxSizeY
= minmax
->ptMaxSize
.y
;
5540 ok(actualMaxSizeX
== expectedMaxSizeX
&& actualMaxSizeY
== expectedMaxSizeY
,
5541 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
5542 expectedMaxSizeX
, expectedMaxSizeY
, actualMaxSizeX
, actualMaxSizeY
,
5543 test_thick_child_name
);
5546 expectedPosX
= rect
.left
;
5547 expectedPosY
= rect
.top
;
5548 actualPosX
= minmax
->ptMaxPosition
.x
;
5549 actualPosY
= minmax
->ptMaxPosition
.y
;
5550 ok(actualPosX
== expectedPosX
&& actualPosY
== expectedPosY
,
5551 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
5552 expectedPosX
, expectedPosY
, actualPosX
, actualPosY
, test_thick_child_name
);
5558 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
5561 #define NUMBER_OF_THICK_CHILD_TESTS 16
5562 static void test_thick_child_size(HWND parentWindow
)
5566 RECT adjustedParentRect
;
5571 LONG expectedHeight
;
5573 LPCTSTR className
= "THICK_CHILD_CLASS";
5576 static const LONG styles
[NUMBER_OF_THICK_CHILD_TESTS
] = {
5577 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
5578 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
5579 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
5580 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
5581 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
5582 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
5583 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
5584 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
5585 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
5586 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
5587 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
5588 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
5589 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
5590 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
5591 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
5592 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
5595 static const LONG exStyles
[NUMBER_OF_THICK_CHILD_TESTS
] = {
5600 WS_EX_DLGMODALFRAME
,
5601 WS_EX_DLGMODALFRAME
,
5602 WS_EX_DLGMODALFRAME
,
5603 WS_EX_DLGMODALFRAME
,
5608 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
5609 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
5610 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
5611 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
5613 static const char *styleName
[NUMBER_OF_THICK_CHILD_TESTS
] = {
5614 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
5615 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
5616 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
5617 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
5618 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
5619 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
5620 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5621 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5622 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
5623 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
5624 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5625 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5626 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5627 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5628 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5629 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5633 cls
.lpfnWndProc
= test_thick_child_size_winproc
;
5636 cls
.hInstance
= GetModuleHandleA(0);
5638 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
5639 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5640 cls
.lpszMenuName
= NULL
;
5641 cls
.lpszClassName
= className
;
5642 SetLastError(0xdeadbeef);
5643 ok(RegisterClassA(&cls
),"RegisterClassA failed, error: %u\n", GetLastError());
5645 for(i
= 0; i
< NUMBER_OF_THICK_CHILD_TESTS
; i
++)
5647 test_thick_child_name
= styleName
[i
];
5648 test_thick_child_style
= styles
[i
];
5649 test_thick_child_exStyle
= exStyles
[i
];
5650 test_thick_child_got_minmax
= FALSE
;
5652 SetLastError(0xdeadbeef);
5653 childWindow
= CreateWindowEx( exStyles
[i
], className
, "", styles
[i
], 0, 0, 0, 0, parentWindow
, 0, GetModuleHandleA(0), NULL
);
5654 ok(childWindow
!= NULL
, "Failed to create child window, error: %u\n", GetLastError());
5656 ok(test_thick_child_got_minmax
, "Got no WM_GETMINMAXINFO\n");
5658 SetLastError(0xdeadbeef);
5659 success
= GetWindowRect(childWindow
, &childRect
);
5660 ok(success
,"GetWindowRect call failed, error: %u\n", GetLastError());
5661 childWidth
= childRect
.right
- childRect
.left
;
5662 childHeight
= childRect
.bottom
- childRect
.top
;
5664 adjustedStyle
= styles
[i
];
5665 if ((adjustedStyle
& WS_CAPTION
) == WS_CAPTION
)
5666 adjustedStyle
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5667 GetClientRect(GetParent(childWindow
), &adjustedParentRect
);
5668 AdjustWindowRectEx(&adjustedParentRect
, adjustedStyle
, FALSE
, test_thick_child_exStyle
);
5671 if (test_thick_child_style
& (WS_DLGFRAME
| WS_BORDER
))
5673 expectedWidth
= GetSystemMetrics(SM_CXMINTRACK
);
5674 expectedHeight
= GetSystemMetrics(SM_CYMINTRACK
);
5678 expectedWidth
= -2 * adjustedParentRect
.left
;
5679 expectedHeight
= -2 * adjustedParentRect
.top
;
5682 ok((childWidth
== expectedWidth
) && (childHeight
== expectedHeight
),
5683 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
5684 test_thick_child_name
, expectedWidth
, expectedHeight
, childWidth
, childHeight
);
5686 SetLastError(0xdeadbeef);
5687 success
= DestroyWindow(childWindow
);
5688 ok(success
,"DestroyWindow call failed, error: %u\n", GetLastError());
5690 ok(UnregisterClass(className
, GetModuleHandleA(0)),"UnregisterClass call failed\n");
5693 static void test_handles( HWND full_hwnd
)
5695 HWND hwnd
= full_hwnd
;
5699 SetLastError( 0xdeadbeef );
5700 ret
= GetWindowRect( hwnd
, &rect
);
5701 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
5704 if ((ULONG_PTR
)full_hwnd
>> 32)
5705 hwnd
= (HWND
)((ULONG_PTR
)full_hwnd
& ~0u);
5707 hwnd
= (HWND
)((ULONG_PTR
)full_hwnd
| ((ULONG_PTR
)~0u << 32));
5708 SetLastError( 0xdeadbeef );
5709 ret
= GetWindowRect( hwnd
, &rect
);
5710 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
5712 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& ~0u) | ((ULONG_PTR
)0x1234 << 32));
5713 SetLastError( 0xdeadbeef );
5714 ret
= GetWindowRect( hwnd
, &rect
);
5715 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
5717 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& 0xffff) | ((ULONG_PTR
)0x9876 << 16));
5718 SetLastError( 0xdeadbeef );
5719 ret
= GetWindowRect( hwnd
, &rect
);
5720 ok( !ret
, "GetWindowRect succeeded for %p\n", hwnd
);
5721 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "wrong error %u\n", GetLastError() );
5723 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& 0xffff) | ((ULONG_PTR
)0x12345678 << 16));
5724 SetLastError( 0xdeadbeef );
5725 ret
= GetWindowRect( hwnd
, &rect
);
5726 ok( !ret
, "GetWindowRect succeeded for %p\n", hwnd
);
5727 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "wrong error %u\n", GetLastError() );
5731 static void test_winregion(void)
5738 if (!pGetWindowRgnBox
)
5740 win_skip("GetWindowRgnBox not supported\n");
5744 hwnd
= CreateWindowExA(0, "static", NULL
, WS_VISIBLE
, 10, 10, 10, 10, NULL
, 0, 0, NULL
);
5746 SetLastError(0xdeadbeef);
5747 ret
= pGetWindowRgnBox(hwnd
, NULL
);
5748 ok( ret
== ERROR
, "Expected ERROR, got %d\n", ret
);
5749 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
5751 hrgn
= CreateRectRgn(2, 3, 10, 15);
5752 ok( hrgn
!= NULL
, "Region creation failed\n");
5755 SetWindowRgn(hwnd
, hrgn
, FALSE
);
5757 SetLastError(0xdeadbeef);
5758 ret
= pGetWindowRgnBox(hwnd
, NULL
);
5759 ok( ret
== ERROR
, "Expected ERROR, got %d\n", ret
);
5760 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
5762 r
.left
= r
.top
= r
.right
= r
.bottom
= 0;
5763 ret
= pGetWindowRgnBox(hwnd
, &r
);
5764 ok( ret
== SIMPLEREGION
, "Expected SIMPLEREGION, got %d\n", ret
);
5765 ok( r
.left
== 2 && r
.top
== 3 && r
.right
== 10 && r
.bottom
== 15,
5766 "Expected (2,3,10,15), got (%d,%d,%d,%d)\n", r
.left
, r
.top
,
5770 DestroyWindow(hwnd
);
5775 HMODULE user32
= GetModuleHandleA( "user32.dll" );
5776 pGetAncestor
= (void *)GetProcAddress( user32
, "GetAncestor" );
5777 pGetWindowInfo
= (void *)GetProcAddress( user32
, "GetWindowInfo" );
5778 pGetWindowModuleFileNameA
= (void *)GetProcAddress( user32
, "GetWindowModuleFileNameA" );
5779 pGetLayeredWindowAttributes
= (void *)GetProcAddress( user32
, "GetLayeredWindowAttributes" );
5780 pSetLayeredWindowAttributes
= (void *)GetProcAddress( user32
, "SetLayeredWindowAttributes" );
5781 pGetMonitorInfoA
= (void *)GetProcAddress( user32
, "GetMonitorInfoA" );
5782 pMonitorFromPoint
= (void *)GetProcAddress( user32
, "MonitorFromPoint" );
5783 pGetWindowRgnBox
= (void *)GetProcAddress( user32
, "GetWindowRgnBox" );
5785 if (!RegisterWindowClasses()) assert(0);
5787 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
5788 if (!hhook
) win_skip( "Cannot set CBT hook, skipping some tests\n" );
5790 hwndMain
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
5791 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
5792 WS_MAXIMIZEBOX
| WS_POPUP
,
5794 0, 0, GetModuleHandle(0), NULL
);
5795 hwndMain2
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
5796 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
5797 WS_MAXIMIZEBOX
| WS_POPUP
,
5799 0, 0, GetModuleHandle(0), NULL
);
5801 assert( hwndMain2
);
5803 our_pid
= GetWindowThreadProcessId(hwndMain
, NULL
);
5805 /* Add the tests below this line */
5806 test_thick_child_size(hwndMain
);
5808 test_hwnd_message();
5809 test_nonclient_area(hwndMain
);
5811 test_GetWindowModuleFileName();
5814 test_capture_3(hwndMain
, hwndMain2
);
5816 test_CreateWindow();
5817 test_parent_owner();
5819 test_enum_thread_windows();
5823 test_SetWindowPos(hwndMain
);
5824 test_SetMenu(hwndMain
);
5825 test_SetFocus(hwndMain
);
5826 test_SetActiveWindow(hwndMain
);
5829 test_children_zorder(hwndMain
);
5830 test_popup_zorder(hwndMain2
, hwndMain
);
5831 test_keyboard_input(hwndMain
);
5832 test_mouse_input(hwndMain
);
5833 test_validatergn(hwndMain
);
5834 test_nccalcscroll( hwndMain
);
5835 test_scrollwindow( hwndMain
);
5836 test_scrollvalidate( hwndMain
);
5837 test_scrolldc( hwndMain
);
5839 test_IsWindowUnicode();
5840 test_vis_rgn(hwndMain
);
5842 test_AdjustWindowRect();
5843 test_window_styles();
5846 test_SetWindowLong();
5848 if (0) test_gettext(); /* crashes on NT4 */
5849 test_GetUpdateRect();
5851 test_layered_window();
5853 test_SetForegroundWindow(hwndMain
);
5854 test_shell_window();
5855 test_handles( hwndMain
);
5858 /* add the tests above this line */
5859 if (hhook
) UnhookWindowsHookEx(hhook
);
5861 DestroyWindow(hwndMain2
);
5862 DestroyWindow(hwndMain
);