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
);
51 static BOOL test_lbuttondown_flag
;
52 static HWND hwndMessage
;
53 static HWND hwndMain
, hwndMain2
;
56 static const char* szAWRClass
= "Winsize";
60 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
62 static void dump_minmax_info( const MINMAXINFO
*minmax
)
64 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
65 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
66 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
67 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
68 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
69 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
72 /* try to make sure pending X events have been processed before continuing */
73 static void flush_events( BOOL remove_messages
)
78 DWORD time
= GetTickCount() + diff
;
82 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
84 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
85 diff
= time
- GetTickCount();
90 /* check the values returned by the various parent/owner functions on a given window */
91 static void check_parents( HWND hwnd
, HWND ga_parent
, HWND gwl_parent
, HWND get_parent
,
92 HWND gw_owner
, HWND ga_root
, HWND ga_root_owner
)
98 res
= pGetAncestor( hwnd
, GA_PARENT
);
99 ok( res
== ga_parent
, "Wrong result for GA_PARENT %p expected %p\n", res
, ga_parent
);
101 res
= (HWND
)GetWindowLongPtrA( hwnd
, GWLP_HWNDPARENT
);
102 ok( res
== gwl_parent
, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res
, gwl_parent
);
103 res
= GetParent( hwnd
);
104 ok( res
== get_parent
, "Wrong result for GetParent %p expected %p\n", res
, get_parent
);
105 res
= GetWindow( hwnd
, GW_OWNER
);
106 ok( res
== gw_owner
, "Wrong result for GW_OWNER %p expected %p\n", res
, gw_owner
);
109 res
= pGetAncestor( hwnd
, GA_ROOT
);
110 ok( res
== ga_root
, "Wrong result for GA_ROOT %p expected %p\n", res
, ga_root
);
111 res
= pGetAncestor( hwnd
, GA_ROOTOWNER
);
112 ok( res
== ga_root_owner
, "Wrong result for GA_ROOTOWNER %p expected %p\n", res
, ga_root_owner
);
116 static BOOL CALLBACK
EnumChildProc( HWND hwndChild
, LPARAM lParam
)
119 trace("EnumChildProc on %p\n", hwndChild
);
120 if (*(LPINT
)lParam
> 1) return FALSE
;
124 /* will search for the given window */
125 static BOOL CALLBACK
EnumChildProc1( HWND hwndChild
, LPARAM lParam
)
127 trace("EnumChildProc1 on %p\n", hwndChild
);
128 if ((HWND
)lParam
== hwndChild
) return FALSE
;
132 static HWND
create_tool_window( LONG style
, HWND parent
)
134 HWND ret
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style
,
135 0, 0, 100, 100, parent
, 0, 0, NULL
);
136 ok( ret
!= 0, "Creation failed\n" );
140 /* test parent and owner values for various combinations */
141 static void test_parent_owner(void)
144 HWND test
, owner
, ret
;
145 HWND desktop
= GetDesktopWindow();
146 HWND child
= create_tool_window( WS_CHILD
, hwndMain
);
149 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain
, hwndMain2
, desktop
, child
);
151 /* child without parent, should fail */
152 SetLastError(0xdeadbeef);
153 test
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
154 WS_CHILD
, 0, 0, 100, 100, 0, 0, 0, NULL
);
155 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD
, "CreateWindowExA should call SetLastError\n" );
156 ok( !test
, "WS_CHILD without parent created\n" );
159 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
160 style
= GetWindowLongA( desktop
, GWL_STYLE
);
161 ok( !SetWindowLongA( desktop
, GWL_STYLE
, WS_POPUP
), "Set GWL_STYLE on desktop succeeded\n" );
162 ok( !SetWindowLongA( desktop
, GWL_STYLE
, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
163 ok( GetWindowLongA( desktop
, GWL_STYLE
) == style
, "Desktop style changed\n" );
165 /* normal child window */
166 test
= create_tool_window( WS_CHILD
, hwndMain
);
167 trace( "created child %p\n", test
);
168 check_parents( test
, hwndMain
, hwndMain
, hwndMain
, 0, hwndMain
, hwndMain
);
169 SetWindowLongA( test
, GWL_STYLE
, 0 );
170 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
171 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
172 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
173 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
|WS_CHILD
);
174 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
175 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
176 DestroyWindow( test
);
178 /* normal child window with WS_MAXIMIZE */
179 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
180 DestroyWindow( test
);
182 /* normal child window with WS_THICKFRAME */
183 test
= create_tool_window( WS_CHILD
| WS_THICKFRAME
, hwndMain
);
184 DestroyWindow( test
);
186 /* popup window with WS_THICKFRAME */
187 test
= create_tool_window( WS_POPUP
| WS_THICKFRAME
, hwndMain
);
188 DestroyWindow( test
);
190 /* child of desktop */
191 test
= create_tool_window( WS_CHILD
, desktop
);
192 trace( "created child of desktop %p\n", test
);
193 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
194 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
195 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
196 SetWindowLongA( test
, GWL_STYLE
, 0 );
197 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
198 DestroyWindow( test
);
200 /* child of desktop with WS_MAXIMIZE */
201 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, desktop
);
202 DestroyWindow( test
);
204 /* child of desktop with WS_MINIMIZE */
205 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, desktop
);
206 DestroyWindow( test
);
209 test
= create_tool_window( WS_CHILD
, child
);
210 trace( "created child of child %p\n", test
);
211 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
212 SetWindowLongA( test
, GWL_STYLE
, 0 );
213 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
214 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
215 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
216 DestroyWindow( test
);
218 /* child of child with WS_MAXIMIZE */
219 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, child
);
220 DestroyWindow( test
);
222 /* child of child with WS_MINIMIZE */
223 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, child
);
224 DestroyWindow( test
);
226 /* not owned top-level window */
227 test
= create_tool_window( 0, 0 );
228 trace( "created top-level %p\n", test
);
229 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
230 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
231 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
232 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
233 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
234 DestroyWindow( test
);
236 /* not owned top-level window with WS_MAXIMIZE */
237 test
= create_tool_window( WS_MAXIMIZE
, 0 );
238 DestroyWindow( test
);
240 /* owned top-level window */
241 test
= create_tool_window( 0, hwndMain
);
242 trace( "created owned top-level %p\n", test
);
243 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
244 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
245 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
246 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
247 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
248 DestroyWindow( test
);
250 /* owned top-level window with WS_MAXIMIZE */
251 test
= create_tool_window( WS_MAXIMIZE
, hwndMain
);
252 DestroyWindow( test
);
254 /* not owned popup */
255 test
= create_tool_window( WS_POPUP
, 0 );
256 trace( "created popup %p\n", test
);
257 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
258 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
259 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
260 SetWindowLongA( test
, GWL_STYLE
, 0 );
261 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
262 DestroyWindow( test
);
264 /* not owned popup with WS_MAXIMIZE */
265 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, 0 );
266 DestroyWindow( test
);
269 test
= create_tool_window( WS_POPUP
, hwndMain
);
270 trace( "created owned popup %p\n", test
);
271 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
272 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
273 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
274 SetWindowLongA( test
, GWL_STYLE
, 0 );
275 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
276 DestroyWindow( test
);
278 /* owned popup with WS_MAXIMIZE */
279 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, hwndMain
);
280 DestroyWindow( test
);
282 /* top-level window owned by child (same as owned by top-level) */
283 test
= create_tool_window( 0, child
);
284 trace( "created top-level owned by child %p\n", test
);
285 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
286 DestroyWindow( test
);
288 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
289 test
= create_tool_window( WS_MAXIMIZE
, child
);
290 DestroyWindow( test
);
292 /* popup owned by desktop (same as not owned) */
293 test
= create_tool_window( WS_POPUP
, desktop
);
294 trace( "created popup owned by desktop %p\n", test
);
295 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
296 DestroyWindow( test
);
298 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
299 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, desktop
);
300 DestroyWindow( test
);
302 /* popup owned by child (same as owned by top-level) */
303 test
= create_tool_window( WS_POPUP
, child
);
304 trace( "created popup owned by child %p\n", test
);
305 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
306 DestroyWindow( test
);
308 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
309 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, child
);
310 DestroyWindow( test
);
312 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
313 test
= create_tool_window( WS_POPUP
| WS_CHILD
, 0 );
314 trace( "created WS_CHILD popup %p\n", test
);
315 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
316 DestroyWindow( test
);
318 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
319 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, 0 );
320 DestroyWindow( test
);
322 /* owned popup with WS_CHILD (same as WS_POPUP only) */
323 test
= create_tool_window( WS_POPUP
| WS_CHILD
, hwndMain
);
324 trace( "created owned WS_CHILD popup %p\n", test
);
325 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
326 DestroyWindow( test
);
328 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
329 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
330 DestroyWindow( test
);
332 /******************** parent changes *************************/
333 trace( "testing parent changes\n" );
336 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
339 /* this test succeeds on NT but crashes on win9x systems */
340 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
341 ok( !ret
, "Set GWL_HWNDPARENT succeeded on desktop\n" );
342 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
343 ok( !SetParent( desktop
, hwndMain
), "SetParent succeeded on desktop\n" );
344 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
346 /* normal child window */
347 test
= create_tool_window( WS_CHILD
, hwndMain
);
348 trace( "created child %p\n", test
);
350 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
351 ok( ret
== hwndMain
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain
);
352 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
354 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
355 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
356 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
358 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)desktop
);
359 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
360 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
362 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
363 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
364 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
365 check_parents( test
, desktop
, child
, desktop
, child
, test
, desktop
);
367 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
368 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
369 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
370 DestroyWindow( test
);
372 /* not owned top-level window */
373 test
= create_tool_window( 0, 0 );
374 trace( "created top-level %p\n", test
);
376 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
377 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
378 check_parents( test
, desktop
, hwndMain2
, 0, hwndMain2
, test
, test
);
380 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
381 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
382 check_parents( test
, desktop
, child
, 0, child
, test
, test
);
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, 0, 0, test
, test
);
387 DestroyWindow( test
);
389 /* not owned popup */
390 test
= create_tool_window( WS_POPUP
, 0 );
391 trace( "created popup %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
, hwndMain2
, hwndMain2
, test
, hwndMain2
);
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
, child
, child
, test
, hwndMain
);
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 /* normal child window */
407 test
= create_tool_window( WS_CHILD
, hwndMain
);
408 trace( "created child %p\n", test
);
410 ret
= SetParent( test
, desktop
);
411 ok( ret
== hwndMain
, "SetParent return value %p expected %p\n", ret
, hwndMain
);
412 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
414 ret
= SetParent( test
, child
);
415 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
416 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
418 ret
= SetParent( test
, hwndMain2
);
419 ok( ret
== child
, "SetParent return value %p expected %p\n", ret
, child
);
420 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
421 DestroyWindow( test
);
423 /* not owned top-level window */
424 test
= create_tool_window( 0, 0 );
425 trace( "created top-level %p\n", test
);
427 ret
= SetParent( test
, child
);
428 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
429 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
430 DestroyWindow( test
);
433 test
= create_tool_window( WS_POPUP
, hwndMain2
);
434 trace( "created owned popup %p\n", test
);
436 ret
= SetParent( test
, child
);
437 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
438 check_parents( test
, child
, child
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
440 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)hwndMain
);
441 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
442 check_parents( test
, hwndMain
, hwndMain
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
443 DestroyWindow( test
);
445 /**************** test owner destruction *******************/
447 /* owned child popup */
448 owner
= create_tool_window( 0, 0 );
449 test
= create_tool_window( WS_POPUP
, owner
);
450 trace( "created owner %p and popup %p\n", owner
, test
);
451 ret
= SetParent( test
, child
);
452 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
453 check_parents( test
, child
, child
, owner
, owner
, hwndMain
, owner
);
454 /* window is now child of 'child' but owned by 'owner' */
455 DestroyWindow( owner
);
456 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
457 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
458 * while Win95, Win2k, WinXP do.
460 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
461 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
464 /* owned top-level 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 check_parents( test
, desktop
, owner
, owner
, owner
, test
, owner
);
469 DestroyWindow( owner
);
470 ok( !IsWindow(test
), "Window %p not destroyed by owner destruction\n", test
);
472 /* top-level popup owned by child */
473 owner
= create_tool_window( WS_CHILD
, hwndMain2
);
474 test
= create_tool_window( WS_POPUP
, 0 );
475 trace( "created owner %p and popup %p\n", owner
, test
);
476 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)owner
);
477 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
478 check_parents( test
, desktop
, owner
, owner
, owner
, test
, hwndMain2
);
479 DestroyWindow( owner
);
480 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
481 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
482 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
483 * while Win95, Win2k, WinXP do.
485 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
489 DestroyWindow(child
);
492 owner
= create_tool_window( WS_OVERLAPPED
, 0 );
493 test
= create_tool_window( WS_POPUP
, desktop
);
495 ok( !GetWindow( test
, GW_OWNER
), "Wrong owner window\n" );
497 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
498 "EnumChildWindows should have returned FALSE\n" );
499 ok( numChildren
== 0, "numChildren should be 0 got %d\n", numChildren
);
501 SetWindowLongA( test
, GWL_STYLE
, (GetWindowLongA( test
, GWL_STYLE
) & ~WS_POPUP
) | WS_CHILD
);
502 ret
= SetParent( test
, owner
);
503 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
506 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
507 "EnumChildWindows should have returned TRUE\n" );
508 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
510 child
= create_tool_window( WS_CHILD
, owner
);
512 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
513 "EnumChildWindows should have returned FALSE\n" );
514 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
515 DestroyWindow( child
);
517 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, owner
);
518 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
520 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
521 "EnumChildWindows should have returned TRUE\n" );
522 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
524 ret
= SetParent( child
, owner
);
525 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
526 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
528 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
529 "EnumChildWindows should have returned FALSE\n" );
530 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
532 ret
= SetParent( child
, NULL
);
533 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
534 ok( ret
== owner
, "SetParent return value %p expected %p\n", ret
, owner
);
536 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
537 "EnumChildWindows should have returned TRUE\n" );
538 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
540 /* even GW_OWNER == owner it's still a desktop's child */
541 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
542 "EnumChildWindows should have found %p and returned FALSE\n", child
);
544 DestroyWindow( child
);
545 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, NULL
);
547 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
548 "EnumChildWindows should have found %p and returned FALSE\n", child
);
550 DestroyWindow( child
);
551 DestroyWindow( test
);
552 DestroyWindow( owner
);
556 static LRESULT WINAPI
main_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
560 case WM_GETMINMAXINFO
:
562 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
564 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
565 dump_minmax_info( minmax
);
566 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
569 case WM_WINDOWPOSCHANGING
:
571 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
572 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
573 trace("main: WM_WINDOWPOSCHANGING\n");
574 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
575 winpos
->hwnd
, winpos
->hwndInsertAfter
,
576 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
577 if (!(winpos
->flags
& SWP_NOMOVE
))
579 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
580 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
582 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
583 if (!(winpos
->flags
& SWP_NOSIZE
) && !is_win9x
)
585 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
586 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
590 case WM_WINDOWPOSCHANGED
:
593 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
594 trace("main: WM_WINDOWPOSCHANGED\n");
595 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
596 winpos
->hwnd
, winpos
->hwndInsertAfter
,
597 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
598 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
599 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
601 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
602 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
604 GetWindowRect(hwnd
, &rc1
);
605 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
606 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
607 /* note: winpos coordinates are relative to parent */
608 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
609 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
612 /* Uncomment this once the test succeeds in all cases */
613 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
616 GetClientRect(hwnd
, &rc2
);
617 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
618 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
619 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
620 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
625 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
626 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
628 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
629 if (got_getminmaxinfo
)
630 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
632 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
633 ok(got_getminmaxinfo
, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
635 ok(!got_getminmaxinfo
, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
639 if (test_lbuttondown_flag
)
641 ShowWindow((HWND
)wparam
, SW_SHOW
);
642 flush_events( FALSE
);
647 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
650 static LRESULT WINAPI
tool_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
654 case WM_GETMINMAXINFO
:
656 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
658 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
659 dump_minmax_info( minmax
);
660 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
665 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
666 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
668 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
669 if (got_getminmaxinfo
)
670 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
672 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
673 ok(got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
675 ok(!got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
680 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
683 static BOOL
RegisterWindowClasses(void)
687 cls
.style
= CS_DBLCLKS
;
688 cls
.lpfnWndProc
= main_window_procA
;
691 cls
.hInstance
= GetModuleHandleA(0);
693 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
694 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
695 cls
.lpszMenuName
= NULL
;
696 cls
.lpszClassName
= "MainWindowClass";
698 if(!RegisterClassA(&cls
)) return FALSE
;
701 cls
.lpfnWndProc
= tool_window_procA
;
704 cls
.hInstance
= GetModuleHandleA(0);
706 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
707 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
708 cls
.lpszMenuName
= NULL
;
709 cls
.lpszClassName
= "ToolWindowClass";
711 if(!RegisterClassA(&cls
)) return FALSE
;
716 static void verify_window_info(HWND hwnd
, const WINDOWINFO
*info
)
718 RECT rcWindow
, rcClient
;
721 ok(IsWindow(hwnd
), "bad window handle\n");
723 GetWindowRect(hwnd
, &rcWindow
);
724 ok(EqualRect(&rcWindow
, &info
->rcWindow
), "wrong rcWindow\n");
726 GetClientRect(hwnd
, &rcClient
);
727 /* translate to screen coordinates */
728 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rcClient
, 2);
729 ok(EqualRect(&rcClient
, &info
->rcClient
), "wrong rcClient\n");
731 ok(info
->dwStyle
== (DWORD
)GetWindowLongA(hwnd
, GWL_STYLE
),
732 "wrong dwStyle: %08x != %08x\n", info
->dwStyle
, GetWindowLongA(hwnd
, GWL_STYLE
));
733 /* Windows reports some undocumented exstyles in WINDOWINFO, but
734 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
736 ok((info
->dwExStyle
& ~0xe0000800) == (DWORD
)GetWindowLongA(hwnd
, GWL_EXSTYLE
),
737 "wrong dwExStyle: %08x != %08x\n", info
->dwExStyle
, GetWindowLongA(hwnd
, GWL_EXSTYLE
));
738 status
= (GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0;
739 ok(info
->dwWindowStatus
== status
, "wrong dwWindowStatus: %04x != %04x\n",
740 info
->dwWindowStatus
, status
);
742 /* win2k and XP return broken border info in GetWindowInfo most of
743 * the time, so there is no point in testing it.
747 ok(info
->cxWindowBorders
== (unsigned)(rcClient
.left
- rcWindow
.left
),
748 "wrong cxWindowBorders %d != %d\n", info
->cxWindowBorders
, rcClient
.left
- rcWindow
.left
);
749 border
= min(rcWindow
.bottom
- rcClient
.bottom
, rcClient
.top
- rcWindow
.top
);
750 ok(info
->cyWindowBorders
== border
,
751 "wrong cyWindowBorders %d != %d\n", info
->cyWindowBorders
, border
);
753 ok(info
->atomWindowType
== GetClassLongA(hwnd
, GCW_ATOM
), "wrong atomWindowType\n");
754 ok(info
->wCreatorVersion
== 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
755 info
->wCreatorVersion
== 0x0500 /* Vista */,
756 "wrong wCreatorVersion %04x\n", info
->wCreatorVersion
);
759 static void FixedAdjustWindowRectEx(RECT
* rc
, LONG style
, BOOL menu
, LONG exstyle
)
761 AdjustWindowRectEx(rc
, style
, menu
, exstyle
);
762 /* AdjustWindowRectEx does not include scroll bars */
763 if (style
& WS_VSCROLL
)
765 if(exstyle
& WS_EX_LEFTSCROLLBAR
)
766 rc
->left
-= GetSystemMetrics(SM_CXVSCROLL
);
768 rc
->right
+= GetSystemMetrics(SM_CXVSCROLL
);
770 if (style
& WS_HSCROLL
)
771 rc
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
774 static void test_nonclient_area(HWND hwnd
)
776 DWORD style
, exstyle
;
777 RECT rc_window
, rc_client
, rc
;
779 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
781 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
782 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
783 menu
= !(style
& WS_CHILD
) && GetMenu(hwnd
) != 0;
785 GetWindowRect(hwnd
, &rc_window
);
786 trace("window: (%d,%d)-(%d,%d)\n", rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
);
787 GetClientRect(hwnd
, &rc_client
);
788 trace("client: (%d,%d)-(%d,%d)\n", rc_client
.left
, rc_client
.top
, rc_client
.right
, rc_client
.bottom
);
790 /* avoid some cases when things go wrong */
791 if (IsRectEmpty(&rc_window
) || IsRectEmpty(&rc_client
) ||
792 rc_window
.right
> 32768 || rc_window
.bottom
> 32768) return;
794 CopyRect(&rc
, &rc_client
);
795 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc
, 2);
796 FixedAdjustWindowRectEx(&rc
, style
, menu
, exstyle
);
798 trace("calc window: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
799 ok(EqualRect(&rc
, &rc_window
), "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
802 CopyRect(&rc
, &rc_window
);
803 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
804 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
805 trace("calc client: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
806 ok(EqualRect(&rc
, &rc_client
), "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
808 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
812 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
813 SetRect(&rc_client
, 0, 0, 250, 150);
814 CopyRect(&rc_window
, &rc_client
);
815 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc_window
, 2);
816 FixedAdjustWindowRectEx(&rc_window
, style
, menu
, exstyle
);
817 trace("calc window: (%d,%d)-(%d,%d)\n",
818 rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
);
820 CopyRect(&rc
, &rc_window
);
821 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
822 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
823 trace("calc client: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
824 ok(EqualRect(&rc
, &rc_client
), "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
827 static LRESULT CALLBACK
cbt_hook_proc(int nCode
, WPARAM wParam
, LPARAM lParam
)
829 static const char *CBT_code_name
[10] = {
840 const char *code_name
= (nCode
>= 0 && nCode
<= HCBT_SETFOCUS
) ? CBT_code_name
[nCode
] : "Unknown";
842 trace("CBT: %d (%s), %08lx, %08lx\n", nCode
, code_name
, wParam
, lParam
);
844 /* on HCBT_DESTROYWND window state is undefined */
845 if (nCode
!= HCBT_DESTROYWND
&& IsWindow((HWND
)wParam
))
851 /* Win98 actually does check the info.cbSize and doesn't allow
852 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
853 * WinXP do not check it at all.
855 info
.cbSize
= sizeof(WINDOWINFO
);
856 ok(pGetWindowInfo((HWND
)wParam
, &info
), "GetWindowInfo should not fail\n");
857 verify_window_info((HWND
)wParam
, &info
);
865 static const RECT rc_null
;
868 CBT_CREATEWNDA
*createwnd
= (CBT_CREATEWNDA
*)lParam
;
869 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
870 (HWND
)wParam
, createwnd
->lpcs
->hwndParent
, createwnd
->lpcs
->style
);
871 ok(createwnd
->hwndInsertAfter
== HWND_TOP
, "hwndInsertAfter should be always HWND_TOP\n");
873 /* WS_VISIBLE should be turned off yet */
874 style
= createwnd
->lpcs
->style
& ~WS_VISIBLE
;
875 ok(style
== GetWindowLongA((HWND
)wParam
, GWL_STYLE
),
876 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
877 GetWindowLongA((HWND
)wParam
, GWL_STYLE
), style
);
881 /* Uncomment this once the test succeeds in all cases */
882 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
884 ok(GetParent((HWND
)wParam
) == hwndMessage
,
885 "wrong result from GetParent %p: message window %p\n",
886 GetParent((HWND
)wParam
), hwndMessage
);
889 ok(!GetParent((HWND
)wParam
), "GetParent should return 0 at this point\n");
891 ok(!GetWindow((HWND
)wParam
, GW_OWNER
), "GW_OWNER should be set to 0 at this point\n");
895 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
896 * Win9x still has them set to 0.
898 ok(GetWindow((HWND
)wParam
, GW_HWNDFIRST
) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
899 ok(GetWindow((HWND
)wParam
, GW_HWNDLAST
) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
901 ok(!GetWindow((HWND
)wParam
, GW_HWNDPREV
), "GW_HWNDPREV should be set to 0 at this point\n");
902 ok(!GetWindow((HWND
)wParam
, GW_HWNDNEXT
), "GW_HWNDNEXT should be set to 0 at this point\n");
906 /* Uncomment this once the test succeeds in all cases */
909 ok(pGetAncestor((HWND
)wParam
, GA_PARENT
) == hwndMessage
, "GA_PARENT should be set to hwndMessage at this point\n");
910 ok(pGetAncestor((HWND
)wParam
, GA_ROOT
) == (HWND
)wParam
,
911 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND
)wParam
, GA_ROOT
), (HWND
)wParam
);
913 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
914 ok(pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
) == hwndMessage
,
915 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
917 ok(pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
) == (HWND
)wParam
,
918 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
), (HWND
)wParam
);
921 ok(GetWindowRect((HWND
)wParam
, &rc
), "GetWindowRect failed\n");
922 ok(EqualRect(&rc
, &rc_null
), "window rect should be set to 0 HCBT_CREATEWND\n");
923 ok(GetClientRect((HWND
)wParam
, &rc
), "GetClientRect failed\n");
924 ok(EqualRect(&rc
, &rc_null
), "client rect should be set to 0 on HCBT_CREATEWND\n");
930 return CallNextHookEx(hhook
, nCode
, wParam
, lParam
);
933 static void test_shell_window(void)
937 HMODULE hinst
, hUser32
;
938 BOOL (WINAPI
*SetShellWindow
)(HWND
);
939 BOOL (WINAPI
*SetShellWindowEx
)(HWND
, HWND
);
940 HWND hwnd1
, hwnd2
, hwnd3
, hwnd4
, hwnd5
;
941 HWND shellWindow
, nextWnd
;
943 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE
))
945 trace("Skipping shell window test on Win9x\n");
949 shellWindow
= GetShellWindow();
950 hinst
= GetModuleHandle(0);
951 hUser32
= GetModuleHandleA("user32");
953 SetShellWindow
= (void *)GetProcAddress(hUser32
, "SetShellWindow");
954 SetShellWindowEx
= (void *)GetProcAddress(hUser32
, "SetShellWindowEx");
956 trace("previous shell window: %p\n", shellWindow
);
962 ret
= DestroyWindow(shellWindow
);
963 error
= GetLastError();
965 ok(!ret
, "DestroyWindow(shellWindow)\n");
966 /* passes on Win XP, but not on Win98 */
967 ok(error
==ERROR_ACCESS_DENIED
, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n");
969 /* close old shell instance */
970 GetWindowThreadProcessId(shellWindow
, &pid
);
971 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, pid
);
972 ret
= TerminateProcess(hProcess
, 0);
973 ok(ret
, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
974 WaitForSingleObject(hProcess
, INFINITE
); /* wait for termination */
975 CloseHandle(hProcess
);
978 hwnd1
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst
, 0);
979 trace("created window 1: %p\n", hwnd1
);
981 ret
= SetShellWindow(hwnd1
);
982 ok(ret
, "first call to SetShellWindow(hwnd1)\n");
983 shellWindow
= GetShellWindow();
984 ok(shellWindow
==hwnd1
, "wrong shell window: %p\n", shellWindow
);
986 ret
= SetShellWindow(hwnd1
);
987 ok(!ret
, "second call to SetShellWindow(hwnd1)\n");
989 ret
= SetShellWindow(0);
990 error
= GetLastError();
991 /* passes on Win XP, but not on Win98
992 ok(!ret, "reset shell window by SetShellWindow(0)\n");
993 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
995 ret
= SetShellWindow(hwnd1
);
996 /* passes on Win XP, but not on Win98
997 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
999 SetWindowLong(hwnd1
, GWL_EXSTYLE
, GetWindowLong(hwnd1
,GWL_EXSTYLE
)|WS_EX_TOPMOST
);
1000 ret
= GetWindowLong(hwnd1
,GWL_EXSTYLE
)&WS_EX_TOPMOST
? TRUE
: FALSE
;
1001 ok(!ret
, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1003 ret
= DestroyWindow(hwnd1
);
1004 ok(ret
, "DestroyWindow(hwnd1)\n");
1006 hwnd2
= CreateWindowEx(WS_EX_TOPMOST
, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst
, 0);
1007 trace("created window 2: %p\n", hwnd2
);
1008 ret
= SetShellWindow(hwnd2
);
1009 ok(!ret
, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1011 hwnd3
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst
, 0);
1012 trace("created window 3: %p\n", hwnd3
);
1014 hwnd4
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst
, 0);
1015 trace("created window 4: %p\n", hwnd4
);
1017 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1018 ok(nextWnd
==hwnd3
, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd
);
1020 ret
= SetShellWindow(hwnd4
);
1021 ok(ret
, "SetShellWindow(hwnd4)\n");
1022 shellWindow
= GetShellWindow();
1023 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1025 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1026 ok(nextWnd
==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd
);
1028 ret
= SetWindowPos(hwnd4
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1029 ok(ret
, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1031 ret
= SetWindowPos(hwnd4
, hwnd3
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1032 ok(ret
, "SetWindowPos(hwnd4, hwnd3\n");
1034 ret
= SetShellWindow(hwnd3
);
1035 ok(!ret
, "SetShellWindow(hwnd3)\n");
1036 shellWindow
= GetShellWindow();
1037 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1039 hwnd5
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst
, 0);
1040 trace("created window 5: %p\n", hwnd5
);
1041 ret
= SetWindowPos(hwnd4
, hwnd5
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1042 ok(ret
, "SetWindowPos(hwnd4, hwnd5)\n");
1046 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1047 ok(nextWnd
==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd
);
1050 /* destroy test windows */
1051 DestroyWindow(hwnd2
);
1052 DestroyWindow(hwnd3
);
1053 DestroyWindow(hwnd4
);
1054 DestroyWindow(hwnd5
);
1057 /************** MDI test ****************/
1059 static char mdi_lParam_test_message
[] = "just a test string";
1061 static void test_MDI_create(HWND parent
, HWND mdi_client
, INT first_id
)
1063 MDICREATESTRUCTA mdi_cs
;
1065 static const WCHAR classW
[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1066 static const WCHAR titleW
[] = {'M','D','I',' ','c','h','i','l','d',0};
1067 BOOL isWin9x
= FALSE
;
1069 mdi_cs
.szClass
= "MDI_child_Class_1";
1070 mdi_cs
.szTitle
= "MDI child";
1071 mdi_cs
.hOwner
= GetModuleHandle(0);
1072 mdi_cs
.x
= CW_USEDEFAULT
;
1073 mdi_cs
.y
= CW_USEDEFAULT
;
1074 mdi_cs
.cx
= CW_USEDEFAULT
;
1075 mdi_cs
.cy
= CW_USEDEFAULT
;
1077 mdi_cs
.lParam
= (LPARAM
)mdi_lParam_test_message
;
1078 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1079 ok(mdi_child
!= 0, "MDI child creation failed\n");
1080 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1081 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1082 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1084 mdi_cs
.style
= 0x7fffffff; /* without WS_POPUP */
1085 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1086 ok(mdi_child
!= 0, "MDI child creation failed\n");
1087 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1088 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1089 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1091 mdi_cs
.style
= 0xffffffff; /* with WS_POPUP */
1092 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1093 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1095 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1099 ok(mdi_child
!= 0, "MDI child creation failed\n");
1100 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1101 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1102 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1105 /* test MDICREATESTRUCT A<->W mapping */
1106 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1108 mdi_cs
.szClass
= (LPCSTR
)classW
;
1109 mdi_cs
.szTitle
= (LPCSTR
)titleW
;
1110 SetLastError(0xdeadbeef);
1111 mdi_child
= (HWND
)SendMessageW(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1114 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1117 ok(mdi_child
!= 0, "MDI child creation failed\n");
1121 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1122 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1123 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1126 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1128 CW_USEDEFAULT
, CW_USEDEFAULT
,
1129 CW_USEDEFAULT
, CW_USEDEFAULT
,
1130 mdi_client
, GetModuleHandle(0),
1131 (LPARAM
)mdi_lParam_test_message
);
1132 ok(mdi_child
!= 0, "MDI child creation failed\n");
1133 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1134 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1135 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1137 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1138 0x7fffffff, /* without WS_POPUP */
1139 CW_USEDEFAULT
, CW_USEDEFAULT
,
1140 CW_USEDEFAULT
, CW_USEDEFAULT
,
1141 mdi_client
, GetModuleHandle(0),
1142 (LPARAM
)mdi_lParam_test_message
);
1143 ok(mdi_child
!= 0, "MDI child creation failed\n");
1144 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1145 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1146 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1148 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1149 0xffffffff, /* with WS_POPUP */
1150 CW_USEDEFAULT
, CW_USEDEFAULT
,
1151 CW_USEDEFAULT
, CW_USEDEFAULT
,
1152 mdi_client
, GetModuleHandle(0),
1153 (LPARAM
)mdi_lParam_test_message
);
1154 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1156 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1160 ok(mdi_child
!= 0, "MDI child creation failed\n");
1161 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1162 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1163 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1166 /* test MDICREATESTRUCT A<->W mapping */
1167 SetLastError(0xdeadbeef);
1168 mdi_child
= CreateMDIWindowW(classW
, titleW
,
1170 CW_USEDEFAULT
, CW_USEDEFAULT
,
1171 CW_USEDEFAULT
, CW_USEDEFAULT
,
1172 mdi_client
, GetModuleHandle(0),
1173 (LPARAM
)mdi_lParam_test_message
);
1176 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1179 ok(mdi_child
!= 0, "MDI child creation failed\n");
1183 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1184 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1185 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1188 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1190 CW_USEDEFAULT
, CW_USEDEFAULT
,
1191 CW_USEDEFAULT
, CW_USEDEFAULT
,
1192 mdi_client
, 0, GetModuleHandle(0),
1193 (LPVOID
)mdi_lParam_test_message
);
1194 ok(mdi_child
!= 0, "MDI child creation failed\n");
1195 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1196 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1197 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1199 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1200 0x7fffffff, /* without WS_POPUP */
1201 CW_USEDEFAULT
, CW_USEDEFAULT
,
1202 CW_USEDEFAULT
, CW_USEDEFAULT
,
1203 mdi_client
, 0, GetModuleHandle(0),
1204 (LPVOID
)mdi_lParam_test_message
);
1205 ok(mdi_child
!= 0, "MDI child creation failed\n");
1206 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1207 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1208 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1210 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1211 0xffffffff, /* with WS_POPUP */
1212 CW_USEDEFAULT
, CW_USEDEFAULT
,
1213 CW_USEDEFAULT
, CW_USEDEFAULT
,
1214 mdi_client
, 0, GetModuleHandle(0),
1215 (LPVOID
)mdi_lParam_test_message
);
1216 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1218 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1222 ok(mdi_child
!= 0, "MDI child creation failed\n");
1223 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1224 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1225 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1228 /* test MDICREATESTRUCT A<->W mapping */
1229 SetLastError(0xdeadbeef);
1230 mdi_child
= CreateWindowExW(WS_EX_MDICHILD
, classW
, titleW
,
1232 CW_USEDEFAULT
, CW_USEDEFAULT
,
1233 CW_USEDEFAULT
, CW_USEDEFAULT
,
1234 mdi_client
, 0, GetModuleHandle(0),
1235 (LPVOID
)mdi_lParam_test_message
);
1238 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1241 ok(mdi_child
!= 0, "MDI child creation failed\n");
1245 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1246 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1247 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1250 /* This test fails on Win9x */
1253 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_2", "MDI child",
1255 CW_USEDEFAULT
, CW_USEDEFAULT
,
1256 CW_USEDEFAULT
, CW_USEDEFAULT
,
1257 parent
, 0, GetModuleHandle(0),
1258 (LPVOID
)mdi_lParam_test_message
);
1259 ok(!mdi_child
, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1262 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1263 WS_CHILD
, /* without WS_POPUP */
1264 CW_USEDEFAULT
, CW_USEDEFAULT
,
1265 CW_USEDEFAULT
, CW_USEDEFAULT
,
1266 mdi_client
, 0, GetModuleHandle(0),
1267 (LPVOID
)mdi_lParam_test_message
);
1268 ok(mdi_child
!= 0, "MDI child creation failed\n");
1269 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1270 DestroyWindow(mdi_child
);
1272 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1273 WS_CHILD
| WS_POPUP
, /* with WS_POPUP */
1274 CW_USEDEFAULT
, CW_USEDEFAULT
,
1275 CW_USEDEFAULT
, CW_USEDEFAULT
,
1276 mdi_client
, 0, GetModuleHandle(0),
1277 (LPVOID
)mdi_lParam_test_message
);
1278 ok(mdi_child
!= 0, "MDI child creation failed\n");
1279 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1280 DestroyWindow(mdi_child
);
1282 /* maximized child */
1283 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1284 WS_CHILD
| WS_MAXIMIZE
,
1285 CW_USEDEFAULT
, CW_USEDEFAULT
,
1286 CW_USEDEFAULT
, CW_USEDEFAULT
,
1287 mdi_client
, 0, GetModuleHandle(0),
1288 (LPVOID
)mdi_lParam_test_message
);
1289 ok(mdi_child
!= 0, "MDI child creation failed\n");
1290 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1291 DestroyWindow(mdi_child
);
1293 trace("Creating maximized child with a caption\n");
1294 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1295 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
,
1296 CW_USEDEFAULT
, CW_USEDEFAULT
,
1297 CW_USEDEFAULT
, CW_USEDEFAULT
,
1298 mdi_client
, 0, GetModuleHandle(0),
1299 (LPVOID
)mdi_lParam_test_message
);
1300 ok(mdi_child
!= 0, "MDI child creation failed\n");
1301 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1302 DestroyWindow(mdi_child
);
1304 trace("Creating maximized child with a caption and a thick frame\n");
1305 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1306 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
| WS_THICKFRAME
,
1307 CW_USEDEFAULT
, CW_USEDEFAULT
,
1308 CW_USEDEFAULT
, CW_USEDEFAULT
,
1309 mdi_client
, 0, GetModuleHandle(0),
1310 (LPVOID
)mdi_lParam_test_message
);
1311 ok(mdi_child
!= 0, "MDI child creation failed\n");
1312 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1313 DestroyWindow(mdi_child
);
1316 /**********************************************************************
1317 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1319 * Note: The rule here is that client rect of the maximized MDI child
1320 * is equal to the client rect of the MDI client window.
1322 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
1326 GetClientRect( client
, &rect
);
1327 AdjustWindowRectEx( &rect
, GetWindowLongA( hwnd
, GWL_STYLE
),
1328 0, GetWindowLongA( hwnd
, GWL_EXSTYLE
));
1330 rect
.right
-= rect
.left
;
1331 rect
.bottom
-= rect
.top
;
1332 lpMinMax
->ptMaxSize
.x
= rect
.right
;
1333 lpMinMax
->ptMaxSize
.y
= rect
.bottom
;
1335 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
1336 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
1338 trace("max rect (%d,%d - %d, %d)\n",
1339 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1342 static LRESULT WINAPI
mdi_child_wnd_proc_1(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1349 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1350 MDICREATESTRUCTA
*mdi_cs
= (MDICREATESTRUCTA
*)cs
->lpCreateParams
;
1352 ok(cs
->dwExStyle
& WS_EX_MDICHILD
, "WS_EX_MDICHILD should be set\n");
1353 ok(mdi_cs
->lParam
== (LPARAM
)mdi_lParam_test_message
, "wrong mdi_cs->lParam\n");
1355 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_1"), "wrong class name\n");
1356 ok(!lstrcmpA(cs
->lpszClass
, mdi_cs
->szClass
), "class name does not match\n");
1357 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1358 ok(!lstrcmpA(cs
->lpszName
, mdi_cs
->szTitle
), "title does not match\n");
1359 ok(cs
->hInstance
== mdi_cs
->hOwner
, "%p != %p\n", cs
->hInstance
, mdi_cs
->hOwner
);
1361 /* MDICREATESTRUCT should have original values */
1362 ok(mdi_cs
->style
== 0 || mdi_cs
->style
== 0x7fffffff || mdi_cs
->style
== 0xffffffff,
1363 "mdi_cs->style does not match (%08x)\n", mdi_cs
->style
);
1364 ok(mdi_cs
->x
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->x
);
1365 ok(mdi_cs
->y
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->y
);
1366 ok(mdi_cs
->cx
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cx
);
1367 ok(mdi_cs
->cy
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cy
);
1369 /* CREATESTRUCT should have fixed values */
1370 ok(cs
->x
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->x
);
1371 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1373 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1374 ok(cs
->cx
!= CW_USEDEFAULT
&& cs
->cx
!= 0, "%d == CW_USEDEFAULT\n", cs
->cx
);
1375 ok(cs
->cy
!= CW_USEDEFAULT
&& cs
->cy
!= 0, "%d == CW_USEDEFAULT\n", cs
->cy
);
1377 ok(!(cs
->style
& WS_POPUP
), "WS_POPUP is not allowed\n");
1379 if (GetWindowLongA(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1381 LONG style
= mdi_cs
->style
| WS_CHILD
| WS_CLIPSIBLINGS
;
1382 ok(cs
->style
== style
,
1383 "cs->style does not match (%08x)\n", cs
->style
);
1387 LONG style
= mdi_cs
->style
;
1389 style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1390 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1391 ok(cs
->style
== style
,
1392 "cs->style does not match (%08x)\n", cs
->style
);
1397 case WM_GETMINMAXINFO
:
1399 HWND client
= GetParent(hwnd
);
1401 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1402 MINMAXINFO my_minmax
;
1403 LONG style
, exstyle
;
1405 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1406 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1408 GetWindowRect(client
, &rc
);
1409 trace("MDI client %p window size = (%d x %d)\n", client
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1410 GetClientRect(client
, &rc
);
1411 trace("MDI client %p client size = (%d x %d)\n", client
, rc
.right
, rc
.bottom
);
1412 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN
),
1413 GetSystemMetrics(SM_CYSCREEN
));
1415 GetClientRect(client
, &rc
);
1416 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1417 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1418 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1419 trace("MDI child: calculated max window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1420 dump_minmax_info( minmax
);
1422 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1423 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1424 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1425 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1427 DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1429 trace("DefMDIChildProc returned:\n");
1430 dump_minmax_info( minmax
);
1432 MDI_ChildGetMinMaxInfo(client
, hwnd
, &my_minmax
);
1433 ok(minmax
->ptMaxSize
.x
== my_minmax
.ptMaxSize
.x
, "default width of maximized child %d != %d\n",
1434 minmax
->ptMaxSize
.x
, my_minmax
.ptMaxSize
.x
);
1435 ok(minmax
->ptMaxSize
.y
== my_minmax
.ptMaxSize
.y
, "default height of maximized child %d != %d\n",
1436 minmax
->ptMaxSize
.y
, my_minmax
.ptMaxSize
.y
);
1441 case WM_MDIACTIVATE
:
1443 HWND active
, client
= GetParent(hwnd
);
1444 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1445 active
= (HWND
)SendMessageA(client
, WM_MDIGETACTIVE
, 0, 0);
1446 if (hwnd
== (HWND
)lparam
) /* if we are being activated */
1447 ok (active
== (HWND
)lparam
, "new active %p != active %p\n", (HWND
)lparam
, active
);
1449 ok (active
== (HWND
)wparam
, "old active %p != active %p\n", (HWND
)wparam
, active
);
1453 return DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1456 static LRESULT WINAPI
mdi_child_wnd_proc_2(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1463 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1465 trace("%s\n", (msg
== WM_NCCREATE
) ? "WM_NCCREATE" : "WM_CREATE");
1466 trace("x %d, y %d, cx %d, cy %d\n", cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
1468 ok(!(cs
->dwExStyle
& WS_EX_MDICHILD
), "WS_EX_MDICHILD should not be set\n");
1469 ok(cs
->lpCreateParams
== mdi_lParam_test_message
, "wrong cs->lpCreateParams\n");
1471 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_2"), "wrong class name\n");
1472 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1474 /* CREATESTRUCT should have fixed values */
1475 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1477 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1478 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1480 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1481 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1482 while Win95, Win2k, WinXP do. */
1483 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1484 ok(cs
->cy
== 0, "%d != 0\n", cs
->cy
);
1488 case WM_GETMINMAXINFO
:
1490 HWND parent
= GetParent(hwnd
);
1492 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1493 LONG style
, exstyle
;
1495 trace("WM_GETMINMAXINFO\n");
1497 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1498 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1500 GetClientRect(parent
, &rc
);
1501 trace("parent %p client size = (%d x %d)\n", parent
, rc
.right
, rc
.bottom
);
1503 GetClientRect(parent
, &rc
);
1504 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1505 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1506 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1507 trace("calculated max child window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1508 dump_minmax_info( minmax
);
1510 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1511 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1512 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1513 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1517 case WM_WINDOWPOSCHANGED
:
1519 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1522 GetWindowRect(hwnd
, &rc1
);
1523 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1524 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1525 /* note: winpos coordinates are relative to parent */
1526 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1527 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1528 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1530 GetWindowRect(hwnd
, &rc1
);
1531 GetClientRect(hwnd
, &rc2
);
1532 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1533 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1534 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1537 case WM_WINDOWPOSCHANGING
:
1539 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1540 WINDOWPOS my_winpos
= *winpos
;
1542 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1543 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1544 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1545 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1547 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1549 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1550 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1551 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1553 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1554 "DefWindowProc should not change WINDOWPOS values\n");
1559 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1562 static LRESULT WINAPI
mdi_main_wnd_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1564 static HWND mdi_client
;
1570 CLIENTCREATESTRUCT client_cs
;
1573 GetClientRect(hwnd
, &rc
);
1575 client_cs
.hWindowMenu
= 0;
1576 client_cs
.idFirstChild
= 1;
1578 /* MDIClient without MDIS_ALLCHILDSTYLES */
1579 mdi_client
= CreateWindowExA(0, "mdiclient",
1581 WS_CHILD
/*| WS_VISIBLE*/,
1582 /* tests depend on a not zero MDIClient size */
1583 0, 0, rc
.right
, rc
.bottom
,
1584 hwnd
, 0, GetModuleHandle(0),
1585 (LPVOID
)&client_cs
);
1587 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1588 DestroyWindow(mdi_client
);
1590 /* MDIClient with MDIS_ALLCHILDSTYLES */
1591 mdi_client
= CreateWindowExA(0, "mdiclient",
1593 WS_CHILD
| MDIS_ALLCHILDSTYLES
/*| WS_VISIBLE*/,
1594 /* tests depend on a not zero MDIClient size */
1595 0, 0, rc
.right
, rc
.bottom
,
1596 hwnd
, 0, GetModuleHandle(0),
1597 (LPVOID
)&client_cs
);
1599 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1600 DestroyWindow(mdi_client
);
1604 case WM_WINDOWPOSCHANGED
:
1606 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1609 GetWindowRect(hwnd
, &rc1
);
1610 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1611 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1612 /* note: winpos coordinates are relative to parent */
1613 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1614 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1615 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1617 GetWindowRect(hwnd
, &rc1
);
1618 GetClientRect(hwnd
, &rc2
);
1619 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1620 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1621 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1624 case WM_WINDOWPOSCHANGING
:
1626 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1627 WINDOWPOS my_winpos
= *winpos
;
1629 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1630 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1631 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1632 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1634 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1636 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1637 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1638 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1640 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1641 "DefWindowProc should not change WINDOWPOS values\n");
1650 return DefFrameProcA(hwnd
, mdi_client
, msg
, wparam
, lparam
);
1653 static BOOL
mdi_RegisterWindowClasses(void)
1658 cls
.lpfnWndProc
= mdi_main_wnd_procA
;
1661 cls
.hInstance
= GetModuleHandleA(0);
1663 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
1664 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1665 cls
.lpszMenuName
= NULL
;
1666 cls
.lpszClassName
= "MDI_parent_Class";
1667 if(!RegisterClassA(&cls
)) return FALSE
;
1669 cls
.lpfnWndProc
= mdi_child_wnd_proc_1
;
1670 cls
.lpszClassName
= "MDI_child_Class_1";
1671 if(!RegisterClassA(&cls
)) return FALSE
;
1673 cls
.lpfnWndProc
= mdi_child_wnd_proc_2
;
1674 cls
.lpszClassName
= "MDI_child_Class_2";
1675 if(!RegisterClassA(&cls
)) return FALSE
;
1680 static void test_mdi(void)
1685 if (!mdi_RegisterWindowClasses()) assert(0);
1687 mdi_hwndMain
= CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1688 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
1689 WS_MAXIMIZEBOX
/*| WS_VISIBLE*/,
1690 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1691 GetDesktopWindow(), 0,
1692 GetModuleHandle(0), NULL
);
1693 assert(mdi_hwndMain
);
1695 while(GetMessage(&msg, 0, 0, 0))
1697 TranslateMessage(&msg);
1698 DispatchMessage(&msg);
1701 DestroyWindow(mdi_hwndMain
);
1704 static void test_icons(void)
1708 HICON icon
= LoadIconA(0, (LPSTR
)IDI_APPLICATION
);
1709 HICON icon2
= LoadIconA(0, (LPSTR
)IDI_QUESTION
);
1710 HICON small_icon
= LoadImageA(0, (LPSTR
)IDI_APPLICATION
, IMAGE_ICON
,
1711 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
1714 cls
.cbSize
= sizeof(cls
);
1716 cls
.lpfnWndProc
= DefWindowProcA
;
1720 cls
.hIcon
= LoadIconA(0, (LPSTR
)IDI_HAND
);
1721 cls
.hIconSm
= small_icon
;
1722 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
1723 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1724 cls
.lpszMenuName
= NULL
;
1725 cls
.lpszClassName
= "IconWindowClass";
1727 RegisterClassExA(&cls
);
1729 hwnd
= CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1730 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, NULL
, NULL
);
1733 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1734 ok( res
== 0, "wrong big icon %p/0\n", res
);
1735 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon
);
1736 ok( res
== 0, "wrong previous big icon %p/0\n", res
);
1737 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1738 ok( res
== icon
, "wrong big icon after set %p/%p\n", res
, icon
);
1739 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon2
);
1740 ok( res
== icon
, "wrong previous big icon %p/%p\n", res
, icon
);
1741 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1742 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1744 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1745 ok( res
== 0, "wrong small icon %p/0\n", res
);
1746 /* this test is XP specific */
1747 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1748 ok( res != 0, "wrong small icon %p\n", res );*/
1749 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)icon
);
1750 ok( res
== 0, "wrong previous small icon %p/0\n", res
);
1751 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1752 ok( res
== icon
, "wrong small icon after set %p/%p\n", res
, icon
);
1753 /* this test is XP specific */
1754 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1755 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1756 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)small_icon
);
1757 ok( res
== icon
, "wrong previous small icon %p/%p\n", res
, icon
);
1758 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1759 ok( res
== small_icon
, "wrong small icon after set %p/%p\n", res
, small_icon
);
1760 /* this test is XP specific */
1761 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1762 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1764 /* make sure the big icon hasn't changed */
1765 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1766 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1768 DestroyWindow( hwnd
);
1771 static LRESULT WINAPI
nccalcsize_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1773 if (msg
== WM_NCCALCSIZE
)
1775 RECT
*rect
= (RECT
*)lparam
;
1776 /* first time around increase the rectangle, next time decrease it */
1777 if (rect
->left
== 100) InflateRect( rect
, 10, 10 );
1778 else InflateRect( rect
, -10, -10 );
1781 return DefWindowProc( hwnd
, msg
, wparam
, lparam
);
1784 static void test_SetWindowPos(HWND hwnd
)
1786 RECT orig_win_rc
, rect
;
1788 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
1790 SetRect(&rect
, 111, 222, 333, 444);
1791 ok(!GetWindowRect(0, &rect
), "GetWindowRect succeeded\n");
1792 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1793 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1795 SetRect(&rect
, 111, 222, 333, 444);
1796 ok(!GetClientRect(0, &rect
), "GetClientRect succeeded\n");
1797 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1798 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1800 GetWindowRect(hwnd
, &orig_win_rc
);
1802 old_proc
= SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)nccalcsize_proc
);
1803 SetWindowPos(hwnd
, 0, 100, 100, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1804 GetWindowRect( hwnd
, &rect
);
1805 ok( rect
.left
== 100 && rect
.top
== 100 && rect
.right
== 100 && rect
.bottom
== 100,
1806 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1807 GetClientRect( hwnd
, &rect
);
1808 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1809 ok( rect
.left
== 90 && rect
.top
== 90 && rect
.right
== 110 && rect
.bottom
== 110,
1810 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1812 SetWindowPos(hwnd
, 0, 200, 200, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1813 GetWindowRect( hwnd
, &rect
);
1814 ok( rect
.left
== 200 && rect
.top
== 200 && rect
.right
== 200 && rect
.bottom
== 200,
1815 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1816 GetClientRect( hwnd
, &rect
);
1817 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1818 ok( rect
.left
== 210 && rect
.top
== 210 && rect
.right
== 190 && rect
.bottom
== 190,
1819 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1821 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1822 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1823 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, old_proc
);
1825 /* Win9x truncates coordinates to 16-bit irrespectively */
1828 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE
);
1829 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE
);
1831 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE
);
1832 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE
);
1835 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1836 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1838 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1839 SetWindowPos(hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1840 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1841 SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1842 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1843 SetWindowPos(hwnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1844 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1847 static void test_SetMenu(HWND parent
)
1851 BOOL is_win9x
= GetWindowLongPtrW(parent
, GWLP_WNDPROC
) == 0;
1855 hMenu
= CreateMenu();
1858 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1861 /* fails on (at least) Wine, NT4, XP SP2 */
1862 test_nonclient_area(parent
);
1864 ret
= GetMenu(parent
);
1865 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1866 /* test whether we can destroy a menu assigned to a window */
1867 retok
= DestroyMenu(hMenu
);
1868 ok( retok
, "DestroyMenu error %d\n", GetLastError());
1869 ok(!IsMenu(hMenu
), "menu handle should be not valid after DestroyMenu\n");
1870 ret
= GetMenu(parent
);
1871 /* This test fails on Win9x */
1873 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1874 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1875 test_nonclient_area(parent
);
1877 hMenu
= CreateMenu();
1881 ret
= GetMenu(parent
);
1882 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1884 ok(!SetMenu(parent
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1885 test_nonclient_area(parent
);
1886 ret
= GetMenu(parent
);
1887 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1889 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1892 /* fails on (at least) Wine, NT4, XP SP2 */
1893 test_nonclient_area(parent
);
1895 ret
= GetMenu(parent
);
1896 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1898 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1899 test_nonclient_area(parent
);
1900 ret
= GetMenu(parent
);
1901 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1904 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, parent
, (HMENU
)10, 0, NULL
);
1907 ret
= GetMenu(child
);
1908 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1910 ok(!SetMenu(child
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1911 test_nonclient_area(child
);
1912 ret
= GetMenu(child
);
1913 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1915 ok(!SetMenu(child
, hMenu
), "SetMenu on a child window should fail\n");
1916 test_nonclient_area(child
);
1917 ret
= GetMenu(child
);
1918 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1920 ok(!SetMenu(child
, 0), "SetMenu(0) on a child window should fail\n");
1921 test_nonclient_area(child
);
1922 ret
= GetMenu(child
);
1923 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1925 style
= GetWindowLong(child
, GWL_STYLE
);
1926 SetWindowLong(child
, GWL_STYLE
, style
| WS_POPUP
);
1927 ok(SetMenu(child
, hMenu
), "SetMenu on a popup child window should not fail\n");
1928 ok(SetMenu(child
, 0), "SetMenu on a popup child window should not fail\n");
1929 SetWindowLong(child
, GWL_STYLE
, style
);
1931 SetWindowLong(child
, GWL_STYLE
, style
| WS_OVERLAPPED
);
1932 ok(!SetMenu(child
, hMenu
), "SetMenu on a overlapped child window should fail\n");
1933 SetWindowLong(child
, GWL_STYLE
, style
);
1935 DestroyWindow(child
);
1939 static void test_window_tree(HWND parent
, const DWORD
*style
, const int *order
, int total
)
1941 HWND child
[5], hwnd
;
1946 hwnd
= GetWindow(parent
, GW_CHILD
);
1947 ok(!hwnd
, "have to start without children to perform the test\n");
1949 for (i
= 0; i
< total
; i
++)
1951 if (style
[i
] & DS_CONTROL
)
1953 child
[i
] = CreateWindowExA(0, MAKEINTATOM(32770), "", style
[i
] & ~WS_VISIBLE
,
1954 0,0,0,0, parent
, (HMENU
)i
, 0, NULL
);
1955 if (style
[i
] & WS_VISIBLE
)
1956 ShowWindow(child
[i
], SW_SHOW
);
1958 SetWindowPos(child
[i
], HWND_BOTTOM
, 0,0,10,10, SWP_NOACTIVATE
);
1961 child
[i
] = CreateWindowExA(0, "static", "", style
[i
], 0,0,10,10,
1962 parent
, (HMENU
)i
, 0, NULL
);
1963 trace("child[%d] = %p\n", i
, child
[i
]);
1964 ok(child
[i
] != 0, "CreateWindowEx failed to create child window\n");
1967 hwnd
= GetWindow(parent
, GW_CHILD
);
1968 ok(hwnd
!= 0, "GetWindow(GW_CHILD) failed\n");
1969 ok(hwnd
== GetWindow(child
[total
- 1], GW_HWNDFIRST
), "GW_HWNDFIRST is wrong\n");
1970 ok(child
[order
[total
- 1]] == GetWindow(child
[0], GW_HWNDLAST
), "GW_HWNDLAST is wrong\n");
1972 for (i
= 0; i
< total
; i
++)
1974 trace("hwnd[%d] = %p\n", i
, hwnd
);
1975 ok(child
[order
[i
]] == hwnd
, "Z order of child #%d is wrong\n", i
);
1977 hwnd
= GetWindow(hwnd
, GW_HWNDNEXT
);
1980 for (i
= 0; i
< total
; i
++)
1981 ok(DestroyWindow(child
[i
]), "DestroyWindow failed\n");
1984 static void test_children_zorder(HWND parent
)
1986 const DWORD simple_style
[5] = { WS_CHILD
, WS_CHILD
, WS_CHILD
, WS_CHILD
,
1988 const int simple_order
[5] = { 0, 1, 2, 3, 4 };
1990 const DWORD complex_style
[5] = { WS_CHILD
, WS_CHILD
| WS_MAXIMIZE
,
1991 WS_CHILD
| WS_VISIBLE
, WS_CHILD
,
1992 WS_CHILD
| WS_MAXIMIZE
| WS_VISIBLE
};
1993 const int complex_order_1
[1] = { 0 };
1994 const int complex_order_2
[2] = { 1, 0 };
1995 const int complex_order_3
[3] = { 1, 0, 2 };
1996 const int complex_order_4
[4] = { 1, 0, 2, 3 };
1997 const int complex_order_5
[5] = { 4, 1, 0, 2, 3 };
1998 const DWORD complex_style_6
[3] = { WS_CHILD
| WS_VISIBLE
,
1999 WS_CHILD
| WS_CLIPSIBLINGS
| DS_CONTROL
| WS_VISIBLE
,
2000 WS_CHILD
| WS_VISIBLE
};
2001 const int complex_order_6
[3] = { 0, 1, 2 };
2003 /* simple WS_CHILD */
2004 test_window_tree(parent
, simple_style
, simple_order
, 5);
2006 /* complex children styles */
2007 test_window_tree(parent
, complex_style
, complex_order_1
, 1);
2008 test_window_tree(parent
, complex_style
, complex_order_2
, 2);
2009 test_window_tree(parent
, complex_style
, complex_order_3
, 3);
2010 test_window_tree(parent
, complex_style
, complex_order_4
, 4);
2011 test_window_tree(parent
, complex_style
, complex_order_5
, 5);
2013 /* another set of complex children styles */
2014 test_window_tree(parent
, complex_style_6
, complex_order_6
, 3);
2017 #define check_z_order(hwnd, next, prev, owner, topmost) \
2018 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2021 static void check_z_order_debug(HWND hwnd
, HWND next
, HWND prev
, HWND owner
,
2022 BOOL topmost
, const char *file
, int line
)
2027 test
= GetWindow(hwnd
, GW_HWNDNEXT
);
2028 /* skip foreign windows */
2029 while (test
&& (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2030 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0)))
2032 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2033 test
= GetWindow(test
, GW_HWNDNEXT
);
2035 ok_(file
, line
)(next
== test
, "expected next %p, got %p\n", next
, test
);
2037 test
= GetWindow(hwnd
, GW_HWNDPREV
);
2038 /* skip foreign windows */
2039 while (test
&& (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2040 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0)))
2042 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2043 test
= GetWindow(test
, GW_HWNDPREV
);
2045 ok_(file
, line
)(prev
== test
, "expected prev %p, got %p\n", prev
, test
);
2047 test
= GetWindow(hwnd
, GW_OWNER
);
2048 ok_(file
, line
)(owner
== test
, "expected owner %p, got %p\n", owner
, test
);
2050 ex_style
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
2051 ok_(file
, line
)(!(ex_style
& WS_EX_TOPMOST
) == !topmost
, "expected %stopmost\n", topmost
? "" : "NOT ");
2054 static void test_popup_zorder(HWND hwnd_D
, HWND hwnd_E
)
2056 HWND hwnd_A
, hwnd_B
, hwnd_C
, hwnd_F
;
2058 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D
, hwnd_E
);
2060 SetWindowPos(hwnd_E
, hwnd_D
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2062 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2063 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2065 hwnd_F
= CreateWindowEx(0, "MainWindowClass", "Owner window",
2066 WS_OVERLAPPED
| WS_CAPTION
,
2068 0, 0, GetModuleHandle(0), NULL
);
2069 trace("hwnd_F %p\n", hwnd_F
);
2070 check_z_order(hwnd_F
, hwnd_D
, 0, 0, FALSE
);
2072 SetWindowPos(hwnd_F
, hwnd_E
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2073 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2074 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2075 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2077 hwnd_C
= CreateWindowEx(0, "MainWindowClass", NULL
,
2080 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2081 trace("hwnd_C %p\n", hwnd_C
);
2082 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2083 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2084 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2085 check_z_order(hwnd_C
, hwnd_D
, 0, hwnd_F
, FALSE
);
2087 hwnd_B
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2090 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2091 trace("hwnd_B %p\n", hwnd_B
);
2092 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2093 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2094 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2095 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2096 check_z_order(hwnd_B
, hwnd_C
, 0, hwnd_F
, TRUE
);
2098 hwnd_A
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2101 0, 0, GetModuleHandle(0), NULL
);
2102 trace("hwnd_A %p\n", hwnd_A
);
2103 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2104 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2105 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2106 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2107 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2108 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2110 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
);
2112 /* move hwnd_F and its popups up */
2113 SetWindowPos(hwnd_F
, HWND_TOP
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2114 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2115 check_z_order(hwnd_D
, hwnd_E
, hwnd_F
, 0, FALSE
);
2116 check_z_order(hwnd_F
, hwnd_D
, hwnd_C
, 0, FALSE
);
2117 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2118 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2119 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2121 /* move hwnd_F and its popups down */
2122 #if 0 /* enable once Wine is fixed to pass this test */
2123 SetWindowPos(hwnd_F
, HWND_BOTTOM
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2124 check_z_order(hwnd_F
, 0, hwnd_C
, 0, FALSE
);
2125 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2126 check_z_order(hwnd_B
, hwnd_C
, hwnd_E
, hwnd_F
, FALSE
);
2127 check_z_order(hwnd_E
, hwnd_B
, hwnd_D
, 0, FALSE
);
2128 check_z_order(hwnd_D
, hwnd_E
, hwnd_A
, 0, FALSE
);
2129 check_z_order(hwnd_A
, hwnd_D
, 0, 0, TRUE
);
2132 DestroyWindow(hwnd_A
);
2133 DestroyWindow(hwnd_B
);
2134 DestroyWindow(hwnd_C
);
2135 DestroyWindow(hwnd_F
);
2138 static void test_vis_rgn( HWND hwnd
)
2140 RECT win_rect
, rgn_rect
;
2141 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2144 ShowWindow(hwnd
,SW_SHOW
);
2145 hdc
= GetDC( hwnd
);
2146 ok( GetRandomRgn( hdc
, hrgn
, SYSRGN
) != 0, "GetRandomRgn failed\n" );
2147 GetWindowRect( hwnd
, &win_rect
);
2148 GetRgnBox( hrgn
, &rgn_rect
);
2149 if (GetVersion() & 0x80000000)
2151 trace("win9x, mapping to screen coords\n");
2152 MapWindowPoints( hwnd
, 0, (POINT
*)&rgn_rect
, 2 );
2154 trace("win: %d,%d-%d,%d\n", win_rect
.left
, win_rect
.top
, win_rect
.right
, win_rect
.bottom
);
2155 trace("rgn: %d,%d-%d,%d\n", rgn_rect
.left
, rgn_rect
.top
, rgn_rect
.right
, rgn_rect
.bottom
);
2156 ok( win_rect
.left
<= rgn_rect
.left
, "rgn left %d not inside win rect %d\n",
2157 rgn_rect
.left
, win_rect
.left
);
2158 ok( win_rect
.top
<= rgn_rect
.top
, "rgn top %d not inside win rect %d\n",
2159 rgn_rect
.top
, win_rect
.top
);
2160 ok( win_rect
.right
>= rgn_rect
.right
, "rgn right %d not inside win rect %d\n",
2161 rgn_rect
.right
, win_rect
.right
);
2162 ok( win_rect
.bottom
>= rgn_rect
.bottom
, "rgn bottom %d not inside win rect %d\n",
2163 rgn_rect
.bottom
, win_rect
.bottom
);
2164 ReleaseDC( hwnd
, hdc
);
2167 static LRESULT WINAPI
set_focus_on_activate_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
2169 if (msg
== WM_ACTIVATE
&& LOWORD(wp
) == WA_ACTIVE
)
2171 HWND child
= GetWindow(hwnd
, GW_CHILD
);
2172 ok(child
!= 0, "couldn't find child window\n");
2174 ok(GetFocus() == child
, "Focus should be on child %p\n", child
);
2177 return DefWindowProc(hwnd
, msg
, wp
, lp
);
2180 static void test_SetFocus(HWND hwnd
)
2183 WNDPROC old_wnd_proc
;
2185 /* check if we can set focus to non-visible windows */
2187 ShowWindow(hwnd
, SW_SHOW
);
2190 ok( GetFocus() == hwnd
, "Failed to set focus to visible window %p\n", hwnd
);
2191 ok( GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
, "Window %p not visible\n", hwnd
);
2192 ShowWindow(hwnd
, SW_HIDE
);
2195 ok( GetFocus() == hwnd
, "Failed to set focus to invisible window %p\n", hwnd
);
2196 ok( !(GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
), "Window %p still visible\n", hwnd
);
2197 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2200 ok( GetFocus() == child
, "Failed to set focus to invisible child %p\n", child
);
2201 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2202 ShowWindow(child
, SW_SHOW
);
2203 ok( GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
, "Child %p is not visible\n", child
);
2204 ok( GetFocus() == child
, "Focus no longer on child %p\n", child
);
2205 ShowWindow(child
, SW_HIDE
);
2206 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2207 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2208 ShowWindow(child
, SW_SHOW
);
2210 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2211 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_HIDEWINDOW
);
2212 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2214 ShowWindow(child
, SW_HIDE
);
2216 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2217 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_SHOWWINDOW
);
2218 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2219 ShowWindow(child
, SW_HIDE
);
2220 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2222 ShowWindow(hwnd
, SW_SHOW
);
2223 ShowWindow(child
, SW_SHOW
);
2225 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2226 EnableWindow(hwnd
, FALSE
);
2227 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2228 EnableWindow(hwnd
, TRUE
);
2230 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2231 ShowWindow(hwnd
, SW_SHOWMINIMIZED
);
2232 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2234 ok( GetFocus() != child
, "Focus should not be on child %p\n", child
);
2235 ok( GetFocus() != hwnd
, "Focus should not be on parent %p\n", hwnd
);
2236 ShowWindow(hwnd
, SW_RESTORE
);
2237 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2238 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
2239 ShowWindow(hwnd
, SW_SHOWMINIMIZED
);
2240 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2241 ok( GetFocus() != child
, "Focus should not be on child %p\n", child
);
2243 ok( GetFocus() != hwnd
, "Focus should not be on parent %p\n", hwnd
);
2244 old_wnd_proc
= (WNDPROC
)SetWindowLongPtr(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)set_focus_on_activate_proc
);
2245 ShowWindow(hwnd
, SW_RESTORE
);
2246 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2248 ok( GetFocus() == child
, "Focus should be on child %p, not %p\n", child
, GetFocus() );
2250 SetWindowLongPtr(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)old_wnd_proc
);
2252 DestroyWindow( child
);
2255 static void check_wnd_state(HWND active
, HWND foreground
, HWND focus
, HWND capture
)
2257 ok(active
== GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2259 ok(foreground
== GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2260 ok(focus
== GetFocus(), "GetFocus() = %p\n", GetFocus());
2261 ok(capture
== GetCapture(), "GetCapture() = %p\n", GetCapture());
2264 static void test_SetActiveWindow(HWND hwnd
)
2268 ShowWindow(hwnd
, SW_HIDE
);
2271 check_wnd_state(0, 0, 0, 0);
2273 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2275 ShowWindow(hwnd
, SW_SHOW
);
2276 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2278 hwnd2
= SetActiveWindow(0);
2279 ok(hwnd2
== hwnd
, "SetActiveWindow returned %p instead of %p\n", hwnd2
, hwnd
);
2280 check_wnd_state(0, 0, 0, 0);
2282 hwnd2
= SetActiveWindow(hwnd
);
2283 ok(hwnd2
== 0, "SetActiveWindow returned %p instead of 0\n", hwnd2
);
2284 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2286 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2287 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2289 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2290 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2292 ShowWindow(hwnd
, SW_HIDE
);
2293 check_wnd_state(0, 0, 0, 0);
2295 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2296 SetActiveWindow(hwnd
);
2297 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2299 ShowWindow(hwnd
, SW_SHOW
);
2300 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2302 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2303 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2305 DestroyWindow(hwnd2
);
2306 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2308 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2309 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2311 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2312 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2314 DestroyWindow(hwnd2
);
2315 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2318 static void test_SetForegroundWindow(HWND hwnd
)
2323 ShowWindow(hwnd
, SW_HIDE
);
2326 check_wnd_state(0, 0, 0, 0);
2328 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2330 ShowWindow(hwnd
, SW_SHOW
);
2331 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2333 hwnd2
= SetActiveWindow(0);
2334 ok(hwnd2
== hwnd
, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2
, hwnd
);
2335 check_wnd_state(0, 0, 0, 0);
2337 ret
= SetForegroundWindow(hwnd
);
2338 ok(ret
, "SetForegroundWindow returned FALSE instead of TRUE\n");
2339 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2341 SetLastError(0xdeadbeef);
2342 ret
= SetForegroundWindow(0);
2343 ok(!ret
, "SetForegroundWindow returned TRUE instead of FALSE\n");
2344 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2345 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2347 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2348 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2350 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2351 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2353 hwnd2
= GetForegroundWindow();
2354 ok(hwnd2
== hwnd
, "Wrong foreground window %p\n", hwnd2
);
2355 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2356 hwnd2
= GetForegroundWindow();
2357 ok(hwnd2
!= hwnd
, "Wrong foreground window %p\n", hwnd2
);
2359 ShowWindow(hwnd
, SW_HIDE
);
2360 check_wnd_state(0, 0, 0, 0);
2362 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2363 ret
= SetForegroundWindow(hwnd
);
2364 ok(ret
, "SetForegroundWindow returned FALSE instead of TRUE\n");
2365 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2367 ShowWindow(hwnd
, SW_SHOW
);
2368 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2370 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2371 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2373 DestroyWindow(hwnd2
);
2374 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2376 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2377 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2379 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2380 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2382 DestroyWindow(hwnd2
);
2383 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2386 static WNDPROC old_button_proc
;
2388 static LRESULT WINAPI
button_hook_proc(HWND button
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2393 key_state
= GetKeyState(VK_LBUTTON
);
2394 ok(!(key_state
& 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state
);
2396 ret
= CallWindowProcA(old_button_proc
, button
, msg
, wparam
, lparam
);
2398 if (msg
== WM_LBUTTONDOWN
)
2402 check_wnd_state(button
, button
, button
, button
);
2404 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2406 trace("hwnd %p\n", hwnd
);
2408 check_wnd_state(button
, button
, button
, button
);
2410 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2412 check_wnd_state(button
, button
, button
, button
);
2414 DestroyWindow(hwnd
);
2416 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2418 trace("hwnd %p\n", hwnd
);
2420 check_wnd_state(button
, button
, button
, button
);
2422 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2423 * match internal button state.
2425 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2426 check_wnd_state(button
, button
, button
, 0);
2428 ShowWindow(hwnd
, SW_SHOW
);
2429 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2431 capture
= SetCapture(hwnd
);
2432 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2434 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2436 DestroyWindow(hwnd
);
2438 check_wnd_state(button
, 0, button
, 0);
2444 static void test_capture_1(void)
2446 HWND button
, capture
;
2448 capture
= GetCapture();
2449 ok(capture
== 0, "GetCapture() = %p\n", capture
);
2451 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2453 trace("button %p\n", button
);
2455 old_button_proc
= (WNDPROC
)SetWindowLongPtrA(button
, GWLP_WNDPROC
, (LONG_PTR
)button_hook_proc
);
2457 SendMessageA(button
, WM_LBUTTONDOWN
, 0, 0);
2459 capture
= SetCapture(button
);
2460 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2461 check_wnd_state(button
, 0, button
, button
);
2463 DestroyWindow(button
);
2464 check_wnd_state(0, 0, 0, 0);
2467 static void test_capture_2(void)
2469 HWND button
, hwnd
, capture
;
2471 check_wnd_state(0, 0, 0, 0);
2473 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2475 trace("button %p\n", button
);
2477 check_wnd_state(button
, button
, button
, 0);
2479 capture
= SetCapture(button
);
2480 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2482 check_wnd_state(button
, button
, button
, button
);
2484 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2485 * internal button state.
2487 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2488 check_wnd_state(button
, button
, button
, button
);
2490 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2492 trace("hwnd %p\n", hwnd
);
2494 check_wnd_state(button
, button
, button
, button
);
2496 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2498 check_wnd_state(button
, button
, button
, button
);
2500 DestroyWindow(hwnd
);
2502 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2504 trace("hwnd %p\n", hwnd
);
2506 check_wnd_state(button
, button
, button
, button
);
2508 ShowWindow(hwnd
, SW_SHOW
);
2510 check_wnd_state(hwnd
, hwnd
, hwnd
, button
);
2512 capture
= SetCapture(hwnd
);
2513 ok(capture
== button
, "SetCapture() = %p\n", capture
);
2515 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2517 DestroyWindow(hwnd
);
2518 check_wnd_state(button
, button
, button
, 0);
2520 DestroyWindow(button
);
2521 check_wnd_state(0, 0, 0, 0);
2524 static void test_capture_3(HWND hwnd1
, HWND hwnd2
)
2528 ShowWindow(hwnd1
, SW_HIDE
);
2529 ShowWindow(hwnd2
, SW_HIDE
);
2531 ok(!IsWindowVisible(hwnd1
), "%p should be invisible\n", hwnd1
);
2532 ok(!IsWindowVisible(hwnd2
), "%p should be invisible\n", hwnd2
);
2535 check_wnd_state(0, 0, 0, hwnd1
);
2538 check_wnd_state(0, 0, 0, hwnd2
);
2540 ShowWindow(hwnd1
, SW_SHOW
);
2541 check_wnd_state(hwnd1
, hwnd1
, hwnd1
, hwnd2
);
2543 ret
= ReleaseCapture();
2544 ok (ret
, "releasecapture did not return TRUE.\n");
2545 ret
= ReleaseCapture();
2546 ok (ret
, "releasecapture did not return TRUE after second try.\n");
2549 static void test_keyboard_input(HWND hwnd
)
2554 ShowWindow(hwnd
, SW_SHOW
);
2556 flush_events( TRUE
);
2558 ok(GetActiveWindow() == hwnd
, "wrong active window %p\n", GetActiveWindow());
2561 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2563 flush_events( TRUE
);
2565 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2566 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2567 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2568 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2569 ok( !ret
, "message %04x available\n", msg
.message
);
2571 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2573 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2574 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2575 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2576 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2577 ok( !ret
, "message %04x available\n", msg
.message
);
2579 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2581 keybd_event(VK_SPACE
, 0, 0, 0);
2582 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2583 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2584 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2585 ok( !ret
, "message %04x available\n", msg
.message
);
2588 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2590 flush_events( TRUE
);
2592 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2593 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2594 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2595 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2596 ok( !ret
, "message %04x available\n", msg
.message
);
2598 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2600 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2601 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2602 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2603 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2604 ok( !ret
, "message %04x available\n", msg
.message
);
2606 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2608 keybd_event(VK_SPACE
, 0, 0, 0);
2609 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2610 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_SYSKEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2611 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2612 ok( !ret
, "message %04x available\n", msg
.message
);
2615 static void test_mouse_input(HWND hwnd
)
2625 ShowWindow(hwnd
, SW_SHOW
);
2628 GetWindowRect(hwnd
, &rc
);
2629 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2631 popup
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_POPUP
,
2632 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
,
2635 ShowWindow(popup
, SW_SHOW
);
2636 UpdateWindow(popup
);
2638 GetWindowRect(popup
, &rc
);
2639 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2641 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
2642 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
2643 trace("setting cursor to (%d,%d)\n", x
, y
);
2647 ok(x
== pt
.x
&& y
== pt
.y
, "wrong cursor pos (%d,%d), expected (%d,%d)\n", pt
.x
, pt
.y
, x
, y
);
2649 flush_events( TRUE
);
2651 /* Check that setting the same position will generate WM_MOUSEMOVE */
2654 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2655 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2656 ok(msg
.pt
.x
== x
&& msg
.pt
.y
== y
, "wrong message coords (%d,%d)/(%d,%d)\n", x
, y
, msg
.pt
.x
, msg
.pt
.y
);
2658 /* force the system to update its internal queue mouse position,
2659 * otherwise it won't generate relative mouse movements below.
2661 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2662 flush_events( TRUE
);
2665 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2666 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2667 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2668 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2669 if (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
2670 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2671 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2672 ok( !ret
, "message %04x available\n", msg
.message
);
2674 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2675 ShowWindow(popup
, SW_HIDE
);
2676 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2677 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2678 flush_events( TRUE
);
2680 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2681 ShowWindow(hwnd
, SW_HIDE
);
2682 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2683 ok( !ret
, "message %04x available\n", msg
.message
);
2684 flush_events( TRUE
);
2686 /* test mouse clicks */
2688 ShowWindow(hwnd
, SW_SHOW
);
2689 flush_events( TRUE
);
2690 ShowWindow(popup
, SW_SHOW
);
2691 flush_events( TRUE
);
2693 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2694 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2695 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2696 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2698 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2699 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2700 msg
.hwnd
, popup
, msg
.message
);
2701 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2702 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2703 msg
.hwnd
, popup
, msg
.message
);
2705 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2706 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2707 msg
.hwnd
, popup
, msg
.message
);
2708 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2709 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2710 msg
.hwnd
, popup
, msg
.message
);
2712 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2713 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p/%p message %04x\n",
2714 msg
.hwnd
, popup
, msg
.message
);
2715 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2716 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p/%p message %04x\n",
2717 msg
.hwnd
, popup
, msg
.message
);
2719 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2720 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2721 msg
.hwnd
, popup
, msg
.message
);
2722 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2723 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2724 msg
.hwnd
, popup
, msg
.message
);
2726 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2727 ok(!ret
, "message %04x available\n", msg
.message
);
2729 ShowWindow(popup
, SW_HIDE
);
2730 flush_events( TRUE
);
2732 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2733 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2734 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2735 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2737 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2738 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2739 msg
.hwnd
, hwnd
, msg
.message
);
2740 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2741 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2742 msg
.hwnd
, hwnd
, msg
.message
);
2744 test_lbuttondown_flag
= TRUE
;
2745 SendMessageA(hwnd
, WM_COMMAND
, (WPARAM
)popup
, 0);
2746 test_lbuttondown_flag
= FALSE
;
2748 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2749 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2750 msg
.hwnd
, popup
, msg
.message
);
2751 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2752 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2753 msg
.hwnd
, popup
, msg
.message
);
2754 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2756 /* Test WM_MOUSEACTIVATE */
2757 #define TEST_MOUSEACTIVATE(A,B) \
2758 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2759 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2761 TEST_MOUSEACTIVATE(HTERROR
,MA_ACTIVATE
);
2762 TEST_MOUSEACTIVATE(HTTRANSPARENT
,MA_ACTIVATE
);
2763 TEST_MOUSEACTIVATE(HTNOWHERE
,MA_ACTIVATE
);
2764 TEST_MOUSEACTIVATE(HTCLIENT
,MA_ACTIVATE
);
2765 TEST_MOUSEACTIVATE(HTCAPTION
,MA_ACTIVATE
);
2766 TEST_MOUSEACTIVATE(HTSYSMENU
,MA_ACTIVATE
);
2767 TEST_MOUSEACTIVATE(HTSIZE
,MA_ACTIVATE
);
2768 TEST_MOUSEACTIVATE(HTMENU
,MA_ACTIVATE
);
2769 TEST_MOUSEACTIVATE(HTHSCROLL
,MA_ACTIVATE
);
2770 TEST_MOUSEACTIVATE(HTVSCROLL
,MA_ACTIVATE
);
2771 TEST_MOUSEACTIVATE(HTMINBUTTON
,MA_ACTIVATE
);
2772 TEST_MOUSEACTIVATE(HTMAXBUTTON
,MA_ACTIVATE
);
2773 TEST_MOUSEACTIVATE(HTLEFT
,MA_ACTIVATE
);
2774 TEST_MOUSEACTIVATE(HTRIGHT
,MA_ACTIVATE
);
2775 TEST_MOUSEACTIVATE(HTTOP
,MA_ACTIVATE
);
2776 TEST_MOUSEACTIVATE(HTTOPLEFT
,MA_ACTIVATE
);
2777 TEST_MOUSEACTIVATE(HTTOPRIGHT
,MA_ACTIVATE
);
2778 TEST_MOUSEACTIVATE(HTBOTTOM
,MA_ACTIVATE
);
2779 TEST_MOUSEACTIVATE(HTBOTTOMLEFT
,MA_ACTIVATE
);
2780 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT
,MA_ACTIVATE
);
2781 TEST_MOUSEACTIVATE(HTBORDER
,MA_ACTIVATE
);
2782 TEST_MOUSEACTIVATE(HTOBJECT
,MA_ACTIVATE
);
2783 TEST_MOUSEACTIVATE(HTCLOSE
,MA_ACTIVATE
);
2784 TEST_MOUSEACTIVATE(HTHELP
,MA_ACTIVATE
);
2786 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2787 flush_events( TRUE
);
2789 DestroyWindow(popup
);
2792 static void test_validatergn(HWND hwnd
)
2798 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_VISIBLE
, 10, 10, 10, 10, hwnd
, 0, 0, NULL
);
2799 ShowWindow(hwnd
, SW_SHOW
);
2800 UpdateWindow( hwnd
);
2801 /* test that ValidateRect validates children*/
2802 InvalidateRect( child
, NULL
, 1);
2803 GetWindowRect( child
, &rc
);
2804 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2805 ret
= GetUpdateRect( child
, &rc2
, 0);
2806 ok( rc2
.right
> rc2
.left
&& rc2
.bottom
> rc2
.top
,
2807 "Update rectangle is empty!\n");
2808 ValidateRect( hwnd
, &rc
);
2809 ret
= GetUpdateRect( child
, &rc2
, 0);
2810 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2811 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
2812 rc2
.right
, rc2
.bottom
);
2814 /* now test ValidateRgn */
2815 InvalidateRect( child
, NULL
, 1);
2816 GetWindowRect( child
, &rc
);
2817 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2818 rgn
= CreateRectRgnIndirect( &rc
);
2819 ValidateRgn( hwnd
, rgn
);
2820 ret
= GetUpdateRect( child
, &rc2
, 0);
2821 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2822 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
2823 rc2
.right
, rc2
.bottom
);
2826 DestroyWindow( child
);
2829 static void nccalchelper(HWND hwnd
, INT x
, INT y
, RECT
*prc
)
2831 MoveWindow( hwnd
, 0, 0, x
, y
, 0);
2832 GetWindowRect( hwnd
, prc
);
2833 trace("window rect is %d,%d - %d,%d\n",
2834 prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
2835 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)prc
);
2836 trace("nccalc rect is %d,%d - %d,%d\n",
2837 prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
2840 static void test_nccalcscroll(HWND parent
)
2843 INT sbheight
= GetSystemMetrics( SM_CYHSCROLL
);
2844 INT sbwidth
= GetSystemMetrics( SM_CXVSCROLL
);
2845 HWND hwnd
= CreateWindowExA(0, "static", NULL
,
2846 WS_CHILD
| WS_VISIBLE
| WS_VSCROLL
| WS_HSCROLL
,
2847 10, 10, 200, 200, parent
, 0, 0, NULL
);
2848 ShowWindow( parent
, SW_SHOW
);
2849 UpdateWindow( parent
);
2851 /* test window too low for a horizontal scroll bar */
2852 nccalchelper( hwnd
, 100, sbheight
, &rc1
);
2853 ok( rc1
.bottom
- rc1
.top
== sbheight
, "Height should be %d size is %d,%d - %d,%d\n",
2854 sbheight
, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2856 /* test window just high enough for a horizontal scroll bar */
2857 nccalchelper( hwnd
, 100, sbheight
+ 1, &rc1
);
2858 ok( rc1
.bottom
- rc1
.top
== 1, "Height should be %d size is %d,%d - %d,%d\n",
2859 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2861 /* test window too narrow for a vertical scroll bar */
2862 nccalchelper( hwnd
, sbwidth
- 1, 100, &rc1
);
2863 ok( rc1
.right
- rc1
.left
== sbwidth
- 1 , "Width should be %d size is %d,%d - %d,%d\n",
2864 sbwidth
- 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2866 /* test window just wide enough for a vertical scroll bar */
2867 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
2868 ok( rc1
.right
- rc1
.left
== 0, "Width should be %d size is %d,%d - %d,%d\n",
2869 0, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2871 /* same test, but with client edge: not enough width */
2872 SetWindowLong( hwnd
, GWL_EXSTYLE
, WS_EX_CLIENTEDGE
| GetWindowLong( hwnd
, GWL_EXSTYLE
));
2873 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
2874 ok( rc1
.right
- rc1
.left
== sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
),
2875 "Width should be %d size is %d,%d - %d,%d\n",
2876 sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
), rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2878 DestroyWindow( hwnd
);
2881 static void test_SetParent(void)
2884 HWND desktop
= GetDesktopWindow();
2886 BOOL is_win9x
= GetWindowLongPtrW(desktop
, GWLP_WNDPROC
) == 0;
2887 HWND parent
, child1
, child2
, child3
, child4
, sibling
;
2889 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
2890 100, 100, 200, 200, 0, 0, 0, NULL
);
2891 assert(parent
!= 0);
2892 child1
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
2893 0, 0, 50, 50, parent
, 0, 0, NULL
);
2894 assert(child1
!= 0);
2895 child2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
2896 0, 0, 50, 50, child1
, 0, 0, NULL
);
2897 assert(child2
!= 0);
2898 child3
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
2899 0, 0, 50, 50, child2
, 0, 0, NULL
);
2900 assert(child3
!= 0);
2901 child4
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
2902 0, 0, 50, 50, child3
, 0, 0, NULL
);
2903 assert(child4
!= 0);
2905 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2906 parent
, child1
, child2
, child3
, child4
);
2908 check_parents(parent
, desktop
, 0, 0, 0, parent
, parent
);
2909 check_parents(child1
, parent
, parent
, parent
, 0, parent
, parent
);
2910 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
2911 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
2912 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
2914 ok(!IsChild(desktop
, parent
), "wrong parent/child %p/%p\n", desktop
, parent
);
2915 ok(!IsChild(desktop
, child1
), "wrong parent/child %p/%p\n", desktop
, child1
);
2916 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
2917 ok(!IsChild(desktop
, child3
), "wrong parent/child %p/%p\n", desktop
, child3
);
2918 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
2920 ok(IsChild(parent
, child1
), "wrong parent/child %p/%p\n", parent
, child1
);
2921 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
2922 ok(!IsChild(parent
, child2
), "wrong parent/child %p/%p\n", parent
, child2
);
2923 ok(!IsChild(child1
, child2
), "wrong parent/child %p/%p\n", child1
, child2
);
2924 ok(!IsChild(parent
, child3
), "wrong parent/child %p/%p\n", parent
, child3
);
2925 ok(IsChild(child2
, child3
), "wrong parent/child %p/%p\n", child2
, child3
);
2926 ok(!IsChild(parent
, child4
), "wrong parent/child %p/%p\n", parent
, child4
);
2927 ok(!IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
2928 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
2930 if (!is_win9x
) /* Win9x doesn't survive this test */
2932 ok(!SetParent(parent
, child1
), "SetParent should fail\n");
2933 ok(!SetParent(child2
, child3
), "SetParent should fail\n");
2934 ok(SetParent(child1
, parent
) != 0, "SetParent should not fail\n");
2935 ok(SetParent(parent
, child2
) != 0, "SetParent should not fail\n");
2936 ok(SetParent(parent
, child3
) != 0, "SetParent should not fail\n");
2937 ok(!SetParent(child2
, parent
), "SetParent should fail\n");
2938 ok(SetParent(parent
, child4
) != 0, "SetParent should not fail\n");
2940 check_parents(parent
, child4
, child4
, 0, 0, child4
, parent
);
2941 check_parents(child1
, parent
, parent
, parent
, 0, child4
, parent
);
2942 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
2943 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
2944 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
2947 hMenu
= CreateMenu();
2948 sibling
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
2949 100, 100, 200, 200, 0, hMenu
, 0, NULL
);
2950 assert(sibling
!= 0);
2952 ok(SetParent(sibling
, parent
) != 0, "SetParent should not fail\n");
2953 ok(GetMenu(sibling
) == hMenu
, "SetParent should not remove menu\n");
2955 ret
= DestroyWindow(parent
);
2956 ok( ret
, "DestroyWindow() error %d\n", GetLastError());
2958 ok(!IsWindow(parent
), "parent still exists\n");
2959 ok(!IsWindow(sibling
), "sibling still exists\n");
2960 ok(!IsWindow(child1
), "child1 still exists\n");
2961 ok(!IsWindow(child2
), "child2 still exists\n");
2962 ok(!IsWindow(child3
), "child3 still exists\n");
2963 ok(!IsWindow(child4
), "child4 still exists\n");
2966 static LRESULT WINAPI
StyleCheckProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2968 LPCREATESTRUCT lpcs
;
2975 lpcs
= (LPCREATESTRUCT
)lparam
;
2976 lpss
= (LPSTYLESTRUCT
)lpcs
->lpCreateParams
;
2979 if ((lpcs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
2980 ((!(lpcs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
2981 (lpcs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
2982 ok(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
, "Window should have WS_EX_WINDOWEDGE style\n");
2984 ok(!(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
2986 ok((lpss
->styleOld
& ~WS_EX_WINDOWEDGE
) == (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
),
2987 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2988 (lpss
->styleOld
& ~WS_EX_WINDOWEDGE
), (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
));
2990 ok(lpss
->styleNew
== lpcs
->style
,
2991 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
2992 lpss
->styleNew
, lpcs
->style
);
2996 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
2999 static ATOM atomStyleCheckClass
;
3001 static void register_style_check_class(void)
3009 GetModuleHandle(NULL
),
3011 LoadCursor(NULL
, IDC_ARROW
),
3012 (HBRUSH
)(COLOR_BTNFACE
+1),
3014 TEXT("WineStyleCheck"),
3017 atomStyleCheckClass
= RegisterClass(&wc
);
3020 static void check_window_style(DWORD dwStyleIn
, DWORD dwExStyleIn
, DWORD dwStyleOut
, DWORD dwExStyleOut
)
3022 DWORD dwActualStyle
;
3023 DWORD dwActualExStyle
;
3026 HWND hwndParent
= NULL
;
3028 ss
.styleNew
= dwStyleIn
;
3029 ss
.styleOld
= dwExStyleIn
;
3031 if (dwStyleIn
& WS_CHILD
)
3033 hwndParent
= CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3034 WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
3037 hwnd
= CreateWindowEx(dwExStyleIn
, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3038 dwStyleIn
, 0, 0, 0, 0, hwndParent
, NULL
, NULL
, &ss
);
3041 flush_events( TRUE
);
3043 dwActualStyle
= GetWindowLong(hwnd
, GWL_STYLE
);
3044 dwActualExStyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
3045 ok((dwActualStyle
== dwStyleOut
) && (dwActualExStyle
== dwExStyleOut
),
3046 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3047 dwActualStyle
, dwStyleOut
, dwActualExStyle
, dwExStyleOut
);
3049 DestroyWindow(hwnd
);
3050 if (hwndParent
) DestroyWindow(hwndParent
);
3053 /* tests what window styles the window manager automatically adds */
3054 static void test_window_styles(void)
3056 register_style_check_class();
3058 check_window_style(0, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
3059 check_window_style(WS_OVERLAPPEDWINDOW
, 0, WS_CLIPSIBLINGS
|WS_OVERLAPPEDWINDOW
, WS_EX_WINDOWEDGE
);
3060 check_window_style(WS_CHILD
, 0, WS_CHILD
, 0);
3061 check_window_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
3062 check_window_style(0, WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_TOOLWINDOW
);
3063 check_window_style(WS_POPUP
, 0, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3064 check_window_style(WS_POPUP
, WS_EX_WINDOWEDGE
, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3065 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
, WS_CHILD
, WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3066 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
|WS_EX_STATICEDGE
, WS_CHILD
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3067 check_window_style(WS_CAPTION
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
);
3068 check_window_style(0, WS_EX_APPWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_APPWINDOW
|WS_EX_WINDOWEDGE
);
3071 static void test_scrollvalidate( HWND parent
)
3074 HRGN hrgn
=CreateRectRgn(0,0,0,0);
3075 HRGN exprgn
, tmprgn
, clipping
;
3076 RECT rc
, rcu
, cliprc
;
3077 /* create two overlapping child windows. The visual region
3078 * of hwnd1 is clipped by the overlapping part of
3079 * hwnd2 because of the WS_CLIPSIBLING style */
3082 clipping
= CreateRectRgn(0,0,0,0);
3083 tmprgn
= CreateRectRgn(0,0,0,0);
3084 exprgn
= CreateRectRgn(0,0,0,0);
3085 hwnd2
= CreateWindowExA(0, "static", NULL
,
3086 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3087 75, 30, 100, 100, parent
, 0, 0, NULL
);
3088 hwnd1
= CreateWindowExA(0, "static", NULL
,
3089 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3090 25, 50, 100, 100, parent
, 0, 0, NULL
);
3091 ShowWindow( parent
, SW_SHOW
);
3092 UpdateWindow( parent
);
3093 GetClientRect( hwnd1
, &rc
);
3095 SetRectRgn( clipping
, 10, 10, 90, 90);
3096 hdc
= GetDC( hwnd1
);
3097 /* for a visual touch */
3098 TextOut( hdc
, 0,10, "0123456789", 10);
3099 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3100 if (winetest_debug
> 0) dump_region(hrgn
);
3101 /* create a region with what is expected */
3102 SetRectRgn( exprgn
, 39,0,49,74);
3103 SetRectRgn( tmprgn
, 88,79,98,93);
3104 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3105 SetRectRgn( tmprgn
, 0,93,98,98);
3106 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3107 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3108 trace("update rect is %d,%d - %d,%d\n",
3109 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3110 /* now with clipping region */
3111 SelectClipRgn( hdc
, clipping
);
3112 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3113 if (winetest_debug
> 0) dump_region(hrgn
);
3114 /* create a region with what is expected */
3115 SetRectRgn( exprgn
, 39,10,49,74);
3116 SetRectRgn( tmprgn
, 80,79,90,85);
3117 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3118 SetRectRgn( tmprgn
, 10,85,90,90);
3119 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3120 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3121 trace("update rect is %d,%d - %d,%d\n",
3122 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3123 ReleaseDC( hwnd1
, hdc
);
3125 /* test scrolling a window with an update region */
3126 DestroyWindow( hwnd2
);
3127 ValidateRect( hwnd1
, NULL
);
3128 SetRect( &rc
, 40,40, 50,50);
3129 InvalidateRect( hwnd1
, &rc
, 1);
3130 GetClientRect( hwnd1
, &rc
);
3132 ScrollWindowEx( hwnd1
, -10, 0, &rc
, &cliprc
, hrgn
, &rcu
,
3133 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3134 if (winetest_debug
> 0) dump_region(hrgn
);
3135 SetRectRgn( exprgn
, 88,0,98,98);
3136 SetRectRgn( tmprgn
, 30, 40, 50, 50);
3137 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3138 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3140 /* clear an update region */
3141 UpdateWindow( hwnd1
);
3143 SetRect( &rc
, 0,40, 100,60);
3144 SetRect( &cliprc
, 0,0, 100,100);
3145 ScrollWindowEx( hwnd1
, 0, -25, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3146 if (winetest_debug
> 0) dump_region( hrgn
);
3147 SetRectRgn( exprgn
, 0, 40, 98, 60 );
3148 ok( EqualRgn( exprgn
, hrgn
), "wrong update region in excessive scroll\n");
3150 /* now test ScrollWindowEx with a combination of
3151 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3152 /* make hwnd2 the child of hwnd1 */
3153 hwnd2
= CreateWindowExA(0, "static", NULL
,
3154 WS_CHILD
| WS_VISIBLE
| WS_BORDER
,
3155 50, 50, 100, 100, hwnd1
, 0, 0, NULL
);
3156 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPSIBLINGS
);
3157 GetClientRect( hwnd1
, &rc
);
3160 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3161 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3162 ValidateRect( hwnd1
, NULL
);
3163 ValidateRect( hwnd2
, NULL
);
3164 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
,
3165 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3166 if (winetest_debug
> 0) dump_region(hrgn
);
3167 SetRectRgn( exprgn
, 88,0,98,88);
3168 SetRectRgn( tmprgn
, 0,88,98,98);
3169 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3170 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3172 /* SW_SCROLLCHILDREN */
3173 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3174 ValidateRect( hwnd1
, NULL
);
3175 ValidateRect( hwnd2
, NULL
);
3176 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3177 if (winetest_debug
> 0) dump_region(hrgn
);
3178 /* expected region is the same as in previous test */
3179 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3181 /* no SW_SCROLLCHILDREN */
3182 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3183 ValidateRect( hwnd1
, NULL
);
3184 ValidateRect( hwnd2
, NULL
);
3185 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3186 if (winetest_debug
> 0) dump_region(hrgn
);
3187 /* expected region is the same as in previous test */
3188 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3190 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3191 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3192 ValidateRect( hwnd1
, NULL
);
3193 ValidateRect( hwnd2
, NULL
);
3194 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3195 if (winetest_debug
> 0) dump_region(hrgn
);
3196 SetRectRgn( exprgn
, 88,0,98,20);
3197 SetRectRgn( tmprgn
, 20,20,98,30);
3198 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3199 SetRectRgn( tmprgn
, 20,30,30,88);
3200 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3201 SetRectRgn( tmprgn
, 0,88,30,98);
3202 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3203 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3206 DeleteObject( hrgn
);
3207 DeleteObject( exprgn
);
3208 DeleteObject( tmprgn
);
3209 DestroyWindow( hwnd1
);
3210 DestroyWindow( hwnd2
);
3213 /* couple of tests of return values of scrollbar functions
3214 * called on a scrollbarless window */
3215 static void test_scroll(void)
3220 HWND hwnd
= CreateWindowExA(0, "Static", "Wine test window",
3221 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_POPUP
,
3222 100, 100, 200, 200, 0, 0, 0, NULL
);
3224 ret
= GetScrollRange( hwnd
, SB_HORZ
, &min
, &max
);
3225 ok( ret
, "GetScrollRange returns FALSE\n");
3226 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3227 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3228 si
.cbSize
= sizeof( si
);
3229 si
.fMask
= SIF_PAGE
;
3230 si
.nPage
= 0xdeadbeef;
3231 ret
= GetScrollInfo( hwnd
, SB_HORZ
, &si
);
3232 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3233 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3235 ret
= GetScrollRange( hwnd
, SB_VERT
, &min
, &max
);
3236 ok( ret
, "GetScrollRange returns FALSE\n");
3237 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3238 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3239 si
.cbSize
= sizeof( si
);
3240 si
.fMask
= SIF_PAGE
;
3241 si
.nPage
= 0xdeadbeef;
3242 ret
= GetScrollInfo( hwnd
, SB_VERT
, &si
);
3243 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3244 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3246 DestroyWindow( hwnd
);
3249 static void test_scrolldc( HWND parent
)
3252 HRGN exprgn
, tmprgn
, hrgn
;
3253 RECT rc
, rc2
, rcu
, cliprc
;
3257 hrgn
= CreateRectRgn(0,0,0,0);
3258 tmprgn
= CreateRectRgn(0,0,0,0);
3259 exprgn
= CreateRectRgn(0,0,0,0);
3261 hwnd1
= CreateWindowExA(0, "static", NULL
,
3262 WS_CHILD
| WS_VISIBLE
,
3263 25, 50, 100, 100, parent
, 0, 0, NULL
);
3264 ShowWindow( parent
, SW_SHOW
);
3265 UpdateWindow( parent
);
3266 flush_events( TRUE
);
3267 GetClientRect( hwnd1
, &rc
);
3268 hdc
= GetDC( hwnd1
);
3269 /* paint the upper half of the window black */
3271 rc2
.bottom
= ( rc
.top
+ rc
.bottom
) /2;
3272 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3273 /* clip region is the lower half */
3275 cliprc
.top
= (rc
.top
+ rc
.bottom
) /2;
3276 /* test whether scrolled pixels are properly clipped */
3277 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3278 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3279 /* this scroll should not cause any visible changes */
3280 ScrollDC( hdc
, 5, -20, &rc
, &cliprc
, hrgn
, &rcu
);
3281 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3282 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3283 /* test with NULL clip rect */
3284 ScrollDC( hdc
, 20, -20, &rc
, NULL
, hrgn
, &rcu
);
3285 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3286 trace("update rect: %d,%d - %d,%d\n",
3287 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3288 if (winetest_debug
> 0) dump_region(hrgn
);
3289 SetRect(&rc2
, 0, 0, 100, 100);
3290 ok(EqualRect(&rcu
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3291 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
3293 SetRectRgn( exprgn
, 0, 0, 20, 80);
3294 SetRectRgn( tmprgn
, 0, 80, 100, 100);
3295 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3296 if (winetest_debug
> 0) dump_region(exprgn
);
3297 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3298 /* test clip rect > scroll rect */
3299 FillRect( hdc
, &rc
, GetStockObject(WHITE_BRUSH
));
3301 InflateRect( &rc2
, -(rc
.right
-rc
.left
)/4, -(rc
.bottom
-rc
.top
)/4);
3302 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3303 ScrollDC( hdc
, 10, 10, &rc2
, &rc
, hrgn
, &rcu
);
3304 SetRectRgn( exprgn
, 25, 25, 75, 35);
3305 SetRectRgn( tmprgn
, 25, 35, 35, 75);
3306 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3307 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3308 colr
= GetPixel( hdc
, 80, 80);
3309 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3310 trace("update rect: %d,%d - %d,%d\n",
3311 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3312 if (winetest_debug
> 0) dump_region(hrgn
);
3316 DeleteObject(exprgn
);
3317 DeleteObject(tmprgn
);
3318 DestroyWindow(hwnd1
);
3321 static void test_params(void)
3326 /* Just a param check */
3327 SetLastError(0xdeadbeef);
3328 rc
= GetWindowText(hwndMain2
, NULL
, 1024);
3329 ok( rc
==0, "GetWindowText: rc=%d err=%d\n",rc
,GetLastError());
3331 SetLastError(0xdeadbeef);
3332 hwnd
=CreateWindow("LISTBOX", "TestList",
3333 (LBS_STANDARD
& ~LBS_SORT
),
3335 NULL
, (HMENU
)1, NULL
, 0);
3337 ok(!hwnd
, "CreateWindow with invalid menu handle should fail\n");
3338 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
|| /* NT */
3339 GetLastError() == 0xdeadbeef, /* Win9x */
3340 "wrong last error value %d\n", GetLastError());
3343 static void test_AWRwindow(LPCSTR
class, LONG style
, LONG exStyle
, BOOL menu
)
3347 hwnd
= CreateWindowEx(exStyle
, class, class, style
,
3354 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style
, exStyle
);
3357 ShowWindow(hwnd
, SW_SHOW
);
3359 test_nonclient_area(hwnd
);
3362 DestroyWindow(hwnd
);
3365 static BOOL
AWR_init(void)
3369 class.style
= CS_HREDRAW
| CS_VREDRAW
;
3370 class.lpfnWndProc
= DefWindowProcA
;
3371 class.cbClsExtra
= 0;
3372 class.cbWndExtra
= 0;
3373 class.hInstance
= 0;
3374 class.hIcon
= LoadIcon (0, IDI_APPLICATION
);
3375 class.hCursor
= LoadCursor (0, IDC_ARROW
);
3376 class.hbrBackground
= 0;
3377 class.lpszMenuName
= 0;
3378 class.lpszClassName
= szAWRClass
;
3380 if (!RegisterClass (&class)) {
3381 ok(FALSE
, "RegisterClass failed\n");
3385 hmenu
= CreateMenu();
3388 ok(hmenu
!= 0, "Failed to create menu\n");
3389 ok(AppendMenu(hmenu
, MF_STRING
, 1, "Test!"), "Failed to create menu item\n");
3395 static void test_AWR_window_size(BOOL menu
)
3399 WS_MAXIMIZE
, WS_BORDER
, WS_DLGFRAME
,
3402 WS_MINIMIZEBOX
, WS_MAXIMIZEBOX
,
3403 WS_HSCROLL
, WS_VSCROLL
3407 WS_EX_TOOLWINDOW
, WS_EX_WINDOWEDGE
,
3410 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3411 WS_EX_DLGMODALFRAME
,
3418 /* A exhaustive check of all the styles takes too long
3419 * so just do a (hopefully representative) sample
3421 for (i
= 0; i
< COUNTOF(styles
); ++i
)
3422 test_AWRwindow(szAWRClass
, styles
[i
], 0, menu
);
3423 for (i
= 0; i
< COUNTOF(exStyles
); ++i
) {
3424 test_AWRwindow(szAWRClass
, WS_POPUP
, exStyles
[i
], menu
);
3425 test_AWRwindow(szAWRClass
, WS_THICKFRAME
, exStyles
[i
], menu
);
3430 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3432 static void test_AdjustWindowRect(void)
3437 SHOWSYSMETRIC(SM_CYCAPTION
);
3438 SHOWSYSMETRIC(SM_CYSMCAPTION
);
3439 SHOWSYSMETRIC(SM_CYMENU
);
3440 SHOWSYSMETRIC(SM_CXEDGE
);
3441 SHOWSYSMETRIC(SM_CYEDGE
);
3442 SHOWSYSMETRIC(SM_CXVSCROLL
);
3443 SHOWSYSMETRIC(SM_CYHSCROLL
);
3444 SHOWSYSMETRIC(SM_CXFRAME
);
3445 SHOWSYSMETRIC(SM_CYFRAME
);
3446 SHOWSYSMETRIC(SM_CXDLGFRAME
);
3447 SHOWSYSMETRIC(SM_CYDLGFRAME
);
3448 SHOWSYSMETRIC(SM_CXBORDER
);
3449 SHOWSYSMETRIC(SM_CYBORDER
);
3451 test_AWR_window_size(FALSE
);
3452 test_AWR_window_size(TRUE
);
3456 #undef SHOWSYSMETRIC
3459 /* Global variables to trigger exit from loop */
3460 static int redrawComplete
, WMPAINT_count
;
3462 static LRESULT WINAPI
redraw_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3467 trace("doing WM_PAINT %d\n", WMPAINT_count
);
3469 if (WMPAINT_count
> 10 && redrawComplete
== 0) {
3471 BeginPaint(hwnd
, &ps
);
3472 EndPaint(hwnd
, &ps
);
3477 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3480 /* Ensure we exit from RedrawNow regardless of invalidated area */
3481 static void test_redrawnow(void)
3486 cls
.style
= CS_DBLCLKS
;
3487 cls
.lpfnWndProc
= redraw_window_procA
;
3490 cls
.hInstance
= GetModuleHandleA(0);
3492 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3493 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3494 cls
.lpszMenuName
= NULL
;
3495 cls
.lpszClassName
= "RedrawWindowClass";
3497 if(!RegisterClassA(&cls
)) {
3498 trace("Register failed %d\n", GetLastError());
3502 hwndMain
= CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3503 CW_USEDEFAULT
, 0, 100, 100, NULL
, NULL
, 0, NULL
);
3505 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3506 ShowWindow(hwndMain
, SW_SHOW
);
3507 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3508 RedrawWindow(hwndMain
, NULL
,NULL
,RDW_UPDATENOW
| RDW_ALLCHILDREN
);
3509 ok( WMPAINT_count
== 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3510 redrawComplete
= TRUE
;
3511 ok( WMPAINT_count
< 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count
);
3514 DestroyWindow( hwndMain
);
3517 struct parentdc_stat
{
3523 struct parentdc_test
{
3524 struct parentdc_stat main
, main_todo
;
3525 struct parentdc_stat child1
, child1_todo
;
3526 struct parentdc_stat child2
, child2_todo
;
3529 static LRESULT WINAPI
parentdc_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3534 struct parentdc_stat
*t
= (struct parentdc_stat
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
3539 trace("doing WM_PAINT on %p\n", hwnd
);
3540 GetClientRect(hwnd
, &rc
);
3541 CopyRect(&t
->client
, &rc
);
3542 trace("client rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3543 GetWindowRect(hwnd
, &rc
);
3544 trace("window rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3545 BeginPaint(hwnd
, &ps
);
3546 CopyRect(&t
->paint
, &ps
.rcPaint
);
3547 GetClipBox(ps
.hdc
, &rc
);
3548 CopyRect(&t
->clip
, &rc
);
3549 trace("clip rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3550 trace("paint rect (%d, %d)-(%d, %d)\n", ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
3551 EndPaint(hwnd
, &ps
);
3554 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3557 static void zero_parentdc_stat(struct parentdc_stat
*t
)
3559 SetRectEmpty(&t
->client
);
3560 SetRectEmpty(&t
->clip
);
3561 SetRectEmpty(&t
->paint
);
3564 static void zero_parentdc_test(struct parentdc_test
*t
)
3566 zero_parentdc_stat(&t
->main
);
3567 zero_parentdc_stat(&t
->child1
);
3568 zero_parentdc_stat(&t
->child2
);
3571 #define parentdc_field_ok(t, w, r, f, got) \
3572 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3573 ": expected %d, got %d\n", \
3576 #define parentdc_todo_field_ok(t, w, r, f, got) \
3577 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3578 else parentdc_field_ok(t, w, r, f, got)
3580 #define parentdc_rect_ok(t, w, r, got) \
3581 parentdc_todo_field_ok(t, w, r, left, got); \
3582 parentdc_todo_field_ok(t, w, r, top, got); \
3583 parentdc_todo_field_ok(t, w, r, right, got); \
3584 parentdc_todo_field_ok(t, w, r, bottom, got);
3586 #define parentdc_win_ok(t, w, got) \
3587 parentdc_rect_ok(t, w, client, got); \
3588 parentdc_rect_ok(t, w, clip, got); \
3589 parentdc_rect_ok(t, w, paint, got);
3591 #define parentdc_ok(t, got) \
3592 parentdc_win_ok(t, main, got); \
3593 parentdc_win_ok(t, child1, got); \
3594 parentdc_win_ok(t, child2, got);
3596 static void test_csparentdc(void)
3598 WNDCLASSA clsMain
, cls
;
3599 HWND hwndMain
, hwnd1
, hwnd2
;
3602 struct parentdc_test test_answer
;
3604 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3605 const struct parentdc_test test1
=
3607 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo
,
3608 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3609 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3612 const struct parentdc_test test2
=
3614 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo
,
3615 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3616 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3619 const struct parentdc_test test3
=
3621 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3622 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3623 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3626 const struct parentdc_test test4
=
3628 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo
,
3629 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo
,
3630 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3633 const struct parentdc_test test5
=
3635 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo
,
3636 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3637 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3640 const struct parentdc_test test6
=
3642 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3643 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3644 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3647 const struct parentdc_test test7
=
3649 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3650 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3651 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3655 clsMain
.style
= CS_DBLCLKS
;
3656 clsMain
.lpfnWndProc
= parentdc_window_procA
;
3657 clsMain
.cbClsExtra
= 0;
3658 clsMain
.cbWndExtra
= 0;
3659 clsMain
.hInstance
= GetModuleHandleA(0);
3661 clsMain
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3662 clsMain
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3663 clsMain
.lpszMenuName
= NULL
;
3664 clsMain
.lpszClassName
= "ParentDcMainWindowClass";
3666 if(!RegisterClassA(&clsMain
)) {
3667 trace("Register failed %d\n", GetLastError());
3671 cls
.style
= CS_DBLCLKS
| CS_PARENTDC
;
3672 cls
.lpfnWndProc
= parentdc_window_procA
;
3675 cls
.hInstance
= GetModuleHandleA(0);
3677 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3678 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3679 cls
.lpszMenuName
= NULL
;
3680 cls
.lpszClassName
= "ParentDcWindowClass";
3682 if(!RegisterClassA(&cls
)) {
3683 trace("Register failed %d\n", GetLastError());
3687 SetRect(&rc
, 0, 0, 150, 150);
3688 AdjustWindowRectEx(&rc
, WS_OVERLAPPEDWINDOW
, FALSE
, 0);
3689 hwndMain
= CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3690 CW_USEDEFAULT
, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, NULL
, NULL
, 0, NULL
);
3691 SetWindowLongPtrA(hwndMain
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.main
);
3692 hwnd1
= CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD
,
3693 20, 20, 40, 40, hwndMain
, NULL
, 0, NULL
);
3694 SetWindowLongPtrA(hwnd1
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child1
);
3695 hwnd2
= CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD
,
3696 40, 40, 40, 40, hwndMain
, NULL
, 0, NULL
);
3697 SetWindowLongPtrA(hwnd2
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child2
);
3698 ShowWindow(hwndMain
, SW_SHOW
);
3699 ShowWindow(hwnd1
, SW_SHOW
);
3700 ShowWindow(hwnd2
, SW_SHOW
);
3701 flush_events( TRUE
);
3703 zero_parentdc_test(&test_answer
);
3704 InvalidateRect(hwndMain
, NULL
, TRUE
);
3705 flush_events( TRUE
);
3706 parentdc_ok(test1
, test_answer
);
3708 zero_parentdc_test(&test_answer
);
3709 SetRect(&rc
, 0, 0, 50, 50);
3710 InvalidateRect(hwndMain
, &rc
, TRUE
);
3711 flush_events( TRUE
);
3712 parentdc_ok(test2
, test_answer
);
3714 zero_parentdc_test(&test_answer
);
3715 SetRect(&rc
, 0, 0, 10, 10);
3716 InvalidateRect(hwndMain
, &rc
, TRUE
);
3717 flush_events( TRUE
);
3718 parentdc_ok(test3
, test_answer
);
3720 zero_parentdc_test(&test_answer
);
3721 SetRect(&rc
, 40, 40, 50, 50);
3722 InvalidateRect(hwndMain
, &rc
, TRUE
);
3723 flush_events( TRUE
);
3724 parentdc_ok(test4
, test_answer
);
3726 zero_parentdc_test(&test_answer
);
3727 SetRect(&rc
, 20, 20, 60, 60);
3728 InvalidateRect(hwndMain
, &rc
, TRUE
);
3729 flush_events( TRUE
);
3730 parentdc_ok(test5
, test_answer
);
3732 zero_parentdc_test(&test_answer
);
3733 SetRect(&rc
, 0, 0, 10, 10);
3734 InvalidateRect(hwnd1
, &rc
, TRUE
);
3735 flush_events( TRUE
);
3736 parentdc_ok(test6
, test_answer
);
3738 zero_parentdc_test(&test_answer
);
3739 SetRect(&rc
, -5, -5, 65, 65);
3740 InvalidateRect(hwnd1
, &rc
, TRUE
);
3741 flush_events( TRUE
);
3742 parentdc_ok(test7
, test_answer
);
3744 DestroyWindow(hwndMain
);
3745 DestroyWindow(hwnd1
);
3746 DestroyWindow(hwnd2
);
3749 static LRESULT WINAPI
def_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3751 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
3754 static LRESULT WINAPI
def_window_procW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3756 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
3759 static void test_IsWindowUnicode(void)
3761 static const char ansi_class_nameA
[] = "ansi class name";
3762 static const WCHAR ansi_class_nameW
[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3763 static const char unicode_class_nameA
[] = "unicode class name";
3764 static const WCHAR unicode_class_nameW
[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3769 memset(&classW
, 0, sizeof(classW
));
3770 classW
.hInstance
= GetModuleHandleA(0);
3771 classW
.lpfnWndProc
= def_window_procW
;
3772 classW
.lpszClassName
= unicode_class_nameW
;
3773 if (!RegisterClassW(&classW
)) return; /* this catches Win9x as well */
3775 memset(&classA
, 0, sizeof(classA
));
3776 classA
.hInstance
= GetModuleHandleA(0);
3777 classA
.lpfnWndProc
= def_window_procA
;
3778 classA
.lpszClassName
= ansi_class_nameA
;
3779 assert(RegisterClassA(&classA
));
3781 /* unicode class: window proc */
3782 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
3783 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3786 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3787 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3788 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3789 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3790 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3792 DestroyWindow(hwnd
);
3794 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
3795 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3798 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3799 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3800 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3801 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3802 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3804 DestroyWindow(hwnd
);
3806 /* ansi class: window proc */
3807 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
3808 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3811 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3812 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3813 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3814 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3815 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3817 DestroyWindow(hwnd
);
3819 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
3820 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3823 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3824 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3825 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3826 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3827 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3829 DestroyWindow(hwnd
);
3831 /* unicode class: class proc */
3832 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
3833 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3836 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3837 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3838 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3839 /* do not restore class window proc back to unicode */
3841 DestroyWindow(hwnd
);
3843 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
3844 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3847 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3848 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3849 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3851 DestroyWindow(hwnd
);
3853 /* ansi class: class proc */
3854 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
3855 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3858 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3859 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3860 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3861 /* do not restore class window proc back to ansi */
3863 DestroyWindow(hwnd
);
3865 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
3866 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3869 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3870 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3871 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3873 DestroyWindow(hwnd
);
3876 static LRESULT CALLBACK
minmax_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
3880 if (msg
!= WM_GETMINMAXINFO
)
3881 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3883 minmax
= (MINMAXINFO
*)lp
;
3885 if ((GetWindowLong(hwnd
, GWL_STYLE
) & WS_CHILD
))
3887 minmax
->ptReserved
.x
= 0;
3888 minmax
->ptReserved
.y
= 0;
3889 minmax
->ptMaxSize
.x
= 400;
3890 minmax
->ptMaxSize
.y
= 400;
3891 minmax
->ptMaxPosition
.x
= 300;
3892 minmax
->ptMaxPosition
.y
= 300;
3893 minmax
->ptMaxTrackSize
.x
= 200;
3894 minmax
->ptMaxTrackSize
.y
= 200;
3895 minmax
->ptMinTrackSize
.x
= 100;
3896 minmax
->ptMinTrackSize
.y
= 100;
3899 DefWindowProc(hwnd
, msg
, wp
, lp
);
3903 static int expected_cx
, expected_cy
;
3904 static RECT expected_rect
;
3906 static LRESULT CALLBACK
winsizes_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
3910 case WM_GETMINMAXINFO
:
3913 GetWindowRect( hwnd
, &rect
);
3914 ok( !rect
.left
&& !rect
.top
&& !rect
.right
&& !rect
.bottom
,
3915 "wrong rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3916 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3921 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
3923 GetWindowRect( hwnd
, &rect
);
3924 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
3925 hwnd
, msg
, cs
->cx
, cs
->cy
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3926 ok( cs
->cx
== expected_cx
, "wrong x size %d/%d\n", cs
->cx
, expected_cx
);
3927 ok( cs
->cy
== expected_cy
, "wrong y size %d/%d\n", cs
->cy
, expected_cy
);
3928 ok( rect
.right
- rect
.left
== expected_rect
.right
- expected_rect
.left
&&
3929 rect
.bottom
- rect
.top
== expected_rect
.bottom
- expected_rect
.top
,
3930 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
3931 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
3932 expected_rect
.left
, expected_rect
.top
, expected_rect
.right
, expected_rect
.bottom
);
3933 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3937 RECT rect
, *r
= (RECT
*)lp
;
3938 GetWindowRect( hwnd
, &rect
);
3939 ok( !memcmp( &rect
, r
, sizeof(rect
) ),
3940 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
3941 r
->left
, r
->top
, r
->right
, r
->bottom
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3942 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3945 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3949 static void test_CreateWindow(void)
3957 #define expect_menu(window, menu) \
3958 SetLastError(0xdeadbeef); \
3959 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
3961 #define expect_style(window, style)\
3962 ok(GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
3964 #define expect_ex_style(window, ex_style)\
3965 ok(GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
3967 hmenu
= CreateMenu();
3969 parent
= GetDesktopWindow();
3970 assert(parent
!= 0);
3972 SetLastError(0xdeadbeef);
3973 ok(IsMenu(hmenu
), "IsMenu error %d\n", GetLastError());
3976 SetLastError(0xdeadbeef);
3977 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
,
3978 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3979 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3980 expect_menu(hwnd
, 1);
3981 expect_style(hwnd
, WS_CHILD
);
3982 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
3983 DestroyWindow(hwnd
);
3985 SetLastError(0xdeadbeef);
3986 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_CAPTION
,
3987 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3988 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3989 expect_menu(hwnd
, 1);
3990 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
3991 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
3992 DestroyWindow(hwnd
);
3994 SetLastError(0xdeadbeef);
3995 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
,
3996 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3997 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3998 expect_menu(hwnd
, 1);
3999 expect_style(hwnd
, WS_CHILD
);
4000 expect_ex_style(hwnd
, 0);
4001 DestroyWindow(hwnd
);
4003 SetLastError(0xdeadbeef);
4004 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_CAPTION
,
4005 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4006 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4007 expect_menu(hwnd
, 1);
4008 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
4009 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4010 DestroyWindow(hwnd
);
4013 SetLastError(0xdeadbeef);
4014 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
4015 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4016 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4017 expect_menu(hwnd
, hmenu
);
4018 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4019 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4020 DestroyWindow(hwnd
);
4021 SetLastError(0xdeadbeef);
4022 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4023 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4025 hmenu
= CreateMenu();
4027 SetLastError(0xdeadbeef);
4028 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4029 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4030 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4031 expect_menu(hwnd
, hmenu
);
4032 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4033 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4034 DestroyWindow(hwnd
);
4035 SetLastError(0xdeadbeef);
4036 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4037 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4039 hmenu
= CreateMenu();
4041 SetLastError(0xdeadbeef);
4042 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
,
4043 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4044 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4045 expect_menu(hwnd
, hmenu
);
4046 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4047 expect_ex_style(hwnd
, 0);
4048 DestroyWindow(hwnd
);
4049 SetLastError(0xdeadbeef);
4050 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4051 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4053 hmenu
= CreateMenu();
4055 SetLastError(0xdeadbeef);
4056 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4057 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4058 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4059 expect_menu(hwnd
, hmenu
);
4060 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4061 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4062 DestroyWindow(hwnd
);
4063 SetLastError(0xdeadbeef);
4064 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4065 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4067 /* WS_CHILD | WS_POPUP */
4068 SetLastError(0xdeadbeef);
4069 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4070 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4071 ok(!hwnd
, "CreateWindowEx should fail\n");
4072 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4074 hmenu
= CreateMenu();
4076 SetLastError(0xdeadbeef);
4077 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4078 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4079 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4080 expect_menu(hwnd
, hmenu
);
4081 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4082 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4083 DestroyWindow(hwnd
);
4084 SetLastError(0xdeadbeef);
4085 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4086 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4088 SetLastError(0xdeadbeef);
4089 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4090 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4091 ok(!hwnd
, "CreateWindowEx should fail\n");
4092 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4094 hmenu
= CreateMenu();
4096 SetLastError(0xdeadbeef);
4097 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4098 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4099 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4100 expect_menu(hwnd
, hmenu
);
4101 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4102 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4103 DestroyWindow(hwnd
);
4104 SetLastError(0xdeadbeef);
4105 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4106 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4108 SetLastError(0xdeadbeef);
4109 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4110 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4111 ok(!hwnd
, "CreateWindowEx should fail\n");
4112 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4114 hmenu
= CreateMenu();
4116 SetLastError(0xdeadbeef);
4117 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4118 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4119 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4120 expect_menu(hwnd
, hmenu
);
4121 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4122 expect_ex_style(hwnd
, 0);
4123 DestroyWindow(hwnd
);
4124 SetLastError(0xdeadbeef);
4125 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4126 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4128 SetLastError(0xdeadbeef);
4129 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4130 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4131 ok(!hwnd
, "CreateWindowEx should fail\n");
4132 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4134 hmenu
= CreateMenu();
4136 SetLastError(0xdeadbeef);
4137 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4138 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4139 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4140 expect_menu(hwnd
, hmenu
);
4141 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4142 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4143 DestroyWindow(hwnd
);
4144 SetLastError(0xdeadbeef);
4145 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4146 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4148 /* test child window sizing */
4150 cls
.lpfnWndProc
= minmax_wnd_proc
;
4153 cls
.hInstance
= GetModuleHandle(0);
4155 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
4156 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4157 cls
.lpszMenuName
= NULL
;
4158 cls
.lpszClassName
= "MinMax_WndClass";
4159 RegisterClass(&cls
);
4161 SetLastError(0xdeadbeef);
4162 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4163 0, 0, 100, 100, 0, 0, 0, NULL
);
4164 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
4165 expect_menu(parent
, 0);
4166 expect_style(parent
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
| WS_CLIPSIBLINGS
);
4167 expect_ex_style(parent
, WS_EX_WINDOWEDGE
);
4169 memset(&minmax
, 0, sizeof(minmax
));
4170 SendMessage(parent
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4171 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxSize
.x
, minmax
.ptMaxSize
.y
);
4172 ok(IsRectEmpty(&rc_minmax
), "ptMaxSize is not empty\n");
4173 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4174 ok(IsRectEmpty(&rc_minmax
), "ptMaxTrackSize is not empty\n");
4176 GetWindowRect(parent
, &rc
);
4177 ok(!IsRectEmpty(&rc
), "parent window rect is empty\n");
4178 GetClientRect(parent
, &rc
);
4179 ok(!IsRectEmpty(&rc
), "parent client rect is empty\n");
4181 InflateRect(&rc
, 200, 200);
4182 trace("creating child with rect (%d,%d-%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4184 SetLastError(0xdeadbeef);
4185 hwnd
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4186 rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
4187 parent
, (HMENU
)1, 0, NULL
);
4188 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4189 expect_menu(hwnd
, 1);
4190 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
);
4191 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4193 memset(&minmax
, 0, sizeof(minmax
));
4194 SendMessage(hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4195 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4197 GetWindowRect(hwnd
, &rc
);
4198 OffsetRect(&rc
, -rc
.left
, -rc
.top
);
4199 ok(EqualRect(&rc
, &rc_minmax
), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4200 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
4201 rc_minmax
.left
, rc_minmax
.top
, rc_minmax
.right
, rc_minmax
.bottom
);
4202 DestroyWindow(hwnd
);
4204 cls
.lpfnWndProc
= winsizes_wnd_proc
;
4205 cls
.lpszClassName
= "Sizes_WndClass";
4206 RegisterClass(&cls
);
4208 expected_cx
= expected_cy
= 200000;
4209 SetRect( &expected_rect
, 0, 0, 200000, 200000 );
4210 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 300000, 300000, 200000, 200000, parent
, 0, 0, NULL
);
4211 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4212 GetClientRect( hwnd
, &rc
);
4213 ok( rc
.right
== 200000, "invalid rect right %u\n", rc
.right
);
4214 ok( rc
.bottom
== 200000, "invalid rect bottom %u\n", rc
.bottom
);
4215 DestroyWindow(hwnd
);
4217 expected_cx
= expected_cy
= -10;
4218 SetRect( &expected_rect
, 0, 0, 0, 0 );
4219 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -20, -20, -10, -10, parent
, 0, 0, NULL
);
4220 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4221 GetClientRect( hwnd
, &rc
);
4222 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4223 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4224 DestroyWindow(hwnd
);
4226 expected_cx
= expected_cy
= -200000;
4227 SetRect( &expected_rect
, 0, 0, 0, 0 );
4228 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -300000, -300000, -200000, -200000, parent
, 0, 0, NULL
);
4229 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4230 GetClientRect( hwnd
, &rc
);
4231 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4232 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4233 DestroyWindow(hwnd
);
4235 /* we need a parent at 0,0 so that child coordinates match */
4236 DestroyWindow(parent
);
4237 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_POPUP
, 0, 0, 100, 100, 0, 0, 0, NULL
);
4238 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
4241 expected_cy
= 0x7fffffff;
4242 SetRect( &expected_rect
, 10, 10, 110, 0x7fffffff );
4243 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 10, 10, 100, 0x7fffffff, parent
, 0, 0, NULL
);
4244 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4245 GetClientRect( hwnd
, &rc
);
4246 ok( rc
.right
== 100, "invalid rect right %u\n", rc
.right
);
4247 ok( rc
.bottom
== 0x7fffffff - 10, "invalid rect bottom %u\n", rc
.bottom
);
4248 DestroyWindow(hwnd
);
4250 expected_cx
= 0x7fffffff;
4251 expected_cy
= 0x7fffffff;
4252 SetRect( &expected_rect
, 20, 10, 0x7fffffff, 0x7fffffff );
4253 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 20, 10, 0x7fffffff, 0x7fffffff, parent
, 0, 0, NULL
);
4254 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4255 GetClientRect( hwnd
, &rc
);
4256 ok( rc
.right
== 0x7fffffff - 20, "invalid rect right %u\n", rc
.right
);
4257 ok( rc
.bottom
== 0x7fffffff - 10, "invalid rect bottom %u\n", rc
.bottom
);
4258 DestroyWindow(hwnd
);
4260 /* top level window */
4261 expected_cx
= expected_cy
= 200000;
4262 SetRect( &expected_rect
, 0, 0, GetSystemMetrics(SM_CXMAXTRACK
), GetSystemMetrics(SM_CYMAXTRACK
) );
4263 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_OVERLAPPEDWINDOW
, 300000, 300000, 200000, 200000, 0, 0, 0, NULL
);
4264 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4265 GetClientRect( hwnd
, &rc
);
4266 ok( rc
.right
<= expected_cx
, "invalid rect right %u\n", rc
.right
);
4267 ok( rc
.bottom
<= expected_cy
, "invalid rect bottom %u\n", rc
.bottom
);
4268 DestroyWindow(hwnd
);
4270 DestroyWindow(parent
);
4272 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4273 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4277 #undef expect_ex_style
4280 /* function that remembers whether the system the test is running on sets the
4281 * last error for user32 functions to make the tests stricter */
4282 static int check_error(DWORD actual
, DWORD expected
)
4284 static int sets_last_error
= -1;
4285 if (sets_last_error
== -1)
4286 sets_last_error
= (actual
!= 0xdeadbeef);
4287 return (!sets_last_error
&& (actual
== 0xdeadbeef)) || (actual
== expected
);
4290 static void test_SetWindowLong(void)
4293 WNDPROC old_window_procW
;
4295 SetLastError(0xdeadbeef);
4296 retval
= SetWindowLongPtr(NULL
, GWLP_WNDPROC
, 0);
4297 ok(!retval
, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval
);
4298 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE
),
4299 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4301 SetLastError(0xdeadbeef);
4302 retval
= SetWindowLongPtr(hwndMain
, 0xdeadbeef, 0);
4303 ok(!retval
, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval
);
4304 ok(check_error(GetLastError(), ERROR_INVALID_INDEX
),
4305 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4307 SetLastError(0xdeadbeef);
4308 retval
= SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4309 ok((WNDPROC
)retval
== main_window_procA
,
4310 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval
);
4311 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4312 retval
= GetWindowLongPtr(hwndMain
, GWLP_WNDPROC
);
4313 ok((WNDPROC
)retval
== main_window_procA
,
4314 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4315 ok(!IsWindowUnicode(hwndMain
), "hwndMain shouldn't be Unicode\n");
4317 old_window_procW
= (WNDPROC
)GetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
);
4318 SetLastError(0xdeadbeef);
4319 retval
= SetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
, 0);
4320 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED
)
4322 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4323 ok(retval
!= 0, "SetWindowLongPtr error %d\n", GetLastError());
4324 ok((WNDPROC
)retval
== old_window_procW
,
4325 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4326 ok(IsWindowUnicode(hwndMain
), "hwndMain should now be Unicode\n");
4328 /* set it back to ANSI */
4329 SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4333 static void test_ShowWindow(void)
4340 SetRect(&rcMain
, 120, 120, 210, 210);
4342 hwnd
= CreateWindowEx(0, "MainWindowClass", NULL
,
4343 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4344 WS_MAXIMIZEBOX
| WS_POPUP
,
4345 rcMain
.left
, rcMain
.top
,
4346 rcMain
.right
- rcMain
.left
, rcMain
.bottom
- rcMain
.top
,
4350 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4351 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4352 ok(!(style
& WS_VISIBLE
), "window should not be visible\n");
4353 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4354 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4355 GetWindowRect(hwnd
, &rc
);
4356 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4358 ret
= ShowWindow(hwnd
, SW_SHOW
);
4359 ok(!ret
, "not expected ret: %lu\n", ret
);
4360 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4361 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4362 ok(style
& WS_VISIBLE
, "window should be visible\n");
4363 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4364 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4365 GetWindowRect(hwnd
, &rc
);
4366 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4368 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4369 ok(ret
, "not expected ret: %lu\n", ret
);
4370 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4371 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4372 ok(style
& WS_VISIBLE
, "window should be visible\n");
4373 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4374 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4375 GetWindowRect(hwnd
, &rc
);
4376 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4378 ShowWindow(hwnd
, SW_RESTORE
);
4379 ok(ret
, "not expected ret: %lu\n", ret
);
4380 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4381 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4382 ok(style
& WS_VISIBLE
, "window should be visible\n");
4383 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4384 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4385 GetWindowRect(hwnd
, &rc
);
4386 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4388 ret
= EnableWindow(hwnd
, FALSE
);
4389 ok(!ret
, "not expected ret: %lu\n", ret
);
4390 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4391 ok(style
& WS_DISABLED
, "window should be disabled\n");
4393 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
4394 ok(!ret
, "not expected ret: %lu\n", ret
);
4395 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4396 ok(style
& WS_DISABLED
, "window should be disabled\n");
4397 ok(style
& WS_VISIBLE
, "window should be visible\n");
4398 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4399 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4400 GetWindowRect(hwnd
, &rc
);
4401 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4403 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
4404 ok(!ret
, "not expected ret: %lu\n", ret
);
4405 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4406 ok(style
& WS_DISABLED
, "window should be disabled\n");
4407 ok(style
& WS_VISIBLE
, "window should be visible\n");
4408 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4409 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4410 GetWindowRect(hwnd
, &rc
);
4411 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4413 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4414 ok(ret
, "not expected ret: %lu\n", ret
);
4415 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4416 ok(style
& WS_DISABLED
, "window should be disabled\n");
4417 ok(style
& WS_VISIBLE
, "window should be visible\n");
4418 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4419 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4420 GetWindowRect(hwnd
, &rc
);
4421 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4423 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
4424 ok(!ret
, "not expected ret: %lu\n", ret
);
4425 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4426 ok(style
& WS_DISABLED
, "window should be disabled\n");
4427 ok(style
& WS_VISIBLE
, "window should be visible\n");
4428 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4429 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4430 GetWindowRect(hwnd
, &rc
);
4431 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4433 ret
= ShowWindow(hwnd
, SW_RESTORE
);
4434 ok(ret
, "not expected ret: %lu\n", ret
);
4435 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4436 ok(style
& WS_DISABLED
, "window should be disabled\n");
4437 ok(style
& WS_VISIBLE
, "window should be visible\n");
4438 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4439 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4440 GetWindowRect(hwnd
, &rc
);
4441 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4443 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4444 ok(!ret
, "not expected ret: %lu\n", ret
);
4445 ok(IsWindow(hwnd
), "window should exist\n");
4447 ret
= EnableWindow(hwnd
, TRUE
);
4448 ok(ret
, "not expected ret: %lu\n", ret
);
4450 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4451 ok(!ret
, "not expected ret: %lu\n", ret
);
4452 ok(!IsWindow(hwnd
), "window should not exist\n");
4455 static void test_gettext(void)
4458 LPCSTR clsname
= "gettexttest";
4462 memset( &cls
, 0, sizeof cls
);
4463 cls
.lpfnWndProc
= DefWindowProc
;
4464 cls
.lpszClassName
= clsname
;
4465 cls
.hInstance
= GetModuleHandle(NULL
);
4467 if (!RegisterClass( &cls
)) return;
4469 hwnd
= CreateWindow( clsname
, "test text", WS_OVERLAPPED
, 0, 0, 10, 10, 0, NULL
, NULL
, NULL
);
4470 ok( hwnd
!= NULL
, "window was null\n");
4472 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10, 0x1000);
4473 ok( r
== 0, "settext should return zero\n");
4475 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10000, 0);
4476 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4478 r
= SendMessage( hwnd
, WM_GETTEXT
, 0xff000000, 0x1000);
4479 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4481 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x1000, 0xff000000);
4482 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4484 DestroyWindow(hwnd
);
4485 UnregisterClass( clsname
, NULL
);
4489 static void test_GetUpdateRect(void)
4492 BOOL ret
, parent_wm_paint
, grandparent_wm_paint
;
4494 HWND hgrandparent
, hparent
, hchild
;
4496 static const char classNameA
[] = "GetUpdateRectClass";
4498 hgrandparent
= CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW
,
4499 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4501 hparent
= CreateWindowA("static", "parent", WS_CHILD
|WS_VISIBLE
,
4502 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4504 hchild
= CreateWindowA("static", "child", WS_CHILD
|WS_VISIBLE
,
4505 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4507 ShowWindow(hgrandparent
, SW_SHOW
);
4508 UpdateWindow(hgrandparent
);
4509 flush_events( TRUE
);
4511 ShowWindow(hchild
, SW_HIDE
);
4512 SetRect(&rc2
, 0, 0, 0, 0);
4513 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4514 ok(!ret
, "GetUpdateRect returned not empty region\n");
4515 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4516 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4517 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4519 SetRect(&rc2
, 10, 10, 40, 40);
4520 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
4521 ok(ret
, "GetUpdateRect returned empty region\n");
4522 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4523 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4524 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4526 parent_wm_paint
= FALSE
;
4527 grandparent_wm_paint
= FALSE
;
4528 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
4530 if (msg
.message
== WM_PAINT
)
4532 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
4533 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
4535 DispatchMessage(&msg
);
4537 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
4538 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
4540 DestroyWindow(hgrandparent
);
4543 cls
.lpfnWndProc
= DefWindowProcA
;
4546 cls
.hInstance
= GetModuleHandleA(0);
4548 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
4549 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4550 cls
.lpszMenuName
= NULL
;
4551 cls
.lpszClassName
= classNameA
;
4553 if(!RegisterClassA(&cls
)) {
4554 trace("Register failed %d\n", GetLastError());
4558 hgrandparent
= CreateWindowA(classNameA
, "grandparent", WS_OVERLAPPEDWINDOW
,
4559 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4561 hparent
= CreateWindowA(classNameA
, "parent", WS_CHILD
|WS_VISIBLE
,
4562 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4564 hchild
= CreateWindowA(classNameA
, "child", WS_CHILD
|WS_VISIBLE
,
4565 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4567 ShowWindow(hgrandparent
, SW_SHOW
);
4568 UpdateWindow(hgrandparent
);
4569 flush_events( TRUE
);
4571 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4572 ok(!ret
, "GetUpdateRect returned not empty region\n");
4574 ShowWindow(hchild
, SW_HIDE
);
4576 SetRect(&rc2
, 0, 0, 0, 0);
4577 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4578 ok(!ret
, "GetUpdateRect returned not empty region\n");
4579 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4580 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4581 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4583 SetRect(&rc2
, 10, 10, 40, 40);
4584 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
4585 ok(ret
, "GetUpdateRect returned empty region\n");
4586 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4587 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4588 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4590 parent_wm_paint
= FALSE
;
4591 grandparent_wm_paint
= FALSE
;
4592 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
4594 if (msg
.message
== WM_PAINT
)
4596 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
4597 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
4599 DispatchMessage(&msg
);
4601 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
4602 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
4604 DestroyWindow(hgrandparent
);
4608 static LRESULT CALLBACK
TestExposedRegion_WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4616 const int waitTime
= 2000;
4618 BeginPaint(hwnd
, &ps
);
4620 /* create and destroy window to create an exposed region on this window */
4621 win
= CreateWindowA("static", "win", WS_VISIBLE
,
4622 10,10,50,50, NULL
, NULL
, 0, NULL
);
4625 waitResult
= MsgWaitForMultipleObjects( 0, NULL
, FALSE
, waitTime
, QS_PAINT
);
4627 ValidateRect(hwnd
, NULL
);
4628 EndPaint(hwnd
, &ps
);
4630 if(waitResult
!= WAIT_TIMEOUT
)
4632 GetUpdateRect(hwnd
, &updateRect
, FALSE
);
4635 ok(!IsRectEmpty(&updateRect
), "Exposed rect should not be empty\n");
4641 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
4644 static void test_Expose(void)
4649 memset(&cls
, 0, sizeof(WNDCLASSA
));
4650 cls
.lpfnWndProc
= TestExposedRegion_WndProc
;
4651 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4652 cls
.lpszClassName
= "TestExposeClass";
4653 atom
= RegisterClassA(&cls
);
4655 mw
= CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE
|WS_OVERLAPPEDWINDOW
,
4656 0, 0, 200, 100, NULL
, NULL
, 0, NULL
);
4662 static void test_GetWindowModuleFileName(void)
4667 char buf1
[MAX_PATH
], buf2
[MAX_PATH
];
4669 if (!pGetWindowModuleFileNameA
)
4671 skip("GetWindowModuleFileNameA is not available\n");
4675 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0,0,0,0, 0, 0, 0, NULL
);
4678 hinst
= (HINSTANCE
)GetWindowLongPtr(hwnd
, GWLP_HINSTANCE
);
4679 ok(hinst
== 0, "expected 0, got %p\n", hinst
);
4682 SetLastError(0xdeadbeef);
4683 ret1
= GetModuleFileName(hinst
, buf1
, sizeof(buf1
));
4684 ok(ret1
, "GetModuleFileName error %u\n", GetLastError());
4687 SetLastError(0xdeadbeef);
4688 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, sizeof(buf2
));
4689 ok(ret2
, "GetWindowModuleFileNameA error %u\n", GetLastError());
4691 ok(ret1
== ret2
, "%u != %u\n", ret1
, ret2
);
4692 ok(!strcmp(buf1
, buf2
), "%s != %s\n", buf1
, buf2
);
4694 hinst
= GetModuleHandle(0);
4696 SetLastError(0xdeadbeef);
4697 ret2
= GetModuleFileName(hinst
, buf2
, ret1
- 2);
4698 ok(ret2
== ret1
- 2, "expected %u, got %u\n", ret1
- 2, ret2
);
4699 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4700 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
4701 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4703 SetLastError(0xdeadbeef);
4704 ret2
= GetModuleFileName(hinst
, buf2
, 0);
4705 ok(!ret2
, "GetModuleFileName should return 0\n");
4706 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4707 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
4708 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4710 SetLastError(0xdeadbeef);
4711 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, ret1
- 2);
4712 ok(ret2
== ret1
- 2, "expected %u, got %u\n", ret1
- 2, ret2
);
4713 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4714 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
4715 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4717 SetLastError(0xdeadbeef);
4718 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, 0);
4719 ok(!ret2
, "expected 0, got %u\n", ret2
);
4720 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4721 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
4722 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4724 DestroyWindow(hwnd
);
4727 hwnd
= (HWND
)0xdeadbeef;
4728 SetLastError(0xdeadbeef);
4729 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
4730 ok(!ret1
, "expected 0, got %u\n", ret1
);
4731 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
4733 hwnd
= GetDesktopWindow();
4734 ok(IsWindow(hwnd
), "got invalid desktop window %p\n", hwnd
);
4735 SetLastError(0xdeadbeef);
4736 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
4737 ok(!ret1
, "expected 0, got %u\n", ret1
);
4739 hwnd
= FindWindow("Shell_TrayWnd", NULL
);
4740 ok(IsWindow(hwnd
), "got invalid tray window %p\n", hwnd
);
4741 SetLastError(0xdeadbeef);
4742 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
4743 ok(!ret1
, "expected 0, got %u\n", ret1
);
4746 static void test_hwnd_message(void)
4748 HWND parent
= 0, hwnd
, found
;
4751 hwnd
= CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION
| WS_VISIBLE
,
4752 100, 100, 200, 200, HWND_MESSAGE
, 0, 0, NULL
);
4755 win_skip("CreateWindowExA with parent HWND_MESSAGE failed\n");
4759 ok( !GetParent(hwnd
), "GetParent should return 0 for message only windows\n" );
4763 HWND root
, desktop
= GetDesktopWindow();
4765 parent
= pGetAncestor(hwnd
, GA_PARENT
);
4766 ok(parent
!= 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
4767 ok(parent
!= desktop
, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
4768 root
= pGetAncestor(hwnd
, GA_ROOT
);
4769 ok(root
== hwnd
, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
4770 ok( !pGetAncestor(parent
, GA_PARENT
), "parent shouldn't have a parent\n" );
4771 trace("parent %p root %p desktop %p\n", parent
, root
, desktop
);
4772 if (!GetClassNameA( parent
, buffer
, sizeof(buffer
) )) buffer
[0] = 0;
4773 ok( !lstrcmpi( buffer
, "Message" ), "wrong parent class '%s'\n", buffer
);
4774 GetWindowRect( parent
, &rect
);
4775 ok( rect
.left
== 0 && rect
.right
== 100 && rect
.top
== 0 && rect
.bottom
== 100,
4776 "wrong parent rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4778 GetWindowRect( hwnd
, &rect
);
4779 ok( rect
.left
== 100 && rect
.right
== 300 && rect
.top
== 100 && rect
.bottom
== 300,
4780 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4782 /* test FindWindow behavior */
4784 found
= FindWindowExA( 0, 0, 0, "message window" );
4785 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
4786 found
= FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
4787 ok( found
== 0, "found message window %p/%p\n", found
, hwnd
);
4790 found
= FindWindowExA( parent
, 0, 0, "message window" );
4791 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
4794 /* test IsChild behavior */
4796 if (parent
) ok( !IsChild( parent
, hwnd
), "HWND_MESSAGE is child of top window\n" );
4798 /* test IsWindowVisible behavior */
4800 ok( !IsWindowVisible( hwnd
), "HWND_MESSAGE window is visible\n" );
4801 if (parent
) ok( !IsWindowVisible( parent
), "HWND_MESSAGE parent is visible\n" );
4803 DestroyWindow(hwnd
);
4808 pGetAncestor
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
4809 pGetWindowInfo
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
4810 pGetWindowModuleFileNameA
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowModuleFileNameA" );
4812 if (!RegisterWindowClasses()) assert(0);
4814 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
4817 hwndMain
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
4818 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4819 WS_MAXIMIZEBOX
| WS_POPUP
,
4821 0, 0, GetModuleHandle(0), NULL
);
4822 hwndMain2
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
4823 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4824 WS_MAXIMIZEBOX
| WS_POPUP
,
4826 0, 0, GetModuleHandle(0), NULL
);
4828 assert( hwndMain2
);
4830 our_pid
= GetWindowThreadProcessId(hwndMain
, NULL
);
4832 /* Add the tests below this line */
4833 test_hwnd_message();
4834 test_nonclient_area(hwndMain
);
4836 test_GetWindowModuleFileName();
4839 test_capture_3(hwndMain
, hwndMain2
);
4841 test_CreateWindow();
4842 test_parent_owner();
4844 test_shell_window();
4848 test_SetWindowPos(hwndMain
);
4849 test_SetMenu(hwndMain
);
4850 test_SetFocus(hwndMain
);
4851 test_SetActiveWindow(hwndMain
);
4852 test_SetForegroundWindow(hwndMain
);
4854 test_children_zorder(hwndMain
);
4855 test_popup_zorder(hwndMain2
, hwndMain
);
4856 test_keyboard_input(hwndMain
);
4857 test_mouse_input(hwndMain
);
4858 test_validatergn(hwndMain
);
4859 test_nccalcscroll( hwndMain
);
4860 test_scrollvalidate( hwndMain
);
4861 test_scrolldc( hwndMain
);
4863 test_IsWindowUnicode();
4864 test_vis_rgn(hwndMain
);
4866 test_AdjustWindowRect();
4867 test_window_styles();
4870 test_SetWindowLong();
4873 test_GetUpdateRect();
4876 /* add the tests above this line */
4877 UnhookWindowsHookEx(hhook
);