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";
59 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
61 /* try to make sure pending X events have been processed before continuing */
62 static void flush_events(void)
66 DWORD time
= GetTickCount() + diff
;
70 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min(10,diff
), QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
71 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
72 diff
= time
- GetTickCount();
76 /* check the values returned by the various parent/owner functions on a given window */
77 static void check_parents( HWND hwnd
, HWND ga_parent
, HWND gwl_parent
, HWND get_parent
,
78 HWND gw_owner
, HWND ga_root
, HWND ga_root_owner
)
84 res
= pGetAncestor( hwnd
, GA_PARENT
);
85 ok( res
== ga_parent
, "Wrong result for GA_PARENT %p expected %p\n", res
, ga_parent
);
87 res
= (HWND
)GetWindowLongPtrA( hwnd
, GWLP_HWNDPARENT
);
88 ok( res
== gwl_parent
, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res
, gwl_parent
);
89 res
= GetParent( hwnd
);
90 ok( res
== get_parent
, "Wrong result for GetParent %p expected %p\n", res
, get_parent
);
91 res
= GetWindow( hwnd
, GW_OWNER
);
92 ok( res
== gw_owner
, "Wrong result for GW_OWNER %p expected %p\n", res
, gw_owner
);
95 res
= pGetAncestor( hwnd
, GA_ROOT
);
96 ok( res
== ga_root
, "Wrong result for GA_ROOT %p expected %p\n", res
, ga_root
);
97 res
= pGetAncestor( hwnd
, GA_ROOTOWNER
);
98 ok( res
== ga_root_owner
, "Wrong result for GA_ROOTOWNER %p expected %p\n", res
, ga_root_owner
);
102 static BOOL CALLBACK
EnumChildProc( HWND hwndChild
, LPARAM lParam
)
105 trace("EnumChildProc on %p\n", hwndChild
);
106 if (*(LPINT
)lParam
> 1) return FALSE
;
110 /* will search for the given window */
111 static BOOL CALLBACK
EnumChildProc1( HWND hwndChild
, LPARAM lParam
)
113 trace("EnumChildProc1 on %p\n", hwndChild
);
114 if ((HWND
)lParam
== hwndChild
) return FALSE
;
118 static HWND
create_tool_window( LONG style
, HWND parent
)
120 HWND ret
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style
,
121 0, 0, 100, 100, parent
, 0, 0, NULL
);
122 ok( ret
!= 0, "Creation failed\n" );
126 /* test parent and owner values for various combinations */
127 static void test_parent_owner(void)
130 HWND test
, owner
, ret
;
131 HWND desktop
= GetDesktopWindow();
132 HWND child
= create_tool_window( WS_CHILD
, hwndMain
);
135 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain
, hwndMain2
, desktop
, child
);
137 /* child without parent, should fail */
138 SetLastError(0xdeadbeef);
139 test
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
140 WS_CHILD
, 0, 0, 100, 100, 0, 0, 0, NULL
);
141 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD
, "CreateWindowExA should call SetLastError\n" );
142 ok( !test
, "WS_CHILD without parent created\n" );
145 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
146 style
= GetWindowLongA( desktop
, GWL_STYLE
);
147 ok( !SetWindowLongA( desktop
, GWL_STYLE
, WS_POPUP
), "Set GWL_STYLE on desktop succeeded\n" );
148 ok( !SetWindowLongA( desktop
, GWL_STYLE
, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
149 ok( GetWindowLongA( desktop
, GWL_STYLE
) == style
, "Desktop style changed\n" );
151 /* normal child window */
152 test
= create_tool_window( WS_CHILD
, hwndMain
);
153 trace( "created child %p\n", test
);
154 check_parents( test
, hwndMain
, hwndMain
, hwndMain
, 0, hwndMain
, hwndMain
);
155 SetWindowLongA( test
, GWL_STYLE
, 0 );
156 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
157 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
158 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
159 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
|WS_CHILD
);
160 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
161 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
162 DestroyWindow( test
);
164 /* normal child window with WS_MAXIMIZE */
165 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
166 DestroyWindow( test
);
168 /* normal child window with WS_THICKFRAME */
169 test
= create_tool_window( WS_CHILD
| WS_THICKFRAME
, hwndMain
);
170 DestroyWindow( test
);
172 /* popup window with WS_THICKFRAME */
173 test
= create_tool_window( WS_POPUP
| WS_THICKFRAME
, hwndMain
);
174 DestroyWindow( test
);
176 /* child of desktop */
177 test
= create_tool_window( WS_CHILD
, desktop
);
178 trace( "created child of desktop %p\n", test
);
179 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
180 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
181 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
182 SetWindowLongA( test
, GWL_STYLE
, 0 );
183 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
184 DestroyWindow( test
);
186 /* child of desktop with WS_MAXIMIZE */
187 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, desktop
);
188 DestroyWindow( test
);
190 /* child of desktop with WS_MINIMIZE */
191 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, desktop
);
192 DestroyWindow( test
);
195 test
= create_tool_window( WS_CHILD
, child
);
196 trace( "created child of child %p\n", test
);
197 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
198 SetWindowLongA( test
, GWL_STYLE
, 0 );
199 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
200 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
201 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
202 DestroyWindow( test
);
204 /* child of child with WS_MAXIMIZE */
205 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, child
);
206 DestroyWindow( test
);
208 /* child of child with WS_MINIMIZE */
209 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, child
);
210 DestroyWindow( test
);
212 /* not owned top-level window */
213 test
= create_tool_window( 0, 0 );
214 trace( "created top-level %p\n", test
);
215 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
216 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
217 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
218 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
219 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
220 DestroyWindow( test
);
222 /* not owned top-level window with WS_MAXIMIZE */
223 test
= create_tool_window( WS_MAXIMIZE
, 0 );
224 DestroyWindow( test
);
226 /* owned top-level window */
227 test
= create_tool_window( 0, hwndMain
);
228 trace( "created owned top-level %p\n", test
);
229 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
230 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
231 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
232 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
233 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
234 DestroyWindow( test
);
236 /* owned top-level window with WS_MAXIMIZE */
237 test
= create_tool_window( WS_MAXIMIZE
, hwndMain
);
238 DestroyWindow( test
);
240 /* not owned popup */
241 test
= create_tool_window( WS_POPUP
, 0 );
242 trace( "created popup %p\n", test
);
243 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
244 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
245 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
246 SetWindowLongA( test
, GWL_STYLE
, 0 );
247 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
248 DestroyWindow( test
);
250 /* not owned popup with WS_MAXIMIZE */
251 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, 0 );
252 DestroyWindow( test
);
255 test
= create_tool_window( WS_POPUP
, hwndMain
);
256 trace( "created owned popup %p\n", test
);
257 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
258 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
259 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
260 SetWindowLongA( test
, GWL_STYLE
, 0 );
261 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
262 DestroyWindow( test
);
264 /* owned popup with WS_MAXIMIZE */
265 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, hwndMain
);
266 DestroyWindow( test
);
268 /* top-level window owned by child (same as owned by top-level) */
269 test
= create_tool_window( 0, child
);
270 trace( "created top-level owned by child %p\n", test
);
271 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
272 DestroyWindow( test
);
274 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
275 test
= create_tool_window( WS_MAXIMIZE
, child
);
276 DestroyWindow( test
);
278 /* popup owned by desktop (same as not owned) */
279 test
= create_tool_window( WS_POPUP
, desktop
);
280 trace( "created popup owned by desktop %p\n", test
);
281 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
282 DestroyWindow( test
);
284 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
285 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, desktop
);
286 DestroyWindow( test
);
288 /* popup owned by child (same as owned by top-level) */
289 test
= create_tool_window( WS_POPUP
, child
);
290 trace( "created popup owned by child %p\n", test
);
291 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
292 DestroyWindow( test
);
294 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
295 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, child
);
296 DestroyWindow( test
);
298 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
299 test
= create_tool_window( WS_POPUP
| WS_CHILD
, 0 );
300 trace( "created WS_CHILD popup %p\n", test
);
301 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
302 DestroyWindow( test
);
304 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
305 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, 0 );
306 DestroyWindow( test
);
308 /* owned popup with WS_CHILD (same as WS_POPUP only) */
309 test
= create_tool_window( WS_POPUP
| WS_CHILD
, hwndMain
);
310 trace( "created owned WS_CHILD popup %p\n", test
);
311 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
312 DestroyWindow( test
);
314 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
315 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
316 DestroyWindow( test
);
318 /******************** parent changes *************************/
319 trace( "testing parent changes\n" );
322 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
325 /* this test succeeds on NT but crashes on win9x systems */
326 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
327 ok( !ret
, "Set GWL_HWNDPARENT succeeded on desktop\n" );
328 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
329 ok( !SetParent( desktop
, hwndMain
), "SetParent succeeded on desktop\n" );
330 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
332 /* normal child window */
333 test
= create_tool_window( WS_CHILD
, hwndMain
);
334 trace( "created child %p\n", test
);
336 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
337 ok( ret
== hwndMain
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain
);
338 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
340 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
341 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
342 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
344 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)desktop
);
345 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
346 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
348 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
349 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
350 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
351 check_parents( test
, desktop
, child
, desktop
, child
, test
, desktop
);
353 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
354 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
355 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
356 DestroyWindow( test
);
358 /* not owned top-level window */
359 test
= create_tool_window( 0, 0 );
360 trace( "created top-level %p\n", test
);
362 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
363 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
364 check_parents( test
, desktop
, hwndMain2
, 0, hwndMain2
, test
, test
);
366 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
367 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
368 check_parents( test
, desktop
, child
, 0, child
, test
, test
);
370 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
371 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
372 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
373 DestroyWindow( test
);
375 /* not owned popup */
376 test
= create_tool_window( WS_POPUP
, 0 );
377 trace( "created popup %p\n", test
);
379 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
380 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
381 check_parents( test
, desktop
, hwndMain2
, hwndMain2
, hwndMain2
, test
, hwndMain2
);
383 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
384 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
385 check_parents( test
, desktop
, child
, child
, child
, test
, hwndMain
);
387 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
388 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
389 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
390 DestroyWindow( test
);
392 /* normal child window */
393 test
= create_tool_window( WS_CHILD
, hwndMain
);
394 trace( "created child %p\n", test
);
396 ret
= SetParent( test
, desktop
);
397 ok( ret
== hwndMain
, "SetParent return value %p expected %p\n", ret
, hwndMain
);
398 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
400 ret
= SetParent( test
, child
);
401 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
402 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
404 ret
= SetParent( test
, hwndMain2
);
405 ok( ret
== child
, "SetParent return value %p expected %p\n", ret
, child
);
406 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
407 DestroyWindow( test
);
409 /* not owned top-level window */
410 test
= create_tool_window( 0, 0 );
411 trace( "created top-level %p\n", test
);
413 ret
= SetParent( test
, child
);
414 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
415 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
416 DestroyWindow( test
);
419 test
= create_tool_window( WS_POPUP
, hwndMain2
);
420 trace( "created owned popup %p\n", test
);
422 ret
= SetParent( test
, child
);
423 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
424 check_parents( test
, child
, child
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
426 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)hwndMain
);
427 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
428 check_parents( test
, hwndMain
, hwndMain
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
429 DestroyWindow( test
);
431 /**************** test owner destruction *******************/
433 /* owned child popup */
434 owner
= create_tool_window( 0, 0 );
435 test
= create_tool_window( WS_POPUP
, owner
);
436 trace( "created owner %p and popup %p\n", owner
, test
);
437 ret
= SetParent( test
, child
);
438 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
439 check_parents( test
, child
, child
, owner
, owner
, hwndMain
, owner
);
440 /* window is now child of 'child' but owned by 'owner' */
441 DestroyWindow( owner
);
442 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
443 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
444 * while Win95, Win2k, WinXP do.
446 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
447 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
450 /* owned top-level popup */
451 owner
= create_tool_window( 0, 0 );
452 test
= create_tool_window( WS_POPUP
, owner
);
453 trace( "created owner %p and popup %p\n", owner
, test
);
454 check_parents( test
, desktop
, owner
, owner
, owner
, test
, owner
);
455 DestroyWindow( owner
);
456 ok( !IsWindow(test
), "Window %p not destroyed by owner destruction\n", test
);
458 /* top-level popup owned by child */
459 owner
= create_tool_window( WS_CHILD
, hwndMain2
);
460 test
= create_tool_window( WS_POPUP
, 0 );
461 trace( "created owner %p and popup %p\n", owner
, test
);
462 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)owner
);
463 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
464 check_parents( test
, desktop
, owner
, owner
, owner
, test
, hwndMain2
);
465 DestroyWindow( owner
);
466 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
467 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
468 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
469 * while Win95, Win2k, WinXP do.
471 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
475 DestroyWindow(child
);
478 owner
= create_tool_window( WS_OVERLAPPED
, 0 );
479 test
= create_tool_window( WS_POPUP
, desktop
);
481 ok( !GetWindow( test
, GW_OWNER
), "Wrong owner window\n" );
483 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
484 "EnumChildWindows should have returned FALSE\n" );
485 ok( numChildren
== 0, "numChildren should be 0 got %d\n", numChildren
);
487 SetWindowLongA( test
, GWL_STYLE
, (GetWindowLongA( test
, GWL_STYLE
) & ~WS_POPUP
) | WS_CHILD
);
488 ret
= SetParent( test
, owner
);
489 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
492 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
493 "EnumChildWindows should have returned TRUE\n" );
494 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
496 child
= create_tool_window( WS_CHILD
, owner
);
498 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
499 "EnumChildWindows should have returned FALSE\n" );
500 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
501 DestroyWindow( child
);
503 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, owner
);
504 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
506 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
507 "EnumChildWindows should have returned TRUE\n" );
508 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
510 ret
= SetParent( child
, owner
);
511 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
512 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
514 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
515 "EnumChildWindows should have returned FALSE\n" );
516 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
518 ret
= SetParent( child
, NULL
);
519 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
520 ok( ret
== owner
, "SetParent return value %p expected %p\n", ret
, owner
);
522 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
523 "EnumChildWindows should have returned TRUE\n" );
524 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
526 /* even GW_OWNER == owner it's still a desktop's child */
527 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
528 "EnumChildWindows should have found %p and returned FALSE\n", child
);
530 DestroyWindow( child
);
531 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, NULL
);
533 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
534 "EnumChildWindows should have found %p and returned FALSE\n", child
);
536 DestroyWindow( child
);
537 DestroyWindow( test
);
538 DestroyWindow( owner
);
542 static LRESULT WINAPI
main_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
546 case WM_GETMINMAXINFO
:
548 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
550 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
551 trace("ptReserved (%d,%d), ptMaxSize (%d,%d), ptMaxPosition (%d,%d)\n"
552 " ptMinTrackSize (%d,%d), ptMaxTrackSize (%d,%d)\n",
553 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
554 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
555 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
556 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
557 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
558 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
561 case WM_WINDOWPOSCHANGING
:
563 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
564 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
565 trace("main: WM_WINDOWPOSCHANGING\n");
566 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
567 winpos
->hwnd
, winpos
->hwndInsertAfter
,
568 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
569 if (!(winpos
->flags
& SWP_NOMOVE
))
571 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
572 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
574 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
575 if (!(winpos
->flags
& SWP_NOSIZE
) && !is_win9x
)
577 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
578 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
582 case WM_WINDOWPOSCHANGED
:
585 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
586 trace("main: WM_WINDOWPOSCHANGED\n");
587 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
588 winpos
->hwnd
, winpos
->hwndInsertAfter
,
589 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
590 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
591 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
593 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
594 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
596 GetWindowRect(hwnd
, &rc1
);
597 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
598 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
599 /* note: winpos coordinates are relative to parent */
600 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
601 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
604 /* Uncomment this once the test succeeds in all cases */
605 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
608 GetClientRect(hwnd
, &rc2
);
609 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
610 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
611 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
612 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
617 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
618 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
620 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
621 if (got_getminmaxinfo
)
622 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
624 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
625 ok(got_getminmaxinfo
, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
627 ok(!got_getminmaxinfo
, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
631 if (test_lbuttondown_flag
)
632 ShowWindow((HWND
)wparam
, SW_SHOW
);
636 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
639 static LRESULT WINAPI
tool_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
643 case WM_GETMINMAXINFO
:
645 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
647 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
648 trace("ptReserved (%d,%d), ptMaxSize (%d,%d), ptMaxPosition (%d,%d)\n"
649 " ptMinTrackSize (%d,%d), ptMaxTrackSize (%d,%d)\n",
650 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
651 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
652 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
653 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
654 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
655 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
660 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
661 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
663 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
664 if (got_getminmaxinfo
)
665 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
667 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
668 ok(got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
670 ok(!got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
675 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
678 static BOOL
RegisterWindowClasses(void)
682 cls
.style
= CS_DBLCLKS
;
683 cls
.lpfnWndProc
= main_window_procA
;
686 cls
.hInstance
= GetModuleHandleA(0);
688 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
689 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
690 cls
.lpszMenuName
= NULL
;
691 cls
.lpszClassName
= "MainWindowClass";
693 if(!RegisterClassA(&cls
)) return FALSE
;
696 cls
.lpfnWndProc
= tool_window_procA
;
699 cls
.hInstance
= GetModuleHandleA(0);
701 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
702 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
703 cls
.lpszMenuName
= NULL
;
704 cls
.lpszClassName
= "ToolWindowClass";
706 if(!RegisterClassA(&cls
)) return FALSE
;
711 static void verify_window_info(HWND hwnd
, const WINDOWINFO
*info
)
713 RECT rcWindow
, rcClient
;
716 ok(IsWindow(hwnd
), "bad window handle\n");
718 GetWindowRect(hwnd
, &rcWindow
);
719 ok(EqualRect(&rcWindow
, &info
->rcWindow
), "wrong rcWindow\n");
721 GetClientRect(hwnd
, &rcClient
);
722 /* translate to screen coordinates */
723 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rcClient
, 2);
724 ok(EqualRect(&rcClient
, &info
->rcClient
), "wrong rcClient\n");
726 ok(info
->dwStyle
== (DWORD
)GetWindowLongA(hwnd
, GWL_STYLE
),
727 "wrong dwStyle: %08x != %08x\n", info
->dwStyle
, GetWindowLongA(hwnd
, GWL_STYLE
));
728 /* Windows reports a not documented exstyle 0x800 in WINDOWINFO, but
729 * doesn't return it in GetWindowLong(hwnd, GWL_EXSTYLE).
731 ok((info
->dwExStyle
& ~0x800) == (DWORD
)GetWindowLongA(hwnd
, GWL_EXSTYLE
),
732 "wrong dwExStyle: %08x != %08x\n", info
->dwExStyle
, GetWindowLongA(hwnd
, GWL_EXSTYLE
));
733 status
= (GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0;
734 ok(info
->dwWindowStatus
== status
, "wrong dwWindowStatus: %04x != %04x\n",
735 info
->dwWindowStatus
, status
);
737 trace("rcWindow: %d,%d - %d,%d\n", rcWindow
.left
, rcWindow
.top
, rcWindow
.right
, rcWindow
.bottom
);
738 trace("rcClient: %d,%d - %d,%d\n", rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
740 /* win2k and XP return broken border info in GetWindowInfo most of
741 * the time, so there is no point in testing it.
745 ok(info
->cxWindowBorders
== (unsigned)(rcClient
.left
- rcWindow
.left
),
746 "wrong cxWindowBorders %d != %d\n", info
->cxWindowBorders
, rcClient
.left
- rcWindow
.left
);
747 border
= min(rcWindow
.bottom
- rcClient
.bottom
, rcClient
.top
- rcWindow
.top
);
748 ok(info
->cyWindowBorders
== border
,
749 "wrong cyWindowBorders %d != %d\n", info
->cyWindowBorders
, border
);
751 ok(info
->atomWindowType
== GetClassLongA(hwnd
, GCW_ATOM
), "wrong atomWindowType\n");
752 ok(info
->wCreatorVersion
== 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
753 info
->wCreatorVersion
== 0x0500 /* Vista */,
754 "wrong wCreatorVersion %04x\n", info
->wCreatorVersion
);
757 static void FixedAdjustWindowRectEx(RECT
* rc
, LONG style
, BOOL menu
, LONG exstyle
)
759 AdjustWindowRectEx(rc
, style
, menu
, exstyle
);
760 /* AdjustWindowRectEx does not include scroll bars */
761 if (style
& WS_VSCROLL
)
763 if(exstyle
& WS_EX_LEFTSCROLLBAR
)
764 rc
->left
-= GetSystemMetrics(SM_CXVSCROLL
);
766 rc
->right
+= GetSystemMetrics(SM_CXVSCROLL
);
768 if (style
& WS_HSCROLL
)
769 rc
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
772 static void test_nonclient_area(HWND hwnd
)
774 DWORD style
, exstyle
;
775 RECT rc_window
, rc_client
, rc
;
777 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
779 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
780 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
781 menu
= !(style
& WS_CHILD
) && GetMenu(hwnd
) != 0;
783 GetWindowRect(hwnd
, &rc_window
);
784 trace("window: (%d,%d)-(%d,%d)\n", rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
);
785 GetClientRect(hwnd
, &rc_client
);
786 trace("client: (%d,%d)-(%d,%d)\n", rc_client
.left
, rc_client
.top
, rc_client
.right
, rc_client
.bottom
);
788 /* avoid some cases when things go wrong */
789 if (IsRectEmpty(&rc_window
) || IsRectEmpty(&rc_client
) ||
790 rc_window
.right
> 32768 || rc_window
.bottom
> 32768) return;
792 CopyRect(&rc
, &rc_client
);
793 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc
, 2);
794 FixedAdjustWindowRectEx(&rc
, style
, menu
, exstyle
);
796 trace("calc window: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
797 ok(EqualRect(&rc
, &rc_window
), "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
800 CopyRect(&rc
, &rc_window
);
801 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
802 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
803 trace("calc client: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
804 ok(EqualRect(&rc
, &rc_client
), "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
806 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
810 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
811 SetRect(&rc_client
, 0, 0, 250, 150);
812 CopyRect(&rc_window
, &rc_client
);
813 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc_window
, 2);
814 FixedAdjustWindowRectEx(&rc_window
, style
, menu
, exstyle
);
815 trace("calc window: (%d,%d)-(%d,%d)\n",
816 rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
);
818 CopyRect(&rc
, &rc_window
);
819 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
820 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
821 trace("calc client: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
822 ok(EqualRect(&rc
, &rc_client
), "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
825 static LRESULT CALLBACK
cbt_hook_proc(int nCode
, WPARAM wParam
, LPARAM lParam
)
827 static const char *CBT_code_name
[10] = {
838 const char *code_name
= (nCode
>= 0 && nCode
<= HCBT_SETFOCUS
) ? CBT_code_name
[nCode
] : "Unknown";
840 trace("CBT: %d (%s), %08lx, %08lx\n", nCode
, code_name
, wParam
, lParam
);
842 /* on HCBT_DESTROYWND window state is undefined */
843 if (nCode
!= HCBT_DESTROYWND
&& IsWindow((HWND
)wParam
))
849 /* Win98 actually does check the info.cbSize and doesn't allow
850 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
851 * WinXP do not check it at all.
853 info
.cbSize
= sizeof(WINDOWINFO
);
854 ok(pGetWindowInfo((HWND
)wParam
, &info
), "GetWindowInfo should not fail\n");
855 verify_window_info((HWND
)wParam
, &info
);
863 static const RECT rc_null
;
866 CBT_CREATEWNDA
*createwnd
= (CBT_CREATEWNDA
*)lParam
;
867 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
868 (HWND
)wParam
, createwnd
->lpcs
->hwndParent
, createwnd
->lpcs
->style
);
869 ok(createwnd
->hwndInsertAfter
== HWND_TOP
, "hwndInsertAfter should be always HWND_TOP\n");
871 /* WS_VISIBLE should be turned off yet */
872 style
= createwnd
->lpcs
->style
& ~WS_VISIBLE
;
873 ok(style
== GetWindowLongA((HWND
)wParam
, GWL_STYLE
),
874 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
875 GetWindowLongA((HWND
)wParam
, GWL_STYLE
), style
);
879 /* Uncomment this once the test succeeds in all cases */
880 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
882 ok(GetParent((HWND
)wParam
) == hwndMessage
,
883 "wrong result from GetParent %p: message window %p\n",
884 GetParent((HWND
)wParam
), hwndMessage
);
887 ok(!GetParent((HWND
)wParam
), "GetParent should return 0 at this point\n");
889 ok(!GetWindow((HWND
)wParam
, GW_OWNER
), "GW_OWNER should be set to 0 at this point\n");
893 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
894 * Win9x still has them set to 0.
896 ok(GetWindow((HWND
)wParam
, GW_HWNDFIRST
) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
897 ok(GetWindow((HWND
)wParam
, GW_HWNDLAST
) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
899 ok(!GetWindow((HWND
)wParam
, GW_HWNDPREV
), "GW_HWNDPREV should be set to 0 at this point\n");
900 ok(!GetWindow((HWND
)wParam
, GW_HWNDNEXT
), "GW_HWNDNEXT should be set to 0 at this point\n");
904 /* Uncomment this once the test succeeds in all cases */
907 ok(pGetAncestor((HWND
)wParam
, GA_PARENT
) == hwndMessage
, "GA_PARENT should be set to hwndMessage at this point\n");
908 ok(pGetAncestor((HWND
)wParam
, GA_ROOT
) == (HWND
)wParam
,
909 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND
)wParam
, GA_ROOT
), (HWND
)wParam
);
911 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
912 ok(pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
) == hwndMessage
,
913 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
915 ok(pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
) == (HWND
)wParam
,
916 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
), (HWND
)wParam
);
919 ok(GetWindowRect((HWND
)wParam
, &rc
), "GetWindowRect failed\n");
920 ok(EqualRect(&rc
, &rc_null
), "window rect should be set to 0 HCBT_CREATEWND\n");
921 ok(GetClientRect((HWND
)wParam
, &rc
), "GetClientRect failed\n");
922 ok(EqualRect(&rc
, &rc_null
), "client rect should be set to 0 on HCBT_CREATEWND\n");
928 return CallNextHookEx(hhook
, nCode
, wParam
, lParam
);
931 static void test_shell_window(void)
935 HMODULE hinst
, hUser32
;
936 BOOL (WINAPI
*SetShellWindow
)(HWND
);
937 BOOL (WINAPI
*SetShellWindowEx
)(HWND
, HWND
);
938 HWND hwnd1
, hwnd2
, hwnd3
, hwnd4
, hwnd5
;
939 HWND shellWindow
, nextWnd
;
941 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE
))
943 trace("Skipping shell window test on Win9x\n");
947 shellWindow
= GetShellWindow();
948 hinst
= GetModuleHandle(0);
949 hUser32
= GetModuleHandleA("user32");
951 SetShellWindow
= (void *)GetProcAddress(hUser32
, "SetShellWindow");
952 SetShellWindowEx
= (void *)GetProcAddress(hUser32
, "SetShellWindowEx");
954 trace("previous shell window: %p\n", shellWindow
);
960 ret
= DestroyWindow(shellWindow
);
961 error
= GetLastError();
963 ok(!ret
, "DestroyWindow(shellWindow)\n");
964 /* passes on Win XP, but not on Win98 */
965 ok(error
==ERROR_ACCESS_DENIED
, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n");
967 /* close old shell instance */
968 GetWindowThreadProcessId(shellWindow
, &pid
);
969 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, pid
);
970 ret
= TerminateProcess(hProcess
, 0);
971 ok(ret
, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
972 WaitForSingleObject(hProcess
, INFINITE
); /* wait for termination */
973 CloseHandle(hProcess
);
976 hwnd1
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst
, 0);
977 trace("created window 1: %p\n", hwnd1
);
979 ret
= SetShellWindow(hwnd1
);
980 ok(ret
, "first call to SetShellWindow(hwnd1)\n");
981 shellWindow
= GetShellWindow();
982 ok(shellWindow
==hwnd1
, "wrong shell window: %p\n", shellWindow
);
984 ret
= SetShellWindow(hwnd1
);
985 ok(!ret
, "second call to SetShellWindow(hwnd1)\n");
987 ret
= SetShellWindow(0);
988 error
= GetLastError();
989 /* passes on Win XP, but not on Win98
990 ok(!ret, "reset shell window by SetShellWindow(0)\n");
991 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
993 ret
= SetShellWindow(hwnd1
);
994 /* passes on Win XP, but not on Win98
995 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
997 SetWindowLong(hwnd1
, GWL_EXSTYLE
, GetWindowLong(hwnd1
,GWL_EXSTYLE
)|WS_EX_TOPMOST
);
998 ret
= GetWindowLong(hwnd1
,GWL_EXSTYLE
)&WS_EX_TOPMOST
? TRUE
: FALSE
;
999 ok(!ret
, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1001 ret
= DestroyWindow(hwnd1
);
1002 ok(ret
, "DestroyWindow(hwnd1)\n");
1004 hwnd2
= CreateWindowEx(WS_EX_TOPMOST
, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst
, 0);
1005 trace("created window 2: %p\n", hwnd2
);
1006 ret
= SetShellWindow(hwnd2
);
1007 ok(!ret
, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1009 hwnd3
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst
, 0);
1010 trace("created window 3: %p\n", hwnd3
);
1012 hwnd4
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst
, 0);
1013 trace("created window 4: %p\n", hwnd4
);
1015 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1016 ok(nextWnd
==hwnd3
, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd
);
1018 ret
= SetShellWindow(hwnd4
);
1019 ok(ret
, "SetShellWindow(hwnd4)\n");
1020 shellWindow
= GetShellWindow();
1021 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1023 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1024 ok(nextWnd
==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd
);
1026 ret
= SetWindowPos(hwnd4
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1027 ok(ret
, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1029 ret
= SetWindowPos(hwnd4
, hwnd3
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1030 ok(ret
, "SetWindowPos(hwnd4, hwnd3\n");
1032 ret
= SetShellWindow(hwnd3
);
1033 ok(!ret
, "SetShellWindow(hwnd3)\n");
1034 shellWindow
= GetShellWindow();
1035 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1037 hwnd5
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst
, 0);
1038 trace("created window 5: %p\n", hwnd5
);
1039 ret
= SetWindowPos(hwnd4
, hwnd5
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1040 ok(ret
, "SetWindowPos(hwnd4, hwnd5)\n");
1044 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1045 ok(nextWnd
==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd
);
1048 /* destroy test windows */
1049 DestroyWindow(hwnd2
);
1050 DestroyWindow(hwnd3
);
1051 DestroyWindow(hwnd4
);
1052 DestroyWindow(hwnd5
);
1055 /************** MDI test ****************/
1057 static char mdi_lParam_test_message
[] = "just a test string";
1059 static void test_MDI_create(HWND parent
, HWND mdi_client
, INT first_id
)
1061 MDICREATESTRUCTA mdi_cs
;
1063 static const WCHAR classW
[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1064 static const WCHAR titleW
[] = {'M','D','I',' ','c','h','i','l','d',0};
1065 BOOL isWin9x
= FALSE
;
1067 mdi_cs
.szClass
= "MDI_child_Class_1";
1068 mdi_cs
.szTitle
= "MDI child";
1069 mdi_cs
.hOwner
= GetModuleHandle(0);
1070 mdi_cs
.x
= CW_USEDEFAULT
;
1071 mdi_cs
.y
= CW_USEDEFAULT
;
1072 mdi_cs
.cx
= CW_USEDEFAULT
;
1073 mdi_cs
.cy
= CW_USEDEFAULT
;
1075 mdi_cs
.lParam
= (LPARAM
)mdi_lParam_test_message
;
1076 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1077 ok(mdi_child
!= 0, "MDI child creation failed\n");
1078 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1079 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1080 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1082 mdi_cs
.style
= 0x7fffffff; /* without WS_POPUP */
1083 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1084 ok(mdi_child
!= 0, "MDI child creation failed\n");
1085 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1086 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1087 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1089 mdi_cs
.style
= 0xffffffff; /* with WS_POPUP */
1090 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1091 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1093 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1097 ok(mdi_child
!= 0, "MDI child creation failed\n");
1098 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1099 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1100 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1103 /* test MDICREATESTRUCT A<->W mapping */
1104 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1106 mdi_cs
.szClass
= (LPCSTR
)classW
;
1107 mdi_cs
.szTitle
= (LPCSTR
)titleW
;
1108 SetLastError(0xdeadbeef);
1109 mdi_child
= (HWND
)SendMessageW(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1112 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1115 ok(mdi_child
!= 0, "MDI child creation failed\n");
1119 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1120 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1121 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1124 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1126 CW_USEDEFAULT
, CW_USEDEFAULT
,
1127 CW_USEDEFAULT
, CW_USEDEFAULT
,
1128 mdi_client
, GetModuleHandle(0),
1129 (LPARAM
)mdi_lParam_test_message
);
1130 ok(mdi_child
!= 0, "MDI child creation failed\n");
1131 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1132 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1133 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1135 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1136 0x7fffffff, /* without WS_POPUP */
1137 CW_USEDEFAULT
, CW_USEDEFAULT
,
1138 CW_USEDEFAULT
, CW_USEDEFAULT
,
1139 mdi_client
, GetModuleHandle(0),
1140 (LPARAM
)mdi_lParam_test_message
);
1141 ok(mdi_child
!= 0, "MDI child creation failed\n");
1142 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1143 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1144 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1146 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1147 0xffffffff, /* with WS_POPUP */
1148 CW_USEDEFAULT
, CW_USEDEFAULT
,
1149 CW_USEDEFAULT
, CW_USEDEFAULT
,
1150 mdi_client
, GetModuleHandle(0),
1151 (LPARAM
)mdi_lParam_test_message
);
1152 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1154 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1158 ok(mdi_child
!= 0, "MDI child creation failed\n");
1159 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1160 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1161 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1164 /* test MDICREATESTRUCT A<->W mapping */
1165 SetLastError(0xdeadbeef);
1166 mdi_child
= CreateMDIWindowW(classW
, titleW
,
1168 CW_USEDEFAULT
, CW_USEDEFAULT
,
1169 CW_USEDEFAULT
, CW_USEDEFAULT
,
1170 mdi_client
, GetModuleHandle(0),
1171 (LPARAM
)mdi_lParam_test_message
);
1174 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1177 ok(mdi_child
!= 0, "MDI child creation failed\n");
1181 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1182 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1183 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1186 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1188 CW_USEDEFAULT
, CW_USEDEFAULT
,
1189 CW_USEDEFAULT
, CW_USEDEFAULT
,
1190 mdi_client
, 0, GetModuleHandle(0),
1191 (LPVOID
)mdi_lParam_test_message
);
1192 ok(mdi_child
!= 0, "MDI child creation failed\n");
1193 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1194 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1195 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1197 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1198 0x7fffffff, /* without WS_POPUP */
1199 CW_USEDEFAULT
, CW_USEDEFAULT
,
1200 CW_USEDEFAULT
, CW_USEDEFAULT
,
1201 mdi_client
, 0, GetModuleHandle(0),
1202 (LPVOID
)mdi_lParam_test_message
);
1203 ok(mdi_child
!= 0, "MDI child creation failed\n");
1204 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1205 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1206 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1208 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1209 0xffffffff, /* with WS_POPUP */
1210 CW_USEDEFAULT
, CW_USEDEFAULT
,
1211 CW_USEDEFAULT
, CW_USEDEFAULT
,
1212 mdi_client
, 0, GetModuleHandle(0),
1213 (LPVOID
)mdi_lParam_test_message
);
1214 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1216 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1220 ok(mdi_child
!= 0, "MDI child creation failed\n");
1221 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1222 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1223 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1226 /* test MDICREATESTRUCT A<->W mapping */
1227 SetLastError(0xdeadbeef);
1228 mdi_child
= CreateWindowExW(WS_EX_MDICHILD
, classW
, titleW
,
1230 CW_USEDEFAULT
, CW_USEDEFAULT
,
1231 CW_USEDEFAULT
, CW_USEDEFAULT
,
1232 mdi_client
, 0, GetModuleHandle(0),
1233 (LPVOID
)mdi_lParam_test_message
);
1236 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1239 ok(mdi_child
!= 0, "MDI child creation failed\n");
1243 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1244 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1245 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1248 /* This test fails on Win9x */
1251 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_2", "MDI child",
1253 CW_USEDEFAULT
, CW_USEDEFAULT
,
1254 CW_USEDEFAULT
, CW_USEDEFAULT
,
1255 parent
, 0, GetModuleHandle(0),
1256 (LPVOID
)mdi_lParam_test_message
);
1257 ok(!mdi_child
, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1260 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1261 WS_CHILD
, /* without WS_POPUP */
1262 CW_USEDEFAULT
, CW_USEDEFAULT
,
1263 CW_USEDEFAULT
, CW_USEDEFAULT
,
1264 mdi_client
, 0, GetModuleHandle(0),
1265 (LPVOID
)mdi_lParam_test_message
);
1266 ok(mdi_child
!= 0, "MDI child creation failed\n");
1267 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1268 DestroyWindow(mdi_child
);
1270 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1271 WS_CHILD
| WS_POPUP
, /* with WS_POPUP */
1272 CW_USEDEFAULT
, CW_USEDEFAULT
,
1273 CW_USEDEFAULT
, CW_USEDEFAULT
,
1274 mdi_client
, 0, GetModuleHandle(0),
1275 (LPVOID
)mdi_lParam_test_message
);
1276 ok(mdi_child
!= 0, "MDI child creation failed\n");
1277 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1278 DestroyWindow(mdi_child
);
1280 /* maximized child */
1281 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1282 WS_CHILD
| WS_MAXIMIZE
,
1283 CW_USEDEFAULT
, CW_USEDEFAULT
,
1284 CW_USEDEFAULT
, CW_USEDEFAULT
,
1285 mdi_client
, 0, GetModuleHandle(0),
1286 (LPVOID
)mdi_lParam_test_message
);
1287 ok(mdi_child
!= 0, "MDI child creation failed\n");
1288 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1289 DestroyWindow(mdi_child
);
1291 trace("Creating maximized child with a caption\n");
1292 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1293 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
,
1294 CW_USEDEFAULT
, CW_USEDEFAULT
,
1295 CW_USEDEFAULT
, CW_USEDEFAULT
,
1296 mdi_client
, 0, GetModuleHandle(0),
1297 (LPVOID
)mdi_lParam_test_message
);
1298 ok(mdi_child
!= 0, "MDI child creation failed\n");
1299 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1300 DestroyWindow(mdi_child
);
1302 trace("Creating maximized child with a caption and a thick frame\n");
1303 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1304 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
| WS_THICKFRAME
,
1305 CW_USEDEFAULT
, CW_USEDEFAULT
,
1306 CW_USEDEFAULT
, CW_USEDEFAULT
,
1307 mdi_client
, 0, GetModuleHandle(0),
1308 (LPVOID
)mdi_lParam_test_message
);
1309 ok(mdi_child
!= 0, "MDI child creation failed\n");
1310 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1311 DestroyWindow(mdi_child
);
1314 /**********************************************************************
1315 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1317 * Note: The rule here is that client rect of the maximized MDI child
1318 * is equal to the client rect of the MDI client window.
1320 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
1324 GetClientRect( client
, &rect
);
1325 AdjustWindowRectEx( &rect
, GetWindowLongA( hwnd
, GWL_STYLE
),
1326 0, GetWindowLongA( hwnd
, GWL_EXSTYLE
));
1328 rect
.right
-= rect
.left
;
1329 rect
.bottom
-= rect
.top
;
1330 lpMinMax
->ptMaxSize
.x
= rect
.right
;
1331 lpMinMax
->ptMaxSize
.y
= rect
.bottom
;
1333 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
1334 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
1336 trace("max rect (%d,%d - %d, %d)\n",
1337 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1340 static LRESULT WINAPI
mdi_child_wnd_proc_1(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1347 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1348 MDICREATESTRUCTA
*mdi_cs
= (MDICREATESTRUCTA
*)cs
->lpCreateParams
;
1350 ok(cs
->dwExStyle
& WS_EX_MDICHILD
, "WS_EX_MDICHILD should be set\n");
1351 ok(mdi_cs
->lParam
== (LPARAM
)mdi_lParam_test_message
, "wrong mdi_cs->lParam\n");
1353 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_1"), "wrong class name\n");
1354 ok(!lstrcmpA(cs
->lpszClass
, mdi_cs
->szClass
), "class name does not match\n");
1355 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1356 ok(!lstrcmpA(cs
->lpszName
, mdi_cs
->szTitle
), "title does not match\n");
1357 ok(cs
->hInstance
== mdi_cs
->hOwner
, "%p != %p\n", cs
->hInstance
, mdi_cs
->hOwner
);
1359 /* MDICREATESTRUCT should have original values */
1360 ok(mdi_cs
->style
== 0 || mdi_cs
->style
== 0x7fffffff || mdi_cs
->style
== 0xffffffff,
1361 "mdi_cs->style does not match (%08x)\n", mdi_cs
->style
);
1362 ok(mdi_cs
->x
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->x
);
1363 ok(mdi_cs
->y
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->y
);
1364 ok(mdi_cs
->cx
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cx
);
1365 ok(mdi_cs
->cy
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cy
);
1367 /* CREATESTRUCT should have fixed values */
1368 ok(cs
->x
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->x
);
1369 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1371 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1372 ok(cs
->cx
!= CW_USEDEFAULT
&& cs
->cx
!= 0, "%d == CW_USEDEFAULT\n", cs
->cx
);
1373 ok(cs
->cy
!= CW_USEDEFAULT
&& cs
->cy
!= 0, "%d == CW_USEDEFAULT\n", cs
->cy
);
1375 ok(!(cs
->style
& WS_POPUP
), "WS_POPUP is not allowed\n");
1377 if (GetWindowLongA(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1379 LONG style
= mdi_cs
->style
| WS_CHILD
| WS_CLIPSIBLINGS
;
1380 ok(cs
->style
== style
,
1381 "cs->style does not match (%08x)\n", cs
->style
);
1385 LONG style
= mdi_cs
->style
;
1387 style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1388 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1389 ok(cs
->style
== style
,
1390 "cs->style does not match (%08x)\n", cs
->style
);
1395 case WM_GETMINMAXINFO
:
1397 HWND client
= GetParent(hwnd
);
1399 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1400 MINMAXINFO my_minmax
;
1401 LONG style
, exstyle
;
1403 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1404 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1406 GetWindowRect(client
, &rc
);
1407 trace("MDI client %p window size = (%d x %d)\n", client
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1408 GetClientRect(client
, &rc
);
1409 trace("MDI client %p client size = (%d x %d)\n", client
, rc
.right
, rc
.bottom
);
1410 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN
),
1411 GetSystemMetrics(SM_CYSCREEN
));
1413 GetClientRect(client
, &rc
);
1414 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1415 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1416 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1417 trace("MDI child: calculated max window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1419 trace("ptReserved = (%d,%d)\n"
1420 "ptMaxSize = (%d,%d)\n"
1421 "ptMaxPosition = (%d,%d)\n"
1422 "ptMinTrackSize = (%d,%d)\n"
1423 "ptMaxTrackSize = (%d,%d)\n",
1424 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
1425 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
1426 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
1427 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
1428 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
1430 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1431 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1432 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1433 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1435 DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1437 trace("DefMDIChildProc returned:\n"
1438 "ptReserved = (%d,%d)\n"
1439 "ptMaxSize = (%d,%d)\n"
1440 "ptMaxPosition = (%d,%d)\n"
1441 "ptMinTrackSize = (%d,%d)\n"
1442 "ptMaxTrackSize = (%d,%d)\n",
1443 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
1444 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
1445 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
1446 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
1447 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
1449 MDI_ChildGetMinMaxInfo(client
, hwnd
, &my_minmax
);
1450 ok(minmax
->ptMaxSize
.x
== my_minmax
.ptMaxSize
.x
, "default width of maximized child %d != %d\n",
1451 minmax
->ptMaxSize
.x
, my_minmax
.ptMaxSize
.x
);
1452 ok(minmax
->ptMaxSize
.y
== my_minmax
.ptMaxSize
.y
, "default height of maximized child %d != %d\n",
1453 minmax
->ptMaxSize
.y
, my_minmax
.ptMaxSize
.y
);
1458 case WM_MDIACTIVATE
:
1460 HWND active
, client
= GetParent(hwnd
);
1461 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1462 active
= (HWND
)SendMessageA(client
, WM_MDIGETACTIVE
, 0, 0);
1463 if (hwnd
== (HWND
)lparam
) /* if we are being activated */
1464 ok (active
== (HWND
)lparam
, "new active %p != active %p\n", (HWND
)lparam
, active
);
1466 ok (active
== (HWND
)wparam
, "old active %p != active %p\n", (HWND
)wparam
, active
);
1470 return DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1473 static LRESULT WINAPI
mdi_child_wnd_proc_2(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1480 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1482 trace("%s\n", (msg
== WM_NCCREATE
) ? "WM_NCCREATE" : "WM_CREATE");
1483 trace("x %d, y %d, cx %d, cy %d\n", cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
1485 ok(!(cs
->dwExStyle
& WS_EX_MDICHILD
), "WS_EX_MDICHILD should not be set\n");
1486 ok(cs
->lpCreateParams
== mdi_lParam_test_message
, "wrong cs->lpCreateParams\n");
1488 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_2"), "wrong class name\n");
1489 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1491 /* CREATESTRUCT should have fixed values */
1492 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1494 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1495 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1497 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1498 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1499 while Win95, Win2k, WinXP do. */
1500 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1501 ok(cs
->cy
== 0, "%d != 0\n", cs
->cy
);
1505 case WM_GETMINMAXINFO
:
1507 HWND parent
= GetParent(hwnd
);
1509 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1510 LONG style
, exstyle
;
1512 trace("WM_GETMINMAXINFO\n");
1514 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1515 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1517 GetClientRect(parent
, &rc
);
1518 trace("parent %p client size = (%d x %d)\n", parent
, rc
.right
, rc
.bottom
);
1520 GetClientRect(parent
, &rc
);
1521 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1522 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1523 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1524 trace("calculated max child window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1526 trace("ptReserved = (%d,%d)\n"
1527 "ptMaxSize = (%d,%d)\n"
1528 "ptMaxPosition = (%d,%d)\n"
1529 "ptMinTrackSize = (%d,%d)\n"
1530 "ptMaxTrackSize = (%d,%d)\n",
1531 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
1532 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
1533 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
1534 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
1535 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
1537 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1538 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1539 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1540 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1544 case WM_WINDOWPOSCHANGED
:
1546 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1549 GetWindowRect(hwnd
, &rc1
);
1550 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1551 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1552 /* note: winpos coordinates are relative to parent */
1553 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1554 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1555 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1557 GetWindowRect(hwnd
, &rc1
);
1558 GetClientRect(hwnd
, &rc2
);
1559 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1560 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1561 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1564 case WM_WINDOWPOSCHANGING
:
1566 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1567 WINDOWPOS my_winpos
= *winpos
;
1569 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1570 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1571 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1572 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1574 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1576 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1577 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1578 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1580 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1581 "DefWindowProc should not change WINDOWPOS values\n");
1586 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1589 static LRESULT WINAPI
mdi_main_wnd_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1591 static HWND mdi_client
;
1597 CLIENTCREATESTRUCT client_cs
;
1600 GetClientRect(hwnd
, &rc
);
1602 client_cs
.hWindowMenu
= 0;
1603 client_cs
.idFirstChild
= 1;
1605 /* MDIClient without MDIS_ALLCHILDSTYLES */
1606 mdi_client
= CreateWindowExA(0, "mdiclient",
1608 WS_CHILD
/*| WS_VISIBLE*/,
1609 /* tests depend on a not zero MDIClient size */
1610 0, 0, rc
.right
, rc
.bottom
,
1611 hwnd
, 0, GetModuleHandle(0),
1612 (LPVOID
)&client_cs
);
1614 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1615 DestroyWindow(mdi_client
);
1617 /* MDIClient with MDIS_ALLCHILDSTYLES */
1618 mdi_client
= CreateWindowExA(0, "mdiclient",
1620 WS_CHILD
| MDIS_ALLCHILDSTYLES
/*| WS_VISIBLE*/,
1621 /* tests depend on a not zero MDIClient size */
1622 0, 0, rc
.right
, rc
.bottom
,
1623 hwnd
, 0, GetModuleHandle(0),
1624 (LPVOID
)&client_cs
);
1626 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1627 DestroyWindow(mdi_client
);
1631 case WM_WINDOWPOSCHANGED
:
1633 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1636 GetWindowRect(hwnd
, &rc1
);
1637 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1638 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1639 /* note: winpos coordinates are relative to parent */
1640 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1641 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1642 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1644 GetWindowRect(hwnd
, &rc1
);
1645 GetClientRect(hwnd
, &rc2
);
1646 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1647 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1648 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1651 case WM_WINDOWPOSCHANGING
:
1653 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1654 WINDOWPOS my_winpos
= *winpos
;
1656 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1657 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1658 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1659 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1661 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1663 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1664 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1665 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1667 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1668 "DefWindowProc should not change WINDOWPOS values\n");
1677 return DefFrameProcA(hwnd
, mdi_client
, msg
, wparam
, lparam
);
1680 static BOOL
mdi_RegisterWindowClasses(void)
1685 cls
.lpfnWndProc
= mdi_main_wnd_procA
;
1688 cls
.hInstance
= GetModuleHandleA(0);
1690 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
1691 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1692 cls
.lpszMenuName
= NULL
;
1693 cls
.lpszClassName
= "MDI_parent_Class";
1694 if(!RegisterClassA(&cls
)) return FALSE
;
1696 cls
.lpfnWndProc
= mdi_child_wnd_proc_1
;
1697 cls
.lpszClassName
= "MDI_child_Class_1";
1698 if(!RegisterClassA(&cls
)) return FALSE
;
1700 cls
.lpfnWndProc
= mdi_child_wnd_proc_2
;
1701 cls
.lpszClassName
= "MDI_child_Class_2";
1702 if(!RegisterClassA(&cls
)) return FALSE
;
1707 static void test_mdi(void)
1712 if (!mdi_RegisterWindowClasses()) assert(0);
1714 mdi_hwndMain
= CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1715 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
1716 WS_MAXIMIZEBOX
/*| WS_VISIBLE*/,
1717 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1718 GetDesktopWindow(), 0,
1719 GetModuleHandle(0), NULL
);
1720 assert(mdi_hwndMain
);
1722 while(GetMessage(&msg, 0, 0, 0))
1724 TranslateMessage(&msg);
1725 DispatchMessage(&msg);
1728 DestroyWindow(mdi_hwndMain
);
1731 static void test_icons(void)
1735 HICON icon
= LoadIconA(0, (LPSTR
)IDI_APPLICATION
);
1736 HICON icon2
= LoadIconA(0, (LPSTR
)IDI_QUESTION
);
1737 HICON small_icon
= LoadImageA(0, (LPSTR
)IDI_APPLICATION
, IMAGE_ICON
,
1738 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
1741 cls
.cbSize
= sizeof(cls
);
1743 cls
.lpfnWndProc
= DefWindowProcA
;
1747 cls
.hIcon
= LoadIconA(0, (LPSTR
)IDI_HAND
);
1748 cls
.hIconSm
= small_icon
;
1749 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
1750 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1751 cls
.lpszMenuName
= NULL
;
1752 cls
.lpszClassName
= "IconWindowClass";
1754 RegisterClassExA(&cls
);
1756 hwnd
= CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1757 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, NULL
, NULL
);
1760 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1761 ok( res
== 0, "wrong big icon %p/0\n", res
);
1762 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon
);
1763 ok( res
== 0, "wrong previous big icon %p/0\n", res
);
1764 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1765 ok( res
== icon
, "wrong big icon after set %p/%p\n", res
, icon
);
1766 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon2
);
1767 ok( res
== icon
, "wrong previous big icon %p/%p\n", res
, icon
);
1768 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1769 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1771 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1772 ok( res
== 0, "wrong small icon %p/0\n", res
);
1773 /* this test is XP specific */
1774 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1775 ok( res != 0, "wrong small icon %p\n", res );*/
1776 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)icon
);
1777 ok( res
== 0, "wrong previous small icon %p/0\n", res
);
1778 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1779 ok( res
== icon
, "wrong small icon after set %p/%p\n", res
, icon
);
1780 /* this test is XP specific */
1781 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1782 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1783 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)small_icon
);
1784 ok( res
== icon
, "wrong previous small icon %p/%p\n", res
, icon
);
1785 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1786 ok( res
== small_icon
, "wrong small icon after set %p/%p\n", res
, small_icon
);
1787 /* this test is XP specific */
1788 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1789 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1791 /* make sure the big icon hasn't changed */
1792 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1793 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1795 DestroyWindow( hwnd
);
1798 static LRESULT WINAPI
nccalcsize_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1800 if (msg
== WM_NCCALCSIZE
)
1802 RECT
*rect
= (RECT
*)lparam
;
1803 /* first time around increase the rectangle, next time decrease it */
1804 if (rect
->left
== 100) InflateRect( rect
, 10, 10 );
1805 else InflateRect( rect
, -10, -10 );
1808 return DefWindowProc( hwnd
, msg
, wparam
, lparam
);
1811 static void test_SetWindowPos(HWND hwnd
)
1813 RECT orig_win_rc
, rect
;
1815 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
1817 SetRect(&rect
, 111, 222, 333, 444);
1818 ok(!GetWindowRect(0, &rect
), "GetWindowRect succeeded\n");
1819 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1820 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1822 SetRect(&rect
, 111, 222, 333, 444);
1823 ok(!GetClientRect(0, &rect
), "GetClientRect succeeded\n");
1824 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1825 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1827 GetWindowRect(hwnd
, &orig_win_rc
);
1829 old_proc
= SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)nccalcsize_proc
);
1830 SetWindowPos(hwnd
, 0, 100, 100, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1831 GetWindowRect( hwnd
, &rect
);
1832 ok( rect
.left
== 100 && rect
.top
== 100 && rect
.right
== 100 && rect
.bottom
== 100,
1833 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1834 GetClientRect( hwnd
, &rect
);
1835 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1836 ok( rect
.left
== 90 && rect
.top
== 90 && rect
.right
== 110 && rect
.bottom
== 110,
1837 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1839 SetWindowPos(hwnd
, 0, 200, 200, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1840 GetWindowRect( hwnd
, &rect
);
1841 ok( rect
.left
== 200 && rect
.top
== 200 && rect
.right
== 200 && rect
.bottom
== 200,
1842 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1843 GetClientRect( hwnd
, &rect
);
1844 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1845 ok( rect
.left
== 210 && rect
.top
== 210 && rect
.right
== 190 && rect
.bottom
== 190,
1846 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1848 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1849 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1850 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, old_proc
);
1852 /* Win9x truncates coordinates to 16-bit irrespectively */
1855 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE
);
1856 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE
);
1858 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE
);
1859 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE
);
1862 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1863 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1865 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1866 SetWindowPos(hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1867 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1868 SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1869 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1870 SetWindowPos(hwnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1871 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1874 static void test_SetMenu(HWND parent
)
1878 BOOL is_win9x
= GetWindowLongPtrW(parent
, GWLP_WNDPROC
) == 0;
1882 hMenu
= CreateMenu();
1885 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1888 /* fails on (at least) Wine, NT4, XP SP2 */
1889 test_nonclient_area(parent
);
1891 ret
= GetMenu(parent
);
1892 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1893 /* test whether we can destroy a menu assigned to a window */
1894 retok
= DestroyMenu(hMenu
);
1895 ok( retok
, "DestroyMenu error %d\n", GetLastError());
1896 ok(!IsMenu(hMenu
), "menu handle should be not valid after DestroyMenu\n");
1897 ret
= GetMenu(parent
);
1898 /* This test fails on Win9x */
1900 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1901 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1902 test_nonclient_area(parent
);
1904 hMenu
= CreateMenu();
1908 ret
= GetMenu(parent
);
1909 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1911 ok(!SetMenu(parent
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1912 test_nonclient_area(parent
);
1913 ret
= GetMenu(parent
);
1914 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1916 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1919 /* fails on (at least) Wine, NT4, XP SP2 */
1920 test_nonclient_area(parent
);
1922 ret
= GetMenu(parent
);
1923 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1925 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1926 test_nonclient_area(parent
);
1927 ret
= GetMenu(parent
);
1928 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1931 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, parent
, (HMENU
)10, 0, NULL
);
1934 ret
= GetMenu(child
);
1935 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1937 ok(!SetMenu(child
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1938 test_nonclient_area(child
);
1939 ret
= GetMenu(child
);
1940 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1942 ok(!SetMenu(child
, hMenu
), "SetMenu on a child window should fail\n");
1943 test_nonclient_area(child
);
1944 ret
= GetMenu(child
);
1945 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1947 ok(!SetMenu(child
, 0), "SetMenu(0) on a child window should fail\n");
1948 test_nonclient_area(child
);
1949 ret
= GetMenu(child
);
1950 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1952 style
= GetWindowLong(child
, GWL_STYLE
);
1953 SetWindowLong(child
, GWL_STYLE
, style
| WS_POPUP
);
1954 ok(SetMenu(child
, hMenu
), "SetMenu on a popup child window should not fail\n");
1955 ok(SetMenu(child
, 0), "SetMenu on a popup child window should not fail\n");
1956 SetWindowLong(child
, GWL_STYLE
, style
);
1958 SetWindowLong(child
, GWL_STYLE
, style
| WS_OVERLAPPED
);
1959 ok(!SetMenu(child
, hMenu
), "SetMenu on a overlapped child window should fail\n");
1960 SetWindowLong(child
, GWL_STYLE
, style
);
1962 DestroyWindow(child
);
1966 static void test_window_tree(HWND parent
, const DWORD
*style
, const int *order
, int total
)
1968 HWND child
[5], hwnd
;
1973 hwnd
= GetWindow(parent
, GW_CHILD
);
1974 ok(!hwnd
, "have to start without children to perform the test\n");
1976 for (i
= 0; i
< total
; i
++)
1978 if (style
[i
] & DS_CONTROL
)
1980 child
[i
] = CreateWindowExA(0, MAKEINTATOM(32770), "", style
[i
] & ~WS_VISIBLE
,
1981 0,0,0,0, parent
, (HMENU
)i
, 0, NULL
);
1982 if (style
[i
] & WS_VISIBLE
)
1983 ShowWindow(child
[i
], SW_SHOW
);
1985 SetWindowPos(child
[i
], HWND_BOTTOM
, 0,0,10,10, SWP_NOACTIVATE
);
1988 child
[i
] = CreateWindowExA(0, "static", "", style
[i
], 0,0,10,10,
1989 parent
, (HMENU
)i
, 0, NULL
);
1990 trace("child[%d] = %p\n", i
, child
[i
]);
1991 ok(child
[i
] != 0, "CreateWindowEx failed to create child window\n");
1994 hwnd
= GetWindow(parent
, GW_CHILD
);
1995 ok(hwnd
!= 0, "GetWindow(GW_CHILD) failed\n");
1996 ok(hwnd
== GetWindow(child
[total
- 1], GW_HWNDFIRST
), "GW_HWNDFIRST is wrong\n");
1997 ok(child
[order
[total
- 1]] == GetWindow(child
[0], GW_HWNDLAST
), "GW_HWNDLAST is wrong\n");
1999 for (i
= 0; i
< total
; i
++)
2001 trace("hwnd[%d] = %p\n", i
, hwnd
);
2002 ok(child
[order
[i
]] == hwnd
, "Z order of child #%d is wrong\n", i
);
2004 hwnd
= GetWindow(hwnd
, GW_HWNDNEXT
);
2007 for (i
= 0; i
< total
; i
++)
2008 ok(DestroyWindow(child
[i
]), "DestroyWindow failed\n");
2011 static void test_children_zorder(HWND parent
)
2013 const DWORD simple_style
[5] = { WS_CHILD
, WS_CHILD
, WS_CHILD
, WS_CHILD
,
2015 const int simple_order
[5] = { 0, 1, 2, 3, 4 };
2017 const DWORD complex_style
[5] = { WS_CHILD
, WS_CHILD
| WS_MAXIMIZE
,
2018 WS_CHILD
| WS_VISIBLE
, WS_CHILD
,
2019 WS_CHILD
| WS_MAXIMIZE
| WS_VISIBLE
};
2020 const int complex_order_1
[1] = { 0 };
2021 const int complex_order_2
[2] = { 1, 0 };
2022 const int complex_order_3
[3] = { 1, 0, 2 };
2023 const int complex_order_4
[4] = { 1, 0, 2, 3 };
2024 const int complex_order_5
[5] = { 4, 1, 0, 2, 3 };
2025 const DWORD complex_style_6
[3] = { WS_CHILD
| WS_VISIBLE
,
2026 WS_CHILD
| WS_CLIPSIBLINGS
| DS_CONTROL
| WS_VISIBLE
,
2027 WS_CHILD
| WS_VISIBLE
};
2028 const int complex_order_6
[3] = { 0, 1, 2 };
2030 /* simple WS_CHILD */
2031 test_window_tree(parent
, simple_style
, simple_order
, 5);
2033 /* complex children styles */
2034 test_window_tree(parent
, complex_style
, complex_order_1
, 1);
2035 test_window_tree(parent
, complex_style
, complex_order_2
, 2);
2036 test_window_tree(parent
, complex_style
, complex_order_3
, 3);
2037 test_window_tree(parent
, complex_style
, complex_order_4
, 4);
2038 test_window_tree(parent
, complex_style
, complex_order_5
, 5);
2040 /* another set of complex children styles */
2041 test_window_tree(parent
, complex_style_6
, complex_order_6
, 3);
2044 #define check_z_order(hwnd, next, prev, owner, topmost) \
2045 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2048 static void check_z_order_debug(HWND hwnd
, HWND next
, HWND prev
, HWND owner
,
2049 BOOL topmost
, const char *file
, int line
)
2054 test
= GetWindow(hwnd
, GW_HWNDNEXT
);
2055 /* skip foreign windows */
2056 while (test
&& (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2057 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0)))
2059 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2060 test
= GetWindow(test
, GW_HWNDNEXT
);
2062 ok_(file
, line
)(next
== test
, "expected next %p, got %p\n", next
, test
);
2064 test
= GetWindow(hwnd
, GW_HWNDPREV
);
2065 /* skip foreign windows */
2066 while (test
&& (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2067 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0)))
2069 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2070 test
= GetWindow(test
, GW_HWNDPREV
);
2072 ok_(file
, line
)(prev
== test
, "expected prev %p, got %p\n", prev
, test
);
2074 test
= GetWindow(hwnd
, GW_OWNER
);
2075 ok_(file
, line
)(owner
== test
, "expected owner %p, got %p\n", owner
, test
);
2077 ex_style
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
2078 ok_(file
, line
)(!(ex_style
& WS_EX_TOPMOST
) == !topmost
, "expected %stopmost\n", topmost
? "" : "NOT ");
2081 static void test_popup_zorder(HWND hwnd_D
, HWND hwnd_E
)
2083 HWND hwnd_A
, hwnd_B
, hwnd_C
, hwnd_F
;
2085 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D
, hwnd_E
);
2087 SetWindowPos(hwnd_E
, hwnd_D
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2089 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2090 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2092 hwnd_F
= CreateWindowEx(0, "MainWindowClass", "Owner window",
2093 WS_OVERLAPPED
| WS_CAPTION
,
2095 0, 0, GetModuleHandle(0), NULL
);
2096 trace("hwnd_F %p\n", hwnd_F
);
2097 check_z_order(hwnd_F
, hwnd_D
, 0, 0, FALSE
);
2099 SetWindowPos(hwnd_F
, hwnd_E
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2100 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2101 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2102 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2104 hwnd_C
= CreateWindowEx(0, "MainWindowClass", NULL
,
2107 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2108 trace("hwnd_C %p\n", hwnd_C
);
2109 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2110 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2111 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2112 check_z_order(hwnd_C
, hwnd_D
, 0, hwnd_F
, FALSE
);
2114 hwnd_B
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2117 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2118 trace("hwnd_B %p\n", hwnd_B
);
2119 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2120 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2121 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2122 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2123 check_z_order(hwnd_B
, hwnd_C
, 0, hwnd_F
, TRUE
);
2125 hwnd_A
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2128 0, 0, GetModuleHandle(0), NULL
);
2129 trace("hwnd_A %p\n", hwnd_A
);
2130 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2131 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2132 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2133 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2134 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2135 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2137 trace("A %p B %p C %p D %p E %p F %p\n", hwnd_A
, hwnd_B
, hwnd_C
, hwnd_D
, hwnd_E
, hwnd_F
);
2139 /* move hwnd_F and its popups up */
2140 SetWindowPos(hwnd_F
, HWND_TOP
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2141 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2142 check_z_order(hwnd_D
, hwnd_E
, hwnd_F
, 0, FALSE
);
2143 check_z_order(hwnd_F
, hwnd_D
, hwnd_C
, 0, FALSE
);
2144 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2145 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2146 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2148 /* move hwnd_F and its popups down */
2149 #if 0 /* enable once Wine is fixed to pass this test */
2150 SetWindowPos(hwnd_F
, HWND_BOTTOM
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2151 check_z_order(hwnd_F
, 0, hwnd_C
, 0, FALSE
);
2152 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2153 check_z_order(hwnd_B
, hwnd_C
, hwnd_E
, hwnd_F
, FALSE
);
2154 check_z_order(hwnd_E
, hwnd_B
, hwnd_D
, 0, FALSE
);
2155 check_z_order(hwnd_D
, hwnd_E
, hwnd_A
, 0, FALSE
);
2156 check_z_order(hwnd_A
, hwnd_D
, 0, 0, TRUE
);
2159 DestroyWindow(hwnd_A
);
2160 DestroyWindow(hwnd_B
);
2161 DestroyWindow(hwnd_C
);
2162 DestroyWindow(hwnd_F
);
2165 static void test_vis_rgn( HWND hwnd
)
2167 RECT win_rect
, rgn_rect
;
2168 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2171 ShowWindow(hwnd
,SW_SHOW
);
2172 hdc
= GetDC( hwnd
);
2173 ok( GetRandomRgn( hdc
, hrgn
, SYSRGN
) != 0, "GetRandomRgn failed\n" );
2174 GetWindowRect( hwnd
, &win_rect
);
2175 GetRgnBox( hrgn
, &rgn_rect
);
2176 if (GetVersion() & 0x80000000)
2178 trace("win9x, mapping to screen coords\n");
2179 MapWindowPoints( hwnd
, 0, (POINT
*)&rgn_rect
, 2 );
2181 trace("win: %d,%d-%d,%d\n", win_rect
.left
, win_rect
.top
, win_rect
.right
, win_rect
.bottom
);
2182 trace("rgn: %d,%d-%d,%d\n", rgn_rect
.left
, rgn_rect
.top
, rgn_rect
.right
, rgn_rect
.bottom
);
2183 ok( win_rect
.left
<= rgn_rect
.left
, "rgn left %d not inside win rect %d\n",
2184 rgn_rect
.left
, win_rect
.left
);
2185 ok( win_rect
.top
<= rgn_rect
.top
, "rgn top %d not inside win rect %d\n",
2186 rgn_rect
.top
, win_rect
.top
);
2187 ok( win_rect
.right
>= rgn_rect
.right
, "rgn right %d not inside win rect %d\n",
2188 rgn_rect
.right
, win_rect
.right
);
2189 ok( win_rect
.bottom
>= rgn_rect
.bottom
, "rgn bottom %d not inside win rect %d\n",
2190 rgn_rect
.bottom
, win_rect
.bottom
);
2191 ReleaseDC( hwnd
, hdc
);
2194 static void test_SetFocus(HWND hwnd
)
2198 /* check if we can set focus to non-visible windows */
2200 ShowWindow(hwnd
, SW_SHOW
);
2203 ok( GetFocus() == hwnd
, "Failed to set focus to visible window %p\n", hwnd
);
2204 ok( GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
, "Window %p not visible\n", hwnd
);
2205 ShowWindow(hwnd
, SW_HIDE
);
2208 ok( GetFocus() == hwnd
, "Failed to set focus to invisible window %p\n", hwnd
);
2209 ok( !(GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
), "Window %p still visible\n", hwnd
);
2210 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2213 ok( GetFocus() == child
, "Failed to set focus to invisible child %p\n", child
);
2214 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2215 ShowWindow(child
, SW_SHOW
);
2216 ok( GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
, "Child %p is not visible\n", child
);
2217 ok( GetFocus() == child
, "Focus no longer on child %p\n", child
);
2218 ShowWindow(child
, SW_HIDE
);
2219 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2220 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2221 ShowWindow(child
, SW_SHOW
);
2223 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2224 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_HIDEWINDOW
);
2225 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2227 ShowWindow(child
, SW_HIDE
);
2229 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2230 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_SHOWWINDOW
);
2231 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2232 ShowWindow(child
, SW_HIDE
);
2233 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2235 ShowWindow(hwnd
, SW_SHOW
);
2236 ShowWindow(child
, SW_SHOW
);
2238 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2239 EnableWindow(hwnd
, FALSE
);
2240 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2241 EnableWindow(hwnd
, TRUE
);
2243 DestroyWindow( child
);
2246 static void check_wnd_state(HWND active
, HWND foreground
, HWND focus
, HWND capture
)
2248 ok(active
== GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2250 ok(foreground
== GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2251 ok(focus
== GetFocus(), "GetFocus() = %p\n", GetFocus());
2252 ok(capture
== GetCapture(), "GetCapture() = %p\n", GetCapture());
2255 static void test_SetActiveWindow(HWND hwnd
)
2259 ShowWindow(hwnd
, SW_HIDE
);
2262 check_wnd_state(0, 0, 0, 0);
2264 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2266 ShowWindow(hwnd
, SW_SHOW
);
2267 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2269 hwnd2
= SetActiveWindow(0);
2270 ok(hwnd2
== hwnd
, "SetActiveWindow returned %p instead of %p\n", hwnd2
, hwnd
);
2271 check_wnd_state(0, 0, 0, 0);
2273 hwnd2
= SetActiveWindow(hwnd
);
2274 ok(hwnd2
== 0, "SetActiveWindow returned %p instead of 0\n", hwnd2
);
2275 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2277 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2278 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2280 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2281 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2283 ShowWindow(hwnd
, SW_HIDE
);
2284 check_wnd_state(0, 0, 0, 0);
2286 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2287 SetActiveWindow(hwnd
);
2288 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2290 ShowWindow(hwnd
, SW_SHOW
);
2291 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2293 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2294 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2296 DestroyWindow(hwnd2
);
2297 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2299 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2300 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2302 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2303 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2305 DestroyWindow(hwnd2
);
2306 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2309 static void test_SetForegroundWindow(HWND hwnd
)
2314 ShowWindow(hwnd
, SW_HIDE
);
2317 check_wnd_state(0, 0, 0, 0);
2319 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2321 ShowWindow(hwnd
, SW_SHOW
);
2322 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2324 hwnd2
= SetActiveWindow(0);
2325 ok(hwnd2
== hwnd
, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2
, hwnd
);
2326 check_wnd_state(0, 0, 0, 0);
2328 ret
= SetForegroundWindow(hwnd
);
2329 ok(ret
, "SetForegroundWindow returned FALSE instead of TRUE\n");
2330 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2332 SetLastError(0xdeadbeef);
2333 ret
= SetForegroundWindow(0);
2334 ok(!ret
, "SetForegroundWindow returned TRUE instead of FALSE\n");
2335 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2336 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2338 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2339 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2341 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2342 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2344 hwnd2
= GetForegroundWindow();
2345 ok(hwnd2
== hwnd
, "Wrong foreground window %p\n", hwnd2
);
2346 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2347 hwnd2
= GetForegroundWindow();
2348 ok(hwnd2
!= hwnd
, "Wrong foreground window %p\n", hwnd2
);
2350 ShowWindow(hwnd
, SW_HIDE
);
2351 check_wnd_state(0, 0, 0, 0);
2353 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2354 ret
= SetForegroundWindow(hwnd
);
2355 ok(ret
, "SetForegroundWindow returned FALSE instead of TRUE\n");
2356 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2358 ShowWindow(hwnd
, SW_SHOW
);
2359 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2361 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2362 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2364 DestroyWindow(hwnd2
);
2365 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2367 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2368 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2370 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2371 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2373 DestroyWindow(hwnd2
);
2374 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2377 static WNDPROC old_button_proc
;
2379 static LRESULT WINAPI
button_hook_proc(HWND button
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2384 key_state
= GetKeyState(VK_LBUTTON
);
2385 ok(!(key_state
& 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state
);
2387 ret
= CallWindowProcA(old_button_proc
, button
, msg
, wparam
, lparam
);
2389 if (msg
== WM_LBUTTONDOWN
)
2393 check_wnd_state(button
, button
, button
, button
);
2395 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2397 trace("hwnd %p\n", hwnd
);
2399 check_wnd_state(button
, button
, button
, button
);
2401 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2403 check_wnd_state(button
, button
, button
, button
);
2405 DestroyWindow(hwnd
);
2407 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2409 trace("hwnd %p\n", hwnd
);
2411 check_wnd_state(button
, button
, button
, button
);
2413 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2414 * match internal button state.
2416 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2417 check_wnd_state(button
, button
, button
, 0);
2419 ShowWindow(hwnd
, SW_SHOW
);
2420 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2422 capture
= SetCapture(hwnd
);
2423 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2425 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2427 DestroyWindow(hwnd
);
2429 check_wnd_state(button
, 0, button
, 0);
2435 static void test_capture_1(void)
2437 HWND button
, capture
;
2439 capture
= GetCapture();
2440 ok(capture
== 0, "GetCapture() = %p\n", capture
);
2442 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2444 trace("button %p\n", button
);
2446 old_button_proc
= (WNDPROC
)SetWindowLongPtrA(button
, GWLP_WNDPROC
, (LONG_PTR
)button_hook_proc
);
2448 SendMessageA(button
, WM_LBUTTONDOWN
, 0, 0);
2450 capture
= SetCapture(button
);
2451 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2452 check_wnd_state(button
, 0, button
, button
);
2454 DestroyWindow(button
);
2455 check_wnd_state(0, 0, 0, 0);
2458 static void test_capture_2(void)
2460 HWND button
, hwnd
, capture
;
2462 check_wnd_state(0, 0, 0, 0);
2464 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2466 trace("button %p\n", button
);
2468 check_wnd_state(button
, button
, button
, 0);
2470 capture
= SetCapture(button
);
2471 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2473 check_wnd_state(button
, button
, button
, button
);
2475 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2476 * internal button state.
2478 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2479 check_wnd_state(button
, button
, button
, button
);
2481 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2483 trace("hwnd %p\n", hwnd
);
2485 check_wnd_state(button
, button
, button
, button
);
2487 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2489 check_wnd_state(button
, button
, button
, button
);
2491 DestroyWindow(hwnd
);
2493 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2495 trace("hwnd %p\n", hwnd
);
2497 check_wnd_state(button
, button
, button
, button
);
2499 ShowWindow(hwnd
, SW_SHOW
);
2501 check_wnd_state(hwnd
, hwnd
, hwnd
, button
);
2503 capture
= SetCapture(hwnd
);
2504 ok(capture
== button
, "SetCapture() = %p\n", capture
);
2506 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2508 DestroyWindow(hwnd
);
2509 check_wnd_state(button
, button
, button
, 0);
2511 DestroyWindow(button
);
2512 check_wnd_state(0, 0, 0, 0);
2515 static void test_capture_3(HWND hwnd1
, HWND hwnd2
)
2519 ShowWindow(hwnd1
, SW_HIDE
);
2520 ShowWindow(hwnd2
, SW_HIDE
);
2522 ok(!IsWindowVisible(hwnd1
), "%p should be invisible\n", hwnd1
);
2523 ok(!IsWindowVisible(hwnd2
), "%p should be invisible\n", hwnd2
);
2526 check_wnd_state(0, 0, 0, hwnd1
);
2529 check_wnd_state(0, 0, 0, hwnd2
);
2531 ShowWindow(hwnd1
, SW_SHOW
);
2532 check_wnd_state(hwnd1
, hwnd1
, hwnd1
, hwnd2
);
2534 ret
= ReleaseCapture();
2535 ok (ret
, "releasecapture did not return TRUE.\n");
2536 ret
= ReleaseCapture();
2537 ok (ret
, "releasecapture did not return TRUE after second try.\n");
2540 static void test_keyboard_input(HWND hwnd
)
2545 ShowWindow(hwnd
, SW_SHOW
);
2549 ok(GetActiveWindow() == hwnd
, "wrong active window %p\n", GetActiveWindow());
2552 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2556 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2557 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2558 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2559 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2560 ok( !ret
, "message %04x available\n", msg
.message
);
2562 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2564 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2565 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2566 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2567 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2568 ok( !ret
, "message %04x available\n", msg
.message
);
2570 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2572 keybd_event(VK_SPACE
, 0, 0, 0);
2573 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2574 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2575 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2576 ok( !ret
, "message %04x available\n", msg
.message
);
2579 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2583 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2584 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2585 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2586 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2587 ok( !ret
, "message %04x available\n", msg
.message
);
2589 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2591 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2592 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2593 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2594 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2595 ok( !ret
, "message %04x available\n", msg
.message
);
2597 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2599 keybd_event(VK_SPACE
, 0, 0, 0);
2600 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2601 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_SYSKEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2602 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2603 ok( !ret
, "message %04x available\n", msg
.message
);
2606 static void test_mouse_input(HWND hwnd
)
2616 ShowWindow(hwnd
, SW_SHOW
);
2619 GetWindowRect(hwnd
, &rc
);
2620 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2622 popup
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_POPUP
,
2623 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
,
2626 ShowWindow(popup
, SW_SHOW
);
2627 UpdateWindow(popup
);
2629 GetWindowRect(popup
, &rc
);
2630 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2632 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
2633 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
2634 trace("setting cursor to (%d,%d)\n", x
, y
);
2638 ok(x
== pt
.x
&& y
== pt
.y
, "wrong cursor pos (%d,%d), expected (%d,%d)\n", pt
.x
, pt
.y
, x
, y
);
2642 /* Check that setting the same position will generate WM_MOUSEMOVE */
2645 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2646 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2647 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
);
2649 /* force the system to update its internal queue mouse position,
2650 * otherwise it won't generate relative mouse movements below.
2652 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2656 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2657 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2658 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2659 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2660 if (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
2661 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2662 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2663 ok( !ret
, "message %04x available\n", msg
.message
);
2665 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2666 ShowWindow(popup
, SW_HIDE
);
2667 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2668 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2671 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2672 ShowWindow(hwnd
, SW_HIDE
);
2673 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2674 ok( !ret
, "message %04x available\n", msg
.message
);
2677 /* test mouse clicks */
2679 ShowWindow(hwnd
, SW_SHOW
);
2681 ShowWindow(popup
, SW_SHOW
);
2684 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2685 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2686 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2687 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2689 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2690 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2691 msg
.hwnd
, popup
, msg
.message
);
2692 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2693 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2694 msg
.hwnd
, popup
, msg
.message
);
2696 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2697 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2698 msg
.hwnd
, popup
, msg
.message
);
2699 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2700 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2701 msg
.hwnd
, popup
, msg
.message
);
2703 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2704 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p/%p message %04x\n",
2705 msg
.hwnd
, popup
, msg
.message
);
2706 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2707 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p/%p message %04x\n",
2708 msg
.hwnd
, popup
, msg
.message
);
2710 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2711 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2712 msg
.hwnd
, popup
, msg
.message
);
2713 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2714 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2715 msg
.hwnd
, popup
, msg
.message
);
2717 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2718 ok(!ret
, "message %04x available\n", msg
.message
);
2720 ShowWindow(popup
, SW_HIDE
);
2723 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2724 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2725 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2726 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2728 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2729 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2730 msg
.hwnd
, hwnd
, msg
.message
);
2731 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2732 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2733 msg
.hwnd
, hwnd
, msg
.message
);
2735 test_lbuttondown_flag
= TRUE
;
2736 SendMessageA(hwnd
, WM_COMMAND
, (WPARAM
)popup
, 0);
2737 test_lbuttondown_flag
= FALSE
;
2739 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2740 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2741 msg
.hwnd
, popup
, msg
.message
);
2742 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2743 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2744 msg
.hwnd
, popup
, msg
.message
);
2745 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2747 /* Test WM_MOUSEACTIVATE */
2748 #define TEST_MOUSEACTIVATE(A,B) \
2749 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2750 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2752 TEST_MOUSEACTIVATE(HTERROR
,MA_ACTIVATE
);
2753 TEST_MOUSEACTIVATE(HTTRANSPARENT
,MA_ACTIVATE
);
2754 TEST_MOUSEACTIVATE(HTNOWHERE
,MA_ACTIVATE
);
2755 TEST_MOUSEACTIVATE(HTCLIENT
,MA_ACTIVATE
);
2756 TEST_MOUSEACTIVATE(HTCAPTION
,MA_ACTIVATE
);
2757 TEST_MOUSEACTIVATE(HTSYSMENU
,MA_ACTIVATE
);
2758 TEST_MOUSEACTIVATE(HTSIZE
,MA_ACTIVATE
);
2759 TEST_MOUSEACTIVATE(HTMENU
,MA_ACTIVATE
);
2760 TEST_MOUSEACTIVATE(HTHSCROLL
,MA_ACTIVATE
);
2761 TEST_MOUSEACTIVATE(HTVSCROLL
,MA_ACTIVATE
);
2762 TEST_MOUSEACTIVATE(HTMINBUTTON
,MA_ACTIVATE
);
2763 TEST_MOUSEACTIVATE(HTMAXBUTTON
,MA_ACTIVATE
);
2764 TEST_MOUSEACTIVATE(HTLEFT
,MA_ACTIVATE
);
2765 TEST_MOUSEACTIVATE(HTRIGHT
,MA_ACTIVATE
);
2766 TEST_MOUSEACTIVATE(HTTOP
,MA_ACTIVATE
);
2767 TEST_MOUSEACTIVATE(HTTOPLEFT
,MA_ACTIVATE
);
2768 TEST_MOUSEACTIVATE(HTTOPRIGHT
,MA_ACTIVATE
);
2769 TEST_MOUSEACTIVATE(HTBOTTOM
,MA_ACTIVATE
);
2770 TEST_MOUSEACTIVATE(HTBOTTOMLEFT
,MA_ACTIVATE
);
2771 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT
,MA_ACTIVATE
);
2772 TEST_MOUSEACTIVATE(HTBORDER
,MA_ACTIVATE
);
2773 TEST_MOUSEACTIVATE(HTOBJECT
,MA_ACTIVATE
);
2774 TEST_MOUSEACTIVATE(HTCLOSE
,MA_ACTIVATE
);
2775 TEST_MOUSEACTIVATE(HTHELP
,MA_ACTIVATE
);
2777 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2780 DestroyWindow(popup
);
2783 static void test_validatergn(HWND hwnd
)
2789 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_VISIBLE
, 10, 10, 10, 10, hwnd
, 0, 0, NULL
);
2790 ShowWindow(hwnd
, SW_SHOW
);
2791 UpdateWindow( hwnd
);
2792 /* test that ValidateRect validates children*/
2793 InvalidateRect( child
, NULL
, 1);
2794 GetWindowRect( child
, &rc
);
2795 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2796 ret
= GetUpdateRect( child
, &rc2
, 0);
2797 ok( rc2
.right
> rc2
.left
&& rc2
.bottom
> rc2
.top
,
2798 "Update rectangle is empty!\n");
2799 ValidateRect( hwnd
, &rc
);
2800 ret
= GetUpdateRect( child
, &rc2
, 0);
2801 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2802 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
2803 rc2
.right
, rc2
.bottom
);
2805 /* now test ValidateRgn */
2806 InvalidateRect( child
, NULL
, 1);
2807 GetWindowRect( child
, &rc
);
2808 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2809 rgn
= CreateRectRgnIndirect( &rc
);
2810 ValidateRgn( hwnd
, rgn
);
2811 ret
= GetUpdateRect( child
, &rc2
, 0);
2812 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2813 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
2814 rc2
.right
, rc2
.bottom
);
2817 DestroyWindow( child
);
2820 static void nccalchelper(HWND hwnd
, INT x
, INT y
, RECT
*prc
)
2822 MoveWindow( hwnd
, 0, 0, x
, y
, 0);
2823 GetWindowRect( hwnd
, prc
);
2824 trace("window rect is %d,%d - %d,%d\n",
2825 prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
2826 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)prc
);
2827 trace("nccalc rect is %d,%d - %d,%d\n",
2828 prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
2831 static void test_nccalcscroll(HWND parent
)
2834 INT sbheight
= GetSystemMetrics( SM_CYHSCROLL
);
2835 INT sbwidth
= GetSystemMetrics( SM_CXVSCROLL
);
2836 HWND hwnd
= CreateWindowExA(0, "static", NULL
,
2837 WS_CHILD
| WS_VISIBLE
| WS_VSCROLL
| WS_HSCROLL
,
2838 10, 10, 200, 200, parent
, 0, 0, NULL
);
2839 ShowWindow( parent
, SW_SHOW
);
2840 UpdateWindow( parent
);
2842 /* test window too low for a horizontal scroll bar */
2843 nccalchelper( hwnd
, 100, sbheight
, &rc1
);
2844 ok( rc1
.bottom
- rc1
.top
== sbheight
, "Height should be %d size is %d,%d - %d,%d\n",
2845 sbheight
, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2847 /* test window just high enough for a horizontal scroll bar */
2848 nccalchelper( hwnd
, 100, sbheight
+ 1, &rc1
);
2849 ok( rc1
.bottom
- rc1
.top
== 1, "Height should be %d size is %d,%d - %d,%d\n",
2850 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2852 /* test window too narrow for a vertical scroll bar */
2853 nccalchelper( hwnd
, sbwidth
- 1, 100, &rc1
);
2854 ok( rc1
.right
- rc1
.left
== sbwidth
- 1 , "Width should be %d size is %d,%d - %d,%d\n",
2855 sbwidth
- 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2857 /* test window just wide enough for a vertical scroll bar */
2858 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
2859 ok( rc1
.right
- rc1
.left
== 0, "Width should be %d size is %d,%d - %d,%d\n",
2860 0, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2862 /* same test, but with client edge: not enough width */
2863 SetWindowLong( hwnd
, GWL_EXSTYLE
, WS_EX_CLIENTEDGE
| GetWindowLong( hwnd
, GWL_EXSTYLE
));
2864 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
2865 ok( rc1
.right
- rc1
.left
== sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
),
2866 "Width should be %d size is %d,%d - %d,%d\n",
2867 sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
), rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2869 DestroyWindow( hwnd
);
2872 static void test_SetParent(void)
2875 HWND desktop
= GetDesktopWindow();
2877 BOOL is_win9x
= GetWindowLongPtrW(desktop
, GWLP_WNDPROC
) == 0;
2878 HWND parent
, child1
, child2
, child3
, child4
, sibling
;
2880 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
2881 100, 100, 200, 200, 0, 0, 0, NULL
);
2882 assert(parent
!= 0);
2883 child1
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
2884 0, 0, 50, 50, parent
, 0, 0, NULL
);
2885 assert(child1
!= 0);
2886 child2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
2887 0, 0, 50, 50, child1
, 0, 0, NULL
);
2888 assert(child2
!= 0);
2889 child3
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
2890 0, 0, 50, 50, child2
, 0, 0, NULL
);
2891 assert(child3
!= 0);
2892 child4
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
2893 0, 0, 50, 50, child3
, 0, 0, NULL
);
2894 assert(child4
!= 0);
2896 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2897 parent
, child1
, child2
, child3
, child4
);
2899 check_parents(parent
, desktop
, 0, 0, 0, parent
, parent
);
2900 check_parents(child1
, parent
, parent
, parent
, 0, parent
, parent
);
2901 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
2902 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
2903 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
2905 ok(!IsChild(desktop
, parent
), "wrong parent/child %p/%p\n", desktop
, parent
);
2906 ok(!IsChild(desktop
, child1
), "wrong parent/child %p/%p\n", desktop
, child1
);
2907 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
2908 ok(!IsChild(desktop
, child3
), "wrong parent/child %p/%p\n", desktop
, child3
);
2909 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
2911 ok(IsChild(parent
, child1
), "wrong parent/child %p/%p\n", parent
, child1
);
2912 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
2913 ok(!IsChild(parent
, child2
), "wrong parent/child %p/%p\n", parent
, child2
);
2914 ok(!IsChild(child1
, child2
), "wrong parent/child %p/%p\n", child1
, child2
);
2915 ok(!IsChild(parent
, child3
), "wrong parent/child %p/%p\n", parent
, child3
);
2916 ok(IsChild(child2
, child3
), "wrong parent/child %p/%p\n", child2
, child3
);
2917 ok(!IsChild(parent
, child4
), "wrong parent/child %p/%p\n", parent
, child4
);
2918 ok(!IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
2919 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
2921 if (!is_win9x
) /* Win9x doesn't survive this test */
2923 ok(!SetParent(parent
, child1
), "SetParent should fail\n");
2924 ok(!SetParent(child2
, child3
), "SetParent should fail\n");
2925 ok(SetParent(child1
, parent
) != 0, "SetParent should not fail\n");
2926 ok(SetParent(parent
, child2
) != 0, "SetParent should not fail\n");
2927 ok(SetParent(parent
, child3
) != 0, "SetParent should not fail\n");
2928 ok(!SetParent(child2
, parent
), "SetParent should fail\n");
2929 ok(SetParent(parent
, child4
) != 0, "SetParent should not fail\n");
2931 check_parents(parent
, child4
, child4
, 0, 0, child4
, parent
);
2932 check_parents(child1
, parent
, parent
, parent
, 0, child4
, parent
);
2933 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
2934 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
2935 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
2938 hMenu
= CreateMenu();
2939 sibling
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
2940 100, 100, 200, 200, 0, hMenu
, 0, NULL
);
2941 assert(sibling
!= 0);
2943 ok(SetParent(sibling
, parent
) != 0, "SetParent should not fail\n");
2944 ok(GetMenu(sibling
) == hMenu
, "SetParent should not remove menu\n");
2946 ret
= DestroyWindow(parent
);
2947 ok( ret
, "DestroyWindow() error %d\n", GetLastError());
2949 ok(!IsWindow(parent
), "parent still exists\n");
2950 ok(!IsWindow(sibling
), "sibling still exists\n");
2951 ok(!IsWindow(child1
), "child1 still exists\n");
2952 ok(!IsWindow(child2
), "child2 still exists\n");
2953 ok(!IsWindow(child3
), "child3 still exists\n");
2954 ok(!IsWindow(child4
), "child4 still exists\n");
2957 static LRESULT WINAPI
StyleCheckProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2959 LPCREATESTRUCT lpcs
;
2966 lpcs
= (LPCREATESTRUCT
)lparam
;
2967 lpss
= (LPSTYLESTRUCT
)lpcs
->lpCreateParams
;
2970 if ((lpcs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
2971 ((!(lpcs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
2972 (lpcs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
2973 ok(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
, "Window should have WS_EX_WINDOWEDGE style\n");
2975 ok(!(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
2977 ok((lpss
->styleOld
& ~WS_EX_WINDOWEDGE
) == (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
),
2978 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2979 (lpss
->styleOld
& ~WS_EX_WINDOWEDGE
), (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
));
2981 ok(lpss
->styleNew
== lpcs
->style
,
2982 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
2983 lpss
->styleNew
, lpcs
->style
);
2987 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
2990 static ATOM atomStyleCheckClass
;
2992 static void register_style_check_class(void)
3000 GetModuleHandle(NULL
),
3002 LoadCursor(NULL
, IDC_ARROW
),
3003 (HBRUSH
)(COLOR_BTNFACE
+1),
3005 TEXT("WineStyleCheck"),
3008 atomStyleCheckClass
= RegisterClass(&wc
);
3011 static void check_window_style(DWORD dwStyleIn
, DWORD dwExStyleIn
, DWORD dwStyleOut
, DWORD dwExStyleOut
)
3013 DWORD dwActualStyle
;
3014 DWORD dwActualExStyle
;
3017 HWND hwndParent
= NULL
;
3019 ss
.styleNew
= dwStyleIn
;
3020 ss
.styleOld
= dwExStyleIn
;
3022 if (dwStyleIn
& WS_CHILD
)
3024 hwndParent
= CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3025 WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
3028 hwnd
= CreateWindowEx(dwExStyleIn
, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3029 dwStyleIn
, 0, 0, 0, 0, hwndParent
, NULL
, NULL
, &ss
);
3034 dwActualStyle
= GetWindowLong(hwnd
, GWL_STYLE
);
3035 dwActualExStyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
3036 ok((dwActualStyle
== dwStyleOut
) && (dwActualExStyle
== dwExStyleOut
),
3037 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3038 dwActualStyle
, dwStyleOut
, dwActualExStyle
, dwExStyleOut
);
3040 DestroyWindow(hwnd
);
3041 if (hwndParent
) DestroyWindow(hwndParent
);
3044 /* tests what window styles the window manager automatically adds */
3045 static void test_window_styles(void)
3047 register_style_check_class();
3049 check_window_style(0, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
3050 check_window_style(WS_OVERLAPPEDWINDOW
, 0, WS_CLIPSIBLINGS
|WS_OVERLAPPEDWINDOW
, WS_EX_WINDOWEDGE
);
3051 check_window_style(WS_CHILD
, 0, WS_CHILD
, 0);
3052 check_window_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
3053 check_window_style(0, WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_TOOLWINDOW
);
3054 check_window_style(WS_POPUP
, 0, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3055 check_window_style(WS_POPUP
, WS_EX_WINDOWEDGE
, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3056 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
, WS_CHILD
, WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3057 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
|WS_EX_STATICEDGE
, WS_CHILD
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3058 check_window_style(WS_CAPTION
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
);
3059 check_window_style(0, WS_EX_APPWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_APPWINDOW
|WS_EX_WINDOWEDGE
);
3062 static void test_scrollvalidate( HWND parent
)
3065 HRGN hrgn
=CreateRectRgn(0,0,0,0);
3066 HRGN exprgn
, tmprgn
, clipping
;
3067 RECT rc
, rcu
, cliprc
;
3068 /* create two overlapping child windows. The visual region
3069 * of hwnd1 is clipped by the overlapping part of
3070 * hwnd2 because of the WS_CLIPSIBLING style */
3073 clipping
= CreateRectRgn(0,0,0,0);
3074 tmprgn
= CreateRectRgn(0,0,0,0);
3075 exprgn
= CreateRectRgn(0,0,0,0);
3076 hwnd2
= CreateWindowExA(0, "static", NULL
,
3077 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3078 75, 30, 100, 100, parent
, 0, 0, NULL
);
3079 hwnd1
= CreateWindowExA(0, "static", NULL
,
3080 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3081 25, 50, 100, 100, parent
, 0, 0, NULL
);
3082 ShowWindow( parent
, SW_SHOW
);
3083 UpdateWindow( parent
);
3084 GetClientRect( hwnd1
, &rc
);
3086 SetRectRgn( clipping
, 10, 10, 90, 90);
3087 hdc
= GetDC( hwnd1
);
3088 /* for a visual touch */
3089 TextOut( hdc
, 0,10, "0123456789", 10);
3090 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3091 if (winetest_debug
> 0) dump_region(hrgn
);
3092 /* create a region with what is expected */
3093 SetRectRgn( exprgn
, 39,0,49,74);
3094 SetRectRgn( tmprgn
, 88,79,98,93);
3095 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3096 SetRectRgn( tmprgn
, 0,93,98,98);
3097 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3098 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3099 trace("update rect is %d,%d - %d,%d\n",
3100 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3101 /* now with clipping region */
3102 SelectClipRgn( hdc
, clipping
);
3103 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3104 if (winetest_debug
> 0) dump_region(hrgn
);
3105 /* create a region with what is expected */
3106 SetRectRgn( exprgn
, 39,10,49,74);
3107 SetRectRgn( tmprgn
, 80,79,90,85);
3108 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3109 SetRectRgn( tmprgn
, 10,85,90,90);
3110 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3111 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3112 trace("update rect is %d,%d - %d,%d\n",
3113 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3114 ReleaseDC( hwnd1
, hdc
);
3116 /* test scrolling a window with an update region */
3117 DestroyWindow( hwnd2
);
3118 ValidateRect( hwnd1
, NULL
);
3119 SetRect( &rc
, 40,40, 50,50);
3120 InvalidateRect( hwnd1
, &rc
, 1);
3121 GetClientRect( hwnd1
, &rc
);
3123 ScrollWindowEx( hwnd1
, -10, 0, &rc
, &cliprc
, hrgn
, &rcu
,
3124 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3125 if (winetest_debug
> 0) dump_region(hrgn
);
3126 SetRectRgn( exprgn
, 88,0,98,98);
3127 SetRectRgn( tmprgn
, 30, 40, 50, 50);
3128 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3129 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3131 /* clear an update region */
3132 UpdateWindow( hwnd1
);
3134 SetRect( &rc
, 0,40, 100,60);
3135 SetRect( &cliprc
, 0,0, 100,100);
3136 ScrollWindowEx( hwnd1
, 0, -25, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3137 if (winetest_debug
> 0) dump_region( hrgn
);
3138 SetRectRgn( exprgn
, 0, 40, 98, 60 );
3139 ok( EqualRgn( exprgn
, hrgn
), "wrong update region in excessive scroll\n");
3141 /* now test ScrollWindowEx with a combination of
3142 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3143 /* make hwnd2 the child of hwnd1 */
3144 hwnd2
= CreateWindowExA(0, "static", NULL
,
3145 WS_CHILD
| WS_VISIBLE
| WS_BORDER
,
3146 50, 50, 100, 100, hwnd1
, 0, 0, NULL
);
3147 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPSIBLINGS
);
3148 GetClientRect( hwnd1
, &rc
);
3151 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3152 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3153 ValidateRect( hwnd1
, NULL
);
3154 ValidateRect( hwnd2
, NULL
);
3155 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
,
3156 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3157 if (winetest_debug
> 0) dump_region(hrgn
);
3158 SetRectRgn( exprgn
, 88,0,98,88);
3159 SetRectRgn( tmprgn
, 0,88,98,98);
3160 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3161 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3163 /* SW_SCROLLCHILDREN */
3164 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3165 ValidateRect( hwnd1
, NULL
);
3166 ValidateRect( hwnd2
, NULL
);
3167 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3168 if (winetest_debug
> 0) dump_region(hrgn
);
3169 /* expected region is the same as in previous test */
3170 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3172 /* no SW_SCROLLCHILDREN */
3173 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3174 ValidateRect( hwnd1
, NULL
);
3175 ValidateRect( hwnd2
, NULL
);
3176 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3177 if (winetest_debug
> 0) dump_region(hrgn
);
3178 /* expected region is the same as in previous test */
3179 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3181 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3182 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3183 ValidateRect( hwnd1
, NULL
);
3184 ValidateRect( hwnd2
, NULL
);
3185 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3186 if (winetest_debug
> 0) dump_region(hrgn
);
3187 SetRectRgn( exprgn
, 88,0,98,20);
3188 SetRectRgn( tmprgn
, 20,20,98,30);
3189 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3190 SetRectRgn( tmprgn
, 20,30,30,88);
3191 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3192 SetRectRgn( tmprgn
, 0,88,30,98);
3193 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3194 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3197 DeleteObject( hrgn
);
3198 DeleteObject( exprgn
);
3199 DeleteObject( tmprgn
);
3200 DestroyWindow( hwnd1
);
3201 DestroyWindow( hwnd2
);
3204 /* couple of tests of return values of scrollbar functions
3205 * called on a scrollbarless window */
3206 static void test_scroll(void)
3211 HWND hwnd
= CreateWindowExA(0, "Static", "Wine test window",
3212 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_POPUP
,
3213 100, 100, 200, 200, 0, 0, 0, NULL
);
3215 ret
= GetScrollRange( hwnd
, SB_HORZ
, &min
, &max
);
3216 ok( ret
, "GetScrollRange returns FALSE\n");
3217 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3218 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3219 si
.cbSize
= sizeof( si
);
3220 si
.fMask
= SIF_PAGE
;
3221 si
.nPage
= 0xdeadbeef;
3222 ret
= GetScrollInfo( hwnd
, SB_HORZ
, &si
);
3223 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3224 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3226 ret
= GetScrollRange( hwnd
, SB_VERT
, &min
, &max
);
3227 ok( ret
, "GetScrollRange returns FALSE\n");
3228 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3229 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3230 si
.cbSize
= sizeof( si
);
3231 si
.fMask
= SIF_PAGE
;
3232 si
.nPage
= 0xdeadbeef;
3233 ret
= GetScrollInfo( hwnd
, SB_VERT
, &si
);
3234 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3235 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3237 DestroyWindow( hwnd
);
3240 static void test_scrolldc( HWND parent
)
3243 HRGN exprgn
, tmprgn
, hrgn
;
3244 RECT rc
, rc2
, rcu
, cliprc
;
3248 hrgn
= CreateRectRgn(0,0,0,0);
3249 tmprgn
= CreateRectRgn(0,0,0,0);
3250 exprgn
= CreateRectRgn(0,0,0,0);
3252 hwnd1
= CreateWindowExA(0, "static", NULL
,
3253 WS_CHILD
| WS_VISIBLE
,
3254 25, 50, 100, 100, parent
, 0, 0, NULL
);
3255 ShowWindow( parent
, SW_SHOW
);
3256 UpdateWindow( parent
);
3258 GetClientRect( hwnd1
, &rc
);
3259 hdc
= GetDC( hwnd1
);
3260 /* paint the upper half of the window black */
3262 rc2
.bottom
= ( rc
.top
+ rc
.bottom
) /2;
3263 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3264 /* clip region is the lower half */
3266 cliprc
.top
= (rc
.top
+ rc
.bottom
) /2;
3267 /* test whether scrolled pixels are properly clipped */
3268 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3269 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3270 /* this scroll should not cause any visible changes */
3271 ScrollDC( hdc
, 5, -20, &rc
, &cliprc
, hrgn
, &rcu
);
3272 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3273 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3274 /* test with NULL clip rect */
3275 ScrollDC( hdc
, 20, -20, &rc
, NULL
, hrgn
, &rcu
);
3276 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3277 trace("update rect: %d,%d - %d,%d\n",
3278 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3279 if (winetest_debug
> 0) dump_region(hrgn
);
3280 SetRect(&rc2
, 0, 0, 100, 100);
3281 ok(EqualRect(&rcu
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3282 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
3284 SetRectRgn( exprgn
, 0, 0, 20, 80);
3285 SetRectRgn( tmprgn
, 0, 80, 100, 100);
3286 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3287 if (winetest_debug
> 0) dump_region(exprgn
);
3288 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3289 /* test clip rect > scroll rect */
3290 FillRect( hdc
, &rc
, GetStockObject(WHITE_BRUSH
));
3292 InflateRect( &rc2
, -(rc
.right
-rc
.left
)/4, -(rc
.bottom
-rc
.top
)/4);
3293 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3294 ScrollDC( hdc
, 10, 10, &rc2
, &rc
, hrgn
, &rcu
);
3295 SetRectRgn( exprgn
, 25, 25, 75, 35);
3296 SetRectRgn( tmprgn
, 25, 35, 35, 75);
3297 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3298 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3299 colr
= GetPixel( hdc
, 80, 80);
3300 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3301 trace("update rect: %d,%d - %d,%d\n",
3302 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3303 if (winetest_debug
> 0) dump_region(hrgn
);
3307 DeleteObject(exprgn
);
3308 DeleteObject(tmprgn
);
3309 DestroyWindow(hwnd1
);
3312 static void test_params(void)
3317 /* Just a param check */
3318 SetLastError(0xdeadbeef);
3319 rc
= GetWindowText(hwndMain2
, NULL
, 1024);
3320 ok( rc
==0, "GetWindowText: rc=%d err=%d\n",rc
,GetLastError());
3322 SetLastError(0xdeadbeef);
3323 hwnd
=CreateWindow("LISTBOX", "TestList",
3324 (LBS_STANDARD
& ~LBS_SORT
),
3326 NULL
, (HMENU
)1, NULL
, 0);
3328 ok(!hwnd
, "CreateWindow with invalid menu handle should fail\n");
3329 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
|| /* NT */
3330 GetLastError() == 0xdeadbeef, /* Win9x */
3331 "wrong last error value %d\n", GetLastError());
3334 static void test_AWRwindow(LPCSTR
class, LONG style
, LONG exStyle
, BOOL menu
)
3338 hwnd
= CreateWindowEx(exStyle
, class, class, style
,
3345 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style
, exStyle
);
3348 ShowWindow(hwnd
, SW_SHOW
);
3350 test_nonclient_area(hwnd
);
3353 DestroyWindow(hwnd
);
3356 static BOOL
AWR_init(void)
3360 class.style
= CS_HREDRAW
| CS_VREDRAW
;
3361 class.lpfnWndProc
= DefWindowProcA
;
3362 class.cbClsExtra
= 0;
3363 class.cbWndExtra
= 0;
3364 class.hInstance
= 0;
3365 class.hIcon
= LoadIcon (0, IDI_APPLICATION
);
3366 class.hCursor
= LoadCursor (0, IDC_ARROW
);
3367 class.hbrBackground
= 0;
3368 class.lpszMenuName
= 0;
3369 class.lpszClassName
= szAWRClass
;
3371 if (!RegisterClass (&class)) {
3372 ok(FALSE
, "RegisterClass failed\n");
3376 hmenu
= CreateMenu();
3379 ok(hmenu
!= 0, "Failed to create menu\n");
3380 ok(AppendMenu(hmenu
, MF_STRING
, 1, "Test!"), "Failed to create menu item\n");
3386 static void test_AWR_window_size(BOOL menu
)
3390 WS_MAXIMIZE
, WS_BORDER
, WS_DLGFRAME
,
3393 WS_MINIMIZEBOX
, WS_MAXIMIZEBOX
,
3394 WS_HSCROLL
, WS_VSCROLL
3398 WS_EX_TOOLWINDOW
, WS_EX_WINDOWEDGE
,
3401 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3402 WS_EX_DLGMODALFRAME
,
3409 /* A exhaustive check of all the styles takes too long
3410 * so just do a (hopefully representative) sample
3412 for (i
= 0; i
< COUNTOF(styles
); ++i
)
3413 test_AWRwindow(szAWRClass
, styles
[i
], 0, menu
);
3414 for (i
= 0; i
< COUNTOF(exStyles
); ++i
) {
3415 test_AWRwindow(szAWRClass
, WS_POPUP
, exStyles
[i
], menu
);
3416 test_AWRwindow(szAWRClass
, WS_THICKFRAME
, exStyles
[i
], menu
);
3421 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3423 static void test_AdjustWindowRect(void)
3428 SHOWSYSMETRIC(SM_CYCAPTION
);
3429 SHOWSYSMETRIC(SM_CYSMCAPTION
);
3430 SHOWSYSMETRIC(SM_CYMENU
);
3431 SHOWSYSMETRIC(SM_CXEDGE
);
3432 SHOWSYSMETRIC(SM_CYEDGE
);
3433 SHOWSYSMETRIC(SM_CXVSCROLL
);
3434 SHOWSYSMETRIC(SM_CYHSCROLL
);
3435 SHOWSYSMETRIC(SM_CXFRAME
);
3436 SHOWSYSMETRIC(SM_CYFRAME
);
3437 SHOWSYSMETRIC(SM_CXDLGFRAME
);
3438 SHOWSYSMETRIC(SM_CYDLGFRAME
);
3439 SHOWSYSMETRIC(SM_CXBORDER
);
3440 SHOWSYSMETRIC(SM_CYBORDER
);
3442 test_AWR_window_size(FALSE
);
3443 test_AWR_window_size(TRUE
);
3447 #undef SHOWSYSMETRIC
3450 /* Global variables to trigger exit from loop */
3451 static int redrawComplete
, WMPAINT_count
;
3453 static LRESULT WINAPI
redraw_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3458 trace("doing WM_PAINT %d\n", WMPAINT_count
);
3460 if (WMPAINT_count
> 10 && redrawComplete
== 0) {
3462 BeginPaint(hwnd
, &ps
);
3463 EndPaint(hwnd
, &ps
);
3468 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3471 /* Ensure we exit from RedrawNow regardless of invalidated area */
3472 static void test_redrawnow(void)
3477 cls
.style
= CS_DBLCLKS
;
3478 cls
.lpfnWndProc
= redraw_window_procA
;
3481 cls
.hInstance
= GetModuleHandleA(0);
3483 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3484 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3485 cls
.lpszMenuName
= NULL
;
3486 cls
.lpszClassName
= "RedrawWindowClass";
3488 if(!RegisterClassA(&cls
)) {
3489 trace("Register failed %d\n", GetLastError());
3493 hwndMain
= CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3494 CW_USEDEFAULT
, 0, 100, 100, NULL
, NULL
, 0, NULL
);
3496 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3497 ShowWindow(hwndMain
, SW_SHOW
);
3498 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3499 RedrawWindow(hwndMain
, NULL
,NULL
,RDW_UPDATENOW
| RDW_ALLCHILDREN
);
3500 ok( WMPAINT_count
== 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3501 redrawComplete
= TRUE
;
3502 ok( WMPAINT_count
< 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count
);
3505 DestroyWindow( hwndMain
);
3508 struct parentdc_stat
{
3514 struct parentdc_test
{
3515 struct parentdc_stat main
, main_todo
;
3516 struct parentdc_stat child1
, child1_todo
;
3517 struct parentdc_stat child2
, child2_todo
;
3520 static LRESULT WINAPI
parentdc_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3525 struct parentdc_stat
*t
= (struct parentdc_stat
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
3530 trace("doing WM_PAINT on %p\n", hwnd
);
3531 GetClientRect(hwnd
, &rc
);
3532 CopyRect(&t
->client
, &rc
);
3533 trace("client rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3534 GetWindowRect(hwnd
, &rc
);
3535 trace("window rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3536 BeginPaint(hwnd
, &ps
);
3537 CopyRect(&t
->paint
, &ps
.rcPaint
);
3538 GetClipBox(ps
.hdc
, &rc
);
3539 CopyRect(&t
->clip
, &rc
);
3540 trace("clip rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3541 trace("paint rect (%d, %d)-(%d, %d)\n", ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
3542 EndPaint(hwnd
, &ps
);
3545 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3548 static void zero_parentdc_stat(struct parentdc_stat
*t
)
3550 SetRectEmpty(&t
->client
);
3551 SetRectEmpty(&t
->clip
);
3552 SetRectEmpty(&t
->paint
);
3555 static void zero_parentdc_test(struct parentdc_test
*t
)
3557 zero_parentdc_stat(&t
->main
);
3558 zero_parentdc_stat(&t
->child1
);
3559 zero_parentdc_stat(&t
->child2
);
3562 #define parentdc_field_ok(t, w, r, f, got) \
3563 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3564 ": expected %d, got %d\n", \
3567 #define parentdc_todo_field_ok(t, w, r, f, got) \
3568 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3569 else parentdc_field_ok(t, w, r, f, got)
3571 #define parentdc_rect_ok(t, w, r, got) \
3572 parentdc_todo_field_ok(t, w, r, left, got); \
3573 parentdc_todo_field_ok(t, w, r, top, got); \
3574 parentdc_todo_field_ok(t, w, r, right, got); \
3575 parentdc_todo_field_ok(t, w, r, bottom, got);
3577 #define parentdc_win_ok(t, w, got) \
3578 parentdc_rect_ok(t, w, client, got); \
3579 parentdc_rect_ok(t, w, clip, got); \
3580 parentdc_rect_ok(t, w, paint, got);
3582 #define parentdc_ok(t, got) \
3583 parentdc_win_ok(t, main, got); \
3584 parentdc_win_ok(t, child1, got); \
3585 parentdc_win_ok(t, child2, got);
3587 static void test_csparentdc(void)
3589 WNDCLASSA clsMain
, cls
;
3590 HWND hwndMain
, hwnd1
, hwnd2
;
3593 struct parentdc_test test_answer
;
3595 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3596 const struct parentdc_test test1
=
3598 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo
,
3599 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3600 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3603 const struct parentdc_test test2
=
3605 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo
,
3606 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3607 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3610 const struct parentdc_test test3
=
3612 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3613 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3614 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3617 const struct parentdc_test test4
=
3619 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo
,
3620 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo
,
3621 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3624 const struct parentdc_test test5
=
3626 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo
,
3627 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3628 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3631 const struct parentdc_test test6
=
3633 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3634 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3635 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3638 const struct parentdc_test test7
=
3640 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3641 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3642 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3646 clsMain
.style
= CS_DBLCLKS
;
3647 clsMain
.lpfnWndProc
= parentdc_window_procA
;
3648 clsMain
.cbClsExtra
= 0;
3649 clsMain
.cbWndExtra
= 0;
3650 clsMain
.hInstance
= GetModuleHandleA(0);
3652 clsMain
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3653 clsMain
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3654 clsMain
.lpszMenuName
= NULL
;
3655 clsMain
.lpszClassName
= "ParentDcMainWindowClass";
3657 if(!RegisterClassA(&clsMain
)) {
3658 trace("Register failed %d\n", GetLastError());
3662 cls
.style
= CS_DBLCLKS
| CS_PARENTDC
;
3663 cls
.lpfnWndProc
= parentdc_window_procA
;
3666 cls
.hInstance
= GetModuleHandleA(0);
3668 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3669 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3670 cls
.lpszMenuName
= NULL
;
3671 cls
.lpszClassName
= "ParentDcWindowClass";
3673 if(!RegisterClassA(&cls
)) {
3674 trace("Register failed %d\n", GetLastError());
3678 SetRect(&rc
, 0, 0, 150, 150);
3679 AdjustWindowRectEx(&rc
, WS_OVERLAPPEDWINDOW
, FALSE
, 0);
3680 hwndMain
= CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3681 CW_USEDEFAULT
, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, NULL
, NULL
, 0, NULL
);
3682 SetWindowLongPtrA(hwndMain
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.main
);
3683 hwnd1
= CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD
,
3684 20, 20, 40, 40, hwndMain
, NULL
, 0, NULL
);
3685 SetWindowLongPtrA(hwnd1
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child1
);
3686 hwnd2
= CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD
,
3687 40, 40, 40, 40, hwndMain
, NULL
, 0, NULL
);
3688 SetWindowLongPtrA(hwnd2
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child2
);
3689 ShowWindow(hwndMain
, SW_SHOW
);
3690 ShowWindow(hwnd1
, SW_SHOW
);
3691 ShowWindow(hwnd2
, SW_SHOW
);
3694 zero_parentdc_test(&test_answer
);
3695 InvalidateRect(hwndMain
, NULL
, TRUE
);
3697 parentdc_ok(test1
, test_answer
);
3699 zero_parentdc_test(&test_answer
);
3700 SetRect(&rc
, 0, 0, 50, 50);
3701 InvalidateRect(hwndMain
, &rc
, TRUE
);
3703 parentdc_ok(test2
, test_answer
);
3705 zero_parentdc_test(&test_answer
);
3706 SetRect(&rc
, 0, 0, 10, 10);
3707 InvalidateRect(hwndMain
, &rc
, TRUE
);
3709 parentdc_ok(test3
, test_answer
);
3711 zero_parentdc_test(&test_answer
);
3712 SetRect(&rc
, 40, 40, 50, 50);
3713 InvalidateRect(hwndMain
, &rc
, TRUE
);
3715 parentdc_ok(test4
, test_answer
);
3717 zero_parentdc_test(&test_answer
);
3718 SetRect(&rc
, 20, 20, 60, 60);
3719 InvalidateRect(hwndMain
, &rc
, TRUE
);
3721 parentdc_ok(test5
, test_answer
);
3723 zero_parentdc_test(&test_answer
);
3724 SetRect(&rc
, 0, 0, 10, 10);
3725 InvalidateRect(hwnd1
, &rc
, TRUE
);
3727 parentdc_ok(test6
, test_answer
);
3729 zero_parentdc_test(&test_answer
);
3730 SetRect(&rc
, -5, -5, 65, 65);
3731 InvalidateRect(hwnd1
, &rc
, TRUE
);
3733 parentdc_ok(test7
, test_answer
);
3735 DestroyWindow(hwndMain
);
3736 DestroyWindow(hwnd1
);
3737 DestroyWindow(hwnd2
);
3740 static LRESULT WINAPI
def_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3742 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
3745 static LRESULT WINAPI
def_window_procW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3747 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
3750 static void test_IsWindowUnicode(void)
3752 static const char ansi_class_nameA
[] = "ansi class name";
3753 static const WCHAR ansi_class_nameW
[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3754 static const char unicode_class_nameA
[] = "unicode class name";
3755 static const WCHAR unicode_class_nameW
[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3760 memset(&classW
, 0, sizeof(classW
));
3761 classW
.hInstance
= GetModuleHandleA(0);
3762 classW
.lpfnWndProc
= def_window_procW
;
3763 classW
.lpszClassName
= unicode_class_nameW
;
3764 if (!RegisterClassW(&classW
)) return; /* this catches Win9x as well */
3766 memset(&classA
, 0, sizeof(classA
));
3767 classA
.hInstance
= GetModuleHandleA(0);
3768 classA
.lpfnWndProc
= def_window_procA
;
3769 classA
.lpszClassName
= ansi_class_nameA
;
3770 assert(RegisterClassA(&classA
));
3772 /* unicode class: window proc */
3773 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
3774 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3777 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3778 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3779 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3780 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3781 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3783 DestroyWindow(hwnd
);
3785 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
3786 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3789 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3790 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3791 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3792 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3793 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3795 DestroyWindow(hwnd
);
3797 /* ansi class: window proc */
3798 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
3799 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3802 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3803 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3804 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3805 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3806 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3808 DestroyWindow(hwnd
);
3810 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
3811 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3814 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3815 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3816 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3817 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3818 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3820 DestroyWindow(hwnd
);
3822 /* unicode class: class proc */
3823 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
3824 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3827 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3828 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3829 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3830 /* do not restore class window proc back to unicode */
3832 DestroyWindow(hwnd
);
3834 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
3835 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3838 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3839 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3840 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3842 DestroyWindow(hwnd
);
3844 /* ansi class: class proc */
3845 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
3846 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3849 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3850 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3851 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3852 /* do not restore class window proc back to ansi */
3854 DestroyWindow(hwnd
);
3856 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
3857 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3860 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3861 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3862 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3864 DestroyWindow(hwnd
);
3867 static LRESULT CALLBACK
minmax_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
3871 if (msg
!= WM_GETMINMAXINFO
)
3872 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3874 minmax
= (MINMAXINFO
*)lp
;
3876 if ((GetWindowLong(hwnd
, GWL_STYLE
) & WS_CHILD
))
3878 minmax
->ptReserved
.x
= 0;
3879 minmax
->ptReserved
.y
= 0;
3880 minmax
->ptMaxSize
.x
= 400;
3881 minmax
->ptMaxSize
.y
= 400;
3882 minmax
->ptMaxPosition
.x
= 300;
3883 minmax
->ptMaxPosition
.y
= 300;
3884 minmax
->ptMaxTrackSize
.x
= 200;
3885 minmax
->ptMaxTrackSize
.y
= 200;
3886 minmax
->ptMinTrackSize
.x
= 100;
3887 minmax
->ptMinTrackSize
.y
= 100;
3890 DefWindowProc(hwnd
, msg
, wp
, lp
);
3894 static int expected_cx
, expected_cy
;
3895 static RECT expected_rect
;
3897 static LRESULT CALLBACK
winsizes_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
3901 case WM_GETMINMAXINFO
:
3904 GetWindowRect( hwnd
, &rect
);
3905 ok( !rect
.left
&& !rect
.top
&& !rect
.right
&& !rect
.bottom
,
3906 "wrong rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3907 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3912 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
3914 GetWindowRect( hwnd
, &rect
);
3915 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
3916 hwnd
, msg
, cs
->cx
, cs
->cy
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3917 ok( cs
->cx
== expected_cx
, "wrong x size %d/%d\n", cs
->cx
, expected_cx
);
3918 ok( cs
->cy
== expected_cy
, "wrong y size %d/%d\n", cs
->cy
, expected_cy
);
3919 ok( rect
.right
- rect
.left
== expected_rect
.right
- expected_rect
.left
&&
3920 rect
.bottom
- rect
.top
== expected_rect
.bottom
- expected_rect
.top
,
3921 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
3922 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
3923 expected_rect
.left
, expected_rect
.top
, expected_rect
.right
, expected_rect
.bottom
);
3924 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3927 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3931 static void test_CreateWindow(void)
3939 #define expect_menu(window, menu) \
3940 SetLastError(0xdeadbeef); \
3941 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
3943 #define expect_style(window, style)\
3944 ok(GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
3946 #define expect_ex_style(window, ex_style)\
3947 ok(GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
3949 hmenu
= CreateMenu();
3951 parent
= GetDesktopWindow();
3952 assert(parent
!= 0);
3954 SetLastError(0xdeadbeef);
3955 ok(IsMenu(hmenu
), "IsMenu error %d\n", GetLastError());
3958 SetLastError(0xdeadbeef);
3959 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
,
3960 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3961 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3962 expect_menu(hwnd
, 1);
3963 expect_style(hwnd
, WS_CHILD
);
3964 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
3965 DestroyWindow(hwnd
);
3967 SetLastError(0xdeadbeef);
3968 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_CAPTION
,
3969 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3970 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3971 expect_menu(hwnd
, 1);
3972 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
3973 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
3974 DestroyWindow(hwnd
);
3976 SetLastError(0xdeadbeef);
3977 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
,
3978 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3979 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3980 expect_menu(hwnd
, 1);
3981 expect_style(hwnd
, WS_CHILD
);
3982 expect_ex_style(hwnd
, 0);
3983 DestroyWindow(hwnd
);
3985 SetLastError(0xdeadbeef);
3986 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_CAPTION
,
3987 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3988 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3989 expect_menu(hwnd
, 1);
3990 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
3991 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
3992 DestroyWindow(hwnd
);
3995 SetLastError(0xdeadbeef);
3996 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
3997 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
3998 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3999 expect_menu(hwnd
, hmenu
);
4000 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4001 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4002 DestroyWindow(hwnd
);
4003 SetLastError(0xdeadbeef);
4004 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4005 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4007 hmenu
= CreateMenu();
4009 SetLastError(0xdeadbeef);
4010 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4011 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4012 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4013 expect_menu(hwnd
, hmenu
);
4014 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4015 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4016 DestroyWindow(hwnd
);
4017 SetLastError(0xdeadbeef);
4018 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4019 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4021 hmenu
= CreateMenu();
4023 SetLastError(0xdeadbeef);
4024 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
,
4025 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4026 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4027 expect_menu(hwnd
, hmenu
);
4028 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4029 expect_ex_style(hwnd
, 0);
4030 DestroyWindow(hwnd
);
4031 SetLastError(0xdeadbeef);
4032 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4033 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4035 hmenu
= CreateMenu();
4037 SetLastError(0xdeadbeef);
4038 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4039 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4040 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4041 expect_menu(hwnd
, hmenu
);
4042 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4043 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4044 DestroyWindow(hwnd
);
4045 SetLastError(0xdeadbeef);
4046 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4047 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4049 /* WS_CHILD | WS_POPUP */
4050 SetLastError(0xdeadbeef);
4051 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4052 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4053 ok(!hwnd
, "CreateWindowEx should fail\n");
4054 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4056 hmenu
= CreateMenu();
4058 SetLastError(0xdeadbeef);
4059 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4060 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4061 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4062 expect_menu(hwnd
, hmenu
);
4063 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4064 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4065 DestroyWindow(hwnd
);
4066 SetLastError(0xdeadbeef);
4067 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4068 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4070 SetLastError(0xdeadbeef);
4071 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4072 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4073 ok(!hwnd
, "CreateWindowEx should fail\n");
4074 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4076 hmenu
= CreateMenu();
4078 SetLastError(0xdeadbeef);
4079 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4080 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4081 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4082 expect_menu(hwnd
, hmenu
);
4083 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4084 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4085 DestroyWindow(hwnd
);
4086 SetLastError(0xdeadbeef);
4087 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4088 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4090 SetLastError(0xdeadbeef);
4091 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4092 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4093 ok(!hwnd
, "CreateWindowEx should fail\n");
4094 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4096 hmenu
= CreateMenu();
4098 SetLastError(0xdeadbeef);
4099 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4100 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4101 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4102 expect_menu(hwnd
, hmenu
);
4103 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4104 expect_ex_style(hwnd
, 0);
4105 DestroyWindow(hwnd
);
4106 SetLastError(0xdeadbeef);
4107 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4108 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4110 SetLastError(0xdeadbeef);
4111 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4112 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4113 ok(!hwnd
, "CreateWindowEx should fail\n");
4114 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4116 hmenu
= CreateMenu();
4118 SetLastError(0xdeadbeef);
4119 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4120 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4121 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4122 expect_menu(hwnd
, hmenu
);
4123 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4124 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4125 DestroyWindow(hwnd
);
4126 SetLastError(0xdeadbeef);
4127 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4128 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4130 /* test child window sizing */
4132 cls
.lpfnWndProc
= minmax_wnd_proc
;
4135 cls
.hInstance
= GetModuleHandle(0);
4137 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
4138 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4139 cls
.lpszMenuName
= NULL
;
4140 cls
.lpszClassName
= "MinMax_WndClass";
4141 RegisterClass(&cls
);
4143 SetLastError(0xdeadbeef);
4144 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4145 0, 0, 100, 100, 0, 0, 0, NULL
);
4146 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
4147 expect_menu(parent
, 0);
4148 expect_style(parent
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
| WS_CLIPSIBLINGS
);
4149 expect_ex_style(parent
, WS_EX_WINDOWEDGE
);
4151 memset(&minmax
, 0, sizeof(minmax
));
4152 SendMessage(parent
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4153 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxSize
.x
, minmax
.ptMaxSize
.y
);
4154 ok(IsRectEmpty(&rc_minmax
), "ptMaxSize is not empty\n");
4155 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4156 ok(IsRectEmpty(&rc_minmax
), "ptMaxTrackSize is not empty\n");
4158 GetWindowRect(parent
, &rc
);
4159 ok(!IsRectEmpty(&rc
), "parent window rect is empty\n");
4160 GetClientRect(parent
, &rc
);
4161 ok(!IsRectEmpty(&rc
), "parent client rect is empty\n");
4163 InflateRect(&rc
, 200, 200);
4164 trace("creating child with rect (%d,%d-%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4166 SetLastError(0xdeadbeef);
4167 hwnd
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4168 rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
4169 parent
, (HMENU
)1, 0, NULL
);
4170 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4171 expect_menu(hwnd
, 1);
4172 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
);
4173 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4175 memset(&minmax
, 0, sizeof(minmax
));
4176 SendMessage(hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4177 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4179 GetWindowRect(hwnd
, &rc
);
4180 OffsetRect(&rc
, -rc
.left
, -rc
.top
);
4181 ok(EqualRect(&rc
, &rc_minmax
), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4182 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
4183 rc_minmax
.left
, rc_minmax
.top
, rc_minmax
.right
, rc_minmax
.bottom
);
4184 DestroyWindow(hwnd
);
4186 cls
.lpfnWndProc
= winsizes_wnd_proc
;
4187 cls
.lpszClassName
= "Sizes_WndClass";
4188 RegisterClass(&cls
);
4190 expected_cx
= expected_cy
= 200000;
4191 SetRect( &expected_rect
, 0, 0, 200000, 200000 );
4192 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 300000, 300000, 200000, 200000, parent
, 0, 0, NULL
);
4193 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4194 GetClientRect( hwnd
, &rc
);
4195 ok( rc
.right
== 200000, "invalid rect right %u\n", rc
.right
);
4196 ok( rc
.bottom
== 200000, "invalid rect bottom %u\n", rc
.bottom
);
4197 DestroyWindow(hwnd
);
4199 expected_cx
= expected_cy
= -10;
4200 SetRect( &expected_rect
, 0, 0, 0, 0 );
4201 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -20, -20, -10, -10, parent
, 0, 0, NULL
);
4202 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4203 GetClientRect( hwnd
, &rc
);
4204 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4205 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4206 DestroyWindow(hwnd
);
4208 expected_cx
= expected_cy
= -200000;
4209 SetRect( &expected_rect
, 0, 0, 0, 0 );
4210 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -300000, -300000, -200000, -200000, parent
, 0, 0, NULL
);
4211 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4212 GetClientRect( hwnd
, &rc
);
4213 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4214 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4215 DestroyWindow(hwnd
);
4217 /* top level window */
4218 expected_cx
= expected_cy
= 200000;
4219 SetRect( &expected_rect
, 0, 0, GetSystemMetrics(SM_CXMAXTRACK
), GetSystemMetrics(SM_CYMAXTRACK
) );
4220 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_OVERLAPPEDWINDOW
, 300000, 300000, 200000, 200000, 0, 0, 0, NULL
);
4221 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4222 GetClientRect( hwnd
, &rc
);
4223 ok( rc
.right
<= expected_cx
, "invalid rect right %u\n", rc
.right
);
4224 ok( rc
.bottom
<= expected_cy
, "invalid rect bottom %u\n", rc
.bottom
);
4225 DestroyWindow(hwnd
);
4227 DestroyWindow(parent
);
4229 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4230 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4234 #undef expect_ex_style
4237 /* function that remembers whether the system the test is running on sets the
4238 * last error for user32 functions to make the tests stricter */
4239 static int check_error(DWORD actual
, DWORD expected
)
4241 static int sets_last_error
= -1;
4242 if (sets_last_error
== -1)
4243 sets_last_error
= (actual
!= 0xdeadbeef);
4244 return (!sets_last_error
&& (actual
== 0xdeadbeef)) || (actual
== expected
);
4247 static void test_SetWindowLong(void)
4250 WNDPROC old_window_procW
;
4252 SetLastError(0xdeadbeef);
4253 retval
= SetWindowLongPtr(NULL
, GWLP_WNDPROC
, 0);
4254 ok(!retval
, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval
);
4255 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE
),
4256 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4258 SetLastError(0xdeadbeef);
4259 retval
= SetWindowLongPtr(hwndMain
, 0xdeadbeef, 0);
4260 ok(!retval
, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval
);
4261 ok(check_error(GetLastError(), ERROR_INVALID_INDEX
),
4262 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4264 SetLastError(0xdeadbeef);
4265 retval
= SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4266 ok((WNDPROC
)retval
== main_window_procA
,
4267 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval
);
4268 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4269 retval
= GetWindowLongPtr(hwndMain
, GWLP_WNDPROC
);
4270 ok((WNDPROC
)retval
== main_window_procA
,
4271 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4272 ok(!IsWindowUnicode(hwndMain
), "hwndMain shouldn't be Unicode\n");
4274 old_window_procW
= (WNDPROC
)GetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
);
4275 SetLastError(0xdeadbeef);
4276 retval
= SetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
, 0);
4277 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED
)
4279 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4280 ok(retval
!= 0, "SetWindowLongPtr error %d\n", GetLastError());
4281 ok((WNDPROC
)retval
== old_window_procW
,
4282 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4283 ok(IsWindowUnicode(hwndMain
), "hwndMain should now be Unicode\n");
4285 /* set it back to ANSI */
4286 SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4290 static void test_ShowWindow(void)
4297 SetRect(&rcMain
, 120, 120, 210, 210);
4299 hwnd
= CreateWindowEx(0, "MainWindowClass", NULL
,
4300 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4301 WS_MAXIMIZEBOX
| WS_POPUP
,
4302 rcMain
.left
, rcMain
.top
,
4303 rcMain
.right
- rcMain
.left
, rcMain
.bottom
- rcMain
.top
,
4307 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4308 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4309 ok(!(style
& WS_VISIBLE
), "window should not be visible\n");
4310 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4311 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4312 GetWindowRect(hwnd
, &rc
);
4313 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4315 ret
= ShowWindow(hwnd
, SW_SHOW
);
4316 ok(!ret
, "not expected ret: %lu\n", ret
);
4317 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4318 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4319 ok(style
& WS_VISIBLE
, "window should be visible\n");
4320 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4321 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4322 GetWindowRect(hwnd
, &rc
);
4323 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4325 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4326 ok(ret
, "not expected ret: %lu\n", ret
);
4327 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4328 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4329 ok(style
& WS_VISIBLE
, "window should be visible\n");
4330 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4331 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4332 GetWindowRect(hwnd
, &rc
);
4333 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4335 ShowWindow(hwnd
, SW_RESTORE
);
4336 ok(ret
, "not expected ret: %lu\n", ret
);
4337 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4338 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4339 ok(style
& WS_VISIBLE
, "window should be visible\n");
4340 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4341 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4342 GetWindowRect(hwnd
, &rc
);
4343 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4345 ret
= EnableWindow(hwnd
, FALSE
);
4346 ok(!ret
, "not expected ret: %lu\n", ret
);
4347 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4348 ok(style
& WS_DISABLED
, "window should be disabled\n");
4350 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
4351 ok(!ret
, "not expected ret: %lu\n", ret
);
4352 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4353 ok(style
& WS_DISABLED
, "window should be disabled\n");
4354 ok(style
& WS_VISIBLE
, "window should be visible\n");
4355 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4356 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4357 GetWindowRect(hwnd
, &rc
);
4358 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4360 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
4361 ok(!ret
, "not expected ret: %lu\n", ret
);
4362 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4363 ok(style
& WS_DISABLED
, "window should be disabled\n");
4364 ok(style
& WS_VISIBLE
, "window should be visible\n");
4365 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4366 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4367 GetWindowRect(hwnd
, &rc
);
4368 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4370 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4371 ok(ret
, "not expected ret: %lu\n", ret
);
4372 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4373 ok(style
& WS_DISABLED
, "window should be disabled\n");
4374 ok(style
& WS_VISIBLE
, "window should be visible\n");
4375 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4376 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4377 GetWindowRect(hwnd
, &rc
);
4378 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4380 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
4381 ok(!ret
, "not expected ret: %lu\n", ret
);
4382 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4383 ok(style
& WS_DISABLED
, "window should be disabled\n");
4384 ok(style
& WS_VISIBLE
, "window should be visible\n");
4385 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4386 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4387 GetWindowRect(hwnd
, &rc
);
4388 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4390 ret
= ShowWindow(hwnd
, SW_RESTORE
);
4391 ok(ret
, "not expected ret: %lu\n", ret
);
4392 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4393 ok(style
& WS_DISABLED
, "window should be disabled\n");
4394 ok(style
& WS_VISIBLE
, "window should be visible\n");
4395 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4396 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4397 GetWindowRect(hwnd
, &rc
);
4398 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4400 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4401 ok(!ret
, "not expected ret: %lu\n", ret
);
4402 ok(IsWindow(hwnd
), "window should exist\n");
4404 ret
= EnableWindow(hwnd
, TRUE
);
4405 ok(ret
, "not expected ret: %lu\n", ret
);
4407 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4408 ok(!ret
, "not expected ret: %lu\n", ret
);
4409 ok(!IsWindow(hwnd
), "window should not exist\n");
4412 static void test_gettext(void)
4415 LPCSTR clsname
= "gettexttest";
4419 memset( &cls
, 0, sizeof cls
);
4420 cls
.lpfnWndProc
= DefWindowProc
;
4421 cls
.lpszClassName
= clsname
;
4422 cls
.hInstance
= GetModuleHandle(NULL
);
4424 if (!RegisterClass( &cls
)) return;
4426 hwnd
= CreateWindow( clsname
, "test text", WS_OVERLAPPED
, 0, 0, 10, 10, 0, NULL
, NULL
, NULL
);
4427 ok( hwnd
!= NULL
, "window was null\n");
4429 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10, 0x1000);
4430 ok( r
== 0, "settext should return zero\n");
4432 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10000, 0);
4433 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4435 r
= SendMessage( hwnd
, WM_GETTEXT
, 0xff000000, 0x1000);
4436 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4438 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x1000, 0xff000000);
4439 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4441 DestroyWindow(hwnd
);
4442 UnregisterClass( clsname
, NULL
);
4446 static void test_GetUpdateRect(void)
4449 BOOL ret
, parent_wm_paint
, grandparent_wm_paint
;
4451 HWND hgrandparent
, hparent
, hchild
;
4453 static const char classNameA
[] = "GetUpdateRectClass";
4455 hgrandparent
= CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW
,
4456 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4458 hparent
= CreateWindowA("static", "parent", WS_CHILD
|WS_VISIBLE
,
4459 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4461 hchild
= CreateWindowA("static", "child", WS_CHILD
|WS_VISIBLE
,
4462 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4464 ShowWindow(hgrandparent
, SW_SHOW
);
4465 UpdateWindow(hgrandparent
);
4468 ShowWindow(hchild
, SW_HIDE
);
4469 SetRect(&rc2
, 0, 0, 0, 0);
4470 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4471 ok(!ret
, "GetUpdateRect returned not empty region\n");
4472 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4473 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4474 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4476 SetRect(&rc2
, 10, 10, 40, 40);
4477 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
4478 ok(ret
, "GetUpdateRect returned empty region\n");
4479 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4480 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4481 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4483 parent_wm_paint
= FALSE
;
4484 grandparent_wm_paint
= FALSE
;
4485 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
4487 if (msg
.message
== WM_PAINT
)
4489 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
4490 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
4492 DispatchMessage(&msg
);
4494 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
4495 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
4497 DestroyWindow(hgrandparent
);
4500 cls
.lpfnWndProc
= DefWindowProcA
;
4503 cls
.hInstance
= GetModuleHandleA(0);
4505 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
4506 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4507 cls
.lpszMenuName
= NULL
;
4508 cls
.lpszClassName
= classNameA
;
4510 if(!RegisterClassA(&cls
)) {
4511 trace("Register failed %d\n", GetLastError());
4515 hgrandparent
= CreateWindowA(classNameA
, "grandparent", WS_OVERLAPPEDWINDOW
,
4516 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4518 hparent
= CreateWindowA(classNameA
, "parent", WS_CHILD
|WS_VISIBLE
,
4519 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4521 hchild
= CreateWindowA(classNameA
, "child", WS_CHILD
|WS_VISIBLE
,
4522 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4524 ShowWindow(hgrandparent
, SW_SHOW
);
4525 UpdateWindow(hgrandparent
);
4528 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4529 ok(!ret
, "GetUpdateRect returned not empty region\n");
4531 ShowWindow(hchild
, SW_HIDE
);
4533 SetRect(&rc2
, 0, 0, 0, 0);
4534 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4535 ok(!ret
, "GetUpdateRect returned not empty region\n");
4536 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4537 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4538 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4540 SetRect(&rc2
, 10, 10, 40, 40);
4541 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
4542 ok(ret
, "GetUpdateRect returned empty region\n");
4543 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4544 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4545 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4547 parent_wm_paint
= FALSE
;
4548 grandparent_wm_paint
= FALSE
;
4549 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
4551 if (msg
.message
== WM_PAINT
)
4553 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
4554 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
4556 DispatchMessage(&msg
);
4558 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
4559 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
4561 DestroyWindow(hgrandparent
);
4566 pGetAncestor
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
4567 pGetWindowInfo
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
4569 hwndMain
= CreateWindowExA(0, "static", NULL
, 0, 0, 0, 0, 0, HWND_MESSAGE
, 0, 0, NULL
);
4572 ok(!GetParent(hwndMain
), "GetParent should return 0 for message only windows\n");
4575 hwndMessage
= pGetAncestor(hwndMain
, GA_PARENT
);
4576 ok(hwndMessage
!= 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
4577 trace("hwndMessage %p\n", hwndMessage
);
4579 DestroyWindow(hwndMain
);
4582 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
4584 if (!RegisterWindowClasses()) assert(0);
4586 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
4589 hwndMain
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
4590 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4591 WS_MAXIMIZEBOX
| WS_POPUP
,
4593 0, 0, GetModuleHandle(0), NULL
);
4594 test_nonclient_area(hwndMain
);
4596 hwndMain2
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
4597 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4598 WS_MAXIMIZEBOX
| WS_POPUP
,
4600 0, 0, GetModuleHandle(0), NULL
);
4602 assert( hwndMain2
);
4604 our_pid
= GetWindowThreadProcessId(hwndMain
, NULL
);
4606 /* Add the tests below this line */
4611 test_capture_3(hwndMain
, hwndMain2
);
4613 test_CreateWindow();
4614 test_parent_owner();
4616 test_shell_window();
4620 test_SetWindowPos(hwndMain
);
4621 test_SetMenu(hwndMain
);
4622 test_SetFocus(hwndMain
);
4623 test_SetActiveWindow(hwndMain
);
4624 test_SetForegroundWindow(hwndMain
);
4626 test_children_zorder(hwndMain
);
4627 test_popup_zorder(hwndMain2
, hwndMain
);
4628 test_keyboard_input(hwndMain
);
4629 test_mouse_input(hwndMain
);
4630 test_validatergn(hwndMain
);
4631 test_nccalcscroll( hwndMain
);
4632 test_scrollvalidate( hwndMain
);
4633 test_scrolldc( hwndMain
);
4635 test_IsWindowUnicode();
4636 test_vis_rgn(hwndMain
);
4638 test_AdjustWindowRect();
4639 test_window_styles();
4642 test_SetWindowLong();
4645 test_GetUpdateRect();
4647 /* add the tests above this line */
4648 UnhookWindowsHookEx(hhook
);