server: Moving a window should only expose the immediate parent.
[wine/gsoc_dplay.git] / dlls / user32 / tests / win.c
blobf3a2ac356318239ff4046d6970b4bdf5614d6aec
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 todo_wine
998 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
999 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
1000 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1003 ret = DestroyWindow(hwnd1);
1004 ok(ret, "DestroyWindow(hwnd1)\n");
1006 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1007 trace("created window 2: %p\n", hwnd2);
1008 ret = SetShellWindow(hwnd2);
1009 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1011 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1012 trace("created window 3: %p\n", hwnd3);
1014 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1015 trace("created window 4: %p\n", hwnd4);
1017 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1018 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1020 ret = SetShellWindow(hwnd4);
1021 ok(ret, "SetShellWindow(hwnd4)\n");
1022 shellWindow = GetShellWindow();
1023 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1025 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1026 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1028 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1029 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1031 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1032 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1034 ret = SetShellWindow(hwnd3);
1035 ok(!ret, "SetShellWindow(hwnd3)\n");
1036 shellWindow = GetShellWindow();
1037 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1039 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1040 trace("created window 5: %p\n", hwnd5);
1041 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1042 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1044 todo_wine
1046 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1047 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1050 /* destroy test windows */
1051 DestroyWindow(hwnd2);
1052 DestroyWindow(hwnd3);
1053 DestroyWindow(hwnd4);
1054 DestroyWindow(hwnd5);
1057 /************** MDI test ****************/
1059 static char mdi_lParam_test_message[] = "just a test string";
1061 static void test_MDI_create(HWND parent, HWND mdi_client, INT first_id)
1063 MDICREATESTRUCTA mdi_cs;
1064 HWND mdi_child;
1065 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1066 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1067 BOOL isWin9x = FALSE;
1069 mdi_cs.szClass = "MDI_child_Class_1";
1070 mdi_cs.szTitle = "MDI child";
1071 mdi_cs.hOwner = GetModuleHandle(0);
1072 mdi_cs.x = CW_USEDEFAULT;
1073 mdi_cs.y = CW_USEDEFAULT;
1074 mdi_cs.cx = CW_USEDEFAULT;
1075 mdi_cs.cy = CW_USEDEFAULT;
1076 mdi_cs.style = 0;
1077 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1078 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1079 ok(mdi_child != 0, "MDI child creation failed\n");
1080 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1081 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1082 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1084 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1085 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1086 ok(mdi_child != 0, "MDI child creation failed\n");
1087 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1088 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1089 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1091 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1092 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1093 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1095 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1097 else
1099 ok(mdi_child != 0, "MDI child creation failed\n");
1100 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1101 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1102 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1105 /* test MDICREATESTRUCT A<->W mapping */
1106 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1107 mdi_cs.style = 0;
1108 mdi_cs.szClass = (LPCSTR)classW;
1109 mdi_cs.szTitle = (LPCSTR)titleW;
1110 SetLastError(0xdeadbeef);
1111 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1112 if (!mdi_child)
1114 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1115 isWin9x = TRUE;
1116 else
1117 ok(mdi_child != 0, "MDI child creation failed\n");
1119 else
1121 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1122 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1123 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1126 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1128 CW_USEDEFAULT, CW_USEDEFAULT,
1129 CW_USEDEFAULT, CW_USEDEFAULT,
1130 mdi_client, GetModuleHandle(0),
1131 (LPARAM)mdi_lParam_test_message);
1132 ok(mdi_child != 0, "MDI child creation failed\n");
1133 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1134 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1135 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1137 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1138 0x7fffffff, /* without WS_POPUP */
1139 CW_USEDEFAULT, CW_USEDEFAULT,
1140 CW_USEDEFAULT, CW_USEDEFAULT,
1141 mdi_client, GetModuleHandle(0),
1142 (LPARAM)mdi_lParam_test_message);
1143 ok(mdi_child != 0, "MDI child creation failed\n");
1144 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1145 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1146 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1148 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1149 0xffffffff, /* with WS_POPUP */
1150 CW_USEDEFAULT, CW_USEDEFAULT,
1151 CW_USEDEFAULT, CW_USEDEFAULT,
1152 mdi_client, GetModuleHandle(0),
1153 (LPARAM)mdi_lParam_test_message);
1154 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1156 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1158 else
1160 ok(mdi_child != 0, "MDI child creation failed\n");
1161 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1162 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1163 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1166 /* test MDICREATESTRUCT A<->W mapping */
1167 SetLastError(0xdeadbeef);
1168 mdi_child = CreateMDIWindowW(classW, titleW,
1170 CW_USEDEFAULT, CW_USEDEFAULT,
1171 CW_USEDEFAULT, CW_USEDEFAULT,
1172 mdi_client, GetModuleHandle(0),
1173 (LPARAM)mdi_lParam_test_message);
1174 if (!mdi_child)
1176 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1177 isWin9x = TRUE;
1178 else
1179 ok(mdi_child != 0, "MDI child creation failed\n");
1181 else
1183 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1184 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1185 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1188 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1190 CW_USEDEFAULT, CW_USEDEFAULT,
1191 CW_USEDEFAULT, CW_USEDEFAULT,
1192 mdi_client, 0, GetModuleHandle(0),
1193 (LPVOID)mdi_lParam_test_message);
1194 ok(mdi_child != 0, "MDI child creation failed\n");
1195 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1196 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1197 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1199 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1200 0x7fffffff, /* without WS_POPUP */
1201 CW_USEDEFAULT, CW_USEDEFAULT,
1202 CW_USEDEFAULT, CW_USEDEFAULT,
1203 mdi_client, 0, GetModuleHandle(0),
1204 (LPVOID)mdi_lParam_test_message);
1205 ok(mdi_child != 0, "MDI child creation failed\n");
1206 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1207 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1208 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1210 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1211 0xffffffff, /* with WS_POPUP */
1212 CW_USEDEFAULT, CW_USEDEFAULT,
1213 CW_USEDEFAULT, CW_USEDEFAULT,
1214 mdi_client, 0, GetModuleHandle(0),
1215 (LPVOID)mdi_lParam_test_message);
1216 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1218 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1220 else
1222 ok(mdi_child != 0, "MDI child creation failed\n");
1223 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1224 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1225 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1228 /* test MDICREATESTRUCT A<->W mapping */
1229 SetLastError(0xdeadbeef);
1230 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1232 CW_USEDEFAULT, CW_USEDEFAULT,
1233 CW_USEDEFAULT, CW_USEDEFAULT,
1234 mdi_client, 0, GetModuleHandle(0),
1235 (LPVOID)mdi_lParam_test_message);
1236 if (!mdi_child)
1238 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1239 isWin9x = TRUE;
1240 else
1241 ok(mdi_child != 0, "MDI child creation failed\n");
1243 else
1245 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1246 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1247 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1250 /* This test fails on Win9x */
1251 if (!isWin9x)
1253 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1254 WS_CHILD,
1255 CW_USEDEFAULT, CW_USEDEFAULT,
1256 CW_USEDEFAULT, CW_USEDEFAULT,
1257 parent, 0, GetModuleHandle(0),
1258 (LPVOID)mdi_lParam_test_message);
1259 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1262 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1263 WS_CHILD, /* without WS_POPUP */
1264 CW_USEDEFAULT, CW_USEDEFAULT,
1265 CW_USEDEFAULT, CW_USEDEFAULT,
1266 mdi_client, 0, GetModuleHandle(0),
1267 (LPVOID)mdi_lParam_test_message);
1268 ok(mdi_child != 0, "MDI child creation failed\n");
1269 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1270 DestroyWindow(mdi_child);
1272 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1273 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1274 CW_USEDEFAULT, CW_USEDEFAULT,
1275 CW_USEDEFAULT, CW_USEDEFAULT,
1276 mdi_client, 0, GetModuleHandle(0),
1277 (LPVOID)mdi_lParam_test_message);
1278 ok(mdi_child != 0, "MDI child creation failed\n");
1279 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1280 DestroyWindow(mdi_child);
1282 /* maximized child */
1283 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1284 WS_CHILD | WS_MAXIMIZE,
1285 CW_USEDEFAULT, CW_USEDEFAULT,
1286 CW_USEDEFAULT, CW_USEDEFAULT,
1287 mdi_client, 0, GetModuleHandle(0),
1288 (LPVOID)mdi_lParam_test_message);
1289 ok(mdi_child != 0, "MDI child creation failed\n");
1290 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1291 DestroyWindow(mdi_child);
1293 trace("Creating maximized child with a caption\n");
1294 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1295 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1296 CW_USEDEFAULT, CW_USEDEFAULT,
1297 CW_USEDEFAULT, CW_USEDEFAULT,
1298 mdi_client, 0, GetModuleHandle(0),
1299 (LPVOID)mdi_lParam_test_message);
1300 ok(mdi_child != 0, "MDI child creation failed\n");
1301 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1302 DestroyWindow(mdi_child);
1304 trace("Creating maximized child with a caption and a thick frame\n");
1305 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1306 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1307 CW_USEDEFAULT, CW_USEDEFAULT,
1308 CW_USEDEFAULT, CW_USEDEFAULT,
1309 mdi_client, 0, GetModuleHandle(0),
1310 (LPVOID)mdi_lParam_test_message);
1311 ok(mdi_child != 0, "MDI child creation failed\n");
1312 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1313 DestroyWindow(mdi_child);
1316 /**********************************************************************
1317 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1319 * Note: The rule here is that client rect of the maximized MDI child
1320 * is equal to the client rect of the MDI client window.
1322 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1324 RECT rect;
1326 GetClientRect( client, &rect );
1327 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1328 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1330 rect.right -= rect.left;
1331 rect.bottom -= rect.top;
1332 lpMinMax->ptMaxSize.x = rect.right;
1333 lpMinMax->ptMaxSize.y = rect.bottom;
1335 lpMinMax->ptMaxPosition.x = rect.left;
1336 lpMinMax->ptMaxPosition.y = rect.top;
1338 trace("max rect (%d,%d - %d, %d)\n",
1339 rect.left, rect.top, rect.right, rect.bottom);
1342 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1344 switch (msg)
1346 case WM_NCCREATE:
1347 case WM_CREATE:
1349 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1350 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs->lpCreateParams;
1352 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1353 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1355 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1356 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1357 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1358 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1359 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1361 /* MDICREATESTRUCT should have original values */
1362 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1363 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1364 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1365 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1366 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1367 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1369 /* CREATESTRUCT should have fixed values */
1370 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1371 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1373 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1374 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1375 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1377 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1379 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1381 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1382 ok(cs->style == style,
1383 "cs->style does not match (%08x)\n", cs->style);
1385 else
1387 LONG style = mdi_cs->style;
1388 style &= ~WS_POPUP;
1389 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1390 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1391 ok(cs->style == style,
1392 "cs->style does not match (%08x)\n", cs->style);
1394 break;
1397 case WM_GETMINMAXINFO:
1399 HWND client = GetParent(hwnd);
1400 RECT rc;
1401 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1402 MINMAXINFO my_minmax;
1403 LONG style, exstyle;
1405 style = GetWindowLongA(hwnd, GWL_STYLE);
1406 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1408 GetWindowRect(client, &rc);
1409 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1410 GetClientRect(client, &rc);
1411 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1412 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1413 GetSystemMetrics(SM_CYSCREEN));
1415 GetClientRect(client, &rc);
1416 if ((style & WS_CAPTION) == WS_CAPTION)
1417 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1418 AdjustWindowRectEx(&rc, style, 0, exstyle);
1419 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1421 trace("ptReserved = (%d,%d)\n"
1422 "ptMaxSize = (%d,%d)\n"
1423 "ptMaxPosition = (%d,%d)\n"
1424 "ptMinTrackSize = (%d,%d)\n"
1425 "ptMaxTrackSize = (%d,%d)\n",
1426 minmax->ptReserved.x, minmax->ptReserved.y,
1427 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1428 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1429 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1430 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1432 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1433 minmax->ptMaxSize.x, rc.right - rc.left);
1434 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1435 minmax->ptMaxSize.y, rc.bottom - rc.top);
1437 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1439 trace("DefMDIChildProc returned:\n"
1440 "ptReserved = (%d,%d)\n"
1441 "ptMaxSize = (%d,%d)\n"
1442 "ptMaxPosition = (%d,%d)\n"
1443 "ptMinTrackSize = (%d,%d)\n"
1444 "ptMaxTrackSize = (%d,%d)\n",
1445 minmax->ptReserved.x, minmax->ptReserved.y,
1446 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1447 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1448 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1449 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1451 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1452 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1453 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1454 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1455 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1457 return 1;
1460 case WM_MDIACTIVATE:
1462 HWND active, client = GetParent(hwnd);
1463 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1464 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1465 if (hwnd == (HWND)lparam) /* if we are being activated */
1466 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1467 else
1468 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1469 break;
1472 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1475 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1477 switch (msg)
1479 case WM_NCCREATE:
1480 case WM_CREATE:
1482 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1484 trace("%s\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE");
1485 trace("x %d, y %d, cx %d, cy %d\n", cs->x, cs->y, cs->cx, cs->cy);
1487 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1488 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1490 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1491 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1493 /* CREATESTRUCT should have fixed values */
1494 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1495 while NT does. */
1496 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1497 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1499 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1500 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1501 while Win95, Win2k, WinXP do. */
1502 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1503 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1504 break;
1507 case WM_GETMINMAXINFO:
1509 HWND parent = GetParent(hwnd);
1510 RECT rc;
1511 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1512 LONG style, exstyle;
1514 trace("WM_GETMINMAXINFO\n");
1516 style = GetWindowLongA(hwnd, GWL_STYLE);
1517 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1519 GetClientRect(parent, &rc);
1520 trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1522 GetClientRect(parent, &rc);
1523 if ((style & WS_CAPTION) == WS_CAPTION)
1524 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1525 AdjustWindowRectEx(&rc, style, 0, exstyle);
1526 trace("calculated max child window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1528 trace("ptReserved = (%d,%d)\n"
1529 "ptMaxSize = (%d,%d)\n"
1530 "ptMaxPosition = (%d,%d)\n"
1531 "ptMinTrackSize = (%d,%d)\n"
1532 "ptMaxTrackSize = (%d,%d)\n",
1533 minmax->ptReserved.x, minmax->ptReserved.y,
1534 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1535 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1536 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1537 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1539 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1540 minmax->ptMaxSize.x, rc.right - rc.left);
1541 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1542 minmax->ptMaxSize.y, rc.bottom - rc.top);
1543 break;
1546 case WM_WINDOWPOSCHANGED:
1548 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1549 RECT rc1, rc2;
1551 GetWindowRect(hwnd, &rc1);
1552 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1553 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1554 /* note: winpos coordinates are relative to parent */
1555 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1556 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1557 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1559 GetWindowRect(hwnd, &rc1);
1560 GetClientRect(hwnd, &rc2);
1561 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1562 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1563 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1565 /* fall through */
1566 case WM_WINDOWPOSCHANGING:
1568 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1569 WINDOWPOS my_winpos = *winpos;
1571 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1572 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1573 winpos->hwnd, winpos->hwndInsertAfter,
1574 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1576 DefWindowProcA(hwnd, msg, wparam, lparam);
1578 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1579 winpos->hwnd, winpos->hwndInsertAfter,
1580 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1582 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1583 "DefWindowProc should not change WINDOWPOS values\n");
1585 return 1;
1588 return DefWindowProcA(hwnd, msg, wparam, lparam);
1591 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1593 static HWND mdi_client;
1595 switch (msg)
1597 case WM_CREATE:
1599 CLIENTCREATESTRUCT client_cs;
1600 RECT rc;
1602 GetClientRect(hwnd, &rc);
1604 client_cs.hWindowMenu = 0;
1605 client_cs.idFirstChild = 1;
1607 /* MDIClient without MDIS_ALLCHILDSTYLES */
1608 mdi_client = CreateWindowExA(0, "mdiclient",
1609 NULL,
1610 WS_CHILD /*| WS_VISIBLE*/,
1611 /* tests depend on a not zero MDIClient size */
1612 0, 0, rc.right, rc.bottom,
1613 hwnd, 0, GetModuleHandle(0),
1614 (LPVOID)&client_cs);
1615 assert(mdi_client);
1616 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1617 DestroyWindow(mdi_client);
1619 /* MDIClient with MDIS_ALLCHILDSTYLES */
1620 mdi_client = CreateWindowExA(0, "mdiclient",
1621 NULL,
1622 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1623 /* tests depend on a not zero MDIClient size */
1624 0, 0, rc.right, rc.bottom,
1625 hwnd, 0, GetModuleHandle(0),
1626 (LPVOID)&client_cs);
1627 assert(mdi_client);
1628 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1629 DestroyWindow(mdi_client);
1630 break;
1633 case WM_WINDOWPOSCHANGED:
1635 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1636 RECT rc1, rc2;
1638 GetWindowRect(hwnd, &rc1);
1639 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1640 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1641 /* note: winpos coordinates are relative to parent */
1642 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1643 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1644 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1646 GetWindowRect(hwnd, &rc1);
1647 GetClientRect(hwnd, &rc2);
1648 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1649 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1650 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1652 /* fall through */
1653 case WM_WINDOWPOSCHANGING:
1655 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1656 WINDOWPOS my_winpos = *winpos;
1658 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1659 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1660 winpos->hwnd, winpos->hwndInsertAfter,
1661 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1663 DefWindowProcA(hwnd, msg, wparam, lparam);
1665 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1666 winpos->hwnd, winpos->hwndInsertAfter,
1667 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1669 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1670 "DefWindowProc should not change WINDOWPOS values\n");
1672 return 1;
1675 case WM_CLOSE:
1676 PostQuitMessage(0);
1677 break;
1679 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1682 static BOOL mdi_RegisterWindowClasses(void)
1684 WNDCLASSA cls;
1686 cls.style = 0;
1687 cls.lpfnWndProc = mdi_main_wnd_procA;
1688 cls.cbClsExtra = 0;
1689 cls.cbWndExtra = 0;
1690 cls.hInstance = GetModuleHandleA(0);
1691 cls.hIcon = 0;
1692 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1693 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1694 cls.lpszMenuName = NULL;
1695 cls.lpszClassName = "MDI_parent_Class";
1696 if(!RegisterClassA(&cls)) return FALSE;
1698 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1699 cls.lpszClassName = "MDI_child_Class_1";
1700 if(!RegisterClassA(&cls)) return FALSE;
1702 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1703 cls.lpszClassName = "MDI_child_Class_2";
1704 if(!RegisterClassA(&cls)) return FALSE;
1706 return TRUE;
1709 static void test_mdi(void)
1711 HWND mdi_hwndMain;
1712 /*MSG msg;*/
1714 if (!mdi_RegisterWindowClasses()) assert(0);
1716 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1717 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1718 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1719 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1720 GetDesktopWindow(), 0,
1721 GetModuleHandle(0), NULL);
1722 assert(mdi_hwndMain);
1724 while(GetMessage(&msg, 0, 0, 0))
1726 TranslateMessage(&msg);
1727 DispatchMessage(&msg);
1732 static void test_icons(void)
1734 WNDCLASSEXA cls;
1735 HWND hwnd;
1736 HICON icon = LoadIconA(0, (LPSTR)IDI_APPLICATION);
1737 HICON icon2 = LoadIconA(0, (LPSTR)IDI_QUESTION);
1738 HICON small_icon = LoadImageA(0, (LPSTR)IDI_APPLICATION, IMAGE_ICON,
1739 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1740 HICON res;
1742 cls.cbSize = sizeof(cls);
1743 cls.style = 0;
1744 cls.lpfnWndProc = DefWindowProcA;
1745 cls.cbClsExtra = 0;
1746 cls.cbWndExtra = 0;
1747 cls.hInstance = 0;
1748 cls.hIcon = LoadIconA(0, (LPSTR)IDI_HAND);
1749 cls.hIconSm = small_icon;
1750 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1751 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1752 cls.lpszMenuName = NULL;
1753 cls.lpszClassName = "IconWindowClass";
1755 RegisterClassExA(&cls);
1757 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1758 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1759 assert( hwnd );
1761 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1762 ok( res == 0, "wrong big icon %p/0\n", res );
1763 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1764 ok( res == 0, "wrong previous big icon %p/0\n", res );
1765 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1766 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1767 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1768 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1769 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1770 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1772 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1773 ok( res == 0, "wrong small icon %p/0\n", res );
1774 /* this test is XP specific */
1775 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1776 ok( res != 0, "wrong small icon %p\n", res );*/
1777 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1778 ok( res == 0, "wrong previous small icon %p/0\n", res );
1779 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1780 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1781 /* this test is XP specific */
1782 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1783 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1784 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1785 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1786 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1787 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1788 /* this test is XP specific */
1789 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1790 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1792 /* make sure the big icon hasn't changed */
1793 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1794 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1797 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1799 if (msg == WM_NCCALCSIZE)
1801 RECT *rect = (RECT *)lparam;
1802 /* first time around increase the rectangle, next time decrease it */
1803 if (rect->left == 100) InflateRect( rect, 10, 10 );
1804 else InflateRect( rect, -10, -10 );
1805 return 0;
1807 return DefWindowProc( hwnd, msg, wparam, lparam );
1810 static void test_SetWindowPos(HWND hwnd)
1812 RECT orig_win_rc, rect;
1813 LONG_PTR old_proc;
1814 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1816 SetRect(&rect, 111, 222, 333, 444);
1817 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1818 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1819 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1821 SetRect(&rect, 111, 222, 333, 444);
1822 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1823 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1824 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1826 GetWindowRect(hwnd, &orig_win_rc);
1828 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1829 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1830 GetWindowRect( hwnd, &rect );
1831 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1832 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1833 GetClientRect( hwnd, &rect );
1834 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1835 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1836 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1838 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1839 GetWindowRect( hwnd, &rect );
1840 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1841 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1842 GetClientRect( hwnd, &rect );
1843 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1844 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1845 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1847 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1848 orig_win_rc.right, orig_win_rc.bottom, 0);
1849 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1851 /* Win9x truncates coordinates to 16-bit irrespectively */
1852 if (!is_win9x)
1854 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1855 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1857 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1858 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1861 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1862 orig_win_rc.right, orig_win_rc.bottom, 0);
1865 static void test_SetMenu(HWND parent)
1867 HWND child;
1868 HMENU hMenu, ret;
1869 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1870 BOOL retok;
1871 DWORD style;
1873 hMenu = CreateMenu();
1874 assert(hMenu);
1876 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1877 if (0)
1879 /* fails on (at least) Wine, NT4, XP SP2 */
1880 test_nonclient_area(parent);
1882 ret = GetMenu(parent);
1883 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1884 /* test whether we can destroy a menu assigned to a window */
1885 retok = DestroyMenu(hMenu);
1886 ok( retok, "DestroyMenu error %d\n", GetLastError());
1887 ok(!IsMenu(hMenu), "menu handle should be not valid after DestroyMenu\n");
1888 ret = GetMenu(parent);
1889 /* This test fails on Win9x */
1890 if (!is_win9x)
1891 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1892 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1893 test_nonclient_area(parent);
1895 hMenu = CreateMenu();
1896 assert(hMenu);
1898 /* parent */
1899 ret = GetMenu(parent);
1900 ok(ret == 0, "unexpected menu id %p\n", ret);
1902 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1903 test_nonclient_area(parent);
1904 ret = GetMenu(parent);
1905 ok(ret == 0, "unexpected menu id %p\n", ret);
1907 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1908 if (0)
1910 /* fails on (at least) Wine, NT4, XP SP2 */
1911 test_nonclient_area(parent);
1913 ret = GetMenu(parent);
1914 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1916 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1917 test_nonclient_area(parent);
1918 ret = GetMenu(parent);
1919 ok(ret == 0, "unexpected menu id %p\n", ret);
1921 /* child */
1922 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1923 assert(child);
1925 ret = GetMenu(child);
1926 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1928 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1929 test_nonclient_area(child);
1930 ret = GetMenu(child);
1931 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1933 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1934 test_nonclient_area(child);
1935 ret = GetMenu(child);
1936 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1938 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1939 test_nonclient_area(child);
1940 ret = GetMenu(child);
1941 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1943 style = GetWindowLong(child, GWL_STYLE);
1944 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
1945 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
1946 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
1947 SetWindowLong(child, GWL_STYLE, style);
1949 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
1950 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
1951 SetWindowLong(child, GWL_STYLE, style);
1953 DestroyWindow(child);
1954 DestroyMenu(hMenu);
1957 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1959 HWND child[5], hwnd;
1960 int i;
1962 assert(total <= 5);
1964 hwnd = GetWindow(parent, GW_CHILD);
1965 ok(!hwnd, "have to start without children to perform the test\n");
1967 for (i = 0; i < total; i++)
1969 if (style[i] & DS_CONTROL)
1971 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
1972 0,0,0,0, parent, (HMENU)i, 0, NULL);
1973 if (style[i] & WS_VISIBLE)
1974 ShowWindow(child[i], SW_SHOW);
1976 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
1978 else
1979 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
1980 parent, (HMENU)i, 0, NULL);
1981 trace("child[%d] = %p\n", i, child[i]);
1982 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
1985 hwnd = GetWindow(parent, GW_CHILD);
1986 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
1987 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
1988 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
1990 for (i = 0; i < total; i++)
1992 trace("hwnd[%d] = %p\n", i, hwnd);
1993 ok(child[order[i]] == hwnd, "Z order of child #%d is wrong\n", i);
1995 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1998 for (i = 0; i < total; i++)
1999 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2002 static void test_children_zorder(HWND parent)
2004 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2005 WS_CHILD };
2006 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2008 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2009 WS_CHILD | WS_VISIBLE, WS_CHILD,
2010 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2011 const int complex_order_1[1] = { 0 };
2012 const int complex_order_2[2] = { 1, 0 };
2013 const int complex_order_3[3] = { 1, 0, 2 };
2014 const int complex_order_4[4] = { 1, 0, 2, 3 };
2015 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2016 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2017 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2018 WS_CHILD | WS_VISIBLE };
2019 const int complex_order_6[3] = { 0, 1, 2 };
2021 /* simple WS_CHILD */
2022 test_window_tree(parent, simple_style, simple_order, 5);
2024 /* complex children styles */
2025 test_window_tree(parent, complex_style, complex_order_1, 1);
2026 test_window_tree(parent, complex_style, complex_order_2, 2);
2027 test_window_tree(parent, complex_style, complex_order_3, 3);
2028 test_window_tree(parent, complex_style, complex_order_4, 4);
2029 test_window_tree(parent, complex_style, complex_order_5, 5);
2031 /* another set of complex children styles */
2032 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2035 static void test_vis_rgn( HWND hwnd )
2037 RECT win_rect, rgn_rect;
2038 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2039 HDC hdc;
2041 ShowWindow(hwnd,SW_SHOW);
2042 hdc = GetDC( hwnd );
2043 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2044 GetWindowRect( hwnd, &win_rect );
2045 GetRgnBox( hrgn, &rgn_rect );
2046 if (GetVersion() & 0x80000000)
2048 trace("win9x, mapping to screen coords\n");
2049 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2051 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2052 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2053 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2054 rgn_rect.left, win_rect.left );
2055 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2056 rgn_rect.top, win_rect.top );
2057 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2058 rgn_rect.right, win_rect.right );
2059 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2060 rgn_rect.bottom, win_rect.bottom );
2061 ReleaseDC( hwnd, hdc );
2064 static void test_SetFocus(HWND hwnd)
2066 HWND child;
2068 /* check if we can set focus to non-visible windows */
2070 ShowWindow(hwnd, SW_SHOW);
2071 SetFocus(0);
2072 SetFocus(hwnd);
2073 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2074 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2075 ShowWindow(hwnd, SW_HIDE);
2076 SetFocus(0);
2077 SetFocus(hwnd);
2078 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2079 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2080 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2081 assert(child);
2082 SetFocus(child);
2083 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2084 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2085 ShowWindow(child, SW_SHOW);
2086 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2087 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2088 ShowWindow(child, SW_HIDE);
2089 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2090 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2091 ShowWindow(child, SW_SHOW);
2092 SetFocus(child);
2093 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2094 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2095 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2097 ShowWindow(child, SW_HIDE);
2098 SetFocus(hwnd);
2099 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2100 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2101 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2102 ShowWindow(child, SW_HIDE);
2103 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2105 ShowWindow(hwnd, SW_SHOW);
2106 ShowWindow(child, SW_SHOW);
2107 SetFocus(child);
2108 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2109 EnableWindow(hwnd, FALSE);
2110 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2111 EnableWindow(hwnd, TRUE);
2113 DestroyWindow( child );
2116 static void check_wnd_state(HWND active, HWND foreground, HWND focus, HWND capture)
2118 ok(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2119 if (foreground)
2120 ok(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2121 ok(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2122 ok(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2125 static void test_SetActiveWindow(HWND hwnd)
2127 HWND hwnd2;
2129 ShowWindow(hwnd, SW_HIDE);
2130 SetFocus(0);
2131 SetActiveWindow(0);
2132 check_wnd_state(0, 0, 0, 0);
2134 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2136 ShowWindow(hwnd, SW_SHOW);
2137 check_wnd_state(hwnd, hwnd, hwnd, 0);
2139 hwnd2 = SetActiveWindow(0);
2140 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2141 check_wnd_state(0, 0, 0, 0);
2143 hwnd2 = SetActiveWindow(hwnd);
2144 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2145 check_wnd_state(hwnd, hwnd, hwnd, 0);
2147 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2148 check_wnd_state(hwnd, hwnd, hwnd, 0);
2150 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2151 check_wnd_state(hwnd, hwnd, hwnd, 0);
2153 ShowWindow(hwnd, SW_HIDE);
2154 check_wnd_state(0, 0, 0, 0);
2156 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2157 SetActiveWindow(hwnd);
2158 check_wnd_state(hwnd, hwnd, hwnd, 0);
2160 ShowWindow(hwnd, SW_SHOW);
2161 check_wnd_state(hwnd, hwnd, hwnd, 0);
2163 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2164 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2166 DestroyWindow(hwnd2);
2167 check_wnd_state(hwnd, hwnd, hwnd, 0);
2169 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2170 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2172 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2173 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2175 DestroyWindow(hwnd2);
2176 check_wnd_state(hwnd, hwnd, hwnd, 0);
2179 static void test_SetForegroundWindow(HWND hwnd)
2181 BOOL ret;
2182 HWND hwnd2;
2184 ShowWindow(hwnd, SW_HIDE);
2185 SetFocus(0);
2186 SetActiveWindow(0);
2187 check_wnd_state(0, 0, 0, 0);
2189 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2191 ShowWindow(hwnd, SW_SHOW);
2192 check_wnd_state(hwnd, hwnd, hwnd, 0);
2194 hwnd2 = SetActiveWindow(0);
2195 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2196 check_wnd_state(0, 0, 0, 0);
2198 ret = SetForegroundWindow(hwnd);
2199 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2200 check_wnd_state(hwnd, hwnd, hwnd, 0);
2202 SetLastError(0xdeadbeef);
2203 ret = SetForegroundWindow(0);
2204 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2205 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2206 check_wnd_state(hwnd, hwnd, hwnd, 0);
2208 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2209 check_wnd_state(hwnd, hwnd, hwnd, 0);
2211 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2212 check_wnd_state(hwnd, hwnd, hwnd, 0);
2214 hwnd2 = GetForegroundWindow();
2215 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2216 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2217 hwnd2 = GetForegroundWindow();
2218 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2220 ShowWindow(hwnd, SW_HIDE);
2221 check_wnd_state(0, 0, 0, 0);
2223 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2224 ret = SetForegroundWindow(hwnd);
2225 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2226 check_wnd_state(hwnd, hwnd, hwnd, 0);
2228 ShowWindow(hwnd, SW_SHOW);
2229 check_wnd_state(hwnd, hwnd, hwnd, 0);
2231 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2232 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2234 DestroyWindow(hwnd2);
2235 check_wnd_state(hwnd, hwnd, hwnd, 0);
2237 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2238 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2240 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2241 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2243 DestroyWindow(hwnd2);
2244 check_wnd_state(hwnd, hwnd, hwnd, 0);
2247 static WNDPROC old_button_proc;
2249 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2251 LRESULT ret;
2252 USHORT key_state;
2254 key_state = GetKeyState(VK_LBUTTON);
2255 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2257 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2259 if (msg == WM_LBUTTONDOWN)
2261 HWND hwnd, capture;
2263 check_wnd_state(button, button, button, button);
2265 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2266 assert(hwnd);
2267 trace("hwnd %p\n", hwnd);
2269 check_wnd_state(button, button, button, button);
2271 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2273 check_wnd_state(button, button, button, button);
2275 DestroyWindow(hwnd);
2277 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2278 assert(hwnd);
2279 trace("hwnd %p\n", hwnd);
2281 check_wnd_state(button, button, button, button);
2283 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2284 * match internal button state.
2286 SendMessage(button, WM_KILLFOCUS, 0, 0);
2287 check_wnd_state(button, button, button, 0);
2289 ShowWindow(hwnd, SW_SHOW);
2290 check_wnd_state(hwnd, hwnd, hwnd, 0);
2292 capture = SetCapture(hwnd);
2293 ok(capture == 0, "SetCapture() = %p\n", capture);
2295 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2297 DestroyWindow(hwnd);
2299 check_wnd_state(button, 0, button, 0);
2302 return ret;
2305 static void test_capture_1(void)
2307 HWND button, capture;
2309 capture = GetCapture();
2310 ok(capture == 0, "GetCapture() = %p\n", capture);
2312 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2313 assert(button);
2314 trace("button %p\n", button);
2316 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2318 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2320 capture = SetCapture(button);
2321 ok(capture == 0, "SetCapture() = %p\n", capture);
2322 check_wnd_state(button, 0, button, button);
2324 DestroyWindow(button);
2325 check_wnd_state(0, 0, 0, 0);
2328 static void test_capture_2(void)
2330 HWND button, hwnd, capture;
2332 check_wnd_state(0, 0, 0, 0);
2334 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2335 assert(button);
2336 trace("button %p\n", button);
2338 check_wnd_state(button, button, button, 0);
2340 capture = SetCapture(button);
2341 ok(capture == 0, "SetCapture() = %p\n", capture);
2343 check_wnd_state(button, button, button, button);
2345 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2346 * internal button state.
2348 SendMessage(button, WM_KILLFOCUS, 0, 0);
2349 check_wnd_state(button, button, button, button);
2351 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2352 assert(hwnd);
2353 trace("hwnd %p\n", hwnd);
2355 check_wnd_state(button, button, button, button);
2357 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2359 check_wnd_state(button, button, button, button);
2361 DestroyWindow(hwnd);
2363 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2364 assert(hwnd);
2365 trace("hwnd %p\n", hwnd);
2367 check_wnd_state(button, button, button, button);
2369 ShowWindow(hwnd, SW_SHOW);
2371 check_wnd_state(hwnd, hwnd, hwnd, button);
2373 capture = SetCapture(hwnd);
2374 ok(capture == button, "SetCapture() = %p\n", capture);
2376 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2378 DestroyWindow(hwnd);
2379 check_wnd_state(button, button, button, 0);
2381 DestroyWindow(button);
2382 check_wnd_state(0, 0, 0, 0);
2385 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2387 BOOL ret;
2389 ShowWindow(hwnd1, SW_HIDE);
2390 ShowWindow(hwnd2, SW_HIDE);
2392 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2393 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2395 SetCapture(hwnd1);
2396 check_wnd_state(0, 0, 0, hwnd1);
2398 SetCapture(hwnd2);
2399 check_wnd_state(0, 0, 0, hwnd2);
2401 ShowWindow(hwnd1, SW_SHOW);
2402 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2404 ret = ReleaseCapture();
2405 ok (ret, "releasecapture did not return TRUE.\n");
2406 ret = ReleaseCapture();
2407 ok (ret, "releasecapture did not return TRUE after second try.\n");
2410 static void test_keyboard_input(HWND hwnd)
2412 MSG msg;
2413 BOOL ret;
2415 ShowWindow(hwnd, SW_SHOW);
2416 UpdateWindow(hwnd);
2417 flush_events();
2419 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2421 SetFocus(hwnd);
2422 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2424 flush_events();
2426 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2427 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2428 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2429 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2430 ok( !ret, "message %04x available\n", msg.message);
2432 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2434 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2435 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2436 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2437 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2438 ok( !ret, "message %04x available\n", msg.message);
2440 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2442 keybd_event(VK_SPACE, 0, 0, 0);
2443 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2444 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2445 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2446 ok( !ret, "message %04x available\n", msg.message);
2448 SetFocus(0);
2449 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2451 flush_events();
2453 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2454 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2455 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2456 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2457 ok( !ret, "message %04x available\n", msg.message);
2459 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2461 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2462 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2463 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2464 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2465 ok( !ret, "message %04x available\n", msg.message);
2467 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2469 keybd_event(VK_SPACE, 0, 0, 0);
2470 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2471 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2472 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2473 ok( !ret, "message %04x available\n", msg.message);
2476 static void test_mouse_input(HWND hwnd)
2478 RECT rc;
2479 POINT pt;
2480 int x, y;
2481 HWND popup;
2482 MSG msg;
2483 BOOL ret;
2484 LRESULT res;
2486 ShowWindow(hwnd, SW_SHOW);
2487 UpdateWindow(hwnd);
2489 GetWindowRect(hwnd, &rc);
2490 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2492 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2493 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2494 hwnd, 0, 0, NULL);
2495 assert(popup != 0);
2496 ShowWindow(popup, SW_SHOW);
2497 UpdateWindow(popup);
2499 GetWindowRect(popup, &rc);
2500 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2502 x = rc.left + (rc.right - rc.left) / 2;
2503 y = rc.top + (rc.bottom - rc.top) / 2;
2504 trace("setting cursor to (%d,%d)\n", x, y);
2506 SetCursorPos(x, y);
2507 GetCursorPos(&pt);
2508 ok(x == pt.x && y == pt.y, "wrong cursor pos (%d,%d), expected (%d,%d)\n", pt.x, pt.y, x, y);
2510 flush_events();
2512 /* Check that setting the same position will generate WM_MOUSEMOVE */
2513 SetCursorPos(x, y);
2514 msg.message = 0;
2515 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2516 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2517 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);
2519 /* force the system to update its internal queue mouse position,
2520 * otherwise it won't generate relative mouse movements below.
2522 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2523 flush_events();
2525 msg.message = 0;
2526 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2527 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2528 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2529 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2530 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2531 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2532 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2533 ok( !ret, "message %04x available\n", msg.message);
2535 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2536 ShowWindow(popup, SW_HIDE);
2537 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2538 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2539 flush_events();
2541 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2542 ShowWindow(hwnd, SW_HIDE);
2543 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2544 ok( !ret, "message %04x available\n", msg.message);
2546 /* test mouse clicks */
2548 ShowWindow(hwnd, SW_SHOW);
2549 ShowWindow(popup, SW_SHOW);
2550 flush_events();
2552 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2553 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2554 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2555 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2557 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2558 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2559 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2560 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2562 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2563 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2564 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2565 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2567 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2568 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2569 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2570 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2572 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2573 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2574 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2575 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2577 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2578 ok(!ret, "message %04x available\n", msg.message);
2580 ShowWindow(popup, SW_HIDE);
2581 flush_events();
2583 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2584 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2585 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2586 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2588 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2589 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2590 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2591 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2593 test_lbuttondown_flag = TRUE;
2594 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
2595 test_lbuttondown_flag = FALSE;
2597 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2598 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2599 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2600 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2601 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2603 /* Test WM_MOUSEACTIVATE */
2604 #define TEST_MOUSEACTIVATE(A,B) \
2605 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2606 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2608 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
2609 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
2610 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
2611 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
2612 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
2613 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
2614 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
2615 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
2616 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
2617 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
2618 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
2619 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
2620 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
2621 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
2622 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
2623 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
2624 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
2625 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
2626 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
2627 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
2628 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
2629 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
2630 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
2631 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
2633 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2634 flush_events();
2636 DestroyWindow(popup);
2639 static void test_validatergn(HWND hwnd)
2641 HWND child;
2642 RECT rc, rc2;
2643 HRGN rgn;
2644 int ret;
2645 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
2646 ShowWindow(hwnd, SW_SHOW);
2647 UpdateWindow( hwnd);
2648 /* test that ValidateRect validates children*/
2649 InvalidateRect( child, NULL, 1);
2650 GetWindowRect( child, &rc);
2651 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2652 ret = GetUpdateRect( child, &rc2, 0);
2653 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
2654 "Update rectangle is empty!\n");
2655 ValidateRect( hwnd, &rc);
2656 ret = GetUpdateRect( child, &rc2, 0);
2657 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2658 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2659 rc2.right, rc2.bottom);
2661 /* now test ValidateRgn */
2662 InvalidateRect( child, NULL, 1);
2663 GetWindowRect( child, &rc);
2664 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2665 rgn = CreateRectRgnIndirect( &rc);
2666 ValidateRgn( hwnd, rgn);
2667 ret = GetUpdateRect( child, &rc2, 0);
2668 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2669 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2670 rc2.right, rc2.bottom);
2672 DeleteObject( rgn);
2673 DestroyWindow( child );
2676 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
2678 MoveWindow( hwnd, 0, 0, x, y, 0);
2679 GetWindowRect( hwnd, prc);
2680 trace("window rect is %d,%d - %d,%d\n",
2681 prc->left,prc->top,prc->right,prc->bottom);
2682 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
2683 trace("nccalc rect is %d,%d - %d,%d\n",
2684 prc->left,prc->top,prc->right,prc->bottom);
2687 static void test_nccalcscroll(HWND parent)
2689 RECT rc1;
2690 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
2691 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
2692 HWND hwnd = CreateWindowExA(0, "static", NULL,
2693 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
2694 10, 10, 200, 200, parent, 0, 0, NULL);
2695 ShowWindow( parent, SW_SHOW);
2696 UpdateWindow( parent);
2698 /* test window too low for a horizontal scroll bar */
2699 nccalchelper( hwnd, 100, sbheight, &rc1);
2700 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
2701 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
2703 /* test window just high enough for a horizontal scroll bar */
2704 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
2705 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
2706 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2708 /* test window too narrow for a vertical scroll bar */
2709 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
2710 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
2711 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2713 /* test window just wide enough for a vertical scroll bar */
2714 nccalchelper( hwnd, sbwidth, 100, &rc1);
2715 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
2716 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
2718 /* same test, but with client edge: not enough width */
2719 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
2720 nccalchelper( hwnd, sbwidth, 100, &rc1);
2721 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
2722 "Width should be %d size is %d,%d - %d,%d\n",
2723 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
2725 DestroyWindow( hwnd);
2728 static void test_SetParent(void)
2730 BOOL ret;
2731 HWND desktop = GetDesktopWindow();
2732 HMENU hMenu;
2733 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
2734 HWND parent, child1, child2, child3, child4, sibling;
2736 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2737 100, 100, 200, 200, 0, 0, 0, NULL);
2738 assert(parent != 0);
2739 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2740 0, 0, 50, 50, parent, 0, 0, NULL);
2741 assert(child1 != 0);
2742 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2743 0, 0, 50, 50, child1, 0, 0, NULL);
2744 assert(child2 != 0);
2745 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2746 0, 0, 50, 50, child2, 0, 0, NULL);
2747 assert(child3 != 0);
2748 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2749 0, 0, 50, 50, child3, 0, 0, NULL);
2750 assert(child4 != 0);
2752 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2753 parent, child1, child2, child3, child4);
2755 check_parents(parent, desktop, 0, 0, 0, parent, parent);
2756 check_parents(child1, parent, parent, parent, 0, parent, parent);
2757 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2758 check_parents(child3, child2, child2, child2, 0, child2, parent);
2759 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2761 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
2762 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
2763 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2764 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
2765 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2767 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
2768 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2769 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
2770 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
2771 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
2772 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
2773 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
2774 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
2775 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2777 if (!is_win9x) /* Win9x doesn't survive this test */
2779 ok(!SetParent(parent, child1), "SetParent should fail\n");
2780 ok(!SetParent(child2, child3), "SetParent should fail\n");
2781 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
2782 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
2783 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
2784 ok(!SetParent(child2, parent), "SetParent should fail\n");
2785 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
2787 check_parents(parent, child4, child4, 0, 0, child4, parent);
2788 check_parents(child1, parent, parent, parent, 0, child4, parent);
2789 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2790 check_parents(child3, child2, child2, child2, 0, child2, parent);
2791 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2794 hMenu = CreateMenu();
2795 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2796 100, 100, 200, 200, 0, hMenu, 0, NULL);
2797 assert(sibling != 0);
2799 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
2800 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
2802 ret = DestroyWindow(parent);
2803 ok( ret, "DestroyWindow() error %d\n", GetLastError());
2805 ok(!IsWindow(parent), "parent still exists\n");
2806 ok(!IsWindow(sibling), "sibling still exists\n");
2807 ok(!IsWindow(child1), "child1 still exists\n");
2808 ok(!IsWindow(child2), "child2 still exists\n");
2809 ok(!IsWindow(child3), "child3 still exists\n");
2810 ok(!IsWindow(child4), "child4 still exists\n");
2813 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2815 LPCREATESTRUCT lpcs;
2816 LPSTYLESTRUCT lpss;
2818 switch (msg)
2820 case WM_NCCREATE:
2821 case WM_CREATE:
2822 lpcs = (LPCREATESTRUCT)lparam;
2823 lpss = (LPSTYLESTRUCT)lpcs->lpCreateParams;
2824 if (lpss)
2826 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
2827 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
2828 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
2829 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
2830 else
2831 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
2833 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
2834 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2835 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
2837 ok(lpss->styleNew == lpcs->style,
2838 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
2839 lpss->styleNew, lpcs->style);
2841 break;
2843 return DefWindowProc(hwnd, msg, wparam, lparam);
2846 static ATOM atomStyleCheckClass;
2848 static void register_style_check_class(void)
2850 WNDCLASS wc =
2853 StyleCheckProc,
2856 GetModuleHandle(NULL),
2857 NULL,
2858 LoadCursor(NULL, IDC_ARROW),
2859 (HBRUSH)(COLOR_BTNFACE+1),
2860 NULL,
2861 TEXT("WineStyleCheck"),
2864 atomStyleCheckClass = RegisterClass(&wc);
2867 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
2869 DWORD dwActualStyle;
2870 DWORD dwActualExStyle;
2871 STYLESTRUCT ss;
2872 HWND hwnd;
2873 HWND hwndParent = NULL;
2875 ss.styleNew = dwStyleIn;
2876 ss.styleOld = dwExStyleIn;
2878 if (dwStyleIn & WS_CHILD)
2880 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
2881 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
2884 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
2885 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
2886 assert(hwnd);
2888 flush_events();
2890 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
2891 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
2892 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
2893 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
2894 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
2896 DestroyWindow(hwnd);
2897 if (hwndParent) DestroyWindow(hwndParent);
2900 /* tests what window styles the window manager automatically adds */
2901 static void test_window_styles(void)
2903 register_style_check_class();
2905 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
2906 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
2907 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
2908 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
2909 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
2910 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
2911 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
2912 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
2913 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
2914 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
2915 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
2918 static void test_scrollvalidate( HWND parent)
2920 HDC hdc;
2921 HRGN hrgn=CreateRectRgn(0,0,0,0);
2922 HRGN exprgn, tmprgn, clipping;
2923 RECT rc, rcu, cliprc;
2924 /* create two overlapping child windows. The visual region
2925 * of hwnd1 is clipped by the overlapping part of
2926 * hwnd2 because of the WS_CLIPSIBLING style */
2927 HWND hwnd1, hwnd2;
2929 clipping = CreateRectRgn(0,0,0,0);
2930 tmprgn = CreateRectRgn(0,0,0,0);
2931 exprgn = CreateRectRgn(0,0,0,0);
2932 hwnd2 = CreateWindowExA(0, "static", NULL,
2933 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
2934 75, 30, 100, 100, parent, 0, 0, NULL);
2935 hwnd1 = CreateWindowExA(0, "static", NULL,
2936 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
2937 25, 50, 100, 100, parent, 0, 0, NULL);
2938 ShowWindow( parent, SW_SHOW);
2939 UpdateWindow( parent);
2940 GetClientRect( hwnd1, &rc);
2941 cliprc=rc;
2942 SetRectRgn( clipping, 10, 10, 90, 90);
2943 hdc = GetDC( hwnd1);
2944 /* for a visual touch */
2945 TextOut( hdc, 0,10, "0123456789", 10);
2946 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
2947 if (winetest_debug > 0) dump_region(hrgn);
2948 /* create a region with what is expected */
2949 SetRectRgn( exprgn, 39,0,49,74);
2950 SetRectRgn( tmprgn, 88,79,98,93);
2951 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2952 SetRectRgn( tmprgn, 0,93,98,98);
2953 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2954 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2955 trace("update rect is %d,%d - %d,%d\n",
2956 rcu.left,rcu.top,rcu.right,rcu.bottom);
2957 /* now with clipping region */
2958 SelectClipRgn( hdc, clipping);
2959 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
2960 if (winetest_debug > 0) dump_region(hrgn);
2961 /* create a region with what is expected */
2962 SetRectRgn( exprgn, 39,10,49,74);
2963 SetRectRgn( tmprgn, 80,79,90,85);
2964 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2965 SetRectRgn( tmprgn, 10,85,90,90);
2966 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2967 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2968 trace("update rect is %d,%d - %d,%d\n",
2969 rcu.left,rcu.top,rcu.right,rcu.bottom);
2970 ReleaseDC( hwnd1, hdc);
2972 /* test scrolling a window with an update region */
2973 DestroyWindow( hwnd2);
2974 ValidateRect( hwnd1, NULL);
2975 SetRect( &rc, 40,40, 50,50);
2976 InvalidateRect( hwnd1, &rc, 1);
2977 GetClientRect( hwnd1, &rc);
2978 cliprc=rc;
2979 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
2980 SW_SCROLLCHILDREN | SW_INVALIDATE);
2981 if (winetest_debug > 0) dump_region(hrgn);
2982 SetRectRgn( exprgn, 88,0,98,98);
2983 SetRectRgn( tmprgn, 30, 40, 50, 50);
2984 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2985 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2987 /* clear an update region */
2988 UpdateWindow( hwnd1 );
2990 SetRect( &rc, 0,40, 100,60);
2991 SetRect( &cliprc, 0,0, 100,100);
2992 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
2993 if (winetest_debug > 0) dump_region( hrgn );
2994 SetRectRgn( exprgn, 0, 40, 98, 60 );
2995 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
2997 /* now test ScrollWindowEx with a combination of
2998 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
2999 /* make hwnd2 the child of hwnd1 */
3000 hwnd2 = CreateWindowExA(0, "static", NULL,
3001 WS_CHILD| WS_VISIBLE | WS_BORDER ,
3002 50, 50, 100, 100, hwnd1, 0, 0, NULL);
3003 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
3004 GetClientRect( hwnd1, &rc);
3005 cliprc=rc;
3007 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3008 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3009 ValidateRect( hwnd1, NULL);
3010 ValidateRect( hwnd2, NULL);
3011 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
3012 SW_SCROLLCHILDREN | SW_INVALIDATE);
3013 if (winetest_debug > 0) dump_region(hrgn);
3014 SetRectRgn( exprgn, 88,0,98,88);
3015 SetRectRgn( tmprgn, 0,88,98,98);
3016 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3017 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3019 /* SW_SCROLLCHILDREN */
3020 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3021 ValidateRect( hwnd1, NULL);
3022 ValidateRect( hwnd2, NULL);
3023 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3024 if (winetest_debug > 0) dump_region(hrgn);
3025 /* expected region is the same as in previous test */
3026 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3028 /* no SW_SCROLLCHILDREN */
3029 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3030 ValidateRect( hwnd1, NULL);
3031 ValidateRect( hwnd2, NULL);
3032 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3033 if (winetest_debug > 0) dump_region(hrgn);
3034 /* expected region is the same as in previous test */
3035 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3037 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3038 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3039 ValidateRect( hwnd1, NULL);
3040 ValidateRect( hwnd2, NULL);
3041 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3042 if (winetest_debug > 0) dump_region(hrgn);
3043 SetRectRgn( exprgn, 88,0,98,20);
3044 SetRectRgn( tmprgn, 20,20,98,30);
3045 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3046 SetRectRgn( tmprgn, 20,30,30,88);
3047 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3048 SetRectRgn( tmprgn, 0,88,30,98);
3049 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3050 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3052 /* clean up */
3053 DeleteObject( hrgn);
3054 DeleteObject( exprgn);
3055 DeleteObject( tmprgn);
3056 DestroyWindow( hwnd1);
3057 DestroyWindow( hwnd2);
3060 /* couple of tests of return values of scrollbar functions
3061 * called on a scrollbarless window */
3062 static void test_scroll(void)
3064 BOOL ret;
3065 INT min, max;
3066 SCROLLINFO si;
3067 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3068 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3069 100, 100, 200, 200, 0, 0, 0, NULL);
3070 /* horizontal */
3071 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3072 ok( ret, "GetScrollRange returns FALSE\n");
3073 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3074 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3075 si.cbSize = sizeof( si);
3076 si.fMask = SIF_PAGE;
3077 si.nPage = 0xdeadbeef;
3078 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3079 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3080 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3081 /* vertical */
3082 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3083 ok( ret, "GetScrollRange returns FALSE\n");
3084 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3085 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3086 si.cbSize = sizeof( si);
3087 si.fMask = SIF_PAGE;
3088 si.nPage = 0xdeadbeef;
3089 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3090 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3091 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3092 /* clean up */
3093 DestroyWindow( hwnd);
3096 static void test_scrolldc( HWND parent)
3098 HDC hdc;
3099 HRGN exprgn, tmprgn, hrgn;
3100 RECT rc, rc2, rcu, cliprc;
3101 HWND hwnd1;
3102 COLORREF colr;
3104 hrgn = CreateRectRgn(0,0,0,0);
3105 tmprgn = CreateRectRgn(0,0,0,0);
3106 exprgn = CreateRectRgn(0,0,0,0);
3108 hwnd1 = CreateWindowExA(0, "static", NULL,
3109 WS_CHILD| WS_VISIBLE,
3110 25, 50, 100, 100, parent, 0, 0, NULL);
3111 ShowWindow( parent, SW_SHOW);
3112 UpdateWindow( parent);
3113 GetClientRect( hwnd1, &rc);
3114 hdc = GetDC( hwnd1);
3115 /* paint the upper half of the window black */
3116 rc2 = rc;
3117 rc2.bottom = ( rc.top + rc.bottom) /2;
3118 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3119 /* clip region is the lower half */
3120 cliprc=rc;
3121 cliprc.top = (rc.top + rc.bottom) /2;
3122 /* test whether scrolled pixels are properly clipped */
3123 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3124 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3125 /* this scroll should not cause any visible changes */
3126 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3127 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3128 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3129 /* test with NULL clip rect */
3130 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3131 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3132 trace("update rect: %d,%d - %d,%d\n",
3133 rcu.left, rcu.top, rcu.right, rcu.bottom);
3134 if (winetest_debug > 0) dump_region(hrgn);
3135 SetRect(&rc2, 0, 0, 100, 100);
3136 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3137 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3139 SetRectRgn( exprgn, 0, 0, 20, 80);
3140 SetRectRgn( tmprgn, 0, 80, 100, 100);
3141 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3142 if (winetest_debug > 0) dump_region(exprgn);
3143 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3144 /* test clip rect > scroll rect */
3145 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3146 rc2=rc;
3147 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3148 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3149 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3150 SetRectRgn( exprgn, 25, 25, 75, 35);
3151 SetRectRgn( tmprgn, 25, 35, 35, 75);
3152 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3153 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3154 colr = GetPixel( hdc, 80, 80);
3155 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3156 trace("update rect: %d,%d - %d,%d\n",
3157 rcu.left, rcu.top, rcu.right, rcu.bottom);
3158 if (winetest_debug > 0) dump_region(hrgn);
3160 /* clean up */
3161 DeleteObject(hrgn);
3162 DeleteObject(exprgn);
3163 DeleteObject(tmprgn);
3164 DestroyWindow(hwnd1);
3167 static void test_params(void)
3169 HWND hwnd;
3170 INT rc;
3172 /* Just a param check */
3173 SetLastError(0xdeadbeef);
3174 rc = GetWindowText(hwndMain2, NULL, 1024);
3175 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
3177 SetLastError(0xdeadbeef);
3178 hwnd=CreateWindow("LISTBOX", "TestList",
3179 (LBS_STANDARD & ~LBS_SORT),
3180 0, 0, 100, 100,
3181 NULL, (HMENU)1, NULL, 0);
3183 ok(!hwnd, "CreateWindow with invalid menu handle should fail\n");
3184 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3185 GetLastError() == 0xdeadbeef, /* Win9x */
3186 "wrong last error value %d\n", GetLastError());
3189 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3191 HWND hwnd = 0;
3193 hwnd = CreateWindowEx(exStyle, class, class, style,
3194 110, 100,
3195 225, 200,
3197 menu ? hmenu : 0,
3198 0, 0);
3199 if (!hwnd) {
3200 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
3201 return;
3203 ShowWindow(hwnd, SW_SHOW);
3205 test_nonclient_area(hwnd);
3207 SetMenu(hwnd, 0);
3208 DestroyWindow(hwnd);
3211 static BOOL AWR_init(void)
3213 WNDCLASS class;
3215 class.style = CS_HREDRAW | CS_VREDRAW;
3216 class.lpfnWndProc = DefWindowProcA;
3217 class.cbClsExtra = 0;
3218 class.cbWndExtra = 0;
3219 class.hInstance = 0;
3220 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3221 class.hCursor = LoadCursor (0, IDC_ARROW);
3222 class.hbrBackground = 0;
3223 class.lpszMenuName = 0;
3224 class.lpszClassName = szAWRClass;
3226 if (!RegisterClass (&class)) {
3227 ok(FALSE, "RegisterClass failed\n");
3228 return FALSE;
3231 hmenu = CreateMenu();
3232 if (!hmenu)
3233 return FALSE;
3234 ok(hmenu != 0, "Failed to create menu\n");
3235 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3237 return TRUE;
3241 static void test_AWR_window_size(BOOL menu)
3243 LONG styles[] = {
3244 WS_POPUP,
3245 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3246 WS_SYSMENU,
3247 WS_THICKFRAME,
3248 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3249 WS_HSCROLL, WS_VSCROLL
3251 LONG exStyles[] = {
3252 WS_EX_CLIENTEDGE,
3253 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3254 WS_EX_APPWINDOW,
3255 #if 0
3256 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3257 WS_EX_DLGMODALFRAME,
3258 WS_EX_STATICEDGE,
3259 #endif
3262 int i;
3264 /* A exhaustive check of all the styles takes too long
3265 * so just do a (hopefully representative) sample
3267 for (i = 0; i < COUNTOF(styles); ++i)
3268 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3269 for (i = 0; i < COUNTOF(exStyles); ++i) {
3270 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3271 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3274 #undef COUNTOF
3276 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3278 static void test_AdjustWindowRect(void)
3280 if (!AWR_init())
3281 return;
3283 SHOWSYSMETRIC(SM_CYCAPTION);
3284 SHOWSYSMETRIC(SM_CYSMCAPTION);
3285 SHOWSYSMETRIC(SM_CYMENU);
3286 SHOWSYSMETRIC(SM_CXEDGE);
3287 SHOWSYSMETRIC(SM_CYEDGE);
3288 SHOWSYSMETRIC(SM_CXVSCROLL);
3289 SHOWSYSMETRIC(SM_CYHSCROLL);
3290 SHOWSYSMETRIC(SM_CXFRAME);
3291 SHOWSYSMETRIC(SM_CYFRAME);
3292 SHOWSYSMETRIC(SM_CXDLGFRAME);
3293 SHOWSYSMETRIC(SM_CYDLGFRAME);
3294 SHOWSYSMETRIC(SM_CXBORDER);
3295 SHOWSYSMETRIC(SM_CYBORDER);
3297 test_AWR_window_size(FALSE);
3298 test_AWR_window_size(TRUE);
3300 DestroyMenu(hmenu);
3302 #undef SHOWSYSMETRIC
3305 /* Global variables to trigger exit from loop */
3306 static int redrawComplete, WMPAINT_count;
3308 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3310 switch (msg)
3312 case WM_PAINT:
3313 trace("doing WM_PAINT %d\n", WMPAINT_count);
3314 WMPAINT_count++;
3315 if (WMPAINT_count > 10 && redrawComplete == 0) {
3316 PAINTSTRUCT ps;
3317 BeginPaint(hwnd, &ps);
3318 EndPaint(hwnd, &ps);
3319 return 1;
3321 return 0;
3323 return DefWindowProc(hwnd, msg, wparam, lparam);
3326 /* Ensure we exit from RedrawNow regardless of invalidated area */
3327 static void test_redrawnow(void)
3329 WNDCLASSA cls;
3330 HWND hwndMain;
3332 cls.style = CS_DBLCLKS;
3333 cls.lpfnWndProc = redraw_window_procA;
3334 cls.cbClsExtra = 0;
3335 cls.cbWndExtra = 0;
3336 cls.hInstance = GetModuleHandleA(0);
3337 cls.hIcon = 0;
3338 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3339 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3340 cls.lpszMenuName = NULL;
3341 cls.lpszClassName = "RedrawWindowClass";
3343 if(!RegisterClassA(&cls)) {
3344 trace("Register failed %d\n", GetLastError());
3345 return;
3348 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3349 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3351 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3352 ShowWindow(hwndMain, SW_SHOW);
3353 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3354 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3355 ok( WMPAINT_count == 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3356 redrawComplete = TRUE;
3357 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3359 /* clean up */
3360 DestroyWindow( hwndMain);
3363 struct parentdc_stat {
3364 RECT client;
3365 RECT clip;
3366 RECT paint;
3369 struct parentdc_test {
3370 struct parentdc_stat main, main_todo;
3371 struct parentdc_stat child1, child1_todo;
3372 struct parentdc_stat child2, child2_todo;
3375 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3377 RECT rc;
3378 PAINTSTRUCT ps;
3380 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3382 switch (msg)
3384 case WM_PAINT:
3385 trace("doing WM_PAINT on %p\n", hwnd);
3386 GetClientRect(hwnd, &rc);
3387 CopyRect(&t->client, &rc);
3388 trace("client rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3389 GetWindowRect(hwnd, &rc);
3390 trace("window rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3391 BeginPaint(hwnd, &ps);
3392 CopyRect(&t->paint, &ps.rcPaint);
3393 GetClipBox(ps.hdc, &rc);
3394 CopyRect(&t->clip, &rc);
3395 trace("clip rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3396 trace("paint rect (%d, %d)-(%d, %d)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3397 EndPaint(hwnd, &ps);
3398 return 0;
3400 return DefWindowProc(hwnd, msg, wparam, lparam);
3403 static void zero_parentdc_stat(struct parentdc_stat *t)
3405 SetRectEmpty(&t->client);
3406 SetRectEmpty(&t->clip);
3407 SetRectEmpty(&t->paint);
3410 static void zero_parentdc_test(struct parentdc_test *t)
3412 zero_parentdc_stat(&t->main);
3413 zero_parentdc_stat(&t->child1);
3414 zero_parentdc_stat(&t->child2);
3417 #define parentdc_field_ok(t, w, r, f, got) \
3418 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3419 ": expected %d, got %d\n", \
3420 t.w.r.f, got.w.r.f)
3422 #define parentdc_todo_field_ok(t, w, r, f, got) \
3423 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3424 else parentdc_field_ok(t, w, r, f, got)
3426 #define parentdc_rect_ok(t, w, r, got) \
3427 parentdc_todo_field_ok(t, w, r, left, got); \
3428 parentdc_todo_field_ok(t, w, r, top, got); \
3429 parentdc_todo_field_ok(t, w, r, right, got); \
3430 parentdc_todo_field_ok(t, w, r, bottom, got);
3432 #define parentdc_win_ok(t, w, got) \
3433 parentdc_rect_ok(t, w, client, got); \
3434 parentdc_rect_ok(t, w, clip, got); \
3435 parentdc_rect_ok(t, w, paint, got);
3437 #define parentdc_ok(t, got) \
3438 parentdc_win_ok(t, main, got); \
3439 parentdc_win_ok(t, child1, got); \
3440 parentdc_win_ok(t, child2, got);
3442 static void test_csparentdc(void)
3444 WNDCLASSA clsMain, cls;
3445 HWND hwndMain, hwnd1, hwnd2;
3446 RECT rc;
3448 struct parentdc_test test_answer;
3450 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3451 const struct parentdc_test test1 =
3453 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
3454 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3455 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3458 const struct parentdc_test test2 =
3460 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
3461 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3462 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3465 const struct parentdc_test test3 =
3467 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3468 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3469 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3472 const struct parentdc_test test4 =
3474 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
3475 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
3476 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3479 const struct parentdc_test test5 =
3481 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
3482 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3483 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3486 const struct parentdc_test test6 =
3488 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3489 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3490 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3493 const struct parentdc_test test7 =
3495 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3496 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3497 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3499 #undef nothing_todo
3501 clsMain.style = CS_DBLCLKS;
3502 clsMain.lpfnWndProc = parentdc_window_procA;
3503 clsMain.cbClsExtra = 0;
3504 clsMain.cbWndExtra = 0;
3505 clsMain.hInstance = GetModuleHandleA(0);
3506 clsMain.hIcon = 0;
3507 clsMain.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3508 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
3509 clsMain.lpszMenuName = NULL;
3510 clsMain.lpszClassName = "ParentDcMainWindowClass";
3512 if(!RegisterClassA(&clsMain)) {
3513 trace("Register failed %d\n", GetLastError());
3514 return;
3517 cls.style = CS_DBLCLKS | CS_PARENTDC;
3518 cls.lpfnWndProc = parentdc_window_procA;
3519 cls.cbClsExtra = 0;
3520 cls.cbWndExtra = 0;
3521 cls.hInstance = GetModuleHandleA(0);
3522 cls.hIcon = 0;
3523 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3524 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3525 cls.lpszMenuName = NULL;
3526 cls.lpszClassName = "ParentDcWindowClass";
3528 if(!RegisterClassA(&cls)) {
3529 trace("Register failed %d\n", GetLastError());
3530 return;
3533 SetRect(&rc, 0, 0, 150, 150);
3534 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
3535 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3536 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
3537 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
3538 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
3539 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
3540 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
3541 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
3542 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
3543 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
3544 ShowWindow(hwndMain, SW_SHOW);
3545 ShowWindow(hwnd1, SW_SHOW);
3546 ShowWindow(hwnd2, SW_SHOW);
3547 flush_events();
3549 zero_parentdc_test(&test_answer);
3550 InvalidateRect(hwndMain, NULL, TRUE);
3551 flush_events();
3552 parentdc_ok(test1, test_answer);
3554 zero_parentdc_test(&test_answer);
3555 SetRect(&rc, 0, 0, 50, 50);
3556 InvalidateRect(hwndMain, &rc, TRUE);
3557 flush_events();
3558 parentdc_ok(test2, test_answer);
3560 zero_parentdc_test(&test_answer);
3561 SetRect(&rc, 0, 0, 10, 10);
3562 InvalidateRect(hwndMain, &rc, TRUE);
3563 flush_events();
3564 parentdc_ok(test3, test_answer);
3566 zero_parentdc_test(&test_answer);
3567 SetRect(&rc, 40, 40, 50, 50);
3568 InvalidateRect(hwndMain, &rc, TRUE);
3569 flush_events();
3570 parentdc_ok(test4, test_answer);
3572 zero_parentdc_test(&test_answer);
3573 SetRect(&rc, 20, 20, 60, 60);
3574 InvalidateRect(hwndMain, &rc, TRUE);
3575 flush_events();
3576 parentdc_ok(test5, test_answer);
3578 zero_parentdc_test(&test_answer);
3579 SetRect(&rc, 0, 0, 10, 10);
3580 InvalidateRect(hwnd1, &rc, TRUE);
3581 flush_events();
3582 parentdc_ok(test6, test_answer);
3584 zero_parentdc_test(&test_answer);
3585 SetRect(&rc, -5, -5, 65, 65);
3586 InvalidateRect(hwnd1, &rc, TRUE);
3587 flush_events();
3588 parentdc_ok(test7, test_answer);
3590 DestroyWindow(hwndMain);
3591 DestroyWindow(hwnd1);
3592 DestroyWindow(hwnd2);
3595 static void test_IsWindowUnicode(void)
3597 static const char ansi_class_nameA[] = "ansi class name";
3598 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3599 static const char unicode_class_nameA[] = "unicode class name";
3600 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3601 WNDCLASSA classA;
3602 WNDCLASSW classW;
3603 HWND hwnd;
3605 memset(&classW, 0, sizeof(classW));
3606 classW.hInstance = GetModuleHandleA(0);
3607 classW.lpfnWndProc = DefWindowProcW;
3608 classW.lpszClassName = unicode_class_nameW;
3609 if (!RegisterClassW(&classW)) return;
3611 memset(&classA, 0, sizeof(classA));
3612 classA.hInstance = GetModuleHandleA(0);
3613 classA.lpfnWndProc = DefWindowProcA;
3614 classA.lpszClassName = ansi_class_nameA;
3615 assert(RegisterClassA(&classA));
3617 /* unicode class: window proc */
3618 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3619 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3620 assert(hwnd);
3622 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3623 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3624 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3625 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3626 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3628 DestroyWindow(hwnd);
3630 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3631 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3632 assert(hwnd);
3634 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3635 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3636 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3637 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3638 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3640 DestroyWindow(hwnd);
3642 /* ansi class: window proc */
3643 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3644 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3645 assert(hwnd);
3647 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3648 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3649 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3650 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3651 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3653 DestroyWindow(hwnd);
3655 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3656 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3657 assert(hwnd);
3659 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3660 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3661 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3662 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3663 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3665 DestroyWindow(hwnd);
3667 /* unicode class: class proc */
3668 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3669 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3670 assert(hwnd);
3672 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3673 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3674 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3675 /* do not restore class window proc back to unicode */
3677 DestroyWindow(hwnd);
3679 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3680 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3681 assert(hwnd);
3683 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3684 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3685 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3687 DestroyWindow(hwnd);
3689 /* ansi class: class proc */
3690 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3691 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3692 assert(hwnd);
3694 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3695 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3696 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3697 /* do not restore class window proc back to ansi */
3699 DestroyWindow(hwnd);
3701 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3702 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3703 assert(hwnd);
3705 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3706 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3707 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3709 DestroyWindow(hwnd);
3712 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
3714 MINMAXINFO *minmax;
3716 if (msg != WM_GETMINMAXINFO)
3717 return DefWindowProc(hwnd, msg, wp, lp);
3719 minmax = (MINMAXINFO *)lp;
3721 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
3723 minmax->ptReserved.x = 0;
3724 minmax->ptReserved.y = 0;
3725 minmax->ptMaxSize.x = 400;
3726 minmax->ptMaxSize.y = 400;
3727 minmax->ptMaxPosition.x = 300;
3728 minmax->ptMaxPosition.y = 300;
3729 minmax->ptMaxTrackSize.x = 200;
3730 minmax->ptMaxTrackSize.y = 200;
3731 minmax->ptMinTrackSize.x = 100;
3732 minmax->ptMinTrackSize.y = 100;
3734 else
3735 DefWindowProc(hwnd, msg, wp, lp);
3736 return 1;
3739 static void test_CreateWindow(void)
3741 WNDCLASS cls;
3742 HWND hwnd, parent;
3743 HMENU hmenu;
3744 RECT rc, rc_minmax;
3745 MINMAXINFO minmax;
3747 #define expect_menu(window, menu) \
3748 SetLastError(0xdeadbeef); \
3749 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
3751 #define expect_style(window, style)\
3752 ok(GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
3754 #define expect_ex_style(window, ex_style)\
3755 ok(GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
3757 hmenu = CreateMenu();
3758 assert(hmenu != 0);
3759 parent = GetDesktopWindow();
3760 assert(parent != 0);
3762 SetLastError(0xdeadbeef);
3763 ok(IsMenu(hmenu), "IsMenu error %d\n", GetLastError());
3765 /* WS_CHILD */
3766 SetLastError(0xdeadbeef);
3767 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
3768 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3769 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3770 expect_menu(hwnd, 1);
3771 expect_style(hwnd, WS_CHILD);
3772 expect_ex_style(hwnd, WS_EX_APPWINDOW);
3773 DestroyWindow(hwnd);
3775 SetLastError(0xdeadbeef);
3776 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
3777 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3778 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3779 expect_menu(hwnd, 1);
3780 expect_style(hwnd, WS_CHILD | WS_CAPTION);
3781 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
3782 DestroyWindow(hwnd);
3784 SetLastError(0xdeadbeef);
3785 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
3786 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3787 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3788 expect_menu(hwnd, 1);
3789 expect_style(hwnd, WS_CHILD);
3790 expect_ex_style(hwnd, 0);
3791 DestroyWindow(hwnd);
3793 SetLastError(0xdeadbeef);
3794 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
3795 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3796 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3797 expect_menu(hwnd, 1);
3798 expect_style(hwnd, WS_CHILD | WS_CAPTION);
3799 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
3800 DestroyWindow(hwnd);
3802 /* WS_POPUP */
3803 SetLastError(0xdeadbeef);
3804 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
3805 0, 0, 100, 100, parent, hmenu, 0, NULL);
3806 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3807 expect_menu(hwnd, hmenu);
3808 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
3809 expect_ex_style(hwnd, WS_EX_APPWINDOW);
3810 DestroyWindow(hwnd);
3811 SetLastError(0xdeadbeef);
3812 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3813 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3815 hmenu = CreateMenu();
3816 assert(hmenu != 0);
3817 SetLastError(0xdeadbeef);
3818 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
3819 0, 0, 100, 100, parent, hmenu, 0, NULL);
3820 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3821 expect_menu(hwnd, hmenu);
3822 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
3823 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
3824 DestroyWindow(hwnd);
3825 SetLastError(0xdeadbeef);
3826 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3827 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3829 hmenu = CreateMenu();
3830 assert(hmenu != 0);
3831 SetLastError(0xdeadbeef);
3832 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
3833 0, 0, 100, 100, parent, hmenu, 0, NULL);
3834 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3835 expect_menu(hwnd, hmenu);
3836 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
3837 expect_ex_style(hwnd, 0);
3838 DestroyWindow(hwnd);
3839 SetLastError(0xdeadbeef);
3840 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3841 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3843 hmenu = CreateMenu();
3844 assert(hmenu != 0);
3845 SetLastError(0xdeadbeef);
3846 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
3847 0, 0, 100, 100, parent, hmenu, 0, NULL);
3848 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3849 expect_menu(hwnd, hmenu);
3850 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
3851 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
3852 DestroyWindow(hwnd);
3853 SetLastError(0xdeadbeef);
3854 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3855 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3857 /* WS_CHILD | WS_POPUP */
3858 SetLastError(0xdeadbeef);
3859 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
3860 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3861 ok(!hwnd, "CreateWindowEx should fail\n");
3862 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3864 hmenu = CreateMenu();
3865 assert(hmenu != 0);
3866 SetLastError(0xdeadbeef);
3867 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
3868 0, 0, 100, 100, parent, hmenu, 0, NULL);
3869 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3870 expect_menu(hwnd, hmenu);
3871 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
3872 expect_ex_style(hwnd, WS_EX_APPWINDOW);
3873 DestroyWindow(hwnd);
3874 SetLastError(0xdeadbeef);
3875 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3876 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3878 SetLastError(0xdeadbeef);
3879 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
3880 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3881 ok(!hwnd, "CreateWindowEx should fail\n");
3882 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3884 hmenu = CreateMenu();
3885 assert(hmenu != 0);
3886 SetLastError(0xdeadbeef);
3887 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
3888 0, 0, 100, 100, parent, hmenu, 0, NULL);
3889 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3890 expect_menu(hwnd, hmenu);
3891 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
3892 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
3893 DestroyWindow(hwnd);
3894 SetLastError(0xdeadbeef);
3895 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3896 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3898 SetLastError(0xdeadbeef);
3899 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
3900 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3901 ok(!hwnd, "CreateWindowEx should fail\n");
3902 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3904 hmenu = CreateMenu();
3905 assert(hmenu != 0);
3906 SetLastError(0xdeadbeef);
3907 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
3908 0, 0, 100, 100, parent, hmenu, 0, NULL);
3909 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3910 expect_menu(hwnd, hmenu);
3911 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
3912 expect_ex_style(hwnd, 0);
3913 DestroyWindow(hwnd);
3914 SetLastError(0xdeadbeef);
3915 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3916 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3918 SetLastError(0xdeadbeef);
3919 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
3920 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3921 ok(!hwnd, "CreateWindowEx should fail\n");
3922 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3924 hmenu = CreateMenu();
3925 assert(hmenu != 0);
3926 SetLastError(0xdeadbeef);
3927 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
3928 0, 0, 100, 100, parent, hmenu, 0, NULL);
3929 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3930 expect_menu(hwnd, hmenu);
3931 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
3932 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
3933 DestroyWindow(hwnd);
3934 SetLastError(0xdeadbeef);
3935 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3936 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
3938 /* test child window sizing */
3939 cls.style = 0;
3940 cls.lpfnWndProc = minmax_wnd_proc;
3941 cls.cbClsExtra = 0;
3942 cls.cbWndExtra = 0;
3943 cls.hInstance = GetModuleHandle(0);
3944 cls.hIcon = 0;
3945 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3946 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3947 cls.lpszMenuName = NULL;
3948 cls.lpszClassName = "MinMax_WndClass";
3949 RegisterClass(&cls);
3951 SetLastError(0xdeadbeef);
3952 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
3953 0, 0, 100, 100, 0, 0, 0, NULL);
3954 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
3955 expect_menu(parent, 0);
3956 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
3957 expect_ex_style(parent, WS_EX_WINDOWEDGE);
3959 memset(&minmax, 0, sizeof(minmax));
3960 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
3961 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
3962 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
3963 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
3964 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
3966 GetWindowRect(parent, &rc);
3967 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
3968 GetClientRect(parent, &rc);
3969 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
3971 InflateRect(&rc, 200, 200);
3972 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
3974 SetLastError(0xdeadbeef);
3975 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
3976 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
3977 parent, (HMENU)1, 0, NULL);
3978 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3979 expect_menu(hwnd, 1);
3980 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
3981 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
3983 memset(&minmax, 0, sizeof(minmax));
3984 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
3985 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
3987 GetWindowRect(hwnd, &rc);
3988 OffsetRect(&rc, -rc.left, -rc.top);
3989 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
3990 rc.left, rc.top, rc.right, rc.bottom,
3991 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
3993 DestroyWindow(hwnd);
3994 DestroyWindow(parent);
3996 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
3998 #undef expect_menu
3999 #undef expect_style
4000 #undef expect_ex_style
4003 /* function that remembers whether the system the test is running on sets the
4004 * last error for user32 functions to make the tests stricter */
4005 static int check_error(DWORD actual, DWORD expected)
4007 static int sets_last_error = -1;
4008 if (sets_last_error == -1)
4009 sets_last_error = (actual != 0xdeadbeef);
4010 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
4013 static void test_SetWindowLong(void)
4015 LONG_PTR retval;
4016 WNDPROC old_window_procW;
4018 SetLastError(0xdeadbeef);
4019 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
4020 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
4021 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
4022 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4024 SetLastError(0xdeadbeef);
4025 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
4026 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
4027 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
4028 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4030 SetLastError(0xdeadbeef);
4031 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4032 ok((WNDPROC)retval == main_window_procA,
4033 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
4034 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4035 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
4036 ok((WNDPROC)retval == main_window_procA,
4037 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4038 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
4040 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
4041 SetLastError(0xdeadbeef);
4042 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
4043 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
4045 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4046 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
4047 ok((WNDPROC)retval == old_window_procW,
4048 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4049 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
4051 /* set it back to ANSI */
4052 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4056 static void test_ShowWindow(void)
4058 HWND hwnd;
4059 DWORD style;
4060 RECT rcMain, rc;
4061 LPARAM ret;
4063 SetRect(&rcMain, 120, 120, 210, 210);
4065 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
4066 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4067 WS_MAXIMIZEBOX | WS_POPUP,
4068 rcMain.left, rcMain.top,
4069 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
4070 0, 0, 0, NULL);
4071 assert(hwnd);
4073 style = GetWindowLong(hwnd, GWL_STYLE);
4074 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4075 ok(!(style & WS_VISIBLE), "window should not be visible\n");
4076 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4077 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4078 GetWindowRect(hwnd, &rc);
4079 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4081 ret = ShowWindow(hwnd, SW_SHOW);
4082 ok(!ret, "not expected ret: %lu\n", ret);
4083 style = GetWindowLong(hwnd, GWL_STYLE);
4084 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4085 ok(style & WS_VISIBLE, "window should be visible\n");
4086 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4087 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4088 GetWindowRect(hwnd, &rc);
4089 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4091 ret = ShowWindow(hwnd, SW_MINIMIZE);
4092 ok(ret, "not expected ret: %lu\n", ret);
4093 style = GetWindowLong(hwnd, GWL_STYLE);
4094 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4095 ok(style & WS_VISIBLE, "window should be visible\n");
4096 ok(style & WS_MINIMIZE, "window should be minimized\n");
4097 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4098 GetWindowRect(hwnd, &rc);
4099 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4101 ShowWindow(hwnd, SW_RESTORE);
4102 ok(ret, "not expected ret: %lu\n", ret);
4103 style = GetWindowLong(hwnd, GWL_STYLE);
4104 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4105 ok(style & WS_VISIBLE, "window should be visible\n");
4106 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4107 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4108 GetWindowRect(hwnd, &rc);
4109 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4111 ret = EnableWindow(hwnd, FALSE);
4112 ok(!ret, "not expected ret: %lu\n", ret);
4113 style = GetWindowLong(hwnd, GWL_STYLE);
4114 ok(style & WS_DISABLED, "window should be disabled\n");
4116 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
4117 ok(!ret, "not expected ret: %lu\n", ret);
4118 style = GetWindowLong(hwnd, GWL_STYLE);
4119 ok(style & WS_DISABLED, "window should be disabled\n");
4120 ok(style & WS_VISIBLE, "window should be visible\n");
4121 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4122 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4123 GetWindowRect(hwnd, &rc);
4124 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4126 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
4127 ok(!ret, "not expected ret: %lu\n", ret);
4128 style = GetWindowLong(hwnd, GWL_STYLE);
4129 ok(style & WS_DISABLED, "window should be disabled\n");
4130 ok(style & WS_VISIBLE, "window should be visible\n");
4131 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4132 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4133 GetWindowRect(hwnd, &rc);
4134 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4136 ret = ShowWindow(hwnd, SW_MINIMIZE);
4137 ok(ret, "not expected ret: %lu\n", ret);
4138 style = GetWindowLong(hwnd, GWL_STYLE);
4139 ok(style & WS_DISABLED, "window should be disabled\n");
4140 ok(style & WS_VISIBLE, "window should be visible\n");
4141 ok(style & WS_MINIMIZE, "window should be minimized\n");
4142 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4143 GetWindowRect(hwnd, &rc);
4144 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4146 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
4147 ok(!ret, "not expected ret: %lu\n", ret);
4148 style = GetWindowLong(hwnd, GWL_STYLE);
4149 ok(style & WS_DISABLED, "window should be disabled\n");
4150 ok(style & WS_VISIBLE, "window should be visible\n");
4151 ok(style & WS_MINIMIZE, "window should be minimized\n");
4152 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4153 GetWindowRect(hwnd, &rc);
4154 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4156 ret = ShowWindow(hwnd, SW_RESTORE);
4157 ok(ret, "not expected ret: %lu\n", ret);
4158 style = GetWindowLong(hwnd, GWL_STYLE);
4159 ok(style & WS_DISABLED, "window should be disabled\n");
4160 ok(style & WS_VISIBLE, "window should be visible\n");
4161 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4162 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4163 GetWindowRect(hwnd, &rc);
4164 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4166 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4167 ok(!ret, "not expected ret: %lu\n", ret);
4168 ok(IsWindow(hwnd), "window should exist\n");
4170 ret = EnableWindow(hwnd, TRUE);
4171 ok(ret, "not expected ret: %lu\n", ret);
4173 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4174 ok(!ret, "not expected ret: %lu\n", ret);
4175 ok(!IsWindow(hwnd), "window should not exist\n");
4178 static void test_gettext(void)
4180 WNDCLASS cls;
4181 LPCSTR clsname = "gettexttest";
4182 HWND hwnd;
4183 LRESULT r;
4185 memset( &cls, 0, sizeof cls );
4186 cls.lpfnWndProc = DefWindowProc;
4187 cls.lpszClassName = clsname;
4188 cls.hInstance = GetModuleHandle(NULL);
4190 if (!RegisterClass( &cls )) return;
4192 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
4193 ok( hwnd != NULL, "window was null\n");
4195 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
4196 ok( r == 0, "settext should return zero\n");
4198 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
4199 ok( r == 0, "settext should return zero (%ld)\n", r);
4201 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
4202 ok( r == 0, "settext should return zero (%ld)\n", r);
4204 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
4205 ok( r == 0, "settext should return zero (%ld)\n", r);
4207 DestroyWindow(hwnd);
4208 UnregisterClass( clsname, NULL );
4212 static void test_GetUpdateRect(void)
4214 RECT rc1, rc2;
4215 HWND hgrandparent, hparent, hchild;
4216 WNDCLASSA cls;
4217 const char* classNameA = "GetUpdateRectClass";
4219 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
4220 0, 0, 100, 100, NULL, NULL, 0, NULL);
4222 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
4223 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4225 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
4226 10, 10, 30, 30, hparent, NULL, 0, NULL);
4228 ShowWindow(hgrandparent, SW_SHOW);
4229 UpdateWindow(hgrandparent);
4231 ShowWindow(hchild, SW_HIDE);
4232 SetRect(&rc2, 0, 0, 0, 0);
4233 GetUpdateRect(hgrandparent, &rc1, FALSE);
4234 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4235 rc1.left, rc1.top, rc1.right, rc1.bottom,
4236 rc2.left, rc2.top, rc2.right, rc2.bottom);
4238 SetRect(&rc2, 10, 10, 40, 40);
4239 GetUpdateRect(hparent, &rc1, FALSE);
4240 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4241 rc1.left, rc1.top, rc1.right, rc1.bottom,
4242 rc2.left, rc2.top, rc2.right, rc2.bottom);
4244 DestroyWindow(hgrandparent);
4246 cls.style = 0;
4247 cls.lpfnWndProc = DefWindowProcA;
4248 cls.cbClsExtra = 0;
4249 cls.cbWndExtra = 0;
4250 cls.hInstance = GetModuleHandleA(0);
4251 cls.hIcon = 0;
4252 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
4253 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4254 cls.lpszMenuName = NULL;
4255 cls.lpszClassName = classNameA;
4257 if(!RegisterClassA(&cls)) {
4258 trace("Register failed %d\n", GetLastError());
4259 return;
4262 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
4263 0, 0, 100, 100, NULL, NULL, 0, NULL);
4265 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
4266 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4268 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
4269 10, 10, 30, 30, hparent, NULL, 0, NULL);
4271 ShowWindow(hgrandparent, SW_SHOW);
4272 UpdateWindow(hgrandparent);
4274 ShowWindow(hchild, SW_HIDE);
4275 SetRect(&rc2, 0, 0, 0, 0);
4276 GetUpdateRect(hgrandparent, &rc1, FALSE);
4277 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4278 rc1.left, rc1.top, rc1.right, rc1.bottom,
4279 rc2.left, rc2.top, rc2.right, rc2.bottom);
4281 SetRect(&rc2, 10, 10, 40, 40);
4282 GetUpdateRect(hparent, &rc1, FALSE);
4283 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4284 rc1.left, rc1.top, rc1.right, rc1.bottom,
4285 rc2.left, rc2.top, rc2.right, rc2.bottom);
4287 DestroyWindow(hgrandparent);
4290 START_TEST(win)
4292 pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
4293 pGetWindowInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
4295 hwndMain = CreateWindowExA(0, "static", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, NULL);
4296 if (hwndMain)
4298 ok(!GetParent(hwndMain), "GetParent should return 0 for message only windows\n");
4299 if (pGetAncestor)
4301 hwndMessage = pGetAncestor(hwndMain, GA_PARENT);
4302 ok(hwndMessage != 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
4303 trace("hwndMessage %p\n", hwndMessage);
4305 DestroyWindow(hwndMain);
4307 else
4308 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
4310 if (!RegisterWindowClasses()) assert(0);
4312 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
4313 assert(hhook);
4315 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
4316 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4317 WS_MAXIMIZEBOX | WS_POPUP,
4318 100, 100, 200, 200,
4319 0, 0, 0, NULL);
4320 test_nonclient_area(hwndMain);
4322 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
4323 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4324 WS_MAXIMIZEBOX | WS_POPUP,
4325 100, 100, 200, 200,
4326 0, 0, 0, NULL);
4327 assert( hwndMain );
4328 assert( hwndMain2 );
4330 /* Add the tests below this line */
4331 test_params();
4333 test_capture_1();
4334 test_capture_2();
4335 test_capture_3(hwndMain, hwndMain2);
4337 test_CreateWindow();
4338 test_parent_owner();
4339 test_SetParent();
4340 test_shell_window();
4342 test_mdi();
4343 test_icons();
4344 test_SetWindowPos(hwndMain);
4345 test_SetMenu(hwndMain);
4346 test_SetFocus(hwndMain);
4347 test_SetActiveWindow(hwndMain);
4348 test_SetForegroundWindow(hwndMain);
4350 test_children_zorder(hwndMain);
4351 test_keyboard_input(hwndMain);
4352 test_mouse_input(hwndMain);
4353 test_validatergn(hwndMain);
4354 test_nccalcscroll( hwndMain);
4355 test_scrollvalidate( hwndMain);
4356 test_scrolldc( hwndMain);
4357 test_scroll();
4358 test_IsWindowUnicode();
4359 test_vis_rgn(hwndMain);
4361 test_AdjustWindowRect();
4362 test_window_styles();
4363 test_redrawnow();
4364 test_csparentdc();
4365 test_SetWindowLong();
4366 test_ShowWindow();
4367 test_gettext();
4368 test_GetUpdateRect();
4370 /* add the tests above this line */
4371 UnhookWindowsHookEx(hhook);