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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 /* To get ICON_SMALL2 with the MSVC headers */
24 #define _WIN32_WINNT 0x0501
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
39 #include "wine/test.h"
41 #ifndef SPI_GETDESKWALLPAPER
42 #define SPI_GETDESKWALLPAPER 0x0073
45 #define LONG_PTR INT_PTR
46 #define ULONG_PTR UINT_PTR
48 void dump_region(HRGN hrgn);
50 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
51 static BOOL (WINAPI *pGetWindowInfo)(HWND,WINDOWINFO*);
53 static BOOL test_lbuttondown_flag;
54 static HWND hwndMessage;
55 static HWND hwndMain, hwndMain2;
58 static const char* szAWRClass = "Winsize";
61 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
63 /* check the values returned by the various parent/owner functions on a given window */
64 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
65 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
71 res = pGetAncestor( hwnd, GA_PARENT );
72 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
74 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
75 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
76 res = GetParent( hwnd );
77 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
78 res = GetWindow( hwnd, GW_OWNER );
79 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
82 res = pGetAncestor( hwnd, GA_ROOT );
83 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
84 res = pGetAncestor( hwnd, GA_ROOTOWNER );
85 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
89 BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
92 trace("EnumChildProc on %p\n", hwndChild);
93 if (*(LPINT)lParam > 1) return FALSE;
97 /* will search for the given window */
98 BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
100 trace("EnumChildProc1 on %p\n", hwndChild);
101 if ((HWND)lParam == hwndChild) return FALSE;
105 static HWND create_tool_window( LONG style, HWND parent )
107 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
108 0, 0, 100, 100, parent, 0, 0, NULL );
109 ok( ret != 0, "Creation failed\n" );
113 /* test parent and owner values for various combinations */
114 static void test_parent_owner(void)
117 HWND test, owner, ret;
118 HWND desktop = GetDesktopWindow();
119 HWND child = create_tool_window( WS_CHILD, hwndMain );
122 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
124 /* child without parent, should fail */
125 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
126 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
127 ok( !test, "WS_CHILD without parent created\n" );
130 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
131 style = GetWindowLongA( desktop, GWL_STYLE );
132 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
133 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
134 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
136 /* normal child window */
137 test = create_tool_window( WS_CHILD, hwndMain );
138 trace( "created child %p\n", test );
139 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
140 SetWindowLongA( test, GWL_STYLE, 0 );
141 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
142 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
143 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
144 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
145 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
146 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
147 DestroyWindow( test );
149 /* normal child window with WS_MAXIMIZE */
150 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
151 DestroyWindow( test );
153 /* normal child window with WS_THICKFRAME */
154 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
155 DestroyWindow( test );
157 /* popup window with WS_THICKFRAME */
158 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
159 DestroyWindow( test );
161 /* child of desktop */
162 test = create_tool_window( WS_CHILD, desktop );
163 trace( "created child of desktop %p\n", test );
164 check_parents( test, desktop, 0, desktop, 0, test, desktop );
165 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
166 check_parents( test, desktop, 0, 0, 0, test, test );
167 SetWindowLongA( test, GWL_STYLE, 0 );
168 check_parents( test, desktop, 0, 0, 0, test, test );
169 DestroyWindow( test );
171 /* child of desktop with WS_MAXIMIZE */
172 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
173 DestroyWindow( test );
175 /* child of desktop with WS_MINIMIZE */
176 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
177 DestroyWindow( test );
180 test = create_tool_window( WS_CHILD, child );
181 trace( "created child of child %p\n", test );
182 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
183 SetWindowLongA( test, GWL_STYLE, 0 );
184 check_parents( test, child, child, 0, 0, hwndMain, test );
185 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
186 check_parents( test, child, child, 0, 0, hwndMain, test );
187 DestroyWindow( test );
189 /* child of child with WS_MAXIMIZE */
190 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
191 DestroyWindow( test );
193 /* child of child with WS_MINIMIZE */
194 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
195 DestroyWindow( test );
197 /* not owned top-level window */
198 test = create_tool_window( 0, 0 );
199 trace( "created top-level %p\n", test );
200 check_parents( test, desktop, 0, 0, 0, test, test );
201 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
202 check_parents( test, desktop, 0, 0, 0, test, test );
203 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
204 check_parents( test, desktop, 0, desktop, 0, test, desktop );
205 DestroyWindow( test );
207 /* not owned top-level window with WS_MAXIMIZE */
208 test = create_tool_window( WS_MAXIMIZE, 0 );
209 DestroyWindow( test );
211 /* owned top-level window */
212 test = create_tool_window( 0, hwndMain );
213 trace( "created owned top-level %p\n", test );
214 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
215 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
216 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
217 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
218 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
219 DestroyWindow( test );
221 /* owned top-level window with WS_MAXIMIZE */
222 test = create_tool_window( WS_MAXIMIZE, hwndMain );
223 DestroyWindow( test );
225 /* not owned popup */
226 test = create_tool_window( WS_POPUP, 0 );
227 trace( "created popup %p\n", test );
228 check_parents( test, desktop, 0, 0, 0, test, test );
229 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
230 check_parents( test, desktop, 0, desktop, 0, test, desktop );
231 SetWindowLongA( test, GWL_STYLE, 0 );
232 check_parents( test, desktop, 0, 0, 0, test, test );
233 DestroyWindow( test );
235 /* not owned popup with WS_MAXIMIZE */
236 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
237 DestroyWindow( test );
240 test = create_tool_window( WS_POPUP, hwndMain );
241 trace( "created owned popup %p\n", test );
242 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
243 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
244 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
245 SetWindowLongA( test, GWL_STYLE, 0 );
246 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
247 DestroyWindow( test );
249 /* owned popup with WS_MAXIMIZE */
250 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
251 DestroyWindow( test );
253 /* top-level window owned by child (same as owned by top-level) */
254 test = create_tool_window( 0, child );
255 trace( "created top-level owned by child %p\n", test );
256 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
257 DestroyWindow( test );
259 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
260 test = create_tool_window( WS_MAXIMIZE, child );
261 DestroyWindow( test );
263 /* popup owned by desktop (same as not owned) */
264 test = create_tool_window( WS_POPUP, desktop );
265 trace( "created popup owned by desktop %p\n", test );
266 check_parents( test, desktop, 0, 0, 0, test, test );
267 DestroyWindow( test );
269 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
270 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
271 DestroyWindow( test );
273 /* popup owned by child (same as owned by top-level) */
274 test = create_tool_window( WS_POPUP, child );
275 trace( "created popup owned by child %p\n", test );
276 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
277 DestroyWindow( test );
279 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
280 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
281 DestroyWindow( test );
283 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
284 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
285 trace( "created WS_CHILD popup %p\n", test );
286 check_parents( test, desktop, 0, 0, 0, test, test );
287 DestroyWindow( test );
289 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
290 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
291 DestroyWindow( test );
293 /* owned popup with WS_CHILD (same as WS_POPUP only) */
294 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
295 trace( "created owned WS_CHILD popup %p\n", test );
296 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
297 DestroyWindow( test );
299 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
300 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
301 DestroyWindow( test );
303 /******************** parent changes *************************/
304 trace( "testing parent changes\n" );
307 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
308 #if 0 /* this test succeeds on NT but crashes on win9x systems */
309 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
310 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
311 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
312 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
313 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
315 /* normal child window */
316 test = create_tool_window( WS_CHILD, hwndMain );
317 trace( "created child %p\n", test );
319 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
320 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
321 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
323 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
324 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
325 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
327 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
328 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
329 check_parents( test, desktop, 0, desktop, 0, test, desktop );
331 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
332 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
333 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
334 check_parents( test, desktop, child, desktop, child, test, desktop );
336 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
337 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
338 check_parents( test, desktop, 0, desktop, 0, test, desktop );
339 DestroyWindow( test );
341 /* not owned top-level window */
342 test = create_tool_window( 0, 0 );
343 trace( "created top-level %p\n", test );
345 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
346 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
347 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
349 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
350 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
351 check_parents( test, desktop, child, 0, child, test, test );
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, 0, 0, test, test );
356 DestroyWindow( test );
358 /* not owned popup */
359 test = create_tool_window( WS_POPUP, 0 );
360 trace( "created popup %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, hwndMain2, hwndMain2, test, hwndMain2 );
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, child, child, test, hwndMain );
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 /* normal child window */
376 test = create_tool_window( WS_CHILD, hwndMain );
377 trace( "created child %p\n", test );
379 ret = SetParent( test, desktop );
380 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
381 check_parents( test, desktop, 0, desktop, 0, test, desktop );
383 ret = SetParent( test, child );
384 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
385 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
387 ret = SetParent( test, hwndMain2 );
388 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
389 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
390 DestroyWindow( test );
392 /* not owned top-level window */
393 test = create_tool_window( 0, 0 );
394 trace( "created top-level %p\n", test );
396 ret = SetParent( test, child );
397 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
398 check_parents( test, child, child, 0, 0, hwndMain, test );
399 DestroyWindow( test );
402 test = create_tool_window( WS_POPUP, hwndMain2 );
403 trace( "created owned popup %p\n", test );
405 ret = SetParent( test, child );
406 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
407 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
409 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
410 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
411 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
412 DestroyWindow( test );
414 /**************** test owner destruction *******************/
416 /* owned child popup */
417 owner = create_tool_window( 0, 0 );
418 test = create_tool_window( WS_POPUP, owner );
419 trace( "created owner %p and popup %p\n", owner, test );
420 ret = SetParent( test, child );
421 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
422 check_parents( test, child, child, owner, owner, hwndMain, owner );
423 /* window is now child of 'child' but owned by 'owner' */
424 DestroyWindow( owner );
425 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
426 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
427 * while Win95, Win2k, WinXP do.
429 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
430 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
433 /* owned top-level 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 check_parents( test, desktop, owner, owner, owner, test, owner );
438 DestroyWindow( owner );
439 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
441 /* top-level popup owned by child */
442 owner = create_tool_window( WS_CHILD, hwndMain2 );
443 test = create_tool_window( WS_POPUP, 0 );
444 trace( "created owner %p and popup %p\n", owner, test );
445 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
446 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
447 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
448 DestroyWindow( owner );
449 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
450 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
451 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
452 * while Win95, Win2k, WinXP do.
454 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
458 DestroyWindow(child);
461 owner = create_tool_window( WS_OVERLAPPED, 0 );
462 test = create_tool_window( WS_POPUP, desktop );
464 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
466 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
467 "EnumChildWindows should have returned FALSE\n" );
468 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
470 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
471 ret = SetParent( test, owner );
472 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
475 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
476 "EnumChildWindows should have returned TRUE\n" );
477 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
479 child = create_tool_window( WS_CHILD, owner );
481 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
482 "EnumChildWindows should have returned FALSE\n" );
483 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
484 DestroyWindow( child );
486 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
487 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
489 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
490 "EnumChildWindows should have returned TRUE\n" );
491 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
493 ret = SetParent( child, owner );
494 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
495 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
497 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
498 "EnumChildWindows should have returned FALSE\n" );
499 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
501 ret = SetParent( child, NULL );
502 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
503 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
505 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
506 "EnumChildWindows should have returned TRUE\n" );
507 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
509 /* even GW_OWNER == owner it's still a desktop's child */
510 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
511 "EnumChildWindows should have found %p and returned FALSE\n", child );
513 DestroyWindow( child );
514 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
516 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
517 "EnumChildWindows should have found %p and returned FALSE\n", child );
519 DestroyWindow( child );
520 DestroyWindow( test );
521 DestroyWindow( owner );
525 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
529 case WM_GETMINMAXINFO:
531 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
533 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd, wparam, lparam);
534 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
535 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
536 minmax->ptReserved.x, minmax->ptReserved.y,
537 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
538 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
539 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
540 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
541 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
544 case WM_WINDOWPOSCHANGING:
546 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
547 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
548 trace("main: WM_WINDOWPOSCHANGING\n");
549 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
550 winpos->hwnd, winpos->hwndInsertAfter,
551 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
552 if (!(winpos->flags & SWP_NOMOVE))
554 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
555 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
557 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
558 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
560 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
561 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
565 case WM_WINDOWPOSCHANGED:
568 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
569 trace("main: WM_WINDOWPOSCHANGED\n");
570 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
571 winpos->hwnd, winpos->hwndInsertAfter,
572 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
573 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
574 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
576 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
577 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
579 GetWindowRect(hwnd, &rc1);
580 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
581 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
582 /* note: winpos coordinates are relative to parent */
583 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
584 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
585 #if 0 /* Uncomment this once the test succeeds in all cases */
586 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
589 GetClientRect(hwnd, &rc2);
590 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
591 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
592 ok(EqualRect(&rc1, &rc2), "rects do not match (%ld,%ld-%ld,%ld) / (%ld,%ld-%ld,%ld)\n",
593 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
598 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
599 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
601 trace("WM_NCCREATE: hwnd %p, parent %p, style %08lx\n", hwnd, cs->hwndParent, cs->style);
602 if (got_getminmaxinfo)
603 trace("%p got WM_GETMINMAXINFO\n", hwnd);
605 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
606 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
608 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
612 if (test_lbuttondown_flag)
613 ShowWindow((HWND)wparam, SW_SHOW);
617 return DefWindowProcA(hwnd, msg, wparam, lparam);
620 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
624 case WM_GETMINMAXINFO:
626 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
628 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd, wparam, lparam);
629 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
630 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
631 minmax->ptReserved.x, minmax->ptReserved.y,
632 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
633 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
634 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
635 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
636 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
641 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
642 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
644 trace("WM_NCCREATE: hwnd %p, parent %p, style %08lx\n", hwnd, cs->hwndParent, cs->style);
645 if (got_getminmaxinfo)
646 trace("%p got WM_GETMINMAXINFO\n", hwnd);
648 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
649 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
651 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
656 return DefWindowProcA(hwnd, msg, wparam, lparam);
659 static BOOL RegisterWindowClasses(void)
663 cls.style = CS_DBLCLKS;
664 cls.lpfnWndProc = main_window_procA;
667 cls.hInstance = GetModuleHandleA(0);
669 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
670 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
671 cls.lpszMenuName = NULL;
672 cls.lpszClassName = "MainWindowClass";
674 if(!RegisterClassA(&cls)) return FALSE;
677 cls.lpfnWndProc = tool_window_procA;
680 cls.hInstance = GetModuleHandleA(0);
682 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
683 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
684 cls.lpszMenuName = NULL;
685 cls.lpszClassName = "ToolWindowClass";
687 if(!RegisterClassA(&cls)) return FALSE;
692 static void verify_window_info(HWND hwnd, const WINDOWINFO *info, BOOL test_borders)
694 RECT rcWindow, rcClient;
698 ok(IsWindow(hwnd), "bad window handle\n");
700 GetWindowRect(hwnd, &rcWindow);
701 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow\n");
703 GetClientRect(hwnd, &rcClient);
704 /* translate to screen coordinates */
705 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
706 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient\n");
708 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
709 "wrong dwStyle: %08lx != %08lx\n", info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE));
710 ok(info->dwExStyle == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
711 "wrong dwExStyle: %08lx != %08lx\n", info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE));
712 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
713 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04lx != %04lx\n",
714 info->dwWindowStatus, status);
716 if (test_borders && !IsRectEmpty(&rcWindow))
718 trace("rcWindow: %ld,%ld - %ld,%ld\n", rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
719 trace("rcClient: %ld,%ld - %ld,%ld\n", rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
721 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
722 "wrong cxWindowBorders %d != %ld\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
723 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
724 ok(info->cyWindowBorders == border,
725 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
728 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType\n");
729 ok(info->wCreatorVersion == 0x0400, "wrong wCreatorVersion %04x\n", info->wCreatorVersion);
732 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
734 AdjustWindowRectEx(rc, style, menu, exstyle);
735 /* AdjustWindowRectEx does not include scroll bars */
736 if (style & WS_VSCROLL)
738 if(exstyle & WS_EX_LEFTSCROLLBAR)
739 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
741 rc->right += GetSystemMetrics(SM_CXVSCROLL);
743 if (style & WS_HSCROLL)
744 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
747 static void test_nonclient_area(HWND hwnd)
749 DWORD style, exstyle;
750 RECT rc_window, rc_client, rc;
752 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
754 style = GetWindowLongA(hwnd, GWL_STYLE);
755 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
756 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
758 GetWindowRect(hwnd, &rc_window);
759 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
760 GetClientRect(hwnd, &rc_client);
761 trace("client: (%ld,%ld)-(%ld,%ld)\n", rc_client.left, rc_client.top, rc_client.right, rc_client.bottom);
763 /* avoid some cases when things go wrong */
764 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
765 rc_window.right > 32768 || rc_window.bottom > 32768) return;
767 CopyRect(&rc, &rc_client);
768 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
769 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
771 trace("calc window: (%ld,%ld)-(%ld,%ld)\n", rc.left, rc.top, rc.right, rc.bottom);
772 ok(EqualRect(&rc, &rc_window), "window rect does not match: style:exstyle=0x%08lx:0x%08lx, menu=%d\n", style, exstyle, menu);
775 CopyRect(&rc, &rc_window);
776 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
777 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
778 trace("calc client: (%ld,%ld)-(%ld,%ld)\n", rc.left, rc.top, rc.right, rc.bottom);
779 ok(EqualRect(&rc, &rc_client), "client rect does not match: style:exstyle=0x%08lx:0x%08lx, menu=%d\n", style, exstyle, menu);
781 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
785 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
786 SetRect(&rc_client, 0, 0, 250, 150);
787 CopyRect(&rc_window, &rc_client);
788 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
789 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
790 trace("calc window: (%ld,%ld)-(%ld,%ld)\n",
791 rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
793 CopyRect(&rc, &rc_window);
794 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
795 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
796 trace("calc client: (%ld,%ld)-(%ld,%ld)\n", rc.left, rc.top, rc.right, rc.bottom);
797 ok(EqualRect(&rc, &rc_client), "synthetic rect does not match: style:exstyle=0x%08lx:0x%08lx, menu=%d\n", style, exstyle, menu);
800 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
802 static const char *CBT_code_name[10] = {
813 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
815 trace("CBT: %d (%s), %08x, %08lx\n", nCode, code_name, wParam, lParam);
817 /* on HCBT_DESTROYWND window state is undefined */
818 if (nCode != HCBT_DESTROYWND && IsWindow((HWND)wParam))
824 /* Win98 actually does check the info.cbSize and doesn't allow
825 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
826 * WinXP do not check it at all.
828 info.cbSize = sizeof(WINDOWINFO);
829 ok(pGetWindowInfo((HWND)wParam, &info), "GetWindowInfo should not fail\n");
830 /* win2k SP4 returns broken border info if GetWindowInfo
831 * is being called from HCBT_DESTROYWND or HCBT_MINMAX hook proc.
833 verify_window_info((HWND)wParam, &info, nCode != HCBT_MINMAX);
841 #if 0 /* Uncomment this once the test succeeds in all cases */
842 static const RECT rc_null;
846 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
847 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08lx\n",
848 (HWND)wParam, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
849 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
851 /* WS_VISIBLE should be turned off yet */
852 style = createwnd->lpcs->style & ~WS_VISIBLE;
853 ok(style == GetWindowLongA((HWND)wParam, GWL_STYLE),
854 "style of hwnd and style in the CREATESTRUCT do not match: %08lx != %08lx\n",
855 GetWindowLongA((HWND)wParam, GWL_STYLE), style);
857 #if 0 /* Uncomment this once the test succeeds in all cases */
858 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
860 ok(GetParent((HWND)wParam) == hwndMessage,
861 "wrong result from GetParent %p: message window %p\n",
862 GetParent((HWND)wParam), hwndMessage);
865 ok(!GetParent((HWND)wParam), "GetParent should return 0 at this point\n");
867 ok(!GetWindow((HWND)wParam, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
869 #if 0 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
870 * Win9x still has them set to 0.
872 ok(GetWindow((HWND)wParam, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
873 ok(GetWindow((HWND)wParam, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
875 ok(!GetWindow((HWND)wParam, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
876 ok(!GetWindow((HWND)wParam, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
878 #if 0 /* Uncomment this once the test succeeds in all cases */
881 ok(pGetAncestor((HWND)wParam, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
882 ok(pGetAncestor((HWND)wParam, GA_ROOT) == (HWND)wParam,
883 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOT), (HWND)wParam);
885 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
886 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == hwndMessage,
887 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
889 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == (HWND)wParam,
890 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOTOWNER), (HWND)wParam);
893 ok(GetWindowRect((HWND)wParam, &rc), "GetWindowRect failed\n");
894 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
895 ok(GetClientRect((HWND)wParam, &rc), "GetClientRect failed\n");
896 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
902 return CallNextHookEx(hhook, nCode, wParam, lParam);
905 static void test_shell_window(void)
909 HMODULE hinst, hUser32;
910 BOOL (WINAPI*SetShellWindow)(HWND);
911 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
912 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
913 HWND shellWindow, nextWnd;
915 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
917 trace("Skipping shell window test on Win9x\n");
921 shellWindow = GetShellWindow();
922 hinst = GetModuleHandle(0);
923 hUser32 = GetModuleHandleA("user32");
925 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
926 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
928 trace("previous shell window: %p\n", shellWindow);
934 ret = DestroyWindow(shellWindow);
935 error = GetLastError();
937 ok(!ret, "DestroyWindow(shellWindow)\n");
938 /* passes on Win XP, but not on Win98 */
939 ok(error==ERROR_ACCESS_DENIED, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n");
941 /* close old shell instance */
942 GetWindowThreadProcessId(shellWindow, &pid);
943 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
944 ret = TerminateProcess(hProcess, 0);
945 ok(ret, "termination of previous shell process failed: GetLastError()=%ld\n", GetLastError());
946 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
947 CloseHandle(hProcess);
950 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
951 trace("created window 1: %p\n", hwnd1);
953 ret = SetShellWindow(hwnd1);
954 ok(ret, "first call to SetShellWindow(hwnd1)\n");
955 shellWindow = GetShellWindow();
956 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
958 ret = SetShellWindow(hwnd1);
959 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
961 ret = SetShellWindow(0);
962 error = GetLastError();
963 /* passes on Win XP, but not on Win98
964 ok(!ret, "reset shell window by SetShellWindow(0)\n");
965 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
967 ret = SetShellWindow(hwnd1);
968 /* passes on Win XP, but not on Win98
969 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
973 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
974 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
975 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
978 ret = DestroyWindow(hwnd1);
979 ok(ret, "DestroyWindow(hwnd1)\n");
981 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
982 trace("created window 2: %p\n", hwnd2);
983 ret = SetShellWindow(hwnd2);
984 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
986 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
987 trace("created window 3: %p\n", hwnd3);
989 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
990 trace("created window 4: %p\n", hwnd4);
992 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
993 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
995 ret = SetShellWindow(hwnd4);
996 ok(ret, "SetShellWindow(hwnd4)\n");
997 shellWindow = GetShellWindow();
998 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1000 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1001 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1003 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1004 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1006 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1007 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1009 ret = SetShellWindow(hwnd3);
1010 ok(!ret, "SetShellWindow(hwnd3)\n");
1011 shellWindow = GetShellWindow();
1012 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1014 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1015 trace("created window 5: %p\n", hwnd5);
1016 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1017 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1021 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1022 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1025 /* destroy test windows */
1026 DestroyWindow(hwnd2);
1027 DestroyWindow(hwnd3);
1028 DestroyWindow(hwnd4);
1029 DestroyWindow(hwnd5);
1032 /************** MDI test ****************/
1034 static const char mdi_lParam_test_message[] = "just a test string";
1036 static void test_MDI_create(HWND parent, HWND mdi_client, INT first_id)
1038 MDICREATESTRUCTA mdi_cs;
1040 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1041 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1042 BOOL isWin9x = FALSE;
1044 mdi_cs.szClass = "MDI_child_Class_1";
1045 mdi_cs.szTitle = "MDI child";
1046 mdi_cs.hOwner = GetModuleHandle(0);
1047 mdi_cs.x = CW_USEDEFAULT;
1048 mdi_cs.y = CW_USEDEFAULT;
1049 mdi_cs.cx = CW_USEDEFAULT;
1050 mdi_cs.cy = CW_USEDEFAULT;
1052 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1053 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1054 ok(mdi_child != 0, "MDI child creation failed\n");
1055 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1056 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1057 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1059 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1060 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1061 ok(mdi_child != 0, "MDI child creation failed\n");
1062 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1063 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1064 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1066 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1067 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1068 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1070 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1074 ok(mdi_child != 0, "MDI child creation failed\n");
1075 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1076 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1077 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1080 /* test MDICREATESTRUCT A<->W mapping */
1081 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1083 mdi_cs.szClass = (LPCSTR)classW;
1084 mdi_cs.szTitle = (LPCSTR)titleW;
1085 SetLastError(0xdeadbeef);
1086 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1089 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1092 ok(mdi_child != 0, "MDI child creation failed\n");
1096 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1097 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1098 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1101 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1103 CW_USEDEFAULT, CW_USEDEFAULT,
1104 CW_USEDEFAULT, CW_USEDEFAULT,
1105 mdi_client, GetModuleHandle(0),
1106 (LPARAM)mdi_lParam_test_message);
1107 ok(mdi_child != 0, "MDI child creation failed\n");
1108 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1109 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1110 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1112 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1113 0x7fffffff, /* without WS_POPUP */
1114 CW_USEDEFAULT, CW_USEDEFAULT,
1115 CW_USEDEFAULT, CW_USEDEFAULT,
1116 mdi_client, GetModuleHandle(0),
1117 (LPARAM)mdi_lParam_test_message);
1118 ok(mdi_child != 0, "MDI child creation failed\n");
1119 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\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");
1123 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1124 0xffffffff, /* with WS_POPUP */
1125 CW_USEDEFAULT, CW_USEDEFAULT,
1126 CW_USEDEFAULT, CW_USEDEFAULT,
1127 mdi_client, GetModuleHandle(0),
1128 (LPARAM)mdi_lParam_test_message);
1129 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1131 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1135 ok(mdi_child != 0, "MDI child creation failed\n");
1136 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1137 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1138 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1141 /* test MDICREATESTRUCT A<->W mapping */
1142 SetLastError(0xdeadbeef);
1143 mdi_child = CreateMDIWindowW(classW, titleW,
1145 CW_USEDEFAULT, CW_USEDEFAULT,
1146 CW_USEDEFAULT, CW_USEDEFAULT,
1147 mdi_client, GetModuleHandle(0),
1148 (LPARAM)mdi_lParam_test_message);
1151 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1154 ok(mdi_child != 0, "MDI child creation failed\n");
1158 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1159 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1160 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1163 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1165 CW_USEDEFAULT, CW_USEDEFAULT,
1166 CW_USEDEFAULT, CW_USEDEFAULT,
1167 mdi_client, 0, GetModuleHandle(0),
1168 (LPVOID)mdi_lParam_test_message);
1169 ok(mdi_child != 0, "MDI child creation failed\n");
1170 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1171 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1172 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1174 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1175 0x7fffffff, /* without WS_POPUP */
1176 CW_USEDEFAULT, CW_USEDEFAULT,
1177 CW_USEDEFAULT, CW_USEDEFAULT,
1178 mdi_client, 0, GetModuleHandle(0),
1179 (LPVOID)mdi_lParam_test_message);
1180 ok(mdi_child != 0, "MDI child creation failed\n");
1181 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\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");
1185 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1186 0xffffffff, /* with WS_POPUP */
1187 CW_USEDEFAULT, CW_USEDEFAULT,
1188 CW_USEDEFAULT, CW_USEDEFAULT,
1189 mdi_client, 0, GetModuleHandle(0),
1190 (LPVOID)mdi_lParam_test_message);
1191 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1193 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1197 ok(mdi_child != 0, "MDI child creation failed\n");
1198 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1199 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1200 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1203 /* test MDICREATESTRUCT A<->W mapping */
1204 SetLastError(0xdeadbeef);
1205 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1207 CW_USEDEFAULT, CW_USEDEFAULT,
1208 CW_USEDEFAULT, CW_USEDEFAULT,
1209 mdi_client, 0, GetModuleHandle(0),
1210 (LPVOID)mdi_lParam_test_message);
1213 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1216 ok(mdi_child != 0, "MDI child creation failed\n");
1220 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1221 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1222 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1225 /* This test fails on Win9x */
1228 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1230 CW_USEDEFAULT, CW_USEDEFAULT,
1231 CW_USEDEFAULT, CW_USEDEFAULT,
1232 parent, 0, GetModuleHandle(0),
1233 (LPVOID)mdi_lParam_test_message);
1234 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1237 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1238 WS_CHILD, /* without WS_POPUP */
1239 CW_USEDEFAULT, CW_USEDEFAULT,
1240 CW_USEDEFAULT, CW_USEDEFAULT,
1241 mdi_client, 0, GetModuleHandle(0),
1242 (LPVOID)mdi_lParam_test_message);
1243 ok(mdi_child != 0, "MDI child creation failed\n");
1244 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1245 DestroyWindow(mdi_child);
1247 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1248 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1249 CW_USEDEFAULT, CW_USEDEFAULT,
1250 CW_USEDEFAULT, CW_USEDEFAULT,
1251 mdi_client, 0, GetModuleHandle(0),
1252 (LPVOID)mdi_lParam_test_message);
1253 ok(mdi_child != 0, "MDI child creation failed\n");
1254 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1255 DestroyWindow(mdi_child);
1257 /* maximized child */
1258 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1259 WS_CHILD | WS_MAXIMIZE,
1260 CW_USEDEFAULT, CW_USEDEFAULT,
1261 CW_USEDEFAULT, CW_USEDEFAULT,
1262 mdi_client, 0, GetModuleHandle(0),
1263 (LPVOID)mdi_lParam_test_message);
1264 ok(mdi_child != 0, "MDI child creation failed\n");
1265 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1266 DestroyWindow(mdi_child);
1268 trace("Creating maximized child with a caption\n");
1269 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1270 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1271 CW_USEDEFAULT, CW_USEDEFAULT,
1272 CW_USEDEFAULT, CW_USEDEFAULT,
1273 mdi_client, 0, GetModuleHandle(0),
1274 (LPVOID)mdi_lParam_test_message);
1275 ok(mdi_child != 0, "MDI child creation failed\n");
1276 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1277 DestroyWindow(mdi_child);
1279 trace("Creating maximized child with a caption and a thick frame\n");
1280 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1281 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1282 CW_USEDEFAULT, CW_USEDEFAULT,
1283 CW_USEDEFAULT, CW_USEDEFAULT,
1284 mdi_client, 0, GetModuleHandle(0),
1285 (LPVOID)mdi_lParam_test_message);
1286 ok(mdi_child != 0, "MDI child creation failed\n");
1287 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1288 DestroyWindow(mdi_child);
1291 /**********************************************************************
1292 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1294 * Note: The rule here is that client rect of the maximized MDI child
1295 * is equal to the client rect of the MDI client window.
1297 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1301 GetClientRect( client, &rect );
1302 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1303 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1305 rect.right -= rect.left;
1306 rect.bottom -= rect.top;
1307 lpMinMax->ptMaxSize.x = rect.right;
1308 lpMinMax->ptMaxSize.y = rect.bottom;
1310 lpMinMax->ptMaxPosition.x = rect.left;
1311 lpMinMax->ptMaxPosition.y = rect.top;
1313 trace("max rect (%ld,%ld - %ld, %ld)\n",
1314 rect.left, rect.top, rect.right, rect.bottom);
1317 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1324 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1325 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs->lpCreateParams;
1327 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1328 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1330 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1331 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1332 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1333 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1334 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1336 /* MDICREATESTRUCT should have original values */
1337 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1338 "mdi_cs->style does not match (%08lx)\n", mdi_cs->style);
1339 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1340 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1341 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1342 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1344 /* CREATESTRUCT should have fixed values */
1345 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1346 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1348 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1349 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1350 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1352 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1354 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1356 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1357 ok(cs->style == style,
1358 "cs->style does not match (%08lx)\n", cs->style);
1362 LONG style = mdi_cs->style;
1364 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1365 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1366 ok(cs->style == style,
1367 "cs->style does not match (%08lx)\n", cs->style);
1372 case WM_GETMINMAXINFO:
1374 HWND client = GetParent(hwnd);
1376 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1377 MINMAXINFO my_minmax;
1378 LONG style, exstyle;
1380 style = GetWindowLongA(hwnd, GWL_STYLE);
1381 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1383 GetWindowRect(client, &rc);
1384 trace("MDI client %p window size = (%ld x %ld)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1385 GetClientRect(client, &rc);
1386 trace("MDI client %p client size = (%ld x %ld)\n", client, rc.right, rc.bottom);
1387 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1388 GetSystemMetrics(SM_CYSCREEN));
1390 GetClientRect(client, &rc);
1391 if ((style & WS_CAPTION) == WS_CAPTION)
1392 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1393 AdjustWindowRectEx(&rc, style, 0, exstyle);
1394 trace("MDI child: calculated max window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1396 trace("ptReserved = (%ld,%ld)\n"
1397 "ptMaxSize = (%ld,%ld)\n"
1398 "ptMaxPosition = (%ld,%ld)\n"
1399 "ptMinTrackSize = (%ld,%ld)\n"
1400 "ptMaxTrackSize = (%ld,%ld)\n",
1401 minmax->ptReserved.x, minmax->ptReserved.y,
1402 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1403 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1404 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1405 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1407 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1408 minmax->ptMaxSize.x, rc.right - rc.left);
1409 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1410 minmax->ptMaxSize.y, rc.bottom - rc.top);
1412 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1414 trace("DefMDIChildProc returned:\n"
1415 "ptReserved = (%ld,%ld)\n"
1416 "ptMaxSize = (%ld,%ld)\n"
1417 "ptMaxPosition = (%ld,%ld)\n"
1418 "ptMinTrackSize = (%ld,%ld)\n"
1419 "ptMaxTrackSize = (%ld,%ld)\n",
1420 minmax->ptReserved.x, minmax->ptReserved.y,
1421 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1422 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1423 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1424 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1426 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1427 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %ld != %ld\n",
1428 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1429 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %ld != %ld\n",
1430 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1435 case WM_MDIACTIVATE:
1437 HWND active, client = GetParent(hwnd);
1438 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1439 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1440 if (hwnd == (HWND)lparam) /* if we are being activated */
1441 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1443 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1447 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1450 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1457 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1459 trace("%s\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE");
1460 trace("x %d, y %d, cx %d, cy %d\n", cs->x, cs->y, cs->cx, cs->cy);
1462 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1463 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1465 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1466 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1468 /* CREATESTRUCT should have fixed values */
1469 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1471 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1472 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1474 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1475 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1476 while Win95, Win2k, WinXP do. */
1477 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1478 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1482 case WM_GETMINMAXINFO:
1484 HWND parent = GetParent(hwnd);
1486 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1487 LONG style, exstyle;
1489 trace("WM_GETMINMAXINFO\n");
1491 style = GetWindowLongA(hwnd, GWL_STYLE);
1492 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1494 GetClientRect(parent, &rc);
1495 trace("parent %p client size = (%ld x %ld)\n", parent, rc.right, rc.bottom);
1497 GetClientRect(parent, &rc);
1498 if ((style & WS_CAPTION) == WS_CAPTION)
1499 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1500 AdjustWindowRectEx(&rc, style, 0, exstyle);
1501 trace("calculated max child window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1503 trace("ptReserved = (%ld,%ld)\n"
1504 "ptMaxSize = (%ld,%ld)\n"
1505 "ptMaxPosition = (%ld,%ld)\n"
1506 "ptMinTrackSize = (%ld,%ld)\n"
1507 "ptMaxTrackSize = (%ld,%ld)\n",
1508 minmax->ptReserved.x, minmax->ptReserved.y,
1509 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1510 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1511 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1512 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1514 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1515 minmax->ptMaxSize.x, rc.right - rc.left);
1516 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1517 minmax->ptMaxSize.y, rc.bottom - rc.top);
1521 case WM_WINDOWPOSCHANGED:
1523 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1526 GetWindowRect(hwnd, &rc1);
1527 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1528 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1529 /* note: winpos coordinates are relative to parent */
1530 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1531 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1532 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1534 GetWindowRect(hwnd, &rc1);
1535 GetClientRect(hwnd, &rc2);
1536 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1537 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1538 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1541 case WM_WINDOWPOSCHANGING:
1543 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1544 WINDOWPOS my_winpos = *winpos;
1546 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1547 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1548 winpos->hwnd, winpos->hwndInsertAfter,
1549 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1551 DefWindowProcA(hwnd, msg, wparam, lparam);
1553 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1554 winpos->hwnd, winpos->hwndInsertAfter,
1555 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1557 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1558 "DefWindowProc should not change WINDOWPOS values\n");
1563 return DefWindowProcA(hwnd, msg, wparam, lparam);
1566 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1568 static HWND mdi_client;
1574 CLIENTCREATESTRUCT client_cs;
1577 GetClientRect(hwnd, &rc);
1579 client_cs.hWindowMenu = 0;
1580 client_cs.idFirstChild = 1;
1582 /* MDIClient without MDIS_ALLCHILDSTYLES */
1583 mdi_client = CreateWindowExA(0, "mdiclient",
1585 WS_CHILD /*| WS_VISIBLE*/,
1586 /* tests depend on a not zero MDIClient size */
1587 0, 0, rc.right, rc.bottom,
1588 hwnd, 0, GetModuleHandle(0),
1589 (LPVOID)&client_cs);
1591 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1592 DestroyWindow(mdi_client);
1594 /* MDIClient with MDIS_ALLCHILDSTYLES */
1595 mdi_client = CreateWindowExA(0, "mdiclient",
1597 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1598 /* tests depend on a not zero MDIClient size */
1599 0, 0, rc.right, rc.bottom,
1600 hwnd, 0, GetModuleHandle(0),
1601 (LPVOID)&client_cs);
1603 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1604 DestroyWindow(mdi_client);
1608 case WM_WINDOWPOSCHANGED:
1610 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1613 GetWindowRect(hwnd, &rc1);
1614 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1615 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1616 /* note: winpos coordinates are relative to parent */
1617 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1618 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1619 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1621 GetWindowRect(hwnd, &rc1);
1622 GetClientRect(hwnd, &rc2);
1623 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1624 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1625 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1628 case WM_WINDOWPOSCHANGING:
1630 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1631 WINDOWPOS my_winpos = *winpos;
1633 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1634 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1635 winpos->hwnd, winpos->hwndInsertAfter,
1636 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1638 DefWindowProcA(hwnd, msg, wparam, lparam);
1640 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1641 winpos->hwnd, winpos->hwndInsertAfter,
1642 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1644 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1645 "DefWindowProc should not change WINDOWPOS values\n");
1654 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1657 static BOOL mdi_RegisterWindowClasses(void)
1662 cls.lpfnWndProc = mdi_main_wnd_procA;
1665 cls.hInstance = GetModuleHandleA(0);
1667 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1668 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1669 cls.lpszMenuName = NULL;
1670 cls.lpszClassName = "MDI_parent_Class";
1671 if(!RegisterClassA(&cls)) return FALSE;
1673 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1674 cls.lpszClassName = "MDI_child_Class_1";
1675 if(!RegisterClassA(&cls)) return FALSE;
1677 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1678 cls.lpszClassName = "MDI_child_Class_2";
1679 if(!RegisterClassA(&cls)) return FALSE;
1684 static void test_mdi(void)
1689 if (!mdi_RegisterWindowClasses()) assert(0);
1691 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1692 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1693 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1694 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1695 GetDesktopWindow(), 0,
1696 GetModuleHandle(0), NULL);
1697 assert(mdi_hwndMain);
1699 while(GetMessage(&msg, 0, 0, 0))
1701 TranslateMessage(&msg);
1702 DispatchMessage(&msg);
1707 static void test_icons(void)
1711 HICON icon = LoadIconA(0, (LPSTR)IDI_APPLICATION);
1712 HICON icon2 = LoadIconA(0, (LPSTR)IDI_QUESTION);
1713 HICON small_icon = LoadImageA(0, (LPSTR)IDI_APPLICATION, IMAGE_ICON,
1714 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1717 cls.cbSize = sizeof(cls);
1719 cls.lpfnWndProc = DefWindowProcA;
1723 cls.hIcon = LoadIconA(0, (LPSTR)IDI_HAND);
1724 cls.hIconSm = small_icon;
1725 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1726 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1727 cls.lpszMenuName = NULL;
1728 cls.lpszClassName = "IconWindowClass";
1730 RegisterClassExA(&cls);
1732 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1733 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1736 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1737 ok( res == 0, "wrong big icon %p/0\n", res );
1738 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1739 ok( res == 0, "wrong previous big icon %p/0\n", res );
1740 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1741 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1742 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1743 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1744 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1745 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1747 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1748 ok( res == 0, "wrong small icon %p/0\n", res );
1749 /* this test is XP specific */
1750 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1751 ok( res != 0, "wrong small icon %p\n", res );*/
1752 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1753 ok( res == 0, "wrong previous small icon %p/0\n", res );
1754 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1755 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1756 /* this test is XP specific */
1757 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1758 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1759 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1760 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1761 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1762 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1763 /* this test is XP specific */
1764 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1765 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1767 /* make sure the big icon hasn't changed */
1768 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1769 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1772 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1774 if (msg == WM_NCCALCSIZE)
1776 RECT *rect = (RECT *)lparam;
1777 /* first time around increase the rectangle, next time decrease it */
1778 if (rect->left == 100) InflateRect( rect, 10, 10 );
1779 else InflateRect( rect, -10, -10 );
1782 return DefWindowProc( hwnd, msg, wparam, lparam );
1785 static void test_SetWindowPos(HWND hwnd)
1787 RECT orig_win_rc, rect;
1789 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1791 SetRect(&rect, 111, 222, 333, 444);
1792 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1793 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1794 "wrong window rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1796 SetRect(&rect, 111, 222, 333, 444);
1797 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1798 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1799 "wrong window rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1801 GetWindowRect(hwnd, &orig_win_rc);
1803 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1804 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1805 GetWindowRect( hwnd, &rect );
1806 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1807 "invalid window rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1808 GetClientRect( hwnd, &rect );
1809 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1810 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1811 "invalid client rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1813 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1814 GetWindowRect( hwnd, &rect );
1815 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1816 "invalid window rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1817 GetClientRect( hwnd, &rect );
1818 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1819 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1820 "invalid client rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1822 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1823 orig_win_rc.right, orig_win_rc.bottom, 0);
1824 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1826 /* Win9x truncates coordinates to 16-bit irrespectively */
1829 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1830 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1832 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1833 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1836 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1837 orig_win_rc.right, orig_win_rc.bottom, 0);
1840 static void test_SetMenu(HWND parent)
1844 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1848 hMenu = CreateMenu();
1851 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1853 /* fails on (at least) Wine, NT4, XP SP2 */
1854 test_nonclient_area(parent);
1856 ret = GetMenu(parent);
1857 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1858 /* test whether we can destroy a menu assigned to a window */
1859 retok = DestroyMenu(hMenu);
1860 ok( retok, "DestroyMenu error %ld\n", GetLastError());
1861 ok(!IsMenu(hMenu), "menu handle should be not valid after DestroyMenu\n");
1862 ret = GetMenu(parent);
1863 /* This test fails on Win9x */
1865 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1866 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1867 test_nonclient_area(parent);
1869 hMenu = CreateMenu();
1873 ret = GetMenu(parent);
1874 ok(ret == 0, "unexpected menu id %p\n", ret);
1876 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1877 test_nonclient_area(parent);
1878 ret = GetMenu(parent);
1879 ok(ret == 0, "unexpected menu id %p\n", ret);
1881 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1883 /* fails on (at least) Wine, NT4, XP SP2 */
1884 test_nonclient_area(parent);
1886 ret = GetMenu(parent);
1887 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1889 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1890 test_nonclient_area(parent);
1891 ret = GetMenu(parent);
1892 ok(ret == 0, "unexpected menu id %p\n", ret);
1895 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1898 ret = GetMenu(child);
1899 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1901 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1902 test_nonclient_area(child);
1903 ret = GetMenu(child);
1904 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1906 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1907 test_nonclient_area(child);
1908 ret = GetMenu(child);
1909 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1911 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1912 test_nonclient_area(child);
1913 ret = GetMenu(child);
1914 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1916 style = GetWindowLong(child, GWL_STYLE);
1917 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
1918 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
1919 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
1920 SetWindowLong(child, GWL_STYLE, style);
1922 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
1923 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
1924 SetWindowLong(child, GWL_STYLE, style);
1926 DestroyWindow(child);
1930 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1932 HWND child[5], hwnd;
1937 hwnd = GetWindow(parent, GW_CHILD);
1938 ok(!hwnd, "have to start without children to perform the test\n");
1940 for (i = 0; i < total; i++)
1942 if (style[i] & DS_CONTROL)
1944 child[i] = CreateWindowExA(0, MAKEINTATOMA(32770), "", style[i] & ~WS_VISIBLE,
1945 0,0,0,0, parent, (HMENU)i, 0, NULL);
1946 if (style[i] & WS_VISIBLE)
1947 ShowWindow(child[i], SW_SHOW);
1949 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
1952 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
1953 parent, (HMENU)i, 0, NULL);
1954 trace("child[%d] = %p\n", i, child[i]);
1955 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
1958 hwnd = GetWindow(parent, GW_CHILD);
1959 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
1960 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
1961 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
1963 for (i = 0; i < total; i++)
1965 trace("hwnd[%d] = %p\n", i, hwnd);
1966 ok(child[order[i]] == hwnd, "Z order of child #%d is wrong\n", i);
1968 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1971 for (i = 0; i < total; i++)
1972 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
1975 static void test_children_zorder(HWND parent)
1977 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
1979 const int simple_order[5] = { 0, 1, 2, 3, 4 };
1981 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
1982 WS_CHILD | WS_VISIBLE, WS_CHILD,
1983 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
1984 const int complex_order_1[1] = { 0 };
1985 const int complex_order_2[2] = { 1, 0 };
1986 const int complex_order_3[3] = { 1, 0, 2 };
1987 const int complex_order_4[4] = { 1, 0, 2, 3 };
1988 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
1989 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
1990 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
1991 WS_CHILD | WS_VISIBLE };
1992 const int complex_order_6[3] = { 0, 1, 2 };
1994 /* simple WS_CHILD */
1995 test_window_tree(parent, simple_style, simple_order, 5);
1997 /* complex children styles */
1998 test_window_tree(parent, complex_style, complex_order_1, 1);
1999 test_window_tree(parent, complex_style, complex_order_2, 2);
2000 test_window_tree(parent, complex_style, complex_order_3, 3);
2001 test_window_tree(parent, complex_style, complex_order_4, 4);
2002 test_window_tree(parent, complex_style, complex_order_5, 5);
2004 /* another set of complex children styles */
2005 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2008 static void test_vis_rgn( HWND hwnd )
2010 RECT win_rect, rgn_rect;
2011 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2014 ShowWindow(hwnd,SW_SHOW);
2015 hdc = GetDC( hwnd );
2016 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2017 GetWindowRect( hwnd, &win_rect );
2018 GetRgnBox( hrgn, &rgn_rect );
2019 if (GetVersion() & 0x80000000)
2021 trace("win9x, mapping to screen coords\n");
2022 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2024 trace("win: %ld,%ld-%ld,%ld\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2025 trace("rgn: %ld,%ld-%ld,%ld\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2026 ok( win_rect.left <= rgn_rect.left, "rgn left %ld not inside win rect %ld\n",
2027 rgn_rect.left, win_rect.left );
2028 ok( win_rect.top <= rgn_rect.top, "rgn top %ld not inside win rect %ld\n",
2029 rgn_rect.top, win_rect.top );
2030 ok( win_rect.right >= rgn_rect.right, "rgn right %ld not inside win rect %ld\n",
2031 rgn_rect.right, win_rect.right );
2032 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %ld not inside win rect %ld\n",
2033 rgn_rect.bottom, win_rect.bottom );
2034 ReleaseDC( hwnd, hdc );
2037 static void test_SetFocus(HWND hwnd)
2041 /* check if we can set focus to non-visible windows */
2043 ShowWindow(hwnd, SW_SHOW);
2046 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2047 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2048 ShowWindow(hwnd, SW_HIDE);
2051 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2052 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2053 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2056 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2057 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2058 ShowWindow(child, SW_SHOW);
2059 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2060 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2061 ShowWindow(child, SW_HIDE);
2062 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2063 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2064 ShowWindow(child, SW_SHOW);
2066 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2067 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2068 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2070 ShowWindow(child, SW_HIDE);
2072 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2073 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2074 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2075 ShowWindow(child, SW_HIDE);
2076 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2078 ShowWindow(hwnd, SW_SHOW);
2079 ShowWindow(child, SW_SHOW);
2081 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2082 EnableWindow(hwnd, FALSE);
2083 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2084 EnableWindow(hwnd, TRUE);
2086 DestroyWindow( child );
2089 static void test_SetActiveWindow(HWND hwnd)
2093 ShowWindow(hwnd, SW_SHOW);
2095 SetActiveWindow(hwnd);
2096 ok( GetActiveWindow() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2097 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2098 ok( GetActiveWindow() == hwnd, "Window %p no longer active\n", hwnd );
2099 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2100 ShowWindow(hwnd, SW_HIDE);
2101 ok( GetActiveWindow() != hwnd, "Window %p is still active\n", hwnd );
2103 /* trace("**testing an invisible window now\n"); */
2104 SetActiveWindow(hwnd);
2105 ok( GetActiveWindow() == hwnd, "Window %p not active\n", hwnd );
2106 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p is visible\n", hwnd );
2108 ShowWindow(hwnd, SW_SHOW);
2110 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2111 ok( GetActiveWindow() == hwnd2, "Window %p is not active\n", hwnd2 );
2112 DestroyWindow(hwnd2);
2113 ok( GetActiveWindow() != hwnd2, "Window %p is still active\n", hwnd2 );
2115 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2116 ok( GetActiveWindow() == hwnd2, "Window %p is not active\n", hwnd2 );
2117 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2118 ok( GetActiveWindow() == hwnd2, "Window %p no longer active (%p)\n", hwnd2, GetActiveWindow() );
2119 DestroyWindow(hwnd2);
2120 ok( GetActiveWindow() != hwnd2, "Window %p is still active\n", hwnd2 );
2123 static void check_wnd_state(HWND active, HWND foreground, HWND focus, HWND capture)
2125 ok(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2127 ok(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2128 ok(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2129 ok(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2132 static WNDPROC old_button_proc;
2134 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2139 key_state = GetKeyState(VK_LBUTTON);
2140 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2142 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2144 if (msg == WM_LBUTTONDOWN)
2148 check_wnd_state(button, button, button, button);
2150 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2152 trace("hwnd %p\n", hwnd);
2154 check_wnd_state(button, button, button, button);
2156 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2158 check_wnd_state(button, button, button, button);
2160 DestroyWindow(hwnd);
2162 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2164 trace("hwnd %p\n", hwnd);
2166 check_wnd_state(button, button, button, button);
2168 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2169 * match internal button state.
2171 SendMessage(button, WM_KILLFOCUS, 0, 0);
2172 check_wnd_state(button, button, button, 0);
2174 ShowWindow(hwnd, SW_SHOW);
2175 check_wnd_state(hwnd, hwnd, hwnd, 0);
2177 capture = SetCapture(hwnd);
2178 ok(capture == 0, "SetCapture() = %p\n", capture);
2180 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2182 DestroyWindow(hwnd);
2184 check_wnd_state(button, 0, button, 0);
2190 static void test_capture_1(void)
2192 HWND button, capture;
2194 capture = GetCapture();
2195 ok(capture == 0, "GetCapture() = %p\n", capture);
2197 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2199 trace("button %p\n", button);
2201 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2203 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2205 capture = SetCapture(button);
2206 ok(capture == 0, "SetCapture() = %p\n", capture);
2207 check_wnd_state(button, 0, button, button);
2209 DestroyWindow(button);
2210 check_wnd_state(0, 0, 0, 0);
2213 static void test_capture_2(void)
2215 HWND button, hwnd, capture;
2217 check_wnd_state(0, 0, 0, 0);
2219 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2221 trace("button %p\n", button);
2223 check_wnd_state(button, button, button, 0);
2225 capture = SetCapture(button);
2226 ok(capture == 0, "SetCapture() = %p\n", capture);
2228 check_wnd_state(button, button, button, button);
2230 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2231 * internal button state.
2233 SendMessage(button, WM_KILLFOCUS, 0, 0);
2234 check_wnd_state(button, button, button, button);
2236 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2238 trace("hwnd %p\n", hwnd);
2240 check_wnd_state(button, button, button, button);
2242 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2244 check_wnd_state(button, button, button, button);
2246 DestroyWindow(hwnd);
2248 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2250 trace("hwnd %p\n", hwnd);
2252 check_wnd_state(button, button, button, button);
2254 ShowWindow(hwnd, SW_SHOW);
2256 check_wnd_state(hwnd, hwnd, hwnd, button);
2258 capture = SetCapture(hwnd);
2259 ok(capture == button, "SetCapture() = %p\n", capture);
2261 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2263 DestroyWindow(hwnd);
2264 check_wnd_state(button, button, button, 0);
2266 DestroyWindow(button);
2267 check_wnd_state(0, 0, 0, 0);
2270 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2274 ShowWindow(hwnd1, SW_HIDE);
2275 ShowWindow(hwnd2, SW_HIDE);
2277 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2278 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2281 check_wnd_state(0, 0, 0, hwnd1);
2284 check_wnd_state(0, 0, 0, hwnd2);
2286 ShowWindow(hwnd1, SW_SHOW);
2287 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2289 ret = ReleaseCapture();
2290 ok (ret, "releasecapture did not return TRUE.\n");
2291 ret = ReleaseCapture();
2292 ok (ret, "releasecapture did not return TRUE after second try.\n");
2295 static void test_keyboard_input(HWND hwnd)
2300 ShowWindow(hwnd, SW_SHOW);
2303 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2306 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2308 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2310 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2311 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2312 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2313 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2314 ok( !ret, "message %04x available\n", msg.message);
2316 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2318 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2319 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2320 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2321 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2322 ok( !ret, "message %04x available\n", msg.message);
2324 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2326 keybd_event(VK_SPACE, 0, 0, 0);
2327 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2328 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2329 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2330 ok( !ret, "message %04x available\n", msg.message);
2333 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2335 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
2337 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2338 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2339 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2340 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2341 ok( !ret, "message %04x available\n", msg.message);
2343 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2345 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2346 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2347 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2348 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2349 ok( !ret, "message %04x available\n", msg.message);
2351 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2353 keybd_event(VK_SPACE, 0, 0, 0);
2354 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2355 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2356 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2357 ok( !ret, "message %04x available\n", msg.message);
2360 static void test_mouse_input(HWND hwnd)
2370 ShowWindow(hwnd, SW_SHOW);
2373 GetWindowRect(hwnd, &rc);
2374 trace("main window %p: (%ld,%ld)-(%ld,%ld)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2376 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2377 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2380 ShowWindow(popup, SW_SHOW);
2381 UpdateWindow(popup);
2383 GetWindowRect(popup, &rc);
2384 trace("popup window %p: (%ld,%ld)-(%ld,%ld)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2386 x = rc.left + (rc.right - rc.left) / 2;
2387 y = rc.top + (rc.bottom - rc.top) / 2;
2388 trace("setting cursor to (%d,%d)\n", x, y);
2392 ok(x == pt.x && y == pt.y, "wrong cursor pos (%ld,%ld), expected (%d,%d)\n", pt.x, pt.y, x, y);
2394 /* force the system to update its internal queue mouse position,
2395 * otherwise it won't generate relative mouse movements below.
2397 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2398 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2401 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2402 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2403 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2404 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2405 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2406 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2407 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2408 ok( !ret, "message %04x available\n", msg.message);
2410 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2411 ShowWindow(popup, SW_HIDE);
2412 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2413 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2414 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2416 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2417 ShowWindow(hwnd, SW_HIDE);
2418 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2419 ok( !ret, "message %04x available\n", msg.message);
2421 /* test mouse clicks */
2423 ShowWindow(hwnd, SW_SHOW);
2424 ShowWindow(popup, SW_SHOW);
2426 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2428 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2429 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2430 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2431 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2433 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2434 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2435 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2436 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2438 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2439 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2440 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2441 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2443 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2444 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2445 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2446 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2448 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2449 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2450 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2451 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2453 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2454 ok(!ret, "message %04x available\n", msg.message);
2456 ShowWindow(popup, SW_HIDE);
2457 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2459 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2460 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2461 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2462 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2464 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2465 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2466 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2467 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2469 test_lbuttondown_flag = TRUE;
2470 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
2471 test_lbuttondown_flag = FALSE;
2473 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2474 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2475 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2476 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2477 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2479 /* Test WM_MOUSEACTIVATE */
2480 #define TEST_MOUSEACTIVATE(A,B) \
2481 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2482 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2484 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
2485 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
2486 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
2487 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
2488 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
2489 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
2490 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
2491 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
2492 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
2493 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
2494 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
2495 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
2496 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
2497 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
2498 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
2499 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
2500 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
2501 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
2502 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
2503 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
2504 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
2505 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
2506 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
2507 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
2509 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2510 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2512 DestroyWindow(popup);
2515 static void test_validatergn(HWND hwnd)
2521 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
2522 ShowWindow(hwnd, SW_SHOW);
2523 UpdateWindow( hwnd);
2524 /* test that ValidateRect validates children*/
2525 InvalidateRect( child, NULL, 1);
2526 GetWindowRect( child, &rc);
2527 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2528 ret = GetUpdateRect( child, &rc2, 0);
2529 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
2530 "Update rectangle is empty!\n");
2531 ValidateRect( hwnd, &rc);
2532 ret = GetUpdateRect( child, &rc2, 0);
2533 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2534 "Update rectangle %ld,%ld-%ld,%ld is not empty!\n", rc2.left, rc2.top,
2535 rc2.right, rc2.bottom);
2537 /* now test ValidateRgn */
2538 InvalidateRect( child, NULL, 1);
2539 GetWindowRect( child, &rc);
2540 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2541 rgn = CreateRectRgnIndirect( &rc);
2542 ValidateRgn( hwnd, rgn);
2543 ret = GetUpdateRect( child, &rc2, 0);
2544 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2545 "Update rectangle %ld,%ld-%ld,%ld is not empty!\n", rc2.left, rc2.top,
2546 rc2.right, rc2.bottom);
2549 DestroyWindow( child );
2552 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
2554 MoveWindow( hwnd, 0, 0, x, y, 0);
2555 GetWindowRect( hwnd, prc);
2556 trace("window rect is %ld,%ld - %ld,%ld\n",
2557 prc->left,prc->top,prc->right,prc->bottom);
2558 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
2559 trace("nccalc rect is %ld,%ld - %ld,%ld\n",
2560 prc->left,prc->top,prc->right,prc->bottom);
2563 static void test_nccalcscroll(HWND parent)
2566 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
2567 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
2568 HWND hwnd = CreateWindowExA(0, "static", NULL,
2569 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
2570 10, 10, 200, 200, parent, 0, 0, NULL);
2571 ShowWindow( parent, SW_SHOW);
2572 UpdateWindow( parent);
2574 /* test window too low for a horizontal scroll bar */
2575 nccalchelper( hwnd, 100, sbheight, &rc1);
2576 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %ld,%ld - %ld,%ld\n",
2577 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
2579 /* test window just high enough for a horizontal scroll bar */
2580 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
2581 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %ld,%ld - %ld,%ld\n",
2582 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2584 /* test window too narrow for a vertical scroll bar */
2585 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
2586 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %ld,%ld - %ld,%ld\n",
2587 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2589 /* test window just wide enough for a vertical scroll bar */
2590 nccalchelper( hwnd, sbwidth, 100, &rc1);
2591 ok( rc1.right - rc1.left == 0, "Width should be %d size is %ld,%ld - %ld,%ld\n",
2592 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
2594 /* same test, but with client edge: not enough width */
2595 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
2596 nccalchelper( hwnd, sbwidth, 100, &rc1);
2597 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
2598 "Width should be %d size is %ld,%ld - %ld,%ld\n",
2599 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
2601 DestroyWindow( hwnd);
2604 static void test_SetParent(void)
2607 HWND desktop = GetDesktopWindow();
2609 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
2610 HWND parent, child1, child2, child3, child4, sibling;
2612 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2613 100, 100, 200, 200, 0, 0, 0, NULL);
2614 assert(parent != 0);
2615 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2616 0, 0, 50, 50, parent, 0, 0, NULL);
2617 assert(child1 != 0);
2618 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2619 0, 0, 50, 50, child1, 0, 0, NULL);
2620 assert(child2 != 0);
2621 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2622 0, 0, 50, 50, child2, 0, 0, NULL);
2623 assert(child3 != 0);
2624 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2625 0, 0, 50, 50, child3, 0, 0, NULL);
2626 assert(child4 != 0);
2628 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2629 parent, child1, child2, child3, child4);
2631 check_parents(parent, desktop, 0, 0, 0, parent, parent);
2632 check_parents(child1, parent, parent, parent, 0, parent, parent);
2633 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2634 check_parents(child3, child2, child2, child2, 0, child2, parent);
2635 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2638 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
2639 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
2640 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2641 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
2642 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2645 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
2647 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2649 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
2650 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
2651 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
2652 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
2653 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
2654 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
2656 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2659 if (!is_win9x) /* Win9x doesn't survive this test */
2661 ok(!SetParent(parent, child1), "SetParent should fail\n");
2662 ok(!SetParent(child2, child3), "SetParent should fail\n");
2663 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
2664 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
2665 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
2666 ok(!SetParent(child2, parent), "SetParent should fail\n");
2667 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
2669 check_parents(parent, child4, child4, 0, 0, child4, parent);
2670 check_parents(child1, parent, parent, parent, 0, child4, parent);
2671 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2672 check_parents(child3, child2, child2, child2, 0, child2, parent);
2673 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2676 hMenu = CreateMenu();
2677 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2678 100, 100, 200, 200, 0, hMenu, 0, NULL);
2679 assert(sibling != 0);
2681 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
2682 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
2684 ret = DestroyWindow(parent);
2685 ok( ret, "DestroyWindow() error %ld\n", GetLastError());
2687 ok(!IsWindow(parent), "parent still exists\n");
2688 ok(!IsWindow(sibling), "sibling still exists\n");
2689 ok(!IsWindow(child1), "child1 still exists\n");
2690 ok(!IsWindow(child2), "child2 still exists\n");
2691 ok(!IsWindow(child3), "child3 still exists\n");
2692 ok(!IsWindow(child4), "child4 still exists\n");
2695 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2697 LPCREATESTRUCT lpcs;
2704 lpcs = (LPCREATESTRUCT)lparam;
2705 lpss = (LPSTYLESTRUCT)lpcs->lpCreateParams;
2708 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
2709 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
2710 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
2711 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
2713 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
2715 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
2716 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2717 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
2719 ok(lpss->styleNew == lpcs->style,
2720 "Style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2721 lpss->styleNew, lpcs->style);
2725 return DefWindowProc(hwnd, msg, wparam, lparam);
2728 static ATOM atomStyleCheckClass;
2730 static void register_style_check_class(void)
2738 GetModuleHandle(NULL),
2740 LoadCursor(NULL, IDC_ARROW),
2741 (HBRUSH)(COLOR_BTNFACE+1),
2743 TEXT("WineStyleCheck"),
2746 atomStyleCheckClass = RegisterClass(&wc);
2749 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
2751 DWORD dwActualStyle;
2752 DWORD dwActualExStyle;
2755 HWND hwndParent = NULL;
2758 ss.styleNew = dwStyleIn;
2759 ss.styleOld = dwExStyleIn;
2761 if (dwStyleIn & WS_CHILD)
2763 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
2764 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
2767 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
2768 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
2771 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2773 TranslateMessage(&msg);
2774 DispatchMessage(&msg);
2777 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
2778 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
2779 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
2780 "Style (0x%08lx) should really be 0x%08lx and/or Ex style (0x%08lx) should really be 0x%08lx\n",
2781 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
2783 DestroyWindow(hwnd);
2784 if (hwndParent) DestroyWindow(hwndParent);
2787 /* tests what window styles the window manager automatically adds */
2788 static void test_window_styles(void)
2790 register_style_check_class();
2792 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
2793 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
2794 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
2795 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
2796 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
2797 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
2798 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
2799 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
2800 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
2801 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
2802 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
2805 static void test_scrollvalidate( HWND parent)
2808 HRGN hrgn=CreateRectRgn(0,0,0,0);
2809 HRGN exprgn, tmprgn, clipping;
2810 RECT rc, rcu, cliprc;
2811 /* create two overlapping child windows. The visual region
2812 * of hwnd1 is clipped by the overlapping part of
2813 * hwnd2 because of the WS_CLIPSIBLING style */
2816 clipping = CreateRectRgn(0,0,0,0);
2817 tmprgn = CreateRectRgn(0,0,0,0);
2818 exprgn = CreateRectRgn(0,0,0,0);
2819 hwnd2 = CreateWindowExA(0, "static", NULL,
2820 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
2821 75, 30, 100, 100, parent, 0, 0, NULL);
2822 hwnd1 = CreateWindowExA(0, "static", NULL,
2823 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
2824 25, 50, 100, 100, parent, 0, 0, NULL);
2825 ShowWindow( parent, SW_SHOW);
2826 UpdateWindow( parent);
2827 GetClientRect( hwnd1, &rc);
2829 SetRectRgn( clipping, 10, 10, 90, 90);
2830 hdc = GetDC( hwnd1);
2831 /* for a visual touch */
2832 TextOut( hdc, 0,10, "0123456789", 10);
2833 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
2834 if (winetest_debug > 0) dump_region(hrgn);
2835 /* create a region with what is expected */
2836 SetRectRgn( exprgn, 39,0,49,74);
2837 SetRectRgn( tmprgn, 88,79,98,93);
2838 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2839 SetRectRgn( tmprgn, 0,93,98,98);
2840 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2841 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2842 trace("update rect is %ld,%ld - %ld,%ld\n",
2843 rcu.left,rcu.top,rcu.right,rcu.bottom);
2844 /* now with clipping region */
2845 SelectClipRgn( hdc, clipping);
2846 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
2847 if (winetest_debug > 0) dump_region(hrgn);
2848 /* create a region with what is expected */
2849 SetRectRgn( exprgn, 39,10,49,74);
2850 SetRectRgn( tmprgn, 80,79,90,85);
2851 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2852 SetRectRgn( tmprgn, 10,85,90,90);
2853 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2854 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2855 trace("update rect is %ld,%ld - %ld,%ld\n",
2856 rcu.left,rcu.top,rcu.right,rcu.bottom);
2857 ReleaseDC( hwnd1, hdc);
2859 /* test scrolling a window with an update region */
2860 DestroyWindow( hwnd2);
2861 ValidateRect( hwnd1, NULL);
2862 SetRect( &rc, 40,40, 50,50);
2863 InvalidateRect( hwnd1, &rc, 1);
2864 GetClientRect( hwnd1, &rc);
2866 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
2867 SW_SCROLLCHILDREN | SW_INVALIDATE);
2868 if (winetest_debug > 0) dump_region(hrgn);
2869 SetRectRgn( exprgn, 88,0,98,98);
2870 SetRectRgn( tmprgn, 30, 40, 50, 50);
2871 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2872 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2874 /* now test ScrollWindowEx with a combination of
2875 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
2876 /* make hwnd2 the child of hwnd1 */
2877 hwnd2 = CreateWindowExA(0, "static", NULL,
2878 WS_CHILD| WS_VISIBLE | WS_BORDER ,
2879 50, 50, 100, 100, hwnd1, 0, 0, NULL);
2880 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
2881 GetClientRect( hwnd1, &rc);
2884 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
2885 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
2886 ValidateRect( hwnd1, NULL);
2887 ValidateRect( hwnd2, NULL);
2888 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
2889 SW_SCROLLCHILDREN | SW_INVALIDATE);
2890 if (winetest_debug > 0) dump_region(hrgn);
2891 SetRectRgn( exprgn, 88,0,98,88);
2892 SetRectRgn( tmprgn, 0,88,98,98);
2893 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2894 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2896 /* SW_SCROLLCHILDREN */
2897 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
2898 ValidateRect( hwnd1, NULL);
2899 ValidateRect( hwnd2, NULL);
2900 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
2901 if (winetest_debug > 0) dump_region(hrgn);
2902 /* expected region is the same as in previous test */
2903 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2905 /* no SW_SCROLLCHILDREN */
2906 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
2907 ValidateRect( hwnd1, NULL);
2908 ValidateRect( hwnd2, NULL);
2909 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
2910 if (winetest_debug > 0) dump_region(hrgn);
2911 /* expected region is the same as in previous test */
2912 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2914 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
2915 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
2916 ValidateRect( hwnd1, NULL);
2917 ValidateRect( hwnd2, NULL);
2918 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
2919 if (winetest_debug > 0) dump_region(hrgn);
2920 SetRectRgn( exprgn, 88,0,98,20);
2921 SetRectRgn( tmprgn, 20,20,98,30);
2922 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2923 SetRectRgn( tmprgn, 20,30,30,88);
2924 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2925 SetRectRgn( tmprgn, 0,88,30,98);
2926 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2927 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2930 DeleteObject( hrgn);
2931 DeleteObject( exprgn);
2932 DeleteObject( tmprgn);
2933 DestroyWindow( hwnd1);
2934 DestroyWindow( hwnd2);
2937 /* couple of tests of return values of scrollbar functions
2938 * called on a scrollbarless window */
2939 static void test_scroll(void)
2944 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
2945 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
2946 100, 100, 200, 200, 0, 0, 0, NULL);
2948 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
2949 ok( ret, "GetScrollRange returns FALSE\n");
2950 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
2951 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
2952 si.cbSize = sizeof( si);
2953 si.fMask = SIF_PAGE;
2954 si.nPage = 0xdeadbeef;
2955 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
2956 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
2957 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
2959 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
2960 ok( ret, "GetScrollRange returns FALSE\n");
2961 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
2962 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
2963 si.cbSize = sizeof( si);
2964 si.fMask = SIF_PAGE;
2965 si.nPage = 0xdeadbeef;
2966 ret = GetScrollInfo( hwnd, SB_VERT, &si);
2967 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
2968 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
2970 DestroyWindow( hwnd);
2973 static void test_scrolldc( HWND parent)
2976 HRGN exprgn, tmprgn, hrgn;
2977 RECT rc, rc2, rcu, cliprc;
2981 hrgn = CreateRectRgn(0,0,0,0);
2982 tmprgn = CreateRectRgn(0,0,0,0);
2983 exprgn = CreateRectRgn(0,0,0,0);
2985 hwnd1 = CreateWindowExA(0, "static", NULL,
2986 WS_CHILD| WS_VISIBLE,
2987 25, 50, 100, 100, parent, 0, 0, NULL);
2988 ShowWindow( parent, SW_SHOW);
2989 UpdateWindow( parent);
2990 GetClientRect( hwnd1, &rc);
2991 hdc = GetDC( hwnd1);
2992 /* paint the upper half of the window black */
2994 rc2.bottom = ( rc.top + rc.bottom) /2;
2995 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
2996 /* clip region is the lower half */
2998 cliprc.top = (rc.top + rc.bottom) /2;
2999 /* test whether scrolled pixels are properly clipped */
3000 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3001 ok ( colr == 0, "pixel should be black, color is %08lx\n", colr);
3002 /* this scroll should not cause any visible changes */
3003 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3004 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3005 ok ( colr == 0, "pixel should be black, color is %08lx\n", colr);
3006 /* test with NULL clip rect */
3007 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3008 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3009 trace("update rect: %ld,%ld - %ld,%ld\n",
3010 rcu.left, rcu.top, rcu.right, rcu.bottom);
3011 if (winetest_debug > 0) dump_region(hrgn);
3012 SetRect(&rc2, 0, 0, 100, 100);
3013 ok(EqualRect(&rcu, &rc2), "rects do not match (%ld,%ld-%ld,%ld) / (%ld,%ld-%ld,%ld)\n",
3014 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3016 SetRectRgn( exprgn, 0, 0, 20, 80);
3017 SetRectRgn( tmprgn, 0, 80, 100, 100);
3018 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3019 if (winetest_debug > 0) dump_region(exprgn);
3020 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3021 /* test clip rect > scroll rect */
3022 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3024 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3025 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3026 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3027 SetRectRgn( exprgn, 25, 25, 75, 35);
3028 SetRectRgn( tmprgn, 25, 35, 35, 75);
3029 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3030 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3031 colr = GetPixel( hdc, 80, 80);
3032 ok ( colr == 0, "pixel should be black, color is %08lx\n", colr);
3033 trace("update rect: %ld,%ld - %ld,%ld\n",
3034 rcu.left, rcu.top, rcu.right, rcu.bottom);
3035 if (winetest_debug > 0) dump_region(hrgn);
3039 DeleteObject(exprgn);
3040 DeleteObject(tmprgn);
3041 DestroyWindow(hwnd1);
3044 static void test_params(void)
3049 /* Just a param check */
3050 SetLastError(0xdeadbeef);
3051 rc = GetWindowText(hwndMain2, NULL, 1024);
3052 ok( rc==0, "GetWindowText: rc=%d err=%ld\n",rc,GetLastError());
3054 SetLastError(0xdeadbeef);
3055 hwnd=CreateWindow("LISTBOX", "TestList",
3056 (LBS_STANDARD & ~LBS_SORT),
3058 NULL, (HMENU)1, NULL, 0);
3060 ok(!hwnd, "CreateWindow with invalid menu handle should fail\n");
3061 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3062 GetLastError() == 0xdeadbeef, /* Win9x */
3063 "wrong last error value %ld\n", GetLastError());
3066 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3070 hwnd = CreateWindowEx(exStyle, class, class, style,
3077 trace("Failed to create window class=%s, style=0x%08lx, exStyle=0x%08lx\n", class, style, exStyle);
3080 ShowWindow(hwnd, SW_SHOW);
3082 test_nonclient_area(hwnd);
3085 DestroyWindow(hwnd);
3088 static BOOL AWR_init(void)
3092 class.style = CS_HREDRAW | CS_VREDRAW;
3093 class.lpfnWndProc = DefWindowProcA;
3094 class.cbClsExtra = 0;
3095 class.cbWndExtra = 0;
3096 class.hInstance = 0;
3097 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3098 class.hCursor = LoadCursor (0, IDC_ARROW);
3099 class.hbrBackground = 0;
3100 class.lpszMenuName = 0;
3101 class.lpszClassName = szAWRClass;
3103 if (!RegisterClass (&class)) {
3104 ok(FALSE, "RegisterClass failed\n");
3108 hmenu = CreateMenu();
3111 ok(hmenu != 0, "Failed to create menu\n");
3112 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3118 static void test_AWR_window_size(BOOL menu)
3122 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3125 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3126 WS_HSCROLL, WS_VSCROLL
3130 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3133 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3134 WS_EX_DLGMODALFRAME,
3141 /* A exhaustive check of all the styles takes too long
3142 * so just do a (hopefully representative) sample
3144 for (i = 0; i < COUNTOF(styles); ++i)
3145 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3146 for (i = 0; i < COUNTOF(exStyles); ++i) {
3147 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3148 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3153 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3155 static void test_AdjustWindowRect(void)
3160 SHOWSYSMETRIC(SM_CYCAPTION);
3161 SHOWSYSMETRIC(SM_CYSMCAPTION);
3162 SHOWSYSMETRIC(SM_CYMENU);
3163 SHOWSYSMETRIC(SM_CXEDGE);
3164 SHOWSYSMETRIC(SM_CYEDGE);
3165 SHOWSYSMETRIC(SM_CXVSCROLL);
3166 SHOWSYSMETRIC(SM_CYHSCROLL);
3167 SHOWSYSMETRIC(SM_CXFRAME);
3168 SHOWSYSMETRIC(SM_CYFRAME);
3169 SHOWSYSMETRIC(SM_CXDLGFRAME);
3170 SHOWSYSMETRIC(SM_CYDLGFRAME);
3171 SHOWSYSMETRIC(SM_CXBORDER);
3172 SHOWSYSMETRIC(SM_CYBORDER);
3174 test_AWR_window_size(FALSE);
3175 test_AWR_window_size(TRUE);
3179 #undef SHOWSYSMETRIC
3182 /* Global variables to trigger exit from loop */
3183 static int redrawComplete, WMPAINT_count;
3185 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3190 trace("doing WM_PAINT %d\n", WMPAINT_count);
3192 if (WMPAINT_count > 10 && redrawComplete == 0) {
3194 BeginPaint(hwnd, &ps);
3195 EndPaint(hwnd, &ps);
3201 return DefWindowProc(hwnd, msg, wparam, lparam);
3204 /* Ensure we exit from RedrawNow regardless of invalidated area */
3205 static void test_redrawnow(void)
3210 cls.style = CS_DBLCLKS;
3211 cls.lpfnWndProc = redraw_window_procA;
3214 cls.hInstance = GetModuleHandleA(0);
3216 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3217 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3218 cls.lpszMenuName = NULL;
3219 cls.lpszClassName = "RedrawWindowClass";
3221 if(!RegisterClassA(&cls)) {
3222 trace("Register failed %ld\n", GetLastError());
3226 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3227 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3229 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3230 ShowWindow(hwndMain, SW_SHOW);
3231 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3232 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3233 ok( WMPAINT_count == 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3234 redrawComplete = TRUE;
3235 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3238 DestroyWindow( hwndMain);
3241 struct parentdc_stat {
3247 struct parentdc_test {
3248 struct parentdc_stat main, main_todo;
3249 struct parentdc_stat child1, child1_todo;
3250 struct parentdc_stat child2, child2_todo;
3253 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3258 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3263 trace("doing WM_PAINT on %p\n", hwnd);
3264 GetClientRect(hwnd, &rc);
3265 CopyRect(&t->client, &rc);
3266 trace("client rect (%ld, %ld)-(%ld, %ld)\n", rc.left, rc.top, rc.right, rc.bottom);
3267 GetWindowRect(hwnd, &rc);
3268 trace("window rect (%ld, %ld)-(%ld, %ld)\n", rc.left, rc.top, rc.right, rc.bottom);
3269 BeginPaint(hwnd, &ps);
3270 CopyRect(&t->paint, &ps.rcPaint);
3271 GetClipBox(ps.hdc, &rc);
3272 CopyRect(&t->clip, &rc);
3273 trace("clip rect (%ld, %ld)-(%ld, %ld)\n", rc.left, rc.top, rc.right, rc.bottom);
3274 trace("paint rect (%ld, %ld)-(%ld, %ld)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3275 EndPaint(hwnd, &ps);
3278 return DefWindowProc(hwnd, msg, wparam, lparam);
3281 static void zero_parentdc_stat(struct parentdc_stat *t)
3283 SetRectEmpty(&t->client);
3284 SetRectEmpty(&t->clip);
3285 SetRectEmpty(&t->paint);
3288 static void zero_parentdc_test(struct parentdc_test *t)
3290 zero_parentdc_stat(&t->main);
3291 zero_parentdc_stat(&t->child1);
3292 zero_parentdc_stat(&t->child2);
3295 #define parentdc_field_ok(t, w, r, f, got) \
3296 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3297 ": expected %ld, got %ld\n", \
3300 #define parentdc_todo_field_ok(t, w, r, f, got) \
3301 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3302 else parentdc_field_ok(t, w, r, f, got)
3304 #define parentdc_rect_ok(t, w, r, got) \
3305 parentdc_todo_field_ok(t, w, r, left, got); \
3306 parentdc_todo_field_ok(t, w, r, top, got); \
3307 parentdc_todo_field_ok(t, w, r, right, got); \
3308 parentdc_todo_field_ok(t, w, r, bottom, got);
3310 #define parentdc_win_ok(t, w, got) \
3311 parentdc_rect_ok(t, w, client, got); \
3312 parentdc_rect_ok(t, w, clip, got); \
3313 parentdc_rect_ok(t, w, paint, got);
3315 #define parentdc_ok(t, got) \
3316 parentdc_win_ok(t, main, got); \
3317 parentdc_win_ok(t, child1, got); \
3318 parentdc_win_ok(t, child2, got);
3320 static void test_csparentdc(void)
3322 WNDCLASSA clsMain, cls;
3323 HWND hwndMain, hwnd1, hwnd2;
3327 struct parentdc_test test_answer;
3329 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3330 const struct parentdc_test test1 =
3332 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
3333 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3334 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3337 const struct parentdc_test test2 =
3339 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
3340 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3341 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3344 const struct parentdc_test test3 =
3346 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3347 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3348 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3351 const struct parentdc_test test4 =
3353 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
3354 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
3355 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3358 const struct parentdc_test test5 =
3360 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
3361 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3362 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3365 const struct parentdc_test test6 =
3367 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3368 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3369 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3372 const struct parentdc_test test7 =
3374 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3375 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3376 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3380 clsMain.style = CS_DBLCLKS;
3381 clsMain.lpfnWndProc = parentdc_window_procA;
3382 clsMain.cbClsExtra = 0;
3383 clsMain.cbWndExtra = 0;
3384 clsMain.hInstance = GetModuleHandleA(0);
3386 clsMain.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3387 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
3388 clsMain.lpszMenuName = NULL;
3389 clsMain.lpszClassName = "ParentDcMainWindowClass";
3391 if(!RegisterClassA(&clsMain)) {
3392 trace("Register failed %ld\n", GetLastError());
3396 cls.style = CS_DBLCLKS | CS_PARENTDC;
3397 cls.lpfnWndProc = parentdc_window_procA;
3400 cls.hInstance = GetModuleHandleA(0);
3402 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3403 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3404 cls.lpszMenuName = NULL;
3405 cls.lpszClassName = "ParentDcWindowClass";
3407 if(!RegisterClassA(&cls)) {
3408 trace("Register failed %ld\n", GetLastError());
3412 SetRect(&rc, 0, 0, 150, 150);
3413 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
3414 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3415 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
3416 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
3417 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
3418 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
3419 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
3420 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
3421 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
3422 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
3423 ShowWindow(hwndMain, SW_SHOW);
3424 ShowWindow(hwnd1, SW_SHOW);
3425 ShowWindow(hwnd2, SW_SHOW);
3427 zero_parentdc_test(&test_answer);
3428 InvalidateRect(hwndMain, NULL, TRUE);
3429 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3430 parentdc_ok(test1, test_answer);
3432 zero_parentdc_test(&test_answer);
3433 SetRect(&rc, 0, 0, 50, 50);
3434 InvalidateRect(hwndMain, &rc, TRUE);
3435 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3436 parentdc_ok(test2, test_answer);
3438 zero_parentdc_test(&test_answer);
3439 SetRect(&rc, 0, 0, 10, 10);
3440 InvalidateRect(hwndMain, &rc, TRUE);
3441 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3442 parentdc_ok(test3, test_answer);
3444 zero_parentdc_test(&test_answer);
3445 SetRect(&rc, 40, 40, 50, 50);
3446 InvalidateRect(hwndMain, &rc, TRUE);
3447 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3448 parentdc_ok(test4, test_answer);
3450 zero_parentdc_test(&test_answer);
3451 SetRect(&rc, 20, 20, 60, 60);
3452 InvalidateRect(hwndMain, &rc, TRUE);
3453 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3454 parentdc_ok(test5, test_answer);
3456 zero_parentdc_test(&test_answer);
3457 SetRect(&rc, 0, 0, 10, 10);
3458 InvalidateRect(hwnd1, &rc, TRUE);
3459 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3460 parentdc_ok(test6, test_answer);
3462 zero_parentdc_test(&test_answer);
3463 SetRect(&rc, -5, -5, 65, 65);
3464 InvalidateRect(hwnd1, &rc, TRUE);
3465 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3466 parentdc_ok(test7, test_answer);
3468 DestroyWindow(hwndMain);
3469 DestroyWindow(hwnd1);
3470 DestroyWindow(hwnd2);
3473 static void test_IsWindowUnicode(void)
3475 static const char ansi_class_nameA[] = "ansi class name";
3476 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3477 static const char unicode_class_nameA[] = "unicode class name";
3478 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3483 memset(&classW, 0, sizeof(classW));
3484 classW.hInstance = GetModuleHandleA(0);
3485 classW.lpfnWndProc = DefWindowProcW;
3486 classW.lpszClassName = unicode_class_nameW;
3487 if (!RegisterClassW(&classW)) return;
3489 memset(&classA, 0, sizeof(classA));
3490 classA.hInstance = GetModuleHandleA(0);
3491 classA.lpfnWndProc = DefWindowProcA;
3492 classA.lpszClassName = ansi_class_nameA;
3493 assert(RegisterClassA(&classA));
3495 /* unicode class: window proc */
3496 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3497 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3500 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3501 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3502 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3503 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3504 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3506 DestroyWindow(hwnd);
3508 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3509 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3512 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3513 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3514 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3515 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3516 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3518 DestroyWindow(hwnd);
3520 /* ansi class: window proc */
3521 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3522 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3525 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3526 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3527 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3528 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3529 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3531 DestroyWindow(hwnd);
3533 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3534 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3537 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3538 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3539 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3540 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3541 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3543 DestroyWindow(hwnd);
3545 /* unicode class: class proc */
3546 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3547 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3550 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3551 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3552 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3553 /* do not restore class window proc back to unicode */
3555 DestroyWindow(hwnd);
3557 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3558 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3561 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3562 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3563 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3565 DestroyWindow(hwnd);
3567 /* ansi class: class proc */
3568 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3569 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3572 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3573 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3574 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3575 /* do not restore class window proc back to ansi */
3577 DestroyWindow(hwnd);
3579 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3580 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3583 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3584 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3585 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3587 DestroyWindow(hwnd);
3592 pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
3593 pGetWindowInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
3595 hwndMain = CreateWindowExA(0, "static", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, NULL);
3598 ok(!GetParent(hwndMain), "GetParent should return 0 for message only windows\n");
3601 hwndMessage = pGetAncestor(hwndMain, GA_PARENT);
3602 ok(hwndMessage != 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
3603 trace("hwndMessage %p\n", hwndMessage);
3605 DestroyWindow(hwndMain);
3608 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
3610 if (!RegisterWindowClasses()) assert(0);
3612 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
3615 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
3616 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3617 WS_MAXIMIZEBOX | WS_POPUP,
3620 test_nonclient_area(hwndMain);
3622 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
3623 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3624 WS_MAXIMIZEBOX | WS_POPUP,
3628 assert( hwndMain2 );
3630 /* Add the tests below this line */
3635 test_capture_3(hwndMain, hwndMain2);
3637 test_parent_owner();
3639 test_shell_window();
3643 test_SetWindowPos(hwndMain);
3644 test_SetMenu(hwndMain);
3645 test_SetFocus(hwndMain);
3646 test_SetActiveWindow(hwndMain);
3648 test_children_zorder(hwndMain);
3649 test_keyboard_input(hwndMain);
3650 test_mouse_input(hwndMain);
3651 test_validatergn(hwndMain);
3652 test_nccalcscroll( hwndMain);
3653 test_scrollvalidate( hwndMain);
3654 test_scrolldc( hwndMain);
3656 test_IsWindowUnicode();
3657 test_vis_rgn(hwndMain);
3659 test_AdjustWindowRect();
3660 test_window_styles();
3664 /* add the tests above this line */
3665 UnhookWindowsHookEx(hhook);