push 52cba0a224aad01bcbdb26d79e43229ba950650e
[wine/hacks.git] / dlls / user32 / tests / win.c
blob13e5d67e4c14c062bb0f009d5e3bf530dda5b96e
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);
50 static BOOL (WINAPI *pGetLayeredWindowAttributes)(HWND,COLORREF*,BYTE*,DWORD*);
51 static BOOL (WINAPI *pSetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD);
52 static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
53 static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
54 static int (WINAPI *pGetWindowRgnBox)(HWND,LPRECT);
56 static BOOL test_lbuttondown_flag;
57 static HWND hwndMessage;
58 static HWND hwndMain, hwndMain2;
59 static HHOOK hhook;
61 static const char* szAWRClass = "Winsize";
62 static HMENU hmenu;
63 static DWORD our_pid;
65 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
67 static void dump_minmax_info( const MINMAXINFO *minmax )
69 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
70 minmax->ptReserved.x, minmax->ptReserved.y,
71 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
72 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
73 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
74 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
77 /* try to make sure pending X events have been processed before continuing */
78 static void flush_events( BOOL remove_messages )
80 MSG msg;
81 int diff = 200;
82 int min_timeout = 100;
83 DWORD time = GetTickCount() + diff;
85 while (diff > 0)
87 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
88 if (remove_messages)
89 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
90 diff = time - GetTickCount();
91 min_timeout = 50;
95 /* check the values returned by the various parent/owner functions on a given window */
96 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
97 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
99 HWND res;
101 if (pGetAncestor)
103 res = pGetAncestor( hwnd, GA_PARENT );
104 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
106 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
107 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
108 res = GetParent( hwnd );
109 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
110 res = GetWindow( hwnd, GW_OWNER );
111 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
112 if (pGetAncestor)
114 res = pGetAncestor( hwnd, GA_ROOT );
115 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
116 res = pGetAncestor( hwnd, GA_ROOTOWNER );
117 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
121 static BOOL ignore_message( UINT message )
123 /* these are always ignored */
124 return (message >= 0xc000 ||
125 message == WM_GETICON ||
126 message == WM_GETOBJECT ||
127 message == WM_TIMECHANGE ||
128 message == WM_DEVICECHANGE);
131 static BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
133 (*(LPINT)lParam)++;
134 trace("EnumChildProc on %p\n", hwndChild);
135 if (*(LPINT)lParam > 1) return FALSE;
136 return TRUE;
139 /* will search for the given window */
140 static BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
142 trace("EnumChildProc1 on %p\n", hwndChild);
143 if ((HWND)lParam == hwndChild) return FALSE;
144 return TRUE;
147 static HWND create_tool_window( LONG style, HWND parent )
149 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
150 0, 0, 100, 100, parent, 0, 0, NULL );
151 ok( ret != 0, "Creation failed\n" );
152 return ret;
155 /* test parent and owner values for various combinations */
156 static void test_parent_owner(void)
158 LONG style;
159 HWND test, owner, ret;
160 HWND desktop = GetDesktopWindow();
161 HWND child = create_tool_window( WS_CHILD, hwndMain );
162 INT numChildren;
164 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
166 /* child without parent, should fail */
167 SetLastError(0xdeadbeef);
168 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
169 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
170 ok( !test, "WS_CHILD without parent created\n" );
171 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD ||
172 broken(GetLastError() == 0xdeadbeef), /* win9x */
173 "CreateWindowExA error %u\n", GetLastError() );
175 /* desktop window */
176 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
177 style = GetWindowLongA( desktop, GWL_STYLE );
178 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
179 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
180 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
182 /* normal child window */
183 test = create_tool_window( WS_CHILD, hwndMain );
184 trace( "created child %p\n", test );
185 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
186 SetWindowLongA( test, GWL_STYLE, 0 );
187 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
188 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
189 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
190 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
191 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
192 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
193 DestroyWindow( test );
195 /* normal child window with WS_MAXIMIZE */
196 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
197 DestroyWindow( test );
199 /* normal child window with WS_THICKFRAME */
200 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
201 DestroyWindow( test );
203 /* popup window with WS_THICKFRAME */
204 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
205 DestroyWindow( test );
207 /* child of desktop */
208 test = create_tool_window( WS_CHILD, desktop );
209 trace( "created child of desktop %p\n", test );
210 check_parents( test, desktop, 0, desktop, 0, test, desktop );
211 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
212 check_parents( test, desktop, 0, 0, 0, test, test );
213 SetWindowLongA( test, GWL_STYLE, 0 );
214 check_parents( test, desktop, 0, 0, 0, test, test );
215 DestroyWindow( test );
217 /* child of desktop with WS_MAXIMIZE */
218 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
219 DestroyWindow( test );
221 /* child of desktop with WS_MINIMIZE */
222 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
223 DestroyWindow( test );
225 /* child of child */
226 test = create_tool_window( WS_CHILD, child );
227 trace( "created child of child %p\n", test );
228 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
229 SetWindowLongA( test, GWL_STYLE, 0 );
230 check_parents( test, child, child, 0, 0, hwndMain, test );
231 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
232 check_parents( test, child, child, 0, 0, hwndMain, test );
233 DestroyWindow( test );
235 /* child of child with WS_MAXIMIZE */
236 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
237 DestroyWindow( test );
239 /* child of child with WS_MINIMIZE */
240 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
241 DestroyWindow( test );
243 /* not owned top-level window */
244 test = create_tool_window( 0, 0 );
245 trace( "created top-level %p\n", test );
246 check_parents( test, desktop, 0, 0, 0, test, test );
247 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
248 check_parents( test, desktop, 0, 0, 0, test, test );
249 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
250 check_parents( test, desktop, 0, desktop, 0, test, desktop );
251 DestroyWindow( test );
253 /* not owned top-level window with WS_MAXIMIZE */
254 test = create_tool_window( WS_MAXIMIZE, 0 );
255 DestroyWindow( test );
257 /* owned top-level window */
258 test = create_tool_window( 0, hwndMain );
259 trace( "created owned top-level %p\n", test );
260 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
261 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
262 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
263 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
264 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
265 DestroyWindow( test );
267 /* owned top-level window with WS_MAXIMIZE */
268 test = create_tool_window( WS_MAXIMIZE, hwndMain );
269 DestroyWindow( test );
271 /* not owned popup */
272 test = create_tool_window( WS_POPUP, 0 );
273 trace( "created popup %p\n", test );
274 check_parents( test, desktop, 0, 0, 0, test, test );
275 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
276 check_parents( test, desktop, 0, desktop, 0, test, desktop );
277 SetWindowLongA( test, GWL_STYLE, 0 );
278 check_parents( test, desktop, 0, 0, 0, test, test );
279 DestroyWindow( test );
281 /* not owned popup with WS_MAXIMIZE */
282 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
283 DestroyWindow( test );
285 /* owned popup */
286 test = create_tool_window( WS_POPUP, hwndMain );
287 trace( "created owned popup %p\n", test );
288 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
289 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
290 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
291 SetWindowLongA( test, GWL_STYLE, 0 );
292 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
293 DestroyWindow( test );
295 /* owned popup with WS_MAXIMIZE */
296 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
297 DestroyWindow( test );
299 /* top-level window owned by child (same as owned by top-level) */
300 test = create_tool_window( 0, child );
301 trace( "created top-level owned by child %p\n", test );
302 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
303 DestroyWindow( test );
305 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
306 test = create_tool_window( WS_MAXIMIZE, child );
307 DestroyWindow( test );
309 /* popup owned by desktop (same as not owned) */
310 test = create_tool_window( WS_POPUP, desktop );
311 trace( "created popup owned by desktop %p\n", test );
312 check_parents( test, desktop, 0, 0, 0, test, test );
313 DestroyWindow( test );
315 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
316 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
317 DestroyWindow( test );
319 /* popup owned by child (same as owned by top-level) */
320 test = create_tool_window( WS_POPUP, child );
321 trace( "created popup owned by child %p\n", test );
322 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
323 DestroyWindow( test );
325 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
326 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
327 DestroyWindow( test );
329 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
330 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
331 trace( "created WS_CHILD popup %p\n", test );
332 check_parents( test, desktop, 0, 0, 0, test, test );
333 DestroyWindow( test );
335 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
336 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
337 DestroyWindow( test );
339 /* owned popup with WS_CHILD (same as WS_POPUP only) */
340 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
341 trace( "created owned WS_CHILD popup %p\n", test );
342 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
343 DestroyWindow( test );
345 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
346 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
347 DestroyWindow( test );
349 /******************** parent changes *************************/
350 trace( "testing parent changes\n" );
352 /* desktop window */
353 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
354 if (0)
356 /* this test succeeds on NT but crashes on win9x systems */
357 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
358 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
359 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
360 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
361 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
363 /* normal child window */
364 test = create_tool_window( WS_CHILD, hwndMain );
365 trace( "created child %p\n", test );
367 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
368 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
369 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
371 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
372 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
373 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
375 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
376 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
377 check_parents( test, desktop, 0, desktop, 0, test, desktop );
379 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
380 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
381 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
382 check_parents( test, desktop, child, desktop, child, test, desktop );
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, desktop, 0, test, desktop );
387 DestroyWindow( test );
389 /* not owned top-level window */
390 test = create_tool_window( 0, 0 );
391 trace( "created top-level %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, 0, hwndMain2, test, test );
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, 0, child, test, test );
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 /* not owned popup */
407 test = create_tool_window( WS_POPUP, 0 );
408 trace( "created popup %p\n", test );
410 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
411 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
412 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
414 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
415 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
416 check_parents( test, desktop, child, child, child, test, hwndMain );
418 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
419 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
420 check_parents( test, desktop, 0, 0, 0, test, test );
421 DestroyWindow( test );
423 /* normal child window */
424 test = create_tool_window( WS_CHILD, hwndMain );
425 trace( "created child %p\n", test );
427 ret = SetParent( test, desktop );
428 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
429 check_parents( test, desktop, 0, desktop, 0, test, desktop );
431 ret = SetParent( test, child );
432 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
433 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
435 ret = SetParent( test, hwndMain2 );
436 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
437 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
438 DestroyWindow( test );
440 /* not owned top-level window */
441 test = create_tool_window( 0, 0 );
442 trace( "created top-level %p\n", test );
444 ret = SetParent( test, child );
445 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
446 check_parents( test, child, child, 0, 0, hwndMain, test );
447 DestroyWindow( test );
449 /* owned popup */
450 test = create_tool_window( WS_POPUP, hwndMain2 );
451 trace( "created owned popup %p\n", test );
453 ret = SetParent( test, child );
454 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
455 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
457 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
458 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
459 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
460 DestroyWindow( test );
462 /**************** test owner destruction *******************/
464 /* owned child 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 ret = SetParent( test, child );
469 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
470 check_parents( test, child, child, owner, owner, hwndMain, owner );
471 /* window is now child of 'child' but owned by 'owner' */
472 DestroyWindow( owner );
473 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
474 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
475 * while Win95, Win2k, WinXP do.
477 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
478 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
479 DestroyWindow(test);
481 /* owned top-level popup */
482 owner = create_tool_window( 0, 0 );
483 test = create_tool_window( WS_POPUP, owner );
484 trace( "created owner %p and popup %p\n", owner, test );
485 check_parents( test, desktop, owner, owner, owner, test, owner );
486 DestroyWindow( owner );
487 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
489 /* top-level popup owned by child */
490 owner = create_tool_window( WS_CHILD, hwndMain2 );
491 test = create_tool_window( WS_POPUP, 0 );
492 trace( "created owner %p and popup %p\n", owner, test );
493 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
494 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
495 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
496 DestroyWindow( owner );
497 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
498 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
499 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
500 * while Win95, Win2k, WinXP do.
502 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
503 DestroyWindow(test);
505 /* final cleanup */
506 DestroyWindow(child);
509 owner = create_tool_window( WS_OVERLAPPED, 0 );
510 test = create_tool_window( WS_POPUP, desktop );
512 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
513 numChildren = 0;
514 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
515 "EnumChildWindows should have returned FALSE\n" );
516 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
518 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
519 ret = SetParent( test, owner );
520 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
522 numChildren = 0;
523 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
524 "EnumChildWindows should have returned TRUE\n" );
525 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
527 child = create_tool_window( WS_CHILD, owner );
528 numChildren = 0;
529 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
530 "EnumChildWindows should have returned FALSE\n" );
531 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
532 DestroyWindow( child );
534 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
535 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
536 numChildren = 0;
537 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
538 "EnumChildWindows should have returned TRUE\n" );
539 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
541 ret = SetParent( child, owner );
542 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
543 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
544 numChildren = 0;
545 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
546 "EnumChildWindows should have returned FALSE\n" );
547 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
549 ret = SetParent( child, NULL );
550 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
551 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
552 numChildren = 0;
553 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
554 "EnumChildWindows should have returned TRUE\n" );
555 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
557 /* even GW_OWNER == owner it's still a desktop's child */
558 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
559 "EnumChildWindows should have found %p and returned FALSE\n", child );
561 DestroyWindow( child );
562 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
564 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
565 "EnumChildWindows should have found %p and returned FALSE\n", child );
567 DestroyWindow( child );
568 DestroyWindow( test );
569 DestroyWindow( owner );
573 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
575 switch (msg)
577 case WM_GETMINMAXINFO:
579 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
581 trace("WM_GETMINMAXINFO: hwnd %p, %08lx, %08lx\n", hwnd, wparam, lparam);
582 dump_minmax_info( minmax );
583 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
584 break;
586 case WM_WINDOWPOSCHANGING:
588 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
589 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
590 trace("main: WM_WINDOWPOSCHANGING %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
591 winpos->hwnd, winpos->hwndInsertAfter,
592 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
593 if (!(winpos->flags & SWP_NOMOVE))
595 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
596 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
598 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
599 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
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 break;
606 case WM_WINDOWPOSCHANGED:
608 RECT rc1, rc2;
609 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
610 trace("main: WM_WINDOWPOSCHANGED %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
611 winpos->hwnd, winpos->hwndInsertAfter,
612 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
613 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
614 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
616 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
617 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
619 GetWindowRect(hwnd, &rc1);
620 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
621 /* note: winpos coordinates are relative to parent */
622 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
623 if (0)
625 /* Uncomment this once the test succeeds in all cases */
626 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
627 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
629 GetClientRect(hwnd, &rc2);
630 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
631 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
632 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
633 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
635 break;
637 case WM_NCCREATE:
639 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
640 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
642 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
643 if (got_getminmaxinfo)
644 trace("%p got WM_GETMINMAXINFO\n", hwnd);
646 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
647 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
648 else
649 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
650 break;
652 case WM_COMMAND:
653 if (test_lbuttondown_flag)
655 ShowWindow((HWND)wparam, SW_SHOW);
656 flush_events( FALSE );
658 break;
661 return DefWindowProcA(hwnd, msg, wparam, lparam);
664 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
666 switch (msg)
668 case WM_GETMINMAXINFO:
670 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
672 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
673 dump_minmax_info( minmax );
674 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
675 break;
677 case WM_NCCREATE:
679 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
680 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
682 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
683 if (got_getminmaxinfo)
684 trace("%p got WM_GETMINMAXINFO\n", hwnd);
686 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
687 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
688 else
689 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
690 break;
694 return DefWindowProcA(hwnd, msg, wparam, lparam);
697 static BOOL RegisterWindowClasses(void)
699 WNDCLASSA cls;
701 cls.style = CS_DBLCLKS;
702 cls.lpfnWndProc = main_window_procA;
703 cls.cbClsExtra = 0;
704 cls.cbWndExtra = 0;
705 cls.hInstance = GetModuleHandleA(0);
706 cls.hIcon = 0;
707 cls.hCursor = LoadCursorA(0, IDC_ARROW);
708 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
709 cls.lpszMenuName = NULL;
710 cls.lpszClassName = "MainWindowClass";
712 if(!RegisterClassA(&cls)) return FALSE;
714 cls.style = 0;
715 cls.lpfnWndProc = tool_window_procA;
716 cls.cbClsExtra = 0;
717 cls.cbWndExtra = 0;
718 cls.hInstance = GetModuleHandleA(0);
719 cls.hIcon = 0;
720 cls.hCursor = LoadCursorA(0, IDC_ARROW);
721 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
722 cls.lpszMenuName = NULL;
723 cls.lpszClassName = "ToolWindowClass";
725 if(!RegisterClassA(&cls)) return FALSE;
727 return TRUE;
730 static void verify_window_info(const char *hook, HWND hwnd, const WINDOWINFO *info)
732 RECT rcWindow, rcClient;
733 DWORD status;
735 ok(IsWindow(hwnd), "bad window handle %p in hook %s\n", hwnd, hook);
737 GetWindowRect(hwnd, &rcWindow);
738 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow for %p in hook %s\n", hwnd, hook);
740 GetClientRect(hwnd, &rcClient);
741 /* translate to screen coordinates */
742 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
743 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient for %p in hook %s\n", hwnd, hook);
745 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
746 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
747 info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE), hwnd, hook);
748 /* Windows reports some undocumented exstyles in WINDOWINFO, but
749 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
751 ok((info->dwExStyle & ~0xe0000800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
752 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
753 info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE), hwnd, hook);
754 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
755 if (GetForegroundWindow())
756 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
757 info->dwWindowStatus, status, GetActiveWindow(), GetForegroundWindow(), hook);
759 /* win2k and XP return broken border info in GetWindowInfo most of
760 * the time, so there is no point in testing it.
762 #if 0
763 UINT border;
764 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
765 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
766 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
767 ok(info->cyWindowBorders == border,
768 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
769 #endif
770 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType for %p in hook %s\n",
771 hwnd, hook);
772 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
773 info->wCreatorVersion == 0x0500 /* Vista */,
774 "wrong wCreatorVersion %04x for %p in hook %s\n", info->wCreatorVersion, hwnd, hook);
777 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
779 AdjustWindowRectEx(rc, style, menu, exstyle);
780 /* AdjustWindowRectEx does not include scroll bars */
781 if (style & WS_VSCROLL)
783 if(exstyle & WS_EX_LEFTSCROLLBAR)
784 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
785 else
786 rc->right += GetSystemMetrics(SM_CXVSCROLL);
788 if (style & WS_HSCROLL)
789 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
792 static void test_nonclient_area(HWND hwnd)
794 DWORD style, exstyle;
795 RECT rc_window, rc_client, rc;
796 BOOL menu;
797 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
798 LRESULT ret;
800 style = GetWindowLongA(hwnd, GWL_STYLE);
801 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
802 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
804 GetWindowRect(hwnd, &rc_window);
805 GetClientRect(hwnd, &rc_client);
807 /* avoid some cases when things go wrong */
808 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
809 rc_window.right > 32768 || rc_window.bottom > 32768) return;
811 CopyRect(&rc, &rc_client);
812 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
813 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
815 ok(EqualRect(&rc, &rc_window),
816 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
817 style, exstyle, menu, rc_window.left, rc_window.top, rc_window.right, rc_window.bottom,
818 rc.left, rc.top, rc.right, rc.bottom);
821 CopyRect(&rc, &rc_window);
822 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
823 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
824 ok(EqualRect(&rc, &rc_client),
825 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
826 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
827 rc.left, rc.top, rc.right, rc.bottom);
829 /* NULL rectangle shouldn't crash */
830 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
831 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
833 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
834 if (is_win9x)
835 return;
837 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
838 SetRect(&rc_client, 0, 0, 250, 150);
839 CopyRect(&rc_window, &rc_client);
840 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
841 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
843 CopyRect(&rc, &rc_window);
844 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
845 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
846 ok(EqualRect(&rc, &rc_client),
847 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
848 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
849 rc.left, rc.top, rc.right, rc.bottom);
852 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
854 static const char *CBT_code_name[10] = {
855 "HCBT_MOVESIZE",
856 "HCBT_MINMAX",
857 "HCBT_QS",
858 "HCBT_CREATEWND",
859 "HCBT_DESTROYWND",
860 "HCBT_ACTIVATE",
861 "HCBT_CLICKSKIPPED",
862 "HCBT_KEYSKIPPED",
863 "HCBT_SYSCOMMAND",
864 "HCBT_SETFOCUS" };
865 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
866 HWND hwnd = (HWND)wParam;
868 switch (nCode)
870 case HCBT_CREATEWND:
872 static const RECT rc_null;
873 RECT rc;
874 LONG style;
875 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
876 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
877 hwnd, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
878 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
880 if (pGetWindowInfo)
882 WINDOWINFO info;
883 info.cbSize = sizeof(WINDOWINFO);
884 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
885 verify_window_info(code_name, hwnd, &info);
888 /* WS_VISIBLE should be turned off yet */
889 style = createwnd->lpcs->style & ~WS_VISIBLE;
890 ok(style == GetWindowLongA(hwnd, GWL_STYLE),
891 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
892 GetWindowLongA(hwnd, GWL_STYLE), style);
894 if (0)
896 /* Uncomment this once the test succeeds in all cases */
897 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
899 ok(GetParent(hwnd) == hwndMessage,
900 "wrong result from GetParent %p: message window %p\n",
901 GetParent(hwnd), hwndMessage);
903 else
904 ok(!GetParent(hwnd), "GetParent should return 0 at this point\n");
906 ok(!GetWindow(hwnd, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
908 if (0)
910 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
911 * Win9x still has them set to 0.
913 ok(GetWindow(hwnd, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
914 ok(GetWindow(hwnd, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
916 ok(!GetWindow(hwnd, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
917 ok(!GetWindow(hwnd, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
919 if (0)
921 /* Uncomment this once the test succeeds in all cases */
922 if (pGetAncestor)
924 ok(pGetAncestor(hwnd, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
925 ok(pGetAncestor(hwnd, GA_ROOT) == hwnd,
926 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOT), hwnd);
928 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
929 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwndMessage,
930 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
931 else
932 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwnd,
933 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOTOWNER), hwnd);
936 ok(GetWindowRect(hwnd, &rc), "GetWindowRect failed\n");
937 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
938 ok(GetClientRect(hwnd, &rc), "GetClientRect failed\n");
939 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
941 break;
943 case HCBT_MOVESIZE:
944 case HCBT_MINMAX:
945 case HCBT_ACTIVATE:
946 case HCBT_SETFOCUS:
947 if (pGetWindowInfo && IsWindow(hwnd))
949 WINDOWINFO info;
951 /* Win98 actually does check the info.cbSize and doesn't allow
952 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
953 * WinXP do not check it at all.
955 info.cbSize = sizeof(WINDOWINFO);
956 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
957 verify_window_info(code_name, hwnd, &info);
959 break;
960 /* on HCBT_DESTROYWND window state is undefined */
961 case HCBT_DESTROYWND:
962 trace( "HCBT_DESTROYWND: hwnd %p\n", hwnd );
963 break;
964 default:
965 break;
968 return CallNextHookEx(hhook, nCode, wParam, lParam);
971 static void test_shell_window(void)
973 BOOL ret;
974 DWORD error;
975 HMODULE hinst, hUser32;
976 BOOL (WINAPI*SetShellWindow)(HWND);
977 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
978 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
979 HWND shellWindow, nextWnd;
981 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
983 trace("Skipping shell window test on Win9x\n");
984 return;
987 shellWindow = GetShellWindow();
988 hinst = GetModuleHandle(0);
989 hUser32 = GetModuleHandleA("user32");
991 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
992 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
994 trace("previous shell window: %p\n", shellWindow);
996 if (shellWindow) {
997 DWORD pid;
998 HANDLE hProcess;
1000 GetWindowThreadProcessId(shellWindow, &pid);
1001 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
1002 if (!hProcess)
1004 skip( "cannot get access to shell process\n" );
1005 return;
1008 SetLastError(0xdeadbeef);
1009 ret = DestroyWindow(shellWindow);
1010 error = GetLastError();
1012 ok(!ret, "DestroyWindow(shellWindow)\n");
1013 /* passes on Win XP, but not on Win98 */
1014 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
1015 "got %u after DestroyWindow(shellWindow)\n", error);
1017 /* close old shell instance */
1018 ret = TerminateProcess(hProcess, 0);
1019 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1020 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
1021 CloseHandle(hProcess);
1024 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
1025 trace("created window 1: %p\n", hwnd1);
1027 ret = SetShellWindow(hwnd1);
1028 ok(ret, "first call to SetShellWindow(hwnd1)\n");
1029 shellWindow = GetShellWindow();
1030 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
1032 ret = SetShellWindow(hwnd1);
1033 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1035 ret = SetShellWindow(0);
1036 error = GetLastError();
1037 /* passes on Win XP, but not on Win98
1038 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1039 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1041 ret = SetShellWindow(hwnd1);
1042 /* passes on Win XP, but not on Win98
1043 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1045 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1046 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
1047 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1049 ret = DestroyWindow(hwnd1);
1050 ok(ret, "DestroyWindow(hwnd1)\n");
1052 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1053 trace("created window 2: %p\n", hwnd2);
1054 ret = SetShellWindow(hwnd2);
1055 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1057 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1058 trace("created window 3: %p\n", hwnd3);
1060 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1061 trace("created window 4: %p\n", hwnd4);
1063 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1064 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1066 ret = SetShellWindow(hwnd4);
1067 ok(ret, "SetShellWindow(hwnd4)\n");
1068 shellWindow = GetShellWindow();
1069 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1071 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1072 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1074 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1075 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1077 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1078 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1080 ret = SetShellWindow(hwnd3);
1081 ok(!ret, "SetShellWindow(hwnd3)\n");
1082 shellWindow = GetShellWindow();
1083 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1085 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1086 trace("created window 5: %p\n", hwnd5);
1087 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1088 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1090 todo_wine
1092 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1093 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1096 /* destroy test windows */
1097 DestroyWindow(hwnd2);
1098 DestroyWindow(hwnd3);
1099 DestroyWindow(hwnd4);
1100 DestroyWindow(hwnd5);
1103 /************** MDI test ****************/
1105 static char mdi_lParam_test_message[] = "just a test string";
1107 static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
1109 MDICREATESTRUCTA mdi_cs;
1110 HWND mdi_child;
1111 INT_PTR id;
1112 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1113 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1114 BOOL isWin9x = FALSE;
1116 mdi_cs.szClass = "MDI_child_Class_1";
1117 mdi_cs.szTitle = "MDI child";
1118 mdi_cs.hOwner = GetModuleHandle(0);
1119 mdi_cs.x = CW_USEDEFAULT;
1120 mdi_cs.y = CW_USEDEFAULT;
1121 mdi_cs.cx = CW_USEDEFAULT;
1122 mdi_cs.cy = CW_USEDEFAULT;
1123 mdi_cs.style = 0;
1124 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1125 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1126 ok(mdi_child != 0, "MDI child creation failed\n");
1127 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1128 ok(id == first_id, "wrong child id %ld\n", id);
1129 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1130 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1132 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1133 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1134 ok(mdi_child != 0, "MDI child creation failed\n");
1135 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1136 ok(id == first_id, "wrong child id %ld\n", id);
1137 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1138 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1140 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1141 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1142 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1144 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1146 else
1148 ok(mdi_child != 0, "MDI child creation failed\n");
1149 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1150 ok(id == first_id, "wrong child id %ld\n", id);
1151 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1152 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1155 /* test MDICREATESTRUCT A<->W mapping */
1156 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1157 mdi_cs.style = 0;
1158 mdi_cs.szClass = (LPCSTR)classW;
1159 mdi_cs.szTitle = (LPCSTR)titleW;
1160 SetLastError(0xdeadbeef);
1161 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1162 if (!mdi_child)
1164 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1165 isWin9x = TRUE;
1166 else
1167 ok(mdi_child != 0, "MDI child creation failed\n");
1169 else
1171 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1172 ok(id == first_id, "wrong child id %ld\n", id);
1173 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1174 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1177 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1179 CW_USEDEFAULT, CW_USEDEFAULT,
1180 CW_USEDEFAULT, CW_USEDEFAULT,
1181 mdi_client, GetModuleHandle(0),
1182 (LPARAM)mdi_lParam_test_message);
1183 ok(mdi_child != 0, "MDI child creation failed\n");
1184 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1185 ok(id == first_id, "wrong child id %ld\n", id);
1186 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1187 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1189 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1190 0x7fffffff, /* without WS_POPUP */
1191 CW_USEDEFAULT, CW_USEDEFAULT,
1192 CW_USEDEFAULT, CW_USEDEFAULT,
1193 mdi_client, GetModuleHandle(0),
1194 (LPARAM)mdi_lParam_test_message);
1195 ok(mdi_child != 0, "MDI child creation failed\n");
1196 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1197 ok(id == first_id, "wrong child id %ld\n", id);
1198 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1199 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1201 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1202 0xffffffff, /* with WS_POPUP */
1203 CW_USEDEFAULT, CW_USEDEFAULT,
1204 CW_USEDEFAULT, CW_USEDEFAULT,
1205 mdi_client, GetModuleHandle(0),
1206 (LPARAM)mdi_lParam_test_message);
1207 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1209 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1211 else
1213 ok(mdi_child != 0, "MDI child creation failed\n");
1214 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1215 ok(id == first_id, "wrong child id %ld\n", id);
1216 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1217 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1220 /* test MDICREATESTRUCT A<->W mapping */
1221 SetLastError(0xdeadbeef);
1222 mdi_child = CreateMDIWindowW(classW, titleW,
1224 CW_USEDEFAULT, CW_USEDEFAULT,
1225 CW_USEDEFAULT, CW_USEDEFAULT,
1226 mdi_client, GetModuleHandle(0),
1227 (LPARAM)mdi_lParam_test_message);
1228 if (!mdi_child)
1230 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1231 isWin9x = TRUE;
1232 else
1233 ok(mdi_child != 0, "MDI child creation failed\n");
1235 else
1237 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1238 ok(id == first_id, "wrong child id %ld\n", id);
1239 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1240 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1243 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1245 CW_USEDEFAULT, CW_USEDEFAULT,
1246 CW_USEDEFAULT, CW_USEDEFAULT,
1247 mdi_client, 0, GetModuleHandle(0),
1248 mdi_lParam_test_message);
1249 ok(mdi_child != 0, "MDI child creation failed\n");
1250 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1251 ok(id == first_id, "wrong child id %ld\n", id);
1252 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1253 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1255 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1256 0x7fffffff, /* without WS_POPUP */
1257 CW_USEDEFAULT, CW_USEDEFAULT,
1258 CW_USEDEFAULT, CW_USEDEFAULT,
1259 mdi_client, 0, GetModuleHandle(0),
1260 mdi_lParam_test_message);
1261 ok(mdi_child != 0, "MDI child creation failed\n");
1262 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1263 ok(id == first_id, "wrong child id %ld\n", id);
1264 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1265 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1267 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1268 0xffffffff, /* with WS_POPUP */
1269 CW_USEDEFAULT, CW_USEDEFAULT,
1270 CW_USEDEFAULT, CW_USEDEFAULT,
1271 mdi_client, 0, GetModuleHandle(0),
1272 mdi_lParam_test_message);
1273 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1275 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1277 else
1279 ok(mdi_child != 0, "MDI child creation failed\n");
1280 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1281 ok(id == first_id, "wrong child id %ld\n", id);
1282 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1283 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1286 /* test MDICREATESTRUCT A<->W mapping */
1287 SetLastError(0xdeadbeef);
1288 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1290 CW_USEDEFAULT, CW_USEDEFAULT,
1291 CW_USEDEFAULT, CW_USEDEFAULT,
1292 mdi_client, 0, GetModuleHandle(0),
1293 mdi_lParam_test_message);
1294 if (!mdi_child)
1296 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1297 isWin9x = TRUE;
1298 else
1299 ok(mdi_child != 0, "MDI child creation failed\n");
1301 else
1303 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1304 ok(id == first_id, "wrong child id %ld\n", id);
1305 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1306 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1309 /* This test fails on Win9x */
1310 if (!isWin9x)
1312 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1313 WS_CHILD,
1314 CW_USEDEFAULT, CW_USEDEFAULT,
1315 CW_USEDEFAULT, CW_USEDEFAULT,
1316 parent, 0, GetModuleHandle(0),
1317 mdi_lParam_test_message);
1318 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1321 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1322 WS_CHILD, /* without WS_POPUP */
1323 CW_USEDEFAULT, CW_USEDEFAULT,
1324 CW_USEDEFAULT, CW_USEDEFAULT,
1325 mdi_client, 0, GetModuleHandle(0),
1326 mdi_lParam_test_message);
1327 ok(mdi_child != 0, "MDI child creation failed\n");
1328 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1329 ok(id == 0, "wrong child id %ld\n", id);
1330 DestroyWindow(mdi_child);
1332 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1333 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1334 CW_USEDEFAULT, CW_USEDEFAULT,
1335 CW_USEDEFAULT, CW_USEDEFAULT,
1336 mdi_client, 0, GetModuleHandle(0),
1337 mdi_lParam_test_message);
1338 ok(mdi_child != 0, "MDI child creation failed\n");
1339 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1340 ok(id == 0, "wrong child id %ld\n", id);
1341 DestroyWindow(mdi_child);
1343 /* maximized child */
1344 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1345 WS_CHILD | WS_MAXIMIZE,
1346 CW_USEDEFAULT, CW_USEDEFAULT,
1347 CW_USEDEFAULT, CW_USEDEFAULT,
1348 mdi_client, 0, GetModuleHandle(0),
1349 mdi_lParam_test_message);
1350 ok(mdi_child != 0, "MDI child creation failed\n");
1351 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1352 ok(id == 0, "wrong child id %ld\n", id);
1353 DestroyWindow(mdi_child);
1355 trace("Creating maximized child with a caption\n");
1356 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1357 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1358 CW_USEDEFAULT, CW_USEDEFAULT,
1359 CW_USEDEFAULT, CW_USEDEFAULT,
1360 mdi_client, 0, GetModuleHandle(0),
1361 mdi_lParam_test_message);
1362 ok(mdi_child != 0, "MDI child creation failed\n");
1363 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1364 ok(id == 0, "wrong child id %ld\n", id);
1365 DestroyWindow(mdi_child);
1367 trace("Creating maximized child with a caption and a thick frame\n");
1368 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1369 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1370 CW_USEDEFAULT, CW_USEDEFAULT,
1371 CW_USEDEFAULT, CW_USEDEFAULT,
1372 mdi_client, 0, GetModuleHandle(0),
1373 mdi_lParam_test_message);
1374 ok(mdi_child != 0, "MDI child creation failed\n");
1375 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1376 ok(id == 0, "wrong child id %ld\n", id);
1377 DestroyWindow(mdi_child);
1380 /**********************************************************************
1381 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1383 * Note: The rule here is that client rect of the maximized MDI child
1384 * is equal to the client rect of the MDI client window.
1386 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1388 RECT rect;
1390 GetClientRect( client, &rect );
1391 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1392 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1394 rect.right -= rect.left;
1395 rect.bottom -= rect.top;
1396 lpMinMax->ptMaxSize.x = rect.right;
1397 lpMinMax->ptMaxSize.y = rect.bottom;
1399 lpMinMax->ptMaxPosition.x = rect.left;
1400 lpMinMax->ptMaxPosition.y = rect.top;
1402 trace("max rect (%d,%d - %d, %d)\n",
1403 rect.left, rect.top, rect.right, rect.bottom);
1406 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1408 switch (msg)
1410 case WM_NCCREATE:
1411 case WM_CREATE:
1413 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1414 MDICREATESTRUCTA *mdi_cs = cs->lpCreateParams;
1416 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1417 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1419 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1420 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1421 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1422 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1423 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1425 /* MDICREATESTRUCT should have original values */
1426 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1427 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1428 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1429 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1430 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1431 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1433 /* CREATESTRUCT should have fixed values */
1434 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1435 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1437 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1438 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1439 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1441 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1443 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1445 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1446 ok(cs->style == style,
1447 "cs->style does not match (%08x)\n", cs->style);
1449 else
1451 LONG style = mdi_cs->style;
1452 style &= ~WS_POPUP;
1453 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1454 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1455 ok(cs->style == style,
1456 "cs->style does not match (%08x)\n", cs->style);
1458 break;
1461 case WM_GETMINMAXINFO:
1463 HWND client = GetParent(hwnd);
1464 RECT rc;
1465 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1466 MINMAXINFO my_minmax;
1467 LONG style, exstyle;
1469 style = GetWindowLongA(hwnd, GWL_STYLE);
1470 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1472 GetWindowRect(client, &rc);
1473 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1474 GetClientRect(client, &rc);
1475 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1476 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1477 GetSystemMetrics(SM_CYSCREEN));
1479 GetClientRect(client, &rc);
1480 if ((style & WS_CAPTION) == WS_CAPTION)
1481 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1482 AdjustWindowRectEx(&rc, style, 0, exstyle);
1483 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1484 dump_minmax_info( minmax );
1486 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1487 minmax->ptMaxSize.x, rc.right - rc.left);
1488 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1489 minmax->ptMaxSize.y, rc.bottom - rc.top);
1491 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1493 trace("DefMDIChildProc returned:\n");
1494 dump_minmax_info( minmax );
1496 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1497 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1498 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1499 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1500 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1502 return 1;
1505 case WM_MDIACTIVATE:
1507 HWND active, client = GetParent(hwnd);
1508 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1509 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1510 if (hwnd == (HWND)lparam) /* if we are being activated */
1511 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1512 else
1513 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1514 break;
1517 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1520 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1522 switch (msg)
1524 case WM_NCCREATE:
1525 case WM_CREATE:
1527 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1529 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE",
1530 cs->x, cs->y, cs->cx, cs->cy);
1532 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1533 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1535 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1536 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1538 /* CREATESTRUCT should have fixed values */
1539 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1540 while NT does. */
1541 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1542 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1544 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1545 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1546 while Win95, Win2k, WinXP do. */
1547 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1548 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1549 break;
1552 case WM_GETMINMAXINFO:
1554 HWND parent = GetParent(hwnd);
1555 RECT rc;
1556 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1557 LONG style, exstyle;
1559 style = GetWindowLongA(hwnd, GWL_STYLE);
1560 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1562 GetClientRect(parent, &rc);
1563 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1565 GetClientRect(parent, &rc);
1566 if ((style & WS_CAPTION) == WS_CAPTION)
1567 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1568 AdjustWindowRectEx(&rc, style, 0, exstyle);
1569 dump_minmax_info( minmax );
1571 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1572 minmax->ptMaxSize.x, rc.right - rc.left);
1573 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1574 minmax->ptMaxSize.y, rc.bottom - rc.top);
1575 break;
1578 case WM_WINDOWPOSCHANGED:
1580 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1581 RECT rc1, rc2;
1583 GetWindowRect(hwnd, &rc1);
1584 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1585 /* note: winpos coordinates are relative to parent */
1586 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1587 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) pos=(%d,%d)-(%d,%d)\n",
1588 rc1.left, rc1.top, rc1.right, rc1.bottom,
1589 rc2.left, rc2.top, rc2.right, rc2.bottom);
1590 GetWindowRect(hwnd, &rc1);
1591 GetClientRect(hwnd, &rc2);
1592 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1593 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1594 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1595 rc1.left, rc1.top, rc1.right, rc1.bottom,
1596 rc2.left, rc2.top, rc2.right, rc2.bottom);
1598 /* fall through */
1599 case WM_WINDOWPOSCHANGING:
1601 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1602 WINDOWPOS my_winpos = *winpos;
1604 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1605 (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
1606 winpos->hwnd, winpos->hwndInsertAfter,
1607 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1609 DefWindowProcA(hwnd, msg, wparam, lparam);
1611 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1612 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1613 winpos->hwnd, winpos->hwndInsertAfter,
1614 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1616 return 1;
1619 return DefWindowProcA(hwnd, msg, wparam, lparam);
1622 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1624 static HWND mdi_client;
1626 switch (msg)
1628 case WM_CREATE:
1630 CLIENTCREATESTRUCT client_cs;
1631 RECT rc;
1633 GetClientRect(hwnd, &rc);
1635 client_cs.hWindowMenu = 0;
1636 client_cs.idFirstChild = 1;
1638 /* MDIClient without MDIS_ALLCHILDSTYLES */
1639 mdi_client = CreateWindowExA(0, "mdiclient",
1640 NULL,
1641 WS_CHILD /*| WS_VISIBLE*/,
1642 /* tests depend on a not zero MDIClient size */
1643 0, 0, rc.right, rc.bottom,
1644 hwnd, 0, GetModuleHandle(0),
1645 &client_cs);
1646 assert(mdi_client);
1647 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1648 DestroyWindow(mdi_client);
1650 /* MDIClient with MDIS_ALLCHILDSTYLES */
1651 mdi_client = CreateWindowExA(0, "mdiclient",
1652 NULL,
1653 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1654 /* tests depend on a not zero MDIClient size */
1655 0, 0, rc.right, rc.bottom,
1656 hwnd, 0, GetModuleHandle(0),
1657 &client_cs);
1658 assert(mdi_client);
1659 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1660 DestroyWindow(mdi_client);
1661 break;
1664 case WM_WINDOWPOSCHANGED:
1666 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1667 RECT rc1, rc2;
1669 GetWindowRect(hwnd, &rc1);
1670 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1671 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1672 /* note: winpos coordinates are relative to parent */
1673 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1674 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1675 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1677 GetWindowRect(hwnd, &rc1);
1678 GetClientRect(hwnd, &rc2);
1679 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1680 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1681 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1683 /* fall through */
1684 case WM_WINDOWPOSCHANGING:
1686 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1687 WINDOWPOS my_winpos = *winpos;
1689 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1690 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1691 winpos->hwnd, winpos->hwndInsertAfter,
1692 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1694 DefWindowProcA(hwnd, msg, wparam, lparam);
1696 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1697 winpos->hwnd, winpos->hwndInsertAfter,
1698 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1700 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1701 "DefWindowProc should not change WINDOWPOS values\n");
1703 return 1;
1706 case WM_CLOSE:
1707 PostQuitMessage(0);
1708 break;
1710 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1713 static BOOL mdi_RegisterWindowClasses(void)
1715 WNDCLASSA cls;
1717 cls.style = 0;
1718 cls.lpfnWndProc = mdi_main_wnd_procA;
1719 cls.cbClsExtra = 0;
1720 cls.cbWndExtra = 0;
1721 cls.hInstance = GetModuleHandleA(0);
1722 cls.hIcon = 0;
1723 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1724 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1725 cls.lpszMenuName = NULL;
1726 cls.lpszClassName = "MDI_parent_Class";
1727 if(!RegisterClassA(&cls)) return FALSE;
1729 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1730 cls.lpszClassName = "MDI_child_Class_1";
1731 if(!RegisterClassA(&cls)) return FALSE;
1733 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1734 cls.lpszClassName = "MDI_child_Class_2";
1735 if(!RegisterClassA(&cls)) return FALSE;
1737 return TRUE;
1740 static void test_mdi(void)
1742 HWND mdi_hwndMain;
1743 /*MSG msg;*/
1745 if (!mdi_RegisterWindowClasses()) assert(0);
1747 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1748 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1749 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1750 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1751 GetDesktopWindow(), 0,
1752 GetModuleHandle(0), NULL);
1753 assert(mdi_hwndMain);
1755 while(GetMessage(&msg, 0, 0, 0))
1757 TranslateMessage(&msg);
1758 DispatchMessage(&msg);
1761 DestroyWindow(mdi_hwndMain);
1764 static void test_icons(void)
1766 WNDCLASSEXA cls;
1767 HWND hwnd;
1768 HICON icon = LoadIconA(0, IDI_APPLICATION);
1769 HICON icon2 = LoadIconA(0, IDI_QUESTION);
1770 HICON small_icon = LoadImageA(0, IDI_APPLICATION, IMAGE_ICON,
1771 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1772 HICON res;
1774 cls.cbSize = sizeof(cls);
1775 cls.style = 0;
1776 cls.lpfnWndProc = DefWindowProcA;
1777 cls.cbClsExtra = 0;
1778 cls.cbWndExtra = 0;
1779 cls.hInstance = 0;
1780 cls.hIcon = LoadIconA(0, IDI_HAND);
1781 cls.hIconSm = small_icon;
1782 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1783 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1784 cls.lpszMenuName = NULL;
1785 cls.lpszClassName = "IconWindowClass";
1787 RegisterClassExA(&cls);
1789 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1790 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1791 assert( hwnd );
1793 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1794 ok( res == 0, "wrong big icon %p/0\n", res );
1795 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1796 ok( res == 0, "wrong previous big icon %p/0\n", res );
1797 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1798 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1799 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1800 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1801 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1802 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1804 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1805 ok( res == 0, "wrong small icon %p/0\n", res );
1806 /* this test is XP specific */
1807 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1808 ok( res != 0, "wrong small icon %p\n", res );*/
1809 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1810 ok( res == 0, "wrong previous small icon %p/0\n", res );
1811 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1812 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1813 /* this test is XP specific */
1814 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1815 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1816 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1817 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1818 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1819 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1820 /* this test is XP specific */
1821 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1822 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1824 /* make sure the big icon hasn't changed */
1825 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1826 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1828 DestroyWindow( hwnd );
1831 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1833 if (msg == WM_NCCALCSIZE)
1835 RECT *rect = (RECT *)lparam;
1836 /* first time around increase the rectangle, next time decrease it */
1837 if (rect->left == 100) InflateRect( rect, 10, 10 );
1838 else InflateRect( rect, -10, -10 );
1839 return 0;
1841 return DefWindowProc( hwnd, msg, wparam, lparam );
1844 static void test_SetWindowPos(HWND hwnd)
1846 RECT orig_win_rc, rect;
1847 LONG_PTR old_proc;
1848 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1850 SetRect(&rect, 111, 222, 333, 444);
1851 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1852 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1853 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1855 SetRect(&rect, 111, 222, 333, 444);
1856 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1857 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1858 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1860 GetWindowRect(hwnd, &orig_win_rc);
1862 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1863 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1864 GetWindowRect( hwnd, &rect );
1865 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1866 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1867 GetClientRect( hwnd, &rect );
1868 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1869 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1870 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1872 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1873 GetWindowRect( hwnd, &rect );
1874 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1875 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1876 GetClientRect( hwnd, &rect );
1877 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1878 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1879 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1881 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1882 orig_win_rc.right, orig_win_rc.bottom, 0);
1883 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1885 /* Win9x truncates coordinates to 16-bit irrespectively */
1886 if (!is_win9x)
1888 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1889 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1891 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1892 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1895 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1896 orig_win_rc.right, orig_win_rc.bottom, 0);
1898 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1899 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1900 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1901 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1902 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1903 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1904 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1907 static void test_SetMenu(HWND parent)
1909 HWND child;
1910 HMENU hMenu, ret;
1911 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1912 BOOL retok;
1913 DWORD style;
1915 hMenu = CreateMenu();
1916 assert(hMenu);
1918 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1919 if (0)
1921 /* fails on (at least) Wine, NT4, XP SP2 */
1922 test_nonclient_area(parent);
1924 ret = GetMenu(parent);
1925 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1926 /* test whether we can destroy a menu assigned to a window */
1927 retok = DestroyMenu(hMenu);
1928 ok( retok, "DestroyMenu error %d\n", GetLastError());
1929 retok = IsMenu(hMenu);
1930 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
1931 ret = GetMenu(parent);
1932 /* This test fails on Win9x */
1933 if (!is_win9x)
1934 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1935 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1936 test_nonclient_area(parent);
1938 hMenu = CreateMenu();
1939 assert(hMenu);
1941 /* parent */
1942 ret = GetMenu(parent);
1943 ok(ret == 0, "unexpected menu id %p\n", ret);
1945 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1946 test_nonclient_area(parent);
1947 ret = GetMenu(parent);
1948 ok(ret == 0, "unexpected menu id %p\n", ret);
1950 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1951 if (0)
1953 /* fails on (at least) Wine, NT4, XP SP2 */
1954 test_nonclient_area(parent);
1956 ret = GetMenu(parent);
1957 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1959 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1960 test_nonclient_area(parent);
1961 ret = GetMenu(parent);
1962 ok(ret == 0, "unexpected menu id %p\n", ret);
1964 /* child */
1965 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1966 assert(child);
1968 ret = GetMenu(child);
1969 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1971 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1972 test_nonclient_area(child);
1973 ret = GetMenu(child);
1974 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1976 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1977 test_nonclient_area(child);
1978 ret = GetMenu(child);
1979 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1981 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1982 test_nonclient_area(child);
1983 ret = GetMenu(child);
1984 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1986 style = GetWindowLong(child, GWL_STYLE);
1987 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
1988 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
1989 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
1990 SetWindowLong(child, GWL_STYLE, style);
1992 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
1993 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
1994 SetWindowLong(child, GWL_STYLE, style);
1996 DestroyWindow(child);
1997 DestroyMenu(hMenu);
2000 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
2002 HWND child[5], hwnd;
2003 INT_PTR i;
2005 assert(total <= 5);
2007 hwnd = GetWindow(parent, GW_CHILD);
2008 ok(!hwnd, "have to start without children to perform the test\n");
2010 for (i = 0; i < total; i++)
2012 if (style[i] & DS_CONTROL)
2014 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
2015 0,0,0,0, parent, (HMENU)i, 0, NULL);
2016 if (style[i] & WS_VISIBLE)
2017 ShowWindow(child[i], SW_SHOW);
2019 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
2021 else
2022 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
2023 parent, (HMENU)i, 0, NULL);
2024 trace("child[%ld] = %p\n", i, child[i]);
2025 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
2028 hwnd = GetWindow(parent, GW_CHILD);
2029 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
2030 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
2031 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
2033 for (i = 0; i < total; i++)
2035 trace("hwnd[%ld] = %p\n", i, hwnd);
2036 ok(child[order[i]] == hwnd, "Z order of child #%ld is wrong\n", i);
2038 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
2041 for (i = 0; i < total; i++)
2042 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2045 static void test_children_zorder(HWND parent)
2047 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2048 WS_CHILD };
2049 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2051 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2052 WS_CHILD | WS_VISIBLE, WS_CHILD,
2053 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2054 const int complex_order_1[1] = { 0 };
2055 const int complex_order_2[2] = { 1, 0 };
2056 const int complex_order_3[3] = { 1, 0, 2 };
2057 const int complex_order_4[4] = { 1, 0, 2, 3 };
2058 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2059 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2060 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2061 WS_CHILD | WS_VISIBLE };
2062 const int complex_order_6[3] = { 0, 1, 2 };
2064 /* simple WS_CHILD */
2065 test_window_tree(parent, simple_style, simple_order, 5);
2067 /* complex children styles */
2068 test_window_tree(parent, complex_style, complex_order_1, 1);
2069 test_window_tree(parent, complex_style, complex_order_2, 2);
2070 test_window_tree(parent, complex_style, complex_order_3, 3);
2071 test_window_tree(parent, complex_style, complex_order_4, 4);
2072 test_window_tree(parent, complex_style, complex_order_5, 5);
2074 /* another set of complex children styles */
2075 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2078 #define check_z_order(hwnd, next, prev, owner, topmost) \
2079 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2080 __FILE__, __LINE__)
2082 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2083 BOOL topmost, const char *file, int line)
2085 HWND test;
2086 DWORD ex_style;
2088 test = GetWindow(hwnd, GW_HWNDNEXT);
2089 /* skip foreign windows */
2090 while (test && test != next &&
2091 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2092 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2093 GetWindow(test, GW_OWNER) == next))
2095 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2096 test = GetWindow(test, GW_HWNDNEXT);
2098 ok_(file, line)(next == test, "expected next %p, got %p\n", next, test);
2100 test = GetWindow(hwnd, GW_HWNDPREV);
2101 /* skip foreign windows */
2102 while (test && test != prev &&
2103 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2104 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2105 GetWindow(test, GW_OWNER) == hwnd))
2107 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2108 test = GetWindow(test, GW_HWNDPREV);
2110 ok_(file, line)(prev == test, "expected prev %p, got %p\n", prev, test);
2112 test = GetWindow(hwnd, GW_OWNER);
2113 ok_(file, line)(owner == test, "expected owner %p, got %p\n", owner, test);
2115 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2116 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "expected %stopmost\n", topmost ? "" : "NOT ");
2119 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E)
2121 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2123 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2125 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2127 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2128 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2130 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2131 WS_OVERLAPPED | WS_CAPTION,
2132 100, 100, 100, 100,
2133 0, 0, GetModuleHandle(0), NULL);
2134 trace("hwnd_F %p\n", hwnd_F);
2135 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2137 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2138 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2139 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2140 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2142 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2143 WS_POPUP,
2144 100, 100, 100, 100,
2145 hwnd_F, 0, GetModuleHandle(0), NULL);
2146 trace("hwnd_C %p\n", hwnd_C);
2147 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2148 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2149 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2150 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2152 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2153 WS_POPUP,
2154 100, 100, 100, 100,
2155 hwnd_F, 0, GetModuleHandle(0), NULL);
2156 trace("hwnd_B %p\n", hwnd_B);
2157 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2158 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2159 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2160 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2161 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2163 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2164 WS_POPUP,
2165 100, 100, 100, 100,
2166 0, 0, GetModuleHandle(0), NULL);
2167 trace("hwnd_A %p\n", hwnd_A);
2168 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2169 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2170 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2171 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2172 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2173 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2175 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);
2177 /* move hwnd_F and its popups up */
2178 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2179 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2180 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2181 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2182 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2183 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2184 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2186 /* move hwnd_F and its popups down */
2187 #if 0 /* enable once Wine is fixed to pass this test */
2188 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2189 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2190 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2191 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2192 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2193 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2194 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2195 #endif
2197 DestroyWindow(hwnd_A);
2198 DestroyWindow(hwnd_B);
2199 DestroyWindow(hwnd_C);
2200 DestroyWindow(hwnd_F);
2203 static void test_vis_rgn( HWND hwnd )
2205 RECT win_rect, rgn_rect;
2206 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2207 HDC hdc;
2209 ShowWindow(hwnd,SW_SHOW);
2210 hdc = GetDC( hwnd );
2211 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2212 GetWindowRect( hwnd, &win_rect );
2213 GetRgnBox( hrgn, &rgn_rect );
2214 if (GetVersion() & 0x80000000)
2216 trace("win9x, mapping to screen coords\n");
2217 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2219 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2220 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2221 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2222 rgn_rect.left, win_rect.left );
2223 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2224 rgn_rect.top, win_rect.top );
2225 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2226 rgn_rect.right, win_rect.right );
2227 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2228 rgn_rect.bottom, win_rect.bottom );
2229 ReleaseDC( hwnd, hdc );
2232 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2234 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2236 HWND child = GetWindow(hwnd, GW_CHILD);
2237 ok(child != 0, "couldn't find child window\n");
2238 SetFocus(child);
2239 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2240 return 0;
2242 return DefWindowProc(hwnd, msg, wp, lp);
2245 static void test_SetFocus(HWND hwnd)
2247 HWND child;
2248 WNDPROC old_wnd_proc;
2250 /* check if we can set focus to non-visible windows */
2252 ShowWindow(hwnd, SW_SHOW);
2253 SetFocus(0);
2254 SetFocus(hwnd);
2255 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2256 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2257 ShowWindow(hwnd, SW_HIDE);
2258 SetFocus(0);
2259 SetFocus(hwnd);
2260 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2261 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2262 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2263 assert(child);
2264 SetFocus(child);
2265 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2266 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2267 ShowWindow(child, SW_SHOW);
2268 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2269 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2270 ShowWindow(child, SW_HIDE);
2271 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2272 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2273 ShowWindow(child, SW_SHOW);
2274 SetFocus(child);
2275 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2276 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2277 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2279 ShowWindow(child, SW_HIDE);
2280 SetFocus(hwnd);
2281 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2282 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2283 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2284 ShowWindow(child, SW_HIDE);
2285 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2287 ShowWindow(hwnd, SW_SHOW);
2288 ShowWindow(child, SW_SHOW);
2289 SetFocus(child);
2290 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2291 EnableWindow(hwnd, FALSE);
2292 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2293 EnableWindow(hwnd, TRUE);
2295 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2296 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2297 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2298 todo_wine
2299 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2300 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2301 ShowWindow(hwnd, SW_RESTORE);
2302 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2303 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2304 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2305 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2306 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2307 todo_wine
2308 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2309 old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2310 ShowWindow(hwnd, SW_RESTORE);
2311 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2312 todo_wine
2313 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2315 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2317 DestroyWindow( child );
2320 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
2321 static void check_wnd_state_(const char *file, int line,
2322 HWND active, HWND foreground, HWND focus, HWND capture)
2324 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2325 if (foreground && GetForegroundWindow())
2326 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2327 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2328 ok_(file, line)(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2331 static void test_SetActiveWindow(HWND hwnd)
2333 HWND hwnd2;
2335 flush_events( TRUE );
2336 ShowWindow(hwnd, SW_HIDE);
2337 SetFocus(0);
2338 SetActiveWindow(0);
2339 check_wnd_state(0, 0, 0, 0);
2341 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2343 ShowWindow(hwnd, SW_SHOW);
2344 check_wnd_state(hwnd, hwnd, hwnd, 0);
2346 hwnd2 = SetActiveWindow(0);
2347 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2348 if (!GetActiveWindow()) /* doesn't always work on vista */
2350 check_wnd_state(0, 0, 0, 0);
2351 hwnd2 = SetActiveWindow(hwnd);
2352 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2354 check_wnd_state(hwnd, hwnd, hwnd, 0);
2356 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2357 check_wnd_state(hwnd, hwnd, hwnd, 0);
2359 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2360 check_wnd_state(hwnd, hwnd, hwnd, 0);
2362 ShowWindow(hwnd, SW_HIDE);
2363 check_wnd_state(0, 0, 0, 0);
2365 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2366 SetActiveWindow(hwnd);
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 void test_SetForegroundWindow(HWND hwnd)
2390 BOOL ret;
2391 HWND hwnd2;
2393 flush_events( TRUE );
2394 ShowWindow(hwnd, SW_HIDE);
2395 SetFocus(0);
2396 SetActiveWindow(0);
2397 check_wnd_state(0, 0, 0, 0);
2399 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2401 ShowWindow(hwnd, SW_SHOW);
2402 check_wnd_state(hwnd, hwnd, hwnd, 0);
2404 hwnd2 = SetActiveWindow(0);
2405 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2406 if (GetActiveWindow() == hwnd) /* doesn't always work on vista */
2407 check_wnd_state(hwnd, hwnd, hwnd, 0);
2408 else
2409 check_wnd_state(0, 0, 0, 0);
2411 ret = SetForegroundWindow(hwnd);
2412 if (!ret)
2414 skip( "SetForegroundWindow not working\n" );
2415 return;
2417 check_wnd_state(hwnd, hwnd, hwnd, 0);
2419 SetLastError(0xdeadbeef);
2420 ret = SetForegroundWindow(0);
2421 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2422 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
2423 broken(GetLastError() == 0xdeadbeef), /* win9x */
2424 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2425 check_wnd_state(hwnd, hwnd, hwnd, 0);
2427 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2428 check_wnd_state(hwnd, hwnd, hwnd, 0);
2430 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2431 check_wnd_state(hwnd, hwnd, hwnd, 0);
2433 hwnd2 = GetForegroundWindow();
2434 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2435 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2436 hwnd2 = GetForegroundWindow();
2437 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2439 ShowWindow(hwnd, SW_HIDE);
2440 check_wnd_state(0, 0, 0, 0);
2442 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2443 ret = SetForegroundWindow(hwnd);
2444 ok(ret || broken(!ret), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
2445 check_wnd_state(hwnd, hwnd, hwnd, 0);
2447 ShowWindow(hwnd, SW_SHOW);
2448 check_wnd_state(hwnd, hwnd, hwnd, 0);
2450 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2451 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2453 DestroyWindow(hwnd2);
2454 check_wnd_state(hwnd, hwnd, hwnd, 0);
2456 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2457 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2459 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2460 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2462 DestroyWindow(hwnd2);
2463 check_wnd_state(hwnd, hwnd, hwnd, 0);
2466 static WNDPROC old_button_proc;
2468 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2470 LRESULT ret;
2471 USHORT key_state;
2473 key_state = GetKeyState(VK_LBUTTON);
2474 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2476 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2478 if (msg == WM_LBUTTONDOWN)
2480 HWND hwnd, capture;
2482 check_wnd_state(button, button, button, button);
2484 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2485 assert(hwnd);
2486 trace("hwnd %p\n", hwnd);
2488 check_wnd_state(button, button, button, button);
2490 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2492 check_wnd_state(button, button, button, button);
2494 DestroyWindow(hwnd);
2496 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2497 assert(hwnd);
2498 trace("hwnd %p\n", hwnd);
2500 check_wnd_state(button, button, button, button);
2502 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2503 * match internal button state.
2505 SendMessage(button, WM_KILLFOCUS, 0, 0);
2506 check_wnd_state(button, button, button, 0);
2508 ShowWindow(hwnd, SW_SHOW);
2509 check_wnd_state(hwnd, hwnd, hwnd, 0);
2511 capture = SetCapture(hwnd);
2512 ok(capture == 0, "SetCapture() = %p\n", capture);
2514 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2516 DestroyWindow(hwnd);
2518 check_wnd_state(button, 0, button, 0);
2521 return ret;
2524 static void test_capture_1(void)
2526 HWND button, capture, oldFocus, oldActive;
2528 oldFocus = GetFocus();
2529 oldActive = GetActiveWindow();
2531 capture = GetCapture();
2532 ok(capture == 0, "GetCapture() = %p\n", capture);
2534 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2535 assert(button);
2536 trace("button %p\n", button);
2538 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2540 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2542 capture = SetCapture(button);
2543 ok(capture == 0, "SetCapture() = %p\n", capture);
2544 check_wnd_state(button, 0, button, button);
2546 DestroyWindow(button);
2547 check_wnd_state(oldActive, 0, oldFocus, 0);
2550 static void test_capture_2(void)
2552 HWND button, hwnd, capture, oldFocus, oldActive;
2554 oldFocus = GetFocus();
2555 oldActive = GetActiveWindow();
2556 check_wnd_state(oldActive, 0, oldFocus, 0);
2558 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2559 assert(button);
2560 trace("button %p\n", button);
2562 check_wnd_state(button, button, button, 0);
2564 capture = SetCapture(button);
2565 ok(capture == 0, "SetCapture() = %p\n", capture);
2567 check_wnd_state(button, button, button, button);
2569 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2570 * internal button state.
2572 SendMessage(button, WM_KILLFOCUS, 0, 0);
2573 check_wnd_state(button, button, button, button);
2575 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2576 assert(hwnd);
2577 trace("hwnd %p\n", hwnd);
2579 check_wnd_state(button, button, button, button);
2581 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2583 check_wnd_state(button, button, button, button);
2585 DestroyWindow(hwnd);
2587 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2588 assert(hwnd);
2589 trace("hwnd %p\n", hwnd);
2591 check_wnd_state(button, button, button, button);
2593 ShowWindow(hwnd, SW_SHOW);
2595 check_wnd_state(hwnd, hwnd, hwnd, button);
2597 capture = SetCapture(hwnd);
2598 ok(capture == button, "SetCapture() = %p\n", capture);
2600 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2602 DestroyWindow(hwnd);
2603 check_wnd_state(button, button, button, 0);
2605 DestroyWindow(button);
2606 check_wnd_state(oldActive, 0, oldFocus, 0);
2609 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2611 BOOL ret;
2613 ShowWindow(hwnd1, SW_HIDE);
2614 ShowWindow(hwnd2, SW_HIDE);
2616 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2617 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2619 SetCapture(hwnd1);
2620 check_wnd_state(0, 0, 0, hwnd1);
2622 SetCapture(hwnd2);
2623 check_wnd_state(0, 0, 0, hwnd2);
2625 ShowWindow(hwnd1, SW_SHOW);
2626 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2628 ret = ReleaseCapture();
2629 ok (ret, "releasecapture did not return TRUE.\n");
2630 ret = ReleaseCapture();
2631 ok (ret, "releasecapture did not return TRUE after second try.\n");
2634 static void test_keyboard_input(HWND hwnd)
2636 MSG msg;
2637 BOOL ret;
2639 flush_events( TRUE );
2640 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
2641 UpdateWindow(hwnd);
2642 flush_events( TRUE );
2644 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2646 SetFocus(hwnd);
2647 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2649 flush_events( TRUE );
2651 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2654 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2655 ok( ret, "no message available\n");
2657 while (ret && msg.message >= 0xc000);
2658 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2660 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2661 while (ret && (msg.message == WM_TIMER || msg.message >= 0xc000));
2662 ok( !ret, "message %04x available\n", msg.message);
2664 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2666 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2667 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2668 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2669 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2670 ok( !ret, "message %04x available\n", msg.message);
2672 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2674 keybd_event(VK_SPACE, 0, 0, 0);
2677 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2678 } while (ret && msg.message >= 0xc000);
2679 if (!ret)
2681 skip( "keybd_event didn't work, skipping keyboard test\n" );
2682 return;
2684 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2685 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2686 ok( !ret, "message %04x available\n", msg.message);
2688 SetFocus(0);
2689 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2691 flush_events( TRUE );
2693 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2694 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2695 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2696 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2697 ok( !ret, "message %04x available\n", msg.message);
2699 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2701 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2702 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2703 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2704 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2705 ok( !ret, "message %04x available\n", msg.message);
2707 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2709 keybd_event(VK_SPACE, 0, 0, 0);
2710 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2711 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2712 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2713 ok( !ret, "message %04x available\n", msg.message);
2716 static BOOL wait_for_message( MSG *msg )
2718 BOOL ret;
2720 for (;;)
2722 ret = PeekMessageA(msg, 0, 0, 0, PM_REMOVE);
2723 if (ret)
2725 if (msg->message == WM_PAINT) DispatchMessage(msg);
2726 else if (!ignore_message(msg->message)) break;
2728 else if (MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
2730 if (!ret) msg->message = 0;
2731 return ret;
2734 static void test_mouse_input(HWND hwnd)
2736 RECT rc;
2737 POINT pt;
2738 int x, y;
2739 HWND popup;
2740 MSG msg;
2741 BOOL ret;
2742 LRESULT res;
2744 ShowWindow(hwnd, SW_SHOW);
2745 UpdateWindow(hwnd);
2746 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2748 GetWindowRect(hwnd, &rc);
2749 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2751 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2752 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2753 hwnd, 0, 0, NULL);
2754 assert(popup != 0);
2755 ShowWindow(popup, SW_SHOW);
2756 UpdateWindow(popup);
2757 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2759 GetWindowRect(popup, &rc);
2760 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2762 x = rc.left + (rc.right - rc.left) / 2;
2763 y = rc.top + (rc.bottom - rc.top) / 2;
2764 trace("setting cursor to (%d,%d)\n", x, y);
2766 SetCursorPos(x, y);
2767 GetCursorPos(&pt);
2768 if (x != pt.x || y != pt.y)
2770 skip( "failed to set mouse position, skipping mouse input tests\n" );
2771 goto done;
2774 flush_events( TRUE );
2776 /* Check that setting the same position may generate WM_MOUSEMOVE */
2777 SetCursorPos(x, y);
2778 msg.message = 0;
2780 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2781 while (ret && msg.message >= 0xc000); /* skip registered messages */
2782 if (ret)
2784 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
2785 msg.hwnd, msg.message);
2786 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
2787 x, y, msg.pt.x, msg.pt.y);
2790 /* force the system to update its internal queue mouse position,
2791 * otherwise it won't generate relative mouse movements below.
2793 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2794 flush_events( TRUE );
2796 msg.message = 0;
2797 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2798 flush_events( FALSE );
2799 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2800 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2802 if (msg.message == WM_TIMER || msg.message >= 0xc000) continue; /* skip registered messages */
2803 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
2804 "hwnd %p message %04x\n", msg.hwnd, msg.message);
2806 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2807 ok( !ret, "message %04x available\n", msg.message);
2809 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2810 ShowWindow(popup, SW_HIDE);
2811 ret = wait_for_message( &msg );
2812 if (ret)
2813 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2814 flush_events( TRUE );
2816 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2817 ShowWindow(hwnd, SW_HIDE);
2818 ret = wait_for_message( &msg );
2819 ok( !ret, "message %04x available\n", msg.message);
2820 flush_events( TRUE );
2822 /* test mouse clicks */
2824 ShowWindow(hwnd, SW_SHOW);
2825 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2826 flush_events( TRUE );
2827 ShowWindow(popup, SW_SHOW);
2828 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2829 flush_events( TRUE );
2831 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2832 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2833 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2834 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2836 ret = wait_for_message( &msg );
2837 if (!ret)
2839 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
2840 goto done;
2842 if (msg.message == WM_MOUSEMOVE) /* win2k has an extra WM_MOUSEMOVE here */
2844 ret = wait_for_message( &msg );
2845 ok(ret, "no message available\n");
2848 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2849 msg.hwnd, popup, msg.message);
2851 ret = wait_for_message( &msg );
2852 ok(ret, "no message available\n");
2853 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2854 msg.hwnd, popup, msg.message);
2856 ret = wait_for_message( &msg );
2857 ok(ret, "no message available\n");
2858 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
2859 msg.hwnd, popup, msg.message);
2861 ret = wait_for_message( &msg );
2862 ok(ret, "no message available\n");
2863 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2864 msg.hwnd, popup, msg.message);
2866 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2867 ok(!ret, "message %04x available\n", msg.message);
2869 ShowWindow(popup, SW_HIDE);
2870 flush_events( TRUE );
2872 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2873 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2874 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2875 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2877 ret = wait_for_message( &msg );
2878 ok(ret, "no message available\n");
2879 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2880 msg.hwnd, hwnd, msg.message);
2881 ret = wait_for_message( &msg );
2882 ok(ret, "no message available\n");
2883 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2884 msg.hwnd, hwnd, msg.message);
2886 test_lbuttondown_flag = TRUE;
2887 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
2888 test_lbuttondown_flag = FALSE;
2890 ret = wait_for_message( &msg );
2891 ok(ret, "no message available\n");
2892 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2893 msg.hwnd, popup, msg.message);
2894 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2895 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2896 msg.hwnd, popup, msg.message);
2897 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2899 /* Test WM_MOUSEACTIVATE */
2900 #define TEST_MOUSEACTIVATE(A,B) \
2901 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2902 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2904 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
2905 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
2906 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
2907 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
2908 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
2909 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
2910 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
2911 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
2912 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
2913 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
2914 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
2915 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
2916 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
2917 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
2918 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
2919 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
2920 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
2921 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
2922 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
2923 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
2924 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
2925 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
2926 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
2927 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
2929 done:
2930 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2931 flush_events( TRUE );
2933 DestroyWindow(popup);
2936 static void test_validatergn(HWND hwnd)
2938 HWND child;
2939 RECT rc, rc2;
2940 HRGN rgn;
2941 int ret;
2942 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
2943 ShowWindow(hwnd, SW_SHOW);
2944 UpdateWindow( hwnd);
2945 /* test that ValidateRect validates children*/
2946 InvalidateRect( child, NULL, 1);
2947 GetWindowRect( child, &rc);
2948 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2949 ret = GetUpdateRect( child, &rc2, 0);
2950 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
2951 "Update rectangle is empty!\n");
2952 ValidateRect( hwnd, &rc);
2953 ret = GetUpdateRect( child, &rc2, 0);
2954 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2955 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2956 rc2.right, rc2.bottom);
2958 /* now test ValidateRgn */
2959 InvalidateRect( child, NULL, 1);
2960 GetWindowRect( child, &rc);
2961 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2962 rgn = CreateRectRgnIndirect( &rc);
2963 ValidateRgn( hwnd, rgn);
2964 ret = GetUpdateRect( child, &rc2, 0);
2965 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2966 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2967 rc2.right, rc2.bottom);
2969 DeleteObject( rgn);
2970 DestroyWindow( child );
2973 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
2975 RECT rc;
2976 MoveWindow( hwnd, 0, 0, x, y, 0);
2977 GetWindowRect( hwnd, prc);
2978 rc = *prc;
2979 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
2980 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
2981 rc.left,rc.top,rc.right,rc.bottom, prc->left,prc->top,prc->right,prc->bottom);
2984 static void test_nccalcscroll(HWND parent)
2986 RECT rc1;
2987 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
2988 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
2989 HWND hwnd = CreateWindowExA(0, "static", NULL,
2990 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
2991 10, 10, 200, 200, parent, 0, 0, NULL);
2992 ShowWindow( parent, SW_SHOW);
2993 UpdateWindow( parent);
2995 /* test window too low for a horizontal scroll bar */
2996 nccalchelper( hwnd, 100, sbheight, &rc1);
2997 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
2998 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
3000 /* test window just high enough for a horizontal scroll bar */
3001 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
3002 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
3003 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3005 /* test window too narrow for a vertical scroll bar */
3006 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
3007 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
3008 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3010 /* test window just wide enough for a vertical scroll bar */
3011 nccalchelper( hwnd, sbwidth, 100, &rc1);
3012 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
3013 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
3015 /* same test, but with client edge: not enough width */
3016 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
3017 nccalchelper( hwnd, sbwidth, 100, &rc1);
3018 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
3019 "Width should be %d size is %d,%d - %d,%d\n",
3020 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
3022 DestroyWindow( hwnd);
3025 static void test_SetParent(void)
3027 BOOL ret;
3028 HWND desktop = GetDesktopWindow();
3029 HMENU hMenu;
3030 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
3031 HWND parent, child1, child2, child3, child4, sibling;
3033 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3034 100, 100, 200, 200, 0, 0, 0, NULL);
3035 assert(parent != 0);
3036 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3037 0, 0, 50, 50, parent, 0, 0, NULL);
3038 assert(child1 != 0);
3039 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3040 0, 0, 50, 50, child1, 0, 0, NULL);
3041 assert(child2 != 0);
3042 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3043 0, 0, 50, 50, child2, 0, 0, NULL);
3044 assert(child3 != 0);
3045 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3046 0, 0, 50, 50, child3, 0, 0, NULL);
3047 assert(child4 != 0);
3049 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
3050 parent, child1, child2, child3, child4);
3052 check_parents(parent, desktop, 0, 0, 0, parent, parent);
3053 check_parents(child1, parent, parent, parent, 0, parent, parent);
3054 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3055 check_parents(child3, child2, child2, child2, 0, child2, parent);
3056 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3058 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
3059 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
3060 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3061 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
3062 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3064 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
3065 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3066 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
3067 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
3068 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
3069 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
3070 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
3071 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3072 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3074 if (!is_win9x) /* Win9x doesn't survive this test */
3076 ok(!SetParent(parent, child1), "SetParent should fail\n");
3077 ok(!SetParent(child2, child3), "SetParent should fail\n");
3078 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
3079 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
3080 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
3081 ok(!SetParent(child2, parent), "SetParent should fail\n");
3082 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
3084 check_parents(parent, child4, child4, 0, 0, child4, parent);
3085 check_parents(child1, parent, parent, parent, 0, child4, parent);
3086 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3087 check_parents(child3, child2, child2, child2, 0, child2, parent);
3088 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3091 hMenu = CreateMenu();
3092 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3093 100, 100, 200, 200, 0, hMenu, 0, NULL);
3094 assert(sibling != 0);
3096 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
3097 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
3099 ret = DestroyWindow(parent);
3100 ok( ret, "DestroyWindow() error %d\n", GetLastError());
3102 ok(!IsWindow(parent), "parent still exists\n");
3103 ok(!IsWindow(sibling), "sibling still exists\n");
3104 ok(!IsWindow(child1), "child1 still exists\n");
3105 ok(!IsWindow(child2), "child2 still exists\n");
3106 ok(!IsWindow(child3), "child3 still exists\n");
3107 ok(!IsWindow(child4), "child4 still exists\n");
3110 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3112 LPCREATESTRUCT lpcs;
3113 LPSTYLESTRUCT lpss;
3115 switch (msg)
3117 case WM_NCCREATE:
3118 case WM_CREATE:
3119 lpcs = (LPCREATESTRUCT)lparam;
3120 lpss = lpcs->lpCreateParams;
3121 if (lpss)
3123 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
3124 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
3125 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
3126 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
3127 else
3128 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3130 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
3131 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
3132 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
3134 ok(lpss->styleNew == lpcs->style,
3135 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3136 lpss->styleNew, lpcs->style);
3138 break;
3140 return DefWindowProc(hwnd, msg, wparam, lparam);
3143 static ATOM atomStyleCheckClass;
3145 static void register_style_check_class(void)
3147 WNDCLASS wc =
3150 StyleCheckProc,
3153 GetModuleHandle(NULL),
3154 NULL,
3155 LoadCursor(NULL, IDC_ARROW),
3156 (HBRUSH)(COLOR_BTNFACE+1),
3157 NULL,
3158 TEXT("WineStyleCheck"),
3161 atomStyleCheckClass = RegisterClass(&wc);
3164 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3166 DWORD dwActualStyle;
3167 DWORD dwActualExStyle;
3168 STYLESTRUCT ss;
3169 HWND hwnd;
3170 HWND hwndParent = NULL;
3172 ss.styleNew = dwStyleIn;
3173 ss.styleOld = dwExStyleIn;
3175 if (dwStyleIn & WS_CHILD)
3177 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
3178 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3181 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
3182 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3183 assert(hwnd);
3185 flush_events( TRUE );
3187 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3188 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3189 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3190 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3191 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3193 DestroyWindow(hwnd);
3194 if (hwndParent) DestroyWindow(hwndParent);
3197 /* tests what window styles the window manager automatically adds */
3198 static void test_window_styles(void)
3200 register_style_check_class();
3202 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3203 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3204 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3205 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3206 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3207 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3208 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3209 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3210 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3211 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3212 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3215 static void test_scrollvalidate( HWND parent)
3217 HDC hdc;
3218 HRGN hrgn=CreateRectRgn(0,0,0,0);
3219 HRGN exprgn, tmprgn, clipping;
3220 RECT rc, rcu, cliprc;
3221 /* create two overlapping child windows. The visual region
3222 * of hwnd1 is clipped by the overlapping part of
3223 * hwnd2 because of the WS_CLIPSIBLING style */
3224 HWND hwnd1, hwnd2;
3226 clipping = CreateRectRgn(0,0,0,0);
3227 tmprgn = CreateRectRgn(0,0,0,0);
3228 exprgn = CreateRectRgn(0,0,0,0);
3229 hwnd2 = CreateWindowExA(0, "static", NULL,
3230 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3231 75, 30, 100, 100, parent, 0, 0, NULL);
3232 hwnd1 = CreateWindowExA(0, "static", NULL,
3233 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3234 25, 50, 100, 100, parent, 0, 0, NULL);
3235 ShowWindow( parent, SW_SHOW);
3236 UpdateWindow( parent);
3237 GetClientRect( hwnd1, &rc);
3238 cliprc=rc;
3239 SetRectRgn( clipping, 10, 10, 90, 90);
3240 hdc = GetDC( hwnd1);
3241 /* for a visual touch */
3242 TextOut( hdc, 0,10, "0123456789", 10);
3243 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3244 if (winetest_debug > 0) dump_region(hrgn);
3245 /* create a region with what is expected */
3246 SetRectRgn( exprgn, 39,0,49,74);
3247 SetRectRgn( tmprgn, 88,79,98,93);
3248 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3249 SetRectRgn( tmprgn, 0,93,98,98);
3250 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3251 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3252 trace("update rect is %d,%d - %d,%d\n",
3253 rcu.left,rcu.top,rcu.right,rcu.bottom);
3254 /* now with clipping region */
3255 SelectClipRgn( hdc, clipping);
3256 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3257 if (winetest_debug > 0) dump_region(hrgn);
3258 /* create a region with what is expected */
3259 SetRectRgn( exprgn, 39,10,49,74);
3260 SetRectRgn( tmprgn, 80,79,90,85);
3261 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3262 SetRectRgn( tmprgn, 10,85,90,90);
3263 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3264 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3265 trace("update rect is %d,%d - %d,%d\n",
3266 rcu.left,rcu.top,rcu.right,rcu.bottom);
3267 ReleaseDC( hwnd1, hdc);
3269 /* test scrolling a window with an update region */
3270 DestroyWindow( hwnd2);
3271 ValidateRect( hwnd1, NULL);
3272 SetRect( &rc, 40,40, 50,50);
3273 InvalidateRect( hwnd1, &rc, 1);
3274 GetClientRect( hwnd1, &rc);
3275 cliprc=rc;
3276 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
3277 SW_SCROLLCHILDREN | SW_INVALIDATE);
3278 if (winetest_debug > 0) dump_region(hrgn);
3279 SetRectRgn( exprgn, 88,0,98,98);
3280 SetRectRgn( tmprgn, 30, 40, 50, 50);
3281 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3282 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3284 /* clear an update region */
3285 UpdateWindow( hwnd1 );
3287 SetRect( &rc, 0,40, 100,60);
3288 SetRect( &cliprc, 0,0, 100,100);
3289 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3290 if (winetest_debug > 0) dump_region( hrgn );
3291 SetRectRgn( exprgn, 0, 40, 98, 60 );
3292 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
3294 /* now test ScrollWindowEx with a combination of
3295 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3296 /* make hwnd2 the child of hwnd1 */
3297 hwnd2 = CreateWindowExA(0, "static", NULL,
3298 WS_CHILD| WS_VISIBLE | WS_BORDER ,
3299 50, 50, 100, 100, hwnd1, 0, 0, NULL);
3300 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
3301 GetClientRect( hwnd1, &rc);
3302 cliprc=rc;
3304 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3305 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3306 ValidateRect( hwnd1, NULL);
3307 ValidateRect( hwnd2, NULL);
3308 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
3309 SW_SCROLLCHILDREN | SW_INVALIDATE);
3310 if (winetest_debug > 0) dump_region(hrgn);
3311 SetRectRgn( exprgn, 88,0,98,88);
3312 SetRectRgn( tmprgn, 0,88,98,98);
3313 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3314 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3316 /* SW_SCROLLCHILDREN */
3317 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3318 ValidateRect( hwnd1, NULL);
3319 ValidateRect( hwnd2, NULL);
3320 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3321 if (winetest_debug > 0) dump_region(hrgn);
3322 /* expected region is the same as in previous test */
3323 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3325 /* no SW_SCROLLCHILDREN */
3326 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3327 ValidateRect( hwnd1, NULL);
3328 ValidateRect( hwnd2, NULL);
3329 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3330 if (winetest_debug > 0) dump_region(hrgn);
3331 /* expected region is the same as in previous test */
3332 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3334 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3335 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3336 ValidateRect( hwnd1, NULL);
3337 ValidateRect( hwnd2, NULL);
3338 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3339 if (winetest_debug > 0) dump_region(hrgn);
3340 SetRectRgn( exprgn, 88,0,98,20);
3341 SetRectRgn( tmprgn, 20,20,98,30);
3342 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3343 SetRectRgn( tmprgn, 20,30,30,88);
3344 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3345 SetRectRgn( tmprgn, 0,88,30,98);
3346 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3347 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3349 /* clean up */
3350 DeleteObject( hrgn);
3351 DeleteObject( exprgn);
3352 DeleteObject( tmprgn);
3353 DestroyWindow( hwnd1);
3354 DestroyWindow( hwnd2);
3357 /* couple of tests of return values of scrollbar functions
3358 * called on a scrollbarless window */
3359 static void test_scroll(void)
3361 BOOL ret;
3362 INT min, max;
3363 SCROLLINFO si;
3364 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3365 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3366 100, 100, 200, 200, 0, 0, 0, NULL);
3367 /* horizontal */
3368 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3369 if (!ret) /* win9x */
3371 win_skip( "GetScrollRange doesn't work\n" );
3372 DestroyWindow( hwnd);
3373 return;
3375 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3376 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3377 si.cbSize = sizeof( si);
3378 si.fMask = SIF_PAGE;
3379 si.nPage = 0xdeadbeef;
3380 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3381 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3382 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3383 /* vertical */
3384 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3385 ok( ret, "GetScrollRange returns FALSE\n");
3386 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3387 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3388 si.cbSize = sizeof( si);
3389 si.fMask = SIF_PAGE;
3390 si.nPage = 0xdeadbeef;
3391 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3392 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3393 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3394 /* clean up */
3395 DestroyWindow( hwnd);
3398 static void test_scrolldc( HWND parent)
3400 HDC hdc;
3401 HRGN exprgn, tmprgn, hrgn;
3402 RECT rc, rc2, rcu, cliprc;
3403 HWND hwnd1;
3404 COLORREF colr;
3406 hrgn = CreateRectRgn(0,0,0,0);
3407 tmprgn = CreateRectRgn(0,0,0,0);
3408 exprgn = CreateRectRgn(0,0,0,0);
3410 hwnd1 = CreateWindowExA(0, "static", NULL,
3411 WS_CHILD| WS_VISIBLE,
3412 25, 50, 100, 100, parent, 0, 0, NULL);
3413 ShowWindow( parent, SW_SHOW);
3414 UpdateWindow( parent);
3415 flush_events( TRUE );
3416 GetClientRect( hwnd1, &rc);
3417 hdc = GetDC( hwnd1);
3418 /* paint the upper half of the window black */
3419 rc2 = rc;
3420 rc2.bottom = ( rc.top + rc.bottom) /2;
3421 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3422 /* clip region is the lower half */
3423 cliprc=rc;
3424 cliprc.top = (rc.top + rc.bottom) /2;
3425 /* test whether scrolled pixels are properly clipped */
3426 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3427 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3428 /* this scroll should not cause any visible changes */
3429 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3430 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3431 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3432 /* test with NULL clip rect */
3433 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3434 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3435 trace("update rect: %d,%d - %d,%d\n",
3436 rcu.left, rcu.top, rcu.right, rcu.bottom);
3437 if (winetest_debug > 0) dump_region(hrgn);
3438 SetRect(&rc2, 0, 0, 100, 100);
3439 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3440 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3442 SetRectRgn( exprgn, 0, 0, 20, 80);
3443 SetRectRgn( tmprgn, 0, 80, 100, 100);
3444 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3445 if (winetest_debug > 0) dump_region(exprgn);
3446 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3447 /* test clip rect > scroll rect */
3448 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3449 rc2=rc;
3450 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3451 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3452 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3453 SetRectRgn( exprgn, 25, 25, 75, 35);
3454 SetRectRgn( tmprgn, 25, 35, 35, 75);
3455 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3456 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3457 trace("update rect: %d,%d - %d,%d\n",
3458 rcu.left, rcu.top, rcu.right, rcu.bottom);
3459 if (winetest_debug > 0) dump_region(hrgn);
3461 /* clean up */
3462 DeleteObject(hrgn);
3463 DeleteObject(exprgn);
3464 DeleteObject(tmprgn);
3465 DestroyWindow(hwnd1);
3468 static void test_params(void)
3470 HWND hwnd;
3471 INT rc;
3473 /* Just a param check */
3474 if (pGetMonitorInfoA)
3476 SetLastError(0xdeadbeef);
3477 rc = GetWindowText(hwndMain2, NULL, 1024);
3478 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
3480 else
3482 /* Skips actually on Win95 and NT4 */
3483 win_skip("Test would crash on Win95\n");
3486 SetLastError(0xdeadbeef);
3487 hwnd=CreateWindow("LISTBOX", "TestList",
3488 (LBS_STANDARD & ~LBS_SORT),
3489 0, 0, 100, 100,
3490 NULL, (HMENU)1, NULL, 0);
3492 ok(!hwnd || broken(hwnd != NULL), /* w2k3 sp2 */
3493 "CreateWindow with invalid menu handle should fail\n");
3494 if (!hwnd)
3495 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3496 GetLastError() == 0xdeadbeef, /* Win9x */
3497 "wrong last error value %d\n", GetLastError());
3500 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3502 HWND hwnd = 0;
3504 hwnd = CreateWindowEx(exStyle, class, class, style,
3505 110, 100,
3506 225, 200,
3508 menu ? hmenu : 0,
3509 0, 0);
3510 if (!hwnd) {
3511 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
3512 return;
3514 ShowWindow(hwnd, SW_SHOW);
3516 test_nonclient_area(hwnd);
3518 SetMenu(hwnd, 0);
3519 DestroyWindow(hwnd);
3522 static BOOL AWR_init(void)
3524 WNDCLASS class;
3526 class.style = CS_HREDRAW | CS_VREDRAW;
3527 class.lpfnWndProc = DefWindowProcA;
3528 class.cbClsExtra = 0;
3529 class.cbWndExtra = 0;
3530 class.hInstance = 0;
3531 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3532 class.hCursor = LoadCursor (0, IDC_ARROW);
3533 class.hbrBackground = 0;
3534 class.lpszMenuName = 0;
3535 class.lpszClassName = szAWRClass;
3537 if (!RegisterClass (&class)) {
3538 ok(FALSE, "RegisterClass failed\n");
3539 return FALSE;
3542 hmenu = CreateMenu();
3543 if (!hmenu)
3544 return FALSE;
3545 ok(hmenu != 0, "Failed to create menu\n");
3546 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3548 return TRUE;
3552 static void test_AWR_window_size(BOOL menu)
3554 LONG styles[] = {
3555 WS_POPUP,
3556 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3557 WS_SYSMENU,
3558 WS_THICKFRAME,
3559 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3560 WS_HSCROLL, WS_VSCROLL
3562 LONG exStyles[] = {
3563 WS_EX_CLIENTEDGE,
3564 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3565 WS_EX_APPWINDOW,
3566 #if 0
3567 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3568 WS_EX_DLGMODALFRAME,
3569 WS_EX_STATICEDGE,
3570 #endif
3573 int i;
3575 /* A exhaustive check of all the styles takes too long
3576 * so just do a (hopefully representative) sample
3578 for (i = 0; i < COUNTOF(styles); ++i)
3579 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3580 for (i = 0; i < COUNTOF(exStyles); ++i) {
3581 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3582 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3585 #undef COUNTOF
3587 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3589 static void test_AdjustWindowRect(void)
3591 if (!AWR_init())
3592 return;
3594 SHOWSYSMETRIC(SM_CYCAPTION);
3595 SHOWSYSMETRIC(SM_CYSMCAPTION);
3596 SHOWSYSMETRIC(SM_CYMENU);
3597 SHOWSYSMETRIC(SM_CXEDGE);
3598 SHOWSYSMETRIC(SM_CYEDGE);
3599 SHOWSYSMETRIC(SM_CXVSCROLL);
3600 SHOWSYSMETRIC(SM_CYHSCROLL);
3601 SHOWSYSMETRIC(SM_CXFRAME);
3602 SHOWSYSMETRIC(SM_CYFRAME);
3603 SHOWSYSMETRIC(SM_CXDLGFRAME);
3604 SHOWSYSMETRIC(SM_CYDLGFRAME);
3605 SHOWSYSMETRIC(SM_CXBORDER);
3606 SHOWSYSMETRIC(SM_CYBORDER);
3608 test_AWR_window_size(FALSE);
3609 test_AWR_window_size(TRUE);
3611 DestroyMenu(hmenu);
3613 #undef SHOWSYSMETRIC
3616 /* Global variables to trigger exit from loop */
3617 static int redrawComplete, WMPAINT_count;
3619 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3621 switch (msg)
3623 case WM_PAINT:
3624 trace("doing WM_PAINT %d\n", WMPAINT_count);
3625 WMPAINT_count++;
3626 if (WMPAINT_count > 10 && redrawComplete == 0) {
3627 PAINTSTRUCT ps;
3628 BeginPaint(hwnd, &ps);
3629 EndPaint(hwnd, &ps);
3630 return 1;
3632 return 0;
3634 return DefWindowProc(hwnd, msg, wparam, lparam);
3637 /* Ensure we exit from RedrawNow regardless of invalidated area */
3638 static void test_redrawnow(void)
3640 WNDCLASSA cls;
3641 HWND hwndMain;
3643 cls.style = CS_DBLCLKS;
3644 cls.lpfnWndProc = redraw_window_procA;
3645 cls.cbClsExtra = 0;
3646 cls.cbWndExtra = 0;
3647 cls.hInstance = GetModuleHandleA(0);
3648 cls.hIcon = 0;
3649 cls.hCursor = LoadCursorA(0, IDC_ARROW);
3650 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3651 cls.lpszMenuName = NULL;
3652 cls.lpszClassName = "RedrawWindowClass";
3654 if(!RegisterClassA(&cls)) {
3655 trace("Register failed %d\n", GetLastError());
3656 return;
3659 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3660 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3662 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3663 ShowWindow(hwndMain, SW_SHOW);
3664 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3665 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3666 ok( WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
3667 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3668 redrawComplete = TRUE;
3669 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3671 /* clean up */
3672 DestroyWindow( hwndMain);
3675 struct parentdc_stat {
3676 RECT client;
3677 RECT clip;
3678 RECT paint;
3681 struct parentdc_test {
3682 struct parentdc_stat main, main_todo;
3683 struct parentdc_stat child1, child1_todo;
3684 struct parentdc_stat child2, child2_todo;
3687 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3689 RECT rc;
3690 PAINTSTRUCT ps;
3692 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3694 switch (msg)
3696 case WM_PAINT:
3697 GetClientRect(hwnd, &rc);
3698 CopyRect(&t->client, &rc);
3699 GetWindowRect(hwnd, &rc);
3700 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd,
3701 t->client.left, t->client.top, t->client.right, t->client.bottom,
3702 rc.left, rc.top, rc.right, rc.bottom);
3703 BeginPaint(hwnd, &ps);
3704 CopyRect(&t->paint, &ps.rcPaint);
3705 GetClipBox(ps.hdc, &rc);
3706 CopyRect(&t->clip, &rc);
3707 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
3708 rc.left, rc.top, rc.right, rc.bottom,
3709 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3710 EndPaint(hwnd, &ps);
3711 return 0;
3713 return DefWindowProc(hwnd, msg, wparam, lparam);
3716 static void zero_parentdc_stat(struct parentdc_stat *t)
3718 SetRectEmpty(&t->client);
3719 SetRectEmpty(&t->clip);
3720 SetRectEmpty(&t->paint);
3723 static void zero_parentdc_test(struct parentdc_test *t)
3725 zero_parentdc_stat(&t->main);
3726 zero_parentdc_stat(&t->child1);
3727 zero_parentdc_stat(&t->child2);
3730 #define parentdc_field_ok(t, w, r, f, got) \
3731 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3732 ": expected %d, got %d\n", \
3733 t.w.r.f, got.w.r.f)
3735 #define parentdc_todo_field_ok(t, w, r, f, got) \
3736 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3737 else parentdc_field_ok(t, w, r, f, got)
3739 #define parentdc_rect_ok(t, w, r, got) \
3740 parentdc_todo_field_ok(t, w, r, left, got); \
3741 parentdc_todo_field_ok(t, w, r, top, got); \
3742 parentdc_todo_field_ok(t, w, r, right, got); \
3743 parentdc_todo_field_ok(t, w, r, bottom, got);
3745 #define parentdc_win_ok(t, w, got) \
3746 parentdc_rect_ok(t, w, client, got); \
3747 parentdc_rect_ok(t, w, clip, got); \
3748 parentdc_rect_ok(t, w, paint, got);
3750 #define parentdc_ok(t, got) \
3751 parentdc_win_ok(t, main, got); \
3752 parentdc_win_ok(t, child1, got); \
3753 parentdc_win_ok(t, child2, got);
3755 static void test_csparentdc(void)
3757 WNDCLASSA clsMain, cls;
3758 HWND hwndMain, hwnd1, hwnd2;
3759 RECT rc;
3761 struct parentdc_test test_answer;
3763 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3764 const struct parentdc_test test1 =
3766 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
3767 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3768 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3771 const struct parentdc_test test2 =
3773 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
3774 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3775 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3778 const struct parentdc_test test3 =
3780 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3781 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3782 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3785 const struct parentdc_test test4 =
3787 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
3788 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
3789 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3792 const struct parentdc_test test5 =
3794 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
3795 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3796 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3799 const struct parentdc_test test6 =
3801 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3802 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3803 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3806 const struct parentdc_test test7 =
3808 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3809 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3810 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3812 #undef nothing_todo
3814 clsMain.style = CS_DBLCLKS;
3815 clsMain.lpfnWndProc = parentdc_window_procA;
3816 clsMain.cbClsExtra = 0;
3817 clsMain.cbWndExtra = 0;
3818 clsMain.hInstance = GetModuleHandleA(0);
3819 clsMain.hIcon = 0;
3820 clsMain.hCursor = LoadCursorA(0, IDC_ARROW);
3821 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
3822 clsMain.lpszMenuName = NULL;
3823 clsMain.lpszClassName = "ParentDcMainWindowClass";
3825 if(!RegisterClassA(&clsMain)) {
3826 trace("Register failed %d\n", GetLastError());
3827 return;
3830 cls.style = CS_DBLCLKS | CS_PARENTDC;
3831 cls.lpfnWndProc = parentdc_window_procA;
3832 cls.cbClsExtra = 0;
3833 cls.cbWndExtra = 0;
3834 cls.hInstance = GetModuleHandleA(0);
3835 cls.hIcon = 0;
3836 cls.hCursor = LoadCursorA(0, IDC_ARROW);
3837 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3838 cls.lpszMenuName = NULL;
3839 cls.lpszClassName = "ParentDcWindowClass";
3841 if(!RegisterClassA(&cls)) {
3842 trace("Register failed %d\n", GetLastError());
3843 return;
3846 SetRect(&rc, 0, 0, 150, 150);
3847 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
3848 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3849 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
3850 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
3851 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
3852 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
3853 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
3854 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
3855 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
3856 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
3857 ShowWindow(hwndMain, SW_SHOW);
3858 ShowWindow(hwnd1, SW_SHOW);
3859 ShowWindow(hwnd2, SW_SHOW);
3860 SetWindowPos(hwndMain, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
3861 flush_events( TRUE );
3863 zero_parentdc_test(&test_answer);
3864 InvalidateRect(hwndMain, NULL, TRUE);
3865 flush_events( TRUE );
3866 parentdc_ok(test1, test_answer);
3868 zero_parentdc_test(&test_answer);
3869 SetRect(&rc, 0, 0, 50, 50);
3870 InvalidateRect(hwndMain, &rc, TRUE);
3871 flush_events( TRUE );
3872 parentdc_ok(test2, test_answer);
3874 zero_parentdc_test(&test_answer);
3875 SetRect(&rc, 0, 0, 10, 10);
3876 InvalidateRect(hwndMain, &rc, TRUE);
3877 flush_events( TRUE );
3878 parentdc_ok(test3, test_answer);
3880 zero_parentdc_test(&test_answer);
3881 SetRect(&rc, 40, 40, 50, 50);
3882 InvalidateRect(hwndMain, &rc, TRUE);
3883 flush_events( TRUE );
3884 parentdc_ok(test4, test_answer);
3886 zero_parentdc_test(&test_answer);
3887 SetRect(&rc, 20, 20, 60, 60);
3888 InvalidateRect(hwndMain, &rc, TRUE);
3889 flush_events( TRUE );
3890 parentdc_ok(test5, test_answer);
3892 zero_parentdc_test(&test_answer);
3893 SetRect(&rc, 0, 0, 10, 10);
3894 InvalidateRect(hwnd1, &rc, TRUE);
3895 flush_events( TRUE );
3896 parentdc_ok(test6, test_answer);
3898 zero_parentdc_test(&test_answer);
3899 SetRect(&rc, -5, -5, 65, 65);
3900 InvalidateRect(hwnd1, &rc, TRUE);
3901 flush_events( TRUE );
3902 parentdc_ok(test7, test_answer);
3904 DestroyWindow(hwndMain);
3905 DestroyWindow(hwnd1);
3906 DestroyWindow(hwnd2);
3909 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3911 return DefWindowProcA(hwnd, msg, wparam, lparam);
3914 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3916 return DefWindowProcW(hwnd, msg, wparam, lparam);
3919 static void test_IsWindowUnicode(void)
3921 static const char ansi_class_nameA[] = "ansi class name";
3922 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3923 static const char unicode_class_nameA[] = "unicode class name";
3924 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3925 WNDCLASSA classA;
3926 WNDCLASSW classW;
3927 HWND hwnd;
3929 memset(&classW, 0, sizeof(classW));
3930 classW.hInstance = GetModuleHandleA(0);
3931 classW.lpfnWndProc = def_window_procW;
3932 classW.lpszClassName = unicode_class_nameW;
3933 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
3935 memset(&classA, 0, sizeof(classA));
3936 classA.hInstance = GetModuleHandleA(0);
3937 classA.lpfnWndProc = def_window_procA;
3938 classA.lpszClassName = ansi_class_nameA;
3939 assert(RegisterClassA(&classA));
3941 /* unicode class: window proc */
3942 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3943 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3944 assert(hwnd);
3946 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3947 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3948 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3949 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3950 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3952 DestroyWindow(hwnd);
3954 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3955 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3956 assert(hwnd);
3958 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3959 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3960 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3961 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3962 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3964 DestroyWindow(hwnd);
3966 /* ansi class: window proc */
3967 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3968 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3969 assert(hwnd);
3971 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3972 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3973 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3974 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3975 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3977 DestroyWindow(hwnd);
3979 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3980 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3981 assert(hwnd);
3983 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3984 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3985 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3986 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3987 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3989 DestroyWindow(hwnd);
3991 /* unicode class: class proc */
3992 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3993 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3994 assert(hwnd);
3996 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3997 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3998 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3999 /* do not restore class window proc back to unicode */
4001 DestroyWindow(hwnd);
4003 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4004 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4005 assert(hwnd);
4007 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4008 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4009 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4011 DestroyWindow(hwnd);
4013 /* ansi class: class proc */
4014 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4015 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4016 assert(hwnd);
4018 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4019 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4020 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4021 /* do not restore class window proc back to ansi */
4023 DestroyWindow(hwnd);
4025 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4026 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4027 assert(hwnd);
4029 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4030 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4031 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4033 DestroyWindow(hwnd);
4036 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4038 MINMAXINFO *minmax;
4040 if (msg != WM_GETMINMAXINFO)
4041 return DefWindowProc(hwnd, msg, wp, lp);
4043 minmax = (MINMAXINFO *)lp;
4045 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
4047 minmax->ptReserved.x = 0;
4048 minmax->ptReserved.y = 0;
4049 minmax->ptMaxSize.x = 400;
4050 minmax->ptMaxSize.y = 400;
4051 minmax->ptMaxPosition.x = 300;
4052 minmax->ptMaxPosition.y = 300;
4053 minmax->ptMaxTrackSize.x = 200;
4054 minmax->ptMaxTrackSize.y = 200;
4055 minmax->ptMinTrackSize.x = 100;
4056 minmax->ptMinTrackSize.y = 100;
4058 else
4059 DefWindowProc(hwnd, msg, wp, lp);
4060 return 1;
4063 static int expected_cx, expected_cy;
4064 static RECT expected_rect, broken_rect;
4066 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4068 switch(msg)
4070 case WM_GETMINMAXINFO:
4072 RECT rect;
4073 GetWindowRect( hwnd, &rect );
4074 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
4075 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4076 return DefWindowProc(hwnd, msg, wp, lp);
4078 case WM_NCCREATE:
4079 case WM_CREATE:
4081 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
4082 RECT rect;
4083 GetWindowRect( hwnd, &rect );
4084 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
4085 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
4086 ok( cs->cx == expected_cx || broken(cs->cx == (short)expected_cx),
4087 "wrong x size %d/%d\n", cs->cx, expected_cx );
4088 ok( cs->cy == expected_cy || broken(cs->cy == (short)expected_cy),
4089 "wrong y size %d/%d\n", cs->cy, expected_cy );
4090 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
4091 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
4092 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
4093 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top) ||
4094 broken( rect.right - rect.left == (short)broken_rect.right - (short)broken_rect.left &&
4095 rect.bottom - rect.top == (short)broken_rect.bottom - (short)broken_rect.top),
4096 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
4097 rect.left, rect.top, rect.right, rect.bottom,
4098 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
4099 return DefWindowProc(hwnd, msg, wp, lp);
4101 case WM_NCCALCSIZE:
4103 RECT rect, *r = (RECT *)lp;
4104 GetWindowRect( hwnd, &rect );
4105 ok( !memcmp( &rect, r, sizeof(rect) ),
4106 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
4107 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
4108 return DefWindowProc(hwnd, msg, wp, lp);
4110 default:
4111 return DefWindowProc(hwnd, msg, wp, lp);
4115 static void test_CreateWindow(void)
4117 WNDCLASS cls;
4118 HWND hwnd, parent;
4119 HMENU hmenu;
4120 RECT rc, rc_minmax;
4121 MINMAXINFO minmax;
4123 #define expect_menu(window, menu) \
4124 SetLastError(0xdeadbeef); \
4125 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
4127 #define expect_style(window, style)\
4128 ok((ULONG)GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
4130 #define expect_ex_style(window, ex_style)\
4131 ok((ULONG)GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
4133 #define expect_gle_broken_9x(gle)\
4134 ok(GetLastError() == gle ||\
4135 broken(GetLastError() == 0xdeadbeef),\
4136 "IsMenu set error %d\n", GetLastError())
4138 hmenu = CreateMenu();
4139 assert(hmenu != 0);
4140 parent = GetDesktopWindow();
4141 assert(parent != 0);
4143 SetLastError(0xdeadbeef);
4144 ok(IsMenu(hmenu), "IsMenu error %d\n", GetLastError());
4146 /* WS_CHILD */
4147 SetLastError(0xdeadbeef);
4148 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
4149 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4150 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4151 expect_menu(hwnd, 1);
4152 expect_style(hwnd, WS_CHILD);
4153 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4154 DestroyWindow(hwnd);
4156 SetLastError(0xdeadbeef);
4157 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
4158 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4159 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4160 expect_menu(hwnd, 1);
4161 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4162 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4163 DestroyWindow(hwnd);
4165 SetLastError(0xdeadbeef);
4166 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
4167 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4168 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4169 expect_menu(hwnd, 1);
4170 expect_style(hwnd, WS_CHILD);
4171 expect_ex_style(hwnd, 0);
4172 DestroyWindow(hwnd);
4174 SetLastError(0xdeadbeef);
4175 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
4176 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4177 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4178 expect_menu(hwnd, 1);
4179 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4180 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4181 DestroyWindow(hwnd);
4183 /* WS_POPUP */
4184 SetLastError(0xdeadbeef);
4185 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4186 0, 0, 100, 100, parent, hmenu, 0, NULL);
4187 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4188 expect_menu(hwnd, hmenu);
4189 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4190 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4191 DestroyWindow(hwnd);
4192 SetLastError(0xdeadbeef);
4193 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4194 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4196 hmenu = CreateMenu();
4197 assert(hmenu != 0);
4198 SetLastError(0xdeadbeef);
4199 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
4200 0, 0, 100, 100, parent, hmenu, 0, NULL);
4201 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4202 expect_menu(hwnd, hmenu);
4203 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4204 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4205 DestroyWindow(hwnd);
4206 SetLastError(0xdeadbeef);
4207 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4208 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4210 hmenu = CreateMenu();
4211 assert(hmenu != 0);
4212 SetLastError(0xdeadbeef);
4213 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
4214 0, 0, 100, 100, parent, hmenu, 0, NULL);
4215 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4216 expect_menu(hwnd, hmenu);
4217 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4218 expect_ex_style(hwnd, 0);
4219 DestroyWindow(hwnd);
4220 SetLastError(0xdeadbeef);
4221 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4222 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4224 hmenu = CreateMenu();
4225 assert(hmenu != 0);
4226 SetLastError(0xdeadbeef);
4227 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
4228 0, 0, 100, 100, parent, hmenu, 0, NULL);
4229 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4230 expect_menu(hwnd, hmenu);
4231 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4232 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4233 DestroyWindow(hwnd);
4234 SetLastError(0xdeadbeef);
4235 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4236 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4238 /* WS_CHILD | WS_POPUP */
4239 SetLastError(0xdeadbeef);
4240 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4241 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4242 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4243 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4244 if (hwnd)
4245 DestroyWindow(hwnd);
4247 hmenu = CreateMenu();
4248 assert(hmenu != 0);
4249 SetLastError(0xdeadbeef);
4250 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4251 0, 0, 100, 100, parent, hmenu, 0, NULL);
4252 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4253 expect_menu(hwnd, hmenu);
4254 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4255 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4256 DestroyWindow(hwnd);
4257 SetLastError(0xdeadbeef);
4258 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4259 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4261 SetLastError(0xdeadbeef);
4262 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4263 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4264 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4265 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4266 if (hwnd)
4267 DestroyWindow(hwnd);
4269 hmenu = CreateMenu();
4270 assert(hmenu != 0);
4271 SetLastError(0xdeadbeef);
4272 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4273 0, 0, 100, 100, parent, hmenu, 0, NULL);
4274 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4275 expect_menu(hwnd, hmenu);
4276 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4277 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4278 DestroyWindow(hwnd);
4279 SetLastError(0xdeadbeef);
4280 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4281 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4283 SetLastError(0xdeadbeef);
4284 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4285 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4286 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4287 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4288 if (hwnd)
4289 DestroyWindow(hwnd);
4291 hmenu = CreateMenu();
4292 assert(hmenu != 0);
4293 SetLastError(0xdeadbeef);
4294 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4295 0, 0, 100, 100, parent, hmenu, 0, NULL);
4296 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4297 expect_menu(hwnd, hmenu);
4298 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4299 expect_ex_style(hwnd, 0);
4300 DestroyWindow(hwnd);
4301 SetLastError(0xdeadbeef);
4302 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4303 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4305 SetLastError(0xdeadbeef);
4306 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4307 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4308 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4309 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4310 if (hwnd)
4311 DestroyWindow(hwnd);
4313 hmenu = CreateMenu();
4314 assert(hmenu != 0);
4315 SetLastError(0xdeadbeef);
4316 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4317 0, 0, 100, 100, parent, hmenu, 0, NULL);
4318 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4319 expect_menu(hwnd, hmenu);
4320 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4321 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4322 DestroyWindow(hwnd);
4323 SetLastError(0xdeadbeef);
4324 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4325 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4327 /* test child window sizing */
4328 cls.style = 0;
4329 cls.lpfnWndProc = minmax_wnd_proc;
4330 cls.cbClsExtra = 0;
4331 cls.cbWndExtra = 0;
4332 cls.hInstance = GetModuleHandle(0);
4333 cls.hIcon = 0;
4334 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4335 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4336 cls.lpszMenuName = NULL;
4337 cls.lpszClassName = "MinMax_WndClass";
4338 RegisterClass(&cls);
4340 SetLastError(0xdeadbeef);
4341 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4342 0, 0, 100, 100, 0, 0, 0, NULL);
4343 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4344 expect_menu(parent, 0);
4345 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
4346 expect_ex_style(parent, WS_EX_WINDOWEDGE);
4348 memset(&minmax, 0, sizeof(minmax));
4349 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4350 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
4351 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
4352 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4353 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
4355 GetWindowRect(parent, &rc);
4356 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
4357 GetClientRect(parent, &rc);
4358 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
4360 InflateRect(&rc, 200, 200);
4361 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4363 SetLastError(0xdeadbeef);
4364 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4365 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
4366 parent, (HMENU)1, 0, NULL);
4367 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4368 expect_menu(hwnd, 1);
4369 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
4370 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4372 memset(&minmax, 0, sizeof(minmax));
4373 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4374 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4376 GetWindowRect(hwnd, &rc);
4377 OffsetRect(&rc, -rc.left, -rc.top);
4378 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4379 rc.left, rc.top, rc.right, rc.bottom,
4380 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
4381 DestroyWindow(hwnd);
4383 cls.lpfnWndProc = winsizes_wnd_proc;
4384 cls.lpszClassName = "Sizes_WndClass";
4385 RegisterClass(&cls);
4387 expected_cx = expected_cy = 200000;
4388 SetRect( &expected_rect, 0, 0, 200000, 200000 );
4389 broken_rect = expected_rect;
4390 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
4391 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4392 GetClientRect( hwnd, &rc );
4393 ok( rc.right == 200000 || broken(rc.right == (short)200000), "invalid rect right %u\n", rc.right );
4394 ok( rc.bottom == 200000 || broken(rc.bottom == (short)200000), "invalid rect bottom %u\n", rc.bottom );
4395 DestroyWindow(hwnd);
4397 expected_cx = expected_cy = -10;
4398 SetRect( &expected_rect, 0, 0, 0, 0 );
4399 SetRect( &broken_rect, 0, 0, -10, -10 );
4400 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
4401 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4402 GetClientRect( hwnd, &rc );
4403 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4404 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4405 DestroyWindow(hwnd);
4407 expected_cx = expected_cy = -200000;
4408 SetRect( &expected_rect, 0, 0, 0, 0 );
4409 SetRect( &broken_rect, 0, 0, -200000, -200000 );
4410 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
4411 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4412 GetClientRect( hwnd, &rc );
4413 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4414 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4415 DestroyWindow(hwnd);
4417 /* we need a parent at 0,0 so that child coordinates match */
4418 DestroyWindow(parent);
4419 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
4420 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4422 expected_cx = 100;
4423 expected_cy = 0x7fffffff;
4424 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
4425 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
4426 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
4427 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4428 GetClientRect( hwnd, &rc );
4429 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
4430 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4431 DestroyWindow(hwnd);
4433 expected_cx = 0x7fffffff;
4434 expected_cy = 0x7fffffff;
4435 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
4436 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
4437 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
4438 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4439 GetClientRect( hwnd, &rc );
4440 ok( rc.right == 0x7fffffff - 20 || broken(rc.right == 0), "invalid rect right %u\n", rc.right );
4441 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4442 DestroyWindow(hwnd);
4444 /* top level window */
4445 expected_cx = expected_cy = 200000;
4446 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
4447 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
4448 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4449 GetClientRect( hwnd, &rc );
4450 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
4451 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
4452 DestroyWindow(hwnd);
4454 DestroyWindow(parent);
4456 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4457 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4459 #undef expect_gle_broken_9x
4460 #undef expect_menu
4461 #undef expect_style
4462 #undef expect_ex_style
4465 /* function that remembers whether the system the test is running on sets the
4466 * last error for user32 functions to make the tests stricter */
4467 static int check_error(DWORD actual, DWORD expected)
4469 static int sets_last_error = -1;
4470 if (sets_last_error == -1)
4471 sets_last_error = (actual != 0xdeadbeef);
4472 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
4475 static void test_SetWindowLong(void)
4477 LONG_PTR retval;
4478 WNDPROC old_window_procW;
4480 SetLastError(0xdeadbeef);
4481 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
4482 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
4483 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
4484 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4486 SetLastError(0xdeadbeef);
4487 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
4488 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
4489 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
4490 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4492 SetLastError(0xdeadbeef);
4493 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4494 ok((WNDPROC)retval == main_window_procA || broken(!retval), /* win9x */
4495 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
4496 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4497 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
4498 ok((WNDPROC)retval == main_window_procA,
4499 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4500 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
4502 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
4503 SetLastError(0xdeadbeef);
4504 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
4505 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
4507 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4508 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
4509 ok((WNDPROC)retval == old_window_procW,
4510 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4511 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
4513 /* set it back to ANSI */
4514 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4518 static void test_ShowWindow(void)
4520 HWND hwnd;
4521 DWORD style;
4522 RECT rcMain, rc;
4523 LPARAM ret;
4525 SetRect(&rcMain, 120, 120, 210, 210);
4527 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
4528 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4529 WS_MAXIMIZEBOX | WS_POPUP,
4530 rcMain.left, rcMain.top,
4531 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
4532 0, 0, 0, NULL);
4533 assert(hwnd);
4535 style = GetWindowLong(hwnd, GWL_STYLE);
4536 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4537 ok(!(style & WS_VISIBLE), "window should not be visible\n");
4538 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4539 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4540 GetWindowRect(hwnd, &rc);
4541 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4542 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4543 rc.left, rc.top, rc.right, rc.bottom);
4545 ret = ShowWindow(hwnd, SW_SHOW);
4546 ok(!ret, "not expected ret: %lu\n", ret);
4547 style = GetWindowLong(hwnd, GWL_STYLE);
4548 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4549 ok(style & WS_VISIBLE, "window should be visible\n");
4550 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4551 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4552 GetWindowRect(hwnd, &rc);
4553 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4554 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4555 rc.left, rc.top, rc.right, rc.bottom);
4557 ret = ShowWindow(hwnd, SW_MINIMIZE);
4558 ok(ret, "not expected ret: %lu\n", ret);
4559 style = GetWindowLong(hwnd, GWL_STYLE);
4560 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4561 ok(style & WS_VISIBLE, "window should be visible\n");
4562 ok(style & WS_MINIMIZE, "window should be minimized\n");
4563 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4564 GetWindowRect(hwnd, &rc);
4565 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4567 ShowWindow(hwnd, SW_RESTORE);
4568 ok(ret, "not expected ret: %lu\n", ret);
4569 style = GetWindowLong(hwnd, GWL_STYLE);
4570 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4571 ok(style & WS_VISIBLE, "window should be visible\n");
4572 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4573 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4574 GetWindowRect(hwnd, &rc);
4575 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4576 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4577 rc.left, rc.top, rc.right, rc.bottom);
4579 ret = EnableWindow(hwnd, FALSE);
4580 ok(!ret, "not expected ret: %lu\n", ret);
4581 style = GetWindowLong(hwnd, GWL_STYLE);
4582 ok(style & WS_DISABLED, "window should be disabled\n");
4584 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
4585 ok(!ret, "not expected ret: %lu\n", ret);
4586 style = GetWindowLong(hwnd, GWL_STYLE);
4587 ok(style & WS_DISABLED, "window should be disabled\n");
4588 ok(style & WS_VISIBLE, "window should be visible\n");
4589 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4590 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4591 GetWindowRect(hwnd, &rc);
4592 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4593 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4594 rc.left, rc.top, rc.right, rc.bottom);
4596 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
4597 ok(!ret, "not expected ret: %lu\n", ret);
4598 style = GetWindowLong(hwnd, GWL_STYLE);
4599 ok(style & WS_DISABLED, "window should be disabled\n");
4600 ok(style & WS_VISIBLE, "window should be visible\n");
4601 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4602 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4603 GetWindowRect(hwnd, &rc);
4604 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4605 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4606 rc.left, rc.top, rc.right, rc.bottom);
4608 ret = ShowWindow(hwnd, SW_MINIMIZE);
4609 ok(ret, "not expected ret: %lu\n", ret);
4610 style = GetWindowLong(hwnd, GWL_STYLE);
4611 ok(style & WS_DISABLED, "window should be disabled\n");
4612 ok(style & WS_VISIBLE, "window should be visible\n");
4613 ok(style & WS_MINIMIZE, "window should be minimized\n");
4614 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4615 GetWindowRect(hwnd, &rc);
4616 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4618 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
4619 ok(!ret, "not expected ret: %lu\n", ret);
4620 style = GetWindowLong(hwnd, GWL_STYLE);
4621 ok(style & WS_DISABLED, "window should be disabled\n");
4622 ok(style & WS_VISIBLE, "window should be visible\n");
4623 ok(style & WS_MINIMIZE, "window should be minimized\n");
4624 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4625 GetWindowRect(hwnd, &rc);
4626 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4628 ret = ShowWindow(hwnd, SW_RESTORE);
4629 ok(ret, "not expected ret: %lu\n", ret);
4630 style = GetWindowLong(hwnd, GWL_STYLE);
4631 ok(style & WS_DISABLED, "window should be disabled\n");
4632 ok(style & WS_VISIBLE, "window should be visible\n");
4633 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4634 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4635 GetWindowRect(hwnd, &rc);
4636 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4637 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4638 rc.left, rc.top, rc.right, rc.bottom);
4640 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4641 ok(!ret, "not expected ret: %lu\n", ret);
4642 ok(IsWindow(hwnd), "window should exist\n");
4644 ret = EnableWindow(hwnd, TRUE);
4645 ok(ret, "not expected ret: %lu\n", ret);
4647 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4648 ok(!ret, "not expected ret: %lu\n", ret);
4649 ok(!IsWindow(hwnd), "window should not exist\n");
4652 static void test_gettext(void)
4654 WNDCLASS cls;
4655 LPCSTR clsname = "gettexttest";
4656 HWND hwnd;
4657 LRESULT r;
4659 memset( &cls, 0, sizeof cls );
4660 cls.lpfnWndProc = DefWindowProc;
4661 cls.lpszClassName = clsname;
4662 cls.hInstance = GetModuleHandle(NULL);
4664 if (!RegisterClass( &cls )) return;
4666 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
4667 ok( hwnd != NULL, "window was null\n");
4669 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
4670 ok( r == 0, "settext should return zero\n");
4672 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
4673 ok( r == 0, "settext should return zero (%ld)\n", r);
4675 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
4676 ok( r == 0, "settext should return zero (%ld)\n", r);
4678 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
4679 ok( r == 0, "settext should return zero (%ld)\n", r);
4681 DestroyWindow(hwnd);
4682 UnregisterClass( clsname, NULL );
4686 static void test_GetUpdateRect(void)
4688 MSG msg;
4689 BOOL ret, parent_wm_paint, grandparent_wm_paint;
4690 RECT rc1, rc2;
4691 HWND hgrandparent, hparent, hchild;
4692 WNDCLASSA cls;
4693 static const char classNameA[] = "GetUpdateRectClass";
4695 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
4696 0, 0, 100, 100, NULL, NULL, 0, NULL);
4698 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
4699 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4701 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
4702 10, 10, 30, 30, hparent, NULL, 0, NULL);
4704 ShowWindow(hgrandparent, SW_SHOW);
4705 UpdateWindow(hgrandparent);
4706 flush_events( TRUE );
4708 ShowWindow(hchild, SW_HIDE);
4709 SetRect(&rc2, 0, 0, 0, 0);
4710 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4711 ok(!ret, "GetUpdateRect returned not empty region\n");
4712 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4713 rc1.left, rc1.top, rc1.right, rc1.bottom,
4714 rc2.left, rc2.top, rc2.right, rc2.bottom);
4716 SetRect(&rc2, 10, 10, 40, 40);
4717 ret = GetUpdateRect(hparent, &rc1, FALSE);
4718 ok(ret, "GetUpdateRect returned empty region\n");
4719 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4720 rc1.left, rc1.top, rc1.right, rc1.bottom,
4721 rc2.left, rc2.top, rc2.right, rc2.bottom);
4723 parent_wm_paint = FALSE;
4724 grandparent_wm_paint = FALSE;
4725 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4727 if (msg.message == WM_PAINT)
4729 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4730 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4732 DispatchMessage(&msg);
4734 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4735 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4737 DestroyWindow(hgrandparent);
4739 cls.style = 0;
4740 cls.lpfnWndProc = DefWindowProcA;
4741 cls.cbClsExtra = 0;
4742 cls.cbWndExtra = 0;
4743 cls.hInstance = GetModuleHandleA(0);
4744 cls.hIcon = 0;
4745 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4746 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4747 cls.lpszMenuName = NULL;
4748 cls.lpszClassName = classNameA;
4750 if(!RegisterClassA(&cls)) {
4751 trace("Register failed %d\n", GetLastError());
4752 return;
4755 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
4756 0, 0, 100, 100, NULL, NULL, 0, NULL);
4758 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
4759 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4761 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
4762 10, 10, 30, 30, hparent, NULL, 0, NULL);
4764 ShowWindow(hgrandparent, SW_SHOW);
4765 UpdateWindow(hgrandparent);
4766 flush_events( TRUE );
4768 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4769 ok(!ret, "GetUpdateRect returned not empty region\n");
4771 ShowWindow(hchild, SW_HIDE);
4773 SetRect(&rc2, 0, 0, 0, 0);
4774 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4775 ok(!ret, "GetUpdateRect returned not empty region\n");
4776 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4777 rc1.left, rc1.top, rc1.right, rc1.bottom,
4778 rc2.left, rc2.top, rc2.right, rc2.bottom);
4780 SetRect(&rc2, 10, 10, 40, 40);
4781 ret = GetUpdateRect(hparent, &rc1, FALSE);
4782 ok(ret, "GetUpdateRect returned empty region\n");
4783 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4784 rc1.left, rc1.top, rc1.right, rc1.bottom,
4785 rc2.left, rc2.top, rc2.right, rc2.bottom);
4787 parent_wm_paint = FALSE;
4788 grandparent_wm_paint = FALSE;
4789 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4791 if (msg.message == WM_PAINT)
4793 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4794 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4796 DispatchMessage(&msg);
4798 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4799 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4801 DestroyWindow(hgrandparent);
4805 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
4807 if(msg == WM_PAINT)
4809 PAINTSTRUCT ps;
4810 RECT updateRect;
4811 DWORD waitResult;
4812 HWND win;
4813 const int waitTime = 2000;
4815 BeginPaint(hwnd, &ps);
4817 /* create and destroy window to create an exposed region on this window */
4818 win = CreateWindowA("static", "win", WS_VISIBLE,
4819 10,10,50,50, NULL, NULL, 0, NULL);
4820 DestroyWindow(win);
4822 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
4824 ValidateRect(hwnd, NULL);
4825 EndPaint(hwnd, &ps);
4827 if(waitResult != WAIT_TIMEOUT)
4829 GetUpdateRect(hwnd, &updateRect, FALSE);
4830 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
4833 return 1;
4835 return DefWindowProc(hwnd, msg, wParam, lParam);
4838 static void test_Expose(void)
4840 ATOM atom;
4841 WNDCLASSA cls;
4842 HWND mw;
4843 memset(&cls, 0, sizeof(WNDCLASSA));
4844 cls.lpfnWndProc = TestExposedRegion_WndProc;
4845 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4846 cls.lpszClassName = "TestExposeClass";
4847 atom = RegisterClassA(&cls);
4849 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
4850 0, 0, 200, 100, NULL, NULL, 0, NULL);
4852 UpdateWindow(mw);
4853 DestroyWindow(mw);
4856 static void test_GetWindowModuleFileName(void)
4858 HWND hwnd;
4859 HINSTANCE hinst;
4860 UINT ret1, ret2;
4861 char buf1[MAX_PATH], buf2[MAX_PATH];
4863 if (!pGetWindowModuleFileNameA)
4865 win_skip("GetWindowModuleFileNameA is not available\n");
4866 return;
4869 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
4870 assert(hwnd);
4872 hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
4873 ok(hinst == 0 || broken(hinst == GetModuleHandle(0)), /* win9x */ "expected 0, got %p\n", hinst);
4875 buf1[0] = 0;
4876 SetLastError(0xdeadbeef);
4877 ret1 = GetModuleFileName(hinst, buf1, sizeof(buf1));
4878 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
4880 buf2[0] = 0;
4881 SetLastError(0xdeadbeef);
4882 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
4883 ok(ret2 || broken(!ret2), /* nt4 sp 3 */
4884 "GetWindowModuleFileNameA error %u\n", GetLastError());
4886 if (ret2)
4888 ok(ret1 == ret2 || broken(ret2 == ret1 + 1), /* win98 */ "%u != %u\n", ret1, ret2);
4889 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
4891 hinst = GetModuleHandle(0);
4893 SetLastError(0xdeadbeef);
4894 ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
4895 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
4896 "expected %u, got %u\n", ret1 - 2, ret2);
4897 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4898 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4899 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4901 SetLastError(0xdeadbeef);
4902 ret2 = GetModuleFileName(hinst, buf2, 0);
4903 ok(!ret2, "GetModuleFileName should return 0\n");
4904 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4905 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4906 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4908 SetLastError(0xdeadbeef);
4909 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
4910 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3) /* win98 */ || broken(!ret2), /* nt4 sp3 */
4911 "expected %u, got %u\n", ret1 - 2, ret2);
4912 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4913 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4914 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4916 SetLastError(0xdeadbeef);
4917 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
4918 ok(!ret2, "expected 0, got %u\n", ret2);
4919 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4920 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4921 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4923 DestroyWindow(hwnd);
4925 buf2[0] = 0;
4926 hwnd = (HWND)0xdeadbeef;
4927 SetLastError(0xdeadbeef);
4928 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4929 ok(!ret1, "expected 0, got %u\n", ret1);
4930 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef), /* win9x */
4931 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
4933 hwnd = FindWindow("Shell_TrayWnd", NULL);
4934 ok(IsWindow(hwnd) || broken(!hwnd), "got invalid tray window %p\n", hwnd);
4935 SetLastError(0xdeadbeef);
4936 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4937 ok(!ret1 || broken(ret1), /* win98 */ "expected 0, got %u\n", ret1);
4939 if (!ret1) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
4941 ret1 = GetModuleFileName(0, buf1, sizeof(buf1));
4942 hwnd = GetDesktopWindow();
4943 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
4944 SetLastError(0xdeadbeef);
4945 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
4946 ok(!ret2 ||
4947 ret1 == ret2 || /* vista */
4948 broken(ret2), /* some win98 return user.exe as file name */
4949 "expected 0 or %u, got %u %s\n", ret1, ret2, buf2);
4953 static void test_hwnd_message(void)
4955 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
4956 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
4958 HWND parent = 0, hwnd, found;
4959 RECT rect;
4961 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
4962 on CreateWindowExA and crash later in the test.
4963 Use UNICODE here to fail on win9x */
4964 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
4965 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
4966 if (!hwnd)
4968 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
4969 return;
4972 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
4973 if (pGetAncestor)
4975 char buffer[100];
4976 HWND root, desktop = GetDesktopWindow();
4978 parent = pGetAncestor(hwnd, GA_PARENT);
4979 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
4980 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
4981 root = pGetAncestor(hwnd, GA_ROOT);
4982 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
4983 ok( !pGetAncestor(parent, GA_PARENT) || broken(pGetAncestor(parent, GA_PARENT) != 0), /* win2k */
4984 "parent shouldn't have parent %p\n", pGetAncestor(parent, GA_PARENT) );
4985 trace("parent %p root %p desktop %p\n", parent, root, desktop);
4986 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
4987 ok( !lstrcmpi( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
4988 GetWindowRect( parent, &rect );
4989 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
4990 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4992 GetWindowRect( hwnd, &rect );
4993 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
4994 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4996 /* test FindWindow behavior */
4998 found = FindWindowExA( 0, 0, 0, "message window" );
4999 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
5000 SetLastError(0xdeadbeef);
5001 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
5002 ok( found == 0, "found message window %p/%p\n", found, hwnd );
5003 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
5004 if (parent)
5006 found = FindWindowExA( parent, 0, 0, "message window" );
5007 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
5010 /* test IsChild behavior */
5012 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
5014 /* test IsWindowVisible behavior */
5016 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
5017 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
5019 DestroyWindow(hwnd);
5022 static void test_layered_window(void)
5024 HWND hwnd;
5025 COLORREF key = 0;
5026 BYTE alpha = 0;
5027 DWORD flags = 0;
5028 BOOL ret;
5030 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes)
5032 win_skip( "layered windows not supported\n" );
5033 return;
5035 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
5036 100, 100, 200, 200, 0, 0, 0, NULL);
5037 assert( hwnd );
5038 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5039 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
5040 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
5041 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
5042 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5043 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5044 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5045 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
5046 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5047 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5048 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5049 ok( key == 0x123456 || key == 0, "wrong color key %x\n", key );
5050 ok( alpha == 44, "wrong alpha %u\n", alpha );
5051 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
5053 /* clearing WS_EX_LAYERED resets attributes */
5054 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5055 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5056 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
5057 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5058 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5059 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5060 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
5061 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5062 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5063 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5064 ok( key == 0x654321, "wrong color key %x\n", key );
5065 ok( alpha == 22, "wrong alpha %u\n", alpha );
5066 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
5068 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
5069 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5070 alpha = 0;
5071 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5072 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5073 ok( key == 0x888888, "wrong color key %x\n", key );
5074 /* alpha not changed on vista if LWA_ALPHA is not set */
5075 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
5076 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
5078 /* color key may or may not be changed without LWA_COLORKEY */
5079 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
5080 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5081 alpha = 0;
5082 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5083 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5084 ok( key == 0x888888 || key == 0x999999, "wrong color key %x\n", key );
5085 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
5086 ok( flags == 0, "wrong flags %x\n", flags );
5088 /* default alpha and color key is 0 */
5089 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5090 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5091 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
5092 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5093 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5094 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5095 ok( key == 0 || key == 0x222222, "wrong color key %x\n", key );
5096 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
5097 ok( flags == 0, "wrong flags %x\n", flags );
5099 DestroyWindow( hwnd );
5102 static MONITORINFO mi;
5104 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
5106 switch (msg)
5108 case WM_NCCREATE:
5110 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
5111 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs->x, cs->y, cs->cx, cs->cy);
5112 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
5113 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
5114 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
5115 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5116 cs->x, cs->y, cs->cx, cs->cy);
5117 break;
5119 case WM_GETMINMAXINFO:
5121 MINMAXINFO *minmax = (MINMAXINFO *)lp;
5122 dump_minmax_info(minmax);
5123 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
5124 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
5125 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
5126 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
5127 break;
5130 return DefWindowProc(hwnd, msg, wp, lp);
5133 static void test_fullscreen(void)
5135 static const DWORD t_style[] = {
5136 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
5138 static const DWORD t_ex_style[] = {
5139 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
5141 WNDCLASS cls;
5142 HWND hwnd;
5143 int i, j;
5144 POINT pt;
5145 RECT rc;
5146 HMONITOR hmon;
5147 LRESULT ret;
5149 if (!pGetMonitorInfoA || !pMonitorFromPoint)
5151 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
5152 return;
5155 pt.x = pt.y = 0;
5156 SetLastError(0xdeadbeef);
5157 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
5158 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
5160 mi.cbSize = sizeof(mi);
5161 SetLastError(0xdeadbeef);
5162 ret = pGetMonitorInfoA(hmon, &mi);
5163 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
5164 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
5165 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5166 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5168 cls.style = 0;
5169 cls.lpfnWndProc = fullscreen_wnd_proc;
5170 cls.cbClsExtra = 0;
5171 cls.cbWndExtra = 0;
5172 cls.hInstance = GetModuleHandle(0);
5173 cls.hIcon = 0;
5174 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5175 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5176 cls.lpszMenuName = NULL;
5177 cls.lpszClassName = "fullscreen_class";
5178 RegisterClass(&cls);
5180 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
5182 DWORD style, ex_style;
5184 /* avoid a WM interaction */
5185 assert(!(t_style[i] & WS_VISIBLE));
5187 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
5189 int fixup;
5191 style = t_style[i];
5192 ex_style = t_ex_style[j];
5194 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5195 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5196 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5197 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5198 GetWindowRect(hwnd, &rc);
5199 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5200 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5201 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5202 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5203 DestroyWindow(hwnd);
5205 style = t_style[i] | WS_MAXIMIZE;
5206 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5207 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5208 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5209 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5210 GetWindowRect(hwnd, &rc);
5211 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5212 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5213 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5214 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5215 DestroyWindow(hwnd);
5217 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
5218 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5219 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5220 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5221 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5222 GetWindowRect(hwnd, &rc);
5223 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5224 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5225 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5226 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5227 DestroyWindow(hwnd);
5229 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
5230 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5231 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5232 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5233 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5234 GetWindowRect(hwnd, &rc);
5235 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5236 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5237 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5238 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5239 DestroyWindow(hwnd);
5241 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
5242 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5243 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5244 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5245 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5246 GetWindowRect(hwnd, &rc);
5247 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5248 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5249 fixup = min(abs(rc.left), abs(rc.top));
5250 InflateRect(&rc, -fixup, -fixup);
5251 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5252 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5253 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
5254 ex_style, style, rc.left, rc.top, rc.right, rc.bottom,
5255 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5256 DestroyWindow(hwnd);
5258 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
5259 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5260 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5261 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5262 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5263 GetWindowRect(hwnd, &rc);
5264 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5265 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5266 fixup = min(abs(rc.left), abs(rc.top));
5267 InflateRect(&rc, -fixup, -fixup);
5268 if (style & (WS_CHILD | WS_POPUP))
5269 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5270 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5271 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5272 else
5273 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5274 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5275 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5276 DestroyWindow(hwnd);
5280 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5283 static BOOL test_thick_child_got_minmax;
5284 static const char * test_thick_child_name;
5285 static LONG test_thick_child_style;
5286 static LONG test_thick_child_exStyle;
5288 static LRESULT WINAPI test_thick_child_size_winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5290 MINMAXINFO* minmax;
5291 int expectedMinTrackX;
5292 int expectedMinTrackY;
5293 int actualMinTrackX;
5294 int actualMinTrackY;
5295 int expectedMaxTrackX;
5296 int expectedMaxTrackY;
5297 int actualMaxTrackX;
5298 int actualMaxTrackY;
5299 int expectedMaxSizeX;
5300 int expectedMaxSizeY;
5301 int actualMaxSizeX;
5302 int actualMaxSizeY;
5303 int expectedPosX;
5304 int expectedPosY;
5305 int actualPosX;
5306 int actualPosY;
5307 LONG adjustedStyle;
5308 RECT rect;
5309 switch (msg)
5311 case WM_GETMINMAXINFO:
5313 minmax = (MINMAXINFO *)lparam;
5314 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
5315 dump_minmax_info( minmax );
5317 test_thick_child_got_minmax = TRUE;
5320 adjustedStyle = test_thick_child_style;
5321 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
5322 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5323 GetClientRect(GetParent(hwnd), &rect);
5324 AdjustWindowRectEx(&rect, adjustedStyle, FALSE, test_thick_child_exStyle);
5326 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
5328 expectedMinTrackX = GetSystemMetrics(SM_CXMINTRACK);
5329 expectedMinTrackY = GetSystemMetrics(SM_CYMINTRACK);
5331 else
5333 expectedMinTrackX = -2 * rect.left;
5334 expectedMinTrackY = -2 * rect.top;
5336 actualMinTrackX = minmax->ptMinTrackSize.x;
5337 actualMinTrackY = minmax->ptMinTrackSize.y;
5339 ok(actualMinTrackX == expectedMinTrackX && actualMinTrackY == expectedMinTrackY,
5340 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
5341 expectedMinTrackX, expectedMinTrackY, actualMinTrackX, actualMinTrackY,
5342 test_thick_child_name);
5344 actualMaxTrackX = minmax->ptMaxTrackSize.x;
5345 actualMaxTrackY = minmax->ptMaxTrackSize.y;
5346 expectedMaxTrackX = GetSystemMetrics(SM_CXMAXTRACK);
5347 expectedMaxTrackY = GetSystemMetrics(SM_CYMAXTRACK);
5348 ok(actualMaxTrackX == expectedMaxTrackX && actualMaxTrackY == expectedMaxTrackY,
5349 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
5350 expectedMaxTrackX, expectedMaxTrackY, actualMaxTrackX, actualMaxTrackY,
5351 test_thick_child_name);
5353 expectedMaxSizeX = rect.right - rect.left;
5354 expectedMaxSizeY = rect.bottom - rect.top;
5355 actualMaxSizeX = minmax->ptMaxSize.x;
5356 actualMaxSizeY = minmax->ptMaxSize.y;
5358 ok(actualMaxSizeX == expectedMaxSizeX && actualMaxSizeY == expectedMaxSizeY,
5359 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
5360 expectedMaxSizeX, expectedMaxSizeY, actualMaxSizeX, actualMaxSizeY,
5361 test_thick_child_name);
5364 expectedPosX = rect.left;
5365 expectedPosY = rect.top;
5366 actualPosX = minmax->ptMaxPosition.x;
5367 actualPosY = minmax->ptMaxPosition.y;
5368 ok(actualPosX == expectedPosX && actualPosY == expectedPosY,
5369 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
5370 expectedPosX, expectedPosY, actualPosX, actualPosY, test_thick_child_name);
5372 break;
5376 return DefWindowProcA(hwnd, msg, wparam, lparam);
5379 #define NUMBER_OF_THICK_CHILD_TESTS 16
5380 static void test_thick_child_size(HWND parentWindow)
5382 BOOL success;
5383 RECT childRect;
5384 RECT adjustedParentRect;
5385 HWND childWindow;
5386 LONG childWidth;
5387 LONG childHeight;
5388 LONG expectedWidth;
5389 LONG expectedHeight;
5390 WNDCLASSA cls;
5391 LPCTSTR className = "THICK_CHILD_CLASS";
5392 int i;
5393 LONG adjustedStyle;
5394 static const LONG styles[NUMBER_OF_THICK_CHILD_TESTS] = {
5395 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5396 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5397 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5398 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5399 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5400 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5401 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5402 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5403 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5404 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5405 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5406 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5407 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5408 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5409 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5410 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5413 static const LONG exStyles[NUMBER_OF_THICK_CHILD_TESTS] = {
5418 WS_EX_DLGMODALFRAME,
5419 WS_EX_DLGMODALFRAME,
5420 WS_EX_DLGMODALFRAME,
5421 WS_EX_DLGMODALFRAME,
5422 WS_EX_STATICEDGE,
5423 WS_EX_STATICEDGE,
5424 WS_EX_STATICEDGE,
5425 WS_EX_STATICEDGE,
5426 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5427 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5428 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5429 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5431 static const char *styleName[NUMBER_OF_THICK_CHILD_TESTS] = {
5432 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
5433 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
5434 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
5435 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
5436 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
5437 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
5438 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5439 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5440 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
5441 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
5442 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5443 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5444 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5445 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5446 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5447 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5450 cls.style = 0;
5451 cls.lpfnWndProc = test_thick_child_size_winproc;
5452 cls.cbClsExtra = 0;
5453 cls.cbWndExtra = 0;
5454 cls.hInstance = GetModuleHandleA(0);
5455 cls.hIcon = 0;
5456 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5457 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5458 cls.lpszMenuName = NULL;
5459 cls.lpszClassName = className;
5460 SetLastError(0xdeadbeef);
5461 ok(RegisterClassA(&cls),"RegisterClassA failed, error: %u\n", GetLastError());
5463 for(i = 0; i < NUMBER_OF_THICK_CHILD_TESTS; i++)
5465 test_thick_child_name = styleName[i];
5466 test_thick_child_style = styles[i];
5467 test_thick_child_exStyle = exStyles[i];
5468 test_thick_child_got_minmax = FALSE;
5470 SetLastError(0xdeadbeef);
5471 childWindow = CreateWindowEx( exStyles[i], className, "", styles[i], 0, 0, 0, 0, parentWindow, 0, GetModuleHandleA(0), NULL );
5472 ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
5474 ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
5476 SetLastError(0xdeadbeef);
5477 success = GetWindowRect(childWindow, &childRect);
5478 ok(success,"GetWindowRect call failed, error: %u\n", GetLastError());
5479 childWidth = childRect.right - childRect.left;
5480 childHeight = childRect.bottom - childRect.top;
5482 adjustedStyle = styles[i];
5483 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
5484 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5485 GetClientRect(GetParent(childWindow), &adjustedParentRect);
5486 AdjustWindowRectEx(&adjustedParentRect, adjustedStyle, FALSE, test_thick_child_exStyle);
5489 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
5491 expectedWidth = GetSystemMetrics(SM_CXMINTRACK);
5492 expectedHeight = GetSystemMetrics(SM_CYMINTRACK);
5494 else
5496 expectedWidth = -2 * adjustedParentRect.left;
5497 expectedHeight = -2 * adjustedParentRect.top;
5500 ok((childWidth == expectedWidth) && (childHeight == expectedHeight),
5501 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
5502 test_thick_child_name, expectedWidth, expectedHeight, childWidth, childHeight);
5504 SetLastError(0xdeadbeef);
5505 success = DestroyWindow(childWindow);
5506 ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
5508 ok(UnregisterClass(className, GetModuleHandleA(0)),"UnregisterClass call failed\n");
5511 static void test_handles( HWND full_hwnd )
5513 HWND hwnd = full_hwnd;
5514 BOOL ret;
5515 RECT rect;
5517 SetLastError( 0xdeadbeef );
5518 ret = GetWindowRect( hwnd, &rect );
5519 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5521 #ifdef _WIN64
5522 if ((ULONG_PTR)full_hwnd >> 32)
5523 hwnd = (HWND)((ULONG_PTR)full_hwnd & ~0u);
5524 else
5525 hwnd = (HWND)((ULONG_PTR)full_hwnd | ((ULONG_PTR)~0u << 32));
5526 SetLastError( 0xdeadbeef );
5527 ret = GetWindowRect( hwnd, &rect );
5528 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5530 hwnd = (HWND)(((ULONG_PTR)full_hwnd & ~0u) | ((ULONG_PTR)0x1234 << 32));
5531 SetLastError( 0xdeadbeef );
5532 ret = GetWindowRect( hwnd, &rect );
5533 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5535 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x9876 << 16));
5536 SetLastError( 0xdeadbeef );
5537 ret = GetWindowRect( hwnd, &rect );
5538 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
5539 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
5541 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x12345678 << 16));
5542 SetLastError( 0xdeadbeef );
5543 ret = GetWindowRect( hwnd, &rect );
5544 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
5545 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
5546 #endif
5549 static void test_winregion(void)
5551 HWND hwnd;
5552 RECT r;
5553 int ret;
5554 HRGN hrgn;
5556 if (!pGetWindowRgnBox)
5558 win_skip("GetWindowRgnBox not supported\n");
5559 return;
5562 hwnd = CreateWindowExA(0, "static", NULL, WS_VISIBLE, 10, 10, 10, 10, NULL, 0, 0, NULL);
5563 /* NULL prect */
5564 SetLastError(0xdeadbeef);
5565 ret = pGetWindowRgnBox(hwnd, NULL);
5566 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
5567 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
5569 hrgn = CreateRectRgn(2, 3, 10, 15);
5570 ok( hrgn != NULL, "Region creation failed\n");
5571 if (hrgn)
5573 SetWindowRgn(hwnd, hrgn, FALSE);
5575 SetLastError(0xdeadbeef);
5576 ret = pGetWindowRgnBox(hwnd, NULL);
5577 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
5578 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
5580 r.left = r.top = r.right = r.bottom = 0;
5581 ret = pGetWindowRgnBox(hwnd, &r);
5582 ok( ret == SIMPLEREGION, "Expected SIMPLEREGION, got %d\n", ret);
5583 ok( r.left == 2 && r.top == 3 && r.right == 10 && r.bottom == 15,
5584 "Expected (2,3,10,15), got (%d,%d,%d,%d)\n", r.left, r.top,
5585 r.right, r.bottom);
5586 DeleteObject(hrgn);
5588 DestroyWindow(hwnd);
5591 START_TEST(win)
5593 HMODULE user32 = GetModuleHandleA( "user32.dll" );
5594 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
5595 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
5596 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
5597 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
5598 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
5599 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
5600 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
5601 pGetWindowRgnBox = (void *)GetProcAddress( user32, "GetWindowRgnBox" );
5603 if (!RegisterWindowClasses()) assert(0);
5605 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
5606 if (!hhook) win_skip( "Cannot set CBT hook, skipping some tests\n" );
5608 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
5609 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5610 WS_MAXIMIZEBOX | WS_POPUP,
5611 100, 100, 200, 200,
5612 0, 0, GetModuleHandle(0), NULL);
5613 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
5614 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5615 WS_MAXIMIZEBOX | WS_POPUP,
5616 100, 100, 200, 200,
5617 0, 0, GetModuleHandle(0), NULL);
5618 assert( hwndMain );
5619 assert( hwndMain2 );
5621 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
5623 /* Add the tests below this line */
5624 test_thick_child_size(hwndMain);
5625 test_fullscreen();
5626 test_hwnd_message();
5627 test_nonclient_area(hwndMain);
5628 test_params();
5629 test_GetWindowModuleFileName();
5630 test_capture_1();
5631 test_capture_2();
5632 test_capture_3(hwndMain, hwndMain2);
5634 test_CreateWindow();
5635 test_parent_owner();
5636 test_SetParent();
5638 test_mdi();
5639 test_icons();
5640 test_SetWindowPos(hwndMain);
5641 test_SetMenu(hwndMain);
5642 test_SetFocus(hwndMain);
5643 test_SetActiveWindow(hwndMain);
5645 test_children_zorder(hwndMain);
5646 test_popup_zorder(hwndMain2, hwndMain);
5647 test_keyboard_input(hwndMain);
5648 test_mouse_input(hwndMain);
5649 test_validatergn(hwndMain);
5650 test_nccalcscroll( hwndMain);
5651 test_scrollvalidate( hwndMain);
5652 test_scrolldc( hwndMain);
5653 test_scroll();
5654 test_IsWindowUnicode();
5655 test_vis_rgn(hwndMain);
5657 test_AdjustWindowRect();
5658 test_window_styles();
5659 test_redrawnow();
5660 test_csparentdc();
5661 test_SetWindowLong();
5662 test_ShowWindow();
5663 if (0) test_gettext(); /* crashes on NT4 */
5664 test_GetUpdateRect();
5665 test_Expose();
5666 test_layered_window();
5668 test_SetForegroundWindow(hwndMain);
5669 test_shell_window();
5670 test_handles( hwndMain );
5671 test_winregion();
5673 /* add the tests above this line */
5674 if (hhook) UnhookWindowsHookEx(hhook);
5676 DestroyWindow(hwndMain2);
5677 DestroyWindow(hwndMain);