push b59ba84f7e04af9ef068bd4c6e96701941f0256e
[wine/hacks.git] / dlls / user32 / tests / win.c
blobd0a9673f428c444ecbbe93008afb048a979de3c9
1 /*
2 * Unit tests for window handling
4 * Copyright 2002 Bill Medland
5 * Copyright 2002 Alexandre Julliard
6 * Copyright 2003 Dmitry Timoshkov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 /* To get ICON_SMALL2 with the MSVC headers */
24 #define _WIN32_WINNT 0x0501
26 #include <assert.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <stdio.h>
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "winuser.h"
36 #include "wine/test.h"
38 #ifndef SPI_GETDESKWALLPAPER
39 #define SPI_GETDESKWALLPAPER 0x0073
40 #endif
42 #define LONG_PTR INT_PTR
43 #define ULONG_PTR UINT_PTR
45 void dump_region(HRGN hrgn);
47 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
48 static BOOL (WINAPI *pGetWindowInfo)(HWND,WINDOWINFO*);
50 static BOOL test_lbuttondown_flag;
51 static HWND hwndMessage;
52 static HWND hwndMain, hwndMain2;
53 static HHOOK hhook;
55 static const char* szAWRClass = "Winsize";
56 static HMENU hmenu;
58 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
60 /* try to make sure pending X events have been processed before continuing */
61 static void flush_events(void)
63 MSG msg;
64 int diff = 200;
65 DWORD time = GetTickCount() + diff;
67 while (diff > 0)
69 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min(10,diff), QS_ALLINPUT ) == WAIT_TIMEOUT) break;
70 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
71 diff = time - GetTickCount();
75 /* check the values returned by the various parent/owner functions on a given window */
76 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
77 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
79 HWND res;
81 if (pGetAncestor)
83 res = pGetAncestor( hwnd, GA_PARENT );
84 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
86 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
87 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
88 res = GetParent( hwnd );
89 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
90 res = GetWindow( hwnd, GW_OWNER );
91 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
92 if (pGetAncestor)
94 res = pGetAncestor( hwnd, GA_ROOT );
95 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
96 res = pGetAncestor( hwnd, GA_ROOTOWNER );
97 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
101 static BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
103 (*(LPINT)lParam)++;
104 trace("EnumChildProc on %p\n", hwndChild);
105 if (*(LPINT)lParam > 1) return FALSE;
106 return TRUE;
109 /* will search for the given window */
110 static BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
112 trace("EnumChildProc1 on %p\n", hwndChild);
113 if ((HWND)lParam == hwndChild) return FALSE;
114 return TRUE;
117 static HWND create_tool_window( LONG style, HWND parent )
119 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
120 0, 0, 100, 100, parent, 0, 0, NULL );
121 ok( ret != 0, "Creation failed\n" );
122 return ret;
125 /* test parent and owner values for various combinations */
126 static void test_parent_owner(void)
128 LONG style;
129 HWND test, owner, ret;
130 HWND desktop = GetDesktopWindow();
131 HWND child = create_tool_window( WS_CHILD, hwndMain );
132 INT numChildren;
134 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
136 /* child without parent, should fail */
137 SetLastError(0xdeadbeef);
138 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
139 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
140 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD, "CreateWindowExA should call SetLastError\n" );
141 ok( !test, "WS_CHILD without parent created\n" );
143 /* desktop window */
144 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
145 style = GetWindowLongA( desktop, GWL_STYLE );
146 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
147 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
148 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
150 /* normal child window */
151 test = create_tool_window( WS_CHILD, hwndMain );
152 trace( "created child %p\n", test );
153 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
154 SetWindowLongA( test, GWL_STYLE, 0 );
155 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
156 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
157 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
158 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
159 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
160 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
161 DestroyWindow( test );
163 /* normal child window with WS_MAXIMIZE */
164 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
165 DestroyWindow( test );
167 /* normal child window with WS_THICKFRAME */
168 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
169 DestroyWindow( test );
171 /* popup window with WS_THICKFRAME */
172 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
173 DestroyWindow( test );
175 /* child of desktop */
176 test = create_tool_window( WS_CHILD, desktop );
177 trace( "created child of desktop %p\n", test );
178 check_parents( test, desktop, 0, desktop, 0, test, desktop );
179 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
180 check_parents( test, desktop, 0, 0, 0, test, test );
181 SetWindowLongA( test, GWL_STYLE, 0 );
182 check_parents( test, desktop, 0, 0, 0, test, test );
183 DestroyWindow( test );
185 /* child of desktop with WS_MAXIMIZE */
186 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
187 DestroyWindow( test );
189 /* child of desktop with WS_MINIMIZE */
190 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
191 DestroyWindow( test );
193 /* child of child */
194 test = create_tool_window( WS_CHILD, child );
195 trace( "created child of child %p\n", test );
196 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
197 SetWindowLongA( test, GWL_STYLE, 0 );
198 check_parents( test, child, child, 0, 0, hwndMain, test );
199 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
200 check_parents( test, child, child, 0, 0, hwndMain, test );
201 DestroyWindow( test );
203 /* child of child with WS_MAXIMIZE */
204 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
205 DestroyWindow( test );
207 /* child of child with WS_MINIMIZE */
208 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
209 DestroyWindow( test );
211 /* not owned top-level window */
212 test = create_tool_window( 0, 0 );
213 trace( "created top-level %p\n", test );
214 check_parents( test, desktop, 0, 0, 0, test, test );
215 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
216 check_parents( test, desktop, 0, 0, 0, test, test );
217 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
218 check_parents( test, desktop, 0, desktop, 0, test, desktop );
219 DestroyWindow( test );
221 /* not owned top-level window with WS_MAXIMIZE */
222 test = create_tool_window( WS_MAXIMIZE, 0 );
223 DestroyWindow( test );
225 /* owned top-level window */
226 test = create_tool_window( 0, hwndMain );
227 trace( "created owned top-level %p\n", test );
228 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
229 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
230 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
231 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
232 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
233 DestroyWindow( test );
235 /* owned top-level window with WS_MAXIMIZE */
236 test = create_tool_window( WS_MAXIMIZE, hwndMain );
237 DestroyWindow( test );
239 /* not owned popup */
240 test = create_tool_window( WS_POPUP, 0 );
241 trace( "created popup %p\n", test );
242 check_parents( test, desktop, 0, 0, 0, test, test );
243 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
244 check_parents( test, desktop, 0, desktop, 0, test, desktop );
245 SetWindowLongA( test, GWL_STYLE, 0 );
246 check_parents( test, desktop, 0, 0, 0, test, test );
247 DestroyWindow( test );
249 /* not owned popup with WS_MAXIMIZE */
250 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
251 DestroyWindow( test );
253 /* owned popup */
254 test = create_tool_window( WS_POPUP, hwndMain );
255 trace( "created owned popup %p\n", test );
256 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
257 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
258 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
259 SetWindowLongA( test, GWL_STYLE, 0 );
260 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
261 DestroyWindow( test );
263 /* owned popup with WS_MAXIMIZE */
264 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
265 DestroyWindow( test );
267 /* top-level window owned by child (same as owned by top-level) */
268 test = create_tool_window( 0, child );
269 trace( "created top-level owned by child %p\n", test );
270 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
271 DestroyWindow( test );
273 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
274 test = create_tool_window( WS_MAXIMIZE, child );
275 DestroyWindow( test );
277 /* popup owned by desktop (same as not owned) */
278 test = create_tool_window( WS_POPUP, desktop );
279 trace( "created popup owned by desktop %p\n", test );
280 check_parents( test, desktop, 0, 0, 0, test, test );
281 DestroyWindow( test );
283 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
284 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
285 DestroyWindow( test );
287 /* popup owned by child (same as owned by top-level) */
288 test = create_tool_window( WS_POPUP, child );
289 trace( "created popup owned by child %p\n", test );
290 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
291 DestroyWindow( test );
293 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
294 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
295 DestroyWindow( test );
297 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
298 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
299 trace( "created WS_CHILD popup %p\n", test );
300 check_parents( test, desktop, 0, 0, 0, test, test );
301 DestroyWindow( test );
303 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
304 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
305 DestroyWindow( test );
307 /* owned popup with WS_CHILD (same as WS_POPUP only) */
308 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
309 trace( "created owned WS_CHILD popup %p\n", test );
310 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
311 DestroyWindow( test );
313 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
314 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
315 DestroyWindow( test );
317 /******************** parent changes *************************/
318 trace( "testing parent changes\n" );
320 /* desktop window */
321 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
322 if (0)
324 /* this test succeeds on NT but crashes on win9x systems */
325 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
326 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
327 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
328 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
329 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
331 /* normal child window */
332 test = create_tool_window( WS_CHILD, hwndMain );
333 trace( "created child %p\n", test );
335 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
336 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
337 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
339 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
340 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
341 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
343 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
344 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
345 check_parents( test, desktop, 0, desktop, 0, test, desktop );
347 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
348 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
349 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
350 check_parents( test, desktop, child, desktop, child, test, desktop );
352 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
353 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
354 check_parents( test, desktop, 0, desktop, 0, test, desktop );
355 DestroyWindow( test );
357 /* not owned top-level window */
358 test = create_tool_window( 0, 0 );
359 trace( "created top-level %p\n", test );
361 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
362 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
363 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
365 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
366 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
367 check_parents( test, desktop, child, 0, child, test, test );
369 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
370 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
371 check_parents( test, desktop, 0, 0, 0, test, test );
372 DestroyWindow( test );
374 /* not owned popup */
375 test = create_tool_window( WS_POPUP, 0 );
376 trace( "created popup %p\n", test );
378 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
379 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
380 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
382 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
383 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
384 check_parents( test, desktop, child, child, child, test, hwndMain );
386 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
387 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
388 check_parents( test, desktop, 0, 0, 0, test, test );
389 DestroyWindow( test );
391 /* normal child window */
392 test = create_tool_window( WS_CHILD, hwndMain );
393 trace( "created child %p\n", test );
395 ret = SetParent( test, desktop );
396 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
397 check_parents( test, desktop, 0, desktop, 0, test, desktop );
399 ret = SetParent( test, child );
400 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
401 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
403 ret = SetParent( test, hwndMain2 );
404 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
405 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
406 DestroyWindow( test );
408 /* not owned top-level window */
409 test = create_tool_window( 0, 0 );
410 trace( "created top-level %p\n", test );
412 ret = SetParent( test, child );
413 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
414 check_parents( test, child, child, 0, 0, hwndMain, test );
415 DestroyWindow( test );
417 /* owned popup */
418 test = create_tool_window( WS_POPUP, hwndMain2 );
419 trace( "created owned popup %p\n", test );
421 ret = SetParent( test, child );
422 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
423 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
425 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
426 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
427 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
428 DestroyWindow( test );
430 /**************** test owner destruction *******************/
432 /* owned child popup */
433 owner = create_tool_window( 0, 0 );
434 test = create_tool_window( WS_POPUP, owner );
435 trace( "created owner %p and popup %p\n", owner, test );
436 ret = SetParent( test, child );
437 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
438 check_parents( test, child, child, owner, owner, hwndMain, owner );
439 /* window is now child of 'child' but owned by 'owner' */
440 DestroyWindow( owner );
441 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
442 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
443 * while Win95, Win2k, WinXP do.
445 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
446 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
447 DestroyWindow(test);
449 /* owned top-level popup */
450 owner = create_tool_window( 0, 0 );
451 test = create_tool_window( WS_POPUP, owner );
452 trace( "created owner %p and popup %p\n", owner, test );
453 check_parents( test, desktop, owner, owner, owner, test, owner );
454 DestroyWindow( owner );
455 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
457 /* top-level popup owned by child */
458 owner = create_tool_window( WS_CHILD, hwndMain2 );
459 test = create_tool_window( WS_POPUP, 0 );
460 trace( "created owner %p and popup %p\n", owner, test );
461 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
462 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
463 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
464 DestroyWindow( owner );
465 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
466 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
467 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
468 * while Win95, Win2k, WinXP do.
470 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
471 DestroyWindow(test);
473 /* final cleanup */
474 DestroyWindow(child);
477 owner = create_tool_window( WS_OVERLAPPED, 0 );
478 test = create_tool_window( WS_POPUP, desktop );
480 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
481 numChildren = 0;
482 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
483 "EnumChildWindows should have returned FALSE\n" );
484 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
486 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
487 ret = SetParent( test, owner );
488 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
490 numChildren = 0;
491 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
492 "EnumChildWindows should have returned TRUE\n" );
493 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
495 child = create_tool_window( WS_CHILD, owner );
496 numChildren = 0;
497 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
498 "EnumChildWindows should have returned FALSE\n" );
499 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
500 DestroyWindow( child );
502 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
503 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
504 numChildren = 0;
505 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
506 "EnumChildWindows should have returned TRUE\n" );
507 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
509 ret = SetParent( child, owner );
510 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
511 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
512 numChildren = 0;
513 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
514 "EnumChildWindows should have returned FALSE\n" );
515 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
517 ret = SetParent( child, NULL );
518 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
519 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
520 numChildren = 0;
521 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
522 "EnumChildWindows should have returned TRUE\n" );
523 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
525 /* even GW_OWNER == owner it's still a desktop's child */
526 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
527 "EnumChildWindows should have found %p and returned FALSE\n", child );
529 DestroyWindow( child );
530 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
532 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
533 "EnumChildWindows should have found %p and returned FALSE\n", child );
535 DestroyWindow( child );
536 DestroyWindow( test );
537 DestroyWindow( owner );
541 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
543 switch (msg)
545 case WM_GETMINMAXINFO:
547 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
549 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
550 trace("ptReserved (%d,%d), ptMaxSize (%d,%d), ptMaxPosition (%d,%d)\n"
551 " ptMinTrackSize (%d,%d), ptMaxTrackSize (%d,%d)\n",
552 minmax->ptReserved.x, minmax->ptReserved.y,
553 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
554 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
555 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
556 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
557 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
558 break;
560 case WM_WINDOWPOSCHANGING:
562 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
563 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
564 trace("main: WM_WINDOWPOSCHANGING\n");
565 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
566 winpos->hwnd, winpos->hwndInsertAfter,
567 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
568 if (!(winpos->flags & SWP_NOMOVE))
570 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
571 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
573 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
574 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
576 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
577 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
579 break;
581 case WM_WINDOWPOSCHANGED:
583 RECT rc1, rc2;
584 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
585 trace("main: WM_WINDOWPOSCHANGED\n");
586 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
587 winpos->hwnd, winpos->hwndInsertAfter,
588 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
589 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
590 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
592 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
593 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
595 GetWindowRect(hwnd, &rc1);
596 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
597 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
598 /* note: winpos coordinates are relative to parent */
599 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
600 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
601 if (0)
603 /* Uncomment this once the test succeeds in all cases */
604 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
607 GetClientRect(hwnd, &rc2);
608 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
609 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
610 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
611 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
612 break;
614 case WM_NCCREATE:
616 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
617 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
619 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
620 if (got_getminmaxinfo)
621 trace("%p got WM_GETMINMAXINFO\n", hwnd);
623 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
624 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
625 else
626 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
627 break;
629 case WM_COMMAND:
630 if (test_lbuttondown_flag)
631 ShowWindow((HWND)wparam, SW_SHOW);
632 break;
635 return DefWindowProcA(hwnd, msg, wparam, lparam);
638 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
640 switch (msg)
642 case WM_GETMINMAXINFO:
644 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
646 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
647 trace("ptReserved (%d,%d), ptMaxSize (%d,%d), ptMaxPosition (%d,%d)\n"
648 " ptMinTrackSize (%d,%d), ptMaxTrackSize (%d,%d)\n",
649 minmax->ptReserved.x, minmax->ptReserved.y,
650 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
651 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
652 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
653 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
654 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
655 break;
657 case WM_NCCREATE:
659 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
660 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
662 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
663 if (got_getminmaxinfo)
664 trace("%p got WM_GETMINMAXINFO\n", hwnd);
666 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
667 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
668 else
669 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
670 break;
674 return DefWindowProcA(hwnd, msg, wparam, lparam);
677 static BOOL RegisterWindowClasses(void)
679 WNDCLASSA cls;
681 cls.style = CS_DBLCLKS;
682 cls.lpfnWndProc = main_window_procA;
683 cls.cbClsExtra = 0;
684 cls.cbWndExtra = 0;
685 cls.hInstance = GetModuleHandleA(0);
686 cls.hIcon = 0;
687 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
688 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
689 cls.lpszMenuName = NULL;
690 cls.lpszClassName = "MainWindowClass";
692 if(!RegisterClassA(&cls)) return FALSE;
694 cls.style = 0;
695 cls.lpfnWndProc = tool_window_procA;
696 cls.cbClsExtra = 0;
697 cls.cbWndExtra = 0;
698 cls.hInstance = GetModuleHandleA(0);
699 cls.hIcon = 0;
700 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
701 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
702 cls.lpszMenuName = NULL;
703 cls.lpszClassName = "ToolWindowClass";
705 if(!RegisterClassA(&cls)) return FALSE;
707 return TRUE;
710 static void verify_window_info(HWND hwnd, const WINDOWINFO *info)
712 RECT rcWindow, rcClient;
713 DWORD status;
715 ok(IsWindow(hwnd), "bad window handle\n");
717 GetWindowRect(hwnd, &rcWindow);
718 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow\n");
720 GetClientRect(hwnd, &rcClient);
721 /* translate to screen coordinates */
722 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
723 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient\n");
725 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
726 "wrong dwStyle: %08x != %08x\n", info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE));
727 /* Windows reports a not documented exstyle 0x800 in WINDOWINFO, but
728 * doesn't return it in GetWindowLong(hwnd, GWL_EXSTYLE).
730 ok((info->dwExStyle & ~0x800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
731 "wrong dwExStyle: %08x != %08x\n", info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE));
732 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
733 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x\n",
734 info->dwWindowStatus, status);
736 trace("rcWindow: %d,%d - %d,%d\n", rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
737 trace("rcClient: %d,%d - %d,%d\n", rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
739 /* win2k and XP return broken border info in GetWindowInfo most of
740 * the time, so there is no point in testing it.
742 #if 0
743 UINT border;
744 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
745 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
746 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
747 ok(info->cyWindowBorders == border,
748 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
749 #endif
750 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType\n");
751 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
752 info->wCreatorVersion == 0x0500 /* Vista */,
753 "wrong wCreatorVersion %04x\n", info->wCreatorVersion);
756 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
758 AdjustWindowRectEx(rc, style, menu, exstyle);
759 /* AdjustWindowRectEx does not include scroll bars */
760 if (style & WS_VSCROLL)
762 if(exstyle & WS_EX_LEFTSCROLLBAR)
763 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
764 else
765 rc->right += GetSystemMetrics(SM_CXVSCROLL);
767 if (style & WS_HSCROLL)
768 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
771 static void test_nonclient_area(HWND hwnd)
773 DWORD style, exstyle;
774 RECT rc_window, rc_client, rc;
775 BOOL menu;
776 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
778 style = GetWindowLongA(hwnd, GWL_STYLE);
779 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
780 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
782 GetWindowRect(hwnd, &rc_window);
783 trace("window: (%d,%d)-(%d,%d)\n", rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
784 GetClientRect(hwnd, &rc_client);
785 trace("client: (%d,%d)-(%d,%d)\n", rc_client.left, rc_client.top, rc_client.right, rc_client.bottom);
787 /* avoid some cases when things go wrong */
788 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
789 rc_window.right > 32768 || rc_window.bottom > 32768) return;
791 CopyRect(&rc, &rc_client);
792 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
793 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
795 trace("calc window: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
796 ok(EqualRect(&rc, &rc_window), "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
799 CopyRect(&rc, &rc_window);
800 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
801 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
802 trace("calc client: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
803 ok(EqualRect(&rc, &rc_client), "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
805 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
806 if (is_win9x)
807 return;
809 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
810 SetRect(&rc_client, 0, 0, 250, 150);
811 CopyRect(&rc_window, &rc_client);
812 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
813 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
814 trace("calc window: (%d,%d)-(%d,%d)\n",
815 rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
817 CopyRect(&rc, &rc_window);
818 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
819 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
820 trace("calc client: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
821 ok(EqualRect(&rc, &rc_client), "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
824 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
826 static const char *CBT_code_name[10] = {
827 "HCBT_MOVESIZE",
828 "HCBT_MINMAX",
829 "HCBT_QS",
830 "HCBT_CREATEWND",
831 "HCBT_DESTROYWND",
832 "HCBT_ACTIVATE",
833 "HCBT_CLICKSKIPPED",
834 "HCBT_KEYSKIPPED",
835 "HCBT_SYSCOMMAND",
836 "HCBT_SETFOCUS" };
837 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
839 trace("CBT: %d (%s), %08lx, %08lx\n", nCode, code_name, wParam, lParam);
841 /* on HCBT_DESTROYWND window state is undefined */
842 if (nCode != HCBT_DESTROYWND && IsWindow((HWND)wParam))
844 if (pGetWindowInfo)
846 WINDOWINFO info;
848 /* Win98 actually does check the info.cbSize and doesn't allow
849 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
850 * WinXP do not check it at all.
852 info.cbSize = sizeof(WINDOWINFO);
853 ok(pGetWindowInfo((HWND)wParam, &info), "GetWindowInfo should not fail\n");
854 verify_window_info((HWND)wParam, &info);
858 switch (nCode)
860 case HCBT_CREATEWND:
862 static const RECT rc_null;
863 RECT rc;
864 LONG style;
865 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
866 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
867 (HWND)wParam, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
868 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
870 /* WS_VISIBLE should be turned off yet */
871 style = createwnd->lpcs->style & ~WS_VISIBLE;
872 ok(style == GetWindowLongA((HWND)wParam, GWL_STYLE),
873 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
874 GetWindowLongA((HWND)wParam, GWL_STYLE), style);
876 if (0)
878 /* Uncomment this once the test succeeds in all cases */
879 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
881 ok(GetParent((HWND)wParam) == hwndMessage,
882 "wrong result from GetParent %p: message window %p\n",
883 GetParent((HWND)wParam), hwndMessage);
885 else
886 ok(!GetParent((HWND)wParam), "GetParent should return 0 at this point\n");
888 ok(!GetWindow((HWND)wParam, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
890 if (0)
892 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
893 * Win9x still has them set to 0.
895 ok(GetWindow((HWND)wParam, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
896 ok(GetWindow((HWND)wParam, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
898 ok(!GetWindow((HWND)wParam, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
899 ok(!GetWindow((HWND)wParam, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
901 if (0)
903 /* Uncomment this once the test succeeds in all cases */
904 if (pGetAncestor)
906 ok(pGetAncestor((HWND)wParam, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
907 ok(pGetAncestor((HWND)wParam, GA_ROOT) == (HWND)wParam,
908 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOT), (HWND)wParam);
910 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
911 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == hwndMessage,
912 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
913 else
914 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == (HWND)wParam,
915 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOTOWNER), (HWND)wParam);
918 ok(GetWindowRect((HWND)wParam, &rc), "GetWindowRect failed\n");
919 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
920 ok(GetClientRect((HWND)wParam, &rc), "GetClientRect failed\n");
921 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
923 break;
927 return CallNextHookEx(hhook, nCode, wParam, lParam);
930 static void test_shell_window(void)
932 BOOL ret;
933 DWORD error;
934 HMODULE hinst, hUser32;
935 BOOL (WINAPI*SetShellWindow)(HWND);
936 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
937 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
938 HWND shellWindow, nextWnd;
940 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
942 trace("Skipping shell window test on Win9x\n");
943 return;
946 shellWindow = GetShellWindow();
947 hinst = GetModuleHandle(0);
948 hUser32 = GetModuleHandleA("user32");
950 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
951 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
953 trace("previous shell window: %p\n", shellWindow);
955 if (shellWindow) {
956 DWORD pid;
957 HANDLE hProcess;
959 ret = DestroyWindow(shellWindow);
960 error = GetLastError();
962 ok(!ret, "DestroyWindow(shellWindow)\n");
963 /* passes on Win XP, but not on Win98 */
964 ok(error==ERROR_ACCESS_DENIED, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n");
966 /* close old shell instance */
967 GetWindowThreadProcessId(shellWindow, &pid);
968 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
969 ret = TerminateProcess(hProcess, 0);
970 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
971 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
972 CloseHandle(hProcess);
975 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
976 trace("created window 1: %p\n", hwnd1);
978 ret = SetShellWindow(hwnd1);
979 ok(ret, "first call to SetShellWindow(hwnd1)\n");
980 shellWindow = GetShellWindow();
981 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
983 ret = SetShellWindow(hwnd1);
984 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
986 ret = SetShellWindow(0);
987 error = GetLastError();
988 /* passes on Win XP, but not on Win98
989 ok(!ret, "reset shell window by SetShellWindow(0)\n");
990 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
992 ret = SetShellWindow(hwnd1);
993 /* passes on Win XP, but not on Win98
994 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
996 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
997 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
998 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1000 ret = DestroyWindow(hwnd1);
1001 ok(ret, "DestroyWindow(hwnd1)\n");
1003 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1004 trace("created window 2: %p\n", hwnd2);
1005 ret = SetShellWindow(hwnd2);
1006 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1008 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1009 trace("created window 3: %p\n", hwnd3);
1011 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1012 trace("created window 4: %p\n", hwnd4);
1014 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1015 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1017 ret = SetShellWindow(hwnd4);
1018 ok(ret, "SetShellWindow(hwnd4)\n");
1019 shellWindow = GetShellWindow();
1020 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1022 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1023 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1025 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1026 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1028 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1029 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1031 ret = SetShellWindow(hwnd3);
1032 ok(!ret, "SetShellWindow(hwnd3)\n");
1033 shellWindow = GetShellWindow();
1034 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1036 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1037 trace("created window 5: %p\n", hwnd5);
1038 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1039 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1041 todo_wine
1043 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1044 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1047 /* destroy test windows */
1048 DestroyWindow(hwnd2);
1049 DestroyWindow(hwnd3);
1050 DestroyWindow(hwnd4);
1051 DestroyWindow(hwnd5);
1054 /************** MDI test ****************/
1056 static char mdi_lParam_test_message[] = "just a test string";
1058 static void test_MDI_create(HWND parent, HWND mdi_client, INT first_id)
1060 MDICREATESTRUCTA mdi_cs;
1061 HWND mdi_child;
1062 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1063 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1064 BOOL isWin9x = FALSE;
1066 mdi_cs.szClass = "MDI_child_Class_1";
1067 mdi_cs.szTitle = "MDI child";
1068 mdi_cs.hOwner = GetModuleHandle(0);
1069 mdi_cs.x = CW_USEDEFAULT;
1070 mdi_cs.y = CW_USEDEFAULT;
1071 mdi_cs.cx = CW_USEDEFAULT;
1072 mdi_cs.cy = CW_USEDEFAULT;
1073 mdi_cs.style = 0;
1074 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1075 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1076 ok(mdi_child != 0, "MDI child creation failed\n");
1077 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1078 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1079 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1081 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1082 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1083 ok(mdi_child != 0, "MDI child creation failed\n");
1084 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1085 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1086 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1088 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1089 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1090 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1092 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1094 else
1096 ok(mdi_child != 0, "MDI child creation failed\n");
1097 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1098 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1099 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1102 /* test MDICREATESTRUCT A<->W mapping */
1103 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1104 mdi_cs.style = 0;
1105 mdi_cs.szClass = (LPCSTR)classW;
1106 mdi_cs.szTitle = (LPCSTR)titleW;
1107 SetLastError(0xdeadbeef);
1108 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1109 if (!mdi_child)
1111 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1112 isWin9x = TRUE;
1113 else
1114 ok(mdi_child != 0, "MDI child creation failed\n");
1116 else
1118 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1119 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1120 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1123 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1125 CW_USEDEFAULT, CW_USEDEFAULT,
1126 CW_USEDEFAULT, CW_USEDEFAULT,
1127 mdi_client, GetModuleHandle(0),
1128 (LPARAM)mdi_lParam_test_message);
1129 ok(mdi_child != 0, "MDI child creation failed\n");
1130 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1131 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1132 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1134 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1135 0x7fffffff, /* without WS_POPUP */
1136 CW_USEDEFAULT, CW_USEDEFAULT,
1137 CW_USEDEFAULT, CW_USEDEFAULT,
1138 mdi_client, GetModuleHandle(0),
1139 (LPARAM)mdi_lParam_test_message);
1140 ok(mdi_child != 0, "MDI child creation failed\n");
1141 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1142 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1143 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1145 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1146 0xffffffff, /* with WS_POPUP */
1147 CW_USEDEFAULT, CW_USEDEFAULT,
1148 CW_USEDEFAULT, CW_USEDEFAULT,
1149 mdi_client, GetModuleHandle(0),
1150 (LPARAM)mdi_lParam_test_message);
1151 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1153 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1155 else
1157 ok(mdi_child != 0, "MDI child creation failed\n");
1158 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\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 /* test MDICREATESTRUCT A<->W mapping */
1164 SetLastError(0xdeadbeef);
1165 mdi_child = CreateMDIWindowW(classW, titleW,
1167 CW_USEDEFAULT, CW_USEDEFAULT,
1168 CW_USEDEFAULT, CW_USEDEFAULT,
1169 mdi_client, GetModuleHandle(0),
1170 (LPARAM)mdi_lParam_test_message);
1171 if (!mdi_child)
1173 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1174 isWin9x = TRUE;
1175 else
1176 ok(mdi_child != 0, "MDI child creation failed\n");
1178 else
1180 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1181 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1182 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1185 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1187 CW_USEDEFAULT, CW_USEDEFAULT,
1188 CW_USEDEFAULT, CW_USEDEFAULT,
1189 mdi_client, 0, GetModuleHandle(0),
1190 (LPVOID)mdi_lParam_test_message);
1191 ok(mdi_child != 0, "MDI child creation failed\n");
1192 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1193 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1194 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1196 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1197 0x7fffffff, /* without WS_POPUP */
1198 CW_USEDEFAULT, CW_USEDEFAULT,
1199 CW_USEDEFAULT, CW_USEDEFAULT,
1200 mdi_client, 0, GetModuleHandle(0),
1201 (LPVOID)mdi_lParam_test_message);
1202 ok(mdi_child != 0, "MDI child creation failed\n");
1203 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1204 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1205 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1207 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1208 0xffffffff, /* with WS_POPUP */
1209 CW_USEDEFAULT, CW_USEDEFAULT,
1210 CW_USEDEFAULT, CW_USEDEFAULT,
1211 mdi_client, 0, GetModuleHandle(0),
1212 (LPVOID)mdi_lParam_test_message);
1213 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1215 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1217 else
1219 ok(mdi_child != 0, "MDI child creation failed\n");
1220 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\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 /* test MDICREATESTRUCT A<->W mapping */
1226 SetLastError(0xdeadbeef);
1227 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1229 CW_USEDEFAULT, CW_USEDEFAULT,
1230 CW_USEDEFAULT, CW_USEDEFAULT,
1231 mdi_client, 0, GetModuleHandle(0),
1232 (LPVOID)mdi_lParam_test_message);
1233 if (!mdi_child)
1235 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1236 isWin9x = TRUE;
1237 else
1238 ok(mdi_child != 0, "MDI child creation failed\n");
1240 else
1242 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1243 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1244 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1247 /* This test fails on Win9x */
1248 if (!isWin9x)
1250 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1251 WS_CHILD,
1252 CW_USEDEFAULT, CW_USEDEFAULT,
1253 CW_USEDEFAULT, CW_USEDEFAULT,
1254 parent, 0, GetModuleHandle(0),
1255 (LPVOID)mdi_lParam_test_message);
1256 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1259 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1260 WS_CHILD, /* without WS_POPUP */
1261 CW_USEDEFAULT, CW_USEDEFAULT,
1262 CW_USEDEFAULT, CW_USEDEFAULT,
1263 mdi_client, 0, GetModuleHandle(0),
1264 (LPVOID)mdi_lParam_test_message);
1265 ok(mdi_child != 0, "MDI child creation failed\n");
1266 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1267 DestroyWindow(mdi_child);
1269 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1270 WS_CHILD | WS_POPUP, /* with WS_POPUP */
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 %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1277 DestroyWindow(mdi_child);
1279 /* maximized child */
1280 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1281 WS_CHILD | WS_MAXIMIZE,
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 %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1288 DestroyWindow(mdi_child);
1290 trace("Creating maximized child with a caption\n");
1291 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1292 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1293 CW_USEDEFAULT, CW_USEDEFAULT,
1294 CW_USEDEFAULT, CW_USEDEFAULT,
1295 mdi_client, 0, GetModuleHandle(0),
1296 (LPVOID)mdi_lParam_test_message);
1297 ok(mdi_child != 0, "MDI child creation failed\n");
1298 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1299 DestroyWindow(mdi_child);
1301 trace("Creating maximized child with a caption and a thick frame\n");
1302 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1303 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1304 CW_USEDEFAULT, CW_USEDEFAULT,
1305 CW_USEDEFAULT, CW_USEDEFAULT,
1306 mdi_client, 0, GetModuleHandle(0),
1307 (LPVOID)mdi_lParam_test_message);
1308 ok(mdi_child != 0, "MDI child creation failed\n");
1309 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1310 DestroyWindow(mdi_child);
1313 /**********************************************************************
1314 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1316 * Note: The rule here is that client rect of the maximized MDI child
1317 * is equal to the client rect of the MDI client window.
1319 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1321 RECT rect;
1323 GetClientRect( client, &rect );
1324 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1325 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1327 rect.right -= rect.left;
1328 rect.bottom -= rect.top;
1329 lpMinMax->ptMaxSize.x = rect.right;
1330 lpMinMax->ptMaxSize.y = rect.bottom;
1332 lpMinMax->ptMaxPosition.x = rect.left;
1333 lpMinMax->ptMaxPosition.y = rect.top;
1335 trace("max rect (%d,%d - %d, %d)\n",
1336 rect.left, rect.top, rect.right, rect.bottom);
1339 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1341 switch (msg)
1343 case WM_NCCREATE:
1344 case WM_CREATE:
1346 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1347 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs->lpCreateParams;
1349 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1350 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1352 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1353 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1354 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1355 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1356 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1358 /* MDICREATESTRUCT should have original values */
1359 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1360 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1361 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1362 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1363 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1364 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1366 /* CREATESTRUCT should have fixed values */
1367 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1368 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1370 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1371 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1372 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1374 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1376 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1378 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1379 ok(cs->style == style,
1380 "cs->style does not match (%08x)\n", cs->style);
1382 else
1384 LONG style = mdi_cs->style;
1385 style &= ~WS_POPUP;
1386 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1387 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1388 ok(cs->style == style,
1389 "cs->style does not match (%08x)\n", cs->style);
1391 break;
1394 case WM_GETMINMAXINFO:
1396 HWND client = GetParent(hwnd);
1397 RECT rc;
1398 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1399 MINMAXINFO my_minmax;
1400 LONG style, exstyle;
1402 style = GetWindowLongA(hwnd, GWL_STYLE);
1403 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1405 GetWindowRect(client, &rc);
1406 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1407 GetClientRect(client, &rc);
1408 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1409 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1410 GetSystemMetrics(SM_CYSCREEN));
1412 GetClientRect(client, &rc);
1413 if ((style & WS_CAPTION) == WS_CAPTION)
1414 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1415 AdjustWindowRectEx(&rc, style, 0, exstyle);
1416 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1418 trace("ptReserved = (%d,%d)\n"
1419 "ptMaxSize = (%d,%d)\n"
1420 "ptMaxPosition = (%d,%d)\n"
1421 "ptMinTrackSize = (%d,%d)\n"
1422 "ptMaxTrackSize = (%d,%d)\n",
1423 minmax->ptReserved.x, minmax->ptReserved.y,
1424 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1425 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1426 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1427 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1429 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1430 minmax->ptMaxSize.x, rc.right - rc.left);
1431 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1432 minmax->ptMaxSize.y, rc.bottom - rc.top);
1434 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1436 trace("DefMDIChildProc returned:\n"
1437 "ptReserved = (%d,%d)\n"
1438 "ptMaxSize = (%d,%d)\n"
1439 "ptMaxPosition = (%d,%d)\n"
1440 "ptMinTrackSize = (%d,%d)\n"
1441 "ptMaxTrackSize = (%d,%d)\n",
1442 minmax->ptReserved.x, minmax->ptReserved.y,
1443 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1444 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1445 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1446 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1448 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1449 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1450 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1451 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1452 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1454 return 1;
1457 case WM_MDIACTIVATE:
1459 HWND active, client = GetParent(hwnd);
1460 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1461 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1462 if (hwnd == (HWND)lparam) /* if we are being activated */
1463 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1464 else
1465 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1466 break;
1469 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1472 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1474 switch (msg)
1476 case WM_NCCREATE:
1477 case WM_CREATE:
1479 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1481 trace("%s\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE");
1482 trace("x %d, y %d, cx %d, cy %d\n", cs->x, cs->y, cs->cx, cs->cy);
1484 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1485 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1487 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1488 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1490 /* CREATESTRUCT should have fixed values */
1491 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1492 while NT does. */
1493 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1494 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1496 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1497 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1498 while Win95, Win2k, WinXP do. */
1499 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1500 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1501 break;
1504 case WM_GETMINMAXINFO:
1506 HWND parent = GetParent(hwnd);
1507 RECT rc;
1508 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1509 LONG style, exstyle;
1511 trace("WM_GETMINMAXINFO\n");
1513 style = GetWindowLongA(hwnd, GWL_STYLE);
1514 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1516 GetClientRect(parent, &rc);
1517 trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1519 GetClientRect(parent, &rc);
1520 if ((style & WS_CAPTION) == WS_CAPTION)
1521 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1522 AdjustWindowRectEx(&rc, style, 0, exstyle);
1523 trace("calculated max child window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1525 trace("ptReserved = (%d,%d)\n"
1526 "ptMaxSize = (%d,%d)\n"
1527 "ptMaxPosition = (%d,%d)\n"
1528 "ptMinTrackSize = (%d,%d)\n"
1529 "ptMaxTrackSize = (%d,%d)\n",
1530 minmax->ptReserved.x, minmax->ptReserved.y,
1531 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1532 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1533 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1534 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1536 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1537 minmax->ptMaxSize.x, rc.right - rc.left);
1538 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1539 minmax->ptMaxSize.y, rc.bottom - rc.top);
1540 break;
1543 case WM_WINDOWPOSCHANGED:
1545 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1546 RECT rc1, rc2;
1548 GetWindowRect(hwnd, &rc1);
1549 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1550 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1551 /* note: winpos coordinates are relative to parent */
1552 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1553 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1554 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1556 GetWindowRect(hwnd, &rc1);
1557 GetClientRect(hwnd, &rc2);
1558 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1559 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1560 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1562 /* fall through */
1563 case WM_WINDOWPOSCHANGING:
1565 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1566 WINDOWPOS my_winpos = *winpos;
1568 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1569 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1570 winpos->hwnd, winpos->hwndInsertAfter,
1571 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1573 DefWindowProcA(hwnd, msg, wparam, lparam);
1575 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1576 winpos->hwnd, winpos->hwndInsertAfter,
1577 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1579 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1580 "DefWindowProc should not change WINDOWPOS values\n");
1582 return 1;
1585 return DefWindowProcA(hwnd, msg, wparam, lparam);
1588 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1590 static HWND mdi_client;
1592 switch (msg)
1594 case WM_CREATE:
1596 CLIENTCREATESTRUCT client_cs;
1597 RECT rc;
1599 GetClientRect(hwnd, &rc);
1601 client_cs.hWindowMenu = 0;
1602 client_cs.idFirstChild = 1;
1604 /* MDIClient without MDIS_ALLCHILDSTYLES */
1605 mdi_client = CreateWindowExA(0, "mdiclient",
1606 NULL,
1607 WS_CHILD /*| WS_VISIBLE*/,
1608 /* tests depend on a not zero MDIClient size */
1609 0, 0, rc.right, rc.bottom,
1610 hwnd, 0, GetModuleHandle(0),
1611 (LPVOID)&client_cs);
1612 assert(mdi_client);
1613 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1614 DestroyWindow(mdi_client);
1616 /* MDIClient with MDIS_ALLCHILDSTYLES */
1617 mdi_client = CreateWindowExA(0, "mdiclient",
1618 NULL,
1619 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1620 /* tests depend on a not zero MDIClient size */
1621 0, 0, rc.right, rc.bottom,
1622 hwnd, 0, GetModuleHandle(0),
1623 (LPVOID)&client_cs);
1624 assert(mdi_client);
1625 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1626 DestroyWindow(mdi_client);
1627 break;
1630 case WM_WINDOWPOSCHANGED:
1632 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1633 RECT rc1, rc2;
1635 GetWindowRect(hwnd, &rc1);
1636 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1637 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1638 /* note: winpos coordinates are relative to parent */
1639 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1640 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1641 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1643 GetWindowRect(hwnd, &rc1);
1644 GetClientRect(hwnd, &rc2);
1645 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1646 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1647 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1649 /* fall through */
1650 case WM_WINDOWPOSCHANGING:
1652 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1653 WINDOWPOS my_winpos = *winpos;
1655 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1656 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1657 winpos->hwnd, winpos->hwndInsertAfter,
1658 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1660 DefWindowProcA(hwnd, msg, wparam, lparam);
1662 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1663 winpos->hwnd, winpos->hwndInsertAfter,
1664 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1666 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1667 "DefWindowProc should not change WINDOWPOS values\n");
1669 return 1;
1672 case WM_CLOSE:
1673 PostQuitMessage(0);
1674 break;
1676 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1679 static BOOL mdi_RegisterWindowClasses(void)
1681 WNDCLASSA cls;
1683 cls.style = 0;
1684 cls.lpfnWndProc = mdi_main_wnd_procA;
1685 cls.cbClsExtra = 0;
1686 cls.cbWndExtra = 0;
1687 cls.hInstance = GetModuleHandleA(0);
1688 cls.hIcon = 0;
1689 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1690 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1691 cls.lpszMenuName = NULL;
1692 cls.lpszClassName = "MDI_parent_Class";
1693 if(!RegisterClassA(&cls)) return FALSE;
1695 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1696 cls.lpszClassName = "MDI_child_Class_1";
1697 if(!RegisterClassA(&cls)) return FALSE;
1699 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1700 cls.lpszClassName = "MDI_child_Class_2";
1701 if(!RegisterClassA(&cls)) return FALSE;
1703 return TRUE;
1706 static void test_mdi(void)
1708 HWND mdi_hwndMain;
1709 /*MSG msg;*/
1711 if (!mdi_RegisterWindowClasses()) assert(0);
1713 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1714 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1715 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1716 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1717 GetDesktopWindow(), 0,
1718 GetModuleHandle(0), NULL);
1719 assert(mdi_hwndMain);
1721 while(GetMessage(&msg, 0, 0, 0))
1723 TranslateMessage(&msg);
1724 DispatchMessage(&msg);
1729 static void test_icons(void)
1731 WNDCLASSEXA cls;
1732 HWND hwnd;
1733 HICON icon = LoadIconA(0, (LPSTR)IDI_APPLICATION);
1734 HICON icon2 = LoadIconA(0, (LPSTR)IDI_QUESTION);
1735 HICON small_icon = LoadImageA(0, (LPSTR)IDI_APPLICATION, IMAGE_ICON,
1736 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1737 HICON res;
1739 cls.cbSize = sizeof(cls);
1740 cls.style = 0;
1741 cls.lpfnWndProc = DefWindowProcA;
1742 cls.cbClsExtra = 0;
1743 cls.cbWndExtra = 0;
1744 cls.hInstance = 0;
1745 cls.hIcon = LoadIconA(0, (LPSTR)IDI_HAND);
1746 cls.hIconSm = small_icon;
1747 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1748 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1749 cls.lpszMenuName = NULL;
1750 cls.lpszClassName = "IconWindowClass";
1752 RegisterClassExA(&cls);
1754 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1755 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1756 assert( hwnd );
1758 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1759 ok( res == 0, "wrong big icon %p/0\n", res );
1760 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1761 ok( res == 0, "wrong previous big icon %p/0\n", res );
1762 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1763 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1764 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1765 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1766 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1767 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1769 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1770 ok( res == 0, "wrong small icon %p/0\n", res );
1771 /* this test is XP specific */
1772 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1773 ok( res != 0, "wrong small icon %p\n", res );*/
1774 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1775 ok( res == 0, "wrong previous small icon %p/0\n", res );
1776 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1777 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1778 /* this test is XP specific */
1779 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1780 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1781 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1782 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1783 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1784 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1785 /* this test is XP specific */
1786 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1787 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1789 /* make sure the big icon hasn't changed */
1790 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1791 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1794 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1796 if (msg == WM_NCCALCSIZE)
1798 RECT *rect = (RECT *)lparam;
1799 /* first time around increase the rectangle, next time decrease it */
1800 if (rect->left == 100) InflateRect( rect, 10, 10 );
1801 else InflateRect( rect, -10, -10 );
1802 return 0;
1804 return DefWindowProc( hwnd, msg, wparam, lparam );
1807 static void test_SetWindowPos(HWND hwnd)
1809 RECT orig_win_rc, rect;
1810 LONG_PTR old_proc;
1811 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1813 SetRect(&rect, 111, 222, 333, 444);
1814 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1815 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1816 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1818 SetRect(&rect, 111, 222, 333, 444);
1819 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1820 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1821 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1823 GetWindowRect(hwnd, &orig_win_rc);
1825 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1826 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1827 GetWindowRect( hwnd, &rect );
1828 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1829 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1830 GetClientRect( hwnd, &rect );
1831 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1832 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1833 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1835 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1836 GetWindowRect( hwnd, &rect );
1837 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1838 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1839 GetClientRect( hwnd, &rect );
1840 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1841 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1842 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1844 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1845 orig_win_rc.right, orig_win_rc.bottom, 0);
1846 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1848 /* Win9x truncates coordinates to 16-bit irrespectively */
1849 if (!is_win9x)
1851 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1852 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1854 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1855 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1858 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1859 orig_win_rc.right, orig_win_rc.bottom, 0);
1862 static void test_SetMenu(HWND parent)
1864 HWND child;
1865 HMENU hMenu, ret;
1866 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1867 BOOL retok;
1868 DWORD style;
1870 hMenu = CreateMenu();
1871 assert(hMenu);
1873 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1874 if (0)
1876 /* fails on (at least) Wine, NT4, XP SP2 */
1877 test_nonclient_area(parent);
1879 ret = GetMenu(parent);
1880 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1881 /* test whether we can destroy a menu assigned to a window */
1882 retok = DestroyMenu(hMenu);
1883 ok( retok, "DestroyMenu error %d\n", GetLastError());
1884 ok(!IsMenu(hMenu), "menu handle should be not valid after DestroyMenu\n");
1885 ret = GetMenu(parent);
1886 /* This test fails on Win9x */
1887 if (!is_win9x)
1888 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);
1892 hMenu = CreateMenu();
1893 assert(hMenu);
1895 /* parent */
1896 ret = GetMenu(parent);
1897 ok(ret == 0, "unexpected menu id %p\n", ret);
1899 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1900 test_nonclient_area(parent);
1901 ret = GetMenu(parent);
1902 ok(ret == 0, "unexpected menu id %p\n", ret);
1904 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1905 if (0)
1907 /* fails on (at least) Wine, NT4, XP SP2 */
1908 test_nonclient_area(parent);
1910 ret = GetMenu(parent);
1911 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1913 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1914 test_nonclient_area(parent);
1915 ret = GetMenu(parent);
1916 ok(ret == 0, "unexpected menu id %p\n", ret);
1918 /* child */
1919 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1920 assert(child);
1922 ret = GetMenu(child);
1923 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1925 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1926 test_nonclient_area(child);
1927 ret = GetMenu(child);
1928 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1930 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1931 test_nonclient_area(child);
1932 ret = GetMenu(child);
1933 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1935 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1936 test_nonclient_area(child);
1937 ret = GetMenu(child);
1938 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1940 style = GetWindowLong(child, GWL_STYLE);
1941 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
1942 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
1943 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
1944 SetWindowLong(child, GWL_STYLE, style);
1946 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
1947 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
1948 SetWindowLong(child, GWL_STYLE, style);
1950 DestroyWindow(child);
1951 DestroyMenu(hMenu);
1954 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1956 HWND child[5], hwnd;
1957 int i;
1959 assert(total <= 5);
1961 hwnd = GetWindow(parent, GW_CHILD);
1962 ok(!hwnd, "have to start without children to perform the test\n");
1964 for (i = 0; i < total; i++)
1966 if (style[i] & DS_CONTROL)
1968 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
1969 0,0,0,0, parent, (HMENU)i, 0, NULL);
1970 if (style[i] & WS_VISIBLE)
1971 ShowWindow(child[i], SW_SHOW);
1973 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
1975 else
1976 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
1977 parent, (HMENU)i, 0, NULL);
1978 trace("child[%d] = %p\n", i, child[i]);
1979 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
1982 hwnd = GetWindow(parent, GW_CHILD);
1983 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
1984 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
1985 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
1987 for (i = 0; i < total; i++)
1989 trace("hwnd[%d] = %p\n", i, hwnd);
1990 ok(child[order[i]] == hwnd, "Z order of child #%d is wrong\n", i);
1992 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1995 for (i = 0; i < total; i++)
1996 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
1999 static void test_children_zorder(HWND parent)
2001 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2002 WS_CHILD };
2003 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2005 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2006 WS_CHILD | WS_VISIBLE, WS_CHILD,
2007 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2008 const int complex_order_1[1] = { 0 };
2009 const int complex_order_2[2] = { 1, 0 };
2010 const int complex_order_3[3] = { 1, 0, 2 };
2011 const int complex_order_4[4] = { 1, 0, 2, 3 };
2012 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2013 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2014 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2015 WS_CHILD | WS_VISIBLE };
2016 const int complex_order_6[3] = { 0, 1, 2 };
2018 /* simple WS_CHILD */
2019 test_window_tree(parent, simple_style, simple_order, 5);
2021 /* complex children styles */
2022 test_window_tree(parent, complex_style, complex_order_1, 1);
2023 test_window_tree(parent, complex_style, complex_order_2, 2);
2024 test_window_tree(parent, complex_style, complex_order_3, 3);
2025 test_window_tree(parent, complex_style, complex_order_4, 4);
2026 test_window_tree(parent, complex_style, complex_order_5, 5);
2028 /* another set of complex children styles */
2029 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2032 static void test_vis_rgn( HWND hwnd )
2034 RECT win_rect, rgn_rect;
2035 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2036 HDC hdc;
2038 ShowWindow(hwnd,SW_SHOW);
2039 hdc = GetDC( hwnd );
2040 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2041 GetWindowRect( hwnd, &win_rect );
2042 GetRgnBox( hrgn, &rgn_rect );
2043 if (GetVersion() & 0x80000000)
2045 trace("win9x, mapping to screen coords\n");
2046 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2048 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2049 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2050 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2051 rgn_rect.left, win_rect.left );
2052 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2053 rgn_rect.top, win_rect.top );
2054 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2055 rgn_rect.right, win_rect.right );
2056 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2057 rgn_rect.bottom, win_rect.bottom );
2058 ReleaseDC( hwnd, hdc );
2061 static void test_SetFocus(HWND hwnd)
2063 HWND child;
2065 /* check if we can set focus to non-visible windows */
2067 ShowWindow(hwnd, SW_SHOW);
2068 SetFocus(0);
2069 SetFocus(hwnd);
2070 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2071 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2072 ShowWindow(hwnd, SW_HIDE);
2073 SetFocus(0);
2074 SetFocus(hwnd);
2075 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2076 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2077 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2078 assert(child);
2079 SetFocus(child);
2080 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2081 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2082 ShowWindow(child, SW_SHOW);
2083 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2084 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2085 ShowWindow(child, SW_HIDE);
2086 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2087 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2088 ShowWindow(child, SW_SHOW);
2089 SetFocus(child);
2090 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2091 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2092 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2094 ShowWindow(child, SW_HIDE);
2095 SetFocus(hwnd);
2096 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2097 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2098 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2099 ShowWindow(child, SW_HIDE);
2100 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2102 ShowWindow(hwnd, SW_SHOW);
2103 ShowWindow(child, SW_SHOW);
2104 SetFocus(child);
2105 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2106 EnableWindow(hwnd, FALSE);
2107 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2108 EnableWindow(hwnd, TRUE);
2110 DestroyWindow( child );
2113 static void check_wnd_state(HWND active, HWND foreground, HWND focus, HWND capture)
2115 ok(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2116 if (foreground)
2117 ok(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2118 ok(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2119 ok(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2122 static void test_SetActiveWindow(HWND hwnd)
2124 HWND hwnd2;
2126 ShowWindow(hwnd, SW_HIDE);
2127 SetFocus(0);
2128 SetActiveWindow(0);
2129 check_wnd_state(0, 0, 0, 0);
2131 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2133 ShowWindow(hwnd, SW_SHOW);
2134 check_wnd_state(hwnd, hwnd, hwnd, 0);
2136 hwnd2 = SetActiveWindow(0);
2137 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2138 check_wnd_state(0, 0, 0, 0);
2140 hwnd2 = SetActiveWindow(hwnd);
2141 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2142 check_wnd_state(hwnd, hwnd, hwnd, 0);
2144 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2145 check_wnd_state(hwnd, hwnd, hwnd, 0);
2147 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2148 check_wnd_state(hwnd, hwnd, hwnd, 0);
2150 ShowWindow(hwnd, SW_HIDE);
2151 check_wnd_state(0, 0, 0, 0);
2153 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2154 SetActiveWindow(hwnd);
2155 check_wnd_state(hwnd, hwnd, hwnd, 0);
2157 ShowWindow(hwnd, SW_SHOW);
2158 check_wnd_state(hwnd, hwnd, hwnd, 0);
2160 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2161 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2163 DestroyWindow(hwnd2);
2164 check_wnd_state(hwnd, hwnd, hwnd, 0);
2166 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2167 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2169 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2170 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2172 DestroyWindow(hwnd2);
2173 check_wnd_state(hwnd, hwnd, hwnd, 0);
2176 static void test_SetForegroundWindow(HWND hwnd)
2178 BOOL ret;
2179 HWND hwnd2;
2181 ShowWindow(hwnd, SW_HIDE);
2182 SetFocus(0);
2183 SetActiveWindow(0);
2184 check_wnd_state(0, 0, 0, 0);
2186 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2188 ShowWindow(hwnd, SW_SHOW);
2189 check_wnd_state(hwnd, hwnd, hwnd, 0);
2191 hwnd2 = SetActiveWindow(0);
2192 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2193 check_wnd_state(0, 0, 0, 0);
2195 ret = SetForegroundWindow(hwnd);
2196 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2197 check_wnd_state(hwnd, hwnd, hwnd, 0);
2199 SetLastError(0xdeadbeef);
2200 ret = SetForegroundWindow(0);
2201 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2202 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2203 check_wnd_state(hwnd, hwnd, hwnd, 0);
2205 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2206 check_wnd_state(hwnd, hwnd, hwnd, 0);
2208 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2209 check_wnd_state(hwnd, hwnd, hwnd, 0);
2211 hwnd2 = GetForegroundWindow();
2212 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2213 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2214 hwnd2 = GetForegroundWindow();
2215 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2217 ShowWindow(hwnd, SW_HIDE);
2218 check_wnd_state(0, 0, 0, 0);
2220 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2221 ret = SetForegroundWindow(hwnd);
2222 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2223 check_wnd_state(hwnd, hwnd, hwnd, 0);
2225 ShowWindow(hwnd, SW_SHOW);
2226 check_wnd_state(hwnd, hwnd, hwnd, 0);
2228 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2229 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2231 DestroyWindow(hwnd2);
2232 check_wnd_state(hwnd, hwnd, hwnd, 0);
2234 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2235 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2237 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2238 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2240 DestroyWindow(hwnd2);
2241 check_wnd_state(hwnd, hwnd, hwnd, 0);
2244 static WNDPROC old_button_proc;
2246 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2248 LRESULT ret;
2249 USHORT key_state;
2251 key_state = GetKeyState(VK_LBUTTON);
2252 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2254 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2256 if (msg == WM_LBUTTONDOWN)
2258 HWND hwnd, capture;
2260 check_wnd_state(button, button, button, button);
2262 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2263 assert(hwnd);
2264 trace("hwnd %p\n", hwnd);
2266 check_wnd_state(button, button, button, button);
2268 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2270 check_wnd_state(button, button, button, button);
2272 DestroyWindow(hwnd);
2274 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2275 assert(hwnd);
2276 trace("hwnd %p\n", hwnd);
2278 check_wnd_state(button, button, button, button);
2280 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2281 * match internal button state.
2283 SendMessage(button, WM_KILLFOCUS, 0, 0);
2284 check_wnd_state(button, button, button, 0);
2286 ShowWindow(hwnd, SW_SHOW);
2287 check_wnd_state(hwnd, hwnd, hwnd, 0);
2289 capture = SetCapture(hwnd);
2290 ok(capture == 0, "SetCapture() = %p\n", capture);
2292 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2294 DestroyWindow(hwnd);
2296 check_wnd_state(button, 0, button, 0);
2299 return ret;
2302 static void test_capture_1(void)
2304 HWND button, capture;
2306 capture = GetCapture();
2307 ok(capture == 0, "GetCapture() = %p\n", capture);
2309 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2310 assert(button);
2311 trace("button %p\n", button);
2313 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2315 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2317 capture = SetCapture(button);
2318 ok(capture == 0, "SetCapture() = %p\n", capture);
2319 check_wnd_state(button, 0, button, button);
2321 DestroyWindow(button);
2322 check_wnd_state(0, 0, 0, 0);
2325 static void test_capture_2(void)
2327 HWND button, hwnd, capture;
2329 check_wnd_state(0, 0, 0, 0);
2331 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2332 assert(button);
2333 trace("button %p\n", button);
2335 check_wnd_state(button, button, button, 0);
2337 capture = SetCapture(button);
2338 ok(capture == 0, "SetCapture() = %p\n", capture);
2340 check_wnd_state(button, button, button, button);
2342 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2343 * internal button state.
2345 SendMessage(button, WM_KILLFOCUS, 0, 0);
2346 check_wnd_state(button, button, button, button);
2348 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2349 assert(hwnd);
2350 trace("hwnd %p\n", hwnd);
2352 check_wnd_state(button, button, button, button);
2354 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2356 check_wnd_state(button, button, button, button);
2358 DestroyWindow(hwnd);
2360 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2361 assert(hwnd);
2362 trace("hwnd %p\n", hwnd);
2364 check_wnd_state(button, button, button, button);
2366 ShowWindow(hwnd, SW_SHOW);
2368 check_wnd_state(hwnd, hwnd, hwnd, button);
2370 capture = SetCapture(hwnd);
2371 ok(capture == button, "SetCapture() = %p\n", capture);
2373 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2375 DestroyWindow(hwnd);
2376 check_wnd_state(button, button, button, 0);
2378 DestroyWindow(button);
2379 check_wnd_state(0, 0, 0, 0);
2382 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2384 BOOL ret;
2386 ShowWindow(hwnd1, SW_HIDE);
2387 ShowWindow(hwnd2, SW_HIDE);
2389 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2390 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2392 SetCapture(hwnd1);
2393 check_wnd_state(0, 0, 0, hwnd1);
2395 SetCapture(hwnd2);
2396 check_wnd_state(0, 0, 0, hwnd2);
2398 ShowWindow(hwnd1, SW_SHOW);
2399 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2401 ret = ReleaseCapture();
2402 ok (ret, "releasecapture did not return TRUE.\n");
2403 ret = ReleaseCapture();
2404 ok (ret, "releasecapture did not return TRUE after second try.\n");
2407 static void test_keyboard_input(HWND hwnd)
2409 MSG msg;
2410 BOOL ret;
2412 ShowWindow(hwnd, SW_SHOW);
2413 UpdateWindow(hwnd);
2414 flush_events();
2416 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2418 SetFocus(hwnd);
2419 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2421 flush_events();
2423 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2424 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2425 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2426 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2427 ok( !ret, "message %04x available\n", msg.message);
2429 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2431 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2432 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2433 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2434 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2435 ok( !ret, "message %04x available\n", msg.message);
2437 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2439 keybd_event(VK_SPACE, 0, 0, 0);
2440 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2441 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2442 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2443 ok( !ret, "message %04x available\n", msg.message);
2445 SetFocus(0);
2446 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2448 flush_events();
2450 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2451 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2452 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "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 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2458 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2459 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2460 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2461 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2462 ok( !ret, "message %04x available\n", msg.message);
2464 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2466 keybd_event(VK_SPACE, 0, 0, 0);
2467 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2468 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2469 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2470 ok( !ret, "message %04x available\n", msg.message);
2473 static void test_mouse_input(HWND hwnd)
2475 RECT rc;
2476 POINT pt;
2477 int x, y;
2478 HWND popup;
2479 MSG msg;
2480 BOOL ret;
2481 LRESULT res;
2483 ShowWindow(hwnd, SW_SHOW);
2484 UpdateWindow(hwnd);
2486 GetWindowRect(hwnd, &rc);
2487 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2489 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2490 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2491 hwnd, 0, 0, NULL);
2492 assert(popup != 0);
2493 ShowWindow(popup, SW_SHOW);
2494 UpdateWindow(popup);
2496 GetWindowRect(popup, &rc);
2497 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2499 x = rc.left + (rc.right - rc.left) / 2;
2500 y = rc.top + (rc.bottom - rc.top) / 2;
2501 trace("setting cursor to (%d,%d)\n", x, y);
2503 SetCursorPos(x, y);
2504 GetCursorPos(&pt);
2505 ok(x == pt.x && y == pt.y, "wrong cursor pos (%d,%d), expected (%d,%d)\n", pt.x, pt.y, x, y);
2507 flush_events();
2509 /* Check that setting the same position will generate WM_MOUSEMOVE */
2510 SetCursorPos(x, y);
2511 msg.message = 0;
2512 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2513 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2514 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n", x, y, msg.pt.x, msg.pt.y);
2516 /* force the system to update its internal queue mouse position,
2517 * otherwise it won't generate relative mouse movements below.
2519 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2520 flush_events();
2522 msg.message = 0;
2523 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2524 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2525 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2526 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2527 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2528 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2529 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2530 ok( !ret, "message %04x available\n", msg.message);
2532 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2533 ShowWindow(popup, SW_HIDE);
2534 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2535 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2536 flush_events();
2538 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2539 ShowWindow(hwnd, SW_HIDE);
2540 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2541 ok( !ret, "message %04x available\n", msg.message);
2543 /* test mouse clicks */
2545 ShowWindow(hwnd, SW_SHOW);
2546 ShowWindow(popup, SW_SHOW);
2547 flush_events();
2549 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2550 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2551 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2552 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2554 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2555 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2556 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2557 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2559 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2560 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2561 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2562 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2564 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2565 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2566 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2567 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2569 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2570 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2571 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2572 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2574 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2575 ok(!ret, "message %04x available\n", msg.message);
2577 ShowWindow(popup, SW_HIDE);
2578 flush_events();
2580 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2581 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2582 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2583 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2585 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2586 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2587 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2588 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2590 test_lbuttondown_flag = TRUE;
2591 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
2592 test_lbuttondown_flag = FALSE;
2594 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2595 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2596 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2597 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2598 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2600 /* Test WM_MOUSEACTIVATE */
2601 #define TEST_MOUSEACTIVATE(A,B) \
2602 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2603 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2605 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
2606 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
2607 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
2608 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
2609 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
2610 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
2611 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
2612 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
2613 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
2614 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
2615 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
2616 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
2617 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
2618 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
2619 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
2620 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
2621 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
2622 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
2623 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
2624 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
2625 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
2626 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
2627 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
2628 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
2630 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2631 flush_events();
2633 DestroyWindow(popup);
2636 static void test_validatergn(HWND hwnd)
2638 HWND child;
2639 RECT rc, rc2;
2640 HRGN rgn;
2641 int ret;
2642 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
2643 ShowWindow(hwnd, SW_SHOW);
2644 UpdateWindow( hwnd);
2645 /* test that ValidateRect validates children*/
2646 InvalidateRect( child, NULL, 1);
2647 GetWindowRect( child, &rc);
2648 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2649 ret = GetUpdateRect( child, &rc2, 0);
2650 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
2651 "Update rectangle is empty!\n");
2652 ValidateRect( hwnd, &rc);
2653 ret = GetUpdateRect( child, &rc2, 0);
2654 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2655 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2656 rc2.right, rc2.bottom);
2658 /* now test ValidateRgn */
2659 InvalidateRect( child, NULL, 1);
2660 GetWindowRect( child, &rc);
2661 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2662 rgn = CreateRectRgnIndirect( &rc);
2663 ValidateRgn( hwnd, rgn);
2664 ret = GetUpdateRect( child, &rc2, 0);
2665 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2666 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2667 rc2.right, rc2.bottom);
2669 DeleteObject( rgn);
2670 DestroyWindow( child );
2673 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
2675 MoveWindow( hwnd, 0, 0, x, y, 0);
2676 GetWindowRect( hwnd, prc);
2677 trace("window rect is %d,%d - %d,%d\n",
2678 prc->left,prc->top,prc->right,prc->bottom);
2679 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
2680 trace("nccalc rect is %d,%d - %d,%d\n",
2681 prc->left,prc->top,prc->right,prc->bottom);
2684 static void test_nccalcscroll(HWND parent)
2686 RECT rc1;
2687 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
2688 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
2689 HWND hwnd = CreateWindowExA(0, "static", NULL,
2690 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
2691 10, 10, 200, 200, parent, 0, 0, NULL);
2692 ShowWindow( parent, SW_SHOW);
2693 UpdateWindow( parent);
2695 /* test window too low for a horizontal scroll bar */
2696 nccalchelper( hwnd, 100, sbheight, &rc1);
2697 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
2698 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
2700 /* test window just high enough for a horizontal scroll bar */
2701 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
2702 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
2703 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2705 /* test window too narrow for a vertical scroll bar */
2706 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
2707 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
2708 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2710 /* test window just wide enough for a vertical scroll bar */
2711 nccalchelper( hwnd, sbwidth, 100, &rc1);
2712 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
2713 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
2715 /* same test, but with client edge: not enough width */
2716 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
2717 nccalchelper( hwnd, sbwidth, 100, &rc1);
2718 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
2719 "Width should be %d size is %d,%d - %d,%d\n",
2720 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
2722 DestroyWindow( hwnd);
2725 static void test_SetParent(void)
2727 BOOL ret;
2728 HWND desktop = GetDesktopWindow();
2729 HMENU hMenu;
2730 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
2731 HWND parent, child1, child2, child3, child4, sibling;
2733 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2734 100, 100, 200, 200, 0, 0, 0, NULL);
2735 assert(parent != 0);
2736 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2737 0, 0, 50, 50, parent, 0, 0, NULL);
2738 assert(child1 != 0);
2739 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2740 0, 0, 50, 50, child1, 0, 0, NULL);
2741 assert(child2 != 0);
2742 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2743 0, 0, 50, 50, child2, 0, 0, NULL);
2744 assert(child3 != 0);
2745 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2746 0, 0, 50, 50, child3, 0, 0, NULL);
2747 assert(child4 != 0);
2749 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2750 parent, child1, child2, child3, child4);
2752 check_parents(parent, desktop, 0, 0, 0, parent, parent);
2753 check_parents(child1, parent, parent, parent, 0, parent, parent);
2754 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2755 check_parents(child3, child2, child2, child2, 0, child2, parent);
2756 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2758 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
2759 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
2760 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2761 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
2762 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2764 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
2765 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2766 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
2767 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
2768 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
2769 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
2770 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
2771 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
2772 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2774 if (!is_win9x) /* Win9x doesn't survive this test */
2776 ok(!SetParent(parent, child1), "SetParent should fail\n");
2777 ok(!SetParent(child2, child3), "SetParent should fail\n");
2778 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
2779 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
2780 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
2781 ok(!SetParent(child2, parent), "SetParent should fail\n");
2782 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
2784 check_parents(parent, child4, child4, 0, 0, child4, parent);
2785 check_parents(child1, parent, parent, parent, 0, child4, parent);
2786 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2787 check_parents(child3, child2, child2, child2, 0, child2, parent);
2788 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2791 hMenu = CreateMenu();
2792 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2793 100, 100, 200, 200, 0, hMenu, 0, NULL);
2794 assert(sibling != 0);
2796 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
2797 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
2799 ret = DestroyWindow(parent);
2800 ok( ret, "DestroyWindow() error %d\n", GetLastError());
2802 ok(!IsWindow(parent), "parent still exists\n");
2803 ok(!IsWindow(sibling), "sibling still exists\n");
2804 ok(!IsWindow(child1), "child1 still exists\n");
2805 ok(!IsWindow(child2), "child2 still exists\n");
2806 ok(!IsWindow(child3), "child3 still exists\n");
2807 ok(!IsWindow(child4), "child4 still exists\n");
2810 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2812 LPCREATESTRUCT lpcs;
2813 LPSTYLESTRUCT lpss;
2815 switch (msg)
2817 case WM_NCCREATE:
2818 case WM_CREATE:
2819 lpcs = (LPCREATESTRUCT)lparam;
2820 lpss = (LPSTYLESTRUCT)lpcs->lpCreateParams;
2821 if (lpss)
2823 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
2824 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
2825 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
2826 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
2827 else
2828 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
2830 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
2831 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2832 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
2834 ok(lpss->styleNew == lpcs->style,
2835 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
2836 lpss->styleNew, lpcs->style);
2838 break;
2840 return DefWindowProc(hwnd, msg, wparam, lparam);
2843 static ATOM atomStyleCheckClass;
2845 static void register_style_check_class(void)
2847 WNDCLASS wc =
2850 StyleCheckProc,
2853 GetModuleHandle(NULL),
2854 NULL,
2855 LoadCursor(NULL, IDC_ARROW),
2856 (HBRUSH)(COLOR_BTNFACE+1),
2857 NULL,
2858 TEXT("WineStyleCheck"),
2861 atomStyleCheckClass = RegisterClass(&wc);
2864 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
2866 DWORD dwActualStyle;
2867 DWORD dwActualExStyle;
2868 STYLESTRUCT ss;
2869 HWND hwnd;
2870 HWND hwndParent = NULL;
2872 ss.styleNew = dwStyleIn;
2873 ss.styleOld = dwExStyleIn;
2875 if (dwStyleIn & WS_CHILD)
2877 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
2878 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
2881 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
2882 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
2883 assert(hwnd);
2885 flush_events();
2887 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
2888 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
2889 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
2890 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
2891 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
2893 DestroyWindow(hwnd);
2894 if (hwndParent) DestroyWindow(hwndParent);
2897 /* tests what window styles the window manager automatically adds */
2898 static void test_window_styles(void)
2900 register_style_check_class();
2902 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
2903 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
2904 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
2905 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
2906 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
2907 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
2908 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
2909 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
2910 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
2911 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
2912 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
2915 static void test_scrollvalidate( HWND parent)
2917 HDC hdc;
2918 HRGN hrgn=CreateRectRgn(0,0,0,0);
2919 HRGN exprgn, tmprgn, clipping;
2920 RECT rc, rcu, cliprc;
2921 /* create two overlapping child windows. The visual region
2922 * of hwnd1 is clipped by the overlapping part of
2923 * hwnd2 because of the WS_CLIPSIBLING style */
2924 HWND hwnd1, hwnd2;
2926 clipping = CreateRectRgn(0,0,0,0);
2927 tmprgn = CreateRectRgn(0,0,0,0);
2928 exprgn = CreateRectRgn(0,0,0,0);
2929 hwnd2 = CreateWindowExA(0, "static", NULL,
2930 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
2931 75, 30, 100, 100, parent, 0, 0, NULL);
2932 hwnd1 = CreateWindowExA(0, "static", NULL,
2933 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
2934 25, 50, 100, 100, parent, 0, 0, NULL);
2935 ShowWindow( parent, SW_SHOW);
2936 UpdateWindow( parent);
2937 GetClientRect( hwnd1, &rc);
2938 cliprc=rc;
2939 SetRectRgn( clipping, 10, 10, 90, 90);
2940 hdc = GetDC( hwnd1);
2941 /* for a visual touch */
2942 TextOut( hdc, 0,10, "0123456789", 10);
2943 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
2944 if (winetest_debug > 0) dump_region(hrgn);
2945 /* create a region with what is expected */
2946 SetRectRgn( exprgn, 39,0,49,74);
2947 SetRectRgn( tmprgn, 88,79,98,93);
2948 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2949 SetRectRgn( tmprgn, 0,93,98,98);
2950 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2951 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2952 trace("update rect is %d,%d - %d,%d\n",
2953 rcu.left,rcu.top,rcu.right,rcu.bottom);
2954 /* now with clipping region */
2955 SelectClipRgn( hdc, clipping);
2956 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
2957 if (winetest_debug > 0) dump_region(hrgn);
2958 /* create a region with what is expected */
2959 SetRectRgn( exprgn, 39,10,49,74);
2960 SetRectRgn( tmprgn, 80,79,90,85);
2961 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2962 SetRectRgn( tmprgn, 10,85,90,90);
2963 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2964 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2965 trace("update rect is %d,%d - %d,%d\n",
2966 rcu.left,rcu.top,rcu.right,rcu.bottom);
2967 ReleaseDC( hwnd1, hdc);
2969 /* test scrolling a window with an update region */
2970 DestroyWindow( hwnd2);
2971 ValidateRect( hwnd1, NULL);
2972 SetRect( &rc, 40,40, 50,50);
2973 InvalidateRect( hwnd1, &rc, 1);
2974 GetClientRect( hwnd1, &rc);
2975 cliprc=rc;
2976 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
2977 SW_SCROLLCHILDREN | SW_INVALIDATE);
2978 if (winetest_debug > 0) dump_region(hrgn);
2979 SetRectRgn( exprgn, 88,0,98,98);
2980 SetRectRgn( tmprgn, 30, 40, 50, 50);
2981 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2982 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2984 /* clear an update region */
2985 UpdateWindow( hwnd1 );
2987 SetRect( &rc, 0,40, 100,60);
2988 SetRect( &cliprc, 0,0, 100,100);
2989 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
2990 if (winetest_debug > 0) dump_region( hrgn );
2991 SetRectRgn( exprgn, 0, 40, 98, 60 );
2992 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
2994 /* now test ScrollWindowEx with a combination of
2995 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
2996 /* make hwnd2 the child of hwnd1 */
2997 hwnd2 = CreateWindowExA(0, "static", NULL,
2998 WS_CHILD| WS_VISIBLE | WS_BORDER ,
2999 50, 50, 100, 100, hwnd1, 0, 0, NULL);
3000 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
3001 GetClientRect( hwnd1, &rc);
3002 cliprc=rc;
3004 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3005 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3006 ValidateRect( hwnd1, NULL);
3007 ValidateRect( hwnd2, NULL);
3008 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
3009 SW_SCROLLCHILDREN | SW_INVALIDATE);
3010 if (winetest_debug > 0) dump_region(hrgn);
3011 SetRectRgn( exprgn, 88,0,98,88);
3012 SetRectRgn( tmprgn, 0,88,98,98);
3013 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3014 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3016 /* SW_SCROLLCHILDREN */
3017 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3018 ValidateRect( hwnd1, NULL);
3019 ValidateRect( hwnd2, NULL);
3020 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3021 if (winetest_debug > 0) dump_region(hrgn);
3022 /* expected region is the same as in previous test */
3023 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3025 /* no SW_SCROLLCHILDREN */
3026 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3027 ValidateRect( hwnd1, NULL);
3028 ValidateRect( hwnd2, NULL);
3029 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3030 if (winetest_debug > 0) dump_region(hrgn);
3031 /* expected region is the same as in previous test */
3032 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3034 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3035 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3036 ValidateRect( hwnd1, NULL);
3037 ValidateRect( hwnd2, NULL);
3038 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3039 if (winetest_debug > 0) dump_region(hrgn);
3040 SetRectRgn( exprgn, 88,0,98,20);
3041 SetRectRgn( tmprgn, 20,20,98,30);
3042 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3043 SetRectRgn( tmprgn, 20,30,30,88);
3044 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3045 SetRectRgn( tmprgn, 0,88,30,98);
3046 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3047 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3049 /* clean up */
3050 DeleteObject( hrgn);
3051 DeleteObject( exprgn);
3052 DeleteObject( tmprgn);
3053 DestroyWindow( hwnd1);
3054 DestroyWindow( hwnd2);
3057 /* couple of tests of return values of scrollbar functions
3058 * called on a scrollbarless window */
3059 static void test_scroll(void)
3061 BOOL ret;
3062 INT min, max;
3063 SCROLLINFO si;
3064 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3065 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3066 100, 100, 200, 200, 0, 0, 0, NULL);
3067 /* horizontal */
3068 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3069 ok( ret, "GetScrollRange returns FALSE\n");
3070 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3071 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3072 si.cbSize = sizeof( si);
3073 si.fMask = SIF_PAGE;
3074 si.nPage = 0xdeadbeef;
3075 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3076 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3077 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3078 /* vertical */
3079 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3080 ok( ret, "GetScrollRange returns FALSE\n");
3081 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3082 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3083 si.cbSize = sizeof( si);
3084 si.fMask = SIF_PAGE;
3085 si.nPage = 0xdeadbeef;
3086 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3087 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3088 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3089 /* clean up */
3090 DestroyWindow( hwnd);
3093 static void test_scrolldc( HWND parent)
3095 HDC hdc;
3096 HRGN exprgn, tmprgn, hrgn;
3097 RECT rc, rc2, rcu, cliprc;
3098 HWND hwnd1;
3099 COLORREF colr;
3101 hrgn = CreateRectRgn(0,0,0,0);
3102 tmprgn = CreateRectRgn(0,0,0,0);
3103 exprgn = CreateRectRgn(0,0,0,0);
3105 hwnd1 = CreateWindowExA(0, "static", NULL,
3106 WS_CHILD| WS_VISIBLE,
3107 25, 50, 100, 100, parent, 0, 0, NULL);
3108 ShowWindow( parent, SW_SHOW);
3109 UpdateWindow( parent);
3110 GetClientRect( hwnd1, &rc);
3111 hdc = GetDC( hwnd1);
3112 /* paint the upper half of the window black */
3113 rc2 = rc;
3114 rc2.bottom = ( rc.top + rc.bottom) /2;
3115 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3116 /* clip region is the lower half */
3117 cliprc=rc;
3118 cliprc.top = (rc.top + rc.bottom) /2;
3119 /* test whether scrolled pixels are properly clipped */
3120 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3121 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3122 /* this scroll should not cause any visible changes */
3123 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3124 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3125 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3126 /* test with NULL clip rect */
3127 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3128 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3129 trace("update rect: %d,%d - %d,%d\n",
3130 rcu.left, rcu.top, rcu.right, rcu.bottom);
3131 if (winetest_debug > 0) dump_region(hrgn);
3132 SetRect(&rc2, 0, 0, 100, 100);
3133 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3134 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3136 SetRectRgn( exprgn, 0, 0, 20, 80);
3137 SetRectRgn( tmprgn, 0, 80, 100, 100);
3138 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3139 if (winetest_debug > 0) dump_region(exprgn);
3140 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3141 /* test clip rect > scroll rect */
3142 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3143 rc2=rc;
3144 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3145 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3146 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3147 SetRectRgn( exprgn, 25, 25, 75, 35);
3148 SetRectRgn( tmprgn, 25, 35, 35, 75);
3149 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3150 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3151 colr = GetPixel( hdc, 80, 80);
3152 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3153 trace("update rect: %d,%d - %d,%d\n",
3154 rcu.left, rcu.top, rcu.right, rcu.bottom);
3155 if (winetest_debug > 0) dump_region(hrgn);
3157 /* clean up */
3158 DeleteObject(hrgn);
3159 DeleteObject(exprgn);
3160 DeleteObject(tmprgn);
3161 DestroyWindow(hwnd1);
3164 static void test_params(void)
3166 HWND hwnd;
3167 INT rc;
3169 /* Just a param check */
3170 SetLastError(0xdeadbeef);
3171 rc = GetWindowText(hwndMain2, NULL, 1024);
3172 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
3174 SetLastError(0xdeadbeef);
3175 hwnd=CreateWindow("LISTBOX", "TestList",
3176 (LBS_STANDARD & ~LBS_SORT),
3177 0, 0, 100, 100,
3178 NULL, (HMENU)1, NULL, 0);
3180 ok(!hwnd, "CreateWindow with invalid menu handle should fail\n");
3181 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3182 GetLastError() == 0xdeadbeef, /* Win9x */
3183 "wrong last error value %d\n", GetLastError());
3186 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3188 HWND hwnd = 0;
3190 hwnd = CreateWindowEx(exStyle, class, class, style,
3191 110, 100,
3192 225, 200,
3194 menu ? hmenu : 0,
3195 0, 0);
3196 if (!hwnd) {
3197 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
3198 return;
3200 ShowWindow(hwnd, SW_SHOW);
3202 test_nonclient_area(hwnd);
3204 SetMenu(hwnd, 0);
3205 DestroyWindow(hwnd);
3208 static BOOL AWR_init(void)
3210 WNDCLASS class;
3212 class.style = CS_HREDRAW | CS_VREDRAW;
3213 class.lpfnWndProc = DefWindowProcA;
3214 class.cbClsExtra = 0;
3215 class.cbWndExtra = 0;
3216 class.hInstance = 0;
3217 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3218 class.hCursor = LoadCursor (0, IDC_ARROW);
3219 class.hbrBackground = 0;
3220 class.lpszMenuName = 0;
3221 class.lpszClassName = szAWRClass;
3223 if (!RegisterClass (&class)) {
3224 ok(FALSE, "RegisterClass failed\n");
3225 return FALSE;
3228 hmenu = CreateMenu();
3229 if (!hmenu)
3230 return FALSE;
3231 ok(hmenu != 0, "Failed to create menu\n");
3232 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3234 return TRUE;
3238 static void test_AWR_window_size(BOOL menu)
3240 LONG styles[] = {
3241 WS_POPUP,
3242 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3243 WS_SYSMENU,
3244 WS_THICKFRAME,
3245 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3246 WS_HSCROLL, WS_VSCROLL
3248 LONG exStyles[] = {
3249 WS_EX_CLIENTEDGE,
3250 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3251 WS_EX_APPWINDOW,
3252 #if 0
3253 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3254 WS_EX_DLGMODALFRAME,
3255 WS_EX_STATICEDGE,
3256 #endif
3259 int i;
3261 /* A exhaustive check of all the styles takes too long
3262 * so just do a (hopefully representative) sample
3264 for (i = 0; i < COUNTOF(styles); ++i)
3265 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3266 for (i = 0; i < COUNTOF(exStyles); ++i) {
3267 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3268 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3271 #undef COUNTOF
3273 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3275 static void test_AdjustWindowRect(void)
3277 if (!AWR_init())
3278 return;
3280 SHOWSYSMETRIC(SM_CYCAPTION);
3281 SHOWSYSMETRIC(SM_CYSMCAPTION);
3282 SHOWSYSMETRIC(SM_CYMENU);
3283 SHOWSYSMETRIC(SM_CXEDGE);
3284 SHOWSYSMETRIC(SM_CYEDGE);
3285 SHOWSYSMETRIC(SM_CXVSCROLL);
3286 SHOWSYSMETRIC(SM_CYHSCROLL);
3287 SHOWSYSMETRIC(SM_CXFRAME);
3288 SHOWSYSMETRIC(SM_CYFRAME);
3289 SHOWSYSMETRIC(SM_CXDLGFRAME);
3290 SHOWSYSMETRIC(SM_CYDLGFRAME);
3291 SHOWSYSMETRIC(SM_CXBORDER);
3292 SHOWSYSMETRIC(SM_CYBORDER);
3294 test_AWR_window_size(FALSE);
3295 test_AWR_window_size(TRUE);
3297 DestroyMenu(hmenu);
3299 #undef SHOWSYSMETRIC
3302 /* Global variables to trigger exit from loop */
3303 static int redrawComplete, WMPAINT_count;
3305 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3307 switch (msg)
3309 case WM_PAINT:
3310 trace("doing WM_PAINT %d\n", WMPAINT_count);
3311 WMPAINT_count++;
3312 if (WMPAINT_count > 10 && redrawComplete == 0) {
3313 PAINTSTRUCT ps;
3314 BeginPaint(hwnd, &ps);
3315 EndPaint(hwnd, &ps);
3316 return 1;
3318 return 0;
3320 return DefWindowProc(hwnd, msg, wparam, lparam);
3323 /* Ensure we exit from RedrawNow regardless of invalidated area */
3324 static void test_redrawnow(void)
3326 WNDCLASSA cls;
3327 HWND hwndMain;
3329 cls.style = CS_DBLCLKS;
3330 cls.lpfnWndProc = redraw_window_procA;
3331 cls.cbClsExtra = 0;
3332 cls.cbWndExtra = 0;
3333 cls.hInstance = GetModuleHandleA(0);
3334 cls.hIcon = 0;
3335 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3336 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3337 cls.lpszMenuName = NULL;
3338 cls.lpszClassName = "RedrawWindowClass";
3340 if(!RegisterClassA(&cls)) {
3341 trace("Register failed %d\n", GetLastError());
3342 return;
3345 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3346 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3348 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3349 ShowWindow(hwndMain, SW_SHOW);
3350 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3351 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3352 ok( WMPAINT_count == 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3353 redrawComplete = TRUE;
3354 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3356 /* clean up */
3357 DestroyWindow( hwndMain);
3360 struct parentdc_stat {
3361 RECT client;
3362 RECT clip;
3363 RECT paint;
3366 struct parentdc_test {
3367 struct parentdc_stat main, main_todo;
3368 struct parentdc_stat child1, child1_todo;
3369 struct parentdc_stat child2, child2_todo;
3372 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3374 RECT rc;
3375 PAINTSTRUCT ps;
3377 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3379 switch (msg)
3381 case WM_PAINT:
3382 trace("doing WM_PAINT on %p\n", hwnd);
3383 GetClientRect(hwnd, &rc);
3384 CopyRect(&t->client, &rc);
3385 trace("client rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3386 GetWindowRect(hwnd, &rc);
3387 trace("window rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3388 BeginPaint(hwnd, &ps);
3389 CopyRect(&t->paint, &ps.rcPaint);
3390 GetClipBox(ps.hdc, &rc);
3391 CopyRect(&t->clip, &rc);
3392 trace("clip rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3393 trace("paint rect (%d, %d)-(%d, %d)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3394 EndPaint(hwnd, &ps);
3395 return 0;
3397 return DefWindowProc(hwnd, msg, wparam, lparam);
3400 static void zero_parentdc_stat(struct parentdc_stat *t)
3402 SetRectEmpty(&t->client);
3403 SetRectEmpty(&t->clip);
3404 SetRectEmpty(&t->paint);
3407 static void zero_parentdc_test(struct parentdc_test *t)
3409 zero_parentdc_stat(&t->main);
3410 zero_parentdc_stat(&t->child1);
3411 zero_parentdc_stat(&t->child2);
3414 #define parentdc_field_ok(t, w, r, f, got) \
3415 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3416 ": expected %d, got %d\n", \
3417 t.w.r.f, got.w.r.f)
3419 #define parentdc_todo_field_ok(t, w, r, f, got) \
3420 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3421 else parentdc_field_ok(t, w, r, f, got)
3423 #define parentdc_rect_ok(t, w, r, got) \
3424 parentdc_todo_field_ok(t, w, r, left, got); \
3425 parentdc_todo_field_ok(t, w, r, top, got); \
3426 parentdc_todo_field_ok(t, w, r, right, got); \
3427 parentdc_todo_field_ok(t, w, r, bottom, got);
3429 #define parentdc_win_ok(t, w, got) \
3430 parentdc_rect_ok(t, w, client, got); \
3431 parentdc_rect_ok(t, w, clip, got); \
3432 parentdc_rect_ok(t, w, paint, got);
3434 #define parentdc_ok(t, got) \
3435 parentdc_win_ok(t, main, got); \
3436 parentdc_win_ok(t, child1, got); \
3437 parentdc_win_ok(t, child2, got);
3439 static void test_csparentdc(void)
3441 WNDCLASSA clsMain, cls;
3442 HWND hwndMain, hwnd1, hwnd2;
3443 RECT rc;
3445 struct parentdc_test test_answer;
3447 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3448 const struct parentdc_test test1 =
3450 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
3451 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3452 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3455 const struct parentdc_test test2 =
3457 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
3458 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3459 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3462 const struct parentdc_test test3 =
3464 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3465 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3466 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3469 const struct parentdc_test test4 =
3471 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
3472 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
3473 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3476 const struct parentdc_test test5 =
3478 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
3479 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3480 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3483 const struct parentdc_test test6 =
3485 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3486 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3487 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3490 const struct parentdc_test test7 =
3492 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3493 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3494 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3496 #undef nothing_todo
3498 clsMain.style = CS_DBLCLKS;
3499 clsMain.lpfnWndProc = parentdc_window_procA;
3500 clsMain.cbClsExtra = 0;
3501 clsMain.cbWndExtra = 0;
3502 clsMain.hInstance = GetModuleHandleA(0);
3503 clsMain.hIcon = 0;
3504 clsMain.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3505 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
3506 clsMain.lpszMenuName = NULL;
3507 clsMain.lpszClassName = "ParentDcMainWindowClass";
3509 if(!RegisterClassA(&clsMain)) {
3510 trace("Register failed %d\n", GetLastError());
3511 return;
3514 cls.style = CS_DBLCLKS | CS_PARENTDC;
3515 cls.lpfnWndProc = parentdc_window_procA;
3516 cls.cbClsExtra = 0;
3517 cls.cbWndExtra = 0;
3518 cls.hInstance = GetModuleHandleA(0);
3519 cls.hIcon = 0;
3520 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3521 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3522 cls.lpszMenuName = NULL;
3523 cls.lpszClassName = "ParentDcWindowClass";
3525 if(!RegisterClassA(&cls)) {
3526 trace("Register failed %d\n", GetLastError());
3527 return;
3530 SetRect(&rc, 0, 0, 150, 150);
3531 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
3532 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3533 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
3534 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
3535 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
3536 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
3537 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
3538 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
3539 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
3540 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
3541 ShowWindow(hwndMain, SW_SHOW);
3542 ShowWindow(hwnd1, SW_SHOW);
3543 ShowWindow(hwnd2, SW_SHOW);
3544 flush_events();
3546 zero_parentdc_test(&test_answer);
3547 InvalidateRect(hwndMain, NULL, TRUE);
3548 flush_events();
3549 parentdc_ok(test1, test_answer);
3551 zero_parentdc_test(&test_answer);
3552 SetRect(&rc, 0, 0, 50, 50);
3553 InvalidateRect(hwndMain, &rc, TRUE);
3554 flush_events();
3555 parentdc_ok(test2, test_answer);
3557 zero_parentdc_test(&test_answer);
3558 SetRect(&rc, 0, 0, 10, 10);
3559 InvalidateRect(hwndMain, &rc, TRUE);
3560 flush_events();
3561 parentdc_ok(test3, test_answer);
3563 zero_parentdc_test(&test_answer);
3564 SetRect(&rc, 40, 40, 50, 50);
3565 InvalidateRect(hwndMain, &rc, TRUE);
3566 flush_events();
3567 parentdc_ok(test4, test_answer);
3569 zero_parentdc_test(&test_answer);
3570 SetRect(&rc, 20, 20, 60, 60);
3571 InvalidateRect(hwndMain, &rc, TRUE);
3572 flush_events();
3573 parentdc_ok(test5, test_answer);
3575 zero_parentdc_test(&test_answer);
3576 SetRect(&rc, 0, 0, 10, 10);
3577 InvalidateRect(hwnd1, &rc, TRUE);
3578 flush_events();
3579 parentdc_ok(test6, test_answer);
3581 zero_parentdc_test(&test_answer);
3582 SetRect(&rc, -5, -5, 65, 65);
3583 InvalidateRect(hwnd1, &rc, TRUE);
3584 flush_events();
3585 parentdc_ok(test7, test_answer);
3587 DestroyWindow(hwndMain);
3588 DestroyWindow(hwnd1);
3589 DestroyWindow(hwnd2);
3592 static void test_IsWindowUnicode(void)
3594 static const char ansi_class_nameA[] = "ansi class name";
3595 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3596 static const char unicode_class_nameA[] = "unicode class name";
3597 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3598 WNDCLASSA classA;
3599 WNDCLASSW classW;
3600 HWND hwnd;
3602 memset(&classW, 0, sizeof(classW));
3603 classW.hInstance = GetModuleHandleA(0);
3604 classW.lpfnWndProc = DefWindowProcW;
3605 classW.lpszClassName = unicode_class_nameW;
3606 if (!RegisterClassW(&classW)) return;
3608 memset(&classA, 0, sizeof(classA));
3609 classA.hInstance = GetModuleHandleA(0);
3610 classA.lpfnWndProc = DefWindowProcA;
3611 classA.lpszClassName = ansi_class_nameA;
3612 assert(RegisterClassA(&classA));
3614 /* unicode class: window proc */
3615 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3616 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3617 assert(hwnd);
3619 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3620 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3621 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3622 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3623 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3625 DestroyWindow(hwnd);
3627 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3628 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3629 assert(hwnd);
3631 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3632 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3633 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3634 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3635 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3637 DestroyWindow(hwnd);
3639 /* ansi class: window proc */
3640 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3641 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3642 assert(hwnd);
3644 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3645 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3646 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3647 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3648 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3650 DestroyWindow(hwnd);
3652 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3653 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3654 assert(hwnd);
3656 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3657 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3658 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3659 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3660 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3662 DestroyWindow(hwnd);
3664 /* unicode class: class proc */
3665 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3666 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3667 assert(hwnd);
3669 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3670 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3671 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3672 /* do not restore class window proc back to unicode */
3674 DestroyWindow(hwnd);
3676 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3677 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3678 assert(hwnd);
3680 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3681 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3682 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3684 DestroyWindow(hwnd);
3686 /* ansi class: class proc */
3687 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3688 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3689 assert(hwnd);
3691 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3692 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3693 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3694 /* do not restore class window proc back to ansi */
3696 DestroyWindow(hwnd);
3698 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3699 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3700 assert(hwnd);
3702 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3703 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3704 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3706 DestroyWindow(hwnd);
3709 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
3711 MINMAXINFO *minmax;
3713 if (msg != WM_GETMINMAXINFO)
3714 return DefWindowProc(hwnd, msg, wp, lp);
3716 minmax = (MINMAXINFO *)lp;
3718 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
3720 minmax->ptReserved.x = 0;
3721 minmax->ptReserved.y = 0;
3722 minmax->ptMaxSize.x = 400;
3723 minmax->ptMaxSize.y = 400;
3724 minmax->ptMaxPosition.x = 300;
3725 minmax->ptMaxPosition.y = 300;
3726 minmax->ptMaxTrackSize.x = 200;
3727 minmax->ptMaxTrackSize.y = 200;
3728 minmax->ptMinTrackSize.x = 100;
3729 minmax->ptMinTrackSize.y = 100;
3731 else
3732 DefWindowProc(hwnd, msg, wp, lp);
3733 return 1;
3736 static int expected_cx, expected_cy;
3737 static RECT expected_rect;
3739 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
3741 switch(msg)
3743 case WM_GETMINMAXINFO:
3745 RECT rect;
3746 GetWindowRect( hwnd, &rect );
3747 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
3748 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
3749 return DefWindowProc(hwnd, msg, wp, lp);
3751 case WM_NCCREATE:
3752 case WM_CREATE:
3754 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
3755 RECT rect;
3756 GetWindowRect( hwnd, &rect );
3757 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
3758 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
3759 ok( cs->cx == expected_cx, "wrong x size %d/%d\n", cs->cx, expected_cx );
3760 ok( cs->cy == expected_cy, "wrong y size %d/%d\n", cs->cy, expected_cy );
3761 ok( rect.right - rect.left == expected_rect.right - expected_rect.left &&
3762 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top,
3763 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
3764 rect.left, rect.top, rect.right, rect.bottom,
3765 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
3766 return DefWindowProc(hwnd, msg, wp, lp);
3768 default:
3769 return DefWindowProc(hwnd, msg, wp, lp);
3773 static void test_CreateWindow(void)
3775 WNDCLASS cls;
3776 HWND hwnd, parent;
3777 HMENU hmenu;
3778 RECT rc, rc_minmax;
3779 MINMAXINFO minmax;
3781 #define expect_menu(window, menu) \
3782 SetLastError(0xdeadbeef); \
3783 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
3785 #define expect_style(window, style)\
3786 ok(GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
3788 #define expect_ex_style(window, ex_style)\
3789 ok(GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
3791 hmenu = CreateMenu();
3792 assert(hmenu != 0);
3793 parent = GetDesktopWindow();
3794 assert(parent != 0);
3796 SetLastError(0xdeadbeef);
3797 ok(IsMenu(hmenu), "IsMenu error %d\n", GetLastError());
3799 /* WS_CHILD */
3800 SetLastError(0xdeadbeef);
3801 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
3802 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3803 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3804 expect_menu(hwnd, 1);
3805 expect_style(hwnd, WS_CHILD);
3806 expect_ex_style(hwnd, WS_EX_APPWINDOW);
3807 DestroyWindow(hwnd);
3809 SetLastError(0xdeadbeef);
3810 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
3811 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3812 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3813 expect_menu(hwnd, 1);
3814 expect_style(hwnd, WS_CHILD | WS_CAPTION);
3815 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
3816 DestroyWindow(hwnd);
3818 SetLastError(0xdeadbeef);
3819 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
3820 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3821 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3822 expect_menu(hwnd, 1);
3823 expect_style(hwnd, WS_CHILD);
3824 expect_ex_style(hwnd, 0);
3825 DestroyWindow(hwnd);
3827 SetLastError(0xdeadbeef);
3828 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
3829 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3830 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3831 expect_menu(hwnd, 1);
3832 expect_style(hwnd, WS_CHILD | WS_CAPTION);
3833 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
3834 DestroyWindow(hwnd);
3836 /* WS_POPUP */
3837 SetLastError(0xdeadbeef);
3838 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
3839 0, 0, 100, 100, parent, hmenu, 0, NULL);
3840 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3841 expect_menu(hwnd, hmenu);
3842 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
3843 expect_ex_style(hwnd, WS_EX_APPWINDOW);
3844 DestroyWindow(hwnd);
3845 SetLastError(0xdeadbeef);
3846 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3847 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3849 hmenu = CreateMenu();
3850 assert(hmenu != 0);
3851 SetLastError(0xdeadbeef);
3852 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
3853 0, 0, 100, 100, parent, hmenu, 0, NULL);
3854 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3855 expect_menu(hwnd, hmenu);
3856 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
3857 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
3858 DestroyWindow(hwnd);
3859 SetLastError(0xdeadbeef);
3860 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3861 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3863 hmenu = CreateMenu();
3864 assert(hmenu != 0);
3865 SetLastError(0xdeadbeef);
3866 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
3867 0, 0, 100, 100, parent, hmenu, 0, NULL);
3868 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3869 expect_menu(hwnd, hmenu);
3870 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
3871 expect_ex_style(hwnd, 0);
3872 DestroyWindow(hwnd);
3873 SetLastError(0xdeadbeef);
3874 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3875 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3877 hmenu = CreateMenu();
3878 assert(hmenu != 0);
3879 SetLastError(0xdeadbeef);
3880 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
3881 0, 0, 100, 100, parent, hmenu, 0, NULL);
3882 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3883 expect_menu(hwnd, hmenu);
3884 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
3885 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
3886 DestroyWindow(hwnd);
3887 SetLastError(0xdeadbeef);
3888 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3889 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3891 /* WS_CHILD | WS_POPUP */
3892 SetLastError(0xdeadbeef);
3893 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
3894 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3895 ok(!hwnd, "CreateWindowEx should fail\n");
3896 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3898 hmenu = CreateMenu();
3899 assert(hmenu != 0);
3900 SetLastError(0xdeadbeef);
3901 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
3902 0, 0, 100, 100, parent, hmenu, 0, NULL);
3903 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3904 expect_menu(hwnd, hmenu);
3905 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
3906 expect_ex_style(hwnd, WS_EX_APPWINDOW);
3907 DestroyWindow(hwnd);
3908 SetLastError(0xdeadbeef);
3909 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3910 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3912 SetLastError(0xdeadbeef);
3913 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
3914 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3915 ok(!hwnd, "CreateWindowEx should fail\n");
3916 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3918 hmenu = CreateMenu();
3919 assert(hmenu != 0);
3920 SetLastError(0xdeadbeef);
3921 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
3922 0, 0, 100, 100, parent, hmenu, 0, NULL);
3923 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3924 expect_menu(hwnd, hmenu);
3925 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
3926 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
3927 DestroyWindow(hwnd);
3928 SetLastError(0xdeadbeef);
3929 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3930 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3932 SetLastError(0xdeadbeef);
3933 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
3934 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3935 ok(!hwnd, "CreateWindowEx should fail\n");
3936 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3938 hmenu = CreateMenu();
3939 assert(hmenu != 0);
3940 SetLastError(0xdeadbeef);
3941 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
3942 0, 0, 100, 100, parent, hmenu, 0, NULL);
3943 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3944 expect_menu(hwnd, hmenu);
3945 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
3946 expect_ex_style(hwnd, 0);
3947 DestroyWindow(hwnd);
3948 SetLastError(0xdeadbeef);
3949 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3950 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3952 SetLastError(0xdeadbeef);
3953 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
3954 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3955 ok(!hwnd, "CreateWindowEx should fail\n");
3956 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3958 hmenu = CreateMenu();
3959 assert(hmenu != 0);
3960 SetLastError(0xdeadbeef);
3961 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
3962 0, 0, 100, 100, parent, hmenu, 0, NULL);
3963 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3964 expect_menu(hwnd, hmenu);
3965 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
3966 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
3967 DestroyWindow(hwnd);
3968 SetLastError(0xdeadbeef);
3969 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3970 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3972 /* test child window sizing */
3973 cls.style = 0;
3974 cls.lpfnWndProc = minmax_wnd_proc;
3975 cls.cbClsExtra = 0;
3976 cls.cbWndExtra = 0;
3977 cls.hInstance = GetModuleHandle(0);
3978 cls.hIcon = 0;
3979 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3980 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3981 cls.lpszMenuName = NULL;
3982 cls.lpszClassName = "MinMax_WndClass";
3983 RegisterClass(&cls);
3985 SetLastError(0xdeadbeef);
3986 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
3987 0, 0, 100, 100, 0, 0, 0, NULL);
3988 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
3989 expect_menu(parent, 0);
3990 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
3991 expect_ex_style(parent, WS_EX_WINDOWEDGE);
3993 memset(&minmax, 0, sizeof(minmax));
3994 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
3995 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
3996 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
3997 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
3998 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
4000 GetWindowRect(parent, &rc);
4001 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
4002 GetClientRect(parent, &rc);
4003 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
4005 InflateRect(&rc, 200, 200);
4006 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4008 SetLastError(0xdeadbeef);
4009 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4010 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
4011 parent, (HMENU)1, 0, NULL);
4012 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4013 expect_menu(hwnd, 1);
4014 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
4015 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4017 memset(&minmax, 0, sizeof(minmax));
4018 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4019 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4021 GetWindowRect(hwnd, &rc);
4022 OffsetRect(&rc, -rc.left, -rc.top);
4023 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4024 rc.left, rc.top, rc.right, rc.bottom,
4025 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
4026 DestroyWindow(hwnd);
4028 cls.lpfnWndProc = winsizes_wnd_proc;
4029 cls.lpszClassName = "Sizes_WndClass";
4030 RegisterClass(&cls);
4032 expected_cx = expected_cy = 200000;
4033 SetRect( &expected_rect, 0, 0, 200000, 200000 );
4034 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
4035 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4036 GetClientRect( hwnd, &rc );
4037 ok( rc.right == 200000, "invalid rect right %u\n", rc.right );
4038 ok( rc.bottom == 200000, "invalid rect bottom %u\n", rc.bottom );
4039 DestroyWindow(hwnd);
4041 expected_cx = expected_cy = -10;
4042 SetRect( &expected_rect, 0, 0, 0, 0 );
4043 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
4044 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4045 GetClientRect( hwnd, &rc );
4046 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4047 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4048 DestroyWindow(hwnd);
4050 expected_cx = expected_cy = -200000;
4051 SetRect( &expected_rect, 0, 0, 0, 0 );
4052 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
4053 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4054 GetClientRect( hwnd, &rc );
4055 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4056 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4057 DestroyWindow(hwnd);
4059 /* top level window */
4060 expected_cx = expected_cy = 200000;
4061 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
4062 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
4063 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4064 GetClientRect( hwnd, &rc );
4065 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
4066 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
4067 DestroyWindow(hwnd);
4069 DestroyWindow(parent);
4071 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4072 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4074 #undef expect_menu
4075 #undef expect_style
4076 #undef expect_ex_style
4079 /* function that remembers whether the system the test is running on sets the
4080 * last error for user32 functions to make the tests stricter */
4081 static int check_error(DWORD actual, DWORD expected)
4083 static int sets_last_error = -1;
4084 if (sets_last_error == -1)
4085 sets_last_error = (actual != 0xdeadbeef);
4086 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
4089 static void test_SetWindowLong(void)
4091 LONG_PTR retval;
4092 WNDPROC old_window_procW;
4094 SetLastError(0xdeadbeef);
4095 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
4096 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
4097 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
4098 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4100 SetLastError(0xdeadbeef);
4101 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
4102 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
4103 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
4104 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4106 SetLastError(0xdeadbeef);
4107 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4108 ok((WNDPROC)retval == main_window_procA,
4109 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
4110 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4111 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
4112 ok((WNDPROC)retval == main_window_procA,
4113 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4114 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
4116 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
4117 SetLastError(0xdeadbeef);
4118 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
4119 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
4121 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4122 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
4123 ok((WNDPROC)retval == old_window_procW,
4124 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4125 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
4127 /* set it back to ANSI */
4128 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4132 static void test_ShowWindow(void)
4134 HWND hwnd;
4135 DWORD style;
4136 RECT rcMain, rc;
4137 LPARAM ret;
4139 SetRect(&rcMain, 120, 120, 210, 210);
4141 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
4142 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4143 WS_MAXIMIZEBOX | WS_POPUP,
4144 rcMain.left, rcMain.top,
4145 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
4146 0, 0, 0, NULL);
4147 assert(hwnd);
4149 style = GetWindowLong(hwnd, GWL_STYLE);
4150 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4151 ok(!(style & WS_VISIBLE), "window should not be visible\n");
4152 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4153 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4154 GetWindowRect(hwnd, &rc);
4155 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4157 ret = ShowWindow(hwnd, SW_SHOW);
4158 ok(!ret, "not expected ret: %lu\n", ret);
4159 style = GetWindowLong(hwnd, GWL_STYLE);
4160 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4161 ok(style & WS_VISIBLE, "window should be visible\n");
4162 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4163 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4164 GetWindowRect(hwnd, &rc);
4165 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4167 ret = ShowWindow(hwnd, SW_MINIMIZE);
4168 ok(ret, "not expected ret: %lu\n", ret);
4169 style = GetWindowLong(hwnd, GWL_STYLE);
4170 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4171 ok(style & WS_VISIBLE, "window should be visible\n");
4172 ok(style & WS_MINIMIZE, "window should be minimized\n");
4173 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4174 GetWindowRect(hwnd, &rc);
4175 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4177 ShowWindow(hwnd, SW_RESTORE);
4178 ok(ret, "not expected ret: %lu\n", ret);
4179 style = GetWindowLong(hwnd, GWL_STYLE);
4180 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4181 ok(style & WS_VISIBLE, "window should be visible\n");
4182 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4183 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4184 GetWindowRect(hwnd, &rc);
4185 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4187 ret = EnableWindow(hwnd, FALSE);
4188 ok(!ret, "not expected ret: %lu\n", ret);
4189 style = GetWindowLong(hwnd, GWL_STYLE);
4190 ok(style & WS_DISABLED, "window should be disabled\n");
4192 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
4193 ok(!ret, "not expected ret: %lu\n", ret);
4194 style = GetWindowLong(hwnd, GWL_STYLE);
4195 ok(style & WS_DISABLED, "window should be disabled\n");
4196 ok(style & WS_VISIBLE, "window should be visible\n");
4197 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4198 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4199 GetWindowRect(hwnd, &rc);
4200 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4202 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
4203 ok(!ret, "not expected ret: %lu\n", ret);
4204 style = GetWindowLong(hwnd, GWL_STYLE);
4205 ok(style & WS_DISABLED, "window should be disabled\n");
4206 ok(style & WS_VISIBLE, "window should be visible\n");
4207 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4208 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4209 GetWindowRect(hwnd, &rc);
4210 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4212 ret = ShowWindow(hwnd, SW_MINIMIZE);
4213 ok(ret, "not expected ret: %lu\n", ret);
4214 style = GetWindowLong(hwnd, GWL_STYLE);
4215 ok(style & WS_DISABLED, "window should be disabled\n");
4216 ok(style & WS_VISIBLE, "window should be visible\n");
4217 ok(style & WS_MINIMIZE, "window should be minimized\n");
4218 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4219 GetWindowRect(hwnd, &rc);
4220 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4222 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
4223 ok(!ret, "not expected ret: %lu\n", ret);
4224 style = GetWindowLong(hwnd, GWL_STYLE);
4225 ok(style & WS_DISABLED, "window should be disabled\n");
4226 ok(style & WS_VISIBLE, "window should be visible\n");
4227 ok(style & WS_MINIMIZE, "window should be minimized\n");
4228 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4229 GetWindowRect(hwnd, &rc);
4230 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4232 ret = ShowWindow(hwnd, SW_RESTORE);
4233 ok(ret, "not expected ret: %lu\n", ret);
4234 style = GetWindowLong(hwnd, GWL_STYLE);
4235 ok(style & WS_DISABLED, "window should be disabled\n");
4236 ok(style & WS_VISIBLE, "window should be visible\n");
4237 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4238 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4239 GetWindowRect(hwnd, &rc);
4240 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4242 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4243 ok(!ret, "not expected ret: %lu\n", ret);
4244 ok(IsWindow(hwnd), "window should exist\n");
4246 ret = EnableWindow(hwnd, TRUE);
4247 ok(ret, "not expected ret: %lu\n", ret);
4249 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4250 ok(!ret, "not expected ret: %lu\n", ret);
4251 ok(!IsWindow(hwnd), "window should not exist\n");
4254 static void test_gettext(void)
4256 WNDCLASS cls;
4257 LPCSTR clsname = "gettexttest";
4258 HWND hwnd;
4259 LRESULT r;
4261 memset( &cls, 0, sizeof cls );
4262 cls.lpfnWndProc = DefWindowProc;
4263 cls.lpszClassName = clsname;
4264 cls.hInstance = GetModuleHandle(NULL);
4266 if (!RegisterClass( &cls )) return;
4268 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
4269 ok( hwnd != NULL, "window was null\n");
4271 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
4272 ok( r == 0, "settext should return zero\n");
4274 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
4275 ok( r == 0, "settext should return zero (%ld)\n", r);
4277 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
4278 ok( r == 0, "settext should return zero (%ld)\n", r);
4280 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
4281 ok( r == 0, "settext should return zero (%ld)\n", r);
4283 DestroyWindow(hwnd);
4284 UnregisterClass( clsname, NULL );
4288 static void test_GetUpdateRect(void)
4290 MSG msg;
4291 BOOL ret, parent_wm_paint, grandparent_wm_paint;
4292 RECT rc1, rc2;
4293 HWND hgrandparent, hparent, hchild;
4294 WNDCLASSA cls;
4295 static const char classNameA[] = "GetUpdateRectClass";
4297 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
4298 0, 0, 100, 100, NULL, NULL, 0, NULL);
4300 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
4301 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4303 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
4304 10, 10, 30, 30, hparent, NULL, 0, NULL);
4306 ShowWindow(hgrandparent, SW_SHOW);
4307 UpdateWindow(hgrandparent);
4308 flush_events();
4310 ShowWindow(hchild, SW_HIDE);
4311 SetRect(&rc2, 0, 0, 0, 0);
4312 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4313 ok(!ret, "GetUpdateRect returned not empty region\n");
4314 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4315 rc1.left, rc1.top, rc1.right, rc1.bottom,
4316 rc2.left, rc2.top, rc2.right, rc2.bottom);
4318 SetRect(&rc2, 10, 10, 40, 40);
4319 ret = GetUpdateRect(hparent, &rc1, FALSE);
4320 ok(ret, "GetUpdateRect returned empty region\n");
4321 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4322 rc1.left, rc1.top, rc1.right, rc1.bottom,
4323 rc2.left, rc2.top, rc2.right, rc2.bottom);
4325 parent_wm_paint = FALSE;
4326 grandparent_wm_paint = FALSE;
4327 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4329 if (msg.message == WM_PAINT)
4331 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4332 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4334 DispatchMessage(&msg);
4336 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4337 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4339 DestroyWindow(hgrandparent);
4341 cls.style = 0;
4342 cls.lpfnWndProc = DefWindowProcA;
4343 cls.cbClsExtra = 0;
4344 cls.cbWndExtra = 0;
4345 cls.hInstance = GetModuleHandleA(0);
4346 cls.hIcon = 0;
4347 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
4348 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4349 cls.lpszMenuName = NULL;
4350 cls.lpszClassName = classNameA;
4352 if(!RegisterClassA(&cls)) {
4353 trace("Register failed %d\n", GetLastError());
4354 return;
4357 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
4358 0, 0, 100, 100, NULL, NULL, 0, NULL);
4360 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
4361 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4363 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
4364 10, 10, 30, 30, hparent, NULL, 0, NULL);
4366 ShowWindow(hgrandparent, SW_SHOW);
4367 UpdateWindow(hgrandparent);
4368 flush_events();
4370 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4371 ok(!ret, "GetUpdateRect returned not empty region\n");
4373 ShowWindow(hchild, SW_HIDE);
4375 SetRect(&rc2, 0, 0, 0, 0);
4376 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4377 ok(!ret, "GetUpdateRect returned not empty region\n");
4378 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4379 rc1.left, rc1.top, rc1.right, rc1.bottom,
4380 rc2.left, rc2.top, rc2.right, rc2.bottom);
4382 SetRect(&rc2, 10, 10, 40, 40);
4383 ret = GetUpdateRect(hparent, &rc1, FALSE);
4384 ok(ret, "GetUpdateRect returned empty region\n");
4385 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4386 rc1.left, rc1.top, rc1.right, rc1.bottom,
4387 rc2.left, rc2.top, rc2.right, rc2.bottom);
4389 parent_wm_paint = FALSE;
4390 grandparent_wm_paint = FALSE;
4391 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4393 if (msg.message == WM_PAINT)
4395 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4396 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4398 DispatchMessage(&msg);
4400 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4401 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4403 DestroyWindow(hgrandparent);
4406 START_TEST(win)
4408 pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
4409 pGetWindowInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
4411 hwndMain = CreateWindowExA(0, "static", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, NULL);
4412 if (hwndMain)
4414 ok(!GetParent(hwndMain), "GetParent should return 0 for message only windows\n");
4415 if (pGetAncestor)
4417 hwndMessage = pGetAncestor(hwndMain, GA_PARENT);
4418 ok(hwndMessage != 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
4419 trace("hwndMessage %p\n", hwndMessage);
4421 DestroyWindow(hwndMain);
4423 else
4424 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
4426 if (!RegisterWindowClasses()) assert(0);
4428 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
4429 assert(hhook);
4431 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
4432 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4433 WS_MAXIMIZEBOX | WS_POPUP,
4434 100, 100, 200, 200,
4435 0, 0, 0, NULL);
4436 test_nonclient_area(hwndMain);
4438 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
4439 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4440 WS_MAXIMIZEBOX | WS_POPUP,
4441 100, 100, 200, 200,
4442 0, 0, 0, NULL);
4443 assert( hwndMain );
4444 assert( hwndMain2 );
4446 /* Add the tests below this line */
4447 test_params();
4449 test_capture_1();
4450 test_capture_2();
4451 test_capture_3(hwndMain, hwndMain2);
4453 test_CreateWindow();
4454 test_parent_owner();
4455 test_SetParent();
4456 test_shell_window();
4458 test_mdi();
4459 test_icons();
4460 test_SetWindowPos(hwndMain);
4461 test_SetMenu(hwndMain);
4462 test_SetFocus(hwndMain);
4463 test_SetActiveWindow(hwndMain);
4464 test_SetForegroundWindow(hwndMain);
4466 test_children_zorder(hwndMain);
4467 test_keyboard_input(hwndMain);
4468 test_mouse_input(hwndMain);
4469 test_validatergn(hwndMain);
4470 test_nccalcscroll( hwndMain);
4471 test_scrollvalidate( hwndMain);
4472 test_scrolldc( hwndMain);
4473 test_scroll();
4474 test_IsWindowUnicode();
4475 test_vis_rgn(hwndMain);
4477 test_AdjustWindowRect();
4478 test_window_styles();
4479 test_redrawnow();
4480 test_csparentdc();
4481 test_SetWindowLong();
4482 test_ShowWindow();
4483 test_gettext();
4484 test_GetUpdateRect();
4486 /* add the tests above this line */
4487 UnhookWindowsHookEx(hhook);