2 * Unit tests for window handling
4 * Copyright 2002 Bill Medland
5 * Copyright 2002 Alexandre Julliard
6 * Copyright 2003 Dmitry Timoshkov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 /* To get ICON_SMALL2 with the MSVC headers */
24 #define _WIN32_WINNT 0x0501
36 #include "wine/test.h"
38 #ifndef SPI_GETDESKWALLPAPER
39 #define SPI_GETDESKWALLPAPER 0x0073
42 #define LONG_PTR INT_PTR
43 #define ULONG_PTR UINT_PTR
45 void dump_region(HRGN hrgn
);
47 static HWND (WINAPI
*pGetAncestor
)(HWND
,UINT
);
48 static BOOL (WINAPI
*pGetWindowInfo
)(HWND
,WINDOWINFO
*);
49 static UINT (WINAPI
*pGetWindowModuleFileNameA
)(HWND
,LPSTR
,UINT
);
50 static BOOL (WINAPI
*pGetLayeredWindowAttributes
)(HWND
,COLORREF
*,BYTE
*,DWORD
*);
51 static BOOL (WINAPI
*pSetLayeredWindowAttributes
)(HWND
,COLORREF
,BYTE
,DWORD
);
52 static BOOL (WINAPI
*pGetMonitorInfoA
)(HMONITOR
,LPMONITORINFO
);
53 static HMONITOR (WINAPI
*pMonitorFromPoint
)(POINT
,DWORD
);
54 static int (WINAPI
*pGetWindowRgnBox
)(HWND
,LPRECT
);
56 static BOOL test_lbuttondown_flag
;
57 static HWND hwndMessage
;
58 static HWND hwndMain
, hwndMain2
;
61 static const char* szAWRClass
= "Winsize";
65 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
67 static void dump_minmax_info( const MINMAXINFO
*minmax
)
69 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
70 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
71 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
72 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
73 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
74 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
77 /* try to make sure pending X events have been processed before continuing */
78 static void flush_events( BOOL remove_messages
)
82 int min_timeout
= 100;
83 DWORD time
= GetTickCount() + diff
;
87 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
89 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
90 diff
= time
- GetTickCount();
95 /* check the values returned by the various parent/owner functions on a given window */
96 static void check_parents( HWND hwnd
, HWND ga_parent
, HWND gwl_parent
, HWND get_parent
,
97 HWND gw_owner
, HWND ga_root
, HWND ga_root_owner
)
103 res
= pGetAncestor( hwnd
, GA_PARENT
);
104 ok( res
== ga_parent
, "Wrong result for GA_PARENT %p expected %p\n", res
, ga_parent
);
106 res
= (HWND
)GetWindowLongPtrA( hwnd
, GWLP_HWNDPARENT
);
107 ok( res
== gwl_parent
, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res
, gwl_parent
);
108 res
= GetParent( hwnd
);
109 ok( res
== get_parent
, "Wrong result for GetParent %p expected %p\n", res
, get_parent
);
110 res
= GetWindow( hwnd
, GW_OWNER
);
111 ok( res
== gw_owner
, "Wrong result for GW_OWNER %p expected %p\n", res
, gw_owner
);
114 res
= pGetAncestor( hwnd
, GA_ROOT
);
115 ok( res
== ga_root
, "Wrong result for GA_ROOT %p expected %p\n", res
, ga_root
);
116 res
= pGetAncestor( hwnd
, GA_ROOTOWNER
);
117 ok( res
== ga_root_owner
, "Wrong result for GA_ROOTOWNER %p expected %p\n", res
, ga_root_owner
);
121 static BOOL CALLBACK
EnumChildProc( HWND hwndChild
, LPARAM lParam
)
124 trace("EnumChildProc on %p\n", hwndChild
);
125 if (*(LPINT
)lParam
> 1) return FALSE
;
129 /* will search for the given window */
130 static BOOL CALLBACK
EnumChildProc1( HWND hwndChild
, LPARAM lParam
)
132 trace("EnumChildProc1 on %p\n", hwndChild
);
133 if ((HWND
)lParam
== hwndChild
) return FALSE
;
137 static HWND
create_tool_window( LONG style
, HWND parent
)
139 HWND ret
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style
,
140 0, 0, 100, 100, parent
, 0, 0, NULL
);
141 ok( ret
!= 0, "Creation failed\n" );
145 /* test parent and owner values for various combinations */
146 static void test_parent_owner(void)
149 HWND test
, owner
, ret
;
150 HWND desktop
= GetDesktopWindow();
151 HWND child
= create_tool_window( WS_CHILD
, hwndMain
);
154 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain
, hwndMain2
, desktop
, child
);
156 /* child without parent, should fail */
157 SetLastError(0xdeadbeef);
158 test
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
159 WS_CHILD
, 0, 0, 100, 100, 0, 0, 0, NULL
);
160 ok( !test
, "WS_CHILD without parent created\n" );
161 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD
||
162 broken(GetLastError() == 0xdeadbeef), /* win9x */
163 "CreateWindowExA error %u\n", GetLastError() );
166 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
167 style
= GetWindowLongA( desktop
, GWL_STYLE
);
168 ok( !SetWindowLongA( desktop
, GWL_STYLE
, WS_POPUP
), "Set GWL_STYLE on desktop succeeded\n" );
169 ok( !SetWindowLongA( desktop
, GWL_STYLE
, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
170 ok( GetWindowLongA( desktop
, GWL_STYLE
) == style
, "Desktop style changed\n" );
172 /* normal child window */
173 test
= create_tool_window( WS_CHILD
, hwndMain
);
174 trace( "created child %p\n", test
);
175 check_parents( test
, hwndMain
, hwndMain
, hwndMain
, 0, hwndMain
, hwndMain
);
176 SetWindowLongA( test
, GWL_STYLE
, 0 );
177 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
178 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
179 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
180 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
|WS_CHILD
);
181 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
182 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
183 DestroyWindow( test
);
185 /* normal child window with WS_MAXIMIZE */
186 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
187 DestroyWindow( test
);
189 /* normal child window with WS_THICKFRAME */
190 test
= create_tool_window( WS_CHILD
| WS_THICKFRAME
, hwndMain
);
191 DestroyWindow( test
);
193 /* popup window with WS_THICKFRAME */
194 test
= create_tool_window( WS_POPUP
| WS_THICKFRAME
, hwndMain
);
195 DestroyWindow( test
);
197 /* child of desktop */
198 test
= create_tool_window( WS_CHILD
, desktop
);
199 trace( "created child of desktop %p\n", test
);
200 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
201 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
202 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
203 SetWindowLongA( test
, GWL_STYLE
, 0 );
204 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
205 DestroyWindow( test
);
207 /* child of desktop with WS_MAXIMIZE */
208 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, desktop
);
209 DestroyWindow( test
);
211 /* child of desktop with WS_MINIMIZE */
212 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, desktop
);
213 DestroyWindow( test
);
216 test
= create_tool_window( WS_CHILD
, child
);
217 trace( "created child of child %p\n", test
);
218 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
219 SetWindowLongA( test
, GWL_STYLE
, 0 );
220 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
221 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
222 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
223 DestroyWindow( test
);
225 /* child of child with WS_MAXIMIZE */
226 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, child
);
227 DestroyWindow( test
);
229 /* child of child with WS_MINIMIZE */
230 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, child
);
231 DestroyWindow( test
);
233 /* not owned top-level window */
234 test
= create_tool_window( 0, 0 );
235 trace( "created top-level %p\n", test
);
236 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
237 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
238 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
239 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
240 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
241 DestroyWindow( test
);
243 /* not owned top-level window with WS_MAXIMIZE */
244 test
= create_tool_window( WS_MAXIMIZE
, 0 );
245 DestroyWindow( test
);
247 /* owned top-level window */
248 test
= create_tool_window( 0, hwndMain
);
249 trace( "created owned top-level %p\n", test
);
250 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
251 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
252 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
253 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
254 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
255 DestroyWindow( test
);
257 /* owned top-level window with WS_MAXIMIZE */
258 test
= create_tool_window( WS_MAXIMIZE
, hwndMain
);
259 DestroyWindow( test
);
261 /* not owned popup */
262 test
= create_tool_window( WS_POPUP
, 0 );
263 trace( "created popup %p\n", test
);
264 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
265 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
266 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
267 SetWindowLongA( test
, GWL_STYLE
, 0 );
268 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
269 DestroyWindow( test
);
271 /* not owned popup with WS_MAXIMIZE */
272 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, 0 );
273 DestroyWindow( test
);
276 test
= create_tool_window( WS_POPUP
, hwndMain
);
277 trace( "created owned popup %p\n", test
);
278 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
279 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
280 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
281 SetWindowLongA( test
, GWL_STYLE
, 0 );
282 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
283 DestroyWindow( test
);
285 /* owned popup with WS_MAXIMIZE */
286 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, hwndMain
);
287 DestroyWindow( test
);
289 /* top-level window owned by child (same as owned by top-level) */
290 test
= create_tool_window( 0, child
);
291 trace( "created top-level owned by child %p\n", test
);
292 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
293 DestroyWindow( test
);
295 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
296 test
= create_tool_window( WS_MAXIMIZE
, child
);
297 DestroyWindow( test
);
299 /* popup owned by desktop (same as not owned) */
300 test
= create_tool_window( WS_POPUP
, desktop
);
301 trace( "created popup owned by desktop %p\n", test
);
302 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
303 DestroyWindow( test
);
305 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
306 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, desktop
);
307 DestroyWindow( test
);
309 /* popup owned by child (same as owned by top-level) */
310 test
= create_tool_window( WS_POPUP
, child
);
311 trace( "created popup owned by child %p\n", test
);
312 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
313 DestroyWindow( test
);
315 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
316 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, child
);
317 DestroyWindow( test
);
319 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
320 test
= create_tool_window( WS_POPUP
| WS_CHILD
, 0 );
321 trace( "created WS_CHILD popup %p\n", test
);
322 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
323 DestroyWindow( test
);
325 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
326 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, 0 );
327 DestroyWindow( test
);
329 /* owned popup with WS_CHILD (same as WS_POPUP only) */
330 test
= create_tool_window( WS_POPUP
| WS_CHILD
, hwndMain
);
331 trace( "created owned WS_CHILD popup %p\n", test
);
332 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
333 DestroyWindow( test
);
335 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
336 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
337 DestroyWindow( test
);
339 /******************** parent changes *************************/
340 trace( "testing parent changes\n" );
343 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
346 /* this test succeeds on NT but crashes on win9x systems */
347 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
348 ok( !ret
, "Set GWL_HWNDPARENT succeeded on desktop\n" );
349 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
350 ok( !SetParent( desktop
, hwndMain
), "SetParent succeeded on desktop\n" );
351 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
353 /* normal child window */
354 test
= create_tool_window( WS_CHILD
, hwndMain
);
355 trace( "created child %p\n", test
);
357 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
358 ok( ret
== hwndMain
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain
);
359 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
361 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
362 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
363 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
365 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)desktop
);
366 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
367 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
369 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
370 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
371 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
372 check_parents( test
, desktop
, child
, desktop
, child
, test
, desktop
);
374 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
375 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
376 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
377 DestroyWindow( test
);
379 /* not owned top-level window */
380 test
= create_tool_window( 0, 0 );
381 trace( "created top-level %p\n", test
);
383 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
384 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
385 check_parents( test
, desktop
, hwndMain2
, 0, hwndMain2
, test
, test
);
387 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
388 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
389 check_parents( test
, desktop
, child
, 0, child
, test
, test
);
391 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
392 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
393 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
394 DestroyWindow( test
);
396 /* not owned popup */
397 test
= create_tool_window( WS_POPUP
, 0 );
398 trace( "created popup %p\n", test
);
400 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
401 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
402 check_parents( test
, desktop
, hwndMain2
, hwndMain2
, hwndMain2
, test
, hwndMain2
);
404 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
405 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
406 check_parents( test
, desktop
, child
, child
, child
, test
, hwndMain
);
408 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
409 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
410 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
411 DestroyWindow( test
);
413 /* normal child window */
414 test
= create_tool_window( WS_CHILD
, hwndMain
);
415 trace( "created child %p\n", test
);
417 ret
= SetParent( test
, desktop
);
418 ok( ret
== hwndMain
, "SetParent return value %p expected %p\n", ret
, hwndMain
);
419 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
421 ret
= SetParent( test
, child
);
422 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
423 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
425 ret
= SetParent( test
, hwndMain2
);
426 ok( ret
== child
, "SetParent return value %p expected %p\n", ret
, child
);
427 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
428 DestroyWindow( test
);
430 /* not owned top-level window */
431 test
= create_tool_window( 0, 0 );
432 trace( "created top-level %p\n", test
);
434 ret
= SetParent( test
, child
);
435 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
436 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
437 DestroyWindow( test
);
440 test
= create_tool_window( WS_POPUP
, hwndMain2
);
441 trace( "created owned popup %p\n", test
);
443 ret
= SetParent( test
, child
);
444 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
445 check_parents( test
, child
, child
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
447 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)hwndMain
);
448 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
449 check_parents( test
, hwndMain
, hwndMain
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
450 DestroyWindow( test
);
452 /**************** test owner destruction *******************/
454 /* owned child popup */
455 owner
= create_tool_window( 0, 0 );
456 test
= create_tool_window( WS_POPUP
, owner
);
457 trace( "created owner %p and popup %p\n", owner
, test
);
458 ret
= SetParent( test
, child
);
459 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
460 check_parents( test
, child
, child
, owner
, owner
, hwndMain
, owner
);
461 /* window is now child of 'child' but owned by 'owner' */
462 DestroyWindow( owner
);
463 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
464 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
465 * while Win95, Win2k, WinXP do.
467 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
468 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
471 /* owned top-level popup */
472 owner
= create_tool_window( 0, 0 );
473 test
= create_tool_window( WS_POPUP
, owner
);
474 trace( "created owner %p and popup %p\n", owner
, test
);
475 check_parents( test
, desktop
, owner
, owner
, owner
, test
, owner
);
476 DestroyWindow( owner
);
477 ok( !IsWindow(test
), "Window %p not destroyed by owner destruction\n", test
);
479 /* top-level popup owned by child */
480 owner
= create_tool_window( WS_CHILD
, hwndMain2
);
481 test
= create_tool_window( WS_POPUP
, 0 );
482 trace( "created owner %p and popup %p\n", owner
, test
);
483 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)owner
);
484 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
485 check_parents( test
, desktop
, owner
, owner
, owner
, test
, hwndMain2
);
486 DestroyWindow( owner
);
487 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
488 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
489 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
490 * while Win95, Win2k, WinXP do.
492 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
496 DestroyWindow(child
);
499 owner
= create_tool_window( WS_OVERLAPPED
, 0 );
500 test
= create_tool_window( WS_POPUP
, desktop
);
502 ok( !GetWindow( test
, GW_OWNER
), "Wrong owner window\n" );
504 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
505 "EnumChildWindows should have returned FALSE\n" );
506 ok( numChildren
== 0, "numChildren should be 0 got %d\n", numChildren
);
508 SetWindowLongA( test
, GWL_STYLE
, (GetWindowLongA( test
, GWL_STYLE
) & ~WS_POPUP
) | WS_CHILD
);
509 ret
= SetParent( test
, owner
);
510 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
513 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
514 "EnumChildWindows should have returned TRUE\n" );
515 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
517 child
= create_tool_window( WS_CHILD
, owner
);
519 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
520 "EnumChildWindows should have returned FALSE\n" );
521 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
522 DestroyWindow( child
);
524 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, owner
);
525 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
527 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
528 "EnumChildWindows should have returned TRUE\n" );
529 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
531 ret
= SetParent( child
, owner
);
532 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
533 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
535 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
536 "EnumChildWindows should have returned FALSE\n" );
537 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
539 ret
= SetParent( child
, NULL
);
540 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
541 ok( ret
== owner
, "SetParent return value %p expected %p\n", ret
, owner
);
543 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
544 "EnumChildWindows should have returned TRUE\n" );
545 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
547 /* even GW_OWNER == owner it's still a desktop's child */
548 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
549 "EnumChildWindows should have found %p and returned FALSE\n", child
);
551 DestroyWindow( child
);
552 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, NULL
);
554 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
555 "EnumChildWindows should have found %p and returned FALSE\n", child
);
557 DestroyWindow( child
);
558 DestroyWindow( test
);
559 DestroyWindow( owner
);
563 static LRESULT WINAPI
main_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
567 case WM_GETMINMAXINFO
:
569 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
571 trace("WM_GETMINMAXINFO: hwnd %p, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
572 dump_minmax_info( minmax
);
573 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
576 case WM_WINDOWPOSCHANGING
:
578 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
579 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
580 trace("main: WM_WINDOWPOSCHANGING %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
581 winpos
->hwnd
, winpos
->hwndInsertAfter
,
582 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
583 if (!(winpos
->flags
& SWP_NOMOVE
))
585 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
586 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
588 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
589 if (!(winpos
->flags
& SWP_NOSIZE
) && !is_win9x
)
591 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
592 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
596 case WM_WINDOWPOSCHANGED
:
599 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
600 trace("main: WM_WINDOWPOSCHANGED %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
601 winpos
->hwnd
, winpos
->hwndInsertAfter
,
602 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
603 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
604 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
606 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
607 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
609 GetWindowRect(hwnd
, &rc1
);
610 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
611 /* note: winpos coordinates are relative to parent */
612 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
615 /* Uncomment this once the test succeeds in all cases */
616 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
617 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
619 GetClientRect(hwnd
, &rc2
);
620 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
621 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
622 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
623 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
629 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
630 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
632 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
633 if (got_getminmaxinfo
)
634 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
636 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
637 ok(got_getminmaxinfo
, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
639 ok(!got_getminmaxinfo
, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
643 if (test_lbuttondown_flag
)
645 ShowWindow((HWND
)wparam
, SW_SHOW
);
646 flush_events( FALSE
);
651 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
654 static LRESULT WINAPI
tool_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
658 case WM_GETMINMAXINFO
:
660 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
662 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
663 dump_minmax_info( minmax
);
664 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
669 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
670 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
672 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
673 if (got_getminmaxinfo
)
674 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
676 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
677 ok(got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
679 ok(!got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
684 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
687 static BOOL
RegisterWindowClasses(void)
691 cls
.style
= CS_DBLCLKS
;
692 cls
.lpfnWndProc
= main_window_procA
;
695 cls
.hInstance
= GetModuleHandleA(0);
697 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
698 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
699 cls
.lpszMenuName
= NULL
;
700 cls
.lpszClassName
= "MainWindowClass";
702 if(!RegisterClassA(&cls
)) return FALSE
;
705 cls
.lpfnWndProc
= tool_window_procA
;
708 cls
.hInstance
= GetModuleHandleA(0);
710 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
711 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
712 cls
.lpszMenuName
= NULL
;
713 cls
.lpszClassName
= "ToolWindowClass";
715 if(!RegisterClassA(&cls
)) return FALSE
;
720 static void verify_window_info(const char *hook
, HWND hwnd
, const WINDOWINFO
*info
)
722 RECT rcWindow
, rcClient
;
725 ok(IsWindow(hwnd
), "bad window handle %p in hook %s\n", hwnd
, hook
);
727 GetWindowRect(hwnd
, &rcWindow
);
728 ok(EqualRect(&rcWindow
, &info
->rcWindow
), "wrong rcWindow for %p in hook %s\n", hwnd
, hook
);
730 GetClientRect(hwnd
, &rcClient
);
731 /* translate to screen coordinates */
732 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rcClient
, 2);
733 ok(EqualRect(&rcClient
, &info
->rcClient
), "wrong rcClient for %p in hook %s\n", hwnd
, hook
);
735 ok(info
->dwStyle
== (DWORD
)GetWindowLongA(hwnd
, GWL_STYLE
),
736 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
737 info
->dwStyle
, GetWindowLongA(hwnd
, GWL_STYLE
), hwnd
, hook
);
738 /* Windows reports some undocumented exstyles in WINDOWINFO, but
739 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
741 ok((info
->dwExStyle
& ~0xe0000800) == (DWORD
)GetWindowLongA(hwnd
, GWL_EXSTYLE
),
742 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
743 info
->dwExStyle
, GetWindowLongA(hwnd
, GWL_EXSTYLE
), hwnd
, hook
);
744 status
= (GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0;
745 if (GetForegroundWindow())
746 ok(info
->dwWindowStatus
== status
, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
747 info
->dwWindowStatus
, status
, GetActiveWindow(), GetForegroundWindow(), hook
);
749 /* win2k and XP return broken border info in GetWindowInfo most of
750 * the time, so there is no point in testing it.
754 ok(info
->cxWindowBorders
== (unsigned)(rcClient
.left
- rcWindow
.left
),
755 "wrong cxWindowBorders %d != %d\n", info
->cxWindowBorders
, rcClient
.left
- rcWindow
.left
);
756 border
= min(rcWindow
.bottom
- rcClient
.bottom
, rcClient
.top
- rcWindow
.top
);
757 ok(info
->cyWindowBorders
== border
,
758 "wrong cyWindowBorders %d != %d\n", info
->cyWindowBorders
, border
);
760 ok(info
->atomWindowType
== GetClassLongA(hwnd
, GCW_ATOM
), "wrong atomWindowType for %p in hook %s\n",
762 ok(info
->wCreatorVersion
== 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
763 info
->wCreatorVersion
== 0x0500 /* Vista */,
764 "wrong wCreatorVersion %04x for %p in hook %s\n", info
->wCreatorVersion
, hwnd
, hook
);
767 static void FixedAdjustWindowRectEx(RECT
* rc
, LONG style
, BOOL menu
, LONG exstyle
)
769 AdjustWindowRectEx(rc
, style
, menu
, exstyle
);
770 /* AdjustWindowRectEx does not include scroll bars */
771 if (style
& WS_VSCROLL
)
773 if(exstyle
& WS_EX_LEFTSCROLLBAR
)
774 rc
->left
-= GetSystemMetrics(SM_CXVSCROLL
);
776 rc
->right
+= GetSystemMetrics(SM_CXVSCROLL
);
778 if (style
& WS_HSCROLL
)
779 rc
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
782 static void test_nonclient_area(HWND hwnd
)
784 DWORD style
, exstyle
;
785 RECT rc_window
, rc_client
, rc
;
787 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
790 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
791 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
792 menu
= !(style
& WS_CHILD
) && GetMenu(hwnd
) != 0;
794 GetWindowRect(hwnd
, &rc_window
);
795 GetClientRect(hwnd
, &rc_client
);
797 /* avoid some cases when things go wrong */
798 if (IsRectEmpty(&rc_window
) || IsRectEmpty(&rc_client
) ||
799 rc_window
.right
> 32768 || rc_window
.bottom
> 32768) return;
801 CopyRect(&rc
, &rc_client
);
802 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc
, 2);
803 FixedAdjustWindowRectEx(&rc
, style
, menu
, exstyle
);
805 ok(EqualRect(&rc
, &rc_window
),
806 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
807 style
, exstyle
, menu
, rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
,
808 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
811 CopyRect(&rc
, &rc_window
);
812 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
813 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
814 ok(EqualRect(&rc
, &rc_client
),
815 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
816 style
, exstyle
, menu
, rc_client
.left
, rc_client
.top
, rc_client
.right
, rc_client
.bottom
,
817 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
819 /* NULL rectangle shouldn't crash */
820 ret
= DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, 0);
821 ok(ret
== 0, "NULL rectangle returned %ld instead of 0\n", ret
);
823 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
827 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
828 SetRect(&rc_client
, 0, 0, 250, 150);
829 CopyRect(&rc_window
, &rc_client
);
830 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc_window
, 2);
831 FixedAdjustWindowRectEx(&rc_window
, style
, menu
, exstyle
);
833 CopyRect(&rc
, &rc_window
);
834 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
835 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
836 ok(EqualRect(&rc
, &rc_client
),
837 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
838 style
, exstyle
, menu
, rc_client
.left
, rc_client
.top
, rc_client
.right
, rc_client
.bottom
,
839 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
842 static LRESULT CALLBACK
cbt_hook_proc(int nCode
, WPARAM wParam
, LPARAM lParam
)
844 static const char *CBT_code_name
[10] = {
855 const char *code_name
= (nCode
>= 0 && nCode
<= HCBT_SETFOCUS
) ? CBT_code_name
[nCode
] : "Unknown";
856 HWND hwnd
= (HWND
)wParam
;
862 static const RECT rc_null
;
865 CBT_CREATEWNDA
*createwnd
= (CBT_CREATEWNDA
*)lParam
;
866 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
867 hwnd
, createwnd
->lpcs
->hwndParent
, createwnd
->lpcs
->style
);
868 ok(createwnd
->hwndInsertAfter
== HWND_TOP
, "hwndInsertAfter should be always HWND_TOP\n");
873 info
.cbSize
= sizeof(WINDOWINFO
);
874 ok(pGetWindowInfo(hwnd
, &info
), "GetWindowInfo should not fail\n");
875 verify_window_info(code_name
, hwnd
, &info
);
878 /* WS_VISIBLE should be turned off yet */
879 style
= createwnd
->lpcs
->style
& ~WS_VISIBLE
;
880 ok(style
== GetWindowLongA(hwnd
, GWL_STYLE
),
881 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
882 GetWindowLongA(hwnd
, GWL_STYLE
), style
);
886 /* Uncomment this once the test succeeds in all cases */
887 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
889 ok(GetParent(hwnd
) == hwndMessage
,
890 "wrong result from GetParent %p: message window %p\n",
891 GetParent(hwnd
), hwndMessage
);
894 ok(!GetParent(hwnd
), "GetParent should return 0 at this point\n");
896 ok(!GetWindow(hwnd
, GW_OWNER
), "GW_OWNER should be set to 0 at this point\n");
900 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
901 * Win9x still has them set to 0.
903 ok(GetWindow(hwnd
, GW_HWNDFIRST
) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
904 ok(GetWindow(hwnd
, GW_HWNDLAST
) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
906 ok(!GetWindow(hwnd
, GW_HWNDPREV
), "GW_HWNDPREV should be set to 0 at this point\n");
907 ok(!GetWindow(hwnd
, GW_HWNDNEXT
), "GW_HWNDNEXT should be set to 0 at this point\n");
911 /* Uncomment this once the test succeeds in all cases */
914 ok(pGetAncestor(hwnd
, GA_PARENT
) == hwndMessage
, "GA_PARENT should be set to hwndMessage at this point\n");
915 ok(pGetAncestor(hwnd
, GA_ROOT
) == hwnd
,
916 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd
, GA_ROOT
), hwnd
);
918 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
919 ok(pGetAncestor(hwnd
, GA_ROOTOWNER
) == hwndMessage
,
920 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
922 ok(pGetAncestor(hwnd
, GA_ROOTOWNER
) == hwnd
,
923 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd
, GA_ROOTOWNER
), hwnd
);
926 ok(GetWindowRect(hwnd
, &rc
), "GetWindowRect failed\n");
927 ok(EqualRect(&rc
, &rc_null
), "window rect should be set to 0 HCBT_CREATEWND\n");
928 ok(GetClientRect(hwnd
, &rc
), "GetClientRect failed\n");
929 ok(EqualRect(&rc
, &rc_null
), "client rect should be set to 0 on HCBT_CREATEWND\n");
937 if (pGetWindowInfo
&& IsWindow(hwnd
))
941 /* Win98 actually does check the info.cbSize and doesn't allow
942 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
943 * WinXP do not check it at all.
945 info
.cbSize
= sizeof(WINDOWINFO
);
946 ok(pGetWindowInfo(hwnd
, &info
), "GetWindowInfo should not fail\n");
947 verify_window_info(code_name
, hwnd
, &info
);
950 /* on HCBT_DESTROYWND window state is undefined */
951 case HCBT_DESTROYWND
:
952 trace( "HCBT_DESTROYWND: hwnd %p\n", hwnd
);
958 return CallNextHookEx(hhook
, nCode
, wParam
, lParam
);
961 static void test_shell_window(void)
965 HMODULE hinst
, hUser32
;
966 BOOL (WINAPI
*SetShellWindow
)(HWND
);
967 BOOL (WINAPI
*SetShellWindowEx
)(HWND
, HWND
);
968 HWND hwnd1
, hwnd2
, hwnd3
, hwnd4
, hwnd5
;
969 HWND shellWindow
, nextWnd
;
971 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE
))
973 trace("Skipping shell window test on Win9x\n");
977 shellWindow
= GetShellWindow();
978 hinst
= GetModuleHandle(0);
979 hUser32
= GetModuleHandleA("user32");
981 SetShellWindow
= (void *)GetProcAddress(hUser32
, "SetShellWindow");
982 SetShellWindowEx
= (void *)GetProcAddress(hUser32
, "SetShellWindowEx");
984 trace("previous shell window: %p\n", shellWindow
);
990 GetWindowThreadProcessId(shellWindow
, &pid
);
991 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, pid
);
994 skip( "cannot get access to shell process\n" );
998 SetLastError(0xdeadbeef);
999 ret
= DestroyWindow(shellWindow
);
1000 error
= GetLastError();
1002 ok(!ret
, "DestroyWindow(shellWindow)\n");
1003 /* passes on Win XP, but not on Win98 */
1004 ok(error
==ERROR_ACCESS_DENIED
|| error
== 0xdeadbeef,
1005 "got %u after DestroyWindow(shellWindow)\n", error
);
1007 /* close old shell instance */
1008 ret
= TerminateProcess(hProcess
, 0);
1009 ok(ret
, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1010 WaitForSingleObject(hProcess
, INFINITE
); /* wait for termination */
1011 CloseHandle(hProcess
);
1014 hwnd1
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst
, 0);
1015 trace("created window 1: %p\n", hwnd1
);
1017 ret
= SetShellWindow(hwnd1
);
1018 ok(ret
, "first call to SetShellWindow(hwnd1)\n");
1019 shellWindow
= GetShellWindow();
1020 ok(shellWindow
==hwnd1
, "wrong shell window: %p\n", shellWindow
);
1022 ret
= SetShellWindow(hwnd1
);
1023 ok(!ret
, "second call to SetShellWindow(hwnd1)\n");
1025 ret
= SetShellWindow(0);
1026 error
= GetLastError();
1027 /* passes on Win XP, but not on Win98
1028 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1029 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1031 ret
= SetShellWindow(hwnd1
);
1032 /* passes on Win XP, but not on Win98
1033 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1035 SetWindowLong(hwnd1
, GWL_EXSTYLE
, GetWindowLong(hwnd1
,GWL_EXSTYLE
)|WS_EX_TOPMOST
);
1036 ret
= GetWindowLong(hwnd1
,GWL_EXSTYLE
)&WS_EX_TOPMOST
? TRUE
: FALSE
;
1037 ok(!ret
, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1039 ret
= DestroyWindow(hwnd1
);
1040 ok(ret
, "DestroyWindow(hwnd1)\n");
1042 hwnd2
= CreateWindowEx(WS_EX_TOPMOST
, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst
, 0);
1043 trace("created window 2: %p\n", hwnd2
);
1044 ret
= SetShellWindow(hwnd2
);
1045 ok(!ret
, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1047 hwnd3
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst
, 0);
1048 trace("created window 3: %p\n", hwnd3
);
1050 hwnd4
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst
, 0);
1051 trace("created window 4: %p\n", hwnd4
);
1053 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1054 ok(nextWnd
==hwnd3
, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd
);
1056 ret
= SetShellWindow(hwnd4
);
1057 ok(ret
, "SetShellWindow(hwnd4)\n");
1058 shellWindow
= GetShellWindow();
1059 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1061 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1062 ok(nextWnd
==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd
);
1064 ret
= SetWindowPos(hwnd4
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1065 ok(ret
, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1067 ret
= SetWindowPos(hwnd4
, hwnd3
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1068 ok(ret
, "SetWindowPos(hwnd4, hwnd3\n");
1070 ret
= SetShellWindow(hwnd3
);
1071 ok(!ret
, "SetShellWindow(hwnd3)\n");
1072 shellWindow
= GetShellWindow();
1073 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1075 hwnd5
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst
, 0);
1076 trace("created window 5: %p\n", hwnd5
);
1077 ret
= SetWindowPos(hwnd4
, hwnd5
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1078 ok(ret
, "SetWindowPos(hwnd4, hwnd5)\n");
1082 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1083 ok(nextWnd
==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd
);
1086 /* destroy test windows */
1087 DestroyWindow(hwnd2
);
1088 DestroyWindow(hwnd3
);
1089 DestroyWindow(hwnd4
);
1090 DestroyWindow(hwnd5
);
1093 /************** MDI test ****************/
1095 static char mdi_lParam_test_message
[] = "just a test string";
1097 static void test_MDI_create(HWND parent
, HWND mdi_client
, INT_PTR first_id
)
1099 MDICREATESTRUCTA mdi_cs
;
1102 static const WCHAR classW
[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1103 static const WCHAR titleW
[] = {'M','D','I',' ','c','h','i','l','d',0};
1104 BOOL isWin9x
= FALSE
;
1106 mdi_cs
.szClass
= "MDI_child_Class_1";
1107 mdi_cs
.szTitle
= "MDI child";
1108 mdi_cs
.hOwner
= GetModuleHandle(0);
1109 mdi_cs
.x
= CW_USEDEFAULT
;
1110 mdi_cs
.y
= CW_USEDEFAULT
;
1111 mdi_cs
.cx
= CW_USEDEFAULT
;
1112 mdi_cs
.cy
= CW_USEDEFAULT
;
1114 mdi_cs
.lParam
= (LPARAM
)mdi_lParam_test_message
;
1115 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1116 ok(mdi_child
!= 0, "MDI child creation failed\n");
1117 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1118 ok(id
== first_id
, "wrong child id %ld\n", id
);
1119 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1120 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1122 mdi_cs
.style
= 0x7fffffff; /* without WS_POPUP */
1123 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1124 ok(mdi_child
!= 0, "MDI child creation failed\n");
1125 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1126 ok(id
== first_id
, "wrong child id %ld\n", id
);
1127 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1128 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1130 mdi_cs
.style
= 0xffffffff; /* with WS_POPUP */
1131 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1132 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1134 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1138 ok(mdi_child
!= 0, "MDI child creation failed\n");
1139 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1140 ok(id
== first_id
, "wrong child id %ld\n", id
);
1141 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1142 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1145 /* test MDICREATESTRUCT A<->W mapping */
1146 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1148 mdi_cs
.szClass
= (LPCSTR
)classW
;
1149 mdi_cs
.szTitle
= (LPCSTR
)titleW
;
1150 SetLastError(0xdeadbeef);
1151 mdi_child
= (HWND
)SendMessageW(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1154 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1157 ok(mdi_child
!= 0, "MDI child creation failed\n");
1161 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1162 ok(id
== first_id
, "wrong child id %ld\n", id
);
1163 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1164 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1167 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1169 CW_USEDEFAULT
, CW_USEDEFAULT
,
1170 CW_USEDEFAULT
, CW_USEDEFAULT
,
1171 mdi_client
, GetModuleHandle(0),
1172 (LPARAM
)mdi_lParam_test_message
);
1173 ok(mdi_child
!= 0, "MDI child creation failed\n");
1174 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1175 ok(id
== first_id
, "wrong child id %ld\n", id
);
1176 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1177 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1179 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1180 0x7fffffff, /* without WS_POPUP */
1181 CW_USEDEFAULT
, CW_USEDEFAULT
,
1182 CW_USEDEFAULT
, CW_USEDEFAULT
,
1183 mdi_client
, GetModuleHandle(0),
1184 (LPARAM
)mdi_lParam_test_message
);
1185 ok(mdi_child
!= 0, "MDI child creation failed\n");
1186 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1187 ok(id
== first_id
, "wrong child id %ld\n", id
);
1188 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1189 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1191 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1192 0xffffffff, /* with WS_POPUP */
1193 CW_USEDEFAULT
, CW_USEDEFAULT
,
1194 CW_USEDEFAULT
, CW_USEDEFAULT
,
1195 mdi_client
, GetModuleHandle(0),
1196 (LPARAM
)mdi_lParam_test_message
);
1197 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1199 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1203 ok(mdi_child
!= 0, "MDI child creation failed\n");
1204 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1205 ok(id
== first_id
, "wrong child id %ld\n", id
);
1206 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1207 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1210 /* test MDICREATESTRUCT A<->W mapping */
1211 SetLastError(0xdeadbeef);
1212 mdi_child
= CreateMDIWindowW(classW
, titleW
,
1214 CW_USEDEFAULT
, CW_USEDEFAULT
,
1215 CW_USEDEFAULT
, CW_USEDEFAULT
,
1216 mdi_client
, GetModuleHandle(0),
1217 (LPARAM
)mdi_lParam_test_message
);
1220 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1223 ok(mdi_child
!= 0, "MDI child creation failed\n");
1227 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1228 ok(id
== first_id
, "wrong child id %ld\n", id
);
1229 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1230 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1233 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1235 CW_USEDEFAULT
, CW_USEDEFAULT
,
1236 CW_USEDEFAULT
, CW_USEDEFAULT
,
1237 mdi_client
, 0, GetModuleHandle(0),
1238 mdi_lParam_test_message
);
1239 ok(mdi_child
!= 0, "MDI child creation failed\n");
1240 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1241 ok(id
== first_id
, "wrong child id %ld\n", id
);
1242 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1243 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1245 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1246 0x7fffffff, /* without WS_POPUP */
1247 CW_USEDEFAULT
, CW_USEDEFAULT
,
1248 CW_USEDEFAULT
, CW_USEDEFAULT
,
1249 mdi_client
, 0, GetModuleHandle(0),
1250 mdi_lParam_test_message
);
1251 ok(mdi_child
!= 0, "MDI child creation failed\n");
1252 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1253 ok(id
== first_id
, "wrong child id %ld\n", id
);
1254 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1255 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1257 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1258 0xffffffff, /* with WS_POPUP */
1259 CW_USEDEFAULT
, CW_USEDEFAULT
,
1260 CW_USEDEFAULT
, CW_USEDEFAULT
,
1261 mdi_client
, 0, GetModuleHandle(0),
1262 mdi_lParam_test_message
);
1263 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1265 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1269 ok(mdi_child
!= 0, "MDI child creation failed\n");
1270 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1271 ok(id
== first_id
, "wrong child id %ld\n", id
);
1272 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1273 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1276 /* test MDICREATESTRUCT A<->W mapping */
1277 SetLastError(0xdeadbeef);
1278 mdi_child
= CreateWindowExW(WS_EX_MDICHILD
, classW
, titleW
,
1280 CW_USEDEFAULT
, CW_USEDEFAULT
,
1281 CW_USEDEFAULT
, CW_USEDEFAULT
,
1282 mdi_client
, 0, GetModuleHandle(0),
1283 mdi_lParam_test_message
);
1286 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1289 ok(mdi_child
!= 0, "MDI child creation failed\n");
1293 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1294 ok(id
== first_id
, "wrong child id %ld\n", id
);
1295 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1296 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1299 /* This test fails on Win9x */
1302 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_2", "MDI child",
1304 CW_USEDEFAULT
, CW_USEDEFAULT
,
1305 CW_USEDEFAULT
, CW_USEDEFAULT
,
1306 parent
, 0, GetModuleHandle(0),
1307 mdi_lParam_test_message
);
1308 ok(!mdi_child
, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1311 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1312 WS_CHILD
, /* without WS_POPUP */
1313 CW_USEDEFAULT
, CW_USEDEFAULT
,
1314 CW_USEDEFAULT
, CW_USEDEFAULT
,
1315 mdi_client
, 0, GetModuleHandle(0),
1316 mdi_lParam_test_message
);
1317 ok(mdi_child
!= 0, "MDI child creation failed\n");
1318 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1319 ok(id
== 0, "wrong child id %ld\n", id
);
1320 DestroyWindow(mdi_child
);
1322 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1323 WS_CHILD
| WS_POPUP
, /* with WS_POPUP */
1324 CW_USEDEFAULT
, CW_USEDEFAULT
,
1325 CW_USEDEFAULT
, CW_USEDEFAULT
,
1326 mdi_client
, 0, GetModuleHandle(0),
1327 mdi_lParam_test_message
);
1328 ok(mdi_child
!= 0, "MDI child creation failed\n");
1329 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1330 ok(id
== 0, "wrong child id %ld\n", id
);
1331 DestroyWindow(mdi_child
);
1333 /* maximized child */
1334 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1335 WS_CHILD
| WS_MAXIMIZE
,
1336 CW_USEDEFAULT
, CW_USEDEFAULT
,
1337 CW_USEDEFAULT
, CW_USEDEFAULT
,
1338 mdi_client
, 0, GetModuleHandle(0),
1339 mdi_lParam_test_message
);
1340 ok(mdi_child
!= 0, "MDI child creation failed\n");
1341 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1342 ok(id
== 0, "wrong child id %ld\n", id
);
1343 DestroyWindow(mdi_child
);
1345 trace("Creating maximized child with a caption\n");
1346 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1347 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
,
1348 CW_USEDEFAULT
, CW_USEDEFAULT
,
1349 CW_USEDEFAULT
, CW_USEDEFAULT
,
1350 mdi_client
, 0, GetModuleHandle(0),
1351 mdi_lParam_test_message
);
1352 ok(mdi_child
!= 0, "MDI child creation failed\n");
1353 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1354 ok(id
== 0, "wrong child id %ld\n", id
);
1355 DestroyWindow(mdi_child
);
1357 trace("Creating maximized child with a caption and a thick frame\n");
1358 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1359 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
| WS_THICKFRAME
,
1360 CW_USEDEFAULT
, CW_USEDEFAULT
,
1361 CW_USEDEFAULT
, CW_USEDEFAULT
,
1362 mdi_client
, 0, GetModuleHandle(0),
1363 mdi_lParam_test_message
);
1364 ok(mdi_child
!= 0, "MDI child creation failed\n");
1365 id
= GetWindowLongPtrA(mdi_child
, GWLP_ID
);
1366 ok(id
== 0, "wrong child id %ld\n", id
);
1367 DestroyWindow(mdi_child
);
1370 /**********************************************************************
1371 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1373 * Note: The rule here is that client rect of the maximized MDI child
1374 * is equal to the client rect of the MDI client window.
1376 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
1380 GetClientRect( client
, &rect
);
1381 AdjustWindowRectEx( &rect
, GetWindowLongA( hwnd
, GWL_STYLE
),
1382 0, GetWindowLongA( hwnd
, GWL_EXSTYLE
));
1384 rect
.right
-= rect
.left
;
1385 rect
.bottom
-= rect
.top
;
1386 lpMinMax
->ptMaxSize
.x
= rect
.right
;
1387 lpMinMax
->ptMaxSize
.y
= rect
.bottom
;
1389 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
1390 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
1392 trace("max rect (%d,%d - %d, %d)\n",
1393 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1396 static LRESULT WINAPI
mdi_child_wnd_proc_1(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1403 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1404 MDICREATESTRUCTA
*mdi_cs
= cs
->lpCreateParams
;
1406 ok(cs
->dwExStyle
& WS_EX_MDICHILD
, "WS_EX_MDICHILD should be set\n");
1407 ok(mdi_cs
->lParam
== (LPARAM
)mdi_lParam_test_message
, "wrong mdi_cs->lParam\n");
1409 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_1"), "wrong class name\n");
1410 ok(!lstrcmpA(cs
->lpszClass
, mdi_cs
->szClass
), "class name does not match\n");
1411 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1412 ok(!lstrcmpA(cs
->lpszName
, mdi_cs
->szTitle
), "title does not match\n");
1413 ok(cs
->hInstance
== mdi_cs
->hOwner
, "%p != %p\n", cs
->hInstance
, mdi_cs
->hOwner
);
1415 /* MDICREATESTRUCT should have original values */
1416 ok(mdi_cs
->style
== 0 || mdi_cs
->style
== 0x7fffffff || mdi_cs
->style
== 0xffffffff,
1417 "mdi_cs->style does not match (%08x)\n", mdi_cs
->style
);
1418 ok(mdi_cs
->x
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->x
);
1419 ok(mdi_cs
->y
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->y
);
1420 ok(mdi_cs
->cx
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cx
);
1421 ok(mdi_cs
->cy
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cy
);
1423 /* CREATESTRUCT should have fixed values */
1424 ok(cs
->x
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->x
);
1425 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1427 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1428 ok(cs
->cx
!= CW_USEDEFAULT
&& cs
->cx
!= 0, "%d == CW_USEDEFAULT\n", cs
->cx
);
1429 ok(cs
->cy
!= CW_USEDEFAULT
&& cs
->cy
!= 0, "%d == CW_USEDEFAULT\n", cs
->cy
);
1431 ok(!(cs
->style
& WS_POPUP
), "WS_POPUP is not allowed\n");
1433 if (GetWindowLongA(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1435 LONG style
= mdi_cs
->style
| WS_CHILD
| WS_CLIPSIBLINGS
;
1436 ok(cs
->style
== style
,
1437 "cs->style does not match (%08x)\n", cs
->style
);
1441 LONG style
= mdi_cs
->style
;
1443 style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1444 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1445 ok(cs
->style
== style
,
1446 "cs->style does not match (%08x)\n", cs
->style
);
1451 case WM_GETMINMAXINFO
:
1453 HWND client
= GetParent(hwnd
);
1455 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1456 MINMAXINFO my_minmax
;
1457 LONG style
, exstyle
;
1459 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1460 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1462 GetWindowRect(client
, &rc
);
1463 trace("MDI client %p window size = (%d x %d)\n", client
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1464 GetClientRect(client
, &rc
);
1465 trace("MDI client %p client size = (%d x %d)\n", client
, rc
.right
, rc
.bottom
);
1466 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN
),
1467 GetSystemMetrics(SM_CYSCREEN
));
1469 GetClientRect(client
, &rc
);
1470 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1471 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1472 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1473 trace("MDI child: calculated max window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1474 dump_minmax_info( minmax
);
1476 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1477 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1478 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1479 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1481 DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1483 trace("DefMDIChildProc returned:\n");
1484 dump_minmax_info( minmax
);
1486 MDI_ChildGetMinMaxInfo(client
, hwnd
, &my_minmax
);
1487 ok(minmax
->ptMaxSize
.x
== my_minmax
.ptMaxSize
.x
, "default width of maximized child %d != %d\n",
1488 minmax
->ptMaxSize
.x
, my_minmax
.ptMaxSize
.x
);
1489 ok(minmax
->ptMaxSize
.y
== my_minmax
.ptMaxSize
.y
, "default height of maximized child %d != %d\n",
1490 minmax
->ptMaxSize
.y
, my_minmax
.ptMaxSize
.y
);
1495 case WM_MDIACTIVATE
:
1497 HWND active
, client
= GetParent(hwnd
);
1498 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1499 active
= (HWND
)SendMessageA(client
, WM_MDIGETACTIVE
, 0, 0);
1500 if (hwnd
== (HWND
)lparam
) /* if we are being activated */
1501 ok (active
== (HWND
)lparam
, "new active %p != active %p\n", (HWND
)lparam
, active
);
1503 ok (active
== (HWND
)wparam
, "old active %p != active %p\n", (HWND
)wparam
, active
);
1507 return DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1510 static LRESULT WINAPI
mdi_child_wnd_proc_2(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1517 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1519 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg
== WM_NCCREATE
) ? "WM_NCCREATE" : "WM_CREATE",
1520 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
1522 ok(!(cs
->dwExStyle
& WS_EX_MDICHILD
), "WS_EX_MDICHILD should not be set\n");
1523 ok(cs
->lpCreateParams
== mdi_lParam_test_message
, "wrong cs->lpCreateParams\n");
1525 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_2"), "wrong class name\n");
1526 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1528 /* CREATESTRUCT should have fixed values */
1529 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1531 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1532 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1534 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1535 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1536 while Win95, Win2k, WinXP do. */
1537 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1538 ok(cs
->cy
== 0, "%d != 0\n", cs
->cy
);
1542 case WM_GETMINMAXINFO
:
1544 HWND parent
= GetParent(hwnd
);
1546 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1547 LONG style
, exstyle
;
1549 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1550 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1552 GetClientRect(parent
, &rc
);
1553 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent
, rc
.right
, rc
.bottom
);
1555 GetClientRect(parent
, &rc
);
1556 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1557 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1558 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1559 dump_minmax_info( minmax
);
1561 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1562 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1563 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1564 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1568 case WM_WINDOWPOSCHANGED
:
1570 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1573 GetWindowRect(hwnd
, &rc1
);
1574 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1575 /* note: winpos coordinates are relative to parent */
1576 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1577 ok(EqualRect(&rc1
, &rc2
), "rects do not match, window=(%d,%d)-(%d,%d) pos=(%d,%d)-(%d,%d)\n",
1578 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
1579 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1580 GetWindowRect(hwnd
, &rc1
);
1581 GetClientRect(hwnd
, &rc2
);
1582 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1583 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1584 ok(EqualRect(&rc1
, &rc2
), "rects do not match, window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1585 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
1586 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1589 case WM_WINDOWPOSCHANGING
:
1591 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1592 WINDOWPOS my_winpos
= *winpos
;
1594 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1595 (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
1596 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1597 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1599 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1601 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1602 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1603 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1604 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1609 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1612 static LRESULT WINAPI
mdi_main_wnd_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1614 static HWND mdi_client
;
1620 CLIENTCREATESTRUCT client_cs
;
1623 GetClientRect(hwnd
, &rc
);
1625 client_cs
.hWindowMenu
= 0;
1626 client_cs
.idFirstChild
= 1;
1628 /* MDIClient without MDIS_ALLCHILDSTYLES */
1629 mdi_client
= CreateWindowExA(0, "mdiclient",
1631 WS_CHILD
/*| WS_VISIBLE*/,
1632 /* tests depend on a not zero MDIClient size */
1633 0, 0, rc
.right
, rc
.bottom
,
1634 hwnd
, 0, GetModuleHandle(0),
1637 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1638 DestroyWindow(mdi_client
);
1640 /* MDIClient with MDIS_ALLCHILDSTYLES */
1641 mdi_client
= CreateWindowExA(0, "mdiclient",
1643 WS_CHILD
| MDIS_ALLCHILDSTYLES
/*| WS_VISIBLE*/,
1644 /* tests depend on a not zero MDIClient size */
1645 0, 0, rc
.right
, rc
.bottom
,
1646 hwnd
, 0, GetModuleHandle(0),
1649 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1650 DestroyWindow(mdi_client
);
1654 case WM_WINDOWPOSCHANGED
:
1656 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1659 GetWindowRect(hwnd
, &rc1
);
1660 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1661 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1662 /* note: winpos coordinates are relative to parent */
1663 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1664 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1665 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1667 GetWindowRect(hwnd
, &rc1
);
1668 GetClientRect(hwnd
, &rc2
);
1669 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1670 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1671 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1674 case WM_WINDOWPOSCHANGING
:
1676 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1677 WINDOWPOS my_winpos
= *winpos
;
1679 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1680 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1681 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1682 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1684 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1686 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1687 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1688 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1690 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1691 "DefWindowProc should not change WINDOWPOS values\n");
1700 return DefFrameProcA(hwnd
, mdi_client
, msg
, wparam
, lparam
);
1703 static BOOL
mdi_RegisterWindowClasses(void)
1708 cls
.lpfnWndProc
= mdi_main_wnd_procA
;
1711 cls
.hInstance
= GetModuleHandleA(0);
1713 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
1714 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1715 cls
.lpszMenuName
= NULL
;
1716 cls
.lpszClassName
= "MDI_parent_Class";
1717 if(!RegisterClassA(&cls
)) return FALSE
;
1719 cls
.lpfnWndProc
= mdi_child_wnd_proc_1
;
1720 cls
.lpszClassName
= "MDI_child_Class_1";
1721 if(!RegisterClassA(&cls
)) return FALSE
;
1723 cls
.lpfnWndProc
= mdi_child_wnd_proc_2
;
1724 cls
.lpszClassName
= "MDI_child_Class_2";
1725 if(!RegisterClassA(&cls
)) return FALSE
;
1730 static void test_mdi(void)
1735 if (!mdi_RegisterWindowClasses()) assert(0);
1737 mdi_hwndMain
= CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1738 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
1739 WS_MAXIMIZEBOX
/*| WS_VISIBLE*/,
1740 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1741 GetDesktopWindow(), 0,
1742 GetModuleHandle(0), NULL
);
1743 assert(mdi_hwndMain
);
1745 while(GetMessage(&msg, 0, 0, 0))
1747 TranslateMessage(&msg);
1748 DispatchMessage(&msg);
1751 DestroyWindow(mdi_hwndMain
);
1754 static void test_icons(void)
1758 HICON icon
= LoadIconA(0, IDI_APPLICATION
);
1759 HICON icon2
= LoadIconA(0, IDI_QUESTION
);
1760 HICON small_icon
= LoadImageA(0, IDI_APPLICATION
, IMAGE_ICON
,
1761 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
1764 cls
.cbSize
= sizeof(cls
);
1766 cls
.lpfnWndProc
= DefWindowProcA
;
1770 cls
.hIcon
= LoadIconA(0, IDI_HAND
);
1771 cls
.hIconSm
= small_icon
;
1772 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
1773 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1774 cls
.lpszMenuName
= NULL
;
1775 cls
.lpszClassName
= "IconWindowClass";
1777 RegisterClassExA(&cls
);
1779 hwnd
= CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1780 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, NULL
, NULL
);
1783 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1784 ok( res
== 0, "wrong big icon %p/0\n", res
);
1785 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon
);
1786 ok( res
== 0, "wrong previous big icon %p/0\n", res
);
1787 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1788 ok( res
== icon
, "wrong big icon after set %p/%p\n", res
, icon
);
1789 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon2
);
1790 ok( res
== icon
, "wrong previous big icon %p/%p\n", res
, icon
);
1791 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1792 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1794 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1795 ok( res
== 0, "wrong small icon %p/0\n", res
);
1796 /* this test is XP specific */
1797 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1798 ok( res != 0, "wrong small icon %p\n", res );*/
1799 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)icon
);
1800 ok( res
== 0, "wrong previous small icon %p/0\n", res
);
1801 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1802 ok( res
== icon
, "wrong small icon after set %p/%p\n", res
, icon
);
1803 /* this test is XP specific */
1804 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1805 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1806 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)small_icon
);
1807 ok( res
== icon
, "wrong previous small icon %p/%p\n", res
, icon
);
1808 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1809 ok( res
== small_icon
, "wrong small icon after set %p/%p\n", res
, small_icon
);
1810 /* this test is XP specific */
1811 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1812 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1814 /* make sure the big icon hasn't changed */
1815 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1816 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1818 DestroyWindow( hwnd
);
1821 static LRESULT WINAPI
nccalcsize_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1823 if (msg
== WM_NCCALCSIZE
)
1825 RECT
*rect
= (RECT
*)lparam
;
1826 /* first time around increase the rectangle, next time decrease it */
1827 if (rect
->left
== 100) InflateRect( rect
, 10, 10 );
1828 else InflateRect( rect
, -10, -10 );
1831 return DefWindowProc( hwnd
, msg
, wparam
, lparam
);
1834 static void test_SetWindowPos(HWND hwnd
)
1836 RECT orig_win_rc
, rect
;
1838 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
1840 SetRect(&rect
, 111, 222, 333, 444);
1841 ok(!GetWindowRect(0, &rect
), "GetWindowRect succeeded\n");
1842 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1843 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1845 SetRect(&rect
, 111, 222, 333, 444);
1846 ok(!GetClientRect(0, &rect
), "GetClientRect succeeded\n");
1847 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1848 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1850 GetWindowRect(hwnd
, &orig_win_rc
);
1852 old_proc
= SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)nccalcsize_proc
);
1853 SetWindowPos(hwnd
, 0, 100, 100, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1854 GetWindowRect( hwnd
, &rect
);
1855 ok( rect
.left
== 100 && rect
.top
== 100 && rect
.right
== 100 && rect
.bottom
== 100,
1856 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1857 GetClientRect( hwnd
, &rect
);
1858 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1859 ok( rect
.left
== 90 && rect
.top
== 90 && rect
.right
== 110 && rect
.bottom
== 110,
1860 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1862 SetWindowPos(hwnd
, 0, 200, 200, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1863 GetWindowRect( hwnd
, &rect
);
1864 ok( rect
.left
== 200 && rect
.top
== 200 && rect
.right
== 200 && rect
.bottom
== 200,
1865 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1866 GetClientRect( hwnd
, &rect
);
1867 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1868 ok( rect
.left
== 210 && rect
.top
== 210 && rect
.right
== 190 && rect
.bottom
== 190,
1869 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1871 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1872 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1873 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, old_proc
);
1875 /* Win9x truncates coordinates to 16-bit irrespectively */
1878 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE
);
1879 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE
);
1881 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE
);
1882 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE
);
1885 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1886 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1888 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1889 SetWindowPos(hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1890 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1891 SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1892 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1893 SetWindowPos(hwnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1894 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1897 static void test_SetMenu(HWND parent
)
1901 BOOL is_win9x
= GetWindowLongPtrW(parent
, GWLP_WNDPROC
) == 0;
1905 hMenu
= CreateMenu();
1908 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1911 /* fails on (at least) Wine, NT4, XP SP2 */
1912 test_nonclient_area(parent
);
1914 ret
= GetMenu(parent
);
1915 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1916 /* test whether we can destroy a menu assigned to a window */
1917 retok
= DestroyMenu(hMenu
);
1918 ok( retok
, "DestroyMenu error %d\n", GetLastError());
1919 retok
= IsMenu(hMenu
);
1920 ok(!retok
|| broken(retok
) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
1921 ret
= GetMenu(parent
);
1922 /* This test fails on Win9x */
1924 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1925 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1926 test_nonclient_area(parent
);
1928 hMenu
= CreateMenu();
1932 ret
= GetMenu(parent
);
1933 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1935 ok(!SetMenu(parent
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1936 test_nonclient_area(parent
);
1937 ret
= GetMenu(parent
);
1938 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1940 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1943 /* fails on (at least) Wine, NT4, XP SP2 */
1944 test_nonclient_area(parent
);
1946 ret
= GetMenu(parent
);
1947 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1949 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1950 test_nonclient_area(parent
);
1951 ret
= GetMenu(parent
);
1952 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1955 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, parent
, (HMENU
)10, 0, NULL
);
1958 ret
= GetMenu(child
);
1959 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1961 ok(!SetMenu(child
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1962 test_nonclient_area(child
);
1963 ret
= GetMenu(child
);
1964 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1966 ok(!SetMenu(child
, hMenu
), "SetMenu on a child window should fail\n");
1967 test_nonclient_area(child
);
1968 ret
= GetMenu(child
);
1969 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1971 ok(!SetMenu(child
, 0), "SetMenu(0) on a child window should fail\n");
1972 test_nonclient_area(child
);
1973 ret
= GetMenu(child
);
1974 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1976 style
= GetWindowLong(child
, GWL_STYLE
);
1977 SetWindowLong(child
, GWL_STYLE
, style
| WS_POPUP
);
1978 ok(SetMenu(child
, hMenu
), "SetMenu on a popup child window should not fail\n");
1979 ok(SetMenu(child
, 0), "SetMenu on a popup child window should not fail\n");
1980 SetWindowLong(child
, GWL_STYLE
, style
);
1982 SetWindowLong(child
, GWL_STYLE
, style
| WS_OVERLAPPED
);
1983 ok(!SetMenu(child
, hMenu
), "SetMenu on a overlapped child window should fail\n");
1984 SetWindowLong(child
, GWL_STYLE
, style
);
1986 DestroyWindow(child
);
1990 static void test_window_tree(HWND parent
, const DWORD
*style
, const int *order
, int total
)
1992 HWND child
[5], hwnd
;
1997 hwnd
= GetWindow(parent
, GW_CHILD
);
1998 ok(!hwnd
, "have to start without children to perform the test\n");
2000 for (i
= 0; i
< total
; i
++)
2002 if (style
[i
] & DS_CONTROL
)
2004 child
[i
] = CreateWindowExA(0, MAKEINTATOM(32770), "", style
[i
] & ~WS_VISIBLE
,
2005 0,0,0,0, parent
, (HMENU
)i
, 0, NULL
);
2006 if (style
[i
] & WS_VISIBLE
)
2007 ShowWindow(child
[i
], SW_SHOW
);
2009 SetWindowPos(child
[i
], HWND_BOTTOM
, 0,0,10,10, SWP_NOACTIVATE
);
2012 child
[i
] = CreateWindowExA(0, "static", "", style
[i
], 0,0,10,10,
2013 parent
, (HMENU
)i
, 0, NULL
);
2014 trace("child[%ld] = %p\n", i
, child
[i
]);
2015 ok(child
[i
] != 0, "CreateWindowEx failed to create child window\n");
2018 hwnd
= GetWindow(parent
, GW_CHILD
);
2019 ok(hwnd
!= 0, "GetWindow(GW_CHILD) failed\n");
2020 ok(hwnd
== GetWindow(child
[total
- 1], GW_HWNDFIRST
), "GW_HWNDFIRST is wrong\n");
2021 ok(child
[order
[total
- 1]] == GetWindow(child
[0], GW_HWNDLAST
), "GW_HWNDLAST is wrong\n");
2023 for (i
= 0; i
< total
; i
++)
2025 trace("hwnd[%ld] = %p\n", i
, hwnd
);
2026 ok(child
[order
[i
]] == hwnd
, "Z order of child #%ld is wrong\n", i
);
2028 hwnd
= GetWindow(hwnd
, GW_HWNDNEXT
);
2031 for (i
= 0; i
< total
; i
++)
2032 ok(DestroyWindow(child
[i
]), "DestroyWindow failed\n");
2035 static void test_children_zorder(HWND parent
)
2037 const DWORD simple_style
[5] = { WS_CHILD
, WS_CHILD
, WS_CHILD
, WS_CHILD
,
2039 const int simple_order
[5] = { 0, 1, 2, 3, 4 };
2041 const DWORD complex_style
[5] = { WS_CHILD
, WS_CHILD
| WS_MAXIMIZE
,
2042 WS_CHILD
| WS_VISIBLE
, WS_CHILD
,
2043 WS_CHILD
| WS_MAXIMIZE
| WS_VISIBLE
};
2044 const int complex_order_1
[1] = { 0 };
2045 const int complex_order_2
[2] = { 1, 0 };
2046 const int complex_order_3
[3] = { 1, 0, 2 };
2047 const int complex_order_4
[4] = { 1, 0, 2, 3 };
2048 const int complex_order_5
[5] = { 4, 1, 0, 2, 3 };
2049 const DWORD complex_style_6
[3] = { WS_CHILD
| WS_VISIBLE
,
2050 WS_CHILD
| WS_CLIPSIBLINGS
| DS_CONTROL
| WS_VISIBLE
,
2051 WS_CHILD
| WS_VISIBLE
};
2052 const int complex_order_6
[3] = { 0, 1, 2 };
2054 /* simple WS_CHILD */
2055 test_window_tree(parent
, simple_style
, simple_order
, 5);
2057 /* complex children styles */
2058 test_window_tree(parent
, complex_style
, complex_order_1
, 1);
2059 test_window_tree(parent
, complex_style
, complex_order_2
, 2);
2060 test_window_tree(parent
, complex_style
, complex_order_3
, 3);
2061 test_window_tree(parent
, complex_style
, complex_order_4
, 4);
2062 test_window_tree(parent
, complex_style
, complex_order_5
, 5);
2064 /* another set of complex children styles */
2065 test_window_tree(parent
, complex_style_6
, complex_order_6
, 3);
2068 #define check_z_order(hwnd, next, prev, owner, topmost) \
2069 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2072 static void check_z_order_debug(HWND hwnd
, HWND next
, HWND prev
, HWND owner
,
2073 BOOL topmost
, const char *file
, int line
)
2078 test
= GetWindow(hwnd
, GW_HWNDNEXT
);
2079 /* skip foreign windows */
2080 while (test
&& test
!= next
&&
2081 (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2082 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0) ||
2083 GetWindow(test
, GW_OWNER
) == next
))
2085 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2086 test
= GetWindow(test
, GW_HWNDNEXT
);
2088 ok_(file
, line
)(next
== test
, "expected next %p, got %p\n", next
, test
);
2090 test
= GetWindow(hwnd
, GW_HWNDPREV
);
2091 /* skip foreign windows */
2092 while (test
&& test
!= prev
&&
2093 (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2094 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0) ||
2095 GetWindow(test
, GW_OWNER
) == hwnd
))
2097 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2098 test
= GetWindow(test
, GW_HWNDPREV
);
2100 ok_(file
, line
)(prev
== test
, "expected prev %p, got %p\n", prev
, test
);
2102 test
= GetWindow(hwnd
, GW_OWNER
);
2103 ok_(file
, line
)(owner
== test
, "expected owner %p, got %p\n", owner
, test
);
2105 ex_style
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
2106 ok_(file
, line
)(!(ex_style
& WS_EX_TOPMOST
) == !topmost
, "expected %stopmost\n", topmost
? "" : "NOT ");
2109 static void test_popup_zorder(HWND hwnd_D
, HWND hwnd_E
)
2111 HWND hwnd_A
, hwnd_B
, hwnd_C
, hwnd_F
;
2113 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D
, hwnd_E
);
2115 SetWindowPos(hwnd_E
, hwnd_D
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2117 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2118 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2120 hwnd_F
= CreateWindowEx(0, "MainWindowClass", "Owner window",
2121 WS_OVERLAPPED
| WS_CAPTION
,
2123 0, 0, GetModuleHandle(0), NULL
);
2124 trace("hwnd_F %p\n", hwnd_F
);
2125 check_z_order(hwnd_F
, hwnd_D
, 0, 0, FALSE
);
2127 SetWindowPos(hwnd_F
, hwnd_E
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2128 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2129 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2130 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2132 hwnd_C
= CreateWindowEx(0, "MainWindowClass", NULL
,
2135 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2136 trace("hwnd_C %p\n", hwnd_C
);
2137 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2138 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2139 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2140 check_z_order(hwnd_C
, hwnd_D
, 0, hwnd_F
, FALSE
);
2142 hwnd_B
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2145 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2146 trace("hwnd_B %p\n", hwnd_B
);
2147 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2148 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2149 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2150 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2151 check_z_order(hwnd_B
, hwnd_C
, 0, hwnd_F
, TRUE
);
2153 hwnd_A
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2156 0, 0, GetModuleHandle(0), NULL
);
2157 trace("hwnd_A %p\n", hwnd_A
);
2158 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2159 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2160 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2161 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2162 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2163 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2165 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
);
2167 /* move hwnd_F and its popups up */
2168 SetWindowPos(hwnd_F
, HWND_TOP
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2169 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2170 check_z_order(hwnd_D
, hwnd_E
, hwnd_F
, 0, FALSE
);
2171 check_z_order(hwnd_F
, hwnd_D
, hwnd_C
, 0, FALSE
);
2172 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2173 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2174 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2176 /* move hwnd_F and its popups down */
2177 #if 0 /* enable once Wine is fixed to pass this test */
2178 SetWindowPos(hwnd_F
, HWND_BOTTOM
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2179 check_z_order(hwnd_F
, 0, hwnd_C
, 0, FALSE
);
2180 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2181 check_z_order(hwnd_B
, hwnd_C
, hwnd_E
, hwnd_F
, FALSE
);
2182 check_z_order(hwnd_E
, hwnd_B
, hwnd_D
, 0, FALSE
);
2183 check_z_order(hwnd_D
, hwnd_E
, hwnd_A
, 0, FALSE
);
2184 check_z_order(hwnd_A
, hwnd_D
, 0, 0, TRUE
);
2187 DestroyWindow(hwnd_A
);
2188 DestroyWindow(hwnd_B
);
2189 DestroyWindow(hwnd_C
);
2190 DestroyWindow(hwnd_F
);
2193 static void test_vis_rgn( HWND hwnd
)
2195 RECT win_rect
, rgn_rect
;
2196 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2199 ShowWindow(hwnd
,SW_SHOW
);
2200 hdc
= GetDC( hwnd
);
2201 ok( GetRandomRgn( hdc
, hrgn
, SYSRGN
) != 0, "GetRandomRgn failed\n" );
2202 GetWindowRect( hwnd
, &win_rect
);
2203 GetRgnBox( hrgn
, &rgn_rect
);
2204 if (GetVersion() & 0x80000000)
2206 trace("win9x, mapping to screen coords\n");
2207 MapWindowPoints( hwnd
, 0, (POINT
*)&rgn_rect
, 2 );
2209 trace("win: %d,%d-%d,%d\n", win_rect
.left
, win_rect
.top
, win_rect
.right
, win_rect
.bottom
);
2210 trace("rgn: %d,%d-%d,%d\n", rgn_rect
.left
, rgn_rect
.top
, rgn_rect
.right
, rgn_rect
.bottom
);
2211 ok( win_rect
.left
<= rgn_rect
.left
, "rgn left %d not inside win rect %d\n",
2212 rgn_rect
.left
, win_rect
.left
);
2213 ok( win_rect
.top
<= rgn_rect
.top
, "rgn top %d not inside win rect %d\n",
2214 rgn_rect
.top
, win_rect
.top
);
2215 ok( win_rect
.right
>= rgn_rect
.right
, "rgn right %d not inside win rect %d\n",
2216 rgn_rect
.right
, win_rect
.right
);
2217 ok( win_rect
.bottom
>= rgn_rect
.bottom
, "rgn bottom %d not inside win rect %d\n",
2218 rgn_rect
.bottom
, win_rect
.bottom
);
2219 ReleaseDC( hwnd
, hdc
);
2222 static LRESULT WINAPI
set_focus_on_activate_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
2224 if (msg
== WM_ACTIVATE
&& LOWORD(wp
) == WA_ACTIVE
)
2226 HWND child
= GetWindow(hwnd
, GW_CHILD
);
2227 ok(child
!= 0, "couldn't find child window\n");
2229 ok(GetFocus() == child
, "Focus should be on child %p\n", child
);
2232 return DefWindowProc(hwnd
, msg
, wp
, lp
);
2235 static void test_SetFocus(HWND hwnd
)
2238 WNDPROC old_wnd_proc
;
2240 /* check if we can set focus to non-visible windows */
2242 ShowWindow(hwnd
, SW_SHOW
);
2245 ok( GetFocus() == hwnd
, "Failed to set focus to visible window %p\n", hwnd
);
2246 ok( GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
, "Window %p not visible\n", hwnd
);
2247 ShowWindow(hwnd
, SW_HIDE
);
2250 ok( GetFocus() == hwnd
, "Failed to set focus to invisible window %p\n", hwnd
);
2251 ok( !(GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
), "Window %p still visible\n", hwnd
);
2252 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2255 ok( GetFocus() == child
, "Failed to set focus to invisible child %p\n", child
);
2256 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2257 ShowWindow(child
, SW_SHOW
);
2258 ok( GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
, "Child %p is not visible\n", child
);
2259 ok( GetFocus() == child
, "Focus no longer on child %p\n", child
);
2260 ShowWindow(child
, SW_HIDE
);
2261 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2262 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2263 ShowWindow(child
, SW_SHOW
);
2265 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2266 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_HIDEWINDOW
);
2267 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2269 ShowWindow(child
, SW_HIDE
);
2271 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2272 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_SHOWWINDOW
);
2273 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2274 ShowWindow(child
, SW_HIDE
);
2275 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2277 ShowWindow(hwnd
, SW_SHOW
);
2278 ShowWindow(child
, SW_SHOW
);
2280 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2281 EnableWindow(hwnd
, FALSE
);
2282 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2283 EnableWindow(hwnd
, TRUE
);
2285 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2286 ShowWindow(hwnd
, SW_SHOWMINIMIZED
);
2287 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2289 ok( GetFocus() != child
, "Focus should not be on child %p\n", child
);
2290 ok( GetFocus() != hwnd
, "Focus should not be on parent %p\n", hwnd
);
2291 ShowWindow(hwnd
, SW_RESTORE
);
2292 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2293 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
2294 ShowWindow(hwnd
, SW_SHOWMINIMIZED
);
2295 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2296 ok( GetFocus() != child
, "Focus should not be on child %p\n", child
);
2298 ok( GetFocus() != hwnd
, "Focus should not be on parent %p\n", hwnd
);
2299 old_wnd_proc
= (WNDPROC
)SetWindowLongPtr(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)set_focus_on_activate_proc
);
2300 ShowWindow(hwnd
, SW_RESTORE
);
2301 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2303 ok( GetFocus() == child
, "Focus should be on child %p, not %p\n", child
, GetFocus() );
2305 SetWindowLongPtr(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)old_wnd_proc
);
2307 DestroyWindow( child
);
2310 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
2311 static void check_wnd_state_(const char *file
, int line
,
2312 HWND active
, HWND foreground
, HWND focus
, HWND capture
)
2314 ok_(file
, line
)(active
== GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2315 if (foreground
&& GetForegroundWindow())
2316 ok_(file
, line
)(foreground
== GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2317 ok_(file
, line
)(focus
== GetFocus(), "GetFocus() = %p\n", GetFocus());
2318 ok_(file
, line
)(capture
== GetCapture(), "GetCapture() = %p\n", GetCapture());
2321 static void test_SetActiveWindow(HWND hwnd
)
2325 flush_events( TRUE
);
2326 ShowWindow(hwnd
, SW_HIDE
);
2329 check_wnd_state(0, 0, 0, 0);
2331 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2333 ShowWindow(hwnd
, SW_SHOW
);
2334 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2336 hwnd2
= SetActiveWindow(0);
2337 ok(hwnd2
== hwnd
, "SetActiveWindow returned %p instead of %p\n", hwnd2
, hwnd
);
2338 if (!GetActiveWindow()) /* doesn't always work on vista */
2340 check_wnd_state(0, 0, 0, 0);
2341 hwnd2
= SetActiveWindow(hwnd
);
2342 ok(hwnd2
== 0, "SetActiveWindow returned %p instead of 0\n", hwnd2
);
2344 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2346 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2347 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2349 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2350 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2352 ShowWindow(hwnd
, SW_HIDE
);
2353 check_wnd_state(0, 0, 0, 0);
2355 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2356 SetActiveWindow(hwnd
);
2357 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2359 ShowWindow(hwnd
, SW_SHOW
);
2360 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2362 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2363 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2365 DestroyWindow(hwnd2
);
2366 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2368 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2369 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2371 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2372 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2374 DestroyWindow(hwnd2
);
2375 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2378 static void test_SetForegroundWindow(HWND hwnd
)
2383 flush_events( TRUE
);
2384 ShowWindow(hwnd
, SW_HIDE
);
2387 check_wnd_state(0, 0, 0, 0);
2389 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2391 ShowWindow(hwnd
, SW_SHOW
);
2392 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2394 hwnd2
= SetActiveWindow(0);
2395 ok(hwnd2
== hwnd
, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2
, hwnd
);
2396 if (GetActiveWindow() == hwnd
) /* doesn't always work on vista */
2397 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2399 check_wnd_state(0, 0, 0, 0);
2401 ret
= SetForegroundWindow(hwnd
);
2404 skip( "SetForegroundWindow not working\n" );
2407 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2409 SetLastError(0xdeadbeef);
2410 ret
= SetForegroundWindow(0);
2411 ok(!ret
, "SetForegroundWindow returned TRUE instead of FALSE\n");
2412 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
||
2413 broken(GetLastError() == 0xdeadbeef), /* win9x */
2414 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2415 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2417 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2418 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2420 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2421 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2423 hwnd2
= GetForegroundWindow();
2424 ok(hwnd2
== hwnd
, "Wrong foreground window %p\n", hwnd2
);
2425 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2426 hwnd2
= GetForegroundWindow();
2427 ok(hwnd2
!= hwnd
, "Wrong foreground window %p\n", hwnd2
);
2429 ShowWindow(hwnd
, SW_HIDE
);
2430 check_wnd_state(0, 0, 0, 0);
2432 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2433 ret
= SetForegroundWindow(hwnd
);
2434 ok(ret
|| broken(!ret
), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
2435 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2437 ShowWindow(hwnd
, SW_SHOW
);
2438 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2440 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2441 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2443 DestroyWindow(hwnd2
);
2444 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2446 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2447 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2449 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2450 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2452 DestroyWindow(hwnd2
);
2453 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2456 static WNDPROC old_button_proc
;
2458 static LRESULT WINAPI
button_hook_proc(HWND button
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2463 key_state
= GetKeyState(VK_LBUTTON
);
2464 ok(!(key_state
& 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state
);
2466 ret
= CallWindowProcA(old_button_proc
, button
, msg
, wparam
, lparam
);
2468 if (msg
== WM_LBUTTONDOWN
)
2472 check_wnd_state(button
, button
, button
, button
);
2474 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2476 trace("hwnd %p\n", hwnd
);
2478 check_wnd_state(button
, button
, button
, button
);
2480 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2482 check_wnd_state(button
, button
, button
, button
);
2484 DestroyWindow(hwnd
);
2486 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2488 trace("hwnd %p\n", hwnd
);
2490 check_wnd_state(button
, button
, button
, button
);
2492 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2493 * match internal button state.
2495 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2496 check_wnd_state(button
, button
, button
, 0);
2498 ShowWindow(hwnd
, SW_SHOW
);
2499 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2501 capture
= SetCapture(hwnd
);
2502 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2504 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2506 DestroyWindow(hwnd
);
2508 check_wnd_state(button
, 0, button
, 0);
2514 static void test_capture_1(void)
2516 HWND button
, capture
, oldFocus
, oldActive
;
2518 oldFocus
= GetFocus();
2519 oldActive
= GetActiveWindow();
2521 capture
= GetCapture();
2522 ok(capture
== 0, "GetCapture() = %p\n", capture
);
2524 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2526 trace("button %p\n", button
);
2528 old_button_proc
= (WNDPROC
)SetWindowLongPtrA(button
, GWLP_WNDPROC
, (LONG_PTR
)button_hook_proc
);
2530 SendMessageA(button
, WM_LBUTTONDOWN
, 0, 0);
2532 capture
= SetCapture(button
);
2533 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2534 check_wnd_state(button
, 0, button
, button
);
2536 DestroyWindow(button
);
2537 check_wnd_state(oldActive
, 0, oldFocus
, 0);
2540 static void test_capture_2(void)
2542 HWND button
, hwnd
, capture
, oldFocus
, oldActive
;
2544 oldFocus
= GetFocus();
2545 oldActive
= GetActiveWindow();
2546 check_wnd_state(oldActive
, 0, oldFocus
, 0);
2548 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2550 trace("button %p\n", button
);
2552 check_wnd_state(button
, button
, button
, 0);
2554 capture
= SetCapture(button
);
2555 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2557 check_wnd_state(button
, button
, button
, button
);
2559 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2560 * internal button state.
2562 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2563 check_wnd_state(button
, button
, button
, button
);
2565 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2567 trace("hwnd %p\n", hwnd
);
2569 check_wnd_state(button
, button
, button
, button
);
2571 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2573 check_wnd_state(button
, button
, button
, button
);
2575 DestroyWindow(hwnd
);
2577 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2579 trace("hwnd %p\n", hwnd
);
2581 check_wnd_state(button
, button
, button
, button
);
2583 ShowWindow(hwnd
, SW_SHOW
);
2585 check_wnd_state(hwnd
, hwnd
, hwnd
, button
);
2587 capture
= SetCapture(hwnd
);
2588 ok(capture
== button
, "SetCapture() = %p\n", capture
);
2590 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2592 DestroyWindow(hwnd
);
2593 check_wnd_state(button
, button
, button
, 0);
2595 DestroyWindow(button
);
2596 check_wnd_state(oldActive
, 0, oldFocus
, 0);
2599 static void test_capture_3(HWND hwnd1
, HWND hwnd2
)
2603 ShowWindow(hwnd1
, SW_HIDE
);
2604 ShowWindow(hwnd2
, SW_HIDE
);
2606 ok(!IsWindowVisible(hwnd1
), "%p should be invisible\n", hwnd1
);
2607 ok(!IsWindowVisible(hwnd2
), "%p should be invisible\n", hwnd2
);
2610 check_wnd_state(0, 0, 0, hwnd1
);
2613 check_wnd_state(0, 0, 0, hwnd2
);
2615 ShowWindow(hwnd1
, SW_SHOW
);
2616 check_wnd_state(hwnd1
, hwnd1
, hwnd1
, hwnd2
);
2618 ret
= ReleaseCapture();
2619 ok (ret
, "releasecapture did not return TRUE.\n");
2620 ret
= ReleaseCapture();
2621 ok (ret
, "releasecapture did not return TRUE after second try.\n");
2624 static void test_keyboard_input(HWND hwnd
)
2629 flush_events( TRUE
);
2630 SetWindowPos(hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_SHOWWINDOW
);
2632 flush_events( TRUE
);
2634 ok(GetActiveWindow() == hwnd
, "wrong active window %p\n", GetActiveWindow());
2637 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2639 flush_events( TRUE
);
2641 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2644 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2645 ok( ret
, "no message available\n");
2647 while (ret
&& msg
.message
>= 0xc000);
2648 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2650 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2651 while (ret
&& (msg
.message
== WM_TIMER
|| msg
.message
>= 0xc000));
2652 ok( !ret
, "message %04x available\n", msg
.message
);
2654 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2656 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2657 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2658 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2659 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2660 ok( !ret
, "message %04x available\n", msg
.message
);
2662 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2664 keybd_event(VK_SPACE
, 0, 0, 0);
2667 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2668 } while (ret
&& msg
.message
>= 0xc000);
2671 skip( "keybd_event didn't work, skipping keyboard test\n" );
2674 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2675 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2676 ok( !ret
, "message %04x available\n", msg
.message
);
2679 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2681 flush_events( TRUE
);
2683 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2684 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2685 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2686 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2687 ok( !ret
, "message %04x available\n", msg
.message
);
2689 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2691 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2692 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2693 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2694 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2695 ok( !ret
, "message %04x available\n", msg
.message
);
2697 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2699 keybd_event(VK_SPACE
, 0, 0, 0);
2700 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2701 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_SYSKEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2702 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2703 ok( !ret
, "message %04x available\n", msg
.message
);
2706 static BOOL
wait_for_message( MSG
*msg
)
2712 ret
= PeekMessageA(msg
, 0, 0, 0, PM_REMOVE
);
2715 if (msg
->message
== WM_PAINT
) DispatchMessage(msg
);
2716 else if (msg
->message
< 0xc000) break; /* skip registered messages */
2718 else if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, 100, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
2720 if (!ret
) msg
->message
= 0;
2724 static void test_mouse_input(HWND hwnd
)
2734 ShowWindow(hwnd
, SW_SHOW
);
2736 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
2738 GetWindowRect(hwnd
, &rc
);
2739 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2741 popup
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_POPUP
,
2742 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
,
2745 ShowWindow(popup
, SW_SHOW
);
2746 UpdateWindow(popup
);
2747 SetWindowPos( popup
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
2749 GetWindowRect(popup
, &rc
);
2750 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2752 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
2753 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
2754 trace("setting cursor to (%d,%d)\n", x
, y
);
2758 if (x
!= pt
.x
|| y
!= pt
.y
)
2760 skip( "failed to set mouse position, skipping mouse input tests\n" );
2764 flush_events( TRUE
);
2766 /* Check that setting the same position may generate WM_MOUSEMOVE */
2770 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2771 while (ret
&& msg
.message
>= 0xc000); /* skip registered messages */
2774 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n",
2775 msg
.hwnd
, msg
.message
);
2776 ok(msg
.pt
.x
== x
&& msg
.pt
.y
== y
, "wrong message coords (%d,%d)/(%d,%d)\n",
2777 x
, y
, msg
.pt
.x
, msg
.pt
.y
);
2780 /* force the system to update its internal queue mouse position,
2781 * otherwise it won't generate relative mouse movements below.
2783 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2784 flush_events( TRUE
);
2787 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2788 flush_events( FALSE
);
2789 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2790 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
2792 if (msg
.message
== WM_TIMER
|| msg
.message
>= 0xc000) continue; /* skip registered messages */
2793 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
,
2794 "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2796 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2797 ok( !ret
, "message %04x available\n", msg
.message
);
2799 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2800 ShowWindow(popup
, SW_HIDE
);
2801 ret
= wait_for_message( &msg
);
2803 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2804 flush_events( TRUE
);
2806 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2807 ShowWindow(hwnd
, SW_HIDE
);
2808 ret
= wait_for_message( &msg
);
2809 ok( !ret
, "message %04x available\n", msg
.message
);
2810 flush_events( TRUE
);
2812 /* test mouse clicks */
2814 ShowWindow(hwnd
, SW_SHOW
);
2815 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
2816 flush_events( TRUE
);
2817 ShowWindow(popup
, SW_SHOW
);
2818 SetWindowPos( popup
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
2819 flush_events( TRUE
);
2821 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2822 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2823 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2824 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2826 ret
= wait_for_message( &msg
);
2829 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
2832 if (msg
.message
== WM_MOUSEMOVE
) /* win2k has an extra WM_MOUSEMOVE here */
2834 ret
= wait_for_message( &msg
);
2835 ok(ret
, "no message available\n");
2838 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2839 msg
.hwnd
, popup
, msg
.message
);
2841 ret
= wait_for_message( &msg
);
2842 ok(ret
, "no message available\n");
2843 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2844 msg
.hwnd
, popup
, msg
.message
);
2846 ret
= wait_for_message( &msg
);
2847 ok(ret
, "no message available\n");
2848 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p/%p message %04x\n",
2849 msg
.hwnd
, popup
, msg
.message
);
2851 ret
= wait_for_message( &msg
);
2852 ok(ret
, "no message available\n");
2853 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2854 msg
.hwnd
, popup
, msg
.message
);
2856 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2857 ok(!ret
, "message %04x available\n", msg
.message
);
2859 ShowWindow(popup
, SW_HIDE
);
2860 flush_events( TRUE
);
2862 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2863 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2864 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2865 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2867 ret
= wait_for_message( &msg
);
2868 ok(ret
, "no message available\n");
2869 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2870 msg
.hwnd
, hwnd
, msg
.message
);
2871 ret
= wait_for_message( &msg
);
2872 ok(ret
, "no message available\n");
2873 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2874 msg
.hwnd
, hwnd
, msg
.message
);
2876 test_lbuttondown_flag
= TRUE
;
2877 SendMessageA(hwnd
, WM_COMMAND
, (WPARAM
)popup
, 0);
2878 test_lbuttondown_flag
= FALSE
;
2880 ret
= wait_for_message( &msg
);
2881 ok(ret
, "no message available\n");
2882 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2883 msg
.hwnd
, popup
, msg
.message
);
2884 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2885 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2886 msg
.hwnd
, popup
, msg
.message
);
2887 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2889 /* Test WM_MOUSEACTIVATE */
2890 #define TEST_MOUSEACTIVATE(A,B) \
2891 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2892 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2894 TEST_MOUSEACTIVATE(HTERROR
,MA_ACTIVATE
);
2895 TEST_MOUSEACTIVATE(HTTRANSPARENT
,MA_ACTIVATE
);
2896 TEST_MOUSEACTIVATE(HTNOWHERE
,MA_ACTIVATE
);
2897 TEST_MOUSEACTIVATE(HTCLIENT
,MA_ACTIVATE
);
2898 TEST_MOUSEACTIVATE(HTCAPTION
,MA_ACTIVATE
);
2899 TEST_MOUSEACTIVATE(HTSYSMENU
,MA_ACTIVATE
);
2900 TEST_MOUSEACTIVATE(HTSIZE
,MA_ACTIVATE
);
2901 TEST_MOUSEACTIVATE(HTMENU
,MA_ACTIVATE
);
2902 TEST_MOUSEACTIVATE(HTHSCROLL
,MA_ACTIVATE
);
2903 TEST_MOUSEACTIVATE(HTVSCROLL
,MA_ACTIVATE
);
2904 TEST_MOUSEACTIVATE(HTMINBUTTON
,MA_ACTIVATE
);
2905 TEST_MOUSEACTIVATE(HTMAXBUTTON
,MA_ACTIVATE
);
2906 TEST_MOUSEACTIVATE(HTLEFT
,MA_ACTIVATE
);
2907 TEST_MOUSEACTIVATE(HTRIGHT
,MA_ACTIVATE
);
2908 TEST_MOUSEACTIVATE(HTTOP
,MA_ACTIVATE
);
2909 TEST_MOUSEACTIVATE(HTTOPLEFT
,MA_ACTIVATE
);
2910 TEST_MOUSEACTIVATE(HTTOPRIGHT
,MA_ACTIVATE
);
2911 TEST_MOUSEACTIVATE(HTBOTTOM
,MA_ACTIVATE
);
2912 TEST_MOUSEACTIVATE(HTBOTTOMLEFT
,MA_ACTIVATE
);
2913 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT
,MA_ACTIVATE
);
2914 TEST_MOUSEACTIVATE(HTBORDER
,MA_ACTIVATE
);
2915 TEST_MOUSEACTIVATE(HTOBJECT
,MA_ACTIVATE
);
2916 TEST_MOUSEACTIVATE(HTCLOSE
,MA_ACTIVATE
);
2917 TEST_MOUSEACTIVATE(HTHELP
,MA_ACTIVATE
);
2920 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2921 flush_events( TRUE
);
2923 DestroyWindow(popup
);
2926 static void test_validatergn(HWND hwnd
)
2932 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_VISIBLE
, 10, 10, 10, 10, hwnd
, 0, 0, NULL
);
2933 ShowWindow(hwnd
, SW_SHOW
);
2934 UpdateWindow( hwnd
);
2935 /* test that ValidateRect validates children*/
2936 InvalidateRect( child
, NULL
, 1);
2937 GetWindowRect( child
, &rc
);
2938 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2939 ret
= GetUpdateRect( child
, &rc2
, 0);
2940 ok( rc2
.right
> rc2
.left
&& rc2
.bottom
> rc2
.top
,
2941 "Update rectangle is empty!\n");
2942 ValidateRect( hwnd
, &rc
);
2943 ret
= GetUpdateRect( child
, &rc2
, 0);
2944 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2945 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
2946 rc2
.right
, rc2
.bottom
);
2948 /* now test ValidateRgn */
2949 InvalidateRect( child
, NULL
, 1);
2950 GetWindowRect( child
, &rc
);
2951 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2952 rgn
= CreateRectRgnIndirect( &rc
);
2953 ValidateRgn( hwnd
, rgn
);
2954 ret
= GetUpdateRect( child
, &rc2
, 0);
2955 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2956 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
2957 rc2
.right
, rc2
.bottom
);
2960 DestroyWindow( child
);
2963 static void nccalchelper(HWND hwnd
, INT x
, INT y
, RECT
*prc
)
2966 MoveWindow( hwnd
, 0, 0, x
, y
, 0);
2967 GetWindowRect( hwnd
, prc
);
2969 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)prc
);
2970 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
2971 rc
.left
,rc
.top
,rc
.right
,rc
.bottom
, prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
2974 static void test_nccalcscroll(HWND parent
)
2977 INT sbheight
= GetSystemMetrics( SM_CYHSCROLL
);
2978 INT sbwidth
= GetSystemMetrics( SM_CXVSCROLL
);
2979 HWND hwnd
= CreateWindowExA(0, "static", NULL
,
2980 WS_CHILD
| WS_VISIBLE
| WS_VSCROLL
| WS_HSCROLL
,
2981 10, 10, 200, 200, parent
, 0, 0, NULL
);
2982 ShowWindow( parent
, SW_SHOW
);
2983 UpdateWindow( parent
);
2985 /* test window too low for a horizontal scroll bar */
2986 nccalchelper( hwnd
, 100, sbheight
, &rc1
);
2987 ok( rc1
.bottom
- rc1
.top
== sbheight
, "Height should be %d size is %d,%d - %d,%d\n",
2988 sbheight
, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2990 /* test window just high enough for a horizontal scroll bar */
2991 nccalchelper( hwnd
, 100, sbheight
+ 1, &rc1
);
2992 ok( rc1
.bottom
- rc1
.top
== 1, "Height should be %d size is %d,%d - %d,%d\n",
2993 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2995 /* test window too narrow for a vertical scroll bar */
2996 nccalchelper( hwnd
, sbwidth
- 1, 100, &rc1
);
2997 ok( rc1
.right
- rc1
.left
== sbwidth
- 1 , "Width should be %d size is %d,%d - %d,%d\n",
2998 sbwidth
- 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3000 /* test window just wide enough for a vertical scroll bar */
3001 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
3002 ok( rc1
.right
- rc1
.left
== 0, "Width should be %d size is %d,%d - %d,%d\n",
3003 0, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3005 /* same test, but with client edge: not enough width */
3006 SetWindowLong( hwnd
, GWL_EXSTYLE
, WS_EX_CLIENTEDGE
| GetWindowLong( hwnd
, GWL_EXSTYLE
));
3007 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
3008 ok( rc1
.right
- rc1
.left
== sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
),
3009 "Width should be %d size is %d,%d - %d,%d\n",
3010 sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
), rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3012 DestroyWindow( hwnd
);
3015 static void test_SetParent(void)
3018 HWND desktop
= GetDesktopWindow();
3020 BOOL is_win9x
= GetWindowLongPtrW(desktop
, GWLP_WNDPROC
) == 0;
3021 HWND parent
, child1
, child2
, child3
, child4
, sibling
;
3023 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
3024 100, 100, 200, 200, 0, 0, 0, NULL
);
3025 assert(parent
!= 0);
3026 child1
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
3027 0, 0, 50, 50, parent
, 0, 0, NULL
);
3028 assert(child1
!= 0);
3029 child2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
3030 0, 0, 50, 50, child1
, 0, 0, NULL
);
3031 assert(child2
!= 0);
3032 child3
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
3033 0, 0, 50, 50, child2
, 0, 0, NULL
);
3034 assert(child3
!= 0);
3035 child4
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
3036 0, 0, 50, 50, child3
, 0, 0, NULL
);
3037 assert(child4
!= 0);
3039 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
3040 parent
, child1
, child2
, child3
, child4
);
3042 check_parents(parent
, desktop
, 0, 0, 0, parent
, parent
);
3043 check_parents(child1
, parent
, parent
, parent
, 0, parent
, parent
);
3044 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
3045 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
3046 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
3048 ok(!IsChild(desktop
, parent
), "wrong parent/child %p/%p\n", desktop
, parent
);
3049 ok(!IsChild(desktop
, child1
), "wrong parent/child %p/%p\n", desktop
, child1
);
3050 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
3051 ok(!IsChild(desktop
, child3
), "wrong parent/child %p/%p\n", desktop
, child3
);
3052 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
3054 ok(IsChild(parent
, child1
), "wrong parent/child %p/%p\n", parent
, child1
);
3055 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
3056 ok(!IsChild(parent
, child2
), "wrong parent/child %p/%p\n", parent
, child2
);
3057 ok(!IsChild(child1
, child2
), "wrong parent/child %p/%p\n", child1
, child2
);
3058 ok(!IsChild(parent
, child3
), "wrong parent/child %p/%p\n", parent
, child3
);
3059 ok(IsChild(child2
, child3
), "wrong parent/child %p/%p\n", child2
, child3
);
3060 ok(!IsChild(parent
, child4
), "wrong parent/child %p/%p\n", parent
, child4
);
3061 ok(!IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
3062 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
3064 if (!is_win9x
) /* Win9x doesn't survive this test */
3066 ok(!SetParent(parent
, child1
), "SetParent should fail\n");
3067 ok(!SetParent(child2
, child3
), "SetParent should fail\n");
3068 ok(SetParent(child1
, parent
) != 0, "SetParent should not fail\n");
3069 ok(SetParent(parent
, child2
) != 0, "SetParent should not fail\n");
3070 ok(SetParent(parent
, child3
) != 0, "SetParent should not fail\n");
3071 ok(!SetParent(child2
, parent
), "SetParent should fail\n");
3072 ok(SetParent(parent
, child4
) != 0, "SetParent should not fail\n");
3074 check_parents(parent
, child4
, child4
, 0, 0, child4
, parent
);
3075 check_parents(child1
, parent
, parent
, parent
, 0, child4
, parent
);
3076 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
3077 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
3078 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
3081 hMenu
= CreateMenu();
3082 sibling
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
3083 100, 100, 200, 200, 0, hMenu
, 0, NULL
);
3084 assert(sibling
!= 0);
3086 ok(SetParent(sibling
, parent
) != 0, "SetParent should not fail\n");
3087 ok(GetMenu(sibling
) == hMenu
, "SetParent should not remove menu\n");
3089 ret
= DestroyWindow(parent
);
3090 ok( ret
, "DestroyWindow() error %d\n", GetLastError());
3092 ok(!IsWindow(parent
), "parent still exists\n");
3093 ok(!IsWindow(sibling
), "sibling still exists\n");
3094 ok(!IsWindow(child1
), "child1 still exists\n");
3095 ok(!IsWindow(child2
), "child2 still exists\n");
3096 ok(!IsWindow(child3
), "child3 still exists\n");
3097 ok(!IsWindow(child4
), "child4 still exists\n");
3100 static LRESULT WINAPI
StyleCheckProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3102 LPCREATESTRUCT lpcs
;
3109 lpcs
= (LPCREATESTRUCT
)lparam
;
3110 lpss
= lpcs
->lpCreateParams
;
3113 if ((lpcs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
3114 ((!(lpcs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
3115 (lpcs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
3116 ok(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
, "Window should have WS_EX_WINDOWEDGE style\n");
3118 ok(!(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3120 ok((lpss
->styleOld
& ~WS_EX_WINDOWEDGE
) == (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
),
3121 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
3122 (lpss
->styleOld
& ~WS_EX_WINDOWEDGE
), (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
));
3124 ok(lpss
->styleNew
== lpcs
->style
,
3125 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3126 lpss
->styleNew
, lpcs
->style
);
3130 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3133 static ATOM atomStyleCheckClass
;
3135 static void register_style_check_class(void)
3143 GetModuleHandle(NULL
),
3145 LoadCursor(NULL
, IDC_ARROW
),
3146 (HBRUSH
)(COLOR_BTNFACE
+1),
3148 TEXT("WineStyleCheck"),
3151 atomStyleCheckClass
= RegisterClass(&wc
);
3154 static void check_window_style(DWORD dwStyleIn
, DWORD dwExStyleIn
, DWORD dwStyleOut
, DWORD dwExStyleOut
)
3156 DWORD dwActualStyle
;
3157 DWORD dwActualExStyle
;
3160 HWND hwndParent
= NULL
;
3162 ss
.styleNew
= dwStyleIn
;
3163 ss
.styleOld
= dwExStyleIn
;
3165 if (dwStyleIn
& WS_CHILD
)
3167 hwndParent
= CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3168 WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
3171 hwnd
= CreateWindowEx(dwExStyleIn
, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3172 dwStyleIn
, 0, 0, 0, 0, hwndParent
, NULL
, NULL
, &ss
);
3175 flush_events( TRUE
);
3177 dwActualStyle
= GetWindowLong(hwnd
, GWL_STYLE
);
3178 dwActualExStyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
3179 ok((dwActualStyle
== dwStyleOut
) && (dwActualExStyle
== dwExStyleOut
),
3180 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3181 dwActualStyle
, dwStyleOut
, dwActualExStyle
, dwExStyleOut
);
3183 DestroyWindow(hwnd
);
3184 if (hwndParent
) DestroyWindow(hwndParent
);
3187 /* tests what window styles the window manager automatically adds */
3188 static void test_window_styles(void)
3190 register_style_check_class();
3192 check_window_style(0, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
3193 check_window_style(WS_OVERLAPPEDWINDOW
, 0, WS_CLIPSIBLINGS
|WS_OVERLAPPEDWINDOW
, WS_EX_WINDOWEDGE
);
3194 check_window_style(WS_CHILD
, 0, WS_CHILD
, 0);
3195 check_window_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
3196 check_window_style(0, WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_TOOLWINDOW
);
3197 check_window_style(WS_POPUP
, 0, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3198 check_window_style(WS_POPUP
, WS_EX_WINDOWEDGE
, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3199 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
, WS_CHILD
, WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3200 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
|WS_EX_STATICEDGE
, WS_CHILD
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3201 check_window_style(WS_CAPTION
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
);
3202 check_window_style(0, WS_EX_APPWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_APPWINDOW
|WS_EX_WINDOWEDGE
);
3205 static void test_scrollvalidate( HWND parent
)
3208 HRGN hrgn
=CreateRectRgn(0,0,0,0);
3209 HRGN exprgn
, tmprgn
, clipping
;
3210 RECT rc
, rcu
, cliprc
;
3211 /* create two overlapping child windows. The visual region
3212 * of hwnd1 is clipped by the overlapping part of
3213 * hwnd2 because of the WS_CLIPSIBLING style */
3216 clipping
= CreateRectRgn(0,0,0,0);
3217 tmprgn
= CreateRectRgn(0,0,0,0);
3218 exprgn
= CreateRectRgn(0,0,0,0);
3219 hwnd2
= CreateWindowExA(0, "static", NULL
,
3220 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3221 75, 30, 100, 100, parent
, 0, 0, NULL
);
3222 hwnd1
= CreateWindowExA(0, "static", NULL
,
3223 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3224 25, 50, 100, 100, parent
, 0, 0, NULL
);
3225 ShowWindow( parent
, SW_SHOW
);
3226 UpdateWindow( parent
);
3227 GetClientRect( hwnd1
, &rc
);
3229 SetRectRgn( clipping
, 10, 10, 90, 90);
3230 hdc
= GetDC( hwnd1
);
3231 /* for a visual touch */
3232 TextOut( hdc
, 0,10, "0123456789", 10);
3233 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3234 if (winetest_debug
> 0) dump_region(hrgn
);
3235 /* create a region with what is expected */
3236 SetRectRgn( exprgn
, 39,0,49,74);
3237 SetRectRgn( tmprgn
, 88,79,98,93);
3238 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3239 SetRectRgn( tmprgn
, 0,93,98,98);
3240 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3241 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3242 trace("update rect is %d,%d - %d,%d\n",
3243 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3244 /* now with clipping region */
3245 SelectClipRgn( hdc
, clipping
);
3246 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3247 if (winetest_debug
> 0) dump_region(hrgn
);
3248 /* create a region with what is expected */
3249 SetRectRgn( exprgn
, 39,10,49,74);
3250 SetRectRgn( tmprgn
, 80,79,90,85);
3251 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3252 SetRectRgn( tmprgn
, 10,85,90,90);
3253 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3254 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3255 trace("update rect is %d,%d - %d,%d\n",
3256 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3257 ReleaseDC( hwnd1
, hdc
);
3259 /* test scrolling a window with an update region */
3260 DestroyWindow( hwnd2
);
3261 ValidateRect( hwnd1
, NULL
);
3262 SetRect( &rc
, 40,40, 50,50);
3263 InvalidateRect( hwnd1
, &rc
, 1);
3264 GetClientRect( hwnd1
, &rc
);
3266 ScrollWindowEx( hwnd1
, -10, 0, &rc
, &cliprc
, hrgn
, &rcu
,
3267 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3268 if (winetest_debug
> 0) dump_region(hrgn
);
3269 SetRectRgn( exprgn
, 88,0,98,98);
3270 SetRectRgn( tmprgn
, 30, 40, 50, 50);
3271 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3272 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3274 /* clear an update region */
3275 UpdateWindow( hwnd1
);
3277 SetRect( &rc
, 0,40, 100,60);
3278 SetRect( &cliprc
, 0,0, 100,100);
3279 ScrollWindowEx( hwnd1
, 0, -25, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3280 if (winetest_debug
> 0) dump_region( hrgn
);
3281 SetRectRgn( exprgn
, 0, 40, 98, 60 );
3282 ok( EqualRgn( exprgn
, hrgn
), "wrong update region in excessive scroll\n");
3284 /* now test ScrollWindowEx with a combination of
3285 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3286 /* make hwnd2 the child of hwnd1 */
3287 hwnd2
= CreateWindowExA(0, "static", NULL
,
3288 WS_CHILD
| WS_VISIBLE
| WS_BORDER
,
3289 50, 50, 100, 100, hwnd1
, 0, 0, NULL
);
3290 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPSIBLINGS
);
3291 GetClientRect( hwnd1
, &rc
);
3294 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3295 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3296 ValidateRect( hwnd1
, NULL
);
3297 ValidateRect( hwnd2
, NULL
);
3298 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
,
3299 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3300 if (winetest_debug
> 0) dump_region(hrgn
);
3301 SetRectRgn( exprgn
, 88,0,98,88);
3302 SetRectRgn( tmprgn
, 0,88,98,98);
3303 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3304 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3306 /* SW_SCROLLCHILDREN */
3307 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3308 ValidateRect( hwnd1
, NULL
);
3309 ValidateRect( hwnd2
, NULL
);
3310 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3311 if (winetest_debug
> 0) dump_region(hrgn
);
3312 /* expected region is the same as in previous test */
3313 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3315 /* no SW_SCROLLCHILDREN */
3316 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3317 ValidateRect( hwnd1
, NULL
);
3318 ValidateRect( hwnd2
, NULL
);
3319 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3320 if (winetest_debug
> 0) dump_region(hrgn
);
3321 /* expected region is the same as in previous test */
3322 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3324 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3325 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3326 ValidateRect( hwnd1
, NULL
);
3327 ValidateRect( hwnd2
, NULL
);
3328 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3329 if (winetest_debug
> 0) dump_region(hrgn
);
3330 SetRectRgn( exprgn
, 88,0,98,20);
3331 SetRectRgn( tmprgn
, 20,20,98,30);
3332 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3333 SetRectRgn( tmprgn
, 20,30,30,88);
3334 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3335 SetRectRgn( tmprgn
, 0,88,30,98);
3336 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3337 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3340 DeleteObject( hrgn
);
3341 DeleteObject( exprgn
);
3342 DeleteObject( tmprgn
);
3343 DestroyWindow( hwnd1
);
3344 DestroyWindow( hwnd2
);
3347 /* couple of tests of return values of scrollbar functions
3348 * called on a scrollbarless window */
3349 static void test_scroll(void)
3354 HWND hwnd
= CreateWindowExA(0, "Static", "Wine test window",
3355 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_POPUP
,
3356 100, 100, 200, 200, 0, 0, 0, NULL
);
3358 ret
= GetScrollRange( hwnd
, SB_HORZ
, &min
, &max
);
3359 if (!ret
) /* win9x */
3361 win_skip( "GetScrollRange doesn't work\n" );
3362 DestroyWindow( hwnd
);
3365 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3366 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3367 si
.cbSize
= sizeof( si
);
3368 si
.fMask
= SIF_PAGE
;
3369 si
.nPage
= 0xdeadbeef;
3370 ret
= GetScrollInfo( hwnd
, SB_HORZ
, &si
);
3371 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3372 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3374 ret
= GetScrollRange( hwnd
, SB_VERT
, &min
, &max
);
3375 ok( ret
, "GetScrollRange returns FALSE\n");
3376 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3377 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3378 si
.cbSize
= sizeof( si
);
3379 si
.fMask
= SIF_PAGE
;
3380 si
.nPage
= 0xdeadbeef;
3381 ret
= GetScrollInfo( hwnd
, SB_VERT
, &si
);
3382 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3383 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3385 DestroyWindow( hwnd
);
3388 static void test_scrolldc( HWND parent
)
3391 HRGN exprgn
, tmprgn
, hrgn
;
3392 RECT rc
, rc2
, rcu
, cliprc
;
3396 hrgn
= CreateRectRgn(0,0,0,0);
3397 tmprgn
= CreateRectRgn(0,0,0,0);
3398 exprgn
= CreateRectRgn(0,0,0,0);
3400 hwnd1
= CreateWindowExA(0, "static", NULL
,
3401 WS_CHILD
| WS_VISIBLE
,
3402 25, 50, 100, 100, parent
, 0, 0, NULL
);
3403 ShowWindow( parent
, SW_SHOW
);
3404 UpdateWindow( parent
);
3405 flush_events( TRUE
);
3406 GetClientRect( hwnd1
, &rc
);
3407 hdc
= GetDC( hwnd1
);
3408 /* paint the upper half of the window black */
3410 rc2
.bottom
= ( rc
.top
+ rc
.bottom
) /2;
3411 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3412 /* clip region is the lower half */
3414 cliprc
.top
= (rc
.top
+ rc
.bottom
) /2;
3415 /* test whether scrolled pixels are properly clipped */
3416 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3417 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3418 /* this scroll should not cause any visible changes */
3419 ScrollDC( hdc
, 5, -20, &rc
, &cliprc
, hrgn
, &rcu
);
3420 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3421 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3422 /* test with NULL clip rect */
3423 ScrollDC( hdc
, 20, -20, &rc
, NULL
, hrgn
, &rcu
);
3424 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3425 trace("update rect: %d,%d - %d,%d\n",
3426 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3427 if (winetest_debug
> 0) dump_region(hrgn
);
3428 SetRect(&rc2
, 0, 0, 100, 100);
3429 ok(EqualRect(&rcu
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3430 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
3432 SetRectRgn( exprgn
, 0, 0, 20, 80);
3433 SetRectRgn( tmprgn
, 0, 80, 100, 100);
3434 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3435 if (winetest_debug
> 0) dump_region(exprgn
);
3436 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3437 /* test clip rect > scroll rect */
3438 FillRect( hdc
, &rc
, GetStockObject(WHITE_BRUSH
));
3440 InflateRect( &rc2
, -(rc
.right
-rc
.left
)/4, -(rc
.bottom
-rc
.top
)/4);
3441 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3442 ScrollDC( hdc
, 10, 10, &rc2
, &rc
, hrgn
, &rcu
);
3443 SetRectRgn( exprgn
, 25, 25, 75, 35);
3444 SetRectRgn( tmprgn
, 25, 35, 35, 75);
3445 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3446 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3447 trace("update rect: %d,%d - %d,%d\n",
3448 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3449 if (winetest_debug
> 0) dump_region(hrgn
);
3453 DeleteObject(exprgn
);
3454 DeleteObject(tmprgn
);
3455 DestroyWindow(hwnd1
);
3458 static void test_params(void)
3463 /* Just a param check */
3464 if (pGetMonitorInfoA
)
3466 SetLastError(0xdeadbeef);
3467 rc
= GetWindowText(hwndMain2
, NULL
, 1024);
3468 ok( rc
==0, "GetWindowText: rc=%d err=%d\n",rc
,GetLastError());
3472 /* Skips actually on Win95 and NT4 */
3473 win_skip("Test would crash on Win95\n");
3476 SetLastError(0xdeadbeef);
3477 hwnd
=CreateWindow("LISTBOX", "TestList",
3478 (LBS_STANDARD
& ~LBS_SORT
),
3480 NULL
, (HMENU
)1, NULL
, 0);
3482 ok(!hwnd
|| broken(hwnd
!= NULL
), /* w2k3 sp2 */
3483 "CreateWindow with invalid menu handle should fail\n");
3485 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
|| /* NT */
3486 GetLastError() == 0xdeadbeef, /* Win9x */
3487 "wrong last error value %d\n", GetLastError());
3490 static void test_AWRwindow(LPCSTR
class, LONG style
, LONG exStyle
, BOOL menu
)
3494 hwnd
= CreateWindowEx(exStyle
, class, class, style
,
3501 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style
, exStyle
);
3504 ShowWindow(hwnd
, SW_SHOW
);
3506 test_nonclient_area(hwnd
);
3509 DestroyWindow(hwnd
);
3512 static BOOL
AWR_init(void)
3516 class.style
= CS_HREDRAW
| CS_VREDRAW
;
3517 class.lpfnWndProc
= DefWindowProcA
;
3518 class.cbClsExtra
= 0;
3519 class.cbWndExtra
= 0;
3520 class.hInstance
= 0;
3521 class.hIcon
= LoadIcon (0, IDI_APPLICATION
);
3522 class.hCursor
= LoadCursor (0, IDC_ARROW
);
3523 class.hbrBackground
= 0;
3524 class.lpszMenuName
= 0;
3525 class.lpszClassName
= szAWRClass
;
3527 if (!RegisterClass (&class)) {
3528 ok(FALSE
, "RegisterClass failed\n");
3532 hmenu
= CreateMenu();
3535 ok(hmenu
!= 0, "Failed to create menu\n");
3536 ok(AppendMenu(hmenu
, MF_STRING
, 1, "Test!"), "Failed to create menu item\n");
3542 static void test_AWR_window_size(BOOL menu
)
3546 WS_MAXIMIZE
, WS_BORDER
, WS_DLGFRAME
,
3549 WS_MINIMIZEBOX
, WS_MAXIMIZEBOX
,
3550 WS_HSCROLL
, WS_VSCROLL
3554 WS_EX_TOOLWINDOW
, WS_EX_WINDOWEDGE
,
3557 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3558 WS_EX_DLGMODALFRAME
,
3565 /* A exhaustive check of all the styles takes too long
3566 * so just do a (hopefully representative) sample
3568 for (i
= 0; i
< COUNTOF(styles
); ++i
)
3569 test_AWRwindow(szAWRClass
, styles
[i
], 0, menu
);
3570 for (i
= 0; i
< COUNTOF(exStyles
); ++i
) {
3571 test_AWRwindow(szAWRClass
, WS_POPUP
, exStyles
[i
], menu
);
3572 test_AWRwindow(szAWRClass
, WS_THICKFRAME
, exStyles
[i
], menu
);
3577 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3579 static void test_AdjustWindowRect(void)
3584 SHOWSYSMETRIC(SM_CYCAPTION
);
3585 SHOWSYSMETRIC(SM_CYSMCAPTION
);
3586 SHOWSYSMETRIC(SM_CYMENU
);
3587 SHOWSYSMETRIC(SM_CXEDGE
);
3588 SHOWSYSMETRIC(SM_CYEDGE
);
3589 SHOWSYSMETRIC(SM_CXVSCROLL
);
3590 SHOWSYSMETRIC(SM_CYHSCROLL
);
3591 SHOWSYSMETRIC(SM_CXFRAME
);
3592 SHOWSYSMETRIC(SM_CYFRAME
);
3593 SHOWSYSMETRIC(SM_CXDLGFRAME
);
3594 SHOWSYSMETRIC(SM_CYDLGFRAME
);
3595 SHOWSYSMETRIC(SM_CXBORDER
);
3596 SHOWSYSMETRIC(SM_CYBORDER
);
3598 test_AWR_window_size(FALSE
);
3599 test_AWR_window_size(TRUE
);
3603 #undef SHOWSYSMETRIC
3606 /* Global variables to trigger exit from loop */
3607 static int redrawComplete
, WMPAINT_count
;
3609 static LRESULT WINAPI
redraw_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3614 trace("doing WM_PAINT %d\n", WMPAINT_count
);
3616 if (WMPAINT_count
> 10 && redrawComplete
== 0) {
3618 BeginPaint(hwnd
, &ps
);
3619 EndPaint(hwnd
, &ps
);
3624 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3627 /* Ensure we exit from RedrawNow regardless of invalidated area */
3628 static void test_redrawnow(void)
3633 cls
.style
= CS_DBLCLKS
;
3634 cls
.lpfnWndProc
= redraw_window_procA
;
3637 cls
.hInstance
= GetModuleHandleA(0);
3639 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
3640 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3641 cls
.lpszMenuName
= NULL
;
3642 cls
.lpszClassName
= "RedrawWindowClass";
3644 if(!RegisterClassA(&cls
)) {
3645 trace("Register failed %d\n", GetLastError());
3649 hwndMain
= CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3650 CW_USEDEFAULT
, 0, 100, 100, NULL
, NULL
, 0, NULL
);
3652 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3653 ShowWindow(hwndMain
, SW_SHOW
);
3654 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3655 RedrawWindow(hwndMain
, NULL
,NULL
,RDW_UPDATENOW
| RDW_ALLCHILDREN
);
3656 ok( WMPAINT_count
== 1 || broken(WMPAINT_count
== 0), /* sometimes on win9x */
3657 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3658 redrawComplete
= TRUE
;
3659 ok( WMPAINT_count
< 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count
);
3662 DestroyWindow( hwndMain
);
3665 struct parentdc_stat
{
3671 struct parentdc_test
{
3672 struct parentdc_stat main
, main_todo
;
3673 struct parentdc_stat child1
, child1_todo
;
3674 struct parentdc_stat child2
, child2_todo
;
3677 static LRESULT WINAPI
parentdc_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3682 struct parentdc_stat
*t
= (struct parentdc_stat
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
3687 GetClientRect(hwnd
, &rc
);
3688 CopyRect(&t
->client
, &rc
);
3689 GetWindowRect(hwnd
, &rc
);
3690 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd
,
3691 t
->client
.left
, t
->client
.top
, t
->client
.right
, t
->client
.bottom
,
3692 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3693 BeginPaint(hwnd
, &ps
);
3694 CopyRect(&t
->paint
, &ps
.rcPaint
);
3695 GetClipBox(ps
.hdc
, &rc
);
3696 CopyRect(&t
->clip
, &rc
);
3697 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
3698 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
3699 ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
3700 EndPaint(hwnd
, &ps
);
3703 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3706 static void zero_parentdc_stat(struct parentdc_stat
*t
)
3708 SetRectEmpty(&t
->client
);
3709 SetRectEmpty(&t
->clip
);
3710 SetRectEmpty(&t
->paint
);
3713 static void zero_parentdc_test(struct parentdc_test
*t
)
3715 zero_parentdc_stat(&t
->main
);
3716 zero_parentdc_stat(&t
->child1
);
3717 zero_parentdc_stat(&t
->child2
);
3720 #define parentdc_field_ok(t, w, r, f, got) \
3721 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3722 ": expected %d, got %d\n", \
3725 #define parentdc_todo_field_ok(t, w, r, f, got) \
3726 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3727 else parentdc_field_ok(t, w, r, f, got)
3729 #define parentdc_rect_ok(t, w, r, got) \
3730 parentdc_todo_field_ok(t, w, r, left, got); \
3731 parentdc_todo_field_ok(t, w, r, top, got); \
3732 parentdc_todo_field_ok(t, w, r, right, got); \
3733 parentdc_todo_field_ok(t, w, r, bottom, got);
3735 #define parentdc_win_ok(t, w, got) \
3736 parentdc_rect_ok(t, w, client, got); \
3737 parentdc_rect_ok(t, w, clip, got); \
3738 parentdc_rect_ok(t, w, paint, got);
3740 #define parentdc_ok(t, got) \
3741 parentdc_win_ok(t, main, got); \
3742 parentdc_win_ok(t, child1, got); \
3743 parentdc_win_ok(t, child2, got);
3745 static void test_csparentdc(void)
3747 WNDCLASSA clsMain
, cls
;
3748 HWND hwndMain
, hwnd1
, hwnd2
;
3751 struct parentdc_test test_answer
;
3753 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3754 const struct parentdc_test test1
=
3756 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo
,
3757 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3758 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3761 const struct parentdc_test test2
=
3763 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo
,
3764 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3765 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3768 const struct parentdc_test test3
=
3770 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3771 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3772 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3775 const struct parentdc_test test4
=
3777 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo
,
3778 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo
,
3779 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3782 const struct parentdc_test test5
=
3784 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo
,
3785 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3786 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3789 const struct parentdc_test test6
=
3791 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3792 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3793 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3796 const struct parentdc_test test7
=
3798 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3799 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3800 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3804 clsMain
.style
= CS_DBLCLKS
;
3805 clsMain
.lpfnWndProc
= parentdc_window_procA
;
3806 clsMain
.cbClsExtra
= 0;
3807 clsMain
.cbWndExtra
= 0;
3808 clsMain
.hInstance
= GetModuleHandleA(0);
3810 clsMain
.hCursor
= LoadCursorA(0, IDC_ARROW
);
3811 clsMain
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3812 clsMain
.lpszMenuName
= NULL
;
3813 clsMain
.lpszClassName
= "ParentDcMainWindowClass";
3815 if(!RegisterClassA(&clsMain
)) {
3816 trace("Register failed %d\n", GetLastError());
3820 cls
.style
= CS_DBLCLKS
| CS_PARENTDC
;
3821 cls
.lpfnWndProc
= parentdc_window_procA
;
3824 cls
.hInstance
= GetModuleHandleA(0);
3826 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
3827 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3828 cls
.lpszMenuName
= NULL
;
3829 cls
.lpszClassName
= "ParentDcWindowClass";
3831 if(!RegisterClassA(&cls
)) {
3832 trace("Register failed %d\n", GetLastError());
3836 SetRect(&rc
, 0, 0, 150, 150);
3837 AdjustWindowRectEx(&rc
, WS_OVERLAPPEDWINDOW
, FALSE
, 0);
3838 hwndMain
= CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3839 CW_USEDEFAULT
, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, NULL
, NULL
, 0, NULL
);
3840 SetWindowLongPtrA(hwndMain
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.main
);
3841 hwnd1
= CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD
,
3842 20, 20, 40, 40, hwndMain
, NULL
, 0, NULL
);
3843 SetWindowLongPtrA(hwnd1
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child1
);
3844 hwnd2
= CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD
,
3845 40, 40, 40, 40, hwndMain
, NULL
, 0, NULL
);
3846 SetWindowLongPtrA(hwnd2
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child2
);
3847 ShowWindow(hwndMain
, SW_SHOW
);
3848 ShowWindow(hwnd1
, SW_SHOW
);
3849 ShowWindow(hwnd2
, SW_SHOW
);
3850 SetWindowPos(hwndMain
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3851 flush_events( TRUE
);
3853 zero_parentdc_test(&test_answer
);
3854 InvalidateRect(hwndMain
, NULL
, TRUE
);
3855 flush_events( TRUE
);
3856 parentdc_ok(test1
, test_answer
);
3858 zero_parentdc_test(&test_answer
);
3859 SetRect(&rc
, 0, 0, 50, 50);
3860 InvalidateRect(hwndMain
, &rc
, TRUE
);
3861 flush_events( TRUE
);
3862 parentdc_ok(test2
, test_answer
);
3864 zero_parentdc_test(&test_answer
);
3865 SetRect(&rc
, 0, 0, 10, 10);
3866 InvalidateRect(hwndMain
, &rc
, TRUE
);
3867 flush_events( TRUE
);
3868 parentdc_ok(test3
, test_answer
);
3870 zero_parentdc_test(&test_answer
);
3871 SetRect(&rc
, 40, 40, 50, 50);
3872 InvalidateRect(hwndMain
, &rc
, TRUE
);
3873 flush_events( TRUE
);
3874 parentdc_ok(test4
, test_answer
);
3876 zero_parentdc_test(&test_answer
);
3877 SetRect(&rc
, 20, 20, 60, 60);
3878 InvalidateRect(hwndMain
, &rc
, TRUE
);
3879 flush_events( TRUE
);
3880 parentdc_ok(test5
, test_answer
);
3882 zero_parentdc_test(&test_answer
);
3883 SetRect(&rc
, 0, 0, 10, 10);
3884 InvalidateRect(hwnd1
, &rc
, TRUE
);
3885 flush_events( TRUE
);
3886 parentdc_ok(test6
, test_answer
);
3888 zero_parentdc_test(&test_answer
);
3889 SetRect(&rc
, -5, -5, 65, 65);
3890 InvalidateRect(hwnd1
, &rc
, TRUE
);
3891 flush_events( TRUE
);
3892 parentdc_ok(test7
, test_answer
);
3894 DestroyWindow(hwndMain
);
3895 DestroyWindow(hwnd1
);
3896 DestroyWindow(hwnd2
);
3899 static LRESULT WINAPI
def_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3901 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
3904 static LRESULT WINAPI
def_window_procW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3906 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
3909 static void test_IsWindowUnicode(void)
3911 static const char ansi_class_nameA
[] = "ansi class name";
3912 static const WCHAR ansi_class_nameW
[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3913 static const char unicode_class_nameA
[] = "unicode class name";
3914 static const WCHAR unicode_class_nameW
[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3919 memset(&classW
, 0, sizeof(classW
));
3920 classW
.hInstance
= GetModuleHandleA(0);
3921 classW
.lpfnWndProc
= def_window_procW
;
3922 classW
.lpszClassName
= unicode_class_nameW
;
3923 if (!RegisterClassW(&classW
)) return; /* this catches Win9x as well */
3925 memset(&classA
, 0, sizeof(classA
));
3926 classA
.hInstance
= GetModuleHandleA(0);
3927 classA
.lpfnWndProc
= def_window_procA
;
3928 classA
.lpszClassName
= ansi_class_nameA
;
3929 assert(RegisterClassA(&classA
));
3931 /* unicode class: window proc */
3932 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
3933 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3936 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3937 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3938 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3939 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3940 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3942 DestroyWindow(hwnd
);
3944 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
3945 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3948 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3949 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3950 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3951 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3952 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3954 DestroyWindow(hwnd
);
3956 /* ansi class: window proc */
3957 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
3958 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3961 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3962 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3963 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3964 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3965 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3967 DestroyWindow(hwnd
);
3969 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
3970 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3973 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3974 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3975 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3976 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3977 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3979 DestroyWindow(hwnd
);
3981 /* unicode class: class proc */
3982 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
3983 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3986 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3987 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3988 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3989 /* do not restore class window proc back to unicode */
3991 DestroyWindow(hwnd
);
3993 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
3994 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3997 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3998 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3999 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4001 DestroyWindow(hwnd
);
4003 /* ansi class: class proc */
4004 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
4005 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4008 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4009 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
4010 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4011 /* do not restore class window proc back to ansi */
4013 DestroyWindow(hwnd
);
4015 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
4016 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4019 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4020 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
4021 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4023 DestroyWindow(hwnd
);
4026 static LRESULT CALLBACK
minmax_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
4030 if (msg
!= WM_GETMINMAXINFO
)
4031 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4033 minmax
= (MINMAXINFO
*)lp
;
4035 if ((GetWindowLong(hwnd
, GWL_STYLE
) & WS_CHILD
))
4037 minmax
->ptReserved
.x
= 0;
4038 minmax
->ptReserved
.y
= 0;
4039 minmax
->ptMaxSize
.x
= 400;
4040 minmax
->ptMaxSize
.y
= 400;
4041 minmax
->ptMaxPosition
.x
= 300;
4042 minmax
->ptMaxPosition
.y
= 300;
4043 minmax
->ptMaxTrackSize
.x
= 200;
4044 minmax
->ptMaxTrackSize
.y
= 200;
4045 minmax
->ptMinTrackSize
.x
= 100;
4046 minmax
->ptMinTrackSize
.y
= 100;
4049 DefWindowProc(hwnd
, msg
, wp
, lp
);
4053 static int expected_cx
, expected_cy
;
4054 static RECT expected_rect
, broken_rect
;
4056 static LRESULT CALLBACK
winsizes_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
4060 case WM_GETMINMAXINFO
:
4063 GetWindowRect( hwnd
, &rect
);
4064 ok( !rect
.left
&& !rect
.top
&& !rect
.right
&& !rect
.bottom
,
4065 "wrong rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4066 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4071 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
4073 GetWindowRect( hwnd
, &rect
);
4074 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
4075 hwnd
, msg
, cs
->cx
, cs
->cy
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4076 ok( cs
->cx
== expected_cx
|| broken(cs
->cx
== (short)expected_cx
),
4077 "wrong x size %d/%d\n", cs
->cx
, expected_cx
);
4078 ok( cs
->cy
== expected_cy
|| broken(cs
->cy
== (short)expected_cy
),
4079 "wrong y size %d/%d\n", cs
->cy
, expected_cy
);
4080 ok( (rect
.right
- rect
.left
== expected_rect
.right
- expected_rect
.left
&&
4081 rect
.bottom
- rect
.top
== expected_rect
.bottom
- expected_rect
.top
) ||
4082 broken( rect
.right
- rect
.left
== broken_rect
.right
- broken_rect
.left
&&
4083 rect
.bottom
- rect
.top
== broken_rect
.bottom
- broken_rect
.top
) ||
4084 broken( rect
.right
- rect
.left
== (short)broken_rect
.right
- (short)broken_rect
.left
&&
4085 rect
.bottom
- rect
.top
== (short)broken_rect
.bottom
- (short)broken_rect
.top
),
4086 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
4087 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
4088 expected_rect
.left
, expected_rect
.top
, expected_rect
.right
, expected_rect
.bottom
);
4089 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4093 RECT rect
, *r
= (RECT
*)lp
;
4094 GetWindowRect( hwnd
, &rect
);
4095 ok( !memcmp( &rect
, r
, sizeof(rect
) ),
4096 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
4097 r
->left
, r
->top
, r
->right
, r
->bottom
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4098 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4101 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4105 static void test_CreateWindow(void)
4113 #define expect_menu(window, menu) \
4114 SetLastError(0xdeadbeef); \
4115 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
4117 #define expect_style(window, style)\
4118 ok((ULONG)GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
4120 #define expect_ex_style(window, ex_style)\
4121 ok((ULONG)GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
4123 #define expect_gle_broken_9x(gle)\
4124 ok(GetLastError() == gle ||\
4125 broken(GetLastError() == 0xdeadbeef),\
4126 "IsMenu set error %d\n", GetLastError())
4128 hmenu
= CreateMenu();
4130 parent
= GetDesktopWindow();
4131 assert(parent
!= 0);
4133 SetLastError(0xdeadbeef);
4134 ok(IsMenu(hmenu
), "IsMenu error %d\n", GetLastError());
4137 SetLastError(0xdeadbeef);
4138 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
,
4139 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4140 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4141 expect_menu(hwnd
, 1);
4142 expect_style(hwnd
, WS_CHILD
);
4143 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4144 DestroyWindow(hwnd
);
4146 SetLastError(0xdeadbeef);
4147 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_CAPTION
,
4148 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4149 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4150 expect_menu(hwnd
, 1);
4151 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
4152 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4153 DestroyWindow(hwnd
);
4155 SetLastError(0xdeadbeef);
4156 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
,
4157 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4158 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4159 expect_menu(hwnd
, 1);
4160 expect_style(hwnd
, WS_CHILD
);
4161 expect_ex_style(hwnd
, 0);
4162 DestroyWindow(hwnd
);
4164 SetLastError(0xdeadbeef);
4165 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_CAPTION
,
4166 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4167 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4168 expect_menu(hwnd
, 1);
4169 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
4170 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4171 DestroyWindow(hwnd
);
4174 SetLastError(0xdeadbeef);
4175 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
4176 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4177 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4178 expect_menu(hwnd
, hmenu
);
4179 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4180 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4181 DestroyWindow(hwnd
);
4182 SetLastError(0xdeadbeef);
4183 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4184 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4186 hmenu
= CreateMenu();
4188 SetLastError(0xdeadbeef);
4189 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4190 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4191 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4192 expect_menu(hwnd
, hmenu
);
4193 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4194 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4195 DestroyWindow(hwnd
);
4196 SetLastError(0xdeadbeef);
4197 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4198 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4200 hmenu
= CreateMenu();
4202 SetLastError(0xdeadbeef);
4203 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
,
4204 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4205 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4206 expect_menu(hwnd
, hmenu
);
4207 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4208 expect_ex_style(hwnd
, 0);
4209 DestroyWindow(hwnd
);
4210 SetLastError(0xdeadbeef);
4211 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4212 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4214 hmenu
= CreateMenu();
4216 SetLastError(0xdeadbeef);
4217 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4218 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4219 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4220 expect_menu(hwnd
, hmenu
);
4221 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4222 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4223 DestroyWindow(hwnd
);
4224 SetLastError(0xdeadbeef);
4225 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4226 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4228 /* WS_CHILD | WS_POPUP */
4229 SetLastError(0xdeadbeef);
4230 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4231 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4232 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
4233 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4235 DestroyWindow(hwnd
);
4237 hmenu
= CreateMenu();
4239 SetLastError(0xdeadbeef);
4240 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4241 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4242 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4243 expect_menu(hwnd
, hmenu
);
4244 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4245 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4246 DestroyWindow(hwnd
);
4247 SetLastError(0xdeadbeef);
4248 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4249 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4251 SetLastError(0xdeadbeef);
4252 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4253 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4254 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
4255 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4257 DestroyWindow(hwnd
);
4259 hmenu
= CreateMenu();
4261 SetLastError(0xdeadbeef);
4262 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4263 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4264 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4265 expect_menu(hwnd
, hmenu
);
4266 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4267 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4268 DestroyWindow(hwnd
);
4269 SetLastError(0xdeadbeef);
4270 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4271 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4273 SetLastError(0xdeadbeef);
4274 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4275 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4276 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
4277 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4279 DestroyWindow(hwnd
);
4281 hmenu
= CreateMenu();
4283 SetLastError(0xdeadbeef);
4284 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4285 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4286 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4287 expect_menu(hwnd
, hmenu
);
4288 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4289 expect_ex_style(hwnd
, 0);
4290 DestroyWindow(hwnd
);
4291 SetLastError(0xdeadbeef);
4292 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4293 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4295 SetLastError(0xdeadbeef);
4296 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4297 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4298 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
4299 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4301 DestroyWindow(hwnd
);
4303 hmenu
= CreateMenu();
4305 SetLastError(0xdeadbeef);
4306 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4307 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4308 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4309 expect_menu(hwnd
, hmenu
);
4310 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4311 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4312 DestroyWindow(hwnd
);
4313 SetLastError(0xdeadbeef);
4314 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4315 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4317 /* test child window sizing */
4319 cls
.lpfnWndProc
= minmax_wnd_proc
;
4322 cls
.hInstance
= GetModuleHandle(0);
4324 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
4325 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4326 cls
.lpszMenuName
= NULL
;
4327 cls
.lpszClassName
= "MinMax_WndClass";
4328 RegisterClass(&cls
);
4330 SetLastError(0xdeadbeef);
4331 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4332 0, 0, 100, 100, 0, 0, 0, NULL
);
4333 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
4334 expect_menu(parent
, 0);
4335 expect_style(parent
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
| WS_CLIPSIBLINGS
);
4336 expect_ex_style(parent
, WS_EX_WINDOWEDGE
);
4338 memset(&minmax
, 0, sizeof(minmax
));
4339 SendMessage(parent
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4340 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxSize
.x
, minmax
.ptMaxSize
.y
);
4341 ok(IsRectEmpty(&rc_minmax
), "ptMaxSize is not empty\n");
4342 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4343 ok(IsRectEmpty(&rc_minmax
), "ptMaxTrackSize is not empty\n");
4345 GetWindowRect(parent
, &rc
);
4346 ok(!IsRectEmpty(&rc
), "parent window rect is empty\n");
4347 GetClientRect(parent
, &rc
);
4348 ok(!IsRectEmpty(&rc
), "parent client rect is empty\n");
4350 InflateRect(&rc
, 200, 200);
4351 trace("creating child with rect (%d,%d-%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4353 SetLastError(0xdeadbeef);
4354 hwnd
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4355 rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
4356 parent
, (HMENU
)1, 0, NULL
);
4357 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4358 expect_menu(hwnd
, 1);
4359 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
);
4360 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4362 memset(&minmax
, 0, sizeof(minmax
));
4363 SendMessage(hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4364 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4366 GetWindowRect(hwnd
, &rc
);
4367 OffsetRect(&rc
, -rc
.left
, -rc
.top
);
4368 ok(EqualRect(&rc
, &rc_minmax
), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4369 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
4370 rc_minmax
.left
, rc_minmax
.top
, rc_minmax
.right
, rc_minmax
.bottom
);
4371 DestroyWindow(hwnd
);
4373 cls
.lpfnWndProc
= winsizes_wnd_proc
;
4374 cls
.lpszClassName
= "Sizes_WndClass";
4375 RegisterClass(&cls
);
4377 expected_cx
= expected_cy
= 200000;
4378 SetRect( &expected_rect
, 0, 0, 200000, 200000 );
4379 broken_rect
= expected_rect
;
4380 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 300000, 300000, 200000, 200000, parent
, 0, 0, NULL
);
4381 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4382 GetClientRect( hwnd
, &rc
);
4383 ok( rc
.right
== 200000 || broken(rc
.right
== (short)200000), "invalid rect right %u\n", rc
.right
);
4384 ok( rc
.bottom
== 200000 || broken(rc
.bottom
== (short)200000), "invalid rect bottom %u\n", rc
.bottom
);
4385 DestroyWindow(hwnd
);
4387 expected_cx
= expected_cy
= -10;
4388 SetRect( &expected_rect
, 0, 0, 0, 0 );
4389 SetRect( &broken_rect
, 0, 0, -10, -10 );
4390 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -20, -20, -10, -10, parent
, 0, 0, NULL
);
4391 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4392 GetClientRect( hwnd
, &rc
);
4393 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4394 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4395 DestroyWindow(hwnd
);
4397 expected_cx
= expected_cy
= -200000;
4398 SetRect( &expected_rect
, 0, 0, 0, 0 );
4399 SetRect( &broken_rect
, 0, 0, -200000, -200000 );
4400 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -300000, -300000, -200000, -200000, parent
, 0, 0, NULL
);
4401 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4402 GetClientRect( hwnd
, &rc
);
4403 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4404 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4405 DestroyWindow(hwnd
);
4407 /* we need a parent at 0,0 so that child coordinates match */
4408 DestroyWindow(parent
);
4409 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_POPUP
, 0, 0, 100, 100, 0, 0, 0, NULL
);
4410 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
4413 expected_cy
= 0x7fffffff;
4414 SetRect( &expected_rect
, 10, 10, 110, 0x7fffffff );
4415 SetRect( &broken_rect
, 10, 10, 110, 0x7fffffffU
+ 10 );
4416 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 10, 10, 100, 0x7fffffff, parent
, 0, 0, NULL
);
4417 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4418 GetClientRect( hwnd
, &rc
);
4419 ok( rc
.right
== 100, "invalid rect right %u\n", rc
.right
);
4420 ok( rc
.bottom
== 0x7fffffff - 10 || broken(rc
.bottom
== 0), "invalid rect bottom %u\n", rc
.bottom
);
4421 DestroyWindow(hwnd
);
4423 expected_cx
= 0x7fffffff;
4424 expected_cy
= 0x7fffffff;
4425 SetRect( &expected_rect
, 20, 10, 0x7fffffff, 0x7fffffff );
4426 SetRect( &broken_rect
, 20, 10, 0x7fffffffU
+ 20, 0x7fffffffU
+ 10 );
4427 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 20, 10, 0x7fffffff, 0x7fffffff, parent
, 0, 0, NULL
);
4428 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4429 GetClientRect( hwnd
, &rc
);
4430 ok( rc
.right
== 0x7fffffff - 20 || broken(rc
.right
== 0), "invalid rect right %u\n", rc
.right
);
4431 ok( rc
.bottom
== 0x7fffffff - 10 || broken(rc
.bottom
== 0), "invalid rect bottom %u\n", rc
.bottom
);
4432 DestroyWindow(hwnd
);
4434 /* top level window */
4435 expected_cx
= expected_cy
= 200000;
4436 SetRect( &expected_rect
, 0, 0, GetSystemMetrics(SM_CXMAXTRACK
), GetSystemMetrics(SM_CYMAXTRACK
) );
4437 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_OVERLAPPEDWINDOW
, 300000, 300000, 200000, 200000, 0, 0, 0, NULL
);
4438 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4439 GetClientRect( hwnd
, &rc
);
4440 ok( rc
.right
<= expected_cx
, "invalid rect right %u\n", rc
.right
);
4441 ok( rc
.bottom
<= expected_cy
, "invalid rect bottom %u\n", rc
.bottom
);
4442 DestroyWindow(hwnd
);
4444 DestroyWindow(parent
);
4446 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4447 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4449 #undef expect_gle_broken_9x
4452 #undef expect_ex_style
4455 /* function that remembers whether the system the test is running on sets the
4456 * last error for user32 functions to make the tests stricter */
4457 static int check_error(DWORD actual
, DWORD expected
)
4459 static int sets_last_error
= -1;
4460 if (sets_last_error
== -1)
4461 sets_last_error
= (actual
!= 0xdeadbeef);
4462 return (!sets_last_error
&& (actual
== 0xdeadbeef)) || (actual
== expected
);
4465 static void test_SetWindowLong(void)
4468 WNDPROC old_window_procW
;
4470 SetLastError(0xdeadbeef);
4471 retval
= SetWindowLongPtr(NULL
, GWLP_WNDPROC
, 0);
4472 ok(!retval
, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval
);
4473 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE
),
4474 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4476 SetLastError(0xdeadbeef);
4477 retval
= SetWindowLongPtr(hwndMain
, 0xdeadbeef, 0);
4478 ok(!retval
, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval
);
4479 ok(check_error(GetLastError(), ERROR_INVALID_INDEX
),
4480 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4482 SetLastError(0xdeadbeef);
4483 retval
= SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4484 ok((WNDPROC
)retval
== main_window_procA
|| broken(!retval
), /* win9x */
4485 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval
);
4486 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4487 retval
= GetWindowLongPtr(hwndMain
, GWLP_WNDPROC
);
4488 ok((WNDPROC
)retval
== main_window_procA
,
4489 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4490 ok(!IsWindowUnicode(hwndMain
), "hwndMain shouldn't be Unicode\n");
4492 old_window_procW
= (WNDPROC
)GetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
);
4493 SetLastError(0xdeadbeef);
4494 retval
= SetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
, 0);
4495 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED
)
4497 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4498 ok(retval
!= 0, "SetWindowLongPtr error %d\n", GetLastError());
4499 ok((WNDPROC
)retval
== old_window_procW
,
4500 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4501 ok(IsWindowUnicode(hwndMain
), "hwndMain should now be Unicode\n");
4503 /* set it back to ANSI */
4504 SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4508 static void test_ShowWindow(void)
4515 SetRect(&rcMain
, 120, 120, 210, 210);
4517 hwnd
= CreateWindowEx(0, "MainWindowClass", NULL
,
4518 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4519 WS_MAXIMIZEBOX
| WS_POPUP
,
4520 rcMain
.left
, rcMain
.top
,
4521 rcMain
.right
- rcMain
.left
, rcMain
.bottom
- rcMain
.top
,
4525 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4526 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4527 ok(!(style
& WS_VISIBLE
), "window should not be visible\n");
4528 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4529 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4530 GetWindowRect(hwnd
, &rc
);
4531 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4532 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4533 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4535 ret
= ShowWindow(hwnd
, SW_SHOW
);
4536 ok(!ret
, "not expected ret: %lu\n", ret
);
4537 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4538 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4539 ok(style
& WS_VISIBLE
, "window should be visible\n");
4540 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4541 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4542 GetWindowRect(hwnd
, &rc
);
4543 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4544 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4545 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4547 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4548 ok(ret
, "not expected ret: %lu\n", ret
);
4549 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4550 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4551 ok(style
& WS_VISIBLE
, "window should be visible\n");
4552 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4553 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4554 GetWindowRect(hwnd
, &rc
);
4555 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4557 ShowWindow(hwnd
, SW_RESTORE
);
4558 ok(ret
, "not expected ret: %lu\n", ret
);
4559 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4560 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4561 ok(style
& WS_VISIBLE
, "window should be visible\n");
4562 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4563 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4564 GetWindowRect(hwnd
, &rc
);
4565 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4566 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4567 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4569 ret
= EnableWindow(hwnd
, FALSE
);
4570 ok(!ret
, "not expected ret: %lu\n", ret
);
4571 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4572 ok(style
& WS_DISABLED
, "window should be disabled\n");
4574 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
4575 ok(!ret
, "not expected ret: %lu\n", ret
);
4576 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4577 ok(style
& WS_DISABLED
, "window should be disabled\n");
4578 ok(style
& WS_VISIBLE
, "window should be visible\n");
4579 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4580 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4581 GetWindowRect(hwnd
, &rc
);
4582 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4583 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4584 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4586 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
4587 ok(!ret
, "not expected ret: %lu\n", ret
);
4588 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4589 ok(style
& WS_DISABLED
, "window should be disabled\n");
4590 ok(style
& WS_VISIBLE
, "window should be visible\n");
4591 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4592 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4593 GetWindowRect(hwnd
, &rc
);
4594 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4595 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4596 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4598 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4599 ok(ret
, "not expected ret: %lu\n", ret
);
4600 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4601 ok(style
& WS_DISABLED
, "window should be disabled\n");
4602 ok(style
& WS_VISIBLE
, "window should be visible\n");
4603 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4604 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4605 GetWindowRect(hwnd
, &rc
);
4606 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4608 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
4609 ok(!ret
, "not expected ret: %lu\n", ret
);
4610 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4611 ok(style
& WS_DISABLED
, "window should be disabled\n");
4612 ok(style
& WS_VISIBLE
, "window should be visible\n");
4613 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4614 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4615 GetWindowRect(hwnd
, &rc
);
4616 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4618 ret
= ShowWindow(hwnd
, SW_RESTORE
);
4619 ok(ret
, "not expected ret: %lu\n", ret
);
4620 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4621 ok(style
& WS_DISABLED
, "window should be disabled\n");
4622 ok(style
& WS_VISIBLE
, "window should be visible\n");
4623 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4624 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4625 GetWindowRect(hwnd
, &rc
);
4626 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4627 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4628 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4630 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4631 ok(!ret
, "not expected ret: %lu\n", ret
);
4632 ok(IsWindow(hwnd
), "window should exist\n");
4634 ret
= EnableWindow(hwnd
, TRUE
);
4635 ok(ret
, "not expected ret: %lu\n", ret
);
4637 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4638 ok(!ret
, "not expected ret: %lu\n", ret
);
4639 ok(!IsWindow(hwnd
), "window should not exist\n");
4642 static void test_gettext(void)
4645 LPCSTR clsname
= "gettexttest";
4649 memset( &cls
, 0, sizeof cls
);
4650 cls
.lpfnWndProc
= DefWindowProc
;
4651 cls
.lpszClassName
= clsname
;
4652 cls
.hInstance
= GetModuleHandle(NULL
);
4654 if (!RegisterClass( &cls
)) return;
4656 hwnd
= CreateWindow( clsname
, "test text", WS_OVERLAPPED
, 0, 0, 10, 10, 0, NULL
, NULL
, NULL
);
4657 ok( hwnd
!= NULL
, "window was null\n");
4659 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10, 0x1000);
4660 ok( r
== 0, "settext should return zero\n");
4662 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10000, 0);
4663 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4665 r
= SendMessage( hwnd
, WM_GETTEXT
, 0xff000000, 0x1000);
4666 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4668 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x1000, 0xff000000);
4669 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4671 DestroyWindow(hwnd
);
4672 UnregisterClass( clsname
, NULL
);
4676 static void test_GetUpdateRect(void)
4679 BOOL ret
, parent_wm_paint
, grandparent_wm_paint
;
4681 HWND hgrandparent
, hparent
, hchild
;
4683 static const char classNameA
[] = "GetUpdateRectClass";
4685 hgrandparent
= CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW
,
4686 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4688 hparent
= CreateWindowA("static", "parent", WS_CHILD
|WS_VISIBLE
,
4689 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4691 hchild
= CreateWindowA("static", "child", WS_CHILD
|WS_VISIBLE
,
4692 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4694 ShowWindow(hgrandparent
, SW_SHOW
);
4695 UpdateWindow(hgrandparent
);
4696 flush_events( TRUE
);
4698 ShowWindow(hchild
, SW_HIDE
);
4699 SetRect(&rc2
, 0, 0, 0, 0);
4700 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4701 ok(!ret
, "GetUpdateRect returned not empty region\n");
4702 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4703 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4704 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4706 SetRect(&rc2
, 10, 10, 40, 40);
4707 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
4708 ok(ret
, "GetUpdateRect returned empty region\n");
4709 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4710 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4711 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4713 parent_wm_paint
= FALSE
;
4714 grandparent_wm_paint
= FALSE
;
4715 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
4717 if (msg
.message
== WM_PAINT
)
4719 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
4720 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
4722 DispatchMessage(&msg
);
4724 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
4725 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
4727 DestroyWindow(hgrandparent
);
4730 cls
.lpfnWndProc
= DefWindowProcA
;
4733 cls
.hInstance
= GetModuleHandleA(0);
4735 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
4736 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4737 cls
.lpszMenuName
= NULL
;
4738 cls
.lpszClassName
= classNameA
;
4740 if(!RegisterClassA(&cls
)) {
4741 trace("Register failed %d\n", GetLastError());
4745 hgrandparent
= CreateWindowA(classNameA
, "grandparent", WS_OVERLAPPEDWINDOW
,
4746 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4748 hparent
= CreateWindowA(classNameA
, "parent", WS_CHILD
|WS_VISIBLE
,
4749 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4751 hchild
= CreateWindowA(classNameA
, "child", WS_CHILD
|WS_VISIBLE
,
4752 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4754 ShowWindow(hgrandparent
, SW_SHOW
);
4755 UpdateWindow(hgrandparent
);
4756 flush_events( TRUE
);
4758 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4759 ok(!ret
, "GetUpdateRect returned not empty region\n");
4761 ShowWindow(hchild
, SW_HIDE
);
4763 SetRect(&rc2
, 0, 0, 0, 0);
4764 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4765 ok(!ret
, "GetUpdateRect returned not empty region\n");
4766 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4767 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4768 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4770 SetRect(&rc2
, 10, 10, 40, 40);
4771 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
4772 ok(ret
, "GetUpdateRect returned empty region\n");
4773 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4774 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4775 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4777 parent_wm_paint
= FALSE
;
4778 grandparent_wm_paint
= FALSE
;
4779 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
4781 if (msg
.message
== WM_PAINT
)
4783 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
4784 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
4786 DispatchMessage(&msg
);
4788 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
4789 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
4791 DestroyWindow(hgrandparent
);
4795 static LRESULT CALLBACK
TestExposedRegion_WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4803 const int waitTime
= 2000;
4805 BeginPaint(hwnd
, &ps
);
4807 /* create and destroy window to create an exposed region on this window */
4808 win
= CreateWindowA("static", "win", WS_VISIBLE
,
4809 10,10,50,50, NULL
, NULL
, 0, NULL
);
4812 waitResult
= MsgWaitForMultipleObjects( 0, NULL
, FALSE
, waitTime
, QS_PAINT
);
4814 ValidateRect(hwnd
, NULL
);
4815 EndPaint(hwnd
, &ps
);
4817 if(waitResult
!= WAIT_TIMEOUT
)
4819 GetUpdateRect(hwnd
, &updateRect
, FALSE
);
4820 ok(IsRectEmpty(&updateRect
), "Exposed rect should be empty\n");
4825 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
4828 static void test_Expose(void)
4833 memset(&cls
, 0, sizeof(WNDCLASSA
));
4834 cls
.lpfnWndProc
= TestExposedRegion_WndProc
;
4835 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4836 cls
.lpszClassName
= "TestExposeClass";
4837 atom
= RegisterClassA(&cls
);
4839 mw
= CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE
|WS_OVERLAPPEDWINDOW
,
4840 0, 0, 200, 100, NULL
, NULL
, 0, NULL
);
4846 static void test_GetWindowModuleFileName(void)
4851 char buf1
[MAX_PATH
], buf2
[MAX_PATH
];
4853 if (!pGetWindowModuleFileNameA
)
4855 win_skip("GetWindowModuleFileNameA is not available\n");
4859 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0,0,0,0, 0, 0, 0, NULL
);
4862 hinst
= (HINSTANCE
)GetWindowLongPtr(hwnd
, GWLP_HINSTANCE
);
4863 ok(hinst
== 0 || broken(hinst
== GetModuleHandle(0)), /* win9x */ "expected 0, got %p\n", hinst
);
4866 SetLastError(0xdeadbeef);
4867 ret1
= GetModuleFileName(hinst
, buf1
, sizeof(buf1
));
4868 ok(ret1
, "GetModuleFileName error %u\n", GetLastError());
4871 SetLastError(0xdeadbeef);
4872 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, sizeof(buf2
));
4873 ok(ret2
|| broken(!ret2
), /* nt4 sp 3 */
4874 "GetWindowModuleFileNameA error %u\n", GetLastError());
4878 ok(ret1
== ret2
|| broken(ret2
== ret1
+ 1), /* win98 */ "%u != %u\n", ret1
, ret2
);
4879 ok(!strcmp(buf1
, buf2
), "%s != %s\n", buf1
, buf2
);
4881 hinst
= GetModuleHandle(0);
4883 SetLastError(0xdeadbeef);
4884 ret2
= GetModuleFileName(hinst
, buf2
, ret1
- 2);
4885 ok(ret2
== ret1
- 2 || broken(ret2
== ret1
- 3), /* win98 */
4886 "expected %u, got %u\n", ret1
- 2, ret2
);
4887 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4888 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
4889 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4891 SetLastError(0xdeadbeef);
4892 ret2
= GetModuleFileName(hinst
, buf2
, 0);
4893 ok(!ret2
, "GetModuleFileName should return 0\n");
4894 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4895 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
4896 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4898 SetLastError(0xdeadbeef);
4899 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, ret1
- 2);
4900 ok(ret2
== ret1
- 2 || broken(ret2
== ret1
- 3) /* win98 */ || broken(!ret2
), /* nt4 sp3 */
4901 "expected %u, got %u\n", ret1
- 2, ret2
);
4902 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4903 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
4904 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4906 SetLastError(0xdeadbeef);
4907 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, 0);
4908 ok(!ret2
, "expected 0, got %u\n", ret2
);
4909 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4910 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
4911 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4913 DestroyWindow(hwnd
);
4916 hwnd
= (HWND
)0xdeadbeef;
4917 SetLastError(0xdeadbeef);
4918 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
4919 ok(!ret1
, "expected 0, got %u\n", ret1
);
4920 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
|| broken(GetLastError() == 0xdeadbeef), /* win9x */
4921 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
4923 hwnd
= FindWindow("Shell_TrayWnd", NULL
);
4924 ok(IsWindow(hwnd
) || broken(!hwnd
), "got invalid tray window %p\n", hwnd
);
4925 SetLastError(0xdeadbeef);
4926 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
4927 ok(!ret1
|| broken(ret1
), /* win98 */ "expected 0, got %u\n", ret1
);
4929 if (!ret1
) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
4931 ret1
= GetModuleFileName(0, buf1
, sizeof(buf1
));
4932 hwnd
= GetDesktopWindow();
4933 ok(IsWindow(hwnd
), "got invalid desktop window %p\n", hwnd
);
4934 SetLastError(0xdeadbeef);
4935 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, sizeof(buf2
));
4937 ret1
== ret2
|| /* vista */
4938 broken(ret2
), /* some win98 return user.exe as file name */
4939 "expected 0 or %u, got %u %s\n", ret1
, ret2
, buf2
);
4943 static void test_hwnd_message(void)
4945 static const WCHAR mainwindowclassW
[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
4946 static const WCHAR message_windowW
[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
4948 HWND parent
= 0, hwnd
, found
;
4951 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
4952 on CreateWindowExA and crash later in the test.
4953 Use UNICODE here to fail on win9x */
4954 hwnd
= CreateWindowExW(0, mainwindowclassW
, message_windowW
, WS_CAPTION
| WS_VISIBLE
,
4955 100, 100, 200, 200, HWND_MESSAGE
, 0, 0, NULL
);
4958 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
4962 ok( !GetParent(hwnd
), "GetParent should return 0 for message only windows\n" );
4966 HWND root
, desktop
= GetDesktopWindow();
4968 parent
= pGetAncestor(hwnd
, GA_PARENT
);
4969 ok(parent
!= 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
4970 ok(parent
!= desktop
, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
4971 root
= pGetAncestor(hwnd
, GA_ROOT
);
4972 ok(root
== hwnd
, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
4973 ok( !pGetAncestor(parent
, GA_PARENT
) || broken(pGetAncestor(parent
, GA_PARENT
) != 0), /* win2k */
4974 "parent shouldn't have parent %p\n", pGetAncestor(parent
, GA_PARENT
) );
4975 trace("parent %p root %p desktop %p\n", parent
, root
, desktop
);
4976 if (!GetClassNameA( parent
, buffer
, sizeof(buffer
) )) buffer
[0] = 0;
4977 ok( !lstrcmpi( buffer
, "Message" ), "wrong parent class '%s'\n", buffer
);
4978 GetWindowRect( parent
, &rect
);
4979 ok( rect
.left
== 0 && rect
.right
== 100 && rect
.top
== 0 && rect
.bottom
== 100,
4980 "wrong parent rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4982 GetWindowRect( hwnd
, &rect
);
4983 ok( rect
.left
== 100 && rect
.right
== 300 && rect
.top
== 100 && rect
.bottom
== 300,
4984 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4986 /* test FindWindow behavior */
4988 found
= FindWindowExA( 0, 0, 0, "message window" );
4989 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
4990 SetLastError(0xdeadbeef);
4991 found
= FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
4992 ok( found
== 0, "found message window %p/%p\n", found
, hwnd
);
4993 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
4996 found
= FindWindowExA( parent
, 0, 0, "message window" );
4997 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
5000 /* test IsChild behavior */
5002 if (parent
) ok( !IsChild( parent
, hwnd
), "HWND_MESSAGE is child of top window\n" );
5004 /* test IsWindowVisible behavior */
5006 ok( !IsWindowVisible( hwnd
), "HWND_MESSAGE window is visible\n" );
5007 if (parent
) ok( !IsWindowVisible( parent
), "HWND_MESSAGE parent is visible\n" );
5009 DestroyWindow(hwnd
);
5012 static void test_layered_window(void)
5020 if (!pGetLayeredWindowAttributes
|| !pSetLayeredWindowAttributes
)
5022 win_skip( "layered windows not supported\n" );
5025 hwnd
= CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION
,
5026 100, 100, 200, 200, 0, 0, 0, NULL
);
5028 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5029 ok( !ret
, "GetLayeredWindowAttributes should fail on non-layered window\n" );
5030 ret
= pSetLayeredWindowAttributes( hwnd
, 0, 0, LWA_ALPHA
);
5031 ok( !ret
, "SetLayeredWindowAttributes should fail on non-layered window\n" );
5032 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
5033 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5034 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5035 ret
= pSetLayeredWindowAttributes( hwnd
, 0x123456, 44, LWA_ALPHA
);
5036 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5037 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5038 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5039 ok( key
== 0x123456 || key
== 0, "wrong color key %x\n", key
);
5040 ok( alpha
== 44, "wrong alpha %u\n", alpha
);
5041 ok( flags
== LWA_ALPHA
, "wrong flags %x\n", flags
);
5043 /* clearing WS_EX_LAYERED resets attributes */
5044 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
5045 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5046 ok( !ret
, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
5047 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
5048 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5049 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5050 ret
= pSetLayeredWindowAttributes( hwnd
, 0x654321, 22, LWA_COLORKEY
| LWA_ALPHA
);
5051 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5052 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5053 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5054 ok( key
== 0x654321, "wrong color key %x\n", key
);
5055 ok( alpha
== 22, "wrong alpha %u\n", alpha
);
5056 ok( flags
== (LWA_COLORKEY
| LWA_ALPHA
), "wrong flags %x\n", flags
);
5058 ret
= pSetLayeredWindowAttributes( hwnd
, 0x888888, 33, LWA_COLORKEY
);
5059 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5061 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5062 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5063 ok( key
== 0x888888, "wrong color key %x\n", key
);
5064 /* alpha not changed on vista if LWA_ALPHA is not set */
5065 ok( alpha
== 22 || alpha
== 33, "wrong alpha %u\n", alpha
);
5066 ok( flags
== LWA_COLORKEY
, "wrong flags %x\n", flags
);
5068 /* color key may or may not be changed without LWA_COLORKEY */
5069 ret
= pSetLayeredWindowAttributes( hwnd
, 0x999999, 44, 0 );
5070 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5072 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5073 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5074 ok( key
== 0x888888 || key
== 0x999999, "wrong color key %x\n", key
);
5075 ok( alpha
== 22 || alpha
== 44, "wrong alpha %u\n", alpha
);
5076 ok( flags
== 0, "wrong flags %x\n", flags
);
5078 /* default alpha and color key is 0 */
5079 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
5080 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
5081 ret
= pSetLayeredWindowAttributes( hwnd
, 0x222222, 55, 0 );
5082 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5083 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5084 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5085 ok( key
== 0 || key
== 0x222222, "wrong color key %x\n", key
);
5086 ok( alpha
== 0 || alpha
== 55, "wrong alpha %u\n", alpha
);
5087 ok( flags
== 0, "wrong flags %x\n", flags
);
5089 DestroyWindow( hwnd
);
5092 static MONITORINFO mi
;
5094 static LRESULT CALLBACK
fullscreen_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
5100 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
5101 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
5102 ok(cs
->x
== mi
.rcMonitor
.left
&& cs
->y
== mi
.rcMonitor
.top
&&
5103 cs
->cx
== mi
.rcMonitor
.right
&& cs
->cy
== mi
.rcMonitor
.bottom
,
5104 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
5105 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5106 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
5109 case WM_GETMINMAXINFO
:
5111 MINMAXINFO
*minmax
= (MINMAXINFO
*)lp
;
5112 dump_minmax_info(minmax
);
5113 ok(minmax
->ptMaxPosition
.x
<= mi
.rcMonitor
.left
, "%d <= %d\n", minmax
->ptMaxPosition
.x
, mi
.rcMonitor
.left
);
5114 ok(minmax
->ptMaxPosition
.y
<= mi
.rcMonitor
.top
, "%d <= %d\n", minmax
->ptMaxPosition
.y
, mi
.rcMonitor
.top
);
5115 ok(minmax
->ptMaxSize
.x
>= mi
.rcMonitor
.right
, "%d >= %d\n", minmax
->ptMaxSize
.x
, mi
.rcMonitor
.right
);
5116 ok(minmax
->ptMaxSize
.y
>= mi
.rcMonitor
.bottom
, "%d >= %d\n", minmax
->ptMaxSize
.y
, mi
.rcMonitor
.bottom
);
5120 return DefWindowProc(hwnd
, msg
, wp
, lp
);
5123 static void test_fullscreen(void)
5125 static const DWORD t_style
[] = {
5126 WS_OVERLAPPED
, WS_POPUP
, WS_CHILD
, WS_THICKFRAME
, WS_DLGFRAME
5128 static const DWORD t_ex_style
[] = {
5129 0, WS_EX_APPWINDOW
, WS_EX_TOOLWINDOW
5139 if (!pGetMonitorInfoA
|| !pMonitorFromPoint
)
5141 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
5146 SetLastError(0xdeadbeef);
5147 hmon
= pMonitorFromPoint(pt
, MONITOR_DEFAULTTOPRIMARY
);
5148 ok(hmon
!= 0, "MonitorFromPoint error %u\n", GetLastError());
5150 mi
.cbSize
= sizeof(mi
);
5151 SetLastError(0xdeadbeef);
5152 ret
= pGetMonitorInfoA(hmon
, &mi
);
5153 ok(ret
, "GetMonitorInfo error %u\n", GetLastError());
5154 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
5155 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5156 mi
.rcWork
.left
, mi
.rcWork
.top
, mi
.rcWork
.right
, mi
.rcWork
.bottom
);
5159 cls
.lpfnWndProc
= fullscreen_wnd_proc
;
5162 cls
.hInstance
= GetModuleHandle(0);
5164 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
5165 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5166 cls
.lpszMenuName
= NULL
;
5167 cls
.lpszClassName
= "fullscreen_class";
5168 RegisterClass(&cls
);
5170 for (i
= 0; i
< sizeof(t_style
)/sizeof(t_style
[0]); i
++)
5172 DWORD style
, ex_style
;
5174 /* avoid a WM interaction */
5175 assert(!(t_style
[i
] & WS_VISIBLE
));
5177 for (j
= 0; j
< sizeof(t_ex_style
)/sizeof(t_ex_style
[0]); j
++)
5182 ex_style
= t_ex_style
[j
];
5184 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5185 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5186 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5187 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5188 GetWindowRect(hwnd
, &rc
);
5189 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5190 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5191 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5192 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5193 DestroyWindow(hwnd
);
5195 style
= t_style
[i
] | WS_MAXIMIZE
;
5196 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5197 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5198 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5199 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5200 GetWindowRect(hwnd
, &rc
);
5201 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5202 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5203 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5204 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5205 DestroyWindow(hwnd
);
5207 style
= t_style
[i
] | WS_MAXIMIZE
| WS_CAPTION
;
5208 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5209 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5210 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5211 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5212 GetWindowRect(hwnd
, &rc
);
5213 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5214 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5215 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5216 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5217 DestroyWindow(hwnd
);
5219 style
= t_style
[i
] | WS_CAPTION
| WS_MAXIMIZEBOX
;
5220 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5221 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5222 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5223 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5224 GetWindowRect(hwnd
, &rc
);
5225 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5226 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5227 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5228 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5229 DestroyWindow(hwnd
);
5231 style
= t_style
[i
] | WS_MAXIMIZE
| WS_CAPTION
| WS_MAXIMIZEBOX
;
5232 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5233 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5234 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5235 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5236 GetWindowRect(hwnd
, &rc
);
5237 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5238 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5239 fixup
= min(abs(rc
.left
), abs(rc
.top
));
5240 InflateRect(&rc
, -fixup
, -fixup
);
5241 ok(rc
.left
>= mi
.rcWork
.left
&& rc
.top
<= mi
.rcWork
.top
&&
5242 rc
.right
<= mi
.rcWork
.right
&& rc
.bottom
<= mi
.rcWork
.bottom
,
5243 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
5244 ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
5245 mi
.rcWork
.left
, mi
.rcWork
.top
, mi
.rcWork
.right
, mi
.rcWork
.bottom
);
5246 DestroyWindow(hwnd
);
5248 style
= t_style
[i
] | WS_MAXIMIZE
| WS_MAXIMIZEBOX
;
5249 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5250 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5251 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5252 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5253 GetWindowRect(hwnd
, &rc
);
5254 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5255 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5256 fixup
= min(abs(rc
.left
), abs(rc
.top
));
5257 InflateRect(&rc
, -fixup
, -fixup
);
5258 if (style
& (WS_CHILD
| WS_POPUP
))
5259 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5260 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5261 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5263 ok(rc
.left
>= mi
.rcWork
.left
&& rc
.top
<= mi
.rcWork
.top
&&
5264 rc
.right
<= mi
.rcWork
.right
&& rc
.bottom
<= mi
.rcWork
.bottom
,
5265 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5266 DestroyWindow(hwnd
);
5270 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5273 static BOOL test_thick_child_got_minmax
;
5274 static const char * test_thick_child_name
;
5275 static LONG test_thick_child_style
;
5276 static LONG test_thick_child_exStyle
;
5278 static LRESULT WINAPI
test_thick_child_size_winproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
5281 int expectedMinTrackX
;
5282 int expectedMinTrackY
;
5283 int actualMinTrackX
;
5284 int actualMinTrackY
;
5285 int expectedMaxTrackX
;
5286 int expectedMaxTrackY
;
5287 int actualMaxTrackX
;
5288 int actualMaxTrackY
;
5289 int expectedMaxSizeX
;
5290 int expectedMaxSizeY
;
5301 case WM_GETMINMAXINFO
:
5303 minmax
= (MINMAXINFO
*)lparam
;
5304 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
5305 dump_minmax_info( minmax
);
5307 test_thick_child_got_minmax
= TRUE
;
5310 adjustedStyle
= test_thick_child_style
;
5311 if ((adjustedStyle
& WS_CAPTION
) == WS_CAPTION
)
5312 adjustedStyle
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5313 GetClientRect(GetParent(hwnd
), &rect
);
5314 AdjustWindowRectEx(&rect
, adjustedStyle
, FALSE
, test_thick_child_exStyle
);
5316 if (test_thick_child_style
& (WS_DLGFRAME
| WS_BORDER
))
5318 expectedMinTrackX
= GetSystemMetrics(SM_CXMINTRACK
);
5319 expectedMinTrackY
= GetSystemMetrics(SM_CYMINTRACK
);
5323 expectedMinTrackX
= -2 * rect
.left
;
5324 expectedMinTrackY
= -2 * rect
.top
;
5326 actualMinTrackX
= minmax
->ptMinTrackSize
.x
;
5327 actualMinTrackY
= minmax
->ptMinTrackSize
.y
;
5329 ok(actualMinTrackX
== expectedMinTrackX
&& actualMinTrackY
== expectedMinTrackY
,
5330 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
5331 expectedMinTrackX
, expectedMinTrackY
, actualMinTrackX
, actualMinTrackY
,
5332 test_thick_child_name
);
5334 actualMaxTrackX
= minmax
->ptMaxTrackSize
.x
;
5335 actualMaxTrackY
= minmax
->ptMaxTrackSize
.y
;
5336 expectedMaxTrackX
= GetSystemMetrics(SM_CXMAXTRACK
);
5337 expectedMaxTrackY
= GetSystemMetrics(SM_CYMAXTRACK
);
5338 ok(actualMaxTrackX
== expectedMaxTrackX
&& actualMaxTrackY
== expectedMaxTrackY
,
5339 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
5340 expectedMaxTrackX
, expectedMaxTrackY
, actualMaxTrackX
, actualMaxTrackY
,
5341 test_thick_child_name
);
5343 expectedMaxSizeX
= rect
.right
- rect
.left
;
5344 expectedMaxSizeY
= rect
.bottom
- rect
.top
;
5345 actualMaxSizeX
= minmax
->ptMaxSize
.x
;
5346 actualMaxSizeY
= minmax
->ptMaxSize
.y
;
5348 ok(actualMaxSizeX
== expectedMaxSizeX
&& actualMaxSizeY
== expectedMaxSizeY
,
5349 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
5350 expectedMaxSizeX
, expectedMaxSizeY
, actualMaxSizeX
, actualMaxSizeY
,
5351 test_thick_child_name
);
5354 expectedPosX
= rect
.left
;
5355 expectedPosY
= rect
.top
;
5356 actualPosX
= minmax
->ptMaxPosition
.x
;
5357 actualPosY
= minmax
->ptMaxPosition
.y
;
5358 ok(actualPosX
== expectedPosX
&& actualPosY
== expectedPosY
,
5359 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
5360 expectedPosX
, expectedPosY
, actualPosX
, actualPosY
, test_thick_child_name
);
5366 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
5369 #define NUMBER_OF_THICK_CHILD_TESTS 16
5370 static void test_thick_child_size(HWND parentWindow
)
5374 RECT adjustedParentRect
;
5379 LONG expectedHeight
;
5381 LPCTSTR className
= "THICK_CHILD_CLASS";
5384 static const LONG styles
[NUMBER_OF_THICK_CHILD_TESTS
] = {
5385 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
5386 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
5387 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
5388 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
5389 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
5390 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
5391 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
5392 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
5393 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
5394 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
5395 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
5396 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
5397 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
5398 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
5399 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
5400 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
5403 static const LONG exStyles
[NUMBER_OF_THICK_CHILD_TESTS
] = {
5408 WS_EX_DLGMODALFRAME
,
5409 WS_EX_DLGMODALFRAME
,
5410 WS_EX_DLGMODALFRAME
,
5411 WS_EX_DLGMODALFRAME
,
5416 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
5417 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
5418 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
5419 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
5421 static const char *styleName
[NUMBER_OF_THICK_CHILD_TESTS
] = {
5422 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
5423 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
5424 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
5425 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
5426 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
5427 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
5428 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5429 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5430 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
5431 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
5432 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5433 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5434 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5435 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5436 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5437 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5441 cls
.lpfnWndProc
= test_thick_child_size_winproc
;
5444 cls
.hInstance
= GetModuleHandleA(0);
5446 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
5447 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5448 cls
.lpszMenuName
= NULL
;
5449 cls
.lpszClassName
= className
;
5450 SetLastError(0xdeadbeef);
5451 ok(RegisterClassA(&cls
),"RegisterClassA failed, error: %u\n", GetLastError());
5453 for(i
= 0; i
< NUMBER_OF_THICK_CHILD_TESTS
; i
++)
5455 test_thick_child_name
= styleName
[i
];
5456 test_thick_child_style
= styles
[i
];
5457 test_thick_child_exStyle
= exStyles
[i
];
5458 test_thick_child_got_minmax
= FALSE
;
5460 SetLastError(0xdeadbeef);
5461 childWindow
= CreateWindowEx( exStyles
[i
], className
, "", styles
[i
], 0, 0, 0, 0, parentWindow
, 0, GetModuleHandleA(0), NULL
);
5462 ok(childWindow
!= NULL
, "Failed to create child window, error: %u\n", GetLastError());
5464 ok(test_thick_child_got_minmax
, "Got no WM_GETMINMAXINFO\n");
5466 SetLastError(0xdeadbeef);
5467 success
= GetWindowRect(childWindow
, &childRect
);
5468 ok(success
,"GetWindowRect call failed, error: %u\n", GetLastError());
5469 childWidth
= childRect
.right
- childRect
.left
;
5470 childHeight
= childRect
.bottom
- childRect
.top
;
5472 adjustedStyle
= styles
[i
];
5473 if ((adjustedStyle
& WS_CAPTION
) == WS_CAPTION
)
5474 adjustedStyle
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5475 GetClientRect(GetParent(childWindow
), &adjustedParentRect
);
5476 AdjustWindowRectEx(&adjustedParentRect
, adjustedStyle
, FALSE
, test_thick_child_exStyle
);
5479 if (test_thick_child_style
& (WS_DLGFRAME
| WS_BORDER
))
5481 expectedWidth
= GetSystemMetrics(SM_CXMINTRACK
);
5482 expectedHeight
= GetSystemMetrics(SM_CYMINTRACK
);
5486 expectedWidth
= -2 * adjustedParentRect
.left
;
5487 expectedHeight
= -2 * adjustedParentRect
.top
;
5490 ok((childWidth
== expectedWidth
) && (childHeight
== expectedHeight
),
5491 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
5492 test_thick_child_name
, expectedWidth
, expectedHeight
, childWidth
, childHeight
);
5494 SetLastError(0xdeadbeef);
5495 success
= DestroyWindow(childWindow
);
5496 ok(success
,"DestroyWindow call failed, error: %u\n", GetLastError());
5498 ok(UnregisterClass(className
, GetModuleHandleA(0)),"UnregisterClass call failed\n");
5501 static void test_handles( HWND full_hwnd
)
5503 HWND hwnd
= full_hwnd
;
5507 SetLastError( 0xdeadbeef );
5508 ret
= GetWindowRect( hwnd
, &rect
);
5509 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
5512 if ((ULONG_PTR
)full_hwnd
>> 32)
5513 hwnd
= (HWND
)((ULONG_PTR
)full_hwnd
& ~0u);
5515 hwnd
= (HWND
)((ULONG_PTR
)full_hwnd
| ((ULONG_PTR
)~0u << 32));
5516 SetLastError( 0xdeadbeef );
5517 ret
= GetWindowRect( hwnd
, &rect
);
5518 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
5520 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& ~0u) | ((ULONG_PTR
)0x1234 << 32));
5521 SetLastError( 0xdeadbeef );
5522 ret
= GetWindowRect( hwnd
, &rect
);
5523 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
5525 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& 0xffff) | ((ULONG_PTR
)0x9876 << 16));
5526 SetLastError( 0xdeadbeef );
5527 ret
= GetWindowRect( hwnd
, &rect
);
5528 ok( !ret
, "GetWindowRect succeeded for %p\n", hwnd
);
5529 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "wrong error %u\n", GetLastError() );
5531 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& 0xffff) | ((ULONG_PTR
)0x12345678 << 16));
5532 SetLastError( 0xdeadbeef );
5533 ret
= GetWindowRect( hwnd
, &rect
);
5534 ok( !ret
, "GetWindowRect succeeded for %p\n", hwnd
);
5535 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "wrong error %u\n", GetLastError() );
5539 static void test_winregion(void)
5546 if (!pGetWindowRgnBox
)
5548 win_skip("GetWindowRgnBox not supported\n");
5552 hwnd
= CreateWindowExA(0, "static", NULL
, WS_VISIBLE
, 10, 10, 10, 10, NULL
, 0, 0, NULL
);
5554 SetLastError(0xdeadbeef);
5555 ret
= pGetWindowRgnBox(hwnd
, NULL
);
5556 ok( ret
== ERROR
, "Expected ERROR, got %d\n", ret
);
5557 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
5559 hrgn
= CreateRectRgn(2, 3, 10, 15);
5560 ok( hrgn
!= NULL
, "Region creation failed\n");
5563 SetWindowRgn(hwnd
, hrgn
, FALSE
);
5565 SetLastError(0xdeadbeef);
5566 ret
= pGetWindowRgnBox(hwnd
, NULL
);
5567 ok( ret
== ERROR
, "Expected ERROR, got %d\n", ret
);
5568 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
5570 r
.left
= r
.top
= r
.right
= r
.bottom
= 0;
5571 ret
= pGetWindowRgnBox(hwnd
, &r
);
5572 ok( ret
== SIMPLEREGION
, "Expected SIMPLEREGION, got %d\n", ret
);
5573 ok( r
.left
== 2 && r
.top
== 3 && r
.right
== 10 && r
.bottom
== 15,
5574 "Expected (2,3,10,15), got (%d,%d,%d,%d)\n", r
.left
, r
.top
,
5578 DestroyWindow(hwnd
);
5583 HMODULE user32
= GetModuleHandleA( "user32.dll" );
5584 pGetAncestor
= (void *)GetProcAddress( user32
, "GetAncestor" );
5585 pGetWindowInfo
= (void *)GetProcAddress( user32
, "GetWindowInfo" );
5586 pGetWindowModuleFileNameA
= (void *)GetProcAddress( user32
, "GetWindowModuleFileNameA" );
5587 pGetLayeredWindowAttributes
= (void *)GetProcAddress( user32
, "GetLayeredWindowAttributes" );
5588 pSetLayeredWindowAttributes
= (void *)GetProcAddress( user32
, "SetLayeredWindowAttributes" );
5589 pGetMonitorInfoA
= (void *)GetProcAddress( user32
, "GetMonitorInfoA" );
5590 pMonitorFromPoint
= (void *)GetProcAddress( user32
, "MonitorFromPoint" );
5591 pGetWindowRgnBox
= (void *)GetProcAddress( user32
, "GetWindowRgnBox" );
5593 if (!RegisterWindowClasses()) assert(0);
5595 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
5596 if (!hhook
) win_skip( "Cannot set CBT hook, skipping some tests\n" );
5598 hwndMain
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
5599 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
5600 WS_MAXIMIZEBOX
| WS_POPUP
,
5602 0, 0, GetModuleHandle(0), NULL
);
5603 hwndMain2
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
5604 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
5605 WS_MAXIMIZEBOX
| WS_POPUP
,
5607 0, 0, GetModuleHandle(0), NULL
);
5609 assert( hwndMain2
);
5611 our_pid
= GetWindowThreadProcessId(hwndMain
, NULL
);
5613 /* Add the tests below this line */
5614 test_thick_child_size(hwndMain
);
5616 test_hwnd_message();
5617 test_nonclient_area(hwndMain
);
5619 test_GetWindowModuleFileName();
5622 test_capture_3(hwndMain
, hwndMain2
);
5624 test_CreateWindow();
5625 test_parent_owner();
5630 test_SetWindowPos(hwndMain
);
5631 test_SetMenu(hwndMain
);
5632 test_SetFocus(hwndMain
);
5633 test_SetActiveWindow(hwndMain
);
5635 test_children_zorder(hwndMain
);
5636 test_popup_zorder(hwndMain2
, hwndMain
);
5637 test_keyboard_input(hwndMain
);
5638 test_mouse_input(hwndMain
);
5639 test_validatergn(hwndMain
);
5640 test_nccalcscroll( hwndMain
);
5641 test_scrollvalidate( hwndMain
);
5642 test_scrolldc( hwndMain
);
5644 test_IsWindowUnicode();
5645 test_vis_rgn(hwndMain
);
5647 test_AdjustWindowRect();
5648 test_window_styles();
5651 test_SetWindowLong();
5653 if (0) test_gettext(); /* crashes on NT4 */
5654 test_GetUpdateRect();
5656 test_layered_window();
5658 test_SetForegroundWindow(hwndMain
);
5659 test_shell_window();
5660 test_handles( hwndMain
);
5663 /* add the tests above this line */
5664 if (hhook
) UnhookWindowsHookEx(hhook
);
5666 DestroyWindow(hwndMain2
);
5667 DestroyWindow(hwndMain
);