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
*);
50 static BOOL test_lbuttondown_flag
;
51 static HWND hwndMessage
;
52 static HWND hwndMain
, hwndMain2
;
55 static const char* szAWRClass
= "Winsize";
58 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
60 /* try to make sure pending X events have been processed before continuing */
61 static void flush_events(void)
65 DWORD time
= GetTickCount() + diff
;
69 MsgWaitForMultipleObjects( 0, NULL
, FALSE
, diff
, QS_ALLINPUT
);
70 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
71 diff
= time
- GetTickCount();
75 /* check the values returned by the various parent/owner functions on a given window */
76 static void check_parents( HWND hwnd
, HWND ga_parent
, HWND gwl_parent
, HWND get_parent
,
77 HWND gw_owner
, HWND ga_root
, HWND ga_root_owner
)
83 res
= pGetAncestor( hwnd
, GA_PARENT
);
84 ok( res
== ga_parent
, "Wrong result for GA_PARENT %p expected %p\n", res
, ga_parent
);
86 res
= (HWND
)GetWindowLongPtrA( hwnd
, GWLP_HWNDPARENT
);
87 ok( res
== gwl_parent
, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res
, gwl_parent
);
88 res
= GetParent( hwnd
);
89 ok( res
== get_parent
, "Wrong result for GetParent %p expected %p\n", res
, get_parent
);
90 res
= GetWindow( hwnd
, GW_OWNER
);
91 ok( res
== gw_owner
, "Wrong result for GW_OWNER %p expected %p\n", res
, gw_owner
);
94 res
= pGetAncestor( hwnd
, GA_ROOT
);
95 ok( res
== ga_root
, "Wrong result for GA_ROOT %p expected %p\n", res
, ga_root
);
96 res
= pGetAncestor( hwnd
, GA_ROOTOWNER
);
97 ok( res
== ga_root_owner
, "Wrong result for GA_ROOTOWNER %p expected %p\n", res
, ga_root_owner
);
101 static BOOL CALLBACK
EnumChildProc( HWND hwndChild
, LPARAM lParam
)
104 trace("EnumChildProc on %p\n", hwndChild
);
105 if (*(LPINT
)lParam
> 1) return FALSE
;
109 /* will search for the given window */
110 static BOOL CALLBACK
EnumChildProc1( HWND hwndChild
, LPARAM lParam
)
112 trace("EnumChildProc1 on %p\n", hwndChild
);
113 if ((HWND
)lParam
== hwndChild
) return FALSE
;
117 static HWND
create_tool_window( LONG style
, HWND parent
)
119 HWND ret
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style
,
120 0, 0, 100, 100, parent
, 0, 0, NULL
);
121 ok( ret
!= 0, "Creation failed\n" );
125 /* test parent and owner values for various combinations */
126 static void test_parent_owner(void)
129 HWND test
, owner
, ret
;
130 HWND desktop
= GetDesktopWindow();
131 HWND child
= create_tool_window( WS_CHILD
, hwndMain
);
134 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain
, hwndMain2
, desktop
, child
);
136 /* child without parent, should fail */
137 SetLastError(0xdeadbeef);
138 test
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
139 WS_CHILD
, 0, 0, 100, 100, 0, 0, 0, NULL
);
140 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD
, "CreateWindowExA should call SetLastError\n" );
141 ok( !test
, "WS_CHILD without parent created\n" );
144 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
145 style
= GetWindowLongA( desktop
, GWL_STYLE
);
146 ok( !SetWindowLongA( desktop
, GWL_STYLE
, WS_POPUP
), "Set GWL_STYLE on desktop succeeded\n" );
147 ok( !SetWindowLongA( desktop
, GWL_STYLE
, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
148 ok( GetWindowLongA( desktop
, GWL_STYLE
) == style
, "Desktop style changed\n" );
150 /* normal child window */
151 test
= create_tool_window( WS_CHILD
, hwndMain
);
152 trace( "created child %p\n", test
);
153 check_parents( test
, hwndMain
, hwndMain
, hwndMain
, 0, hwndMain
, hwndMain
);
154 SetWindowLongA( test
, GWL_STYLE
, 0 );
155 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
156 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
157 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
158 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
|WS_CHILD
);
159 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
160 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
161 DestroyWindow( test
);
163 /* normal child window with WS_MAXIMIZE */
164 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
165 DestroyWindow( test
);
167 /* normal child window with WS_THICKFRAME */
168 test
= create_tool_window( WS_CHILD
| WS_THICKFRAME
, hwndMain
);
169 DestroyWindow( test
);
171 /* popup window with WS_THICKFRAME */
172 test
= create_tool_window( WS_POPUP
| WS_THICKFRAME
, hwndMain
);
173 DestroyWindow( test
);
175 /* child of desktop */
176 test
= create_tool_window( WS_CHILD
, desktop
);
177 trace( "created child of desktop %p\n", test
);
178 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
179 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
180 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
181 SetWindowLongA( test
, GWL_STYLE
, 0 );
182 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
183 DestroyWindow( test
);
185 /* child of desktop with WS_MAXIMIZE */
186 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, desktop
);
187 DestroyWindow( test
);
189 /* child of desktop with WS_MINIMIZE */
190 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, desktop
);
191 DestroyWindow( test
);
194 test
= create_tool_window( WS_CHILD
, child
);
195 trace( "created child of child %p\n", test
);
196 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
197 SetWindowLongA( test
, GWL_STYLE
, 0 );
198 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
199 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
200 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
201 DestroyWindow( test
);
203 /* child of child with WS_MAXIMIZE */
204 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, child
);
205 DestroyWindow( test
);
207 /* child of child with WS_MINIMIZE */
208 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, child
);
209 DestroyWindow( test
);
211 /* not owned top-level window */
212 test
= create_tool_window( 0, 0 );
213 trace( "created top-level %p\n", test
);
214 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
215 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
216 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
217 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
218 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
219 DestroyWindow( test
);
221 /* not owned top-level window with WS_MAXIMIZE */
222 test
= create_tool_window( WS_MAXIMIZE
, 0 );
223 DestroyWindow( test
);
225 /* owned top-level window */
226 test
= create_tool_window( 0, hwndMain
);
227 trace( "created owned top-level %p\n", test
);
228 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
229 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
230 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
231 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
232 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
233 DestroyWindow( test
);
235 /* owned top-level window with WS_MAXIMIZE */
236 test
= create_tool_window( WS_MAXIMIZE
, hwndMain
);
237 DestroyWindow( test
);
239 /* not owned popup */
240 test
= create_tool_window( WS_POPUP
, 0 );
241 trace( "created popup %p\n", test
);
242 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
243 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
244 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
245 SetWindowLongA( test
, GWL_STYLE
, 0 );
246 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
247 DestroyWindow( test
);
249 /* not owned popup with WS_MAXIMIZE */
250 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, 0 );
251 DestroyWindow( test
);
254 test
= create_tool_window( WS_POPUP
, hwndMain
);
255 trace( "created owned popup %p\n", test
);
256 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
257 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
258 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
259 SetWindowLongA( test
, GWL_STYLE
, 0 );
260 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
261 DestroyWindow( test
);
263 /* owned popup with WS_MAXIMIZE */
264 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, hwndMain
);
265 DestroyWindow( test
);
267 /* top-level window owned by child (same as owned by top-level) */
268 test
= create_tool_window( 0, child
);
269 trace( "created top-level owned by child %p\n", test
);
270 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
271 DestroyWindow( test
);
273 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
274 test
= create_tool_window( WS_MAXIMIZE
, child
);
275 DestroyWindow( test
);
277 /* popup owned by desktop (same as not owned) */
278 test
= create_tool_window( WS_POPUP
, desktop
);
279 trace( "created popup owned by desktop %p\n", test
);
280 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
281 DestroyWindow( test
);
283 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
284 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, desktop
);
285 DestroyWindow( test
);
287 /* popup owned by child (same as owned by top-level) */
288 test
= create_tool_window( WS_POPUP
, child
);
289 trace( "created popup owned by child %p\n", test
);
290 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
291 DestroyWindow( test
);
293 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
294 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, child
);
295 DestroyWindow( test
);
297 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
298 test
= create_tool_window( WS_POPUP
| WS_CHILD
, 0 );
299 trace( "created WS_CHILD popup %p\n", test
);
300 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
301 DestroyWindow( test
);
303 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
304 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, 0 );
305 DestroyWindow( test
);
307 /* owned popup with WS_CHILD (same as WS_POPUP only) */
308 test
= create_tool_window( WS_POPUP
| WS_CHILD
, hwndMain
);
309 trace( "created owned WS_CHILD popup %p\n", test
);
310 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
311 DestroyWindow( test
);
313 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
314 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
315 DestroyWindow( test
);
317 /******************** parent changes *************************/
318 trace( "testing parent changes\n" );
321 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
324 /* this test succeeds on NT but crashes on win9x systems */
325 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
326 ok( !ret
, "Set GWL_HWNDPARENT succeeded on desktop\n" );
327 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
328 ok( !SetParent( desktop
, hwndMain
), "SetParent succeeded on desktop\n" );
329 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
331 /* normal child window */
332 test
= create_tool_window( WS_CHILD
, hwndMain
);
333 trace( "created child %p\n", test
);
335 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
336 ok( ret
== hwndMain
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain
);
337 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
339 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
340 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
341 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
343 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)desktop
);
344 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
345 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
347 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
348 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
349 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
350 check_parents( test
, desktop
, child
, desktop
, child
, test
, desktop
);
352 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
353 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
354 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
355 DestroyWindow( test
);
357 /* not owned top-level window */
358 test
= create_tool_window( 0, 0 );
359 trace( "created top-level %p\n", test
);
361 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
362 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
363 check_parents( test
, desktop
, hwndMain2
, 0, hwndMain2
, test
, test
);
365 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
366 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
367 check_parents( test
, desktop
, child
, 0, child
, test
, test
);
369 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
370 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
371 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
372 DestroyWindow( test
);
374 /* not owned popup */
375 test
= create_tool_window( WS_POPUP
, 0 );
376 trace( "created popup %p\n", test
);
378 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
379 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
380 check_parents( test
, desktop
, hwndMain2
, hwndMain2
, hwndMain2
, test
, hwndMain2
);
382 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
383 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
384 check_parents( test
, desktop
, child
, child
, child
, test
, hwndMain
);
386 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
387 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
388 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
389 DestroyWindow( test
);
391 /* normal child window */
392 test
= create_tool_window( WS_CHILD
, hwndMain
);
393 trace( "created child %p\n", test
);
395 ret
= SetParent( test
, desktop
);
396 ok( ret
== hwndMain
, "SetParent return value %p expected %p\n", ret
, hwndMain
);
397 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
399 ret
= SetParent( test
, child
);
400 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
401 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
403 ret
= SetParent( test
, hwndMain2
);
404 ok( ret
== child
, "SetParent return value %p expected %p\n", ret
, child
);
405 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
406 DestroyWindow( test
);
408 /* not owned top-level window */
409 test
= create_tool_window( 0, 0 );
410 trace( "created top-level %p\n", test
);
412 ret
= SetParent( test
, child
);
413 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
414 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
415 DestroyWindow( test
);
418 test
= create_tool_window( WS_POPUP
, hwndMain2
);
419 trace( "created owned popup %p\n", test
);
421 ret
= SetParent( test
, child
);
422 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
423 check_parents( test
, child
, child
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
425 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)hwndMain
);
426 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
427 check_parents( test
, hwndMain
, hwndMain
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
428 DestroyWindow( test
);
430 /**************** test owner destruction *******************/
432 /* owned child popup */
433 owner
= create_tool_window( 0, 0 );
434 test
= create_tool_window( WS_POPUP
, owner
);
435 trace( "created owner %p and popup %p\n", owner
, test
);
436 ret
= SetParent( test
, child
);
437 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
438 check_parents( test
, child
, child
, owner
, owner
, hwndMain
, owner
);
439 /* window is now child of 'child' but owned by 'owner' */
440 DestroyWindow( owner
);
441 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
442 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
443 * while Win95, Win2k, WinXP do.
445 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
446 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
449 /* owned top-level popup */
450 owner
= create_tool_window( 0, 0 );
451 test
= create_tool_window( WS_POPUP
, owner
);
452 trace( "created owner %p and popup %p\n", owner
, test
);
453 check_parents( test
, desktop
, owner
, owner
, owner
, test
, owner
);
454 DestroyWindow( owner
);
455 ok( !IsWindow(test
), "Window %p not destroyed by owner destruction\n", test
);
457 /* top-level popup owned by child */
458 owner
= create_tool_window( WS_CHILD
, hwndMain2
);
459 test
= create_tool_window( WS_POPUP
, 0 );
460 trace( "created owner %p and popup %p\n", owner
, test
);
461 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)owner
);
462 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
463 check_parents( test
, desktop
, owner
, owner
, owner
, test
, hwndMain2
);
464 DestroyWindow( owner
);
465 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
466 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
467 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
468 * while Win95, Win2k, WinXP do.
470 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
474 DestroyWindow(child
);
477 owner
= create_tool_window( WS_OVERLAPPED
, 0 );
478 test
= create_tool_window( WS_POPUP
, desktop
);
480 ok( !GetWindow( test
, GW_OWNER
), "Wrong owner window\n" );
482 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
483 "EnumChildWindows should have returned FALSE\n" );
484 ok( numChildren
== 0, "numChildren should be 0 got %d\n", numChildren
);
486 SetWindowLongA( test
, GWL_STYLE
, (GetWindowLongA( test
, GWL_STYLE
) & ~WS_POPUP
) | WS_CHILD
);
487 ret
= SetParent( test
, owner
);
488 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
491 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
492 "EnumChildWindows should have returned TRUE\n" );
493 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
495 child
= create_tool_window( WS_CHILD
, owner
);
497 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
498 "EnumChildWindows should have returned FALSE\n" );
499 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
500 DestroyWindow( child
);
502 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, owner
);
503 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
505 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
506 "EnumChildWindows should have returned TRUE\n" );
507 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
509 ret
= SetParent( child
, owner
);
510 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
511 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
513 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
514 "EnumChildWindows should have returned FALSE\n" );
515 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
517 ret
= SetParent( child
, NULL
);
518 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
519 ok( ret
== owner
, "SetParent return value %p expected %p\n", ret
, owner
);
521 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
522 "EnumChildWindows should have returned TRUE\n" );
523 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
525 /* even GW_OWNER == owner it's still a desktop's child */
526 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
527 "EnumChildWindows should have found %p and returned FALSE\n", child
);
529 DestroyWindow( child
);
530 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, NULL
);
532 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
533 "EnumChildWindows should have found %p and returned FALSE\n", child
);
535 DestroyWindow( child
);
536 DestroyWindow( test
);
537 DestroyWindow( owner
);
541 static LRESULT WINAPI
main_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
545 case WM_GETMINMAXINFO
:
547 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
549 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
550 trace("ptReserved (%d,%d), ptMaxSize (%d,%d), ptMaxPosition (%d,%d)\n"
551 " ptMinTrackSize (%d,%d), ptMaxTrackSize (%d,%d)\n",
552 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
553 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
554 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
555 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
556 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
557 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
560 case WM_WINDOWPOSCHANGING
:
562 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
563 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
564 trace("main: WM_WINDOWPOSCHANGING\n");
565 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
566 winpos
->hwnd
, winpos
->hwndInsertAfter
,
567 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
568 if (!(winpos
->flags
& SWP_NOMOVE
))
570 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
571 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
573 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
574 if (!(winpos
->flags
& SWP_NOSIZE
) && !is_win9x
)
576 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
577 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
581 case WM_WINDOWPOSCHANGED
:
584 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
585 trace("main: WM_WINDOWPOSCHANGED\n");
586 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
587 winpos
->hwnd
, winpos
->hwndInsertAfter
,
588 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
589 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
590 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
592 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
593 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
595 GetWindowRect(hwnd
, &rc1
);
596 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
597 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
598 /* note: winpos coordinates are relative to parent */
599 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
600 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
603 /* Uncomment this once the test succeeds in all cases */
604 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
607 GetClientRect(hwnd
, &rc2
);
608 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
609 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
610 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
611 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
616 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
617 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
619 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
620 if (got_getminmaxinfo
)
621 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
623 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
624 ok(got_getminmaxinfo
, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
626 ok(!got_getminmaxinfo
, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
630 if (test_lbuttondown_flag
)
631 ShowWindow((HWND
)wparam
, SW_SHOW
);
635 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
638 static LRESULT WINAPI
tool_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
642 case WM_GETMINMAXINFO
:
644 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
646 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
647 trace("ptReserved (%d,%d), ptMaxSize (%d,%d), ptMaxPosition (%d,%d)\n"
648 " ptMinTrackSize (%d,%d), ptMaxTrackSize (%d,%d)\n",
649 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
650 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
651 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
652 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
653 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
654 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
659 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
660 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
662 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
663 if (got_getminmaxinfo
)
664 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
666 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
667 ok(got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
669 ok(!got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
674 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
677 static BOOL
RegisterWindowClasses(void)
681 cls
.style
= CS_DBLCLKS
;
682 cls
.lpfnWndProc
= main_window_procA
;
685 cls
.hInstance
= GetModuleHandleA(0);
687 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
688 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
689 cls
.lpszMenuName
= NULL
;
690 cls
.lpszClassName
= "MainWindowClass";
692 if(!RegisterClassA(&cls
)) return FALSE
;
695 cls
.lpfnWndProc
= tool_window_procA
;
698 cls
.hInstance
= GetModuleHandleA(0);
700 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
701 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
702 cls
.lpszMenuName
= NULL
;
703 cls
.lpszClassName
= "ToolWindowClass";
705 if(!RegisterClassA(&cls
)) return FALSE
;
710 static void verify_window_info(HWND hwnd
, const WINDOWINFO
*info
)
712 RECT rcWindow
, rcClient
;
715 ok(IsWindow(hwnd
), "bad window handle\n");
717 GetWindowRect(hwnd
, &rcWindow
);
718 ok(EqualRect(&rcWindow
, &info
->rcWindow
), "wrong rcWindow\n");
720 GetClientRect(hwnd
, &rcClient
);
721 /* translate to screen coordinates */
722 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rcClient
, 2);
723 ok(EqualRect(&rcClient
, &info
->rcClient
), "wrong rcClient\n");
725 ok(info
->dwStyle
== (DWORD
)GetWindowLongA(hwnd
, GWL_STYLE
),
726 "wrong dwStyle: %08x != %08x\n", info
->dwStyle
, GetWindowLongA(hwnd
, GWL_STYLE
));
727 /* Windows reports a not documented exstyle 0x800 in WINDOWINFO, but
728 * doesn't return it in GetWindowLong(hwnd, GWL_EXSTYLE).
730 ok((info
->dwExStyle
& ~0x800) == (DWORD
)GetWindowLongA(hwnd
, GWL_EXSTYLE
),
731 "wrong dwExStyle: %08x != %08x\n", info
->dwExStyle
, GetWindowLongA(hwnd
, GWL_EXSTYLE
));
732 status
= (GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0;
733 ok(info
->dwWindowStatus
== status
, "wrong dwWindowStatus: %04x != %04x\n",
734 info
->dwWindowStatus
, status
);
736 trace("rcWindow: %d,%d - %d,%d\n", rcWindow
.left
, rcWindow
.top
, rcWindow
.right
, rcWindow
.bottom
);
737 trace("rcClient: %d,%d - %d,%d\n", rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
739 /* win2k and XP return broken border info in GetWindowInfo most of
740 * the time, so there is no point in testing it.
744 ok(info
->cxWindowBorders
== (unsigned)(rcClient
.left
- rcWindow
.left
),
745 "wrong cxWindowBorders %d != %d\n", info
->cxWindowBorders
, rcClient
.left
- rcWindow
.left
);
746 border
= min(rcWindow
.bottom
- rcClient
.bottom
, rcClient
.top
- rcWindow
.top
);
747 ok(info
->cyWindowBorders
== border
,
748 "wrong cyWindowBorders %d != %d\n", info
->cyWindowBorders
, border
);
750 ok(info
->atomWindowType
== GetClassLongA(hwnd
, GCW_ATOM
), "wrong atomWindowType\n");
751 ok(info
->wCreatorVersion
== 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
752 info
->wCreatorVersion
== 0x0500 /* Vista */,
753 "wrong wCreatorVersion %04x\n", info
->wCreatorVersion
);
756 static void FixedAdjustWindowRectEx(RECT
* rc
, LONG style
, BOOL menu
, LONG exstyle
)
758 AdjustWindowRectEx(rc
, style
, menu
, exstyle
);
759 /* AdjustWindowRectEx does not include scroll bars */
760 if (style
& WS_VSCROLL
)
762 if(exstyle
& WS_EX_LEFTSCROLLBAR
)
763 rc
->left
-= GetSystemMetrics(SM_CXVSCROLL
);
765 rc
->right
+= GetSystemMetrics(SM_CXVSCROLL
);
767 if (style
& WS_HSCROLL
)
768 rc
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
771 static void test_nonclient_area(HWND hwnd
)
773 DWORD style
, exstyle
;
774 RECT rc_window
, rc_client
, rc
;
776 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
778 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
779 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
780 menu
= !(style
& WS_CHILD
) && GetMenu(hwnd
) != 0;
782 GetWindowRect(hwnd
, &rc_window
);
783 trace("window: (%d,%d)-(%d,%d)\n", rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
);
784 GetClientRect(hwnd
, &rc_client
);
785 trace("client: (%d,%d)-(%d,%d)\n", rc_client
.left
, rc_client
.top
, rc_client
.right
, rc_client
.bottom
);
787 /* avoid some cases when things go wrong */
788 if (IsRectEmpty(&rc_window
) || IsRectEmpty(&rc_client
) ||
789 rc_window
.right
> 32768 || rc_window
.bottom
> 32768) return;
791 CopyRect(&rc
, &rc_client
);
792 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc
, 2);
793 FixedAdjustWindowRectEx(&rc
, style
, menu
, exstyle
);
795 trace("calc window: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
796 ok(EqualRect(&rc
, &rc_window
), "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
799 CopyRect(&rc
, &rc_window
);
800 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
801 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
802 trace("calc client: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
803 ok(EqualRect(&rc
, &rc_client
), "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
805 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
809 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
810 SetRect(&rc_client
, 0, 0, 250, 150);
811 CopyRect(&rc_window
, &rc_client
);
812 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc_window
, 2);
813 FixedAdjustWindowRectEx(&rc_window
, style
, menu
, exstyle
);
814 trace("calc window: (%d,%d)-(%d,%d)\n",
815 rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
);
817 CopyRect(&rc
, &rc_window
);
818 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
819 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
820 trace("calc client: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
821 ok(EqualRect(&rc
, &rc_client
), "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
824 static LRESULT CALLBACK
cbt_hook_proc(int nCode
, WPARAM wParam
, LPARAM lParam
)
826 static const char *CBT_code_name
[10] = {
837 const char *code_name
= (nCode
>= 0 && nCode
<= HCBT_SETFOCUS
) ? CBT_code_name
[nCode
] : "Unknown";
839 trace("CBT: %d (%s), %08lx, %08lx\n", nCode
, code_name
, wParam
, lParam
);
841 /* on HCBT_DESTROYWND window state is undefined */
842 if (nCode
!= HCBT_DESTROYWND
&& IsWindow((HWND
)wParam
))
848 /* Win98 actually does check the info.cbSize and doesn't allow
849 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
850 * WinXP do not check it at all.
852 info
.cbSize
= sizeof(WINDOWINFO
);
853 ok(pGetWindowInfo((HWND
)wParam
, &info
), "GetWindowInfo should not fail\n");
854 verify_window_info((HWND
)wParam
, &info
);
862 static const RECT rc_null
;
865 CBT_CREATEWNDA
*createwnd
= (CBT_CREATEWNDA
*)lParam
;
866 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
867 (HWND
)wParam
, createwnd
->lpcs
->hwndParent
, createwnd
->lpcs
->style
);
868 ok(createwnd
->hwndInsertAfter
== HWND_TOP
, "hwndInsertAfter should be always HWND_TOP\n");
870 /* WS_VISIBLE should be turned off yet */
871 style
= createwnd
->lpcs
->style
& ~WS_VISIBLE
;
872 ok(style
== GetWindowLongA((HWND
)wParam
, GWL_STYLE
),
873 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
874 GetWindowLongA((HWND
)wParam
, GWL_STYLE
), style
);
878 /* Uncomment this once the test succeeds in all cases */
879 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
881 ok(GetParent((HWND
)wParam
) == hwndMessage
,
882 "wrong result from GetParent %p: message window %p\n",
883 GetParent((HWND
)wParam
), hwndMessage
);
886 ok(!GetParent((HWND
)wParam
), "GetParent should return 0 at this point\n");
888 ok(!GetWindow((HWND
)wParam
, GW_OWNER
), "GW_OWNER should be set to 0 at this point\n");
892 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
893 * Win9x still has them set to 0.
895 ok(GetWindow((HWND
)wParam
, GW_HWNDFIRST
) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
896 ok(GetWindow((HWND
)wParam
, GW_HWNDLAST
) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
898 ok(!GetWindow((HWND
)wParam
, GW_HWNDPREV
), "GW_HWNDPREV should be set to 0 at this point\n");
899 ok(!GetWindow((HWND
)wParam
, GW_HWNDNEXT
), "GW_HWNDNEXT should be set to 0 at this point\n");
903 /* Uncomment this once the test succeeds in all cases */
906 ok(pGetAncestor((HWND
)wParam
, GA_PARENT
) == hwndMessage
, "GA_PARENT should be set to hwndMessage at this point\n");
907 ok(pGetAncestor((HWND
)wParam
, GA_ROOT
) == (HWND
)wParam
,
908 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND
)wParam
, GA_ROOT
), (HWND
)wParam
);
910 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
911 ok(pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
) == hwndMessage
,
912 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
914 ok(pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
) == (HWND
)wParam
,
915 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
), (HWND
)wParam
);
918 ok(GetWindowRect((HWND
)wParam
, &rc
), "GetWindowRect failed\n");
919 ok(EqualRect(&rc
, &rc_null
), "window rect should be set to 0 HCBT_CREATEWND\n");
920 ok(GetClientRect((HWND
)wParam
, &rc
), "GetClientRect failed\n");
921 ok(EqualRect(&rc
, &rc_null
), "client rect should be set to 0 on HCBT_CREATEWND\n");
927 return CallNextHookEx(hhook
, nCode
, wParam
, lParam
);
930 static void test_shell_window(void)
934 HMODULE hinst
, hUser32
;
935 BOOL (WINAPI
*SetShellWindow
)(HWND
);
936 BOOL (WINAPI
*SetShellWindowEx
)(HWND
, HWND
);
937 HWND hwnd1
, hwnd2
, hwnd3
, hwnd4
, hwnd5
;
938 HWND shellWindow
, nextWnd
;
940 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE
))
942 trace("Skipping shell window test on Win9x\n");
946 shellWindow
= GetShellWindow();
947 hinst
= GetModuleHandle(0);
948 hUser32
= GetModuleHandleA("user32");
950 SetShellWindow
= (void *)GetProcAddress(hUser32
, "SetShellWindow");
951 SetShellWindowEx
= (void *)GetProcAddress(hUser32
, "SetShellWindowEx");
953 trace("previous shell window: %p\n", shellWindow
);
959 ret
= DestroyWindow(shellWindow
);
960 error
= GetLastError();
962 ok(!ret
, "DestroyWindow(shellWindow)\n");
963 /* passes on Win XP, but not on Win98 */
964 ok(error
==ERROR_ACCESS_DENIED
, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n");
966 /* close old shell instance */
967 GetWindowThreadProcessId(shellWindow
, &pid
);
968 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, pid
);
969 ret
= TerminateProcess(hProcess
, 0);
970 ok(ret
, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
971 WaitForSingleObject(hProcess
, INFINITE
); /* wait for termination */
972 CloseHandle(hProcess
);
975 hwnd1
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst
, 0);
976 trace("created window 1: %p\n", hwnd1
);
978 ret
= SetShellWindow(hwnd1
);
979 ok(ret
, "first call to SetShellWindow(hwnd1)\n");
980 shellWindow
= GetShellWindow();
981 ok(shellWindow
==hwnd1
, "wrong shell window: %p\n", shellWindow
);
983 ret
= SetShellWindow(hwnd1
);
984 ok(!ret
, "second call to SetShellWindow(hwnd1)\n");
986 ret
= SetShellWindow(0);
987 error
= GetLastError();
988 /* passes on Win XP, but not on Win98
989 ok(!ret, "reset shell window by SetShellWindow(0)\n");
990 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
992 ret
= SetShellWindow(hwnd1
);
993 /* passes on Win XP, but not on Win98
994 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
998 SetWindowLong(hwnd1
, GWL_EXSTYLE
, GetWindowLong(hwnd1
,GWL_EXSTYLE
)|WS_EX_TOPMOST
);
999 ret
= GetWindowLong(hwnd1
,GWL_EXSTYLE
)&WS_EX_TOPMOST
? TRUE
: FALSE
;
1000 ok(!ret
, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1003 ret
= DestroyWindow(hwnd1
);
1004 ok(ret
, "DestroyWindow(hwnd1)\n");
1006 hwnd2
= CreateWindowEx(WS_EX_TOPMOST
, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst
, 0);
1007 trace("created window 2: %p\n", hwnd2
);
1008 ret
= SetShellWindow(hwnd2
);
1009 ok(!ret
, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1011 hwnd3
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst
, 0);
1012 trace("created window 3: %p\n", hwnd3
);
1014 hwnd4
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst
, 0);
1015 trace("created window 4: %p\n", hwnd4
);
1017 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1018 ok(nextWnd
==hwnd3
, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd
);
1020 ret
= SetShellWindow(hwnd4
);
1021 ok(ret
, "SetShellWindow(hwnd4)\n");
1022 shellWindow
= GetShellWindow();
1023 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1025 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1026 ok(nextWnd
==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd
);
1028 ret
= SetWindowPos(hwnd4
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1029 ok(ret
, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1031 ret
= SetWindowPos(hwnd4
, hwnd3
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1032 ok(ret
, "SetWindowPos(hwnd4, hwnd3\n");
1034 ret
= SetShellWindow(hwnd3
);
1035 ok(!ret
, "SetShellWindow(hwnd3)\n");
1036 shellWindow
= GetShellWindow();
1037 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1039 hwnd5
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst
, 0);
1040 trace("created window 5: %p\n", hwnd5
);
1041 ret
= SetWindowPos(hwnd4
, hwnd5
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1042 ok(ret
, "SetWindowPos(hwnd4, hwnd5)\n");
1046 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1047 ok(nextWnd
==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd
);
1050 /* destroy test windows */
1051 DestroyWindow(hwnd2
);
1052 DestroyWindow(hwnd3
);
1053 DestroyWindow(hwnd4
);
1054 DestroyWindow(hwnd5
);
1057 /************** MDI test ****************/
1059 static char mdi_lParam_test_message
[] = "just a test string";
1061 static void test_MDI_create(HWND parent
, HWND mdi_client
, INT first_id
)
1063 MDICREATESTRUCTA mdi_cs
;
1065 static const WCHAR classW
[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1066 static const WCHAR titleW
[] = {'M','D','I',' ','c','h','i','l','d',0};
1067 BOOL isWin9x
= FALSE
;
1069 mdi_cs
.szClass
= "MDI_child_Class_1";
1070 mdi_cs
.szTitle
= "MDI child";
1071 mdi_cs
.hOwner
= GetModuleHandle(0);
1072 mdi_cs
.x
= CW_USEDEFAULT
;
1073 mdi_cs
.y
= CW_USEDEFAULT
;
1074 mdi_cs
.cx
= CW_USEDEFAULT
;
1075 mdi_cs
.cy
= CW_USEDEFAULT
;
1077 mdi_cs
.lParam
= (LPARAM
)mdi_lParam_test_message
;
1078 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1079 ok(mdi_child
!= 0, "MDI child creation failed\n");
1080 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1081 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1082 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1084 mdi_cs
.style
= 0x7fffffff; /* without WS_POPUP */
1085 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1086 ok(mdi_child
!= 0, "MDI child creation failed\n");
1087 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1088 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1089 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1091 mdi_cs
.style
= 0xffffffff; /* with WS_POPUP */
1092 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1093 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1095 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1099 ok(mdi_child
!= 0, "MDI child creation failed\n");
1100 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1101 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1102 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1105 /* test MDICREATESTRUCT A<->W mapping */
1106 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1108 mdi_cs
.szClass
= (LPCSTR
)classW
;
1109 mdi_cs
.szTitle
= (LPCSTR
)titleW
;
1110 SetLastError(0xdeadbeef);
1111 mdi_child
= (HWND
)SendMessageW(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1114 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1117 ok(mdi_child
!= 0, "MDI child creation failed\n");
1121 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1122 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1123 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1126 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1128 CW_USEDEFAULT
, CW_USEDEFAULT
,
1129 CW_USEDEFAULT
, CW_USEDEFAULT
,
1130 mdi_client
, GetModuleHandle(0),
1131 (LPARAM
)mdi_lParam_test_message
);
1132 ok(mdi_child
!= 0, "MDI child creation failed\n");
1133 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1134 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1135 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1137 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1138 0x7fffffff, /* without WS_POPUP */
1139 CW_USEDEFAULT
, CW_USEDEFAULT
,
1140 CW_USEDEFAULT
, CW_USEDEFAULT
,
1141 mdi_client
, GetModuleHandle(0),
1142 (LPARAM
)mdi_lParam_test_message
);
1143 ok(mdi_child
!= 0, "MDI child creation failed\n");
1144 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1145 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1146 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1148 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1149 0xffffffff, /* with WS_POPUP */
1150 CW_USEDEFAULT
, CW_USEDEFAULT
,
1151 CW_USEDEFAULT
, CW_USEDEFAULT
,
1152 mdi_client
, GetModuleHandle(0),
1153 (LPARAM
)mdi_lParam_test_message
);
1154 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1156 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1160 ok(mdi_child
!= 0, "MDI child creation failed\n");
1161 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1162 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1163 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1166 /* test MDICREATESTRUCT A<->W mapping */
1167 SetLastError(0xdeadbeef);
1168 mdi_child
= CreateMDIWindowW(classW
, titleW
,
1170 CW_USEDEFAULT
, CW_USEDEFAULT
,
1171 CW_USEDEFAULT
, CW_USEDEFAULT
,
1172 mdi_client
, GetModuleHandle(0),
1173 (LPARAM
)mdi_lParam_test_message
);
1176 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1179 ok(mdi_child
!= 0, "MDI child creation failed\n");
1183 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1184 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1185 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1188 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1190 CW_USEDEFAULT
, CW_USEDEFAULT
,
1191 CW_USEDEFAULT
, CW_USEDEFAULT
,
1192 mdi_client
, 0, GetModuleHandle(0),
1193 (LPVOID
)mdi_lParam_test_message
);
1194 ok(mdi_child
!= 0, "MDI child creation failed\n");
1195 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1196 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1197 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1199 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1200 0x7fffffff, /* without WS_POPUP */
1201 CW_USEDEFAULT
, CW_USEDEFAULT
,
1202 CW_USEDEFAULT
, CW_USEDEFAULT
,
1203 mdi_client
, 0, GetModuleHandle(0),
1204 (LPVOID
)mdi_lParam_test_message
);
1205 ok(mdi_child
!= 0, "MDI child creation failed\n");
1206 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1207 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1208 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1210 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1211 0xffffffff, /* with WS_POPUP */
1212 CW_USEDEFAULT
, CW_USEDEFAULT
,
1213 CW_USEDEFAULT
, CW_USEDEFAULT
,
1214 mdi_client
, 0, GetModuleHandle(0),
1215 (LPVOID
)mdi_lParam_test_message
);
1216 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1218 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1222 ok(mdi_child
!= 0, "MDI child creation failed\n");
1223 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1224 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1225 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1228 /* test MDICREATESTRUCT A<->W mapping */
1229 SetLastError(0xdeadbeef);
1230 mdi_child
= CreateWindowExW(WS_EX_MDICHILD
, classW
, titleW
,
1232 CW_USEDEFAULT
, CW_USEDEFAULT
,
1233 CW_USEDEFAULT
, CW_USEDEFAULT
,
1234 mdi_client
, 0, GetModuleHandle(0),
1235 (LPVOID
)mdi_lParam_test_message
);
1238 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1241 ok(mdi_child
!= 0, "MDI child creation failed\n");
1245 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1246 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1247 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1250 /* This test fails on Win9x */
1253 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_2", "MDI child",
1255 CW_USEDEFAULT
, CW_USEDEFAULT
,
1256 CW_USEDEFAULT
, CW_USEDEFAULT
,
1257 parent
, 0, GetModuleHandle(0),
1258 (LPVOID
)mdi_lParam_test_message
);
1259 ok(!mdi_child
, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1262 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1263 WS_CHILD
, /* without WS_POPUP */
1264 CW_USEDEFAULT
, CW_USEDEFAULT
,
1265 CW_USEDEFAULT
, CW_USEDEFAULT
,
1266 mdi_client
, 0, GetModuleHandle(0),
1267 (LPVOID
)mdi_lParam_test_message
);
1268 ok(mdi_child
!= 0, "MDI child creation failed\n");
1269 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1270 DestroyWindow(mdi_child
);
1272 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1273 WS_CHILD
| WS_POPUP
, /* with WS_POPUP */
1274 CW_USEDEFAULT
, CW_USEDEFAULT
,
1275 CW_USEDEFAULT
, CW_USEDEFAULT
,
1276 mdi_client
, 0, GetModuleHandle(0),
1277 (LPVOID
)mdi_lParam_test_message
);
1278 ok(mdi_child
!= 0, "MDI child creation failed\n");
1279 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1280 DestroyWindow(mdi_child
);
1282 /* maximized child */
1283 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1284 WS_CHILD
| WS_MAXIMIZE
,
1285 CW_USEDEFAULT
, CW_USEDEFAULT
,
1286 CW_USEDEFAULT
, CW_USEDEFAULT
,
1287 mdi_client
, 0, GetModuleHandle(0),
1288 (LPVOID
)mdi_lParam_test_message
);
1289 ok(mdi_child
!= 0, "MDI child creation failed\n");
1290 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1291 DestroyWindow(mdi_child
);
1293 trace("Creating maximized child with a caption\n");
1294 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1295 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
,
1296 CW_USEDEFAULT
, CW_USEDEFAULT
,
1297 CW_USEDEFAULT
, CW_USEDEFAULT
,
1298 mdi_client
, 0, GetModuleHandle(0),
1299 (LPVOID
)mdi_lParam_test_message
);
1300 ok(mdi_child
!= 0, "MDI child creation failed\n");
1301 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1302 DestroyWindow(mdi_child
);
1304 trace("Creating maximized child with a caption and a thick frame\n");
1305 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1306 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
| WS_THICKFRAME
,
1307 CW_USEDEFAULT
, CW_USEDEFAULT
,
1308 CW_USEDEFAULT
, CW_USEDEFAULT
,
1309 mdi_client
, 0, GetModuleHandle(0),
1310 (LPVOID
)mdi_lParam_test_message
);
1311 ok(mdi_child
!= 0, "MDI child creation failed\n");
1312 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1313 DestroyWindow(mdi_child
);
1316 /**********************************************************************
1317 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1319 * Note: The rule here is that client rect of the maximized MDI child
1320 * is equal to the client rect of the MDI client window.
1322 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
1326 GetClientRect( client
, &rect
);
1327 AdjustWindowRectEx( &rect
, GetWindowLongA( hwnd
, GWL_STYLE
),
1328 0, GetWindowLongA( hwnd
, GWL_EXSTYLE
));
1330 rect
.right
-= rect
.left
;
1331 rect
.bottom
-= rect
.top
;
1332 lpMinMax
->ptMaxSize
.x
= rect
.right
;
1333 lpMinMax
->ptMaxSize
.y
= rect
.bottom
;
1335 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
1336 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
1338 trace("max rect (%d,%d - %d, %d)\n",
1339 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1342 static LRESULT WINAPI
mdi_child_wnd_proc_1(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1349 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1350 MDICREATESTRUCTA
*mdi_cs
= (MDICREATESTRUCTA
*)cs
->lpCreateParams
;
1352 ok(cs
->dwExStyle
& WS_EX_MDICHILD
, "WS_EX_MDICHILD should be set\n");
1353 ok(mdi_cs
->lParam
== (LPARAM
)mdi_lParam_test_message
, "wrong mdi_cs->lParam\n");
1355 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_1"), "wrong class name\n");
1356 ok(!lstrcmpA(cs
->lpszClass
, mdi_cs
->szClass
), "class name does not match\n");
1357 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1358 ok(!lstrcmpA(cs
->lpszName
, mdi_cs
->szTitle
), "title does not match\n");
1359 ok(cs
->hInstance
== mdi_cs
->hOwner
, "%p != %p\n", cs
->hInstance
, mdi_cs
->hOwner
);
1361 /* MDICREATESTRUCT should have original values */
1362 ok(mdi_cs
->style
== 0 || mdi_cs
->style
== 0x7fffffff || mdi_cs
->style
== 0xffffffff,
1363 "mdi_cs->style does not match (%08x)\n", mdi_cs
->style
);
1364 ok(mdi_cs
->x
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->x
);
1365 ok(mdi_cs
->y
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->y
);
1366 ok(mdi_cs
->cx
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cx
);
1367 ok(mdi_cs
->cy
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cy
);
1369 /* CREATESTRUCT should have fixed values */
1370 ok(cs
->x
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->x
);
1371 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1373 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1374 ok(cs
->cx
!= CW_USEDEFAULT
&& cs
->cx
!= 0, "%d == CW_USEDEFAULT\n", cs
->cx
);
1375 ok(cs
->cy
!= CW_USEDEFAULT
&& cs
->cy
!= 0, "%d == CW_USEDEFAULT\n", cs
->cy
);
1377 ok(!(cs
->style
& WS_POPUP
), "WS_POPUP is not allowed\n");
1379 if (GetWindowLongA(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1381 LONG style
= mdi_cs
->style
| WS_CHILD
| WS_CLIPSIBLINGS
;
1382 ok(cs
->style
== style
,
1383 "cs->style does not match (%08x)\n", cs
->style
);
1387 LONG style
= mdi_cs
->style
;
1389 style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1390 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1391 ok(cs
->style
== style
,
1392 "cs->style does not match (%08x)\n", cs
->style
);
1397 case WM_GETMINMAXINFO
:
1399 HWND client
= GetParent(hwnd
);
1401 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1402 MINMAXINFO my_minmax
;
1403 LONG style
, exstyle
;
1405 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1406 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1408 GetWindowRect(client
, &rc
);
1409 trace("MDI client %p window size = (%d x %d)\n", client
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1410 GetClientRect(client
, &rc
);
1411 trace("MDI client %p client size = (%d x %d)\n", client
, rc
.right
, rc
.bottom
);
1412 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN
),
1413 GetSystemMetrics(SM_CYSCREEN
));
1415 GetClientRect(client
, &rc
);
1416 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1417 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1418 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1419 trace("MDI child: calculated max window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1421 trace("ptReserved = (%d,%d)\n"
1422 "ptMaxSize = (%d,%d)\n"
1423 "ptMaxPosition = (%d,%d)\n"
1424 "ptMinTrackSize = (%d,%d)\n"
1425 "ptMaxTrackSize = (%d,%d)\n",
1426 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
1427 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
1428 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
1429 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
1430 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
1432 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1433 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1434 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1435 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1437 DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1439 trace("DefMDIChildProc returned:\n"
1440 "ptReserved = (%d,%d)\n"
1441 "ptMaxSize = (%d,%d)\n"
1442 "ptMaxPosition = (%d,%d)\n"
1443 "ptMinTrackSize = (%d,%d)\n"
1444 "ptMaxTrackSize = (%d,%d)\n",
1445 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
1446 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
1447 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
1448 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
1449 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
1451 MDI_ChildGetMinMaxInfo(client
, hwnd
, &my_minmax
);
1452 ok(minmax
->ptMaxSize
.x
== my_minmax
.ptMaxSize
.x
, "default width of maximized child %d != %d\n",
1453 minmax
->ptMaxSize
.x
, my_minmax
.ptMaxSize
.x
);
1454 ok(minmax
->ptMaxSize
.y
== my_minmax
.ptMaxSize
.y
, "default height of maximized child %d != %d\n",
1455 minmax
->ptMaxSize
.y
, my_minmax
.ptMaxSize
.y
);
1460 case WM_MDIACTIVATE
:
1462 HWND active
, client
= GetParent(hwnd
);
1463 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1464 active
= (HWND
)SendMessageA(client
, WM_MDIGETACTIVE
, 0, 0);
1465 if (hwnd
== (HWND
)lparam
) /* if we are being activated */
1466 ok (active
== (HWND
)lparam
, "new active %p != active %p\n", (HWND
)lparam
, active
);
1468 ok (active
== (HWND
)wparam
, "old active %p != active %p\n", (HWND
)wparam
, active
);
1472 return DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1475 static LRESULT WINAPI
mdi_child_wnd_proc_2(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1482 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1484 trace("%s\n", (msg
== WM_NCCREATE
) ? "WM_NCCREATE" : "WM_CREATE");
1485 trace("x %d, y %d, cx %d, cy %d\n", cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
1487 ok(!(cs
->dwExStyle
& WS_EX_MDICHILD
), "WS_EX_MDICHILD should not be set\n");
1488 ok(cs
->lpCreateParams
== mdi_lParam_test_message
, "wrong cs->lpCreateParams\n");
1490 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_2"), "wrong class name\n");
1491 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1493 /* CREATESTRUCT should have fixed values */
1494 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1496 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1497 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1499 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1500 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1501 while Win95, Win2k, WinXP do. */
1502 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1503 ok(cs
->cy
== 0, "%d != 0\n", cs
->cy
);
1507 case WM_GETMINMAXINFO
:
1509 HWND parent
= GetParent(hwnd
);
1511 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1512 LONG style
, exstyle
;
1514 trace("WM_GETMINMAXINFO\n");
1516 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1517 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1519 GetClientRect(parent
, &rc
);
1520 trace("parent %p client size = (%d x %d)\n", parent
, rc
.right
, rc
.bottom
);
1522 GetClientRect(parent
, &rc
);
1523 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1524 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1525 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1526 trace("calculated max child window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1528 trace("ptReserved = (%d,%d)\n"
1529 "ptMaxSize = (%d,%d)\n"
1530 "ptMaxPosition = (%d,%d)\n"
1531 "ptMinTrackSize = (%d,%d)\n"
1532 "ptMaxTrackSize = (%d,%d)\n",
1533 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
1534 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
1535 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
1536 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
1537 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
1539 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1540 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1541 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1542 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1546 case WM_WINDOWPOSCHANGED
:
1548 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1551 GetWindowRect(hwnd
, &rc1
);
1552 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1553 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1554 /* note: winpos coordinates are relative to parent */
1555 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1556 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1557 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1559 GetWindowRect(hwnd
, &rc1
);
1560 GetClientRect(hwnd
, &rc2
);
1561 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1562 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1563 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1566 case WM_WINDOWPOSCHANGING
:
1568 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1569 WINDOWPOS my_winpos
= *winpos
;
1571 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1572 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1573 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1574 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1576 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1578 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1579 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1580 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1582 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1583 "DefWindowProc should not change WINDOWPOS values\n");
1588 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1591 static LRESULT WINAPI
mdi_main_wnd_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1593 static HWND mdi_client
;
1599 CLIENTCREATESTRUCT client_cs
;
1602 GetClientRect(hwnd
, &rc
);
1604 client_cs
.hWindowMenu
= 0;
1605 client_cs
.idFirstChild
= 1;
1607 /* MDIClient without MDIS_ALLCHILDSTYLES */
1608 mdi_client
= CreateWindowExA(0, "mdiclient",
1610 WS_CHILD
/*| WS_VISIBLE*/,
1611 /* tests depend on a not zero MDIClient size */
1612 0, 0, rc
.right
, rc
.bottom
,
1613 hwnd
, 0, GetModuleHandle(0),
1614 (LPVOID
)&client_cs
);
1616 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1617 DestroyWindow(mdi_client
);
1619 /* MDIClient with MDIS_ALLCHILDSTYLES */
1620 mdi_client
= CreateWindowExA(0, "mdiclient",
1622 WS_CHILD
| MDIS_ALLCHILDSTYLES
/*| WS_VISIBLE*/,
1623 /* tests depend on a not zero MDIClient size */
1624 0, 0, rc
.right
, rc
.bottom
,
1625 hwnd
, 0, GetModuleHandle(0),
1626 (LPVOID
)&client_cs
);
1628 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1629 DestroyWindow(mdi_client
);
1633 case WM_WINDOWPOSCHANGED
:
1635 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1638 GetWindowRect(hwnd
, &rc1
);
1639 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1640 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1641 /* note: winpos coordinates are relative to parent */
1642 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1643 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1644 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1646 GetWindowRect(hwnd
, &rc1
);
1647 GetClientRect(hwnd
, &rc2
);
1648 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1649 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1650 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1653 case WM_WINDOWPOSCHANGING
:
1655 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1656 WINDOWPOS my_winpos
= *winpos
;
1658 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1659 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1660 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1661 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1663 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1665 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1666 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1667 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1669 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1670 "DefWindowProc should not change WINDOWPOS values\n");
1679 return DefFrameProcA(hwnd
, mdi_client
, msg
, wparam
, lparam
);
1682 static BOOL
mdi_RegisterWindowClasses(void)
1687 cls
.lpfnWndProc
= mdi_main_wnd_procA
;
1690 cls
.hInstance
= GetModuleHandleA(0);
1692 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
1693 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1694 cls
.lpszMenuName
= NULL
;
1695 cls
.lpszClassName
= "MDI_parent_Class";
1696 if(!RegisterClassA(&cls
)) return FALSE
;
1698 cls
.lpfnWndProc
= mdi_child_wnd_proc_1
;
1699 cls
.lpszClassName
= "MDI_child_Class_1";
1700 if(!RegisterClassA(&cls
)) return FALSE
;
1702 cls
.lpfnWndProc
= mdi_child_wnd_proc_2
;
1703 cls
.lpszClassName
= "MDI_child_Class_2";
1704 if(!RegisterClassA(&cls
)) return FALSE
;
1709 static void test_mdi(void)
1714 if (!mdi_RegisterWindowClasses()) assert(0);
1716 mdi_hwndMain
= CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1717 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
1718 WS_MAXIMIZEBOX
/*| WS_VISIBLE*/,
1719 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1720 GetDesktopWindow(), 0,
1721 GetModuleHandle(0), NULL
);
1722 assert(mdi_hwndMain
);
1724 while(GetMessage(&msg, 0, 0, 0))
1726 TranslateMessage(&msg);
1727 DispatchMessage(&msg);
1732 static void test_icons(void)
1736 HICON icon
= LoadIconA(0, (LPSTR
)IDI_APPLICATION
);
1737 HICON icon2
= LoadIconA(0, (LPSTR
)IDI_QUESTION
);
1738 HICON small_icon
= LoadImageA(0, (LPSTR
)IDI_APPLICATION
, IMAGE_ICON
,
1739 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
1742 cls
.cbSize
= sizeof(cls
);
1744 cls
.lpfnWndProc
= DefWindowProcA
;
1748 cls
.hIcon
= LoadIconA(0, (LPSTR
)IDI_HAND
);
1749 cls
.hIconSm
= small_icon
;
1750 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
1751 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1752 cls
.lpszMenuName
= NULL
;
1753 cls
.lpszClassName
= "IconWindowClass";
1755 RegisterClassExA(&cls
);
1757 hwnd
= CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1758 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, NULL
, NULL
);
1761 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1762 ok( res
== 0, "wrong big icon %p/0\n", res
);
1763 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon
);
1764 ok( res
== 0, "wrong previous big icon %p/0\n", res
);
1765 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1766 ok( res
== icon
, "wrong big icon after set %p/%p\n", res
, icon
);
1767 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon2
);
1768 ok( res
== icon
, "wrong previous big icon %p/%p\n", res
, icon
);
1769 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1770 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1772 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1773 ok( res
== 0, "wrong small icon %p/0\n", res
);
1774 /* this test is XP specific */
1775 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1776 ok( res != 0, "wrong small icon %p\n", res );*/
1777 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)icon
);
1778 ok( res
== 0, "wrong previous small icon %p/0\n", res
);
1779 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1780 ok( res
== icon
, "wrong small icon after set %p/%p\n", res
, icon
);
1781 /* this test is XP specific */
1782 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1783 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1784 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)small_icon
);
1785 ok( res
== icon
, "wrong previous small icon %p/%p\n", res
, icon
);
1786 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1787 ok( res
== small_icon
, "wrong small icon after set %p/%p\n", res
, small_icon
);
1788 /* this test is XP specific */
1789 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1790 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1792 /* make sure the big icon hasn't changed */
1793 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1794 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1797 static LRESULT WINAPI
nccalcsize_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1799 if (msg
== WM_NCCALCSIZE
)
1801 RECT
*rect
= (RECT
*)lparam
;
1802 /* first time around increase the rectangle, next time decrease it */
1803 if (rect
->left
== 100) InflateRect( rect
, 10, 10 );
1804 else InflateRect( rect
, -10, -10 );
1807 return DefWindowProc( hwnd
, msg
, wparam
, lparam
);
1810 static void test_SetWindowPos(HWND hwnd
)
1812 RECT orig_win_rc
, rect
;
1814 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
1816 SetRect(&rect
, 111, 222, 333, 444);
1817 ok(!GetWindowRect(0, &rect
), "GetWindowRect succeeded\n");
1818 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1819 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1821 SetRect(&rect
, 111, 222, 333, 444);
1822 ok(!GetClientRect(0, &rect
), "GetClientRect succeeded\n");
1823 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1824 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1826 GetWindowRect(hwnd
, &orig_win_rc
);
1828 old_proc
= SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)nccalcsize_proc
);
1829 SetWindowPos(hwnd
, 0, 100, 100, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1830 GetWindowRect( hwnd
, &rect
);
1831 ok( rect
.left
== 100 && rect
.top
== 100 && rect
.right
== 100 && rect
.bottom
== 100,
1832 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1833 GetClientRect( hwnd
, &rect
);
1834 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1835 ok( rect
.left
== 90 && rect
.top
== 90 && rect
.right
== 110 && rect
.bottom
== 110,
1836 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1838 SetWindowPos(hwnd
, 0, 200, 200, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1839 GetWindowRect( hwnd
, &rect
);
1840 ok( rect
.left
== 200 && rect
.top
== 200 && rect
.right
== 200 && rect
.bottom
== 200,
1841 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1842 GetClientRect( hwnd
, &rect
);
1843 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1844 ok( rect
.left
== 210 && rect
.top
== 210 && rect
.right
== 190 && rect
.bottom
== 190,
1845 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1847 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1848 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1849 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, old_proc
);
1851 /* Win9x truncates coordinates to 16-bit irrespectively */
1854 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE
);
1855 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE
);
1857 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE
);
1858 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE
);
1861 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1862 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1865 static void test_SetMenu(HWND parent
)
1869 BOOL is_win9x
= GetWindowLongPtrW(parent
, GWLP_WNDPROC
) == 0;
1873 hMenu
= CreateMenu();
1876 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1879 /* fails on (at least) Wine, NT4, XP SP2 */
1880 test_nonclient_area(parent
);
1882 ret
= GetMenu(parent
);
1883 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1884 /* test whether we can destroy a menu assigned to a window */
1885 retok
= DestroyMenu(hMenu
);
1886 ok( retok
, "DestroyMenu error %d\n", GetLastError());
1887 ok(!IsMenu(hMenu
), "menu handle should be not valid after DestroyMenu\n");
1888 ret
= GetMenu(parent
);
1889 /* This test fails on Win9x */
1891 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1892 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1893 test_nonclient_area(parent
);
1895 hMenu
= CreateMenu();
1899 ret
= GetMenu(parent
);
1900 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1902 ok(!SetMenu(parent
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1903 test_nonclient_area(parent
);
1904 ret
= GetMenu(parent
);
1905 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1907 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1910 /* fails on (at least) Wine, NT4, XP SP2 */
1911 test_nonclient_area(parent
);
1913 ret
= GetMenu(parent
);
1914 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1916 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1917 test_nonclient_area(parent
);
1918 ret
= GetMenu(parent
);
1919 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1922 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, parent
, (HMENU
)10, 0, NULL
);
1925 ret
= GetMenu(child
);
1926 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1928 ok(!SetMenu(child
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1929 test_nonclient_area(child
);
1930 ret
= GetMenu(child
);
1931 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1933 ok(!SetMenu(child
, hMenu
), "SetMenu on a child window should fail\n");
1934 test_nonclient_area(child
);
1935 ret
= GetMenu(child
);
1936 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1938 ok(!SetMenu(child
, 0), "SetMenu(0) on a child window should fail\n");
1939 test_nonclient_area(child
);
1940 ret
= GetMenu(child
);
1941 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1943 style
= GetWindowLong(child
, GWL_STYLE
);
1944 SetWindowLong(child
, GWL_STYLE
, style
| WS_POPUP
);
1945 ok(SetMenu(child
, hMenu
), "SetMenu on a popup child window should not fail\n");
1946 ok(SetMenu(child
, 0), "SetMenu on a popup child window should not fail\n");
1947 SetWindowLong(child
, GWL_STYLE
, style
);
1949 SetWindowLong(child
, GWL_STYLE
, style
| WS_OVERLAPPED
);
1950 ok(!SetMenu(child
, hMenu
), "SetMenu on a overlapped child window should fail\n");
1951 SetWindowLong(child
, GWL_STYLE
, style
);
1953 DestroyWindow(child
);
1957 static void test_window_tree(HWND parent
, const DWORD
*style
, const int *order
, int total
)
1959 HWND child
[5], hwnd
;
1964 hwnd
= GetWindow(parent
, GW_CHILD
);
1965 ok(!hwnd
, "have to start without children to perform the test\n");
1967 for (i
= 0; i
< total
; i
++)
1969 if (style
[i
] & DS_CONTROL
)
1971 child
[i
] = CreateWindowExA(0, MAKEINTATOM(32770), "", style
[i
] & ~WS_VISIBLE
,
1972 0,0,0,0, parent
, (HMENU
)i
, 0, NULL
);
1973 if (style
[i
] & WS_VISIBLE
)
1974 ShowWindow(child
[i
], SW_SHOW
);
1976 SetWindowPos(child
[i
], HWND_BOTTOM
, 0,0,10,10, SWP_NOACTIVATE
);
1979 child
[i
] = CreateWindowExA(0, "static", "", style
[i
], 0,0,10,10,
1980 parent
, (HMENU
)i
, 0, NULL
);
1981 trace("child[%d] = %p\n", i
, child
[i
]);
1982 ok(child
[i
] != 0, "CreateWindowEx failed to create child window\n");
1985 hwnd
= GetWindow(parent
, GW_CHILD
);
1986 ok(hwnd
!= 0, "GetWindow(GW_CHILD) failed\n");
1987 ok(hwnd
== GetWindow(child
[total
- 1], GW_HWNDFIRST
), "GW_HWNDFIRST is wrong\n");
1988 ok(child
[order
[total
- 1]] == GetWindow(child
[0], GW_HWNDLAST
), "GW_HWNDLAST is wrong\n");
1990 for (i
= 0; i
< total
; i
++)
1992 trace("hwnd[%d] = %p\n", i
, hwnd
);
1993 ok(child
[order
[i
]] == hwnd
, "Z order of child #%d is wrong\n", i
);
1995 hwnd
= GetWindow(hwnd
, GW_HWNDNEXT
);
1998 for (i
= 0; i
< total
; i
++)
1999 ok(DestroyWindow(child
[i
]), "DestroyWindow failed\n");
2002 static void test_children_zorder(HWND parent
)
2004 const DWORD simple_style
[5] = { WS_CHILD
, WS_CHILD
, WS_CHILD
, WS_CHILD
,
2006 const int simple_order
[5] = { 0, 1, 2, 3, 4 };
2008 const DWORD complex_style
[5] = { WS_CHILD
, WS_CHILD
| WS_MAXIMIZE
,
2009 WS_CHILD
| WS_VISIBLE
, WS_CHILD
,
2010 WS_CHILD
| WS_MAXIMIZE
| WS_VISIBLE
};
2011 const int complex_order_1
[1] = { 0 };
2012 const int complex_order_2
[2] = { 1, 0 };
2013 const int complex_order_3
[3] = { 1, 0, 2 };
2014 const int complex_order_4
[4] = { 1, 0, 2, 3 };
2015 const int complex_order_5
[5] = { 4, 1, 0, 2, 3 };
2016 const DWORD complex_style_6
[3] = { WS_CHILD
| WS_VISIBLE
,
2017 WS_CHILD
| WS_CLIPSIBLINGS
| DS_CONTROL
| WS_VISIBLE
,
2018 WS_CHILD
| WS_VISIBLE
};
2019 const int complex_order_6
[3] = { 0, 1, 2 };
2021 /* simple WS_CHILD */
2022 test_window_tree(parent
, simple_style
, simple_order
, 5);
2024 /* complex children styles */
2025 test_window_tree(parent
, complex_style
, complex_order_1
, 1);
2026 test_window_tree(parent
, complex_style
, complex_order_2
, 2);
2027 test_window_tree(parent
, complex_style
, complex_order_3
, 3);
2028 test_window_tree(parent
, complex_style
, complex_order_4
, 4);
2029 test_window_tree(parent
, complex_style
, complex_order_5
, 5);
2031 /* another set of complex children styles */
2032 test_window_tree(parent
, complex_style_6
, complex_order_6
, 3);
2035 static void test_vis_rgn( HWND hwnd
)
2037 RECT win_rect
, rgn_rect
;
2038 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2041 ShowWindow(hwnd
,SW_SHOW
);
2042 hdc
= GetDC( hwnd
);
2043 ok( GetRandomRgn( hdc
, hrgn
, SYSRGN
) != 0, "GetRandomRgn failed\n" );
2044 GetWindowRect( hwnd
, &win_rect
);
2045 GetRgnBox( hrgn
, &rgn_rect
);
2046 if (GetVersion() & 0x80000000)
2048 trace("win9x, mapping to screen coords\n");
2049 MapWindowPoints( hwnd
, 0, (POINT
*)&rgn_rect
, 2 );
2051 trace("win: %d,%d-%d,%d\n", win_rect
.left
, win_rect
.top
, win_rect
.right
, win_rect
.bottom
);
2052 trace("rgn: %d,%d-%d,%d\n", rgn_rect
.left
, rgn_rect
.top
, rgn_rect
.right
, rgn_rect
.bottom
);
2053 ok( win_rect
.left
<= rgn_rect
.left
, "rgn left %d not inside win rect %d\n",
2054 rgn_rect
.left
, win_rect
.left
);
2055 ok( win_rect
.top
<= rgn_rect
.top
, "rgn top %d not inside win rect %d\n",
2056 rgn_rect
.top
, win_rect
.top
);
2057 ok( win_rect
.right
>= rgn_rect
.right
, "rgn right %d not inside win rect %d\n",
2058 rgn_rect
.right
, win_rect
.right
);
2059 ok( win_rect
.bottom
>= rgn_rect
.bottom
, "rgn bottom %d not inside win rect %d\n",
2060 rgn_rect
.bottom
, win_rect
.bottom
);
2061 ReleaseDC( hwnd
, hdc
);
2064 static void test_SetFocus(HWND hwnd
)
2068 /* check if we can set focus to non-visible windows */
2070 ShowWindow(hwnd
, SW_SHOW
);
2073 ok( GetFocus() == hwnd
, "Failed to set focus to visible window %p\n", hwnd
);
2074 ok( GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
, "Window %p not visible\n", hwnd
);
2075 ShowWindow(hwnd
, SW_HIDE
);
2078 ok( GetFocus() == hwnd
, "Failed to set focus to invisible window %p\n", hwnd
);
2079 ok( !(GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
), "Window %p still visible\n", hwnd
);
2080 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2083 ok( GetFocus() == child
, "Failed to set focus to invisible child %p\n", child
);
2084 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2085 ShowWindow(child
, SW_SHOW
);
2086 ok( GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
, "Child %p is not visible\n", child
);
2087 ok( GetFocus() == child
, "Focus no longer on child %p\n", child
);
2088 ShowWindow(child
, SW_HIDE
);
2089 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2090 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2091 ShowWindow(child
, SW_SHOW
);
2093 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2094 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_HIDEWINDOW
);
2095 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2097 ShowWindow(child
, SW_HIDE
);
2099 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2100 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_SHOWWINDOW
);
2101 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2102 ShowWindow(child
, SW_HIDE
);
2103 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2105 ShowWindow(hwnd
, SW_SHOW
);
2106 ShowWindow(child
, SW_SHOW
);
2108 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2109 EnableWindow(hwnd
, FALSE
);
2110 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2111 EnableWindow(hwnd
, TRUE
);
2113 DestroyWindow( child
);
2116 static void check_wnd_state(HWND active
, HWND foreground
, HWND focus
, HWND capture
)
2118 ok(active
== GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2120 ok(foreground
== GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2121 ok(focus
== GetFocus(), "GetFocus() = %p\n", GetFocus());
2122 ok(capture
== GetCapture(), "GetCapture() = %p\n", GetCapture());
2125 static void test_SetActiveWindow(HWND hwnd
)
2129 ShowWindow(hwnd
, SW_HIDE
);
2132 check_wnd_state(0, 0, 0, 0);
2134 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2136 ShowWindow(hwnd
, SW_SHOW
);
2137 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2139 hwnd2
= SetActiveWindow(0);
2140 ok(hwnd2
== hwnd
, "SetActiveWindow returned %p instead of %p\n", hwnd2
, hwnd
);
2141 check_wnd_state(0, 0, 0, 0);
2143 hwnd2
= SetActiveWindow(hwnd
);
2144 ok(hwnd2
== 0, "SetActiveWindow returned %p instead of 0\n", hwnd2
);
2145 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2147 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2148 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2150 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2151 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2153 ShowWindow(hwnd
, SW_HIDE
);
2154 check_wnd_state(0, 0, 0, 0);
2156 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2157 SetActiveWindow(hwnd
);
2158 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2160 ShowWindow(hwnd
, SW_SHOW
);
2161 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2163 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2164 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2166 DestroyWindow(hwnd2
);
2167 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2169 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2170 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2172 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2173 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2175 DestroyWindow(hwnd2
);
2176 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2179 static void test_SetForegroundWindow(HWND hwnd
)
2184 ShowWindow(hwnd
, SW_HIDE
);
2187 check_wnd_state(0, 0, 0, 0);
2189 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2191 ShowWindow(hwnd
, SW_SHOW
);
2192 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2194 hwnd2
= SetActiveWindow(0);
2195 ok(hwnd2
== hwnd
, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2
, hwnd
);
2196 check_wnd_state(0, 0, 0, 0);
2198 ret
= SetForegroundWindow(hwnd
);
2199 ok(ret
, "SetForegroundWindow returned FALSE instead of TRUE\n");
2200 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2202 SetLastError(0xdeadbeef);
2203 ret
= SetForegroundWindow(0);
2204 ok(!ret
, "SetForegroundWindow returned TRUE instead of FALSE\n");
2205 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2206 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2208 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2209 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2211 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2212 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2214 ShowWindow(hwnd
, SW_HIDE
);
2215 check_wnd_state(0, 0, 0, 0);
2217 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2218 ret
= SetForegroundWindow(hwnd
);
2219 ok(ret
, "SetForegroundWindow returned FALSE instead of TRUE\n");
2220 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2222 ShowWindow(hwnd
, SW_SHOW
);
2223 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2225 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2226 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2228 DestroyWindow(hwnd2
);
2229 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2231 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2232 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2234 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2235 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2237 DestroyWindow(hwnd2
);
2238 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2241 static WNDPROC old_button_proc
;
2243 static LRESULT WINAPI
button_hook_proc(HWND button
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2248 key_state
= GetKeyState(VK_LBUTTON
);
2249 ok(!(key_state
& 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state
);
2251 ret
= CallWindowProcA(old_button_proc
, button
, msg
, wparam
, lparam
);
2253 if (msg
== WM_LBUTTONDOWN
)
2257 check_wnd_state(button
, button
, button
, button
);
2259 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2261 trace("hwnd %p\n", hwnd
);
2263 check_wnd_state(button
, button
, button
, button
);
2265 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2267 check_wnd_state(button
, button
, button
, button
);
2269 DestroyWindow(hwnd
);
2271 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2273 trace("hwnd %p\n", hwnd
);
2275 check_wnd_state(button
, button
, button
, button
);
2277 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2278 * match internal button state.
2280 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2281 check_wnd_state(button
, button
, button
, 0);
2283 ShowWindow(hwnd
, SW_SHOW
);
2284 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2286 capture
= SetCapture(hwnd
);
2287 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2289 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2291 DestroyWindow(hwnd
);
2293 check_wnd_state(button
, 0, button
, 0);
2299 static void test_capture_1(void)
2301 HWND button
, capture
;
2303 capture
= GetCapture();
2304 ok(capture
== 0, "GetCapture() = %p\n", capture
);
2306 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2308 trace("button %p\n", button
);
2310 old_button_proc
= (WNDPROC
)SetWindowLongPtrA(button
, GWLP_WNDPROC
, (LONG_PTR
)button_hook_proc
);
2312 SendMessageA(button
, WM_LBUTTONDOWN
, 0, 0);
2314 capture
= SetCapture(button
);
2315 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2316 check_wnd_state(button
, 0, button
, button
);
2318 DestroyWindow(button
);
2319 check_wnd_state(0, 0, 0, 0);
2322 static void test_capture_2(void)
2324 HWND button
, hwnd
, capture
;
2326 check_wnd_state(0, 0, 0, 0);
2328 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2330 trace("button %p\n", button
);
2332 check_wnd_state(button
, button
, button
, 0);
2334 capture
= SetCapture(button
);
2335 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2337 check_wnd_state(button
, button
, button
, button
);
2339 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2340 * internal button state.
2342 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2343 check_wnd_state(button
, button
, button
, button
);
2345 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2347 trace("hwnd %p\n", hwnd
);
2349 check_wnd_state(button
, button
, button
, button
);
2351 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2353 check_wnd_state(button
, button
, button
, button
);
2355 DestroyWindow(hwnd
);
2357 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2359 trace("hwnd %p\n", hwnd
);
2361 check_wnd_state(button
, button
, button
, button
);
2363 ShowWindow(hwnd
, SW_SHOW
);
2365 check_wnd_state(hwnd
, hwnd
, hwnd
, button
);
2367 capture
= SetCapture(hwnd
);
2368 ok(capture
== button
, "SetCapture() = %p\n", capture
);
2370 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2372 DestroyWindow(hwnd
);
2373 check_wnd_state(button
, button
, button
, 0);
2375 DestroyWindow(button
);
2376 check_wnd_state(0, 0, 0, 0);
2379 static void test_capture_3(HWND hwnd1
, HWND hwnd2
)
2383 ShowWindow(hwnd1
, SW_HIDE
);
2384 ShowWindow(hwnd2
, SW_HIDE
);
2386 ok(!IsWindowVisible(hwnd1
), "%p should be invisible\n", hwnd1
);
2387 ok(!IsWindowVisible(hwnd2
), "%p should be invisible\n", hwnd2
);
2390 check_wnd_state(0, 0, 0, hwnd1
);
2393 check_wnd_state(0, 0, 0, hwnd2
);
2395 ShowWindow(hwnd1
, SW_SHOW
);
2396 check_wnd_state(hwnd1
, hwnd1
, hwnd1
, hwnd2
);
2398 ret
= ReleaseCapture();
2399 ok (ret
, "releasecapture did not return TRUE.\n");
2400 ret
= ReleaseCapture();
2401 ok (ret
, "releasecapture did not return TRUE after second try.\n");
2404 static void test_keyboard_input(HWND hwnd
)
2409 ShowWindow(hwnd
, SW_SHOW
);
2413 ok(GetActiveWindow() == hwnd
, "wrong active window %p\n", GetActiveWindow());
2416 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2418 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2420 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2421 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2422 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2423 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2424 ok( !ret
, "message %04x available\n", msg
.message
);
2426 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2428 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2429 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2430 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2431 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2432 ok( !ret
, "message %04x available\n", msg
.message
);
2434 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2436 keybd_event(VK_SPACE
, 0, 0, 0);
2437 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2438 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2439 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2440 ok( !ret
, "message %04x available\n", msg
.message
);
2443 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2445 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage(&msg
);
2447 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2448 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2449 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2450 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2451 ok( !ret
, "message %04x available\n", msg
.message
);
2453 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2455 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2456 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2457 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2458 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2459 ok( !ret
, "message %04x available\n", msg
.message
);
2461 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2463 keybd_event(VK_SPACE
, 0, 0, 0);
2464 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2465 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_SYSKEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2466 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2467 ok( !ret
, "message %04x available\n", msg
.message
);
2470 static void test_mouse_input(HWND hwnd
)
2480 ShowWindow(hwnd
, SW_SHOW
);
2483 GetWindowRect(hwnd
, &rc
);
2484 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2486 popup
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_POPUP
,
2487 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
,
2490 ShowWindow(popup
, SW_SHOW
);
2491 UpdateWindow(popup
);
2493 GetWindowRect(popup
, &rc
);
2494 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2496 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
2497 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
2498 trace("setting cursor to (%d,%d)\n", x
, y
);
2502 ok(x
== pt
.x
&& y
== pt
.y
, "wrong cursor pos (%d,%d), expected (%d,%d)\n", pt
.x
, pt
.y
, x
, y
);
2504 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2506 /* Check that setting the same position will generate WM_MOUSEMOVE */
2509 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2510 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2511 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
);
2513 /* force the system to update its internal queue mouse position,
2514 * otherwise it won't generate relative mouse movements below.
2516 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2517 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2520 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2521 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2522 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2523 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2524 if (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
2525 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2526 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2527 ok( !ret
, "message %04x available\n", msg
.message
);
2529 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2530 ShowWindow(popup
, SW_HIDE
);
2531 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2532 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2533 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2535 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2536 ShowWindow(hwnd
, SW_HIDE
);
2537 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2538 ok( !ret
, "message %04x available\n", msg
.message
);
2540 /* test mouse clicks */
2542 ShowWindow(hwnd
, SW_SHOW
);
2543 ShowWindow(popup
, SW_SHOW
);
2545 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2548 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2549 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2550 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2551 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2553 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2554 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2555 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2556 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2558 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2559 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2560 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2561 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2563 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2564 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2565 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2566 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2568 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2569 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2570 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2571 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2573 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2574 ok(!ret
, "message %04x available\n", msg
.message
);
2576 ShowWindow(popup
, SW_HIDE
);
2577 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2579 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2580 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2581 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2582 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2584 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2585 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2586 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2587 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2589 test_lbuttondown_flag
= TRUE
;
2590 SendMessageA(hwnd
, WM_COMMAND
, (WPARAM
)popup
, 0);
2591 test_lbuttondown_flag
= FALSE
;
2593 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2594 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2595 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2596 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2597 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2599 /* Test WM_MOUSEACTIVATE */
2600 #define TEST_MOUSEACTIVATE(A,B) \
2601 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2602 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2604 TEST_MOUSEACTIVATE(HTERROR
,MA_ACTIVATE
);
2605 TEST_MOUSEACTIVATE(HTTRANSPARENT
,MA_ACTIVATE
);
2606 TEST_MOUSEACTIVATE(HTNOWHERE
,MA_ACTIVATE
);
2607 TEST_MOUSEACTIVATE(HTCLIENT
,MA_ACTIVATE
);
2608 TEST_MOUSEACTIVATE(HTCAPTION
,MA_ACTIVATE
);
2609 TEST_MOUSEACTIVATE(HTSYSMENU
,MA_ACTIVATE
);
2610 TEST_MOUSEACTIVATE(HTSIZE
,MA_ACTIVATE
);
2611 TEST_MOUSEACTIVATE(HTMENU
,MA_ACTIVATE
);
2612 TEST_MOUSEACTIVATE(HTHSCROLL
,MA_ACTIVATE
);
2613 TEST_MOUSEACTIVATE(HTVSCROLL
,MA_ACTIVATE
);
2614 TEST_MOUSEACTIVATE(HTMINBUTTON
,MA_ACTIVATE
);
2615 TEST_MOUSEACTIVATE(HTMAXBUTTON
,MA_ACTIVATE
);
2616 TEST_MOUSEACTIVATE(HTLEFT
,MA_ACTIVATE
);
2617 TEST_MOUSEACTIVATE(HTRIGHT
,MA_ACTIVATE
);
2618 TEST_MOUSEACTIVATE(HTTOP
,MA_ACTIVATE
);
2619 TEST_MOUSEACTIVATE(HTTOPLEFT
,MA_ACTIVATE
);
2620 TEST_MOUSEACTIVATE(HTTOPRIGHT
,MA_ACTIVATE
);
2621 TEST_MOUSEACTIVATE(HTBOTTOM
,MA_ACTIVATE
);
2622 TEST_MOUSEACTIVATE(HTBOTTOMLEFT
,MA_ACTIVATE
);
2623 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT
,MA_ACTIVATE
);
2624 TEST_MOUSEACTIVATE(HTBORDER
,MA_ACTIVATE
);
2625 TEST_MOUSEACTIVATE(HTOBJECT
,MA_ACTIVATE
);
2626 TEST_MOUSEACTIVATE(HTCLOSE
,MA_ACTIVATE
);
2627 TEST_MOUSEACTIVATE(HTHELP
,MA_ACTIVATE
);
2629 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2630 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2632 DestroyWindow(popup
);
2635 static void test_validatergn(HWND hwnd
)
2641 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_VISIBLE
, 10, 10, 10, 10, hwnd
, 0, 0, NULL
);
2642 ShowWindow(hwnd
, SW_SHOW
);
2643 UpdateWindow( hwnd
);
2644 /* test that ValidateRect validates children*/
2645 InvalidateRect( child
, NULL
, 1);
2646 GetWindowRect( child
, &rc
);
2647 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2648 ret
= GetUpdateRect( child
, &rc2
, 0);
2649 ok( rc2
.right
> rc2
.left
&& rc2
.bottom
> rc2
.top
,
2650 "Update rectangle is empty!\n");
2651 ValidateRect( hwnd
, &rc
);
2652 ret
= GetUpdateRect( child
, &rc2
, 0);
2653 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2654 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
2655 rc2
.right
, rc2
.bottom
);
2657 /* now test ValidateRgn */
2658 InvalidateRect( child
, NULL
, 1);
2659 GetWindowRect( child
, &rc
);
2660 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2661 rgn
= CreateRectRgnIndirect( &rc
);
2662 ValidateRgn( hwnd
, rgn
);
2663 ret
= GetUpdateRect( child
, &rc2
, 0);
2664 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2665 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
2666 rc2
.right
, rc2
.bottom
);
2669 DestroyWindow( child
);
2672 static void nccalchelper(HWND hwnd
, INT x
, INT y
, RECT
*prc
)
2674 MoveWindow( hwnd
, 0, 0, x
, y
, 0);
2675 GetWindowRect( hwnd
, prc
);
2676 trace("window rect is %d,%d - %d,%d\n",
2677 prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
2678 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)prc
);
2679 trace("nccalc rect is %d,%d - %d,%d\n",
2680 prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
2683 static void test_nccalcscroll(HWND parent
)
2686 INT sbheight
= GetSystemMetrics( SM_CYHSCROLL
);
2687 INT sbwidth
= GetSystemMetrics( SM_CXVSCROLL
);
2688 HWND hwnd
= CreateWindowExA(0, "static", NULL
,
2689 WS_CHILD
| WS_VISIBLE
| WS_VSCROLL
| WS_HSCROLL
,
2690 10, 10, 200, 200, parent
, 0, 0, NULL
);
2691 ShowWindow( parent
, SW_SHOW
);
2692 UpdateWindow( parent
);
2694 /* test window too low for a horizontal scroll bar */
2695 nccalchelper( hwnd
, 100, sbheight
, &rc1
);
2696 ok( rc1
.bottom
- rc1
.top
== sbheight
, "Height should be %d size is %d,%d - %d,%d\n",
2697 sbheight
, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2699 /* test window just high enough for a horizontal scroll bar */
2700 nccalchelper( hwnd
, 100, sbheight
+ 1, &rc1
);
2701 ok( rc1
.bottom
- rc1
.top
== 1, "Height should be %d size is %d,%d - %d,%d\n",
2702 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2704 /* test window too narrow for a vertical scroll bar */
2705 nccalchelper( hwnd
, sbwidth
- 1, 100, &rc1
);
2706 ok( rc1
.right
- rc1
.left
== sbwidth
- 1 , "Width should be %d size is %d,%d - %d,%d\n",
2707 sbwidth
- 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2709 /* test window just wide enough for a vertical scroll bar */
2710 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
2711 ok( rc1
.right
- rc1
.left
== 0, "Width should be %d size is %d,%d - %d,%d\n",
2712 0, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2714 /* same test, but with client edge: not enough width */
2715 SetWindowLong( hwnd
, GWL_EXSTYLE
, WS_EX_CLIENTEDGE
| GetWindowLong( hwnd
, GWL_EXSTYLE
));
2716 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
2717 ok( rc1
.right
- rc1
.left
== sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
),
2718 "Width should be %d size is %d,%d - %d,%d\n",
2719 sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
), rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2721 DestroyWindow( hwnd
);
2724 static void test_SetParent(void)
2727 HWND desktop
= GetDesktopWindow();
2729 BOOL is_win9x
= GetWindowLongPtrW(desktop
, GWLP_WNDPROC
) == 0;
2730 HWND parent
, child1
, child2
, child3
, child4
, sibling
;
2732 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
2733 100, 100, 200, 200, 0, 0, 0, NULL
);
2734 assert(parent
!= 0);
2735 child1
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
2736 0, 0, 50, 50, parent
, 0, 0, NULL
);
2737 assert(child1
!= 0);
2738 child2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
2739 0, 0, 50, 50, child1
, 0, 0, NULL
);
2740 assert(child2
!= 0);
2741 child3
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
2742 0, 0, 50, 50, child2
, 0, 0, NULL
);
2743 assert(child3
!= 0);
2744 child4
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
2745 0, 0, 50, 50, child3
, 0, 0, NULL
);
2746 assert(child4
!= 0);
2748 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2749 parent
, child1
, child2
, child3
, child4
);
2751 check_parents(parent
, desktop
, 0, 0, 0, parent
, parent
);
2752 check_parents(child1
, parent
, parent
, parent
, 0, parent
, parent
);
2753 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
2754 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
2755 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
2758 ok(!IsChild(desktop
, parent
), "wrong parent/child %p/%p\n", desktop
, parent
);
2759 ok(!IsChild(desktop
, child1
), "wrong parent/child %p/%p\n", desktop
, child1
);
2760 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
2761 ok(!IsChild(desktop
, child3
), "wrong parent/child %p/%p\n", desktop
, child3
);
2762 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
2765 ok(IsChild(parent
, child1
), "wrong parent/child %p/%p\n", parent
, child1
);
2767 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
2769 ok(!IsChild(parent
, child2
), "wrong parent/child %p/%p\n", parent
, child2
);
2770 ok(!IsChild(child1
, child2
), "wrong parent/child %p/%p\n", child1
, child2
);
2771 ok(!IsChild(parent
, child3
), "wrong parent/child %p/%p\n", parent
, child3
);
2772 ok(IsChild(child2
, child3
), "wrong parent/child %p/%p\n", child2
, child3
);
2773 ok(!IsChild(parent
, child4
), "wrong parent/child %p/%p\n", parent
, child4
);
2774 ok(!IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
2776 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
2779 if (!is_win9x
) /* Win9x doesn't survive this test */
2781 ok(!SetParent(parent
, child1
), "SetParent should fail\n");
2782 ok(!SetParent(child2
, child3
), "SetParent should fail\n");
2783 ok(SetParent(child1
, parent
) != 0, "SetParent should not fail\n");
2784 ok(SetParent(parent
, child2
) != 0, "SetParent should not fail\n");
2785 ok(SetParent(parent
, child3
) != 0, "SetParent should not fail\n");
2786 ok(!SetParent(child2
, parent
), "SetParent should fail\n");
2787 ok(SetParent(parent
, child4
) != 0, "SetParent should not fail\n");
2789 check_parents(parent
, child4
, child4
, 0, 0, child4
, parent
);
2790 check_parents(child1
, parent
, parent
, parent
, 0, child4
, parent
);
2791 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
2792 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
2793 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
2796 hMenu
= CreateMenu();
2797 sibling
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
2798 100, 100, 200, 200, 0, hMenu
, 0, NULL
);
2799 assert(sibling
!= 0);
2801 ok(SetParent(sibling
, parent
) != 0, "SetParent should not fail\n");
2802 ok(GetMenu(sibling
) == hMenu
, "SetParent should not remove menu\n");
2804 ret
= DestroyWindow(parent
);
2805 ok( ret
, "DestroyWindow() error %d\n", GetLastError());
2807 ok(!IsWindow(parent
), "parent still exists\n");
2808 ok(!IsWindow(sibling
), "sibling still exists\n");
2809 ok(!IsWindow(child1
), "child1 still exists\n");
2810 ok(!IsWindow(child2
), "child2 still exists\n");
2811 ok(!IsWindow(child3
), "child3 still exists\n");
2812 ok(!IsWindow(child4
), "child4 still exists\n");
2815 static LRESULT WINAPI
StyleCheckProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2817 LPCREATESTRUCT lpcs
;
2824 lpcs
= (LPCREATESTRUCT
)lparam
;
2825 lpss
= (LPSTYLESTRUCT
)lpcs
->lpCreateParams
;
2828 if ((lpcs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
2829 ((!(lpcs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
2830 (lpcs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
2831 ok(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
, "Window should have WS_EX_WINDOWEDGE style\n");
2833 ok(!(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
2835 ok((lpss
->styleOld
& ~WS_EX_WINDOWEDGE
) == (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
),
2836 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2837 (lpss
->styleOld
& ~WS_EX_WINDOWEDGE
), (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
));
2839 ok(lpss
->styleNew
== lpcs
->style
,
2840 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
2841 lpss
->styleNew
, lpcs
->style
);
2845 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
2848 static ATOM atomStyleCheckClass
;
2850 static void register_style_check_class(void)
2858 GetModuleHandle(NULL
),
2860 LoadCursor(NULL
, IDC_ARROW
),
2861 (HBRUSH
)(COLOR_BTNFACE
+1),
2863 TEXT("WineStyleCheck"),
2866 atomStyleCheckClass
= RegisterClass(&wc
);
2869 static void check_window_style(DWORD dwStyleIn
, DWORD dwExStyleIn
, DWORD dwStyleOut
, DWORD dwExStyleOut
)
2871 DWORD dwActualStyle
;
2872 DWORD dwActualExStyle
;
2875 HWND hwndParent
= NULL
;
2878 ss
.styleNew
= dwStyleIn
;
2879 ss
.styleOld
= dwExStyleIn
;
2881 if (dwStyleIn
& WS_CHILD
)
2883 hwndParent
= CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass
), NULL
,
2884 WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
2887 hwnd
= CreateWindowEx(dwExStyleIn
, MAKEINTATOM(atomStyleCheckClass
), NULL
,
2888 dwStyleIn
, 0, 0, 0, 0, hwndParent
, NULL
, NULL
, &ss
);
2891 while (PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
))
2893 TranslateMessage(&msg
);
2894 DispatchMessage(&msg
);
2897 dwActualStyle
= GetWindowLong(hwnd
, GWL_STYLE
);
2898 dwActualExStyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
2899 ok((dwActualStyle
== dwStyleOut
) && (dwActualExStyle
== dwExStyleOut
),
2900 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
2901 dwActualStyle
, dwStyleOut
, dwActualExStyle
, dwExStyleOut
);
2903 DestroyWindow(hwnd
);
2904 if (hwndParent
) DestroyWindow(hwndParent
);
2907 /* tests what window styles the window manager automatically adds */
2908 static void test_window_styles(void)
2910 register_style_check_class();
2912 check_window_style(0, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
2913 check_window_style(WS_OVERLAPPEDWINDOW
, 0, WS_CLIPSIBLINGS
|WS_OVERLAPPEDWINDOW
, WS_EX_WINDOWEDGE
);
2914 check_window_style(WS_CHILD
, 0, WS_CHILD
, 0);
2915 check_window_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
2916 check_window_style(0, WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_TOOLWINDOW
);
2917 check_window_style(WS_POPUP
, 0, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
2918 check_window_style(WS_POPUP
, WS_EX_WINDOWEDGE
, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
2919 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
, WS_CHILD
, WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
2920 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
|WS_EX_STATICEDGE
, WS_CHILD
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
2921 check_window_style(WS_CAPTION
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
);
2922 check_window_style(0, WS_EX_APPWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_APPWINDOW
|WS_EX_WINDOWEDGE
);
2925 static void test_scrollvalidate( HWND parent
)
2928 HRGN hrgn
=CreateRectRgn(0,0,0,0);
2929 HRGN exprgn
, tmprgn
, clipping
;
2930 RECT rc
, rcu
, cliprc
;
2931 /* create two overlapping child windows. The visual region
2932 * of hwnd1 is clipped by the overlapping part of
2933 * hwnd2 because of the WS_CLIPSIBLING style */
2936 clipping
= CreateRectRgn(0,0,0,0);
2937 tmprgn
= CreateRectRgn(0,0,0,0);
2938 exprgn
= CreateRectRgn(0,0,0,0);
2939 hwnd2
= CreateWindowExA(0, "static", NULL
,
2940 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
2941 75, 30, 100, 100, parent
, 0, 0, NULL
);
2942 hwnd1
= CreateWindowExA(0, "static", NULL
,
2943 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
2944 25, 50, 100, 100, parent
, 0, 0, NULL
);
2945 ShowWindow( parent
, SW_SHOW
);
2946 UpdateWindow( parent
);
2947 GetClientRect( hwnd1
, &rc
);
2949 SetRectRgn( clipping
, 10, 10, 90, 90);
2950 hdc
= GetDC( hwnd1
);
2951 /* for a visual touch */
2952 TextOut( hdc
, 0,10, "0123456789", 10);
2953 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
2954 if (winetest_debug
> 0) dump_region(hrgn
);
2955 /* create a region with what is expected */
2956 SetRectRgn( exprgn
, 39,0,49,74);
2957 SetRectRgn( tmprgn
, 88,79,98,93);
2958 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
2959 SetRectRgn( tmprgn
, 0,93,98,98);
2960 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
2961 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
2962 trace("update rect is %d,%d - %d,%d\n",
2963 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
2964 /* now with clipping region */
2965 SelectClipRgn( hdc
, clipping
);
2966 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
2967 if (winetest_debug
> 0) dump_region(hrgn
);
2968 /* create a region with what is expected */
2969 SetRectRgn( exprgn
, 39,10,49,74);
2970 SetRectRgn( tmprgn
, 80,79,90,85);
2971 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
2972 SetRectRgn( tmprgn
, 10,85,90,90);
2973 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
2974 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
2975 trace("update rect is %d,%d - %d,%d\n",
2976 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
2977 ReleaseDC( hwnd1
, hdc
);
2979 /* test scrolling a window with an update region */
2980 DestroyWindow( hwnd2
);
2981 ValidateRect( hwnd1
, NULL
);
2982 SetRect( &rc
, 40,40, 50,50);
2983 InvalidateRect( hwnd1
, &rc
, 1);
2984 GetClientRect( hwnd1
, &rc
);
2986 ScrollWindowEx( hwnd1
, -10, 0, &rc
, &cliprc
, hrgn
, &rcu
,
2987 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
2988 if (winetest_debug
> 0) dump_region(hrgn
);
2989 SetRectRgn( exprgn
, 88,0,98,98);
2990 SetRectRgn( tmprgn
, 30, 40, 50, 50);
2991 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
2992 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
2994 /* clear an update region */
2995 UpdateWindow( hwnd1
);
2997 SetRect( &rc
, 0,40, 100,60);
2998 SetRect( &cliprc
, 0,0, 100,100);
2999 ScrollWindowEx( hwnd1
, 0, -25, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3000 if (winetest_debug
> 0) dump_region( hrgn
);
3001 SetRectRgn( exprgn
, 0, 40, 98, 60 );
3002 ok( EqualRgn( exprgn
, hrgn
), "wrong update region in excessive scroll\n");
3004 /* now test ScrollWindowEx with a combination of
3005 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3006 /* make hwnd2 the child of hwnd1 */
3007 hwnd2
= CreateWindowExA(0, "static", NULL
,
3008 WS_CHILD
| WS_VISIBLE
| WS_BORDER
,
3009 50, 50, 100, 100, hwnd1
, 0, 0, NULL
);
3010 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPSIBLINGS
);
3011 GetClientRect( hwnd1
, &rc
);
3014 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3015 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3016 ValidateRect( hwnd1
, NULL
);
3017 ValidateRect( hwnd2
, NULL
);
3018 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
,
3019 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3020 if (winetest_debug
> 0) dump_region(hrgn
);
3021 SetRectRgn( exprgn
, 88,0,98,88);
3022 SetRectRgn( tmprgn
, 0,88,98,98);
3023 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3024 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3026 /* SW_SCROLLCHILDREN */
3027 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3028 ValidateRect( hwnd1
, NULL
);
3029 ValidateRect( hwnd2
, NULL
);
3030 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3031 if (winetest_debug
> 0) dump_region(hrgn
);
3032 /* expected region is the same as in previous test */
3033 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3035 /* no SW_SCROLLCHILDREN */
3036 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3037 ValidateRect( hwnd1
, NULL
);
3038 ValidateRect( hwnd2
, NULL
);
3039 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3040 if (winetest_debug
> 0) dump_region(hrgn
);
3041 /* expected region is the same as in previous test */
3042 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3044 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3045 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3046 ValidateRect( hwnd1
, NULL
);
3047 ValidateRect( hwnd2
, NULL
);
3048 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3049 if (winetest_debug
> 0) dump_region(hrgn
);
3050 SetRectRgn( exprgn
, 88,0,98,20);
3051 SetRectRgn( tmprgn
, 20,20,98,30);
3052 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3053 SetRectRgn( tmprgn
, 20,30,30,88);
3054 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3055 SetRectRgn( tmprgn
, 0,88,30,98);
3056 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3057 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3060 DeleteObject( hrgn
);
3061 DeleteObject( exprgn
);
3062 DeleteObject( tmprgn
);
3063 DestroyWindow( hwnd1
);
3064 DestroyWindow( hwnd2
);
3067 /* couple of tests of return values of scrollbar functions
3068 * called on a scrollbarless window */
3069 static void test_scroll(void)
3074 HWND hwnd
= CreateWindowExA(0, "Static", "Wine test window",
3075 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_POPUP
,
3076 100, 100, 200, 200, 0, 0, 0, NULL
);
3078 ret
= GetScrollRange( hwnd
, SB_HORZ
, &min
, &max
);
3079 ok( ret
, "GetScrollRange returns FALSE\n");
3080 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3081 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3082 si
.cbSize
= sizeof( si
);
3083 si
.fMask
= SIF_PAGE
;
3084 si
.nPage
= 0xdeadbeef;
3085 ret
= GetScrollInfo( hwnd
, SB_HORZ
, &si
);
3086 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3087 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3089 ret
= GetScrollRange( hwnd
, SB_VERT
, &min
, &max
);
3090 ok( ret
, "GetScrollRange returns FALSE\n");
3091 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3092 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3093 si
.cbSize
= sizeof( si
);
3094 si
.fMask
= SIF_PAGE
;
3095 si
.nPage
= 0xdeadbeef;
3096 ret
= GetScrollInfo( hwnd
, SB_VERT
, &si
);
3097 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3098 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3100 DestroyWindow( hwnd
);
3103 static void test_scrolldc( HWND parent
)
3106 HRGN exprgn
, tmprgn
, hrgn
;
3107 RECT rc
, rc2
, rcu
, cliprc
;
3111 hrgn
= CreateRectRgn(0,0,0,0);
3112 tmprgn
= CreateRectRgn(0,0,0,0);
3113 exprgn
= CreateRectRgn(0,0,0,0);
3115 hwnd1
= CreateWindowExA(0, "static", NULL
,
3116 WS_CHILD
| WS_VISIBLE
,
3117 25, 50, 100, 100, parent
, 0, 0, NULL
);
3118 ShowWindow( parent
, SW_SHOW
);
3119 UpdateWindow( parent
);
3120 GetClientRect( hwnd1
, &rc
);
3121 hdc
= GetDC( hwnd1
);
3122 /* paint the upper half of the window black */
3124 rc2
.bottom
= ( rc
.top
+ rc
.bottom
) /2;
3125 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3126 /* clip region is the lower half */
3128 cliprc
.top
= (rc
.top
+ rc
.bottom
) /2;
3129 /* test whether scrolled pixels are properly clipped */
3130 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3131 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3132 /* this scroll should not cause any visible changes */
3133 ScrollDC( hdc
, 5, -20, &rc
, &cliprc
, hrgn
, &rcu
);
3134 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3135 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3136 /* test with NULL clip rect */
3137 ScrollDC( hdc
, 20, -20, &rc
, NULL
, hrgn
, &rcu
);
3138 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3139 trace("update rect: %d,%d - %d,%d\n",
3140 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3141 if (winetest_debug
> 0) dump_region(hrgn
);
3142 SetRect(&rc2
, 0, 0, 100, 100);
3143 ok(EqualRect(&rcu
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3144 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
3146 SetRectRgn( exprgn
, 0, 0, 20, 80);
3147 SetRectRgn( tmprgn
, 0, 80, 100, 100);
3148 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3149 if (winetest_debug
> 0) dump_region(exprgn
);
3150 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3151 /* test clip rect > scroll rect */
3152 FillRect( hdc
, &rc
, GetStockObject(WHITE_BRUSH
));
3154 InflateRect( &rc2
, -(rc
.right
-rc
.left
)/4, -(rc
.bottom
-rc
.top
)/4);
3155 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3156 ScrollDC( hdc
, 10, 10, &rc2
, &rc
, hrgn
, &rcu
);
3157 SetRectRgn( exprgn
, 25, 25, 75, 35);
3158 SetRectRgn( tmprgn
, 25, 35, 35, 75);
3159 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3160 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3161 colr
= GetPixel( hdc
, 80, 80);
3162 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3163 trace("update rect: %d,%d - %d,%d\n",
3164 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3165 if (winetest_debug
> 0) dump_region(hrgn
);
3169 DeleteObject(exprgn
);
3170 DeleteObject(tmprgn
);
3171 DestroyWindow(hwnd1
);
3174 static void test_params(void)
3179 /* Just a param check */
3180 SetLastError(0xdeadbeef);
3181 rc
= GetWindowText(hwndMain2
, NULL
, 1024);
3182 ok( rc
==0, "GetWindowText: rc=%d err=%d\n",rc
,GetLastError());
3184 SetLastError(0xdeadbeef);
3185 hwnd
=CreateWindow("LISTBOX", "TestList",
3186 (LBS_STANDARD
& ~LBS_SORT
),
3188 NULL
, (HMENU
)1, NULL
, 0);
3190 ok(!hwnd
, "CreateWindow with invalid menu handle should fail\n");
3191 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
|| /* NT */
3192 GetLastError() == 0xdeadbeef, /* Win9x */
3193 "wrong last error value %d\n", GetLastError());
3196 static void test_AWRwindow(LPCSTR
class, LONG style
, LONG exStyle
, BOOL menu
)
3200 hwnd
= CreateWindowEx(exStyle
, class, class, style
,
3207 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style
, exStyle
);
3210 ShowWindow(hwnd
, SW_SHOW
);
3212 test_nonclient_area(hwnd
);
3215 DestroyWindow(hwnd
);
3218 static BOOL
AWR_init(void)
3222 class.style
= CS_HREDRAW
| CS_VREDRAW
;
3223 class.lpfnWndProc
= DefWindowProcA
;
3224 class.cbClsExtra
= 0;
3225 class.cbWndExtra
= 0;
3226 class.hInstance
= 0;
3227 class.hIcon
= LoadIcon (0, IDI_APPLICATION
);
3228 class.hCursor
= LoadCursor (0, IDC_ARROW
);
3229 class.hbrBackground
= 0;
3230 class.lpszMenuName
= 0;
3231 class.lpszClassName
= szAWRClass
;
3233 if (!RegisterClass (&class)) {
3234 ok(FALSE
, "RegisterClass failed\n");
3238 hmenu
= CreateMenu();
3241 ok(hmenu
!= 0, "Failed to create menu\n");
3242 ok(AppendMenu(hmenu
, MF_STRING
, 1, "Test!"), "Failed to create menu item\n");
3248 static void test_AWR_window_size(BOOL menu
)
3252 WS_MAXIMIZE
, WS_BORDER
, WS_DLGFRAME
,
3255 WS_MINIMIZEBOX
, WS_MAXIMIZEBOX
,
3256 WS_HSCROLL
, WS_VSCROLL
3260 WS_EX_TOOLWINDOW
, WS_EX_WINDOWEDGE
,
3263 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3264 WS_EX_DLGMODALFRAME
,
3271 /* A exhaustive check of all the styles takes too long
3272 * so just do a (hopefully representative) sample
3274 for (i
= 0; i
< COUNTOF(styles
); ++i
)
3275 test_AWRwindow(szAWRClass
, styles
[i
], 0, menu
);
3276 for (i
= 0; i
< COUNTOF(exStyles
); ++i
) {
3277 test_AWRwindow(szAWRClass
, WS_POPUP
, exStyles
[i
], menu
);
3278 test_AWRwindow(szAWRClass
, WS_THICKFRAME
, exStyles
[i
], menu
);
3283 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3285 static void test_AdjustWindowRect(void)
3290 SHOWSYSMETRIC(SM_CYCAPTION
);
3291 SHOWSYSMETRIC(SM_CYSMCAPTION
);
3292 SHOWSYSMETRIC(SM_CYMENU
);
3293 SHOWSYSMETRIC(SM_CXEDGE
);
3294 SHOWSYSMETRIC(SM_CYEDGE
);
3295 SHOWSYSMETRIC(SM_CXVSCROLL
);
3296 SHOWSYSMETRIC(SM_CYHSCROLL
);
3297 SHOWSYSMETRIC(SM_CXFRAME
);
3298 SHOWSYSMETRIC(SM_CYFRAME
);
3299 SHOWSYSMETRIC(SM_CXDLGFRAME
);
3300 SHOWSYSMETRIC(SM_CYDLGFRAME
);
3301 SHOWSYSMETRIC(SM_CXBORDER
);
3302 SHOWSYSMETRIC(SM_CYBORDER
);
3304 test_AWR_window_size(FALSE
);
3305 test_AWR_window_size(TRUE
);
3309 #undef SHOWSYSMETRIC
3312 /* Global variables to trigger exit from loop */
3313 static int redrawComplete
, WMPAINT_count
;
3315 static LRESULT WINAPI
redraw_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3320 trace("doing WM_PAINT %d\n", WMPAINT_count
);
3322 if (WMPAINT_count
> 10 && redrawComplete
== 0) {
3324 BeginPaint(hwnd
, &ps
);
3325 EndPaint(hwnd
, &ps
);
3331 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3334 /* Ensure we exit from RedrawNow regardless of invalidated area */
3335 static void test_redrawnow(void)
3340 cls
.style
= CS_DBLCLKS
;
3341 cls
.lpfnWndProc
= redraw_window_procA
;
3344 cls
.hInstance
= GetModuleHandleA(0);
3346 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3347 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3348 cls
.lpszMenuName
= NULL
;
3349 cls
.lpszClassName
= "RedrawWindowClass";
3351 if(!RegisterClassA(&cls
)) {
3352 trace("Register failed %d\n", GetLastError());
3356 hwndMain
= CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3357 CW_USEDEFAULT
, 0, 100, 100, NULL
, NULL
, 0, NULL
);
3359 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3360 ShowWindow(hwndMain
, SW_SHOW
);
3361 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3362 RedrawWindow(hwndMain
, NULL
,NULL
,RDW_UPDATENOW
| RDW_ALLCHILDREN
);
3363 ok( WMPAINT_count
== 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3364 redrawComplete
= TRUE
;
3365 ok( WMPAINT_count
< 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count
);
3368 DestroyWindow( hwndMain
);
3371 struct parentdc_stat
{
3377 struct parentdc_test
{
3378 struct parentdc_stat main
, main_todo
;
3379 struct parentdc_stat child1
, child1_todo
;
3380 struct parentdc_stat child2
, child2_todo
;
3383 static LRESULT WINAPI
parentdc_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3388 struct parentdc_stat
*t
= (struct parentdc_stat
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
3393 trace("doing WM_PAINT on %p\n", hwnd
);
3394 GetClientRect(hwnd
, &rc
);
3395 CopyRect(&t
->client
, &rc
);
3396 trace("client rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3397 GetWindowRect(hwnd
, &rc
);
3398 trace("window rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3399 BeginPaint(hwnd
, &ps
);
3400 CopyRect(&t
->paint
, &ps
.rcPaint
);
3401 GetClipBox(ps
.hdc
, &rc
);
3402 CopyRect(&t
->clip
, &rc
);
3403 trace("clip rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3404 trace("paint rect (%d, %d)-(%d, %d)\n", ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
3405 EndPaint(hwnd
, &ps
);
3408 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3411 static void zero_parentdc_stat(struct parentdc_stat
*t
)
3413 SetRectEmpty(&t
->client
);
3414 SetRectEmpty(&t
->clip
);
3415 SetRectEmpty(&t
->paint
);
3418 static void zero_parentdc_test(struct parentdc_test
*t
)
3420 zero_parentdc_stat(&t
->main
);
3421 zero_parentdc_stat(&t
->child1
);
3422 zero_parentdc_stat(&t
->child2
);
3425 #define parentdc_field_ok(t, w, r, f, got) \
3426 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3427 ": expected %d, got %d\n", \
3430 #define parentdc_todo_field_ok(t, w, r, f, got) \
3431 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3432 else parentdc_field_ok(t, w, r, f, got)
3434 #define parentdc_rect_ok(t, w, r, got) \
3435 parentdc_todo_field_ok(t, w, r, left, got); \
3436 parentdc_todo_field_ok(t, w, r, top, got); \
3437 parentdc_todo_field_ok(t, w, r, right, got); \
3438 parentdc_todo_field_ok(t, w, r, bottom, got);
3440 #define parentdc_win_ok(t, w, got) \
3441 parentdc_rect_ok(t, w, client, got); \
3442 parentdc_rect_ok(t, w, clip, got); \
3443 parentdc_rect_ok(t, w, paint, got);
3445 #define parentdc_ok(t, got) \
3446 parentdc_win_ok(t, main, got); \
3447 parentdc_win_ok(t, child1, got); \
3448 parentdc_win_ok(t, child2, got);
3450 static void test_csparentdc(void)
3452 WNDCLASSA clsMain
, cls
;
3453 HWND hwndMain
, hwnd1
, hwnd2
;
3457 struct parentdc_test test_answer
;
3459 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3460 const struct parentdc_test test1
=
3462 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo
,
3463 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3464 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3467 const struct parentdc_test test2
=
3469 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo
,
3470 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3471 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3474 const struct parentdc_test test3
=
3476 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3477 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3478 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3481 const struct parentdc_test test4
=
3483 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo
,
3484 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo
,
3485 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3488 const struct parentdc_test test5
=
3490 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo
,
3491 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3492 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3495 const struct parentdc_test test6
=
3497 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3498 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3499 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3502 const struct parentdc_test test7
=
3504 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3505 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3506 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3510 clsMain
.style
= CS_DBLCLKS
;
3511 clsMain
.lpfnWndProc
= parentdc_window_procA
;
3512 clsMain
.cbClsExtra
= 0;
3513 clsMain
.cbWndExtra
= 0;
3514 clsMain
.hInstance
= GetModuleHandleA(0);
3516 clsMain
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3517 clsMain
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3518 clsMain
.lpszMenuName
= NULL
;
3519 clsMain
.lpszClassName
= "ParentDcMainWindowClass";
3521 if(!RegisterClassA(&clsMain
)) {
3522 trace("Register failed %d\n", GetLastError());
3526 cls
.style
= CS_DBLCLKS
| CS_PARENTDC
;
3527 cls
.lpfnWndProc
= parentdc_window_procA
;
3530 cls
.hInstance
= GetModuleHandleA(0);
3532 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3533 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3534 cls
.lpszMenuName
= NULL
;
3535 cls
.lpszClassName
= "ParentDcWindowClass";
3537 if(!RegisterClassA(&cls
)) {
3538 trace("Register failed %d\n", GetLastError());
3542 SetRect(&rc
, 0, 0, 150, 150);
3543 AdjustWindowRectEx(&rc
, WS_OVERLAPPEDWINDOW
, FALSE
, 0);
3544 hwndMain
= CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3545 CW_USEDEFAULT
, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, NULL
, NULL
, 0, NULL
);
3546 SetWindowLongPtrA(hwndMain
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.main
);
3547 hwnd1
= CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD
,
3548 20, 20, 40, 40, hwndMain
, NULL
, 0, NULL
);
3549 SetWindowLongPtrA(hwnd1
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child1
);
3550 hwnd2
= CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD
,
3551 40, 40, 40, 40, hwndMain
, NULL
, 0, NULL
);
3552 SetWindowLongPtrA(hwnd2
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child2
);
3553 ShowWindow(hwndMain
, SW_SHOW
);
3554 ShowWindow(hwnd1
, SW_SHOW
);
3555 ShowWindow(hwnd2
, SW_SHOW
);
3558 zero_parentdc_test(&test_answer
);
3559 InvalidateRect(hwndMain
, NULL
, TRUE
);
3560 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
3561 parentdc_ok(test1
, test_answer
);
3563 zero_parentdc_test(&test_answer
);
3564 SetRect(&rc
, 0, 0, 50, 50);
3565 InvalidateRect(hwndMain
, &rc
, TRUE
);
3566 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
3567 parentdc_ok(test2
, test_answer
);
3569 zero_parentdc_test(&test_answer
);
3570 SetRect(&rc
, 0, 0, 10, 10);
3571 InvalidateRect(hwndMain
, &rc
, TRUE
);
3572 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
3573 parentdc_ok(test3
, test_answer
);
3575 zero_parentdc_test(&test_answer
);
3576 SetRect(&rc
, 40, 40, 50, 50);
3577 InvalidateRect(hwndMain
, &rc
, TRUE
);
3578 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
3579 parentdc_ok(test4
, test_answer
);
3581 zero_parentdc_test(&test_answer
);
3582 SetRect(&rc
, 20, 20, 60, 60);
3583 InvalidateRect(hwndMain
, &rc
, TRUE
);
3584 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
3585 parentdc_ok(test5
, test_answer
);
3587 zero_parentdc_test(&test_answer
);
3588 SetRect(&rc
, 0, 0, 10, 10);
3589 InvalidateRect(hwnd1
, &rc
, TRUE
);
3590 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
3591 parentdc_ok(test6
, test_answer
);
3593 zero_parentdc_test(&test_answer
);
3594 SetRect(&rc
, -5, -5, 65, 65);
3595 InvalidateRect(hwnd1
, &rc
, TRUE
);
3596 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
3597 parentdc_ok(test7
, test_answer
);
3599 DestroyWindow(hwndMain
);
3600 DestroyWindow(hwnd1
);
3601 DestroyWindow(hwnd2
);
3604 static void test_IsWindowUnicode(void)
3606 static const char ansi_class_nameA
[] = "ansi class name";
3607 static const WCHAR ansi_class_nameW
[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3608 static const char unicode_class_nameA
[] = "unicode class name";
3609 static const WCHAR unicode_class_nameW
[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3614 memset(&classW
, 0, sizeof(classW
));
3615 classW
.hInstance
= GetModuleHandleA(0);
3616 classW
.lpfnWndProc
= DefWindowProcW
;
3617 classW
.lpszClassName
= unicode_class_nameW
;
3618 if (!RegisterClassW(&classW
)) return;
3620 memset(&classA
, 0, sizeof(classA
));
3621 classA
.hInstance
= GetModuleHandleA(0);
3622 classA
.lpfnWndProc
= DefWindowProcA
;
3623 classA
.lpszClassName
= ansi_class_nameA
;
3624 assert(RegisterClassA(&classA
));
3626 /* unicode class: window proc */
3627 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
3628 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3631 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3632 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)DefWindowProcA
);
3633 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3634 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)DefWindowProcW
);
3635 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3637 DestroyWindow(hwnd
);
3639 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
3640 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3643 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3644 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)DefWindowProcA
);
3645 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3646 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)DefWindowProcW
);
3647 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3649 DestroyWindow(hwnd
);
3651 /* ansi class: window proc */
3652 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
3653 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3656 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3657 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)DefWindowProcW
);
3658 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3659 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)DefWindowProcA
);
3660 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3662 DestroyWindow(hwnd
);
3664 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
3665 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3668 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3669 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)DefWindowProcW
);
3670 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3671 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)DefWindowProcA
);
3672 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3674 DestroyWindow(hwnd
);
3676 /* unicode class: class proc */
3677 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
3678 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3681 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3682 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)DefWindowProcA
);
3683 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3684 /* do not restore class window proc back to unicode */
3686 DestroyWindow(hwnd
);
3688 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
3689 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3692 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3693 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)DefWindowProcW
);
3694 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3696 DestroyWindow(hwnd
);
3698 /* ansi class: class proc */
3699 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
3700 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3703 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3704 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)DefWindowProcW
);
3705 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3706 /* do not restore class window proc back to ansi */
3708 DestroyWindow(hwnd
);
3710 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
3711 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3714 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3715 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)DefWindowProcA
);
3716 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3718 DestroyWindow(hwnd
);
3721 static LRESULT CALLBACK
minmax_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
3725 if (msg
!= WM_GETMINMAXINFO
)
3726 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3728 minmax
= (MINMAXINFO
*)lp
;
3730 if ((GetWindowLong(hwnd
, GWL_STYLE
) & WS_CHILD
))
3732 minmax
->ptReserved
.x
= 0;
3733 minmax
->ptReserved
.y
= 0;
3734 minmax
->ptMaxSize
.x
= 400;
3735 minmax
->ptMaxSize
.y
= 400;
3736 minmax
->ptMaxPosition
.x
= 300;
3737 minmax
->ptMaxPosition
.y
= 300;
3738 minmax
->ptMaxTrackSize
.x
= 200;
3739 minmax
->ptMaxTrackSize
.y
= 200;
3740 minmax
->ptMinTrackSize
.x
= 100;
3741 minmax
->ptMinTrackSize
.y
= 100;
3744 DefWindowProc(hwnd
, msg
, wp
, lp
);
3748 static void test_CreateWindow(void)
3756 #define expect_menu(window, menu) \
3757 SetLastError(0xdeadbeef); \
3758 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
3760 #define expect_style(window, style)\
3761 ok(GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
3763 #define expect_ex_style(window, ex_style)\
3764 ok(GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
3766 hmenu
= CreateMenu();
3768 parent
= GetDesktopWindow();
3769 assert(parent
!= 0);
3771 SetLastError(0xdeadbeef);
3772 ok(IsMenu(hmenu
), "IsMenu error %d\n", GetLastError());
3775 SetLastError(0xdeadbeef);
3776 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
,
3777 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3778 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3779 expect_menu(hwnd
, 1);
3780 expect_style(hwnd
, WS_CHILD
);
3781 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
3782 DestroyWindow(hwnd
);
3784 SetLastError(0xdeadbeef);
3785 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_CAPTION
,
3786 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3787 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3788 expect_menu(hwnd
, 1);
3789 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
3790 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
3791 DestroyWindow(hwnd
);
3793 SetLastError(0xdeadbeef);
3794 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
,
3795 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3796 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3797 expect_menu(hwnd
, 1);
3798 expect_style(hwnd
, WS_CHILD
);
3799 expect_ex_style(hwnd
, 0);
3800 DestroyWindow(hwnd
);
3802 SetLastError(0xdeadbeef);
3803 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_CAPTION
,
3804 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3805 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3806 expect_menu(hwnd
, 1);
3807 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
3808 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
3809 DestroyWindow(hwnd
);
3812 SetLastError(0xdeadbeef);
3813 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
3814 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
3815 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3816 expect_menu(hwnd
, hmenu
);
3817 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
3818 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
3819 DestroyWindow(hwnd
);
3820 SetLastError(0xdeadbeef);
3821 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
3822 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
3824 hmenu
= CreateMenu();
3826 SetLastError(0xdeadbeef);
3827 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
| WS_CAPTION
,
3828 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
3829 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3830 expect_menu(hwnd
, hmenu
);
3831 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
3832 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
3833 DestroyWindow(hwnd
);
3834 SetLastError(0xdeadbeef);
3835 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
3836 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
3838 hmenu
= CreateMenu();
3840 SetLastError(0xdeadbeef);
3841 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
,
3842 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
3843 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3844 expect_menu(hwnd
, hmenu
);
3845 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
3846 expect_ex_style(hwnd
, 0);
3847 DestroyWindow(hwnd
);
3848 SetLastError(0xdeadbeef);
3849 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
3850 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
3852 hmenu
= CreateMenu();
3854 SetLastError(0xdeadbeef);
3855 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
| WS_CAPTION
,
3856 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
3857 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3858 expect_menu(hwnd
, hmenu
);
3859 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
3860 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
3861 DestroyWindow(hwnd
);
3862 SetLastError(0xdeadbeef);
3863 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
3864 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
3866 /* WS_CHILD | WS_POPUP */
3867 SetLastError(0xdeadbeef);
3868 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
3869 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3870 ok(!hwnd
, "CreateWindowEx should fail\n");
3871 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
3873 hmenu
= CreateMenu();
3875 SetLastError(0xdeadbeef);
3876 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
3877 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
3878 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3879 expect_menu(hwnd
, hmenu
);
3880 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
3881 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
3882 DestroyWindow(hwnd
);
3883 SetLastError(0xdeadbeef);
3884 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
3885 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
3887 SetLastError(0xdeadbeef);
3888 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
3889 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3890 ok(!hwnd
, "CreateWindowEx should fail\n");
3891 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
3893 hmenu
= CreateMenu();
3895 SetLastError(0xdeadbeef);
3896 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
3897 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
3898 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3899 expect_menu(hwnd
, hmenu
);
3900 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
3901 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
3902 DestroyWindow(hwnd
);
3903 SetLastError(0xdeadbeef);
3904 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
3905 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
3907 SetLastError(0xdeadbeef);
3908 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
3909 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3910 ok(!hwnd
, "CreateWindowEx should fail\n");
3911 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
3913 hmenu
= CreateMenu();
3915 SetLastError(0xdeadbeef);
3916 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
3917 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
3918 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3919 expect_menu(hwnd
, hmenu
);
3920 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
3921 expect_ex_style(hwnd
, 0);
3922 DestroyWindow(hwnd
);
3923 SetLastError(0xdeadbeef);
3924 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
3925 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
3927 SetLastError(0xdeadbeef);
3928 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
3929 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3930 ok(!hwnd
, "CreateWindowEx should fail\n");
3931 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
3933 hmenu
= CreateMenu();
3935 SetLastError(0xdeadbeef);
3936 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
3937 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
3938 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3939 expect_menu(hwnd
, hmenu
);
3940 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
3941 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
3942 DestroyWindow(hwnd
);
3943 SetLastError(0xdeadbeef);
3944 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
3945 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
3947 /* test child window sizing */
3949 cls
.lpfnWndProc
= minmax_wnd_proc
;
3952 cls
.hInstance
= GetModuleHandle(0);
3954 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3955 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3956 cls
.lpszMenuName
= NULL
;
3957 cls
.lpszClassName
= "MinMax_WndClass";
3958 RegisterClass(&cls
);
3960 SetLastError(0xdeadbeef);
3961 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
3962 0, 0, 100, 100, 0, 0, 0, NULL
);
3963 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
3964 expect_menu(parent
, 0);
3965 expect_style(parent
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
| WS_CLIPSIBLINGS
);
3966 expect_ex_style(parent
, WS_EX_WINDOWEDGE
);
3968 memset(&minmax
, 0, sizeof(minmax
));
3969 SendMessage(parent
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
3970 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxSize
.x
, minmax
.ptMaxSize
.y
);
3971 ok(IsRectEmpty(&rc_minmax
), "ptMaxSize is not empty\n");
3972 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
3973 ok(IsRectEmpty(&rc_minmax
), "ptMaxTrackSize is not empty\n");
3975 GetWindowRect(parent
, &rc
);
3976 ok(!IsRectEmpty(&rc
), "parent window rect is empty\n");
3977 GetClientRect(parent
, &rc
);
3978 ok(!IsRectEmpty(&rc
), "parent client rect is empty\n");
3980 InflateRect(&rc
, 200, 200);
3981 trace("creating child with rect (%d,%d-%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3983 SetLastError(0xdeadbeef);
3984 hwnd
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
3985 rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
3986 parent
, (HMENU
)1, 0, NULL
);
3987 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3988 expect_menu(hwnd
, 1);
3989 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
);
3990 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
3992 memset(&minmax
, 0, sizeof(minmax
));
3993 SendMessage(hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
3994 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
3996 GetWindowRect(hwnd
, &rc
);
3997 OffsetRect(&rc
, -rc
.left
, -rc
.top
);
3998 ok(EqualRect(&rc
, &rc_minmax
), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
3999 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
4000 rc_minmax
.left
, rc_minmax
.top
, rc_minmax
.right
, rc_minmax
.bottom
);
4002 DestroyWindow(hwnd
);
4003 DestroyWindow(parent
);
4005 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4009 #undef expect_ex_style
4012 /* function that remembers whether the system the test is running on sets the
4013 * last error for user32 functions to make the tests stricter */
4014 static int check_error(DWORD actual
, DWORD expected
)
4016 static int sets_last_error
= -1;
4017 if (sets_last_error
== -1)
4018 sets_last_error
= (actual
!= 0xdeadbeef);
4019 return (!sets_last_error
&& (actual
== 0xdeadbeef)) || (actual
== expected
);
4022 static void test_SetWindowLong(void)
4025 WNDPROC old_window_procW
;
4027 SetLastError(0xdeadbeef);
4028 retval
= SetWindowLongPtr(NULL
, GWLP_WNDPROC
, 0);
4029 ok(!retval
, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval
);
4030 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE
),
4031 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4033 SetLastError(0xdeadbeef);
4034 retval
= SetWindowLongPtr(hwndMain
, 0xdeadbeef, 0);
4035 ok(!retval
, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval
);
4036 ok(check_error(GetLastError(), ERROR_INVALID_INDEX
),
4037 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4039 SetLastError(0xdeadbeef);
4040 retval
= SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4041 ok((WNDPROC
)retval
== main_window_procA
,
4042 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval
);
4043 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4044 retval
= GetWindowLongPtr(hwndMain
, GWLP_WNDPROC
);
4045 ok((WNDPROC
)retval
== main_window_procA
,
4046 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4047 ok(!IsWindowUnicode(hwndMain
), "hwndMain shouldn't be Unicode\n");
4049 old_window_procW
= (WNDPROC
)GetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
);
4050 SetLastError(0xdeadbeef);
4051 retval
= SetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
, 0);
4052 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED
)
4054 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4055 ok(retval
!= 0, "SetWindowLongPtr error %d\n", GetLastError());
4056 ok((WNDPROC
)retval
== old_window_procW
,
4057 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4058 ok(IsWindowUnicode(hwndMain
), "hwndMain should now be Unicode\n");
4060 /* set it back to ANSI */
4061 SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4065 static void test_ShowWindow(void)
4072 SetRect(&rcMain
, 120, 120, 210, 210);
4074 hwnd
= CreateWindowEx(0, "MainWindowClass", NULL
,
4075 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4076 WS_MAXIMIZEBOX
| WS_POPUP
,
4077 rcMain
.left
, rcMain
.top
,
4078 rcMain
.right
- rcMain
.left
, rcMain
.bottom
- rcMain
.top
,
4082 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4083 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4084 ok(!(style
& WS_VISIBLE
), "window should not be visible\n");
4085 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4086 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4087 GetWindowRect(hwnd
, &rc
);
4088 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4090 ret
= ShowWindow(hwnd
, SW_SHOW
);
4091 ok(!ret
, "not expected ret: %lu\n", ret
);
4092 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4093 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4094 ok(style
& WS_VISIBLE
, "window should be visible\n");
4095 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4096 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4097 GetWindowRect(hwnd
, &rc
);
4098 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4100 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4101 ok(ret
, "not expected ret: %lu\n", ret
);
4102 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4103 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4104 ok(style
& WS_VISIBLE
, "window should be visible\n");
4105 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4106 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4107 GetWindowRect(hwnd
, &rc
);
4108 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4110 ShowWindow(hwnd
, SW_RESTORE
);
4111 ok(ret
, "not expected ret: %lu\n", ret
);
4112 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4113 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4114 ok(style
& WS_VISIBLE
, "window should be visible\n");
4115 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4116 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4117 GetWindowRect(hwnd
, &rc
);
4118 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4120 ret
= EnableWindow(hwnd
, FALSE
);
4121 ok(!ret
, "not expected ret: %lu\n", ret
);
4122 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4123 ok(style
& WS_DISABLED
, "window should be disabled\n");
4125 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
4126 ok(!ret
, "not expected ret: %lu\n", ret
);
4127 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4128 ok(style
& WS_DISABLED
, "window should be disabled\n");
4129 ok(style
& WS_VISIBLE
, "window should be visible\n");
4130 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4131 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4132 GetWindowRect(hwnd
, &rc
);
4133 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4135 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
4136 ok(!ret
, "not expected ret: %lu\n", ret
);
4137 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4138 ok(style
& WS_DISABLED
, "window should be disabled\n");
4139 ok(style
& WS_VISIBLE
, "window should be visible\n");
4140 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4141 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4142 GetWindowRect(hwnd
, &rc
);
4143 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4145 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4146 ok(ret
, "not expected ret: %lu\n", ret
);
4147 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4148 ok(style
& WS_DISABLED
, "window should be disabled\n");
4149 ok(style
& WS_VISIBLE
, "window should be visible\n");
4150 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4151 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4152 GetWindowRect(hwnd
, &rc
);
4153 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4155 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
4156 ok(!ret
, "not expected ret: %lu\n", ret
);
4157 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4158 ok(style
& WS_DISABLED
, "window should be disabled\n");
4159 ok(style
& WS_VISIBLE
, "window should be visible\n");
4160 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4161 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4162 GetWindowRect(hwnd
, &rc
);
4163 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4165 ret
= ShowWindow(hwnd
, SW_RESTORE
);
4166 ok(ret
, "not expected ret: %lu\n", ret
);
4167 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4168 ok(style
& WS_DISABLED
, "window should be disabled\n");
4169 ok(style
& WS_VISIBLE
, "window should be visible\n");
4170 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4171 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4172 GetWindowRect(hwnd
, &rc
);
4173 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4175 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4176 ok(!ret
, "not expected ret: %lu\n", ret
);
4177 ok(IsWindow(hwnd
), "window should exist\n");
4179 ret
= EnableWindow(hwnd
, TRUE
);
4180 ok(ret
, "not expected ret: %lu\n", ret
);
4182 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4183 ok(!ret
, "not expected ret: %lu\n", ret
);
4184 ok(!IsWindow(hwnd
), "window should not exist\n");
4187 static void test_gettext(void)
4190 LPCSTR clsname
= "gettexttest";
4194 memset( &cls
, 0, sizeof cls
);
4195 cls
.lpfnWndProc
= DefWindowProc
;
4196 cls
.lpszClassName
= clsname
;
4197 cls
.hInstance
= GetModuleHandle(NULL
);
4199 if (!RegisterClass( &cls
)) return;
4201 hwnd
= CreateWindow( clsname
, "test text", WS_OVERLAPPED
, 0, 0, 10, 10, 0, NULL
, NULL
, NULL
);
4202 ok( hwnd
!= NULL
, "window was null\n");
4204 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10, 0x1000);
4205 ok( r
== 0, "settext should return zero\n");
4207 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10000, 0);
4208 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4210 r
= SendMessage( hwnd
, WM_GETTEXT
, 0xff000000, 0x1000);
4211 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4213 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x1000, 0xff000000);
4214 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4216 DestroyWindow(hwnd
);
4217 UnregisterClass( clsname
, NULL
);
4221 static void test_GetUpdateRect(void)
4224 HWND hgrandparent
, hparent
, hchild
;
4226 const char* classNameA
= "GetUpdateRectClass";
4228 hgrandparent
= CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW
,
4229 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4231 hparent
= CreateWindowA("static", "parent", WS_CHILD
|WS_VISIBLE
,
4232 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4234 hchild
= CreateWindowA("static", "child", WS_CHILD
|WS_VISIBLE
,
4235 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4237 ShowWindow(hgrandparent
, SW_SHOW
);
4238 UpdateWindow(hgrandparent
);
4240 ShowWindow(hchild
, SW_HIDE
);
4241 SetRect(&rc2
, 0, 0, 0, 0);
4242 GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4245 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4246 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4247 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4250 SetRect(&rc2
, 10, 10, 40, 40);
4251 GetUpdateRect(hparent
, &rc1
, FALSE
);
4252 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4253 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4254 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4256 DestroyWindow(hgrandparent
);
4259 cls
.lpfnWndProc
= DefWindowProcA
;
4262 cls
.hInstance
= GetModuleHandleA(0);
4264 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
4265 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4266 cls
.lpszMenuName
= NULL
;
4267 cls
.lpszClassName
= classNameA
;
4269 if(!RegisterClassA(&cls
)) {
4270 trace("Register failed %d\n", GetLastError());
4274 hgrandparent
= CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW
,
4275 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4277 hparent
= CreateWindowA(classNameA
, "parent", WS_CHILD
|WS_VISIBLE
,
4278 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4280 hchild
= CreateWindowA(classNameA
, "child", WS_CHILD
|WS_VISIBLE
,
4281 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4283 ShowWindow(hgrandparent
, SW_SHOW
);
4284 UpdateWindow(hgrandparent
);
4286 ShowWindow(hchild
, SW_HIDE
);
4287 SetRect(&rc2
, 0, 0, 0, 0);
4288 GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4291 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4292 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4293 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4296 SetRect(&rc2
, 10, 10, 40, 40);
4297 GetUpdateRect(hparent
, &rc1
, FALSE
);
4298 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4299 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4300 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4302 DestroyWindow(hgrandparent
);
4307 pGetAncestor
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
4308 pGetWindowInfo
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
4310 hwndMain
= CreateWindowExA(0, "static", NULL
, 0, 0, 0, 0, 0, HWND_MESSAGE
, 0, 0, NULL
);
4313 ok(!GetParent(hwndMain
), "GetParent should return 0 for message only windows\n");
4316 hwndMessage
= pGetAncestor(hwndMain
, GA_PARENT
);
4317 ok(hwndMessage
!= 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
4318 trace("hwndMessage %p\n", hwndMessage
);
4320 DestroyWindow(hwndMain
);
4323 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
4325 if (!RegisterWindowClasses()) assert(0);
4327 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
4330 hwndMain
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
4331 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4332 WS_MAXIMIZEBOX
| WS_POPUP
,
4335 test_nonclient_area(hwndMain
);
4337 hwndMain2
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
4338 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4339 WS_MAXIMIZEBOX
| WS_POPUP
,
4343 assert( hwndMain2
);
4345 /* Add the tests below this line */
4350 test_capture_3(hwndMain
, hwndMain2
);
4352 test_CreateWindow();
4353 test_parent_owner();
4355 test_shell_window();
4359 test_SetWindowPos(hwndMain
);
4360 test_SetMenu(hwndMain
);
4361 test_SetFocus(hwndMain
);
4362 test_SetActiveWindow(hwndMain
);
4363 test_SetForegroundWindow(hwndMain
);
4365 test_children_zorder(hwndMain
);
4366 test_keyboard_input(hwndMain
);
4367 test_mouse_input(hwndMain
);
4368 test_validatergn(hwndMain
);
4369 test_nccalcscroll( hwndMain
);
4370 test_scrollvalidate( hwndMain
);
4371 test_scrolldc( hwndMain
);
4373 test_IsWindowUnicode();
4374 test_vis_rgn(hwndMain
);
4376 test_AdjustWindowRect();
4377 test_window_styles();
4380 test_SetWindowLong();
4383 test_GetUpdateRect();
4385 /* add the tests above this line */
4386 UnhookWindowsHookEx(hhook
);