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
);
55 static BOOL test_lbuttondown_flag
;
56 static HWND hwndMessage
;
57 static HWND hwndMain
, hwndMain2
;
60 static const char* szAWRClass
= "Winsize";
64 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
66 static void dump_minmax_info( const MINMAXINFO
*minmax
)
68 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
69 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
70 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
71 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
72 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
73 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
76 /* try to make sure pending X events have been processed before continuing */
77 static void flush_events( BOOL remove_messages
)
82 DWORD time
= GetTickCount() + diff
;
86 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
88 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
89 diff
= time
- GetTickCount();
94 /* check the values returned by the various parent/owner functions on a given window */
95 static void check_parents( HWND hwnd
, HWND ga_parent
, HWND gwl_parent
, HWND get_parent
,
96 HWND gw_owner
, HWND ga_root
, HWND ga_root_owner
)
102 res
= pGetAncestor( hwnd
, GA_PARENT
);
103 ok( res
== ga_parent
, "Wrong result for GA_PARENT %p expected %p\n", res
, ga_parent
);
105 res
= (HWND
)GetWindowLongPtrA( hwnd
, GWLP_HWNDPARENT
);
106 ok( res
== gwl_parent
, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res
, gwl_parent
);
107 res
= GetParent( hwnd
);
108 ok( res
== get_parent
, "Wrong result for GetParent %p expected %p\n", res
, get_parent
);
109 res
= GetWindow( hwnd
, GW_OWNER
);
110 ok( res
== gw_owner
, "Wrong result for GW_OWNER %p expected %p\n", res
, gw_owner
);
113 res
= pGetAncestor( hwnd
, GA_ROOT
);
114 ok( res
== ga_root
, "Wrong result for GA_ROOT %p expected %p\n", res
, ga_root
);
115 res
= pGetAncestor( hwnd
, GA_ROOTOWNER
);
116 ok( res
== ga_root_owner
, "Wrong result for GA_ROOTOWNER %p expected %p\n", res
, ga_root_owner
);
120 static BOOL CALLBACK
EnumChildProc( HWND hwndChild
, LPARAM lParam
)
123 trace("EnumChildProc on %p\n", hwndChild
);
124 if (*(LPINT
)lParam
> 1) return FALSE
;
128 /* will search for the given window */
129 static BOOL CALLBACK
EnumChildProc1( HWND hwndChild
, LPARAM lParam
)
131 trace("EnumChildProc1 on %p\n", hwndChild
);
132 if ((HWND
)lParam
== hwndChild
) return FALSE
;
136 static HWND
create_tool_window( LONG style
, HWND parent
)
138 HWND ret
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style
,
139 0, 0, 100, 100, parent
, 0, 0, NULL
);
140 ok( ret
!= 0, "Creation failed\n" );
144 /* test parent and owner values for various combinations */
145 static void test_parent_owner(void)
148 HWND test
, owner
, ret
;
149 HWND desktop
= GetDesktopWindow();
150 HWND child
= create_tool_window( WS_CHILD
, hwndMain
);
153 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain
, hwndMain2
, desktop
, child
);
155 /* child without parent, should fail */
156 SetLastError(0xdeadbeef);
157 test
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
158 WS_CHILD
, 0, 0, 100, 100, 0, 0, 0, NULL
);
159 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD
, "CreateWindowExA should call SetLastError\n" );
160 ok( !test
, "WS_CHILD without parent created\n" );
163 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
164 style
= GetWindowLongA( desktop
, GWL_STYLE
);
165 ok( !SetWindowLongA( desktop
, GWL_STYLE
, WS_POPUP
), "Set GWL_STYLE on desktop succeeded\n" );
166 ok( !SetWindowLongA( desktop
, GWL_STYLE
, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
167 ok( GetWindowLongA( desktop
, GWL_STYLE
) == style
, "Desktop style changed\n" );
169 /* normal child window */
170 test
= create_tool_window( WS_CHILD
, hwndMain
);
171 trace( "created child %p\n", test
);
172 check_parents( test
, hwndMain
, hwndMain
, hwndMain
, 0, hwndMain
, hwndMain
);
173 SetWindowLongA( test
, GWL_STYLE
, 0 );
174 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
175 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
176 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
177 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
|WS_CHILD
);
178 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
179 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
180 DestroyWindow( test
);
182 /* normal child window with WS_MAXIMIZE */
183 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
184 DestroyWindow( test
);
186 /* normal child window with WS_THICKFRAME */
187 test
= create_tool_window( WS_CHILD
| WS_THICKFRAME
, hwndMain
);
188 DestroyWindow( test
);
190 /* popup window with WS_THICKFRAME */
191 test
= create_tool_window( WS_POPUP
| WS_THICKFRAME
, hwndMain
);
192 DestroyWindow( test
);
194 /* child of desktop */
195 test
= create_tool_window( WS_CHILD
, desktop
);
196 trace( "created child of desktop %p\n", test
);
197 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
198 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
199 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
200 SetWindowLongA( test
, GWL_STYLE
, 0 );
201 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
202 DestroyWindow( test
);
204 /* child of desktop with WS_MAXIMIZE */
205 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, desktop
);
206 DestroyWindow( test
);
208 /* child of desktop with WS_MINIMIZE */
209 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, desktop
);
210 DestroyWindow( test
);
213 test
= create_tool_window( WS_CHILD
, child
);
214 trace( "created child of child %p\n", test
);
215 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
216 SetWindowLongA( test
, GWL_STYLE
, 0 );
217 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
218 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
219 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
220 DestroyWindow( test
);
222 /* child of child with WS_MAXIMIZE */
223 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, child
);
224 DestroyWindow( test
);
226 /* child of child with WS_MINIMIZE */
227 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, child
);
228 DestroyWindow( test
);
230 /* not owned top-level window */
231 test
= create_tool_window( 0, 0 );
232 trace( "created top-level %p\n", test
);
233 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
234 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
235 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
236 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
237 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
238 DestroyWindow( test
);
240 /* not owned top-level window with WS_MAXIMIZE */
241 test
= create_tool_window( WS_MAXIMIZE
, 0 );
242 DestroyWindow( test
);
244 /* owned top-level window */
245 test
= create_tool_window( 0, hwndMain
);
246 trace( "created owned top-level %p\n", test
);
247 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
248 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
249 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
250 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
251 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
252 DestroyWindow( test
);
254 /* owned top-level window with WS_MAXIMIZE */
255 test
= create_tool_window( WS_MAXIMIZE
, hwndMain
);
256 DestroyWindow( test
);
258 /* not owned popup */
259 test
= create_tool_window( WS_POPUP
, 0 );
260 trace( "created popup %p\n", test
);
261 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
262 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
263 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
264 SetWindowLongA( test
, GWL_STYLE
, 0 );
265 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
266 DestroyWindow( test
);
268 /* not owned popup with WS_MAXIMIZE */
269 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, 0 );
270 DestroyWindow( test
);
273 test
= create_tool_window( WS_POPUP
, hwndMain
);
274 trace( "created owned popup %p\n", test
);
275 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
276 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
277 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
278 SetWindowLongA( test
, GWL_STYLE
, 0 );
279 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
280 DestroyWindow( test
);
282 /* owned popup with WS_MAXIMIZE */
283 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, hwndMain
);
284 DestroyWindow( test
);
286 /* top-level window owned by child (same as owned by top-level) */
287 test
= create_tool_window( 0, child
);
288 trace( "created top-level owned by child %p\n", test
);
289 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
290 DestroyWindow( test
);
292 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
293 test
= create_tool_window( WS_MAXIMIZE
, child
);
294 DestroyWindow( test
);
296 /* popup owned by desktop (same as not owned) */
297 test
= create_tool_window( WS_POPUP
, desktop
);
298 trace( "created popup owned by desktop %p\n", test
);
299 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
300 DestroyWindow( test
);
302 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
303 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, desktop
);
304 DestroyWindow( test
);
306 /* popup owned by child (same as owned by top-level) */
307 test
= create_tool_window( WS_POPUP
, child
);
308 trace( "created popup owned by child %p\n", test
);
309 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
310 DestroyWindow( test
);
312 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
313 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, child
);
314 DestroyWindow( test
);
316 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
317 test
= create_tool_window( WS_POPUP
| WS_CHILD
, 0 );
318 trace( "created WS_CHILD popup %p\n", test
);
319 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
320 DestroyWindow( test
);
322 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
323 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, 0 );
324 DestroyWindow( test
);
326 /* owned popup with WS_CHILD (same as WS_POPUP only) */
327 test
= create_tool_window( WS_POPUP
| WS_CHILD
, hwndMain
);
328 trace( "created owned WS_CHILD popup %p\n", test
);
329 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
330 DestroyWindow( test
);
332 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
333 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
334 DestroyWindow( test
);
336 /******************** parent changes *************************/
337 trace( "testing parent changes\n" );
340 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
343 /* this test succeeds on NT but crashes on win9x systems */
344 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
345 ok( !ret
, "Set GWL_HWNDPARENT succeeded on desktop\n" );
346 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
347 ok( !SetParent( desktop
, hwndMain
), "SetParent succeeded on desktop\n" );
348 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
350 /* normal child window */
351 test
= create_tool_window( WS_CHILD
, hwndMain
);
352 trace( "created child %p\n", test
);
354 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
355 ok( ret
== hwndMain
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain
);
356 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
358 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
359 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
360 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
362 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)desktop
);
363 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
364 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
366 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
367 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
368 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
369 check_parents( test
, desktop
, child
, desktop
, child
, test
, desktop
);
371 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
372 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
373 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
374 DestroyWindow( test
);
376 /* not owned top-level window */
377 test
= create_tool_window( 0, 0 );
378 trace( "created top-level %p\n", test
);
380 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
381 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
382 check_parents( test
, desktop
, hwndMain2
, 0, hwndMain2
, test
, test
);
384 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
385 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
386 check_parents( test
, desktop
, child
, 0, child
, test
, test
);
388 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
389 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
390 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
391 DestroyWindow( test
);
393 /* not owned popup */
394 test
= create_tool_window( WS_POPUP
, 0 );
395 trace( "created popup %p\n", test
);
397 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
398 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
399 check_parents( test
, desktop
, hwndMain2
, hwndMain2
, hwndMain2
, test
, hwndMain2
);
401 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
402 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
403 check_parents( test
, desktop
, child
, child
, child
, test
, hwndMain
);
405 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
406 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
407 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
408 DestroyWindow( test
);
410 /* normal child window */
411 test
= create_tool_window( WS_CHILD
, hwndMain
);
412 trace( "created child %p\n", test
);
414 ret
= SetParent( test
, desktop
);
415 ok( ret
== hwndMain
, "SetParent return value %p expected %p\n", ret
, hwndMain
);
416 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
418 ret
= SetParent( test
, child
);
419 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
420 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
422 ret
= SetParent( test
, hwndMain2
);
423 ok( ret
== child
, "SetParent return value %p expected %p\n", ret
, child
);
424 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
425 DestroyWindow( test
);
427 /* not owned top-level window */
428 test
= create_tool_window( 0, 0 );
429 trace( "created top-level %p\n", test
);
431 ret
= SetParent( test
, child
);
432 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
433 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
434 DestroyWindow( test
);
437 test
= create_tool_window( WS_POPUP
, hwndMain2
);
438 trace( "created owned popup %p\n", test
);
440 ret
= SetParent( test
, child
);
441 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
442 check_parents( test
, child
, child
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
444 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)hwndMain
);
445 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
446 check_parents( test
, hwndMain
, hwndMain
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
447 DestroyWindow( test
);
449 /**************** test owner destruction *******************/
451 /* owned child popup */
452 owner
= create_tool_window( 0, 0 );
453 test
= create_tool_window( WS_POPUP
, owner
);
454 trace( "created owner %p and popup %p\n", owner
, test
);
455 ret
= SetParent( test
, child
);
456 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
457 check_parents( test
, child
, child
, owner
, owner
, hwndMain
, owner
);
458 /* window is now child of 'child' but owned by 'owner' */
459 DestroyWindow( owner
);
460 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
461 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
462 * while Win95, Win2k, WinXP do.
464 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
465 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
468 /* owned top-level popup */
469 owner
= create_tool_window( 0, 0 );
470 test
= create_tool_window( WS_POPUP
, owner
);
471 trace( "created owner %p and popup %p\n", owner
, test
);
472 check_parents( test
, desktop
, owner
, owner
, owner
, test
, owner
);
473 DestroyWindow( owner
);
474 ok( !IsWindow(test
), "Window %p not destroyed by owner destruction\n", test
);
476 /* top-level popup owned by child */
477 owner
= create_tool_window( WS_CHILD
, hwndMain2
);
478 test
= create_tool_window( WS_POPUP
, 0 );
479 trace( "created owner %p and popup %p\n", owner
, test
);
480 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)owner
);
481 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
482 check_parents( test
, desktop
, owner
, owner
, owner
, test
, hwndMain2
);
483 DestroyWindow( owner
);
484 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
485 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
486 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
487 * while Win95, Win2k, WinXP do.
489 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
493 DestroyWindow(child
);
496 owner
= create_tool_window( WS_OVERLAPPED
, 0 );
497 test
= create_tool_window( WS_POPUP
, desktop
);
499 ok( !GetWindow( test
, GW_OWNER
), "Wrong owner window\n" );
501 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
502 "EnumChildWindows should have returned FALSE\n" );
503 ok( numChildren
== 0, "numChildren should be 0 got %d\n", numChildren
);
505 SetWindowLongA( test
, GWL_STYLE
, (GetWindowLongA( test
, GWL_STYLE
) & ~WS_POPUP
) | WS_CHILD
);
506 ret
= SetParent( test
, owner
);
507 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
510 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
511 "EnumChildWindows should have returned TRUE\n" );
512 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
514 child
= create_tool_window( WS_CHILD
, owner
);
516 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
517 "EnumChildWindows should have returned FALSE\n" );
518 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
519 DestroyWindow( child
);
521 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, owner
);
522 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
524 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
525 "EnumChildWindows should have returned TRUE\n" );
526 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
528 ret
= SetParent( child
, owner
);
529 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
530 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
532 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
533 "EnumChildWindows should have returned FALSE\n" );
534 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
536 ret
= SetParent( child
, NULL
);
537 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
538 ok( ret
== owner
, "SetParent return value %p expected %p\n", ret
, owner
);
540 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
541 "EnumChildWindows should have returned TRUE\n" );
542 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
544 /* even GW_OWNER == owner it's still a desktop's child */
545 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
546 "EnumChildWindows should have found %p and returned FALSE\n", child
);
548 DestroyWindow( child
);
549 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, NULL
);
551 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
552 "EnumChildWindows should have found %p and returned FALSE\n", child
);
554 DestroyWindow( child
);
555 DestroyWindow( test
);
556 DestroyWindow( owner
);
560 static LRESULT WINAPI
main_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
564 case WM_GETMINMAXINFO
:
566 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
568 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
569 dump_minmax_info( minmax
);
570 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
573 case WM_WINDOWPOSCHANGING
:
575 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
576 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
577 trace("main: WM_WINDOWPOSCHANGING\n");
578 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
579 winpos
->hwnd
, winpos
->hwndInsertAfter
,
580 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
581 if (!(winpos
->flags
& SWP_NOMOVE
))
583 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
584 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
586 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
587 if (!(winpos
->flags
& SWP_NOSIZE
) && !is_win9x
)
589 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
590 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
594 case WM_WINDOWPOSCHANGED
:
597 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
598 trace("main: WM_WINDOWPOSCHANGED\n");
599 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
600 winpos
->hwnd
, winpos
->hwndInsertAfter
,
601 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
602 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
603 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
605 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
606 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
608 GetWindowRect(hwnd
, &rc1
);
609 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
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);
613 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
616 /* Uncomment this once the test succeeds in all cases */
617 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
620 GetClientRect(hwnd
, &rc2
);
621 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
622 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
623 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
624 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, (LPSTR
)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, (LPSTR
)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(HWND hwnd
, const WINDOWINFO
*info
)
722 RECT rcWindow
, rcClient
;
725 ok(IsWindow(hwnd
), "bad window handle\n");
727 GetWindowRect(hwnd
, &rcWindow
);
728 ok(EqualRect(&rcWindow
, &info
->rcWindow
), "wrong rcWindow\n");
730 GetClientRect(hwnd
, &rcClient
);
731 /* translate to screen coordinates */
732 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rcClient
, 2);
733 ok(EqualRect(&rcClient
, &info
->rcClient
), "wrong rcClient\n");
735 ok(info
->dwStyle
== (DWORD
)GetWindowLongA(hwnd
, GWL_STYLE
),
736 "wrong dwStyle: %08x != %08x\n", info
->dwStyle
, GetWindowLongA(hwnd
, GWL_STYLE
));
737 /* Windows reports some undocumented exstyles in WINDOWINFO, but
738 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
740 ok((info
->dwExStyle
& ~0xe0000800) == (DWORD
)GetWindowLongA(hwnd
, GWL_EXSTYLE
),
741 "wrong dwExStyle: %08x != %08x\n", info
->dwExStyle
, GetWindowLongA(hwnd
, GWL_EXSTYLE
));
742 status
= (GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0;
743 ok(info
->dwWindowStatus
== status
, "wrong dwWindowStatus: %04x != %04x\n",
744 info
->dwWindowStatus
, status
);
746 /* win2k and XP return broken border info in GetWindowInfo most of
747 * the time, so there is no point in testing it.
751 ok(info
->cxWindowBorders
== (unsigned)(rcClient
.left
- rcWindow
.left
),
752 "wrong cxWindowBorders %d != %d\n", info
->cxWindowBorders
, rcClient
.left
- rcWindow
.left
);
753 border
= min(rcWindow
.bottom
- rcClient
.bottom
, rcClient
.top
- rcWindow
.top
);
754 ok(info
->cyWindowBorders
== border
,
755 "wrong cyWindowBorders %d != %d\n", info
->cyWindowBorders
, border
);
757 ok(info
->atomWindowType
== GetClassLongA(hwnd
, GCW_ATOM
), "wrong atomWindowType\n");
758 ok(info
->wCreatorVersion
== 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
759 info
->wCreatorVersion
== 0x0500 /* Vista */,
760 "wrong wCreatorVersion %04x\n", info
->wCreatorVersion
);
763 static void FixedAdjustWindowRectEx(RECT
* rc
, LONG style
, BOOL menu
, LONG exstyle
)
765 AdjustWindowRectEx(rc
, style
, menu
, exstyle
);
766 /* AdjustWindowRectEx does not include scroll bars */
767 if (style
& WS_VSCROLL
)
769 if(exstyle
& WS_EX_LEFTSCROLLBAR
)
770 rc
->left
-= GetSystemMetrics(SM_CXVSCROLL
);
772 rc
->right
+= GetSystemMetrics(SM_CXVSCROLL
);
774 if (style
& WS_HSCROLL
)
775 rc
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
778 static void test_nonclient_area(HWND hwnd
)
780 DWORD style
, exstyle
;
781 RECT rc_window
, rc_client
, rc
;
783 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
785 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
786 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
787 menu
= !(style
& WS_CHILD
) && GetMenu(hwnd
) != 0;
789 GetWindowRect(hwnd
, &rc_window
);
790 trace("window: (%d,%d)-(%d,%d)\n", rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
);
791 GetClientRect(hwnd
, &rc_client
);
792 trace("client: (%d,%d)-(%d,%d)\n", rc_client
.left
, rc_client
.top
, rc_client
.right
, rc_client
.bottom
);
794 /* avoid some cases when things go wrong */
795 if (IsRectEmpty(&rc_window
) || IsRectEmpty(&rc_client
) ||
796 rc_window
.right
> 32768 || rc_window
.bottom
> 32768) return;
798 CopyRect(&rc
, &rc_client
);
799 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc
, 2);
800 FixedAdjustWindowRectEx(&rc
, style
, menu
, exstyle
);
802 trace("calc window: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
803 ok(EqualRect(&rc
, &rc_window
), "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
806 CopyRect(&rc
, &rc_window
);
807 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
808 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
809 trace("calc client: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
810 ok(EqualRect(&rc
, &rc_client
), "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
812 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
816 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
817 SetRect(&rc_client
, 0, 0, 250, 150);
818 CopyRect(&rc_window
, &rc_client
);
819 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc_window
, 2);
820 FixedAdjustWindowRectEx(&rc_window
, style
, menu
, exstyle
);
821 trace("calc window: (%d,%d)-(%d,%d)\n",
822 rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
);
824 CopyRect(&rc
, &rc_window
);
825 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
826 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
827 trace("calc client: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
828 ok(EqualRect(&rc
, &rc_client
), "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
831 static LRESULT CALLBACK
cbt_hook_proc(int nCode
, WPARAM wParam
, LPARAM lParam
)
833 static const char *CBT_code_name
[10] = {
844 const char *code_name
= (nCode
>= 0 && nCode
<= HCBT_SETFOCUS
) ? CBT_code_name
[nCode
] : "Unknown";
846 trace("CBT: %d (%s), %08lx, %08lx\n", nCode
, code_name
, wParam
, lParam
);
848 /* on HCBT_DESTROYWND window state is undefined */
849 if (nCode
!= HCBT_DESTROYWND
&& IsWindow((HWND
)wParam
))
855 /* Win98 actually does check the info.cbSize and doesn't allow
856 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
857 * WinXP do not check it at all.
859 info
.cbSize
= sizeof(WINDOWINFO
);
860 ok(pGetWindowInfo((HWND
)wParam
, &info
), "GetWindowInfo should not fail\n");
861 verify_window_info((HWND
)wParam
, &info
);
869 static const RECT rc_null
;
872 CBT_CREATEWNDA
*createwnd
= (CBT_CREATEWNDA
*)lParam
;
873 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
874 (HWND
)wParam
, createwnd
->lpcs
->hwndParent
, createwnd
->lpcs
->style
);
875 ok(createwnd
->hwndInsertAfter
== HWND_TOP
, "hwndInsertAfter should be always HWND_TOP\n");
877 /* WS_VISIBLE should be turned off yet */
878 style
= createwnd
->lpcs
->style
& ~WS_VISIBLE
;
879 ok(style
== GetWindowLongA((HWND
)wParam
, GWL_STYLE
),
880 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
881 GetWindowLongA((HWND
)wParam
, GWL_STYLE
), style
);
885 /* Uncomment this once the test succeeds in all cases */
886 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
888 ok(GetParent((HWND
)wParam
) == hwndMessage
,
889 "wrong result from GetParent %p: message window %p\n",
890 GetParent((HWND
)wParam
), hwndMessage
);
893 ok(!GetParent((HWND
)wParam
), "GetParent should return 0 at this point\n");
895 ok(!GetWindow((HWND
)wParam
, GW_OWNER
), "GW_OWNER should be set to 0 at this point\n");
899 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
900 * Win9x still has them set to 0.
902 ok(GetWindow((HWND
)wParam
, GW_HWNDFIRST
) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
903 ok(GetWindow((HWND
)wParam
, GW_HWNDLAST
) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
905 ok(!GetWindow((HWND
)wParam
, GW_HWNDPREV
), "GW_HWNDPREV should be set to 0 at this point\n");
906 ok(!GetWindow((HWND
)wParam
, GW_HWNDNEXT
), "GW_HWNDNEXT should be set to 0 at this point\n");
910 /* Uncomment this once the test succeeds in all cases */
913 ok(pGetAncestor((HWND
)wParam
, GA_PARENT
) == hwndMessage
, "GA_PARENT should be set to hwndMessage at this point\n");
914 ok(pGetAncestor((HWND
)wParam
, GA_ROOT
) == (HWND
)wParam
,
915 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND
)wParam
, GA_ROOT
), (HWND
)wParam
);
917 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
918 ok(pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
) == hwndMessage
,
919 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
921 ok(pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
) == (HWND
)wParam
,
922 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
), (HWND
)wParam
);
925 ok(GetWindowRect((HWND
)wParam
, &rc
), "GetWindowRect failed\n");
926 ok(EqualRect(&rc
, &rc_null
), "window rect should be set to 0 HCBT_CREATEWND\n");
927 ok(GetClientRect((HWND
)wParam
, &rc
), "GetClientRect failed\n");
928 ok(EqualRect(&rc
, &rc_null
), "client rect should be set to 0 on HCBT_CREATEWND\n");
934 return CallNextHookEx(hhook
, nCode
, wParam
, lParam
);
937 static void test_shell_window(void)
941 HMODULE hinst
, hUser32
;
942 BOOL (WINAPI
*SetShellWindow
)(HWND
);
943 BOOL (WINAPI
*SetShellWindowEx
)(HWND
, HWND
);
944 HWND hwnd1
, hwnd2
, hwnd3
, hwnd4
, hwnd5
;
945 HWND shellWindow
, nextWnd
;
947 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE
))
949 trace("Skipping shell window test on Win9x\n");
953 shellWindow
= GetShellWindow();
954 hinst
= GetModuleHandle(0);
955 hUser32
= GetModuleHandleA("user32");
957 SetShellWindow
= (void *)GetProcAddress(hUser32
, "SetShellWindow");
958 SetShellWindowEx
= (void *)GetProcAddress(hUser32
, "SetShellWindowEx");
960 trace("previous shell window: %p\n", shellWindow
);
966 SetLastError(0xdeadbeef);
967 ret
= DestroyWindow(shellWindow
);
968 error
= GetLastError();
970 ok(!ret
, "DestroyWindow(shellWindow)\n");
971 /* passes on Win XP, but not on Win98 */
972 ok(error
==ERROR_ACCESS_DENIED
|| error
== 0xdeadbeef,
973 "got %u after DestroyWindow(shellWindow)\n", error
);
975 /* close old shell instance */
976 GetWindowThreadProcessId(shellWindow
, &pid
);
977 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, pid
);
978 ret
= TerminateProcess(hProcess
, 0);
979 ok(ret
, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
980 WaitForSingleObject(hProcess
, INFINITE
); /* wait for termination */
981 CloseHandle(hProcess
);
984 hwnd1
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst
, 0);
985 trace("created window 1: %p\n", hwnd1
);
987 ret
= SetShellWindow(hwnd1
);
988 ok(ret
, "first call to SetShellWindow(hwnd1)\n");
989 shellWindow
= GetShellWindow();
990 ok(shellWindow
==hwnd1
, "wrong shell window: %p\n", shellWindow
);
992 ret
= SetShellWindow(hwnd1
);
993 ok(!ret
, "second call to SetShellWindow(hwnd1)\n");
995 ret
= SetShellWindow(0);
996 error
= GetLastError();
997 /* passes on Win XP, but not on Win98
998 ok(!ret, "reset shell window by SetShellWindow(0)\n");
999 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1001 ret
= SetShellWindow(hwnd1
);
1002 /* passes on Win XP, but not on Win98
1003 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1005 SetWindowLong(hwnd1
, GWL_EXSTYLE
, GetWindowLong(hwnd1
,GWL_EXSTYLE
)|WS_EX_TOPMOST
);
1006 ret
= GetWindowLong(hwnd1
,GWL_EXSTYLE
)&WS_EX_TOPMOST
? TRUE
: FALSE
;
1007 ok(!ret
, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1009 ret
= DestroyWindow(hwnd1
);
1010 ok(ret
, "DestroyWindow(hwnd1)\n");
1012 hwnd2
= CreateWindowEx(WS_EX_TOPMOST
, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst
, 0);
1013 trace("created window 2: %p\n", hwnd2
);
1014 ret
= SetShellWindow(hwnd2
);
1015 ok(!ret
, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1017 hwnd3
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst
, 0);
1018 trace("created window 3: %p\n", hwnd3
);
1020 hwnd4
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst
, 0);
1021 trace("created window 4: %p\n", hwnd4
);
1023 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1024 ok(nextWnd
==hwnd3
, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd
);
1026 ret
= SetShellWindow(hwnd4
);
1027 ok(ret
, "SetShellWindow(hwnd4)\n");
1028 shellWindow
= GetShellWindow();
1029 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1031 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1032 ok(nextWnd
==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd
);
1034 ret
= SetWindowPos(hwnd4
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1035 ok(ret
, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1037 ret
= SetWindowPos(hwnd4
, hwnd3
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1038 ok(ret
, "SetWindowPos(hwnd4, hwnd3\n");
1040 ret
= SetShellWindow(hwnd3
);
1041 ok(!ret
, "SetShellWindow(hwnd3)\n");
1042 shellWindow
= GetShellWindow();
1043 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1045 hwnd5
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst
, 0);
1046 trace("created window 5: %p\n", hwnd5
);
1047 ret
= SetWindowPos(hwnd4
, hwnd5
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1048 ok(ret
, "SetWindowPos(hwnd4, hwnd5)\n");
1052 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1053 ok(nextWnd
==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd
);
1056 /* destroy test windows */
1057 DestroyWindow(hwnd2
);
1058 DestroyWindow(hwnd3
);
1059 DestroyWindow(hwnd4
);
1060 DestroyWindow(hwnd5
);
1063 /************** MDI test ****************/
1065 static char mdi_lParam_test_message
[] = "just a test string";
1067 static void test_MDI_create(HWND parent
, HWND mdi_client
, INT first_id
)
1069 MDICREATESTRUCTA mdi_cs
;
1071 static const WCHAR classW
[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1072 static const WCHAR titleW
[] = {'M','D','I',' ','c','h','i','l','d',0};
1073 BOOL isWin9x
= FALSE
;
1075 mdi_cs
.szClass
= "MDI_child_Class_1";
1076 mdi_cs
.szTitle
= "MDI child";
1077 mdi_cs
.hOwner
= GetModuleHandle(0);
1078 mdi_cs
.x
= CW_USEDEFAULT
;
1079 mdi_cs
.y
= CW_USEDEFAULT
;
1080 mdi_cs
.cx
= CW_USEDEFAULT
;
1081 mdi_cs
.cy
= CW_USEDEFAULT
;
1083 mdi_cs
.lParam
= (LPARAM
)mdi_lParam_test_message
;
1084 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1085 ok(mdi_child
!= 0, "MDI child creation failed\n");
1086 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1087 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1088 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1090 mdi_cs
.style
= 0x7fffffff; /* without WS_POPUP */
1091 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1092 ok(mdi_child
!= 0, "MDI child creation failed\n");
1093 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1094 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1095 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1097 mdi_cs
.style
= 0xffffffff; /* with WS_POPUP */
1098 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1099 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1101 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1105 ok(mdi_child
!= 0, "MDI child creation failed\n");
1106 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1107 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1108 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1111 /* test MDICREATESTRUCT A<->W mapping */
1112 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1114 mdi_cs
.szClass
= (LPCSTR
)classW
;
1115 mdi_cs
.szTitle
= (LPCSTR
)titleW
;
1116 SetLastError(0xdeadbeef);
1117 mdi_child
= (HWND
)SendMessageW(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1120 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1123 ok(mdi_child
!= 0, "MDI child creation failed\n");
1127 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1128 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1129 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1132 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1134 CW_USEDEFAULT
, CW_USEDEFAULT
,
1135 CW_USEDEFAULT
, CW_USEDEFAULT
,
1136 mdi_client
, GetModuleHandle(0),
1137 (LPARAM
)mdi_lParam_test_message
);
1138 ok(mdi_child
!= 0, "MDI child creation failed\n");
1139 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1140 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1141 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1143 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1144 0x7fffffff, /* without WS_POPUP */
1145 CW_USEDEFAULT
, CW_USEDEFAULT
,
1146 CW_USEDEFAULT
, CW_USEDEFAULT
,
1147 mdi_client
, GetModuleHandle(0),
1148 (LPARAM
)mdi_lParam_test_message
);
1149 ok(mdi_child
!= 0, "MDI child creation failed\n");
1150 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1151 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1152 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1154 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1155 0xffffffff, /* with WS_POPUP */
1156 CW_USEDEFAULT
, CW_USEDEFAULT
,
1157 CW_USEDEFAULT
, CW_USEDEFAULT
,
1158 mdi_client
, GetModuleHandle(0),
1159 (LPARAM
)mdi_lParam_test_message
);
1160 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1162 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1166 ok(mdi_child
!= 0, "MDI child creation failed\n");
1167 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1168 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1169 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1172 /* test MDICREATESTRUCT A<->W mapping */
1173 SetLastError(0xdeadbeef);
1174 mdi_child
= CreateMDIWindowW(classW
, titleW
,
1176 CW_USEDEFAULT
, CW_USEDEFAULT
,
1177 CW_USEDEFAULT
, CW_USEDEFAULT
,
1178 mdi_client
, GetModuleHandle(0),
1179 (LPARAM
)mdi_lParam_test_message
);
1182 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1185 ok(mdi_child
!= 0, "MDI child creation failed\n");
1189 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1190 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1191 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1194 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1196 CW_USEDEFAULT
, CW_USEDEFAULT
,
1197 CW_USEDEFAULT
, CW_USEDEFAULT
,
1198 mdi_client
, 0, GetModuleHandle(0),
1199 (LPVOID
)mdi_lParam_test_message
);
1200 ok(mdi_child
!= 0, "MDI child creation failed\n");
1201 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1202 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1203 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1205 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1206 0x7fffffff, /* without WS_POPUP */
1207 CW_USEDEFAULT
, CW_USEDEFAULT
,
1208 CW_USEDEFAULT
, CW_USEDEFAULT
,
1209 mdi_client
, 0, GetModuleHandle(0),
1210 (LPVOID
)mdi_lParam_test_message
);
1211 ok(mdi_child
!= 0, "MDI child creation failed\n");
1212 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1213 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1214 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1216 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1217 0xffffffff, /* with WS_POPUP */
1218 CW_USEDEFAULT
, CW_USEDEFAULT
,
1219 CW_USEDEFAULT
, CW_USEDEFAULT
,
1220 mdi_client
, 0, GetModuleHandle(0),
1221 (LPVOID
)mdi_lParam_test_message
);
1222 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1224 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1228 ok(mdi_child
!= 0, "MDI child creation failed\n");
1229 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1230 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1231 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1234 /* test MDICREATESTRUCT A<->W mapping */
1235 SetLastError(0xdeadbeef);
1236 mdi_child
= CreateWindowExW(WS_EX_MDICHILD
, classW
, titleW
,
1238 CW_USEDEFAULT
, CW_USEDEFAULT
,
1239 CW_USEDEFAULT
, CW_USEDEFAULT
,
1240 mdi_client
, 0, GetModuleHandle(0),
1241 (LPVOID
)mdi_lParam_test_message
);
1244 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1247 ok(mdi_child
!= 0, "MDI child creation failed\n");
1251 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1252 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1253 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1256 /* This test fails on Win9x */
1259 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_2", "MDI child",
1261 CW_USEDEFAULT
, CW_USEDEFAULT
,
1262 CW_USEDEFAULT
, CW_USEDEFAULT
,
1263 parent
, 0, GetModuleHandle(0),
1264 (LPVOID
)mdi_lParam_test_message
);
1265 ok(!mdi_child
, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1268 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1269 WS_CHILD
, /* without WS_POPUP */
1270 CW_USEDEFAULT
, CW_USEDEFAULT
,
1271 CW_USEDEFAULT
, CW_USEDEFAULT
,
1272 mdi_client
, 0, GetModuleHandle(0),
1273 (LPVOID
)mdi_lParam_test_message
);
1274 ok(mdi_child
!= 0, "MDI child creation failed\n");
1275 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1276 DestroyWindow(mdi_child
);
1278 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1279 WS_CHILD
| WS_POPUP
, /* with WS_POPUP */
1280 CW_USEDEFAULT
, CW_USEDEFAULT
,
1281 CW_USEDEFAULT
, CW_USEDEFAULT
,
1282 mdi_client
, 0, GetModuleHandle(0),
1283 (LPVOID
)mdi_lParam_test_message
);
1284 ok(mdi_child
!= 0, "MDI child creation failed\n");
1285 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1286 DestroyWindow(mdi_child
);
1288 /* maximized child */
1289 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1290 WS_CHILD
| WS_MAXIMIZE
,
1291 CW_USEDEFAULT
, CW_USEDEFAULT
,
1292 CW_USEDEFAULT
, CW_USEDEFAULT
,
1293 mdi_client
, 0, GetModuleHandle(0),
1294 (LPVOID
)mdi_lParam_test_message
);
1295 ok(mdi_child
!= 0, "MDI child creation failed\n");
1296 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1297 DestroyWindow(mdi_child
);
1299 trace("Creating maximized child with a caption\n");
1300 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1301 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
,
1302 CW_USEDEFAULT
, CW_USEDEFAULT
,
1303 CW_USEDEFAULT
, CW_USEDEFAULT
,
1304 mdi_client
, 0, GetModuleHandle(0),
1305 (LPVOID
)mdi_lParam_test_message
);
1306 ok(mdi_child
!= 0, "MDI child creation failed\n");
1307 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1308 DestroyWindow(mdi_child
);
1310 trace("Creating maximized child with a caption and a thick frame\n");
1311 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1312 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
| WS_THICKFRAME
,
1313 CW_USEDEFAULT
, CW_USEDEFAULT
,
1314 CW_USEDEFAULT
, CW_USEDEFAULT
,
1315 mdi_client
, 0, GetModuleHandle(0),
1316 (LPVOID
)mdi_lParam_test_message
);
1317 ok(mdi_child
!= 0, "MDI child creation failed\n");
1318 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1319 DestroyWindow(mdi_child
);
1322 /**********************************************************************
1323 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1325 * Note: The rule here is that client rect of the maximized MDI child
1326 * is equal to the client rect of the MDI client window.
1328 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
1332 GetClientRect( client
, &rect
);
1333 AdjustWindowRectEx( &rect
, GetWindowLongA( hwnd
, GWL_STYLE
),
1334 0, GetWindowLongA( hwnd
, GWL_EXSTYLE
));
1336 rect
.right
-= rect
.left
;
1337 rect
.bottom
-= rect
.top
;
1338 lpMinMax
->ptMaxSize
.x
= rect
.right
;
1339 lpMinMax
->ptMaxSize
.y
= rect
.bottom
;
1341 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
1342 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
1344 trace("max rect (%d,%d - %d, %d)\n",
1345 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1348 static LRESULT WINAPI
mdi_child_wnd_proc_1(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1355 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1356 MDICREATESTRUCTA
*mdi_cs
= (MDICREATESTRUCTA
*)cs
->lpCreateParams
;
1358 ok(cs
->dwExStyle
& WS_EX_MDICHILD
, "WS_EX_MDICHILD should be set\n");
1359 ok(mdi_cs
->lParam
== (LPARAM
)mdi_lParam_test_message
, "wrong mdi_cs->lParam\n");
1361 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_1"), "wrong class name\n");
1362 ok(!lstrcmpA(cs
->lpszClass
, mdi_cs
->szClass
), "class name does not match\n");
1363 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1364 ok(!lstrcmpA(cs
->lpszName
, mdi_cs
->szTitle
), "title does not match\n");
1365 ok(cs
->hInstance
== mdi_cs
->hOwner
, "%p != %p\n", cs
->hInstance
, mdi_cs
->hOwner
);
1367 /* MDICREATESTRUCT should have original values */
1368 ok(mdi_cs
->style
== 0 || mdi_cs
->style
== 0x7fffffff || mdi_cs
->style
== 0xffffffff,
1369 "mdi_cs->style does not match (%08x)\n", mdi_cs
->style
);
1370 ok(mdi_cs
->x
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->x
);
1371 ok(mdi_cs
->y
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->y
);
1372 ok(mdi_cs
->cx
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cx
);
1373 ok(mdi_cs
->cy
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cy
);
1375 /* CREATESTRUCT should have fixed values */
1376 ok(cs
->x
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->x
);
1377 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1379 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1380 ok(cs
->cx
!= CW_USEDEFAULT
&& cs
->cx
!= 0, "%d == CW_USEDEFAULT\n", cs
->cx
);
1381 ok(cs
->cy
!= CW_USEDEFAULT
&& cs
->cy
!= 0, "%d == CW_USEDEFAULT\n", cs
->cy
);
1383 ok(!(cs
->style
& WS_POPUP
), "WS_POPUP is not allowed\n");
1385 if (GetWindowLongA(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1387 LONG style
= mdi_cs
->style
| WS_CHILD
| WS_CLIPSIBLINGS
;
1388 ok(cs
->style
== style
,
1389 "cs->style does not match (%08x)\n", cs
->style
);
1393 LONG style
= mdi_cs
->style
;
1395 style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1396 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1397 ok(cs
->style
== style
,
1398 "cs->style does not match (%08x)\n", cs
->style
);
1403 case WM_GETMINMAXINFO
:
1405 HWND client
= GetParent(hwnd
);
1407 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1408 MINMAXINFO my_minmax
;
1409 LONG style
, exstyle
;
1411 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1412 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1414 GetWindowRect(client
, &rc
);
1415 trace("MDI client %p window size = (%d x %d)\n", client
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1416 GetClientRect(client
, &rc
);
1417 trace("MDI client %p client size = (%d x %d)\n", client
, rc
.right
, rc
.bottom
);
1418 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN
),
1419 GetSystemMetrics(SM_CYSCREEN
));
1421 GetClientRect(client
, &rc
);
1422 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1423 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1424 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1425 trace("MDI child: calculated max window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1426 dump_minmax_info( minmax
);
1428 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1429 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1430 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1431 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1433 DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1435 trace("DefMDIChildProc returned:\n");
1436 dump_minmax_info( minmax
);
1438 MDI_ChildGetMinMaxInfo(client
, hwnd
, &my_minmax
);
1439 ok(minmax
->ptMaxSize
.x
== my_minmax
.ptMaxSize
.x
, "default width of maximized child %d != %d\n",
1440 minmax
->ptMaxSize
.x
, my_minmax
.ptMaxSize
.x
);
1441 ok(minmax
->ptMaxSize
.y
== my_minmax
.ptMaxSize
.y
, "default height of maximized child %d != %d\n",
1442 minmax
->ptMaxSize
.y
, my_minmax
.ptMaxSize
.y
);
1447 case WM_MDIACTIVATE
:
1449 HWND active
, client
= GetParent(hwnd
);
1450 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1451 active
= (HWND
)SendMessageA(client
, WM_MDIGETACTIVE
, 0, 0);
1452 if (hwnd
== (HWND
)lparam
) /* if we are being activated */
1453 ok (active
== (HWND
)lparam
, "new active %p != active %p\n", (HWND
)lparam
, active
);
1455 ok (active
== (HWND
)wparam
, "old active %p != active %p\n", (HWND
)wparam
, active
);
1459 return DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1462 static LRESULT WINAPI
mdi_child_wnd_proc_2(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1469 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1471 trace("%s\n", (msg
== WM_NCCREATE
) ? "WM_NCCREATE" : "WM_CREATE");
1472 trace("x %d, y %d, cx %d, cy %d\n", cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
1474 ok(!(cs
->dwExStyle
& WS_EX_MDICHILD
), "WS_EX_MDICHILD should not be set\n");
1475 ok(cs
->lpCreateParams
== mdi_lParam_test_message
, "wrong cs->lpCreateParams\n");
1477 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_2"), "wrong class name\n");
1478 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1480 /* CREATESTRUCT should have fixed values */
1481 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1483 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1484 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1486 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1487 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1488 while Win95, Win2k, WinXP do. */
1489 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1490 ok(cs
->cy
== 0, "%d != 0\n", cs
->cy
);
1494 case WM_GETMINMAXINFO
:
1496 HWND parent
= GetParent(hwnd
);
1498 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1499 LONG style
, exstyle
;
1501 trace("WM_GETMINMAXINFO\n");
1503 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1504 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1506 GetClientRect(parent
, &rc
);
1507 trace("parent %p client size = (%d x %d)\n", parent
, rc
.right
, rc
.bottom
);
1509 GetClientRect(parent
, &rc
);
1510 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1511 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1512 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1513 trace("calculated max child window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1514 dump_minmax_info( minmax
);
1516 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1517 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1518 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1519 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1523 case WM_WINDOWPOSCHANGED
:
1525 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1528 GetWindowRect(hwnd
, &rc1
);
1529 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1530 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1531 /* note: winpos coordinates are relative to parent */
1532 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1533 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1534 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1536 GetWindowRect(hwnd
, &rc1
);
1537 GetClientRect(hwnd
, &rc2
);
1538 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1539 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1540 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1543 case WM_WINDOWPOSCHANGING
:
1545 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1546 WINDOWPOS my_winpos
= *winpos
;
1548 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1549 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1550 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1551 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1553 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1555 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1556 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1557 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1559 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1560 "DefWindowProc should not change WINDOWPOS values\n");
1565 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1568 static LRESULT WINAPI
mdi_main_wnd_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1570 static HWND mdi_client
;
1576 CLIENTCREATESTRUCT client_cs
;
1579 GetClientRect(hwnd
, &rc
);
1581 client_cs
.hWindowMenu
= 0;
1582 client_cs
.idFirstChild
= 1;
1584 /* MDIClient without MDIS_ALLCHILDSTYLES */
1585 mdi_client
= CreateWindowExA(0, "mdiclient",
1587 WS_CHILD
/*| WS_VISIBLE*/,
1588 /* tests depend on a not zero MDIClient size */
1589 0, 0, rc
.right
, rc
.bottom
,
1590 hwnd
, 0, GetModuleHandle(0),
1591 (LPVOID
)&client_cs
);
1593 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1594 DestroyWindow(mdi_client
);
1596 /* MDIClient with MDIS_ALLCHILDSTYLES */
1597 mdi_client
= CreateWindowExA(0, "mdiclient",
1599 WS_CHILD
| MDIS_ALLCHILDSTYLES
/*| WS_VISIBLE*/,
1600 /* tests depend on a not zero MDIClient size */
1601 0, 0, rc
.right
, rc
.bottom
,
1602 hwnd
, 0, GetModuleHandle(0),
1603 (LPVOID
)&client_cs
);
1605 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1606 DestroyWindow(mdi_client
);
1610 case WM_WINDOWPOSCHANGED
:
1612 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1615 GetWindowRect(hwnd
, &rc1
);
1616 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1617 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1618 /* note: winpos coordinates are relative to parent */
1619 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1620 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1621 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1623 GetWindowRect(hwnd
, &rc1
);
1624 GetClientRect(hwnd
, &rc2
);
1625 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1626 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1627 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1630 case WM_WINDOWPOSCHANGING
:
1632 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1633 WINDOWPOS my_winpos
= *winpos
;
1635 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1636 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1637 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1638 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1640 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1642 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1643 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1644 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1646 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1647 "DefWindowProc should not change WINDOWPOS values\n");
1656 return DefFrameProcA(hwnd
, mdi_client
, msg
, wparam
, lparam
);
1659 static BOOL
mdi_RegisterWindowClasses(void)
1664 cls
.lpfnWndProc
= mdi_main_wnd_procA
;
1667 cls
.hInstance
= GetModuleHandleA(0);
1669 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
1670 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1671 cls
.lpszMenuName
= NULL
;
1672 cls
.lpszClassName
= "MDI_parent_Class";
1673 if(!RegisterClassA(&cls
)) return FALSE
;
1675 cls
.lpfnWndProc
= mdi_child_wnd_proc_1
;
1676 cls
.lpszClassName
= "MDI_child_Class_1";
1677 if(!RegisterClassA(&cls
)) return FALSE
;
1679 cls
.lpfnWndProc
= mdi_child_wnd_proc_2
;
1680 cls
.lpszClassName
= "MDI_child_Class_2";
1681 if(!RegisterClassA(&cls
)) return FALSE
;
1686 static void test_mdi(void)
1691 if (!mdi_RegisterWindowClasses()) assert(0);
1693 mdi_hwndMain
= CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1694 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
1695 WS_MAXIMIZEBOX
/*| WS_VISIBLE*/,
1696 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1697 GetDesktopWindow(), 0,
1698 GetModuleHandle(0), NULL
);
1699 assert(mdi_hwndMain
);
1701 while(GetMessage(&msg, 0, 0, 0))
1703 TranslateMessage(&msg);
1704 DispatchMessage(&msg);
1707 DestroyWindow(mdi_hwndMain
);
1710 static void test_icons(void)
1714 HICON icon
= LoadIconA(0, (LPSTR
)IDI_APPLICATION
);
1715 HICON icon2
= LoadIconA(0, (LPSTR
)IDI_QUESTION
);
1716 HICON small_icon
= LoadImageA(0, (LPSTR
)IDI_APPLICATION
, IMAGE_ICON
,
1717 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
1720 cls
.cbSize
= sizeof(cls
);
1722 cls
.lpfnWndProc
= DefWindowProcA
;
1726 cls
.hIcon
= LoadIconA(0, (LPSTR
)IDI_HAND
);
1727 cls
.hIconSm
= small_icon
;
1728 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
1729 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1730 cls
.lpszMenuName
= NULL
;
1731 cls
.lpszClassName
= "IconWindowClass";
1733 RegisterClassExA(&cls
);
1735 hwnd
= CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1736 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, NULL
, NULL
);
1739 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1740 ok( res
== 0, "wrong big icon %p/0\n", res
);
1741 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon
);
1742 ok( res
== 0, "wrong previous big icon %p/0\n", res
);
1743 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1744 ok( res
== icon
, "wrong big icon after set %p/%p\n", res
, icon
);
1745 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon2
);
1746 ok( res
== icon
, "wrong previous big icon %p/%p\n", res
, icon
);
1747 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1748 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1750 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1751 ok( res
== 0, "wrong small icon %p/0\n", res
);
1752 /* this test is XP specific */
1753 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1754 ok( res != 0, "wrong small icon %p\n", res );*/
1755 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)icon
);
1756 ok( res
== 0, "wrong previous small icon %p/0\n", res
);
1757 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1758 ok( res
== icon
, "wrong small icon after set %p/%p\n", res
, icon
);
1759 /* this test is XP specific */
1760 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1761 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1762 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)small_icon
);
1763 ok( res
== icon
, "wrong previous small icon %p/%p\n", res
, icon
);
1764 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1765 ok( res
== small_icon
, "wrong small icon after set %p/%p\n", res
, small_icon
);
1766 /* this test is XP specific */
1767 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1768 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1770 /* make sure the big icon hasn't changed */
1771 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1772 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1774 DestroyWindow( hwnd
);
1777 static LRESULT WINAPI
nccalcsize_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1779 if (msg
== WM_NCCALCSIZE
)
1781 RECT
*rect
= (RECT
*)lparam
;
1782 /* first time around increase the rectangle, next time decrease it */
1783 if (rect
->left
== 100) InflateRect( rect
, 10, 10 );
1784 else InflateRect( rect
, -10, -10 );
1787 return DefWindowProc( hwnd
, msg
, wparam
, lparam
);
1790 static void test_SetWindowPos(HWND hwnd
)
1792 RECT orig_win_rc
, rect
;
1794 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
1796 SetRect(&rect
, 111, 222, 333, 444);
1797 ok(!GetWindowRect(0, &rect
), "GetWindowRect succeeded\n");
1798 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1799 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1801 SetRect(&rect
, 111, 222, 333, 444);
1802 ok(!GetClientRect(0, &rect
), "GetClientRect succeeded\n");
1803 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1804 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1806 GetWindowRect(hwnd
, &orig_win_rc
);
1808 old_proc
= SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)nccalcsize_proc
);
1809 SetWindowPos(hwnd
, 0, 100, 100, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1810 GetWindowRect( hwnd
, &rect
);
1811 ok( rect
.left
== 100 && rect
.top
== 100 && rect
.right
== 100 && rect
.bottom
== 100,
1812 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1813 GetClientRect( hwnd
, &rect
);
1814 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1815 ok( rect
.left
== 90 && rect
.top
== 90 && rect
.right
== 110 && rect
.bottom
== 110,
1816 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1818 SetWindowPos(hwnd
, 0, 200, 200, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1819 GetWindowRect( hwnd
, &rect
);
1820 ok( rect
.left
== 200 && rect
.top
== 200 && rect
.right
== 200 && rect
.bottom
== 200,
1821 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1822 GetClientRect( hwnd
, &rect
);
1823 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1824 ok( rect
.left
== 210 && rect
.top
== 210 && rect
.right
== 190 && rect
.bottom
== 190,
1825 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1827 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1828 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1829 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, old_proc
);
1831 /* Win9x truncates coordinates to 16-bit irrespectively */
1834 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE
);
1835 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE
);
1837 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE
);
1838 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE
);
1841 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1842 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1844 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1845 SetWindowPos(hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1846 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1847 SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1848 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1849 SetWindowPos(hwnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1850 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1853 static void test_SetMenu(HWND parent
)
1857 BOOL is_win9x
= GetWindowLongPtrW(parent
, GWLP_WNDPROC
) == 0;
1861 hMenu
= CreateMenu();
1864 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1867 /* fails on (at least) Wine, NT4, XP SP2 */
1868 test_nonclient_area(parent
);
1870 ret
= GetMenu(parent
);
1871 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1872 /* test whether we can destroy a menu assigned to a window */
1873 retok
= DestroyMenu(hMenu
);
1874 ok( retok
, "DestroyMenu error %d\n", GetLastError());
1875 ok(!IsMenu(hMenu
), "menu handle should be not valid after DestroyMenu\n");
1876 ret
= GetMenu(parent
);
1877 /* This test fails on Win9x */
1879 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1880 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1881 test_nonclient_area(parent
);
1883 hMenu
= CreateMenu();
1887 ret
= GetMenu(parent
);
1888 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1890 ok(!SetMenu(parent
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1891 test_nonclient_area(parent
);
1892 ret
= GetMenu(parent
);
1893 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1895 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1898 /* fails on (at least) Wine, NT4, XP SP2 */
1899 test_nonclient_area(parent
);
1901 ret
= GetMenu(parent
);
1902 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1904 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1905 test_nonclient_area(parent
);
1906 ret
= GetMenu(parent
);
1907 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1910 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, parent
, (HMENU
)10, 0, NULL
);
1913 ret
= GetMenu(child
);
1914 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1916 ok(!SetMenu(child
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1917 test_nonclient_area(child
);
1918 ret
= GetMenu(child
);
1919 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1921 ok(!SetMenu(child
, hMenu
), "SetMenu on a child window should fail\n");
1922 test_nonclient_area(child
);
1923 ret
= GetMenu(child
);
1924 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1926 ok(!SetMenu(child
, 0), "SetMenu(0) on a child window should fail\n");
1927 test_nonclient_area(child
);
1928 ret
= GetMenu(child
);
1929 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1931 style
= GetWindowLong(child
, GWL_STYLE
);
1932 SetWindowLong(child
, GWL_STYLE
, style
| WS_POPUP
);
1933 ok(SetMenu(child
, hMenu
), "SetMenu on a popup child window should not fail\n");
1934 ok(SetMenu(child
, 0), "SetMenu on a popup child window should not fail\n");
1935 SetWindowLong(child
, GWL_STYLE
, style
);
1937 SetWindowLong(child
, GWL_STYLE
, style
| WS_OVERLAPPED
);
1938 ok(!SetMenu(child
, hMenu
), "SetMenu on a overlapped child window should fail\n");
1939 SetWindowLong(child
, GWL_STYLE
, style
);
1941 DestroyWindow(child
);
1945 static void test_window_tree(HWND parent
, const DWORD
*style
, const int *order
, int total
)
1947 HWND child
[5], hwnd
;
1952 hwnd
= GetWindow(parent
, GW_CHILD
);
1953 ok(!hwnd
, "have to start without children to perform the test\n");
1955 for (i
= 0; i
< total
; i
++)
1957 if (style
[i
] & DS_CONTROL
)
1959 child
[i
] = CreateWindowExA(0, MAKEINTATOM(32770), "", style
[i
] & ~WS_VISIBLE
,
1960 0,0,0,0, parent
, (HMENU
)i
, 0, NULL
);
1961 if (style
[i
] & WS_VISIBLE
)
1962 ShowWindow(child
[i
], SW_SHOW
);
1964 SetWindowPos(child
[i
], HWND_BOTTOM
, 0,0,10,10, SWP_NOACTIVATE
);
1967 child
[i
] = CreateWindowExA(0, "static", "", style
[i
], 0,0,10,10,
1968 parent
, (HMENU
)i
, 0, NULL
);
1969 trace("child[%d] = %p\n", i
, child
[i
]);
1970 ok(child
[i
] != 0, "CreateWindowEx failed to create child window\n");
1973 hwnd
= GetWindow(parent
, GW_CHILD
);
1974 ok(hwnd
!= 0, "GetWindow(GW_CHILD) failed\n");
1975 ok(hwnd
== GetWindow(child
[total
- 1], GW_HWNDFIRST
), "GW_HWNDFIRST is wrong\n");
1976 ok(child
[order
[total
- 1]] == GetWindow(child
[0], GW_HWNDLAST
), "GW_HWNDLAST is wrong\n");
1978 for (i
= 0; i
< total
; i
++)
1980 trace("hwnd[%d] = %p\n", i
, hwnd
);
1981 ok(child
[order
[i
]] == hwnd
, "Z order of child #%d is wrong\n", i
);
1983 hwnd
= GetWindow(hwnd
, GW_HWNDNEXT
);
1986 for (i
= 0; i
< total
; i
++)
1987 ok(DestroyWindow(child
[i
]), "DestroyWindow failed\n");
1990 static void test_children_zorder(HWND parent
)
1992 const DWORD simple_style
[5] = { WS_CHILD
, WS_CHILD
, WS_CHILD
, WS_CHILD
,
1994 const int simple_order
[5] = { 0, 1, 2, 3, 4 };
1996 const DWORD complex_style
[5] = { WS_CHILD
, WS_CHILD
| WS_MAXIMIZE
,
1997 WS_CHILD
| WS_VISIBLE
, WS_CHILD
,
1998 WS_CHILD
| WS_MAXIMIZE
| WS_VISIBLE
};
1999 const int complex_order_1
[1] = { 0 };
2000 const int complex_order_2
[2] = { 1, 0 };
2001 const int complex_order_3
[3] = { 1, 0, 2 };
2002 const int complex_order_4
[4] = { 1, 0, 2, 3 };
2003 const int complex_order_5
[5] = { 4, 1, 0, 2, 3 };
2004 const DWORD complex_style_6
[3] = { WS_CHILD
| WS_VISIBLE
,
2005 WS_CHILD
| WS_CLIPSIBLINGS
| DS_CONTROL
| WS_VISIBLE
,
2006 WS_CHILD
| WS_VISIBLE
};
2007 const int complex_order_6
[3] = { 0, 1, 2 };
2009 /* simple WS_CHILD */
2010 test_window_tree(parent
, simple_style
, simple_order
, 5);
2012 /* complex children styles */
2013 test_window_tree(parent
, complex_style
, complex_order_1
, 1);
2014 test_window_tree(parent
, complex_style
, complex_order_2
, 2);
2015 test_window_tree(parent
, complex_style
, complex_order_3
, 3);
2016 test_window_tree(parent
, complex_style
, complex_order_4
, 4);
2017 test_window_tree(parent
, complex_style
, complex_order_5
, 5);
2019 /* another set of complex children styles */
2020 test_window_tree(parent
, complex_style_6
, complex_order_6
, 3);
2023 #define check_z_order(hwnd, next, prev, owner, topmost) \
2024 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2027 static void check_z_order_debug(HWND hwnd
, HWND next
, HWND prev
, HWND owner
,
2028 BOOL topmost
, const char *file
, int line
)
2033 test
= GetWindow(hwnd
, GW_HWNDNEXT
);
2034 /* skip foreign windows */
2035 while (test
&& (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2036 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0)))
2038 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2039 test
= GetWindow(test
, GW_HWNDNEXT
);
2041 ok_(file
, line
)(next
== test
, "expected next %p, got %p\n", next
, test
);
2043 test
= GetWindow(hwnd
, GW_HWNDPREV
);
2044 /* skip foreign windows */
2045 while (test
&& (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2046 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0)))
2048 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2049 test
= GetWindow(test
, GW_HWNDPREV
);
2051 ok_(file
, line
)(prev
== test
, "expected prev %p, got %p\n", prev
, test
);
2053 test
= GetWindow(hwnd
, GW_OWNER
);
2054 ok_(file
, line
)(owner
== test
, "expected owner %p, got %p\n", owner
, test
);
2056 ex_style
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
2057 ok_(file
, line
)(!(ex_style
& WS_EX_TOPMOST
) == !topmost
, "expected %stopmost\n", topmost
? "" : "NOT ");
2060 static void test_popup_zorder(HWND hwnd_D
, HWND hwnd_E
)
2062 HWND hwnd_A
, hwnd_B
, hwnd_C
, hwnd_F
;
2064 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D
, hwnd_E
);
2066 SetWindowPos(hwnd_E
, hwnd_D
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2068 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2069 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2071 hwnd_F
= CreateWindowEx(0, "MainWindowClass", "Owner window",
2072 WS_OVERLAPPED
| WS_CAPTION
,
2074 0, 0, GetModuleHandle(0), NULL
);
2075 trace("hwnd_F %p\n", hwnd_F
);
2076 check_z_order(hwnd_F
, hwnd_D
, 0, 0, FALSE
);
2078 SetWindowPos(hwnd_F
, hwnd_E
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2079 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2080 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2081 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2083 hwnd_C
= CreateWindowEx(0, "MainWindowClass", NULL
,
2086 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2087 trace("hwnd_C %p\n", hwnd_C
);
2088 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2089 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2090 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2091 check_z_order(hwnd_C
, hwnd_D
, 0, hwnd_F
, FALSE
);
2093 hwnd_B
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2096 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2097 trace("hwnd_B %p\n", hwnd_B
);
2098 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2099 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2100 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2101 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2102 check_z_order(hwnd_B
, hwnd_C
, 0, hwnd_F
, TRUE
);
2104 hwnd_A
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2107 0, 0, GetModuleHandle(0), NULL
);
2108 trace("hwnd_A %p\n", hwnd_A
);
2109 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2110 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2111 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2112 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2113 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2114 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2116 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
);
2118 /* move hwnd_F and its popups up */
2119 SetWindowPos(hwnd_F
, HWND_TOP
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2120 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2121 check_z_order(hwnd_D
, hwnd_E
, hwnd_F
, 0, FALSE
);
2122 check_z_order(hwnd_F
, hwnd_D
, hwnd_C
, 0, FALSE
);
2123 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2124 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2125 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2127 /* move hwnd_F and its popups down */
2128 #if 0 /* enable once Wine is fixed to pass this test */
2129 SetWindowPos(hwnd_F
, HWND_BOTTOM
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2130 check_z_order(hwnd_F
, 0, hwnd_C
, 0, FALSE
);
2131 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2132 check_z_order(hwnd_B
, hwnd_C
, hwnd_E
, hwnd_F
, FALSE
);
2133 check_z_order(hwnd_E
, hwnd_B
, hwnd_D
, 0, FALSE
);
2134 check_z_order(hwnd_D
, hwnd_E
, hwnd_A
, 0, FALSE
);
2135 check_z_order(hwnd_A
, hwnd_D
, 0, 0, TRUE
);
2138 DestroyWindow(hwnd_A
);
2139 DestroyWindow(hwnd_B
);
2140 DestroyWindow(hwnd_C
);
2141 DestroyWindow(hwnd_F
);
2144 static void test_vis_rgn( HWND hwnd
)
2146 RECT win_rect
, rgn_rect
;
2147 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2150 ShowWindow(hwnd
,SW_SHOW
);
2151 hdc
= GetDC( hwnd
);
2152 ok( GetRandomRgn( hdc
, hrgn
, SYSRGN
) != 0, "GetRandomRgn failed\n" );
2153 GetWindowRect( hwnd
, &win_rect
);
2154 GetRgnBox( hrgn
, &rgn_rect
);
2155 if (GetVersion() & 0x80000000)
2157 trace("win9x, mapping to screen coords\n");
2158 MapWindowPoints( hwnd
, 0, (POINT
*)&rgn_rect
, 2 );
2160 trace("win: %d,%d-%d,%d\n", win_rect
.left
, win_rect
.top
, win_rect
.right
, win_rect
.bottom
);
2161 trace("rgn: %d,%d-%d,%d\n", rgn_rect
.left
, rgn_rect
.top
, rgn_rect
.right
, rgn_rect
.bottom
);
2162 ok( win_rect
.left
<= rgn_rect
.left
, "rgn left %d not inside win rect %d\n",
2163 rgn_rect
.left
, win_rect
.left
);
2164 ok( win_rect
.top
<= rgn_rect
.top
, "rgn top %d not inside win rect %d\n",
2165 rgn_rect
.top
, win_rect
.top
);
2166 ok( win_rect
.right
>= rgn_rect
.right
, "rgn right %d not inside win rect %d\n",
2167 rgn_rect
.right
, win_rect
.right
);
2168 ok( win_rect
.bottom
>= rgn_rect
.bottom
, "rgn bottom %d not inside win rect %d\n",
2169 rgn_rect
.bottom
, win_rect
.bottom
);
2170 ReleaseDC( hwnd
, hdc
);
2173 static LRESULT WINAPI
set_focus_on_activate_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
2175 if (msg
== WM_ACTIVATE
&& LOWORD(wp
) == WA_ACTIVE
)
2177 HWND child
= GetWindow(hwnd
, GW_CHILD
);
2178 ok(child
!= 0, "couldn't find child window\n");
2180 ok(GetFocus() == child
, "Focus should be on child %p\n", child
);
2183 return DefWindowProc(hwnd
, msg
, wp
, lp
);
2186 static void test_SetFocus(HWND hwnd
)
2189 WNDPROC old_wnd_proc
;
2191 /* check if we can set focus to non-visible windows */
2193 ShowWindow(hwnd
, SW_SHOW
);
2196 ok( GetFocus() == hwnd
, "Failed to set focus to visible window %p\n", hwnd
);
2197 ok( GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
, "Window %p not visible\n", hwnd
);
2198 ShowWindow(hwnd
, SW_HIDE
);
2201 ok( GetFocus() == hwnd
, "Failed to set focus to invisible window %p\n", hwnd
);
2202 ok( !(GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
), "Window %p still visible\n", hwnd
);
2203 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2206 ok( GetFocus() == child
, "Failed to set focus to invisible child %p\n", child
);
2207 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2208 ShowWindow(child
, SW_SHOW
);
2209 ok( GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
, "Child %p is not visible\n", child
);
2210 ok( GetFocus() == child
, "Focus no longer on child %p\n", child
);
2211 ShowWindow(child
, SW_HIDE
);
2212 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2213 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2214 ShowWindow(child
, SW_SHOW
);
2216 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2217 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_HIDEWINDOW
);
2218 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2220 ShowWindow(child
, SW_HIDE
);
2222 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2223 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_SHOWWINDOW
);
2224 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2225 ShowWindow(child
, SW_HIDE
);
2226 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2228 ShowWindow(hwnd
, SW_SHOW
);
2229 ShowWindow(child
, SW_SHOW
);
2231 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2232 EnableWindow(hwnd
, FALSE
);
2233 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2234 EnableWindow(hwnd
, TRUE
);
2236 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2237 ShowWindow(hwnd
, SW_SHOWMINIMIZED
);
2238 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2240 ok( GetFocus() != child
, "Focus should not be on child %p\n", child
);
2241 ok( GetFocus() != hwnd
, "Focus should not be on parent %p\n", hwnd
);
2242 ShowWindow(hwnd
, SW_RESTORE
);
2243 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2244 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
2245 ShowWindow(hwnd
, SW_SHOWMINIMIZED
);
2246 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2247 ok( GetFocus() != child
, "Focus should not be on child %p\n", child
);
2249 ok( GetFocus() != hwnd
, "Focus should not be on parent %p\n", hwnd
);
2250 old_wnd_proc
= (WNDPROC
)SetWindowLongPtr(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)set_focus_on_activate_proc
);
2251 ShowWindow(hwnd
, SW_RESTORE
);
2252 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2254 ok( GetFocus() == child
, "Focus should be on child %p, not %p\n", child
, GetFocus() );
2256 SetWindowLongPtr(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)old_wnd_proc
);
2258 DestroyWindow( child
);
2261 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
2262 static void check_wnd_state_(const char *file
, int line
,
2263 HWND active
, HWND foreground
, HWND focus
, HWND capture
)
2265 ok_(file
, line
)(active
== GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2267 ok_(file
, line
)(foreground
== GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2268 ok_(file
, line
)(focus
== GetFocus(), "GetFocus() = %p\n", GetFocus());
2269 ok_(file
, line
)(capture
== GetCapture(), "GetCapture() = %p\n", GetCapture());
2272 static void test_SetActiveWindow(HWND hwnd
)
2276 flush_events( TRUE
);
2277 ShowWindow(hwnd
, SW_HIDE
);
2280 check_wnd_state(0, 0, 0, 0);
2282 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2284 ShowWindow(hwnd
, SW_SHOW
);
2285 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2287 hwnd2
= SetActiveWindow(0);
2288 ok(hwnd2
== hwnd
, "SetActiveWindow returned %p instead of %p\n", hwnd2
, hwnd
);
2289 check_wnd_state(0, 0, 0, 0);
2291 hwnd2
= SetActiveWindow(hwnd
);
2292 ok(hwnd2
== 0, "SetActiveWindow returned %p instead of 0\n", hwnd2
);
2293 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2295 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2296 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2298 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2299 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2301 ShowWindow(hwnd
, SW_HIDE
);
2302 check_wnd_state(0, 0, 0, 0);
2304 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2305 SetActiveWindow(hwnd
);
2306 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2308 ShowWindow(hwnd
, SW_SHOW
);
2309 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2311 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2312 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2314 DestroyWindow(hwnd2
);
2315 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2317 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2318 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2320 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2321 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2323 DestroyWindow(hwnd2
);
2324 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2327 static void test_SetForegroundWindow(HWND hwnd
)
2332 flush_events( TRUE
);
2333 ShowWindow(hwnd
, SW_HIDE
);
2336 check_wnd_state(0, 0, 0, 0);
2338 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2340 ShowWindow(hwnd
, SW_SHOW
);
2341 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2343 hwnd2
= SetActiveWindow(0);
2344 ok(hwnd2
== hwnd
, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2
, hwnd
);
2345 check_wnd_state(0, 0, 0, 0);
2347 ret
= SetForegroundWindow(hwnd
);
2348 ok(ret
, "SetForegroundWindow returned FALSE instead of TRUE\n");
2349 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2351 SetLastError(0xdeadbeef);
2352 ret
= SetForegroundWindow(0);
2353 ok(!ret
, "SetForegroundWindow returned TRUE instead of FALSE\n");
2354 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2355 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2357 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2358 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2360 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2361 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2363 hwnd2
= GetForegroundWindow();
2364 ok(hwnd2
== hwnd
, "Wrong foreground window %p\n", hwnd2
);
2365 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2366 hwnd2
= GetForegroundWindow();
2367 ok(hwnd2
!= hwnd
, "Wrong foreground window %p\n", hwnd2
);
2369 ShowWindow(hwnd
, SW_HIDE
);
2370 check_wnd_state(0, 0, 0, 0);
2372 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2373 ret
= SetForegroundWindow(hwnd
);
2374 ok(ret
, "SetForegroundWindow returned FALSE instead of TRUE\n");
2375 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2377 ShowWindow(hwnd
, SW_SHOW
);
2378 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2380 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2381 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2383 DestroyWindow(hwnd2
);
2384 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2386 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2387 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2389 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2390 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2392 DestroyWindow(hwnd2
);
2393 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2396 static WNDPROC old_button_proc
;
2398 static LRESULT WINAPI
button_hook_proc(HWND button
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2403 key_state
= GetKeyState(VK_LBUTTON
);
2404 ok(!(key_state
& 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state
);
2406 ret
= CallWindowProcA(old_button_proc
, button
, msg
, wparam
, lparam
);
2408 if (msg
== WM_LBUTTONDOWN
)
2412 check_wnd_state(button
, button
, button
, button
);
2414 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2416 trace("hwnd %p\n", hwnd
);
2418 check_wnd_state(button
, button
, button
, button
);
2420 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2422 check_wnd_state(button
, button
, button
, button
);
2424 DestroyWindow(hwnd
);
2426 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2428 trace("hwnd %p\n", hwnd
);
2430 check_wnd_state(button
, button
, button
, button
);
2432 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2433 * match internal button state.
2435 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2436 check_wnd_state(button
, button
, button
, 0);
2438 ShowWindow(hwnd
, SW_SHOW
);
2439 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2441 capture
= SetCapture(hwnd
);
2442 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2444 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2446 DestroyWindow(hwnd
);
2448 check_wnd_state(button
, 0, button
, 0);
2454 static void test_capture_1(void)
2456 HWND button
, capture
;
2458 capture
= GetCapture();
2459 ok(capture
== 0, "GetCapture() = %p\n", capture
);
2461 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2463 trace("button %p\n", button
);
2465 old_button_proc
= (WNDPROC
)SetWindowLongPtrA(button
, GWLP_WNDPROC
, (LONG_PTR
)button_hook_proc
);
2467 SendMessageA(button
, WM_LBUTTONDOWN
, 0, 0);
2469 capture
= SetCapture(button
);
2470 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2471 check_wnd_state(button
, 0, button
, button
);
2473 DestroyWindow(button
);
2474 check_wnd_state(0, 0, 0, 0);
2477 static void test_capture_2(void)
2479 HWND button
, hwnd
, capture
;
2481 check_wnd_state(0, 0, 0, 0);
2483 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2485 trace("button %p\n", button
);
2487 check_wnd_state(button
, button
, button
, 0);
2489 capture
= SetCapture(button
);
2490 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2492 check_wnd_state(button
, button
, button
, button
);
2494 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2495 * internal button state.
2497 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2498 check_wnd_state(button
, button
, button
, button
);
2500 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2502 trace("hwnd %p\n", hwnd
);
2504 check_wnd_state(button
, button
, button
, button
);
2506 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2508 check_wnd_state(button
, button
, button
, button
);
2510 DestroyWindow(hwnd
);
2512 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2514 trace("hwnd %p\n", hwnd
);
2516 check_wnd_state(button
, button
, button
, button
);
2518 ShowWindow(hwnd
, SW_SHOW
);
2520 check_wnd_state(hwnd
, hwnd
, hwnd
, button
);
2522 capture
= SetCapture(hwnd
);
2523 ok(capture
== button
, "SetCapture() = %p\n", capture
);
2525 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2527 DestroyWindow(hwnd
);
2528 check_wnd_state(button
, button
, button
, 0);
2530 DestroyWindow(button
);
2531 check_wnd_state(0, 0, 0, 0);
2534 static void test_capture_3(HWND hwnd1
, HWND hwnd2
)
2538 ShowWindow(hwnd1
, SW_HIDE
);
2539 ShowWindow(hwnd2
, SW_HIDE
);
2541 ok(!IsWindowVisible(hwnd1
), "%p should be invisible\n", hwnd1
);
2542 ok(!IsWindowVisible(hwnd2
), "%p should be invisible\n", hwnd2
);
2545 check_wnd_state(0, 0, 0, hwnd1
);
2548 check_wnd_state(0, 0, 0, hwnd2
);
2550 ShowWindow(hwnd1
, SW_SHOW
);
2551 check_wnd_state(hwnd1
, hwnd1
, hwnd1
, hwnd2
);
2553 ret
= ReleaseCapture();
2554 ok (ret
, "releasecapture did not return TRUE.\n");
2555 ret
= ReleaseCapture();
2556 ok (ret
, "releasecapture did not return TRUE after second try.\n");
2559 static void test_keyboard_input(HWND hwnd
)
2564 flush_events( TRUE
);
2565 SetWindowPos(hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_SHOWWINDOW
);
2567 flush_events( TRUE
);
2569 ok(GetActiveWindow() == hwnd
, "wrong active window %p\n", GetActiveWindow());
2572 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2574 flush_events( TRUE
);
2576 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2577 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2578 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2579 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2580 ok( !ret
, "message %04x available\n", msg
.message
);
2582 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2584 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2585 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2586 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2587 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2588 ok( !ret
, "message %04x available\n", msg
.message
);
2590 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2592 keybd_event(VK_SPACE
, 0, 0, 0);
2593 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2594 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2595 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2596 ok( !ret
, "message %04x available\n", msg
.message
);
2599 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2601 flush_events( TRUE
);
2603 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2604 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2605 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2606 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2607 ok( !ret
, "message %04x available\n", msg
.message
);
2609 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2611 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2612 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2613 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2614 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2615 ok( !ret
, "message %04x available\n", msg
.message
);
2617 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2619 keybd_event(VK_SPACE
, 0, 0, 0);
2620 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2621 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_SYSKEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2622 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2623 ok( !ret
, "message %04x available\n", msg
.message
);
2626 static void test_mouse_input(HWND hwnd
)
2636 ShowWindow(hwnd
, SW_SHOW
);
2639 GetWindowRect(hwnd
, &rc
);
2640 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2642 popup
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_POPUP
,
2643 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
,
2646 ShowWindow(popup
, SW_SHOW
);
2647 UpdateWindow(popup
);
2649 GetWindowRect(popup
, &rc
);
2650 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2652 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
2653 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
2654 trace("setting cursor to (%d,%d)\n", x
, y
);
2658 ok(x
== pt
.x
&& y
== pt
.y
, "wrong cursor pos (%d,%d), expected (%d,%d)\n", pt
.x
, pt
.y
, x
, y
);
2660 flush_events( TRUE
);
2662 /* Check that setting the same position will generate WM_MOUSEMOVE */
2665 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2666 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2667 ok(msg
.pt
.x
== x
&& msg
.pt
.y
== y
, "wrong message coords (%d,%d)/(%d,%d)\n", x
, y
, msg
.pt
.x
, msg
.pt
.y
);
2669 /* force the system to update its internal queue mouse position,
2670 * otherwise it won't generate relative mouse movements below.
2672 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2673 flush_events( TRUE
);
2676 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2677 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2678 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2679 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2680 if (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
2681 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2682 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2683 ok( !ret
, "message %04x available\n", msg
.message
);
2685 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2686 ShowWindow(popup
, SW_HIDE
);
2688 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2689 while (msg
.message
>= 0xc000); /* skip registered messages */
2690 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2691 flush_events( TRUE
);
2693 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2694 ShowWindow(hwnd
, SW_HIDE
);
2696 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2697 while (ret
&& msg
.message
>= 0xc000); /* skip registered messages */
2698 ok( !ret
, "message %04x available\n", msg
.message
);
2699 flush_events( TRUE
);
2701 /* test mouse clicks */
2703 ShowWindow(hwnd
, SW_SHOW
);
2704 flush_events( TRUE
);
2705 ShowWindow(popup
, SW_SHOW
);
2706 flush_events( TRUE
);
2708 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2709 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2710 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2711 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2713 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2714 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2715 msg
.hwnd
, popup
, msg
.message
);
2716 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2717 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2718 msg
.hwnd
, popup
, msg
.message
);
2720 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2721 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2722 msg
.hwnd
, popup
, msg
.message
);
2723 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2724 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2725 msg
.hwnd
, popup
, msg
.message
);
2727 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2728 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p/%p message %04x\n",
2729 msg
.hwnd
, popup
, msg
.message
);
2730 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2731 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p/%p message %04x\n",
2732 msg
.hwnd
, popup
, msg
.message
);
2734 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2735 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2736 msg
.hwnd
, popup
, msg
.message
);
2737 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2738 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2739 msg
.hwnd
, popup
, msg
.message
);
2741 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2742 ok(!ret
, "message %04x available\n", msg
.message
);
2744 ShowWindow(popup
, SW_HIDE
);
2745 flush_events( TRUE
);
2747 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2748 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2749 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2750 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2752 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2753 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2754 msg
.hwnd
, hwnd
, msg
.message
);
2755 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2756 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2757 msg
.hwnd
, hwnd
, msg
.message
);
2759 test_lbuttondown_flag
= TRUE
;
2760 SendMessageA(hwnd
, WM_COMMAND
, (WPARAM
)popup
, 0);
2761 test_lbuttondown_flag
= FALSE
;
2764 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2765 while (msg
.message
>= 0xc000); /* skip registered messages */
2766 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2767 msg
.hwnd
, popup
, msg
.message
);
2768 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2769 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2770 msg
.hwnd
, popup
, msg
.message
);
2771 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2773 /* Test WM_MOUSEACTIVATE */
2774 #define TEST_MOUSEACTIVATE(A,B) \
2775 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2776 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2778 TEST_MOUSEACTIVATE(HTERROR
,MA_ACTIVATE
);
2779 TEST_MOUSEACTIVATE(HTTRANSPARENT
,MA_ACTIVATE
);
2780 TEST_MOUSEACTIVATE(HTNOWHERE
,MA_ACTIVATE
);
2781 TEST_MOUSEACTIVATE(HTCLIENT
,MA_ACTIVATE
);
2782 TEST_MOUSEACTIVATE(HTCAPTION
,MA_ACTIVATE
);
2783 TEST_MOUSEACTIVATE(HTSYSMENU
,MA_ACTIVATE
);
2784 TEST_MOUSEACTIVATE(HTSIZE
,MA_ACTIVATE
);
2785 TEST_MOUSEACTIVATE(HTMENU
,MA_ACTIVATE
);
2786 TEST_MOUSEACTIVATE(HTHSCROLL
,MA_ACTIVATE
);
2787 TEST_MOUSEACTIVATE(HTVSCROLL
,MA_ACTIVATE
);
2788 TEST_MOUSEACTIVATE(HTMINBUTTON
,MA_ACTIVATE
);
2789 TEST_MOUSEACTIVATE(HTMAXBUTTON
,MA_ACTIVATE
);
2790 TEST_MOUSEACTIVATE(HTLEFT
,MA_ACTIVATE
);
2791 TEST_MOUSEACTIVATE(HTRIGHT
,MA_ACTIVATE
);
2792 TEST_MOUSEACTIVATE(HTTOP
,MA_ACTIVATE
);
2793 TEST_MOUSEACTIVATE(HTTOPLEFT
,MA_ACTIVATE
);
2794 TEST_MOUSEACTIVATE(HTTOPRIGHT
,MA_ACTIVATE
);
2795 TEST_MOUSEACTIVATE(HTBOTTOM
,MA_ACTIVATE
);
2796 TEST_MOUSEACTIVATE(HTBOTTOMLEFT
,MA_ACTIVATE
);
2797 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT
,MA_ACTIVATE
);
2798 TEST_MOUSEACTIVATE(HTBORDER
,MA_ACTIVATE
);
2799 TEST_MOUSEACTIVATE(HTOBJECT
,MA_ACTIVATE
);
2800 TEST_MOUSEACTIVATE(HTCLOSE
,MA_ACTIVATE
);
2801 TEST_MOUSEACTIVATE(HTHELP
,MA_ACTIVATE
);
2803 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2804 flush_events( TRUE
);
2806 DestroyWindow(popup
);
2809 static void test_validatergn(HWND hwnd
)
2815 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_VISIBLE
, 10, 10, 10, 10, hwnd
, 0, 0, NULL
);
2816 ShowWindow(hwnd
, SW_SHOW
);
2817 UpdateWindow( hwnd
);
2818 /* test that ValidateRect validates children*/
2819 InvalidateRect( child
, NULL
, 1);
2820 GetWindowRect( child
, &rc
);
2821 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2822 ret
= GetUpdateRect( child
, &rc2
, 0);
2823 ok( rc2
.right
> rc2
.left
&& rc2
.bottom
> rc2
.top
,
2824 "Update rectangle is empty!\n");
2825 ValidateRect( hwnd
, &rc
);
2826 ret
= GetUpdateRect( child
, &rc2
, 0);
2827 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2828 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
2829 rc2
.right
, rc2
.bottom
);
2831 /* now test ValidateRgn */
2832 InvalidateRect( child
, NULL
, 1);
2833 GetWindowRect( child
, &rc
);
2834 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2835 rgn
= CreateRectRgnIndirect( &rc
);
2836 ValidateRgn( hwnd
, rgn
);
2837 ret
= GetUpdateRect( child
, &rc2
, 0);
2838 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2839 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
2840 rc2
.right
, rc2
.bottom
);
2843 DestroyWindow( child
);
2846 static void nccalchelper(HWND hwnd
, INT x
, INT y
, RECT
*prc
)
2848 MoveWindow( hwnd
, 0, 0, x
, y
, 0);
2849 GetWindowRect( hwnd
, prc
);
2850 trace("window rect is %d,%d - %d,%d\n",
2851 prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
2852 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)prc
);
2853 trace("nccalc rect is %d,%d - %d,%d\n",
2854 prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
2857 static void test_nccalcscroll(HWND parent
)
2860 INT sbheight
= GetSystemMetrics( SM_CYHSCROLL
);
2861 INT sbwidth
= GetSystemMetrics( SM_CXVSCROLL
);
2862 HWND hwnd
= CreateWindowExA(0, "static", NULL
,
2863 WS_CHILD
| WS_VISIBLE
| WS_VSCROLL
| WS_HSCROLL
,
2864 10, 10, 200, 200, parent
, 0, 0, NULL
);
2865 ShowWindow( parent
, SW_SHOW
);
2866 UpdateWindow( parent
);
2868 /* test window too low for a horizontal scroll bar */
2869 nccalchelper( hwnd
, 100, sbheight
, &rc1
);
2870 ok( rc1
.bottom
- rc1
.top
== sbheight
, "Height should be %d size is %d,%d - %d,%d\n",
2871 sbheight
, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2873 /* test window just high enough for a horizontal scroll bar */
2874 nccalchelper( hwnd
, 100, sbheight
+ 1, &rc1
);
2875 ok( rc1
.bottom
- rc1
.top
== 1, "Height should be %d size is %d,%d - %d,%d\n",
2876 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2878 /* test window too narrow for a vertical scroll bar */
2879 nccalchelper( hwnd
, sbwidth
- 1, 100, &rc1
);
2880 ok( rc1
.right
- rc1
.left
== sbwidth
- 1 , "Width should be %d size is %d,%d - %d,%d\n",
2881 sbwidth
- 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2883 /* test window just wide enough for a vertical scroll bar */
2884 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
2885 ok( rc1
.right
- rc1
.left
== 0, "Width should be %d size is %d,%d - %d,%d\n",
2886 0, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2888 /* same test, but with client edge: not enough width */
2889 SetWindowLong( hwnd
, GWL_EXSTYLE
, WS_EX_CLIENTEDGE
| GetWindowLong( hwnd
, GWL_EXSTYLE
));
2890 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
2891 ok( rc1
.right
- rc1
.left
== sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
),
2892 "Width should be %d size is %d,%d - %d,%d\n",
2893 sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
), rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2895 DestroyWindow( hwnd
);
2898 static void test_SetParent(void)
2901 HWND desktop
= GetDesktopWindow();
2903 BOOL is_win9x
= GetWindowLongPtrW(desktop
, GWLP_WNDPROC
) == 0;
2904 HWND parent
, child1
, child2
, child3
, child4
, sibling
;
2906 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
2907 100, 100, 200, 200, 0, 0, 0, NULL
);
2908 assert(parent
!= 0);
2909 child1
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
2910 0, 0, 50, 50, parent
, 0, 0, NULL
);
2911 assert(child1
!= 0);
2912 child2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
2913 0, 0, 50, 50, child1
, 0, 0, NULL
);
2914 assert(child2
!= 0);
2915 child3
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
2916 0, 0, 50, 50, child2
, 0, 0, NULL
);
2917 assert(child3
!= 0);
2918 child4
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
2919 0, 0, 50, 50, child3
, 0, 0, NULL
);
2920 assert(child4
!= 0);
2922 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2923 parent
, child1
, child2
, child3
, child4
);
2925 check_parents(parent
, desktop
, 0, 0, 0, parent
, parent
);
2926 check_parents(child1
, parent
, parent
, parent
, 0, parent
, parent
);
2927 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
2928 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
2929 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
2931 ok(!IsChild(desktop
, parent
), "wrong parent/child %p/%p\n", desktop
, parent
);
2932 ok(!IsChild(desktop
, child1
), "wrong parent/child %p/%p\n", desktop
, child1
);
2933 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
2934 ok(!IsChild(desktop
, child3
), "wrong parent/child %p/%p\n", desktop
, child3
);
2935 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
2937 ok(IsChild(parent
, child1
), "wrong parent/child %p/%p\n", parent
, child1
);
2938 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
2939 ok(!IsChild(parent
, child2
), "wrong parent/child %p/%p\n", parent
, child2
);
2940 ok(!IsChild(child1
, child2
), "wrong parent/child %p/%p\n", child1
, child2
);
2941 ok(!IsChild(parent
, child3
), "wrong parent/child %p/%p\n", parent
, child3
);
2942 ok(IsChild(child2
, child3
), "wrong parent/child %p/%p\n", child2
, child3
);
2943 ok(!IsChild(parent
, child4
), "wrong parent/child %p/%p\n", parent
, child4
);
2944 ok(!IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
2945 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
2947 if (!is_win9x
) /* Win9x doesn't survive this test */
2949 ok(!SetParent(parent
, child1
), "SetParent should fail\n");
2950 ok(!SetParent(child2
, child3
), "SetParent should fail\n");
2951 ok(SetParent(child1
, parent
) != 0, "SetParent should not fail\n");
2952 ok(SetParent(parent
, child2
) != 0, "SetParent should not fail\n");
2953 ok(SetParent(parent
, child3
) != 0, "SetParent should not fail\n");
2954 ok(!SetParent(child2
, parent
), "SetParent should fail\n");
2955 ok(SetParent(parent
, child4
) != 0, "SetParent should not fail\n");
2957 check_parents(parent
, child4
, child4
, 0, 0, child4
, parent
);
2958 check_parents(child1
, parent
, parent
, parent
, 0, child4
, parent
);
2959 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
2960 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
2961 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
2964 hMenu
= CreateMenu();
2965 sibling
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
2966 100, 100, 200, 200, 0, hMenu
, 0, NULL
);
2967 assert(sibling
!= 0);
2969 ok(SetParent(sibling
, parent
) != 0, "SetParent should not fail\n");
2970 ok(GetMenu(sibling
) == hMenu
, "SetParent should not remove menu\n");
2972 ret
= DestroyWindow(parent
);
2973 ok( ret
, "DestroyWindow() error %d\n", GetLastError());
2975 ok(!IsWindow(parent
), "parent still exists\n");
2976 ok(!IsWindow(sibling
), "sibling still exists\n");
2977 ok(!IsWindow(child1
), "child1 still exists\n");
2978 ok(!IsWindow(child2
), "child2 still exists\n");
2979 ok(!IsWindow(child3
), "child3 still exists\n");
2980 ok(!IsWindow(child4
), "child4 still exists\n");
2983 static LRESULT WINAPI
StyleCheckProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2985 LPCREATESTRUCT lpcs
;
2992 lpcs
= (LPCREATESTRUCT
)lparam
;
2993 lpss
= (LPSTYLESTRUCT
)lpcs
->lpCreateParams
;
2996 if ((lpcs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
2997 ((!(lpcs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
2998 (lpcs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
2999 ok(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
, "Window should have WS_EX_WINDOWEDGE style\n");
3001 ok(!(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3003 ok((lpss
->styleOld
& ~WS_EX_WINDOWEDGE
) == (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
),
3004 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
3005 (lpss
->styleOld
& ~WS_EX_WINDOWEDGE
), (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
));
3007 ok(lpss
->styleNew
== lpcs
->style
,
3008 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3009 lpss
->styleNew
, lpcs
->style
);
3013 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3016 static ATOM atomStyleCheckClass
;
3018 static void register_style_check_class(void)
3026 GetModuleHandle(NULL
),
3028 LoadCursor(NULL
, IDC_ARROW
),
3029 (HBRUSH
)(COLOR_BTNFACE
+1),
3031 TEXT("WineStyleCheck"),
3034 atomStyleCheckClass
= RegisterClass(&wc
);
3037 static void check_window_style(DWORD dwStyleIn
, DWORD dwExStyleIn
, DWORD dwStyleOut
, DWORD dwExStyleOut
)
3039 DWORD dwActualStyle
;
3040 DWORD dwActualExStyle
;
3043 HWND hwndParent
= NULL
;
3045 ss
.styleNew
= dwStyleIn
;
3046 ss
.styleOld
= dwExStyleIn
;
3048 if (dwStyleIn
& WS_CHILD
)
3050 hwndParent
= CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3051 WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
3054 hwnd
= CreateWindowEx(dwExStyleIn
, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3055 dwStyleIn
, 0, 0, 0, 0, hwndParent
, NULL
, NULL
, &ss
);
3058 flush_events( TRUE
);
3060 dwActualStyle
= GetWindowLong(hwnd
, GWL_STYLE
);
3061 dwActualExStyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
3062 ok((dwActualStyle
== dwStyleOut
) && (dwActualExStyle
== dwExStyleOut
),
3063 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3064 dwActualStyle
, dwStyleOut
, dwActualExStyle
, dwExStyleOut
);
3066 DestroyWindow(hwnd
);
3067 if (hwndParent
) DestroyWindow(hwndParent
);
3070 /* tests what window styles the window manager automatically adds */
3071 static void test_window_styles(void)
3073 register_style_check_class();
3075 check_window_style(0, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
3076 check_window_style(WS_OVERLAPPEDWINDOW
, 0, WS_CLIPSIBLINGS
|WS_OVERLAPPEDWINDOW
, WS_EX_WINDOWEDGE
);
3077 check_window_style(WS_CHILD
, 0, WS_CHILD
, 0);
3078 check_window_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
3079 check_window_style(0, WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_TOOLWINDOW
);
3080 check_window_style(WS_POPUP
, 0, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3081 check_window_style(WS_POPUP
, WS_EX_WINDOWEDGE
, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3082 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
, WS_CHILD
, WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3083 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
|WS_EX_STATICEDGE
, WS_CHILD
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3084 check_window_style(WS_CAPTION
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
);
3085 check_window_style(0, WS_EX_APPWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_APPWINDOW
|WS_EX_WINDOWEDGE
);
3088 static void test_scrollvalidate( HWND parent
)
3091 HRGN hrgn
=CreateRectRgn(0,0,0,0);
3092 HRGN exprgn
, tmprgn
, clipping
;
3093 RECT rc
, rcu
, cliprc
;
3094 /* create two overlapping child windows. The visual region
3095 * of hwnd1 is clipped by the overlapping part of
3096 * hwnd2 because of the WS_CLIPSIBLING style */
3099 clipping
= CreateRectRgn(0,0,0,0);
3100 tmprgn
= CreateRectRgn(0,0,0,0);
3101 exprgn
= CreateRectRgn(0,0,0,0);
3102 hwnd2
= CreateWindowExA(0, "static", NULL
,
3103 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3104 75, 30, 100, 100, parent
, 0, 0, NULL
);
3105 hwnd1
= CreateWindowExA(0, "static", NULL
,
3106 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3107 25, 50, 100, 100, parent
, 0, 0, NULL
);
3108 ShowWindow( parent
, SW_SHOW
);
3109 UpdateWindow( parent
);
3110 GetClientRect( hwnd1
, &rc
);
3112 SetRectRgn( clipping
, 10, 10, 90, 90);
3113 hdc
= GetDC( hwnd1
);
3114 /* for a visual touch */
3115 TextOut( hdc
, 0,10, "0123456789", 10);
3116 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3117 if (winetest_debug
> 0) dump_region(hrgn
);
3118 /* create a region with what is expected */
3119 SetRectRgn( exprgn
, 39,0,49,74);
3120 SetRectRgn( tmprgn
, 88,79,98,93);
3121 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3122 SetRectRgn( tmprgn
, 0,93,98,98);
3123 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3124 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3125 trace("update rect is %d,%d - %d,%d\n",
3126 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3127 /* now with clipping region */
3128 SelectClipRgn( hdc
, clipping
);
3129 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3130 if (winetest_debug
> 0) dump_region(hrgn
);
3131 /* create a region with what is expected */
3132 SetRectRgn( exprgn
, 39,10,49,74);
3133 SetRectRgn( tmprgn
, 80,79,90,85);
3134 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3135 SetRectRgn( tmprgn
, 10,85,90,90);
3136 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3137 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3138 trace("update rect is %d,%d - %d,%d\n",
3139 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3140 ReleaseDC( hwnd1
, hdc
);
3142 /* test scrolling a window with an update region */
3143 DestroyWindow( hwnd2
);
3144 ValidateRect( hwnd1
, NULL
);
3145 SetRect( &rc
, 40,40, 50,50);
3146 InvalidateRect( hwnd1
, &rc
, 1);
3147 GetClientRect( hwnd1
, &rc
);
3149 ScrollWindowEx( hwnd1
, -10, 0, &rc
, &cliprc
, hrgn
, &rcu
,
3150 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3151 if (winetest_debug
> 0) dump_region(hrgn
);
3152 SetRectRgn( exprgn
, 88,0,98,98);
3153 SetRectRgn( tmprgn
, 30, 40, 50, 50);
3154 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3155 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3157 /* clear an update region */
3158 UpdateWindow( hwnd1
);
3160 SetRect( &rc
, 0,40, 100,60);
3161 SetRect( &cliprc
, 0,0, 100,100);
3162 ScrollWindowEx( hwnd1
, 0, -25, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3163 if (winetest_debug
> 0) dump_region( hrgn
);
3164 SetRectRgn( exprgn
, 0, 40, 98, 60 );
3165 ok( EqualRgn( exprgn
, hrgn
), "wrong update region in excessive scroll\n");
3167 /* now test ScrollWindowEx with a combination of
3168 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3169 /* make hwnd2 the child of hwnd1 */
3170 hwnd2
= CreateWindowExA(0, "static", NULL
,
3171 WS_CHILD
| WS_VISIBLE
| WS_BORDER
,
3172 50, 50, 100, 100, hwnd1
, 0, 0, NULL
);
3173 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPSIBLINGS
);
3174 GetClientRect( hwnd1
, &rc
);
3177 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3178 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3179 ValidateRect( hwnd1
, NULL
);
3180 ValidateRect( hwnd2
, NULL
);
3181 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
,
3182 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3183 if (winetest_debug
> 0) dump_region(hrgn
);
3184 SetRectRgn( exprgn
, 88,0,98,88);
3185 SetRectRgn( tmprgn
, 0,88,98,98);
3186 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3187 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3189 /* SW_SCROLLCHILDREN */
3190 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3191 ValidateRect( hwnd1
, NULL
);
3192 ValidateRect( hwnd2
, NULL
);
3193 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3194 if (winetest_debug
> 0) dump_region(hrgn
);
3195 /* expected region is the same as in previous test */
3196 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3198 /* no SW_SCROLLCHILDREN */
3199 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3200 ValidateRect( hwnd1
, NULL
);
3201 ValidateRect( hwnd2
, NULL
);
3202 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3203 if (winetest_debug
> 0) dump_region(hrgn
);
3204 /* expected region is the same as in previous test */
3205 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3207 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3208 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3209 ValidateRect( hwnd1
, NULL
);
3210 ValidateRect( hwnd2
, NULL
);
3211 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3212 if (winetest_debug
> 0) dump_region(hrgn
);
3213 SetRectRgn( exprgn
, 88,0,98,20);
3214 SetRectRgn( tmprgn
, 20,20,98,30);
3215 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3216 SetRectRgn( tmprgn
, 20,30,30,88);
3217 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3218 SetRectRgn( tmprgn
, 0,88,30,98);
3219 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3220 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3223 DeleteObject( hrgn
);
3224 DeleteObject( exprgn
);
3225 DeleteObject( tmprgn
);
3226 DestroyWindow( hwnd1
);
3227 DestroyWindow( hwnd2
);
3230 /* couple of tests of return values of scrollbar functions
3231 * called on a scrollbarless window */
3232 static void test_scroll(void)
3237 HWND hwnd
= CreateWindowExA(0, "Static", "Wine test window",
3238 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_POPUP
,
3239 100, 100, 200, 200, 0, 0, 0, NULL
);
3241 ret
= GetScrollRange( hwnd
, SB_HORZ
, &min
, &max
);
3242 ok( ret
, "GetScrollRange returns FALSE\n");
3243 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3244 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3245 si
.cbSize
= sizeof( si
);
3246 si
.fMask
= SIF_PAGE
;
3247 si
.nPage
= 0xdeadbeef;
3248 ret
= GetScrollInfo( hwnd
, SB_HORZ
, &si
);
3249 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3250 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3252 ret
= GetScrollRange( hwnd
, SB_VERT
, &min
, &max
);
3253 ok( ret
, "GetScrollRange returns FALSE\n");
3254 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3255 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3256 si
.cbSize
= sizeof( si
);
3257 si
.fMask
= SIF_PAGE
;
3258 si
.nPage
= 0xdeadbeef;
3259 ret
= GetScrollInfo( hwnd
, SB_VERT
, &si
);
3260 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3261 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3263 DestroyWindow( hwnd
);
3266 static void test_scrolldc( HWND parent
)
3269 HRGN exprgn
, tmprgn
, hrgn
;
3270 RECT rc
, rc2
, rcu
, cliprc
;
3274 hrgn
= CreateRectRgn(0,0,0,0);
3275 tmprgn
= CreateRectRgn(0,0,0,0);
3276 exprgn
= CreateRectRgn(0,0,0,0);
3278 hwnd1
= CreateWindowExA(0, "static", NULL
,
3279 WS_CHILD
| WS_VISIBLE
,
3280 25, 50, 100, 100, parent
, 0, 0, NULL
);
3281 ShowWindow( parent
, SW_SHOW
);
3282 UpdateWindow( parent
);
3283 flush_events( TRUE
);
3284 GetClientRect( hwnd1
, &rc
);
3285 hdc
= GetDC( hwnd1
);
3286 /* paint the upper half of the window black */
3288 rc2
.bottom
= ( rc
.top
+ rc
.bottom
) /2;
3289 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3290 /* clip region is the lower half */
3292 cliprc
.top
= (rc
.top
+ rc
.bottom
) /2;
3293 /* test whether scrolled pixels are properly clipped */
3294 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3295 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3296 /* this scroll should not cause any visible changes */
3297 ScrollDC( hdc
, 5, -20, &rc
, &cliprc
, hrgn
, &rcu
);
3298 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3299 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3300 /* test with NULL clip rect */
3301 ScrollDC( hdc
, 20, -20, &rc
, NULL
, hrgn
, &rcu
);
3302 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3303 trace("update rect: %d,%d - %d,%d\n",
3304 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3305 if (winetest_debug
> 0) dump_region(hrgn
);
3306 SetRect(&rc2
, 0, 0, 100, 100);
3307 ok(EqualRect(&rcu
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3308 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
3310 SetRectRgn( exprgn
, 0, 0, 20, 80);
3311 SetRectRgn( tmprgn
, 0, 80, 100, 100);
3312 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3313 if (winetest_debug
> 0) dump_region(exprgn
);
3314 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3315 /* test clip rect > scroll rect */
3316 FillRect( hdc
, &rc
, GetStockObject(WHITE_BRUSH
));
3318 InflateRect( &rc2
, -(rc
.right
-rc
.left
)/4, -(rc
.bottom
-rc
.top
)/4);
3319 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3320 ScrollDC( hdc
, 10, 10, &rc2
, &rc
, hrgn
, &rcu
);
3321 SetRectRgn( exprgn
, 25, 25, 75, 35);
3322 SetRectRgn( tmprgn
, 25, 35, 35, 75);
3323 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3324 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3325 colr
= GetPixel( hdc
, 80, 80);
3326 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3327 trace("update rect: %d,%d - %d,%d\n",
3328 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3329 if (winetest_debug
> 0) dump_region(hrgn
);
3333 DeleteObject(exprgn
);
3334 DeleteObject(tmprgn
);
3335 DestroyWindow(hwnd1
);
3338 static void test_params(void)
3343 /* Just a param check */
3344 SetLastError(0xdeadbeef);
3345 rc
= GetWindowText(hwndMain2
, NULL
, 1024);
3346 ok( rc
==0, "GetWindowText: rc=%d err=%d\n",rc
,GetLastError());
3348 SetLastError(0xdeadbeef);
3349 hwnd
=CreateWindow("LISTBOX", "TestList",
3350 (LBS_STANDARD
& ~LBS_SORT
),
3352 NULL
, (HMENU
)1, NULL
, 0);
3354 ok(!hwnd
, "CreateWindow with invalid menu handle should fail\n");
3355 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
|| /* NT */
3356 GetLastError() == 0xdeadbeef, /* Win9x */
3357 "wrong last error value %d\n", GetLastError());
3360 static void test_AWRwindow(LPCSTR
class, LONG style
, LONG exStyle
, BOOL menu
)
3364 hwnd
= CreateWindowEx(exStyle
, class, class, style
,
3371 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style
, exStyle
);
3374 ShowWindow(hwnd
, SW_SHOW
);
3376 test_nonclient_area(hwnd
);
3379 DestroyWindow(hwnd
);
3382 static BOOL
AWR_init(void)
3386 class.style
= CS_HREDRAW
| CS_VREDRAW
;
3387 class.lpfnWndProc
= DefWindowProcA
;
3388 class.cbClsExtra
= 0;
3389 class.cbWndExtra
= 0;
3390 class.hInstance
= 0;
3391 class.hIcon
= LoadIcon (0, IDI_APPLICATION
);
3392 class.hCursor
= LoadCursor (0, IDC_ARROW
);
3393 class.hbrBackground
= 0;
3394 class.lpszMenuName
= 0;
3395 class.lpszClassName
= szAWRClass
;
3397 if (!RegisterClass (&class)) {
3398 ok(FALSE
, "RegisterClass failed\n");
3402 hmenu
= CreateMenu();
3405 ok(hmenu
!= 0, "Failed to create menu\n");
3406 ok(AppendMenu(hmenu
, MF_STRING
, 1, "Test!"), "Failed to create menu item\n");
3412 static void test_AWR_window_size(BOOL menu
)
3416 WS_MAXIMIZE
, WS_BORDER
, WS_DLGFRAME
,
3419 WS_MINIMIZEBOX
, WS_MAXIMIZEBOX
,
3420 WS_HSCROLL
, WS_VSCROLL
3424 WS_EX_TOOLWINDOW
, WS_EX_WINDOWEDGE
,
3427 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3428 WS_EX_DLGMODALFRAME
,
3435 /* A exhaustive check of all the styles takes too long
3436 * so just do a (hopefully representative) sample
3438 for (i
= 0; i
< COUNTOF(styles
); ++i
)
3439 test_AWRwindow(szAWRClass
, styles
[i
], 0, menu
);
3440 for (i
= 0; i
< COUNTOF(exStyles
); ++i
) {
3441 test_AWRwindow(szAWRClass
, WS_POPUP
, exStyles
[i
], menu
);
3442 test_AWRwindow(szAWRClass
, WS_THICKFRAME
, exStyles
[i
], menu
);
3447 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3449 static void test_AdjustWindowRect(void)
3454 SHOWSYSMETRIC(SM_CYCAPTION
);
3455 SHOWSYSMETRIC(SM_CYSMCAPTION
);
3456 SHOWSYSMETRIC(SM_CYMENU
);
3457 SHOWSYSMETRIC(SM_CXEDGE
);
3458 SHOWSYSMETRIC(SM_CYEDGE
);
3459 SHOWSYSMETRIC(SM_CXVSCROLL
);
3460 SHOWSYSMETRIC(SM_CYHSCROLL
);
3461 SHOWSYSMETRIC(SM_CXFRAME
);
3462 SHOWSYSMETRIC(SM_CYFRAME
);
3463 SHOWSYSMETRIC(SM_CXDLGFRAME
);
3464 SHOWSYSMETRIC(SM_CYDLGFRAME
);
3465 SHOWSYSMETRIC(SM_CXBORDER
);
3466 SHOWSYSMETRIC(SM_CYBORDER
);
3468 test_AWR_window_size(FALSE
);
3469 test_AWR_window_size(TRUE
);
3473 #undef SHOWSYSMETRIC
3476 /* Global variables to trigger exit from loop */
3477 static int redrawComplete
, WMPAINT_count
;
3479 static LRESULT WINAPI
redraw_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3484 trace("doing WM_PAINT %d\n", WMPAINT_count
);
3486 if (WMPAINT_count
> 10 && redrawComplete
== 0) {
3488 BeginPaint(hwnd
, &ps
);
3489 EndPaint(hwnd
, &ps
);
3494 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3497 /* Ensure we exit from RedrawNow regardless of invalidated area */
3498 static void test_redrawnow(void)
3503 cls
.style
= CS_DBLCLKS
;
3504 cls
.lpfnWndProc
= redraw_window_procA
;
3507 cls
.hInstance
= GetModuleHandleA(0);
3509 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3510 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3511 cls
.lpszMenuName
= NULL
;
3512 cls
.lpszClassName
= "RedrawWindowClass";
3514 if(!RegisterClassA(&cls
)) {
3515 trace("Register failed %d\n", GetLastError());
3519 hwndMain
= CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3520 CW_USEDEFAULT
, 0, 100, 100, NULL
, NULL
, 0, NULL
);
3522 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3523 ShowWindow(hwndMain
, SW_SHOW
);
3524 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3525 RedrawWindow(hwndMain
, NULL
,NULL
,RDW_UPDATENOW
| RDW_ALLCHILDREN
);
3526 ok( WMPAINT_count
== 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3527 redrawComplete
= TRUE
;
3528 ok( WMPAINT_count
< 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count
);
3531 DestroyWindow( hwndMain
);
3534 struct parentdc_stat
{
3540 struct parentdc_test
{
3541 struct parentdc_stat main
, main_todo
;
3542 struct parentdc_stat child1
, child1_todo
;
3543 struct parentdc_stat child2
, child2_todo
;
3546 static LRESULT WINAPI
parentdc_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3551 struct parentdc_stat
*t
= (struct parentdc_stat
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
3556 trace("doing WM_PAINT on %p\n", hwnd
);
3557 GetClientRect(hwnd
, &rc
);
3558 CopyRect(&t
->client
, &rc
);
3559 trace("client rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3560 GetWindowRect(hwnd
, &rc
);
3561 trace("window rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3562 BeginPaint(hwnd
, &ps
);
3563 CopyRect(&t
->paint
, &ps
.rcPaint
);
3564 GetClipBox(ps
.hdc
, &rc
);
3565 CopyRect(&t
->clip
, &rc
);
3566 trace("clip rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3567 trace("paint rect (%d, %d)-(%d, %d)\n", ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
3568 EndPaint(hwnd
, &ps
);
3571 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3574 static void zero_parentdc_stat(struct parentdc_stat
*t
)
3576 SetRectEmpty(&t
->client
);
3577 SetRectEmpty(&t
->clip
);
3578 SetRectEmpty(&t
->paint
);
3581 static void zero_parentdc_test(struct parentdc_test
*t
)
3583 zero_parentdc_stat(&t
->main
);
3584 zero_parentdc_stat(&t
->child1
);
3585 zero_parentdc_stat(&t
->child2
);
3588 #define parentdc_field_ok(t, w, r, f, got) \
3589 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3590 ": expected %d, got %d\n", \
3593 #define parentdc_todo_field_ok(t, w, r, f, got) \
3594 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3595 else parentdc_field_ok(t, w, r, f, got)
3597 #define parentdc_rect_ok(t, w, r, got) \
3598 parentdc_todo_field_ok(t, w, r, left, got); \
3599 parentdc_todo_field_ok(t, w, r, top, got); \
3600 parentdc_todo_field_ok(t, w, r, right, got); \
3601 parentdc_todo_field_ok(t, w, r, bottom, got);
3603 #define parentdc_win_ok(t, w, got) \
3604 parentdc_rect_ok(t, w, client, got); \
3605 parentdc_rect_ok(t, w, clip, got); \
3606 parentdc_rect_ok(t, w, paint, got);
3608 #define parentdc_ok(t, got) \
3609 parentdc_win_ok(t, main, got); \
3610 parentdc_win_ok(t, child1, got); \
3611 parentdc_win_ok(t, child2, got);
3613 static void test_csparentdc(void)
3615 WNDCLASSA clsMain
, cls
;
3616 HWND hwndMain
, hwnd1
, hwnd2
;
3619 struct parentdc_test test_answer
;
3621 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3622 const struct parentdc_test test1
=
3624 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo
,
3625 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3626 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3629 const struct parentdc_test test2
=
3631 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo
,
3632 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3633 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3636 const struct parentdc_test test3
=
3638 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3639 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3640 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3643 const struct parentdc_test test4
=
3645 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo
,
3646 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo
,
3647 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3650 const struct parentdc_test test5
=
3652 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo
,
3653 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3654 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3657 const struct parentdc_test test6
=
3659 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3660 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3661 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3664 const struct parentdc_test test7
=
3666 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3667 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3668 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3672 clsMain
.style
= CS_DBLCLKS
;
3673 clsMain
.lpfnWndProc
= parentdc_window_procA
;
3674 clsMain
.cbClsExtra
= 0;
3675 clsMain
.cbWndExtra
= 0;
3676 clsMain
.hInstance
= GetModuleHandleA(0);
3678 clsMain
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3679 clsMain
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3680 clsMain
.lpszMenuName
= NULL
;
3681 clsMain
.lpszClassName
= "ParentDcMainWindowClass";
3683 if(!RegisterClassA(&clsMain
)) {
3684 trace("Register failed %d\n", GetLastError());
3688 cls
.style
= CS_DBLCLKS
| CS_PARENTDC
;
3689 cls
.lpfnWndProc
= parentdc_window_procA
;
3692 cls
.hInstance
= GetModuleHandleA(0);
3694 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3695 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3696 cls
.lpszMenuName
= NULL
;
3697 cls
.lpszClassName
= "ParentDcWindowClass";
3699 if(!RegisterClassA(&cls
)) {
3700 trace("Register failed %d\n", GetLastError());
3704 SetRect(&rc
, 0, 0, 150, 150);
3705 AdjustWindowRectEx(&rc
, WS_OVERLAPPEDWINDOW
, FALSE
, 0);
3706 hwndMain
= CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3707 CW_USEDEFAULT
, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, NULL
, NULL
, 0, NULL
);
3708 SetWindowLongPtrA(hwndMain
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.main
);
3709 hwnd1
= CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD
,
3710 20, 20, 40, 40, hwndMain
, NULL
, 0, NULL
);
3711 SetWindowLongPtrA(hwnd1
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child1
);
3712 hwnd2
= CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD
,
3713 40, 40, 40, 40, hwndMain
, NULL
, 0, NULL
);
3714 SetWindowLongPtrA(hwnd2
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child2
);
3715 ShowWindow(hwndMain
, SW_SHOW
);
3716 ShowWindow(hwnd1
, SW_SHOW
);
3717 ShowWindow(hwnd2
, SW_SHOW
);
3718 flush_events( TRUE
);
3720 zero_parentdc_test(&test_answer
);
3721 InvalidateRect(hwndMain
, NULL
, TRUE
);
3722 flush_events( TRUE
);
3723 parentdc_ok(test1
, test_answer
);
3725 zero_parentdc_test(&test_answer
);
3726 SetRect(&rc
, 0, 0, 50, 50);
3727 InvalidateRect(hwndMain
, &rc
, TRUE
);
3728 flush_events( TRUE
);
3729 parentdc_ok(test2
, test_answer
);
3731 zero_parentdc_test(&test_answer
);
3732 SetRect(&rc
, 0, 0, 10, 10);
3733 InvalidateRect(hwndMain
, &rc
, TRUE
);
3734 flush_events( TRUE
);
3735 parentdc_ok(test3
, test_answer
);
3737 zero_parentdc_test(&test_answer
);
3738 SetRect(&rc
, 40, 40, 50, 50);
3739 InvalidateRect(hwndMain
, &rc
, TRUE
);
3740 flush_events( TRUE
);
3741 parentdc_ok(test4
, test_answer
);
3743 zero_parentdc_test(&test_answer
);
3744 SetRect(&rc
, 20, 20, 60, 60);
3745 InvalidateRect(hwndMain
, &rc
, TRUE
);
3746 flush_events( TRUE
);
3747 parentdc_ok(test5
, test_answer
);
3749 zero_parentdc_test(&test_answer
);
3750 SetRect(&rc
, 0, 0, 10, 10);
3751 InvalidateRect(hwnd1
, &rc
, TRUE
);
3752 flush_events( TRUE
);
3753 parentdc_ok(test6
, test_answer
);
3755 zero_parentdc_test(&test_answer
);
3756 SetRect(&rc
, -5, -5, 65, 65);
3757 InvalidateRect(hwnd1
, &rc
, TRUE
);
3758 flush_events( TRUE
);
3759 parentdc_ok(test7
, test_answer
);
3761 DestroyWindow(hwndMain
);
3762 DestroyWindow(hwnd1
);
3763 DestroyWindow(hwnd2
);
3766 static LRESULT WINAPI
def_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3768 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
3771 static LRESULT WINAPI
def_window_procW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3773 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
3776 static void test_IsWindowUnicode(void)
3778 static const char ansi_class_nameA
[] = "ansi class name";
3779 static const WCHAR ansi_class_nameW
[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3780 static const char unicode_class_nameA
[] = "unicode class name";
3781 static const WCHAR unicode_class_nameW
[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3786 memset(&classW
, 0, sizeof(classW
));
3787 classW
.hInstance
= GetModuleHandleA(0);
3788 classW
.lpfnWndProc
= def_window_procW
;
3789 classW
.lpszClassName
= unicode_class_nameW
;
3790 if (!RegisterClassW(&classW
)) return; /* this catches Win9x as well */
3792 memset(&classA
, 0, sizeof(classA
));
3793 classA
.hInstance
= GetModuleHandleA(0);
3794 classA
.lpfnWndProc
= def_window_procA
;
3795 classA
.lpszClassName
= ansi_class_nameA
;
3796 assert(RegisterClassA(&classA
));
3798 /* unicode class: window proc */
3799 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
3800 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3803 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3804 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3805 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3806 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3807 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3809 DestroyWindow(hwnd
);
3811 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
3812 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3815 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3816 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3817 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3818 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3819 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3821 DestroyWindow(hwnd
);
3823 /* ansi class: window proc */
3824 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
3825 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3828 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3829 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3830 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3831 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3832 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3834 DestroyWindow(hwnd
);
3836 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
3837 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3840 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3841 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3842 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3843 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3844 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3846 DestroyWindow(hwnd
);
3848 /* unicode class: class proc */
3849 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
3850 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3853 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3854 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3855 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3856 /* do not restore class window proc back to unicode */
3858 DestroyWindow(hwnd
);
3860 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
3861 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3864 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3865 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3866 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3868 DestroyWindow(hwnd
);
3870 /* ansi class: class proc */
3871 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
3872 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3875 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3876 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3877 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3878 /* do not restore class window proc back to ansi */
3880 DestroyWindow(hwnd
);
3882 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
3883 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3886 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3887 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3888 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3890 DestroyWindow(hwnd
);
3893 static LRESULT CALLBACK
minmax_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
3897 if (msg
!= WM_GETMINMAXINFO
)
3898 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3900 minmax
= (MINMAXINFO
*)lp
;
3902 if ((GetWindowLong(hwnd
, GWL_STYLE
) & WS_CHILD
))
3904 minmax
->ptReserved
.x
= 0;
3905 minmax
->ptReserved
.y
= 0;
3906 minmax
->ptMaxSize
.x
= 400;
3907 minmax
->ptMaxSize
.y
= 400;
3908 minmax
->ptMaxPosition
.x
= 300;
3909 minmax
->ptMaxPosition
.y
= 300;
3910 minmax
->ptMaxTrackSize
.x
= 200;
3911 minmax
->ptMaxTrackSize
.y
= 200;
3912 minmax
->ptMinTrackSize
.x
= 100;
3913 minmax
->ptMinTrackSize
.y
= 100;
3916 DefWindowProc(hwnd
, msg
, wp
, lp
);
3920 static int expected_cx
, expected_cy
;
3921 static RECT expected_rect
, broken_rect
;
3923 static LRESULT CALLBACK
winsizes_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
3927 case WM_GETMINMAXINFO
:
3930 GetWindowRect( hwnd
, &rect
);
3931 ok( !rect
.left
&& !rect
.top
&& !rect
.right
&& !rect
.bottom
,
3932 "wrong rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3933 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3938 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
3940 GetWindowRect( hwnd
, &rect
);
3941 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
3942 hwnd
, msg
, cs
->cx
, cs
->cy
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3943 ok( cs
->cx
== expected_cx
, "wrong x size %d/%d\n", cs
->cx
, expected_cx
);
3944 ok( cs
->cy
== expected_cy
, "wrong y size %d/%d\n", cs
->cy
, expected_cy
);
3945 ok( (rect
.right
- rect
.left
== expected_rect
.right
- expected_rect
.left
&&
3946 rect
.bottom
- rect
.top
== expected_rect
.bottom
- expected_rect
.top
) ||
3947 broken( rect
.right
- rect
.left
== broken_rect
.right
- broken_rect
.left
&&
3948 rect
.bottom
- rect
.top
== broken_rect
.bottom
- broken_rect
.top
),
3949 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
3950 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
3951 expected_rect
.left
, expected_rect
.top
, expected_rect
.right
, expected_rect
.bottom
);
3952 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3956 RECT rect
, *r
= (RECT
*)lp
;
3957 GetWindowRect( hwnd
, &rect
);
3958 ok( !memcmp( &rect
, r
, sizeof(rect
) ),
3959 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
3960 r
->left
, r
->top
, r
->right
, r
->bottom
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3961 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3964 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3968 static void test_CreateWindow(void)
3976 #define expect_menu(window, menu) \
3977 SetLastError(0xdeadbeef); \
3978 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
3980 #define expect_style(window, style)\
3981 ok(GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
3983 #define expect_ex_style(window, ex_style)\
3984 ok(GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
3986 hmenu
= CreateMenu();
3988 parent
= GetDesktopWindow();
3989 assert(parent
!= 0);
3991 SetLastError(0xdeadbeef);
3992 ok(IsMenu(hmenu
), "IsMenu error %d\n", GetLastError());
3995 SetLastError(0xdeadbeef);
3996 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
,
3997 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3998 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3999 expect_menu(hwnd
, 1);
4000 expect_style(hwnd
, WS_CHILD
);
4001 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4002 DestroyWindow(hwnd
);
4004 SetLastError(0xdeadbeef);
4005 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_CAPTION
,
4006 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4007 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4008 expect_menu(hwnd
, 1);
4009 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
4010 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4011 DestroyWindow(hwnd
);
4013 SetLastError(0xdeadbeef);
4014 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
,
4015 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4016 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4017 expect_menu(hwnd
, 1);
4018 expect_style(hwnd
, WS_CHILD
);
4019 expect_ex_style(hwnd
, 0);
4020 DestroyWindow(hwnd
);
4022 SetLastError(0xdeadbeef);
4023 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_CAPTION
,
4024 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4025 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4026 expect_menu(hwnd
, 1);
4027 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
4028 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4029 DestroyWindow(hwnd
);
4032 SetLastError(0xdeadbeef);
4033 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
4034 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4035 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4036 expect_menu(hwnd
, hmenu
);
4037 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4038 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4039 DestroyWindow(hwnd
);
4040 SetLastError(0xdeadbeef);
4041 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4042 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4044 hmenu
= CreateMenu();
4046 SetLastError(0xdeadbeef);
4047 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4048 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4049 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4050 expect_menu(hwnd
, hmenu
);
4051 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4052 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4053 DestroyWindow(hwnd
);
4054 SetLastError(0xdeadbeef);
4055 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4056 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4058 hmenu
= CreateMenu();
4060 SetLastError(0xdeadbeef);
4061 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
,
4062 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4063 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4064 expect_menu(hwnd
, hmenu
);
4065 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4066 expect_ex_style(hwnd
, 0);
4067 DestroyWindow(hwnd
);
4068 SetLastError(0xdeadbeef);
4069 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4070 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4072 hmenu
= CreateMenu();
4074 SetLastError(0xdeadbeef);
4075 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4076 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4077 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4078 expect_menu(hwnd
, hmenu
);
4079 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4080 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4081 DestroyWindow(hwnd
);
4082 SetLastError(0xdeadbeef);
4083 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4084 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4086 /* WS_CHILD | WS_POPUP */
4087 SetLastError(0xdeadbeef);
4088 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4089 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4090 ok(!hwnd
, "CreateWindowEx should fail\n");
4091 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4093 hmenu
= CreateMenu();
4095 SetLastError(0xdeadbeef);
4096 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4097 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4098 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4099 expect_menu(hwnd
, hmenu
);
4100 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4101 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4102 DestroyWindow(hwnd
);
4103 SetLastError(0xdeadbeef);
4104 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4105 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4107 SetLastError(0xdeadbeef);
4108 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4109 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4110 ok(!hwnd
, "CreateWindowEx should fail\n");
4111 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4113 hmenu
= CreateMenu();
4115 SetLastError(0xdeadbeef);
4116 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4117 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4118 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4119 expect_menu(hwnd
, hmenu
);
4120 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4121 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4122 DestroyWindow(hwnd
);
4123 SetLastError(0xdeadbeef);
4124 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4125 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4127 SetLastError(0xdeadbeef);
4128 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4129 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4130 ok(!hwnd
, "CreateWindowEx should fail\n");
4131 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4133 hmenu
= CreateMenu();
4135 SetLastError(0xdeadbeef);
4136 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4137 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4138 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4139 expect_menu(hwnd
, hmenu
);
4140 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4141 expect_ex_style(hwnd
, 0);
4142 DestroyWindow(hwnd
);
4143 SetLastError(0xdeadbeef);
4144 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4145 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4147 SetLastError(0xdeadbeef);
4148 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4149 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4150 ok(!hwnd
, "CreateWindowEx should fail\n");
4151 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4153 hmenu
= CreateMenu();
4155 SetLastError(0xdeadbeef);
4156 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4157 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4158 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4159 expect_menu(hwnd
, hmenu
);
4160 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4161 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4162 DestroyWindow(hwnd
);
4163 SetLastError(0xdeadbeef);
4164 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4165 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4167 /* test child window sizing */
4169 cls
.lpfnWndProc
= minmax_wnd_proc
;
4172 cls
.hInstance
= GetModuleHandle(0);
4174 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
4175 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4176 cls
.lpszMenuName
= NULL
;
4177 cls
.lpszClassName
= "MinMax_WndClass";
4178 RegisterClass(&cls
);
4180 SetLastError(0xdeadbeef);
4181 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4182 0, 0, 100, 100, 0, 0, 0, NULL
);
4183 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
4184 expect_menu(parent
, 0);
4185 expect_style(parent
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
| WS_CLIPSIBLINGS
);
4186 expect_ex_style(parent
, WS_EX_WINDOWEDGE
);
4188 memset(&minmax
, 0, sizeof(minmax
));
4189 SendMessage(parent
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4190 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxSize
.x
, minmax
.ptMaxSize
.y
);
4191 ok(IsRectEmpty(&rc_minmax
), "ptMaxSize is not empty\n");
4192 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4193 ok(IsRectEmpty(&rc_minmax
), "ptMaxTrackSize is not empty\n");
4195 GetWindowRect(parent
, &rc
);
4196 ok(!IsRectEmpty(&rc
), "parent window rect is empty\n");
4197 GetClientRect(parent
, &rc
);
4198 ok(!IsRectEmpty(&rc
), "parent client rect is empty\n");
4200 InflateRect(&rc
, 200, 200);
4201 trace("creating child with rect (%d,%d-%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4203 SetLastError(0xdeadbeef);
4204 hwnd
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4205 rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
4206 parent
, (HMENU
)1, 0, NULL
);
4207 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4208 expect_menu(hwnd
, 1);
4209 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
);
4210 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4212 memset(&minmax
, 0, sizeof(minmax
));
4213 SendMessage(hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4214 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4216 GetWindowRect(hwnd
, &rc
);
4217 OffsetRect(&rc
, -rc
.left
, -rc
.top
);
4218 ok(EqualRect(&rc
, &rc_minmax
), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4219 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
4220 rc_minmax
.left
, rc_minmax
.top
, rc_minmax
.right
, rc_minmax
.bottom
);
4221 DestroyWindow(hwnd
);
4223 cls
.lpfnWndProc
= winsizes_wnd_proc
;
4224 cls
.lpszClassName
= "Sizes_WndClass";
4225 RegisterClass(&cls
);
4227 expected_cx
= expected_cy
= 200000;
4228 SetRect( &expected_rect
, 0, 0, 200000, 200000 );
4229 broken_rect
= expected_rect
;
4230 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 300000, 300000, 200000, 200000, parent
, 0, 0, NULL
);
4231 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4232 GetClientRect( hwnd
, &rc
);
4233 ok( rc
.right
== 200000, "invalid rect right %u\n", rc
.right
);
4234 ok( rc
.bottom
== 200000, "invalid rect bottom %u\n", rc
.bottom
);
4235 DestroyWindow(hwnd
);
4237 expected_cx
= expected_cy
= -10;
4238 SetRect( &expected_rect
, 0, 0, 0, 0 );
4239 broken_rect
= expected_rect
;
4240 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -20, -20, -10, -10, parent
, 0, 0, NULL
);
4241 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4242 GetClientRect( hwnd
, &rc
);
4243 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4244 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4245 DestroyWindow(hwnd
);
4247 expected_cx
= expected_cy
= -200000;
4248 SetRect( &expected_rect
, 0, 0, 0, 0 );
4249 broken_rect
= expected_rect
;
4250 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -300000, -300000, -200000, -200000, parent
, 0, 0, NULL
);
4251 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4252 GetClientRect( hwnd
, &rc
);
4253 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4254 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4255 DestroyWindow(hwnd
);
4257 /* we need a parent at 0,0 so that child coordinates match */
4258 DestroyWindow(parent
);
4259 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_POPUP
, 0, 0, 100, 100, 0, 0, 0, NULL
);
4260 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
4263 expected_cy
= 0x7fffffff;
4264 SetRect( &expected_rect
, 10, 10, 110, 0x7fffffff );
4265 SetRect( &broken_rect
, 10, 10, 110, 0x7fffffffU
+ 10 );
4266 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 10, 10, 100, 0x7fffffff, parent
, 0, 0, NULL
);
4267 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4268 GetClientRect( hwnd
, &rc
);
4269 ok( rc
.right
== 100, "invalid rect right %u\n", rc
.right
);
4270 ok( rc
.bottom
== 0x7fffffff - 10 || broken(rc
.bottom
== 0), "invalid rect bottom %u\n", rc
.bottom
);
4271 DestroyWindow(hwnd
);
4273 expected_cx
= 0x7fffffff;
4274 expected_cy
= 0x7fffffff;
4275 SetRect( &expected_rect
, 20, 10, 0x7fffffff, 0x7fffffff );
4276 SetRect( &broken_rect
, 20, 10, 0x7fffffffU
+ 20, 0x7fffffffU
+ 10 );
4277 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 20, 10, 0x7fffffff, 0x7fffffff, parent
, 0, 0, NULL
);
4278 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4279 GetClientRect( hwnd
, &rc
);
4280 ok( rc
.right
== 0x7fffffff - 20 || broken(rc
.right
== 0), "invalid rect right %u\n", rc
.right
);
4281 ok( rc
.bottom
== 0x7fffffff - 10 || broken(rc
.bottom
== 0), "invalid rect bottom %u\n", rc
.bottom
);
4282 DestroyWindow(hwnd
);
4284 /* top level window */
4285 expected_cx
= expected_cy
= 200000;
4286 SetRect( &expected_rect
, 0, 0, GetSystemMetrics(SM_CXMAXTRACK
), GetSystemMetrics(SM_CYMAXTRACK
) );
4287 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_OVERLAPPEDWINDOW
, 300000, 300000, 200000, 200000, 0, 0, 0, NULL
);
4288 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4289 GetClientRect( hwnd
, &rc
);
4290 ok( rc
.right
<= expected_cx
, "invalid rect right %u\n", rc
.right
);
4291 ok( rc
.bottom
<= expected_cy
, "invalid rect bottom %u\n", rc
.bottom
);
4292 DestroyWindow(hwnd
);
4294 DestroyWindow(parent
);
4296 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4297 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4301 #undef expect_ex_style
4304 /* function that remembers whether the system the test is running on sets the
4305 * last error for user32 functions to make the tests stricter */
4306 static int check_error(DWORD actual
, DWORD expected
)
4308 static int sets_last_error
= -1;
4309 if (sets_last_error
== -1)
4310 sets_last_error
= (actual
!= 0xdeadbeef);
4311 return (!sets_last_error
&& (actual
== 0xdeadbeef)) || (actual
== expected
);
4314 static void test_SetWindowLong(void)
4317 WNDPROC old_window_procW
;
4319 SetLastError(0xdeadbeef);
4320 retval
= SetWindowLongPtr(NULL
, GWLP_WNDPROC
, 0);
4321 ok(!retval
, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval
);
4322 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE
),
4323 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4325 SetLastError(0xdeadbeef);
4326 retval
= SetWindowLongPtr(hwndMain
, 0xdeadbeef, 0);
4327 ok(!retval
, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval
);
4328 ok(check_error(GetLastError(), ERROR_INVALID_INDEX
),
4329 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4331 SetLastError(0xdeadbeef);
4332 retval
= SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4333 ok((WNDPROC
)retval
== main_window_procA
,
4334 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval
);
4335 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4336 retval
= GetWindowLongPtr(hwndMain
, GWLP_WNDPROC
);
4337 ok((WNDPROC
)retval
== main_window_procA
,
4338 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4339 ok(!IsWindowUnicode(hwndMain
), "hwndMain shouldn't be Unicode\n");
4341 old_window_procW
= (WNDPROC
)GetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
);
4342 SetLastError(0xdeadbeef);
4343 retval
= SetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
, 0);
4344 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED
)
4346 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4347 ok(retval
!= 0, "SetWindowLongPtr error %d\n", GetLastError());
4348 ok((WNDPROC
)retval
== old_window_procW
,
4349 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4350 ok(IsWindowUnicode(hwndMain
), "hwndMain should now be Unicode\n");
4352 /* set it back to ANSI */
4353 SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4357 static void test_ShowWindow(void)
4364 SetRect(&rcMain
, 120, 120, 210, 210);
4366 hwnd
= CreateWindowEx(0, "MainWindowClass", NULL
,
4367 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4368 WS_MAXIMIZEBOX
| WS_POPUP
,
4369 rcMain
.left
, rcMain
.top
,
4370 rcMain
.right
- rcMain
.left
, rcMain
.bottom
- rcMain
.top
,
4374 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4375 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4376 ok(!(style
& WS_VISIBLE
), "window should not be visible\n");
4377 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4378 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4379 GetWindowRect(hwnd
, &rc
);
4380 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4381 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4382 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4384 ret
= ShowWindow(hwnd
, SW_SHOW
);
4385 ok(!ret
, "not expected ret: %lu\n", ret
);
4386 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4387 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4388 ok(style
& WS_VISIBLE
, "window should be visible\n");
4389 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4390 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4391 GetWindowRect(hwnd
, &rc
);
4392 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4393 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4394 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4396 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4397 ok(ret
, "not expected ret: %lu\n", ret
);
4398 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4399 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4400 ok(style
& WS_VISIBLE
, "window should be visible\n");
4401 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4402 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4403 GetWindowRect(hwnd
, &rc
);
4404 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4406 ShowWindow(hwnd
, SW_RESTORE
);
4407 ok(ret
, "not expected ret: %lu\n", ret
);
4408 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4409 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4410 ok(style
& WS_VISIBLE
, "window should be visible\n");
4411 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4412 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4413 GetWindowRect(hwnd
, &rc
);
4414 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4415 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4416 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4418 ret
= EnableWindow(hwnd
, FALSE
);
4419 ok(!ret
, "not expected ret: %lu\n", ret
);
4420 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4421 ok(style
& WS_DISABLED
, "window should be disabled\n");
4423 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
4424 ok(!ret
, "not expected ret: %lu\n", ret
);
4425 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4426 ok(style
& WS_DISABLED
, "window should be disabled\n");
4427 ok(style
& WS_VISIBLE
, "window should be visible\n");
4428 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4429 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4430 GetWindowRect(hwnd
, &rc
);
4431 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4432 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4433 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4435 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
4436 ok(!ret
, "not expected ret: %lu\n", ret
);
4437 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4438 ok(style
& WS_DISABLED
, "window should be disabled\n");
4439 ok(style
& WS_VISIBLE
, "window should be visible\n");
4440 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4441 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4442 GetWindowRect(hwnd
, &rc
);
4443 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4444 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4445 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4447 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4448 ok(ret
, "not expected ret: %lu\n", ret
);
4449 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4450 ok(style
& WS_DISABLED
, "window should be disabled\n");
4451 ok(style
& WS_VISIBLE
, "window should be visible\n");
4452 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4453 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4454 GetWindowRect(hwnd
, &rc
);
4455 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4457 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
4458 ok(!ret
, "not expected ret: %lu\n", ret
);
4459 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4460 ok(style
& WS_DISABLED
, "window should be disabled\n");
4461 ok(style
& WS_VISIBLE
, "window should be visible\n");
4462 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4463 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4464 GetWindowRect(hwnd
, &rc
);
4465 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4467 ret
= ShowWindow(hwnd
, SW_RESTORE
);
4468 ok(ret
, "not expected ret: %lu\n", ret
);
4469 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4470 ok(style
& WS_DISABLED
, "window should be disabled\n");
4471 ok(style
& WS_VISIBLE
, "window should be visible\n");
4472 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4473 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4474 GetWindowRect(hwnd
, &rc
);
4475 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4476 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4477 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4479 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4480 ok(!ret
, "not expected ret: %lu\n", ret
);
4481 ok(IsWindow(hwnd
), "window should exist\n");
4483 ret
= EnableWindow(hwnd
, TRUE
);
4484 ok(ret
, "not expected ret: %lu\n", ret
);
4486 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4487 ok(!ret
, "not expected ret: %lu\n", ret
);
4488 ok(!IsWindow(hwnd
), "window should not exist\n");
4491 static void test_gettext(void)
4494 LPCSTR clsname
= "gettexttest";
4498 memset( &cls
, 0, sizeof cls
);
4499 cls
.lpfnWndProc
= DefWindowProc
;
4500 cls
.lpszClassName
= clsname
;
4501 cls
.hInstance
= GetModuleHandle(NULL
);
4503 if (!RegisterClass( &cls
)) return;
4505 hwnd
= CreateWindow( clsname
, "test text", WS_OVERLAPPED
, 0, 0, 10, 10, 0, NULL
, NULL
, NULL
);
4506 ok( hwnd
!= NULL
, "window was null\n");
4508 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10, 0x1000);
4509 ok( r
== 0, "settext should return zero\n");
4511 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10000, 0);
4512 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4514 r
= SendMessage( hwnd
, WM_GETTEXT
, 0xff000000, 0x1000);
4515 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4517 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x1000, 0xff000000);
4518 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4520 DestroyWindow(hwnd
);
4521 UnregisterClass( clsname
, NULL
);
4525 static void test_GetUpdateRect(void)
4528 BOOL ret
, parent_wm_paint
, grandparent_wm_paint
;
4530 HWND hgrandparent
, hparent
, hchild
;
4532 static const char classNameA
[] = "GetUpdateRectClass";
4534 hgrandparent
= CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW
,
4535 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4537 hparent
= CreateWindowA("static", "parent", WS_CHILD
|WS_VISIBLE
,
4538 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4540 hchild
= CreateWindowA("static", "child", WS_CHILD
|WS_VISIBLE
,
4541 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4543 ShowWindow(hgrandparent
, SW_SHOW
);
4544 UpdateWindow(hgrandparent
);
4545 flush_events( TRUE
);
4547 ShowWindow(hchild
, SW_HIDE
);
4548 SetRect(&rc2
, 0, 0, 0, 0);
4549 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4550 ok(!ret
, "GetUpdateRect returned not empty region\n");
4551 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4552 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4553 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4555 SetRect(&rc2
, 10, 10, 40, 40);
4556 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
4557 ok(ret
, "GetUpdateRect returned empty region\n");
4558 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4559 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4560 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4562 parent_wm_paint
= FALSE
;
4563 grandparent_wm_paint
= FALSE
;
4564 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
4566 if (msg
.message
== WM_PAINT
)
4568 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
4569 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
4571 DispatchMessage(&msg
);
4573 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
4574 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
4576 DestroyWindow(hgrandparent
);
4579 cls
.lpfnWndProc
= DefWindowProcA
;
4582 cls
.hInstance
= GetModuleHandleA(0);
4584 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
4585 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4586 cls
.lpszMenuName
= NULL
;
4587 cls
.lpszClassName
= classNameA
;
4589 if(!RegisterClassA(&cls
)) {
4590 trace("Register failed %d\n", GetLastError());
4594 hgrandparent
= CreateWindowA(classNameA
, "grandparent", WS_OVERLAPPEDWINDOW
,
4595 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4597 hparent
= CreateWindowA(classNameA
, "parent", WS_CHILD
|WS_VISIBLE
,
4598 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4600 hchild
= CreateWindowA(classNameA
, "child", WS_CHILD
|WS_VISIBLE
,
4601 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4603 ShowWindow(hgrandparent
, SW_SHOW
);
4604 UpdateWindow(hgrandparent
);
4605 flush_events( TRUE
);
4607 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4608 ok(!ret
, "GetUpdateRect returned not empty region\n");
4610 ShowWindow(hchild
, SW_HIDE
);
4612 SetRect(&rc2
, 0, 0, 0, 0);
4613 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4614 ok(!ret
, "GetUpdateRect returned not empty region\n");
4615 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4616 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4617 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4619 SetRect(&rc2
, 10, 10, 40, 40);
4620 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
4621 ok(ret
, "GetUpdateRect returned empty region\n");
4622 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4623 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4624 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4626 parent_wm_paint
= FALSE
;
4627 grandparent_wm_paint
= FALSE
;
4628 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
4630 if (msg
.message
== WM_PAINT
)
4632 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
4633 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
4635 DispatchMessage(&msg
);
4637 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
4638 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
4640 DestroyWindow(hgrandparent
);
4644 static LRESULT CALLBACK
TestExposedRegion_WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4652 const int waitTime
= 2000;
4654 BeginPaint(hwnd
, &ps
);
4656 /* create and destroy window to create an exposed region on this window */
4657 win
= CreateWindowA("static", "win", WS_VISIBLE
,
4658 10,10,50,50, NULL
, NULL
, 0, NULL
);
4661 waitResult
= MsgWaitForMultipleObjects( 0, NULL
, FALSE
, waitTime
, QS_PAINT
);
4663 ValidateRect(hwnd
, NULL
);
4664 EndPaint(hwnd
, &ps
);
4666 if(waitResult
!= WAIT_TIMEOUT
)
4668 GetUpdateRect(hwnd
, &updateRect
, FALSE
);
4669 ok(IsRectEmpty(&updateRect
), "Exposed rect should be empty\n");
4674 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
4677 static void test_Expose(void)
4682 memset(&cls
, 0, sizeof(WNDCLASSA
));
4683 cls
.lpfnWndProc
= TestExposedRegion_WndProc
;
4684 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4685 cls
.lpszClassName
= "TestExposeClass";
4686 atom
= RegisterClassA(&cls
);
4688 mw
= CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE
|WS_OVERLAPPEDWINDOW
,
4689 0, 0, 200, 100, NULL
, NULL
, 0, NULL
);
4695 static void test_GetWindowModuleFileName(void)
4700 char buf1
[MAX_PATH
], buf2
[MAX_PATH
];
4702 if (!pGetWindowModuleFileNameA
)
4704 skip("GetWindowModuleFileNameA is not available\n");
4708 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0,0,0,0, 0, 0, 0, NULL
);
4711 hinst
= (HINSTANCE
)GetWindowLongPtr(hwnd
, GWLP_HINSTANCE
);
4712 ok(hinst
== 0, "expected 0, got %p\n", hinst
);
4715 SetLastError(0xdeadbeef);
4716 ret1
= GetModuleFileName(hinst
, buf1
, sizeof(buf1
));
4717 ok(ret1
, "GetModuleFileName error %u\n", GetLastError());
4720 SetLastError(0xdeadbeef);
4721 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, sizeof(buf2
));
4722 ok(ret2
, "GetWindowModuleFileNameA error %u\n", GetLastError());
4724 ok(ret1
== ret2
, "%u != %u\n", ret1
, ret2
);
4725 ok(!strcmp(buf1
, buf2
), "%s != %s\n", buf1
, buf2
);
4727 hinst
= GetModuleHandle(0);
4729 SetLastError(0xdeadbeef);
4730 ret2
= GetModuleFileName(hinst
, buf2
, ret1
- 2);
4731 ok(ret2
== ret1
- 2, "expected %u, got %u\n", ret1
- 2, ret2
);
4732 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4733 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
4734 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4736 SetLastError(0xdeadbeef);
4737 ret2
= GetModuleFileName(hinst
, buf2
, 0);
4738 ok(!ret2
, "GetModuleFileName should return 0\n");
4739 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4740 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
4741 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4743 SetLastError(0xdeadbeef);
4744 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, ret1
- 2);
4745 ok(ret2
== ret1
- 2, "expected %u, got %u\n", ret1
- 2, ret2
);
4746 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4747 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
4748 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4750 SetLastError(0xdeadbeef);
4751 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, 0);
4752 ok(!ret2
, "expected 0, got %u\n", ret2
);
4753 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4754 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
4755 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4757 DestroyWindow(hwnd
);
4760 hwnd
= (HWND
)0xdeadbeef;
4761 SetLastError(0xdeadbeef);
4762 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
4763 ok(!ret1
, "expected 0, got %u\n", ret1
);
4764 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
4766 ret1
= GetModuleFileName(0, buf1
, sizeof(buf1
));
4767 hwnd
= GetDesktopWindow();
4768 ok(IsWindow(hwnd
), "got invalid desktop window %p\n", hwnd
);
4769 SetLastError(0xdeadbeef);
4770 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, sizeof(buf2
));
4771 ok(!ret2
|| ret1
== ret2
/* vista */, "expected 0, got %u\n", ret2
);
4773 hwnd
= FindWindow("Shell_TrayWnd", NULL
);
4774 ok(IsWindow(hwnd
), "got invalid tray window %p\n", hwnd
);
4775 SetLastError(0xdeadbeef);
4776 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
4777 ok(!ret1
, "expected 0, got %u\n", ret1
);
4780 static void test_hwnd_message(void)
4782 static const WCHAR mainwindowclassW
[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
4783 static const WCHAR message_windowW
[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
4785 HWND parent
= 0, hwnd
, found
;
4788 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
4789 on CreateWindowExA and crash later in the test.
4790 Use UNICODE here to fail on win9x */
4791 hwnd
= CreateWindowExW(0, mainwindowclassW
, message_windowW
, WS_CAPTION
| WS_VISIBLE
,
4792 100, 100, 200, 200, HWND_MESSAGE
, 0, 0, NULL
);
4795 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
4799 ok( !GetParent(hwnd
), "GetParent should return 0 for message only windows\n" );
4803 HWND root
, desktop
= GetDesktopWindow();
4805 parent
= pGetAncestor(hwnd
, GA_PARENT
);
4806 ok(parent
!= 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
4807 ok(parent
!= desktop
, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
4808 root
= pGetAncestor(hwnd
, GA_ROOT
);
4809 ok(root
== hwnd
, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
4810 ok( !pGetAncestor(parent
, GA_PARENT
), "parent shouldn't have a parent\n" );
4811 trace("parent %p root %p desktop %p\n", parent
, root
, desktop
);
4812 if (!GetClassNameA( parent
, buffer
, sizeof(buffer
) )) buffer
[0] = 0;
4813 ok( !lstrcmpi( buffer
, "Message" ), "wrong parent class '%s'\n", buffer
);
4814 GetWindowRect( parent
, &rect
);
4815 ok( rect
.left
== 0 && rect
.right
== 100 && rect
.top
== 0 && rect
.bottom
== 100,
4816 "wrong parent rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4818 GetWindowRect( hwnd
, &rect
);
4819 ok( rect
.left
== 100 && rect
.right
== 300 && rect
.top
== 100 && rect
.bottom
== 300,
4820 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4822 /* test FindWindow behavior */
4824 found
= FindWindowExA( 0, 0, 0, "message window" );
4825 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
4826 SetLastError(0xdeadbeef);
4827 found
= FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
4828 ok( found
== 0, "found message window %p/%p\n", found
, hwnd
);
4829 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
4832 found
= FindWindowExA( parent
, 0, 0, "message window" );
4833 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
4836 /* test IsChild behavior */
4838 if (parent
) ok( !IsChild( parent
, hwnd
), "HWND_MESSAGE is child of top window\n" );
4840 /* test IsWindowVisible behavior */
4842 ok( !IsWindowVisible( hwnd
), "HWND_MESSAGE window is visible\n" );
4843 if (parent
) ok( !IsWindowVisible( parent
), "HWND_MESSAGE parent is visible\n" );
4845 DestroyWindow(hwnd
);
4848 static void test_layered_window(void)
4856 if (!pGetLayeredWindowAttributes
|| !pSetLayeredWindowAttributes
)
4858 win_skip( "layered windows not supported\n" );
4861 hwnd
= CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION
,
4862 100, 100, 200, 200, 0, 0, 0, NULL
);
4864 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
4865 ok( !ret
, "GetLayeredWindowAttributes should fail on non-layered window\n" );
4866 ret
= pSetLayeredWindowAttributes( hwnd
, 0, 0, LWA_ALPHA
);
4867 ok( !ret
, "SetLayeredWindowAttributes should fail on non-layered window\n" );
4868 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
4869 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
4870 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
4871 ret
= pSetLayeredWindowAttributes( hwnd
, 0x123456, 44, LWA_ALPHA
);
4872 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
4873 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
4874 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
4875 ok( key
== 0x123456, "wrong color key %x\n", key
);
4876 ok( alpha
== 44, "wrong alpha %u\n", alpha
);
4877 ok( flags
== LWA_ALPHA
, "wrong flags %x\n", flags
);
4879 /* clearing WS_EX_LAYERED resets attributes */
4880 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
4881 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
4882 ok( !ret
, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
4883 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
4884 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
4885 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
4886 ret
= pSetLayeredWindowAttributes( hwnd
, 0x654321, 22, LWA_COLORKEY
| LWA_ALPHA
);
4887 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
4888 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
4889 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
4890 ok( key
== 0x654321, "wrong color key %x\n", key
);
4891 ok( alpha
== 22, "wrong alpha %u\n", alpha
);
4892 ok( flags
== (LWA_COLORKEY
| LWA_ALPHA
), "wrong flags %x\n", flags
);
4894 ret
= pSetLayeredWindowAttributes( hwnd
, 0x888888, 33, LWA_COLORKEY
);
4895 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
4897 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
4898 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
4899 ok( key
== 0x888888, "wrong color key %x\n", key
);
4900 /* alpha not changed on vista if LWA_ALPHA is not set */
4901 ok( alpha
== 22 || alpha
== 33, "wrong alpha %u\n", alpha
);
4902 ok( flags
== LWA_COLORKEY
, "wrong flags %x\n", flags
);
4904 /* color key always changed */
4905 ret
= pSetLayeredWindowAttributes( hwnd
, 0x999999, 44, 0 );
4906 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
4908 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
4909 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
4910 ok( key
== 0x999999, "wrong color key %x\n", key
);
4911 ok( alpha
== 22 || alpha
== 44, "wrong alpha %u\n", alpha
);
4912 ok( flags
== 0, "wrong flags %x\n", flags
);
4914 /* default alpha is 0 */
4915 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
4916 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
4917 ret
= pSetLayeredWindowAttributes( hwnd
, 0x222222, 55, 0 );
4918 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
4919 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
4920 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
4921 ok( key
== 0x222222, "wrong color key %x\n", key
);
4922 ok( alpha
== 0 || alpha
== 55, "wrong alpha %u\n", alpha
);
4923 ok( flags
== 0, "wrong flags %x\n", flags
);
4925 DestroyWindow( hwnd
);
4928 static MONITORINFO mi
;
4930 static LRESULT CALLBACK
fullscreen_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
4936 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
4937 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
4938 ok(cs
->x
== mi
.rcMonitor
.left
&& cs
->y
== mi
.rcMonitor
.top
&&
4939 cs
->cx
== mi
.rcMonitor
.right
&& cs
->cy
== mi
.rcMonitor
.bottom
,
4940 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
4941 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
4942 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
4945 case WM_GETMINMAXINFO
:
4947 MINMAXINFO
*minmax
= (MINMAXINFO
*)lp
;
4948 dump_minmax_info(minmax
);
4949 ok(minmax
->ptMaxPosition
.x
<= mi
.rcMonitor
.left
, "%d <= %d\n", minmax
->ptMaxPosition
.x
, mi
.rcMonitor
.left
);
4950 ok(minmax
->ptMaxPosition
.y
<= mi
.rcMonitor
.top
, "%d <= %d\n", minmax
->ptMaxPosition
.y
, mi
.rcMonitor
.top
);
4951 ok(minmax
->ptMaxSize
.x
>= mi
.rcMonitor
.right
, "%d >= %d\n", minmax
->ptMaxSize
.x
, mi
.rcMonitor
.right
);
4952 ok(minmax
->ptMaxSize
.y
>= mi
.rcMonitor
.bottom
, "%d >= %d\n", minmax
->ptMaxSize
.y
, mi
.rcMonitor
.bottom
);
4956 return DefWindowProc(hwnd
, msg
, wp
, lp
);
4959 static void test_fullscreen(void)
4961 static const DWORD t_style
[] = {
4962 WS_OVERLAPPED
, WS_POPUP
, WS_CHILD
, WS_THICKFRAME
, WS_DLGFRAME
4964 static const DWORD t_ex_style
[] = {
4965 0, WS_EX_APPWINDOW
, WS_EX_TOOLWINDOW
4975 if (!pGetMonitorInfoA
|| !pMonitorFromPoint
)
4977 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
4982 SetLastError(0xdeadbeef);
4983 hmon
= pMonitorFromPoint(pt
, MONITOR_DEFAULTTOPRIMARY
);
4984 ok(hmon
!= 0, "MonitorFromPoint error %u\n", GetLastError());
4986 mi
.cbSize
= sizeof(mi
);
4987 SetLastError(0xdeadbeef);
4988 ret
= pGetMonitorInfoA(hmon
, &mi
);
4989 ok(ret
, "GetMonitorInfo error %u\n", GetLastError());
4990 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
4991 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
4992 mi
.rcWork
.left
, mi
.rcWork
.top
, mi
.rcWork
.right
, mi
.rcWork
.bottom
);
4995 cls
.lpfnWndProc
= fullscreen_wnd_proc
;
4998 cls
.hInstance
= GetModuleHandle(0);
5000 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
5001 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5002 cls
.lpszMenuName
= NULL
;
5003 cls
.lpszClassName
= "fullscreen_class";
5004 RegisterClass(&cls
);
5006 for (i
= 0; i
< sizeof(t_style
)/sizeof(t_style
[0]); i
++)
5008 DWORD style
, ex_style
;
5010 /* avoid a WM interaction */
5011 assert(!(t_style
[i
] & WS_VISIBLE
));
5013 for (j
= 0; j
< sizeof(t_ex_style
)/sizeof(t_ex_style
[0]); j
++)
5018 ex_style
= t_ex_style
[j
];
5020 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5021 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5022 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5023 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5024 GetWindowRect(hwnd
, &rc
);
5025 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5026 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5027 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5028 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5029 DestroyWindow(hwnd
);
5031 style
= t_style
[i
] | WS_MAXIMIZE
;
5032 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5033 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5034 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5035 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5036 GetWindowRect(hwnd
, &rc
);
5037 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5038 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5039 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5040 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5041 DestroyWindow(hwnd
);
5043 style
= t_style
[i
] | WS_MAXIMIZE
| WS_CAPTION
;
5044 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5045 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5046 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5047 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5048 GetWindowRect(hwnd
, &rc
);
5049 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5050 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5051 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5052 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5053 DestroyWindow(hwnd
);
5055 style
= t_style
[i
] | WS_CAPTION
| WS_MAXIMIZEBOX
;
5056 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5057 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5058 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5059 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5060 GetWindowRect(hwnd
, &rc
);
5061 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5062 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5063 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5064 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5065 DestroyWindow(hwnd
);
5067 style
= t_style
[i
] | WS_MAXIMIZE
| WS_CAPTION
| WS_MAXIMIZEBOX
;
5068 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5069 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5070 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5071 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5072 GetWindowRect(hwnd
, &rc
);
5073 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5074 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5075 fixup
= min(abs(rc
.left
), abs(rc
.top
));
5076 InflateRect(&rc
, -fixup
, -fixup
);
5077 /* FIXME: this doesn't work correctly in Wine for child windows yet */
5078 if (style
& WS_CHILD
)
5080 ok(rc
.left
>= mi
.rcWork
.left
&& rc
.top
<= mi
.rcWork
.top
&&
5081 rc
.right
<= mi
.rcWork
.right
&& rc
.bottom
<= mi
.rcWork
.bottom
,
5082 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5084 ok(rc
.left
>= mi
.rcWork
.left
&& rc
.top
<= mi
.rcWork
.top
&&
5085 rc
.right
<= mi
.rcWork
.right
&& rc
.bottom
<= mi
.rcWork
.bottom
,
5086 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5087 DestroyWindow(hwnd
);
5089 style
= t_style
[i
] | WS_MAXIMIZE
| WS_MAXIMIZEBOX
;
5090 hwnd
= CreateWindowExA(ex_style
, "fullscreen_class", NULL
, style
,
5091 mi
.rcMonitor
.left
, mi
.rcMonitor
.top
, mi
.rcMonitor
.right
, mi
.rcMonitor
.bottom
,
5092 GetDesktopWindow(), 0, GetModuleHandle(0), NULL
);
5093 ok(hwnd
!= 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i
, ex_style
, style
);
5094 GetWindowRect(hwnd
, &rc
);
5095 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5096 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5097 fixup
= min(abs(rc
.left
), abs(rc
.top
));
5098 InflateRect(&rc
, -fixup
, -fixup
);
5099 if (style
& (WS_CHILD
| WS_POPUP
))
5100 ok(rc
.left
<= mi
.rcMonitor
.left
&& rc
.top
<= mi
.rcMonitor
.top
&&
5101 rc
.right
>= mi
.rcMonitor
.right
&& rc
.bottom
>= mi
.rcMonitor
.bottom
,
5102 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5104 ok(rc
.left
>= mi
.rcWork
.left
&& rc
.top
<= mi
.rcWork
.top
&&
5105 rc
.right
<= mi
.rcWork
.right
&& rc
.bottom
<= mi
.rcWork
.bottom
,
5106 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style
, style
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5107 DestroyWindow(hwnd
);
5111 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5116 HMODULE user32
= GetModuleHandleA( "user32.dll" );
5117 pGetAncestor
= (void *)GetProcAddress( user32
, "GetAncestor" );
5118 pGetWindowInfo
= (void *)GetProcAddress( user32
, "GetWindowInfo" );
5119 pGetWindowModuleFileNameA
= (void *)GetProcAddress( user32
, "GetWindowModuleFileNameA" );
5120 pGetLayeredWindowAttributes
= (void *)GetProcAddress( user32
, "GetLayeredWindowAttributes" );
5121 pSetLayeredWindowAttributes
= (void *)GetProcAddress( user32
, "SetLayeredWindowAttributes" );
5122 pGetMonitorInfoA
= (void *)GetProcAddress( user32
, "GetMonitorInfoA" );
5123 pMonitorFromPoint
= (void *)GetProcAddress( user32
, "MonitorFromPoint" );
5125 if (!RegisterWindowClasses()) assert(0);
5127 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
5130 hwndMain
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
5131 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
5132 WS_MAXIMIZEBOX
| WS_POPUP
,
5134 0, 0, GetModuleHandle(0), NULL
);
5135 hwndMain2
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
5136 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
5137 WS_MAXIMIZEBOX
| WS_POPUP
,
5139 0, 0, GetModuleHandle(0), NULL
);
5141 assert( hwndMain2
);
5143 our_pid
= GetWindowThreadProcessId(hwndMain
, NULL
);
5145 /* Add the tests below this line */
5147 test_hwnd_message();
5148 test_nonclient_area(hwndMain
);
5150 test_GetWindowModuleFileName();
5153 test_capture_3(hwndMain
, hwndMain2
);
5155 test_CreateWindow();
5156 test_parent_owner();
5161 test_SetWindowPos(hwndMain
);
5162 test_SetMenu(hwndMain
);
5163 test_SetFocus(hwndMain
);
5164 test_SetActiveWindow(hwndMain
);
5166 test_children_zorder(hwndMain
);
5167 test_popup_zorder(hwndMain2
, hwndMain
);
5168 test_keyboard_input(hwndMain
);
5169 test_mouse_input(hwndMain
);
5170 test_validatergn(hwndMain
);
5171 test_nccalcscroll( hwndMain
);
5172 test_scrollvalidate( hwndMain
);
5173 test_scrolldc( hwndMain
);
5175 test_IsWindowUnicode();
5176 test_vis_rgn(hwndMain
);
5178 test_AdjustWindowRect();
5179 test_window_styles();
5182 test_SetWindowLong();
5184 if (0) test_gettext(); /* crashes on NT4 */
5185 test_GetUpdateRect();
5187 test_layered_window();
5189 test_SetForegroundWindow(hwndMain
);
5190 test_shell_window();
5192 /* add the tests above this line */
5193 UnhookWindowsHookEx(hhook
);