push d2761731c253bfe9a5961252b22d8cea093833f5
[wine/hacks.git] / dlls / user32 / tests / win.c
blob1964e88ec26af29f9208744dae99cfff8b3505a4
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*);
49 static UINT (WINAPI *pGetWindowModuleFileNameA)(HWND,LPSTR,UINT);
51 static BOOL test_lbuttondown_flag;
52 static HWND hwndMessage;
53 static HWND hwndMain, hwndMain2;
54 static HHOOK hhook;
56 static const char* szAWRClass = "Winsize";
57 static HMENU hmenu;
58 static DWORD our_pid;
60 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
62 static void dump_minmax_info( const MINMAXINFO *minmax )
64 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
65 minmax->ptReserved.x, minmax->ptReserved.y,
66 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
67 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
68 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
69 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
72 /* try to make sure pending X events have been processed before continuing */
73 static void flush_events( BOOL remove_messages )
75 MSG msg;
76 int diff = 200;
77 int min_timeout = 50;
78 DWORD time = GetTickCount() + diff;
80 while (diff > 0)
82 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
83 if (remove_messages)
84 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
85 diff = time - GetTickCount();
86 min_timeout = 10;
90 /* check the values returned by the various parent/owner functions on a given window */
91 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
92 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
94 HWND res;
96 if (pGetAncestor)
98 res = pGetAncestor( hwnd, GA_PARENT );
99 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
101 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
102 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
103 res = GetParent( hwnd );
104 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
105 res = GetWindow( hwnd, GW_OWNER );
106 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
107 if (pGetAncestor)
109 res = pGetAncestor( hwnd, GA_ROOT );
110 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
111 res = pGetAncestor( hwnd, GA_ROOTOWNER );
112 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
116 static BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
118 (*(LPINT)lParam)++;
119 trace("EnumChildProc on %p\n", hwndChild);
120 if (*(LPINT)lParam > 1) return FALSE;
121 return TRUE;
124 /* will search for the given window */
125 static BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
127 trace("EnumChildProc1 on %p\n", hwndChild);
128 if ((HWND)lParam == hwndChild) return FALSE;
129 return TRUE;
132 static HWND create_tool_window( LONG style, HWND parent )
134 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
135 0, 0, 100, 100, parent, 0, 0, NULL );
136 ok( ret != 0, "Creation failed\n" );
137 return ret;
140 /* test parent and owner values for various combinations */
141 static void test_parent_owner(void)
143 LONG style;
144 HWND test, owner, ret;
145 HWND desktop = GetDesktopWindow();
146 HWND child = create_tool_window( WS_CHILD, hwndMain );
147 INT numChildren;
149 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
151 /* child without parent, should fail */
152 SetLastError(0xdeadbeef);
153 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
154 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
155 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD, "CreateWindowExA should call SetLastError\n" );
156 ok( !test, "WS_CHILD without parent created\n" );
158 /* desktop window */
159 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
160 style = GetWindowLongA( desktop, GWL_STYLE );
161 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
162 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
163 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
165 /* normal child window */
166 test = create_tool_window( WS_CHILD, hwndMain );
167 trace( "created child %p\n", test );
168 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
169 SetWindowLongA( test, GWL_STYLE, 0 );
170 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
171 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
172 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
173 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
174 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
175 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
176 DestroyWindow( test );
178 /* normal child window with WS_MAXIMIZE */
179 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
180 DestroyWindow( test );
182 /* normal child window with WS_THICKFRAME */
183 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
184 DestroyWindow( test );
186 /* popup window with WS_THICKFRAME */
187 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
188 DestroyWindow( test );
190 /* child of desktop */
191 test = create_tool_window( WS_CHILD, desktop );
192 trace( "created child of desktop %p\n", test );
193 check_parents( test, desktop, 0, desktop, 0, test, desktop );
194 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
195 check_parents( test, desktop, 0, 0, 0, test, test );
196 SetWindowLongA( test, GWL_STYLE, 0 );
197 check_parents( test, desktop, 0, 0, 0, test, test );
198 DestroyWindow( test );
200 /* child of desktop with WS_MAXIMIZE */
201 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
202 DestroyWindow( test );
204 /* child of desktop with WS_MINIMIZE */
205 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
206 DestroyWindow( test );
208 /* child of child */
209 test = create_tool_window( WS_CHILD, child );
210 trace( "created child of child %p\n", test );
211 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
212 SetWindowLongA( test, GWL_STYLE, 0 );
213 check_parents( test, child, child, 0, 0, hwndMain, test );
214 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
215 check_parents( test, child, child, 0, 0, hwndMain, test );
216 DestroyWindow( test );
218 /* child of child with WS_MAXIMIZE */
219 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
220 DestroyWindow( test );
222 /* child of child with WS_MINIMIZE */
223 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
224 DestroyWindow( test );
226 /* not owned top-level window */
227 test = create_tool_window( 0, 0 );
228 trace( "created top-level %p\n", test );
229 check_parents( test, desktop, 0, 0, 0, test, test );
230 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
231 check_parents( test, desktop, 0, 0, 0, test, test );
232 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
233 check_parents( test, desktop, 0, desktop, 0, test, desktop );
234 DestroyWindow( test );
236 /* not owned top-level window with WS_MAXIMIZE */
237 test = create_tool_window( WS_MAXIMIZE, 0 );
238 DestroyWindow( test );
240 /* owned top-level window */
241 test = create_tool_window( 0, hwndMain );
242 trace( "created owned top-level %p\n", test );
243 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
244 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
245 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
246 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
247 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
248 DestroyWindow( test );
250 /* owned top-level window with WS_MAXIMIZE */
251 test = create_tool_window( WS_MAXIMIZE, hwndMain );
252 DestroyWindow( test );
254 /* not owned popup */
255 test = create_tool_window( WS_POPUP, 0 );
256 trace( "created popup %p\n", test );
257 check_parents( test, desktop, 0, 0, 0, test, test );
258 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
259 check_parents( test, desktop, 0, desktop, 0, test, desktop );
260 SetWindowLongA( test, GWL_STYLE, 0 );
261 check_parents( test, desktop, 0, 0, 0, test, test );
262 DestroyWindow( test );
264 /* not owned popup with WS_MAXIMIZE */
265 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
266 DestroyWindow( test );
268 /* owned popup */
269 test = create_tool_window( WS_POPUP, hwndMain );
270 trace( "created owned popup %p\n", test );
271 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
272 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
273 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
274 SetWindowLongA( test, GWL_STYLE, 0 );
275 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
276 DestroyWindow( test );
278 /* owned popup with WS_MAXIMIZE */
279 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
280 DestroyWindow( test );
282 /* top-level window owned by child (same as owned by top-level) */
283 test = create_tool_window( 0, child );
284 trace( "created top-level owned by child %p\n", test );
285 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
286 DestroyWindow( test );
288 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
289 test = create_tool_window( WS_MAXIMIZE, child );
290 DestroyWindow( test );
292 /* popup owned by desktop (same as not owned) */
293 test = create_tool_window( WS_POPUP, desktop );
294 trace( "created popup owned by desktop %p\n", test );
295 check_parents( test, desktop, 0, 0, 0, test, test );
296 DestroyWindow( test );
298 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
299 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
300 DestroyWindow( test );
302 /* popup owned by child (same as owned by top-level) */
303 test = create_tool_window( WS_POPUP, child );
304 trace( "created popup owned by child %p\n", test );
305 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
306 DestroyWindow( test );
308 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
309 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
310 DestroyWindow( test );
312 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
313 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
314 trace( "created WS_CHILD popup %p\n", test );
315 check_parents( test, desktop, 0, 0, 0, test, test );
316 DestroyWindow( test );
318 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
319 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
320 DestroyWindow( test );
322 /* owned popup with WS_CHILD (same as WS_POPUP only) */
323 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
324 trace( "created owned WS_CHILD popup %p\n", test );
325 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
326 DestroyWindow( test );
328 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
329 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
330 DestroyWindow( test );
332 /******************** parent changes *************************/
333 trace( "testing parent changes\n" );
335 /* desktop window */
336 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
337 if (0)
339 /* this test succeeds on NT but crashes on win9x systems */
340 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
341 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
342 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
343 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
344 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
346 /* normal child window */
347 test = create_tool_window( WS_CHILD, hwndMain );
348 trace( "created child %p\n", test );
350 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
351 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
352 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
354 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
355 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
356 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
358 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
359 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
360 check_parents( test, desktop, 0, desktop, 0, test, desktop );
362 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
363 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
364 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
365 check_parents( test, desktop, child, desktop, child, test, desktop );
367 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
368 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
369 check_parents( test, desktop, 0, desktop, 0, test, desktop );
370 DestroyWindow( test );
372 /* not owned top-level window */
373 test = create_tool_window( 0, 0 );
374 trace( "created top-level %p\n", test );
376 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
377 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
378 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
380 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
381 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
382 check_parents( test, desktop, child, 0, child, test, test );
384 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
385 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
386 check_parents( test, desktop, 0, 0, 0, test, test );
387 DestroyWindow( test );
389 /* not owned popup */
390 test = create_tool_window( WS_POPUP, 0 );
391 trace( "created popup %p\n", test );
393 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
394 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
395 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
397 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
398 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
399 check_parents( test, desktop, child, child, child, test, hwndMain );
401 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
402 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
403 check_parents( test, desktop, 0, 0, 0, test, test );
404 DestroyWindow( test );
406 /* normal child window */
407 test = create_tool_window( WS_CHILD, hwndMain );
408 trace( "created child %p\n", test );
410 ret = SetParent( test, desktop );
411 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
412 check_parents( test, desktop, 0, desktop, 0, test, desktop );
414 ret = SetParent( test, child );
415 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
416 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
418 ret = SetParent( test, hwndMain2 );
419 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
420 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
421 DestroyWindow( test );
423 /* not owned top-level window */
424 test = create_tool_window( 0, 0 );
425 trace( "created top-level %p\n", test );
427 ret = SetParent( test, child );
428 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
429 check_parents( test, child, child, 0, 0, hwndMain, test );
430 DestroyWindow( test );
432 /* owned popup */
433 test = create_tool_window( WS_POPUP, hwndMain2 );
434 trace( "created owned popup %p\n", 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, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
440 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
441 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
442 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
443 DestroyWindow( test );
445 /**************** test owner destruction *******************/
447 /* owned child popup */
448 owner = create_tool_window( 0, 0 );
449 test = create_tool_window( WS_POPUP, owner );
450 trace( "created owner %p and popup %p\n", owner, test );
451 ret = SetParent( test, child );
452 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
453 check_parents( test, child, child, owner, owner, hwndMain, owner );
454 /* window is now child of 'child' but owned by 'owner' */
455 DestroyWindow( owner );
456 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
457 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
458 * while Win95, Win2k, WinXP do.
460 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
461 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
462 DestroyWindow(test);
464 /* owned top-level popup */
465 owner = create_tool_window( 0, 0 );
466 test = create_tool_window( WS_POPUP, owner );
467 trace( "created owner %p and popup %p\n", owner, test );
468 check_parents( test, desktop, owner, owner, owner, test, owner );
469 DestroyWindow( owner );
470 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
472 /* top-level popup owned by child */
473 owner = create_tool_window( WS_CHILD, hwndMain2 );
474 test = create_tool_window( WS_POPUP, 0 );
475 trace( "created owner %p and popup %p\n", owner, test );
476 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
477 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
478 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
479 DestroyWindow( owner );
480 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
481 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
482 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
483 * while Win95, Win2k, WinXP do.
485 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
486 DestroyWindow(test);
488 /* final cleanup */
489 DestroyWindow(child);
492 owner = create_tool_window( WS_OVERLAPPED, 0 );
493 test = create_tool_window( WS_POPUP, desktop );
495 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
496 numChildren = 0;
497 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
498 "EnumChildWindows should have returned FALSE\n" );
499 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
501 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
502 ret = SetParent( test, owner );
503 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
505 numChildren = 0;
506 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
507 "EnumChildWindows should have returned TRUE\n" );
508 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
510 child = create_tool_window( WS_CHILD, owner );
511 numChildren = 0;
512 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
513 "EnumChildWindows should have returned FALSE\n" );
514 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
515 DestroyWindow( child );
517 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
518 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
519 numChildren = 0;
520 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
521 "EnumChildWindows should have returned TRUE\n" );
522 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
524 ret = SetParent( child, owner );
525 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
526 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
527 numChildren = 0;
528 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
529 "EnumChildWindows should have returned FALSE\n" );
530 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
532 ret = SetParent( child, NULL );
533 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
534 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
535 numChildren = 0;
536 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
537 "EnumChildWindows should have returned TRUE\n" );
538 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
540 /* even GW_OWNER == owner it's still a desktop's child */
541 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
542 "EnumChildWindows should have found %p and returned FALSE\n", child );
544 DestroyWindow( child );
545 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
547 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
548 "EnumChildWindows should have found %p and returned FALSE\n", child );
550 DestroyWindow( child );
551 DestroyWindow( test );
552 DestroyWindow( owner );
556 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
558 switch (msg)
560 case WM_GETMINMAXINFO:
562 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
564 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
565 dump_minmax_info( minmax );
566 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
567 break;
569 case WM_WINDOWPOSCHANGING:
571 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
572 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
573 trace("main: WM_WINDOWPOSCHANGING\n");
574 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
575 winpos->hwnd, winpos->hwndInsertAfter,
576 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
577 if (!(winpos->flags & SWP_NOMOVE))
579 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
580 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
582 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
583 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
585 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
586 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
588 break;
590 case WM_WINDOWPOSCHANGED:
592 RECT rc1, rc2;
593 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
594 trace("main: WM_WINDOWPOSCHANGED\n");
595 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
596 winpos->hwnd, winpos->hwndInsertAfter,
597 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
598 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
599 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
601 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
602 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
604 GetWindowRect(hwnd, &rc1);
605 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
606 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
607 /* note: winpos coordinates are relative to parent */
608 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
609 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
610 if (0)
612 /* Uncomment this once the test succeeds in all cases */
613 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
616 GetClientRect(hwnd, &rc2);
617 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
618 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
619 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
620 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
621 break;
623 case WM_NCCREATE:
625 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
626 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
628 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
629 if (got_getminmaxinfo)
630 trace("%p got WM_GETMINMAXINFO\n", hwnd);
632 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
633 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
634 else
635 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
636 break;
638 case WM_COMMAND:
639 if (test_lbuttondown_flag)
641 ShowWindow((HWND)wparam, SW_SHOW);
642 flush_events( FALSE );
644 break;
647 return DefWindowProcA(hwnd, msg, wparam, lparam);
650 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
652 switch (msg)
654 case WM_GETMINMAXINFO:
656 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
658 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
659 dump_minmax_info( minmax );
660 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
661 break;
663 case WM_NCCREATE:
665 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
666 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
668 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
669 if (got_getminmaxinfo)
670 trace("%p got WM_GETMINMAXINFO\n", hwnd);
672 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
673 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
674 else
675 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
676 break;
680 return DefWindowProcA(hwnd, msg, wparam, lparam);
683 static BOOL RegisterWindowClasses(void)
685 WNDCLASSA cls;
687 cls.style = CS_DBLCLKS;
688 cls.lpfnWndProc = main_window_procA;
689 cls.cbClsExtra = 0;
690 cls.cbWndExtra = 0;
691 cls.hInstance = GetModuleHandleA(0);
692 cls.hIcon = 0;
693 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
694 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
695 cls.lpszMenuName = NULL;
696 cls.lpszClassName = "MainWindowClass";
698 if(!RegisterClassA(&cls)) return FALSE;
700 cls.style = 0;
701 cls.lpfnWndProc = tool_window_procA;
702 cls.cbClsExtra = 0;
703 cls.cbWndExtra = 0;
704 cls.hInstance = GetModuleHandleA(0);
705 cls.hIcon = 0;
706 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
707 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
708 cls.lpszMenuName = NULL;
709 cls.lpszClassName = "ToolWindowClass";
711 if(!RegisterClassA(&cls)) return FALSE;
713 return TRUE;
716 static void verify_window_info(HWND hwnd, const WINDOWINFO *info)
718 RECT rcWindow, rcClient;
719 DWORD status;
721 ok(IsWindow(hwnd), "bad window handle\n");
723 GetWindowRect(hwnd, &rcWindow);
724 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow\n");
726 GetClientRect(hwnd, &rcClient);
727 /* translate to screen coordinates */
728 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
729 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient\n");
731 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
732 "wrong dwStyle: %08x != %08x\n", info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE));
733 /* Windows reports some undocumented exstyles in WINDOWINFO, but
734 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
736 ok((info->dwExStyle & ~0xe0000800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
737 "wrong dwExStyle: %08x != %08x\n", info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE));
738 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
739 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x\n",
740 info->dwWindowStatus, status);
742 /* win2k and XP return broken border info in GetWindowInfo most of
743 * the time, so there is no point in testing it.
745 #if 0
746 UINT border;
747 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
748 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
749 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
750 ok(info->cyWindowBorders == border,
751 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
752 #endif
753 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType\n");
754 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
755 info->wCreatorVersion == 0x0500 /* Vista */,
756 "wrong wCreatorVersion %04x\n", info->wCreatorVersion);
759 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
761 AdjustWindowRectEx(rc, style, menu, exstyle);
762 /* AdjustWindowRectEx does not include scroll bars */
763 if (style & WS_VSCROLL)
765 if(exstyle & WS_EX_LEFTSCROLLBAR)
766 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
767 else
768 rc->right += GetSystemMetrics(SM_CXVSCROLL);
770 if (style & WS_HSCROLL)
771 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
774 static void test_nonclient_area(HWND hwnd)
776 DWORD style, exstyle;
777 RECT rc_window, rc_client, rc;
778 BOOL menu;
779 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
781 style = GetWindowLongA(hwnd, GWL_STYLE);
782 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
783 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
785 GetWindowRect(hwnd, &rc_window);
786 trace("window: (%d,%d)-(%d,%d)\n", rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
787 GetClientRect(hwnd, &rc_client);
788 trace("client: (%d,%d)-(%d,%d)\n", rc_client.left, rc_client.top, rc_client.right, rc_client.bottom);
790 /* avoid some cases when things go wrong */
791 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
792 rc_window.right > 32768 || rc_window.bottom > 32768) return;
794 CopyRect(&rc, &rc_client);
795 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
796 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
798 trace("calc window: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
799 ok(EqualRect(&rc, &rc_window), "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
802 CopyRect(&rc, &rc_window);
803 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
804 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
805 trace("calc client: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
806 ok(EqualRect(&rc, &rc_client), "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
808 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
809 if (is_win9x)
810 return;
812 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
813 SetRect(&rc_client, 0, 0, 250, 150);
814 CopyRect(&rc_window, &rc_client);
815 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
816 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
817 trace("calc window: (%d,%d)-(%d,%d)\n",
818 rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
820 CopyRect(&rc, &rc_window);
821 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
822 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
823 trace("calc client: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
824 ok(EqualRect(&rc, &rc_client), "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
827 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
829 static const char *CBT_code_name[10] = {
830 "HCBT_MOVESIZE",
831 "HCBT_MINMAX",
832 "HCBT_QS",
833 "HCBT_CREATEWND",
834 "HCBT_DESTROYWND",
835 "HCBT_ACTIVATE",
836 "HCBT_CLICKSKIPPED",
837 "HCBT_KEYSKIPPED",
838 "HCBT_SYSCOMMAND",
839 "HCBT_SETFOCUS" };
840 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
842 trace("CBT: %d (%s), %08lx, %08lx\n", nCode, code_name, wParam, lParam);
844 /* on HCBT_DESTROYWND window state is undefined */
845 if (nCode != HCBT_DESTROYWND && IsWindow((HWND)wParam))
847 if (pGetWindowInfo)
849 WINDOWINFO info;
851 /* Win98 actually does check the info.cbSize and doesn't allow
852 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
853 * WinXP do not check it at all.
855 info.cbSize = sizeof(WINDOWINFO);
856 ok(pGetWindowInfo((HWND)wParam, &info), "GetWindowInfo should not fail\n");
857 verify_window_info((HWND)wParam, &info);
861 switch (nCode)
863 case HCBT_CREATEWND:
865 static const RECT rc_null;
866 RECT rc;
867 LONG style;
868 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
869 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
870 (HWND)wParam, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
871 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
873 /* WS_VISIBLE should be turned off yet */
874 style = createwnd->lpcs->style & ~WS_VISIBLE;
875 ok(style == GetWindowLongA((HWND)wParam, GWL_STYLE),
876 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
877 GetWindowLongA((HWND)wParam, GWL_STYLE), style);
879 if (0)
881 /* Uncomment this once the test succeeds in all cases */
882 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
884 ok(GetParent((HWND)wParam) == hwndMessage,
885 "wrong result from GetParent %p: message window %p\n",
886 GetParent((HWND)wParam), hwndMessage);
888 else
889 ok(!GetParent((HWND)wParam), "GetParent should return 0 at this point\n");
891 ok(!GetWindow((HWND)wParam, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
893 if (0)
895 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
896 * Win9x still has them set to 0.
898 ok(GetWindow((HWND)wParam, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
899 ok(GetWindow((HWND)wParam, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
901 ok(!GetWindow((HWND)wParam, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
902 ok(!GetWindow((HWND)wParam, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
904 if (0)
906 /* Uncomment this once the test succeeds in all cases */
907 if (pGetAncestor)
909 ok(pGetAncestor((HWND)wParam, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
910 ok(pGetAncestor((HWND)wParam, GA_ROOT) == (HWND)wParam,
911 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOT), (HWND)wParam);
913 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
914 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == hwndMessage,
915 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
916 else
917 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == (HWND)wParam,
918 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOTOWNER), (HWND)wParam);
921 ok(GetWindowRect((HWND)wParam, &rc), "GetWindowRect failed\n");
922 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
923 ok(GetClientRect((HWND)wParam, &rc), "GetClientRect failed\n");
924 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
926 break;
930 return CallNextHookEx(hhook, nCode, wParam, lParam);
933 static void test_shell_window(void)
935 BOOL ret;
936 DWORD error;
937 HMODULE hinst, hUser32;
938 BOOL (WINAPI*SetShellWindow)(HWND);
939 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
940 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
941 HWND shellWindow, nextWnd;
943 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
945 trace("Skipping shell window test on Win9x\n");
946 return;
949 shellWindow = GetShellWindow();
950 hinst = GetModuleHandle(0);
951 hUser32 = GetModuleHandleA("user32");
953 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
954 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
956 trace("previous shell window: %p\n", shellWindow);
958 if (shellWindow) {
959 DWORD pid;
960 HANDLE hProcess;
962 ret = DestroyWindow(shellWindow);
963 error = GetLastError();
965 ok(!ret, "DestroyWindow(shellWindow)\n");
966 /* passes on Win XP, but not on Win98 */
967 ok(error==ERROR_ACCESS_DENIED, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n");
969 /* close old shell instance */
970 GetWindowThreadProcessId(shellWindow, &pid);
971 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
972 ret = TerminateProcess(hProcess, 0);
973 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
974 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
975 CloseHandle(hProcess);
978 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
979 trace("created window 1: %p\n", hwnd1);
981 ret = SetShellWindow(hwnd1);
982 ok(ret, "first call to SetShellWindow(hwnd1)\n");
983 shellWindow = GetShellWindow();
984 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
986 ret = SetShellWindow(hwnd1);
987 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
989 ret = SetShellWindow(0);
990 error = GetLastError();
991 /* passes on Win XP, but not on Win98
992 ok(!ret, "reset shell window by SetShellWindow(0)\n");
993 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
995 ret = SetShellWindow(hwnd1);
996 /* passes on Win XP, but not on Win98
997 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
999 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1000 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
1001 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);
1420 dump_minmax_info( minmax );
1422 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1423 minmax->ptMaxSize.x, rc.right - rc.left);
1424 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1425 minmax->ptMaxSize.y, rc.bottom - rc.top);
1427 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1429 trace("DefMDIChildProc returned:\n");
1430 dump_minmax_info( minmax );
1432 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1433 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1434 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1435 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1436 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1438 return 1;
1441 case WM_MDIACTIVATE:
1443 HWND active, client = GetParent(hwnd);
1444 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1445 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1446 if (hwnd == (HWND)lparam) /* if we are being activated */
1447 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1448 else
1449 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1450 break;
1453 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1456 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1458 switch (msg)
1460 case WM_NCCREATE:
1461 case WM_CREATE:
1463 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1465 trace("%s\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE");
1466 trace("x %d, y %d, cx %d, cy %d\n", cs->x, cs->y, cs->cx, cs->cy);
1468 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1469 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1471 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1472 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1474 /* CREATESTRUCT should have fixed values */
1475 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1476 while NT does. */
1477 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1478 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1480 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1481 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1482 while Win95, Win2k, WinXP do. */
1483 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1484 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1485 break;
1488 case WM_GETMINMAXINFO:
1490 HWND parent = GetParent(hwnd);
1491 RECT rc;
1492 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1493 LONG style, exstyle;
1495 trace("WM_GETMINMAXINFO\n");
1497 style = GetWindowLongA(hwnd, GWL_STYLE);
1498 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1500 GetClientRect(parent, &rc);
1501 trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1503 GetClientRect(parent, &rc);
1504 if ((style & WS_CAPTION) == WS_CAPTION)
1505 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1506 AdjustWindowRectEx(&rc, style, 0, exstyle);
1507 trace("calculated max child window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1508 dump_minmax_info( minmax );
1510 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1511 minmax->ptMaxSize.x, rc.right - rc.left);
1512 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1513 minmax->ptMaxSize.y, rc.bottom - rc.top);
1514 break;
1517 case WM_WINDOWPOSCHANGED:
1519 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1520 RECT rc1, rc2;
1522 GetWindowRect(hwnd, &rc1);
1523 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1524 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1525 /* note: winpos coordinates are relative to parent */
1526 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1527 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1528 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1530 GetWindowRect(hwnd, &rc1);
1531 GetClientRect(hwnd, &rc2);
1532 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1533 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1534 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1536 /* fall through */
1537 case WM_WINDOWPOSCHANGING:
1539 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1540 WINDOWPOS my_winpos = *winpos;
1542 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1543 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1544 winpos->hwnd, winpos->hwndInsertAfter,
1545 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1547 DefWindowProcA(hwnd, msg, wparam, lparam);
1549 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1550 winpos->hwnd, winpos->hwndInsertAfter,
1551 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1553 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1554 "DefWindowProc should not change WINDOWPOS values\n");
1556 return 1;
1559 return DefWindowProcA(hwnd, msg, wparam, lparam);
1562 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1564 static HWND mdi_client;
1566 switch (msg)
1568 case WM_CREATE:
1570 CLIENTCREATESTRUCT client_cs;
1571 RECT rc;
1573 GetClientRect(hwnd, &rc);
1575 client_cs.hWindowMenu = 0;
1576 client_cs.idFirstChild = 1;
1578 /* MDIClient without MDIS_ALLCHILDSTYLES */
1579 mdi_client = CreateWindowExA(0, "mdiclient",
1580 NULL,
1581 WS_CHILD /*| WS_VISIBLE*/,
1582 /* tests depend on a not zero MDIClient size */
1583 0, 0, rc.right, rc.bottom,
1584 hwnd, 0, GetModuleHandle(0),
1585 (LPVOID)&client_cs);
1586 assert(mdi_client);
1587 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1588 DestroyWindow(mdi_client);
1590 /* MDIClient with MDIS_ALLCHILDSTYLES */
1591 mdi_client = CreateWindowExA(0, "mdiclient",
1592 NULL,
1593 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1594 /* tests depend on a not zero MDIClient size */
1595 0, 0, rc.right, rc.bottom,
1596 hwnd, 0, GetModuleHandle(0),
1597 (LPVOID)&client_cs);
1598 assert(mdi_client);
1599 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1600 DestroyWindow(mdi_client);
1601 break;
1604 case WM_WINDOWPOSCHANGED:
1606 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1607 RECT rc1, rc2;
1609 GetWindowRect(hwnd, &rc1);
1610 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1611 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1612 /* note: winpos coordinates are relative to parent */
1613 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1614 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1615 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1617 GetWindowRect(hwnd, &rc1);
1618 GetClientRect(hwnd, &rc2);
1619 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1620 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1621 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1623 /* fall through */
1624 case WM_WINDOWPOSCHANGING:
1626 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1627 WINDOWPOS my_winpos = *winpos;
1629 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1630 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1631 winpos->hwnd, winpos->hwndInsertAfter,
1632 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1634 DefWindowProcA(hwnd, msg, wparam, lparam);
1636 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1637 winpos->hwnd, winpos->hwndInsertAfter,
1638 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1640 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1641 "DefWindowProc should not change WINDOWPOS values\n");
1643 return 1;
1646 case WM_CLOSE:
1647 PostQuitMessage(0);
1648 break;
1650 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1653 static BOOL mdi_RegisterWindowClasses(void)
1655 WNDCLASSA cls;
1657 cls.style = 0;
1658 cls.lpfnWndProc = mdi_main_wnd_procA;
1659 cls.cbClsExtra = 0;
1660 cls.cbWndExtra = 0;
1661 cls.hInstance = GetModuleHandleA(0);
1662 cls.hIcon = 0;
1663 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1664 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1665 cls.lpszMenuName = NULL;
1666 cls.lpszClassName = "MDI_parent_Class";
1667 if(!RegisterClassA(&cls)) return FALSE;
1669 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1670 cls.lpszClassName = "MDI_child_Class_1";
1671 if(!RegisterClassA(&cls)) return FALSE;
1673 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1674 cls.lpszClassName = "MDI_child_Class_2";
1675 if(!RegisterClassA(&cls)) return FALSE;
1677 return TRUE;
1680 static void test_mdi(void)
1682 HWND mdi_hwndMain;
1683 /*MSG msg;*/
1685 if (!mdi_RegisterWindowClasses()) assert(0);
1687 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1688 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1689 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1690 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1691 GetDesktopWindow(), 0,
1692 GetModuleHandle(0), NULL);
1693 assert(mdi_hwndMain);
1695 while(GetMessage(&msg, 0, 0, 0))
1697 TranslateMessage(&msg);
1698 DispatchMessage(&msg);
1701 DestroyWindow(mdi_hwndMain);
1704 static void test_icons(void)
1706 WNDCLASSEXA cls;
1707 HWND hwnd;
1708 HICON icon = LoadIconA(0, (LPSTR)IDI_APPLICATION);
1709 HICON icon2 = LoadIconA(0, (LPSTR)IDI_QUESTION);
1710 HICON small_icon = LoadImageA(0, (LPSTR)IDI_APPLICATION, IMAGE_ICON,
1711 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1712 HICON res;
1714 cls.cbSize = sizeof(cls);
1715 cls.style = 0;
1716 cls.lpfnWndProc = DefWindowProcA;
1717 cls.cbClsExtra = 0;
1718 cls.cbWndExtra = 0;
1719 cls.hInstance = 0;
1720 cls.hIcon = LoadIconA(0, (LPSTR)IDI_HAND);
1721 cls.hIconSm = small_icon;
1722 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1723 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1724 cls.lpszMenuName = NULL;
1725 cls.lpszClassName = "IconWindowClass";
1727 RegisterClassExA(&cls);
1729 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1730 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1731 assert( hwnd );
1733 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1734 ok( res == 0, "wrong big icon %p/0\n", res );
1735 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1736 ok( res == 0, "wrong previous big icon %p/0\n", res );
1737 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1738 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1739 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1740 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1741 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1742 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1744 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1745 ok( res == 0, "wrong small icon %p/0\n", res );
1746 /* this test is XP specific */
1747 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1748 ok( res != 0, "wrong small icon %p\n", res );*/
1749 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1750 ok( res == 0, "wrong previous small icon %p/0\n", res );
1751 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1752 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1753 /* this test is XP specific */
1754 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1755 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1756 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1757 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1758 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1759 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1760 /* this test is XP specific */
1761 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1762 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1764 /* make sure the big icon hasn't changed */
1765 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1766 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1768 DestroyWindow( hwnd );
1771 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1773 if (msg == WM_NCCALCSIZE)
1775 RECT *rect = (RECT *)lparam;
1776 /* first time around increase the rectangle, next time decrease it */
1777 if (rect->left == 100) InflateRect( rect, 10, 10 );
1778 else InflateRect( rect, -10, -10 );
1779 return 0;
1781 return DefWindowProc( hwnd, msg, wparam, lparam );
1784 static void test_SetWindowPos(HWND hwnd)
1786 RECT orig_win_rc, rect;
1787 LONG_PTR old_proc;
1788 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1790 SetRect(&rect, 111, 222, 333, 444);
1791 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1792 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1793 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1795 SetRect(&rect, 111, 222, 333, 444);
1796 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1797 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1798 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1800 GetWindowRect(hwnd, &orig_win_rc);
1802 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1803 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1804 GetWindowRect( hwnd, &rect );
1805 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1806 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1807 GetClientRect( hwnd, &rect );
1808 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1809 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1810 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1812 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1813 GetWindowRect( hwnd, &rect );
1814 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1815 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1816 GetClientRect( hwnd, &rect );
1817 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1818 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1819 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1821 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1822 orig_win_rc.right, orig_win_rc.bottom, 0);
1823 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1825 /* Win9x truncates coordinates to 16-bit irrespectively */
1826 if (!is_win9x)
1828 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1829 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1831 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1832 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1835 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1836 orig_win_rc.right, orig_win_rc.bottom, 0);
1838 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1839 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1840 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1841 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1842 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1843 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1844 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1847 static void test_SetMenu(HWND parent)
1849 HWND child;
1850 HMENU hMenu, ret;
1851 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1852 BOOL retok;
1853 DWORD style;
1855 hMenu = CreateMenu();
1856 assert(hMenu);
1858 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1859 if (0)
1861 /* fails on (at least) Wine, NT4, XP SP2 */
1862 test_nonclient_area(parent);
1864 ret = GetMenu(parent);
1865 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1866 /* test whether we can destroy a menu assigned to a window */
1867 retok = DestroyMenu(hMenu);
1868 ok( retok, "DestroyMenu error %d\n", GetLastError());
1869 ok(!IsMenu(hMenu), "menu handle should be not valid after DestroyMenu\n");
1870 ret = GetMenu(parent);
1871 /* This test fails on Win9x */
1872 if (!is_win9x)
1873 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1874 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1875 test_nonclient_area(parent);
1877 hMenu = CreateMenu();
1878 assert(hMenu);
1880 /* parent */
1881 ret = GetMenu(parent);
1882 ok(ret == 0, "unexpected menu id %p\n", ret);
1884 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1885 test_nonclient_area(parent);
1886 ret = GetMenu(parent);
1887 ok(ret == 0, "unexpected menu id %p\n", ret);
1889 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1890 if (0)
1892 /* fails on (at least) Wine, NT4, XP SP2 */
1893 test_nonclient_area(parent);
1895 ret = GetMenu(parent);
1896 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1898 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1899 test_nonclient_area(parent);
1900 ret = GetMenu(parent);
1901 ok(ret == 0, "unexpected menu id %p\n", ret);
1903 /* child */
1904 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1905 assert(child);
1907 ret = GetMenu(child);
1908 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1910 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1911 test_nonclient_area(child);
1912 ret = GetMenu(child);
1913 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1915 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1916 test_nonclient_area(child);
1917 ret = GetMenu(child);
1918 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1920 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1921 test_nonclient_area(child);
1922 ret = GetMenu(child);
1923 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1925 style = GetWindowLong(child, GWL_STYLE);
1926 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
1927 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
1928 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
1929 SetWindowLong(child, GWL_STYLE, style);
1931 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
1932 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
1933 SetWindowLong(child, GWL_STYLE, style);
1935 DestroyWindow(child);
1936 DestroyMenu(hMenu);
1939 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1941 HWND child[5], hwnd;
1942 int i;
1944 assert(total <= 5);
1946 hwnd = GetWindow(parent, GW_CHILD);
1947 ok(!hwnd, "have to start without children to perform the test\n");
1949 for (i = 0; i < total; i++)
1951 if (style[i] & DS_CONTROL)
1953 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
1954 0,0,0,0, parent, (HMENU)i, 0, NULL);
1955 if (style[i] & WS_VISIBLE)
1956 ShowWindow(child[i], SW_SHOW);
1958 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
1960 else
1961 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
1962 parent, (HMENU)i, 0, NULL);
1963 trace("child[%d] = %p\n", i, child[i]);
1964 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
1967 hwnd = GetWindow(parent, GW_CHILD);
1968 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
1969 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
1970 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
1972 for (i = 0; i < total; i++)
1974 trace("hwnd[%d] = %p\n", i, hwnd);
1975 ok(child[order[i]] == hwnd, "Z order of child #%d is wrong\n", i);
1977 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1980 for (i = 0; i < total; i++)
1981 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
1984 static void test_children_zorder(HWND parent)
1986 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
1987 WS_CHILD };
1988 const int simple_order[5] = { 0, 1, 2, 3, 4 };
1990 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
1991 WS_CHILD | WS_VISIBLE, WS_CHILD,
1992 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
1993 const int complex_order_1[1] = { 0 };
1994 const int complex_order_2[2] = { 1, 0 };
1995 const int complex_order_3[3] = { 1, 0, 2 };
1996 const int complex_order_4[4] = { 1, 0, 2, 3 };
1997 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
1998 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
1999 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2000 WS_CHILD | WS_VISIBLE };
2001 const int complex_order_6[3] = { 0, 1, 2 };
2003 /* simple WS_CHILD */
2004 test_window_tree(parent, simple_style, simple_order, 5);
2006 /* complex children styles */
2007 test_window_tree(parent, complex_style, complex_order_1, 1);
2008 test_window_tree(parent, complex_style, complex_order_2, 2);
2009 test_window_tree(parent, complex_style, complex_order_3, 3);
2010 test_window_tree(parent, complex_style, complex_order_4, 4);
2011 test_window_tree(parent, complex_style, complex_order_5, 5);
2013 /* another set of complex children styles */
2014 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2017 #define check_z_order(hwnd, next, prev, owner, topmost) \
2018 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2019 __FILE__, __LINE__)
2021 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2022 BOOL topmost, const char *file, int line)
2024 HWND test;
2025 DWORD ex_style;
2027 test = GetWindow(hwnd, GW_HWNDNEXT);
2028 /* skip foreign windows */
2029 while (test && (GetWindowThreadProcessId(test, NULL) != our_pid ||
2030 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0)))
2032 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2033 test = GetWindow(test, GW_HWNDNEXT);
2035 ok_(file, line)(next == test, "expected next %p, got %p\n", next, test);
2037 test = GetWindow(hwnd, GW_HWNDPREV);
2038 /* skip foreign windows */
2039 while (test && (GetWindowThreadProcessId(test, NULL) != our_pid ||
2040 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0)))
2042 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2043 test = GetWindow(test, GW_HWNDPREV);
2045 ok_(file, line)(prev == test, "expected prev %p, got %p\n", prev, test);
2047 test = GetWindow(hwnd, GW_OWNER);
2048 ok_(file, line)(owner == test, "expected owner %p, got %p\n", owner, test);
2050 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2051 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "expected %stopmost\n", topmost ? "" : "NOT ");
2054 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E)
2056 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2058 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2060 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2062 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2063 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2065 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2066 WS_OVERLAPPED | WS_CAPTION,
2067 100, 100, 100, 100,
2068 0, 0, GetModuleHandle(0), NULL);
2069 trace("hwnd_F %p\n", hwnd_F);
2070 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2072 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2073 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2074 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2075 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2077 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2078 WS_POPUP,
2079 100, 100, 100, 100,
2080 hwnd_F, 0, GetModuleHandle(0), NULL);
2081 trace("hwnd_C %p\n", hwnd_C);
2082 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2083 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2084 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2085 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2087 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2088 WS_POPUP,
2089 100, 100, 100, 100,
2090 hwnd_F, 0, GetModuleHandle(0), NULL);
2091 trace("hwnd_B %p\n", hwnd_B);
2092 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2093 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2094 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2095 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2096 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2098 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2099 WS_POPUP,
2100 100, 100, 100, 100,
2101 0, 0, GetModuleHandle(0), NULL);
2102 trace("hwnd_A %p\n", hwnd_A);
2103 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2104 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2105 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2106 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2107 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2108 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2110 trace("A %p B %p C %p D %p E %p F %p\n", hwnd_A, hwnd_B, hwnd_C, hwnd_D, hwnd_E, hwnd_F);
2112 /* move hwnd_F and its popups up */
2113 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2114 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2115 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2116 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2117 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2118 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2119 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2121 /* move hwnd_F and its popups down */
2122 #if 0 /* enable once Wine is fixed to pass this test */
2123 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2124 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2125 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2126 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2127 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2128 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2129 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2130 #endif
2132 DestroyWindow(hwnd_A);
2133 DestroyWindow(hwnd_B);
2134 DestroyWindow(hwnd_C);
2135 DestroyWindow(hwnd_F);
2138 static void test_vis_rgn( HWND hwnd )
2140 RECT win_rect, rgn_rect;
2141 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2142 HDC hdc;
2144 ShowWindow(hwnd,SW_SHOW);
2145 hdc = GetDC( hwnd );
2146 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2147 GetWindowRect( hwnd, &win_rect );
2148 GetRgnBox( hrgn, &rgn_rect );
2149 if (GetVersion() & 0x80000000)
2151 trace("win9x, mapping to screen coords\n");
2152 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2154 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2155 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2156 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2157 rgn_rect.left, win_rect.left );
2158 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2159 rgn_rect.top, win_rect.top );
2160 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2161 rgn_rect.right, win_rect.right );
2162 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2163 rgn_rect.bottom, win_rect.bottom );
2164 ReleaseDC( hwnd, hdc );
2167 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2169 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2171 HWND child = GetWindow(hwnd, GW_CHILD);
2172 ok(child != 0, "couldn't find child window\n");
2173 SetFocus(child);
2174 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2175 return 0;
2177 return DefWindowProc(hwnd, msg, wp, lp);
2180 static void test_SetFocus(HWND hwnd)
2182 HWND child;
2183 WNDPROC old_wnd_proc;
2185 /* check if we can set focus to non-visible windows */
2187 ShowWindow(hwnd, SW_SHOW);
2188 SetFocus(0);
2189 SetFocus(hwnd);
2190 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2191 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2192 ShowWindow(hwnd, SW_HIDE);
2193 SetFocus(0);
2194 SetFocus(hwnd);
2195 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2196 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2197 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2198 assert(child);
2199 SetFocus(child);
2200 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2201 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2202 ShowWindow(child, SW_SHOW);
2203 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2204 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2205 ShowWindow(child, SW_HIDE);
2206 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2207 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2208 ShowWindow(child, SW_SHOW);
2209 SetFocus(child);
2210 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2211 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2212 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2214 ShowWindow(child, SW_HIDE);
2215 SetFocus(hwnd);
2216 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2217 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2218 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2219 ShowWindow(child, SW_HIDE);
2220 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2222 ShowWindow(hwnd, SW_SHOW);
2223 ShowWindow(child, SW_SHOW);
2224 SetFocus(child);
2225 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2226 EnableWindow(hwnd, FALSE);
2227 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2228 EnableWindow(hwnd, TRUE);
2230 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2231 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2232 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2233 todo_wine
2234 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2235 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2236 ShowWindow(hwnd, SW_RESTORE);
2237 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2238 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2239 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2240 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2241 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2242 todo_wine
2243 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2244 old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2245 ShowWindow(hwnd, SW_RESTORE);
2246 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2247 todo_wine
2248 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2250 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2252 DestroyWindow( child );
2255 static void check_wnd_state(HWND active, HWND foreground, HWND focus, HWND capture)
2257 ok(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2258 if (foreground)
2259 ok(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2260 ok(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2261 ok(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2264 static void test_SetActiveWindow(HWND hwnd)
2266 HWND hwnd2;
2268 flush_events( TRUE );
2269 ShowWindow(hwnd, SW_HIDE);
2270 SetFocus(0);
2271 SetActiveWindow(0);
2272 check_wnd_state(0, 0, 0, 0);
2274 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2276 ShowWindow(hwnd, SW_SHOW);
2277 check_wnd_state(hwnd, hwnd, hwnd, 0);
2279 hwnd2 = SetActiveWindow(0);
2280 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2281 check_wnd_state(0, 0, 0, 0);
2283 hwnd2 = SetActiveWindow(hwnd);
2284 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2285 check_wnd_state(hwnd, hwnd, hwnd, 0);
2287 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2288 check_wnd_state(hwnd, hwnd, hwnd, 0);
2290 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2291 check_wnd_state(hwnd, hwnd, hwnd, 0);
2293 ShowWindow(hwnd, SW_HIDE);
2294 check_wnd_state(0, 0, 0, 0);
2296 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2297 SetActiveWindow(hwnd);
2298 check_wnd_state(hwnd, hwnd, hwnd, 0);
2300 ShowWindow(hwnd, SW_SHOW);
2301 check_wnd_state(hwnd, hwnd, hwnd, 0);
2303 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2304 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2306 DestroyWindow(hwnd2);
2307 check_wnd_state(hwnd, hwnd, hwnd, 0);
2309 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2310 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2312 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2313 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2315 DestroyWindow(hwnd2);
2316 check_wnd_state(hwnd, hwnd, hwnd, 0);
2319 static void test_SetForegroundWindow(HWND hwnd)
2321 BOOL ret;
2322 HWND hwnd2;
2324 flush_events( TRUE );
2325 ShowWindow(hwnd, SW_HIDE);
2326 SetFocus(0);
2327 SetActiveWindow(0);
2328 check_wnd_state(0, 0, 0, 0);
2330 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2332 ShowWindow(hwnd, SW_SHOW);
2333 check_wnd_state(hwnd, hwnd, hwnd, 0);
2335 hwnd2 = SetActiveWindow(0);
2336 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2337 check_wnd_state(0, 0, 0, 0);
2339 ret = SetForegroundWindow(hwnd);
2340 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2341 check_wnd_state(hwnd, hwnd, hwnd, 0);
2343 SetLastError(0xdeadbeef);
2344 ret = SetForegroundWindow(0);
2345 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2346 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2347 check_wnd_state(hwnd, hwnd, hwnd, 0);
2349 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2350 check_wnd_state(hwnd, hwnd, hwnd, 0);
2352 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2353 check_wnd_state(hwnd, hwnd, hwnd, 0);
2355 hwnd2 = GetForegroundWindow();
2356 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2357 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2358 hwnd2 = GetForegroundWindow();
2359 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2361 ShowWindow(hwnd, SW_HIDE);
2362 check_wnd_state(0, 0, 0, 0);
2364 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2365 ret = SetForegroundWindow(hwnd);
2366 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2367 check_wnd_state(hwnd, hwnd, hwnd, 0);
2369 ShowWindow(hwnd, SW_SHOW);
2370 check_wnd_state(hwnd, hwnd, hwnd, 0);
2372 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2373 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2375 DestroyWindow(hwnd2);
2376 check_wnd_state(hwnd, hwnd, hwnd, 0);
2378 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2379 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2381 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2382 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2384 DestroyWindow(hwnd2);
2385 check_wnd_state(hwnd, hwnd, hwnd, 0);
2388 static WNDPROC old_button_proc;
2390 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2392 LRESULT ret;
2393 USHORT key_state;
2395 key_state = GetKeyState(VK_LBUTTON);
2396 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2398 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2400 if (msg == WM_LBUTTONDOWN)
2402 HWND hwnd, capture;
2404 check_wnd_state(button, button, button, button);
2406 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2407 assert(hwnd);
2408 trace("hwnd %p\n", hwnd);
2410 check_wnd_state(button, button, button, button);
2412 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2414 check_wnd_state(button, button, button, button);
2416 DestroyWindow(hwnd);
2418 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2419 assert(hwnd);
2420 trace("hwnd %p\n", hwnd);
2422 check_wnd_state(button, button, button, button);
2424 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2425 * match internal button state.
2427 SendMessage(button, WM_KILLFOCUS, 0, 0);
2428 check_wnd_state(button, button, button, 0);
2430 ShowWindow(hwnd, SW_SHOW);
2431 check_wnd_state(hwnd, hwnd, hwnd, 0);
2433 capture = SetCapture(hwnd);
2434 ok(capture == 0, "SetCapture() = %p\n", capture);
2436 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2438 DestroyWindow(hwnd);
2440 check_wnd_state(button, 0, button, 0);
2443 return ret;
2446 static void test_capture_1(void)
2448 HWND button, capture;
2450 capture = GetCapture();
2451 ok(capture == 0, "GetCapture() = %p\n", capture);
2453 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2454 assert(button);
2455 trace("button %p\n", button);
2457 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2459 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2461 capture = SetCapture(button);
2462 ok(capture == 0, "SetCapture() = %p\n", capture);
2463 check_wnd_state(button, 0, button, button);
2465 DestroyWindow(button);
2466 check_wnd_state(0, 0, 0, 0);
2469 static void test_capture_2(void)
2471 HWND button, hwnd, capture;
2473 check_wnd_state(0, 0, 0, 0);
2475 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2476 assert(button);
2477 trace("button %p\n", button);
2479 check_wnd_state(button, button, button, 0);
2481 capture = SetCapture(button);
2482 ok(capture == 0, "SetCapture() = %p\n", capture);
2484 check_wnd_state(button, button, button, button);
2486 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2487 * internal button state.
2489 SendMessage(button, WM_KILLFOCUS, 0, 0);
2490 check_wnd_state(button, button, button, button);
2492 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2493 assert(hwnd);
2494 trace("hwnd %p\n", hwnd);
2496 check_wnd_state(button, button, button, button);
2498 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2500 check_wnd_state(button, button, button, button);
2502 DestroyWindow(hwnd);
2504 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2505 assert(hwnd);
2506 trace("hwnd %p\n", hwnd);
2508 check_wnd_state(button, button, button, button);
2510 ShowWindow(hwnd, SW_SHOW);
2512 check_wnd_state(hwnd, hwnd, hwnd, button);
2514 capture = SetCapture(hwnd);
2515 ok(capture == button, "SetCapture() = %p\n", capture);
2517 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2519 DestroyWindow(hwnd);
2520 check_wnd_state(button, button, button, 0);
2522 DestroyWindow(button);
2523 check_wnd_state(0, 0, 0, 0);
2526 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2528 BOOL ret;
2530 ShowWindow(hwnd1, SW_HIDE);
2531 ShowWindow(hwnd2, SW_HIDE);
2533 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2534 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2536 SetCapture(hwnd1);
2537 check_wnd_state(0, 0, 0, hwnd1);
2539 SetCapture(hwnd2);
2540 check_wnd_state(0, 0, 0, hwnd2);
2542 ShowWindow(hwnd1, SW_SHOW);
2543 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2545 ret = ReleaseCapture();
2546 ok (ret, "releasecapture did not return TRUE.\n");
2547 ret = ReleaseCapture();
2548 ok (ret, "releasecapture did not return TRUE after second try.\n");
2551 static void test_keyboard_input(HWND hwnd)
2553 MSG msg;
2554 BOOL ret;
2556 flush_events( TRUE );
2557 ShowWindow(hwnd, SW_SHOW);
2558 UpdateWindow(hwnd);
2559 flush_events( TRUE );
2561 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2563 SetFocus(hwnd);
2564 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2566 flush_events( TRUE );
2568 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2569 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2570 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2571 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2572 ok( !ret, "message %04x available\n", msg.message);
2574 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2576 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2577 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2578 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2579 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2580 ok( !ret, "message %04x available\n", msg.message);
2582 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2584 keybd_event(VK_SPACE, 0, 0, 0);
2585 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2586 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2587 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2588 ok( !ret, "message %04x available\n", msg.message);
2590 SetFocus(0);
2591 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2593 flush_events( TRUE );
2595 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2596 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2597 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2598 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2599 ok( !ret, "message %04x available\n", msg.message);
2601 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2603 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2604 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2605 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2606 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2607 ok( !ret, "message %04x available\n", msg.message);
2609 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2611 keybd_event(VK_SPACE, 0, 0, 0);
2612 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2613 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2614 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2615 ok( !ret, "message %04x available\n", msg.message);
2618 static void test_mouse_input(HWND hwnd)
2620 RECT rc;
2621 POINT pt;
2622 int x, y;
2623 HWND popup;
2624 MSG msg;
2625 BOOL ret;
2626 LRESULT res;
2628 ShowWindow(hwnd, SW_SHOW);
2629 UpdateWindow(hwnd);
2631 GetWindowRect(hwnd, &rc);
2632 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2634 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2635 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2636 hwnd, 0, 0, NULL);
2637 assert(popup != 0);
2638 ShowWindow(popup, SW_SHOW);
2639 UpdateWindow(popup);
2641 GetWindowRect(popup, &rc);
2642 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2644 x = rc.left + (rc.right - rc.left) / 2;
2645 y = rc.top + (rc.bottom - rc.top) / 2;
2646 trace("setting cursor to (%d,%d)\n", x, y);
2648 SetCursorPos(x, y);
2649 GetCursorPos(&pt);
2650 ok(x == pt.x && y == pt.y, "wrong cursor pos (%d,%d), expected (%d,%d)\n", pt.x, pt.y, x, y);
2652 flush_events( TRUE );
2654 /* Check that setting the same position will generate WM_MOUSEMOVE */
2655 SetCursorPos(x, y);
2656 msg.message = 0;
2657 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2658 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2659 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);
2661 /* force the system to update its internal queue mouse position,
2662 * otherwise it won't generate relative mouse movements below.
2664 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2665 flush_events( TRUE );
2667 msg.message = 0;
2668 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2669 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2670 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2671 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2672 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2673 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2674 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2675 ok( !ret, "message %04x available\n", msg.message);
2677 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2678 ShowWindow(popup, SW_HIDE);
2679 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2680 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2681 flush_events( TRUE );
2683 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2684 ShowWindow(hwnd, SW_HIDE);
2685 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2686 ok( !ret, "message %04x available\n", msg.message);
2687 flush_events( TRUE );
2689 /* test mouse clicks */
2691 ShowWindow(hwnd, SW_SHOW);
2692 flush_events( TRUE );
2693 ShowWindow(popup, SW_SHOW);
2694 flush_events( TRUE );
2696 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2697 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2698 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2699 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2701 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2702 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2703 msg.hwnd, popup, msg.message);
2704 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2705 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2706 msg.hwnd, popup, msg.message);
2708 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2709 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2710 msg.hwnd, popup, msg.message);
2711 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2712 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2713 msg.hwnd, popup, msg.message);
2715 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2716 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
2717 msg.hwnd, popup, msg.message);
2718 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2719 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
2720 msg.hwnd, popup, msg.message);
2722 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2723 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2724 msg.hwnd, popup, msg.message);
2725 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2726 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2727 msg.hwnd, popup, msg.message);
2729 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2730 ok(!ret, "message %04x available\n", msg.message);
2732 ShowWindow(popup, SW_HIDE);
2733 flush_events( TRUE );
2735 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2736 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2737 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2738 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2740 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2741 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2742 msg.hwnd, hwnd, msg.message);
2743 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2744 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2745 msg.hwnd, hwnd, msg.message);
2747 test_lbuttondown_flag = TRUE;
2748 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
2749 test_lbuttondown_flag = FALSE;
2751 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2752 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2753 msg.hwnd, popup, msg.message);
2754 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2755 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2756 msg.hwnd, popup, msg.message);
2757 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2759 /* Test WM_MOUSEACTIVATE */
2760 #define TEST_MOUSEACTIVATE(A,B) \
2761 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2762 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2764 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
2765 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
2766 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
2767 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
2768 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
2769 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
2770 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
2771 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
2772 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
2773 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
2774 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
2775 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
2776 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
2777 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
2778 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
2779 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
2780 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
2781 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
2782 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
2783 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
2784 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
2785 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
2786 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
2787 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
2789 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2790 flush_events( TRUE );
2792 DestroyWindow(popup);
2795 static void test_validatergn(HWND hwnd)
2797 HWND child;
2798 RECT rc, rc2;
2799 HRGN rgn;
2800 int ret;
2801 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
2802 ShowWindow(hwnd, SW_SHOW);
2803 UpdateWindow( hwnd);
2804 /* test that ValidateRect validates children*/
2805 InvalidateRect( child, NULL, 1);
2806 GetWindowRect( child, &rc);
2807 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2808 ret = GetUpdateRect( child, &rc2, 0);
2809 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
2810 "Update rectangle is empty!\n");
2811 ValidateRect( hwnd, &rc);
2812 ret = GetUpdateRect( child, &rc2, 0);
2813 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2814 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2815 rc2.right, rc2.bottom);
2817 /* now test ValidateRgn */
2818 InvalidateRect( child, NULL, 1);
2819 GetWindowRect( child, &rc);
2820 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2821 rgn = CreateRectRgnIndirect( &rc);
2822 ValidateRgn( hwnd, rgn);
2823 ret = GetUpdateRect( child, &rc2, 0);
2824 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2825 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2826 rc2.right, rc2.bottom);
2828 DeleteObject( rgn);
2829 DestroyWindow( child );
2832 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
2834 MoveWindow( hwnd, 0, 0, x, y, 0);
2835 GetWindowRect( hwnd, prc);
2836 trace("window rect is %d,%d - %d,%d\n",
2837 prc->left,prc->top,prc->right,prc->bottom);
2838 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
2839 trace("nccalc rect is %d,%d - %d,%d\n",
2840 prc->left,prc->top,prc->right,prc->bottom);
2843 static void test_nccalcscroll(HWND parent)
2845 RECT rc1;
2846 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
2847 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
2848 HWND hwnd = CreateWindowExA(0, "static", NULL,
2849 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
2850 10, 10, 200, 200, parent, 0, 0, NULL);
2851 ShowWindow( parent, SW_SHOW);
2852 UpdateWindow( parent);
2854 /* test window too low for a horizontal scroll bar */
2855 nccalchelper( hwnd, 100, sbheight, &rc1);
2856 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
2857 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
2859 /* test window just high enough for a horizontal scroll bar */
2860 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
2861 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
2862 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2864 /* test window too narrow for a vertical scroll bar */
2865 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
2866 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
2867 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2869 /* test window just wide enough for a vertical scroll bar */
2870 nccalchelper( hwnd, sbwidth, 100, &rc1);
2871 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
2872 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
2874 /* same test, but with client edge: not enough width */
2875 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
2876 nccalchelper( hwnd, sbwidth, 100, &rc1);
2877 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
2878 "Width should be %d size is %d,%d - %d,%d\n",
2879 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
2881 DestroyWindow( hwnd);
2884 static void test_SetParent(void)
2886 BOOL ret;
2887 HWND desktop = GetDesktopWindow();
2888 HMENU hMenu;
2889 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
2890 HWND parent, child1, child2, child3, child4, sibling;
2892 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2893 100, 100, 200, 200, 0, 0, 0, NULL);
2894 assert(parent != 0);
2895 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2896 0, 0, 50, 50, parent, 0, 0, NULL);
2897 assert(child1 != 0);
2898 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2899 0, 0, 50, 50, child1, 0, 0, NULL);
2900 assert(child2 != 0);
2901 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2902 0, 0, 50, 50, child2, 0, 0, NULL);
2903 assert(child3 != 0);
2904 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2905 0, 0, 50, 50, child3, 0, 0, NULL);
2906 assert(child4 != 0);
2908 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2909 parent, child1, child2, child3, child4);
2911 check_parents(parent, desktop, 0, 0, 0, parent, parent);
2912 check_parents(child1, parent, parent, parent, 0, parent, parent);
2913 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2914 check_parents(child3, child2, child2, child2, 0, child2, parent);
2915 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2917 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
2918 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
2919 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2920 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
2921 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2923 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
2924 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2925 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
2926 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
2927 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
2928 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
2929 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
2930 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
2931 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2933 if (!is_win9x) /* Win9x doesn't survive this test */
2935 ok(!SetParent(parent, child1), "SetParent should fail\n");
2936 ok(!SetParent(child2, child3), "SetParent should fail\n");
2937 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
2938 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
2939 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
2940 ok(!SetParent(child2, parent), "SetParent should fail\n");
2941 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
2943 check_parents(parent, child4, child4, 0, 0, child4, parent);
2944 check_parents(child1, parent, parent, parent, 0, child4, parent);
2945 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2946 check_parents(child3, child2, child2, child2, 0, child2, parent);
2947 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2950 hMenu = CreateMenu();
2951 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2952 100, 100, 200, 200, 0, hMenu, 0, NULL);
2953 assert(sibling != 0);
2955 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
2956 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
2958 ret = DestroyWindow(parent);
2959 ok( ret, "DestroyWindow() error %d\n", GetLastError());
2961 ok(!IsWindow(parent), "parent still exists\n");
2962 ok(!IsWindow(sibling), "sibling still exists\n");
2963 ok(!IsWindow(child1), "child1 still exists\n");
2964 ok(!IsWindow(child2), "child2 still exists\n");
2965 ok(!IsWindow(child3), "child3 still exists\n");
2966 ok(!IsWindow(child4), "child4 still exists\n");
2969 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2971 LPCREATESTRUCT lpcs;
2972 LPSTYLESTRUCT lpss;
2974 switch (msg)
2976 case WM_NCCREATE:
2977 case WM_CREATE:
2978 lpcs = (LPCREATESTRUCT)lparam;
2979 lpss = (LPSTYLESTRUCT)lpcs->lpCreateParams;
2980 if (lpss)
2982 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
2983 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
2984 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
2985 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
2986 else
2987 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
2989 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
2990 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2991 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
2993 ok(lpss->styleNew == lpcs->style,
2994 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
2995 lpss->styleNew, lpcs->style);
2997 break;
2999 return DefWindowProc(hwnd, msg, wparam, lparam);
3002 static ATOM atomStyleCheckClass;
3004 static void register_style_check_class(void)
3006 WNDCLASS wc =
3009 StyleCheckProc,
3012 GetModuleHandle(NULL),
3013 NULL,
3014 LoadCursor(NULL, IDC_ARROW),
3015 (HBRUSH)(COLOR_BTNFACE+1),
3016 NULL,
3017 TEXT("WineStyleCheck"),
3020 atomStyleCheckClass = RegisterClass(&wc);
3023 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3025 DWORD dwActualStyle;
3026 DWORD dwActualExStyle;
3027 STYLESTRUCT ss;
3028 HWND hwnd;
3029 HWND hwndParent = NULL;
3031 ss.styleNew = dwStyleIn;
3032 ss.styleOld = dwExStyleIn;
3034 if (dwStyleIn & WS_CHILD)
3036 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
3037 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3040 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
3041 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3042 assert(hwnd);
3044 flush_events( TRUE );
3046 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3047 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3048 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3049 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3050 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3052 DestroyWindow(hwnd);
3053 if (hwndParent) DestroyWindow(hwndParent);
3056 /* tests what window styles the window manager automatically adds */
3057 static void test_window_styles(void)
3059 register_style_check_class();
3061 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3062 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3063 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3064 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3065 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3066 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3067 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3068 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3069 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3070 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3071 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3074 static void test_scrollvalidate( HWND parent)
3076 HDC hdc;
3077 HRGN hrgn=CreateRectRgn(0,0,0,0);
3078 HRGN exprgn, tmprgn, clipping;
3079 RECT rc, rcu, cliprc;
3080 /* create two overlapping child windows. The visual region
3081 * of hwnd1 is clipped by the overlapping part of
3082 * hwnd2 because of the WS_CLIPSIBLING style */
3083 HWND hwnd1, hwnd2;
3085 clipping = CreateRectRgn(0,0,0,0);
3086 tmprgn = CreateRectRgn(0,0,0,0);
3087 exprgn = CreateRectRgn(0,0,0,0);
3088 hwnd2 = CreateWindowExA(0, "static", NULL,
3089 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3090 75, 30, 100, 100, parent, 0, 0, NULL);
3091 hwnd1 = CreateWindowExA(0, "static", NULL,
3092 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3093 25, 50, 100, 100, parent, 0, 0, NULL);
3094 ShowWindow( parent, SW_SHOW);
3095 UpdateWindow( parent);
3096 GetClientRect( hwnd1, &rc);
3097 cliprc=rc;
3098 SetRectRgn( clipping, 10, 10, 90, 90);
3099 hdc = GetDC( hwnd1);
3100 /* for a visual touch */
3101 TextOut( hdc, 0,10, "0123456789", 10);
3102 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3103 if (winetest_debug > 0) dump_region(hrgn);
3104 /* create a region with what is expected */
3105 SetRectRgn( exprgn, 39,0,49,74);
3106 SetRectRgn( tmprgn, 88,79,98,93);
3107 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3108 SetRectRgn( tmprgn, 0,93,98,98);
3109 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3110 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3111 trace("update rect is %d,%d - %d,%d\n",
3112 rcu.left,rcu.top,rcu.right,rcu.bottom);
3113 /* now with clipping region */
3114 SelectClipRgn( hdc, clipping);
3115 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3116 if (winetest_debug > 0) dump_region(hrgn);
3117 /* create a region with what is expected */
3118 SetRectRgn( exprgn, 39,10,49,74);
3119 SetRectRgn( tmprgn, 80,79,90,85);
3120 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3121 SetRectRgn( tmprgn, 10,85,90,90);
3122 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3123 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3124 trace("update rect is %d,%d - %d,%d\n",
3125 rcu.left,rcu.top,rcu.right,rcu.bottom);
3126 ReleaseDC( hwnd1, hdc);
3128 /* test scrolling a window with an update region */
3129 DestroyWindow( hwnd2);
3130 ValidateRect( hwnd1, NULL);
3131 SetRect( &rc, 40,40, 50,50);
3132 InvalidateRect( hwnd1, &rc, 1);
3133 GetClientRect( hwnd1, &rc);
3134 cliprc=rc;
3135 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
3136 SW_SCROLLCHILDREN | SW_INVALIDATE);
3137 if (winetest_debug > 0) dump_region(hrgn);
3138 SetRectRgn( exprgn, 88,0,98,98);
3139 SetRectRgn( tmprgn, 30, 40, 50, 50);
3140 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3141 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3143 /* clear an update region */
3144 UpdateWindow( hwnd1 );
3146 SetRect( &rc, 0,40, 100,60);
3147 SetRect( &cliprc, 0,0, 100,100);
3148 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3149 if (winetest_debug > 0) dump_region( hrgn );
3150 SetRectRgn( exprgn, 0, 40, 98, 60 );
3151 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
3153 /* now test ScrollWindowEx with a combination of
3154 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3155 /* make hwnd2 the child of hwnd1 */
3156 hwnd2 = CreateWindowExA(0, "static", NULL,
3157 WS_CHILD| WS_VISIBLE | WS_BORDER ,
3158 50, 50, 100, 100, hwnd1, 0, 0, NULL);
3159 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
3160 GetClientRect( hwnd1, &rc);
3161 cliprc=rc;
3163 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3164 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3165 ValidateRect( hwnd1, NULL);
3166 ValidateRect( hwnd2, NULL);
3167 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
3168 SW_SCROLLCHILDREN | SW_INVALIDATE);
3169 if (winetest_debug > 0) dump_region(hrgn);
3170 SetRectRgn( exprgn, 88,0,98,88);
3171 SetRectRgn( tmprgn, 0,88,98,98);
3172 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3173 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3175 /* SW_SCROLLCHILDREN */
3176 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3177 ValidateRect( hwnd1, NULL);
3178 ValidateRect( hwnd2, NULL);
3179 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3180 if (winetest_debug > 0) dump_region(hrgn);
3181 /* expected region is the same as in previous test */
3182 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3184 /* no SW_SCROLLCHILDREN */
3185 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3186 ValidateRect( hwnd1, NULL);
3187 ValidateRect( hwnd2, NULL);
3188 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3189 if (winetest_debug > 0) dump_region(hrgn);
3190 /* expected region is the same as in previous test */
3191 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3193 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3194 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3195 ValidateRect( hwnd1, NULL);
3196 ValidateRect( hwnd2, NULL);
3197 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3198 if (winetest_debug > 0) dump_region(hrgn);
3199 SetRectRgn( exprgn, 88,0,98,20);
3200 SetRectRgn( tmprgn, 20,20,98,30);
3201 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3202 SetRectRgn( tmprgn, 20,30,30,88);
3203 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3204 SetRectRgn( tmprgn, 0,88,30,98);
3205 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3206 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3208 /* clean up */
3209 DeleteObject( hrgn);
3210 DeleteObject( exprgn);
3211 DeleteObject( tmprgn);
3212 DestroyWindow( hwnd1);
3213 DestroyWindow( hwnd2);
3216 /* couple of tests of return values of scrollbar functions
3217 * called on a scrollbarless window */
3218 static void test_scroll(void)
3220 BOOL ret;
3221 INT min, max;
3222 SCROLLINFO si;
3223 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3224 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3225 100, 100, 200, 200, 0, 0, 0, NULL);
3226 /* horizontal */
3227 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3228 ok( ret, "GetScrollRange returns FALSE\n");
3229 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3230 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3231 si.cbSize = sizeof( si);
3232 si.fMask = SIF_PAGE;
3233 si.nPage = 0xdeadbeef;
3234 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3235 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3236 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3237 /* vertical */
3238 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3239 ok( ret, "GetScrollRange returns FALSE\n");
3240 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3241 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3242 si.cbSize = sizeof( si);
3243 si.fMask = SIF_PAGE;
3244 si.nPage = 0xdeadbeef;
3245 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3246 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3247 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3248 /* clean up */
3249 DestroyWindow( hwnd);
3252 static void test_scrolldc( HWND parent)
3254 HDC hdc;
3255 HRGN exprgn, tmprgn, hrgn;
3256 RECT rc, rc2, rcu, cliprc;
3257 HWND hwnd1;
3258 COLORREF colr;
3260 hrgn = CreateRectRgn(0,0,0,0);
3261 tmprgn = CreateRectRgn(0,0,0,0);
3262 exprgn = CreateRectRgn(0,0,0,0);
3264 hwnd1 = CreateWindowExA(0, "static", NULL,
3265 WS_CHILD| WS_VISIBLE,
3266 25, 50, 100, 100, parent, 0, 0, NULL);
3267 ShowWindow( parent, SW_SHOW);
3268 UpdateWindow( parent);
3269 flush_events( TRUE );
3270 GetClientRect( hwnd1, &rc);
3271 hdc = GetDC( hwnd1);
3272 /* paint the upper half of the window black */
3273 rc2 = rc;
3274 rc2.bottom = ( rc.top + rc.bottom) /2;
3275 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3276 /* clip region is the lower half */
3277 cliprc=rc;
3278 cliprc.top = (rc.top + rc.bottom) /2;
3279 /* test whether scrolled pixels are properly clipped */
3280 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3281 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3282 /* this scroll should not cause any visible changes */
3283 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3284 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3285 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3286 /* test with NULL clip rect */
3287 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3288 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3289 trace("update rect: %d,%d - %d,%d\n",
3290 rcu.left, rcu.top, rcu.right, rcu.bottom);
3291 if (winetest_debug > 0) dump_region(hrgn);
3292 SetRect(&rc2, 0, 0, 100, 100);
3293 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3294 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3296 SetRectRgn( exprgn, 0, 0, 20, 80);
3297 SetRectRgn( tmprgn, 0, 80, 100, 100);
3298 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3299 if (winetest_debug > 0) dump_region(exprgn);
3300 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3301 /* test clip rect > scroll rect */
3302 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3303 rc2=rc;
3304 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3305 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3306 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3307 SetRectRgn( exprgn, 25, 25, 75, 35);
3308 SetRectRgn( tmprgn, 25, 35, 35, 75);
3309 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3310 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3311 colr = GetPixel( hdc, 80, 80);
3312 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3313 trace("update rect: %d,%d - %d,%d\n",
3314 rcu.left, rcu.top, rcu.right, rcu.bottom);
3315 if (winetest_debug > 0) dump_region(hrgn);
3317 /* clean up */
3318 DeleteObject(hrgn);
3319 DeleteObject(exprgn);
3320 DeleteObject(tmprgn);
3321 DestroyWindow(hwnd1);
3324 static void test_params(void)
3326 HWND hwnd;
3327 INT rc;
3329 /* Just a param check */
3330 SetLastError(0xdeadbeef);
3331 rc = GetWindowText(hwndMain2, NULL, 1024);
3332 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
3334 SetLastError(0xdeadbeef);
3335 hwnd=CreateWindow("LISTBOX", "TestList",
3336 (LBS_STANDARD & ~LBS_SORT),
3337 0, 0, 100, 100,
3338 NULL, (HMENU)1, NULL, 0);
3340 ok(!hwnd, "CreateWindow with invalid menu handle should fail\n");
3341 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3342 GetLastError() == 0xdeadbeef, /* Win9x */
3343 "wrong last error value %d\n", GetLastError());
3346 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3348 HWND hwnd = 0;
3350 hwnd = CreateWindowEx(exStyle, class, class, style,
3351 110, 100,
3352 225, 200,
3354 menu ? hmenu : 0,
3355 0, 0);
3356 if (!hwnd) {
3357 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
3358 return;
3360 ShowWindow(hwnd, SW_SHOW);
3362 test_nonclient_area(hwnd);
3364 SetMenu(hwnd, 0);
3365 DestroyWindow(hwnd);
3368 static BOOL AWR_init(void)
3370 WNDCLASS class;
3372 class.style = CS_HREDRAW | CS_VREDRAW;
3373 class.lpfnWndProc = DefWindowProcA;
3374 class.cbClsExtra = 0;
3375 class.cbWndExtra = 0;
3376 class.hInstance = 0;
3377 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3378 class.hCursor = LoadCursor (0, IDC_ARROW);
3379 class.hbrBackground = 0;
3380 class.lpszMenuName = 0;
3381 class.lpszClassName = szAWRClass;
3383 if (!RegisterClass (&class)) {
3384 ok(FALSE, "RegisterClass failed\n");
3385 return FALSE;
3388 hmenu = CreateMenu();
3389 if (!hmenu)
3390 return FALSE;
3391 ok(hmenu != 0, "Failed to create menu\n");
3392 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3394 return TRUE;
3398 static void test_AWR_window_size(BOOL menu)
3400 LONG styles[] = {
3401 WS_POPUP,
3402 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3403 WS_SYSMENU,
3404 WS_THICKFRAME,
3405 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3406 WS_HSCROLL, WS_VSCROLL
3408 LONG exStyles[] = {
3409 WS_EX_CLIENTEDGE,
3410 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3411 WS_EX_APPWINDOW,
3412 #if 0
3413 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3414 WS_EX_DLGMODALFRAME,
3415 WS_EX_STATICEDGE,
3416 #endif
3419 int i;
3421 /* A exhaustive check of all the styles takes too long
3422 * so just do a (hopefully representative) sample
3424 for (i = 0; i < COUNTOF(styles); ++i)
3425 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3426 for (i = 0; i < COUNTOF(exStyles); ++i) {
3427 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3428 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3431 #undef COUNTOF
3433 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3435 static void test_AdjustWindowRect(void)
3437 if (!AWR_init())
3438 return;
3440 SHOWSYSMETRIC(SM_CYCAPTION);
3441 SHOWSYSMETRIC(SM_CYSMCAPTION);
3442 SHOWSYSMETRIC(SM_CYMENU);
3443 SHOWSYSMETRIC(SM_CXEDGE);
3444 SHOWSYSMETRIC(SM_CYEDGE);
3445 SHOWSYSMETRIC(SM_CXVSCROLL);
3446 SHOWSYSMETRIC(SM_CYHSCROLL);
3447 SHOWSYSMETRIC(SM_CXFRAME);
3448 SHOWSYSMETRIC(SM_CYFRAME);
3449 SHOWSYSMETRIC(SM_CXDLGFRAME);
3450 SHOWSYSMETRIC(SM_CYDLGFRAME);
3451 SHOWSYSMETRIC(SM_CXBORDER);
3452 SHOWSYSMETRIC(SM_CYBORDER);
3454 test_AWR_window_size(FALSE);
3455 test_AWR_window_size(TRUE);
3457 DestroyMenu(hmenu);
3459 #undef SHOWSYSMETRIC
3462 /* Global variables to trigger exit from loop */
3463 static int redrawComplete, WMPAINT_count;
3465 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3467 switch (msg)
3469 case WM_PAINT:
3470 trace("doing WM_PAINT %d\n", WMPAINT_count);
3471 WMPAINT_count++;
3472 if (WMPAINT_count > 10 && redrawComplete == 0) {
3473 PAINTSTRUCT ps;
3474 BeginPaint(hwnd, &ps);
3475 EndPaint(hwnd, &ps);
3476 return 1;
3478 return 0;
3480 return DefWindowProc(hwnd, msg, wparam, lparam);
3483 /* Ensure we exit from RedrawNow regardless of invalidated area */
3484 static void test_redrawnow(void)
3486 WNDCLASSA cls;
3487 HWND hwndMain;
3489 cls.style = CS_DBLCLKS;
3490 cls.lpfnWndProc = redraw_window_procA;
3491 cls.cbClsExtra = 0;
3492 cls.cbWndExtra = 0;
3493 cls.hInstance = GetModuleHandleA(0);
3494 cls.hIcon = 0;
3495 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3496 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3497 cls.lpszMenuName = NULL;
3498 cls.lpszClassName = "RedrawWindowClass";
3500 if(!RegisterClassA(&cls)) {
3501 trace("Register failed %d\n", GetLastError());
3502 return;
3505 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3506 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3508 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3509 ShowWindow(hwndMain, SW_SHOW);
3510 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3511 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3512 ok( WMPAINT_count == 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3513 redrawComplete = TRUE;
3514 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3516 /* clean up */
3517 DestroyWindow( hwndMain);
3520 struct parentdc_stat {
3521 RECT client;
3522 RECT clip;
3523 RECT paint;
3526 struct parentdc_test {
3527 struct parentdc_stat main, main_todo;
3528 struct parentdc_stat child1, child1_todo;
3529 struct parentdc_stat child2, child2_todo;
3532 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3534 RECT rc;
3535 PAINTSTRUCT ps;
3537 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3539 switch (msg)
3541 case WM_PAINT:
3542 trace("doing WM_PAINT on %p\n", hwnd);
3543 GetClientRect(hwnd, &rc);
3544 CopyRect(&t->client, &rc);
3545 trace("client rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3546 GetWindowRect(hwnd, &rc);
3547 trace("window rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3548 BeginPaint(hwnd, &ps);
3549 CopyRect(&t->paint, &ps.rcPaint);
3550 GetClipBox(ps.hdc, &rc);
3551 CopyRect(&t->clip, &rc);
3552 trace("clip rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3553 trace("paint rect (%d, %d)-(%d, %d)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3554 EndPaint(hwnd, &ps);
3555 return 0;
3557 return DefWindowProc(hwnd, msg, wparam, lparam);
3560 static void zero_parentdc_stat(struct parentdc_stat *t)
3562 SetRectEmpty(&t->client);
3563 SetRectEmpty(&t->clip);
3564 SetRectEmpty(&t->paint);
3567 static void zero_parentdc_test(struct parentdc_test *t)
3569 zero_parentdc_stat(&t->main);
3570 zero_parentdc_stat(&t->child1);
3571 zero_parentdc_stat(&t->child2);
3574 #define parentdc_field_ok(t, w, r, f, got) \
3575 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3576 ": expected %d, got %d\n", \
3577 t.w.r.f, got.w.r.f)
3579 #define parentdc_todo_field_ok(t, w, r, f, got) \
3580 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3581 else parentdc_field_ok(t, w, r, f, got)
3583 #define parentdc_rect_ok(t, w, r, got) \
3584 parentdc_todo_field_ok(t, w, r, left, got); \
3585 parentdc_todo_field_ok(t, w, r, top, got); \
3586 parentdc_todo_field_ok(t, w, r, right, got); \
3587 parentdc_todo_field_ok(t, w, r, bottom, got);
3589 #define parentdc_win_ok(t, w, got) \
3590 parentdc_rect_ok(t, w, client, got); \
3591 parentdc_rect_ok(t, w, clip, got); \
3592 parentdc_rect_ok(t, w, paint, got);
3594 #define parentdc_ok(t, got) \
3595 parentdc_win_ok(t, main, got); \
3596 parentdc_win_ok(t, child1, got); \
3597 parentdc_win_ok(t, child2, got);
3599 static void test_csparentdc(void)
3601 WNDCLASSA clsMain, cls;
3602 HWND hwndMain, hwnd1, hwnd2;
3603 RECT rc;
3605 struct parentdc_test test_answer;
3607 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3608 const struct parentdc_test test1 =
3610 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
3611 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3612 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3615 const struct parentdc_test test2 =
3617 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
3618 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3619 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3622 const struct parentdc_test test3 =
3624 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3625 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3626 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3629 const struct parentdc_test test4 =
3631 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
3632 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
3633 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3636 const struct parentdc_test test5 =
3638 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
3639 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3640 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3643 const struct parentdc_test test6 =
3645 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3646 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3647 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3650 const struct parentdc_test test7 =
3652 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3653 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3654 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3656 #undef nothing_todo
3658 clsMain.style = CS_DBLCLKS;
3659 clsMain.lpfnWndProc = parentdc_window_procA;
3660 clsMain.cbClsExtra = 0;
3661 clsMain.cbWndExtra = 0;
3662 clsMain.hInstance = GetModuleHandleA(0);
3663 clsMain.hIcon = 0;
3664 clsMain.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3665 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
3666 clsMain.lpszMenuName = NULL;
3667 clsMain.lpszClassName = "ParentDcMainWindowClass";
3669 if(!RegisterClassA(&clsMain)) {
3670 trace("Register failed %d\n", GetLastError());
3671 return;
3674 cls.style = CS_DBLCLKS | CS_PARENTDC;
3675 cls.lpfnWndProc = parentdc_window_procA;
3676 cls.cbClsExtra = 0;
3677 cls.cbWndExtra = 0;
3678 cls.hInstance = GetModuleHandleA(0);
3679 cls.hIcon = 0;
3680 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3681 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3682 cls.lpszMenuName = NULL;
3683 cls.lpszClassName = "ParentDcWindowClass";
3685 if(!RegisterClassA(&cls)) {
3686 trace("Register failed %d\n", GetLastError());
3687 return;
3690 SetRect(&rc, 0, 0, 150, 150);
3691 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
3692 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3693 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
3694 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
3695 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
3696 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
3697 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
3698 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
3699 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
3700 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
3701 ShowWindow(hwndMain, SW_SHOW);
3702 ShowWindow(hwnd1, SW_SHOW);
3703 ShowWindow(hwnd2, SW_SHOW);
3704 flush_events( TRUE );
3706 zero_parentdc_test(&test_answer);
3707 InvalidateRect(hwndMain, NULL, TRUE);
3708 flush_events( TRUE );
3709 parentdc_ok(test1, test_answer);
3711 zero_parentdc_test(&test_answer);
3712 SetRect(&rc, 0, 0, 50, 50);
3713 InvalidateRect(hwndMain, &rc, TRUE);
3714 flush_events( TRUE );
3715 parentdc_ok(test2, test_answer);
3717 zero_parentdc_test(&test_answer);
3718 SetRect(&rc, 0, 0, 10, 10);
3719 InvalidateRect(hwndMain, &rc, TRUE);
3720 flush_events( TRUE );
3721 parentdc_ok(test3, test_answer);
3723 zero_parentdc_test(&test_answer);
3724 SetRect(&rc, 40, 40, 50, 50);
3725 InvalidateRect(hwndMain, &rc, TRUE);
3726 flush_events( TRUE );
3727 parentdc_ok(test4, test_answer);
3729 zero_parentdc_test(&test_answer);
3730 SetRect(&rc, 20, 20, 60, 60);
3731 InvalidateRect(hwndMain, &rc, TRUE);
3732 flush_events( TRUE );
3733 parentdc_ok(test5, test_answer);
3735 zero_parentdc_test(&test_answer);
3736 SetRect(&rc, 0, 0, 10, 10);
3737 InvalidateRect(hwnd1, &rc, TRUE);
3738 flush_events( TRUE );
3739 parentdc_ok(test6, test_answer);
3741 zero_parentdc_test(&test_answer);
3742 SetRect(&rc, -5, -5, 65, 65);
3743 InvalidateRect(hwnd1, &rc, TRUE);
3744 flush_events( TRUE );
3745 parentdc_ok(test7, test_answer);
3747 DestroyWindow(hwndMain);
3748 DestroyWindow(hwnd1);
3749 DestroyWindow(hwnd2);
3752 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3754 return DefWindowProcA(hwnd, msg, wparam, lparam);
3757 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3759 return DefWindowProcW(hwnd, msg, wparam, lparam);
3762 static void test_IsWindowUnicode(void)
3764 static const char ansi_class_nameA[] = "ansi class name";
3765 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3766 static const char unicode_class_nameA[] = "unicode class name";
3767 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3768 WNDCLASSA classA;
3769 WNDCLASSW classW;
3770 HWND hwnd;
3772 memset(&classW, 0, sizeof(classW));
3773 classW.hInstance = GetModuleHandleA(0);
3774 classW.lpfnWndProc = def_window_procW;
3775 classW.lpszClassName = unicode_class_nameW;
3776 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
3778 memset(&classA, 0, sizeof(classA));
3779 classA.hInstance = GetModuleHandleA(0);
3780 classA.lpfnWndProc = def_window_procA;
3781 classA.lpszClassName = ansi_class_nameA;
3782 assert(RegisterClassA(&classA));
3784 /* unicode class: window proc */
3785 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3786 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3787 assert(hwnd);
3789 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3790 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3791 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3792 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3793 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3795 DestroyWindow(hwnd);
3797 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3798 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3799 assert(hwnd);
3801 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3802 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3803 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3804 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3805 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3807 DestroyWindow(hwnd);
3809 /* ansi class: window proc */
3810 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3811 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3812 assert(hwnd);
3814 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3815 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3816 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3817 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3818 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3820 DestroyWindow(hwnd);
3822 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3823 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3824 assert(hwnd);
3826 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3827 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3828 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3829 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3830 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3832 DestroyWindow(hwnd);
3834 /* unicode class: class proc */
3835 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3836 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3837 assert(hwnd);
3839 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3840 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3841 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3842 /* do not restore class window proc back to unicode */
3844 DestroyWindow(hwnd);
3846 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3847 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3848 assert(hwnd);
3850 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3851 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
3852 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3854 DestroyWindow(hwnd);
3856 /* ansi class: class proc */
3857 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3858 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3859 assert(hwnd);
3861 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3862 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
3863 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3864 /* do not restore class window proc back to ansi */
3866 DestroyWindow(hwnd);
3868 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3869 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3870 assert(hwnd);
3872 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3873 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3874 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3876 DestroyWindow(hwnd);
3879 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
3881 MINMAXINFO *minmax;
3883 if (msg != WM_GETMINMAXINFO)
3884 return DefWindowProc(hwnd, msg, wp, lp);
3886 minmax = (MINMAXINFO *)lp;
3888 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
3890 minmax->ptReserved.x = 0;
3891 minmax->ptReserved.y = 0;
3892 minmax->ptMaxSize.x = 400;
3893 minmax->ptMaxSize.y = 400;
3894 minmax->ptMaxPosition.x = 300;
3895 minmax->ptMaxPosition.y = 300;
3896 minmax->ptMaxTrackSize.x = 200;
3897 minmax->ptMaxTrackSize.y = 200;
3898 minmax->ptMinTrackSize.x = 100;
3899 minmax->ptMinTrackSize.y = 100;
3901 else
3902 DefWindowProc(hwnd, msg, wp, lp);
3903 return 1;
3906 static int expected_cx, expected_cy;
3907 static RECT expected_rect;
3909 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
3911 switch(msg)
3913 case WM_GETMINMAXINFO:
3915 RECT rect;
3916 GetWindowRect( hwnd, &rect );
3917 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
3918 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
3919 return DefWindowProc(hwnd, msg, wp, lp);
3921 case WM_NCCREATE:
3922 case WM_CREATE:
3924 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
3925 RECT rect;
3926 GetWindowRect( hwnd, &rect );
3927 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
3928 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
3929 ok( cs->cx == expected_cx, "wrong x size %d/%d\n", cs->cx, expected_cx );
3930 ok( cs->cy == expected_cy, "wrong y size %d/%d\n", cs->cy, expected_cy );
3931 ok( rect.right - rect.left == expected_rect.right - expected_rect.left &&
3932 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top,
3933 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
3934 rect.left, rect.top, rect.right, rect.bottom,
3935 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
3936 return DefWindowProc(hwnd, msg, wp, lp);
3938 case WM_NCCALCSIZE:
3940 RECT rect, *r = (RECT *)lp;
3941 GetWindowRect( hwnd, &rect );
3942 ok( !memcmp( &rect, r, sizeof(rect) ),
3943 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
3944 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
3945 return DefWindowProc(hwnd, msg, wp, lp);
3947 default:
3948 return DefWindowProc(hwnd, msg, wp, lp);
3952 static void test_CreateWindow(void)
3954 WNDCLASS cls;
3955 HWND hwnd, parent;
3956 HMENU hmenu;
3957 RECT rc, rc_minmax;
3958 MINMAXINFO minmax;
3960 #define expect_menu(window, menu) \
3961 SetLastError(0xdeadbeef); \
3962 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
3964 #define expect_style(window, style)\
3965 ok(GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
3967 #define expect_ex_style(window, ex_style)\
3968 ok(GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
3970 hmenu = CreateMenu();
3971 assert(hmenu != 0);
3972 parent = GetDesktopWindow();
3973 assert(parent != 0);
3975 SetLastError(0xdeadbeef);
3976 ok(IsMenu(hmenu), "IsMenu error %d\n", GetLastError());
3978 /* WS_CHILD */
3979 SetLastError(0xdeadbeef);
3980 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
3981 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3982 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3983 expect_menu(hwnd, 1);
3984 expect_style(hwnd, WS_CHILD);
3985 expect_ex_style(hwnd, WS_EX_APPWINDOW);
3986 DestroyWindow(hwnd);
3988 SetLastError(0xdeadbeef);
3989 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
3990 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3991 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3992 expect_menu(hwnd, 1);
3993 expect_style(hwnd, WS_CHILD | WS_CAPTION);
3994 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
3995 DestroyWindow(hwnd);
3997 SetLastError(0xdeadbeef);
3998 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
3999 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4000 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4001 expect_menu(hwnd, 1);
4002 expect_style(hwnd, WS_CHILD);
4003 expect_ex_style(hwnd, 0);
4004 DestroyWindow(hwnd);
4006 SetLastError(0xdeadbeef);
4007 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
4008 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4009 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4010 expect_menu(hwnd, 1);
4011 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4012 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4013 DestroyWindow(hwnd);
4015 /* WS_POPUP */
4016 SetLastError(0xdeadbeef);
4017 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4018 0, 0, 100, 100, parent, hmenu, 0, NULL);
4019 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4020 expect_menu(hwnd, hmenu);
4021 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4022 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4023 DestroyWindow(hwnd);
4024 SetLastError(0xdeadbeef);
4025 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4026 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4028 hmenu = CreateMenu();
4029 assert(hmenu != 0);
4030 SetLastError(0xdeadbeef);
4031 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
4032 0, 0, 100, 100, parent, hmenu, 0, NULL);
4033 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4034 expect_menu(hwnd, hmenu);
4035 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4036 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4037 DestroyWindow(hwnd);
4038 SetLastError(0xdeadbeef);
4039 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4040 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4042 hmenu = CreateMenu();
4043 assert(hmenu != 0);
4044 SetLastError(0xdeadbeef);
4045 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
4046 0, 0, 100, 100, parent, hmenu, 0, NULL);
4047 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4048 expect_menu(hwnd, hmenu);
4049 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4050 expect_ex_style(hwnd, 0);
4051 DestroyWindow(hwnd);
4052 SetLastError(0xdeadbeef);
4053 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4054 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4056 hmenu = CreateMenu();
4057 assert(hmenu != 0);
4058 SetLastError(0xdeadbeef);
4059 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
4060 0, 0, 100, 100, parent, hmenu, 0, NULL);
4061 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4062 expect_menu(hwnd, hmenu);
4063 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4064 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4065 DestroyWindow(hwnd);
4066 SetLastError(0xdeadbeef);
4067 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4068 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4070 /* WS_CHILD | WS_POPUP */
4071 SetLastError(0xdeadbeef);
4072 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4073 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4074 ok(!hwnd, "CreateWindowEx should fail\n");
4075 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4077 hmenu = CreateMenu();
4078 assert(hmenu != 0);
4079 SetLastError(0xdeadbeef);
4080 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4081 0, 0, 100, 100, parent, hmenu, 0, NULL);
4082 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4083 expect_menu(hwnd, hmenu);
4084 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4085 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4086 DestroyWindow(hwnd);
4087 SetLastError(0xdeadbeef);
4088 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4089 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4091 SetLastError(0xdeadbeef);
4092 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4093 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4094 ok(!hwnd, "CreateWindowEx should fail\n");
4095 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4097 hmenu = CreateMenu();
4098 assert(hmenu != 0);
4099 SetLastError(0xdeadbeef);
4100 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4101 0, 0, 100, 100, parent, hmenu, 0, NULL);
4102 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4103 expect_menu(hwnd, hmenu);
4104 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4105 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4106 DestroyWindow(hwnd);
4107 SetLastError(0xdeadbeef);
4108 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4109 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4111 SetLastError(0xdeadbeef);
4112 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4113 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4114 ok(!hwnd, "CreateWindowEx should fail\n");
4115 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4117 hmenu = CreateMenu();
4118 assert(hmenu != 0);
4119 SetLastError(0xdeadbeef);
4120 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4121 0, 0, 100, 100, parent, hmenu, 0, NULL);
4122 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4123 expect_menu(hwnd, hmenu);
4124 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4125 expect_ex_style(hwnd, 0);
4126 DestroyWindow(hwnd);
4127 SetLastError(0xdeadbeef);
4128 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4129 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4131 SetLastError(0xdeadbeef);
4132 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4133 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4134 ok(!hwnd, "CreateWindowEx should fail\n");
4135 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4137 hmenu = CreateMenu();
4138 assert(hmenu != 0);
4139 SetLastError(0xdeadbeef);
4140 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4141 0, 0, 100, 100, parent, hmenu, 0, NULL);
4142 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4143 expect_menu(hwnd, hmenu);
4144 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4145 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4146 DestroyWindow(hwnd);
4147 SetLastError(0xdeadbeef);
4148 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4149 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4151 /* test child window sizing */
4152 cls.style = 0;
4153 cls.lpfnWndProc = minmax_wnd_proc;
4154 cls.cbClsExtra = 0;
4155 cls.cbWndExtra = 0;
4156 cls.hInstance = GetModuleHandle(0);
4157 cls.hIcon = 0;
4158 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
4159 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4160 cls.lpszMenuName = NULL;
4161 cls.lpszClassName = "MinMax_WndClass";
4162 RegisterClass(&cls);
4164 SetLastError(0xdeadbeef);
4165 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4166 0, 0, 100, 100, 0, 0, 0, NULL);
4167 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4168 expect_menu(parent, 0);
4169 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
4170 expect_ex_style(parent, WS_EX_WINDOWEDGE);
4172 memset(&minmax, 0, sizeof(minmax));
4173 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4174 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
4175 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
4176 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4177 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
4179 GetWindowRect(parent, &rc);
4180 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
4181 GetClientRect(parent, &rc);
4182 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
4184 InflateRect(&rc, 200, 200);
4185 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4187 SetLastError(0xdeadbeef);
4188 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4189 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
4190 parent, (HMENU)1, 0, NULL);
4191 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4192 expect_menu(hwnd, 1);
4193 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
4194 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4196 memset(&minmax, 0, sizeof(minmax));
4197 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4198 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4200 GetWindowRect(hwnd, &rc);
4201 OffsetRect(&rc, -rc.left, -rc.top);
4202 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4203 rc.left, rc.top, rc.right, rc.bottom,
4204 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
4205 DestroyWindow(hwnd);
4207 cls.lpfnWndProc = winsizes_wnd_proc;
4208 cls.lpszClassName = "Sizes_WndClass";
4209 RegisterClass(&cls);
4211 expected_cx = expected_cy = 200000;
4212 SetRect( &expected_rect, 0, 0, 200000, 200000 );
4213 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
4214 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4215 GetClientRect( hwnd, &rc );
4216 ok( rc.right == 200000, "invalid rect right %u\n", rc.right );
4217 ok( rc.bottom == 200000, "invalid rect bottom %u\n", rc.bottom );
4218 DestroyWindow(hwnd);
4220 expected_cx = expected_cy = -10;
4221 SetRect( &expected_rect, 0, 0, 0, 0 );
4222 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
4223 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4224 GetClientRect( hwnd, &rc );
4225 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4226 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4227 DestroyWindow(hwnd);
4229 expected_cx = expected_cy = -200000;
4230 SetRect( &expected_rect, 0, 0, 0, 0 );
4231 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
4232 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4233 GetClientRect( hwnd, &rc );
4234 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4235 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4236 DestroyWindow(hwnd);
4238 /* we need a parent at 0,0 so that child coordinates match */
4239 DestroyWindow(parent);
4240 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
4241 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4243 expected_cx = 100;
4244 expected_cy = 0x7fffffff;
4245 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
4246 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
4247 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4248 GetClientRect( hwnd, &rc );
4249 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
4250 ok( rc.bottom == 0x7fffffff - 10, "invalid rect bottom %u\n", rc.bottom );
4251 DestroyWindow(hwnd);
4253 expected_cx = 0x7fffffff;
4254 expected_cy = 0x7fffffff;
4255 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
4256 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
4257 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4258 GetClientRect( hwnd, &rc );
4259 ok( rc.right == 0x7fffffff - 20, "invalid rect right %u\n", rc.right );
4260 ok( rc.bottom == 0x7fffffff - 10, "invalid rect bottom %u\n", rc.bottom );
4261 DestroyWindow(hwnd);
4263 /* top level window */
4264 expected_cx = expected_cy = 200000;
4265 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
4266 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
4267 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4268 GetClientRect( hwnd, &rc );
4269 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
4270 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
4271 DestroyWindow(hwnd);
4273 DestroyWindow(parent);
4275 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4276 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4278 #undef expect_menu
4279 #undef expect_style
4280 #undef expect_ex_style
4283 /* function that remembers whether the system the test is running on sets the
4284 * last error for user32 functions to make the tests stricter */
4285 static int check_error(DWORD actual, DWORD expected)
4287 static int sets_last_error = -1;
4288 if (sets_last_error == -1)
4289 sets_last_error = (actual != 0xdeadbeef);
4290 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
4293 static void test_SetWindowLong(void)
4295 LONG_PTR retval;
4296 WNDPROC old_window_procW;
4298 SetLastError(0xdeadbeef);
4299 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
4300 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
4301 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
4302 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4304 SetLastError(0xdeadbeef);
4305 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
4306 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
4307 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
4308 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4310 SetLastError(0xdeadbeef);
4311 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4312 ok((WNDPROC)retval == main_window_procA,
4313 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
4314 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4315 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
4316 ok((WNDPROC)retval == main_window_procA,
4317 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4318 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
4320 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
4321 SetLastError(0xdeadbeef);
4322 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
4323 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
4325 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4326 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
4327 ok((WNDPROC)retval == old_window_procW,
4328 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4329 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
4331 /* set it back to ANSI */
4332 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4336 static void test_ShowWindow(void)
4338 HWND hwnd;
4339 DWORD style;
4340 RECT rcMain, rc;
4341 LPARAM ret;
4343 SetRect(&rcMain, 120, 120, 210, 210);
4345 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
4346 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4347 WS_MAXIMIZEBOX | WS_POPUP,
4348 rcMain.left, rcMain.top,
4349 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
4350 0, 0, 0, NULL);
4351 assert(hwnd);
4353 style = GetWindowLong(hwnd, GWL_STYLE);
4354 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4355 ok(!(style & WS_VISIBLE), "window should not be visible\n");
4356 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4357 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4358 GetWindowRect(hwnd, &rc);
4359 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4361 ret = ShowWindow(hwnd, SW_SHOW);
4362 ok(!ret, "not expected ret: %lu\n", ret);
4363 style = GetWindowLong(hwnd, GWL_STYLE);
4364 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4365 ok(style & WS_VISIBLE, "window should be visible\n");
4366 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4367 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4368 GetWindowRect(hwnd, &rc);
4369 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4371 ret = ShowWindow(hwnd, SW_MINIMIZE);
4372 ok(ret, "not expected ret: %lu\n", ret);
4373 style = GetWindowLong(hwnd, GWL_STYLE);
4374 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4375 ok(style & WS_VISIBLE, "window should be visible\n");
4376 ok(style & WS_MINIMIZE, "window should be minimized\n");
4377 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4378 GetWindowRect(hwnd, &rc);
4379 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4381 ShowWindow(hwnd, SW_RESTORE);
4382 ok(ret, "not expected ret: %lu\n", ret);
4383 style = GetWindowLong(hwnd, GWL_STYLE);
4384 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4385 ok(style & WS_VISIBLE, "window should be visible\n");
4386 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4387 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4388 GetWindowRect(hwnd, &rc);
4389 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4391 ret = EnableWindow(hwnd, FALSE);
4392 ok(!ret, "not expected ret: %lu\n", ret);
4393 style = GetWindowLong(hwnd, GWL_STYLE);
4394 ok(style & WS_DISABLED, "window should be disabled\n");
4396 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
4397 ok(!ret, "not expected ret: %lu\n", ret);
4398 style = GetWindowLong(hwnd, GWL_STYLE);
4399 ok(style & WS_DISABLED, "window should be disabled\n");
4400 ok(style & WS_VISIBLE, "window should be visible\n");
4401 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4402 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4403 GetWindowRect(hwnd, &rc);
4404 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4406 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
4407 ok(!ret, "not expected ret: %lu\n", ret);
4408 style = GetWindowLong(hwnd, GWL_STYLE);
4409 ok(style & WS_DISABLED, "window should be disabled\n");
4410 ok(style & WS_VISIBLE, "window should be visible\n");
4411 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4412 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4413 GetWindowRect(hwnd, &rc);
4414 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4416 ret = ShowWindow(hwnd, SW_MINIMIZE);
4417 ok(ret, "not expected ret: %lu\n", ret);
4418 style = GetWindowLong(hwnd, GWL_STYLE);
4419 ok(style & WS_DISABLED, "window should be disabled\n");
4420 ok(style & WS_VISIBLE, "window should be visible\n");
4421 ok(style & WS_MINIMIZE, "window should be minimized\n");
4422 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4423 GetWindowRect(hwnd, &rc);
4424 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4426 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
4427 ok(!ret, "not expected ret: %lu\n", ret);
4428 style = GetWindowLong(hwnd, GWL_STYLE);
4429 ok(style & WS_DISABLED, "window should be disabled\n");
4430 ok(style & WS_VISIBLE, "window should be visible\n");
4431 ok(style & WS_MINIMIZE, "window should be minimized\n");
4432 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4433 GetWindowRect(hwnd, &rc);
4434 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4436 ret = ShowWindow(hwnd, SW_RESTORE);
4437 ok(ret, "not expected ret: %lu\n", ret);
4438 style = GetWindowLong(hwnd, GWL_STYLE);
4439 ok(style & WS_DISABLED, "window should be disabled\n");
4440 ok(style & WS_VISIBLE, "window should be visible\n");
4441 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4442 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4443 GetWindowRect(hwnd, &rc);
4444 ok(EqualRect(&rcMain, &rc), "rects should match\n");
4446 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4447 ok(!ret, "not expected ret: %lu\n", ret);
4448 ok(IsWindow(hwnd), "window should exist\n");
4450 ret = EnableWindow(hwnd, TRUE);
4451 ok(ret, "not expected ret: %lu\n", ret);
4453 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4454 ok(!ret, "not expected ret: %lu\n", ret);
4455 ok(!IsWindow(hwnd), "window should not exist\n");
4458 static void test_gettext(void)
4460 WNDCLASS cls;
4461 LPCSTR clsname = "gettexttest";
4462 HWND hwnd;
4463 LRESULT r;
4465 memset( &cls, 0, sizeof cls );
4466 cls.lpfnWndProc = DefWindowProc;
4467 cls.lpszClassName = clsname;
4468 cls.hInstance = GetModuleHandle(NULL);
4470 if (!RegisterClass( &cls )) return;
4472 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
4473 ok( hwnd != NULL, "window was null\n");
4475 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
4476 ok( r == 0, "settext should return zero\n");
4478 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
4479 ok( r == 0, "settext should return zero (%ld)\n", r);
4481 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
4482 ok( r == 0, "settext should return zero (%ld)\n", r);
4484 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
4485 ok( r == 0, "settext should return zero (%ld)\n", r);
4487 DestroyWindow(hwnd);
4488 UnregisterClass( clsname, NULL );
4492 static void test_GetUpdateRect(void)
4494 MSG msg;
4495 BOOL ret, parent_wm_paint, grandparent_wm_paint;
4496 RECT rc1, rc2;
4497 HWND hgrandparent, hparent, hchild;
4498 WNDCLASSA cls;
4499 static const char classNameA[] = "GetUpdateRectClass";
4501 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
4502 0, 0, 100, 100, NULL, NULL, 0, NULL);
4504 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
4505 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4507 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
4508 10, 10, 30, 30, hparent, NULL, 0, NULL);
4510 ShowWindow(hgrandparent, SW_SHOW);
4511 UpdateWindow(hgrandparent);
4512 flush_events( TRUE );
4514 ShowWindow(hchild, SW_HIDE);
4515 SetRect(&rc2, 0, 0, 0, 0);
4516 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4517 ok(!ret, "GetUpdateRect returned not empty region\n");
4518 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4519 rc1.left, rc1.top, rc1.right, rc1.bottom,
4520 rc2.left, rc2.top, rc2.right, rc2.bottom);
4522 SetRect(&rc2, 10, 10, 40, 40);
4523 ret = GetUpdateRect(hparent, &rc1, FALSE);
4524 ok(ret, "GetUpdateRect returned empty region\n");
4525 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4526 rc1.left, rc1.top, rc1.right, rc1.bottom,
4527 rc2.left, rc2.top, rc2.right, rc2.bottom);
4529 parent_wm_paint = FALSE;
4530 grandparent_wm_paint = FALSE;
4531 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4533 if (msg.message == WM_PAINT)
4535 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4536 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4538 DispatchMessage(&msg);
4540 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4541 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4543 DestroyWindow(hgrandparent);
4545 cls.style = 0;
4546 cls.lpfnWndProc = DefWindowProcA;
4547 cls.cbClsExtra = 0;
4548 cls.cbWndExtra = 0;
4549 cls.hInstance = GetModuleHandleA(0);
4550 cls.hIcon = 0;
4551 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
4552 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4553 cls.lpszMenuName = NULL;
4554 cls.lpszClassName = classNameA;
4556 if(!RegisterClassA(&cls)) {
4557 trace("Register failed %d\n", GetLastError());
4558 return;
4561 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
4562 0, 0, 100, 100, NULL, NULL, 0, NULL);
4564 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
4565 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4567 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
4568 10, 10, 30, 30, hparent, NULL, 0, NULL);
4570 ShowWindow(hgrandparent, SW_SHOW);
4571 UpdateWindow(hgrandparent);
4572 flush_events( TRUE );
4574 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4575 ok(!ret, "GetUpdateRect returned not empty region\n");
4577 ShowWindow(hchild, SW_HIDE);
4579 SetRect(&rc2, 0, 0, 0, 0);
4580 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4581 ok(!ret, "GetUpdateRect returned not empty region\n");
4582 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4583 rc1.left, rc1.top, rc1.right, rc1.bottom,
4584 rc2.left, rc2.top, rc2.right, rc2.bottom);
4586 SetRect(&rc2, 10, 10, 40, 40);
4587 ret = GetUpdateRect(hparent, &rc1, FALSE);
4588 ok(ret, "GetUpdateRect returned empty region\n");
4589 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4590 rc1.left, rc1.top, rc1.right, rc1.bottom,
4591 rc2.left, rc2.top, rc2.right, rc2.bottom);
4593 parent_wm_paint = FALSE;
4594 grandparent_wm_paint = FALSE;
4595 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4597 if (msg.message == WM_PAINT)
4599 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4600 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4602 DispatchMessage(&msg);
4604 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4605 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4607 DestroyWindow(hgrandparent);
4611 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
4613 if(msg == WM_PAINT)
4615 PAINTSTRUCT ps;
4616 RECT updateRect;
4617 DWORD waitResult;
4618 HWND win;
4619 const int waitTime = 2000;
4621 BeginPaint(hwnd, &ps);
4623 /* create and destroy window to create an exposed region on this window */
4624 win = CreateWindowA("static", "win", WS_VISIBLE,
4625 10,10,50,50, NULL, NULL, 0, NULL);
4626 DestroyWindow(win);
4628 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
4630 ValidateRect(hwnd, NULL);
4631 EndPaint(hwnd, &ps);
4633 if(waitResult != WAIT_TIMEOUT)
4635 GetUpdateRect(hwnd, &updateRect, FALSE);
4636 todo_wine
4638 ok(!IsRectEmpty(&updateRect), "Exposed rect should not be empty\n");
4642 return 1;
4644 return DefWindowProc(hwnd, msg, wParam, lParam);
4647 static void test_Expose(void)
4649 ATOM atom;
4650 WNDCLASSA cls;
4651 HWND mw;
4652 memset(&cls, 0, sizeof(WNDCLASSA));
4653 cls.lpfnWndProc = TestExposedRegion_WndProc;
4654 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4655 cls.lpszClassName = "TestExposeClass";
4656 atom = RegisterClassA(&cls);
4658 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
4659 0, 0, 200, 100, NULL, NULL, 0, NULL);
4661 UpdateWindow(mw);
4662 DestroyWindow(mw);
4665 static void test_GetWindowModuleFileName(void)
4667 HWND hwnd;
4668 HINSTANCE hinst;
4669 UINT ret1, ret2;
4670 char buf1[MAX_PATH], buf2[MAX_PATH];
4672 if (!pGetWindowModuleFileNameA)
4674 skip("GetWindowModuleFileNameA is not available\n");
4675 return;
4678 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
4679 assert(hwnd);
4681 hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
4682 ok(hinst == 0, "expected 0, got %p\n", hinst);
4684 buf1[0] = 0;
4685 SetLastError(0xdeadbeef);
4686 ret1 = GetModuleFileName(hinst, buf1, sizeof(buf1));
4687 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
4689 buf2[0] = 0;
4690 SetLastError(0xdeadbeef);
4691 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
4692 ok(ret2, "GetWindowModuleFileNameA error %u\n", GetLastError());
4694 ok(ret1 == ret2, "%u != %u\n", ret1, ret2);
4695 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
4697 hinst = GetModuleHandle(0);
4699 SetLastError(0xdeadbeef);
4700 ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
4701 ok(ret2 == ret1 - 2, "expected %u, got %u\n", ret1 - 2, ret2);
4702 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4703 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4704 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4706 SetLastError(0xdeadbeef);
4707 ret2 = GetModuleFileName(hinst, buf2, 0);
4708 ok(!ret2, "GetModuleFileName should return 0\n");
4709 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4710 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4711 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4713 SetLastError(0xdeadbeef);
4714 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
4715 ok(ret2 == ret1 - 2, "expected %u, got %u\n", ret1 - 2, ret2);
4716 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4717 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4718 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4720 SetLastError(0xdeadbeef);
4721 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
4722 ok(!ret2, "expected 0, got %u\n", ret2);
4723 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4724 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4725 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4727 DestroyWindow(hwnd);
4729 buf2[0] = 0;
4730 hwnd = (HWND)0xdeadbeef;
4731 SetLastError(0xdeadbeef);
4732 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4733 ok(!ret1, "expected 0, got %u\n", ret1);
4734 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
4736 hwnd = GetDesktopWindow();
4737 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
4738 SetLastError(0xdeadbeef);
4739 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4740 ok(!ret1, "expected 0, got %u\n", ret1);
4742 hwnd = FindWindow("Shell_TrayWnd", NULL);
4743 ok(IsWindow(hwnd), "got invalid tray window %p\n", hwnd);
4744 SetLastError(0xdeadbeef);
4745 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4746 ok(!ret1, "expected 0, got %u\n", ret1);
4749 static void test_hwnd_message(void)
4751 HWND parent = 0, hwnd, found;
4752 RECT rect;
4754 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION | WS_VISIBLE,
4755 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
4756 if (!hwnd)
4758 win_skip("CreateWindowExA with parent HWND_MESSAGE failed\n");
4759 return;
4762 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
4763 if (pGetAncestor)
4765 char buffer[100];
4766 HWND root, desktop = GetDesktopWindow();
4768 parent = pGetAncestor(hwnd, GA_PARENT);
4769 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
4770 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
4771 root = pGetAncestor(hwnd, GA_ROOT);
4772 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
4773 ok( !pGetAncestor(parent, GA_PARENT), "parent shouldn't have a parent\n" );
4774 trace("parent %p root %p desktop %p\n", parent, root, desktop);
4775 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
4776 ok( !lstrcmpi( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
4777 GetWindowRect( parent, &rect );
4778 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
4779 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4781 GetWindowRect( hwnd, &rect );
4782 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
4783 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4785 /* test FindWindow behavior */
4787 found = FindWindowExA( 0, 0, 0, "message window" );
4788 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
4789 SetLastError(0xdeadbeef);
4790 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
4791 ok( found == 0, "found message window %p/%p\n", found, hwnd );
4792 todo_wine
4793 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
4794 if (parent)
4796 found = FindWindowExA( parent, 0, 0, "message window" );
4797 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
4800 /* test IsChild behavior */
4802 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
4804 /* test IsWindowVisible behavior */
4806 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
4807 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
4809 DestroyWindow(hwnd);
4812 START_TEST(win)
4814 pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
4815 pGetWindowInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
4816 pGetWindowModuleFileNameA = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowModuleFileNameA" );
4818 if (!RegisterWindowClasses()) assert(0);
4820 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
4821 assert(hhook);
4823 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
4824 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4825 WS_MAXIMIZEBOX | WS_POPUP,
4826 100, 100, 200, 200,
4827 0, 0, GetModuleHandle(0), NULL);
4828 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
4829 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4830 WS_MAXIMIZEBOX | WS_POPUP,
4831 100, 100, 200, 200,
4832 0, 0, GetModuleHandle(0), NULL);
4833 assert( hwndMain );
4834 assert( hwndMain2 );
4836 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
4838 /* Add the tests below this line */
4839 test_hwnd_message();
4840 test_nonclient_area(hwndMain);
4841 test_params();
4842 test_GetWindowModuleFileName();
4843 test_capture_1();
4844 test_capture_2();
4845 test_capture_3(hwndMain, hwndMain2);
4847 test_CreateWindow();
4848 test_parent_owner();
4849 test_SetParent();
4850 test_shell_window();
4852 test_mdi();
4853 test_icons();
4854 test_SetWindowPos(hwndMain);
4855 test_SetMenu(hwndMain);
4856 test_SetFocus(hwndMain);
4857 test_SetActiveWindow(hwndMain);
4858 test_SetForegroundWindow(hwndMain);
4860 test_children_zorder(hwndMain);
4861 test_popup_zorder(hwndMain2, hwndMain);
4862 test_keyboard_input(hwndMain);
4863 test_mouse_input(hwndMain);
4864 test_validatergn(hwndMain);
4865 test_nccalcscroll( hwndMain);
4866 test_scrollvalidate( hwndMain);
4867 test_scrolldc( hwndMain);
4868 test_scroll();
4869 test_IsWindowUnicode();
4870 test_vis_rgn(hwndMain);
4872 test_AdjustWindowRect();
4873 test_window_styles();
4874 test_redrawnow();
4875 test_csparentdc();
4876 test_SetWindowLong();
4877 test_ShowWindow();
4878 test_gettext();
4879 test_GetUpdateRect();
4880 test_Expose();
4882 /* add the tests above this line */
4883 UnhookWindowsHookEx(hhook);