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);
2665 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2668 skip( "keybd_event didn't work, skipping keyboard test\n" );
2671 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2672 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2673 ok( !ret
, "message %04x available\n", msg
.message
);
2676 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2678 flush_events( TRUE
);
2680 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2681 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2682 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2683 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2684 ok( !ret
, "message %04x available\n", msg
.message
);
2686 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2688 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2689 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2690 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2691 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2692 ok( !ret
, "message %04x available\n", msg
.message
);
2694 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2696 keybd_event(VK_SPACE
, 0, 0, 0);
2697 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2698 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_SYSKEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2699 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2700 ok( !ret
, "message %04x available\n", msg
.message
);
2703 static BOOL
wait_for_message( MSG
*msg
)
2709 ret
= PeekMessageA(msg
, 0, 0, 0, PM_REMOVE
);
2712 if (msg
->message
== WM_PAINT
) DispatchMessage(msg
);
2713 else if (msg
->message
< 0xc000) break; /* skip registered messages */
2715 else if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, 100, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
2717 if (!ret
) msg
->message
= 0;
2721 static void test_mouse_input(HWND hwnd
)
2731 ShowWindow(hwnd
, SW_SHOW
);
2733 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
2735 GetWindowRect(hwnd
, &rc
);
2736 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2738 popup
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_POPUP
,
2739 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
,
2742 ShowWindow(popup
, SW_SHOW
);
2743 UpdateWindow(popup
);
2744 SetWindowPos( popup
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
2746 GetWindowRect(popup
, &rc
);
2747 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2749 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
2750 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
2751 trace("setting cursor to (%d,%d)\n", x
, y
);
2755 if (x
!= pt
.x
|| y
!= pt
.y
)
2757 skip( "failed to set mouse position, skipping mouse input tests\n" );
2761 flush_events( TRUE
);
2763 /* Check that setting the same position may generate WM_MOUSEMOVE */
2767 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2768 while (ret
&& msg
.message
>= 0xc000); /* skip registered messages */
2771 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n",
2772 msg
.hwnd
, msg
.message
);
2773 ok(msg
.pt
.x
== x
&& msg
.pt
.y
== y
, "wrong message coords (%d,%d)/(%d,%d)\n",
2774 x
, y
, msg
.pt
.x
, msg
.pt
.y
);
2777 /* force the system to update its internal queue mouse position,
2778 * otherwise it won't generate relative mouse movements below.
2780 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2781 flush_events( TRUE
);
2784 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2785 flush_events( FALSE
);
2786 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2787 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
2789 if (msg
.message
== WM_TIMER
|| msg
.message
>= 0xc000) continue; /* skip registered messages */
2790 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
,
2791 "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2793 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2794 ok( !ret
, "message %04x available\n", msg
.message
);
2796 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2797 ShowWindow(popup
, SW_HIDE
);
2798 ret
= wait_for_message( &msg
);
2800 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2801 flush_events( TRUE
);
2803 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2804 ShowWindow(hwnd
, SW_HIDE
);
2805 ret
= wait_for_message( &msg
);
2806 ok( !ret
, "message %04x available\n", msg
.message
);
2807 flush_events( TRUE
);
2809 /* test mouse clicks */
2811 ShowWindow(hwnd
, SW_SHOW
);
2812 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
2813 flush_events( TRUE
);
2814 ShowWindow(popup
, SW_SHOW
);
2815 SetWindowPos( popup
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
2816 flush_events( TRUE
);
2818 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2819 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2820 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2821 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2823 ret
= wait_for_message( &msg
);
2826 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
2829 if (msg
.message
== WM_MOUSEMOVE
) /* win2k has an extra WM_MOUSEMOVE here */
2831 ret
= wait_for_message( &msg
);
2832 ok(ret
, "no message available\n");
2835 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2836 msg
.hwnd
, popup
, msg
.message
);
2838 ret
= wait_for_message( &msg
);
2839 ok(ret
, "no message available\n");
2840 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2841 msg
.hwnd
, popup
, msg
.message
);
2843 ret
= wait_for_message( &msg
);
2844 ok(ret
, "no message available\n");
2845 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p/%p message %04x\n",
2846 msg
.hwnd
, popup
, msg
.message
);
2848 ret
= wait_for_message( &msg
);
2849 ok(ret
, "no message available\n");
2850 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2851 msg
.hwnd
, popup
, msg
.message
);
2853 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2854 ok(!ret
, "message %04x available\n", msg
.message
);
2856 ShowWindow(popup
, SW_HIDE
);
2857 flush_events( TRUE
);
2859 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2860 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2861 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2862 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2864 ret
= wait_for_message( &msg
);
2865 ok(ret
, "no message available\n");
2866 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2867 msg
.hwnd
, hwnd
, msg
.message
);
2868 ret
= wait_for_message( &msg
);
2869 ok(ret
, "no message available\n");
2870 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2871 msg
.hwnd
, hwnd
, msg
.message
);
2873 test_lbuttondown_flag
= TRUE
;
2874 SendMessageA(hwnd
, WM_COMMAND
, (WPARAM
)popup
, 0);
2875 test_lbuttondown_flag
= FALSE
;
2877 ret
= wait_for_message( &msg
);
2878 ok(ret
, "no message available\n");
2879 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2880 msg
.hwnd
, popup
, msg
.message
);
2881 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2882 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "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");
2886 /* Test WM_MOUSEACTIVATE */
2887 #define TEST_MOUSEACTIVATE(A,B) \
2888 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2889 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2891 TEST_MOUSEACTIVATE(HTERROR
,MA_ACTIVATE
);
2892 TEST_MOUSEACTIVATE(HTTRANSPARENT
,MA_ACTIVATE
);
2893 TEST_MOUSEACTIVATE(HTNOWHERE
,MA_ACTIVATE
);
2894 TEST_MOUSEACTIVATE(HTCLIENT
,MA_ACTIVATE
);
2895 TEST_MOUSEACTIVATE(HTCAPTION
,MA_ACTIVATE
);
2896 TEST_MOUSEACTIVATE(HTSYSMENU
,MA_ACTIVATE
);
2897 TEST_MOUSEACTIVATE(HTSIZE
,MA_ACTIVATE
);
2898 TEST_MOUSEACTIVATE(HTMENU
,MA_ACTIVATE
);
2899 TEST_MOUSEACTIVATE(HTHSCROLL
,MA_ACTIVATE
);
2900 TEST_MOUSEACTIVATE(HTVSCROLL
,MA_ACTIVATE
);
2901 TEST_MOUSEACTIVATE(HTMINBUTTON
,MA_ACTIVATE
);
2902 TEST_MOUSEACTIVATE(HTMAXBUTTON
,MA_ACTIVATE
);
2903 TEST_MOUSEACTIVATE(HTLEFT
,MA_ACTIVATE
);
2904 TEST_MOUSEACTIVATE(HTRIGHT
,MA_ACTIVATE
);
2905 TEST_MOUSEACTIVATE(HTTOP
,MA_ACTIVATE
);
2906 TEST_MOUSEACTIVATE(HTTOPLEFT
,MA_ACTIVATE
);
2907 TEST_MOUSEACTIVATE(HTTOPRIGHT
,MA_ACTIVATE
);
2908 TEST_MOUSEACTIVATE(HTBOTTOM
,MA_ACTIVATE
);
2909 TEST_MOUSEACTIVATE(HTBOTTOMLEFT
,MA_ACTIVATE
);
2910 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT
,MA_ACTIVATE
);
2911 TEST_MOUSEACTIVATE(HTBORDER
,MA_ACTIVATE
);
2912 TEST_MOUSEACTIVATE(HTOBJECT
,MA_ACTIVATE
);
2913 TEST_MOUSEACTIVATE(HTCLOSE
,MA_ACTIVATE
);
2914 TEST_MOUSEACTIVATE(HTHELP
,MA_ACTIVATE
);
2917 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2918 flush_events( TRUE
);
2920 DestroyWindow(popup
);
2923 static void test_validatergn(HWND hwnd
)
2929 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_VISIBLE
, 10, 10, 10, 10, hwnd
, 0, 0, NULL
);
2930 ShowWindow(hwnd
, SW_SHOW
);
2931 UpdateWindow( hwnd
);
2932 /* test that ValidateRect validates children*/
2933 InvalidateRect( child
, NULL
, 1);
2934 GetWindowRect( child
, &rc
);
2935 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2936 ret
= GetUpdateRect( child
, &rc2
, 0);
2937 ok( rc2
.right
> rc2
.left
&& rc2
.bottom
> rc2
.top
,
2938 "Update rectangle is empty!\n");
2939 ValidateRect( hwnd
, &rc
);
2940 ret
= GetUpdateRect( child
, &rc2
, 0);
2941 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2942 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
2943 rc2
.right
, rc2
.bottom
);
2945 /* now test ValidateRgn */
2946 InvalidateRect( child
, NULL
, 1);
2947 GetWindowRect( child
, &rc
);
2948 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2949 rgn
= CreateRectRgnIndirect( &rc
);
2950 ValidateRgn( hwnd
, rgn
);
2951 ret
= GetUpdateRect( child
, &rc2
, 0);
2952 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2953 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
2954 rc2
.right
, rc2
.bottom
);
2957 DestroyWindow( child
);
2960 static void nccalchelper(HWND hwnd
, INT x
, INT y
, RECT
*prc
)
2963 MoveWindow( hwnd
, 0, 0, x
, y
, 0);
2964 GetWindowRect( hwnd
, prc
);
2966 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)prc
);
2967 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
2968 rc
.left
,rc
.top
,rc
.right
,rc
.bottom
, prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
2971 static void test_nccalcscroll(HWND parent
)
2974 INT sbheight
= GetSystemMetrics( SM_CYHSCROLL
);
2975 INT sbwidth
= GetSystemMetrics( SM_CXVSCROLL
);
2976 HWND hwnd
= CreateWindowExA(0, "static", NULL
,
2977 WS_CHILD
| WS_VISIBLE
| WS_VSCROLL
| WS_HSCROLL
,
2978 10, 10, 200, 200, parent
, 0, 0, NULL
);
2979 ShowWindow( parent
, SW_SHOW
);
2980 UpdateWindow( parent
);
2982 /* test window too low for a horizontal scroll bar */
2983 nccalchelper( hwnd
, 100, sbheight
, &rc1
);
2984 ok( rc1
.bottom
- rc1
.top
== sbheight
, "Height should be %d size is %d,%d - %d,%d\n",
2985 sbheight
, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2987 /* test window just high enough for a horizontal scroll bar */
2988 nccalchelper( hwnd
, 100, sbheight
+ 1, &rc1
);
2989 ok( rc1
.bottom
- rc1
.top
== 1, "Height should be %d size is %d,%d - %d,%d\n",
2990 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2992 /* test window too narrow for a vertical scroll bar */
2993 nccalchelper( hwnd
, sbwidth
- 1, 100, &rc1
);
2994 ok( rc1
.right
- rc1
.left
== sbwidth
- 1 , "Width should be %d size is %d,%d - %d,%d\n",
2995 sbwidth
- 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2997 /* test window just wide enough for a vertical scroll bar */
2998 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
2999 ok( rc1
.right
- rc1
.left
== 0, "Width should be %d size is %d,%d - %d,%d\n",
3000 0, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3002 /* same test, but with client edge: not enough width */
3003 SetWindowLong( hwnd
, GWL_EXSTYLE
, WS_EX_CLIENTEDGE
| GetWindowLong( hwnd
, GWL_EXSTYLE
));
3004 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
3005 ok( rc1
.right
- rc1
.left
== sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
),
3006 "Width should be %d size is %d,%d - %d,%d\n",
3007 sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
), rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
3009 DestroyWindow( hwnd
);
3012 static void test_SetParent(void)
3015 HWND desktop
= GetDesktopWindow();
3017 BOOL is_win9x
= GetWindowLongPtrW(desktop
, GWLP_WNDPROC
) == 0;
3018 HWND parent
, child1
, child2
, child3
, child4
, sibling
;
3020 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
3021 100, 100, 200, 200, 0, 0, 0, NULL
);
3022 assert(parent
!= 0);
3023 child1
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
3024 0, 0, 50, 50, parent
, 0, 0, NULL
);
3025 assert(child1
!= 0);
3026 child2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
3027 0, 0, 50, 50, child1
, 0, 0, NULL
);
3028 assert(child2
!= 0);
3029 child3
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
3030 0, 0, 50, 50, child2
, 0, 0, NULL
);
3031 assert(child3
!= 0);
3032 child4
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
3033 0, 0, 50, 50, child3
, 0, 0, NULL
);
3034 assert(child4
!= 0);
3036 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
3037 parent
, child1
, child2
, child3
, child4
);
3039 check_parents(parent
, desktop
, 0, 0, 0, parent
, parent
);
3040 check_parents(child1
, parent
, parent
, parent
, 0, parent
, parent
);
3041 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
3042 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
3043 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
3045 ok(!IsChild(desktop
, parent
), "wrong parent/child %p/%p\n", desktop
, parent
);
3046 ok(!IsChild(desktop
, child1
), "wrong parent/child %p/%p\n", desktop
, child1
);
3047 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
3048 ok(!IsChild(desktop
, child3
), "wrong parent/child %p/%p\n", desktop
, child3
);
3049 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
3051 ok(IsChild(parent
, child1
), "wrong parent/child %p/%p\n", parent
, child1
);
3052 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
3053 ok(!IsChild(parent
, child2
), "wrong parent/child %p/%p\n", parent
, child2
);
3054 ok(!IsChild(child1
, child2
), "wrong parent/child %p/%p\n", child1
, child2
);
3055 ok(!IsChild(parent
, child3
), "wrong parent/child %p/%p\n", parent
, child3
);
3056 ok(IsChild(child2
, child3
), "wrong parent/child %p/%p\n", child2
, child3
);
3057 ok(!IsChild(parent
, child4
), "wrong parent/child %p/%p\n", parent
, child4
);
3058 ok(!IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
3059 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
3061 if (!is_win9x
) /* Win9x doesn't survive this test */
3063 ok(!SetParent(parent
, child1
), "SetParent should fail\n");
3064 ok(!SetParent(child2
, child3
), "SetParent should fail\n");
3065 ok(SetParent(child1
, parent
) != 0, "SetParent should not fail\n");
3066 ok(SetParent(parent
, child2
) != 0, "SetParent should not fail\n");
3067 ok(SetParent(parent
, child3
) != 0, "SetParent should not fail\n");
3068 ok(!SetParent(child2
, parent
), "SetParent should fail\n");
3069 ok(SetParent(parent
, child4
) != 0, "SetParent should not fail\n");
3071 check_parents(parent
, child4
, child4
, 0, 0, child4
, parent
);
3072 check_parents(child1
, parent
, parent
, parent
, 0, child4
, parent
);
3073 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
3074 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
3075 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
3078 hMenu
= CreateMenu();
3079 sibling
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
3080 100, 100, 200, 200, 0, hMenu
, 0, NULL
);
3081 assert(sibling
!= 0);
3083 ok(SetParent(sibling
, parent
) != 0, "SetParent should not fail\n");
3084 ok(GetMenu(sibling
) == hMenu
, "SetParent should not remove menu\n");
3086 ret
= DestroyWindow(parent
);
3087 ok( ret
, "DestroyWindow() error %d\n", GetLastError());
3089 ok(!IsWindow(parent
), "parent still exists\n");
3090 ok(!IsWindow(sibling
), "sibling still exists\n");
3091 ok(!IsWindow(child1
), "child1 still exists\n");
3092 ok(!IsWindow(child2
), "child2 still exists\n");
3093 ok(!IsWindow(child3
), "child3 still exists\n");
3094 ok(!IsWindow(child4
), "child4 still exists\n");
3097 static LRESULT WINAPI
StyleCheckProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3099 LPCREATESTRUCT lpcs
;
3106 lpcs
= (LPCREATESTRUCT
)lparam
;
3107 lpss
= lpcs
->lpCreateParams
;
3110 if ((lpcs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
3111 ((!(lpcs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
3112 (lpcs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
3113 ok(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
, "Window should have WS_EX_WINDOWEDGE style\n");
3115 ok(!(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3117 ok((lpss
->styleOld
& ~WS_EX_WINDOWEDGE
) == (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
),
3118 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
3119 (lpss
->styleOld
& ~WS_EX_WINDOWEDGE
), (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
));
3121 ok(lpss
->styleNew
== lpcs
->style
,
3122 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3123 lpss
->styleNew
, lpcs
->style
);
3127 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3130 static ATOM atomStyleCheckClass
;
3132 static void register_style_check_class(void)
3140 GetModuleHandle(NULL
),
3142 LoadCursor(NULL
, IDC_ARROW
),
3143 (HBRUSH
)(COLOR_BTNFACE
+1),
3145 TEXT("WineStyleCheck"),
3148 atomStyleCheckClass
= RegisterClass(&wc
);
3151 static void check_window_style(DWORD dwStyleIn
, DWORD dwExStyleIn
, DWORD dwStyleOut
, DWORD dwExStyleOut
)
3153 DWORD dwActualStyle
;
3154 DWORD dwActualExStyle
;
3157 HWND hwndParent
= NULL
;
3159 ss
.styleNew
= dwStyleIn
;
3160 ss
.styleOld
= dwExStyleIn
;
3162 if (dwStyleIn
& WS_CHILD
)
3164 hwndParent
= CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3165 WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
3168 hwnd
= CreateWindowEx(dwExStyleIn
, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3169 dwStyleIn
, 0, 0, 0, 0, hwndParent
, NULL
, NULL
, &ss
);
3172 flush_events( TRUE
);
3174 dwActualStyle
= GetWindowLong(hwnd
, GWL_STYLE
);
3175 dwActualExStyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
3176 ok((dwActualStyle
== dwStyleOut
) && (dwActualExStyle
== dwExStyleOut
),
3177 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3178 dwActualStyle
, dwStyleOut
, dwActualExStyle
, dwExStyleOut
);
3180 DestroyWindow(hwnd
);
3181 if (hwndParent
) DestroyWindow(hwndParent
);
3184 /* tests what window styles the window manager automatically adds */
3185 static void test_window_styles(void)
3187 register_style_check_class();
3189 check_window_style(0, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
3190 check_window_style(WS_OVERLAPPEDWINDOW
, 0, WS_CLIPSIBLINGS
|WS_OVERLAPPEDWINDOW
, WS_EX_WINDOWEDGE
);
3191 check_window_style(WS_CHILD
, 0, WS_CHILD
, 0);
3192 check_window_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
3193 check_window_style(0, WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_TOOLWINDOW
);
3194 check_window_style(WS_POPUP
, 0, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3195 check_window_style(WS_POPUP
, WS_EX_WINDOWEDGE
, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3196 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
, WS_CHILD
, WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3197 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
|WS_EX_STATICEDGE
, WS_CHILD
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3198 check_window_style(WS_CAPTION
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
);
3199 check_window_style(0, WS_EX_APPWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_APPWINDOW
|WS_EX_WINDOWEDGE
);
3202 static void test_scrollvalidate( HWND parent
)
3205 HRGN hrgn
=CreateRectRgn(0,0,0,0);
3206 HRGN exprgn
, tmprgn
, clipping
;
3207 RECT rc
, rcu
, cliprc
;
3208 /* create two overlapping child windows. The visual region
3209 * of hwnd1 is clipped by the overlapping part of
3210 * hwnd2 because of the WS_CLIPSIBLING style */
3213 clipping
= CreateRectRgn(0,0,0,0);
3214 tmprgn
= CreateRectRgn(0,0,0,0);
3215 exprgn
= CreateRectRgn(0,0,0,0);
3216 hwnd2
= CreateWindowExA(0, "static", NULL
,
3217 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3218 75, 30, 100, 100, parent
, 0, 0, NULL
);
3219 hwnd1
= CreateWindowExA(0, "static", NULL
,
3220 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3221 25, 50, 100, 100, parent
, 0, 0, NULL
);
3222 ShowWindow( parent
, SW_SHOW
);
3223 UpdateWindow( parent
);
3224 GetClientRect( hwnd1
, &rc
);
3226 SetRectRgn( clipping
, 10, 10, 90, 90);
3227 hdc
= GetDC( hwnd1
);
3228 /* for a visual touch */
3229 TextOut( hdc
, 0,10, "0123456789", 10);
3230 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3231 if (winetest_debug
> 0) dump_region(hrgn
);
3232 /* create a region with what is expected */
3233 SetRectRgn( exprgn
, 39,0,49,74);
3234 SetRectRgn( tmprgn
, 88,79,98,93);
3235 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3236 SetRectRgn( tmprgn
, 0,93,98,98);
3237 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3238 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3239 trace("update rect is %d,%d - %d,%d\n",
3240 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3241 /* now with clipping region */
3242 SelectClipRgn( hdc
, clipping
);
3243 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3244 if (winetest_debug
> 0) dump_region(hrgn
);
3245 /* create a region with what is expected */
3246 SetRectRgn( exprgn
, 39,10,49,74);
3247 SetRectRgn( tmprgn
, 80,79,90,85);
3248 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3249 SetRectRgn( tmprgn
, 10,85,90,90);
3250 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3251 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3252 trace("update rect is %d,%d - %d,%d\n",
3253 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3254 ReleaseDC( hwnd1
, hdc
);
3256 /* test scrolling a window with an update region */
3257 DestroyWindow( hwnd2
);
3258 ValidateRect( hwnd1
, NULL
);
3259 SetRect( &rc
, 40,40, 50,50);
3260 InvalidateRect( hwnd1
, &rc
, 1);
3261 GetClientRect( hwnd1
, &rc
);
3263 ScrollWindowEx( hwnd1
, -10, 0, &rc
, &cliprc
, hrgn
, &rcu
,
3264 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3265 if (winetest_debug
> 0) dump_region(hrgn
);
3266 SetRectRgn( exprgn
, 88,0,98,98);
3267 SetRectRgn( tmprgn
, 30, 40, 50, 50);
3268 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3269 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3271 /* clear an update region */
3272 UpdateWindow( hwnd1
);
3274 SetRect( &rc
, 0,40, 100,60);
3275 SetRect( &cliprc
, 0,0, 100,100);
3276 ScrollWindowEx( hwnd1
, 0, -25, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3277 if (winetest_debug
> 0) dump_region( hrgn
);
3278 SetRectRgn( exprgn
, 0, 40, 98, 60 );
3279 ok( EqualRgn( exprgn
, hrgn
), "wrong update region in excessive scroll\n");
3281 /* now test ScrollWindowEx with a combination of
3282 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3283 /* make hwnd2 the child of hwnd1 */
3284 hwnd2
= CreateWindowExA(0, "static", NULL
,
3285 WS_CHILD
| WS_VISIBLE
| WS_BORDER
,
3286 50, 50, 100, 100, hwnd1
, 0, 0, NULL
);
3287 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPSIBLINGS
);
3288 GetClientRect( hwnd1
, &rc
);
3291 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3292 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3293 ValidateRect( hwnd1
, NULL
);
3294 ValidateRect( hwnd2
, NULL
);
3295 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
,
3296 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3297 if (winetest_debug
> 0) dump_region(hrgn
);
3298 SetRectRgn( exprgn
, 88,0,98,88);
3299 SetRectRgn( tmprgn
, 0,88,98,98);
3300 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3301 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3303 /* SW_SCROLLCHILDREN */
3304 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3305 ValidateRect( hwnd1
, NULL
);
3306 ValidateRect( hwnd2
, NULL
);
3307 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3308 if (winetest_debug
> 0) dump_region(hrgn
);
3309 /* expected region is the same as in previous test */
3310 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3312 /* no SW_SCROLLCHILDREN */
3313 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3314 ValidateRect( hwnd1
, NULL
);
3315 ValidateRect( hwnd2
, NULL
);
3316 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3317 if (winetest_debug
> 0) dump_region(hrgn
);
3318 /* expected region is the same as in previous test */
3319 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3321 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3322 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3323 ValidateRect( hwnd1
, NULL
);
3324 ValidateRect( hwnd2
, NULL
);
3325 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3326 if (winetest_debug
> 0) dump_region(hrgn
);
3327 SetRectRgn( exprgn
, 88,0,98,20);
3328 SetRectRgn( tmprgn
, 20,20,98,30);
3329 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3330 SetRectRgn( tmprgn
, 20,30,30,88);
3331 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3332 SetRectRgn( tmprgn
, 0,88,30,98);
3333 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3334 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3337 DeleteObject( hrgn
);
3338 DeleteObject( exprgn
);
3339 DeleteObject( tmprgn
);
3340 DestroyWindow( hwnd1
);
3341 DestroyWindow( hwnd2
);
3344 /* couple of tests of return values of scrollbar functions
3345 * called on a scrollbarless window */
3346 static void test_scroll(void)
3351 HWND hwnd
= CreateWindowExA(0, "Static", "Wine test window",
3352 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_POPUP
,
3353 100, 100, 200, 200, 0, 0, 0, NULL
);
3355 ret
= GetScrollRange( hwnd
, SB_HORZ
, &min
, &max
);
3356 if (!ret
) /* win9x */
3358 win_skip( "GetScrollRange doesn't work\n" );
3359 DestroyWindow( hwnd
);
3362 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3363 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3364 si
.cbSize
= sizeof( si
);
3365 si
.fMask
= SIF_PAGE
;
3366 si
.nPage
= 0xdeadbeef;
3367 ret
= GetScrollInfo( hwnd
, SB_HORZ
, &si
);
3368 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3369 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3371 ret
= GetScrollRange( hwnd
, SB_VERT
, &min
, &max
);
3372 ok( ret
, "GetScrollRange returns FALSE\n");
3373 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3374 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3375 si
.cbSize
= sizeof( si
);
3376 si
.fMask
= SIF_PAGE
;
3377 si
.nPage
= 0xdeadbeef;
3378 ret
= GetScrollInfo( hwnd
, SB_VERT
, &si
);
3379 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3380 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3382 DestroyWindow( hwnd
);
3385 static void test_scrolldc( HWND parent
)
3388 HRGN exprgn
, tmprgn
, hrgn
;
3389 RECT rc
, rc2
, rcu
, cliprc
;
3393 hrgn
= CreateRectRgn(0,0,0,0);
3394 tmprgn
= CreateRectRgn(0,0,0,0);
3395 exprgn
= CreateRectRgn(0,0,0,0);
3397 hwnd1
= CreateWindowExA(0, "static", NULL
,
3398 WS_CHILD
| WS_VISIBLE
,
3399 25, 50, 100, 100, parent
, 0, 0, NULL
);
3400 ShowWindow( parent
, SW_SHOW
);
3401 UpdateWindow( parent
);
3402 flush_events( TRUE
);
3403 GetClientRect( hwnd1
, &rc
);
3404 hdc
= GetDC( hwnd1
);
3405 /* paint the upper half of the window black */
3407 rc2
.bottom
= ( rc
.top
+ rc
.bottom
) /2;
3408 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3409 /* clip region is the lower half */
3411 cliprc
.top
= (rc
.top
+ rc
.bottom
) /2;
3412 /* test whether scrolled pixels are properly clipped */
3413 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3414 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3415 /* this scroll should not cause any visible changes */
3416 ScrollDC( hdc
, 5, -20, &rc
, &cliprc
, hrgn
, &rcu
);
3417 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3418 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3419 /* test with NULL clip rect */
3420 ScrollDC( hdc
, 20, -20, &rc
, NULL
, hrgn
, &rcu
);
3421 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3422 trace("update rect: %d,%d - %d,%d\n",
3423 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3424 if (winetest_debug
> 0) dump_region(hrgn
);
3425 SetRect(&rc2
, 0, 0, 100, 100);
3426 ok(EqualRect(&rcu
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3427 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
3429 SetRectRgn( exprgn
, 0, 0, 20, 80);
3430 SetRectRgn( tmprgn
, 0, 80, 100, 100);
3431 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3432 if (winetest_debug
> 0) dump_region(exprgn
);
3433 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3434 /* test clip rect > scroll rect */
3435 FillRect( hdc
, &rc
, GetStockObject(WHITE_BRUSH
));
3437 InflateRect( &rc2
, -(rc
.right
-rc
.left
)/4, -(rc
.bottom
-rc
.top
)/4);
3438 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3439 ScrollDC( hdc
, 10, 10, &rc2
, &rc
, hrgn
, &rcu
);
3440 SetRectRgn( exprgn
, 25, 25, 75, 35);
3441 SetRectRgn( tmprgn
, 25, 35, 35, 75);
3442 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3443 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3444 trace("update rect: %d,%d - %d,%d\n",
3445 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3446 if (winetest_debug
> 0) dump_region(hrgn
);
3450 DeleteObject(exprgn
);
3451 DeleteObject(tmprgn
);
3452 DestroyWindow(hwnd1
);
3455 static void test_params(void)
3460 /* Just a param check */
3461 if (pGetMonitorInfoA
)
3463 SetLastError(0xdeadbeef);
3464 rc
= GetWindowText(hwndMain2
, NULL
, 1024);
3465 ok( rc
==0, "GetWindowText: rc=%d err=%d\n",rc
,GetLastError());
3469 /* Skips actually on Win95 and NT4 */
3470 win_skip("Test would crash on Win95\n");
3473 SetLastError(0xdeadbeef);
3474 hwnd
=CreateWindow("LISTBOX", "TestList",
3475 (LBS_STANDARD
& ~LBS_SORT
),
3477 NULL
, (HMENU
)1, NULL
, 0);
3479 ok(!hwnd
|| broken(hwnd
!= NULL
), /* w2k3 sp2 */
3480 "CreateWindow with invalid menu handle should fail\n");
3482 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
|| /* NT */
3483 GetLastError() == 0xdeadbeef, /* Win9x */
3484 "wrong last error value %d\n", GetLastError());
3487 static void test_AWRwindow(LPCSTR
class, LONG style
, LONG exStyle
, BOOL menu
)
3491 hwnd
= CreateWindowEx(exStyle
, class, class, style
,
3498 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style
, exStyle
);
3501 ShowWindow(hwnd
, SW_SHOW
);
3503 test_nonclient_area(hwnd
);
3506 DestroyWindow(hwnd
);
3509 static BOOL
AWR_init(void)
3513 class.style
= CS_HREDRAW
| CS_VREDRAW
;
3514 class.lpfnWndProc
= DefWindowProcA
;
3515 class.cbClsExtra
= 0;
3516 class.cbWndExtra
= 0;
3517 class.hInstance
= 0;
3518 class.hIcon
= LoadIcon (0, IDI_APPLICATION
);
3519 class.hCursor
= LoadCursor (0, IDC_ARROW
);
3520 class.hbrBackground
= 0;
3521 class.lpszMenuName
= 0;
3522 class.lpszClassName
= szAWRClass
;
3524 if (!RegisterClass (&class)) {
3525 ok(FALSE
, "RegisterClass failed\n");
3529 hmenu
= CreateMenu();
3532 ok(hmenu
!= 0, "Failed to create menu\n");
3533 ok(AppendMenu(hmenu
, MF_STRING
, 1, "Test!"), "Failed to create menu item\n");
3539 static void test_AWR_window_size(BOOL menu
)
3543 WS_MAXIMIZE
, WS_BORDER
, WS_DLGFRAME
,
3546 WS_MINIMIZEBOX
, WS_MAXIMIZEBOX
,
3547 WS_HSCROLL
, WS_VSCROLL
3551 WS_EX_TOOLWINDOW
, WS_EX_WINDOWEDGE
,
3554 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3555 WS_EX_DLGMODALFRAME
,
3562 /* A exhaustive check of all the styles takes too long
3563 * so just do a (hopefully representative) sample
3565 for (i
= 0; i
< COUNTOF(styles
); ++i
)
3566 test_AWRwindow(szAWRClass
, styles
[i
], 0, menu
);
3567 for (i
= 0; i
< COUNTOF(exStyles
); ++i
) {
3568 test_AWRwindow(szAWRClass
, WS_POPUP
, exStyles
[i
], menu
);
3569 test_AWRwindow(szAWRClass
, WS_THICKFRAME
, exStyles
[i
], menu
);
3574 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3576 static void test_AdjustWindowRect(void)
3581 SHOWSYSMETRIC(SM_CYCAPTION
);
3582 SHOWSYSMETRIC(SM_CYSMCAPTION
);
3583 SHOWSYSMETRIC(SM_CYMENU
);
3584 SHOWSYSMETRIC(SM_CXEDGE
);
3585 SHOWSYSMETRIC(SM_CYEDGE
);
3586 SHOWSYSMETRIC(SM_CXVSCROLL
);
3587 SHOWSYSMETRIC(SM_CYHSCROLL
);
3588 SHOWSYSMETRIC(SM_CXFRAME
);
3589 SHOWSYSMETRIC(SM_CYFRAME
);
3590 SHOWSYSMETRIC(SM_CXDLGFRAME
);
3591 SHOWSYSMETRIC(SM_CYDLGFRAME
);
3592 SHOWSYSMETRIC(SM_CXBORDER
);
3593 SHOWSYSMETRIC(SM_CYBORDER
);
3595 test_AWR_window_size(FALSE
);
3596 test_AWR_window_size(TRUE
);
3600 #undef SHOWSYSMETRIC
3603 /* Global variables to trigger exit from loop */
3604 static int redrawComplete
, WMPAINT_count
;
3606 static LRESULT WINAPI
redraw_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3611 trace("doing WM_PAINT %d\n", WMPAINT_count
);
3613 if (WMPAINT_count
> 10 && redrawComplete
== 0) {
3615 BeginPaint(hwnd
, &ps
);
3616 EndPaint(hwnd
, &ps
);
3621 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3624 /* Ensure we exit from RedrawNow regardless of invalidated area */
3625 static void test_redrawnow(void)
3630 cls
.style
= CS_DBLCLKS
;
3631 cls
.lpfnWndProc
= redraw_window_procA
;
3634 cls
.hInstance
= GetModuleHandleA(0);
3636 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
3637 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3638 cls
.lpszMenuName
= NULL
;
3639 cls
.lpszClassName
= "RedrawWindowClass";
3641 if(!RegisterClassA(&cls
)) {
3642 trace("Register failed %d\n", GetLastError());
3646 hwndMain
= CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3647 CW_USEDEFAULT
, 0, 100, 100, NULL
, NULL
, 0, NULL
);
3649 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3650 ShowWindow(hwndMain
, SW_SHOW
);
3651 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3652 RedrawWindow(hwndMain
, NULL
,NULL
,RDW_UPDATENOW
| RDW_ALLCHILDREN
);
3653 ok( WMPAINT_count
== 1 || broken(WMPAINT_count
== 0), /* sometimes on win9x */
3654 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3655 redrawComplete
= TRUE
;
3656 ok( WMPAINT_count
< 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count
);
3659 DestroyWindow( hwndMain
);
3662 struct parentdc_stat
{
3668 struct parentdc_test
{
3669 struct parentdc_stat main
, main_todo
;
3670 struct parentdc_stat child1
, child1_todo
;
3671 struct parentdc_stat child2
, child2_todo
;
3674 static LRESULT WINAPI
parentdc_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3679 struct parentdc_stat
*t
= (struct parentdc_stat
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
3684 GetClientRect(hwnd
, &rc
);
3685 CopyRect(&t
->client
, &rc
);
3686 GetWindowRect(hwnd
, &rc
);
3687 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd
,
3688 t
->client
.left
, t
->client
.top
, t
->client
.right
, t
->client
.bottom
,
3689 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3690 BeginPaint(hwnd
, &ps
);
3691 CopyRect(&t
->paint
, &ps
.rcPaint
);
3692 GetClipBox(ps
.hdc
, &rc
);
3693 CopyRect(&t
->clip
, &rc
);
3694 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
3695 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
3696 ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
3697 EndPaint(hwnd
, &ps
);
3700 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3703 static void zero_parentdc_stat(struct parentdc_stat
*t
)
3705 SetRectEmpty(&t
->client
);
3706 SetRectEmpty(&t
->clip
);
3707 SetRectEmpty(&t
->paint
);
3710 static void zero_parentdc_test(struct parentdc_test
*t
)
3712 zero_parentdc_stat(&t
->main
);
3713 zero_parentdc_stat(&t
->child1
);
3714 zero_parentdc_stat(&t
->child2
);
3717 #define parentdc_field_ok(t, w, r, f, got) \
3718 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3719 ": expected %d, got %d\n", \
3722 #define parentdc_todo_field_ok(t, w, r, f, got) \
3723 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3724 else parentdc_field_ok(t, w, r, f, got)
3726 #define parentdc_rect_ok(t, w, r, got) \
3727 parentdc_todo_field_ok(t, w, r, left, got); \
3728 parentdc_todo_field_ok(t, w, r, top, got); \
3729 parentdc_todo_field_ok(t, w, r, right, got); \
3730 parentdc_todo_field_ok(t, w, r, bottom, got);
3732 #define parentdc_win_ok(t, w, got) \
3733 parentdc_rect_ok(t, w, client, got); \
3734 parentdc_rect_ok(t, w, clip, got); \
3735 parentdc_rect_ok(t, w, paint, got);
3737 #define parentdc_ok(t, got) \
3738 parentdc_win_ok(t, main, got); \
3739 parentdc_win_ok(t, child1, got); \
3740 parentdc_win_ok(t, child2, got);
3742 static void test_csparentdc(void)
3744 WNDCLASSA clsMain
, cls
;
3745 HWND hwndMain
, hwnd1
, hwnd2
;
3748 struct parentdc_test test_answer
;
3750 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3751 const struct parentdc_test test1
=
3753 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo
,
3754 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3755 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3758 const struct parentdc_test test2
=
3760 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo
,
3761 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3762 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3765 const struct parentdc_test test3
=
3767 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3768 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3769 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3772 const struct parentdc_test test4
=
3774 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo
,
3775 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo
,
3776 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3779 const struct parentdc_test test5
=
3781 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo
,
3782 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3783 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3786 const struct parentdc_test test6
=
3788 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3789 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3790 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3793 const struct parentdc_test test7
=
3795 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3796 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3797 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3801 clsMain
.style
= CS_DBLCLKS
;
3802 clsMain
.lpfnWndProc
= parentdc_window_procA
;
3803 clsMain
.cbClsExtra
= 0;
3804 clsMain
.cbWndExtra
= 0;
3805 clsMain
.hInstance
= GetModuleHandleA(0);
3807 clsMain
.hCursor
= LoadCursorA(0, IDC_ARROW
);
3808 clsMain
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3809 clsMain
.lpszMenuName
= NULL
;
3810 clsMain
.lpszClassName
= "ParentDcMainWindowClass";
3812 if(!RegisterClassA(&clsMain
)) {
3813 trace("Register failed %d\n", GetLastError());
3817 cls
.style
= CS_DBLCLKS
| CS_PARENTDC
;
3818 cls
.lpfnWndProc
= parentdc_window_procA
;
3821 cls
.hInstance
= GetModuleHandleA(0);
3823 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
3824 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3825 cls
.lpszMenuName
= NULL
;
3826 cls
.lpszClassName
= "ParentDcWindowClass";
3828 if(!RegisterClassA(&cls
)) {
3829 trace("Register failed %d\n", GetLastError());
3833 SetRect(&rc
, 0, 0, 150, 150);
3834 AdjustWindowRectEx(&rc
, WS_OVERLAPPEDWINDOW
, FALSE
, 0);
3835 hwndMain
= CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3836 CW_USEDEFAULT
, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, NULL
, NULL
, 0, NULL
);
3837 SetWindowLongPtrA(hwndMain
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.main
);
3838 hwnd1
= CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD
,
3839 20, 20, 40, 40, hwndMain
, NULL
, 0, NULL
);
3840 SetWindowLongPtrA(hwnd1
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child1
);
3841 hwnd2
= CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD
,
3842 40, 40, 40, 40, hwndMain
, NULL
, 0, NULL
);
3843 SetWindowLongPtrA(hwnd2
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child2
);
3844 ShowWindow(hwndMain
, SW_SHOW
);
3845 ShowWindow(hwnd1
, SW_SHOW
);
3846 ShowWindow(hwnd2
, SW_SHOW
);
3847 SetWindowPos(hwndMain
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
3848 flush_events( TRUE
);
3850 zero_parentdc_test(&test_answer
);
3851 InvalidateRect(hwndMain
, NULL
, TRUE
);
3852 flush_events( TRUE
);
3853 parentdc_ok(test1
, test_answer
);
3855 zero_parentdc_test(&test_answer
);
3856 SetRect(&rc
, 0, 0, 50, 50);
3857 InvalidateRect(hwndMain
, &rc
, TRUE
);
3858 flush_events( TRUE
);
3859 parentdc_ok(test2
, test_answer
);
3861 zero_parentdc_test(&test_answer
);
3862 SetRect(&rc
, 0, 0, 10, 10);
3863 InvalidateRect(hwndMain
, &rc
, TRUE
);
3864 flush_events( TRUE
);
3865 parentdc_ok(test3
, test_answer
);
3867 zero_parentdc_test(&test_answer
);
3868 SetRect(&rc
, 40, 40, 50, 50);
3869 InvalidateRect(hwndMain
, &rc
, TRUE
);
3870 flush_events( TRUE
);
3871 parentdc_ok(test4
, test_answer
);
3873 zero_parentdc_test(&test_answer
);
3874 SetRect(&rc
, 20, 20, 60, 60);
3875 InvalidateRect(hwndMain
, &rc
, TRUE
);
3876 flush_events( TRUE
);
3877 parentdc_ok(test5
, test_answer
);
3879 zero_parentdc_test(&test_answer
);
3880 SetRect(&rc
, 0, 0, 10, 10);
3881 InvalidateRect(hwnd1
, &rc
, TRUE
);
3882 flush_events( TRUE
);
3883 parentdc_ok(test6
, test_answer
);
3885 zero_parentdc_test(&test_answer
);
3886 SetRect(&rc
, -5, -5, 65, 65);
3887 InvalidateRect(hwnd1
, &rc
, TRUE
);
3888 flush_events( TRUE
);
3889 parentdc_ok(test7
, test_answer
);
3891 DestroyWindow(hwndMain
);
3892 DestroyWindow(hwnd1
);
3893 DestroyWindow(hwnd2
);
3896 static LRESULT WINAPI
def_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3898 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
3901 static LRESULT WINAPI
def_window_procW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3903 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
3906 static void test_IsWindowUnicode(void)
3908 static const char ansi_class_nameA
[] = "ansi class name";
3909 static const WCHAR ansi_class_nameW
[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3910 static const char unicode_class_nameA
[] = "unicode class name";
3911 static const WCHAR unicode_class_nameW
[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3916 memset(&classW
, 0, sizeof(classW
));
3917 classW
.hInstance
= GetModuleHandleA(0);
3918 classW
.lpfnWndProc
= def_window_procW
;
3919 classW
.lpszClassName
= unicode_class_nameW
;
3920 if (!RegisterClassW(&classW
)) return; /* this catches Win9x as well */
3922 memset(&classA
, 0, sizeof(classA
));
3923 classA
.hInstance
= GetModuleHandleA(0);
3924 classA
.lpfnWndProc
= def_window_procA
;
3925 classA
.lpszClassName
= ansi_class_nameA
;
3926 assert(RegisterClassA(&classA
));
3928 /* unicode class: window proc */
3929 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
3930 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3933 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3934 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3935 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3936 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3937 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3939 DestroyWindow(hwnd
);
3941 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
3942 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3945 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3946 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3947 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3948 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3949 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3951 DestroyWindow(hwnd
);
3953 /* ansi class: window proc */
3954 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
3955 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3958 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3959 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3960 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3961 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3962 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3964 DestroyWindow(hwnd
);
3966 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
3967 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3970 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3971 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3972 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3973 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3974 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3976 DestroyWindow(hwnd
);
3978 /* unicode class: class proc */
3979 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
3980 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3983 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3984 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3985 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3986 /* do not restore class window proc back to unicode */
3988 DestroyWindow(hwnd
);
3990 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
3991 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3994 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3995 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3996 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3998 DestroyWindow(hwnd
);
4000 /* ansi class: class proc */
4001 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
4002 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4005 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4006 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
4007 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
4008 /* do not restore class window proc back to ansi */
4010 DestroyWindow(hwnd
);
4012 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
4013 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
4016 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4017 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
4018 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
4020 DestroyWindow(hwnd
);
4023 static LRESULT CALLBACK
minmax_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
4027 if (msg
!= WM_GETMINMAXINFO
)
4028 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4030 minmax
= (MINMAXINFO
*)lp
;
4032 if ((GetWindowLong(hwnd
, GWL_STYLE
) & WS_CHILD
))
4034 minmax
->ptReserved
.x
= 0;
4035 minmax
->ptReserved
.y
= 0;
4036 minmax
->ptMaxSize
.x
= 400;
4037 minmax
->ptMaxSize
.y
= 400;
4038 minmax
->ptMaxPosition
.x
= 300;
4039 minmax
->ptMaxPosition
.y
= 300;
4040 minmax
->ptMaxTrackSize
.x
= 200;
4041 minmax
->ptMaxTrackSize
.y
= 200;
4042 minmax
->ptMinTrackSize
.x
= 100;
4043 minmax
->ptMinTrackSize
.y
= 100;
4046 DefWindowProc(hwnd
, msg
, wp
, lp
);
4050 static int expected_cx
, expected_cy
;
4051 static RECT expected_rect
, broken_rect
;
4053 static LRESULT CALLBACK
winsizes_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
4057 case WM_GETMINMAXINFO
:
4060 GetWindowRect( hwnd
, &rect
);
4061 ok( !rect
.left
&& !rect
.top
&& !rect
.right
&& !rect
.bottom
,
4062 "wrong rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4063 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4068 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
4070 GetWindowRect( hwnd
, &rect
);
4071 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
4072 hwnd
, msg
, cs
->cx
, cs
->cy
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4073 ok( cs
->cx
== expected_cx
|| broken(cs
->cx
== (short)expected_cx
),
4074 "wrong x size %d/%d\n", cs
->cx
, expected_cx
);
4075 ok( cs
->cy
== expected_cy
|| broken(cs
->cy
== (short)expected_cy
),
4076 "wrong y size %d/%d\n", cs
->cy
, expected_cy
);
4077 ok( (rect
.right
- rect
.left
== expected_rect
.right
- expected_rect
.left
&&
4078 rect
.bottom
- rect
.top
== expected_rect
.bottom
- expected_rect
.top
) ||
4079 broken( rect
.right
- rect
.left
== broken_rect
.right
- broken_rect
.left
&&
4080 rect
.bottom
- rect
.top
== broken_rect
.bottom
- broken_rect
.top
) ||
4081 broken( rect
.right
- rect
.left
== (short)broken_rect
.right
- (short)broken_rect
.left
&&
4082 rect
.bottom
- rect
.top
== (short)broken_rect
.bottom
- (short)broken_rect
.top
),
4083 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
4084 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
4085 expected_rect
.left
, expected_rect
.top
, expected_rect
.right
, expected_rect
.bottom
);
4086 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4090 RECT rect
, *r
= (RECT
*)lp
;
4091 GetWindowRect( hwnd
, &rect
);
4092 ok( !memcmp( &rect
, r
, sizeof(rect
) ),
4093 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
4094 r
->left
, r
->top
, r
->right
, r
->bottom
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4095 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4098 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4102 static void test_CreateWindow(void)
4110 #define expect_menu(window, menu) \
4111 SetLastError(0xdeadbeef); \
4112 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
4114 #define expect_style(window, style)\
4115 ok((ULONG)GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
4117 #define expect_ex_style(window, ex_style)\
4118 ok((ULONG)GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
4120 #define expect_gle_broken_9x(gle)\
4121 ok(GetLastError() == gle ||\
4122 broken(GetLastError() == 0xdeadbeef),\
4123 "IsMenu set error %d\n", GetLastError())
4125 hmenu
= CreateMenu();
4127 parent
= GetDesktopWindow();
4128 assert(parent
!= 0);
4130 SetLastError(0xdeadbeef);
4131 ok(IsMenu(hmenu
), "IsMenu error %d\n", GetLastError());
4134 SetLastError(0xdeadbeef);
4135 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
,
4136 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4137 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4138 expect_menu(hwnd
, 1);
4139 expect_style(hwnd
, WS_CHILD
);
4140 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4141 DestroyWindow(hwnd
);
4143 SetLastError(0xdeadbeef);
4144 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_CAPTION
,
4145 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4146 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4147 expect_menu(hwnd
, 1);
4148 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
4149 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4150 DestroyWindow(hwnd
);
4152 SetLastError(0xdeadbeef);
4153 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
,
4154 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4155 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4156 expect_menu(hwnd
, 1);
4157 expect_style(hwnd
, WS_CHILD
);
4158 expect_ex_style(hwnd
, 0);
4159 DestroyWindow(hwnd
);
4161 SetLastError(0xdeadbeef);
4162 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_CAPTION
,
4163 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4164 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4165 expect_menu(hwnd
, 1);
4166 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
4167 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4168 DestroyWindow(hwnd
);
4171 SetLastError(0xdeadbeef);
4172 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
4173 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4174 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4175 expect_menu(hwnd
, hmenu
);
4176 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4177 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4178 DestroyWindow(hwnd
);
4179 SetLastError(0xdeadbeef);
4180 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4181 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4183 hmenu
= CreateMenu();
4185 SetLastError(0xdeadbeef);
4186 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4187 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4188 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4189 expect_menu(hwnd
, hmenu
);
4190 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4191 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4192 DestroyWindow(hwnd
);
4193 SetLastError(0xdeadbeef);
4194 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4195 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4197 hmenu
= CreateMenu();
4199 SetLastError(0xdeadbeef);
4200 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
,
4201 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4202 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4203 expect_menu(hwnd
, hmenu
);
4204 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4205 expect_ex_style(hwnd
, 0);
4206 DestroyWindow(hwnd
);
4207 SetLastError(0xdeadbeef);
4208 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4209 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4211 hmenu
= CreateMenu();
4213 SetLastError(0xdeadbeef);
4214 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4215 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4216 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4217 expect_menu(hwnd
, hmenu
);
4218 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4219 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4220 DestroyWindow(hwnd
);
4221 SetLastError(0xdeadbeef);
4222 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4223 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4225 /* WS_CHILD | WS_POPUP */
4226 SetLastError(0xdeadbeef);
4227 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4228 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4229 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
4230 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4232 DestroyWindow(hwnd
);
4234 hmenu
= CreateMenu();
4236 SetLastError(0xdeadbeef);
4237 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4238 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4239 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4240 expect_menu(hwnd
, hmenu
);
4241 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4242 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4243 DestroyWindow(hwnd
);
4244 SetLastError(0xdeadbeef);
4245 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4246 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4248 SetLastError(0xdeadbeef);
4249 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4250 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4251 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
4252 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4254 DestroyWindow(hwnd
);
4256 hmenu
= CreateMenu();
4258 SetLastError(0xdeadbeef);
4259 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4260 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4261 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4262 expect_menu(hwnd
, hmenu
);
4263 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4264 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4265 DestroyWindow(hwnd
);
4266 SetLastError(0xdeadbeef);
4267 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4268 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4270 SetLastError(0xdeadbeef);
4271 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4272 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4273 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
4274 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4276 DestroyWindow(hwnd
);
4278 hmenu
= CreateMenu();
4280 SetLastError(0xdeadbeef);
4281 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4282 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4283 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4284 expect_menu(hwnd
, hmenu
);
4285 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4286 expect_ex_style(hwnd
, 0);
4287 DestroyWindow(hwnd
);
4288 SetLastError(0xdeadbeef);
4289 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4290 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4292 SetLastError(0xdeadbeef);
4293 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4294 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4295 ok(!hwnd
|| broken(hwnd
!= 0 /* Win9x */), "CreateWindowEx should fail\n");
4296 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4298 DestroyWindow(hwnd
);
4300 hmenu
= CreateMenu();
4302 SetLastError(0xdeadbeef);
4303 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4304 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4305 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4306 expect_menu(hwnd
, hmenu
);
4307 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4308 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4309 DestroyWindow(hwnd
);
4310 SetLastError(0xdeadbeef);
4311 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4312 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE
);
4314 /* test child window sizing */
4316 cls
.lpfnWndProc
= minmax_wnd_proc
;
4319 cls
.hInstance
= GetModuleHandle(0);
4321 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
4322 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4323 cls
.lpszMenuName
= NULL
;
4324 cls
.lpszClassName
= "MinMax_WndClass";
4325 RegisterClass(&cls
);
4327 SetLastError(0xdeadbeef);
4328 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4329 0, 0, 100, 100, 0, 0, 0, NULL
);
4330 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
4331 expect_menu(parent
, 0);
4332 expect_style(parent
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
| WS_CLIPSIBLINGS
);
4333 expect_ex_style(parent
, WS_EX_WINDOWEDGE
);
4335 memset(&minmax
, 0, sizeof(minmax
));
4336 SendMessage(parent
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4337 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxSize
.x
, minmax
.ptMaxSize
.y
);
4338 ok(IsRectEmpty(&rc_minmax
), "ptMaxSize is not empty\n");
4339 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4340 ok(IsRectEmpty(&rc_minmax
), "ptMaxTrackSize is not empty\n");
4342 GetWindowRect(parent
, &rc
);
4343 ok(!IsRectEmpty(&rc
), "parent window rect is empty\n");
4344 GetClientRect(parent
, &rc
);
4345 ok(!IsRectEmpty(&rc
), "parent client rect is empty\n");
4347 InflateRect(&rc
, 200, 200);
4348 trace("creating child with rect (%d,%d-%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4350 SetLastError(0xdeadbeef);
4351 hwnd
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4352 rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
4353 parent
, (HMENU
)1, 0, NULL
);
4354 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4355 expect_menu(hwnd
, 1);
4356 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
);
4357 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4359 memset(&minmax
, 0, sizeof(minmax
));
4360 SendMessage(hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4361 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4363 GetWindowRect(hwnd
, &rc
);
4364 OffsetRect(&rc
, -rc
.left
, -rc
.top
);
4365 ok(EqualRect(&rc
, &rc_minmax
), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4366 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
4367 rc_minmax
.left
, rc_minmax
.top
, rc_minmax
.right
, rc_minmax
.bottom
);
4368 DestroyWindow(hwnd
);
4370 cls
.lpfnWndProc
= winsizes_wnd_proc
;
4371 cls
.lpszClassName
= "Sizes_WndClass";
4372 RegisterClass(&cls
);
4374 expected_cx
= expected_cy
= 200000;
4375 SetRect( &expected_rect
, 0, 0, 200000, 200000 );
4376 broken_rect
= expected_rect
;
4377 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 300000, 300000, 200000, 200000, parent
, 0, 0, NULL
);
4378 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4379 GetClientRect( hwnd
, &rc
);
4380 ok( rc
.right
== 200000 || broken(rc
.right
== (short)200000), "invalid rect right %u\n", rc
.right
);
4381 ok( rc
.bottom
== 200000 || broken(rc
.bottom
== (short)200000), "invalid rect bottom %u\n", rc
.bottom
);
4382 DestroyWindow(hwnd
);
4384 expected_cx
= expected_cy
= -10;
4385 SetRect( &expected_rect
, 0, 0, 0, 0 );
4386 SetRect( &broken_rect
, 0, 0, -10, -10 );
4387 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -20, -20, -10, -10, parent
, 0, 0, NULL
);
4388 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4389 GetClientRect( hwnd
, &rc
);
4390 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4391 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4392 DestroyWindow(hwnd
);
4394 expected_cx
= expected_cy
= -200000;
4395 SetRect( &expected_rect
, 0, 0, 0, 0 );
4396 SetRect( &broken_rect
, 0, 0, -200000, -200000 );
4397 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -300000, -300000, -200000, -200000, parent
, 0, 0, NULL
);
4398 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4399 GetClientRect( hwnd
, &rc
);
4400 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4401 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4402 DestroyWindow(hwnd
);
4404 /* we need a parent at 0,0 so that child coordinates match */
4405 DestroyWindow(parent
);
4406 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_POPUP
, 0, 0, 100, 100, 0, 0, 0, NULL
);
4407 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
4410 expected_cy
= 0x7fffffff;
4411 SetRect( &expected_rect
, 10, 10, 110, 0x7fffffff );
4412 SetRect( &broken_rect
, 10, 10, 110, 0x7fffffffU
+ 10 );
4413 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 10, 10, 100, 0x7fffffff, parent
, 0, 0, NULL
);
4414 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4415 GetClientRect( hwnd
, &rc
);
4416 ok( rc
.right
== 100, "invalid rect right %u\n", rc
.right
);
4417 ok( rc
.bottom
== 0x7fffffff - 10 || broken(rc
.bottom
== 0), "invalid rect bottom %u\n", rc
.bottom
);
4418 DestroyWindow(hwnd
);
4420 expected_cx
= 0x7fffffff;
4421 expected_cy
= 0x7fffffff;
4422 SetRect( &expected_rect
, 20, 10, 0x7fffffff, 0x7fffffff );
4423 SetRect( &broken_rect
, 20, 10, 0x7fffffffU
+ 20, 0x7fffffffU
+ 10 );
4424 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 20, 10, 0x7fffffff, 0x7fffffff, parent
, 0, 0, NULL
);
4425 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4426 GetClientRect( hwnd
, &rc
);
4427 ok( rc
.right
== 0x7fffffff - 20 || broken(rc
.right
== 0), "invalid rect right %u\n", rc
.right
);
4428 ok( rc
.bottom
== 0x7fffffff - 10 || broken(rc
.bottom
== 0), "invalid rect bottom %u\n", rc
.bottom
);
4429 DestroyWindow(hwnd
);
4431 /* top level window */
4432 expected_cx
= expected_cy
= 200000;
4433 SetRect( &expected_rect
, 0, 0, GetSystemMetrics(SM_CXMAXTRACK
), GetSystemMetrics(SM_CYMAXTRACK
) );
4434 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_OVERLAPPEDWINDOW
, 300000, 300000, 200000, 200000, 0, 0, 0, NULL
);
4435 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4436 GetClientRect( hwnd
, &rc
);
4437 ok( rc
.right
<= expected_cx
, "invalid rect right %u\n", rc
.right
);
4438 ok( rc
.bottom
<= expected_cy
, "invalid rect bottom %u\n", rc
.bottom
);
4439 DestroyWindow(hwnd
);
4441 DestroyWindow(parent
);
4443 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4444 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4446 #undef expect_gle_broken_9x
4449 #undef expect_ex_style
4452 /* function that remembers whether the system the test is running on sets the
4453 * last error for user32 functions to make the tests stricter */
4454 static int check_error(DWORD actual
, DWORD expected
)
4456 static int sets_last_error
= -1;
4457 if (sets_last_error
== -1)
4458 sets_last_error
= (actual
!= 0xdeadbeef);
4459 return (!sets_last_error
&& (actual
== 0xdeadbeef)) || (actual
== expected
);
4462 static void test_SetWindowLong(void)
4465 WNDPROC old_window_procW
;
4467 SetLastError(0xdeadbeef);
4468 retval
= SetWindowLongPtr(NULL
, GWLP_WNDPROC
, 0);
4469 ok(!retval
, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval
);
4470 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE
),
4471 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4473 SetLastError(0xdeadbeef);
4474 retval
= SetWindowLongPtr(hwndMain
, 0xdeadbeef, 0);
4475 ok(!retval
, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval
);
4476 ok(check_error(GetLastError(), ERROR_INVALID_INDEX
),
4477 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4479 SetLastError(0xdeadbeef);
4480 retval
= SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4481 ok((WNDPROC
)retval
== main_window_procA
|| broken(!retval
), /* win9x */
4482 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval
);
4483 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4484 retval
= GetWindowLongPtr(hwndMain
, GWLP_WNDPROC
);
4485 ok((WNDPROC
)retval
== main_window_procA
,
4486 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4487 ok(!IsWindowUnicode(hwndMain
), "hwndMain shouldn't be Unicode\n");
4489 old_window_procW
= (WNDPROC
)GetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
);
4490 SetLastError(0xdeadbeef);
4491 retval
= SetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
, 0);
4492 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED
)
4494 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4495 ok(retval
!= 0, "SetWindowLongPtr error %d\n", GetLastError());
4496 ok((WNDPROC
)retval
== old_window_procW
,
4497 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4498 ok(IsWindowUnicode(hwndMain
), "hwndMain should now be Unicode\n");
4500 /* set it back to ANSI */
4501 SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4505 static void test_ShowWindow(void)
4512 SetRect(&rcMain
, 120, 120, 210, 210);
4514 hwnd
= CreateWindowEx(0, "MainWindowClass", NULL
,
4515 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4516 WS_MAXIMIZEBOX
| WS_POPUP
,
4517 rcMain
.left
, rcMain
.top
,
4518 rcMain
.right
- rcMain
.left
, rcMain
.bottom
- rcMain
.top
,
4522 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4523 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4524 ok(!(style
& WS_VISIBLE
), "window should not be visible\n");
4525 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4526 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4527 GetWindowRect(hwnd
, &rc
);
4528 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4529 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4530 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4532 ret
= ShowWindow(hwnd
, SW_SHOW
);
4533 ok(!ret
, "not expected ret: %lu\n", ret
);
4534 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4535 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4536 ok(style
& WS_VISIBLE
, "window should be visible\n");
4537 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4538 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4539 GetWindowRect(hwnd
, &rc
);
4540 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4541 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4542 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4544 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4545 ok(ret
, "not expected ret: %lu\n", ret
);
4546 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4547 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4548 ok(style
& WS_VISIBLE
, "window should be visible\n");
4549 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4550 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4551 GetWindowRect(hwnd
, &rc
);
4552 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4554 ShowWindow(hwnd
, SW_RESTORE
);
4555 ok(ret
, "not expected ret: %lu\n", ret
);
4556 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4557 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4558 ok(style
& WS_VISIBLE
, "window should be visible\n");
4559 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4560 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4561 GetWindowRect(hwnd
, &rc
);
4562 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4563 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4564 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4566 ret
= EnableWindow(hwnd
, FALSE
);
4567 ok(!ret
, "not expected ret: %lu\n", ret
);
4568 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4569 ok(style
& WS_DISABLED
, "window should be disabled\n");
4571 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
4572 ok(!ret
, "not expected ret: %lu\n", ret
);
4573 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4574 ok(style
& WS_DISABLED
, "window should be disabled\n");
4575 ok(style
& WS_VISIBLE
, "window should be visible\n");
4576 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4577 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4578 GetWindowRect(hwnd
, &rc
);
4579 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4580 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4581 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4583 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
4584 ok(!ret
, "not expected ret: %lu\n", ret
);
4585 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4586 ok(style
& WS_DISABLED
, "window should be disabled\n");
4587 ok(style
& WS_VISIBLE
, "window should be visible\n");
4588 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4589 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4590 GetWindowRect(hwnd
, &rc
);
4591 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4592 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4593 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4595 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4596 ok(ret
, "not expected ret: %lu\n", ret
);
4597 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4598 ok(style
& WS_DISABLED
, "window should be disabled\n");
4599 ok(style
& WS_VISIBLE
, "window should be visible\n");
4600 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4601 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4602 GetWindowRect(hwnd
, &rc
);
4603 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4605 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
4606 ok(!ret
, "not expected ret: %lu\n", ret
);
4607 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4608 ok(style
& WS_DISABLED
, "window should be disabled\n");
4609 ok(style
& WS_VISIBLE
, "window should be visible\n");
4610 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4611 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4612 GetWindowRect(hwnd
, &rc
);
4613 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4615 ret
= ShowWindow(hwnd
, SW_RESTORE
);
4616 ok(ret
, "not expected ret: %lu\n", ret
);
4617 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4618 ok(style
& WS_DISABLED
, "window should be disabled\n");
4619 ok(style
& WS_VISIBLE
, "window should be visible\n");
4620 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4621 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4622 GetWindowRect(hwnd
, &rc
);
4623 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4624 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4625 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4627 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4628 ok(!ret
, "not expected ret: %lu\n", ret
);
4629 ok(IsWindow(hwnd
), "window should exist\n");
4631 ret
= EnableWindow(hwnd
, TRUE
);
4632 ok(ret
, "not expected ret: %lu\n", ret
);
4634 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4635 ok(!ret
, "not expected ret: %lu\n", ret
);
4636 ok(!IsWindow(hwnd
), "window should not exist\n");
4639 static void test_gettext(void)
4642 LPCSTR clsname
= "gettexttest";
4646 memset( &cls
, 0, sizeof cls
);
4647 cls
.lpfnWndProc
= DefWindowProc
;
4648 cls
.lpszClassName
= clsname
;
4649 cls
.hInstance
= GetModuleHandle(NULL
);
4651 if (!RegisterClass( &cls
)) return;
4653 hwnd
= CreateWindow( clsname
, "test text", WS_OVERLAPPED
, 0, 0, 10, 10, 0, NULL
, NULL
, NULL
);
4654 ok( hwnd
!= NULL
, "window was null\n");
4656 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10, 0x1000);
4657 ok( r
== 0, "settext should return zero\n");
4659 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10000, 0);
4660 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4662 r
= SendMessage( hwnd
, WM_GETTEXT
, 0xff000000, 0x1000);
4663 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4665 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x1000, 0xff000000);
4666 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4668 DestroyWindow(hwnd
);
4669 UnregisterClass( clsname
, NULL
);
4673 static void test_GetUpdateRect(void)
4676 BOOL ret
, parent_wm_paint
, grandparent_wm_paint
;
4678 HWND hgrandparent
, hparent
, hchild
;
4680 static const char classNameA
[] = "GetUpdateRectClass";
4682 hgrandparent
= CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW
,
4683 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4685 hparent
= CreateWindowA("static", "parent", WS_CHILD
|WS_VISIBLE
,
4686 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4688 hchild
= CreateWindowA("static", "child", WS_CHILD
|WS_VISIBLE
,
4689 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4691 ShowWindow(hgrandparent
, SW_SHOW
);
4692 UpdateWindow(hgrandparent
);
4693 flush_events( TRUE
);
4695 ShowWindow(hchild
, SW_HIDE
);
4696 SetRect(&rc2
, 0, 0, 0, 0);
4697 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4698 ok(!ret
, "GetUpdateRect returned not empty region\n");
4699 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4700 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4701 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4703 SetRect(&rc2
, 10, 10, 40, 40);
4704 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
4705 ok(ret
, "GetUpdateRect returned empty region\n");
4706 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4707 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4708 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4710 parent_wm_paint
= FALSE
;
4711 grandparent_wm_paint
= FALSE
;
4712 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
4714 if (msg
.message
== WM_PAINT
)
4716 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
4717 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
4719 DispatchMessage(&msg
);
4721 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
4722 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
4724 DestroyWindow(hgrandparent
);
4727 cls
.lpfnWndProc
= DefWindowProcA
;
4730 cls
.hInstance
= GetModuleHandleA(0);
4732 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
4733 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4734 cls
.lpszMenuName
= NULL
;
4735 cls
.lpszClassName
= classNameA
;
4737 if(!RegisterClassA(&cls
)) {
4738 trace("Register failed %d\n", GetLastError());
4742 hgrandparent
= CreateWindowA(classNameA
, "grandparent", WS_OVERLAPPEDWINDOW
,
4743 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4745 hparent
= CreateWindowA(classNameA
, "parent", WS_CHILD
|WS_VISIBLE
,
4746 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4748 hchild
= CreateWindowA(classNameA
, "child", WS_CHILD
|WS_VISIBLE
,
4749 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4751 ShowWindow(hgrandparent
, SW_SHOW
);
4752 UpdateWindow(hgrandparent
);
4753 flush_events( TRUE
);
4755 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4756 ok(!ret
, "GetUpdateRect returned not empty region\n");
4758 ShowWindow(hchild
, SW_HIDE
);
4760 SetRect(&rc2
, 0, 0, 0, 0);
4761 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4762 ok(!ret
, "GetUpdateRect returned not empty region\n");
4763 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4764 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4765 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4767 SetRect(&rc2
, 10, 10, 40, 40);
4768 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
4769 ok(ret
, "GetUpdateRect returned empty region\n");
4770 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4771 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4772 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4774 parent_wm_paint
= FALSE
;
4775 grandparent_wm_paint
= FALSE
;
4776 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
4778 if (msg
.message
== WM_PAINT
)
4780 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
4781 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
4783 DispatchMessage(&msg
);
4785 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
4786 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
4788 DestroyWindow(hgrandparent
);
4792 static LRESULT CALLBACK
TestExposedRegion_WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4800 const int waitTime
= 2000;
4802 BeginPaint(hwnd
, &ps
);
4804 /* create and destroy window to create an exposed region on this window */
4805 win
= CreateWindowA("static", "win", WS_VISIBLE
,
4806 10,10,50,50, NULL
, NULL
, 0, NULL
);
4809 waitResult
= MsgWaitForMultipleObjects( 0, NULL
, FALSE
, waitTime
, QS_PAINT
);
4811 ValidateRect(hwnd
, NULL
);
4812 EndPaint(hwnd
, &ps
);
4814 if(waitResult
!= WAIT_TIMEOUT
)
4816 GetUpdateRect(hwnd
, &updateRect
, FALSE
);
4817 ok(IsRectEmpty(&updateRect
), "Exposed rect should be empty\n");
4822 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
4825 static void test_Expose(void)
4830 memset(&cls
, 0, sizeof(WNDCLASSA
));
4831 cls
.lpfnWndProc
= TestExposedRegion_WndProc
;
4832 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4833 cls
.lpszClassName
= "TestExposeClass";
4834 atom
= RegisterClassA(&cls
);
4836 mw
= CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE
|WS_OVERLAPPEDWINDOW
,
4837 0, 0, 200, 100, NULL
, NULL
, 0, NULL
);
4843 static void test_GetWindowModuleFileName(void)
4848 char buf1
[MAX_PATH
], buf2
[MAX_PATH
];
4850 if (!pGetWindowModuleFileNameA
)
4852 win_skip("GetWindowModuleFileNameA is not available\n");
4856 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0,0,0,0, 0, 0, 0, NULL
);
4859 hinst
= (HINSTANCE
)GetWindowLongPtr(hwnd
, GWLP_HINSTANCE
);
4860 ok(hinst
== 0 || broken(hinst
== GetModuleHandle(0)), /* win9x */ "expected 0, got %p\n", hinst
);
4863 SetLastError(0xdeadbeef);
4864 ret1
= GetModuleFileName(hinst
, buf1
, sizeof(buf1
));
4865 ok(ret1
, "GetModuleFileName error %u\n", GetLastError());
4868 SetLastError(0xdeadbeef);
4869 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, sizeof(buf2
));
4870 ok(ret2
|| broken(!ret2
), /* nt4 sp 3 */
4871 "GetWindowModuleFileNameA error %u\n", GetLastError());
4875 ok(ret1
== ret2
|| broken(ret2
== ret1
+ 1), /* win98 */ "%u != %u\n", ret1
, ret2
);
4876 ok(!strcmp(buf1
, buf2
), "%s != %s\n", buf1
, buf2
);
4878 hinst
= GetModuleHandle(0);
4880 SetLastError(0xdeadbeef);
4881 ret2
= GetModuleFileName(hinst
, buf2
, ret1
- 2);
4882 ok(ret2
== ret1
- 2 || broken(ret2
== ret1
- 3), /* win98 */
4883 "expected %u, got %u\n", ret1
- 2, ret2
);
4884 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4885 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
4886 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4888 SetLastError(0xdeadbeef);
4889 ret2
= GetModuleFileName(hinst
, buf2
, 0);
4890 ok(!ret2
, "GetModuleFileName should return 0\n");
4891 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4892 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
4893 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4895 SetLastError(0xdeadbeef);
4896 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, ret1
- 2);
4897 ok(ret2
== ret1
- 2 || broken(ret2
== ret1
- 3) /* win98 */ || broken(!ret2
), /* nt4 sp3 */
4898 "expected %u, got %u\n", ret1
- 2, ret2
);
4899 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4900 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
4901 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4903 SetLastError(0xdeadbeef);
4904 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, 0);
4905 ok(!ret2
, "expected 0, got %u\n", ret2
);
4906 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4907 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
4908 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4910 DestroyWindow(hwnd
);
4913 hwnd
= (HWND
)0xdeadbeef;
4914 SetLastError(0xdeadbeef);
4915 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
4916 ok(!ret1
, "expected 0, got %u\n", ret1
);
4917 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
|| broken(GetLastError() == 0xdeadbeef), /* win9x */
4918 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
4920 hwnd
= FindWindow("Shell_TrayWnd", NULL
);
4921 ok(IsWindow(hwnd
) || broken(!hwnd
), "got invalid tray window %p\n", hwnd
);
4922 SetLastError(0xdeadbeef);
4923 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
4924 ok(!ret1
|| broken(ret1
), /* win98 */ "expected 0, got %u\n", ret1
);
4926 if (!ret1
) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
4928 ret1
= GetModuleFileName(0, buf1
, sizeof(buf1
));
4929 hwnd
= GetDesktopWindow();
4930 ok(IsWindow(hwnd
), "got invalid desktop window %p\n", hwnd
);
4931 SetLastError(0xdeadbeef);
4932 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, sizeof(buf2
));
4933 ok(!ret2
|| ret1
== ret2
/* vista */, "expected 0 or %u, got %u %s\n", ret1
, ret2
, buf2
);
4937 static void test_hwnd_message(void)
4939 static const WCHAR mainwindowclassW
[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
4940 static const WCHAR message_windowW
[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
4942 HWND parent
= 0, hwnd
, found
;
4945 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
4946 on CreateWindowExA and crash later in the test.
4947 Use UNICODE here to fail on win9x */
4948 hwnd
= CreateWindowExW(0, mainwindowclassW
, message_windowW
, WS_CAPTION
| WS_VISIBLE
,
4949 100, 100, 200, 200, HWND_MESSAGE
, 0, 0, NULL
);
4952 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
4956 ok( !GetParent(hwnd
), "GetParent should return 0 for message only windows\n" );
4960 HWND root
, desktop
= GetDesktopWindow();
4962 parent
= pGetAncestor(hwnd
, GA_PARENT
);
4963 ok(parent
!= 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
4964 ok(parent
!= desktop
, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
4965 root
= pGetAncestor(hwnd
, GA_ROOT
);
4966 ok(root
== hwnd
, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
4967 ok( !pGetAncestor(parent
, GA_PARENT
) || broken(pGetAncestor(parent
, GA_PARENT
) != 0), /* win2k */
4968 "parent shouldn't have parent %p\n", pGetAncestor(parent
, GA_PARENT
) );
4969 trace("parent %p root %p desktop %p\n", parent
, root
, desktop
);
4970 if (!GetClassNameA( parent
, buffer
, sizeof(buffer
) )) buffer
[0] = 0;
4971 ok( !lstrcmpi( buffer
, "Message" ), "wrong parent class '%s'\n", buffer
);
4972 GetWindowRect( parent
, &rect
);
4973 ok( rect
.left
== 0 && rect
.right
== 100 && rect
.top
== 0 && rect
.bottom
== 100,
4974 "wrong parent rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4976 GetWindowRect( hwnd
, &rect
);
4977 ok( rect
.left
== 100 && rect
.right
== 300 && rect
.top
== 100 && rect
.bottom
== 300,
4978 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4980 /* test FindWindow behavior */
4982 found
= FindWindowExA( 0, 0, 0, "message window" );
4983 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
4984 SetLastError(0xdeadbeef);
4985 found
= FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
4986 ok( found
== 0, "found message window %p/%p\n", found
, hwnd
);
4987 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
4990 found
= FindWindowExA( parent
, 0, 0, "message window" );
4991 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
4994 /* test IsChild behavior */
4996 if (parent
) ok( !IsChild( parent
, hwnd
), "HWND_MESSAGE is child of top window\n" );
4998 /* test IsWindowVisible behavior */
5000 ok( !IsWindowVisible( hwnd
), "HWND_MESSAGE window is visible\n" );
5001 if (parent
) ok( !IsWindowVisible( parent
), "HWND_MESSAGE parent is visible\n" );
5003 DestroyWindow(hwnd
);
5006 static void test_layered_window(void)
5014 if (!pGetLayeredWindowAttributes
|| !pSetLayeredWindowAttributes
)
5016 win_skip( "layered windows not supported\n" );
5019 hwnd
= CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION
,
5020 100, 100, 200, 200, 0, 0, 0, NULL
);
5022 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5023 ok( !ret
, "GetLayeredWindowAttributes should fail on non-layered window\n" );
5024 ret
= pSetLayeredWindowAttributes( hwnd
, 0, 0, LWA_ALPHA
);
5025 ok( !ret
, "SetLayeredWindowAttributes should fail on non-layered window\n" );
5026 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
5027 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5028 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5029 ret
= pSetLayeredWindowAttributes( hwnd
, 0x123456, 44, LWA_ALPHA
);
5030 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5031 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5032 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5033 ok( key
== 0x123456 || key
== 0, "wrong color key %x\n", key
);
5034 ok( alpha
== 44, "wrong alpha %u\n", alpha
);
5035 ok( flags
== LWA_ALPHA
, "wrong flags %x\n", flags
);
5037 /* clearing WS_EX_LAYERED resets attributes */
5038 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
5039 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5040 ok( !ret
, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
5041 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
5042 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5043 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5044 ret
= pSetLayeredWindowAttributes( hwnd
, 0x654321, 22, LWA_COLORKEY
| LWA_ALPHA
);
5045 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5046 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5047 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5048 ok( key
== 0x654321, "wrong color key %x\n", key
);
5049 ok( alpha
== 22, "wrong alpha %u\n", alpha
);
5050 ok( flags
== (LWA_COLORKEY
| LWA_ALPHA
), "wrong flags %x\n", flags
);
5052 ret
= pSetLayeredWindowAttributes( hwnd
, 0x888888, 33, LWA_COLORKEY
);
5053 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5055 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5056 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5057 ok( key
== 0x888888, "wrong color key %x\n", key
);
5058 /* alpha not changed on vista if LWA_ALPHA is not set */
5059 ok( alpha
== 22 || alpha
== 33, "wrong alpha %u\n", alpha
);
5060 ok( flags
== LWA_COLORKEY
, "wrong flags %x\n", flags
);
5062 /* color key may or may not be changed without LWA_COLORKEY */
5063 ret
= pSetLayeredWindowAttributes( hwnd
, 0x999999, 44, 0 );
5064 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5066 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5067 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5068 ok( key
== 0x888888 || key
== 0x999999, "wrong color key %x\n", key
);
5069 ok( alpha
== 22 || alpha
== 44, "wrong alpha %u\n", alpha
);
5070 ok( flags
== 0, "wrong flags %x\n", flags
);
5072 /* default alpha and color key is 0 */
5073 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
5074 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
5075 ret
= pSetLayeredWindowAttributes( hwnd
, 0x222222, 55, 0 );
5076 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
5077 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
5078 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
5079 ok( key
== 0 || key
== 0x222222, "wrong color key %x\n", key
);
5080 ok( alpha
== 0 || alpha
== 55, "wrong alpha %u\n", alpha
);
5081 ok( flags
== 0, "wrong flags %x\n", flags
);
5083 DestroyWindow( hwnd
);
5086 static MONITORINFO mi
;
5088 static LRESULT CALLBACK
fullscreen_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
5094 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
5095 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
5096 ok(cs
->x
== mi
.rcMonitor
.left
&& cs
->y
== mi
.rcMonitor
.top
&&
5097 cs
->cx
== mi
.rcMonitor
.right
&& cs
->cy
== mi
.rcMonitor
.bottom
,
5098 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
5099 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5100 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
5103 case WM_GETMINMAXINFO
:
5105 MINMAXINFO
*minmax
= (MINMAXINFO
*)lp
;
5106 dump_minmax_info(minmax
);
5107 ok(minmax
->ptMaxPosition
.x
<= mi
.rcMonitor
.left
, "%d <= %d\n", minmax
->ptMaxPosition
.x
, mi
.rcMonitor
.left
);
5108 ok(minmax
->ptMaxPosition
.y
<= mi
.rcMonitor
.top
, "%d <= %d\n", minmax
->ptMaxPosition
.y
, mi
.rcMonitor
.top
);
5109 ok(minmax
->ptMaxSize
.x
>= mi
.rcMonitor
.right
, "%d >= %d\n", minmax
->ptMaxSize
.x
, mi
.rcMonitor
.right
);
5110 ok(minmax
->ptMaxSize
.y
>= mi
.rcMonitor
.bottom
, "%d >= %d\n", minmax
->ptMaxSize
.y
, mi
.rcMonitor
.bottom
);
5114 return DefWindowProc(hwnd
, msg
, wp
, lp
);
5117 static void test_fullscreen(void)
5119 static const DWORD t_style
[] = {
5120 WS_OVERLAPPED
, WS_POPUP
, WS_CHILD
, WS_THICKFRAME
, WS_DLGFRAME
5122 static const DWORD t_ex_style
[] = {
5123 0, WS_EX_APPWINDOW
, WS_EX_TOOLWINDOW
5133 if (!pGetMonitorInfoA
|| !pMonitorFromPoint
)
5135 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
5140 SetLastError(0xdeadbeef);
5141 hmon
= pMonitorFromPoint(pt
, MONITOR_DEFAULTTOPRIMARY
);
5142 ok(hmon
!= 0, "MonitorFromPoint error %u\n", GetLastError());
5144 mi
.cbSize
= sizeof(mi
);
5145 SetLastError(0xdeadbeef);
5146 ret
= pGetMonitorInfoA(hmon
, &mi
);
5147 ok(ret
, "GetMonitorInfo error %u\n", GetLastError());
5148 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
5149 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5150 mi
.rcWork
.left
, mi
.rcWork
.top
, mi
.rcWork
.right
, mi
.rcWork
.bottom
);
5153 cls
.lpfnWndProc
= fullscreen_wnd_proc
;
5156 cls
.hInstance
= GetModuleHandle(0);
5158 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
5159 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5160 cls
.lpszMenuName
= NULL
;
5161 cls
.lpszClassName
= "fullscreen_class";
5162 RegisterClass(&cls
);
5164 for (i
= 0; i
< sizeof(t_style
)/sizeof(t_style
[0]); i
++)
5166 DWORD style
, ex_style
;
5168 /* avoid a WM interaction */
5169 assert(!(t_style
[i
] & WS_VISIBLE
));
5171 for (j
= 0; j
< sizeof(t_ex_style
)/sizeof(t_ex_style
[0]); j
++)
5176 ex_style
= t_ex_style
[j
];
5178 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5179 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5180 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5181 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5182 GetWindowRect(hwnd
, &rc
);
5183 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5184 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5185 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5186 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5187 DestroyWindow(hwnd
);
5189 style
= t_style
[i
] | WS_MAXIMIZE
;
5190 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5191 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5192 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5193 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5194 GetWindowRect(hwnd
, &rc
);
5195 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5196 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5197 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5198 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5199 DestroyWindow(hwnd
);
5201 style
= t_style
[i
] | WS_MAXIMIZE
| WS_CAPTION
;
5202 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5203 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5204 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5205 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5206 GetWindowRect(hwnd
, &rc
);
5207 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5208 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5209 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5210 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5211 DestroyWindow(hwnd
);
5213 style
= t_style
[i
] | WS_CAPTION
| WS_MAXIMIZEBOX
;
5214 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5215 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5216 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5217 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5218 GetWindowRect(hwnd
, &rc
);
5219 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5220 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5221 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5222 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5223 DestroyWindow(hwnd
);
5225 style
= t_style
[i
] | WS_MAXIMIZE
| WS_CAPTION
| WS_MAXIMIZEBOX
;
5226 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5227 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5228 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5229 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5230 GetWindowRect(hwnd
, &rc
);
5231 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5232 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5233 fixup
= min(abs(rc
.left
), abs(rc
.top
));
5234 InflateRect(&rc
, -fixup
, -fixup
);
5235 ok(rc
.left
>= mi
.rcWork
.left
&& rc
.top
<= mi
.rcWork
.top
&&
5236 rc
.right
<= mi
.rcWork
.right
&& rc
.bottom
<= mi
.rcWork
.bottom
,
5237 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
5238 ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
5239 mi
.rcWork
.left
, mi
.rcWork
.top
, mi
.rcWork
.right
, mi
.rcWork
.bottom
);
5240 DestroyWindow(hwnd
);
5242 style
= t_style
[i
] | WS_MAXIMIZE
| WS_MAXIMIZEBOX
;
5243 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5244 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5245 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5246 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5247 GetWindowRect(hwnd
, &rc
);
5248 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5249 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5250 fixup
= min(abs(rc
.left
), abs(rc
.top
));
5251 InflateRect(&rc
, -fixup
, -fixup
);
5252 if (style
& (WS_CHILD
| WS_POPUP
))
5253 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5254 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5255 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5257 ok(rc
.left
>= mi
.rcWork
.left
&& rc
.top
<= mi
.rcWork
.top
&&
5258 rc
.right
<= mi
.rcWork
.right
&& rc
.bottom
<= mi
.rcWork
.bottom
,
5259 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5260 DestroyWindow(hwnd
);
5264 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5267 static BOOL test_thick_child_got_minmax
;
5268 static const char * test_thick_child_name
;
5269 static LONG test_thick_child_style
;
5270 static LONG test_thick_child_exStyle
;
5272 static LRESULT WINAPI
test_thick_child_size_winproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
5275 int expectedMinTrackX
;
5276 int expectedMinTrackY
;
5277 int actualMinTrackX
;
5278 int actualMinTrackY
;
5279 int expectedMaxTrackX
;
5280 int expectedMaxTrackY
;
5281 int actualMaxTrackX
;
5282 int actualMaxTrackY
;
5283 int expectedMaxSizeX
;
5284 int expectedMaxSizeY
;
5295 case WM_GETMINMAXINFO
:
5297 minmax
= (MINMAXINFO
*)lparam
;
5298 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
5299 dump_minmax_info( minmax
);
5301 test_thick_child_got_minmax
= TRUE
;
5304 adjustedStyle
= test_thick_child_style
;
5305 if ((adjustedStyle
& WS_CAPTION
) == WS_CAPTION
)
5306 adjustedStyle
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5307 GetClientRect(GetParent(hwnd
), &rect
);
5308 AdjustWindowRectEx(&rect
, adjustedStyle
, FALSE
, test_thick_child_exStyle
);
5310 if (test_thick_child_style
& (WS_DLGFRAME
| WS_BORDER
))
5312 expectedMinTrackX
= GetSystemMetrics(SM_CXMINTRACK
);
5313 expectedMinTrackY
= GetSystemMetrics(SM_CYMINTRACK
);
5317 expectedMinTrackX
= -2 * rect
.left
;
5318 expectedMinTrackY
= -2 * rect
.top
;
5320 actualMinTrackX
= minmax
->ptMinTrackSize
.x
;
5321 actualMinTrackY
= minmax
->ptMinTrackSize
.y
;
5323 ok(actualMinTrackX
== expectedMinTrackX
&& actualMinTrackY
== expectedMinTrackY
,
5324 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
5325 expectedMinTrackX
, expectedMinTrackY
, actualMinTrackX
, actualMinTrackY
,
5326 test_thick_child_name
);
5328 actualMaxTrackX
= minmax
->ptMaxTrackSize
.x
;
5329 actualMaxTrackY
= minmax
->ptMaxTrackSize
.y
;
5330 expectedMaxTrackX
= GetSystemMetrics(SM_CXMAXTRACK
);
5331 expectedMaxTrackY
= GetSystemMetrics(SM_CYMAXTRACK
);
5332 ok(actualMaxTrackX
== expectedMaxTrackX
&& actualMaxTrackY
== expectedMaxTrackY
,
5333 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
5334 expectedMaxTrackX
, expectedMaxTrackY
, actualMaxTrackX
, actualMaxTrackY
,
5335 test_thick_child_name
);
5337 expectedMaxSizeX
= rect
.right
- rect
.left
;
5338 expectedMaxSizeY
= rect
.bottom
- rect
.top
;
5339 actualMaxSizeX
= minmax
->ptMaxSize
.x
;
5340 actualMaxSizeY
= minmax
->ptMaxSize
.y
;
5342 ok(actualMaxSizeX
== expectedMaxSizeX
&& actualMaxSizeY
== expectedMaxSizeY
,
5343 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
5344 expectedMaxSizeX
, expectedMaxSizeY
, actualMaxSizeX
, actualMaxSizeY
,
5345 test_thick_child_name
);
5348 expectedPosX
= rect
.left
;
5349 expectedPosY
= rect
.top
;
5350 actualPosX
= minmax
->ptMaxPosition
.x
;
5351 actualPosY
= minmax
->ptMaxPosition
.y
;
5352 ok(actualPosX
== expectedPosX
&& actualPosY
== expectedPosY
,
5353 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
5354 expectedPosX
, expectedPosY
, actualPosX
, actualPosY
, test_thick_child_name
);
5360 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
5363 #define NUMBER_OF_THICK_CHILD_TESTS 16
5364 static void test_thick_child_size(HWND parentWindow
)
5368 RECT adjustedParentRect
;
5373 LONG expectedHeight
;
5375 LPCTSTR className
= "THICK_CHILD_CLASS";
5378 static const LONG styles
[NUMBER_OF_THICK_CHILD_TESTS
] = {
5379 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
5380 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
5381 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
5382 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
5383 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
5384 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
5385 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
5386 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
5387 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
5388 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
5389 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
5390 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
5391 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
,
5392 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
,
5393 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
,
5394 WS_CHILD
| WS_VISIBLE
| WS_THICKFRAME
| WS_BORDER
,
5397 static const LONG exStyles
[NUMBER_OF_THICK_CHILD_TESTS
] = {
5402 WS_EX_DLGMODALFRAME
,
5403 WS_EX_DLGMODALFRAME
,
5404 WS_EX_DLGMODALFRAME
,
5405 WS_EX_DLGMODALFRAME
,
5410 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
5411 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
5412 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
5413 WS_EX_STATICEDGE
| WS_EX_DLGMODALFRAME
,
5415 static const char *styleName
[NUMBER_OF_THICK_CHILD_TESTS
] = {
5416 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
5417 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
5418 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
5419 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
5420 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
5421 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
5422 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5423 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5424 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
5425 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
5426 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5427 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5428 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5429 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5430 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5431 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5435 cls
.lpfnWndProc
= test_thick_child_size_winproc
;
5438 cls
.hInstance
= GetModuleHandleA(0);
5440 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
5441 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5442 cls
.lpszMenuName
= NULL
;
5443 cls
.lpszClassName
= className
;
5444 SetLastError(0xdeadbeef);
5445 ok(RegisterClassA(&cls
),"RegisterClassA failed, error: %u\n", GetLastError());
5447 for(i
= 0; i
< NUMBER_OF_THICK_CHILD_TESTS
; i
++)
5449 test_thick_child_name
= styleName
[i
];
5450 test_thick_child_style
= styles
[i
];
5451 test_thick_child_exStyle
= exStyles
[i
];
5452 test_thick_child_got_minmax
= FALSE
;
5454 SetLastError(0xdeadbeef);
5455 childWindow
= CreateWindowEx( exStyles
[i
], className
, "", styles
[i
], 0, 0, 0, 0, parentWindow
, 0, GetModuleHandleA(0), NULL
);
5456 ok(childWindow
!= NULL
, "Failed to create child window, error: %u\n", GetLastError());
5458 ok(test_thick_child_got_minmax
, "Got no WM_GETMINMAXINFO\n");
5460 SetLastError(0xdeadbeef);
5461 success
= GetWindowRect(childWindow
, &childRect
);
5462 ok(success
,"GetWindowRect call failed, error: %u\n", GetLastError());
5463 childWidth
= childRect
.right
- childRect
.left
;
5464 childHeight
= childRect
.bottom
- childRect
.top
;
5466 adjustedStyle
= styles
[i
];
5467 if ((adjustedStyle
& WS_CAPTION
) == WS_CAPTION
)
5468 adjustedStyle
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5469 GetClientRect(GetParent(childWindow
), &adjustedParentRect
);
5470 AdjustWindowRectEx(&adjustedParentRect
, adjustedStyle
, FALSE
, test_thick_child_exStyle
);
5473 if (test_thick_child_style
& (WS_DLGFRAME
| WS_BORDER
))
5475 expectedWidth
= GetSystemMetrics(SM_CXMINTRACK
);
5476 expectedHeight
= GetSystemMetrics(SM_CYMINTRACK
);
5480 expectedWidth
= -2 * adjustedParentRect
.left
;
5481 expectedHeight
= -2 * adjustedParentRect
.top
;
5484 ok((childWidth
== expectedWidth
) && (childHeight
== expectedHeight
),
5485 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
5486 test_thick_child_name
, expectedWidth
, expectedHeight
, childWidth
, childHeight
);
5488 SetLastError(0xdeadbeef);
5489 success
= DestroyWindow(childWindow
);
5490 ok(success
,"DestroyWindow call failed, error: %u\n", GetLastError());
5492 ok(UnregisterClass(className
, GetModuleHandleA(0)),"UnregisterClass call failed\n");
5495 static void test_handles( HWND full_hwnd
)
5497 HWND hwnd
= full_hwnd
;
5501 SetLastError( 0xdeadbeef );
5502 ret
= GetWindowRect( hwnd
, &rect
);
5503 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
5506 if ((ULONG_PTR
)full_hwnd
>> 32)
5507 hwnd
= (HWND
)((ULONG_PTR
)full_hwnd
& ~0u);
5509 hwnd
= (HWND
)((ULONG_PTR
)full_hwnd
| ((ULONG_PTR
)~0u << 32));
5510 SetLastError( 0xdeadbeef );
5511 ret
= GetWindowRect( hwnd
, &rect
);
5512 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
5514 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& ~0u) | ((ULONG_PTR
)0x1234 << 32));
5515 SetLastError( 0xdeadbeef );
5516 ret
= GetWindowRect( hwnd
, &rect
);
5517 ok( ret
, "GetWindowRect failed for %p err %u\n", hwnd
, GetLastError() );
5519 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& 0xffff) | ((ULONG_PTR
)0x9876 << 16));
5520 SetLastError( 0xdeadbeef );
5521 ret
= GetWindowRect( hwnd
, &rect
);
5522 ok( !ret
, "GetWindowRect succeeded for %p\n", hwnd
);
5523 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "wrong error %u\n", GetLastError() );
5525 hwnd
= (HWND
)(((ULONG_PTR
)full_hwnd
& 0xffff) | ((ULONG_PTR
)0x12345678 << 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() );
5533 static void test_winregion(void)
5540 if (!pGetWindowRgnBox
)
5542 win_skip("GetWindowRgnBox not supported\n");
5546 hwnd
= CreateWindowExA(0, "static", NULL
, WS_VISIBLE
, 10, 10, 10, 10, NULL
, 0, 0, NULL
);
5548 SetLastError(0xdeadbeef);
5549 ret
= pGetWindowRgnBox(hwnd
, NULL
);
5550 ok( ret
== ERROR
, "Expected ERROR, got %d\n", ret
);
5551 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
5553 hrgn
= CreateRectRgn(2, 3, 10, 15);
5554 ok( hrgn
!= NULL
, "Region creation failed\n");
5557 SetWindowRgn(hwnd
, hrgn
, FALSE
);
5559 SetLastError(0xdeadbeef);
5560 ret
= pGetWindowRgnBox(hwnd
, NULL
);
5561 ok( ret
== ERROR
, "Expected ERROR, got %d\n", ret
);
5562 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
5564 r
.left
= r
.top
= r
.right
= r
.bottom
= 0;
5565 ret
= pGetWindowRgnBox(hwnd
, &r
);
5566 ok( ret
== SIMPLEREGION
, "Expected SIMPLEREGION, got %d\n", ret
);
5567 ok( r
.left
== 2 && r
.top
== 3 && r
.right
== 10 && r
.bottom
== 15,
5568 "Expected (2,3,10,15), got (%d,%d,%d,%d)\n", r
.left
, r
.top
,
5572 DestroyWindow(hwnd
);
5577 HMODULE user32
= GetModuleHandleA( "user32.dll" );
5578 pGetAncestor
= (void *)GetProcAddress( user32
, "GetAncestor" );
5579 pGetWindowInfo
= (void *)GetProcAddress( user32
, "GetWindowInfo" );
5580 pGetWindowModuleFileNameA
= (void *)GetProcAddress( user32
, "GetWindowModuleFileNameA" );
5581 pGetLayeredWindowAttributes
= (void *)GetProcAddress( user32
, "GetLayeredWindowAttributes" );
5582 pSetLayeredWindowAttributes
= (void *)GetProcAddress( user32
, "SetLayeredWindowAttributes" );
5583 pGetMonitorInfoA
= (void *)GetProcAddress( user32
, "GetMonitorInfoA" );
5584 pMonitorFromPoint
= (void *)GetProcAddress( user32
, "MonitorFromPoint" );
5585 pGetWindowRgnBox
= (void *)GetProcAddress( user32
, "GetWindowRgnBox" );
5587 if (!RegisterWindowClasses()) assert(0);
5589 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
5590 if (!hhook
) win_skip( "Cannot set CBT hook, skipping some tests\n" );
5592 hwndMain
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
5593 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
5594 WS_MAXIMIZEBOX
| WS_POPUP
,
5596 0, 0, GetModuleHandle(0), NULL
);
5597 hwndMain2
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
5598 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
5599 WS_MAXIMIZEBOX
| WS_POPUP
,
5601 0, 0, GetModuleHandle(0), NULL
);
5603 assert( hwndMain2
);
5605 our_pid
= GetWindowThreadProcessId(hwndMain
, NULL
);
5607 /* Add the tests below this line */
5608 test_thick_child_size(hwndMain
);
5610 test_hwnd_message();
5611 test_nonclient_area(hwndMain
);
5613 test_GetWindowModuleFileName();
5616 test_capture_3(hwndMain
, hwndMain2
);
5618 test_CreateWindow();
5619 test_parent_owner();
5624 test_SetWindowPos(hwndMain
);
5625 test_SetMenu(hwndMain
);
5626 test_SetFocus(hwndMain
);
5627 test_SetActiveWindow(hwndMain
);
5629 test_children_zorder(hwndMain
);
5630 test_popup_zorder(hwndMain2
, hwndMain
);
5631 test_keyboard_input(hwndMain
);
5632 test_mouse_input(hwndMain
);
5633 test_validatergn(hwndMain
);
5634 test_nccalcscroll( hwndMain
);
5635 test_scrollvalidate( hwndMain
);
5636 test_scrolldc( hwndMain
);
5638 test_IsWindowUnicode();
5639 test_vis_rgn(hwndMain
);
5641 test_AdjustWindowRect();
5642 test_window_styles();
5645 test_SetWindowLong();
5647 if (0) test_gettext(); /* crashes on NT4 */
5648 test_GetUpdateRect();
5650 test_layered_window();
5652 test_SetForegroundWindow(hwndMain
);
5653 test_shell_window();
5654 test_handles( hwndMain
);
5657 /* add the tests above this line */
5658 if (hhook
) UnhookWindowsHookEx(hhook
);
5660 DestroyWindow(hwndMain2
);
5661 DestroyWindow(hwndMain
);