push d1f5df181c120dbe494f7c89b454752c2e0dcc04
[wine/hacks.git] / dlls / user32 / tests / win.c
blobf3befc43634f23b33a73abd719a8cdd2c24e3f8c
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);
55 static BOOL test_lbuttondown_flag;
56 static HWND hwndMessage;
57 static HWND hwndMain, hwndMain2;
58 static HHOOK hhook;
60 static const char* szAWRClass = "Winsize";
61 static HMENU hmenu;
62 static DWORD our_pid;
64 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
66 static void dump_minmax_info( const MINMAXINFO *minmax )
68 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
69 minmax->ptReserved.x, minmax->ptReserved.y,
70 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
71 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
72 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
73 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
76 /* try to make sure pending X events have been processed before continuing */
77 static void flush_events( BOOL remove_messages )
79 MSG msg;
80 int diff = 200;
81 int min_timeout = 100;
82 DWORD time = GetTickCount() + diff;
84 while (diff > 0)
86 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
87 if (remove_messages)
88 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
89 diff = time - GetTickCount();
90 min_timeout = 50;
94 /* check the values returned by the various parent/owner functions on a given window */
95 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
96 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
98 HWND res;
100 if (pGetAncestor)
102 res = pGetAncestor( hwnd, GA_PARENT );
103 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
105 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
106 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
107 res = GetParent( hwnd );
108 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
109 res = GetWindow( hwnd, GW_OWNER );
110 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
111 if (pGetAncestor)
113 res = pGetAncestor( hwnd, GA_ROOT );
114 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
115 res = pGetAncestor( hwnd, GA_ROOTOWNER );
116 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
120 static BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
122 (*(LPINT)lParam)++;
123 trace("EnumChildProc on %p\n", hwndChild);
124 if (*(LPINT)lParam > 1) return FALSE;
125 return TRUE;
128 /* will search for the given window */
129 static BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
131 trace("EnumChildProc1 on %p\n", hwndChild);
132 if ((HWND)lParam == hwndChild) return FALSE;
133 return TRUE;
136 static HWND create_tool_window( LONG style, HWND parent )
138 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
139 0, 0, 100, 100, parent, 0, 0, NULL );
140 ok( ret != 0, "Creation failed\n" );
141 return ret;
144 /* test parent and owner values for various combinations */
145 static void test_parent_owner(void)
147 LONG style;
148 HWND test, owner, ret;
149 HWND desktop = GetDesktopWindow();
150 HWND child = create_tool_window( WS_CHILD, hwndMain );
151 INT numChildren;
153 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
155 /* child without parent, should fail */
156 SetLastError(0xdeadbeef);
157 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
158 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
159 ok( !test, "WS_CHILD without parent created\n" );
160 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD ||
161 broken(GetLastError() == 0xdeadbeef), /* win9x */
162 "CreateWindowExA error %u\n", GetLastError() );
164 /* desktop window */
165 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
166 style = GetWindowLongA( desktop, GWL_STYLE );
167 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
168 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
169 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
171 /* normal child window */
172 test = create_tool_window( WS_CHILD, hwndMain );
173 trace( "created child %p\n", test );
174 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
175 SetWindowLongA( test, GWL_STYLE, 0 );
176 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
177 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
178 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
179 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
180 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
181 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
182 DestroyWindow( test );
184 /* normal child window with WS_MAXIMIZE */
185 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
186 DestroyWindow( test );
188 /* normal child window with WS_THICKFRAME */
189 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
190 DestroyWindow( test );
192 /* popup window with WS_THICKFRAME */
193 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
194 DestroyWindow( test );
196 /* child of desktop */
197 test = create_tool_window( WS_CHILD, desktop );
198 trace( "created child of desktop %p\n", test );
199 check_parents( test, desktop, 0, desktop, 0, test, desktop );
200 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
201 check_parents( test, desktop, 0, 0, 0, test, test );
202 SetWindowLongA( test, GWL_STYLE, 0 );
203 check_parents( test, desktop, 0, 0, 0, test, test );
204 DestroyWindow( test );
206 /* child of desktop with WS_MAXIMIZE */
207 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
208 DestroyWindow( test );
210 /* child of desktop with WS_MINIMIZE */
211 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
212 DestroyWindow( test );
214 /* child of child */
215 test = create_tool_window( WS_CHILD, child );
216 trace( "created child of child %p\n", test );
217 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
218 SetWindowLongA( test, GWL_STYLE, 0 );
219 check_parents( test, child, child, 0, 0, hwndMain, test );
220 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
221 check_parents( test, child, child, 0, 0, hwndMain, test );
222 DestroyWindow( test );
224 /* child of child with WS_MAXIMIZE */
225 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
226 DestroyWindow( test );
228 /* child of child with WS_MINIMIZE */
229 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
230 DestroyWindow( test );
232 /* not owned top-level window */
233 test = create_tool_window( 0, 0 );
234 trace( "created top-level %p\n", test );
235 check_parents( test, desktop, 0, 0, 0, test, test );
236 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
237 check_parents( test, desktop, 0, 0, 0, test, test );
238 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
239 check_parents( test, desktop, 0, desktop, 0, test, desktop );
240 DestroyWindow( test );
242 /* not owned top-level window with WS_MAXIMIZE */
243 test = create_tool_window( WS_MAXIMIZE, 0 );
244 DestroyWindow( test );
246 /* owned top-level window */
247 test = create_tool_window( 0, hwndMain );
248 trace( "created owned top-level %p\n", test );
249 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
250 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
251 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
252 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
253 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
254 DestroyWindow( test );
256 /* owned top-level window with WS_MAXIMIZE */
257 test = create_tool_window( WS_MAXIMIZE, hwndMain );
258 DestroyWindow( test );
260 /* not owned popup */
261 test = create_tool_window( WS_POPUP, 0 );
262 trace( "created popup %p\n", test );
263 check_parents( test, desktop, 0, 0, 0, test, test );
264 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
265 check_parents( test, desktop, 0, desktop, 0, test, desktop );
266 SetWindowLongA( test, GWL_STYLE, 0 );
267 check_parents( test, desktop, 0, 0, 0, test, test );
268 DestroyWindow( test );
270 /* not owned popup with WS_MAXIMIZE */
271 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
272 DestroyWindow( test );
274 /* owned popup */
275 test = create_tool_window( WS_POPUP, hwndMain );
276 trace( "created owned popup %p\n", test );
277 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
278 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
279 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
280 SetWindowLongA( test, GWL_STYLE, 0 );
281 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
282 DestroyWindow( test );
284 /* owned popup with WS_MAXIMIZE */
285 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
286 DestroyWindow( test );
288 /* top-level window owned by child (same as owned by top-level) */
289 test = create_tool_window( 0, child );
290 trace( "created top-level owned by child %p\n", test );
291 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
292 DestroyWindow( test );
294 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
295 test = create_tool_window( WS_MAXIMIZE, child );
296 DestroyWindow( test );
298 /* popup owned by desktop (same as not owned) */
299 test = create_tool_window( WS_POPUP, desktop );
300 trace( "created popup owned by desktop %p\n", test );
301 check_parents( test, desktop, 0, 0, 0, test, test );
302 DestroyWindow( test );
304 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
305 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
306 DestroyWindow( test );
308 /* popup owned by child (same as owned by top-level) */
309 test = create_tool_window( WS_POPUP, child );
310 trace( "created popup owned by child %p\n", test );
311 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
312 DestroyWindow( test );
314 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
315 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
316 DestroyWindow( test );
318 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
319 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
320 trace( "created WS_CHILD popup %p\n", test );
321 check_parents( test, desktop, 0, 0, 0, test, test );
322 DestroyWindow( test );
324 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
325 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
326 DestroyWindow( test );
328 /* owned popup with WS_CHILD (same as WS_POPUP only) */
329 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
330 trace( "created owned WS_CHILD popup %p\n", test );
331 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
332 DestroyWindow( test );
334 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
335 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
336 DestroyWindow( test );
338 /******************** parent changes *************************/
339 trace( "testing parent changes\n" );
341 /* desktop window */
342 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
343 if (0)
345 /* this test succeeds on NT but crashes on win9x systems */
346 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
347 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
348 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
349 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
350 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
352 /* normal child window */
353 test = create_tool_window( WS_CHILD, hwndMain );
354 trace( "created child %p\n", test );
356 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
357 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
358 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
360 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
361 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
362 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
364 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
365 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
366 check_parents( test, desktop, 0, desktop, 0, test, desktop );
368 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
369 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
370 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
371 check_parents( test, desktop, child, desktop, child, test, desktop );
373 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
374 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
375 check_parents( test, desktop, 0, desktop, 0, test, desktop );
376 DestroyWindow( test );
378 /* not owned top-level window */
379 test = create_tool_window( 0, 0 );
380 trace( "created top-level %p\n", test );
382 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
383 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
384 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
386 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
387 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
388 check_parents( test, desktop, child, 0, child, test, test );
390 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
391 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
392 check_parents( test, desktop, 0, 0, 0, test, test );
393 DestroyWindow( test );
395 /* not owned popup */
396 test = create_tool_window( WS_POPUP, 0 );
397 trace( "created popup %p\n", test );
399 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
400 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
401 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
403 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
404 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
405 check_parents( test, desktop, child, child, child, test, hwndMain );
407 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
408 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
409 check_parents( test, desktop, 0, 0, 0, test, test );
410 DestroyWindow( test );
412 /* normal child window */
413 test = create_tool_window( WS_CHILD, hwndMain );
414 trace( "created child %p\n", test );
416 ret = SetParent( test, desktop );
417 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
418 check_parents( test, desktop, 0, desktop, 0, test, desktop );
420 ret = SetParent( test, child );
421 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
422 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
424 ret = SetParent( test, hwndMain2 );
425 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
426 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
427 DestroyWindow( test );
429 /* not owned top-level window */
430 test = create_tool_window( 0, 0 );
431 trace( "created top-level %p\n", test );
433 ret = SetParent( test, child );
434 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
435 check_parents( test, child, child, 0, 0, hwndMain, test );
436 DestroyWindow( test );
438 /* owned popup */
439 test = create_tool_window( WS_POPUP, hwndMain2 );
440 trace( "created owned popup %p\n", test );
442 ret = SetParent( test, child );
443 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
444 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
446 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
447 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
448 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
449 DestroyWindow( test );
451 /**************** test owner destruction *******************/
453 /* owned child popup */
454 owner = create_tool_window( 0, 0 );
455 test = create_tool_window( WS_POPUP, owner );
456 trace( "created owner %p and popup %p\n", owner, test );
457 ret = SetParent( test, child );
458 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
459 check_parents( test, child, child, owner, owner, hwndMain, owner );
460 /* window is now child of 'child' but owned by 'owner' */
461 DestroyWindow( owner );
462 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
463 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
464 * while Win95, Win2k, WinXP do.
466 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
467 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
468 DestroyWindow(test);
470 /* owned top-level popup */
471 owner = create_tool_window( 0, 0 );
472 test = create_tool_window( WS_POPUP, owner );
473 trace( "created owner %p and popup %p\n", owner, test );
474 check_parents( test, desktop, owner, owner, owner, test, owner );
475 DestroyWindow( owner );
476 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
478 /* top-level popup owned by child */
479 owner = create_tool_window( WS_CHILD, hwndMain2 );
480 test = create_tool_window( WS_POPUP, 0 );
481 trace( "created owner %p and popup %p\n", owner, test );
482 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
483 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
484 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
485 DestroyWindow( owner );
486 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
487 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
488 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
489 * while Win95, Win2k, WinXP do.
491 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
492 DestroyWindow(test);
494 /* final cleanup */
495 DestroyWindow(child);
498 owner = create_tool_window( WS_OVERLAPPED, 0 );
499 test = create_tool_window( WS_POPUP, desktop );
501 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
502 numChildren = 0;
503 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
504 "EnumChildWindows should have returned FALSE\n" );
505 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
507 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
508 ret = SetParent( test, owner );
509 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
511 numChildren = 0;
512 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
513 "EnumChildWindows should have returned TRUE\n" );
514 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
516 child = create_tool_window( WS_CHILD, owner );
517 numChildren = 0;
518 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
519 "EnumChildWindows should have returned FALSE\n" );
520 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
521 DestroyWindow( child );
523 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
524 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
525 numChildren = 0;
526 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
527 "EnumChildWindows should have returned TRUE\n" );
528 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
530 ret = SetParent( child, owner );
531 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
532 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
533 numChildren = 0;
534 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
535 "EnumChildWindows should have returned FALSE\n" );
536 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
538 ret = SetParent( child, NULL );
539 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
540 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
541 numChildren = 0;
542 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
543 "EnumChildWindows should have returned TRUE\n" );
544 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
546 /* even GW_OWNER == owner it's still a desktop's child */
547 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
548 "EnumChildWindows should have found %p and returned FALSE\n", child );
550 DestroyWindow( child );
551 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
553 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
554 "EnumChildWindows should have found %p and returned FALSE\n", child );
556 DestroyWindow( child );
557 DestroyWindow( test );
558 DestroyWindow( owner );
562 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
564 switch (msg)
566 case WM_GETMINMAXINFO:
568 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
570 trace("WM_GETMINMAXINFO: hwnd %p, %08lx, %08lx\n", hwnd, wparam, lparam);
571 dump_minmax_info( minmax );
572 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
573 break;
575 case WM_WINDOWPOSCHANGING:
577 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
578 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
579 trace("main: WM_WINDOWPOSCHANGING %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
580 winpos->hwnd, winpos->hwndInsertAfter,
581 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
582 if (!(winpos->flags & SWP_NOMOVE))
584 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
585 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
587 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
588 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
590 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
591 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
593 break;
595 case WM_WINDOWPOSCHANGED:
597 RECT rc1, rc2;
598 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
599 trace("main: WM_WINDOWPOSCHANGED %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
600 winpos->hwnd, winpos->hwndInsertAfter,
601 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
602 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
603 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
605 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
606 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
608 GetWindowRect(hwnd, &rc1);
609 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
610 /* note: winpos coordinates are relative to parent */
611 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
612 if (0)
614 /* Uncomment this once the test succeeds in all cases */
615 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
616 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
619 GetClientRect(hwnd, &rc2);
620 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
621 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
622 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
623 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
624 break;
626 case WM_NCCREATE:
628 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
629 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
631 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
632 if (got_getminmaxinfo)
633 trace("%p got WM_GETMINMAXINFO\n", hwnd);
635 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
636 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
637 else
638 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
639 break;
641 case WM_COMMAND:
642 if (test_lbuttondown_flag)
644 ShowWindow((HWND)wparam, SW_SHOW);
645 flush_events( FALSE );
647 break;
650 return DefWindowProcA(hwnd, msg, wparam, lparam);
653 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
655 switch (msg)
657 case WM_GETMINMAXINFO:
659 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
661 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
662 dump_minmax_info( minmax );
663 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
664 break;
666 case WM_NCCREATE:
668 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
669 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
671 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
672 if (got_getminmaxinfo)
673 trace("%p got WM_GETMINMAXINFO\n", hwnd);
675 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
676 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
677 else
678 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
679 break;
683 return DefWindowProcA(hwnd, msg, wparam, lparam);
686 static BOOL RegisterWindowClasses(void)
688 WNDCLASSA cls;
690 cls.style = CS_DBLCLKS;
691 cls.lpfnWndProc = main_window_procA;
692 cls.cbClsExtra = 0;
693 cls.cbWndExtra = 0;
694 cls.hInstance = GetModuleHandleA(0);
695 cls.hIcon = 0;
696 cls.hCursor = LoadCursorA(0, IDC_ARROW);
697 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
698 cls.lpszMenuName = NULL;
699 cls.lpszClassName = "MainWindowClass";
701 if(!RegisterClassA(&cls)) return FALSE;
703 cls.style = 0;
704 cls.lpfnWndProc = tool_window_procA;
705 cls.cbClsExtra = 0;
706 cls.cbWndExtra = 0;
707 cls.hInstance = GetModuleHandleA(0);
708 cls.hIcon = 0;
709 cls.hCursor = LoadCursorA(0, IDC_ARROW);
710 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
711 cls.lpszMenuName = NULL;
712 cls.lpszClassName = "ToolWindowClass";
714 if(!RegisterClassA(&cls)) return FALSE;
716 return TRUE;
719 static void verify_window_info(const char *hook, HWND hwnd, const WINDOWINFO *info)
721 RECT rcWindow, rcClient;
722 DWORD status;
724 ok(IsWindow(hwnd), "bad window handle %p in hook %s\n", hwnd, hook);
726 GetWindowRect(hwnd, &rcWindow);
727 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow for %p in hook %s\n", hwnd, hook);
729 GetClientRect(hwnd, &rcClient);
730 /* translate to screen coordinates */
731 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
732 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient for %p in hook %s\n", hwnd, hook);
734 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
735 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
736 info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE), hwnd, hook);
737 /* Windows reports some undocumented exstyles in WINDOWINFO, but
738 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
740 ok((info->dwExStyle & ~0xe0000800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
741 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
742 info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE), hwnd, hook);
743 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
744 if (GetForegroundWindow())
745 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
746 info->dwWindowStatus, status, GetActiveWindow(), GetForegroundWindow(), hook);
748 /* win2k and XP return broken border info in GetWindowInfo most of
749 * the time, so there is no point in testing it.
751 #if 0
752 UINT border;
753 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
754 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
755 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
756 ok(info->cyWindowBorders == border,
757 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
758 #endif
759 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType for %p in hook %s\n",
760 hwnd, hook);
761 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
762 info->wCreatorVersion == 0x0500 /* Vista */,
763 "wrong wCreatorVersion %04x for %p in hook %s\n", info->wCreatorVersion, hwnd, hook);
766 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
768 AdjustWindowRectEx(rc, style, menu, exstyle);
769 /* AdjustWindowRectEx does not include scroll bars */
770 if (style & WS_VSCROLL)
772 if(exstyle & WS_EX_LEFTSCROLLBAR)
773 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
774 else
775 rc->right += GetSystemMetrics(SM_CXVSCROLL);
777 if (style & WS_HSCROLL)
778 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
781 static void test_nonclient_area(HWND hwnd)
783 DWORD style, exstyle;
784 RECT rc_window, rc_client, rc;
785 BOOL menu;
786 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
787 LRESULT ret;
789 style = GetWindowLongA(hwnd, GWL_STYLE);
790 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
791 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
793 GetWindowRect(hwnd, &rc_window);
794 GetClientRect(hwnd, &rc_client);
796 /* avoid some cases when things go wrong */
797 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
798 rc_window.right > 32768 || rc_window.bottom > 32768) return;
800 CopyRect(&rc, &rc_client);
801 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
802 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
804 ok(EqualRect(&rc, &rc_window),
805 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
806 style, exstyle, menu, rc_window.left, rc_window.top, rc_window.right, rc_window.bottom,
807 rc.left, rc.top, rc.right, rc.bottom);
810 CopyRect(&rc, &rc_window);
811 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
812 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
813 ok(EqualRect(&rc, &rc_client),
814 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
815 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
816 rc.left, rc.top, rc.right, rc.bottom);
818 /* NULL rectangle shouldn't crash */
819 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
820 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
822 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
823 if (is_win9x)
824 return;
826 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
827 SetRect(&rc_client, 0, 0, 250, 150);
828 CopyRect(&rc_window, &rc_client);
829 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
830 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
832 CopyRect(&rc, &rc_window);
833 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
834 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
835 ok(EqualRect(&rc, &rc_client),
836 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
837 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
838 rc.left, rc.top, rc.right, rc.bottom);
841 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
843 static const char *CBT_code_name[10] = {
844 "HCBT_MOVESIZE",
845 "HCBT_MINMAX",
846 "HCBT_QS",
847 "HCBT_CREATEWND",
848 "HCBT_DESTROYWND",
849 "HCBT_ACTIVATE",
850 "HCBT_CLICKSKIPPED",
851 "HCBT_KEYSKIPPED",
852 "HCBT_SYSCOMMAND",
853 "HCBT_SETFOCUS" };
854 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
855 HWND hwnd = (HWND)wParam;
857 switch (nCode)
859 case HCBT_CREATEWND:
861 static const RECT rc_null;
862 RECT rc;
863 LONG style;
864 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
865 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
866 hwnd, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
867 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
869 if (pGetWindowInfo)
871 WINDOWINFO info;
872 info.cbSize = sizeof(WINDOWINFO);
873 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
874 verify_window_info(code_name, hwnd, &info);
877 /* WS_VISIBLE should be turned off yet */
878 style = createwnd->lpcs->style & ~WS_VISIBLE;
879 ok(style == GetWindowLongA(hwnd, GWL_STYLE),
880 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
881 GetWindowLongA(hwnd, GWL_STYLE), style);
883 if (0)
885 /* Uncomment this once the test succeeds in all cases */
886 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
888 ok(GetParent(hwnd) == hwndMessage,
889 "wrong result from GetParent %p: message window %p\n",
890 GetParent(hwnd), hwndMessage);
892 else
893 ok(!GetParent(hwnd), "GetParent should return 0 at this point\n");
895 ok(!GetWindow(hwnd, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
897 if (0)
899 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
900 * Win9x still has them set to 0.
902 ok(GetWindow(hwnd, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
903 ok(GetWindow(hwnd, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
905 ok(!GetWindow(hwnd, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
906 ok(!GetWindow(hwnd, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
908 if (0)
910 /* Uncomment this once the test succeeds in all cases */
911 if (pGetAncestor)
913 ok(pGetAncestor(hwnd, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
914 ok(pGetAncestor(hwnd, GA_ROOT) == hwnd,
915 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOT), hwnd);
917 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
918 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwndMessage,
919 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
920 else
921 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwnd,
922 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOTOWNER), hwnd);
925 ok(GetWindowRect(hwnd, &rc), "GetWindowRect failed\n");
926 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
927 ok(GetClientRect(hwnd, &rc), "GetClientRect failed\n");
928 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
930 break;
932 case HCBT_MOVESIZE:
933 case HCBT_MINMAX:
934 case HCBT_ACTIVATE:
935 case HCBT_SETFOCUS:
936 if (pGetWindowInfo && IsWindow(hwnd))
938 WINDOWINFO info;
940 /* Win98 actually does check the info.cbSize and doesn't allow
941 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
942 * WinXP do not check it at all.
944 info.cbSize = sizeof(WINDOWINFO);
945 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
946 verify_window_info(code_name, hwnd, &info);
948 break;
949 /* on HCBT_DESTROYWND window state is undefined */
950 case HCBT_DESTROYWND:
951 trace( "HCBT_DESTROYWND: hwnd %p\n", hwnd );
952 break;
953 default:
954 break;
957 return CallNextHookEx(hhook, nCode, wParam, lParam);
960 static void test_shell_window(void)
962 BOOL ret;
963 DWORD error;
964 HMODULE hinst, hUser32;
965 BOOL (WINAPI*SetShellWindow)(HWND);
966 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
967 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
968 HWND shellWindow, nextWnd;
970 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
972 trace("Skipping shell window test on Win9x\n");
973 return;
976 shellWindow = GetShellWindow();
977 hinst = GetModuleHandle(0);
978 hUser32 = GetModuleHandleA("user32");
980 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
981 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
983 trace("previous shell window: %p\n", shellWindow);
985 if (shellWindow) {
986 DWORD pid;
987 HANDLE hProcess;
989 SetLastError(0xdeadbeef);
990 ret = DestroyWindow(shellWindow);
991 error = GetLastError();
993 ok(!ret, "DestroyWindow(shellWindow)\n");
994 /* passes on Win XP, but not on Win98 */
995 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
996 "got %u after DestroyWindow(shellWindow)\n", error);
998 /* close old shell instance */
999 GetWindowThreadProcessId(shellWindow, &pid);
1000 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
1001 ret = TerminateProcess(hProcess, 0);
1002 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1003 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
1004 CloseHandle(hProcess);
1007 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
1008 trace("created window 1: %p\n", hwnd1);
1010 ret = SetShellWindow(hwnd1);
1011 ok(ret, "first call to SetShellWindow(hwnd1)\n");
1012 shellWindow = GetShellWindow();
1013 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
1015 ret = SetShellWindow(hwnd1);
1016 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1018 ret = SetShellWindow(0);
1019 error = GetLastError();
1020 /* passes on Win XP, but not on Win98
1021 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1022 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1024 ret = SetShellWindow(hwnd1);
1025 /* passes on Win XP, but not on Win98
1026 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1028 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1029 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
1030 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1032 ret = DestroyWindow(hwnd1);
1033 ok(ret, "DestroyWindow(hwnd1)\n");
1035 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1036 trace("created window 2: %p\n", hwnd2);
1037 ret = SetShellWindow(hwnd2);
1038 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1040 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1041 trace("created window 3: %p\n", hwnd3);
1043 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1044 trace("created window 4: %p\n", hwnd4);
1046 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1047 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1049 ret = SetShellWindow(hwnd4);
1050 ok(ret, "SetShellWindow(hwnd4)\n");
1051 shellWindow = GetShellWindow();
1052 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1054 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1055 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1057 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1058 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1060 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1061 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1063 ret = SetShellWindow(hwnd3);
1064 ok(!ret, "SetShellWindow(hwnd3)\n");
1065 shellWindow = GetShellWindow();
1066 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1068 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1069 trace("created window 5: %p\n", hwnd5);
1070 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1071 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1073 todo_wine
1075 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1076 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1079 /* destroy test windows */
1080 DestroyWindow(hwnd2);
1081 DestroyWindow(hwnd3);
1082 DestroyWindow(hwnd4);
1083 DestroyWindow(hwnd5);
1086 /************** MDI test ****************/
1088 static char mdi_lParam_test_message[] = "just a test string";
1090 static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
1092 MDICREATESTRUCTA mdi_cs;
1093 HWND mdi_child;
1094 INT_PTR id;
1095 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1096 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1097 BOOL isWin9x = FALSE;
1099 mdi_cs.szClass = "MDI_child_Class_1";
1100 mdi_cs.szTitle = "MDI child";
1101 mdi_cs.hOwner = GetModuleHandle(0);
1102 mdi_cs.x = CW_USEDEFAULT;
1103 mdi_cs.y = CW_USEDEFAULT;
1104 mdi_cs.cx = CW_USEDEFAULT;
1105 mdi_cs.cy = CW_USEDEFAULT;
1106 mdi_cs.style = 0;
1107 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1108 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1109 ok(mdi_child != 0, "MDI child creation failed\n");
1110 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1111 ok(id == first_id, "wrong child id %ld\n", id);
1112 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1113 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1115 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1116 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1117 ok(mdi_child != 0, "MDI child creation failed\n");
1118 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1119 ok(id == first_id, "wrong child id %ld\n", id);
1120 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1121 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1123 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1124 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1125 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1127 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1129 else
1131 ok(mdi_child != 0, "MDI child creation failed\n");
1132 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1133 ok(id == first_id, "wrong child id %ld\n", id);
1134 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1135 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1138 /* test MDICREATESTRUCT A<->W mapping */
1139 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1140 mdi_cs.style = 0;
1141 mdi_cs.szClass = (LPCSTR)classW;
1142 mdi_cs.szTitle = (LPCSTR)titleW;
1143 SetLastError(0xdeadbeef);
1144 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1145 if (!mdi_child)
1147 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1148 isWin9x = TRUE;
1149 else
1150 ok(mdi_child != 0, "MDI child creation failed\n");
1152 else
1154 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1155 ok(id == first_id, "wrong child id %ld\n", id);
1156 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1157 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1160 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1162 CW_USEDEFAULT, CW_USEDEFAULT,
1163 CW_USEDEFAULT, CW_USEDEFAULT,
1164 mdi_client, GetModuleHandle(0),
1165 (LPARAM)mdi_lParam_test_message);
1166 ok(mdi_child != 0, "MDI child creation failed\n");
1167 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1168 ok(id == first_id, "wrong child id %ld\n", id);
1169 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1170 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1172 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1173 0x7fffffff, /* without WS_POPUP */
1174 CW_USEDEFAULT, CW_USEDEFAULT,
1175 CW_USEDEFAULT, CW_USEDEFAULT,
1176 mdi_client, GetModuleHandle(0),
1177 (LPARAM)mdi_lParam_test_message);
1178 ok(mdi_child != 0, "MDI child creation failed\n");
1179 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1180 ok(id == first_id, "wrong child id %ld\n", id);
1181 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1182 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1184 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1185 0xffffffff, /* with WS_POPUP */
1186 CW_USEDEFAULT, CW_USEDEFAULT,
1187 CW_USEDEFAULT, CW_USEDEFAULT,
1188 mdi_client, GetModuleHandle(0),
1189 (LPARAM)mdi_lParam_test_message);
1190 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1192 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1194 else
1196 ok(mdi_child != 0, "MDI child creation failed\n");
1197 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1198 ok(id == first_id, "wrong child id %ld\n", id);
1199 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1200 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1203 /* test MDICREATESTRUCT A<->W mapping */
1204 SetLastError(0xdeadbeef);
1205 mdi_child = CreateMDIWindowW(classW, titleW,
1207 CW_USEDEFAULT, CW_USEDEFAULT,
1208 CW_USEDEFAULT, CW_USEDEFAULT,
1209 mdi_client, GetModuleHandle(0),
1210 (LPARAM)mdi_lParam_test_message);
1211 if (!mdi_child)
1213 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1214 isWin9x = TRUE;
1215 else
1216 ok(mdi_child != 0, "MDI child creation failed\n");
1218 else
1220 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1221 ok(id == first_id, "wrong child id %ld\n", id);
1222 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1223 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1226 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1228 CW_USEDEFAULT, CW_USEDEFAULT,
1229 CW_USEDEFAULT, CW_USEDEFAULT,
1230 mdi_client, 0, GetModuleHandle(0),
1231 mdi_lParam_test_message);
1232 ok(mdi_child != 0, "MDI child creation failed\n");
1233 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1234 ok(id == first_id, "wrong child id %ld\n", id);
1235 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1236 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1238 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1239 0x7fffffff, /* without WS_POPUP */
1240 CW_USEDEFAULT, CW_USEDEFAULT,
1241 CW_USEDEFAULT, CW_USEDEFAULT,
1242 mdi_client, 0, GetModuleHandle(0),
1243 mdi_lParam_test_message);
1244 ok(mdi_child != 0, "MDI child creation failed\n");
1245 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1246 ok(id == first_id, "wrong child id %ld\n", id);
1247 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1248 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1250 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1251 0xffffffff, /* with WS_POPUP */
1252 CW_USEDEFAULT, CW_USEDEFAULT,
1253 CW_USEDEFAULT, CW_USEDEFAULT,
1254 mdi_client, 0, GetModuleHandle(0),
1255 mdi_lParam_test_message);
1256 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1258 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1260 else
1262 ok(mdi_child != 0, "MDI child creation failed\n");
1263 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1264 ok(id == first_id, "wrong child id %ld\n", id);
1265 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1266 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1269 /* test MDICREATESTRUCT A<->W mapping */
1270 SetLastError(0xdeadbeef);
1271 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1273 CW_USEDEFAULT, CW_USEDEFAULT,
1274 CW_USEDEFAULT, CW_USEDEFAULT,
1275 mdi_client, 0, GetModuleHandle(0),
1276 mdi_lParam_test_message);
1277 if (!mdi_child)
1279 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1280 isWin9x = TRUE;
1281 else
1282 ok(mdi_child != 0, "MDI child creation failed\n");
1284 else
1286 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1287 ok(id == first_id, "wrong child id %ld\n", id);
1288 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1289 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1292 /* This test fails on Win9x */
1293 if (!isWin9x)
1295 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1296 WS_CHILD,
1297 CW_USEDEFAULT, CW_USEDEFAULT,
1298 CW_USEDEFAULT, CW_USEDEFAULT,
1299 parent, 0, GetModuleHandle(0),
1300 mdi_lParam_test_message);
1301 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1304 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1305 WS_CHILD, /* without WS_POPUP */
1306 CW_USEDEFAULT, CW_USEDEFAULT,
1307 CW_USEDEFAULT, CW_USEDEFAULT,
1308 mdi_client, 0, GetModuleHandle(0),
1309 mdi_lParam_test_message);
1310 ok(mdi_child != 0, "MDI child creation failed\n");
1311 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1312 ok(id == 0, "wrong child id %ld\n", id);
1313 DestroyWindow(mdi_child);
1315 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1316 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1317 CW_USEDEFAULT, CW_USEDEFAULT,
1318 CW_USEDEFAULT, CW_USEDEFAULT,
1319 mdi_client, 0, GetModuleHandle(0),
1320 mdi_lParam_test_message);
1321 ok(mdi_child != 0, "MDI child creation failed\n");
1322 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1323 ok(id == 0, "wrong child id %ld\n", id);
1324 DestroyWindow(mdi_child);
1326 /* maximized child */
1327 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1328 WS_CHILD | WS_MAXIMIZE,
1329 CW_USEDEFAULT, CW_USEDEFAULT,
1330 CW_USEDEFAULT, CW_USEDEFAULT,
1331 mdi_client, 0, GetModuleHandle(0),
1332 mdi_lParam_test_message);
1333 ok(mdi_child != 0, "MDI child creation failed\n");
1334 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1335 ok(id == 0, "wrong child id %ld\n", id);
1336 DestroyWindow(mdi_child);
1338 trace("Creating maximized child with a caption\n");
1339 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1340 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1341 CW_USEDEFAULT, CW_USEDEFAULT,
1342 CW_USEDEFAULT, CW_USEDEFAULT,
1343 mdi_client, 0, GetModuleHandle(0),
1344 mdi_lParam_test_message);
1345 ok(mdi_child != 0, "MDI child creation failed\n");
1346 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1347 ok(id == 0, "wrong child id %ld\n", id);
1348 DestroyWindow(mdi_child);
1350 trace("Creating maximized child with a caption and a thick frame\n");
1351 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1352 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1353 CW_USEDEFAULT, CW_USEDEFAULT,
1354 CW_USEDEFAULT, CW_USEDEFAULT,
1355 mdi_client, 0, GetModuleHandle(0),
1356 mdi_lParam_test_message);
1357 ok(mdi_child != 0, "MDI child creation failed\n");
1358 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1359 ok(id == 0, "wrong child id %ld\n", id);
1360 DestroyWindow(mdi_child);
1363 /**********************************************************************
1364 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1366 * Note: The rule here is that client rect of the maximized MDI child
1367 * is equal to the client rect of the MDI client window.
1369 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1371 RECT rect;
1373 GetClientRect( client, &rect );
1374 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1375 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1377 rect.right -= rect.left;
1378 rect.bottom -= rect.top;
1379 lpMinMax->ptMaxSize.x = rect.right;
1380 lpMinMax->ptMaxSize.y = rect.bottom;
1382 lpMinMax->ptMaxPosition.x = rect.left;
1383 lpMinMax->ptMaxPosition.y = rect.top;
1385 trace("max rect (%d,%d - %d, %d)\n",
1386 rect.left, rect.top, rect.right, rect.bottom);
1389 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1391 switch (msg)
1393 case WM_NCCREATE:
1394 case WM_CREATE:
1396 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1397 MDICREATESTRUCTA *mdi_cs = cs->lpCreateParams;
1399 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1400 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1402 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1403 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1404 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1405 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1406 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1408 /* MDICREATESTRUCT should have original values */
1409 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1410 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1411 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1412 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1413 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1414 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1416 /* CREATESTRUCT should have fixed values */
1417 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1418 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1420 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1421 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1422 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1424 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1426 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1428 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1429 ok(cs->style == style,
1430 "cs->style does not match (%08x)\n", cs->style);
1432 else
1434 LONG style = mdi_cs->style;
1435 style &= ~WS_POPUP;
1436 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1437 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1438 ok(cs->style == style,
1439 "cs->style does not match (%08x)\n", cs->style);
1441 break;
1444 case WM_GETMINMAXINFO:
1446 HWND client = GetParent(hwnd);
1447 RECT rc;
1448 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1449 MINMAXINFO my_minmax;
1450 LONG style, exstyle;
1452 style = GetWindowLongA(hwnd, GWL_STYLE);
1453 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1455 GetWindowRect(client, &rc);
1456 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1457 GetClientRect(client, &rc);
1458 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1459 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1460 GetSystemMetrics(SM_CYSCREEN));
1462 GetClientRect(client, &rc);
1463 if ((style & WS_CAPTION) == WS_CAPTION)
1464 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1465 AdjustWindowRectEx(&rc, style, 0, exstyle);
1466 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1467 dump_minmax_info( minmax );
1469 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1470 minmax->ptMaxSize.x, rc.right - rc.left);
1471 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1472 minmax->ptMaxSize.y, rc.bottom - rc.top);
1474 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1476 trace("DefMDIChildProc returned:\n");
1477 dump_minmax_info( minmax );
1479 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1480 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1481 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1482 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1483 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1485 return 1;
1488 case WM_MDIACTIVATE:
1490 HWND active, client = GetParent(hwnd);
1491 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1492 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1493 if (hwnd == (HWND)lparam) /* if we are being activated */
1494 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1495 else
1496 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1497 break;
1500 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1503 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1505 switch (msg)
1507 case WM_NCCREATE:
1508 case WM_CREATE:
1510 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1512 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE",
1513 cs->x, cs->y, cs->cx, cs->cy);
1515 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1516 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1518 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1519 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1521 /* CREATESTRUCT should have fixed values */
1522 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1523 while NT does. */
1524 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1525 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1527 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1528 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1529 while Win95, Win2k, WinXP do. */
1530 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1531 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1532 break;
1535 case WM_GETMINMAXINFO:
1537 HWND parent = GetParent(hwnd);
1538 RECT rc;
1539 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1540 LONG style, exstyle;
1542 style = GetWindowLongA(hwnd, GWL_STYLE);
1543 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1545 GetClientRect(parent, &rc);
1546 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1548 GetClientRect(parent, &rc);
1549 if ((style & WS_CAPTION) == WS_CAPTION)
1550 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1551 AdjustWindowRectEx(&rc, style, 0, exstyle);
1552 dump_minmax_info( minmax );
1554 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1555 minmax->ptMaxSize.x, rc.right - rc.left);
1556 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1557 minmax->ptMaxSize.y, rc.bottom - rc.top);
1558 break;
1561 case WM_WINDOWPOSCHANGED:
1563 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1564 RECT rc1, rc2;
1566 GetWindowRect(hwnd, &rc1);
1567 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1568 /* note: winpos coordinates are relative to parent */
1569 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1570 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) pos=(%d,%d)-(%d,%d)\n",
1571 rc1.left, rc1.top, rc1.right, rc1.bottom,
1572 rc2.left, rc2.top, rc2.right, rc2.bottom);
1573 GetWindowRect(hwnd, &rc1);
1574 GetClientRect(hwnd, &rc2);
1575 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1576 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1577 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1578 rc1.left, rc1.top, rc1.right, rc1.bottom,
1579 rc2.left, rc2.top, rc2.right, rc2.bottom);
1581 /* fall through */
1582 case WM_WINDOWPOSCHANGING:
1584 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1585 WINDOWPOS my_winpos = *winpos;
1587 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1588 (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
1589 winpos->hwnd, winpos->hwndInsertAfter,
1590 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1592 DefWindowProcA(hwnd, msg, wparam, lparam);
1594 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1595 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1596 winpos->hwnd, winpos->hwndInsertAfter,
1597 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1599 return 1;
1602 return DefWindowProcA(hwnd, msg, wparam, lparam);
1605 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1607 static HWND mdi_client;
1609 switch (msg)
1611 case WM_CREATE:
1613 CLIENTCREATESTRUCT client_cs;
1614 RECT rc;
1616 GetClientRect(hwnd, &rc);
1618 client_cs.hWindowMenu = 0;
1619 client_cs.idFirstChild = 1;
1621 /* MDIClient without MDIS_ALLCHILDSTYLES */
1622 mdi_client = CreateWindowExA(0, "mdiclient",
1623 NULL,
1624 WS_CHILD /*| WS_VISIBLE*/,
1625 /* tests depend on a not zero MDIClient size */
1626 0, 0, rc.right, rc.bottom,
1627 hwnd, 0, GetModuleHandle(0),
1628 &client_cs);
1629 assert(mdi_client);
1630 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1631 DestroyWindow(mdi_client);
1633 /* MDIClient with MDIS_ALLCHILDSTYLES */
1634 mdi_client = CreateWindowExA(0, "mdiclient",
1635 NULL,
1636 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1637 /* tests depend on a not zero MDIClient size */
1638 0, 0, rc.right, rc.bottom,
1639 hwnd, 0, GetModuleHandle(0),
1640 &client_cs);
1641 assert(mdi_client);
1642 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1643 DestroyWindow(mdi_client);
1644 break;
1647 case WM_WINDOWPOSCHANGED:
1649 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1650 RECT rc1, rc2;
1652 GetWindowRect(hwnd, &rc1);
1653 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1654 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1655 /* note: winpos coordinates are relative to parent */
1656 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1657 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1658 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1660 GetWindowRect(hwnd, &rc1);
1661 GetClientRect(hwnd, &rc2);
1662 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1663 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1664 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1666 /* fall through */
1667 case WM_WINDOWPOSCHANGING:
1669 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1670 WINDOWPOS my_winpos = *winpos;
1672 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1673 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1674 winpos->hwnd, winpos->hwndInsertAfter,
1675 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1677 DefWindowProcA(hwnd, msg, wparam, lparam);
1679 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1680 winpos->hwnd, winpos->hwndInsertAfter,
1681 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1683 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1684 "DefWindowProc should not change WINDOWPOS values\n");
1686 return 1;
1689 case WM_CLOSE:
1690 PostQuitMessage(0);
1691 break;
1693 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1696 static BOOL mdi_RegisterWindowClasses(void)
1698 WNDCLASSA cls;
1700 cls.style = 0;
1701 cls.lpfnWndProc = mdi_main_wnd_procA;
1702 cls.cbClsExtra = 0;
1703 cls.cbWndExtra = 0;
1704 cls.hInstance = GetModuleHandleA(0);
1705 cls.hIcon = 0;
1706 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1707 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1708 cls.lpszMenuName = NULL;
1709 cls.lpszClassName = "MDI_parent_Class";
1710 if(!RegisterClassA(&cls)) return FALSE;
1712 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1713 cls.lpszClassName = "MDI_child_Class_1";
1714 if(!RegisterClassA(&cls)) return FALSE;
1716 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1717 cls.lpszClassName = "MDI_child_Class_2";
1718 if(!RegisterClassA(&cls)) return FALSE;
1720 return TRUE;
1723 static void test_mdi(void)
1725 HWND mdi_hwndMain;
1726 /*MSG msg;*/
1728 if (!mdi_RegisterWindowClasses()) assert(0);
1730 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1731 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1732 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1733 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1734 GetDesktopWindow(), 0,
1735 GetModuleHandle(0), NULL);
1736 assert(mdi_hwndMain);
1738 while(GetMessage(&msg, 0, 0, 0))
1740 TranslateMessage(&msg);
1741 DispatchMessage(&msg);
1744 DestroyWindow(mdi_hwndMain);
1747 static void test_icons(void)
1749 WNDCLASSEXA cls;
1750 HWND hwnd;
1751 HICON icon = LoadIconA(0, IDI_APPLICATION);
1752 HICON icon2 = LoadIconA(0, IDI_QUESTION);
1753 HICON small_icon = LoadImageA(0, IDI_APPLICATION, IMAGE_ICON,
1754 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1755 HICON res;
1757 cls.cbSize = sizeof(cls);
1758 cls.style = 0;
1759 cls.lpfnWndProc = DefWindowProcA;
1760 cls.cbClsExtra = 0;
1761 cls.cbWndExtra = 0;
1762 cls.hInstance = 0;
1763 cls.hIcon = LoadIconA(0, IDI_HAND);
1764 cls.hIconSm = small_icon;
1765 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1766 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1767 cls.lpszMenuName = NULL;
1768 cls.lpszClassName = "IconWindowClass";
1770 RegisterClassExA(&cls);
1772 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1773 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1774 assert( hwnd );
1776 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1777 ok( res == 0, "wrong big icon %p/0\n", res );
1778 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1779 ok( res == 0, "wrong previous big icon %p/0\n", res );
1780 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1781 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1782 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1783 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1784 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1785 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1787 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1788 ok( res == 0, "wrong small icon %p/0\n", res );
1789 /* this test is XP specific */
1790 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1791 ok( res != 0, "wrong small icon %p\n", res );*/
1792 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1793 ok( res == 0, "wrong previous small icon %p/0\n", res );
1794 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1795 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1796 /* this test is XP specific */
1797 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1798 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1799 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1800 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1801 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1802 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1803 /* this test is XP specific */
1804 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1805 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1807 /* make sure the big icon hasn't changed */
1808 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1809 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1811 DestroyWindow( hwnd );
1814 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1816 if (msg == WM_NCCALCSIZE)
1818 RECT *rect = (RECT *)lparam;
1819 /* first time around increase the rectangle, next time decrease it */
1820 if (rect->left == 100) InflateRect( rect, 10, 10 );
1821 else InflateRect( rect, -10, -10 );
1822 return 0;
1824 return DefWindowProc( hwnd, msg, wparam, lparam );
1827 static void test_SetWindowPos(HWND hwnd)
1829 RECT orig_win_rc, rect;
1830 LONG_PTR old_proc;
1831 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1833 SetRect(&rect, 111, 222, 333, 444);
1834 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1835 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1836 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1838 SetRect(&rect, 111, 222, 333, 444);
1839 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1840 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1841 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1843 GetWindowRect(hwnd, &orig_win_rc);
1845 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1846 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1847 GetWindowRect( hwnd, &rect );
1848 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1849 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1850 GetClientRect( hwnd, &rect );
1851 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1852 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1853 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1855 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1856 GetWindowRect( hwnd, &rect );
1857 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1858 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1859 GetClientRect( hwnd, &rect );
1860 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1861 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1862 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1864 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1865 orig_win_rc.right, orig_win_rc.bottom, 0);
1866 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1868 /* Win9x truncates coordinates to 16-bit irrespectively */
1869 if (!is_win9x)
1871 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1872 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1874 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1875 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1878 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1879 orig_win_rc.right, orig_win_rc.bottom, 0);
1881 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1882 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1883 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1884 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1885 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1886 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1887 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1890 static void test_SetMenu(HWND parent)
1892 HWND child;
1893 HMENU hMenu, ret;
1894 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1895 BOOL retok;
1896 DWORD style;
1898 hMenu = CreateMenu();
1899 assert(hMenu);
1901 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1902 if (0)
1904 /* fails on (at least) Wine, NT4, XP SP2 */
1905 test_nonclient_area(parent);
1907 ret = GetMenu(parent);
1908 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1909 /* test whether we can destroy a menu assigned to a window */
1910 retok = DestroyMenu(hMenu);
1911 ok( retok, "DestroyMenu error %d\n", GetLastError());
1912 retok = IsMenu(hMenu);
1913 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
1914 ret = GetMenu(parent);
1915 /* This test fails on Win9x */
1916 if (!is_win9x)
1917 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1918 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1919 test_nonclient_area(parent);
1921 hMenu = CreateMenu();
1922 assert(hMenu);
1924 /* parent */
1925 ret = GetMenu(parent);
1926 ok(ret == 0, "unexpected menu id %p\n", ret);
1928 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1929 test_nonclient_area(parent);
1930 ret = GetMenu(parent);
1931 ok(ret == 0, "unexpected menu id %p\n", ret);
1933 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1934 if (0)
1936 /* fails on (at least) Wine, NT4, XP SP2 */
1937 test_nonclient_area(parent);
1939 ret = GetMenu(parent);
1940 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1942 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1943 test_nonclient_area(parent);
1944 ret = GetMenu(parent);
1945 ok(ret == 0, "unexpected menu id %p\n", ret);
1947 /* child */
1948 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1949 assert(child);
1951 ret = GetMenu(child);
1952 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1954 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1955 test_nonclient_area(child);
1956 ret = GetMenu(child);
1957 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1959 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1960 test_nonclient_area(child);
1961 ret = GetMenu(child);
1962 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1964 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1965 test_nonclient_area(child);
1966 ret = GetMenu(child);
1967 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1969 style = GetWindowLong(child, GWL_STYLE);
1970 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
1971 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
1972 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
1973 SetWindowLong(child, GWL_STYLE, style);
1975 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
1976 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
1977 SetWindowLong(child, GWL_STYLE, style);
1979 DestroyWindow(child);
1980 DestroyMenu(hMenu);
1983 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1985 HWND child[5], hwnd;
1986 INT_PTR i;
1988 assert(total <= 5);
1990 hwnd = GetWindow(parent, GW_CHILD);
1991 ok(!hwnd, "have to start without children to perform the test\n");
1993 for (i = 0; i < total; i++)
1995 if (style[i] & DS_CONTROL)
1997 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
1998 0,0,0,0, parent, (HMENU)i, 0, NULL);
1999 if (style[i] & WS_VISIBLE)
2000 ShowWindow(child[i], SW_SHOW);
2002 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
2004 else
2005 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
2006 parent, (HMENU)i, 0, NULL);
2007 trace("child[%ld] = %p\n", i, child[i]);
2008 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
2011 hwnd = GetWindow(parent, GW_CHILD);
2012 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
2013 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
2014 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
2016 for (i = 0; i < total; i++)
2018 trace("hwnd[%ld] = %p\n", i, hwnd);
2019 ok(child[order[i]] == hwnd, "Z order of child #%ld is wrong\n", i);
2021 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
2024 for (i = 0; i < total; i++)
2025 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2028 static void test_children_zorder(HWND parent)
2030 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2031 WS_CHILD };
2032 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2034 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2035 WS_CHILD | WS_VISIBLE, WS_CHILD,
2036 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2037 const int complex_order_1[1] = { 0 };
2038 const int complex_order_2[2] = { 1, 0 };
2039 const int complex_order_3[3] = { 1, 0, 2 };
2040 const int complex_order_4[4] = { 1, 0, 2, 3 };
2041 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2042 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2043 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2044 WS_CHILD | WS_VISIBLE };
2045 const int complex_order_6[3] = { 0, 1, 2 };
2047 /* simple WS_CHILD */
2048 test_window_tree(parent, simple_style, simple_order, 5);
2050 /* complex children styles */
2051 test_window_tree(parent, complex_style, complex_order_1, 1);
2052 test_window_tree(parent, complex_style, complex_order_2, 2);
2053 test_window_tree(parent, complex_style, complex_order_3, 3);
2054 test_window_tree(parent, complex_style, complex_order_4, 4);
2055 test_window_tree(parent, complex_style, complex_order_5, 5);
2057 /* another set of complex children styles */
2058 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2061 #define check_z_order(hwnd, next, prev, owner, topmost) \
2062 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2063 __FILE__, __LINE__)
2065 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2066 BOOL topmost, const char *file, int line)
2068 HWND test;
2069 DWORD ex_style;
2071 test = GetWindow(hwnd, GW_HWNDNEXT);
2072 /* skip foreign windows */
2073 while (test && (GetWindowThreadProcessId(test, NULL) != our_pid ||
2074 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0)))
2076 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2077 test = GetWindow(test, GW_HWNDNEXT);
2079 ok_(file, line)(next == test, "expected next %p, got %p\n", next, test);
2081 test = GetWindow(hwnd, GW_HWNDPREV);
2082 /* skip foreign windows */
2083 while (test && (GetWindowThreadProcessId(test, NULL) != our_pid ||
2084 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0)))
2086 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2087 test = GetWindow(test, GW_HWNDPREV);
2089 ok_(file, line)(prev == test, "expected prev %p, got %p\n", prev, test);
2091 test = GetWindow(hwnd, GW_OWNER);
2092 ok_(file, line)(owner == test, "expected owner %p, got %p\n", owner, test);
2094 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2095 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "expected %stopmost\n", topmost ? "" : "NOT ");
2098 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E)
2100 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2102 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2104 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2106 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2107 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2109 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2110 WS_OVERLAPPED | WS_CAPTION,
2111 100, 100, 100, 100,
2112 0, 0, GetModuleHandle(0), NULL);
2113 trace("hwnd_F %p\n", hwnd_F);
2114 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2116 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2117 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2118 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2119 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2121 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2122 WS_POPUP,
2123 100, 100, 100, 100,
2124 hwnd_F, 0, GetModuleHandle(0), NULL);
2125 trace("hwnd_C %p\n", hwnd_C);
2126 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2127 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2128 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2129 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2131 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2132 WS_POPUP,
2133 100, 100, 100, 100,
2134 hwnd_F, 0, GetModuleHandle(0), NULL);
2135 trace("hwnd_B %p\n", hwnd_B);
2136 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2137 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2138 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2139 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2140 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2142 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2143 WS_POPUP,
2144 100, 100, 100, 100,
2145 0, 0, GetModuleHandle(0), NULL);
2146 trace("hwnd_A %p\n", hwnd_A);
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, hwnd_B, hwnd_F, FALSE);
2151 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2152 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2154 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);
2156 /* move hwnd_F and its popups up */
2157 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2158 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2159 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2160 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2161 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2162 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2163 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2165 /* move hwnd_F and its popups down */
2166 #if 0 /* enable once Wine is fixed to pass this test */
2167 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2168 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2169 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2170 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2171 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2172 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2173 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2174 #endif
2176 DestroyWindow(hwnd_A);
2177 DestroyWindow(hwnd_B);
2178 DestroyWindow(hwnd_C);
2179 DestroyWindow(hwnd_F);
2182 static void test_vis_rgn( HWND hwnd )
2184 RECT win_rect, rgn_rect;
2185 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2186 HDC hdc;
2188 ShowWindow(hwnd,SW_SHOW);
2189 hdc = GetDC( hwnd );
2190 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2191 GetWindowRect( hwnd, &win_rect );
2192 GetRgnBox( hrgn, &rgn_rect );
2193 if (GetVersion() & 0x80000000)
2195 trace("win9x, mapping to screen coords\n");
2196 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2198 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2199 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2200 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2201 rgn_rect.left, win_rect.left );
2202 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2203 rgn_rect.top, win_rect.top );
2204 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2205 rgn_rect.right, win_rect.right );
2206 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2207 rgn_rect.bottom, win_rect.bottom );
2208 ReleaseDC( hwnd, hdc );
2211 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2213 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2215 HWND child = GetWindow(hwnd, GW_CHILD);
2216 ok(child != 0, "couldn't find child window\n");
2217 SetFocus(child);
2218 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2219 return 0;
2221 return DefWindowProc(hwnd, msg, wp, lp);
2224 static void test_SetFocus(HWND hwnd)
2226 HWND child;
2227 WNDPROC old_wnd_proc;
2229 /* check if we can set focus to non-visible windows */
2231 ShowWindow(hwnd, SW_SHOW);
2232 SetFocus(0);
2233 SetFocus(hwnd);
2234 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2235 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2236 ShowWindow(hwnd, SW_HIDE);
2237 SetFocus(0);
2238 SetFocus(hwnd);
2239 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2240 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2241 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2242 assert(child);
2243 SetFocus(child);
2244 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2245 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2246 ShowWindow(child, SW_SHOW);
2247 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2248 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2249 ShowWindow(child, SW_HIDE);
2250 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2251 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2252 ShowWindow(child, SW_SHOW);
2253 SetFocus(child);
2254 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2255 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2256 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2258 ShowWindow(child, SW_HIDE);
2259 SetFocus(hwnd);
2260 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2261 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2262 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2263 ShowWindow(child, SW_HIDE);
2264 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2266 ShowWindow(hwnd, SW_SHOW);
2267 ShowWindow(child, SW_SHOW);
2268 SetFocus(child);
2269 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2270 EnableWindow(hwnd, FALSE);
2271 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2272 EnableWindow(hwnd, TRUE);
2274 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2275 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2276 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2277 todo_wine
2278 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2279 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2280 ShowWindow(hwnd, SW_RESTORE);
2281 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2282 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2283 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2284 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2285 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2286 todo_wine
2287 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2288 old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2289 ShowWindow(hwnd, SW_RESTORE);
2290 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2291 todo_wine
2292 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2294 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2296 DestroyWindow( child );
2299 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
2300 static void check_wnd_state_(const char *file, int line,
2301 HWND active, HWND foreground, HWND focus, HWND capture)
2303 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2304 if (foreground && GetForegroundWindow())
2305 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2306 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2307 ok_(file, line)(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2310 static void test_SetActiveWindow(HWND hwnd)
2312 HWND hwnd2;
2314 flush_events( TRUE );
2315 ShowWindow(hwnd, SW_HIDE);
2316 SetFocus(0);
2317 SetActiveWindow(0);
2318 check_wnd_state(0, 0, 0, 0);
2320 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2322 ShowWindow(hwnd, SW_SHOW);
2323 check_wnd_state(hwnd, hwnd, hwnd, 0);
2325 hwnd2 = SetActiveWindow(0);
2326 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2327 if (!GetActiveWindow()) /* doesn't always work on vista */
2329 check_wnd_state(0, 0, 0, 0);
2330 hwnd2 = SetActiveWindow(hwnd);
2331 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2333 check_wnd_state(hwnd, hwnd, hwnd, 0);
2335 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2336 check_wnd_state(hwnd, hwnd, hwnd, 0);
2338 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2339 check_wnd_state(hwnd, hwnd, hwnd, 0);
2341 ShowWindow(hwnd, SW_HIDE);
2342 check_wnd_state(0, 0, 0, 0);
2344 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2345 SetActiveWindow(hwnd);
2346 check_wnd_state(hwnd, hwnd, hwnd, 0);
2348 ShowWindow(hwnd, SW_SHOW);
2349 check_wnd_state(hwnd, hwnd, hwnd, 0);
2351 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2352 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2354 DestroyWindow(hwnd2);
2355 check_wnd_state(hwnd, hwnd, hwnd, 0);
2357 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2358 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2360 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2361 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2363 DestroyWindow(hwnd2);
2364 check_wnd_state(hwnd, hwnd, hwnd, 0);
2367 static void test_SetForegroundWindow(HWND hwnd)
2369 BOOL ret;
2370 HWND hwnd2;
2372 flush_events( TRUE );
2373 ShowWindow(hwnd, SW_HIDE);
2374 SetFocus(0);
2375 SetActiveWindow(0);
2376 check_wnd_state(0, 0, 0, 0);
2378 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2380 ShowWindow(hwnd, SW_SHOW);
2381 check_wnd_state(hwnd, hwnd, hwnd, 0);
2383 hwnd2 = SetActiveWindow(0);
2384 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2385 if (GetActiveWindow() == hwnd) /* doesn't always work on vista */
2386 check_wnd_state(hwnd, hwnd, hwnd, 0);
2387 else
2388 check_wnd_state(0, 0, 0, 0);
2390 ret = SetForegroundWindow(hwnd);
2391 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2392 check_wnd_state(hwnd, hwnd, hwnd, 0);
2394 SetLastError(0xdeadbeef);
2395 ret = SetForegroundWindow(0);
2396 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2397 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
2398 broken(GetLastError() == 0xdeadbeef), /* win9x */
2399 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2400 check_wnd_state(hwnd, hwnd, hwnd, 0);
2402 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2403 check_wnd_state(hwnd, hwnd, hwnd, 0);
2405 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2406 check_wnd_state(hwnd, hwnd, hwnd, 0);
2408 hwnd2 = GetForegroundWindow();
2409 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2410 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2411 hwnd2 = GetForegroundWindow();
2412 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2414 ShowWindow(hwnd, SW_HIDE);
2415 check_wnd_state(0, 0, 0, 0);
2417 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2418 ret = SetForegroundWindow(hwnd);
2419 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2420 check_wnd_state(hwnd, hwnd, hwnd, 0);
2422 ShowWindow(hwnd, SW_SHOW);
2423 check_wnd_state(hwnd, hwnd, hwnd, 0);
2425 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2426 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2428 DestroyWindow(hwnd2);
2429 check_wnd_state(hwnd, hwnd, hwnd, 0);
2431 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2432 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2434 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2435 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2437 DestroyWindow(hwnd2);
2438 check_wnd_state(hwnd, hwnd, hwnd, 0);
2441 static WNDPROC old_button_proc;
2443 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2445 LRESULT ret;
2446 USHORT key_state;
2448 key_state = GetKeyState(VK_LBUTTON);
2449 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2451 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2453 if (msg == WM_LBUTTONDOWN)
2455 HWND hwnd, capture;
2457 check_wnd_state(button, button, button, button);
2459 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2460 assert(hwnd);
2461 trace("hwnd %p\n", hwnd);
2463 check_wnd_state(button, button, button, button);
2465 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2467 check_wnd_state(button, button, button, button);
2469 DestroyWindow(hwnd);
2471 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2472 assert(hwnd);
2473 trace("hwnd %p\n", hwnd);
2475 check_wnd_state(button, button, button, button);
2477 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2478 * match internal button state.
2480 SendMessage(button, WM_KILLFOCUS, 0, 0);
2481 check_wnd_state(button, button, button, 0);
2483 ShowWindow(hwnd, SW_SHOW);
2484 check_wnd_state(hwnd, hwnd, hwnd, 0);
2486 capture = SetCapture(hwnd);
2487 ok(capture == 0, "SetCapture() = %p\n", capture);
2489 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2491 DestroyWindow(hwnd);
2493 check_wnd_state(button, 0, button, 0);
2496 return ret;
2499 static void test_capture_1(void)
2501 HWND button, capture, oldFocus, oldActive;
2503 oldFocus = GetFocus();
2504 oldActive = GetActiveWindow();
2506 capture = GetCapture();
2507 ok(capture == 0, "GetCapture() = %p\n", capture);
2509 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2510 assert(button);
2511 trace("button %p\n", button);
2513 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2515 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2517 capture = SetCapture(button);
2518 ok(capture == 0, "SetCapture() = %p\n", capture);
2519 check_wnd_state(button, 0, button, button);
2521 DestroyWindow(button);
2522 check_wnd_state(oldActive, 0, oldFocus, 0);
2525 static void test_capture_2(void)
2527 HWND button, hwnd, capture, oldFocus, oldActive;
2529 oldFocus = GetFocus();
2530 oldActive = GetActiveWindow();
2531 check_wnd_state(oldActive, 0, oldFocus, 0);
2533 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2534 assert(button);
2535 trace("button %p\n", button);
2537 check_wnd_state(button, button, button, 0);
2539 capture = SetCapture(button);
2540 ok(capture == 0, "SetCapture() = %p\n", capture);
2542 check_wnd_state(button, button, button, button);
2544 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2545 * internal button state.
2547 SendMessage(button, WM_KILLFOCUS, 0, 0);
2548 check_wnd_state(button, button, button, button);
2550 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2551 assert(hwnd);
2552 trace("hwnd %p\n", hwnd);
2554 check_wnd_state(button, button, button, button);
2556 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2558 check_wnd_state(button, button, button, button);
2560 DestroyWindow(hwnd);
2562 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2563 assert(hwnd);
2564 trace("hwnd %p\n", hwnd);
2566 check_wnd_state(button, button, button, button);
2568 ShowWindow(hwnd, SW_SHOW);
2570 check_wnd_state(hwnd, hwnd, hwnd, button);
2572 capture = SetCapture(hwnd);
2573 ok(capture == button, "SetCapture() = %p\n", capture);
2575 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2577 DestroyWindow(hwnd);
2578 check_wnd_state(button, button, button, 0);
2580 DestroyWindow(button);
2581 check_wnd_state(oldActive, 0, oldFocus, 0);
2584 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2586 BOOL ret;
2588 ShowWindow(hwnd1, SW_HIDE);
2589 ShowWindow(hwnd2, SW_HIDE);
2591 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2592 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2594 SetCapture(hwnd1);
2595 check_wnd_state(0, 0, 0, hwnd1);
2597 SetCapture(hwnd2);
2598 check_wnd_state(0, 0, 0, hwnd2);
2600 ShowWindow(hwnd1, SW_SHOW);
2601 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2603 ret = ReleaseCapture();
2604 ok (ret, "releasecapture did not return TRUE.\n");
2605 ret = ReleaseCapture();
2606 ok (ret, "releasecapture did not return TRUE after second try.\n");
2609 static void test_keyboard_input(HWND hwnd)
2611 MSG msg;
2612 BOOL ret;
2614 flush_events( TRUE );
2615 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
2616 UpdateWindow(hwnd);
2617 flush_events( TRUE );
2619 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2621 SetFocus(hwnd);
2622 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2624 flush_events( TRUE );
2626 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2627 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2628 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2629 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2630 ok( !ret, "message %04x available\n", msg.message);
2632 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2634 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2635 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2636 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2637 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2638 ok( !ret, "message %04x available\n", msg.message);
2640 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2642 keybd_event(VK_SPACE, 0, 0, 0);
2643 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2644 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2645 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2646 ok( !ret, "message %04x available\n", msg.message);
2648 SetFocus(0);
2649 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2651 flush_events( TRUE );
2653 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2654 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2655 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2656 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2657 ok( !ret, "message %04x available\n", msg.message);
2659 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2661 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2662 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2663 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2664 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2665 ok( !ret, "message %04x available\n", msg.message);
2667 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2669 keybd_event(VK_SPACE, 0, 0, 0);
2670 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2671 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2672 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2673 ok( !ret, "message %04x available\n", msg.message);
2676 static BOOL wait_for_message( MSG *msg )
2678 BOOL ret;
2680 for (;;)
2682 ret = PeekMessageA(msg, 0, 0, 0, PM_REMOVE);
2683 if (ret)
2685 if (msg->message == WM_PAINT) DispatchMessage(msg);
2686 else if (msg->message < 0xc000) break; /* skip registered messages */
2688 else if (MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
2690 if (!ret) msg->message = 0;
2691 return ret;
2694 static void test_mouse_input(HWND hwnd)
2696 RECT rc;
2697 POINT pt;
2698 int x, y;
2699 HWND popup;
2700 MSG msg;
2701 BOOL ret;
2702 LRESULT res;
2704 ShowWindow(hwnd, SW_SHOW);
2705 UpdateWindow(hwnd);
2706 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2708 GetWindowRect(hwnd, &rc);
2709 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2711 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2712 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2713 hwnd, 0, 0, NULL);
2714 assert(popup != 0);
2715 ShowWindow(popup, SW_SHOW);
2716 UpdateWindow(popup);
2717 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2719 GetWindowRect(popup, &rc);
2720 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2722 x = rc.left + (rc.right - rc.left) / 2;
2723 y = rc.top + (rc.bottom - rc.top) / 2;
2724 trace("setting cursor to (%d,%d)\n", x, y);
2726 SetCursorPos(x, y);
2727 GetCursorPos(&pt);
2728 ok(x == pt.x && y == pt.y, "wrong cursor pos (%d,%d), expected (%d,%d)\n", pt.x, pt.y, x, y);
2730 flush_events( TRUE );
2732 /* Check that setting the same position may generate WM_MOUSEMOVE */
2733 SetCursorPos(x, y);
2734 msg.message = 0;
2736 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2737 while (ret && msg.message >= 0xc000); /* skip registered messages */
2738 if (ret)
2740 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
2741 msg.hwnd, msg.message);
2742 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
2743 x, y, msg.pt.x, msg.pt.y);
2746 /* force the system to update its internal queue mouse position,
2747 * otherwise it won't generate relative mouse movements below.
2749 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2750 flush_events( TRUE );
2752 msg.message = 0;
2753 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2754 flush_events( FALSE );
2755 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2756 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2758 if (msg.message >= 0xc000) continue; /* skip registered messages */
2759 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
2760 "hwnd %p message %04x\n", msg.hwnd, msg.message);
2762 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2763 ok( !ret, "message %04x available\n", msg.message);
2765 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2766 ShowWindow(popup, SW_HIDE);
2767 ret = wait_for_message( &msg );
2768 if (ret)
2769 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2770 flush_events( TRUE );
2772 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2773 ShowWindow(hwnd, SW_HIDE);
2774 ret = wait_for_message( &msg );
2775 ok( !ret, "message %04x available\n", msg.message);
2776 flush_events( TRUE );
2778 /* test mouse clicks */
2780 ShowWindow(hwnd, SW_SHOW);
2781 flush_events( TRUE );
2782 ShowWindow(popup, SW_SHOW);
2783 flush_events( TRUE );
2785 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2786 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2787 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2788 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2790 ret = wait_for_message( &msg );
2791 ok(ret, "no message available\n");
2792 if (msg.message == WM_MOUSEMOVE) /* win2k has an extra WM_MOUSEMOVE here */
2794 ret = wait_for_message( &msg );
2795 ok(ret, "no message available\n");
2798 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2799 msg.hwnd, popup, msg.message);
2801 ret = wait_for_message( &msg );
2802 ok(ret, "no message available\n");
2803 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2804 msg.hwnd, popup, msg.message);
2806 ret = wait_for_message( &msg );
2807 ok(ret, "no message available\n");
2808 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
2809 msg.hwnd, popup, msg.message);
2811 ret = wait_for_message( &msg );
2812 ok(ret, "no message available\n");
2813 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2814 msg.hwnd, popup, msg.message);
2816 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2817 ok(!ret, "message %04x available\n", msg.message);
2819 ShowWindow(popup, SW_HIDE);
2820 flush_events( TRUE );
2822 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2823 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2824 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2825 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2827 ret = wait_for_message( &msg );
2828 ok(ret, "no message available\n");
2829 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2830 msg.hwnd, hwnd, msg.message);
2831 ret = wait_for_message( &msg );
2832 ok(ret, "no message available\n");
2833 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2834 msg.hwnd, hwnd, msg.message);
2836 test_lbuttondown_flag = TRUE;
2837 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
2838 test_lbuttondown_flag = FALSE;
2840 ret = wait_for_message( &msg );
2841 ok(ret, "no message available\n");
2842 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2843 msg.hwnd, popup, msg.message);
2844 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2845 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2846 msg.hwnd, popup, msg.message);
2847 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2849 /* Test WM_MOUSEACTIVATE */
2850 #define TEST_MOUSEACTIVATE(A,B) \
2851 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2852 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2854 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
2855 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
2856 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
2857 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
2858 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
2859 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
2860 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
2861 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
2862 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
2863 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
2864 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
2865 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
2866 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
2867 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
2868 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
2869 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
2870 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
2871 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
2872 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
2873 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
2874 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
2875 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
2876 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
2877 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
2879 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2880 flush_events( TRUE );
2882 DestroyWindow(popup);
2885 static void test_validatergn(HWND hwnd)
2887 HWND child;
2888 RECT rc, rc2;
2889 HRGN rgn;
2890 int ret;
2891 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
2892 ShowWindow(hwnd, SW_SHOW);
2893 UpdateWindow( hwnd);
2894 /* test that ValidateRect validates children*/
2895 InvalidateRect( child, NULL, 1);
2896 GetWindowRect( child, &rc);
2897 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2898 ret = GetUpdateRect( child, &rc2, 0);
2899 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
2900 "Update rectangle is empty!\n");
2901 ValidateRect( hwnd, &rc);
2902 ret = GetUpdateRect( child, &rc2, 0);
2903 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2904 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2905 rc2.right, rc2.bottom);
2907 /* now test ValidateRgn */
2908 InvalidateRect( child, NULL, 1);
2909 GetWindowRect( child, &rc);
2910 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2911 rgn = CreateRectRgnIndirect( &rc);
2912 ValidateRgn( hwnd, rgn);
2913 ret = GetUpdateRect( child, &rc2, 0);
2914 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2915 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2916 rc2.right, rc2.bottom);
2918 DeleteObject( rgn);
2919 DestroyWindow( child );
2922 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
2924 RECT rc;
2925 MoveWindow( hwnd, 0, 0, x, y, 0);
2926 GetWindowRect( hwnd, prc);
2927 rc = *prc;
2928 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
2929 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
2930 rc.left,rc.top,rc.right,rc.bottom, prc->left,prc->top,prc->right,prc->bottom);
2933 static void test_nccalcscroll(HWND parent)
2935 RECT rc1;
2936 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
2937 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
2938 HWND hwnd = CreateWindowExA(0, "static", NULL,
2939 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
2940 10, 10, 200, 200, parent, 0, 0, NULL);
2941 ShowWindow( parent, SW_SHOW);
2942 UpdateWindow( parent);
2944 /* test window too low for a horizontal scroll bar */
2945 nccalchelper( hwnd, 100, sbheight, &rc1);
2946 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
2947 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
2949 /* test window just high enough for a horizontal scroll bar */
2950 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
2951 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
2952 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2954 /* test window too narrow for a vertical scroll bar */
2955 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
2956 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
2957 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2959 /* test window just wide enough for a vertical scroll bar */
2960 nccalchelper( hwnd, sbwidth, 100, &rc1);
2961 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
2962 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
2964 /* same test, but with client edge: not enough width */
2965 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
2966 nccalchelper( hwnd, sbwidth, 100, &rc1);
2967 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
2968 "Width should be %d size is %d,%d - %d,%d\n",
2969 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
2971 DestroyWindow( hwnd);
2974 static void test_SetParent(void)
2976 BOOL ret;
2977 HWND desktop = GetDesktopWindow();
2978 HMENU hMenu;
2979 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
2980 HWND parent, child1, child2, child3, child4, sibling;
2982 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2983 100, 100, 200, 200, 0, 0, 0, NULL);
2984 assert(parent != 0);
2985 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2986 0, 0, 50, 50, parent, 0, 0, NULL);
2987 assert(child1 != 0);
2988 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2989 0, 0, 50, 50, child1, 0, 0, NULL);
2990 assert(child2 != 0);
2991 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2992 0, 0, 50, 50, child2, 0, 0, NULL);
2993 assert(child3 != 0);
2994 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2995 0, 0, 50, 50, child3, 0, 0, NULL);
2996 assert(child4 != 0);
2998 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2999 parent, child1, child2, child3, child4);
3001 check_parents(parent, desktop, 0, 0, 0, parent, parent);
3002 check_parents(child1, parent, parent, parent, 0, parent, parent);
3003 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3004 check_parents(child3, child2, child2, child2, 0, child2, parent);
3005 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3007 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
3008 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
3009 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3010 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
3011 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3013 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
3014 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3015 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
3016 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
3017 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
3018 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
3019 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
3020 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3021 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3023 if (!is_win9x) /* Win9x doesn't survive this test */
3025 ok(!SetParent(parent, child1), "SetParent should fail\n");
3026 ok(!SetParent(child2, child3), "SetParent should fail\n");
3027 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
3028 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
3029 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
3030 ok(!SetParent(child2, parent), "SetParent should fail\n");
3031 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
3033 check_parents(parent, child4, child4, 0, 0, child4, parent);
3034 check_parents(child1, parent, parent, parent, 0, child4, parent);
3035 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3036 check_parents(child3, child2, child2, child2, 0, child2, parent);
3037 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3040 hMenu = CreateMenu();
3041 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3042 100, 100, 200, 200, 0, hMenu, 0, NULL);
3043 assert(sibling != 0);
3045 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
3046 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
3048 ret = DestroyWindow(parent);
3049 ok( ret, "DestroyWindow() error %d\n", GetLastError());
3051 ok(!IsWindow(parent), "parent still exists\n");
3052 ok(!IsWindow(sibling), "sibling still exists\n");
3053 ok(!IsWindow(child1), "child1 still exists\n");
3054 ok(!IsWindow(child2), "child2 still exists\n");
3055 ok(!IsWindow(child3), "child3 still exists\n");
3056 ok(!IsWindow(child4), "child4 still exists\n");
3059 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3061 LPCREATESTRUCT lpcs;
3062 LPSTYLESTRUCT lpss;
3064 switch (msg)
3066 case WM_NCCREATE:
3067 case WM_CREATE:
3068 lpcs = (LPCREATESTRUCT)lparam;
3069 lpss = lpcs->lpCreateParams;
3070 if (lpss)
3072 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
3073 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
3074 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
3075 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
3076 else
3077 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3079 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
3080 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
3081 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
3083 ok(lpss->styleNew == lpcs->style,
3084 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3085 lpss->styleNew, lpcs->style);
3087 break;
3089 return DefWindowProc(hwnd, msg, wparam, lparam);
3092 static ATOM atomStyleCheckClass;
3094 static void register_style_check_class(void)
3096 WNDCLASS wc =
3099 StyleCheckProc,
3102 GetModuleHandle(NULL),
3103 NULL,
3104 LoadCursor(NULL, IDC_ARROW),
3105 (HBRUSH)(COLOR_BTNFACE+1),
3106 NULL,
3107 TEXT("WineStyleCheck"),
3110 atomStyleCheckClass = RegisterClass(&wc);
3113 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3115 DWORD dwActualStyle;
3116 DWORD dwActualExStyle;
3117 STYLESTRUCT ss;
3118 HWND hwnd;
3119 HWND hwndParent = NULL;
3121 ss.styleNew = dwStyleIn;
3122 ss.styleOld = dwExStyleIn;
3124 if (dwStyleIn & WS_CHILD)
3126 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
3127 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3130 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
3131 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3132 assert(hwnd);
3134 flush_events( TRUE );
3136 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3137 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3138 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3139 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3140 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3142 DestroyWindow(hwnd);
3143 if (hwndParent) DestroyWindow(hwndParent);
3146 /* tests what window styles the window manager automatically adds */
3147 static void test_window_styles(void)
3149 register_style_check_class();
3151 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3152 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3153 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3154 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3155 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3156 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3157 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3158 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3159 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3160 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3161 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3164 static void test_scrollvalidate( HWND parent)
3166 HDC hdc;
3167 HRGN hrgn=CreateRectRgn(0,0,0,0);
3168 HRGN exprgn, tmprgn, clipping;
3169 RECT rc, rcu, cliprc;
3170 /* create two overlapping child windows. The visual region
3171 * of hwnd1 is clipped by the overlapping part of
3172 * hwnd2 because of the WS_CLIPSIBLING style */
3173 HWND hwnd1, hwnd2;
3175 clipping = CreateRectRgn(0,0,0,0);
3176 tmprgn = CreateRectRgn(0,0,0,0);
3177 exprgn = CreateRectRgn(0,0,0,0);
3178 hwnd2 = CreateWindowExA(0, "static", NULL,
3179 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3180 75, 30, 100, 100, parent, 0, 0, NULL);
3181 hwnd1 = CreateWindowExA(0, "static", NULL,
3182 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3183 25, 50, 100, 100, parent, 0, 0, NULL);
3184 ShowWindow( parent, SW_SHOW);
3185 UpdateWindow( parent);
3186 GetClientRect( hwnd1, &rc);
3187 cliprc=rc;
3188 SetRectRgn( clipping, 10, 10, 90, 90);
3189 hdc = GetDC( hwnd1);
3190 /* for a visual touch */
3191 TextOut( hdc, 0,10, "0123456789", 10);
3192 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3193 if (winetest_debug > 0) dump_region(hrgn);
3194 /* create a region with what is expected */
3195 SetRectRgn( exprgn, 39,0,49,74);
3196 SetRectRgn( tmprgn, 88,79,98,93);
3197 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3198 SetRectRgn( tmprgn, 0,93,98,98);
3199 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3200 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3201 trace("update rect is %d,%d - %d,%d\n",
3202 rcu.left,rcu.top,rcu.right,rcu.bottom);
3203 /* now with clipping region */
3204 SelectClipRgn( hdc, clipping);
3205 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3206 if (winetest_debug > 0) dump_region(hrgn);
3207 /* create a region with what is expected */
3208 SetRectRgn( exprgn, 39,10,49,74);
3209 SetRectRgn( tmprgn, 80,79,90,85);
3210 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3211 SetRectRgn( tmprgn, 10,85,90,90);
3212 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3213 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3214 trace("update rect is %d,%d - %d,%d\n",
3215 rcu.left,rcu.top,rcu.right,rcu.bottom);
3216 ReleaseDC( hwnd1, hdc);
3218 /* test scrolling a window with an update region */
3219 DestroyWindow( hwnd2);
3220 ValidateRect( hwnd1, NULL);
3221 SetRect( &rc, 40,40, 50,50);
3222 InvalidateRect( hwnd1, &rc, 1);
3223 GetClientRect( hwnd1, &rc);
3224 cliprc=rc;
3225 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
3226 SW_SCROLLCHILDREN | SW_INVALIDATE);
3227 if (winetest_debug > 0) dump_region(hrgn);
3228 SetRectRgn( exprgn, 88,0,98,98);
3229 SetRectRgn( tmprgn, 30, 40, 50, 50);
3230 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3231 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3233 /* clear an update region */
3234 UpdateWindow( hwnd1 );
3236 SetRect( &rc, 0,40, 100,60);
3237 SetRect( &cliprc, 0,0, 100,100);
3238 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3239 if (winetest_debug > 0) dump_region( hrgn );
3240 SetRectRgn( exprgn, 0, 40, 98, 60 );
3241 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
3243 /* now test ScrollWindowEx with a combination of
3244 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3245 /* make hwnd2 the child of hwnd1 */
3246 hwnd2 = CreateWindowExA(0, "static", NULL,
3247 WS_CHILD| WS_VISIBLE | WS_BORDER ,
3248 50, 50, 100, 100, hwnd1, 0, 0, NULL);
3249 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
3250 GetClientRect( hwnd1, &rc);
3251 cliprc=rc;
3253 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3254 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3255 ValidateRect( hwnd1, NULL);
3256 ValidateRect( hwnd2, NULL);
3257 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
3258 SW_SCROLLCHILDREN | SW_INVALIDATE);
3259 if (winetest_debug > 0) dump_region(hrgn);
3260 SetRectRgn( exprgn, 88,0,98,88);
3261 SetRectRgn( tmprgn, 0,88,98,98);
3262 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3263 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3265 /* SW_SCROLLCHILDREN */
3266 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3267 ValidateRect( hwnd1, NULL);
3268 ValidateRect( hwnd2, NULL);
3269 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3270 if (winetest_debug > 0) dump_region(hrgn);
3271 /* expected region is the same as in previous test */
3272 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3274 /* no SW_SCROLLCHILDREN */
3275 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3276 ValidateRect( hwnd1, NULL);
3277 ValidateRect( hwnd2, NULL);
3278 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3279 if (winetest_debug > 0) dump_region(hrgn);
3280 /* expected region is the same as in previous test */
3281 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3283 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3284 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3285 ValidateRect( hwnd1, NULL);
3286 ValidateRect( hwnd2, NULL);
3287 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3288 if (winetest_debug > 0) dump_region(hrgn);
3289 SetRectRgn( exprgn, 88,0,98,20);
3290 SetRectRgn( tmprgn, 20,20,98,30);
3291 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3292 SetRectRgn( tmprgn, 20,30,30,88);
3293 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3294 SetRectRgn( tmprgn, 0,88,30,98);
3295 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3296 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3298 /* clean up */
3299 DeleteObject( hrgn);
3300 DeleteObject( exprgn);
3301 DeleteObject( tmprgn);
3302 DestroyWindow( hwnd1);
3303 DestroyWindow( hwnd2);
3306 /* couple of tests of return values of scrollbar functions
3307 * called on a scrollbarless window */
3308 static void test_scroll(void)
3310 BOOL ret;
3311 INT min, max;
3312 SCROLLINFO si;
3313 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3314 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3315 100, 100, 200, 200, 0, 0, 0, NULL);
3316 /* horizontal */
3317 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3318 if (!ret) /* win9x */
3320 win_skip( "GetScrollRange doesn't work\n" );
3321 DestroyWindow( hwnd);
3322 return;
3324 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3325 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3326 si.cbSize = sizeof( si);
3327 si.fMask = SIF_PAGE;
3328 si.nPage = 0xdeadbeef;
3329 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3330 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3331 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3332 /* vertical */
3333 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3334 ok( ret, "GetScrollRange returns FALSE\n");
3335 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3336 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3337 si.cbSize = sizeof( si);
3338 si.fMask = SIF_PAGE;
3339 si.nPage = 0xdeadbeef;
3340 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3341 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3342 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3343 /* clean up */
3344 DestroyWindow( hwnd);
3347 static void test_scrolldc( HWND parent)
3349 HDC hdc;
3350 HRGN exprgn, tmprgn, hrgn;
3351 RECT rc, rc2, rcu, cliprc;
3352 HWND hwnd1;
3353 COLORREF colr;
3355 hrgn = CreateRectRgn(0,0,0,0);
3356 tmprgn = CreateRectRgn(0,0,0,0);
3357 exprgn = CreateRectRgn(0,0,0,0);
3359 hwnd1 = CreateWindowExA(0, "static", NULL,
3360 WS_CHILD| WS_VISIBLE,
3361 25, 50, 100, 100, parent, 0, 0, NULL);
3362 ShowWindow( parent, SW_SHOW);
3363 UpdateWindow( parent);
3364 flush_events( TRUE );
3365 GetClientRect( hwnd1, &rc);
3366 hdc = GetDC( hwnd1);
3367 /* paint the upper half of the window black */
3368 rc2 = rc;
3369 rc2.bottom = ( rc.top + rc.bottom) /2;
3370 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3371 /* clip region is the lower half */
3372 cliprc=rc;
3373 cliprc.top = (rc.top + rc.bottom) /2;
3374 /* test whether scrolled pixels are properly clipped */
3375 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3376 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3377 /* this scroll should not cause any visible changes */
3378 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3379 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3380 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3381 /* test with NULL clip rect */
3382 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3383 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3384 trace("update rect: %d,%d - %d,%d\n",
3385 rcu.left, rcu.top, rcu.right, rcu.bottom);
3386 if (winetest_debug > 0) dump_region(hrgn);
3387 SetRect(&rc2, 0, 0, 100, 100);
3388 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3389 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3391 SetRectRgn( exprgn, 0, 0, 20, 80);
3392 SetRectRgn( tmprgn, 0, 80, 100, 100);
3393 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3394 if (winetest_debug > 0) dump_region(exprgn);
3395 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3396 /* test clip rect > scroll rect */
3397 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3398 rc2=rc;
3399 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3400 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3401 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3402 SetRectRgn( exprgn, 25, 25, 75, 35);
3403 SetRectRgn( tmprgn, 25, 35, 35, 75);
3404 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3405 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3406 colr = GetPixel( hdc, 80, 80);
3407 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3408 trace("update rect: %d,%d - %d,%d\n",
3409 rcu.left, rcu.top, rcu.right, rcu.bottom);
3410 if (winetest_debug > 0) dump_region(hrgn);
3412 /* clean up */
3413 DeleteObject(hrgn);
3414 DeleteObject(exprgn);
3415 DeleteObject(tmprgn);
3416 DestroyWindow(hwnd1);
3419 static void test_params(void)
3421 HWND hwnd;
3422 INT rc;
3424 /* Just a param check */
3425 if (pGetMonitorInfoA)
3427 SetLastError(0xdeadbeef);
3428 rc = GetWindowText(hwndMain2, NULL, 1024);
3429 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
3431 else
3433 /* Skips actually on Win95 and NT4 */
3434 win_skip("Test would crash on Win95\n");
3437 SetLastError(0xdeadbeef);
3438 hwnd=CreateWindow("LISTBOX", "TestList",
3439 (LBS_STANDARD & ~LBS_SORT),
3440 0, 0, 100, 100,
3441 NULL, (HMENU)1, NULL, 0);
3443 ok(!hwnd, "CreateWindow with invalid menu handle should fail\n");
3444 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3445 GetLastError() == 0xdeadbeef, /* Win9x */
3446 "wrong last error value %d\n", GetLastError());
3449 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3451 HWND hwnd = 0;
3453 hwnd = CreateWindowEx(exStyle, class, class, style,
3454 110, 100,
3455 225, 200,
3457 menu ? hmenu : 0,
3458 0, 0);
3459 if (!hwnd) {
3460 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
3461 return;
3463 ShowWindow(hwnd, SW_SHOW);
3465 test_nonclient_area(hwnd);
3467 SetMenu(hwnd, 0);
3468 DestroyWindow(hwnd);
3471 static BOOL AWR_init(void)
3473 WNDCLASS class;
3475 class.style = CS_HREDRAW | CS_VREDRAW;
3476 class.lpfnWndProc = DefWindowProcA;
3477 class.cbClsExtra = 0;
3478 class.cbWndExtra = 0;
3479 class.hInstance = 0;
3480 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3481 class.hCursor = LoadCursor (0, IDC_ARROW);
3482 class.hbrBackground = 0;
3483 class.lpszMenuName = 0;
3484 class.lpszClassName = szAWRClass;
3486 if (!RegisterClass (&class)) {
3487 ok(FALSE, "RegisterClass failed\n");
3488 return FALSE;
3491 hmenu = CreateMenu();
3492 if (!hmenu)
3493 return FALSE;
3494 ok(hmenu != 0, "Failed to create menu\n");
3495 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3497 return TRUE;
3501 static void test_AWR_window_size(BOOL menu)
3503 LONG styles[] = {
3504 WS_POPUP,
3505 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3506 WS_SYSMENU,
3507 WS_THICKFRAME,
3508 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3509 WS_HSCROLL, WS_VSCROLL
3511 LONG exStyles[] = {
3512 WS_EX_CLIENTEDGE,
3513 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3514 WS_EX_APPWINDOW,
3515 #if 0
3516 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3517 WS_EX_DLGMODALFRAME,
3518 WS_EX_STATICEDGE,
3519 #endif
3522 int i;
3524 /* A exhaustive check of all the styles takes too long
3525 * so just do a (hopefully representative) sample
3527 for (i = 0; i < COUNTOF(styles); ++i)
3528 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3529 for (i = 0; i < COUNTOF(exStyles); ++i) {
3530 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3531 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3534 #undef COUNTOF
3536 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3538 static void test_AdjustWindowRect(void)
3540 if (!AWR_init())
3541 return;
3543 SHOWSYSMETRIC(SM_CYCAPTION);
3544 SHOWSYSMETRIC(SM_CYSMCAPTION);
3545 SHOWSYSMETRIC(SM_CYMENU);
3546 SHOWSYSMETRIC(SM_CXEDGE);
3547 SHOWSYSMETRIC(SM_CYEDGE);
3548 SHOWSYSMETRIC(SM_CXVSCROLL);
3549 SHOWSYSMETRIC(SM_CYHSCROLL);
3550 SHOWSYSMETRIC(SM_CXFRAME);
3551 SHOWSYSMETRIC(SM_CYFRAME);
3552 SHOWSYSMETRIC(SM_CXDLGFRAME);
3553 SHOWSYSMETRIC(SM_CYDLGFRAME);
3554 SHOWSYSMETRIC(SM_CXBORDER);
3555 SHOWSYSMETRIC(SM_CYBORDER);
3557 test_AWR_window_size(FALSE);
3558 test_AWR_window_size(TRUE);
3560 DestroyMenu(hmenu);
3562 #undef SHOWSYSMETRIC
3565 /* Global variables to trigger exit from loop */
3566 static int redrawComplete, WMPAINT_count;
3568 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3570 switch (msg)
3572 case WM_PAINT:
3573 trace("doing WM_PAINT %d\n", WMPAINT_count);
3574 WMPAINT_count++;
3575 if (WMPAINT_count > 10 && redrawComplete == 0) {
3576 PAINTSTRUCT ps;
3577 BeginPaint(hwnd, &ps);
3578 EndPaint(hwnd, &ps);
3579 return 1;
3581 return 0;
3583 return DefWindowProc(hwnd, msg, wparam, lparam);
3586 /* Ensure we exit from RedrawNow regardless of invalidated area */
3587 static void test_redrawnow(void)
3589 WNDCLASSA cls;
3590 HWND hwndMain;
3592 cls.style = CS_DBLCLKS;
3593 cls.lpfnWndProc = redraw_window_procA;
3594 cls.cbClsExtra = 0;
3595 cls.cbWndExtra = 0;
3596 cls.hInstance = GetModuleHandleA(0);
3597 cls.hIcon = 0;
3598 cls.hCursor = LoadCursorA(0, IDC_ARROW);
3599 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3600 cls.lpszMenuName = NULL;
3601 cls.lpszClassName = "RedrawWindowClass";
3603 if(!RegisterClassA(&cls)) {
3604 trace("Register failed %d\n", GetLastError());
3605 return;
3608 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3609 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3611 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3612 ShowWindow(hwndMain, SW_SHOW);
3613 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3614 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3615 ok( WMPAINT_count == 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3616 redrawComplete = TRUE;
3617 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3619 /* clean up */
3620 DestroyWindow( hwndMain);
3623 struct parentdc_stat {
3624 RECT client;
3625 RECT clip;
3626 RECT paint;
3629 struct parentdc_test {
3630 struct parentdc_stat main, main_todo;
3631 struct parentdc_stat child1, child1_todo;
3632 struct parentdc_stat child2, child2_todo;
3635 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3637 RECT rc;
3638 PAINTSTRUCT ps;
3640 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3642 switch (msg)
3644 case WM_PAINT:
3645 GetClientRect(hwnd, &rc);
3646 CopyRect(&t->client, &rc);
3647 GetWindowRect(hwnd, &rc);
3648 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd,
3649 t->client.left, t->client.top, t->client.right, t->client.bottom,
3650 rc.left, rc.top, rc.right, rc.bottom);
3651 BeginPaint(hwnd, &ps);
3652 CopyRect(&t->paint, &ps.rcPaint);
3653 GetClipBox(ps.hdc, &rc);
3654 CopyRect(&t->clip, &rc);
3655 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
3656 rc.left, rc.top, rc.right, rc.bottom,
3657 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3658 EndPaint(hwnd, &ps);
3659 return 0;
3661 return DefWindowProc(hwnd, msg, wparam, lparam);
3664 static void zero_parentdc_stat(struct parentdc_stat *t)
3666 SetRectEmpty(&t->client);
3667 SetRectEmpty(&t->clip);
3668 SetRectEmpty(&t->paint);
3671 static void zero_parentdc_test(struct parentdc_test *t)
3673 zero_parentdc_stat(&t->main);
3674 zero_parentdc_stat(&t->child1);
3675 zero_parentdc_stat(&t->child2);
3678 #define parentdc_field_ok(t, w, r, f, got) \
3679 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3680 ": expected %d, got %d\n", \
3681 t.w.r.f, got.w.r.f)
3683 #define parentdc_todo_field_ok(t, w, r, f, got) \
3684 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3685 else parentdc_field_ok(t, w, r, f, got)
3687 #define parentdc_rect_ok(t, w, r, got) \
3688 parentdc_todo_field_ok(t, w, r, left, got); \
3689 parentdc_todo_field_ok(t, w, r, top, got); \
3690 parentdc_todo_field_ok(t, w, r, right, got); \
3691 parentdc_todo_field_ok(t, w, r, bottom, got);
3693 #define parentdc_win_ok(t, w, got) \
3694 parentdc_rect_ok(t, w, client, got); \
3695 parentdc_rect_ok(t, w, clip, got); \
3696 parentdc_rect_ok(t, w, paint, got);
3698 #define parentdc_ok(t, got) \
3699 parentdc_win_ok(t, main, got); \
3700 parentdc_win_ok(t, child1, got); \
3701 parentdc_win_ok(t, child2, got);
3703 static void test_csparentdc(void)
3705 WNDCLASSA clsMain, cls;
3706 HWND hwndMain, hwnd1, hwnd2;
3707 RECT rc;
3709 struct parentdc_test test_answer;
3711 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3712 const struct parentdc_test test1 =
3714 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
3715 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3716 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3719 const struct parentdc_test test2 =
3721 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
3722 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3723 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3726 const struct parentdc_test test3 =
3728 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3729 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3730 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3733 const struct parentdc_test test4 =
3735 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
3736 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
3737 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3740 const struct parentdc_test test5 =
3742 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
3743 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3744 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3747 const struct parentdc_test test6 =
3749 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3750 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3751 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3754 const struct parentdc_test test7 =
3756 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3757 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3758 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3760 #undef nothing_todo
3762 clsMain.style = CS_DBLCLKS;
3763 clsMain.lpfnWndProc = parentdc_window_procA;
3764 clsMain.cbClsExtra = 0;
3765 clsMain.cbWndExtra = 0;
3766 clsMain.hInstance = GetModuleHandleA(0);
3767 clsMain.hIcon = 0;
3768 clsMain.hCursor = LoadCursorA(0, IDC_ARROW);
3769 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
3770 clsMain.lpszMenuName = NULL;
3771 clsMain.lpszClassName = "ParentDcMainWindowClass";
3773 if(!RegisterClassA(&clsMain)) {
3774 trace("Register failed %d\n", GetLastError());
3775 return;
3778 cls.style = CS_DBLCLKS | CS_PARENTDC;
3779 cls.lpfnWndProc = parentdc_window_procA;
3780 cls.cbClsExtra = 0;
3781 cls.cbWndExtra = 0;
3782 cls.hInstance = GetModuleHandleA(0);
3783 cls.hIcon = 0;
3784 cls.hCursor = LoadCursorA(0, IDC_ARROW);
3785 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3786 cls.lpszMenuName = NULL;
3787 cls.lpszClassName = "ParentDcWindowClass";
3789 if(!RegisterClassA(&cls)) {
3790 trace("Register failed %d\n", GetLastError());
3791 return;
3794 SetRect(&rc, 0, 0, 150, 150);
3795 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
3796 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3797 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
3798 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
3799 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
3800 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
3801 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
3802 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
3803 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
3804 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
3805 ShowWindow(hwndMain, SW_SHOW);
3806 ShowWindow(hwnd1, SW_SHOW);
3807 ShowWindow(hwnd2, SW_SHOW);
3808 SetWindowPos(hwndMain, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
3809 flush_events( TRUE );
3811 zero_parentdc_test(&test_answer);
3812 InvalidateRect(hwndMain, NULL, TRUE);
3813 flush_events( TRUE );
3814 parentdc_ok(test1, test_answer);
3816 zero_parentdc_test(&test_answer);
3817 SetRect(&rc, 0, 0, 50, 50);
3818 InvalidateRect(hwndMain, &rc, TRUE);
3819 flush_events( TRUE );
3820 parentdc_ok(test2, test_answer);
3822 zero_parentdc_test(&test_answer);
3823 SetRect(&rc, 0, 0, 10, 10);
3824 InvalidateRect(hwndMain, &rc, TRUE);
3825 flush_events( TRUE );
3826 parentdc_ok(test3, test_answer);
3828 zero_parentdc_test(&test_answer);
3829 SetRect(&rc, 40, 40, 50, 50);
3830 InvalidateRect(hwndMain, &rc, TRUE);
3831 flush_events( TRUE );
3832 parentdc_ok(test4, test_answer);
3834 zero_parentdc_test(&test_answer);
3835 SetRect(&rc, 20, 20, 60, 60);
3836 InvalidateRect(hwndMain, &rc, TRUE);
3837 flush_events( TRUE );
3838 parentdc_ok(test5, test_answer);
3840 zero_parentdc_test(&test_answer);
3841 SetRect(&rc, 0, 0, 10, 10);
3842 InvalidateRect(hwnd1, &rc, TRUE);
3843 flush_events( TRUE );
3844 parentdc_ok(test6, test_answer);
3846 zero_parentdc_test(&test_answer);
3847 SetRect(&rc, -5, -5, 65, 65);
3848 InvalidateRect(hwnd1, &rc, TRUE);
3849 flush_events( TRUE );
3850 parentdc_ok(test7, test_answer);
3852 DestroyWindow(hwndMain);
3853 DestroyWindow(hwnd1);
3854 DestroyWindow(hwnd2);
3857 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3859 return DefWindowProcA(hwnd, msg, wparam, lparam);
3862 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3864 return DefWindowProcW(hwnd, msg, wparam, lparam);
3867 static void test_IsWindowUnicode(void)
3869 static const char ansi_class_nameA[] = "ansi class name";
3870 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3871 static const char unicode_class_nameA[] = "unicode class name";
3872 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3873 WNDCLASSA classA;
3874 WNDCLASSW classW;
3875 HWND hwnd;
3877 memset(&classW, 0, sizeof(classW));
3878 classW.hInstance = GetModuleHandleA(0);
3879 classW.lpfnWndProc = def_window_procW;
3880 classW.lpszClassName = unicode_class_nameW;
3881 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
3883 memset(&classA, 0, sizeof(classA));
3884 classA.hInstance = GetModuleHandleA(0);
3885 classA.lpfnWndProc = def_window_procA;
3886 classA.lpszClassName = ansi_class_nameA;
3887 assert(RegisterClassA(&classA));
3889 /* unicode class: window proc */
3890 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3891 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3892 assert(hwnd);
3894 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3895 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3896 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3897 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3898 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3900 DestroyWindow(hwnd);
3902 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3903 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3904 assert(hwnd);
3906 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3907 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3908 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3909 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3910 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3912 DestroyWindow(hwnd);
3914 /* ansi class: window proc */
3915 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3916 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3917 assert(hwnd);
3919 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3920 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3921 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3922 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3923 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3925 DestroyWindow(hwnd);
3927 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3928 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3929 assert(hwnd);
3931 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3932 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3933 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3934 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3935 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3937 DestroyWindow(hwnd);
3939 /* unicode class: class proc */
3940 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3941 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3942 assert(hwnd);
3944 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3945 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3946 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3947 /* do not restore class window proc back to unicode */
3949 DestroyWindow(hwnd);
3951 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3952 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3953 assert(hwnd);
3955 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3956 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
3957 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3959 DestroyWindow(hwnd);
3961 /* ansi class: class proc */
3962 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3963 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3964 assert(hwnd);
3966 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3967 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
3968 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3969 /* do not restore class window proc back to ansi */
3971 DestroyWindow(hwnd);
3973 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3974 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3975 assert(hwnd);
3977 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3978 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3979 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3981 DestroyWindow(hwnd);
3984 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
3986 MINMAXINFO *minmax;
3988 if (msg != WM_GETMINMAXINFO)
3989 return DefWindowProc(hwnd, msg, wp, lp);
3991 minmax = (MINMAXINFO *)lp;
3993 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
3995 minmax->ptReserved.x = 0;
3996 minmax->ptReserved.y = 0;
3997 minmax->ptMaxSize.x = 400;
3998 minmax->ptMaxSize.y = 400;
3999 minmax->ptMaxPosition.x = 300;
4000 minmax->ptMaxPosition.y = 300;
4001 minmax->ptMaxTrackSize.x = 200;
4002 minmax->ptMaxTrackSize.y = 200;
4003 minmax->ptMinTrackSize.x = 100;
4004 minmax->ptMinTrackSize.y = 100;
4006 else
4007 DefWindowProc(hwnd, msg, wp, lp);
4008 return 1;
4011 static int expected_cx, expected_cy;
4012 static RECT expected_rect, broken_rect;
4014 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4016 switch(msg)
4018 case WM_GETMINMAXINFO:
4020 RECT rect;
4021 GetWindowRect( hwnd, &rect );
4022 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
4023 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4024 return DefWindowProc(hwnd, msg, wp, lp);
4026 case WM_NCCREATE:
4027 case WM_CREATE:
4029 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
4030 RECT rect;
4031 GetWindowRect( hwnd, &rect );
4032 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
4033 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
4034 ok( cs->cx == expected_cx || broken(cs->cx == (short)expected_cx),
4035 "wrong x size %d/%d\n", cs->cx, expected_cx );
4036 ok( cs->cy == expected_cy || broken(cs->cy == (short)expected_cy),
4037 "wrong y size %d/%d\n", cs->cy, expected_cy );
4038 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
4039 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
4040 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
4041 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top) ||
4042 broken( rect.right - rect.left == (short)broken_rect.right - (short)broken_rect.left &&
4043 rect.bottom - rect.top == (short)broken_rect.bottom - (short)broken_rect.top),
4044 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
4045 rect.left, rect.top, rect.right, rect.bottom,
4046 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
4047 return DefWindowProc(hwnd, msg, wp, lp);
4049 case WM_NCCALCSIZE:
4051 RECT rect, *r = (RECT *)lp;
4052 GetWindowRect( hwnd, &rect );
4053 ok( !memcmp( &rect, r, sizeof(rect) ),
4054 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
4055 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
4056 return DefWindowProc(hwnd, msg, wp, lp);
4058 default:
4059 return DefWindowProc(hwnd, msg, wp, lp);
4063 static void test_CreateWindow(void)
4065 WNDCLASS cls;
4066 HWND hwnd, parent;
4067 HMENU hmenu;
4068 RECT rc, rc_minmax;
4069 MINMAXINFO minmax;
4071 #define expect_menu(window, menu) \
4072 SetLastError(0xdeadbeef); \
4073 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
4075 #define expect_style(window, style)\
4076 ok((ULONG)GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
4078 #define expect_ex_style(window, ex_style)\
4079 ok((ULONG)GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
4081 #define expect_gle_broken_9x(gle)\
4082 ok(GetLastError() == gle ||\
4083 broken(GetLastError() == 0xdeadbeef),\
4084 "IsMenu set error %d\n", GetLastError())
4086 hmenu = CreateMenu();
4087 assert(hmenu != 0);
4088 parent = GetDesktopWindow();
4089 assert(parent != 0);
4091 SetLastError(0xdeadbeef);
4092 ok(IsMenu(hmenu), "IsMenu error %d\n", GetLastError());
4094 /* WS_CHILD */
4095 SetLastError(0xdeadbeef);
4096 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
4097 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4098 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4099 expect_menu(hwnd, 1);
4100 expect_style(hwnd, WS_CHILD);
4101 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4102 DestroyWindow(hwnd);
4104 SetLastError(0xdeadbeef);
4105 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
4106 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4107 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4108 expect_menu(hwnd, 1);
4109 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4110 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4111 DestroyWindow(hwnd);
4113 SetLastError(0xdeadbeef);
4114 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
4115 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4116 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4117 expect_menu(hwnd, 1);
4118 expect_style(hwnd, WS_CHILD);
4119 expect_ex_style(hwnd, 0);
4120 DestroyWindow(hwnd);
4122 SetLastError(0xdeadbeef);
4123 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
4124 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4125 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4126 expect_menu(hwnd, 1);
4127 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4128 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4129 DestroyWindow(hwnd);
4131 /* WS_POPUP */
4132 SetLastError(0xdeadbeef);
4133 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4134 0, 0, 100, 100, parent, hmenu, 0, NULL);
4135 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4136 expect_menu(hwnd, hmenu);
4137 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4138 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4139 DestroyWindow(hwnd);
4140 SetLastError(0xdeadbeef);
4141 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4142 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4144 hmenu = CreateMenu();
4145 assert(hmenu != 0);
4146 SetLastError(0xdeadbeef);
4147 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
4148 0, 0, 100, 100, parent, hmenu, 0, NULL);
4149 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4150 expect_menu(hwnd, hmenu);
4151 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4152 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4153 DestroyWindow(hwnd);
4154 SetLastError(0xdeadbeef);
4155 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4156 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4158 hmenu = CreateMenu();
4159 assert(hmenu != 0);
4160 SetLastError(0xdeadbeef);
4161 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
4162 0, 0, 100, 100, parent, hmenu, 0, NULL);
4163 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4164 expect_menu(hwnd, hmenu);
4165 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4166 expect_ex_style(hwnd, 0);
4167 DestroyWindow(hwnd);
4168 SetLastError(0xdeadbeef);
4169 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4170 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4172 hmenu = CreateMenu();
4173 assert(hmenu != 0);
4174 SetLastError(0xdeadbeef);
4175 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
4176 0, 0, 100, 100, parent, hmenu, 0, NULL);
4177 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4178 expect_menu(hwnd, hmenu);
4179 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4180 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4181 DestroyWindow(hwnd);
4182 SetLastError(0xdeadbeef);
4183 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4184 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4186 /* WS_CHILD | WS_POPUP */
4187 SetLastError(0xdeadbeef);
4188 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4189 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4190 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4191 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4192 if (hwnd)
4193 DestroyWindow(hwnd);
4195 hmenu = CreateMenu();
4196 assert(hmenu != 0);
4197 SetLastError(0xdeadbeef);
4198 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4199 0, 0, 100, 100, parent, hmenu, 0, NULL);
4200 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4201 expect_menu(hwnd, hmenu);
4202 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4203 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4204 DestroyWindow(hwnd);
4205 SetLastError(0xdeadbeef);
4206 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4207 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4209 SetLastError(0xdeadbeef);
4210 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4211 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4212 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4213 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4214 if (hwnd)
4215 DestroyWindow(hwnd);
4217 hmenu = CreateMenu();
4218 assert(hmenu != 0);
4219 SetLastError(0xdeadbeef);
4220 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4221 0, 0, 100, 100, parent, hmenu, 0, NULL);
4222 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4223 expect_menu(hwnd, hmenu);
4224 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4225 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4226 DestroyWindow(hwnd);
4227 SetLastError(0xdeadbeef);
4228 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4229 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4231 SetLastError(0xdeadbeef);
4232 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4233 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4234 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4235 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4236 if (hwnd)
4237 DestroyWindow(hwnd);
4239 hmenu = CreateMenu();
4240 assert(hmenu != 0);
4241 SetLastError(0xdeadbeef);
4242 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4243 0, 0, 100, 100, parent, hmenu, 0, NULL);
4244 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4245 expect_menu(hwnd, hmenu);
4246 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4247 expect_ex_style(hwnd, 0);
4248 DestroyWindow(hwnd);
4249 SetLastError(0xdeadbeef);
4250 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4251 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4253 SetLastError(0xdeadbeef);
4254 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4255 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4256 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4257 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4258 if (hwnd)
4259 DestroyWindow(hwnd);
4261 hmenu = CreateMenu();
4262 assert(hmenu != 0);
4263 SetLastError(0xdeadbeef);
4264 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4265 0, 0, 100, 100, parent, hmenu, 0, NULL);
4266 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4267 expect_menu(hwnd, hmenu);
4268 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4269 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4270 DestroyWindow(hwnd);
4271 SetLastError(0xdeadbeef);
4272 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4273 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4275 /* test child window sizing */
4276 cls.style = 0;
4277 cls.lpfnWndProc = minmax_wnd_proc;
4278 cls.cbClsExtra = 0;
4279 cls.cbWndExtra = 0;
4280 cls.hInstance = GetModuleHandle(0);
4281 cls.hIcon = 0;
4282 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4283 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4284 cls.lpszMenuName = NULL;
4285 cls.lpszClassName = "MinMax_WndClass";
4286 RegisterClass(&cls);
4288 SetLastError(0xdeadbeef);
4289 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4290 0, 0, 100, 100, 0, 0, 0, NULL);
4291 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4292 expect_menu(parent, 0);
4293 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
4294 expect_ex_style(parent, WS_EX_WINDOWEDGE);
4296 memset(&minmax, 0, sizeof(minmax));
4297 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4298 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
4299 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
4300 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4301 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
4303 GetWindowRect(parent, &rc);
4304 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
4305 GetClientRect(parent, &rc);
4306 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
4308 InflateRect(&rc, 200, 200);
4309 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4311 SetLastError(0xdeadbeef);
4312 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4313 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
4314 parent, (HMENU)1, 0, NULL);
4315 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4316 expect_menu(hwnd, 1);
4317 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
4318 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4320 memset(&minmax, 0, sizeof(minmax));
4321 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4322 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4324 GetWindowRect(hwnd, &rc);
4325 OffsetRect(&rc, -rc.left, -rc.top);
4326 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4327 rc.left, rc.top, rc.right, rc.bottom,
4328 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
4329 DestroyWindow(hwnd);
4331 cls.lpfnWndProc = winsizes_wnd_proc;
4332 cls.lpszClassName = "Sizes_WndClass";
4333 RegisterClass(&cls);
4335 expected_cx = expected_cy = 200000;
4336 SetRect( &expected_rect, 0, 0, 200000, 200000 );
4337 broken_rect = expected_rect;
4338 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
4339 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4340 GetClientRect( hwnd, &rc );
4341 ok( rc.right == 200000 || broken(rc.right == (short)200000), "invalid rect right %u\n", rc.right );
4342 ok( rc.bottom == 200000 || broken(rc.bottom == (short)200000), "invalid rect bottom %u\n", rc.bottom );
4343 DestroyWindow(hwnd);
4345 expected_cx = expected_cy = -10;
4346 SetRect( &expected_rect, 0, 0, 0, 0 );
4347 SetRect( &broken_rect, 0, 0, -10, -10 );
4348 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
4349 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4350 GetClientRect( hwnd, &rc );
4351 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4352 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4353 DestroyWindow(hwnd);
4355 expected_cx = expected_cy = -200000;
4356 SetRect( &expected_rect, 0, 0, 0, 0 );
4357 SetRect( &broken_rect, 0, 0, -200000, -200000 );
4358 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
4359 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4360 GetClientRect( hwnd, &rc );
4361 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4362 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4363 DestroyWindow(hwnd);
4365 /* we need a parent at 0,0 so that child coordinates match */
4366 DestroyWindow(parent);
4367 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
4368 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4370 expected_cx = 100;
4371 expected_cy = 0x7fffffff;
4372 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
4373 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
4374 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
4375 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4376 GetClientRect( hwnd, &rc );
4377 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
4378 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4379 DestroyWindow(hwnd);
4381 expected_cx = 0x7fffffff;
4382 expected_cy = 0x7fffffff;
4383 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
4384 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
4385 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
4386 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4387 GetClientRect( hwnd, &rc );
4388 ok( rc.right == 0x7fffffff - 20 || broken(rc.right == 0), "invalid rect right %u\n", rc.right );
4389 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4390 DestroyWindow(hwnd);
4392 /* top level window */
4393 expected_cx = expected_cy = 200000;
4394 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
4395 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
4396 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4397 GetClientRect( hwnd, &rc );
4398 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
4399 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
4400 DestroyWindow(hwnd);
4402 DestroyWindow(parent);
4404 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4405 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4407 #undef expect_gle_broken_9x
4408 #undef expect_menu
4409 #undef expect_style
4410 #undef expect_ex_style
4413 /* function that remembers whether the system the test is running on sets the
4414 * last error for user32 functions to make the tests stricter */
4415 static int check_error(DWORD actual, DWORD expected)
4417 static int sets_last_error = -1;
4418 if (sets_last_error == -1)
4419 sets_last_error = (actual != 0xdeadbeef);
4420 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
4423 static void test_SetWindowLong(void)
4425 LONG_PTR retval;
4426 WNDPROC old_window_procW;
4428 SetLastError(0xdeadbeef);
4429 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
4430 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
4431 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
4432 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4434 SetLastError(0xdeadbeef);
4435 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
4436 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
4437 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
4438 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4440 SetLastError(0xdeadbeef);
4441 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4442 ok((WNDPROC)retval == main_window_procA || broken(!retval), /* win9x */
4443 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
4444 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4445 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
4446 ok((WNDPROC)retval == main_window_procA,
4447 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4448 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
4450 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
4451 SetLastError(0xdeadbeef);
4452 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
4453 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
4455 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4456 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
4457 ok((WNDPROC)retval == old_window_procW,
4458 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4459 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
4461 /* set it back to ANSI */
4462 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4466 static void test_ShowWindow(void)
4468 HWND hwnd;
4469 DWORD style;
4470 RECT rcMain, rc;
4471 LPARAM ret;
4473 SetRect(&rcMain, 120, 120, 210, 210);
4475 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
4476 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4477 WS_MAXIMIZEBOX | WS_POPUP,
4478 rcMain.left, rcMain.top,
4479 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
4480 0, 0, 0, NULL);
4481 assert(hwnd);
4483 style = GetWindowLong(hwnd, GWL_STYLE);
4484 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4485 ok(!(style & WS_VISIBLE), "window should not be visible\n");
4486 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4487 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4488 GetWindowRect(hwnd, &rc);
4489 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4490 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4491 rc.left, rc.top, rc.right, rc.bottom);
4493 ret = ShowWindow(hwnd, SW_SHOW);
4494 ok(!ret, "not expected ret: %lu\n", ret);
4495 style = GetWindowLong(hwnd, GWL_STYLE);
4496 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4497 ok(style & WS_VISIBLE, "window should be visible\n");
4498 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4499 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4500 GetWindowRect(hwnd, &rc);
4501 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4502 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4503 rc.left, rc.top, rc.right, rc.bottom);
4505 ret = ShowWindow(hwnd, SW_MINIMIZE);
4506 ok(ret, "not expected ret: %lu\n", ret);
4507 style = GetWindowLong(hwnd, GWL_STYLE);
4508 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4509 ok(style & WS_VISIBLE, "window should be visible\n");
4510 ok(style & WS_MINIMIZE, "window should be minimized\n");
4511 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4512 GetWindowRect(hwnd, &rc);
4513 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4515 ShowWindow(hwnd, SW_RESTORE);
4516 ok(ret, "not expected ret: %lu\n", ret);
4517 style = GetWindowLong(hwnd, GWL_STYLE);
4518 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4519 ok(style & WS_VISIBLE, "window should be visible\n");
4520 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4521 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4522 GetWindowRect(hwnd, &rc);
4523 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4524 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4525 rc.left, rc.top, rc.right, rc.bottom);
4527 ret = EnableWindow(hwnd, FALSE);
4528 ok(!ret, "not expected ret: %lu\n", ret);
4529 style = GetWindowLong(hwnd, GWL_STYLE);
4530 ok(style & WS_DISABLED, "window should be disabled\n");
4532 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
4533 ok(!ret, "not expected ret: %lu\n", ret);
4534 style = GetWindowLong(hwnd, GWL_STYLE);
4535 ok(style & WS_DISABLED, "window should be disabled\n");
4536 ok(style & WS_VISIBLE, "window should be visible\n");
4537 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4538 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4539 GetWindowRect(hwnd, &rc);
4540 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4541 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4542 rc.left, rc.top, rc.right, rc.bottom);
4544 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
4545 ok(!ret, "not expected ret: %lu\n", ret);
4546 style = GetWindowLong(hwnd, GWL_STYLE);
4547 ok(style & WS_DISABLED, "window should be disabled\n");
4548 ok(style & WS_VISIBLE, "window should be visible\n");
4549 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4550 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4551 GetWindowRect(hwnd, &rc);
4552 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4553 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4554 rc.left, rc.top, rc.right, rc.bottom);
4556 ret = ShowWindow(hwnd, SW_MINIMIZE);
4557 ok(ret, "not expected ret: %lu\n", ret);
4558 style = GetWindowLong(hwnd, GWL_STYLE);
4559 ok(style & WS_DISABLED, "window should be disabled\n");
4560 ok(style & WS_VISIBLE, "window should be visible\n");
4561 ok(style & WS_MINIMIZE, "window should be minimized\n");
4562 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4563 GetWindowRect(hwnd, &rc);
4564 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4566 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
4567 ok(!ret, "not expected ret: %lu\n", ret);
4568 style = GetWindowLong(hwnd, GWL_STYLE);
4569 ok(style & WS_DISABLED, "window should be disabled\n");
4570 ok(style & WS_VISIBLE, "window should be visible\n");
4571 ok(style & WS_MINIMIZE, "window should be minimized\n");
4572 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4573 GetWindowRect(hwnd, &rc);
4574 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4576 ret = ShowWindow(hwnd, SW_RESTORE);
4577 ok(ret, "not expected ret: %lu\n", ret);
4578 style = GetWindowLong(hwnd, GWL_STYLE);
4579 ok(style & WS_DISABLED, "window should be disabled\n");
4580 ok(style & WS_VISIBLE, "window should be visible\n");
4581 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4582 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4583 GetWindowRect(hwnd, &rc);
4584 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4585 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4586 rc.left, rc.top, rc.right, rc.bottom);
4588 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4589 ok(!ret, "not expected ret: %lu\n", ret);
4590 ok(IsWindow(hwnd), "window should exist\n");
4592 ret = EnableWindow(hwnd, TRUE);
4593 ok(ret, "not expected ret: %lu\n", ret);
4595 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4596 ok(!ret, "not expected ret: %lu\n", ret);
4597 ok(!IsWindow(hwnd), "window should not exist\n");
4600 static void test_gettext(void)
4602 WNDCLASS cls;
4603 LPCSTR clsname = "gettexttest";
4604 HWND hwnd;
4605 LRESULT r;
4607 memset( &cls, 0, sizeof cls );
4608 cls.lpfnWndProc = DefWindowProc;
4609 cls.lpszClassName = clsname;
4610 cls.hInstance = GetModuleHandle(NULL);
4612 if (!RegisterClass( &cls )) return;
4614 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
4615 ok( hwnd != NULL, "window was null\n");
4617 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
4618 ok( r == 0, "settext should return zero\n");
4620 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
4621 ok( r == 0, "settext should return zero (%ld)\n", r);
4623 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
4624 ok( r == 0, "settext should return zero (%ld)\n", r);
4626 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
4627 ok( r == 0, "settext should return zero (%ld)\n", r);
4629 DestroyWindow(hwnd);
4630 UnregisterClass( clsname, NULL );
4634 static void test_GetUpdateRect(void)
4636 MSG msg;
4637 BOOL ret, parent_wm_paint, grandparent_wm_paint;
4638 RECT rc1, rc2;
4639 HWND hgrandparent, hparent, hchild;
4640 WNDCLASSA cls;
4641 static const char classNameA[] = "GetUpdateRectClass";
4643 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
4644 0, 0, 100, 100, NULL, NULL, 0, NULL);
4646 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
4647 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4649 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
4650 10, 10, 30, 30, hparent, NULL, 0, NULL);
4652 ShowWindow(hgrandparent, SW_SHOW);
4653 UpdateWindow(hgrandparent);
4654 flush_events( TRUE );
4656 ShowWindow(hchild, SW_HIDE);
4657 SetRect(&rc2, 0, 0, 0, 0);
4658 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4659 ok(!ret, "GetUpdateRect returned not empty region\n");
4660 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4661 rc1.left, rc1.top, rc1.right, rc1.bottom,
4662 rc2.left, rc2.top, rc2.right, rc2.bottom);
4664 SetRect(&rc2, 10, 10, 40, 40);
4665 ret = GetUpdateRect(hparent, &rc1, FALSE);
4666 ok(ret, "GetUpdateRect returned empty region\n");
4667 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4668 rc1.left, rc1.top, rc1.right, rc1.bottom,
4669 rc2.left, rc2.top, rc2.right, rc2.bottom);
4671 parent_wm_paint = FALSE;
4672 grandparent_wm_paint = FALSE;
4673 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4675 if (msg.message == WM_PAINT)
4677 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4678 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4680 DispatchMessage(&msg);
4682 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4683 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4685 DestroyWindow(hgrandparent);
4687 cls.style = 0;
4688 cls.lpfnWndProc = DefWindowProcA;
4689 cls.cbClsExtra = 0;
4690 cls.cbWndExtra = 0;
4691 cls.hInstance = GetModuleHandleA(0);
4692 cls.hIcon = 0;
4693 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4694 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4695 cls.lpszMenuName = NULL;
4696 cls.lpszClassName = classNameA;
4698 if(!RegisterClassA(&cls)) {
4699 trace("Register failed %d\n", GetLastError());
4700 return;
4703 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
4704 0, 0, 100, 100, NULL, NULL, 0, NULL);
4706 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
4707 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4709 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
4710 10, 10, 30, 30, hparent, NULL, 0, NULL);
4712 ShowWindow(hgrandparent, SW_SHOW);
4713 UpdateWindow(hgrandparent);
4714 flush_events( TRUE );
4716 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4717 ok(!ret, "GetUpdateRect returned not empty region\n");
4719 ShowWindow(hchild, SW_HIDE);
4721 SetRect(&rc2, 0, 0, 0, 0);
4722 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4723 ok(!ret, "GetUpdateRect returned not empty region\n");
4724 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4725 rc1.left, rc1.top, rc1.right, rc1.bottom,
4726 rc2.left, rc2.top, rc2.right, rc2.bottom);
4728 SetRect(&rc2, 10, 10, 40, 40);
4729 ret = GetUpdateRect(hparent, &rc1, FALSE);
4730 ok(ret, "GetUpdateRect returned empty region\n");
4731 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4732 rc1.left, rc1.top, rc1.right, rc1.bottom,
4733 rc2.left, rc2.top, rc2.right, rc2.bottom);
4735 parent_wm_paint = FALSE;
4736 grandparent_wm_paint = FALSE;
4737 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4739 if (msg.message == WM_PAINT)
4741 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4742 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4744 DispatchMessage(&msg);
4746 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4747 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4749 DestroyWindow(hgrandparent);
4753 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
4755 if(msg == WM_PAINT)
4757 PAINTSTRUCT ps;
4758 RECT updateRect;
4759 DWORD waitResult;
4760 HWND win;
4761 const int waitTime = 2000;
4763 BeginPaint(hwnd, &ps);
4765 /* create and destroy window to create an exposed region on this window */
4766 win = CreateWindowA("static", "win", WS_VISIBLE,
4767 10,10,50,50, NULL, NULL, 0, NULL);
4768 DestroyWindow(win);
4770 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
4772 ValidateRect(hwnd, NULL);
4773 EndPaint(hwnd, &ps);
4775 if(waitResult != WAIT_TIMEOUT)
4777 GetUpdateRect(hwnd, &updateRect, FALSE);
4778 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
4781 return 1;
4783 return DefWindowProc(hwnd, msg, wParam, lParam);
4786 static void test_Expose(void)
4788 ATOM atom;
4789 WNDCLASSA cls;
4790 HWND mw;
4791 memset(&cls, 0, sizeof(WNDCLASSA));
4792 cls.lpfnWndProc = TestExposedRegion_WndProc;
4793 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4794 cls.lpszClassName = "TestExposeClass";
4795 atom = RegisterClassA(&cls);
4797 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
4798 0, 0, 200, 100, NULL, NULL, 0, NULL);
4800 UpdateWindow(mw);
4801 DestroyWindow(mw);
4804 static void test_GetWindowModuleFileName(void)
4806 HWND hwnd;
4807 HINSTANCE hinst;
4808 UINT ret1, ret2;
4809 char buf1[MAX_PATH], buf2[MAX_PATH];
4811 if (!pGetWindowModuleFileNameA)
4813 skip("GetWindowModuleFileNameA is not available\n");
4814 return;
4817 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
4818 assert(hwnd);
4820 hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
4821 ok(hinst == 0 || broken(hinst == GetModuleHandle(0)), /* win9x */ "expected 0, got %p\n", hinst);
4823 buf1[0] = 0;
4824 SetLastError(0xdeadbeef);
4825 ret1 = GetModuleFileName(hinst, buf1, sizeof(buf1));
4826 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
4828 buf2[0] = 0;
4829 SetLastError(0xdeadbeef);
4830 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
4831 ok(ret2, "GetWindowModuleFileNameA error %u\n", GetLastError());
4833 ok(ret1 == ret2 || broken(ret2 == ret1 + 1), /* win98 */ "%u != %u\n", ret1, ret2);
4834 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
4836 hinst = GetModuleHandle(0);
4838 SetLastError(0xdeadbeef);
4839 ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
4840 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
4841 "expected %u, got %u\n", ret1 - 2, ret2);
4842 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4843 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4844 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4846 SetLastError(0xdeadbeef);
4847 ret2 = GetModuleFileName(hinst, buf2, 0);
4848 ok(!ret2, "GetModuleFileName should return 0\n");
4849 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4850 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4851 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4853 SetLastError(0xdeadbeef);
4854 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
4855 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
4856 "expected %u, got %u\n", ret1 - 2, ret2);
4857 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4858 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4859 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4861 SetLastError(0xdeadbeef);
4862 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
4863 ok(!ret2, "expected 0, got %u\n", ret2);
4864 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4865 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4866 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4868 DestroyWindow(hwnd);
4870 buf2[0] = 0;
4871 hwnd = (HWND)0xdeadbeef;
4872 SetLastError(0xdeadbeef);
4873 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4874 ok(!ret1, "expected 0, got %u\n", ret1);
4875 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef), /* win9x */
4876 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
4878 hwnd = FindWindow("Shell_TrayWnd", NULL);
4879 ok(IsWindow(hwnd), "got invalid tray window %p\n", hwnd);
4880 SetLastError(0xdeadbeef);
4881 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4882 ok(!ret1 || broken(ret1), /* win98 */ "expected 0, got %u\n", ret1);
4884 if (!ret1) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
4886 ret1 = GetModuleFileName(0, buf1, sizeof(buf1));
4887 hwnd = GetDesktopWindow();
4888 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
4889 SetLastError(0xdeadbeef);
4890 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
4891 ok(!ret2 || ret1 == ret2 /* vista */, "expected 0 or %u, got %u %s\n", ret1, ret2, buf2);
4895 static void test_hwnd_message(void)
4897 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
4898 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
4900 HWND parent = 0, hwnd, found;
4901 RECT rect;
4903 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
4904 on CreateWindowExA and crash later in the test.
4905 Use UNICODE here to fail on win9x */
4906 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
4907 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
4908 if (!hwnd)
4910 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
4911 return;
4914 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
4915 if (pGetAncestor)
4917 char buffer[100];
4918 HWND root, desktop = GetDesktopWindow();
4920 parent = pGetAncestor(hwnd, GA_PARENT);
4921 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
4922 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
4923 root = pGetAncestor(hwnd, GA_ROOT);
4924 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
4925 ok( !pGetAncestor(parent, GA_PARENT) || broken(pGetAncestor(parent, GA_PARENT) != 0), /* win2k */
4926 "parent shouldn't have parent %p\n", pGetAncestor(parent, GA_PARENT) );
4927 trace("parent %p root %p desktop %p\n", parent, root, desktop);
4928 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
4929 ok( !lstrcmpi( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
4930 GetWindowRect( parent, &rect );
4931 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
4932 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4934 GetWindowRect( hwnd, &rect );
4935 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
4936 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4938 /* test FindWindow behavior */
4940 found = FindWindowExA( 0, 0, 0, "message window" );
4941 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
4942 SetLastError(0xdeadbeef);
4943 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
4944 ok( found == 0, "found message window %p/%p\n", found, hwnd );
4945 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
4946 if (parent)
4948 found = FindWindowExA( parent, 0, 0, "message window" );
4949 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
4952 /* test IsChild behavior */
4954 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
4956 /* test IsWindowVisible behavior */
4958 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
4959 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
4961 DestroyWindow(hwnd);
4964 static void test_layered_window(void)
4966 HWND hwnd;
4967 COLORREF key = 0;
4968 BYTE alpha = 0;
4969 DWORD flags = 0;
4970 BOOL ret;
4972 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes)
4974 win_skip( "layered windows not supported\n" );
4975 return;
4977 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
4978 100, 100, 200, 200, 0, 0, 0, NULL);
4979 assert( hwnd );
4980 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4981 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
4982 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
4983 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
4984 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
4985 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4986 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
4987 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
4988 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4989 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4990 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4991 ok( key == 0x123456 || key == 0, "wrong color key %x\n", key );
4992 ok( alpha == 44, "wrong alpha %u\n", alpha );
4993 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
4995 /* clearing WS_EX_LAYERED resets attributes */
4996 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
4997 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4998 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
4999 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5000 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5001 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5002 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
5003 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5004 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5005 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5006 ok( key == 0x654321, "wrong color key %x\n", key );
5007 ok( alpha == 22, "wrong alpha %u\n", alpha );
5008 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
5010 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
5011 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5012 alpha = 0;
5013 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5014 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5015 ok( key == 0x888888, "wrong color key %x\n", key );
5016 /* alpha not changed on vista if LWA_ALPHA is not set */
5017 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
5018 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
5020 /* color key may or may not be changed without LWA_COLORKEY */
5021 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
5022 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5023 alpha = 0;
5024 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5025 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5026 ok( key == 0x888888 || key == 0x999999, "wrong color key %x\n", key );
5027 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
5028 ok( flags == 0, "wrong flags %x\n", flags );
5030 /* default alpha and color key is 0 */
5031 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5032 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5033 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
5034 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5035 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5036 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5037 ok( key == 0 || key == 0x222222, "wrong color key %x\n", key );
5038 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
5039 ok( flags == 0, "wrong flags %x\n", flags );
5041 DestroyWindow( hwnd );
5044 static MONITORINFO mi;
5046 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
5048 switch (msg)
5050 case WM_NCCREATE:
5052 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
5053 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs->x, cs->y, cs->cx, cs->cy);
5054 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
5055 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
5056 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
5057 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5058 cs->x, cs->y, cs->cx, cs->cy);
5059 break;
5061 case WM_GETMINMAXINFO:
5063 MINMAXINFO *minmax = (MINMAXINFO *)lp;
5064 dump_minmax_info(minmax);
5065 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
5066 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
5067 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
5068 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
5069 break;
5072 return DefWindowProc(hwnd, msg, wp, lp);
5075 static void test_fullscreen(void)
5077 static const DWORD t_style[] = {
5078 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
5080 static const DWORD t_ex_style[] = {
5081 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
5083 WNDCLASS cls;
5084 HWND hwnd;
5085 int i, j;
5086 POINT pt;
5087 RECT rc;
5088 HMONITOR hmon;
5089 LRESULT ret;
5091 if (!pGetMonitorInfoA || !pMonitorFromPoint)
5093 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
5094 return;
5097 pt.x = pt.y = 0;
5098 SetLastError(0xdeadbeef);
5099 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
5100 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
5102 mi.cbSize = sizeof(mi);
5103 SetLastError(0xdeadbeef);
5104 ret = pGetMonitorInfoA(hmon, &mi);
5105 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
5106 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
5107 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5108 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5110 cls.style = 0;
5111 cls.lpfnWndProc = fullscreen_wnd_proc;
5112 cls.cbClsExtra = 0;
5113 cls.cbWndExtra = 0;
5114 cls.hInstance = GetModuleHandle(0);
5115 cls.hIcon = 0;
5116 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5117 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5118 cls.lpszMenuName = NULL;
5119 cls.lpszClassName = "fullscreen_class";
5120 RegisterClass(&cls);
5122 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
5124 DWORD style, ex_style;
5126 /* avoid a WM interaction */
5127 assert(!(t_style[i] & WS_VISIBLE));
5129 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
5131 int fixup;
5133 style = t_style[i];
5134 ex_style = t_ex_style[j];
5136 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5137 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5138 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5139 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5140 GetWindowRect(hwnd, &rc);
5141 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5142 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5143 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5144 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5145 DestroyWindow(hwnd);
5147 style = t_style[i] | WS_MAXIMIZE;
5148 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5149 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5150 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5151 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5152 GetWindowRect(hwnd, &rc);
5153 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5154 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5155 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5156 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5157 DestroyWindow(hwnd);
5159 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
5160 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5161 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5162 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5163 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5164 GetWindowRect(hwnd, &rc);
5165 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5166 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5167 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5168 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5169 DestroyWindow(hwnd);
5171 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
5172 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5173 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5174 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5175 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5176 GetWindowRect(hwnd, &rc);
5177 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5178 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5179 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5180 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5181 DestroyWindow(hwnd);
5183 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
5184 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5185 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5186 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5187 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5188 GetWindowRect(hwnd, &rc);
5189 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5190 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5191 fixup = min(abs(rc.left), abs(rc.top));
5192 InflateRect(&rc, -fixup, -fixup);
5193 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5194 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5195 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
5196 ex_style, style, rc.left, rc.top, rc.right, rc.bottom,
5197 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5198 DestroyWindow(hwnd);
5200 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
5201 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5202 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5203 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5204 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5205 GetWindowRect(hwnd, &rc);
5206 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5207 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5208 fixup = min(abs(rc.left), abs(rc.top));
5209 InflateRect(&rc, -fixup, -fixup);
5210 if (style & (WS_CHILD | WS_POPUP))
5211 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5212 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5213 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5214 else
5215 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5216 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5217 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5218 DestroyWindow(hwnd);
5222 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5225 static BOOL test_thick_child_got_minmax;
5226 static const char * test_thick_child_name;
5227 static LONG test_thick_child_style;
5228 static LONG test_thick_child_exStyle;
5230 static LRESULT WINAPI test_thick_child_size_winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5232 MINMAXINFO* minmax;
5233 int expectedMinTrackX;
5234 int expectedMinTrackY;
5235 int actualMinTrackX;
5236 int actualMinTrackY;
5237 int expectedMaxTrackX;
5238 int expectedMaxTrackY;
5239 int actualMaxTrackX;
5240 int actualMaxTrackY;
5241 int expectedMaxSizeX;
5242 int expectedMaxSizeY;
5243 int actualMaxSizeX;
5244 int actualMaxSizeY;
5245 int expectedPosX;
5246 int expectedPosY;
5247 int actualPosX;
5248 int actualPosY;
5249 LONG adjustedStyle;
5250 RECT rect;
5251 switch (msg)
5253 case WM_GETMINMAXINFO:
5255 minmax = (MINMAXINFO *)lparam;
5256 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
5257 dump_minmax_info( minmax );
5259 test_thick_child_got_minmax = TRUE;
5262 adjustedStyle = test_thick_child_style;
5263 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
5264 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5265 GetClientRect(GetParent(hwnd), &rect);
5266 AdjustWindowRectEx(&rect, adjustedStyle, FALSE, test_thick_child_exStyle);
5268 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
5270 expectedMinTrackX = GetSystemMetrics(SM_CXMINTRACK);
5271 expectedMinTrackY = GetSystemMetrics(SM_CYMINTRACK);
5273 else
5275 expectedMinTrackX = -2 * rect.left;
5276 expectedMinTrackY = -2 * rect.top;
5278 actualMinTrackX = minmax->ptMinTrackSize.x;
5279 actualMinTrackY = minmax->ptMinTrackSize.y;
5281 ok(actualMinTrackX == expectedMinTrackX && actualMinTrackY == expectedMinTrackY,
5282 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
5283 expectedMinTrackX, expectedMinTrackY, actualMinTrackX, actualMinTrackY,
5284 test_thick_child_name);
5286 actualMaxTrackX = minmax->ptMaxTrackSize.x;
5287 actualMaxTrackY = minmax->ptMaxTrackSize.y;
5288 expectedMaxTrackX = GetSystemMetrics(SM_CXMAXTRACK);
5289 expectedMaxTrackY = GetSystemMetrics(SM_CYMAXTRACK);
5290 ok(actualMaxTrackX == expectedMaxTrackX && actualMaxTrackY == expectedMaxTrackY,
5291 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
5292 expectedMaxTrackX, expectedMaxTrackY, actualMaxTrackX, actualMaxTrackY,
5293 test_thick_child_name);
5295 expectedMaxSizeX = rect.right - rect.left;
5296 expectedMaxSizeY = rect.bottom - rect.top;
5297 actualMaxSizeX = minmax->ptMaxSize.x;
5298 actualMaxSizeY = minmax->ptMaxSize.y;
5300 ok(actualMaxSizeX == expectedMaxSizeX && actualMaxSizeY == expectedMaxSizeY,
5301 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
5302 expectedMaxSizeX, expectedMaxSizeY, actualMaxSizeX, actualMaxSizeY,
5303 test_thick_child_name);
5306 expectedPosX = rect.left;
5307 expectedPosY = rect.top;
5308 actualPosX = minmax->ptMaxPosition.x;
5309 actualPosY = minmax->ptMaxPosition.y;
5310 ok(actualPosX == expectedPosX && actualPosY == expectedPosY,
5311 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
5312 expectedPosX, expectedPosY, actualPosX, actualPosY, test_thick_child_name);
5314 break;
5318 return DefWindowProcA(hwnd, msg, wparam, lparam);
5321 #define NUMBER_OF_THICK_CHILD_TESTS 16
5322 static void test_thick_child_size(HWND parentWindow)
5324 BOOL success;
5325 RECT childRect;
5326 RECT adjustedParentRect;
5327 HWND childWindow;
5328 LONG childWidth;
5329 LONG childHeight;
5330 LONG expectedWidth;
5331 LONG expectedHeight;
5332 WNDCLASSA cls;
5333 LPCTSTR className = "THICK_CHILD_CLASS";
5334 int i;
5335 LONG adjustedStyle;
5336 static const LONG styles[NUMBER_OF_THICK_CHILD_TESTS] = {
5337 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5338 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5339 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5340 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5341 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5342 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5343 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5344 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5345 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5346 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5347 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5348 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5349 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5350 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5351 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5352 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5355 static const LONG exStyles[NUMBER_OF_THICK_CHILD_TESTS] = {
5360 WS_EX_DLGMODALFRAME,
5361 WS_EX_DLGMODALFRAME,
5362 WS_EX_DLGMODALFRAME,
5363 WS_EX_DLGMODALFRAME,
5364 WS_EX_STATICEDGE,
5365 WS_EX_STATICEDGE,
5366 WS_EX_STATICEDGE,
5367 WS_EX_STATICEDGE,
5368 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5369 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5370 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5371 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5373 static const char *styleName[NUMBER_OF_THICK_CHILD_TESTS] = {
5374 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
5375 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
5376 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
5377 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
5378 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
5379 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
5380 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5381 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5382 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
5383 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
5384 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5385 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5386 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5387 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5388 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5389 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5392 cls.style = 0;
5393 cls.lpfnWndProc = test_thick_child_size_winproc;
5394 cls.cbClsExtra = 0;
5395 cls.cbWndExtra = 0;
5396 cls.hInstance = GetModuleHandleA(0);
5397 cls.hIcon = 0;
5398 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5399 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5400 cls.lpszMenuName = NULL;
5401 cls.lpszClassName = className;
5402 SetLastError(0xdeadbeef);
5403 ok(RegisterClassA(&cls),"RegisterClassA failed, error: %u\n", GetLastError());
5405 for(i = 0; i < NUMBER_OF_THICK_CHILD_TESTS; i++)
5407 test_thick_child_name = styleName[i];
5408 test_thick_child_style = styles[i];
5409 test_thick_child_exStyle = exStyles[i];
5410 test_thick_child_got_minmax = FALSE;
5412 SetLastError(0xdeadbeef);
5413 childWindow = CreateWindowEx( exStyles[i], className, "", styles[i], 0, 0, 0, 0, parentWindow, 0, GetModuleHandleA(0), NULL );
5414 ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
5416 ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
5418 SetLastError(0xdeadbeef);
5419 success = GetWindowRect(childWindow, &childRect);
5420 ok(success,"GetWindowRect call failed, error: %u\n", GetLastError());
5421 childWidth = childRect.right - childRect.left;
5422 childHeight = childRect.bottom - childRect.top;
5424 adjustedStyle = styles[i];
5425 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
5426 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5427 GetClientRect(GetParent(childWindow), &adjustedParentRect);
5428 AdjustWindowRectEx(&adjustedParentRect, adjustedStyle, FALSE, test_thick_child_exStyle);
5431 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
5433 expectedWidth = GetSystemMetrics(SM_CXMINTRACK);
5434 expectedHeight = GetSystemMetrics(SM_CYMINTRACK);
5436 else
5438 expectedWidth = -2 * adjustedParentRect.left;
5439 expectedHeight = -2 * adjustedParentRect.top;
5442 ok((childWidth == expectedWidth) && (childHeight == expectedHeight),
5443 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
5444 test_thick_child_name, expectedWidth, expectedHeight, childWidth, childHeight);
5446 SetLastError(0xdeadbeef);
5447 success = DestroyWindow(childWindow);
5448 ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
5450 ok(UnregisterClass(className, GetModuleHandleA(0)),"UnregisterClass call failed\n");
5453 static void test_handles( HWND full_hwnd )
5455 HWND hwnd = full_hwnd;
5456 BOOL ret;
5457 RECT rect;
5459 SetLastError( 0xdeadbeef );
5460 ret = GetWindowRect( hwnd, &rect );
5461 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5463 #ifdef _WIN64
5464 if ((ULONG_PTR)full_hwnd >> 32)
5465 hwnd = (HWND)((ULONG_PTR)full_hwnd & ~0u);
5466 else
5467 hwnd = (HWND)((ULONG_PTR)full_hwnd | ((ULONG_PTR)~0u << 32));
5468 SetLastError( 0xdeadbeef );
5469 ret = GetWindowRect( hwnd, &rect );
5470 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5472 hwnd = (HWND)(((ULONG_PTR)full_hwnd & ~0u) | ((ULONG_PTR)0x1234 << 32));
5473 SetLastError( 0xdeadbeef );
5474 ret = GetWindowRect( hwnd, &rect );
5475 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5477 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x9876 << 16));
5478 SetLastError( 0xdeadbeef );
5479 ret = GetWindowRect( hwnd, &rect );
5480 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
5481 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
5483 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x12345678 << 16));
5484 SetLastError( 0xdeadbeef );
5485 ret = GetWindowRect( hwnd, &rect );
5486 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
5487 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
5488 #endif
5491 START_TEST(win)
5493 HMODULE user32 = GetModuleHandleA( "user32.dll" );
5494 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
5495 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
5496 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
5497 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
5498 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
5499 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
5500 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
5502 if (!RegisterWindowClasses()) assert(0);
5504 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
5505 if (!hhook) win_skip( "Cannot set CBT hook, skipping some tests\n" );
5507 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
5508 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5509 WS_MAXIMIZEBOX | WS_POPUP,
5510 100, 100, 200, 200,
5511 0, 0, GetModuleHandle(0), NULL);
5512 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
5513 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5514 WS_MAXIMIZEBOX | WS_POPUP,
5515 100, 100, 200, 200,
5516 0, 0, GetModuleHandle(0), NULL);
5517 assert( hwndMain );
5518 assert( hwndMain2 );
5520 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
5522 /* Add the tests below this line */
5523 test_thick_child_size(hwndMain);
5524 test_fullscreen();
5525 test_hwnd_message();
5526 test_nonclient_area(hwndMain);
5527 test_params();
5528 test_GetWindowModuleFileName();
5529 test_capture_1();
5530 test_capture_2();
5531 test_capture_3(hwndMain, hwndMain2);
5533 test_CreateWindow();
5534 test_parent_owner();
5535 test_SetParent();
5537 test_mdi();
5538 test_icons();
5539 test_SetWindowPos(hwndMain);
5540 test_SetMenu(hwndMain);
5541 test_SetFocus(hwndMain);
5542 test_SetActiveWindow(hwndMain);
5544 test_children_zorder(hwndMain);
5545 test_popup_zorder(hwndMain2, hwndMain);
5546 test_keyboard_input(hwndMain);
5547 test_mouse_input(hwndMain);
5548 test_validatergn(hwndMain);
5549 test_nccalcscroll( hwndMain);
5550 test_scrollvalidate( hwndMain);
5551 test_scrolldc( hwndMain);
5552 test_scroll();
5553 test_IsWindowUnicode();
5554 test_vis_rgn(hwndMain);
5556 test_AdjustWindowRect();
5557 test_window_styles();
5558 test_redrawnow();
5559 test_csparentdc();
5560 test_SetWindowLong();
5561 test_ShowWindow();
5562 if (0) test_gettext(); /* crashes on NT4 */
5563 test_GetUpdateRect();
5564 test_Expose();
5565 test_layered_window();
5567 test_SetForegroundWindow(hwndMain);
5568 test_shell_window();
5569 test_handles( hwndMain );
5571 /* add the tests above this line */
5572 if (hhook) UnhookWindowsHookEx(hhook);
5574 DestroyWindow(hwndMain2);
5575 DestroyWindow(hwndMain);