2 * Unit tests for window handling
4 * Copyright 2002 Bill Medland
5 * Copyright 2002 Alexandre Julliard
6 * Copyright 2003 Dmitry Timoshkov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 /* To get ICON_SMALL2 with the MSVC headers */
24 #define _WIN32_WINNT 0x0501
36 #include "wine/test.h"
38 #ifndef SPI_GETDESKWALLPAPER
39 #define SPI_GETDESKWALLPAPER 0x0073
42 #define LONG_PTR INT_PTR
43 #define ULONG_PTR UINT_PTR
45 void dump_region(HRGN hrgn
);
47 static HWND (WINAPI
*pGetAncestor
)(HWND
,UINT
);
48 static BOOL (WINAPI
*pGetWindowInfo
)(HWND
,WINDOWINFO
*);
49 static UINT (WINAPI
*pGetWindowModuleFileNameA
)(HWND
,LPSTR
,UINT
);
51 static BOOL test_lbuttondown_flag
;
52 static HWND hwndMessage
;
53 static HWND hwndMain
, hwndMain2
;
56 static const char* szAWRClass
= "Winsize";
60 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
62 /* try to make sure pending X events have been processed before continuing */
63 static void flush_events( BOOL remove_messages
)
68 DWORD time
= GetTickCount() + diff
;
72 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
74 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
75 diff
= time
- GetTickCount();
80 /* check the values returned by the various parent/owner functions on a given window */
81 static void check_parents( HWND hwnd
, HWND ga_parent
, HWND gwl_parent
, HWND get_parent
,
82 HWND gw_owner
, HWND ga_root
, HWND ga_root_owner
)
88 res
= pGetAncestor( hwnd
, GA_PARENT
);
89 ok( res
== ga_parent
, "Wrong result for GA_PARENT %p expected %p\n", res
, ga_parent
);
91 res
= (HWND
)GetWindowLongPtrA( hwnd
, GWLP_HWNDPARENT
);
92 ok( res
== gwl_parent
, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res
, gwl_parent
);
93 res
= GetParent( hwnd
);
94 ok( res
== get_parent
, "Wrong result for GetParent %p expected %p\n", res
, get_parent
);
95 res
= GetWindow( hwnd
, GW_OWNER
);
96 ok( res
== gw_owner
, "Wrong result for GW_OWNER %p expected %p\n", res
, gw_owner
);
99 res
= pGetAncestor( hwnd
, GA_ROOT
);
100 ok( res
== ga_root
, "Wrong result for GA_ROOT %p expected %p\n", res
, ga_root
);
101 res
= pGetAncestor( hwnd
, GA_ROOTOWNER
);
102 ok( res
== ga_root_owner
, "Wrong result for GA_ROOTOWNER %p expected %p\n", res
, ga_root_owner
);
106 static BOOL CALLBACK
EnumChildProc( HWND hwndChild
, LPARAM lParam
)
109 trace("EnumChildProc on %p\n", hwndChild
);
110 if (*(LPINT
)lParam
> 1) return FALSE
;
114 /* will search for the given window */
115 static BOOL CALLBACK
EnumChildProc1( HWND hwndChild
, LPARAM lParam
)
117 trace("EnumChildProc1 on %p\n", hwndChild
);
118 if ((HWND
)lParam
== hwndChild
) return FALSE
;
122 static HWND
create_tool_window( LONG style
, HWND parent
)
124 HWND ret
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style
,
125 0, 0, 100, 100, parent
, 0, 0, NULL
);
126 ok( ret
!= 0, "Creation failed\n" );
130 /* test parent and owner values for various combinations */
131 static void test_parent_owner(void)
134 HWND test
, owner
, ret
;
135 HWND desktop
= GetDesktopWindow();
136 HWND child
= create_tool_window( WS_CHILD
, hwndMain
);
139 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain
, hwndMain2
, desktop
, child
);
141 /* child without parent, should fail */
142 SetLastError(0xdeadbeef);
143 test
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
144 WS_CHILD
, 0, 0, 100, 100, 0, 0, 0, NULL
);
145 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD
, "CreateWindowExA should call SetLastError\n" );
146 ok( !test
, "WS_CHILD without parent created\n" );
149 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
150 style
= GetWindowLongA( desktop
, GWL_STYLE
);
151 ok( !SetWindowLongA( desktop
, GWL_STYLE
, WS_POPUP
), "Set GWL_STYLE on desktop succeeded\n" );
152 ok( !SetWindowLongA( desktop
, GWL_STYLE
, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
153 ok( GetWindowLongA( desktop
, GWL_STYLE
) == style
, "Desktop style changed\n" );
155 /* normal child window */
156 test
= create_tool_window( WS_CHILD
, hwndMain
);
157 trace( "created child %p\n", test
);
158 check_parents( test
, hwndMain
, hwndMain
, hwndMain
, 0, hwndMain
, hwndMain
);
159 SetWindowLongA( test
, GWL_STYLE
, 0 );
160 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
161 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
162 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
163 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
|WS_CHILD
);
164 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
165 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
166 DestroyWindow( test
);
168 /* normal child window with WS_MAXIMIZE */
169 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
170 DestroyWindow( test
);
172 /* normal child window with WS_THICKFRAME */
173 test
= create_tool_window( WS_CHILD
| WS_THICKFRAME
, hwndMain
);
174 DestroyWindow( test
);
176 /* popup window with WS_THICKFRAME */
177 test
= create_tool_window( WS_POPUP
| WS_THICKFRAME
, hwndMain
);
178 DestroyWindow( test
);
180 /* child of desktop */
181 test
= create_tool_window( WS_CHILD
, desktop
);
182 trace( "created child of desktop %p\n", test
);
183 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
184 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
185 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
186 SetWindowLongA( test
, GWL_STYLE
, 0 );
187 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
188 DestroyWindow( test
);
190 /* child of desktop with WS_MAXIMIZE */
191 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, desktop
);
192 DestroyWindow( test
);
194 /* child of desktop with WS_MINIMIZE */
195 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, desktop
);
196 DestroyWindow( test
);
199 test
= create_tool_window( WS_CHILD
, child
);
200 trace( "created child of child %p\n", test
);
201 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
202 SetWindowLongA( test
, GWL_STYLE
, 0 );
203 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
204 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
205 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
206 DestroyWindow( test
);
208 /* child of child with WS_MAXIMIZE */
209 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, child
);
210 DestroyWindow( test
);
212 /* child of child with WS_MINIMIZE */
213 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, child
);
214 DestroyWindow( test
);
216 /* not owned top-level window */
217 test
= create_tool_window( 0, 0 );
218 trace( "created top-level %p\n", test
);
219 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
220 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
221 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
222 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
223 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
224 DestroyWindow( test
);
226 /* not owned top-level window with WS_MAXIMIZE */
227 test
= create_tool_window( WS_MAXIMIZE
, 0 );
228 DestroyWindow( test
);
230 /* owned top-level window */
231 test
= create_tool_window( 0, hwndMain
);
232 trace( "created owned top-level %p\n", test
);
233 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
234 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
235 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
236 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
237 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
238 DestroyWindow( test
);
240 /* owned top-level window with WS_MAXIMIZE */
241 test
= create_tool_window( WS_MAXIMIZE
, hwndMain
);
242 DestroyWindow( test
);
244 /* not owned popup */
245 test
= create_tool_window( WS_POPUP
, 0 );
246 trace( "created popup %p\n", test
);
247 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
248 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
249 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
250 SetWindowLongA( test
, GWL_STYLE
, 0 );
251 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
252 DestroyWindow( test
);
254 /* not owned popup with WS_MAXIMIZE */
255 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, 0 );
256 DestroyWindow( test
);
259 test
= create_tool_window( WS_POPUP
, hwndMain
);
260 trace( "created owned popup %p\n", test
);
261 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
262 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
263 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
264 SetWindowLongA( test
, GWL_STYLE
, 0 );
265 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
266 DestroyWindow( test
);
268 /* owned popup with WS_MAXIMIZE */
269 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, hwndMain
);
270 DestroyWindow( test
);
272 /* top-level window owned by child (same as owned by top-level) */
273 test
= create_tool_window( 0, child
);
274 trace( "created top-level owned by child %p\n", test
);
275 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
276 DestroyWindow( test
);
278 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
279 test
= create_tool_window( WS_MAXIMIZE
, child
);
280 DestroyWindow( test
);
282 /* popup owned by desktop (same as not owned) */
283 test
= create_tool_window( WS_POPUP
, desktop
);
284 trace( "created popup owned by desktop %p\n", test
);
285 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
286 DestroyWindow( test
);
288 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
289 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, desktop
);
290 DestroyWindow( test
);
292 /* popup owned by child (same as owned by top-level) */
293 test
= create_tool_window( WS_POPUP
, child
);
294 trace( "created popup owned by child %p\n", test
);
295 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
296 DestroyWindow( test
);
298 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
299 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, child
);
300 DestroyWindow( test
);
302 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
303 test
= create_tool_window( WS_POPUP
| WS_CHILD
, 0 );
304 trace( "created WS_CHILD popup %p\n", test
);
305 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
306 DestroyWindow( test
);
308 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
309 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, 0 );
310 DestroyWindow( test
);
312 /* owned popup with WS_CHILD (same as WS_POPUP only) */
313 test
= create_tool_window( WS_POPUP
| WS_CHILD
, hwndMain
);
314 trace( "created owned WS_CHILD popup %p\n", test
);
315 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
316 DestroyWindow( test
);
318 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
319 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
320 DestroyWindow( test
);
322 /******************** parent changes *************************/
323 trace( "testing parent changes\n" );
326 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
329 /* this test succeeds on NT but crashes on win9x systems */
330 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
331 ok( !ret
, "Set GWL_HWNDPARENT succeeded on desktop\n" );
332 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
333 ok( !SetParent( desktop
, hwndMain
), "SetParent succeeded on desktop\n" );
334 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
336 /* normal child window */
337 test
= create_tool_window( WS_CHILD
, hwndMain
);
338 trace( "created child %p\n", test
);
340 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
341 ok( ret
== hwndMain
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain
);
342 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
344 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
345 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
346 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
348 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)desktop
);
349 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
350 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
352 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
353 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
354 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
355 check_parents( test
, desktop
, child
, desktop
, child
, test
, desktop
);
357 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
358 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
359 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
360 DestroyWindow( test
);
362 /* not owned top-level window */
363 test
= create_tool_window( 0, 0 );
364 trace( "created top-level %p\n", test
);
366 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
367 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
368 check_parents( test
, desktop
, hwndMain2
, 0, hwndMain2
, test
, test
);
370 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
371 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
372 check_parents( test
, desktop
, child
, 0, child
, test
, test
);
374 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
375 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
376 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
377 DestroyWindow( test
);
379 /* not owned popup */
380 test
= create_tool_window( WS_POPUP
, 0 );
381 trace( "created popup %p\n", test
);
383 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
384 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
385 check_parents( test
, desktop
, hwndMain2
, hwndMain2
, hwndMain2
, test
, hwndMain2
);
387 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
388 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
389 check_parents( test
, desktop
, child
, child
, child
, test
, hwndMain
);
391 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
392 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
393 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
394 DestroyWindow( test
);
396 /* normal child window */
397 test
= create_tool_window( WS_CHILD
, hwndMain
);
398 trace( "created child %p\n", test
);
400 ret
= SetParent( test
, desktop
);
401 ok( ret
== hwndMain
, "SetParent return value %p expected %p\n", ret
, hwndMain
);
402 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
404 ret
= SetParent( test
, child
);
405 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
406 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
408 ret
= SetParent( test
, hwndMain2
);
409 ok( ret
== child
, "SetParent return value %p expected %p\n", ret
, child
);
410 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
411 DestroyWindow( test
);
413 /* not owned top-level window */
414 test
= create_tool_window( 0, 0 );
415 trace( "created top-level %p\n", test
);
417 ret
= SetParent( test
, child
);
418 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
419 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
420 DestroyWindow( test
);
423 test
= create_tool_window( WS_POPUP
, hwndMain2
);
424 trace( "created owned popup %p\n", test
);
426 ret
= SetParent( test
, child
);
427 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
428 check_parents( test
, child
, child
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
430 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)hwndMain
);
431 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
432 check_parents( test
, hwndMain
, hwndMain
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
433 DestroyWindow( test
);
435 /**************** test owner destruction *******************/
437 /* owned child popup */
438 owner
= create_tool_window( 0, 0 );
439 test
= create_tool_window( WS_POPUP
, owner
);
440 trace( "created owner %p and popup %p\n", owner
, test
);
441 ret
= SetParent( test
, child
);
442 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
443 check_parents( test
, child
, child
, owner
, owner
, hwndMain
, owner
);
444 /* window is now child of 'child' but owned by 'owner' */
445 DestroyWindow( owner
);
446 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
447 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
448 * while Win95, Win2k, WinXP do.
450 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
451 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
454 /* owned top-level popup */
455 owner
= create_tool_window( 0, 0 );
456 test
= create_tool_window( WS_POPUP
, owner
);
457 trace( "created owner %p and popup %p\n", owner
, test
);
458 check_parents( test
, desktop
, owner
, owner
, owner
, test
, owner
);
459 DestroyWindow( owner
);
460 ok( !IsWindow(test
), "Window %p not destroyed by owner destruction\n", test
);
462 /* top-level popup owned by child */
463 owner
= create_tool_window( WS_CHILD
, hwndMain2
);
464 test
= create_tool_window( WS_POPUP
, 0 );
465 trace( "created owner %p and popup %p\n", owner
, test
);
466 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)owner
);
467 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
468 check_parents( test
, desktop
, owner
, owner
, owner
, test
, hwndMain2
);
469 DestroyWindow( owner
);
470 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
471 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
472 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
473 * while Win95, Win2k, WinXP do.
475 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
479 DestroyWindow(child
);
482 owner
= create_tool_window( WS_OVERLAPPED
, 0 );
483 test
= create_tool_window( WS_POPUP
, desktop
);
485 ok( !GetWindow( test
, GW_OWNER
), "Wrong owner window\n" );
487 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
488 "EnumChildWindows should have returned FALSE\n" );
489 ok( numChildren
== 0, "numChildren should be 0 got %d\n", numChildren
);
491 SetWindowLongA( test
, GWL_STYLE
, (GetWindowLongA( test
, GWL_STYLE
) & ~WS_POPUP
) | WS_CHILD
);
492 ret
= SetParent( test
, owner
);
493 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
496 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
497 "EnumChildWindows should have returned TRUE\n" );
498 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
500 child
= create_tool_window( WS_CHILD
, owner
);
502 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
503 "EnumChildWindows should have returned FALSE\n" );
504 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
505 DestroyWindow( child
);
507 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, owner
);
508 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
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 ret
= SetParent( child
, owner
);
515 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
516 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
518 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
519 "EnumChildWindows should have returned FALSE\n" );
520 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
522 ret
= SetParent( child
, NULL
);
523 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
524 ok( ret
== owner
, "SetParent return value %p expected %p\n", ret
, owner
);
526 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
527 "EnumChildWindows should have returned TRUE\n" );
528 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
530 /* even GW_OWNER == owner it's still a desktop's child */
531 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
532 "EnumChildWindows should have found %p and returned FALSE\n", child
);
534 DestroyWindow( child
);
535 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, NULL
);
537 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
538 "EnumChildWindows should have found %p and returned FALSE\n", child
);
540 DestroyWindow( child
);
541 DestroyWindow( test
);
542 DestroyWindow( owner
);
546 static LRESULT WINAPI
main_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
550 case WM_GETMINMAXINFO
:
552 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
554 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
555 trace("ptReserved (%d,%d), ptMaxSize (%d,%d), ptMaxPosition (%d,%d)\n"
556 " ptMinTrackSize (%d,%d), ptMaxTrackSize (%d,%d)\n",
557 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
558 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
559 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
560 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
561 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
562 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
565 case WM_WINDOWPOSCHANGING
:
567 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
568 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
569 trace("main: WM_WINDOWPOSCHANGING\n");
570 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
571 winpos
->hwnd
, winpos
->hwndInsertAfter
,
572 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
573 if (!(winpos
->flags
& SWP_NOMOVE
))
575 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
576 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
578 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
579 if (!(winpos
->flags
& SWP_NOSIZE
) && !is_win9x
)
581 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
582 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
586 case WM_WINDOWPOSCHANGED
:
589 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
590 trace("main: WM_WINDOWPOSCHANGED\n");
591 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
592 winpos
->hwnd
, winpos
->hwndInsertAfter
,
593 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
594 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
595 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
597 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
598 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
600 GetWindowRect(hwnd
, &rc1
);
601 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
602 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
603 /* note: winpos coordinates are relative to parent */
604 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
605 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
608 /* Uncomment this once the test succeeds in all cases */
609 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
612 GetClientRect(hwnd
, &rc2
);
613 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
614 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
615 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
616 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
621 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
622 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
624 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
625 if (got_getminmaxinfo
)
626 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
628 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
629 ok(got_getminmaxinfo
, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
631 ok(!got_getminmaxinfo
, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
635 if (test_lbuttondown_flag
)
637 ShowWindow((HWND
)wparam
, SW_SHOW
);
638 flush_events( FALSE
);
643 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
646 static LRESULT WINAPI
tool_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
650 case WM_GETMINMAXINFO
:
652 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
654 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
655 trace("ptReserved (%d,%d), ptMaxSize (%d,%d), ptMaxPosition (%d,%d)\n"
656 " ptMinTrackSize (%d,%d), ptMaxTrackSize (%d,%d)\n",
657 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
658 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
659 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
660 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
661 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
662 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
667 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
668 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
670 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
671 if (got_getminmaxinfo
)
672 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
674 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
675 ok(got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
677 ok(!got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
682 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
685 static BOOL
RegisterWindowClasses(void)
689 cls
.style
= CS_DBLCLKS
;
690 cls
.lpfnWndProc
= main_window_procA
;
693 cls
.hInstance
= GetModuleHandleA(0);
695 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
696 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
697 cls
.lpszMenuName
= NULL
;
698 cls
.lpszClassName
= "MainWindowClass";
700 if(!RegisterClassA(&cls
)) return FALSE
;
703 cls
.lpfnWndProc
= tool_window_procA
;
706 cls
.hInstance
= GetModuleHandleA(0);
708 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
709 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
710 cls
.lpszMenuName
= NULL
;
711 cls
.lpszClassName
= "ToolWindowClass";
713 if(!RegisterClassA(&cls
)) return FALSE
;
718 static void verify_window_info(HWND hwnd
, const WINDOWINFO
*info
)
720 RECT rcWindow
, rcClient
;
723 ok(IsWindow(hwnd
), "bad window handle\n");
725 GetWindowRect(hwnd
, &rcWindow
);
726 ok(EqualRect(&rcWindow
, &info
->rcWindow
), "wrong rcWindow\n");
728 GetClientRect(hwnd
, &rcClient
);
729 /* translate to screen coordinates */
730 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rcClient
, 2);
731 ok(EqualRect(&rcClient
, &info
->rcClient
), "wrong rcClient\n");
733 ok(info
->dwStyle
== (DWORD
)GetWindowLongA(hwnd
, GWL_STYLE
),
734 "wrong dwStyle: %08x != %08x\n", info
->dwStyle
, GetWindowLongA(hwnd
, GWL_STYLE
));
735 /* Windows reports a not documented exstyle 0x800 in WINDOWINFO, but
736 * doesn't return it in GetWindowLong(hwnd, GWL_EXSTYLE).
738 ok((info
->dwExStyle
& ~0x800) == (DWORD
)GetWindowLongA(hwnd
, GWL_EXSTYLE
),
739 "wrong dwExStyle: %08x != %08x\n", info
->dwExStyle
, GetWindowLongA(hwnd
, GWL_EXSTYLE
));
740 status
= (GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0;
741 ok(info
->dwWindowStatus
== status
, "wrong dwWindowStatus: %04x != %04x\n",
742 info
->dwWindowStatus
, status
);
744 trace("rcWindow: %d,%d - %d,%d\n", rcWindow
.left
, rcWindow
.top
, rcWindow
.right
, rcWindow
.bottom
);
745 trace("rcClient: %d,%d - %d,%d\n", rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
747 /* win2k and XP return broken border info in GetWindowInfo most of
748 * the time, so there is no point in testing it.
752 ok(info
->cxWindowBorders
== (unsigned)(rcClient
.left
- rcWindow
.left
),
753 "wrong cxWindowBorders %d != %d\n", info
->cxWindowBorders
, rcClient
.left
- rcWindow
.left
);
754 border
= min(rcWindow
.bottom
- rcClient
.bottom
, rcClient
.top
- rcWindow
.top
);
755 ok(info
->cyWindowBorders
== border
,
756 "wrong cyWindowBorders %d != %d\n", info
->cyWindowBorders
, border
);
758 ok(info
->atomWindowType
== GetClassLongA(hwnd
, GCW_ATOM
), "wrong atomWindowType\n");
759 ok(info
->wCreatorVersion
== 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
760 info
->wCreatorVersion
== 0x0500 /* Vista */,
761 "wrong wCreatorVersion %04x\n", info
->wCreatorVersion
);
764 static void FixedAdjustWindowRectEx(RECT
* rc
, LONG style
, BOOL menu
, LONG exstyle
)
766 AdjustWindowRectEx(rc
, style
, menu
, exstyle
);
767 /* AdjustWindowRectEx does not include scroll bars */
768 if (style
& WS_VSCROLL
)
770 if(exstyle
& WS_EX_LEFTSCROLLBAR
)
771 rc
->left
-= GetSystemMetrics(SM_CXVSCROLL
);
773 rc
->right
+= GetSystemMetrics(SM_CXVSCROLL
);
775 if (style
& WS_HSCROLL
)
776 rc
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
779 static void test_nonclient_area(HWND hwnd
)
781 DWORD style
, exstyle
;
782 RECT rc_window
, rc_client
, rc
;
784 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
786 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
787 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
788 menu
= !(style
& WS_CHILD
) && GetMenu(hwnd
) != 0;
790 GetWindowRect(hwnd
, &rc_window
);
791 trace("window: (%d,%d)-(%d,%d)\n", rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
);
792 GetClientRect(hwnd
, &rc_client
);
793 trace("client: (%d,%d)-(%d,%d)\n", rc_client
.left
, rc_client
.top
, rc_client
.right
, rc_client
.bottom
);
795 /* avoid some cases when things go wrong */
796 if (IsRectEmpty(&rc_window
) || IsRectEmpty(&rc_client
) ||
797 rc_window
.right
> 32768 || rc_window
.bottom
> 32768) return;
799 CopyRect(&rc
, &rc_client
);
800 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc
, 2);
801 FixedAdjustWindowRectEx(&rc
, style
, menu
, exstyle
);
803 trace("calc window: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
804 ok(EqualRect(&rc
, &rc_window
), "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
807 CopyRect(&rc
, &rc_window
);
808 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
809 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
810 trace("calc client: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
811 ok(EqualRect(&rc
, &rc_client
), "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
813 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
817 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
818 SetRect(&rc_client
, 0, 0, 250, 150);
819 CopyRect(&rc_window
, &rc_client
);
820 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc_window
, 2);
821 FixedAdjustWindowRectEx(&rc_window
, style
, menu
, exstyle
);
822 trace("calc window: (%d,%d)-(%d,%d)\n",
823 rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
);
825 CopyRect(&rc
, &rc_window
);
826 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
827 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
828 trace("calc client: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
829 ok(EqualRect(&rc
, &rc_client
), "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
832 static LRESULT CALLBACK
cbt_hook_proc(int nCode
, WPARAM wParam
, LPARAM lParam
)
834 static const char *CBT_code_name
[10] = {
845 const char *code_name
= (nCode
>= 0 && nCode
<= HCBT_SETFOCUS
) ? CBT_code_name
[nCode
] : "Unknown";
847 trace("CBT: %d (%s), %08lx, %08lx\n", nCode
, code_name
, wParam
, lParam
);
849 /* on HCBT_DESTROYWND window state is undefined */
850 if (nCode
!= HCBT_DESTROYWND
&& IsWindow((HWND
)wParam
))
856 /* Win98 actually does check the info.cbSize and doesn't allow
857 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
858 * WinXP do not check it at all.
860 info
.cbSize
= sizeof(WINDOWINFO
);
861 ok(pGetWindowInfo((HWND
)wParam
, &info
), "GetWindowInfo should not fail\n");
862 verify_window_info((HWND
)wParam
, &info
);
870 static const RECT rc_null
;
873 CBT_CREATEWNDA
*createwnd
= (CBT_CREATEWNDA
*)lParam
;
874 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
875 (HWND
)wParam
, createwnd
->lpcs
->hwndParent
, createwnd
->lpcs
->style
);
876 ok(createwnd
->hwndInsertAfter
== HWND_TOP
, "hwndInsertAfter should be always HWND_TOP\n");
878 /* WS_VISIBLE should be turned off yet */
879 style
= createwnd
->lpcs
->style
& ~WS_VISIBLE
;
880 ok(style
== GetWindowLongA((HWND
)wParam
, GWL_STYLE
),
881 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
882 GetWindowLongA((HWND
)wParam
, GWL_STYLE
), style
);
886 /* Uncomment this once the test succeeds in all cases */
887 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
889 ok(GetParent((HWND
)wParam
) == hwndMessage
,
890 "wrong result from GetParent %p: message window %p\n",
891 GetParent((HWND
)wParam
), hwndMessage
);
894 ok(!GetParent((HWND
)wParam
), "GetParent should return 0 at this point\n");
896 ok(!GetWindow((HWND
)wParam
, GW_OWNER
), "GW_OWNER should be set to 0 at this point\n");
900 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
901 * Win9x still has them set to 0.
903 ok(GetWindow((HWND
)wParam
, GW_HWNDFIRST
) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
904 ok(GetWindow((HWND
)wParam
, GW_HWNDLAST
) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
906 ok(!GetWindow((HWND
)wParam
, GW_HWNDPREV
), "GW_HWNDPREV should be set to 0 at this point\n");
907 ok(!GetWindow((HWND
)wParam
, GW_HWNDNEXT
), "GW_HWNDNEXT should be set to 0 at this point\n");
911 /* Uncomment this once the test succeeds in all cases */
914 ok(pGetAncestor((HWND
)wParam
, GA_PARENT
) == hwndMessage
, "GA_PARENT should be set to hwndMessage at this point\n");
915 ok(pGetAncestor((HWND
)wParam
, GA_ROOT
) == (HWND
)wParam
,
916 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND
)wParam
, GA_ROOT
), (HWND
)wParam
);
918 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
919 ok(pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
) == hwndMessage
,
920 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
922 ok(pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
) == (HWND
)wParam
,
923 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
), (HWND
)wParam
);
926 ok(GetWindowRect((HWND
)wParam
, &rc
), "GetWindowRect failed\n");
927 ok(EqualRect(&rc
, &rc_null
), "window rect should be set to 0 HCBT_CREATEWND\n");
928 ok(GetClientRect((HWND
)wParam
, &rc
), "GetClientRect failed\n");
929 ok(EqualRect(&rc
, &rc_null
), "client rect should be set to 0 on HCBT_CREATEWND\n");
935 return CallNextHookEx(hhook
, nCode
, wParam
, lParam
);
938 static void test_shell_window(void)
942 HMODULE hinst
, hUser32
;
943 BOOL (WINAPI
*SetShellWindow
)(HWND
);
944 BOOL (WINAPI
*SetShellWindowEx
)(HWND
, HWND
);
945 HWND hwnd1
, hwnd2
, hwnd3
, hwnd4
, hwnd5
;
946 HWND shellWindow
, nextWnd
;
948 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE
))
950 trace("Skipping shell window test on Win9x\n");
954 shellWindow
= GetShellWindow();
955 hinst
= GetModuleHandle(0);
956 hUser32
= GetModuleHandleA("user32");
958 SetShellWindow
= (void *)GetProcAddress(hUser32
, "SetShellWindow");
959 SetShellWindowEx
= (void *)GetProcAddress(hUser32
, "SetShellWindowEx");
961 trace("previous shell window: %p\n", shellWindow
);
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_ACCESS_DENIED after DestroyWindow(shellWindow)\n");
974 /* close old shell instance */
975 GetWindowThreadProcessId(shellWindow
, &pid
);
976 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, pid
);
977 ret
= TerminateProcess(hProcess
, 0);
978 ok(ret
, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
979 WaitForSingleObject(hProcess
, INFINITE
); /* wait for termination */
980 CloseHandle(hProcess
);
983 hwnd1
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst
, 0);
984 trace("created window 1: %p\n", hwnd1
);
986 ret
= SetShellWindow(hwnd1
);
987 ok(ret
, "first call to SetShellWindow(hwnd1)\n");
988 shellWindow
= GetShellWindow();
989 ok(shellWindow
==hwnd1
, "wrong shell window: %p\n", shellWindow
);
991 ret
= SetShellWindow(hwnd1
);
992 ok(!ret
, "second call to SetShellWindow(hwnd1)\n");
994 ret
= SetShellWindow(0);
995 error
= GetLastError();
996 /* passes on Win XP, but not on Win98
997 ok(!ret, "reset shell window by SetShellWindow(0)\n");
998 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1000 ret
= SetShellWindow(hwnd1
);
1001 /* passes on Win XP, but not on Win98
1002 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1004 SetWindowLong(hwnd1
, GWL_EXSTYLE
, GetWindowLong(hwnd1
,GWL_EXSTYLE
)|WS_EX_TOPMOST
);
1005 ret
= GetWindowLong(hwnd1
,GWL_EXSTYLE
)&WS_EX_TOPMOST
? TRUE
: FALSE
;
1006 ok(!ret
, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1008 ret
= DestroyWindow(hwnd1
);
1009 ok(ret
, "DestroyWindow(hwnd1)\n");
1011 hwnd2
= CreateWindowEx(WS_EX_TOPMOST
, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst
, 0);
1012 trace("created window 2: %p\n", hwnd2
);
1013 ret
= SetShellWindow(hwnd2
);
1014 ok(!ret
, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1016 hwnd3
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst
, 0);
1017 trace("created window 3: %p\n", hwnd3
);
1019 hwnd4
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst
, 0);
1020 trace("created window 4: %p\n", hwnd4
);
1022 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1023 ok(nextWnd
==hwnd3
, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd
);
1025 ret
= SetShellWindow(hwnd4
);
1026 ok(ret
, "SetShellWindow(hwnd4)\n");
1027 shellWindow
= GetShellWindow();
1028 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1030 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1031 ok(nextWnd
==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd
);
1033 ret
= SetWindowPos(hwnd4
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1034 ok(ret
, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1036 ret
= SetWindowPos(hwnd4
, hwnd3
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1037 ok(ret
, "SetWindowPos(hwnd4, hwnd3\n");
1039 ret
= SetShellWindow(hwnd3
);
1040 ok(!ret
, "SetShellWindow(hwnd3)\n");
1041 shellWindow
= GetShellWindow();
1042 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1044 hwnd5
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst
, 0);
1045 trace("created window 5: %p\n", hwnd5
);
1046 ret
= SetWindowPos(hwnd4
, hwnd5
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1047 ok(ret
, "SetWindowPos(hwnd4, hwnd5)\n");
1051 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1052 ok(nextWnd
==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd
);
1055 /* destroy test windows */
1056 DestroyWindow(hwnd2
);
1057 DestroyWindow(hwnd3
);
1058 DestroyWindow(hwnd4
);
1059 DestroyWindow(hwnd5
);
1062 /************** MDI test ****************/
1064 static char mdi_lParam_test_message
[] = "just a test string";
1066 static void test_MDI_create(HWND parent
, HWND mdi_client
, INT first_id
)
1068 MDICREATESTRUCTA mdi_cs
;
1070 static const WCHAR classW
[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1071 static const WCHAR titleW
[] = {'M','D','I',' ','c','h','i','l','d',0};
1072 BOOL isWin9x
= FALSE
;
1074 mdi_cs
.szClass
= "MDI_child_Class_1";
1075 mdi_cs
.szTitle
= "MDI child";
1076 mdi_cs
.hOwner
= GetModuleHandle(0);
1077 mdi_cs
.x
= CW_USEDEFAULT
;
1078 mdi_cs
.y
= CW_USEDEFAULT
;
1079 mdi_cs
.cx
= CW_USEDEFAULT
;
1080 mdi_cs
.cy
= CW_USEDEFAULT
;
1082 mdi_cs
.lParam
= (LPARAM
)mdi_lParam_test_message
;
1083 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1084 ok(mdi_child
!= 0, "MDI child creation failed\n");
1085 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1086 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1087 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1089 mdi_cs
.style
= 0x7fffffff; /* without WS_POPUP */
1090 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1091 ok(mdi_child
!= 0, "MDI child creation failed\n");
1092 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1093 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1094 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1096 mdi_cs
.style
= 0xffffffff; /* with WS_POPUP */
1097 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1098 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1100 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1104 ok(mdi_child
!= 0, "MDI child creation failed\n");
1105 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1106 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1107 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1110 /* test MDICREATESTRUCT A<->W mapping */
1111 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1113 mdi_cs
.szClass
= (LPCSTR
)classW
;
1114 mdi_cs
.szTitle
= (LPCSTR
)titleW
;
1115 SetLastError(0xdeadbeef);
1116 mdi_child
= (HWND
)SendMessageW(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1119 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1122 ok(mdi_child
!= 0, "MDI child creation failed\n");
1126 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1127 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1128 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1131 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1133 CW_USEDEFAULT
, CW_USEDEFAULT
,
1134 CW_USEDEFAULT
, CW_USEDEFAULT
,
1135 mdi_client
, GetModuleHandle(0),
1136 (LPARAM
)mdi_lParam_test_message
);
1137 ok(mdi_child
!= 0, "MDI child creation failed\n");
1138 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1139 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1140 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1142 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1143 0x7fffffff, /* without WS_POPUP */
1144 CW_USEDEFAULT
, CW_USEDEFAULT
,
1145 CW_USEDEFAULT
, CW_USEDEFAULT
,
1146 mdi_client
, GetModuleHandle(0),
1147 (LPARAM
)mdi_lParam_test_message
);
1148 ok(mdi_child
!= 0, "MDI child creation failed\n");
1149 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1150 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1151 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1153 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1154 0xffffffff, /* with WS_POPUP */
1155 CW_USEDEFAULT
, CW_USEDEFAULT
,
1156 CW_USEDEFAULT
, CW_USEDEFAULT
,
1157 mdi_client
, GetModuleHandle(0),
1158 (LPARAM
)mdi_lParam_test_message
);
1159 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1161 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1165 ok(mdi_child
!= 0, "MDI child creation failed\n");
1166 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1167 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1168 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1171 /* test MDICREATESTRUCT A<->W mapping */
1172 SetLastError(0xdeadbeef);
1173 mdi_child
= CreateMDIWindowW(classW
, titleW
,
1175 CW_USEDEFAULT
, CW_USEDEFAULT
,
1176 CW_USEDEFAULT
, CW_USEDEFAULT
,
1177 mdi_client
, GetModuleHandle(0),
1178 (LPARAM
)mdi_lParam_test_message
);
1181 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1184 ok(mdi_child
!= 0, "MDI child creation failed\n");
1188 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1189 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1190 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1193 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1195 CW_USEDEFAULT
, CW_USEDEFAULT
,
1196 CW_USEDEFAULT
, CW_USEDEFAULT
,
1197 mdi_client
, 0, GetModuleHandle(0),
1198 (LPVOID
)mdi_lParam_test_message
);
1199 ok(mdi_child
!= 0, "MDI child creation failed\n");
1200 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1201 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1202 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1204 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1205 0x7fffffff, /* without WS_POPUP */
1206 CW_USEDEFAULT
, CW_USEDEFAULT
,
1207 CW_USEDEFAULT
, CW_USEDEFAULT
,
1208 mdi_client
, 0, GetModuleHandle(0),
1209 (LPVOID
)mdi_lParam_test_message
);
1210 ok(mdi_child
!= 0, "MDI child creation failed\n");
1211 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1212 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1213 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1215 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1216 0xffffffff, /* with WS_POPUP */
1217 CW_USEDEFAULT
, CW_USEDEFAULT
,
1218 CW_USEDEFAULT
, CW_USEDEFAULT
,
1219 mdi_client
, 0, GetModuleHandle(0),
1220 (LPVOID
)mdi_lParam_test_message
);
1221 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1223 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1227 ok(mdi_child
!= 0, "MDI child creation failed\n");
1228 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1229 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1230 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1233 /* test MDICREATESTRUCT A<->W mapping */
1234 SetLastError(0xdeadbeef);
1235 mdi_child
= CreateWindowExW(WS_EX_MDICHILD
, classW
, titleW
,
1237 CW_USEDEFAULT
, CW_USEDEFAULT
,
1238 CW_USEDEFAULT
, CW_USEDEFAULT
,
1239 mdi_client
, 0, GetModuleHandle(0),
1240 (LPVOID
)mdi_lParam_test_message
);
1243 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1246 ok(mdi_child
!= 0, "MDI child creation failed\n");
1250 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1251 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1252 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1255 /* This test fails on Win9x */
1258 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_2", "MDI child",
1260 CW_USEDEFAULT
, CW_USEDEFAULT
,
1261 CW_USEDEFAULT
, CW_USEDEFAULT
,
1262 parent
, 0, GetModuleHandle(0),
1263 (LPVOID
)mdi_lParam_test_message
);
1264 ok(!mdi_child
, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1267 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1268 WS_CHILD
, /* without WS_POPUP */
1269 CW_USEDEFAULT
, CW_USEDEFAULT
,
1270 CW_USEDEFAULT
, CW_USEDEFAULT
,
1271 mdi_client
, 0, GetModuleHandle(0),
1272 (LPVOID
)mdi_lParam_test_message
);
1273 ok(mdi_child
!= 0, "MDI child creation failed\n");
1274 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1275 DestroyWindow(mdi_child
);
1277 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1278 WS_CHILD
| WS_POPUP
, /* with WS_POPUP */
1279 CW_USEDEFAULT
, CW_USEDEFAULT
,
1280 CW_USEDEFAULT
, CW_USEDEFAULT
,
1281 mdi_client
, 0, GetModuleHandle(0),
1282 (LPVOID
)mdi_lParam_test_message
);
1283 ok(mdi_child
!= 0, "MDI child creation failed\n");
1284 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1285 DestroyWindow(mdi_child
);
1287 /* maximized child */
1288 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1289 WS_CHILD
| WS_MAXIMIZE
,
1290 CW_USEDEFAULT
, CW_USEDEFAULT
,
1291 CW_USEDEFAULT
, CW_USEDEFAULT
,
1292 mdi_client
, 0, GetModuleHandle(0),
1293 (LPVOID
)mdi_lParam_test_message
);
1294 ok(mdi_child
!= 0, "MDI child creation failed\n");
1295 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1296 DestroyWindow(mdi_child
);
1298 trace("Creating maximized child with a caption\n");
1299 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1300 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
,
1301 CW_USEDEFAULT
, CW_USEDEFAULT
,
1302 CW_USEDEFAULT
, CW_USEDEFAULT
,
1303 mdi_client
, 0, GetModuleHandle(0),
1304 (LPVOID
)mdi_lParam_test_message
);
1305 ok(mdi_child
!= 0, "MDI child creation failed\n");
1306 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1307 DestroyWindow(mdi_child
);
1309 trace("Creating maximized child with a caption and a thick frame\n");
1310 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1311 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
| WS_THICKFRAME
,
1312 CW_USEDEFAULT
, CW_USEDEFAULT
,
1313 CW_USEDEFAULT
, CW_USEDEFAULT
,
1314 mdi_client
, 0, GetModuleHandle(0),
1315 (LPVOID
)mdi_lParam_test_message
);
1316 ok(mdi_child
!= 0, "MDI child creation failed\n");
1317 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1318 DestroyWindow(mdi_child
);
1321 /**********************************************************************
1322 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1324 * Note: The rule here is that client rect of the maximized MDI child
1325 * is equal to the client rect of the MDI client window.
1327 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
1331 GetClientRect( client
, &rect
);
1332 AdjustWindowRectEx( &rect
, GetWindowLongA( hwnd
, GWL_STYLE
),
1333 0, GetWindowLongA( hwnd
, GWL_EXSTYLE
));
1335 rect
.right
-= rect
.left
;
1336 rect
.bottom
-= rect
.top
;
1337 lpMinMax
->ptMaxSize
.x
= rect
.right
;
1338 lpMinMax
->ptMaxSize
.y
= rect
.bottom
;
1340 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
1341 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
1343 trace("max rect (%d,%d - %d, %d)\n",
1344 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1347 static LRESULT WINAPI
mdi_child_wnd_proc_1(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1354 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1355 MDICREATESTRUCTA
*mdi_cs
= (MDICREATESTRUCTA
*)cs
->lpCreateParams
;
1357 ok(cs
->dwExStyle
& WS_EX_MDICHILD
, "WS_EX_MDICHILD should be set\n");
1358 ok(mdi_cs
->lParam
== (LPARAM
)mdi_lParam_test_message
, "wrong mdi_cs->lParam\n");
1360 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_1"), "wrong class name\n");
1361 ok(!lstrcmpA(cs
->lpszClass
, mdi_cs
->szClass
), "class name does not match\n");
1362 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1363 ok(!lstrcmpA(cs
->lpszName
, mdi_cs
->szTitle
), "title does not match\n");
1364 ok(cs
->hInstance
== mdi_cs
->hOwner
, "%p != %p\n", cs
->hInstance
, mdi_cs
->hOwner
);
1366 /* MDICREATESTRUCT should have original values */
1367 ok(mdi_cs
->style
== 0 || mdi_cs
->style
== 0x7fffffff || mdi_cs
->style
== 0xffffffff,
1368 "mdi_cs->style does not match (%08x)\n", mdi_cs
->style
);
1369 ok(mdi_cs
->x
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->x
);
1370 ok(mdi_cs
->y
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->y
);
1371 ok(mdi_cs
->cx
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cx
);
1372 ok(mdi_cs
->cy
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cy
);
1374 /* CREATESTRUCT should have fixed values */
1375 ok(cs
->x
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->x
);
1376 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1378 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1379 ok(cs
->cx
!= CW_USEDEFAULT
&& cs
->cx
!= 0, "%d == CW_USEDEFAULT\n", cs
->cx
);
1380 ok(cs
->cy
!= CW_USEDEFAULT
&& cs
->cy
!= 0, "%d == CW_USEDEFAULT\n", cs
->cy
);
1382 ok(!(cs
->style
& WS_POPUP
), "WS_POPUP is not allowed\n");
1384 if (GetWindowLongA(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1386 LONG style
= mdi_cs
->style
| WS_CHILD
| WS_CLIPSIBLINGS
;
1387 ok(cs
->style
== style
,
1388 "cs->style does not match (%08x)\n", cs
->style
);
1392 LONG style
= mdi_cs
->style
;
1394 style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1395 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1396 ok(cs
->style
== style
,
1397 "cs->style does not match (%08x)\n", cs
->style
);
1402 case WM_GETMINMAXINFO
:
1404 HWND client
= GetParent(hwnd
);
1406 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1407 MINMAXINFO my_minmax
;
1408 LONG style
, exstyle
;
1410 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1411 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1413 GetWindowRect(client
, &rc
);
1414 trace("MDI client %p window size = (%d x %d)\n", client
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1415 GetClientRect(client
, &rc
);
1416 trace("MDI client %p client size = (%d x %d)\n", client
, rc
.right
, rc
.bottom
);
1417 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN
),
1418 GetSystemMetrics(SM_CYSCREEN
));
1420 GetClientRect(client
, &rc
);
1421 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1422 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1423 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1424 trace("MDI child: calculated max window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1426 trace("ptReserved = (%d,%d)\n"
1427 "ptMaxSize = (%d,%d)\n"
1428 "ptMaxPosition = (%d,%d)\n"
1429 "ptMinTrackSize = (%d,%d)\n"
1430 "ptMaxTrackSize = (%d,%d)\n",
1431 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
1432 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
1433 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
1434 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
1435 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
1437 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1438 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1439 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1440 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1442 DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1444 trace("DefMDIChildProc returned:\n"
1445 "ptReserved = (%d,%d)\n"
1446 "ptMaxSize = (%d,%d)\n"
1447 "ptMaxPosition = (%d,%d)\n"
1448 "ptMinTrackSize = (%d,%d)\n"
1449 "ptMaxTrackSize = (%d,%d)\n",
1450 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
1451 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
1452 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
1453 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
1454 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
1456 MDI_ChildGetMinMaxInfo(client
, hwnd
, &my_minmax
);
1457 ok(minmax
->ptMaxSize
.x
== my_minmax
.ptMaxSize
.x
, "default width of maximized child %d != %d\n",
1458 minmax
->ptMaxSize
.x
, my_minmax
.ptMaxSize
.x
);
1459 ok(minmax
->ptMaxSize
.y
== my_minmax
.ptMaxSize
.y
, "default height of maximized child %d != %d\n",
1460 minmax
->ptMaxSize
.y
, my_minmax
.ptMaxSize
.y
);
1465 case WM_MDIACTIVATE
:
1467 HWND active
, client
= GetParent(hwnd
);
1468 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1469 active
= (HWND
)SendMessageA(client
, WM_MDIGETACTIVE
, 0, 0);
1470 if (hwnd
== (HWND
)lparam
) /* if we are being activated */
1471 ok (active
== (HWND
)lparam
, "new active %p != active %p\n", (HWND
)lparam
, active
);
1473 ok (active
== (HWND
)wparam
, "old active %p != active %p\n", (HWND
)wparam
, active
);
1477 return DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1480 static LRESULT WINAPI
mdi_child_wnd_proc_2(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1487 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1489 trace("%s\n", (msg
== WM_NCCREATE
) ? "WM_NCCREATE" : "WM_CREATE");
1490 trace("x %d, y %d, cx %d, cy %d\n", cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
1492 ok(!(cs
->dwExStyle
& WS_EX_MDICHILD
), "WS_EX_MDICHILD should not be set\n");
1493 ok(cs
->lpCreateParams
== mdi_lParam_test_message
, "wrong cs->lpCreateParams\n");
1495 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_2"), "wrong class name\n");
1496 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1498 /* CREATESTRUCT should have fixed values */
1499 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1501 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1502 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1504 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1505 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1506 while Win95, Win2k, WinXP do. */
1507 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1508 ok(cs
->cy
== 0, "%d != 0\n", cs
->cy
);
1512 case WM_GETMINMAXINFO
:
1514 HWND parent
= GetParent(hwnd
);
1516 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1517 LONG style
, exstyle
;
1519 trace("WM_GETMINMAXINFO\n");
1521 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1522 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1524 GetClientRect(parent
, &rc
);
1525 trace("parent %p client size = (%d x %d)\n", parent
, rc
.right
, rc
.bottom
);
1527 GetClientRect(parent
, &rc
);
1528 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1529 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1530 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1531 trace("calculated max child window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1533 trace("ptReserved = (%d,%d)\n"
1534 "ptMaxSize = (%d,%d)\n"
1535 "ptMaxPosition = (%d,%d)\n"
1536 "ptMinTrackSize = (%d,%d)\n"
1537 "ptMaxTrackSize = (%d,%d)\n",
1538 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
1539 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
1540 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
1541 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
1542 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
1544 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1545 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1546 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1547 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1551 case WM_WINDOWPOSCHANGED
:
1553 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1556 GetWindowRect(hwnd
, &rc1
);
1557 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1558 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1559 /* note: winpos coordinates are relative to parent */
1560 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1561 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1562 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1564 GetWindowRect(hwnd
, &rc1
);
1565 GetClientRect(hwnd
, &rc2
);
1566 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1567 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1568 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1571 case WM_WINDOWPOSCHANGING
:
1573 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1574 WINDOWPOS my_winpos
= *winpos
;
1576 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1577 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1578 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1579 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1581 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1583 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1584 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1585 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1587 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1588 "DefWindowProc should not change WINDOWPOS values\n");
1593 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1596 static LRESULT WINAPI
mdi_main_wnd_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1598 static HWND mdi_client
;
1604 CLIENTCREATESTRUCT client_cs
;
1607 GetClientRect(hwnd
, &rc
);
1609 client_cs
.hWindowMenu
= 0;
1610 client_cs
.idFirstChild
= 1;
1612 /* MDIClient without MDIS_ALLCHILDSTYLES */
1613 mdi_client
= CreateWindowExA(0, "mdiclient",
1615 WS_CHILD
/*| WS_VISIBLE*/,
1616 /* tests depend on a not zero MDIClient size */
1617 0, 0, rc
.right
, rc
.bottom
,
1618 hwnd
, 0, GetModuleHandle(0),
1619 (LPVOID
)&client_cs
);
1621 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1622 DestroyWindow(mdi_client
);
1624 /* MDIClient with MDIS_ALLCHILDSTYLES */
1625 mdi_client
= CreateWindowExA(0, "mdiclient",
1627 WS_CHILD
| MDIS_ALLCHILDSTYLES
/*| WS_VISIBLE*/,
1628 /* tests depend on a not zero MDIClient size */
1629 0, 0, rc
.right
, rc
.bottom
,
1630 hwnd
, 0, GetModuleHandle(0),
1631 (LPVOID
)&client_cs
);
1633 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1634 DestroyWindow(mdi_client
);
1638 case WM_WINDOWPOSCHANGED
:
1640 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1643 GetWindowRect(hwnd
, &rc1
);
1644 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1645 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1646 /* note: winpos coordinates are relative to parent */
1647 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1648 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1649 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1651 GetWindowRect(hwnd
, &rc1
);
1652 GetClientRect(hwnd
, &rc2
);
1653 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1654 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1655 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1658 case WM_WINDOWPOSCHANGING
:
1660 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1661 WINDOWPOS my_winpos
= *winpos
;
1663 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1664 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1665 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1666 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1668 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1670 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1671 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1672 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1674 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1675 "DefWindowProc should not change WINDOWPOS values\n");
1684 return DefFrameProcA(hwnd
, mdi_client
, msg
, wparam
, lparam
);
1687 static BOOL
mdi_RegisterWindowClasses(void)
1692 cls
.lpfnWndProc
= mdi_main_wnd_procA
;
1695 cls
.hInstance
= GetModuleHandleA(0);
1697 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
1698 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1699 cls
.lpszMenuName
= NULL
;
1700 cls
.lpszClassName
= "MDI_parent_Class";
1701 if(!RegisterClassA(&cls
)) return FALSE
;
1703 cls
.lpfnWndProc
= mdi_child_wnd_proc_1
;
1704 cls
.lpszClassName
= "MDI_child_Class_1";
1705 if(!RegisterClassA(&cls
)) return FALSE
;
1707 cls
.lpfnWndProc
= mdi_child_wnd_proc_2
;
1708 cls
.lpszClassName
= "MDI_child_Class_2";
1709 if(!RegisterClassA(&cls
)) return FALSE
;
1714 static void test_mdi(void)
1719 if (!mdi_RegisterWindowClasses()) assert(0);
1721 mdi_hwndMain
= CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1722 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
1723 WS_MAXIMIZEBOX
/*| WS_VISIBLE*/,
1724 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1725 GetDesktopWindow(), 0,
1726 GetModuleHandle(0), NULL
);
1727 assert(mdi_hwndMain
);
1729 while(GetMessage(&msg, 0, 0, 0))
1731 TranslateMessage(&msg);
1732 DispatchMessage(&msg);
1735 DestroyWindow(mdi_hwndMain
);
1738 static void test_icons(void)
1742 HICON icon
= LoadIconA(0, (LPSTR
)IDI_APPLICATION
);
1743 HICON icon2
= LoadIconA(0, (LPSTR
)IDI_QUESTION
);
1744 HICON small_icon
= LoadImageA(0, (LPSTR
)IDI_APPLICATION
, IMAGE_ICON
,
1745 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
1748 cls
.cbSize
= sizeof(cls
);
1750 cls
.lpfnWndProc
= DefWindowProcA
;
1754 cls
.hIcon
= LoadIconA(0, (LPSTR
)IDI_HAND
);
1755 cls
.hIconSm
= small_icon
;
1756 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
1757 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1758 cls
.lpszMenuName
= NULL
;
1759 cls
.lpszClassName
= "IconWindowClass";
1761 RegisterClassExA(&cls
);
1763 hwnd
= CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1764 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, NULL
, NULL
);
1767 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1768 ok( res
== 0, "wrong big icon %p/0\n", res
);
1769 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon
);
1770 ok( res
== 0, "wrong previous big icon %p/0\n", res
);
1771 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1772 ok( res
== icon
, "wrong big icon after set %p/%p\n", res
, icon
);
1773 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon2
);
1774 ok( res
== icon
, "wrong previous big icon %p/%p\n", res
, icon
);
1775 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1776 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1778 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1779 ok( res
== 0, "wrong small icon %p/0\n", res
);
1780 /* this test is XP specific */
1781 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1782 ok( res != 0, "wrong small icon %p\n", res );*/
1783 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)icon
);
1784 ok( res
== 0, "wrong previous small icon %p/0\n", res
);
1785 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1786 ok( res
== icon
, "wrong small icon after set %p/%p\n", res
, icon
);
1787 /* this test is XP specific */
1788 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1789 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1790 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)small_icon
);
1791 ok( res
== icon
, "wrong previous small icon %p/%p\n", res
, icon
);
1792 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1793 ok( res
== small_icon
, "wrong small icon after set %p/%p\n", res
, small_icon
);
1794 /* this test is XP specific */
1795 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1796 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1798 /* make sure the big icon hasn't changed */
1799 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1800 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1802 DestroyWindow( hwnd
);
1805 static LRESULT WINAPI
nccalcsize_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1807 if (msg
== WM_NCCALCSIZE
)
1809 RECT
*rect
= (RECT
*)lparam
;
1810 /* first time around increase the rectangle, next time decrease it */
1811 if (rect
->left
== 100) InflateRect( rect
, 10, 10 );
1812 else InflateRect( rect
, -10, -10 );
1815 return DefWindowProc( hwnd
, msg
, wparam
, lparam
);
1818 static void test_SetWindowPos(HWND hwnd
)
1820 RECT orig_win_rc
, rect
;
1822 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
1824 SetRect(&rect
, 111, 222, 333, 444);
1825 ok(!GetWindowRect(0, &rect
), "GetWindowRect succeeded\n");
1826 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1827 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1829 SetRect(&rect
, 111, 222, 333, 444);
1830 ok(!GetClientRect(0, &rect
), "GetClientRect succeeded\n");
1831 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1832 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1834 GetWindowRect(hwnd
, &orig_win_rc
);
1836 old_proc
= SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)nccalcsize_proc
);
1837 SetWindowPos(hwnd
, 0, 100, 100, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1838 GetWindowRect( hwnd
, &rect
);
1839 ok( rect
.left
== 100 && rect
.top
== 100 && rect
.right
== 100 && rect
.bottom
== 100,
1840 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1841 GetClientRect( hwnd
, &rect
);
1842 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1843 ok( rect
.left
== 90 && rect
.top
== 90 && rect
.right
== 110 && rect
.bottom
== 110,
1844 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1846 SetWindowPos(hwnd
, 0, 200, 200, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1847 GetWindowRect( hwnd
, &rect
);
1848 ok( rect
.left
== 200 && rect
.top
== 200 && rect
.right
== 200 && rect
.bottom
== 200,
1849 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1850 GetClientRect( hwnd
, &rect
);
1851 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1852 ok( rect
.left
== 210 && rect
.top
== 210 && rect
.right
== 190 && rect
.bottom
== 190,
1853 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1855 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1856 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1857 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, old_proc
);
1859 /* Win9x truncates coordinates to 16-bit irrespectively */
1862 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE
);
1863 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE
);
1865 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE
);
1866 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE
);
1869 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1870 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1872 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1873 SetWindowPos(hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1874 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1875 SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1876 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1877 SetWindowPos(hwnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1878 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1881 static void test_SetMenu(HWND parent
)
1885 BOOL is_win9x
= GetWindowLongPtrW(parent
, GWLP_WNDPROC
) == 0;
1889 hMenu
= CreateMenu();
1892 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1895 /* fails on (at least) Wine, NT4, XP SP2 */
1896 test_nonclient_area(parent
);
1898 ret
= GetMenu(parent
);
1899 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1900 /* test whether we can destroy a menu assigned to a window */
1901 retok
= DestroyMenu(hMenu
);
1902 ok( retok
, "DestroyMenu error %d\n", GetLastError());
1903 ok(!IsMenu(hMenu
), "menu handle should be not valid after DestroyMenu\n");
1904 ret
= GetMenu(parent
);
1905 /* This test fails on Win9x */
1907 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1908 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1909 test_nonclient_area(parent
);
1911 hMenu
= CreateMenu();
1915 ret
= GetMenu(parent
);
1916 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1918 ok(!SetMenu(parent
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1919 test_nonclient_area(parent
);
1920 ret
= GetMenu(parent
);
1921 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1923 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1926 /* fails on (at least) Wine, NT4, XP SP2 */
1927 test_nonclient_area(parent
);
1929 ret
= GetMenu(parent
);
1930 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1932 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1933 test_nonclient_area(parent
);
1934 ret
= GetMenu(parent
);
1935 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1938 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, parent
, (HMENU
)10, 0, NULL
);
1941 ret
= GetMenu(child
);
1942 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1944 ok(!SetMenu(child
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1945 test_nonclient_area(child
);
1946 ret
= GetMenu(child
);
1947 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1949 ok(!SetMenu(child
, hMenu
), "SetMenu on a child window should fail\n");
1950 test_nonclient_area(child
);
1951 ret
= GetMenu(child
);
1952 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1954 ok(!SetMenu(child
, 0), "SetMenu(0) on a child window should fail\n");
1955 test_nonclient_area(child
);
1956 ret
= GetMenu(child
);
1957 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1959 style
= GetWindowLong(child
, GWL_STYLE
);
1960 SetWindowLong(child
, GWL_STYLE
, style
| WS_POPUP
);
1961 ok(SetMenu(child
, hMenu
), "SetMenu on a popup child window should not fail\n");
1962 ok(SetMenu(child
, 0), "SetMenu on a popup child window should not fail\n");
1963 SetWindowLong(child
, GWL_STYLE
, style
);
1965 SetWindowLong(child
, GWL_STYLE
, style
| WS_OVERLAPPED
);
1966 ok(!SetMenu(child
, hMenu
), "SetMenu on a overlapped child window should fail\n");
1967 SetWindowLong(child
, GWL_STYLE
, style
);
1969 DestroyWindow(child
);
1973 static void test_window_tree(HWND parent
, const DWORD
*style
, const int *order
, int total
)
1975 HWND child
[5], hwnd
;
1980 hwnd
= GetWindow(parent
, GW_CHILD
);
1981 ok(!hwnd
, "have to start without children to perform the test\n");
1983 for (i
= 0; i
< total
; i
++)
1985 if (style
[i
] & DS_CONTROL
)
1987 child
[i
] = CreateWindowExA(0, MAKEINTATOM(32770), "", style
[i
] & ~WS_VISIBLE
,
1988 0,0,0,0, parent
, (HMENU
)i
, 0, NULL
);
1989 if (style
[i
] & WS_VISIBLE
)
1990 ShowWindow(child
[i
], SW_SHOW
);
1992 SetWindowPos(child
[i
], HWND_BOTTOM
, 0,0,10,10, SWP_NOACTIVATE
);
1995 child
[i
] = CreateWindowExA(0, "static", "", style
[i
], 0,0,10,10,
1996 parent
, (HMENU
)i
, 0, NULL
);
1997 trace("child[%d] = %p\n", i
, child
[i
]);
1998 ok(child
[i
] != 0, "CreateWindowEx failed to create child window\n");
2001 hwnd
= GetWindow(parent
, GW_CHILD
);
2002 ok(hwnd
!= 0, "GetWindow(GW_CHILD) failed\n");
2003 ok(hwnd
== GetWindow(child
[total
- 1], GW_HWNDFIRST
), "GW_HWNDFIRST is wrong\n");
2004 ok(child
[order
[total
- 1]] == GetWindow(child
[0], GW_HWNDLAST
), "GW_HWNDLAST is wrong\n");
2006 for (i
= 0; i
< total
; i
++)
2008 trace("hwnd[%d] = %p\n", i
, hwnd
);
2009 ok(child
[order
[i
]] == hwnd
, "Z order of child #%d is wrong\n", i
);
2011 hwnd
= GetWindow(hwnd
, GW_HWNDNEXT
);
2014 for (i
= 0; i
< total
; i
++)
2015 ok(DestroyWindow(child
[i
]), "DestroyWindow failed\n");
2018 static void test_children_zorder(HWND parent
)
2020 const DWORD simple_style
[5] = { WS_CHILD
, WS_CHILD
, WS_CHILD
, WS_CHILD
,
2022 const int simple_order
[5] = { 0, 1, 2, 3, 4 };
2024 const DWORD complex_style
[5] = { WS_CHILD
, WS_CHILD
| WS_MAXIMIZE
,
2025 WS_CHILD
| WS_VISIBLE
, WS_CHILD
,
2026 WS_CHILD
| WS_MAXIMIZE
| WS_VISIBLE
};
2027 const int complex_order_1
[1] = { 0 };
2028 const int complex_order_2
[2] = { 1, 0 };
2029 const int complex_order_3
[3] = { 1, 0, 2 };
2030 const int complex_order_4
[4] = { 1, 0, 2, 3 };
2031 const int complex_order_5
[5] = { 4, 1, 0, 2, 3 };
2032 const DWORD complex_style_6
[3] = { WS_CHILD
| WS_VISIBLE
,
2033 WS_CHILD
| WS_CLIPSIBLINGS
| DS_CONTROL
| WS_VISIBLE
,
2034 WS_CHILD
| WS_VISIBLE
};
2035 const int complex_order_6
[3] = { 0, 1, 2 };
2037 /* simple WS_CHILD */
2038 test_window_tree(parent
, simple_style
, simple_order
, 5);
2040 /* complex children styles */
2041 test_window_tree(parent
, complex_style
, complex_order_1
, 1);
2042 test_window_tree(parent
, complex_style
, complex_order_2
, 2);
2043 test_window_tree(parent
, complex_style
, complex_order_3
, 3);
2044 test_window_tree(parent
, complex_style
, complex_order_4
, 4);
2045 test_window_tree(parent
, complex_style
, complex_order_5
, 5);
2047 /* another set of complex children styles */
2048 test_window_tree(parent
, complex_style_6
, complex_order_6
, 3);
2051 #define check_z_order(hwnd, next, prev, owner, topmost) \
2052 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2055 static void check_z_order_debug(HWND hwnd
, HWND next
, HWND prev
, HWND owner
,
2056 BOOL topmost
, const char *file
, int line
)
2061 test
= GetWindow(hwnd
, GW_HWNDNEXT
);
2062 /* skip foreign windows */
2063 while (test
&& (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2064 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0)))
2066 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2067 test
= GetWindow(test
, GW_HWNDNEXT
);
2069 ok_(file
, line
)(next
== test
, "expected next %p, got %p\n", next
, test
);
2071 test
= GetWindow(hwnd
, GW_HWNDPREV
);
2072 /* skip foreign windows */
2073 while (test
&& (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2074 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0)))
2076 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2077 test
= GetWindow(test
, GW_HWNDPREV
);
2079 ok_(file
, line
)(prev
== test
, "expected prev %p, got %p\n", prev
, test
);
2081 test
= GetWindow(hwnd
, GW_OWNER
);
2082 ok_(file
, line
)(owner
== test
, "expected owner %p, got %p\n", owner
, test
);
2084 ex_style
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
2085 ok_(file
, line
)(!(ex_style
& WS_EX_TOPMOST
) == !topmost
, "expected %stopmost\n", topmost
? "" : "NOT ");
2088 static void test_popup_zorder(HWND hwnd_D
, HWND hwnd_E
)
2090 HWND hwnd_A
, hwnd_B
, hwnd_C
, hwnd_F
;
2092 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D
, hwnd_E
);
2094 SetWindowPos(hwnd_E
, hwnd_D
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2096 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2097 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2099 hwnd_F
= CreateWindowEx(0, "MainWindowClass", "Owner window",
2100 WS_OVERLAPPED
| WS_CAPTION
,
2102 0, 0, GetModuleHandle(0), NULL
);
2103 trace("hwnd_F %p\n", hwnd_F
);
2104 check_z_order(hwnd_F
, hwnd_D
, 0, 0, FALSE
);
2106 SetWindowPos(hwnd_F
, hwnd_E
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2107 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2108 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2109 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2111 hwnd_C
= CreateWindowEx(0, "MainWindowClass", NULL
,
2114 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2115 trace("hwnd_C %p\n", hwnd_C
);
2116 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2117 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2118 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2119 check_z_order(hwnd_C
, hwnd_D
, 0, hwnd_F
, FALSE
);
2121 hwnd_B
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2124 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2125 trace("hwnd_B %p\n", hwnd_B
);
2126 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2127 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2128 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2129 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2130 check_z_order(hwnd_B
, hwnd_C
, 0, hwnd_F
, TRUE
);
2132 hwnd_A
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2135 0, 0, GetModuleHandle(0), NULL
);
2136 trace("hwnd_A %p\n", hwnd_A
);
2137 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2138 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2139 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2140 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2141 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2142 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2144 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
);
2146 /* move hwnd_F and its popups up */
2147 SetWindowPos(hwnd_F
, HWND_TOP
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2148 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2149 check_z_order(hwnd_D
, hwnd_E
, hwnd_F
, 0, FALSE
);
2150 check_z_order(hwnd_F
, hwnd_D
, hwnd_C
, 0, FALSE
);
2151 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2152 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2153 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2155 /* move hwnd_F and its popups down */
2156 #if 0 /* enable once Wine is fixed to pass this test */
2157 SetWindowPos(hwnd_F
, HWND_BOTTOM
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2158 check_z_order(hwnd_F
, 0, hwnd_C
, 0, FALSE
);
2159 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2160 check_z_order(hwnd_B
, hwnd_C
, hwnd_E
, hwnd_F
, FALSE
);
2161 check_z_order(hwnd_E
, hwnd_B
, hwnd_D
, 0, FALSE
);
2162 check_z_order(hwnd_D
, hwnd_E
, hwnd_A
, 0, FALSE
);
2163 check_z_order(hwnd_A
, hwnd_D
, 0, 0, TRUE
);
2166 DestroyWindow(hwnd_A
);
2167 DestroyWindow(hwnd_B
);
2168 DestroyWindow(hwnd_C
);
2169 DestroyWindow(hwnd_F
);
2172 static void test_vis_rgn( HWND hwnd
)
2174 RECT win_rect
, rgn_rect
;
2175 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2178 ShowWindow(hwnd
,SW_SHOW
);
2179 hdc
= GetDC( hwnd
);
2180 ok( GetRandomRgn( hdc
, hrgn
, SYSRGN
) != 0, "GetRandomRgn failed\n" );
2181 GetWindowRect( hwnd
, &win_rect
);
2182 GetRgnBox( hrgn
, &rgn_rect
);
2183 if (GetVersion() & 0x80000000)
2185 trace("win9x, mapping to screen coords\n");
2186 MapWindowPoints( hwnd
, 0, (POINT
*)&rgn_rect
, 2 );
2188 trace("win: %d,%d-%d,%d\n", win_rect
.left
, win_rect
.top
, win_rect
.right
, win_rect
.bottom
);
2189 trace("rgn: %d,%d-%d,%d\n", rgn_rect
.left
, rgn_rect
.top
, rgn_rect
.right
, rgn_rect
.bottom
);
2190 ok( win_rect
.left
<= rgn_rect
.left
, "rgn left %d not inside win rect %d\n",
2191 rgn_rect
.left
, win_rect
.left
);
2192 ok( win_rect
.top
<= rgn_rect
.top
, "rgn top %d not inside win rect %d\n",
2193 rgn_rect
.top
, win_rect
.top
);
2194 ok( win_rect
.right
>= rgn_rect
.right
, "rgn right %d not inside win rect %d\n",
2195 rgn_rect
.right
, win_rect
.right
);
2196 ok( win_rect
.bottom
>= rgn_rect
.bottom
, "rgn bottom %d not inside win rect %d\n",
2197 rgn_rect
.bottom
, win_rect
.bottom
);
2198 ReleaseDC( hwnd
, hdc
);
2201 static void test_SetFocus(HWND hwnd
)
2205 /* check if we can set focus to non-visible windows */
2207 ShowWindow(hwnd
, SW_SHOW
);
2210 ok( GetFocus() == hwnd
, "Failed to set focus to visible window %p\n", hwnd
);
2211 ok( GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
, "Window %p not visible\n", hwnd
);
2212 ShowWindow(hwnd
, SW_HIDE
);
2215 ok( GetFocus() == hwnd
, "Failed to set focus to invisible window %p\n", hwnd
);
2216 ok( !(GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
), "Window %p still visible\n", hwnd
);
2217 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2220 ok( GetFocus() == child
, "Failed to set focus to invisible child %p\n", child
);
2221 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2222 ShowWindow(child
, SW_SHOW
);
2223 ok( GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
, "Child %p is not visible\n", child
);
2224 ok( GetFocus() == child
, "Focus no longer on child %p\n", child
);
2225 ShowWindow(child
, SW_HIDE
);
2226 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2227 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2228 ShowWindow(child
, SW_SHOW
);
2230 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2231 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_HIDEWINDOW
);
2232 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2234 ShowWindow(child
, SW_HIDE
);
2236 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2237 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_SHOWWINDOW
);
2238 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2239 ShowWindow(child
, SW_HIDE
);
2240 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2242 ShowWindow(hwnd
, SW_SHOW
);
2243 ShowWindow(child
, SW_SHOW
);
2245 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2246 EnableWindow(hwnd
, FALSE
);
2247 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2248 EnableWindow(hwnd
, TRUE
);
2250 DestroyWindow( child
);
2253 static void check_wnd_state(HWND active
, HWND foreground
, HWND focus
, HWND capture
)
2255 ok(active
== GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2257 ok(foreground
== GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2258 ok(focus
== GetFocus(), "GetFocus() = %p\n", GetFocus());
2259 ok(capture
== GetCapture(), "GetCapture() = %p\n", GetCapture());
2262 static void test_SetActiveWindow(HWND hwnd
)
2266 ShowWindow(hwnd
, SW_HIDE
);
2269 check_wnd_state(0, 0, 0, 0);
2271 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2273 ShowWindow(hwnd
, SW_SHOW
);
2274 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2276 hwnd2
= SetActiveWindow(0);
2277 ok(hwnd2
== hwnd
, "SetActiveWindow returned %p instead of %p\n", hwnd2
, hwnd
);
2278 check_wnd_state(0, 0, 0, 0);
2280 hwnd2
= SetActiveWindow(hwnd
);
2281 ok(hwnd2
== 0, "SetActiveWindow returned %p instead of 0\n", hwnd2
);
2282 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2284 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2285 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2287 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2288 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2290 ShowWindow(hwnd
, SW_HIDE
);
2291 check_wnd_state(0, 0, 0, 0);
2293 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2294 SetActiveWindow(hwnd
);
2295 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2297 ShowWindow(hwnd
, SW_SHOW
);
2298 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2300 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2301 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2303 DestroyWindow(hwnd2
);
2304 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2306 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2307 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2309 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2310 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2312 DestroyWindow(hwnd2
);
2313 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2316 static void test_SetForegroundWindow(HWND hwnd
)
2321 ShowWindow(hwnd
, SW_HIDE
);
2324 check_wnd_state(0, 0, 0, 0);
2326 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2328 ShowWindow(hwnd
, SW_SHOW
);
2329 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2331 hwnd2
= SetActiveWindow(0);
2332 ok(hwnd2
== hwnd
, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2
, hwnd
);
2333 check_wnd_state(0, 0, 0, 0);
2335 ret
= SetForegroundWindow(hwnd
);
2336 ok(ret
, "SetForegroundWindow returned FALSE instead of TRUE\n");
2337 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2339 SetLastError(0xdeadbeef);
2340 ret
= SetForegroundWindow(0);
2341 ok(!ret
, "SetForegroundWindow returned TRUE instead of FALSE\n");
2342 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2343 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2345 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2346 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2348 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2349 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2351 hwnd2
= GetForegroundWindow();
2352 ok(hwnd2
== hwnd
, "Wrong foreground window %p\n", hwnd2
);
2353 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2354 hwnd2
= GetForegroundWindow();
2355 ok(hwnd2
!= hwnd
, "Wrong foreground window %p\n", hwnd2
);
2357 ShowWindow(hwnd
, SW_HIDE
);
2358 check_wnd_state(0, 0, 0, 0);
2360 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2361 ret
= SetForegroundWindow(hwnd
);
2362 ok(ret
, "SetForegroundWindow returned FALSE instead of TRUE\n");
2363 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2365 ShowWindow(hwnd
, SW_SHOW
);
2366 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2368 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2369 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2371 DestroyWindow(hwnd2
);
2372 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2374 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2375 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2377 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2378 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2380 DestroyWindow(hwnd2
);
2381 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2384 static WNDPROC old_button_proc
;
2386 static LRESULT WINAPI
button_hook_proc(HWND button
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2391 key_state
= GetKeyState(VK_LBUTTON
);
2392 ok(!(key_state
& 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state
);
2394 ret
= CallWindowProcA(old_button_proc
, button
, msg
, wparam
, lparam
);
2396 if (msg
== WM_LBUTTONDOWN
)
2400 check_wnd_state(button
, button
, button
, button
);
2402 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2404 trace("hwnd %p\n", hwnd
);
2406 check_wnd_state(button
, button
, button
, button
);
2408 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2410 check_wnd_state(button
, button
, button
, button
);
2412 DestroyWindow(hwnd
);
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 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2421 * match internal button state.
2423 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2424 check_wnd_state(button
, button
, button
, 0);
2426 ShowWindow(hwnd
, SW_SHOW
);
2427 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2429 capture
= SetCapture(hwnd
);
2430 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2432 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2434 DestroyWindow(hwnd
);
2436 check_wnd_state(button
, 0, button
, 0);
2442 static void test_capture_1(void)
2444 HWND button
, capture
;
2446 capture
= GetCapture();
2447 ok(capture
== 0, "GetCapture() = %p\n", capture
);
2449 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2451 trace("button %p\n", button
);
2453 old_button_proc
= (WNDPROC
)SetWindowLongPtrA(button
, GWLP_WNDPROC
, (LONG_PTR
)button_hook_proc
);
2455 SendMessageA(button
, WM_LBUTTONDOWN
, 0, 0);
2457 capture
= SetCapture(button
);
2458 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2459 check_wnd_state(button
, 0, button
, button
);
2461 DestroyWindow(button
);
2462 check_wnd_state(0, 0, 0, 0);
2465 static void test_capture_2(void)
2467 HWND button
, hwnd
, capture
;
2469 check_wnd_state(0, 0, 0, 0);
2471 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2473 trace("button %p\n", button
);
2475 check_wnd_state(button
, button
, button
, 0);
2477 capture
= SetCapture(button
);
2478 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2480 check_wnd_state(button
, button
, button
, button
);
2482 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2483 * internal button state.
2485 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2486 check_wnd_state(button
, button
, button
, button
);
2488 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2490 trace("hwnd %p\n", hwnd
);
2492 check_wnd_state(button
, button
, button
, button
);
2494 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2496 check_wnd_state(button
, button
, button
, button
);
2498 DestroyWindow(hwnd
);
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_SHOW
);
2508 check_wnd_state(hwnd
, hwnd
, hwnd
, button
);
2510 capture
= SetCapture(hwnd
);
2511 ok(capture
== button
, "SetCapture() = %p\n", capture
);
2513 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2515 DestroyWindow(hwnd
);
2516 check_wnd_state(button
, button
, button
, 0);
2518 DestroyWindow(button
);
2519 check_wnd_state(0, 0, 0, 0);
2522 static void test_capture_3(HWND hwnd1
, HWND hwnd2
)
2526 ShowWindow(hwnd1
, SW_HIDE
);
2527 ShowWindow(hwnd2
, SW_HIDE
);
2529 ok(!IsWindowVisible(hwnd1
), "%p should be invisible\n", hwnd1
);
2530 ok(!IsWindowVisible(hwnd2
), "%p should be invisible\n", hwnd2
);
2533 check_wnd_state(0, 0, 0, hwnd1
);
2536 check_wnd_state(0, 0, 0, hwnd2
);
2538 ShowWindow(hwnd1
, SW_SHOW
);
2539 check_wnd_state(hwnd1
, hwnd1
, hwnd1
, hwnd2
);
2541 ret
= ReleaseCapture();
2542 ok (ret
, "releasecapture did not return TRUE.\n");
2543 ret
= ReleaseCapture();
2544 ok (ret
, "releasecapture did not return TRUE after second try.\n");
2547 static void test_keyboard_input(HWND hwnd
)
2552 ShowWindow(hwnd
, SW_SHOW
);
2554 flush_events( TRUE
);
2556 ok(GetActiveWindow() == hwnd
, "wrong active window %p\n", GetActiveWindow());
2559 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2561 flush_events( TRUE
);
2563 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2564 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2565 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2566 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2567 ok( !ret
, "message %04x available\n", msg
.message
);
2569 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2571 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2572 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2573 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2574 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2575 ok( !ret
, "message %04x available\n", msg
.message
);
2577 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2579 keybd_event(VK_SPACE
, 0, 0, 0);
2580 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2581 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2582 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2583 ok( !ret
, "message %04x available\n", msg
.message
);
2586 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2588 flush_events( TRUE
);
2590 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2591 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2592 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2593 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2594 ok( !ret
, "message %04x available\n", msg
.message
);
2596 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2598 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2599 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2600 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2601 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2602 ok( !ret
, "message %04x available\n", msg
.message
);
2604 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2606 keybd_event(VK_SPACE
, 0, 0, 0);
2607 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2608 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_SYSKEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2609 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2610 ok( !ret
, "message %04x available\n", msg
.message
);
2613 static void test_mouse_input(HWND hwnd
)
2623 ShowWindow(hwnd
, SW_SHOW
);
2626 GetWindowRect(hwnd
, &rc
);
2627 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2629 popup
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_POPUP
,
2630 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
,
2633 ShowWindow(popup
, SW_SHOW
);
2634 UpdateWindow(popup
);
2636 GetWindowRect(popup
, &rc
);
2637 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2639 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
2640 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
2641 trace("setting cursor to (%d,%d)\n", x
, y
);
2645 ok(x
== pt
.x
&& y
== pt
.y
, "wrong cursor pos (%d,%d), expected (%d,%d)\n", pt
.x
, pt
.y
, x
, y
);
2647 flush_events( TRUE
);
2649 /* Check that setting the same position will generate WM_MOUSEMOVE */
2652 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2653 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2654 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
);
2656 /* force the system to update its internal queue mouse position,
2657 * otherwise it won't generate relative mouse movements below.
2659 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2660 flush_events( TRUE
);
2663 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2664 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2665 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2666 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2667 if (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
2668 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2669 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2670 ok( !ret
, "message %04x available\n", msg
.message
);
2672 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2673 ShowWindow(popup
, SW_HIDE
);
2674 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2675 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2676 flush_events( TRUE
);
2678 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2679 ShowWindow(hwnd
, SW_HIDE
);
2680 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2681 ok( !ret
, "message %04x available\n", msg
.message
);
2682 flush_events( TRUE
);
2684 /* test mouse clicks */
2686 ShowWindow(hwnd
, SW_SHOW
);
2687 flush_events( TRUE
);
2688 ShowWindow(popup
, SW_SHOW
);
2689 flush_events( TRUE
);
2691 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2692 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2693 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2694 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2696 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2697 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2698 msg
.hwnd
, popup
, msg
.message
);
2699 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2700 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2701 msg
.hwnd
, popup
, msg
.message
);
2703 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2704 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2705 msg
.hwnd
, popup
, msg
.message
);
2706 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2707 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2708 msg
.hwnd
, popup
, msg
.message
);
2710 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2711 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p/%p message %04x\n",
2712 msg
.hwnd
, popup
, msg
.message
);
2713 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2714 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p/%p message %04x\n",
2715 msg
.hwnd
, popup
, msg
.message
);
2717 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2718 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2719 msg
.hwnd
, popup
, msg
.message
);
2720 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "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
);
2724 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2725 ok(!ret
, "message %04x available\n", msg
.message
);
2727 ShowWindow(popup
, SW_HIDE
);
2728 flush_events( TRUE
);
2730 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2731 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2732 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2733 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2735 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2736 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2737 msg
.hwnd
, hwnd
, msg
.message
);
2738 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2739 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2740 msg
.hwnd
, hwnd
, msg
.message
);
2742 test_lbuttondown_flag
= TRUE
;
2743 SendMessageA(hwnd
, WM_COMMAND
, (WPARAM
)popup
, 0);
2744 test_lbuttondown_flag
= FALSE
;
2746 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2747 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2748 msg
.hwnd
, popup
, msg
.message
);
2749 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2750 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2751 msg
.hwnd
, popup
, msg
.message
);
2752 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2754 /* Test WM_MOUSEACTIVATE */
2755 #define TEST_MOUSEACTIVATE(A,B) \
2756 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2757 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2759 TEST_MOUSEACTIVATE(HTERROR
,MA_ACTIVATE
);
2760 TEST_MOUSEACTIVATE(HTTRANSPARENT
,MA_ACTIVATE
);
2761 TEST_MOUSEACTIVATE(HTNOWHERE
,MA_ACTIVATE
);
2762 TEST_MOUSEACTIVATE(HTCLIENT
,MA_ACTIVATE
);
2763 TEST_MOUSEACTIVATE(HTCAPTION
,MA_ACTIVATE
);
2764 TEST_MOUSEACTIVATE(HTSYSMENU
,MA_ACTIVATE
);
2765 TEST_MOUSEACTIVATE(HTSIZE
,MA_ACTIVATE
);
2766 TEST_MOUSEACTIVATE(HTMENU
,MA_ACTIVATE
);
2767 TEST_MOUSEACTIVATE(HTHSCROLL
,MA_ACTIVATE
);
2768 TEST_MOUSEACTIVATE(HTVSCROLL
,MA_ACTIVATE
);
2769 TEST_MOUSEACTIVATE(HTMINBUTTON
,MA_ACTIVATE
);
2770 TEST_MOUSEACTIVATE(HTMAXBUTTON
,MA_ACTIVATE
);
2771 TEST_MOUSEACTIVATE(HTLEFT
,MA_ACTIVATE
);
2772 TEST_MOUSEACTIVATE(HTRIGHT
,MA_ACTIVATE
);
2773 TEST_MOUSEACTIVATE(HTTOP
,MA_ACTIVATE
);
2774 TEST_MOUSEACTIVATE(HTTOPLEFT
,MA_ACTIVATE
);
2775 TEST_MOUSEACTIVATE(HTTOPRIGHT
,MA_ACTIVATE
);
2776 TEST_MOUSEACTIVATE(HTBOTTOM
,MA_ACTIVATE
);
2777 TEST_MOUSEACTIVATE(HTBOTTOMLEFT
,MA_ACTIVATE
);
2778 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT
,MA_ACTIVATE
);
2779 TEST_MOUSEACTIVATE(HTBORDER
,MA_ACTIVATE
);
2780 TEST_MOUSEACTIVATE(HTOBJECT
,MA_ACTIVATE
);
2781 TEST_MOUSEACTIVATE(HTCLOSE
,MA_ACTIVATE
);
2782 TEST_MOUSEACTIVATE(HTHELP
,MA_ACTIVATE
);
2784 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2785 flush_events( TRUE
);
2787 DestroyWindow(popup
);
2790 static void test_validatergn(HWND hwnd
)
2796 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_VISIBLE
, 10, 10, 10, 10, hwnd
, 0, 0, NULL
);
2797 ShowWindow(hwnd
, SW_SHOW
);
2798 UpdateWindow( hwnd
);
2799 /* test that ValidateRect validates children*/
2800 InvalidateRect( child
, NULL
, 1);
2801 GetWindowRect( child
, &rc
);
2802 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2803 ret
= GetUpdateRect( child
, &rc2
, 0);
2804 ok( rc2
.right
> rc2
.left
&& rc2
.bottom
> rc2
.top
,
2805 "Update rectangle is empty!\n");
2806 ValidateRect( hwnd
, &rc
);
2807 ret
= GetUpdateRect( child
, &rc2
, 0);
2808 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2809 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
2810 rc2
.right
, rc2
.bottom
);
2812 /* now test ValidateRgn */
2813 InvalidateRect( child
, NULL
, 1);
2814 GetWindowRect( child
, &rc
);
2815 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2816 rgn
= CreateRectRgnIndirect( &rc
);
2817 ValidateRgn( hwnd
, rgn
);
2818 ret
= GetUpdateRect( child
, &rc2
, 0);
2819 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2820 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
2821 rc2
.right
, rc2
.bottom
);
2824 DestroyWindow( child
);
2827 static void nccalchelper(HWND hwnd
, INT x
, INT y
, RECT
*prc
)
2829 MoveWindow( hwnd
, 0, 0, x
, y
, 0);
2830 GetWindowRect( hwnd
, prc
);
2831 trace("window rect is %d,%d - %d,%d\n",
2832 prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
2833 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)prc
);
2834 trace("nccalc rect is %d,%d - %d,%d\n",
2835 prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
2838 static void test_nccalcscroll(HWND parent
)
2841 INT sbheight
= GetSystemMetrics( SM_CYHSCROLL
);
2842 INT sbwidth
= GetSystemMetrics( SM_CXVSCROLL
);
2843 HWND hwnd
= CreateWindowExA(0, "static", NULL
,
2844 WS_CHILD
| WS_VISIBLE
| WS_VSCROLL
| WS_HSCROLL
,
2845 10, 10, 200, 200, parent
, 0, 0, NULL
);
2846 ShowWindow( parent
, SW_SHOW
);
2847 UpdateWindow( parent
);
2849 /* test window too low for a horizontal scroll bar */
2850 nccalchelper( hwnd
, 100, sbheight
, &rc1
);
2851 ok( rc1
.bottom
- rc1
.top
== sbheight
, "Height should be %d size is %d,%d - %d,%d\n",
2852 sbheight
, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2854 /* test window just high enough for a horizontal scroll bar */
2855 nccalchelper( hwnd
, 100, sbheight
+ 1, &rc1
);
2856 ok( rc1
.bottom
- rc1
.top
== 1, "Height should be %d size is %d,%d - %d,%d\n",
2857 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2859 /* test window too narrow for a vertical scroll bar */
2860 nccalchelper( hwnd
, sbwidth
- 1, 100, &rc1
);
2861 ok( rc1
.right
- rc1
.left
== sbwidth
- 1 , "Width should be %d size is %d,%d - %d,%d\n",
2862 sbwidth
- 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2864 /* test window just wide enough for a vertical scroll bar */
2865 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
2866 ok( rc1
.right
- rc1
.left
== 0, "Width should be %d size is %d,%d - %d,%d\n",
2867 0, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2869 /* same test, but with client edge: not enough width */
2870 SetWindowLong( hwnd
, GWL_EXSTYLE
, WS_EX_CLIENTEDGE
| GetWindowLong( hwnd
, GWL_EXSTYLE
));
2871 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
2872 ok( rc1
.right
- rc1
.left
== sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
),
2873 "Width should be %d size is %d,%d - %d,%d\n",
2874 sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
), rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2876 DestroyWindow( hwnd
);
2879 static void test_SetParent(void)
2882 HWND desktop
= GetDesktopWindow();
2884 BOOL is_win9x
= GetWindowLongPtrW(desktop
, GWLP_WNDPROC
) == 0;
2885 HWND parent
, child1
, child2
, child3
, child4
, sibling
;
2887 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
2888 100, 100, 200, 200, 0, 0, 0, NULL
);
2889 assert(parent
!= 0);
2890 child1
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
2891 0, 0, 50, 50, parent
, 0, 0, NULL
);
2892 assert(child1
!= 0);
2893 child2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
2894 0, 0, 50, 50, child1
, 0, 0, NULL
);
2895 assert(child2
!= 0);
2896 child3
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
2897 0, 0, 50, 50, child2
, 0, 0, NULL
);
2898 assert(child3
!= 0);
2899 child4
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
2900 0, 0, 50, 50, child3
, 0, 0, NULL
);
2901 assert(child4
!= 0);
2903 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2904 parent
, child1
, child2
, child3
, child4
);
2906 check_parents(parent
, desktop
, 0, 0, 0, parent
, parent
);
2907 check_parents(child1
, parent
, parent
, parent
, 0, parent
, parent
);
2908 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
2909 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
2910 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
2912 ok(!IsChild(desktop
, parent
), "wrong parent/child %p/%p\n", desktop
, parent
);
2913 ok(!IsChild(desktop
, child1
), "wrong parent/child %p/%p\n", desktop
, child1
);
2914 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
2915 ok(!IsChild(desktop
, child3
), "wrong parent/child %p/%p\n", desktop
, child3
);
2916 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
2918 ok(IsChild(parent
, child1
), "wrong parent/child %p/%p\n", parent
, child1
);
2919 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
2920 ok(!IsChild(parent
, child2
), "wrong parent/child %p/%p\n", parent
, child2
);
2921 ok(!IsChild(child1
, child2
), "wrong parent/child %p/%p\n", child1
, child2
);
2922 ok(!IsChild(parent
, child3
), "wrong parent/child %p/%p\n", parent
, child3
);
2923 ok(IsChild(child2
, child3
), "wrong parent/child %p/%p\n", child2
, child3
);
2924 ok(!IsChild(parent
, child4
), "wrong parent/child %p/%p\n", parent
, child4
);
2925 ok(!IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
2926 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
2928 if (!is_win9x
) /* Win9x doesn't survive this test */
2930 ok(!SetParent(parent
, child1
), "SetParent should fail\n");
2931 ok(!SetParent(child2
, child3
), "SetParent should fail\n");
2932 ok(SetParent(child1
, parent
) != 0, "SetParent should not fail\n");
2933 ok(SetParent(parent
, child2
) != 0, "SetParent should not fail\n");
2934 ok(SetParent(parent
, child3
) != 0, "SetParent should not fail\n");
2935 ok(!SetParent(child2
, parent
), "SetParent should fail\n");
2936 ok(SetParent(parent
, child4
) != 0, "SetParent should not fail\n");
2938 check_parents(parent
, child4
, child4
, 0, 0, child4
, parent
);
2939 check_parents(child1
, parent
, parent
, parent
, 0, child4
, parent
);
2940 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
2941 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
2942 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
2945 hMenu
= CreateMenu();
2946 sibling
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
2947 100, 100, 200, 200, 0, hMenu
, 0, NULL
);
2948 assert(sibling
!= 0);
2950 ok(SetParent(sibling
, parent
) != 0, "SetParent should not fail\n");
2951 ok(GetMenu(sibling
) == hMenu
, "SetParent should not remove menu\n");
2953 ret
= DestroyWindow(parent
);
2954 ok( ret
, "DestroyWindow() error %d\n", GetLastError());
2956 ok(!IsWindow(parent
), "parent still exists\n");
2957 ok(!IsWindow(sibling
), "sibling still exists\n");
2958 ok(!IsWindow(child1
), "child1 still exists\n");
2959 ok(!IsWindow(child2
), "child2 still exists\n");
2960 ok(!IsWindow(child3
), "child3 still exists\n");
2961 ok(!IsWindow(child4
), "child4 still exists\n");
2964 static LRESULT WINAPI
StyleCheckProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2966 LPCREATESTRUCT lpcs
;
2973 lpcs
= (LPCREATESTRUCT
)lparam
;
2974 lpss
= (LPSTYLESTRUCT
)lpcs
->lpCreateParams
;
2977 if ((lpcs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
2978 ((!(lpcs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
2979 (lpcs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
2980 ok(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
, "Window should have WS_EX_WINDOWEDGE style\n");
2982 ok(!(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
2984 ok((lpss
->styleOld
& ~WS_EX_WINDOWEDGE
) == (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
),
2985 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2986 (lpss
->styleOld
& ~WS_EX_WINDOWEDGE
), (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
));
2988 ok(lpss
->styleNew
== lpcs
->style
,
2989 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
2990 lpss
->styleNew
, lpcs
->style
);
2994 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
2997 static ATOM atomStyleCheckClass
;
2999 static void register_style_check_class(void)
3007 GetModuleHandle(NULL
),
3009 LoadCursor(NULL
, IDC_ARROW
),
3010 (HBRUSH
)(COLOR_BTNFACE
+1),
3012 TEXT("WineStyleCheck"),
3015 atomStyleCheckClass
= RegisterClass(&wc
);
3018 static void check_window_style(DWORD dwStyleIn
, DWORD dwExStyleIn
, DWORD dwStyleOut
, DWORD dwExStyleOut
)
3020 DWORD dwActualStyle
;
3021 DWORD dwActualExStyle
;
3024 HWND hwndParent
= NULL
;
3026 ss
.styleNew
= dwStyleIn
;
3027 ss
.styleOld
= dwExStyleIn
;
3029 if (dwStyleIn
& WS_CHILD
)
3031 hwndParent
= CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3032 WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
3035 hwnd
= CreateWindowEx(dwExStyleIn
, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3036 dwStyleIn
, 0, 0, 0, 0, hwndParent
, NULL
, NULL
, &ss
);
3039 flush_events( TRUE
);
3041 dwActualStyle
= GetWindowLong(hwnd
, GWL_STYLE
);
3042 dwActualExStyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
3043 ok((dwActualStyle
== dwStyleOut
) && (dwActualExStyle
== dwExStyleOut
),
3044 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3045 dwActualStyle
, dwStyleOut
, dwActualExStyle
, dwExStyleOut
);
3047 DestroyWindow(hwnd
);
3048 if (hwndParent
) DestroyWindow(hwndParent
);
3051 /* tests what window styles the window manager automatically adds */
3052 static void test_window_styles(void)
3054 register_style_check_class();
3056 check_window_style(0, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
3057 check_window_style(WS_OVERLAPPEDWINDOW
, 0, WS_CLIPSIBLINGS
|WS_OVERLAPPEDWINDOW
, WS_EX_WINDOWEDGE
);
3058 check_window_style(WS_CHILD
, 0, WS_CHILD
, 0);
3059 check_window_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
3060 check_window_style(0, WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_TOOLWINDOW
);
3061 check_window_style(WS_POPUP
, 0, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3062 check_window_style(WS_POPUP
, WS_EX_WINDOWEDGE
, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3063 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
, WS_CHILD
, WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3064 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
|WS_EX_STATICEDGE
, WS_CHILD
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3065 check_window_style(WS_CAPTION
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
);
3066 check_window_style(0, WS_EX_APPWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_APPWINDOW
|WS_EX_WINDOWEDGE
);
3069 static void test_scrollvalidate( HWND parent
)
3072 HRGN hrgn
=CreateRectRgn(0,0,0,0);
3073 HRGN exprgn
, tmprgn
, clipping
;
3074 RECT rc
, rcu
, cliprc
;
3075 /* create two overlapping child windows. The visual region
3076 * of hwnd1 is clipped by the overlapping part of
3077 * hwnd2 because of the WS_CLIPSIBLING style */
3080 clipping
= CreateRectRgn(0,0,0,0);
3081 tmprgn
= CreateRectRgn(0,0,0,0);
3082 exprgn
= CreateRectRgn(0,0,0,0);
3083 hwnd2
= CreateWindowExA(0, "static", NULL
,
3084 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3085 75, 30, 100, 100, parent
, 0, 0, NULL
);
3086 hwnd1
= CreateWindowExA(0, "static", NULL
,
3087 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3088 25, 50, 100, 100, parent
, 0, 0, NULL
);
3089 ShowWindow( parent
, SW_SHOW
);
3090 UpdateWindow( parent
);
3091 GetClientRect( hwnd1
, &rc
);
3093 SetRectRgn( clipping
, 10, 10, 90, 90);
3094 hdc
= GetDC( hwnd1
);
3095 /* for a visual touch */
3096 TextOut( hdc
, 0,10, "0123456789", 10);
3097 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3098 if (winetest_debug
> 0) dump_region(hrgn
);
3099 /* create a region with what is expected */
3100 SetRectRgn( exprgn
, 39,0,49,74);
3101 SetRectRgn( tmprgn
, 88,79,98,93);
3102 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3103 SetRectRgn( tmprgn
, 0,93,98,98);
3104 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3105 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3106 trace("update rect is %d,%d - %d,%d\n",
3107 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3108 /* now with clipping region */
3109 SelectClipRgn( hdc
, clipping
);
3110 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3111 if (winetest_debug
> 0) dump_region(hrgn
);
3112 /* create a region with what is expected */
3113 SetRectRgn( exprgn
, 39,10,49,74);
3114 SetRectRgn( tmprgn
, 80,79,90,85);
3115 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3116 SetRectRgn( tmprgn
, 10,85,90,90);
3117 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3118 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3119 trace("update rect is %d,%d - %d,%d\n",
3120 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3121 ReleaseDC( hwnd1
, hdc
);
3123 /* test scrolling a window with an update region */
3124 DestroyWindow( hwnd2
);
3125 ValidateRect( hwnd1
, NULL
);
3126 SetRect( &rc
, 40,40, 50,50);
3127 InvalidateRect( hwnd1
, &rc
, 1);
3128 GetClientRect( hwnd1
, &rc
);
3130 ScrollWindowEx( hwnd1
, -10, 0, &rc
, &cliprc
, hrgn
, &rcu
,
3131 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3132 if (winetest_debug
> 0) dump_region(hrgn
);
3133 SetRectRgn( exprgn
, 88,0,98,98);
3134 SetRectRgn( tmprgn
, 30, 40, 50, 50);
3135 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3136 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3138 /* clear an update region */
3139 UpdateWindow( hwnd1
);
3141 SetRect( &rc
, 0,40, 100,60);
3142 SetRect( &cliprc
, 0,0, 100,100);
3143 ScrollWindowEx( hwnd1
, 0, -25, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3144 if (winetest_debug
> 0) dump_region( hrgn
);
3145 SetRectRgn( exprgn
, 0, 40, 98, 60 );
3146 ok( EqualRgn( exprgn
, hrgn
), "wrong update region in excessive scroll\n");
3148 /* now test ScrollWindowEx with a combination of
3149 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3150 /* make hwnd2 the child of hwnd1 */
3151 hwnd2
= CreateWindowExA(0, "static", NULL
,
3152 WS_CHILD
| WS_VISIBLE
| WS_BORDER
,
3153 50, 50, 100, 100, hwnd1
, 0, 0, NULL
);
3154 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPSIBLINGS
);
3155 GetClientRect( hwnd1
, &rc
);
3158 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3159 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3160 ValidateRect( hwnd1
, NULL
);
3161 ValidateRect( hwnd2
, NULL
);
3162 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
,
3163 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3164 if (winetest_debug
> 0) dump_region(hrgn
);
3165 SetRectRgn( exprgn
, 88,0,98,88);
3166 SetRectRgn( tmprgn
, 0,88,98,98);
3167 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3168 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3170 /* SW_SCROLLCHILDREN */
3171 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3172 ValidateRect( hwnd1
, NULL
);
3173 ValidateRect( hwnd2
, NULL
);
3174 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3175 if (winetest_debug
> 0) dump_region(hrgn
);
3176 /* expected region is the same as in previous test */
3177 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3179 /* no SW_SCROLLCHILDREN */
3180 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3181 ValidateRect( hwnd1
, NULL
);
3182 ValidateRect( hwnd2
, NULL
);
3183 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3184 if (winetest_debug
> 0) dump_region(hrgn
);
3185 /* expected region is the same as in previous test */
3186 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3188 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3189 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3190 ValidateRect( hwnd1
, NULL
);
3191 ValidateRect( hwnd2
, NULL
);
3192 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3193 if (winetest_debug
> 0) dump_region(hrgn
);
3194 SetRectRgn( exprgn
, 88,0,98,20);
3195 SetRectRgn( tmprgn
, 20,20,98,30);
3196 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3197 SetRectRgn( tmprgn
, 20,30,30,88);
3198 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3199 SetRectRgn( tmprgn
, 0,88,30,98);
3200 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3201 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3204 DeleteObject( hrgn
);
3205 DeleteObject( exprgn
);
3206 DeleteObject( tmprgn
);
3207 DestroyWindow( hwnd1
);
3208 DestroyWindow( hwnd2
);
3211 /* couple of tests of return values of scrollbar functions
3212 * called on a scrollbarless window */
3213 static void test_scroll(void)
3218 HWND hwnd
= CreateWindowExA(0, "Static", "Wine test window",
3219 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_POPUP
,
3220 100, 100, 200, 200, 0, 0, 0, NULL
);
3222 ret
= GetScrollRange( hwnd
, SB_HORZ
, &min
, &max
);
3223 ok( ret
, "GetScrollRange returns FALSE\n");
3224 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3225 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3226 si
.cbSize
= sizeof( si
);
3227 si
.fMask
= SIF_PAGE
;
3228 si
.nPage
= 0xdeadbeef;
3229 ret
= GetScrollInfo( hwnd
, SB_HORZ
, &si
);
3230 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3231 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3233 ret
= GetScrollRange( hwnd
, SB_VERT
, &min
, &max
);
3234 ok( ret
, "GetScrollRange returns FALSE\n");
3235 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3236 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3237 si
.cbSize
= sizeof( si
);
3238 si
.fMask
= SIF_PAGE
;
3239 si
.nPage
= 0xdeadbeef;
3240 ret
= GetScrollInfo( hwnd
, SB_VERT
, &si
);
3241 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3242 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3244 DestroyWindow( hwnd
);
3247 static void test_scrolldc( HWND parent
)
3250 HRGN exprgn
, tmprgn
, hrgn
;
3251 RECT rc
, rc2
, rcu
, cliprc
;
3255 hrgn
= CreateRectRgn(0,0,0,0);
3256 tmprgn
= CreateRectRgn(0,0,0,0);
3257 exprgn
= CreateRectRgn(0,0,0,0);
3259 hwnd1
= CreateWindowExA(0, "static", NULL
,
3260 WS_CHILD
| WS_VISIBLE
,
3261 25, 50, 100, 100, parent
, 0, 0, NULL
);
3262 ShowWindow( parent
, SW_SHOW
);
3263 UpdateWindow( parent
);
3264 flush_events( TRUE
);
3265 GetClientRect( hwnd1
, &rc
);
3266 hdc
= GetDC( hwnd1
);
3267 /* paint the upper half of the window black */
3269 rc2
.bottom
= ( rc
.top
+ rc
.bottom
) /2;
3270 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3271 /* clip region is the lower half */
3273 cliprc
.top
= (rc
.top
+ rc
.bottom
) /2;
3274 /* test whether scrolled pixels are properly clipped */
3275 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3276 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3277 /* this scroll should not cause any visible changes */
3278 ScrollDC( hdc
, 5, -20, &rc
, &cliprc
, hrgn
, &rcu
);
3279 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3280 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3281 /* test with NULL clip rect */
3282 ScrollDC( hdc
, 20, -20, &rc
, NULL
, hrgn
, &rcu
);
3283 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3284 trace("update rect: %d,%d - %d,%d\n",
3285 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3286 if (winetest_debug
> 0) dump_region(hrgn
);
3287 SetRect(&rc2
, 0, 0, 100, 100);
3288 ok(EqualRect(&rcu
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3289 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
3291 SetRectRgn( exprgn
, 0, 0, 20, 80);
3292 SetRectRgn( tmprgn
, 0, 80, 100, 100);
3293 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3294 if (winetest_debug
> 0) dump_region(exprgn
);
3295 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3296 /* test clip rect > scroll rect */
3297 FillRect( hdc
, &rc
, GetStockObject(WHITE_BRUSH
));
3299 InflateRect( &rc2
, -(rc
.right
-rc
.left
)/4, -(rc
.bottom
-rc
.top
)/4);
3300 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3301 ScrollDC( hdc
, 10, 10, &rc2
, &rc
, hrgn
, &rcu
);
3302 SetRectRgn( exprgn
, 25, 25, 75, 35);
3303 SetRectRgn( tmprgn
, 25, 35, 35, 75);
3304 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3305 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3306 colr
= GetPixel( hdc
, 80, 80);
3307 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3308 trace("update rect: %d,%d - %d,%d\n",
3309 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3310 if (winetest_debug
> 0) dump_region(hrgn
);
3314 DeleteObject(exprgn
);
3315 DeleteObject(tmprgn
);
3316 DestroyWindow(hwnd1
);
3319 static void test_params(void)
3324 /* Just a param check */
3325 SetLastError(0xdeadbeef);
3326 rc
= GetWindowText(hwndMain2
, NULL
, 1024);
3327 ok( rc
==0, "GetWindowText: rc=%d err=%d\n",rc
,GetLastError());
3329 SetLastError(0xdeadbeef);
3330 hwnd
=CreateWindow("LISTBOX", "TestList",
3331 (LBS_STANDARD
& ~LBS_SORT
),
3333 NULL
, (HMENU
)1, NULL
, 0);
3335 ok(!hwnd
, "CreateWindow with invalid menu handle should fail\n");
3336 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
|| /* NT */
3337 GetLastError() == 0xdeadbeef, /* Win9x */
3338 "wrong last error value %d\n", GetLastError());
3341 static void test_AWRwindow(LPCSTR
class, LONG style
, LONG exStyle
, BOOL menu
)
3345 hwnd
= CreateWindowEx(exStyle
, class, class, style
,
3352 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style
, exStyle
);
3355 ShowWindow(hwnd
, SW_SHOW
);
3357 test_nonclient_area(hwnd
);
3360 DestroyWindow(hwnd
);
3363 static BOOL
AWR_init(void)
3367 class.style
= CS_HREDRAW
| CS_VREDRAW
;
3368 class.lpfnWndProc
= DefWindowProcA
;
3369 class.cbClsExtra
= 0;
3370 class.cbWndExtra
= 0;
3371 class.hInstance
= 0;
3372 class.hIcon
= LoadIcon (0, IDI_APPLICATION
);
3373 class.hCursor
= LoadCursor (0, IDC_ARROW
);
3374 class.hbrBackground
= 0;
3375 class.lpszMenuName
= 0;
3376 class.lpszClassName
= szAWRClass
;
3378 if (!RegisterClass (&class)) {
3379 ok(FALSE
, "RegisterClass failed\n");
3383 hmenu
= CreateMenu();
3386 ok(hmenu
!= 0, "Failed to create menu\n");
3387 ok(AppendMenu(hmenu
, MF_STRING
, 1, "Test!"), "Failed to create menu item\n");
3393 static void test_AWR_window_size(BOOL menu
)
3397 WS_MAXIMIZE
, WS_BORDER
, WS_DLGFRAME
,
3400 WS_MINIMIZEBOX
, WS_MAXIMIZEBOX
,
3401 WS_HSCROLL
, WS_VSCROLL
3405 WS_EX_TOOLWINDOW
, WS_EX_WINDOWEDGE
,
3408 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3409 WS_EX_DLGMODALFRAME
,
3416 /* A exhaustive check of all the styles takes too long
3417 * so just do a (hopefully representative) sample
3419 for (i
= 0; i
< COUNTOF(styles
); ++i
)
3420 test_AWRwindow(szAWRClass
, styles
[i
], 0, menu
);
3421 for (i
= 0; i
< COUNTOF(exStyles
); ++i
) {
3422 test_AWRwindow(szAWRClass
, WS_POPUP
, exStyles
[i
], menu
);
3423 test_AWRwindow(szAWRClass
, WS_THICKFRAME
, exStyles
[i
], menu
);
3428 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3430 static void test_AdjustWindowRect(void)
3435 SHOWSYSMETRIC(SM_CYCAPTION
);
3436 SHOWSYSMETRIC(SM_CYSMCAPTION
);
3437 SHOWSYSMETRIC(SM_CYMENU
);
3438 SHOWSYSMETRIC(SM_CXEDGE
);
3439 SHOWSYSMETRIC(SM_CYEDGE
);
3440 SHOWSYSMETRIC(SM_CXVSCROLL
);
3441 SHOWSYSMETRIC(SM_CYHSCROLL
);
3442 SHOWSYSMETRIC(SM_CXFRAME
);
3443 SHOWSYSMETRIC(SM_CYFRAME
);
3444 SHOWSYSMETRIC(SM_CXDLGFRAME
);
3445 SHOWSYSMETRIC(SM_CYDLGFRAME
);
3446 SHOWSYSMETRIC(SM_CXBORDER
);
3447 SHOWSYSMETRIC(SM_CYBORDER
);
3449 test_AWR_window_size(FALSE
);
3450 test_AWR_window_size(TRUE
);
3454 #undef SHOWSYSMETRIC
3457 /* Global variables to trigger exit from loop */
3458 static int redrawComplete
, WMPAINT_count
;
3460 static LRESULT WINAPI
redraw_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3465 trace("doing WM_PAINT %d\n", WMPAINT_count
);
3467 if (WMPAINT_count
> 10 && redrawComplete
== 0) {
3469 BeginPaint(hwnd
, &ps
);
3470 EndPaint(hwnd
, &ps
);
3475 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3478 /* Ensure we exit from RedrawNow regardless of invalidated area */
3479 static void test_redrawnow(void)
3484 cls
.style
= CS_DBLCLKS
;
3485 cls
.lpfnWndProc
= redraw_window_procA
;
3488 cls
.hInstance
= GetModuleHandleA(0);
3490 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3491 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3492 cls
.lpszMenuName
= NULL
;
3493 cls
.lpszClassName
= "RedrawWindowClass";
3495 if(!RegisterClassA(&cls
)) {
3496 trace("Register failed %d\n", GetLastError());
3500 hwndMain
= CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3501 CW_USEDEFAULT
, 0, 100, 100, NULL
, NULL
, 0, NULL
);
3503 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3504 ShowWindow(hwndMain
, SW_SHOW
);
3505 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3506 RedrawWindow(hwndMain
, NULL
,NULL
,RDW_UPDATENOW
| RDW_ALLCHILDREN
);
3507 ok( WMPAINT_count
== 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3508 redrawComplete
= TRUE
;
3509 ok( WMPAINT_count
< 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count
);
3512 DestroyWindow( hwndMain
);
3515 struct parentdc_stat
{
3521 struct parentdc_test
{
3522 struct parentdc_stat main
, main_todo
;
3523 struct parentdc_stat child1
, child1_todo
;
3524 struct parentdc_stat child2
, child2_todo
;
3527 static LRESULT WINAPI
parentdc_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3532 struct parentdc_stat
*t
= (struct parentdc_stat
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
3537 trace("doing WM_PAINT on %p\n", hwnd
);
3538 GetClientRect(hwnd
, &rc
);
3539 CopyRect(&t
->client
, &rc
);
3540 trace("client rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3541 GetWindowRect(hwnd
, &rc
);
3542 trace("window rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3543 BeginPaint(hwnd
, &ps
);
3544 CopyRect(&t
->paint
, &ps
.rcPaint
);
3545 GetClipBox(ps
.hdc
, &rc
);
3546 CopyRect(&t
->clip
, &rc
);
3547 trace("clip rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3548 trace("paint rect (%d, %d)-(%d, %d)\n", ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
3549 EndPaint(hwnd
, &ps
);
3552 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3555 static void zero_parentdc_stat(struct parentdc_stat
*t
)
3557 SetRectEmpty(&t
->client
);
3558 SetRectEmpty(&t
->clip
);
3559 SetRectEmpty(&t
->paint
);
3562 static void zero_parentdc_test(struct parentdc_test
*t
)
3564 zero_parentdc_stat(&t
->main
);
3565 zero_parentdc_stat(&t
->child1
);
3566 zero_parentdc_stat(&t
->child2
);
3569 #define parentdc_field_ok(t, w, r, f, got) \
3570 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3571 ": expected %d, got %d\n", \
3574 #define parentdc_todo_field_ok(t, w, r, f, got) \
3575 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3576 else parentdc_field_ok(t, w, r, f, got)
3578 #define parentdc_rect_ok(t, w, r, got) \
3579 parentdc_todo_field_ok(t, w, r, left, got); \
3580 parentdc_todo_field_ok(t, w, r, top, got); \
3581 parentdc_todo_field_ok(t, w, r, right, got); \
3582 parentdc_todo_field_ok(t, w, r, bottom, got);
3584 #define parentdc_win_ok(t, w, got) \
3585 parentdc_rect_ok(t, w, client, got); \
3586 parentdc_rect_ok(t, w, clip, got); \
3587 parentdc_rect_ok(t, w, paint, got);
3589 #define parentdc_ok(t, got) \
3590 parentdc_win_ok(t, main, got); \
3591 parentdc_win_ok(t, child1, got); \
3592 parentdc_win_ok(t, child2, got);
3594 static void test_csparentdc(void)
3596 WNDCLASSA clsMain
, cls
;
3597 HWND hwndMain
, hwnd1
, hwnd2
;
3600 struct parentdc_test test_answer
;
3602 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3603 const struct parentdc_test test1
=
3605 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo
,
3606 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3607 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3610 const struct parentdc_test test2
=
3612 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo
,
3613 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3614 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3617 const struct parentdc_test test3
=
3619 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3620 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3621 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3624 const struct parentdc_test test4
=
3626 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo
,
3627 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo
,
3628 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3631 const struct parentdc_test test5
=
3633 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo
,
3634 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3635 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3638 const struct parentdc_test test6
=
3640 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3641 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3642 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3645 const struct parentdc_test test7
=
3647 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3648 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3649 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3653 clsMain
.style
= CS_DBLCLKS
;
3654 clsMain
.lpfnWndProc
= parentdc_window_procA
;
3655 clsMain
.cbClsExtra
= 0;
3656 clsMain
.cbWndExtra
= 0;
3657 clsMain
.hInstance
= GetModuleHandleA(0);
3659 clsMain
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3660 clsMain
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3661 clsMain
.lpszMenuName
= NULL
;
3662 clsMain
.lpszClassName
= "ParentDcMainWindowClass";
3664 if(!RegisterClassA(&clsMain
)) {
3665 trace("Register failed %d\n", GetLastError());
3669 cls
.style
= CS_DBLCLKS
| CS_PARENTDC
;
3670 cls
.lpfnWndProc
= parentdc_window_procA
;
3673 cls
.hInstance
= GetModuleHandleA(0);
3675 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3676 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3677 cls
.lpszMenuName
= NULL
;
3678 cls
.lpszClassName
= "ParentDcWindowClass";
3680 if(!RegisterClassA(&cls
)) {
3681 trace("Register failed %d\n", GetLastError());
3685 SetRect(&rc
, 0, 0, 150, 150);
3686 AdjustWindowRectEx(&rc
, WS_OVERLAPPEDWINDOW
, FALSE
, 0);
3687 hwndMain
= CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3688 CW_USEDEFAULT
, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, NULL
, NULL
, 0, NULL
);
3689 SetWindowLongPtrA(hwndMain
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.main
);
3690 hwnd1
= CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD
,
3691 20, 20, 40, 40, hwndMain
, NULL
, 0, NULL
);
3692 SetWindowLongPtrA(hwnd1
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child1
);
3693 hwnd2
= CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD
,
3694 40, 40, 40, 40, hwndMain
, NULL
, 0, NULL
);
3695 SetWindowLongPtrA(hwnd2
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child2
);
3696 ShowWindow(hwndMain
, SW_SHOW
);
3697 ShowWindow(hwnd1
, SW_SHOW
);
3698 ShowWindow(hwnd2
, SW_SHOW
);
3699 flush_events( TRUE
);
3701 zero_parentdc_test(&test_answer
);
3702 InvalidateRect(hwndMain
, NULL
, TRUE
);
3703 flush_events( TRUE
);
3704 parentdc_ok(test1
, test_answer
);
3706 zero_parentdc_test(&test_answer
);
3707 SetRect(&rc
, 0, 0, 50, 50);
3708 InvalidateRect(hwndMain
, &rc
, TRUE
);
3709 flush_events( TRUE
);
3710 parentdc_ok(test2
, test_answer
);
3712 zero_parentdc_test(&test_answer
);
3713 SetRect(&rc
, 0, 0, 10, 10);
3714 InvalidateRect(hwndMain
, &rc
, TRUE
);
3715 flush_events( TRUE
);
3716 parentdc_ok(test3
, test_answer
);
3718 zero_parentdc_test(&test_answer
);
3719 SetRect(&rc
, 40, 40, 50, 50);
3720 InvalidateRect(hwndMain
, &rc
, TRUE
);
3721 flush_events( TRUE
);
3722 parentdc_ok(test4
, test_answer
);
3724 zero_parentdc_test(&test_answer
);
3725 SetRect(&rc
, 20, 20, 60, 60);
3726 InvalidateRect(hwndMain
, &rc
, TRUE
);
3727 flush_events( TRUE
);
3728 parentdc_ok(test5
, test_answer
);
3730 zero_parentdc_test(&test_answer
);
3731 SetRect(&rc
, 0, 0, 10, 10);
3732 InvalidateRect(hwnd1
, &rc
, TRUE
);
3733 flush_events( TRUE
);
3734 parentdc_ok(test6
, test_answer
);
3736 zero_parentdc_test(&test_answer
);
3737 SetRect(&rc
, -5, -5, 65, 65);
3738 InvalidateRect(hwnd1
, &rc
, TRUE
);
3739 flush_events( TRUE
);
3740 parentdc_ok(test7
, test_answer
);
3742 DestroyWindow(hwndMain
);
3743 DestroyWindow(hwnd1
);
3744 DestroyWindow(hwnd2
);
3747 static LRESULT WINAPI
def_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3749 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
3752 static LRESULT WINAPI
def_window_procW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3754 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
3757 static void test_IsWindowUnicode(void)
3759 static const char ansi_class_nameA
[] = "ansi class name";
3760 static const WCHAR ansi_class_nameW
[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3761 static const char unicode_class_nameA
[] = "unicode class name";
3762 static const WCHAR unicode_class_nameW
[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3767 memset(&classW
, 0, sizeof(classW
));
3768 classW
.hInstance
= GetModuleHandleA(0);
3769 classW
.lpfnWndProc
= def_window_procW
;
3770 classW
.lpszClassName
= unicode_class_nameW
;
3771 if (!RegisterClassW(&classW
)) return; /* this catches Win9x as well */
3773 memset(&classA
, 0, sizeof(classA
));
3774 classA
.hInstance
= GetModuleHandleA(0);
3775 classA
.lpfnWndProc
= def_window_procA
;
3776 classA
.lpszClassName
= ansi_class_nameA
;
3777 assert(RegisterClassA(&classA
));
3779 /* unicode class: window proc */
3780 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
3781 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3784 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3785 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3786 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3787 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3788 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3790 DestroyWindow(hwnd
);
3792 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
3793 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3796 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3797 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3798 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3799 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3800 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3802 DestroyWindow(hwnd
);
3804 /* ansi class: window proc */
3805 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
3806 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3809 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3810 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3811 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3812 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3813 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3815 DestroyWindow(hwnd
);
3817 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
3818 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3821 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3822 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3823 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3824 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3825 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3827 DestroyWindow(hwnd
);
3829 /* unicode class: class proc */
3830 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
3831 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3834 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3835 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3836 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3837 /* do not restore class window proc back to unicode */
3839 DestroyWindow(hwnd
);
3841 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
3842 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3845 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3846 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3847 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3849 DestroyWindow(hwnd
);
3851 /* ansi class: class proc */
3852 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
3853 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3856 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3857 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3858 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3859 /* do not restore class window proc back to ansi */
3861 DestroyWindow(hwnd
);
3863 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
3864 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3867 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3868 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3869 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3871 DestroyWindow(hwnd
);
3874 static LRESULT CALLBACK
minmax_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
3878 if (msg
!= WM_GETMINMAXINFO
)
3879 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3881 minmax
= (MINMAXINFO
*)lp
;
3883 if ((GetWindowLong(hwnd
, GWL_STYLE
) & WS_CHILD
))
3885 minmax
->ptReserved
.x
= 0;
3886 minmax
->ptReserved
.y
= 0;
3887 minmax
->ptMaxSize
.x
= 400;
3888 minmax
->ptMaxSize
.y
= 400;
3889 minmax
->ptMaxPosition
.x
= 300;
3890 minmax
->ptMaxPosition
.y
= 300;
3891 minmax
->ptMaxTrackSize
.x
= 200;
3892 minmax
->ptMaxTrackSize
.y
= 200;
3893 minmax
->ptMinTrackSize
.x
= 100;
3894 minmax
->ptMinTrackSize
.y
= 100;
3897 DefWindowProc(hwnd
, msg
, wp
, lp
);
3901 static int expected_cx
, expected_cy
;
3902 static RECT expected_rect
;
3904 static LRESULT CALLBACK
winsizes_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
3908 case WM_GETMINMAXINFO
:
3911 GetWindowRect( hwnd
, &rect
);
3912 ok( !rect
.left
&& !rect
.top
&& !rect
.right
&& !rect
.bottom
,
3913 "wrong rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3914 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3919 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
3921 GetWindowRect( hwnd
, &rect
);
3922 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
3923 hwnd
, msg
, cs
->cx
, cs
->cy
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3924 ok( cs
->cx
== expected_cx
, "wrong x size %d/%d\n", cs
->cx
, expected_cx
);
3925 ok( cs
->cy
== expected_cy
, "wrong y size %d/%d\n", cs
->cy
, expected_cy
);
3926 ok( rect
.right
- rect
.left
== expected_rect
.right
- expected_rect
.left
&&
3927 rect
.bottom
- rect
.top
== expected_rect
.bottom
- expected_rect
.top
,
3928 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
3929 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
3930 expected_rect
.left
, expected_rect
.top
, expected_rect
.right
, expected_rect
.bottom
);
3931 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3935 RECT rect
, *r
= (RECT
*)lp
;
3936 GetWindowRect( hwnd
, &rect
);
3937 ok( !memcmp( &rect
, r
, sizeof(rect
) ),
3938 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
3939 r
->left
, r
->top
, r
->right
, r
->bottom
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3940 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3943 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3947 static void test_CreateWindow(void)
3955 #define expect_menu(window, menu) \
3956 SetLastError(0xdeadbeef); \
3957 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
3959 #define expect_style(window, style)\
3960 ok(GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
3962 #define expect_ex_style(window, ex_style)\
3963 ok(GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
3965 hmenu
= CreateMenu();
3967 parent
= GetDesktopWindow();
3968 assert(parent
!= 0);
3970 SetLastError(0xdeadbeef);
3971 ok(IsMenu(hmenu
), "IsMenu error %d\n", GetLastError());
3974 SetLastError(0xdeadbeef);
3975 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
,
3976 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3977 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3978 expect_menu(hwnd
, 1);
3979 expect_style(hwnd
, WS_CHILD
);
3980 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
3981 DestroyWindow(hwnd
);
3983 SetLastError(0xdeadbeef);
3984 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_CAPTION
,
3985 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3986 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3987 expect_menu(hwnd
, 1);
3988 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
3989 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
3990 DestroyWindow(hwnd
);
3992 SetLastError(0xdeadbeef);
3993 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
,
3994 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3995 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3996 expect_menu(hwnd
, 1);
3997 expect_style(hwnd
, WS_CHILD
);
3998 expect_ex_style(hwnd
, 0);
3999 DestroyWindow(hwnd
);
4001 SetLastError(0xdeadbeef);
4002 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_CAPTION
,
4003 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4004 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4005 expect_menu(hwnd
, 1);
4006 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
4007 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4008 DestroyWindow(hwnd
);
4011 SetLastError(0xdeadbeef);
4012 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
4013 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4014 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4015 expect_menu(hwnd
, hmenu
);
4016 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4017 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4018 DestroyWindow(hwnd
);
4019 SetLastError(0xdeadbeef);
4020 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4021 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4023 hmenu
= CreateMenu();
4025 SetLastError(0xdeadbeef);
4026 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4027 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4028 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4029 expect_menu(hwnd
, hmenu
);
4030 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4031 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4032 DestroyWindow(hwnd
);
4033 SetLastError(0xdeadbeef);
4034 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4035 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4037 hmenu
= CreateMenu();
4039 SetLastError(0xdeadbeef);
4040 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
,
4041 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4042 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4043 expect_menu(hwnd
, hmenu
);
4044 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4045 expect_ex_style(hwnd
, 0);
4046 DestroyWindow(hwnd
);
4047 SetLastError(0xdeadbeef);
4048 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4049 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4051 hmenu
= CreateMenu();
4053 SetLastError(0xdeadbeef);
4054 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4055 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4056 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4057 expect_menu(hwnd
, hmenu
);
4058 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4059 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4060 DestroyWindow(hwnd
);
4061 SetLastError(0xdeadbeef);
4062 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4063 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4065 /* WS_CHILD | WS_POPUP */
4066 SetLastError(0xdeadbeef);
4067 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4068 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4069 ok(!hwnd
, "CreateWindowEx 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(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
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_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4080 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
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 SetLastError(0xdeadbeef);
4087 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4088 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4089 ok(!hwnd
, "CreateWindowEx should fail\n");
4090 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4092 hmenu
= CreateMenu();
4094 SetLastError(0xdeadbeef);
4095 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4096 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4097 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4098 expect_menu(hwnd
, hmenu
);
4099 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4100 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4101 DestroyWindow(hwnd
);
4102 SetLastError(0xdeadbeef);
4103 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4104 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4106 SetLastError(0xdeadbeef);
4107 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4108 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4109 ok(!hwnd
, "CreateWindowEx should fail\n");
4110 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4112 hmenu
= CreateMenu();
4114 SetLastError(0xdeadbeef);
4115 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4116 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4117 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4118 expect_menu(hwnd
, hmenu
);
4119 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4120 expect_ex_style(hwnd
, 0);
4121 DestroyWindow(hwnd
);
4122 SetLastError(0xdeadbeef);
4123 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4124 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4126 SetLastError(0xdeadbeef);
4127 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4128 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4129 ok(!hwnd
, "CreateWindowEx should fail\n");
4130 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4132 hmenu
= CreateMenu();
4134 SetLastError(0xdeadbeef);
4135 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4136 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4137 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4138 expect_menu(hwnd
, hmenu
);
4139 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4140 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4141 DestroyWindow(hwnd
);
4142 SetLastError(0xdeadbeef);
4143 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4144 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4146 /* test child window sizing */
4148 cls
.lpfnWndProc
= minmax_wnd_proc
;
4151 cls
.hInstance
= GetModuleHandle(0);
4153 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
4154 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4155 cls
.lpszMenuName
= NULL
;
4156 cls
.lpszClassName
= "MinMax_WndClass";
4157 RegisterClass(&cls
);
4159 SetLastError(0xdeadbeef);
4160 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4161 0, 0, 100, 100, 0, 0, 0, NULL
);
4162 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
4163 expect_menu(parent
, 0);
4164 expect_style(parent
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
| WS_CLIPSIBLINGS
);
4165 expect_ex_style(parent
, WS_EX_WINDOWEDGE
);
4167 memset(&minmax
, 0, sizeof(minmax
));
4168 SendMessage(parent
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4169 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxSize
.x
, minmax
.ptMaxSize
.y
);
4170 ok(IsRectEmpty(&rc_minmax
), "ptMaxSize is not empty\n");
4171 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4172 ok(IsRectEmpty(&rc_minmax
), "ptMaxTrackSize is not empty\n");
4174 GetWindowRect(parent
, &rc
);
4175 ok(!IsRectEmpty(&rc
), "parent window rect is empty\n");
4176 GetClientRect(parent
, &rc
);
4177 ok(!IsRectEmpty(&rc
), "parent client rect is empty\n");
4179 InflateRect(&rc
, 200, 200);
4180 trace("creating child with rect (%d,%d-%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4182 SetLastError(0xdeadbeef);
4183 hwnd
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4184 rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
4185 parent
, (HMENU
)1, 0, NULL
);
4186 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4187 expect_menu(hwnd
, 1);
4188 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
);
4189 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4191 memset(&minmax
, 0, sizeof(minmax
));
4192 SendMessage(hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4193 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4195 GetWindowRect(hwnd
, &rc
);
4196 OffsetRect(&rc
, -rc
.left
, -rc
.top
);
4197 ok(EqualRect(&rc
, &rc_minmax
), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4198 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
4199 rc_minmax
.left
, rc_minmax
.top
, rc_minmax
.right
, rc_minmax
.bottom
);
4200 DestroyWindow(hwnd
);
4202 cls
.lpfnWndProc
= winsizes_wnd_proc
;
4203 cls
.lpszClassName
= "Sizes_WndClass";
4204 RegisterClass(&cls
);
4206 expected_cx
= expected_cy
= 200000;
4207 SetRect( &expected_rect
, 0, 0, 200000, 200000 );
4208 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 300000, 300000, 200000, 200000, parent
, 0, 0, NULL
);
4209 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4210 GetClientRect( hwnd
, &rc
);
4211 ok( rc
.right
== 200000, "invalid rect right %u\n", rc
.right
);
4212 ok( rc
.bottom
== 200000, "invalid rect bottom %u\n", rc
.bottom
);
4213 DestroyWindow(hwnd
);
4215 expected_cx
= expected_cy
= -10;
4216 SetRect( &expected_rect
, 0, 0, 0, 0 );
4217 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -20, -20, -10, -10, parent
, 0, 0, NULL
);
4218 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4219 GetClientRect( hwnd
, &rc
);
4220 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4221 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4222 DestroyWindow(hwnd
);
4224 expected_cx
= expected_cy
= -200000;
4225 SetRect( &expected_rect
, 0, 0, 0, 0 );
4226 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -300000, -300000, -200000, -200000, parent
, 0, 0, NULL
);
4227 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4228 GetClientRect( hwnd
, &rc
);
4229 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4230 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4231 DestroyWindow(hwnd
);
4233 /* we need a parent at 0,0 so that child coordinates match */
4234 DestroyWindow(parent
);
4235 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_POPUP
, 0, 0, 100, 100, 0, 0, 0, NULL
);
4236 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
4239 expected_cy
= 0x7fffffff;
4240 SetRect( &expected_rect
, 10, 10, 110, 0x7fffffff );
4241 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 10, 10, 100, 0x7fffffff, parent
, 0, 0, NULL
);
4242 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4243 GetClientRect( hwnd
, &rc
);
4244 ok( rc
.right
== 100, "invalid rect right %u\n", rc
.right
);
4245 ok( rc
.bottom
== 0x7fffffff - 10, "invalid rect bottom %u\n", rc
.bottom
);
4246 DestroyWindow(hwnd
);
4248 expected_cx
= 0x7fffffff;
4249 expected_cy
= 0x7fffffff;
4250 SetRect( &expected_rect
, 20, 10, 0x7fffffff, 0x7fffffff );
4251 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 20, 10, 0x7fffffff, 0x7fffffff, parent
, 0, 0, NULL
);
4252 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4253 GetClientRect( hwnd
, &rc
);
4254 ok( rc
.right
== 0x7fffffff - 20, "invalid rect right %u\n", rc
.right
);
4255 ok( rc
.bottom
== 0x7fffffff - 10, "invalid rect bottom %u\n", rc
.bottom
);
4256 DestroyWindow(hwnd
);
4258 /* top level window */
4259 expected_cx
= expected_cy
= 200000;
4260 SetRect( &expected_rect
, 0, 0, GetSystemMetrics(SM_CXMAXTRACK
), GetSystemMetrics(SM_CYMAXTRACK
) );
4261 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_OVERLAPPEDWINDOW
, 300000, 300000, 200000, 200000, 0, 0, 0, NULL
);
4262 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4263 GetClientRect( hwnd
, &rc
);
4264 ok( rc
.right
<= expected_cx
, "invalid rect right %u\n", rc
.right
);
4265 ok( rc
.bottom
<= expected_cy
, "invalid rect bottom %u\n", rc
.bottom
);
4266 DestroyWindow(hwnd
);
4268 DestroyWindow(parent
);
4270 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4271 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4275 #undef expect_ex_style
4278 /* function that remembers whether the system the test is running on sets the
4279 * last error for user32 functions to make the tests stricter */
4280 static int check_error(DWORD actual
, DWORD expected
)
4282 static int sets_last_error
= -1;
4283 if (sets_last_error
== -1)
4284 sets_last_error
= (actual
!= 0xdeadbeef);
4285 return (!sets_last_error
&& (actual
== 0xdeadbeef)) || (actual
== expected
);
4288 static void test_SetWindowLong(void)
4291 WNDPROC old_window_procW
;
4293 SetLastError(0xdeadbeef);
4294 retval
= SetWindowLongPtr(NULL
, GWLP_WNDPROC
, 0);
4295 ok(!retval
, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval
);
4296 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE
),
4297 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4299 SetLastError(0xdeadbeef);
4300 retval
= SetWindowLongPtr(hwndMain
, 0xdeadbeef, 0);
4301 ok(!retval
, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval
);
4302 ok(check_error(GetLastError(), ERROR_INVALID_INDEX
),
4303 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4305 SetLastError(0xdeadbeef);
4306 retval
= SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4307 ok((WNDPROC
)retval
== main_window_procA
,
4308 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval
);
4309 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4310 retval
= GetWindowLongPtr(hwndMain
, GWLP_WNDPROC
);
4311 ok((WNDPROC
)retval
== main_window_procA
,
4312 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4313 ok(!IsWindowUnicode(hwndMain
), "hwndMain shouldn't be Unicode\n");
4315 old_window_procW
= (WNDPROC
)GetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
);
4316 SetLastError(0xdeadbeef);
4317 retval
= SetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
, 0);
4318 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED
)
4320 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4321 ok(retval
!= 0, "SetWindowLongPtr error %d\n", GetLastError());
4322 ok((WNDPROC
)retval
== old_window_procW
,
4323 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4324 ok(IsWindowUnicode(hwndMain
), "hwndMain should now be Unicode\n");
4326 /* set it back to ANSI */
4327 SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4331 static void test_ShowWindow(void)
4338 SetRect(&rcMain
, 120, 120, 210, 210);
4340 hwnd
= CreateWindowEx(0, "MainWindowClass", NULL
,
4341 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4342 WS_MAXIMIZEBOX
| WS_POPUP
,
4343 rcMain
.left
, rcMain
.top
,
4344 rcMain
.right
- rcMain
.left
, rcMain
.bottom
- rcMain
.top
,
4348 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4349 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4350 ok(!(style
& WS_VISIBLE
), "window should not be visible\n");
4351 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4352 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4353 GetWindowRect(hwnd
, &rc
);
4354 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4356 ret
= ShowWindow(hwnd
, SW_SHOW
);
4357 ok(!ret
, "not expected ret: %lu\n", ret
);
4358 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4359 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4360 ok(style
& WS_VISIBLE
, "window should be visible\n");
4361 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4362 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4363 GetWindowRect(hwnd
, &rc
);
4364 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4366 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4367 ok(ret
, "not expected ret: %lu\n", ret
);
4368 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4369 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4370 ok(style
& WS_VISIBLE
, "window should be visible\n");
4371 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4372 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4373 GetWindowRect(hwnd
, &rc
);
4374 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4376 ShowWindow(hwnd
, SW_RESTORE
);
4377 ok(ret
, "not expected ret: %lu\n", ret
);
4378 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4379 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4380 ok(style
& WS_VISIBLE
, "window should be visible\n");
4381 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4382 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4383 GetWindowRect(hwnd
, &rc
);
4384 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4386 ret
= EnableWindow(hwnd
, FALSE
);
4387 ok(!ret
, "not expected ret: %lu\n", ret
);
4388 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4389 ok(style
& WS_DISABLED
, "window should be disabled\n");
4391 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
4392 ok(!ret
, "not expected ret: %lu\n", ret
);
4393 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4394 ok(style
& WS_DISABLED
, "window should be disabled\n");
4395 ok(style
& WS_VISIBLE
, "window should be visible\n");
4396 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4397 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4398 GetWindowRect(hwnd
, &rc
);
4399 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4401 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
4402 ok(!ret
, "not expected ret: %lu\n", ret
);
4403 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4404 ok(style
& WS_DISABLED
, "window should be disabled\n");
4405 ok(style
& WS_VISIBLE
, "window should be visible\n");
4406 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4407 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4408 GetWindowRect(hwnd
, &rc
);
4409 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4411 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4412 ok(ret
, "not expected ret: %lu\n", ret
);
4413 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4414 ok(style
& WS_DISABLED
, "window should be disabled\n");
4415 ok(style
& WS_VISIBLE
, "window should be visible\n");
4416 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4417 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4418 GetWindowRect(hwnd
, &rc
);
4419 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4421 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
4422 ok(!ret
, "not expected ret: %lu\n", ret
);
4423 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4424 ok(style
& WS_DISABLED
, "window should be disabled\n");
4425 ok(style
& WS_VISIBLE
, "window should be visible\n");
4426 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4427 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4428 GetWindowRect(hwnd
, &rc
);
4429 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4431 ret
= ShowWindow(hwnd
, SW_RESTORE
);
4432 ok(ret
, "not expected ret: %lu\n", ret
);
4433 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4434 ok(style
& WS_DISABLED
, "window should be disabled\n");
4435 ok(style
& WS_VISIBLE
, "window should be visible\n");
4436 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4437 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4438 GetWindowRect(hwnd
, &rc
);
4439 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4441 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4442 ok(!ret
, "not expected ret: %lu\n", ret
);
4443 ok(IsWindow(hwnd
), "window should exist\n");
4445 ret
= EnableWindow(hwnd
, TRUE
);
4446 ok(ret
, "not expected ret: %lu\n", ret
);
4448 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4449 ok(!ret
, "not expected ret: %lu\n", ret
);
4450 ok(!IsWindow(hwnd
), "window should not exist\n");
4453 static void test_gettext(void)
4456 LPCSTR clsname
= "gettexttest";
4460 memset( &cls
, 0, sizeof cls
);
4461 cls
.lpfnWndProc
= DefWindowProc
;
4462 cls
.lpszClassName
= clsname
;
4463 cls
.hInstance
= GetModuleHandle(NULL
);
4465 if (!RegisterClass( &cls
)) return;
4467 hwnd
= CreateWindow( clsname
, "test text", WS_OVERLAPPED
, 0, 0, 10, 10, 0, NULL
, NULL
, NULL
);
4468 ok( hwnd
!= NULL
, "window was null\n");
4470 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10, 0x1000);
4471 ok( r
== 0, "settext should return zero\n");
4473 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10000, 0);
4474 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4476 r
= SendMessage( hwnd
, WM_GETTEXT
, 0xff000000, 0x1000);
4477 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4479 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x1000, 0xff000000);
4480 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4482 DestroyWindow(hwnd
);
4483 UnregisterClass( clsname
, NULL
);
4487 static void test_GetUpdateRect(void)
4490 BOOL ret
, parent_wm_paint
, grandparent_wm_paint
;
4492 HWND hgrandparent
, hparent
, hchild
;
4494 static const char classNameA
[] = "GetUpdateRectClass";
4496 hgrandparent
= CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW
,
4497 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4499 hparent
= CreateWindowA("static", "parent", WS_CHILD
|WS_VISIBLE
,
4500 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4502 hchild
= CreateWindowA("static", "child", WS_CHILD
|WS_VISIBLE
,
4503 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4505 ShowWindow(hgrandparent
, SW_SHOW
);
4506 UpdateWindow(hgrandparent
);
4507 flush_events( TRUE
);
4509 ShowWindow(hchild
, SW_HIDE
);
4510 SetRect(&rc2
, 0, 0, 0, 0);
4511 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4512 ok(!ret
, "GetUpdateRect returned not empty region\n");
4513 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4514 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4515 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4517 SetRect(&rc2
, 10, 10, 40, 40);
4518 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
4519 ok(ret
, "GetUpdateRect returned empty region\n");
4520 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4521 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4522 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4524 parent_wm_paint
= FALSE
;
4525 grandparent_wm_paint
= FALSE
;
4526 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
4528 if (msg
.message
== WM_PAINT
)
4530 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
4531 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
4533 DispatchMessage(&msg
);
4535 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
4536 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
4538 DestroyWindow(hgrandparent
);
4541 cls
.lpfnWndProc
= DefWindowProcA
;
4544 cls
.hInstance
= GetModuleHandleA(0);
4546 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
4547 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4548 cls
.lpszMenuName
= NULL
;
4549 cls
.lpszClassName
= classNameA
;
4551 if(!RegisterClassA(&cls
)) {
4552 trace("Register failed %d\n", GetLastError());
4556 hgrandparent
= CreateWindowA(classNameA
, "grandparent", WS_OVERLAPPEDWINDOW
,
4557 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4559 hparent
= CreateWindowA(classNameA
, "parent", WS_CHILD
|WS_VISIBLE
,
4560 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4562 hchild
= CreateWindowA(classNameA
, "child", WS_CHILD
|WS_VISIBLE
,
4563 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4565 ShowWindow(hgrandparent
, SW_SHOW
);
4566 UpdateWindow(hgrandparent
);
4567 flush_events( TRUE
);
4569 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4570 ok(!ret
, "GetUpdateRect returned not empty region\n");
4572 ShowWindow(hchild
, SW_HIDE
);
4574 SetRect(&rc2
, 0, 0, 0, 0);
4575 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4576 ok(!ret
, "GetUpdateRect returned not empty region\n");
4577 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4578 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4579 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4581 SetRect(&rc2
, 10, 10, 40, 40);
4582 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
4583 ok(ret
, "GetUpdateRect returned empty region\n");
4584 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4585 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4586 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4588 parent_wm_paint
= FALSE
;
4589 grandparent_wm_paint
= FALSE
;
4590 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
4592 if (msg
.message
== WM_PAINT
)
4594 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
4595 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
4597 DispatchMessage(&msg
);
4599 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
4600 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
4602 DestroyWindow(hgrandparent
);
4606 static LRESULT CALLBACK
TestExposedRegion_WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4614 const int waitTime
= 2000;
4616 BeginPaint(hwnd
, &ps
);
4618 /* create and destroy window to create an exposed region on this window */
4619 win
= CreateWindowA("static", "win", WS_VISIBLE
,
4620 10,10,50,50, NULL
, NULL
, 0, NULL
);
4623 waitResult
= MsgWaitForMultipleObjects( 0, NULL
, FALSE
, waitTime
, QS_PAINT
);
4625 ValidateRect(hwnd
, NULL
);
4626 EndPaint(hwnd
, &ps
);
4628 if(waitResult
!= WAIT_TIMEOUT
)
4630 GetUpdateRect(hwnd
, &updateRect
, FALSE
);
4633 ok(!IsRectEmpty(&updateRect
), "Exposed rect should not be empty\n");
4639 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
4642 static void test_Expose(void)
4647 memset(&cls
, 0, sizeof(WNDCLASSA
));
4648 cls
.lpfnWndProc
= TestExposedRegion_WndProc
;
4649 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4650 cls
.lpszClassName
= "TestExposeClass";
4651 atom
= RegisterClassA(&cls
);
4653 mw
= CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE
|WS_OVERLAPPEDWINDOW
,
4654 0, 0, 200, 100, NULL
, NULL
, 0, NULL
);
4660 static void test_GetWindowModuleFileName(void)
4665 char buf1
[MAX_PATH
], buf2
[MAX_PATH
];
4667 if (!pGetWindowModuleFileNameA
)
4669 skip("GetWindowModuleFileNameA is not available\n");
4673 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0,0,0,0, 0, 0, 0, NULL
);
4676 hinst
= (HINSTANCE
)GetWindowLongPtr(hwnd
, GWLP_HINSTANCE
);
4677 ok(hinst
== 0, "expected 0, got %p\n", hinst
);
4680 SetLastError(0xdeadbeef);
4681 ret1
= GetModuleFileName(hinst
, buf1
, sizeof(buf1
));
4682 ok(ret1
, "GetModuleFileName error %u\n", GetLastError());
4685 SetLastError(0xdeadbeef);
4686 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, sizeof(buf2
));
4687 ok(ret2
, "GetWindowModuleFileNameA error %u\n", GetLastError());
4689 ok(ret1
== ret2
, "%u != %u\n", ret1
, ret2
);
4690 ok(!strcmp(buf1
, buf2
), "%s != %s\n", buf1
, buf2
);
4692 hinst
= GetModuleHandle(0);
4694 /* MSDN mentions ERROR_INSUFFICIENT_BUFFER, but XP doesn't do it */
4695 SetLastError(0xdeadbeef);
4696 ret2
= GetModuleFileName(hinst
, buf2
, ret1
- 2);
4697 ok(ret2
== ret1
- 2, "expected %u, got %u\n", ret1
- 2, ret2
);
4698 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %u\n", GetLastError());
4700 SetLastError(0xdeadbeef);
4701 ret2
= GetModuleFileName(hinst
, buf2
, 0);
4702 ok(!ret2
, "GetModuleFileName should return 0\n");
4703 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %u\n", GetLastError());
4705 SetLastError(0xdeadbeef);
4706 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, ret1
- 2);
4707 ok(ret2
== ret1
- 2, "expected %u, got %u\n", ret1
- 2, ret2
);
4708 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %u\n", GetLastError());
4710 SetLastError(0xdeadbeef);
4711 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, 0);
4712 ok(!ret2
, "expected 0, got %u\n", ret2
);
4713 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %u\n", GetLastError());
4715 DestroyWindow(hwnd
);
4718 hwnd
= (HWND
)0xdeadbeef;
4719 SetLastError(0xdeadbeef);
4720 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
4721 ok(!ret1
, "expected 0, got %u\n", ret1
);
4722 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
4724 hwnd
= GetDesktopWindow();
4725 ok(IsWindow(hwnd
), "got invalid desktop window %p\n", hwnd
);
4726 SetLastError(0xdeadbeef);
4727 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
4728 ok(!ret1
, "expected 0, got %u\n", ret1
);
4730 hwnd
= FindWindow("Shell_TrayWnd", NULL
);
4731 ok(IsWindow(hwnd
), "got invalid tray window %p\n", hwnd
);
4732 SetLastError(0xdeadbeef);
4733 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
4734 ok(!ret1
, "expected 0, got %u\n", ret1
);
4739 pGetAncestor
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
4740 pGetWindowInfo
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
4741 pGetWindowModuleFileNameA
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowModuleFileNameA" );
4743 hwndMain
= CreateWindowExA(0, "static", NULL
, 0, 0, 0, 0, 0, HWND_MESSAGE
, 0, 0, NULL
);
4746 ok(!GetParent(hwndMain
), "GetParent should return 0 for message only windows\n");
4749 hwndMessage
= pGetAncestor(hwndMain
, GA_PARENT
);
4750 ok(hwndMessage
!= 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
4751 trace("hwndMessage %p\n", hwndMessage
);
4753 DestroyWindow(hwndMain
);
4756 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
4758 if (!RegisterWindowClasses()) assert(0);
4760 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
4763 hwndMain
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
4764 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4765 WS_MAXIMIZEBOX
| WS_POPUP
,
4767 0, 0, GetModuleHandle(0), NULL
);
4768 test_nonclient_area(hwndMain
);
4770 hwndMain2
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
4771 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4772 WS_MAXIMIZEBOX
| WS_POPUP
,
4774 0, 0, GetModuleHandle(0), NULL
);
4776 assert( hwndMain2
);
4778 our_pid
= GetWindowThreadProcessId(hwndMain
, NULL
);
4780 /* Add the tests below this line */
4782 test_GetWindowModuleFileName();
4785 test_capture_3(hwndMain
, hwndMain2
);
4787 test_CreateWindow();
4788 test_parent_owner();
4790 test_shell_window();
4794 test_SetWindowPos(hwndMain
);
4795 test_SetMenu(hwndMain
);
4796 test_SetFocus(hwndMain
);
4797 test_SetActiveWindow(hwndMain
);
4798 test_SetForegroundWindow(hwndMain
);
4800 test_children_zorder(hwndMain
);
4801 test_popup_zorder(hwndMain2
, hwndMain
);
4802 test_keyboard_input(hwndMain
);
4803 test_mouse_input(hwndMain
);
4804 test_validatergn(hwndMain
);
4805 test_nccalcscroll( hwndMain
);
4806 test_scrollvalidate( hwndMain
);
4807 test_scrolldc( hwndMain
);
4809 test_IsWindowUnicode();
4810 test_vis_rgn(hwndMain
);
4812 test_AdjustWindowRect();
4813 test_window_styles();
4816 test_SetWindowLong();
4819 test_GetUpdateRect();
4822 /* add the tests above this line */
4823 UnhookWindowsHookEx(hhook
);