Release 1.1.37.
[wine/gsoc-2012-control.git] / dlls / user32 / tests / win.c
blob6fb6ce01b6f2fcf0447f9cccbbc9c3de30c5cf3d
1 /*
2 * Unit tests for window handling
4 * Copyright 2002 Bill Medland
5 * Copyright 2002 Alexandre Julliard
6 * Copyright 2003 Dmitry Timoshkov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 /* To get ICON_SMALL2 with the MSVC headers */
24 #define _WIN32_WINNT 0x0501
26 #include <assert.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <stdio.h>
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "winuser.h"
36 #include "wine/test.h"
38 #ifndef SPI_GETDESKWALLPAPER
39 #define SPI_GETDESKWALLPAPER 0x0073
40 #endif
42 #define LONG_PTR INT_PTR
43 #define ULONG_PTR UINT_PTR
45 void dump_region(HRGN hrgn);
47 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
48 static BOOL (WINAPI *pGetWindowInfo)(HWND,WINDOWINFO*);
49 static UINT (WINAPI *pGetWindowModuleFileNameA)(HWND,LPSTR,UINT);
50 static BOOL (WINAPI *pGetLayeredWindowAttributes)(HWND,COLORREF*,BYTE*,DWORD*);
51 static BOOL (WINAPI *pSetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD);
52 static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
53 static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
54 static int (WINAPI *pGetWindowRgnBox)(HWND,LPRECT);
55 static BOOL (WINAPI *pGetGUIThreadInfo)(DWORD, GUITHREADINFO*);
57 static BOOL test_lbuttondown_flag;
58 static HWND hwndMessage;
59 static HWND hwndMain, hwndMain2;
60 static HHOOK hhook;
62 static const char* szAWRClass = "Winsize";
63 static HMENU hmenu;
64 static DWORD our_pid;
66 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
68 static void dump_minmax_info( const MINMAXINFO *minmax )
70 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
71 minmax->ptReserved.x, minmax->ptReserved.y,
72 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
73 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
74 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
75 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
78 /* try to make sure pending X events have been processed before continuing */
79 static void flush_events( BOOL remove_messages )
81 MSG msg;
82 int diff = 200;
83 int min_timeout = 100;
84 DWORD time = GetTickCount() + diff;
86 while (diff > 0)
88 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
89 if (remove_messages)
90 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
91 diff = time - GetTickCount();
92 min_timeout = 50;
96 /* check the values returned by the various parent/owner functions on a given window */
97 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
98 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
100 HWND res;
102 if (pGetAncestor)
104 res = pGetAncestor( hwnd, GA_PARENT );
105 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
107 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
108 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
109 res = GetParent( hwnd );
110 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
111 res = GetWindow( hwnd, GW_OWNER );
112 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
113 if (pGetAncestor)
115 res = pGetAncestor( hwnd, GA_ROOT );
116 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
117 res = pGetAncestor( hwnd, GA_ROOTOWNER );
118 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
122 static BOOL ignore_message( UINT message )
124 /* these are always ignored */
125 return (message >= 0xc000 ||
126 message == WM_GETICON ||
127 message == WM_GETOBJECT ||
128 message == WM_TIMECHANGE ||
129 message == WM_DEVICECHANGE);
132 static BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
134 (*(LPINT)lParam)++;
135 trace("EnumChildProc on %p\n", hwndChild);
136 if (*(LPINT)lParam > 1) return FALSE;
137 return TRUE;
140 /* will search for the given window */
141 static BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
143 trace("EnumChildProc1 on %p\n", hwndChild);
144 if ((HWND)lParam == hwndChild) return FALSE;
145 return TRUE;
148 static HWND create_tool_window( LONG style, HWND parent )
150 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
151 0, 0, 100, 100, parent, 0, 0, NULL );
152 ok( ret != 0, "Creation failed\n" );
153 return ret;
156 /* test parent and owner values for various combinations */
157 static void test_parent_owner(void)
159 LONG style;
160 HWND test, owner, ret;
161 HWND desktop = GetDesktopWindow();
162 HWND child = create_tool_window( WS_CHILD, hwndMain );
163 INT numChildren;
165 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
167 /* child without parent, should fail */
168 SetLastError(0xdeadbeef);
169 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
170 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
171 ok( !test, "WS_CHILD without parent created\n" );
172 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD ||
173 broken(GetLastError() == 0xdeadbeef), /* win9x */
174 "CreateWindowExA error %u\n", GetLastError() );
176 /* desktop window */
177 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
178 style = GetWindowLongA( desktop, GWL_STYLE );
179 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
180 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
181 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
183 /* normal child window */
184 test = create_tool_window( WS_CHILD, hwndMain );
185 trace( "created child %p\n", test );
186 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
187 SetWindowLongA( test, GWL_STYLE, 0 );
188 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
189 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
190 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
191 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
192 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
193 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
194 DestroyWindow( test );
196 /* normal child window with WS_MAXIMIZE */
197 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
198 DestroyWindow( test );
200 /* normal child window with WS_THICKFRAME */
201 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
202 DestroyWindow( test );
204 /* popup window with WS_THICKFRAME */
205 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
206 DestroyWindow( test );
208 /* child of desktop */
209 test = create_tool_window( WS_CHILD, desktop );
210 trace( "created child of desktop %p\n", test );
211 check_parents( test, desktop, 0, desktop, 0, test, desktop );
212 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
213 check_parents( test, desktop, 0, 0, 0, test, test );
214 SetWindowLongA( test, GWL_STYLE, 0 );
215 check_parents( test, desktop, 0, 0, 0, test, test );
216 DestroyWindow( test );
218 /* child of desktop with WS_MAXIMIZE */
219 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
220 DestroyWindow( test );
222 /* child of desktop with WS_MINIMIZE */
223 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
224 DestroyWindow( test );
226 /* child of child */
227 test = create_tool_window( WS_CHILD, child );
228 trace( "created child of child %p\n", test );
229 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
230 SetWindowLongA( test, GWL_STYLE, 0 );
231 check_parents( test, child, child, 0, 0, hwndMain, test );
232 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
233 check_parents( test, child, child, 0, 0, hwndMain, test );
234 DestroyWindow( test );
236 /* child of child with WS_MAXIMIZE */
237 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
238 DestroyWindow( test );
240 /* child of child with WS_MINIMIZE */
241 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
242 DestroyWindow( test );
244 /* not owned top-level window */
245 test = create_tool_window( 0, 0 );
246 trace( "created top-level %p\n", test );
247 check_parents( test, desktop, 0, 0, 0, test, test );
248 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
249 check_parents( test, desktop, 0, 0, 0, test, test );
250 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
251 check_parents( test, desktop, 0, desktop, 0, test, desktop );
252 DestroyWindow( test );
254 /* not owned top-level window with WS_MAXIMIZE */
255 test = create_tool_window( WS_MAXIMIZE, 0 );
256 DestroyWindow( test );
258 /* owned top-level window */
259 test = create_tool_window( 0, hwndMain );
260 trace( "created owned top-level %p\n", test );
261 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
262 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
263 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
264 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
265 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
266 DestroyWindow( test );
268 /* owned top-level window with WS_MAXIMIZE */
269 test = create_tool_window( WS_MAXIMIZE, hwndMain );
270 DestroyWindow( test );
272 /* not owned popup */
273 test = create_tool_window( WS_POPUP, 0 );
274 trace( "created popup %p\n", test );
275 check_parents( test, desktop, 0, 0, 0, test, test );
276 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
277 check_parents( test, desktop, 0, desktop, 0, test, desktop );
278 SetWindowLongA( test, GWL_STYLE, 0 );
279 check_parents( test, desktop, 0, 0, 0, test, test );
280 DestroyWindow( test );
282 /* not owned popup with WS_MAXIMIZE */
283 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
284 DestroyWindow( test );
286 /* owned popup */
287 test = create_tool_window( WS_POPUP, hwndMain );
288 trace( "created owned popup %p\n", test );
289 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
290 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
291 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
292 SetWindowLongA( test, GWL_STYLE, 0 );
293 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
294 DestroyWindow( test );
296 /* owned popup with WS_MAXIMIZE */
297 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
298 DestroyWindow( test );
300 /* top-level window owned by child (same as owned by top-level) */
301 test = create_tool_window( 0, child );
302 trace( "created top-level owned by child %p\n", test );
303 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
304 DestroyWindow( test );
306 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
307 test = create_tool_window( WS_MAXIMIZE, child );
308 DestroyWindow( test );
310 /* popup owned by desktop (same as not owned) */
311 test = create_tool_window( WS_POPUP, desktop );
312 trace( "created popup owned by desktop %p\n", test );
313 check_parents( test, desktop, 0, 0, 0, test, test );
314 DestroyWindow( test );
316 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
317 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
318 DestroyWindow( test );
320 /* popup owned by child (same as owned by top-level) */
321 test = create_tool_window( WS_POPUP, child );
322 trace( "created popup owned by child %p\n", test );
323 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
324 DestroyWindow( test );
326 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
327 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
328 DestroyWindow( test );
330 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
331 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
332 trace( "created WS_CHILD popup %p\n", test );
333 check_parents( test, desktop, 0, 0, 0, test, test );
334 DestroyWindow( test );
336 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
337 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
338 DestroyWindow( test );
340 /* owned popup with WS_CHILD (same as WS_POPUP only) */
341 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
342 trace( "created owned WS_CHILD popup %p\n", test );
343 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
344 DestroyWindow( test );
346 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
347 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
348 DestroyWindow( test );
350 /******************** parent changes *************************/
351 trace( "testing parent changes\n" );
353 /* desktop window */
354 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
355 if (0)
357 /* this test succeeds on NT but crashes on win9x systems */
358 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
359 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
360 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
361 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
362 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
364 /* normal child window */
365 test = create_tool_window( WS_CHILD, hwndMain );
366 trace( "created child %p\n", test );
368 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
369 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
370 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
372 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
373 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
374 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
376 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
377 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
378 check_parents( test, desktop, 0, desktop, 0, test, desktop );
380 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
381 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
382 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
383 check_parents( test, desktop, child, desktop, child, test, desktop );
385 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
386 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
387 check_parents( test, desktop, 0, desktop, 0, test, desktop );
388 DestroyWindow( test );
390 /* not owned top-level window */
391 test = create_tool_window( 0, 0 );
392 trace( "created top-level %p\n", test );
394 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
395 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
396 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
398 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
399 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
400 check_parents( test, desktop, child, 0, child, test, test );
402 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
403 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
404 check_parents( test, desktop, 0, 0, 0, test, test );
405 DestroyWindow( test );
407 /* not owned popup */
408 test = create_tool_window( WS_POPUP, 0 );
409 trace( "created popup %p\n", test );
411 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
412 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
413 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
415 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
416 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
417 check_parents( test, desktop, child, child, child, test, hwndMain );
419 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
420 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
421 check_parents( test, desktop, 0, 0, 0, test, test );
422 DestroyWindow( test );
424 /* normal child window */
425 test = create_tool_window( WS_CHILD, hwndMain );
426 trace( "created child %p\n", test );
428 ret = SetParent( test, desktop );
429 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
430 check_parents( test, desktop, 0, desktop, 0, test, desktop );
432 ret = SetParent( test, child );
433 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
434 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
436 ret = SetParent( test, hwndMain2 );
437 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
438 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
439 DestroyWindow( test );
441 /* not owned top-level window */
442 test = create_tool_window( 0, 0 );
443 trace( "created top-level %p\n", test );
445 ret = SetParent( test, child );
446 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
447 check_parents( test, child, child, 0, 0, hwndMain, test );
448 DestroyWindow( test );
450 /* owned popup */
451 test = create_tool_window( WS_POPUP, hwndMain2 );
452 trace( "created owned popup %p\n", test );
454 ret = SetParent( test, child );
455 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
456 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
458 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
459 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
460 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
461 DestroyWindow( test );
463 /**************** test owner destruction *******************/
465 /* owned child popup */
466 owner = create_tool_window( 0, 0 );
467 test = create_tool_window( WS_POPUP, owner );
468 trace( "created owner %p and popup %p\n", owner, test );
469 ret = SetParent( test, child );
470 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
471 check_parents( test, child, child, owner, owner, hwndMain, owner );
472 /* window is now child of 'child' but owned by 'owner' */
473 DestroyWindow( owner );
474 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
475 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
476 * while Win95, Win2k, WinXP do.
478 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
479 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
480 DestroyWindow(test);
482 /* owned top-level popup */
483 owner = create_tool_window( 0, 0 );
484 test = create_tool_window( WS_POPUP, owner );
485 trace( "created owner %p and popup %p\n", owner, test );
486 check_parents( test, desktop, owner, owner, owner, test, owner );
487 DestroyWindow( owner );
488 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
490 /* top-level popup owned by child */
491 owner = create_tool_window( WS_CHILD, hwndMain2 );
492 test = create_tool_window( WS_POPUP, 0 );
493 trace( "created owner %p and popup %p\n", owner, test );
494 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
495 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
496 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
497 DestroyWindow( owner );
498 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
499 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
500 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
501 * while Win95, Win2k, WinXP do.
503 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
504 DestroyWindow(test);
506 /* final cleanup */
507 DestroyWindow(child);
510 owner = create_tool_window( WS_OVERLAPPED, 0 );
511 test = create_tool_window( WS_POPUP, desktop );
513 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
514 numChildren = 0;
515 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
516 "EnumChildWindows should have returned FALSE\n" );
517 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
519 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
520 ret = SetParent( test, owner );
521 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
523 numChildren = 0;
524 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
525 "EnumChildWindows should have returned TRUE\n" );
526 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
528 child = create_tool_window( WS_CHILD, owner );
529 numChildren = 0;
530 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
531 "EnumChildWindows should have returned FALSE\n" );
532 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
533 DestroyWindow( child );
535 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
536 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
537 numChildren = 0;
538 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
539 "EnumChildWindows should have returned TRUE\n" );
540 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
542 ret = SetParent( child, owner );
543 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
544 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
545 numChildren = 0;
546 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
547 "EnumChildWindows should have returned FALSE\n" );
548 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
550 ret = SetParent( child, NULL );
551 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
552 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
553 numChildren = 0;
554 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
555 "EnumChildWindows should have returned TRUE\n" );
556 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
558 /* even GW_OWNER == owner it's still a desktop's child */
559 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
560 "EnumChildWindows should have found %p and returned FALSE\n", child );
562 DestroyWindow( child );
563 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
565 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
566 "EnumChildWindows should have found %p and returned FALSE\n", child );
568 DestroyWindow( child );
569 DestroyWindow( test );
570 DestroyWindow( owner );
573 static BOOL CALLBACK enum_proc( HWND hwnd, LPARAM lParam)
575 (*(LPINT)lParam)++;
576 if (*(LPINT)lParam > 2) return FALSE;
577 return TRUE;
579 static DWORD CALLBACK enum_thread( void *arg )
581 INT count;
582 HWND hwnd[3];
583 BOOL ret;
584 MSG msg;
586 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ); /* make sure we have a message queue */
588 count = 0;
589 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
590 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
591 ok( count == 0, "count should be 0 got %d\n", count );
593 hwnd[0] = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", WS_POPUP,
594 0, 0, 100, 100, 0, 0, 0, NULL );
595 count = 0;
596 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
597 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
598 if (count != 2) /* Vista gives us two windows for the price of one */
600 ok( count == 1, "count should be 1 got %d\n", count );
601 hwnd[2] = CreateWindowExA(0, "ToolWindowClass", "Tool window 2", WS_POPUP,
602 0, 0, 100, 100, 0, 0, 0, NULL );
604 else hwnd[2] = 0;
606 hwnd[1] = CreateWindowExA(0, "ToolWindowClass", "Tool window 3", WS_POPUP,
607 0, 0, 100, 100, 0, 0, 0, NULL );
608 count = 0;
609 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
610 ok( !ret, "EnumThreadWindows should have returned FALSE\n" );
611 ok( count == 3, "count should be 3 got %d\n", count );
613 if (hwnd[2]) DestroyWindow(hwnd[2]);
614 DestroyWindow(hwnd[1]);
615 DestroyWindow(hwnd[0]);
616 return 0;
619 /* test EnumThreadWindows in a separate thread */
620 static void test_enum_thread_windows(void)
622 DWORD id;
623 HANDLE handle = CreateThread( NULL, 0, enum_thread, 0, 0, &id );
624 ok( !WaitForSingleObject( handle, 10000 ), "wait failed\n" );
625 CloseHandle( handle );
628 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
630 switch (msg)
632 case WM_GETMINMAXINFO:
634 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
636 trace("WM_GETMINMAXINFO: hwnd %p, %08lx, %08lx\n", hwnd, wparam, lparam);
637 dump_minmax_info( minmax );
638 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
639 break;
641 case WM_WINDOWPOSCHANGING:
643 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
644 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
645 trace("main: WM_WINDOWPOSCHANGING %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
646 winpos->hwnd, winpos->hwndInsertAfter,
647 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
648 if (!(winpos->flags & SWP_NOMOVE))
650 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
651 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
653 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
654 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
656 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
657 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
659 break;
661 case WM_WINDOWPOSCHANGED:
663 RECT rc1, rc2;
664 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
665 trace("main: WM_WINDOWPOSCHANGED %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
666 winpos->hwnd, winpos->hwndInsertAfter,
667 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
668 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
669 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
671 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
672 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
674 GetWindowRect(hwnd, &rc1);
675 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
676 /* note: winpos coordinates are relative to parent */
677 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
678 if (0)
680 /* Uncomment this once the test succeeds in all cases */
681 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
682 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
684 GetClientRect(hwnd, &rc2);
685 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
686 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
687 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
688 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
690 break;
692 case WM_NCCREATE:
694 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
695 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
697 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
698 if (got_getminmaxinfo)
699 trace("%p got WM_GETMINMAXINFO\n", hwnd);
701 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
702 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
703 else
704 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
705 break;
707 case WM_COMMAND:
708 if (test_lbuttondown_flag)
710 ShowWindow((HWND)wparam, SW_SHOW);
711 flush_events( FALSE );
713 break;
716 return DefWindowProcA(hwnd, msg, wparam, lparam);
719 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
721 switch (msg)
723 case WM_GETMINMAXINFO:
725 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
727 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
728 dump_minmax_info( minmax );
729 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
730 break;
732 case WM_NCCREATE:
734 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
735 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
737 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
738 if (got_getminmaxinfo)
739 trace("%p got WM_GETMINMAXINFO\n", hwnd);
741 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
742 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
743 else
744 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
745 break;
749 return DefWindowProcA(hwnd, msg, wparam, lparam);
752 static BOOL RegisterWindowClasses(void)
754 WNDCLASSA cls;
756 cls.style = CS_DBLCLKS;
757 cls.lpfnWndProc = main_window_procA;
758 cls.cbClsExtra = 0;
759 cls.cbWndExtra = 0;
760 cls.hInstance = GetModuleHandleA(0);
761 cls.hIcon = 0;
762 cls.hCursor = LoadCursorA(0, IDC_ARROW);
763 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
764 cls.lpszMenuName = NULL;
765 cls.lpszClassName = "MainWindowClass";
767 if(!RegisterClassA(&cls)) return FALSE;
769 cls.style = 0;
770 cls.lpfnWndProc = tool_window_procA;
771 cls.cbClsExtra = 0;
772 cls.cbWndExtra = 0;
773 cls.hInstance = GetModuleHandleA(0);
774 cls.hIcon = 0;
775 cls.hCursor = LoadCursorA(0, IDC_ARROW);
776 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
777 cls.lpszMenuName = NULL;
778 cls.lpszClassName = "ToolWindowClass";
780 if(!RegisterClassA(&cls)) return FALSE;
782 return TRUE;
785 static void verify_window_info(const char *hook, HWND hwnd, const WINDOWINFO *info)
787 RECT rcWindow, rcClient;
788 DWORD status;
790 ok(IsWindow(hwnd), "bad window handle %p in hook %s\n", hwnd, hook);
792 GetWindowRect(hwnd, &rcWindow);
793 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow for %p in hook %s\n", hwnd, hook);
795 GetClientRect(hwnd, &rcClient);
796 /* translate to screen coordinates */
797 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
798 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient for %p in hook %s\n", hwnd, hook);
800 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
801 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
802 info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE), hwnd, hook);
803 /* Windows reports some undocumented exstyles in WINDOWINFO, but
804 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
806 ok((info->dwExStyle & ~0xe0000800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
807 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
808 info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE), hwnd, hook);
809 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
810 if (GetForegroundWindow())
811 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
812 info->dwWindowStatus, status, GetActiveWindow(), GetForegroundWindow(), hook);
814 /* win2k and XP return broken border info in GetWindowInfo most of
815 * the time, so there is no point in testing it.
817 #if 0
818 UINT border;
819 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
820 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
821 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
822 ok(info->cyWindowBorders == border,
823 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
824 #endif
825 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType for %p in hook %s\n",
826 hwnd, hook);
827 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
828 info->wCreatorVersion == 0x0500 /* Vista */,
829 "wrong wCreatorVersion %04x for %p in hook %s\n", info->wCreatorVersion, hwnd, hook);
832 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
834 AdjustWindowRectEx(rc, style, menu, exstyle);
835 /* AdjustWindowRectEx does not include scroll bars */
836 if (style & WS_VSCROLL)
838 if(exstyle & WS_EX_LEFTSCROLLBAR)
839 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
840 else
841 rc->right += GetSystemMetrics(SM_CXVSCROLL);
843 if (style & WS_HSCROLL)
844 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
847 static void test_nonclient_area(HWND hwnd)
849 DWORD style, exstyle;
850 RECT rc_window, rc_client, rc;
851 BOOL menu;
852 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
853 LRESULT ret;
855 style = GetWindowLongA(hwnd, GWL_STYLE);
856 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
857 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
859 GetWindowRect(hwnd, &rc_window);
860 GetClientRect(hwnd, &rc_client);
862 /* avoid some cases when things go wrong */
863 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
864 rc_window.right > 32768 || rc_window.bottom > 32768) return;
866 CopyRect(&rc, &rc_client);
867 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
868 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
870 ok(EqualRect(&rc, &rc_window),
871 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
872 style, exstyle, menu, rc_window.left, rc_window.top, rc_window.right, rc_window.bottom,
873 rc.left, rc.top, rc.right, rc.bottom);
876 CopyRect(&rc, &rc_window);
877 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
878 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
879 ok(EqualRect(&rc, &rc_client),
880 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
881 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
882 rc.left, rc.top, rc.right, rc.bottom);
884 /* NULL rectangle shouldn't crash */
885 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
886 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
888 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
889 if (is_win9x)
890 return;
892 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
893 SetRect(&rc_client, 0, 0, 250, 150);
894 CopyRect(&rc_window, &rc_client);
895 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
896 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
898 CopyRect(&rc, &rc_window);
899 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
900 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
901 ok(EqualRect(&rc, &rc_client),
902 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
903 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
904 rc.left, rc.top, rc.right, rc.bottom);
907 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
909 static const char *CBT_code_name[10] = {
910 "HCBT_MOVESIZE",
911 "HCBT_MINMAX",
912 "HCBT_QS",
913 "HCBT_CREATEWND",
914 "HCBT_DESTROYWND",
915 "HCBT_ACTIVATE",
916 "HCBT_CLICKSKIPPED",
917 "HCBT_KEYSKIPPED",
918 "HCBT_SYSCOMMAND",
919 "HCBT_SETFOCUS" };
920 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
921 HWND hwnd = (HWND)wParam;
923 switch (nCode)
925 case HCBT_CREATEWND:
927 static const RECT rc_null;
928 RECT rc;
929 LONG style;
930 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
931 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
932 hwnd, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
933 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
935 if (pGetWindowInfo)
937 WINDOWINFO info;
938 info.cbSize = sizeof(WINDOWINFO);
939 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
940 verify_window_info(code_name, hwnd, &info);
943 /* WS_VISIBLE should be turned off yet */
944 style = createwnd->lpcs->style & ~WS_VISIBLE;
945 ok(style == GetWindowLongA(hwnd, GWL_STYLE),
946 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
947 GetWindowLongA(hwnd, GWL_STYLE), style);
949 if (0)
951 /* Uncomment this once the test succeeds in all cases */
952 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
954 ok(GetParent(hwnd) == hwndMessage,
955 "wrong result from GetParent %p: message window %p\n",
956 GetParent(hwnd), hwndMessage);
958 else
959 ok(!GetParent(hwnd), "GetParent should return 0 at this point\n");
961 ok(!GetWindow(hwnd, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
963 if (0)
965 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
966 * Win9x still has them set to 0.
968 ok(GetWindow(hwnd, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
969 ok(GetWindow(hwnd, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
971 ok(!GetWindow(hwnd, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
972 ok(!GetWindow(hwnd, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
974 if (0)
976 /* Uncomment this once the test succeeds in all cases */
977 if (pGetAncestor)
979 ok(pGetAncestor(hwnd, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
980 ok(pGetAncestor(hwnd, GA_ROOT) == hwnd,
981 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOT), hwnd);
983 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
984 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwndMessage,
985 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
986 else
987 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwnd,
988 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOTOWNER), hwnd);
991 ok(GetWindowRect(hwnd, &rc), "GetWindowRect failed\n");
992 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
993 ok(GetClientRect(hwnd, &rc), "GetClientRect failed\n");
994 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
996 break;
998 case HCBT_MOVESIZE:
999 case HCBT_MINMAX:
1000 case HCBT_ACTIVATE:
1001 case HCBT_SETFOCUS:
1002 if (pGetWindowInfo && IsWindow(hwnd))
1004 WINDOWINFO info;
1006 /* Win98 actually does check the info.cbSize and doesn't allow
1007 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
1008 * WinXP do not check it at all.
1010 info.cbSize = sizeof(WINDOWINFO);
1011 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
1012 verify_window_info(code_name, hwnd, &info);
1014 break;
1015 /* on HCBT_DESTROYWND window state is undefined */
1016 case HCBT_DESTROYWND:
1017 trace( "HCBT_DESTROYWND: hwnd %p\n", hwnd );
1018 break;
1019 default:
1020 break;
1023 return CallNextHookEx(hhook, nCode, wParam, lParam);
1026 static void test_shell_window(void)
1028 BOOL ret;
1029 DWORD error;
1030 HMODULE hinst, hUser32;
1031 BOOL (WINAPI*SetShellWindow)(HWND);
1032 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
1033 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
1034 HWND shellWindow, nextWnd;
1036 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
1038 trace("Skipping shell window test on Win9x\n");
1039 return;
1042 shellWindow = GetShellWindow();
1043 hinst = GetModuleHandle(0);
1044 hUser32 = GetModuleHandleA("user32");
1046 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
1047 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
1049 trace("previous shell window: %p\n", shellWindow);
1051 if (shellWindow) {
1052 DWORD pid;
1053 HANDLE hProcess;
1055 GetWindowThreadProcessId(shellWindow, &pid);
1056 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
1057 if (!hProcess)
1059 skip( "cannot get access to shell process\n" );
1060 return;
1063 SetLastError(0xdeadbeef);
1064 ret = DestroyWindow(shellWindow);
1065 error = GetLastError();
1067 ok(!ret, "DestroyWindow(shellWindow)\n");
1068 /* passes on Win XP, but not on Win98 */
1069 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
1070 "got %u after DestroyWindow(shellWindow)\n", error);
1072 /* close old shell instance */
1073 ret = TerminateProcess(hProcess, 0);
1074 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1075 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
1076 CloseHandle(hProcess);
1079 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
1080 trace("created window 1: %p\n", hwnd1);
1082 ret = SetShellWindow(hwnd1);
1083 ok(ret, "first call to SetShellWindow(hwnd1)\n");
1084 shellWindow = GetShellWindow();
1085 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
1087 ret = SetShellWindow(hwnd1);
1088 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1090 ret = SetShellWindow(0);
1091 error = GetLastError();
1092 /* passes on Win XP, but not on Win98
1093 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1094 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1096 ret = SetShellWindow(hwnd1);
1097 /* passes on Win XP, but not on Win98
1098 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1100 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1101 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
1102 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1104 ret = DestroyWindow(hwnd1);
1105 ok(ret, "DestroyWindow(hwnd1)\n");
1107 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1108 trace("created window 2: %p\n", hwnd2);
1109 ret = SetShellWindow(hwnd2);
1110 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1112 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1113 trace("created window 3: %p\n", hwnd3);
1115 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1116 trace("created window 4: %p\n", hwnd4);
1118 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1119 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1121 ret = SetShellWindow(hwnd4);
1122 ok(ret, "SetShellWindow(hwnd4)\n");
1123 shellWindow = GetShellWindow();
1124 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1126 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1127 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1129 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1130 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1132 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1133 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1135 ret = SetShellWindow(hwnd3);
1136 ok(!ret, "SetShellWindow(hwnd3)\n");
1137 shellWindow = GetShellWindow();
1138 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1140 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1141 trace("created window 5: %p\n", hwnd5);
1142 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1143 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1145 todo_wine
1147 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1148 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1151 /* destroy test windows */
1152 DestroyWindow(hwnd2);
1153 DestroyWindow(hwnd3);
1154 DestroyWindow(hwnd4);
1155 DestroyWindow(hwnd5);
1158 /************** MDI test ****************/
1160 static char mdi_lParam_test_message[] = "just a test string";
1162 static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
1164 MDICREATESTRUCTA mdi_cs;
1165 HWND mdi_child;
1166 INT_PTR id;
1167 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1168 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1169 BOOL isWin9x = FALSE;
1171 mdi_cs.szClass = "MDI_child_Class_1";
1172 mdi_cs.szTitle = "MDI child";
1173 mdi_cs.hOwner = GetModuleHandle(0);
1174 mdi_cs.x = CW_USEDEFAULT;
1175 mdi_cs.y = CW_USEDEFAULT;
1176 mdi_cs.cx = CW_USEDEFAULT;
1177 mdi_cs.cy = CW_USEDEFAULT;
1178 mdi_cs.style = 0;
1179 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1180 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1181 ok(mdi_child != 0, "MDI child creation failed\n");
1182 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1183 ok(id == first_id, "wrong child id %ld\n", id);
1184 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1185 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1187 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1188 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1189 ok(mdi_child != 0, "MDI child creation failed\n");
1190 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1191 ok(id == first_id, "wrong child id %ld\n", id);
1192 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1193 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1195 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1196 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1197 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1199 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1201 else
1203 ok(mdi_child != 0, "MDI child creation failed\n");
1204 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1205 ok(id == first_id, "wrong child id %ld\n", id);
1206 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1207 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1210 /* test MDICREATESTRUCT A<->W mapping */
1211 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1212 mdi_cs.style = 0;
1213 mdi_cs.szClass = (LPCSTR)classW;
1214 mdi_cs.szTitle = (LPCSTR)titleW;
1215 SetLastError(0xdeadbeef);
1216 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1217 if (!mdi_child)
1219 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1220 isWin9x = TRUE;
1221 else
1222 ok(mdi_child != 0, "MDI child creation failed\n");
1224 else
1226 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1227 ok(id == first_id, "wrong child id %ld\n", id);
1228 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1229 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1232 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1234 CW_USEDEFAULT, CW_USEDEFAULT,
1235 CW_USEDEFAULT, CW_USEDEFAULT,
1236 mdi_client, GetModuleHandle(0),
1237 (LPARAM)mdi_lParam_test_message);
1238 ok(mdi_child != 0, "MDI child creation failed\n");
1239 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1240 ok(id == first_id, "wrong child id %ld\n", id);
1241 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1242 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1244 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1245 0x7fffffff, /* without WS_POPUP */
1246 CW_USEDEFAULT, CW_USEDEFAULT,
1247 CW_USEDEFAULT, CW_USEDEFAULT,
1248 mdi_client, GetModuleHandle(0),
1249 (LPARAM)mdi_lParam_test_message);
1250 ok(mdi_child != 0, "MDI child creation failed\n");
1251 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1252 ok(id == first_id, "wrong child id %ld\n", id);
1253 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1254 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1256 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1257 0xffffffff, /* with WS_POPUP */
1258 CW_USEDEFAULT, CW_USEDEFAULT,
1259 CW_USEDEFAULT, CW_USEDEFAULT,
1260 mdi_client, GetModuleHandle(0),
1261 (LPARAM)mdi_lParam_test_message);
1262 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1264 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1266 else
1268 ok(mdi_child != 0, "MDI child creation failed\n");
1269 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1270 ok(id == first_id, "wrong child id %ld\n", id);
1271 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1272 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1275 /* test MDICREATESTRUCT A<->W mapping */
1276 SetLastError(0xdeadbeef);
1277 mdi_child = CreateMDIWindowW(classW, titleW,
1279 CW_USEDEFAULT, CW_USEDEFAULT,
1280 CW_USEDEFAULT, CW_USEDEFAULT,
1281 mdi_client, GetModuleHandle(0),
1282 (LPARAM)mdi_lParam_test_message);
1283 if (!mdi_child)
1285 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1286 isWin9x = TRUE;
1287 else
1288 ok(mdi_child != 0, "MDI child creation failed\n");
1290 else
1292 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1293 ok(id == first_id, "wrong child id %ld\n", id);
1294 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1295 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1298 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1300 CW_USEDEFAULT, CW_USEDEFAULT,
1301 CW_USEDEFAULT, CW_USEDEFAULT,
1302 mdi_client, 0, GetModuleHandle(0),
1303 mdi_lParam_test_message);
1304 ok(mdi_child != 0, "MDI child creation failed\n");
1305 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1306 ok(id == first_id, "wrong child id %ld\n", id);
1307 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1308 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1310 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1311 0x7fffffff, /* without WS_POPUP */
1312 CW_USEDEFAULT, CW_USEDEFAULT,
1313 CW_USEDEFAULT, CW_USEDEFAULT,
1314 mdi_client, 0, GetModuleHandle(0),
1315 mdi_lParam_test_message);
1316 ok(mdi_child != 0, "MDI child creation failed\n");
1317 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1318 ok(id == first_id, "wrong child id %ld\n", id);
1319 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1320 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1322 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1323 0xffffffff, /* with WS_POPUP */
1324 CW_USEDEFAULT, CW_USEDEFAULT,
1325 CW_USEDEFAULT, CW_USEDEFAULT,
1326 mdi_client, 0, GetModuleHandle(0),
1327 mdi_lParam_test_message);
1328 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1330 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1332 else
1334 ok(mdi_child != 0, "MDI child creation failed\n");
1335 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1336 ok(id == first_id, "wrong child id %ld\n", id);
1337 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1338 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1341 /* test MDICREATESTRUCT A<->W mapping */
1342 SetLastError(0xdeadbeef);
1343 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1345 CW_USEDEFAULT, CW_USEDEFAULT,
1346 CW_USEDEFAULT, CW_USEDEFAULT,
1347 mdi_client, 0, GetModuleHandle(0),
1348 mdi_lParam_test_message);
1349 if (!mdi_child)
1351 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1352 isWin9x = TRUE;
1353 else
1354 ok(mdi_child != 0, "MDI child creation failed\n");
1356 else
1358 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1359 ok(id == first_id, "wrong child id %ld\n", id);
1360 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1361 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1364 /* This test fails on Win9x */
1365 if (!isWin9x)
1367 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1368 WS_CHILD,
1369 CW_USEDEFAULT, CW_USEDEFAULT,
1370 CW_USEDEFAULT, CW_USEDEFAULT,
1371 parent, 0, GetModuleHandle(0),
1372 mdi_lParam_test_message);
1373 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1376 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1377 WS_CHILD, /* without WS_POPUP */
1378 CW_USEDEFAULT, CW_USEDEFAULT,
1379 CW_USEDEFAULT, CW_USEDEFAULT,
1380 mdi_client, 0, GetModuleHandle(0),
1381 mdi_lParam_test_message);
1382 ok(mdi_child != 0, "MDI child creation failed\n");
1383 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1384 ok(id == 0, "wrong child id %ld\n", id);
1385 DestroyWindow(mdi_child);
1387 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1388 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1389 CW_USEDEFAULT, CW_USEDEFAULT,
1390 CW_USEDEFAULT, CW_USEDEFAULT,
1391 mdi_client, 0, GetModuleHandle(0),
1392 mdi_lParam_test_message);
1393 ok(mdi_child != 0, "MDI child creation failed\n");
1394 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1395 ok(id == 0, "wrong child id %ld\n", id);
1396 DestroyWindow(mdi_child);
1398 /* maximized child */
1399 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1400 WS_CHILD | WS_MAXIMIZE,
1401 CW_USEDEFAULT, CW_USEDEFAULT,
1402 CW_USEDEFAULT, CW_USEDEFAULT,
1403 mdi_client, 0, GetModuleHandle(0),
1404 mdi_lParam_test_message);
1405 ok(mdi_child != 0, "MDI child creation failed\n");
1406 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1407 ok(id == 0, "wrong child id %ld\n", id);
1408 DestroyWindow(mdi_child);
1410 trace("Creating maximized child with a caption\n");
1411 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1412 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1413 CW_USEDEFAULT, CW_USEDEFAULT,
1414 CW_USEDEFAULT, CW_USEDEFAULT,
1415 mdi_client, 0, GetModuleHandle(0),
1416 mdi_lParam_test_message);
1417 ok(mdi_child != 0, "MDI child creation failed\n");
1418 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1419 ok(id == 0, "wrong child id %ld\n", id);
1420 DestroyWindow(mdi_child);
1422 trace("Creating maximized child with a caption and a thick frame\n");
1423 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1424 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1425 CW_USEDEFAULT, CW_USEDEFAULT,
1426 CW_USEDEFAULT, CW_USEDEFAULT,
1427 mdi_client, 0, GetModuleHandle(0),
1428 mdi_lParam_test_message);
1429 ok(mdi_child != 0, "MDI child creation failed\n");
1430 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1431 ok(id == 0, "wrong child id %ld\n", id);
1432 DestroyWindow(mdi_child);
1435 /**********************************************************************
1436 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1438 * Note: The rule here is that client rect of the maximized MDI child
1439 * is equal to the client rect of the MDI client window.
1441 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1443 RECT rect;
1445 GetClientRect( client, &rect );
1446 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1447 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1449 rect.right -= rect.left;
1450 rect.bottom -= rect.top;
1451 lpMinMax->ptMaxSize.x = rect.right;
1452 lpMinMax->ptMaxSize.y = rect.bottom;
1454 lpMinMax->ptMaxPosition.x = rect.left;
1455 lpMinMax->ptMaxPosition.y = rect.top;
1457 trace("max rect (%d,%d - %d, %d)\n",
1458 rect.left, rect.top, rect.right, rect.bottom);
1461 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1463 switch (msg)
1465 case WM_NCCREATE:
1466 case WM_CREATE:
1468 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1469 MDICREATESTRUCTA *mdi_cs = cs->lpCreateParams;
1471 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1472 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1474 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1475 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1476 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1477 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1478 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1480 /* MDICREATESTRUCT should have original values */
1481 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1482 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1483 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1484 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1485 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1486 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1488 /* CREATESTRUCT should have fixed values */
1489 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1490 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1492 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1493 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1494 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1496 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1498 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1500 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1501 ok(cs->style == style,
1502 "cs->style does not match (%08x)\n", cs->style);
1504 else
1506 LONG style = mdi_cs->style;
1507 style &= ~WS_POPUP;
1508 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1509 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1510 ok(cs->style == style,
1511 "cs->style does not match (%08x)\n", cs->style);
1513 break;
1516 case WM_GETMINMAXINFO:
1518 HWND client = GetParent(hwnd);
1519 RECT rc;
1520 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1521 MINMAXINFO my_minmax;
1522 LONG style, exstyle;
1524 style = GetWindowLongA(hwnd, GWL_STYLE);
1525 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1527 GetWindowRect(client, &rc);
1528 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1529 GetClientRect(client, &rc);
1530 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1531 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1532 GetSystemMetrics(SM_CYSCREEN));
1534 GetClientRect(client, &rc);
1535 if ((style & WS_CAPTION) == WS_CAPTION)
1536 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1537 AdjustWindowRectEx(&rc, style, 0, exstyle);
1538 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1539 dump_minmax_info( minmax );
1541 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1542 minmax->ptMaxSize.x, rc.right - rc.left);
1543 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1544 minmax->ptMaxSize.y, rc.bottom - rc.top);
1546 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1548 trace("DefMDIChildProc returned:\n");
1549 dump_minmax_info( minmax );
1551 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1552 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1553 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1554 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1555 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1557 return 1;
1560 case WM_MDIACTIVATE:
1562 HWND active, client = GetParent(hwnd);
1563 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1564 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1565 if (hwnd == (HWND)lparam) /* if we are being activated */
1566 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1567 else
1568 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1569 break;
1572 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1575 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1577 switch (msg)
1579 case WM_NCCREATE:
1580 case WM_CREATE:
1582 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1584 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE",
1585 cs->x, cs->y, cs->cx, cs->cy);
1587 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1588 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1590 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1591 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1593 /* CREATESTRUCT should have fixed values */
1594 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1595 while NT does. */
1596 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1597 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1599 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1600 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1601 while Win95, Win2k, WinXP do. */
1602 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1603 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1604 break;
1607 case WM_GETMINMAXINFO:
1609 HWND parent = GetParent(hwnd);
1610 RECT rc;
1611 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1612 LONG style, exstyle;
1614 style = GetWindowLongA(hwnd, GWL_STYLE);
1615 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1617 GetClientRect(parent, &rc);
1618 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1620 GetClientRect(parent, &rc);
1621 if ((style & WS_CAPTION) == WS_CAPTION)
1622 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1623 AdjustWindowRectEx(&rc, style, 0, exstyle);
1624 dump_minmax_info( minmax );
1626 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1627 minmax->ptMaxSize.x, rc.right - rc.left);
1628 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1629 minmax->ptMaxSize.y, rc.bottom - rc.top);
1630 break;
1633 case WM_WINDOWPOSCHANGED:
1635 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1636 RECT rc1, rc2;
1638 GetWindowRect(hwnd, &rc1);
1639 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1640 /* note: winpos coordinates are relative to parent */
1641 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1642 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) pos=(%d,%d)-(%d,%d)\n",
1643 rc1.left, rc1.top, rc1.right, rc1.bottom,
1644 rc2.left, rc2.top, rc2.right, rc2.bottom);
1645 GetWindowRect(hwnd, &rc1);
1646 GetClientRect(hwnd, &rc2);
1647 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1648 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1649 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1650 rc1.left, rc1.top, rc1.right, rc1.bottom,
1651 rc2.left, rc2.top, rc2.right, rc2.bottom);
1653 /* fall through */
1654 case WM_WINDOWPOSCHANGING:
1656 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1657 WINDOWPOS my_winpos = *winpos;
1659 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1660 (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
1661 winpos->hwnd, winpos->hwndInsertAfter,
1662 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1664 DefWindowProcA(hwnd, msg, wparam, lparam);
1666 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1667 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1668 winpos->hwnd, winpos->hwndInsertAfter,
1669 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1671 return 1;
1674 return DefWindowProcA(hwnd, msg, wparam, lparam);
1677 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1679 static HWND mdi_client;
1681 switch (msg)
1683 case WM_CREATE:
1685 CLIENTCREATESTRUCT client_cs;
1686 RECT rc;
1688 GetClientRect(hwnd, &rc);
1690 client_cs.hWindowMenu = 0;
1691 client_cs.idFirstChild = 1;
1693 /* MDIClient without MDIS_ALLCHILDSTYLES */
1694 mdi_client = CreateWindowExA(0, "mdiclient",
1695 NULL,
1696 WS_CHILD /*| WS_VISIBLE*/,
1697 /* tests depend on a not zero MDIClient size */
1698 0, 0, rc.right, rc.bottom,
1699 hwnd, 0, GetModuleHandle(0),
1700 &client_cs);
1701 assert(mdi_client);
1702 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1703 DestroyWindow(mdi_client);
1705 /* MDIClient with MDIS_ALLCHILDSTYLES */
1706 mdi_client = CreateWindowExA(0, "mdiclient",
1707 NULL,
1708 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1709 /* tests depend on a not zero MDIClient size */
1710 0, 0, rc.right, rc.bottom,
1711 hwnd, 0, GetModuleHandle(0),
1712 &client_cs);
1713 assert(mdi_client);
1714 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1715 DestroyWindow(mdi_client);
1716 break;
1719 case WM_WINDOWPOSCHANGED:
1721 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1722 RECT rc1, rc2;
1724 GetWindowRect(hwnd, &rc1);
1725 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1726 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1727 /* note: winpos coordinates are relative to parent */
1728 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1729 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1730 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1732 GetWindowRect(hwnd, &rc1);
1733 GetClientRect(hwnd, &rc2);
1734 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1735 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1736 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1738 /* fall through */
1739 case WM_WINDOWPOSCHANGING:
1741 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1742 WINDOWPOS my_winpos = *winpos;
1744 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1745 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1746 winpos->hwnd, winpos->hwndInsertAfter,
1747 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1749 DefWindowProcA(hwnd, msg, wparam, lparam);
1751 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1752 winpos->hwnd, winpos->hwndInsertAfter,
1753 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1755 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1756 "DefWindowProc should not change WINDOWPOS values\n");
1758 return 1;
1761 case WM_CLOSE:
1762 PostQuitMessage(0);
1763 break;
1765 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1768 static BOOL mdi_RegisterWindowClasses(void)
1770 WNDCLASSA cls;
1772 cls.style = 0;
1773 cls.lpfnWndProc = mdi_main_wnd_procA;
1774 cls.cbClsExtra = 0;
1775 cls.cbWndExtra = 0;
1776 cls.hInstance = GetModuleHandleA(0);
1777 cls.hIcon = 0;
1778 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1779 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1780 cls.lpszMenuName = NULL;
1781 cls.lpszClassName = "MDI_parent_Class";
1782 if(!RegisterClassA(&cls)) return FALSE;
1784 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1785 cls.lpszClassName = "MDI_child_Class_1";
1786 if(!RegisterClassA(&cls)) return FALSE;
1788 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1789 cls.lpszClassName = "MDI_child_Class_2";
1790 if(!RegisterClassA(&cls)) return FALSE;
1792 return TRUE;
1795 static void test_mdi(void)
1797 HWND mdi_hwndMain;
1798 /*MSG msg;*/
1800 if (!mdi_RegisterWindowClasses()) assert(0);
1802 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1803 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1804 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1805 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1806 GetDesktopWindow(), 0,
1807 GetModuleHandle(0), NULL);
1808 assert(mdi_hwndMain);
1810 while(GetMessage(&msg, 0, 0, 0))
1812 TranslateMessage(&msg);
1813 DispatchMessage(&msg);
1816 DestroyWindow(mdi_hwndMain);
1819 static void test_icons(void)
1821 WNDCLASSEXA cls;
1822 HWND hwnd;
1823 HICON icon = LoadIconA(0, IDI_APPLICATION);
1824 HICON icon2 = LoadIconA(0, IDI_QUESTION);
1825 HICON small_icon = LoadImageA(0, IDI_APPLICATION, IMAGE_ICON,
1826 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1827 HICON res;
1829 cls.cbSize = sizeof(cls);
1830 cls.style = 0;
1831 cls.lpfnWndProc = DefWindowProcA;
1832 cls.cbClsExtra = 0;
1833 cls.cbWndExtra = 0;
1834 cls.hInstance = 0;
1835 cls.hIcon = LoadIconA(0, IDI_HAND);
1836 cls.hIconSm = small_icon;
1837 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1838 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1839 cls.lpszMenuName = NULL;
1840 cls.lpszClassName = "IconWindowClass";
1842 RegisterClassExA(&cls);
1844 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1845 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1846 assert( hwnd );
1848 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1849 ok( res == 0, "wrong big icon %p/0\n", res );
1850 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1851 ok( res == 0, "wrong previous big icon %p/0\n", res );
1852 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1853 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1854 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1855 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1856 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1857 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1859 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1860 ok( res == 0, "wrong small icon %p/0\n", res );
1861 /* this test is XP specific */
1862 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1863 ok( res != 0, "wrong small icon %p\n", res );*/
1864 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1865 ok( res == 0, "wrong previous small icon %p/0\n", res );
1866 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1867 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1868 /* this test is XP specific */
1869 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1870 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1871 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1872 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1873 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1874 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1875 /* this test is XP specific */
1876 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1877 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1879 /* make sure the big icon hasn't changed */
1880 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1881 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1883 DestroyWindow( hwnd );
1886 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1888 if (msg == WM_NCCALCSIZE)
1890 RECT *rect = (RECT *)lparam;
1891 /* first time around increase the rectangle, next time decrease it */
1892 if (rect->left == 100) InflateRect( rect, 10, 10 );
1893 else InflateRect( rect, -10, -10 );
1894 return 0;
1896 return DefWindowProc( hwnd, msg, wparam, lparam );
1899 static void test_SetWindowPos(HWND hwnd)
1901 RECT orig_win_rc, rect;
1902 LONG_PTR old_proc;
1903 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1905 SetRect(&rect, 111, 222, 333, 444);
1906 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1907 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1908 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1910 SetRect(&rect, 111, 222, 333, 444);
1911 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1912 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1913 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1915 GetWindowRect(hwnd, &orig_win_rc);
1917 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1918 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1919 GetWindowRect( hwnd, &rect );
1920 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1921 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1922 GetClientRect( hwnd, &rect );
1923 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1924 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1925 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1927 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1928 GetWindowRect( hwnd, &rect );
1929 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1930 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1931 GetClientRect( hwnd, &rect );
1932 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1933 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1934 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1936 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1937 orig_win_rc.right, orig_win_rc.bottom, 0);
1938 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1940 /* Win9x truncates coordinates to 16-bit irrespectively */
1941 if (!is_win9x)
1943 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1944 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1946 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1947 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1950 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1951 orig_win_rc.right, orig_win_rc.bottom, 0);
1953 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1954 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1955 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1956 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1957 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1958 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1959 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1962 static void test_SetMenu(HWND parent)
1964 HWND child;
1965 HMENU hMenu, ret;
1966 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1967 BOOL retok;
1968 DWORD style;
1970 hMenu = CreateMenu();
1971 assert(hMenu);
1973 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1974 if (0)
1976 /* fails on (at least) Wine, NT4, XP SP2 */
1977 test_nonclient_area(parent);
1979 ret = GetMenu(parent);
1980 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1981 /* test whether we can destroy a menu assigned to a window */
1982 retok = DestroyMenu(hMenu);
1983 ok( retok, "DestroyMenu error %d\n", GetLastError());
1984 retok = IsMenu(hMenu);
1985 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
1986 ret = GetMenu(parent);
1987 /* This test fails on Win9x */
1988 if (!is_win9x)
1989 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1990 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1991 test_nonclient_area(parent);
1993 hMenu = CreateMenu();
1994 assert(hMenu);
1996 /* parent */
1997 ret = GetMenu(parent);
1998 ok(ret == 0, "unexpected menu id %p\n", ret);
2000 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2001 test_nonclient_area(parent);
2002 ret = GetMenu(parent);
2003 ok(ret == 0, "unexpected menu id %p\n", ret);
2005 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2006 if (0)
2008 /* fails on (at least) Wine, NT4, XP SP2 */
2009 test_nonclient_area(parent);
2011 ret = GetMenu(parent);
2012 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2014 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2015 test_nonclient_area(parent);
2016 ret = GetMenu(parent);
2017 ok(ret == 0, "unexpected menu id %p\n", ret);
2019 /* child */
2020 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
2021 assert(child);
2023 ret = GetMenu(child);
2024 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2026 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2027 test_nonclient_area(child);
2028 ret = GetMenu(child);
2029 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2031 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
2032 test_nonclient_area(child);
2033 ret = GetMenu(child);
2034 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2036 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
2037 test_nonclient_area(child);
2038 ret = GetMenu(child);
2039 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2041 style = GetWindowLong(child, GWL_STYLE);
2042 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
2043 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
2044 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
2045 SetWindowLong(child, GWL_STYLE, style);
2047 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
2048 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
2049 SetWindowLong(child, GWL_STYLE, style);
2051 DestroyWindow(child);
2052 DestroyMenu(hMenu);
2055 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
2057 HWND child[5], hwnd;
2058 INT_PTR i;
2060 assert(total <= 5);
2062 hwnd = GetWindow(parent, GW_CHILD);
2063 ok(!hwnd, "have to start without children to perform the test\n");
2065 for (i = 0; i < total; i++)
2067 if (style[i] & DS_CONTROL)
2069 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
2070 0,0,0,0, parent, (HMENU)i, 0, NULL);
2071 if (style[i] & WS_VISIBLE)
2072 ShowWindow(child[i], SW_SHOW);
2074 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
2076 else
2077 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
2078 parent, (HMENU)i, 0, NULL);
2079 trace("child[%ld] = %p\n", i, child[i]);
2080 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
2083 hwnd = GetWindow(parent, GW_CHILD);
2084 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
2085 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
2086 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
2088 for (i = 0; i < total; i++)
2090 trace("hwnd[%ld] = %p\n", i, hwnd);
2091 ok(child[order[i]] == hwnd, "Z order of child #%ld is wrong\n", i);
2093 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
2096 for (i = 0; i < total; i++)
2097 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2100 static void test_children_zorder(HWND parent)
2102 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2103 WS_CHILD };
2104 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2106 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2107 WS_CHILD | WS_VISIBLE, WS_CHILD,
2108 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2109 const int complex_order_1[1] = { 0 };
2110 const int complex_order_2[2] = { 1, 0 };
2111 const int complex_order_3[3] = { 1, 0, 2 };
2112 const int complex_order_4[4] = { 1, 0, 2, 3 };
2113 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2114 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2115 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2116 WS_CHILD | WS_VISIBLE };
2117 const int complex_order_6[3] = { 0, 1, 2 };
2119 /* simple WS_CHILD */
2120 test_window_tree(parent, simple_style, simple_order, 5);
2122 /* complex children styles */
2123 test_window_tree(parent, complex_style, complex_order_1, 1);
2124 test_window_tree(parent, complex_style, complex_order_2, 2);
2125 test_window_tree(parent, complex_style, complex_order_3, 3);
2126 test_window_tree(parent, complex_style, complex_order_4, 4);
2127 test_window_tree(parent, complex_style, complex_order_5, 5);
2129 /* another set of complex children styles */
2130 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2133 #define check_z_order(hwnd, next, prev, owner, topmost) \
2134 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2135 __FILE__, __LINE__)
2137 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2138 BOOL topmost, const char *file, int line)
2140 HWND test;
2141 DWORD ex_style;
2143 test = GetWindow(hwnd, GW_HWNDNEXT);
2144 /* skip foreign windows */
2145 while (test && test != next &&
2146 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2147 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2148 GetWindow(test, GW_OWNER) == next))
2150 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2151 test = GetWindow(test, GW_HWNDNEXT);
2153 ok_(file, line)(next == test, "expected next %p, got %p\n", next, test);
2155 test = GetWindow(hwnd, GW_HWNDPREV);
2156 /* skip foreign windows */
2157 while (test && test != prev &&
2158 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2159 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2160 GetWindow(test, GW_OWNER) == hwnd))
2162 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2163 test = GetWindow(test, GW_HWNDPREV);
2165 ok_(file, line)(prev == test, "expected prev %p, got %p\n", prev, test);
2167 test = GetWindow(hwnd, GW_OWNER);
2168 ok_(file, line)(owner == test, "expected owner %p, got %p\n", owner, test);
2170 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2171 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "expected %stopmost\n", topmost ? "" : "NOT ");
2174 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E)
2176 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2178 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2180 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2182 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2183 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2185 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2186 WS_OVERLAPPED | WS_CAPTION,
2187 100, 100, 100, 100,
2188 0, 0, GetModuleHandle(0), NULL);
2189 trace("hwnd_F %p\n", hwnd_F);
2190 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2192 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2193 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2194 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2195 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2197 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2198 WS_POPUP,
2199 100, 100, 100, 100,
2200 hwnd_F, 0, GetModuleHandle(0), NULL);
2201 trace("hwnd_C %p\n", hwnd_C);
2202 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2203 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2204 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2205 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2207 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2208 WS_POPUP,
2209 100, 100, 100, 100,
2210 hwnd_F, 0, GetModuleHandle(0), NULL);
2211 trace("hwnd_B %p\n", hwnd_B);
2212 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2213 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2214 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2215 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2216 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2218 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2219 WS_POPUP,
2220 100, 100, 100, 100,
2221 0, 0, GetModuleHandle(0), NULL);
2222 trace("hwnd_A %p\n", hwnd_A);
2223 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2224 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2225 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2226 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2227 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2228 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2230 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);
2232 /* move hwnd_F and its popups up */
2233 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2234 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2235 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2236 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2237 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2238 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2239 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2241 /* move hwnd_F and its popups down */
2242 #if 0 /* enable once Wine is fixed to pass this test */
2243 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2244 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2245 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2246 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2247 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2248 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2249 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2250 #endif
2252 DestroyWindow(hwnd_A);
2253 DestroyWindow(hwnd_B);
2254 DestroyWindow(hwnd_C);
2255 DestroyWindow(hwnd_F);
2258 static void test_vis_rgn( HWND hwnd )
2260 RECT win_rect, rgn_rect;
2261 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2262 HDC hdc;
2264 ShowWindow(hwnd,SW_SHOW);
2265 hdc = GetDC( hwnd );
2266 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2267 GetWindowRect( hwnd, &win_rect );
2268 GetRgnBox( hrgn, &rgn_rect );
2269 if (GetVersion() & 0x80000000)
2271 trace("win9x, mapping to screen coords\n");
2272 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2274 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2275 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2276 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2277 rgn_rect.left, win_rect.left );
2278 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2279 rgn_rect.top, win_rect.top );
2280 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2281 rgn_rect.right, win_rect.right );
2282 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2283 rgn_rect.bottom, win_rect.bottom );
2284 ReleaseDC( hwnd, hdc );
2287 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2289 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2291 HWND child = GetWindow(hwnd, GW_CHILD);
2292 ok(child != 0, "couldn't find child window\n");
2293 SetFocus(child);
2294 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2295 return 0;
2297 return DefWindowProc(hwnd, msg, wp, lp);
2300 static void test_SetFocus(HWND hwnd)
2302 HWND child, child2;
2303 WNDPROC old_wnd_proc;
2305 /* check if we can set focus to non-visible windows */
2307 ShowWindow(hwnd, SW_SHOW);
2308 SetFocus(0);
2309 SetFocus(hwnd);
2310 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2311 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2312 ShowWindow(hwnd, SW_HIDE);
2313 SetFocus(0);
2314 SetFocus(hwnd);
2315 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2316 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2317 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2318 assert(child);
2319 SetFocus(child);
2320 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2321 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2322 ShowWindow(child, SW_SHOW);
2323 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2324 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2325 ShowWindow(child, SW_HIDE);
2326 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2327 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2328 ShowWindow(child, SW_SHOW);
2329 child2 = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, child, 0, 0, NULL);
2330 assert(child2);
2331 ShowWindow(child2, SW_SHOW);
2332 SetFocus(child2);
2333 ShowWindow(child, SW_HIDE);
2334 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2335 ok( GetFocus() == child2, "Focus should be on %p, not %p\n", child2, GetFocus() );
2336 ShowWindow(child, SW_SHOW);
2337 SetFocus(child);
2338 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2339 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2340 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2342 ShowWindow(child, SW_HIDE);
2343 SetFocus(hwnd);
2344 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2345 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2346 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2347 ShowWindow(child, SW_HIDE);
2348 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2350 ShowWindow(hwnd, SW_SHOW);
2351 ShowWindow(child, SW_SHOW);
2352 SetFocus(child);
2353 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2354 EnableWindow(hwnd, FALSE);
2355 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2356 EnableWindow(hwnd, TRUE);
2358 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2359 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2360 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2361 todo_wine
2362 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2363 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2364 ShowWindow(hwnd, SW_RESTORE);
2365 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2366 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2367 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2368 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2369 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2370 todo_wine
2371 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2372 old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2373 ShowWindow(hwnd, SW_RESTORE);
2374 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2375 todo_wine
2376 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2378 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2380 DestroyWindow( child2 );
2381 DestroyWindow( child );
2384 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
2385 static void check_wnd_state_(const char *file, int line,
2386 HWND active, HWND foreground, HWND focus, HWND capture)
2388 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2389 /* only check foreground if it belongs to the current thread */
2390 /* foreground can be moved to a different app pretty much at any time */
2391 if (foreground && GetForegroundWindow() &&
2392 GetWindowThreadProcessId(GetForegroundWindow(), NULL) == GetCurrentThreadId())
2393 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2394 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2395 ok_(file, line)(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2398 static void test_SetActiveWindow(HWND hwnd)
2400 HWND hwnd2;
2402 flush_events( TRUE );
2403 ShowWindow(hwnd, SW_HIDE);
2404 SetFocus(0);
2405 SetActiveWindow(0);
2406 check_wnd_state(0, 0, 0, 0);
2408 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2410 ShowWindow(hwnd, SW_SHOW);
2411 check_wnd_state(hwnd, hwnd, hwnd, 0);
2413 hwnd2 = SetActiveWindow(0);
2414 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2415 if (!GetActiveWindow()) /* doesn't always work on vista */
2417 check_wnd_state(0, 0, 0, 0);
2418 hwnd2 = SetActiveWindow(hwnd);
2419 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2421 check_wnd_state(hwnd, hwnd, hwnd, 0);
2423 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2424 check_wnd_state(hwnd, hwnd, hwnd, 0);
2426 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2427 check_wnd_state(hwnd, hwnd, hwnd, 0);
2429 ShowWindow(hwnd, SW_HIDE);
2430 check_wnd_state(0, 0, 0, 0);
2432 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2433 SetActiveWindow(hwnd);
2434 check_wnd_state(hwnd, hwnd, hwnd, 0);
2436 ShowWindow(hwnd, SW_SHOW);
2437 check_wnd_state(hwnd, hwnd, hwnd, 0);
2439 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2440 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2442 DestroyWindow(hwnd2);
2443 check_wnd_state(hwnd, hwnd, hwnd, 0);
2445 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2446 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2448 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2449 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2451 DestroyWindow(hwnd2);
2452 check_wnd_state(hwnd, hwnd, hwnd, 0);
2455 static void test_SetForegroundWindow(HWND hwnd)
2457 BOOL ret;
2458 HWND hwnd2;
2460 flush_events( TRUE );
2461 ShowWindow(hwnd, SW_HIDE);
2462 SetFocus(0);
2463 SetActiveWindow(0);
2464 check_wnd_state(0, 0, 0, 0);
2466 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2468 ShowWindow(hwnd, SW_SHOW);
2469 check_wnd_state(hwnd, hwnd, hwnd, 0);
2471 hwnd2 = SetActiveWindow(0);
2472 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2473 if (GetActiveWindow() == hwnd) /* doesn't always work on vista */
2474 check_wnd_state(hwnd, hwnd, hwnd, 0);
2475 else
2476 check_wnd_state(0, 0, 0, 0);
2478 ret = SetForegroundWindow(hwnd);
2479 if (!ret)
2481 skip( "SetForegroundWindow not working\n" );
2482 return;
2484 check_wnd_state(hwnd, hwnd, hwnd, 0);
2486 SetLastError(0xdeadbeef);
2487 ret = SetForegroundWindow(0);
2488 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2489 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
2490 broken(GetLastError() == 0xdeadbeef), /* win9x */
2491 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2492 check_wnd_state(hwnd, hwnd, hwnd, 0);
2494 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2495 check_wnd_state(hwnd, hwnd, hwnd, 0);
2497 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2498 check_wnd_state(hwnd, hwnd, hwnd, 0);
2500 hwnd2 = GetForegroundWindow();
2501 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2502 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2503 hwnd2 = GetForegroundWindow();
2504 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2506 ShowWindow(hwnd, SW_HIDE);
2507 check_wnd_state(0, 0, 0, 0);
2509 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2510 ret = SetForegroundWindow(hwnd);
2511 ok(ret || broken(!ret), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
2512 check_wnd_state(hwnd, hwnd, hwnd, 0);
2514 ShowWindow(hwnd, SW_SHOW);
2515 check_wnd_state(hwnd, hwnd, hwnd, 0);
2517 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2518 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2520 DestroyWindow(hwnd2);
2521 check_wnd_state(hwnd, hwnd, hwnd, 0);
2523 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2524 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2526 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2527 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2529 DestroyWindow(hwnd2);
2530 check_wnd_state(hwnd, hwnd, hwnd, 0);
2533 static WNDPROC old_button_proc;
2535 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2537 LRESULT ret;
2538 USHORT key_state;
2540 key_state = GetKeyState(VK_LBUTTON);
2541 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2543 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2545 if (msg == WM_LBUTTONDOWN)
2547 HWND hwnd, capture;
2549 check_wnd_state(button, button, button, button);
2551 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2552 assert(hwnd);
2553 trace("hwnd %p\n", hwnd);
2555 check_wnd_state(button, button, button, button);
2557 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2559 check_wnd_state(button, button, button, button);
2561 DestroyWindow(hwnd);
2563 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2564 assert(hwnd);
2565 trace("hwnd %p\n", hwnd);
2567 check_wnd_state(button, button, button, button);
2569 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2570 * match internal button state.
2572 SendMessage(button, WM_KILLFOCUS, 0, 0);
2573 check_wnd_state(button, button, button, 0);
2575 ShowWindow(hwnd, SW_SHOW);
2576 check_wnd_state(hwnd, hwnd, hwnd, 0);
2578 capture = SetCapture(hwnd);
2579 ok(capture == 0, "SetCapture() = %p\n", capture);
2581 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2583 DestroyWindow(hwnd);
2585 check_wnd_state(button, 0, button, 0);
2588 return ret;
2591 static void test_capture_1(void)
2593 HWND button, capture, oldFocus, oldActive;
2595 oldFocus = GetFocus();
2596 oldActive = GetActiveWindow();
2598 capture = GetCapture();
2599 ok(capture == 0, "GetCapture() = %p\n", capture);
2601 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2602 assert(button);
2603 trace("button %p\n", button);
2605 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2607 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2609 capture = SetCapture(button);
2610 ok(capture == 0, "SetCapture() = %p\n", capture);
2611 check_wnd_state(button, 0, button, button);
2613 DestroyWindow(button);
2614 check_wnd_state(oldActive, 0, oldFocus, 0);
2617 static void test_capture_2(void)
2619 HWND button, hwnd, capture, oldFocus, oldActive;
2621 oldFocus = GetFocus();
2622 oldActive = GetActiveWindow();
2623 check_wnd_state(oldActive, 0, oldFocus, 0);
2625 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2626 assert(button);
2627 trace("button %p\n", button);
2629 check_wnd_state(button, button, button, 0);
2631 capture = SetCapture(button);
2632 ok(capture == 0, "SetCapture() = %p\n", capture);
2634 check_wnd_state(button, button, button, button);
2636 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2637 * internal button state.
2639 SendMessage(button, WM_KILLFOCUS, 0, 0);
2640 check_wnd_state(button, button, button, button);
2642 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2643 assert(hwnd);
2644 trace("hwnd %p\n", hwnd);
2646 check_wnd_state(button, button, button, button);
2648 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2650 check_wnd_state(button, button, button, button);
2652 DestroyWindow(hwnd);
2654 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2655 assert(hwnd);
2656 trace("hwnd %p\n", hwnd);
2658 check_wnd_state(button, button, button, button);
2660 ShowWindow(hwnd, SW_SHOW);
2662 check_wnd_state(hwnd, hwnd, hwnd, button);
2664 capture = SetCapture(hwnd);
2665 ok(capture == button, "SetCapture() = %p\n", capture);
2667 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2669 DestroyWindow(hwnd);
2670 check_wnd_state(button, button, button, 0);
2672 DestroyWindow(button);
2673 check_wnd_state(oldActive, 0, oldFocus, 0);
2676 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2678 BOOL ret;
2680 ShowWindow(hwnd1, SW_HIDE);
2681 ShowWindow(hwnd2, SW_HIDE);
2683 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2684 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2686 SetCapture(hwnd1);
2687 check_wnd_state(0, 0, 0, hwnd1);
2689 SetCapture(hwnd2);
2690 check_wnd_state(0, 0, 0, hwnd2);
2692 ShowWindow(hwnd1, SW_SHOW);
2693 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2695 ret = ReleaseCapture();
2696 ok (ret, "releasecapture did not return TRUE.\n");
2697 ret = ReleaseCapture();
2698 ok (ret, "releasecapture did not return TRUE after second try.\n");
2701 static LRESULT CALLBACK test_capture_4_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2703 GUITHREADINFO gti;
2704 HWND cap_wnd, cap_wnd2, set_cap_wnd;
2705 BOOL status;
2706 switch (msg)
2708 case WM_CAPTURECHANGED:
2710 /* now try to release capture from menu. this should fail */
2711 if (pGetGUIThreadInfo)
2713 memset(&gti, 0, sizeof(GUITHREADINFO));
2714 gti.cbSize = sizeof(GUITHREADINFO);
2715 status = pGetGUIThreadInfo(GetCurrentThreadId(), &gti);
2716 ok(status, "GetGUIThreadInfo() failed!\n");
2717 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
2719 cap_wnd = GetCapture();
2721 /* check that re-setting the capture for the menu fails */
2722 set_cap_wnd = SetCapture(cap_wnd);
2723 ok(!set_cap_wnd, "SetCapture should have failed!\n");
2725 /* check that SetCapture fails for another window and that it does not touch the error code */
2726 set_cap_wnd = SetCapture(hWnd);
2727 ok(!set_cap_wnd, "ReleaseCapture should have failed!\n");
2729 /* check that ReleaseCapture fails and does not touch the error code */
2730 status = ReleaseCapture();
2731 ok(!status, "ReleaseCapture should have failed!\n");
2733 /* check that thread info did not change */
2734 if (pGetGUIThreadInfo)
2736 memset(&gti, 0, sizeof(GUITHREADINFO));
2737 gti.cbSize = sizeof(GUITHREADINFO);
2738 status = pGetGUIThreadInfo(GetCurrentThreadId(), &gti);
2739 ok(status, "GetGUIThreadInfo() failed!\n");
2740 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
2743 /* verify that no capture change took place */
2744 cap_wnd2 = GetCapture();
2745 ok(cap_wnd2 == cap_wnd, "Capture changed!\n");
2747 /* we are done. kill the window */
2748 DestroyWindow(hWnd);
2749 break;
2751 default:
2752 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
2754 return 0;
2757 /* Test that no-one can mess around with the current capture while a menu is open */
2758 static void test_capture_4(void)
2760 BOOL ret;
2761 HMENU hmenu;
2762 HWND hwnd;
2763 WNDCLASSA wclass;
2764 HINSTANCE hInstance = GetModuleHandleA( NULL );
2766 if (!pGetGUIThreadInfo)
2767 win_skip("GetGUIThreadInfo is not available\n");
2769 wclass.lpszClassName = "TestCapture4Class";
2770 wclass.style = CS_HREDRAW | CS_VREDRAW;
2771 wclass.lpfnWndProc = test_capture_4_proc;
2772 wclass.hInstance = hInstance;
2773 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
2774 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
2775 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2776 wclass.lpszMenuName = 0;
2777 wclass.cbClsExtra = 0;
2778 wclass.cbWndExtra = 0;
2779 assert (RegisterClassA( &wclass ));
2780 assert (hwnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
2781 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2782 400, 200, NULL, NULL, hInstance, NULL) );
2783 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
2784 if (!hwnd) return;
2785 hmenu = CreatePopupMenu();
2787 ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest2");
2788 ok( ret, "AppendMenuA has failed!\n");
2790 /* set main window to have initial capture */
2791 SetCapture(hwnd);
2793 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
2795 win_skip("TrackPopupMenu test crashes on Win9x/WinMe\n");
2797 else
2799 /* create popup (it will self-destruct) */
2800 ret = TrackPopupMenu(hmenu, TPM_RETURNCMD, 100, 100, 0, hwnd, NULL);
2801 ok( ret == 0, "TrackPopupMenu returned %d expected zero\n", ret);
2804 /* clean up */
2805 DestroyMenu(hmenu);
2806 DestroyWindow(hwnd);
2809 /* PeekMessage wrapper that ignores the messages we don't care about */
2810 static BOOL peek_message( MSG *msg )
2812 BOOL ret;
2815 ret = PeekMessageA(msg, 0, 0, 0, PM_REMOVE);
2816 } while (ret && (msg->message == WM_TIMER || ignore_message(msg->message)));
2817 return ret;
2820 static void test_keyboard_input(HWND hwnd)
2822 MSG msg;
2823 BOOL ret;
2825 flush_events( TRUE );
2826 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
2827 UpdateWindow(hwnd);
2828 flush_events( TRUE );
2830 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2832 SetFocus(hwnd);
2833 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2835 flush_events( TRUE );
2837 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2838 ret = peek_message(&msg);
2839 ok( ret, "no message available\n");
2840 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2841 ret = peek_message(&msg);
2842 ok( !ret, "message %04x available\n", msg.message);
2844 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2846 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2847 ret = peek_message(&msg);
2848 ok(ret, "no message available\n");
2849 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2850 ret = peek_message(&msg);
2851 ok( !ret, "message %04x available\n", msg.message);
2853 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2855 keybd_event(VK_SPACE, 0, 0, 0);
2856 if (!peek_message(&msg))
2858 skip( "keybd_event didn't work, skipping keyboard test\n" );
2859 return;
2861 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2862 ret = peek_message(&msg);
2863 ok( !ret, "message %04x available\n", msg.message);
2865 SetFocus(0);
2866 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2868 flush_events( TRUE );
2870 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2871 ret = peek_message(&msg);
2872 ok(ret, "no message available\n");
2873 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2874 ret = peek_message(&msg);
2875 ok( !ret, "message %04x available\n", msg.message);
2877 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2879 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2880 ret = peek_message(&msg);
2881 ok(ret, "no message available\n");
2882 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2883 ret = peek_message(&msg);
2884 ok( !ret, "message %04x available\n", msg.message);
2886 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2888 keybd_event(VK_SPACE, 0, 0, 0);
2889 ret = peek_message(&msg);
2890 ok(ret, "no message available\n");
2891 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2892 ret = peek_message(&msg);
2893 ok( !ret, "message %04x available\n", msg.message);
2896 static BOOL wait_for_message( MSG *msg )
2898 BOOL ret;
2900 for (;;)
2902 ret = peek_message(msg);
2903 if (ret)
2905 if (msg->message == WM_PAINT) DispatchMessage(msg);
2906 else break;
2908 else if (MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
2910 if (!ret) msg->message = 0;
2911 return ret;
2914 static void test_mouse_input(HWND hwnd)
2916 RECT rc;
2917 POINT pt;
2918 int x, y;
2919 HWND popup;
2920 MSG msg;
2921 BOOL ret;
2922 LRESULT res;
2924 ShowWindow(hwnd, SW_SHOW);
2925 UpdateWindow(hwnd);
2926 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2928 GetWindowRect(hwnd, &rc);
2929 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2931 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2932 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2933 hwnd, 0, 0, NULL);
2934 assert(popup != 0);
2935 ShowWindow(popup, SW_SHOW);
2936 UpdateWindow(popup);
2937 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2939 GetWindowRect(popup, &rc);
2940 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2942 x = rc.left + (rc.right - rc.left) / 2;
2943 y = rc.top + (rc.bottom - rc.top) / 2;
2944 trace("setting cursor to (%d,%d)\n", x, y);
2946 SetCursorPos(x, y);
2947 GetCursorPos(&pt);
2948 if (x != pt.x || y != pt.y)
2950 skip( "failed to set mouse position, skipping mouse input tests\n" );
2951 goto done;
2954 flush_events( TRUE );
2956 /* Check that setting the same position may generate WM_MOUSEMOVE */
2957 SetCursorPos(x, y);
2958 msg.message = 0;
2959 ret = peek_message(&msg);
2960 if (ret)
2962 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
2963 msg.hwnd, msg.message);
2964 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
2965 x, y, msg.pt.x, msg.pt.y);
2968 /* force the system to update its internal queue mouse position,
2969 * otherwise it won't generate relative mouse movements below.
2971 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2972 flush_events( TRUE );
2974 msg.message = 0;
2975 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2976 flush_events( FALSE );
2977 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2978 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2980 if (msg.message == WM_TIMER || ignore_message(msg.message)) continue;
2981 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
2982 "hwnd %p message %04x\n", msg.hwnd, msg.message);
2984 ret = peek_message(&msg);
2985 ok( !ret, "message %04x available\n", msg.message);
2987 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2988 ShowWindow(popup, SW_HIDE);
2989 ret = wait_for_message( &msg );
2990 if (ret)
2991 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2992 flush_events( TRUE );
2994 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2995 ShowWindow(hwnd, SW_HIDE);
2996 ret = wait_for_message( &msg );
2997 ok( !ret, "message %04x available\n", msg.message);
2998 flush_events( TRUE );
3000 /* test mouse clicks */
3002 ShowWindow(hwnd, SW_SHOW);
3003 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3004 flush_events( TRUE );
3005 ShowWindow(popup, SW_SHOW);
3006 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3007 flush_events( TRUE );
3009 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3010 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3011 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3012 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3014 ret = wait_for_message( &msg );
3015 if (!ret)
3017 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
3018 goto done;
3020 if (msg.message == WM_MOUSEMOVE) /* win2k has an extra WM_MOUSEMOVE here */
3022 ret = wait_for_message( &msg );
3023 ok(ret, "no message available\n");
3026 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3027 msg.hwnd, popup, msg.message);
3029 ret = wait_for_message( &msg );
3030 ok(ret, "no message available\n");
3031 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3032 msg.hwnd, popup, msg.message);
3034 ret = wait_for_message( &msg );
3035 ok(ret, "no message available\n");
3036 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
3037 msg.hwnd, popup, msg.message);
3039 ret = wait_for_message( &msg );
3040 ok(ret, "no message available\n");
3041 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3042 msg.hwnd, popup, msg.message);
3044 ret = peek_message(&msg);
3045 ok(!ret, "message %04x available\n", msg.message);
3047 ShowWindow(popup, SW_HIDE);
3048 flush_events( TRUE );
3050 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3051 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3052 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3053 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3055 ret = wait_for_message( &msg );
3056 ok(ret, "no message available\n");
3057 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3058 msg.hwnd, hwnd, msg.message);
3059 ret = wait_for_message( &msg );
3060 ok(ret, "no message available\n");
3061 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3062 msg.hwnd, hwnd, msg.message);
3064 test_lbuttondown_flag = TRUE;
3065 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
3066 test_lbuttondown_flag = FALSE;
3068 ret = wait_for_message( &msg );
3069 ok(ret, "no message available\n");
3070 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3071 msg.hwnd, popup, msg.message);
3072 ok(peek_message(&msg), "no message available\n");
3073 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3074 msg.hwnd, popup, msg.message);
3075 ok(peek_message(&msg), "no message available\n");
3077 /* Test WM_MOUSEACTIVATE */
3078 #define TEST_MOUSEACTIVATE(A,B) \
3079 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
3080 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
3082 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
3083 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
3084 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
3085 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
3086 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
3087 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
3088 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
3089 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
3090 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
3091 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
3092 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
3093 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
3094 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
3095 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
3096 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
3097 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
3098 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
3099 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
3100 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
3101 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
3102 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
3103 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
3104 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
3105 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
3107 done:
3108 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
3109 flush_events( TRUE );
3111 DestroyWindow(popup);
3114 static void test_validatergn(HWND hwnd)
3116 HWND child;
3117 RECT rc, rc2;
3118 HRGN rgn;
3119 int ret;
3120 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
3121 ShowWindow(hwnd, SW_SHOW);
3122 UpdateWindow( hwnd);
3123 /* test that ValidateRect validates children*/
3124 InvalidateRect( child, NULL, 1);
3125 GetWindowRect( child, &rc);
3126 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3127 ret = GetUpdateRect( child, &rc2, 0);
3128 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
3129 "Update rectangle is empty!\n");
3130 ValidateRect( hwnd, &rc);
3131 ret = GetUpdateRect( child, &rc2, 0);
3132 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3133 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3134 rc2.right, rc2.bottom);
3136 /* now test ValidateRgn */
3137 InvalidateRect( child, NULL, 1);
3138 GetWindowRect( child, &rc);
3139 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3140 rgn = CreateRectRgnIndirect( &rc);
3141 ValidateRgn( hwnd, rgn);
3142 ret = GetUpdateRect( child, &rc2, 0);
3143 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3144 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3145 rc2.right, rc2.bottom);
3147 DeleteObject( rgn);
3148 DestroyWindow( child );
3151 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
3153 RECT rc;
3154 MoveWindow( hwnd, 0, 0, x, y, 0);
3155 GetWindowRect( hwnd, prc);
3156 rc = *prc;
3157 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
3158 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
3159 rc.left,rc.top,rc.right,rc.bottom, prc->left,prc->top,prc->right,prc->bottom);
3162 static void test_nccalcscroll(HWND parent)
3164 RECT rc1;
3165 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
3166 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
3167 HWND hwnd = CreateWindowExA(0, "static", NULL,
3168 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
3169 10, 10, 200, 200, parent, 0, 0, NULL);
3170 ShowWindow( parent, SW_SHOW);
3171 UpdateWindow( parent);
3173 /* test window too low for a horizontal scroll bar */
3174 nccalchelper( hwnd, 100, sbheight, &rc1);
3175 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
3176 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
3178 /* test window just high enough for a horizontal scroll bar */
3179 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
3180 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
3181 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3183 /* test window too narrow for a vertical scroll bar */
3184 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
3185 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
3186 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3188 /* test window just wide enough for a vertical scroll bar */
3189 nccalchelper( hwnd, sbwidth, 100, &rc1);
3190 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
3191 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
3193 /* same test, but with client edge: not enough width */
3194 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
3195 nccalchelper( hwnd, sbwidth, 100, &rc1);
3196 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
3197 "Width should be %d size is %d,%d - %d,%d\n",
3198 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
3200 DestroyWindow( hwnd);
3203 static void test_SetParent(void)
3205 BOOL ret;
3206 HWND desktop = GetDesktopWindow();
3207 HMENU hMenu;
3208 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
3209 HWND parent, child1, child2, child3, child4, sibling;
3211 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3212 100, 100, 200, 200, 0, 0, 0, NULL);
3213 assert(parent != 0);
3214 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3215 0, 0, 50, 50, parent, 0, 0, NULL);
3216 assert(child1 != 0);
3217 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3218 0, 0, 50, 50, child1, 0, 0, NULL);
3219 assert(child2 != 0);
3220 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3221 0, 0, 50, 50, child2, 0, 0, NULL);
3222 assert(child3 != 0);
3223 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3224 0, 0, 50, 50, child3, 0, 0, NULL);
3225 assert(child4 != 0);
3227 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
3228 parent, child1, child2, child3, child4);
3230 check_parents(parent, desktop, 0, 0, 0, parent, parent);
3231 check_parents(child1, parent, parent, parent, 0, parent, parent);
3232 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3233 check_parents(child3, child2, child2, child2, 0, child2, parent);
3234 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3236 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
3237 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
3238 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3239 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
3240 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3242 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
3243 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3244 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
3245 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
3246 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
3247 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
3248 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
3249 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3250 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3252 if (!is_win9x) /* Win9x doesn't survive this test */
3254 ok(!SetParent(parent, child1), "SetParent should fail\n");
3255 ok(!SetParent(child2, child3), "SetParent should fail\n");
3256 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
3257 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
3258 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
3259 ok(!SetParent(child2, parent), "SetParent should fail\n");
3260 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
3262 check_parents(parent, child4, child4, 0, 0, child4, parent);
3263 check_parents(child1, parent, parent, parent, 0, child4, parent);
3264 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3265 check_parents(child3, child2, child2, child2, 0, child2, parent);
3266 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3269 hMenu = CreateMenu();
3270 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3271 100, 100, 200, 200, 0, hMenu, 0, NULL);
3272 assert(sibling != 0);
3274 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
3275 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
3277 ret = DestroyWindow(parent);
3278 ok( ret, "DestroyWindow() error %d\n", GetLastError());
3280 ok(!IsWindow(parent), "parent still exists\n");
3281 ok(!IsWindow(sibling), "sibling still exists\n");
3282 ok(!IsWindow(child1), "child1 still exists\n");
3283 ok(!IsWindow(child2), "child2 still exists\n");
3284 ok(!IsWindow(child3), "child3 still exists\n");
3285 ok(!IsWindow(child4), "child4 still exists\n");
3288 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3290 LPCREATESTRUCT lpcs;
3291 LPSTYLESTRUCT lpss;
3293 switch (msg)
3295 case WM_NCCREATE:
3296 case WM_CREATE:
3297 lpcs = (LPCREATESTRUCT)lparam;
3298 lpss = lpcs->lpCreateParams;
3299 if (lpss)
3301 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
3302 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
3303 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
3304 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
3305 else
3306 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3308 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
3309 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
3310 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
3312 ok(lpss->styleNew == lpcs->style,
3313 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3314 lpss->styleNew, lpcs->style);
3316 break;
3318 return DefWindowProc(hwnd, msg, wparam, lparam);
3321 static ATOM atomStyleCheckClass;
3323 static void register_style_check_class(void)
3325 WNDCLASS wc =
3328 StyleCheckProc,
3331 GetModuleHandle(NULL),
3332 NULL,
3333 LoadCursor(NULL, IDC_ARROW),
3334 (HBRUSH)(COLOR_BTNFACE+1),
3335 NULL,
3336 TEXT("WineStyleCheck"),
3339 atomStyleCheckClass = RegisterClass(&wc);
3342 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3344 DWORD dwActualStyle;
3345 DWORD dwActualExStyle;
3346 STYLESTRUCT ss;
3347 HWND hwnd;
3348 HWND hwndParent = NULL;
3350 ss.styleNew = dwStyleIn;
3351 ss.styleOld = dwExStyleIn;
3353 if (dwStyleIn & WS_CHILD)
3355 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
3356 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3359 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
3360 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3361 assert(hwnd);
3363 flush_events( TRUE );
3365 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3366 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3367 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3368 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3369 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3371 DestroyWindow(hwnd);
3372 if (hwndParent) DestroyWindow(hwndParent);
3375 /* tests what window styles the window manager automatically adds */
3376 static void test_window_styles(void)
3378 register_style_check_class();
3380 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3381 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3382 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3383 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3384 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3385 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3386 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3387 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3388 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3389 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3390 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3393 static void test_scrollwindow( HWND hwnd)
3395 HDC hdc;
3396 RECT rc, rc2, rc3;
3397 COLORREF colr;
3399 ShowWindow( hwnd, SW_SHOW);
3400 UpdateWindow( hwnd);
3401 flush_events( TRUE );
3402 GetClientRect( hwnd, &rc);
3403 hdc = GetDC( hwnd);
3404 /* test ScrollWindow(Ex) with no clip rectangle */
3405 /* paint the lower half of the window black */
3406 rc2 = rc;
3407 rc2.top = ( rc2.top + rc2.bottom) / 2;
3408 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3409 /* paint the upper half of the window white */
3410 rc2.bottom = rc2.top;
3411 rc2.top =0;
3412 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
3413 /* scroll lower half up */
3414 rc2 = rc;
3415 rc2.top = ( rc2.top + rc2.bottom) / 2;
3416 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, NULL, NULL, NULL, SW_ERASE);
3417 flush_events(FALSE);
3418 /* expected: black should have scrolled to the upper half */
3419 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
3420 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3421 /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
3422 /* paint the lower half of the window black */
3423 rc2 = rc;
3424 rc2.top = ( rc2.top + rc2.bottom) / 2;
3425 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3426 /* paint the upper half of the window white */
3427 rc2.bottom = rc2.top;
3428 rc2.top =0;
3429 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
3430 /* scroll lower half up */
3431 rc2 = rc;
3432 rc2.top = ( rc2.top + rc2.bottom) / 2;
3433 rc3 = rc;
3434 rc3.left = rc3.right / 4;
3435 rc3.right -= rc3.right / 4;
3436 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, &rc3, NULL, NULL, SW_ERASE);
3437 flush_events(FALSE);
3438 /* expected: black should have scrolled to the upper half */
3439 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
3440 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3442 /* clean up */
3443 ReleaseDC( hwnd, hdc);
3446 static void test_scrollvalidate( HWND parent)
3448 HDC hdc;
3449 HRGN hrgn=CreateRectRgn(0,0,0,0);
3450 HRGN exprgn, tmprgn, clipping;
3451 RECT rc, rcu, cliprc;
3452 /* create two overlapping child windows. The visual region
3453 * of hwnd1 is clipped by the overlapping part of
3454 * hwnd2 because of the WS_CLIPSIBLING style */
3455 HWND hwnd1, hwnd2;
3457 clipping = CreateRectRgn(0,0,0,0);
3458 tmprgn = CreateRectRgn(0,0,0,0);
3459 exprgn = CreateRectRgn(0,0,0,0);
3460 hwnd2 = CreateWindowExA(0, "static", NULL,
3461 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3462 75, 30, 100, 100, parent, 0, 0, NULL);
3463 hwnd1 = CreateWindowExA(0, "static", NULL,
3464 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3465 25, 50, 100, 100, parent, 0, 0, NULL);
3466 ShowWindow( parent, SW_SHOW);
3467 UpdateWindow( parent);
3468 GetClientRect( hwnd1, &rc);
3469 cliprc=rc;
3470 SetRectRgn( clipping, 10, 10, 90, 90);
3471 hdc = GetDC( hwnd1);
3472 /* for a visual touch */
3473 TextOut( hdc, 0,10, "0123456789", 10);
3474 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3475 if (winetest_debug > 0) dump_region(hrgn);
3476 /* create a region with what is expected */
3477 SetRectRgn( exprgn, 39,0,49,74);
3478 SetRectRgn( tmprgn, 88,79,98,93);
3479 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3480 SetRectRgn( tmprgn, 0,93,98,98);
3481 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3482 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3483 trace("update rect is %d,%d - %d,%d\n",
3484 rcu.left,rcu.top,rcu.right,rcu.bottom);
3485 /* now with clipping region */
3486 SelectClipRgn( hdc, clipping);
3487 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3488 if (winetest_debug > 0) dump_region(hrgn);
3489 /* create a region with what is expected */
3490 SetRectRgn( exprgn, 39,10,49,74);
3491 SetRectRgn( tmprgn, 80,79,90,85);
3492 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3493 SetRectRgn( tmprgn, 10,85,90,90);
3494 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3495 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3496 trace("update rect is %d,%d - %d,%d\n",
3497 rcu.left,rcu.top,rcu.right,rcu.bottom);
3498 ReleaseDC( hwnd1, hdc);
3500 /* test scrolling a window with an update region */
3501 DestroyWindow( hwnd2);
3502 ValidateRect( hwnd1, NULL);
3503 SetRect( &rc, 40,40, 50,50);
3504 InvalidateRect( hwnd1, &rc, 1);
3505 GetClientRect( hwnd1, &rc);
3506 cliprc=rc;
3507 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
3508 SW_SCROLLCHILDREN | SW_INVALIDATE);
3509 if (winetest_debug > 0) dump_region(hrgn);
3510 SetRectRgn( exprgn, 88,0,98,98);
3511 SetRectRgn( tmprgn, 30, 40, 50, 50);
3512 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3513 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3515 /* clear an update region */
3516 UpdateWindow( hwnd1 );
3518 SetRect( &rc, 0,40, 100,60);
3519 SetRect( &cliprc, 0,0, 100,100);
3520 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3521 if (winetest_debug > 0) dump_region( hrgn );
3522 SetRectRgn( exprgn, 0, 40, 98, 60 );
3523 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
3525 /* now test ScrollWindowEx with a combination of
3526 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3527 /* make hwnd2 the child of hwnd1 */
3528 hwnd2 = CreateWindowExA(0, "static", NULL,
3529 WS_CHILD| WS_VISIBLE | WS_BORDER ,
3530 50, 50, 100, 100, hwnd1, 0, 0, NULL);
3531 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
3532 GetClientRect( hwnd1, &rc);
3533 cliprc=rc;
3535 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3536 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3537 ValidateRect( hwnd1, NULL);
3538 ValidateRect( hwnd2, NULL);
3539 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
3540 SW_SCROLLCHILDREN | SW_INVALIDATE);
3541 if (winetest_debug > 0) dump_region(hrgn);
3542 SetRectRgn( exprgn, 88,0,98,88);
3543 SetRectRgn( tmprgn, 0,88,98,98);
3544 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3545 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3547 /* SW_SCROLLCHILDREN */
3548 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3549 ValidateRect( hwnd1, NULL);
3550 ValidateRect( hwnd2, NULL);
3551 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3552 if (winetest_debug > 0) dump_region(hrgn);
3553 /* expected region is the same as in previous test */
3554 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3556 /* no SW_SCROLLCHILDREN */
3557 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3558 ValidateRect( hwnd1, NULL);
3559 ValidateRect( hwnd2, NULL);
3560 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3561 if (winetest_debug > 0) dump_region(hrgn);
3562 /* expected region is the same as in previous test */
3563 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3565 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3566 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3567 ValidateRect( hwnd1, NULL);
3568 ValidateRect( hwnd2, NULL);
3569 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3570 if (winetest_debug > 0) dump_region(hrgn);
3571 SetRectRgn( exprgn, 88,0,98,20);
3572 SetRectRgn( tmprgn, 20,20,98,30);
3573 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3574 SetRectRgn( tmprgn, 20,30,30,88);
3575 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3576 SetRectRgn( tmprgn, 0,88,30,98);
3577 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3578 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3580 /* clean up */
3581 DeleteObject( hrgn);
3582 DeleteObject( exprgn);
3583 DeleteObject( tmprgn);
3584 DestroyWindow( hwnd1);
3585 DestroyWindow( hwnd2);
3588 /* couple of tests of return values of scrollbar functions
3589 * called on a scrollbarless window */
3590 static void test_scroll(void)
3592 BOOL ret;
3593 INT min, max;
3594 SCROLLINFO si;
3595 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3596 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3597 100, 100, 200, 200, 0, 0, 0, NULL);
3598 /* horizontal */
3599 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3600 if (!ret) /* win9x */
3602 win_skip( "GetScrollRange doesn't work\n" );
3603 DestroyWindow( hwnd);
3604 return;
3606 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3607 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3608 si.cbSize = sizeof( si);
3609 si.fMask = SIF_PAGE;
3610 si.nPage = 0xdeadbeef;
3611 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3612 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3613 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3614 /* vertical */
3615 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3616 ok( ret, "GetScrollRange returns FALSE\n");
3617 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3618 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3619 si.cbSize = sizeof( si);
3620 si.fMask = SIF_PAGE;
3621 si.nPage = 0xdeadbeef;
3622 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3623 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3624 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3625 /* clean up */
3626 DestroyWindow( hwnd);
3629 static void test_scrolldc( HWND parent)
3631 HDC hdc;
3632 HRGN exprgn, tmprgn, hrgn;
3633 RECT rc, rc2, rcu, cliprc;
3634 HWND hwnd1;
3635 COLORREF colr;
3637 hrgn = CreateRectRgn(0,0,0,0);
3638 tmprgn = CreateRectRgn(0,0,0,0);
3639 exprgn = CreateRectRgn(0,0,0,0);
3641 hwnd1 = CreateWindowExA(0, "static", NULL,
3642 WS_CHILD| WS_VISIBLE,
3643 25, 50, 100, 100, parent, 0, 0, NULL);
3644 ShowWindow( parent, SW_SHOW);
3645 UpdateWindow( parent);
3646 flush_events( TRUE );
3647 GetClientRect( hwnd1, &rc);
3648 hdc = GetDC( hwnd1);
3649 /* paint the upper half of the window black */
3650 rc2 = rc;
3651 rc2.bottom = ( rc.top + rc.bottom) /2;
3652 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3653 /* clip region is the lower half */
3654 cliprc=rc;
3655 cliprc.top = (rc.top + rc.bottom) /2;
3656 /* test whether scrolled pixels are properly clipped */
3657 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3658 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3659 /* this scroll should not cause any visible changes */
3660 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3661 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3662 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3663 /* test with NULL clip rect */
3664 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3665 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3666 trace("update rect: %d,%d - %d,%d\n",
3667 rcu.left, rcu.top, rcu.right, rcu.bottom);
3668 if (winetest_debug > 0) dump_region(hrgn);
3669 SetRect(&rc2, 0, 0, 100, 100);
3670 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3671 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3673 SetRectRgn( exprgn, 0, 0, 20, 80);
3674 SetRectRgn( tmprgn, 0, 80, 100, 100);
3675 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3676 if (winetest_debug > 0) dump_region(exprgn);
3677 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3678 /* test clip rect > scroll rect */
3679 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3680 rc2=rc;
3681 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3682 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3683 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3684 SetRectRgn( exprgn, 25, 25, 75, 35);
3685 SetRectRgn( tmprgn, 25, 35, 35, 75);
3686 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3687 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3688 trace("update rect: %d,%d - %d,%d\n",
3689 rcu.left, rcu.top, rcu.right, rcu.bottom);
3690 if (winetest_debug > 0) dump_region(hrgn);
3692 /* clean up */
3693 DeleteObject(hrgn);
3694 DeleteObject(exprgn);
3695 DeleteObject(tmprgn);
3696 DestroyWindow(hwnd1);
3699 static void test_params(void)
3701 HWND hwnd;
3702 INT rc;
3704 /* Just a param check */
3705 if (pGetMonitorInfoA)
3707 SetLastError(0xdeadbeef);
3708 rc = GetWindowText(hwndMain2, NULL, 1024);
3709 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
3711 else
3713 /* Skips actually on Win95 and NT4 */
3714 win_skip("Test would crash on Win95\n");
3717 SetLastError(0xdeadbeef);
3718 hwnd=CreateWindow("LISTBOX", "TestList",
3719 (LBS_STANDARD & ~LBS_SORT),
3720 0, 0, 100, 100,
3721 NULL, (HMENU)1, NULL, 0);
3723 ok(!hwnd || broken(hwnd != NULL), /* w2k3 sp2 */
3724 "CreateWindow with invalid menu handle should fail\n");
3725 if (!hwnd)
3726 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3727 GetLastError() == 0xdeadbeef, /* Win9x */
3728 "wrong last error value %d\n", GetLastError());
3731 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3733 HWND hwnd = 0;
3735 hwnd = CreateWindowEx(exStyle, class, class, style,
3736 110, 100,
3737 225, 200,
3739 menu ? hmenu : 0,
3740 0, 0);
3741 if (!hwnd) {
3742 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
3743 return;
3745 ShowWindow(hwnd, SW_SHOW);
3747 test_nonclient_area(hwnd);
3749 SetMenu(hwnd, 0);
3750 DestroyWindow(hwnd);
3753 static BOOL AWR_init(void)
3755 WNDCLASS class;
3757 class.style = CS_HREDRAW | CS_VREDRAW;
3758 class.lpfnWndProc = DefWindowProcA;
3759 class.cbClsExtra = 0;
3760 class.cbWndExtra = 0;
3761 class.hInstance = 0;
3762 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3763 class.hCursor = LoadCursor (0, IDC_ARROW);
3764 class.hbrBackground = 0;
3765 class.lpszMenuName = 0;
3766 class.lpszClassName = szAWRClass;
3768 if (!RegisterClass (&class)) {
3769 ok(FALSE, "RegisterClass failed\n");
3770 return FALSE;
3773 hmenu = CreateMenu();
3774 if (!hmenu)
3775 return FALSE;
3776 ok(hmenu != 0, "Failed to create menu\n");
3777 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3779 return TRUE;
3783 static void test_AWR_window_size(BOOL menu)
3785 LONG styles[] = {
3786 WS_POPUP,
3787 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3788 WS_SYSMENU,
3789 WS_THICKFRAME,
3790 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3791 WS_HSCROLL, WS_VSCROLL
3793 LONG exStyles[] = {
3794 WS_EX_CLIENTEDGE,
3795 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3796 WS_EX_APPWINDOW,
3797 #if 0
3798 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3799 WS_EX_DLGMODALFRAME,
3800 WS_EX_STATICEDGE,
3801 #endif
3804 int i;
3806 /* A exhaustive check of all the styles takes too long
3807 * so just do a (hopefully representative) sample
3809 for (i = 0; i < COUNTOF(styles); ++i)
3810 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3811 for (i = 0; i < COUNTOF(exStyles); ++i) {
3812 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3813 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3816 #undef COUNTOF
3818 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3820 static void test_AdjustWindowRect(void)
3822 if (!AWR_init())
3823 return;
3825 SHOWSYSMETRIC(SM_CYCAPTION);
3826 SHOWSYSMETRIC(SM_CYSMCAPTION);
3827 SHOWSYSMETRIC(SM_CYMENU);
3828 SHOWSYSMETRIC(SM_CXEDGE);
3829 SHOWSYSMETRIC(SM_CYEDGE);
3830 SHOWSYSMETRIC(SM_CXVSCROLL);
3831 SHOWSYSMETRIC(SM_CYHSCROLL);
3832 SHOWSYSMETRIC(SM_CXFRAME);
3833 SHOWSYSMETRIC(SM_CYFRAME);
3834 SHOWSYSMETRIC(SM_CXDLGFRAME);
3835 SHOWSYSMETRIC(SM_CYDLGFRAME);
3836 SHOWSYSMETRIC(SM_CXBORDER);
3837 SHOWSYSMETRIC(SM_CYBORDER);
3839 test_AWR_window_size(FALSE);
3840 test_AWR_window_size(TRUE);
3842 DestroyMenu(hmenu);
3844 #undef SHOWSYSMETRIC
3847 /* Global variables to trigger exit from loop */
3848 static int redrawComplete, WMPAINT_count;
3850 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3852 switch (msg)
3854 case WM_PAINT:
3855 trace("doing WM_PAINT %d\n", WMPAINT_count);
3856 WMPAINT_count++;
3857 if (WMPAINT_count > 10 && redrawComplete == 0) {
3858 PAINTSTRUCT ps;
3859 BeginPaint(hwnd, &ps);
3860 EndPaint(hwnd, &ps);
3861 return 1;
3863 return 0;
3865 return DefWindowProc(hwnd, msg, wparam, lparam);
3868 /* Ensure we exit from RedrawNow regardless of invalidated area */
3869 static void test_redrawnow(void)
3871 WNDCLASSA cls;
3872 HWND hwndMain;
3874 cls.style = CS_DBLCLKS;
3875 cls.lpfnWndProc = redraw_window_procA;
3876 cls.cbClsExtra = 0;
3877 cls.cbWndExtra = 0;
3878 cls.hInstance = GetModuleHandleA(0);
3879 cls.hIcon = 0;
3880 cls.hCursor = LoadCursorA(0, IDC_ARROW);
3881 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3882 cls.lpszMenuName = NULL;
3883 cls.lpszClassName = "RedrawWindowClass";
3885 if(!RegisterClassA(&cls)) {
3886 trace("Register failed %d\n", GetLastError());
3887 return;
3890 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3891 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3893 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3894 ShowWindow(hwndMain, SW_SHOW);
3895 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3896 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3897 ok( WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
3898 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3899 redrawComplete = TRUE;
3900 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3902 /* clean up */
3903 DestroyWindow( hwndMain);
3906 struct parentdc_stat {
3907 RECT client;
3908 RECT clip;
3909 RECT paint;
3912 struct parentdc_test {
3913 struct parentdc_stat main, main_todo;
3914 struct parentdc_stat child1, child1_todo;
3915 struct parentdc_stat child2, child2_todo;
3918 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3920 RECT rc;
3921 PAINTSTRUCT ps;
3923 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3925 switch (msg)
3927 case WM_PAINT:
3928 GetClientRect(hwnd, &rc);
3929 CopyRect(&t->client, &rc);
3930 GetWindowRect(hwnd, &rc);
3931 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd,
3932 t->client.left, t->client.top, t->client.right, t->client.bottom,
3933 rc.left, rc.top, rc.right, rc.bottom);
3934 BeginPaint(hwnd, &ps);
3935 CopyRect(&t->paint, &ps.rcPaint);
3936 GetClipBox(ps.hdc, &rc);
3937 CopyRect(&t->clip, &rc);
3938 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
3939 rc.left, rc.top, rc.right, rc.bottom,
3940 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3941 EndPaint(hwnd, &ps);
3942 return 0;
3944 return DefWindowProc(hwnd, msg, wparam, lparam);
3947 static void zero_parentdc_stat(struct parentdc_stat *t)
3949 SetRectEmpty(&t->client);
3950 SetRectEmpty(&t->clip);
3951 SetRectEmpty(&t->paint);
3954 static void zero_parentdc_test(struct parentdc_test *t)
3956 zero_parentdc_stat(&t->main);
3957 zero_parentdc_stat(&t->child1);
3958 zero_parentdc_stat(&t->child2);
3961 #define parentdc_field_ok(t, w, r, f, got) \
3962 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3963 ": expected %d, got %d\n", \
3964 t.w.r.f, got.w.r.f)
3966 #define parentdc_todo_field_ok(t, w, r, f, got) \
3967 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3968 else parentdc_field_ok(t, w, r, f, got)
3970 #define parentdc_rect_ok(t, w, r, got) \
3971 parentdc_todo_field_ok(t, w, r, left, got); \
3972 parentdc_todo_field_ok(t, w, r, top, got); \
3973 parentdc_todo_field_ok(t, w, r, right, got); \
3974 parentdc_todo_field_ok(t, w, r, bottom, got);
3976 #define parentdc_win_ok(t, w, got) \
3977 parentdc_rect_ok(t, w, client, got); \
3978 parentdc_rect_ok(t, w, clip, got); \
3979 parentdc_rect_ok(t, w, paint, got);
3981 #define parentdc_ok(t, got) \
3982 parentdc_win_ok(t, main, got); \
3983 parentdc_win_ok(t, child1, got); \
3984 parentdc_win_ok(t, child2, got);
3986 static void test_csparentdc(void)
3988 WNDCLASSA clsMain, cls;
3989 HWND hwndMain, hwnd1, hwnd2;
3990 RECT rc;
3992 struct parentdc_test test_answer;
3994 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3995 const struct parentdc_test test1 =
3997 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
3998 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3999 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4002 const struct parentdc_test test2 =
4004 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
4005 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4006 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4009 const struct parentdc_test test3 =
4011 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4012 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4013 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4016 const struct parentdc_test test4 =
4018 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
4019 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
4020 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4023 const struct parentdc_test test5 =
4025 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
4026 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4027 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4030 const struct parentdc_test test6 =
4032 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4033 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4034 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4037 const struct parentdc_test test7 =
4039 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4040 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4041 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4043 #undef nothing_todo
4045 clsMain.style = CS_DBLCLKS;
4046 clsMain.lpfnWndProc = parentdc_window_procA;
4047 clsMain.cbClsExtra = 0;
4048 clsMain.cbWndExtra = 0;
4049 clsMain.hInstance = GetModuleHandleA(0);
4050 clsMain.hIcon = 0;
4051 clsMain.hCursor = LoadCursorA(0, IDC_ARROW);
4052 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
4053 clsMain.lpszMenuName = NULL;
4054 clsMain.lpszClassName = "ParentDcMainWindowClass";
4056 if(!RegisterClassA(&clsMain)) {
4057 trace("Register failed %d\n", GetLastError());
4058 return;
4061 cls.style = CS_DBLCLKS | CS_PARENTDC;
4062 cls.lpfnWndProc = parentdc_window_procA;
4063 cls.cbClsExtra = 0;
4064 cls.cbWndExtra = 0;
4065 cls.hInstance = GetModuleHandleA(0);
4066 cls.hIcon = 0;
4067 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4068 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4069 cls.lpszMenuName = NULL;
4070 cls.lpszClassName = "ParentDcWindowClass";
4072 if(!RegisterClassA(&cls)) {
4073 trace("Register failed %d\n", GetLastError());
4074 return;
4077 SetRect(&rc, 0, 0, 150, 150);
4078 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
4079 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
4080 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
4081 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
4082 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
4083 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
4084 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
4085 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
4086 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
4087 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
4088 ShowWindow(hwndMain, SW_SHOW);
4089 ShowWindow(hwnd1, SW_SHOW);
4090 ShowWindow(hwnd2, SW_SHOW);
4091 SetWindowPos(hwndMain, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
4092 flush_events( TRUE );
4094 zero_parentdc_test(&test_answer);
4095 InvalidateRect(hwndMain, NULL, TRUE);
4096 flush_events( TRUE );
4097 parentdc_ok(test1, test_answer);
4099 zero_parentdc_test(&test_answer);
4100 SetRect(&rc, 0, 0, 50, 50);
4101 InvalidateRect(hwndMain, &rc, TRUE);
4102 flush_events( TRUE );
4103 parentdc_ok(test2, test_answer);
4105 zero_parentdc_test(&test_answer);
4106 SetRect(&rc, 0, 0, 10, 10);
4107 InvalidateRect(hwndMain, &rc, TRUE);
4108 flush_events( TRUE );
4109 parentdc_ok(test3, test_answer);
4111 zero_parentdc_test(&test_answer);
4112 SetRect(&rc, 40, 40, 50, 50);
4113 InvalidateRect(hwndMain, &rc, TRUE);
4114 flush_events( TRUE );
4115 parentdc_ok(test4, test_answer);
4117 zero_parentdc_test(&test_answer);
4118 SetRect(&rc, 20, 20, 60, 60);
4119 InvalidateRect(hwndMain, &rc, TRUE);
4120 flush_events( TRUE );
4121 parentdc_ok(test5, test_answer);
4123 zero_parentdc_test(&test_answer);
4124 SetRect(&rc, 0, 0, 10, 10);
4125 InvalidateRect(hwnd1, &rc, TRUE);
4126 flush_events( TRUE );
4127 parentdc_ok(test6, test_answer);
4129 zero_parentdc_test(&test_answer);
4130 SetRect(&rc, -5, -5, 65, 65);
4131 InvalidateRect(hwnd1, &rc, TRUE);
4132 flush_events( TRUE );
4133 parentdc_ok(test7, test_answer);
4135 DestroyWindow(hwndMain);
4136 DestroyWindow(hwnd1);
4137 DestroyWindow(hwnd2);
4140 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4142 return DefWindowProcA(hwnd, msg, wparam, lparam);
4145 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4147 return DefWindowProcW(hwnd, msg, wparam, lparam);
4150 static void test_IsWindowUnicode(void)
4152 static const char ansi_class_nameA[] = "ansi class name";
4153 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
4154 static const char unicode_class_nameA[] = "unicode class name";
4155 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
4156 WNDCLASSA classA;
4157 WNDCLASSW classW;
4158 HWND hwnd;
4160 memset(&classW, 0, sizeof(classW));
4161 classW.hInstance = GetModuleHandleA(0);
4162 classW.lpfnWndProc = def_window_procW;
4163 classW.lpszClassName = unicode_class_nameW;
4164 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
4166 memset(&classA, 0, sizeof(classA));
4167 classA.hInstance = GetModuleHandleA(0);
4168 classA.lpfnWndProc = def_window_procA;
4169 classA.lpszClassName = ansi_class_nameA;
4170 assert(RegisterClassA(&classA));
4172 /* unicode class: window proc */
4173 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4174 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4175 assert(hwnd);
4177 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4178 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4179 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4180 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4181 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4183 DestroyWindow(hwnd);
4185 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4186 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4187 assert(hwnd);
4189 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4190 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4191 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4192 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4193 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4195 DestroyWindow(hwnd);
4197 /* ansi class: window proc */
4198 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4199 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4200 assert(hwnd);
4202 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4203 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4204 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4205 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4206 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4208 DestroyWindow(hwnd);
4210 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4211 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4212 assert(hwnd);
4214 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4215 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4216 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4217 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4218 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4220 DestroyWindow(hwnd);
4222 /* unicode class: class proc */
4223 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4224 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4225 assert(hwnd);
4227 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4228 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4229 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4230 /* do not restore class window proc back to unicode */
4232 DestroyWindow(hwnd);
4234 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4235 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4236 assert(hwnd);
4238 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4239 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4240 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4242 DestroyWindow(hwnd);
4244 /* ansi class: class proc */
4245 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4246 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4247 assert(hwnd);
4249 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4250 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4251 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4252 /* do not restore class window proc back to ansi */
4254 DestroyWindow(hwnd);
4256 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4257 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4258 assert(hwnd);
4260 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4261 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4262 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4264 DestroyWindow(hwnd);
4267 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4269 MINMAXINFO *minmax;
4271 if (msg != WM_GETMINMAXINFO)
4272 return DefWindowProc(hwnd, msg, wp, lp);
4274 minmax = (MINMAXINFO *)lp;
4276 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
4278 minmax->ptReserved.x = 0;
4279 minmax->ptReserved.y = 0;
4280 minmax->ptMaxSize.x = 400;
4281 minmax->ptMaxSize.y = 400;
4282 minmax->ptMaxPosition.x = 300;
4283 minmax->ptMaxPosition.y = 300;
4284 minmax->ptMaxTrackSize.x = 200;
4285 minmax->ptMaxTrackSize.y = 200;
4286 minmax->ptMinTrackSize.x = 100;
4287 minmax->ptMinTrackSize.y = 100;
4289 else
4290 DefWindowProc(hwnd, msg, wp, lp);
4291 return 1;
4294 static int expected_cx, expected_cy;
4295 static RECT expected_rect, broken_rect;
4297 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4299 switch(msg)
4301 case WM_GETMINMAXINFO:
4303 RECT rect;
4304 GetWindowRect( hwnd, &rect );
4305 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
4306 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4307 return DefWindowProc(hwnd, msg, wp, lp);
4309 case WM_NCCREATE:
4310 case WM_CREATE:
4312 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
4313 RECT rect;
4314 GetWindowRect( hwnd, &rect );
4315 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
4316 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
4317 ok( cs->cx == expected_cx || broken(cs->cx == (short)expected_cx),
4318 "wrong x size %d/%d\n", cs->cx, expected_cx );
4319 ok( cs->cy == expected_cy || broken(cs->cy == (short)expected_cy),
4320 "wrong y size %d/%d\n", cs->cy, expected_cy );
4321 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
4322 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
4323 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
4324 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top) ||
4325 broken( rect.right - rect.left == (short)broken_rect.right - (short)broken_rect.left &&
4326 rect.bottom - rect.top == (short)broken_rect.bottom - (short)broken_rect.top),
4327 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
4328 rect.left, rect.top, rect.right, rect.bottom,
4329 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
4330 return DefWindowProc(hwnd, msg, wp, lp);
4332 case WM_NCCALCSIZE:
4334 RECT rect, *r = (RECT *)lp;
4335 GetWindowRect( hwnd, &rect );
4336 ok( !memcmp( &rect, r, sizeof(rect) ),
4337 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
4338 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
4339 return DefWindowProc(hwnd, msg, wp, lp);
4341 default:
4342 return DefWindowProc(hwnd, msg, wp, lp);
4346 static void test_CreateWindow(void)
4348 WNDCLASS cls;
4349 HWND hwnd, parent;
4350 HMENU hmenu;
4351 RECT rc, rc_minmax;
4352 MINMAXINFO minmax;
4354 #define expect_menu(window, menu) \
4355 SetLastError(0xdeadbeef); \
4356 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
4358 #define expect_style(window, style)\
4359 ok((ULONG)GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
4361 #define expect_ex_style(window, ex_style)\
4362 ok((ULONG)GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
4364 #define expect_gle_broken_9x(gle)\
4365 ok(GetLastError() == gle ||\
4366 broken(GetLastError() == 0xdeadbeef),\
4367 "IsMenu set error %d\n", GetLastError())
4369 hmenu = CreateMenu();
4370 assert(hmenu != 0);
4371 parent = GetDesktopWindow();
4372 assert(parent != 0);
4374 SetLastError(0xdeadbeef);
4375 ok(IsMenu(hmenu), "IsMenu error %d\n", GetLastError());
4377 /* WS_CHILD */
4378 SetLastError(0xdeadbeef);
4379 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
4380 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4381 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4382 expect_menu(hwnd, 1);
4383 expect_style(hwnd, WS_CHILD);
4384 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4385 DestroyWindow(hwnd);
4387 SetLastError(0xdeadbeef);
4388 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
4389 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4390 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4391 expect_menu(hwnd, 1);
4392 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4393 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4394 DestroyWindow(hwnd);
4396 SetLastError(0xdeadbeef);
4397 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
4398 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4399 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4400 expect_menu(hwnd, 1);
4401 expect_style(hwnd, WS_CHILD);
4402 expect_ex_style(hwnd, 0);
4403 DestroyWindow(hwnd);
4405 SetLastError(0xdeadbeef);
4406 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
4407 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4408 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4409 expect_menu(hwnd, 1);
4410 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4411 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4412 DestroyWindow(hwnd);
4414 /* WS_POPUP */
4415 SetLastError(0xdeadbeef);
4416 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4417 0, 0, 100, 100, parent, hmenu, 0, NULL);
4418 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4419 expect_menu(hwnd, hmenu);
4420 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4421 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4422 DestroyWindow(hwnd);
4423 SetLastError(0xdeadbeef);
4424 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4425 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4427 hmenu = CreateMenu();
4428 assert(hmenu != 0);
4429 SetLastError(0xdeadbeef);
4430 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
4431 0, 0, 100, 100, parent, hmenu, 0, NULL);
4432 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4433 expect_menu(hwnd, hmenu);
4434 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4435 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4436 DestroyWindow(hwnd);
4437 SetLastError(0xdeadbeef);
4438 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4439 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4441 hmenu = CreateMenu();
4442 assert(hmenu != 0);
4443 SetLastError(0xdeadbeef);
4444 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
4445 0, 0, 100, 100, parent, hmenu, 0, NULL);
4446 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4447 expect_menu(hwnd, hmenu);
4448 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4449 expect_ex_style(hwnd, 0);
4450 DestroyWindow(hwnd);
4451 SetLastError(0xdeadbeef);
4452 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4453 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4455 hmenu = CreateMenu();
4456 assert(hmenu != 0);
4457 SetLastError(0xdeadbeef);
4458 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
4459 0, 0, 100, 100, parent, hmenu, 0, NULL);
4460 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4461 expect_menu(hwnd, hmenu);
4462 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4463 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4464 DestroyWindow(hwnd);
4465 SetLastError(0xdeadbeef);
4466 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4467 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4469 /* WS_CHILD | WS_POPUP */
4470 SetLastError(0xdeadbeef);
4471 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4472 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4473 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4474 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4475 if (hwnd)
4476 DestroyWindow(hwnd);
4478 hmenu = CreateMenu();
4479 assert(hmenu != 0);
4480 SetLastError(0xdeadbeef);
4481 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4482 0, 0, 100, 100, parent, hmenu, 0, NULL);
4483 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4484 expect_menu(hwnd, hmenu);
4485 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4486 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4487 DestroyWindow(hwnd);
4488 SetLastError(0xdeadbeef);
4489 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4490 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4492 SetLastError(0xdeadbeef);
4493 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4494 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4495 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4496 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4497 if (hwnd)
4498 DestroyWindow(hwnd);
4500 hmenu = CreateMenu();
4501 assert(hmenu != 0);
4502 SetLastError(0xdeadbeef);
4503 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4504 0, 0, 100, 100, parent, hmenu, 0, NULL);
4505 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4506 expect_menu(hwnd, hmenu);
4507 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4508 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4509 DestroyWindow(hwnd);
4510 SetLastError(0xdeadbeef);
4511 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4512 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4514 SetLastError(0xdeadbeef);
4515 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4516 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4517 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4518 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4519 if (hwnd)
4520 DestroyWindow(hwnd);
4522 hmenu = CreateMenu();
4523 assert(hmenu != 0);
4524 SetLastError(0xdeadbeef);
4525 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4526 0, 0, 100, 100, parent, hmenu, 0, NULL);
4527 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4528 expect_menu(hwnd, hmenu);
4529 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4530 expect_ex_style(hwnd, 0);
4531 DestroyWindow(hwnd);
4532 SetLastError(0xdeadbeef);
4533 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4534 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4536 SetLastError(0xdeadbeef);
4537 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4538 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4539 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4540 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4541 if (hwnd)
4542 DestroyWindow(hwnd);
4544 hmenu = CreateMenu();
4545 assert(hmenu != 0);
4546 SetLastError(0xdeadbeef);
4547 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4548 0, 0, 100, 100, parent, hmenu, 0, NULL);
4549 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4550 expect_menu(hwnd, hmenu);
4551 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4552 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4553 DestroyWindow(hwnd);
4554 SetLastError(0xdeadbeef);
4555 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4556 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4558 /* test child window sizing */
4559 cls.style = 0;
4560 cls.lpfnWndProc = minmax_wnd_proc;
4561 cls.cbClsExtra = 0;
4562 cls.cbWndExtra = 0;
4563 cls.hInstance = GetModuleHandle(0);
4564 cls.hIcon = 0;
4565 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4566 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4567 cls.lpszMenuName = NULL;
4568 cls.lpszClassName = "MinMax_WndClass";
4569 RegisterClass(&cls);
4571 SetLastError(0xdeadbeef);
4572 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4573 0, 0, 100, 100, 0, 0, 0, NULL);
4574 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4575 expect_menu(parent, 0);
4576 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
4577 expect_ex_style(parent, WS_EX_WINDOWEDGE);
4579 memset(&minmax, 0, sizeof(minmax));
4580 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4581 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
4582 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
4583 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4584 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
4586 GetWindowRect(parent, &rc);
4587 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
4588 GetClientRect(parent, &rc);
4589 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
4591 InflateRect(&rc, 200, 200);
4592 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4594 SetLastError(0xdeadbeef);
4595 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4596 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
4597 parent, (HMENU)1, 0, NULL);
4598 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4599 expect_menu(hwnd, 1);
4600 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
4601 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4603 memset(&minmax, 0, sizeof(minmax));
4604 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4605 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4607 GetWindowRect(hwnd, &rc);
4608 OffsetRect(&rc, -rc.left, -rc.top);
4609 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4610 rc.left, rc.top, rc.right, rc.bottom,
4611 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
4612 DestroyWindow(hwnd);
4614 cls.lpfnWndProc = winsizes_wnd_proc;
4615 cls.lpszClassName = "Sizes_WndClass";
4616 RegisterClass(&cls);
4618 expected_cx = expected_cy = 200000;
4619 SetRect( &expected_rect, 0, 0, 200000, 200000 );
4620 broken_rect = expected_rect;
4621 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
4622 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4623 GetClientRect( hwnd, &rc );
4624 ok( rc.right == 200000 || broken(rc.right == (short)200000), "invalid rect right %u\n", rc.right );
4625 ok( rc.bottom == 200000 || broken(rc.bottom == (short)200000), "invalid rect bottom %u\n", rc.bottom );
4626 DestroyWindow(hwnd);
4628 expected_cx = expected_cy = -10;
4629 SetRect( &expected_rect, 0, 0, 0, 0 );
4630 SetRect( &broken_rect, 0, 0, -10, -10 );
4631 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
4632 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4633 GetClientRect( hwnd, &rc );
4634 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4635 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4636 DestroyWindow(hwnd);
4638 expected_cx = expected_cy = -200000;
4639 SetRect( &expected_rect, 0, 0, 0, 0 );
4640 SetRect( &broken_rect, 0, 0, -200000, -200000 );
4641 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
4642 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4643 GetClientRect( hwnd, &rc );
4644 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4645 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4646 DestroyWindow(hwnd);
4648 /* we need a parent at 0,0 so that child coordinates match */
4649 DestroyWindow(parent);
4650 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
4651 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4653 expected_cx = 100;
4654 expected_cy = 0x7fffffff;
4655 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
4656 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
4657 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
4658 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4659 GetClientRect( hwnd, &rc );
4660 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
4661 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4662 DestroyWindow(hwnd);
4664 expected_cx = 0x7fffffff;
4665 expected_cy = 0x7fffffff;
4666 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
4667 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
4668 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
4669 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4670 GetClientRect( hwnd, &rc );
4671 ok( rc.right == 0x7fffffff - 20 || broken(rc.right == 0), "invalid rect right %u\n", rc.right );
4672 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4673 DestroyWindow(hwnd);
4675 /* top level window */
4676 expected_cx = expected_cy = 200000;
4677 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
4678 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
4679 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4680 GetClientRect( hwnd, &rc );
4681 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
4682 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
4683 DestroyWindow(hwnd);
4685 DestroyWindow(parent);
4687 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4688 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4690 #undef expect_gle_broken_9x
4691 #undef expect_menu
4692 #undef expect_style
4693 #undef expect_ex_style
4696 /* function that remembers whether the system the test is running on sets the
4697 * last error for user32 functions to make the tests stricter */
4698 static int check_error(DWORD actual, DWORD expected)
4700 static int sets_last_error = -1;
4701 if (sets_last_error == -1)
4702 sets_last_error = (actual != 0xdeadbeef);
4703 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
4706 static void test_SetWindowLong(void)
4708 LONG_PTR retval;
4709 WNDPROC old_window_procW;
4711 SetLastError(0xdeadbeef);
4712 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
4713 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
4714 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
4715 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4717 SetLastError(0xdeadbeef);
4718 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
4719 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
4720 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
4721 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4723 SetLastError(0xdeadbeef);
4724 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4725 ok((WNDPROC)retval == main_window_procA || broken(!retval), /* win9x */
4726 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
4727 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4728 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
4729 ok((WNDPROC)retval == main_window_procA,
4730 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4731 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
4733 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
4734 SetLastError(0xdeadbeef);
4735 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
4736 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
4738 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4739 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
4740 ok((WNDPROC)retval == old_window_procW,
4741 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4742 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
4744 /* set it back to ANSI */
4745 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4749 static void test_ShowWindow(void)
4751 HWND hwnd;
4752 DWORD style;
4753 RECT rcMain, rc;
4754 LPARAM ret;
4756 SetRect(&rcMain, 120, 120, 210, 210);
4758 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
4759 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4760 WS_MAXIMIZEBOX | WS_POPUP,
4761 rcMain.left, rcMain.top,
4762 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
4763 0, 0, 0, NULL);
4764 assert(hwnd);
4766 style = GetWindowLong(hwnd, GWL_STYLE);
4767 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4768 ok(!(style & WS_VISIBLE), "window should not be visible\n");
4769 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4770 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4771 GetWindowRect(hwnd, &rc);
4772 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4773 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4774 rc.left, rc.top, rc.right, rc.bottom);
4776 ret = ShowWindow(hwnd, SW_SHOW);
4777 ok(!ret, "not expected ret: %lu\n", ret);
4778 style = GetWindowLong(hwnd, GWL_STYLE);
4779 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4780 ok(style & WS_VISIBLE, "window should be visible\n");
4781 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4782 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4783 GetWindowRect(hwnd, &rc);
4784 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4785 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4786 rc.left, rc.top, rc.right, rc.bottom);
4788 ret = ShowWindow(hwnd, SW_MINIMIZE);
4789 ok(ret, "not expected ret: %lu\n", ret);
4790 style = GetWindowLong(hwnd, GWL_STYLE);
4791 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4792 ok(style & WS_VISIBLE, "window should be visible\n");
4793 ok(style & WS_MINIMIZE, "window should be minimized\n");
4794 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4795 GetWindowRect(hwnd, &rc);
4796 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4798 ShowWindow(hwnd, SW_RESTORE);
4799 ok(ret, "not expected ret: %lu\n", ret);
4800 style = GetWindowLong(hwnd, GWL_STYLE);
4801 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4802 ok(style & WS_VISIBLE, "window should be visible\n");
4803 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4804 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4805 GetWindowRect(hwnd, &rc);
4806 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4807 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4808 rc.left, rc.top, rc.right, rc.bottom);
4810 ret = EnableWindow(hwnd, FALSE);
4811 ok(!ret, "not expected ret: %lu\n", ret);
4812 style = GetWindowLong(hwnd, GWL_STYLE);
4813 ok(style & WS_DISABLED, "window should be disabled\n");
4815 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
4816 ok(!ret, "not expected ret: %lu\n", ret);
4817 style = GetWindowLong(hwnd, GWL_STYLE);
4818 ok(style & WS_DISABLED, "window should be disabled\n");
4819 ok(style & WS_VISIBLE, "window should be visible\n");
4820 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4821 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4822 GetWindowRect(hwnd, &rc);
4823 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4824 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4825 rc.left, rc.top, rc.right, rc.bottom);
4827 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
4828 ok(!ret, "not expected ret: %lu\n", ret);
4829 style = GetWindowLong(hwnd, GWL_STYLE);
4830 ok(style & WS_DISABLED, "window should be disabled\n");
4831 ok(style & WS_VISIBLE, "window should be visible\n");
4832 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4833 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4834 GetWindowRect(hwnd, &rc);
4835 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4836 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4837 rc.left, rc.top, rc.right, rc.bottom);
4839 ret = ShowWindow(hwnd, SW_MINIMIZE);
4840 ok(ret, "not expected ret: %lu\n", ret);
4841 style = GetWindowLong(hwnd, GWL_STYLE);
4842 ok(style & WS_DISABLED, "window should be disabled\n");
4843 ok(style & WS_VISIBLE, "window should be visible\n");
4844 ok(style & WS_MINIMIZE, "window should be minimized\n");
4845 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4846 GetWindowRect(hwnd, &rc);
4847 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4849 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
4850 ok(!ret, "not expected ret: %lu\n", ret);
4851 style = GetWindowLong(hwnd, GWL_STYLE);
4852 ok(style & WS_DISABLED, "window should be disabled\n");
4853 ok(style & WS_VISIBLE, "window should be visible\n");
4854 ok(style & WS_MINIMIZE, "window should be minimized\n");
4855 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4856 GetWindowRect(hwnd, &rc);
4857 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4859 ret = ShowWindow(hwnd, SW_RESTORE);
4860 ok(ret, "not expected ret: %lu\n", ret);
4861 style = GetWindowLong(hwnd, GWL_STYLE);
4862 ok(style & WS_DISABLED, "window should be disabled\n");
4863 ok(style & WS_VISIBLE, "window should be visible\n");
4864 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4865 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4866 GetWindowRect(hwnd, &rc);
4867 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4868 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4869 rc.left, rc.top, rc.right, rc.bottom);
4871 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4872 ok(!ret, "not expected ret: %lu\n", ret);
4873 ok(IsWindow(hwnd), "window should exist\n");
4875 ret = EnableWindow(hwnd, TRUE);
4876 ok(ret, "not expected ret: %lu\n", ret);
4878 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4879 ok(!ret, "not expected ret: %lu\n", ret);
4880 ok(!IsWindow(hwnd), "window should not exist\n");
4883 static void test_gettext(void)
4885 WNDCLASS cls;
4886 LPCSTR clsname = "gettexttest";
4887 HWND hwnd;
4888 LRESULT r;
4890 memset( &cls, 0, sizeof cls );
4891 cls.lpfnWndProc = DefWindowProc;
4892 cls.lpszClassName = clsname;
4893 cls.hInstance = GetModuleHandle(NULL);
4895 if (!RegisterClass( &cls )) return;
4897 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
4898 ok( hwnd != NULL, "window was null\n");
4900 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
4901 ok( r == 0, "settext should return zero\n");
4903 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
4904 ok( r == 0, "settext should return zero (%ld)\n", r);
4906 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
4907 ok( r == 0, "settext should return zero (%ld)\n", r);
4909 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
4910 ok( r == 0, "settext should return zero (%ld)\n", r);
4912 DestroyWindow(hwnd);
4913 UnregisterClass( clsname, NULL );
4917 static void test_GetUpdateRect(void)
4919 MSG msg;
4920 BOOL ret, parent_wm_paint, grandparent_wm_paint;
4921 RECT rc1, rc2;
4922 HWND hgrandparent, hparent, hchild;
4923 WNDCLASSA cls;
4924 static const char classNameA[] = "GetUpdateRectClass";
4926 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
4927 0, 0, 100, 100, NULL, NULL, 0, NULL);
4929 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
4930 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4932 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
4933 10, 10, 30, 30, hparent, NULL, 0, NULL);
4935 ShowWindow(hgrandparent, SW_SHOW);
4936 UpdateWindow(hgrandparent);
4937 flush_events( TRUE );
4939 ShowWindow(hchild, SW_HIDE);
4940 SetRect(&rc2, 0, 0, 0, 0);
4941 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4942 ok(!ret, "GetUpdateRect returned not empty region\n");
4943 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4944 rc1.left, rc1.top, rc1.right, rc1.bottom,
4945 rc2.left, rc2.top, rc2.right, rc2.bottom);
4947 SetRect(&rc2, 10, 10, 40, 40);
4948 ret = GetUpdateRect(hparent, &rc1, FALSE);
4949 ok(ret, "GetUpdateRect returned empty region\n");
4950 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4951 rc1.left, rc1.top, rc1.right, rc1.bottom,
4952 rc2.left, rc2.top, rc2.right, rc2.bottom);
4954 parent_wm_paint = FALSE;
4955 grandparent_wm_paint = FALSE;
4956 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4958 if (msg.message == WM_PAINT)
4960 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4961 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4963 DispatchMessage(&msg);
4965 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4966 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4968 DestroyWindow(hgrandparent);
4970 cls.style = 0;
4971 cls.lpfnWndProc = DefWindowProcA;
4972 cls.cbClsExtra = 0;
4973 cls.cbWndExtra = 0;
4974 cls.hInstance = GetModuleHandleA(0);
4975 cls.hIcon = 0;
4976 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4977 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4978 cls.lpszMenuName = NULL;
4979 cls.lpszClassName = classNameA;
4981 if(!RegisterClassA(&cls)) {
4982 trace("Register failed %d\n", GetLastError());
4983 return;
4986 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
4987 0, 0, 100, 100, NULL, NULL, 0, NULL);
4989 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
4990 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4992 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
4993 10, 10, 30, 30, hparent, NULL, 0, NULL);
4995 ShowWindow(hgrandparent, SW_SHOW);
4996 UpdateWindow(hgrandparent);
4997 flush_events( TRUE );
4999 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5000 ok(!ret, "GetUpdateRect returned not empty region\n");
5002 ShowWindow(hchild, SW_HIDE);
5004 SetRect(&rc2, 0, 0, 0, 0);
5005 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5006 ok(!ret, "GetUpdateRect returned not empty region\n");
5007 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5008 rc1.left, rc1.top, rc1.right, rc1.bottom,
5009 rc2.left, rc2.top, rc2.right, rc2.bottom);
5011 SetRect(&rc2, 10, 10, 40, 40);
5012 ret = GetUpdateRect(hparent, &rc1, FALSE);
5013 ok(ret, "GetUpdateRect returned empty region\n");
5014 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5015 rc1.left, rc1.top, rc1.right, rc1.bottom,
5016 rc2.left, rc2.top, rc2.right, rc2.bottom);
5018 parent_wm_paint = FALSE;
5019 grandparent_wm_paint = FALSE;
5020 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
5022 if (msg.message == WM_PAINT)
5024 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
5025 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
5027 DispatchMessage(&msg);
5029 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
5030 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
5032 DestroyWindow(hgrandparent);
5036 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5038 if(msg == WM_PAINT)
5040 PAINTSTRUCT ps;
5041 RECT updateRect;
5042 DWORD waitResult;
5043 HWND win;
5044 const int waitTime = 2000;
5046 BeginPaint(hwnd, &ps);
5048 /* create and destroy window to create an exposed region on this window */
5049 win = CreateWindowA("static", "win", WS_VISIBLE,
5050 10,10,50,50, NULL, NULL, 0, NULL);
5051 DestroyWindow(win);
5053 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
5055 ValidateRect(hwnd, NULL);
5056 EndPaint(hwnd, &ps);
5058 if(waitResult != WAIT_TIMEOUT)
5060 GetUpdateRect(hwnd, &updateRect, FALSE);
5061 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
5064 return 1;
5066 return DefWindowProc(hwnd, msg, wParam, lParam);
5069 static void test_Expose(void)
5071 ATOM atom;
5072 WNDCLASSA cls;
5073 HWND mw;
5074 memset(&cls, 0, sizeof(WNDCLASSA));
5075 cls.lpfnWndProc = TestExposedRegion_WndProc;
5076 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5077 cls.lpszClassName = "TestExposeClass";
5078 atom = RegisterClassA(&cls);
5080 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
5081 0, 0, 200, 100, NULL, NULL, 0, NULL);
5083 UpdateWindow(mw);
5084 DestroyWindow(mw);
5087 static LRESULT CALLBACK TestNCRedraw_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5089 static UINT ncredrawflags;
5090 PAINTSTRUCT ps;
5092 switch(msg)
5094 case WM_CREATE:
5095 ncredrawflags = *(UINT *) (((CREATESTRUCT *)lParam)->lpCreateParams);
5096 return 0;
5097 case WM_NCPAINT:
5098 RedrawWindow(hwnd, NULL, NULL, ncredrawflags);
5099 break;
5100 case WM_PAINT:
5101 BeginPaint(hwnd, &ps);
5102 EndPaint(hwnd, &ps);
5103 return 0;
5105 return DefWindowProc(hwnd, msg, wParam, lParam);
5108 static void run_NCRedrawLoop(UINT flags)
5110 HWND hwnd;
5111 MSG msg;
5113 UINT loopcount = 0;
5115 hwnd = CreateWindowA("TestNCRedrawClass", "MainWindow",
5116 WS_OVERLAPPEDWINDOW, 0, 0, 200, 100,
5117 NULL, NULL, 0, &flags);
5118 ShowWindow(hwnd, SW_SHOW);
5119 UpdateWindow(hwnd);
5120 while(PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE) != 0)
5122 if (msg.message == WM_PAINT) loopcount++;
5123 if (loopcount >= 100) break;
5124 TranslateMessage(&msg);
5125 DispatchMessage(&msg);
5126 MsgWaitForMultipleObjects(0, NULL, FALSE, 100, QS_ALLINPUT);
5128 if (flags == (RDW_INVALIDATE | RDW_FRAME))
5129 todo_wine ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
5130 else
5131 ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
5132 DestroyWindow(hwnd);
5135 static void test_NCRedraw(void)
5137 WNDCLASSA wndclass;
5139 wndclass.lpszClassName = "TestNCRedrawClass";
5140 wndclass.style = CS_HREDRAW | CS_VREDRAW;
5141 wndclass.lpfnWndProc = TestNCRedraw_WndProc;
5142 wndclass.cbClsExtra = 0;
5143 wndclass.cbWndExtra = 0;
5144 wndclass.hInstance = 0;
5145 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
5146 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
5147 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
5148 wndclass.lpszMenuName = NULL;
5150 RegisterClassA(&wndclass);
5152 run_NCRedrawLoop(RDW_INVALIDATE | RDW_FRAME);
5153 run_NCRedrawLoop(RDW_INVALIDATE);
5156 static void test_GetWindowModuleFileName(void)
5158 HWND hwnd;
5159 HINSTANCE hinst;
5160 UINT ret1, ret2;
5161 char buf1[MAX_PATH], buf2[MAX_PATH];
5163 if (!pGetWindowModuleFileNameA)
5165 win_skip("GetWindowModuleFileNameA is not available\n");
5166 return;
5169 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
5170 assert(hwnd);
5172 hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
5173 ok(hinst == 0 || broken(hinst == GetModuleHandle(0)), /* win9x */ "expected 0, got %p\n", hinst);
5175 buf1[0] = 0;
5176 SetLastError(0xdeadbeef);
5177 ret1 = GetModuleFileName(hinst, buf1, sizeof(buf1));
5178 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
5180 buf2[0] = 0;
5181 SetLastError(0xdeadbeef);
5182 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
5183 ok(ret2 || broken(!ret2), /* nt4 sp 3 */
5184 "GetWindowModuleFileNameA error %u\n", GetLastError());
5186 if (ret2)
5188 ok(ret1 == ret2 || broken(ret2 == ret1 + 1), /* win98 */ "%u != %u\n", ret1, ret2);
5189 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
5191 hinst = GetModuleHandle(0);
5193 SetLastError(0xdeadbeef);
5194 ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
5195 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
5196 "expected %u, got %u\n", ret1 - 2, ret2);
5197 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5198 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5199 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5201 SetLastError(0xdeadbeef);
5202 ret2 = GetModuleFileName(hinst, buf2, 0);
5203 ok(!ret2, "GetModuleFileName should return 0\n");
5204 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5205 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5206 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5208 SetLastError(0xdeadbeef);
5209 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
5210 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3) /* win98 */ || broken(!ret2), /* nt4 sp3 */
5211 "expected %u, got %u\n", ret1 - 2, ret2);
5212 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5213 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5214 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5216 SetLastError(0xdeadbeef);
5217 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
5218 ok(!ret2, "expected 0, got %u\n", ret2);
5219 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5220 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5221 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5223 DestroyWindow(hwnd);
5225 buf2[0] = 0;
5226 hwnd = (HWND)0xdeadbeef;
5227 SetLastError(0xdeadbeef);
5228 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
5229 ok(!ret1, "expected 0, got %u\n", ret1);
5230 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef), /* win9x */
5231 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
5233 hwnd = FindWindow("Shell_TrayWnd", NULL);
5234 ok(IsWindow(hwnd) || broken(!hwnd), "got invalid tray window %p\n", hwnd);
5235 SetLastError(0xdeadbeef);
5236 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
5237 ok(!ret1 || broken(ret1), /* win98 */ "expected 0, got %u\n", ret1);
5239 if (!ret1) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
5241 ret1 = GetModuleFileName(0, buf1, sizeof(buf1));
5242 hwnd = GetDesktopWindow();
5243 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
5244 SetLastError(0xdeadbeef);
5245 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
5246 ok(!ret2 ||
5247 ret1 == ret2 || /* vista */
5248 broken(ret2), /* some win98 return user.exe as file name */
5249 "expected 0 or %u, got %u %s\n", ret1, ret2, buf2);
5253 static void test_hwnd_message(void)
5255 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
5256 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
5258 HWND parent = 0, hwnd, found;
5259 RECT rect;
5261 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
5262 on CreateWindowExA and crash later in the test.
5263 Use UNICODE here to fail on win9x */
5264 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
5265 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
5266 if (!hwnd)
5268 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
5269 return;
5272 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
5273 if (pGetAncestor)
5275 char buffer[100];
5276 HWND root, desktop = GetDesktopWindow();
5278 parent = pGetAncestor(hwnd, GA_PARENT);
5279 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
5280 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
5281 root = pGetAncestor(hwnd, GA_ROOT);
5282 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
5283 ok( !pGetAncestor(parent, GA_PARENT) || broken(pGetAncestor(parent, GA_PARENT) != 0), /* win2k */
5284 "parent shouldn't have parent %p\n", pGetAncestor(parent, GA_PARENT) );
5285 trace("parent %p root %p desktop %p\n", parent, root, desktop);
5286 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
5287 ok( !lstrcmpi( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
5288 GetWindowRect( parent, &rect );
5289 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
5290 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
5292 GetWindowRect( hwnd, &rect );
5293 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
5294 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
5296 /* test FindWindow behavior */
5298 found = FindWindowExA( 0, 0, 0, "message window" );
5299 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
5300 SetLastError(0xdeadbeef);
5301 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
5302 ok( found == 0, "found message window %p/%p\n", found, hwnd );
5303 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
5304 if (parent)
5306 found = FindWindowExA( parent, 0, 0, "message window" );
5307 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
5310 /* test IsChild behavior */
5312 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
5314 /* test IsWindowVisible behavior */
5316 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
5317 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
5319 DestroyWindow(hwnd);
5322 static void test_layered_window(void)
5324 HWND hwnd;
5325 COLORREF key = 0;
5326 BYTE alpha = 0;
5327 DWORD flags = 0;
5328 BOOL ret;
5330 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes)
5332 win_skip( "layered windows not supported\n" );
5333 return;
5335 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
5336 100, 100, 200, 200, 0, 0, 0, NULL);
5337 assert( hwnd );
5338 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5339 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
5340 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
5341 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
5342 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5343 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5344 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5345 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
5346 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5347 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5348 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5349 ok( key == 0x123456 || key == 0, "wrong color key %x\n", key );
5350 ok( alpha == 44, "wrong alpha %u\n", alpha );
5351 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
5353 /* clearing WS_EX_LAYERED resets attributes */
5354 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5355 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5356 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
5357 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5358 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5359 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5360 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
5361 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5362 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5363 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5364 ok( key == 0x654321, "wrong color key %x\n", key );
5365 ok( alpha == 22, "wrong alpha %u\n", alpha );
5366 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
5368 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
5369 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5370 alpha = 0;
5371 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5372 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5373 ok( key == 0x888888, "wrong color key %x\n", key );
5374 /* alpha not changed on vista if LWA_ALPHA is not set */
5375 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
5376 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
5378 /* color key may or may not be changed without LWA_COLORKEY */
5379 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
5380 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5381 alpha = 0;
5382 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5383 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5384 ok( key == 0x888888 || key == 0x999999, "wrong color key %x\n", key );
5385 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
5386 ok( flags == 0, "wrong flags %x\n", flags );
5388 /* default alpha and color key is 0 */
5389 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5390 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5391 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
5392 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5393 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5394 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5395 ok( key == 0 || key == 0x222222, "wrong color key %x\n", key );
5396 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
5397 ok( flags == 0, "wrong flags %x\n", flags );
5399 DestroyWindow( hwnd );
5402 static MONITORINFO mi;
5404 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
5406 switch (msg)
5408 case WM_NCCREATE:
5410 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
5411 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs->x, cs->y, cs->cx, cs->cy);
5412 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
5413 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
5414 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
5415 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5416 cs->x, cs->y, cs->cx, cs->cy);
5417 break;
5419 case WM_GETMINMAXINFO:
5421 MINMAXINFO *minmax = (MINMAXINFO *)lp;
5422 dump_minmax_info(minmax);
5423 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
5424 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
5425 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
5426 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
5427 break;
5430 return DefWindowProc(hwnd, msg, wp, lp);
5433 static void test_fullscreen(void)
5435 static const DWORD t_style[] = {
5436 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
5438 static const DWORD t_ex_style[] = {
5439 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
5441 WNDCLASS cls;
5442 HWND hwnd;
5443 int i, j;
5444 POINT pt;
5445 RECT rc;
5446 HMONITOR hmon;
5447 LRESULT ret;
5449 if (!pGetMonitorInfoA || !pMonitorFromPoint)
5451 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
5452 return;
5455 pt.x = pt.y = 0;
5456 SetLastError(0xdeadbeef);
5457 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
5458 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
5460 mi.cbSize = sizeof(mi);
5461 SetLastError(0xdeadbeef);
5462 ret = pGetMonitorInfoA(hmon, &mi);
5463 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
5464 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
5465 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5466 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5468 cls.style = 0;
5469 cls.lpfnWndProc = fullscreen_wnd_proc;
5470 cls.cbClsExtra = 0;
5471 cls.cbWndExtra = 0;
5472 cls.hInstance = GetModuleHandle(0);
5473 cls.hIcon = 0;
5474 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5475 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5476 cls.lpszMenuName = NULL;
5477 cls.lpszClassName = "fullscreen_class";
5478 RegisterClass(&cls);
5480 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
5482 DWORD style, ex_style;
5484 /* avoid a WM interaction */
5485 assert(!(t_style[i] & WS_VISIBLE));
5487 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
5489 int fixup;
5491 style = t_style[i];
5492 ex_style = t_ex_style[j];
5494 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5495 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5496 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5497 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5498 GetWindowRect(hwnd, &rc);
5499 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5500 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5501 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5502 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5503 DestroyWindow(hwnd);
5505 style = t_style[i] | WS_MAXIMIZE;
5506 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5507 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5508 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5509 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5510 GetWindowRect(hwnd, &rc);
5511 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5512 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5513 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5514 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5515 DestroyWindow(hwnd);
5517 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
5518 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5519 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5520 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5521 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5522 GetWindowRect(hwnd, &rc);
5523 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5524 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5525 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5526 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5527 DestroyWindow(hwnd);
5529 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
5530 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5531 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5532 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5533 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5534 GetWindowRect(hwnd, &rc);
5535 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5536 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5537 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5538 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5539 DestroyWindow(hwnd);
5541 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
5542 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5543 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5544 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5545 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5546 GetWindowRect(hwnd, &rc);
5547 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5548 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5549 fixup = min(abs(rc.left), abs(rc.top));
5550 InflateRect(&rc, -fixup, -fixup);
5551 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5552 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5553 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
5554 ex_style, style, rc.left, rc.top, rc.right, rc.bottom,
5555 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5556 DestroyWindow(hwnd);
5558 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
5559 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5560 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5561 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5562 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5563 GetWindowRect(hwnd, &rc);
5564 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5565 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5566 fixup = min(abs(rc.left), abs(rc.top));
5567 InflateRect(&rc, -fixup, -fixup);
5568 if (style & (WS_CHILD | WS_POPUP))
5569 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5570 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5571 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5572 else
5573 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5574 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5575 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5576 DestroyWindow(hwnd);
5580 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5583 static BOOL test_thick_child_got_minmax;
5584 static const char * test_thick_child_name;
5585 static LONG test_thick_child_style;
5586 static LONG test_thick_child_exStyle;
5588 static LRESULT WINAPI test_thick_child_size_winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5590 MINMAXINFO* minmax;
5591 int expectedMinTrackX;
5592 int expectedMinTrackY;
5593 int actualMinTrackX;
5594 int actualMinTrackY;
5595 int expectedMaxTrackX;
5596 int expectedMaxTrackY;
5597 int actualMaxTrackX;
5598 int actualMaxTrackY;
5599 int expectedMaxSizeX;
5600 int expectedMaxSizeY;
5601 int actualMaxSizeX;
5602 int actualMaxSizeY;
5603 int expectedPosX;
5604 int expectedPosY;
5605 int actualPosX;
5606 int actualPosY;
5607 LONG adjustedStyle;
5608 RECT rect;
5609 switch (msg)
5611 case WM_GETMINMAXINFO:
5613 minmax = (MINMAXINFO *)lparam;
5614 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
5615 dump_minmax_info( minmax );
5617 test_thick_child_got_minmax = TRUE;
5620 adjustedStyle = test_thick_child_style;
5621 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
5622 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5623 GetClientRect(GetParent(hwnd), &rect);
5624 AdjustWindowRectEx(&rect, adjustedStyle, FALSE, test_thick_child_exStyle);
5626 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
5628 expectedMinTrackX = GetSystemMetrics(SM_CXMINTRACK);
5629 expectedMinTrackY = GetSystemMetrics(SM_CYMINTRACK);
5631 else
5633 expectedMinTrackX = -2 * rect.left;
5634 expectedMinTrackY = -2 * rect.top;
5636 actualMinTrackX = minmax->ptMinTrackSize.x;
5637 actualMinTrackY = minmax->ptMinTrackSize.y;
5639 ok(actualMinTrackX == expectedMinTrackX && actualMinTrackY == expectedMinTrackY,
5640 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
5641 expectedMinTrackX, expectedMinTrackY, actualMinTrackX, actualMinTrackY,
5642 test_thick_child_name);
5644 actualMaxTrackX = minmax->ptMaxTrackSize.x;
5645 actualMaxTrackY = minmax->ptMaxTrackSize.y;
5646 expectedMaxTrackX = GetSystemMetrics(SM_CXMAXTRACK);
5647 expectedMaxTrackY = GetSystemMetrics(SM_CYMAXTRACK);
5648 ok(actualMaxTrackX == expectedMaxTrackX && actualMaxTrackY == expectedMaxTrackY,
5649 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
5650 expectedMaxTrackX, expectedMaxTrackY, actualMaxTrackX, actualMaxTrackY,
5651 test_thick_child_name);
5653 expectedMaxSizeX = rect.right - rect.left;
5654 expectedMaxSizeY = rect.bottom - rect.top;
5655 actualMaxSizeX = minmax->ptMaxSize.x;
5656 actualMaxSizeY = minmax->ptMaxSize.y;
5658 ok(actualMaxSizeX == expectedMaxSizeX && actualMaxSizeY == expectedMaxSizeY,
5659 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
5660 expectedMaxSizeX, expectedMaxSizeY, actualMaxSizeX, actualMaxSizeY,
5661 test_thick_child_name);
5664 expectedPosX = rect.left;
5665 expectedPosY = rect.top;
5666 actualPosX = minmax->ptMaxPosition.x;
5667 actualPosY = minmax->ptMaxPosition.y;
5668 ok(actualPosX == expectedPosX && actualPosY == expectedPosY,
5669 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
5670 expectedPosX, expectedPosY, actualPosX, actualPosY, test_thick_child_name);
5672 break;
5676 return DefWindowProcA(hwnd, msg, wparam, lparam);
5679 #define NUMBER_OF_THICK_CHILD_TESTS 16
5680 static void test_thick_child_size(HWND parentWindow)
5682 BOOL success;
5683 RECT childRect;
5684 RECT adjustedParentRect;
5685 HWND childWindow;
5686 LONG childWidth;
5687 LONG childHeight;
5688 LONG expectedWidth;
5689 LONG expectedHeight;
5690 WNDCLASSA cls;
5691 LPCTSTR className = "THICK_CHILD_CLASS";
5692 int i;
5693 LONG adjustedStyle;
5694 static const LONG styles[NUMBER_OF_THICK_CHILD_TESTS] = {
5695 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5696 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5697 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5698 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5699 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5700 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5701 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5702 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5703 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5704 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5705 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5706 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5707 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5708 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5709 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5710 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5713 static const LONG exStyles[NUMBER_OF_THICK_CHILD_TESTS] = {
5718 WS_EX_DLGMODALFRAME,
5719 WS_EX_DLGMODALFRAME,
5720 WS_EX_DLGMODALFRAME,
5721 WS_EX_DLGMODALFRAME,
5722 WS_EX_STATICEDGE,
5723 WS_EX_STATICEDGE,
5724 WS_EX_STATICEDGE,
5725 WS_EX_STATICEDGE,
5726 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5727 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5728 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5729 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5731 static const char *styleName[NUMBER_OF_THICK_CHILD_TESTS] = {
5732 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
5733 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
5734 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
5735 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
5736 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
5737 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
5738 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5739 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5740 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
5741 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
5742 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5743 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5744 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5745 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5746 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5747 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5750 cls.style = 0;
5751 cls.lpfnWndProc = test_thick_child_size_winproc;
5752 cls.cbClsExtra = 0;
5753 cls.cbWndExtra = 0;
5754 cls.hInstance = GetModuleHandleA(0);
5755 cls.hIcon = 0;
5756 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5757 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5758 cls.lpszMenuName = NULL;
5759 cls.lpszClassName = className;
5760 SetLastError(0xdeadbeef);
5761 ok(RegisterClassA(&cls),"RegisterClassA failed, error: %u\n", GetLastError());
5763 for(i = 0; i < NUMBER_OF_THICK_CHILD_TESTS; i++)
5765 test_thick_child_name = styleName[i];
5766 test_thick_child_style = styles[i];
5767 test_thick_child_exStyle = exStyles[i];
5768 test_thick_child_got_minmax = FALSE;
5770 SetLastError(0xdeadbeef);
5771 childWindow = CreateWindowEx( exStyles[i], className, "", styles[i], 0, 0, 0, 0, parentWindow, 0, GetModuleHandleA(0), NULL );
5772 ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
5774 ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
5776 SetLastError(0xdeadbeef);
5777 success = GetWindowRect(childWindow, &childRect);
5778 ok(success,"GetWindowRect call failed, error: %u\n", GetLastError());
5779 childWidth = childRect.right - childRect.left;
5780 childHeight = childRect.bottom - childRect.top;
5782 adjustedStyle = styles[i];
5783 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
5784 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5785 GetClientRect(GetParent(childWindow), &adjustedParentRect);
5786 AdjustWindowRectEx(&adjustedParentRect, adjustedStyle, FALSE, test_thick_child_exStyle);
5789 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
5791 expectedWidth = GetSystemMetrics(SM_CXMINTRACK);
5792 expectedHeight = GetSystemMetrics(SM_CYMINTRACK);
5794 else
5796 expectedWidth = -2 * adjustedParentRect.left;
5797 expectedHeight = -2 * adjustedParentRect.top;
5800 ok((childWidth == expectedWidth) && (childHeight == expectedHeight),
5801 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
5802 test_thick_child_name, expectedWidth, expectedHeight, childWidth, childHeight);
5804 SetLastError(0xdeadbeef);
5805 success = DestroyWindow(childWindow);
5806 ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
5808 ok(UnregisterClass(className, GetModuleHandleA(0)),"UnregisterClass call failed\n");
5811 static void test_handles( HWND full_hwnd )
5813 HWND hwnd = full_hwnd;
5814 BOOL ret;
5815 RECT rect;
5817 SetLastError( 0xdeadbeef );
5818 ret = GetWindowRect( hwnd, &rect );
5819 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5821 #ifdef _WIN64
5822 if ((ULONG_PTR)full_hwnd >> 32)
5823 hwnd = (HWND)((ULONG_PTR)full_hwnd & ~0u);
5824 else
5825 hwnd = (HWND)((ULONG_PTR)full_hwnd | ((ULONG_PTR)~0u << 32));
5826 SetLastError( 0xdeadbeef );
5827 ret = GetWindowRect( hwnd, &rect );
5828 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5830 hwnd = (HWND)(((ULONG_PTR)full_hwnd & ~0u) | ((ULONG_PTR)0x1234 << 32));
5831 SetLastError( 0xdeadbeef );
5832 ret = GetWindowRect( hwnd, &rect );
5833 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5835 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x9876 << 16));
5836 SetLastError( 0xdeadbeef );
5837 ret = GetWindowRect( hwnd, &rect );
5838 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
5839 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
5841 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x12345678 << 16));
5842 SetLastError( 0xdeadbeef );
5843 ret = GetWindowRect( hwnd, &rect );
5844 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
5845 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
5846 #endif
5849 static void test_winregion(void)
5851 HWND hwnd;
5852 RECT r;
5853 int ret;
5854 HRGN hrgn;
5856 if (!pGetWindowRgnBox)
5858 win_skip("GetWindowRgnBox not supported\n");
5859 return;
5862 hwnd = CreateWindowExA(0, "static", NULL, WS_VISIBLE, 10, 10, 10, 10, NULL, 0, 0, NULL);
5863 /* NULL prect */
5864 SetLastError(0xdeadbeef);
5865 ret = pGetWindowRgnBox(hwnd, NULL);
5866 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
5867 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
5869 hrgn = CreateRectRgn(2, 3, 10, 15);
5870 ok( hrgn != NULL, "Region creation failed\n");
5871 if (hrgn)
5873 SetWindowRgn(hwnd, hrgn, FALSE);
5875 SetLastError(0xdeadbeef);
5876 ret = pGetWindowRgnBox(hwnd, NULL);
5877 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
5878 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
5880 r.left = r.top = r.right = r.bottom = 0;
5881 ret = pGetWindowRgnBox(hwnd, &r);
5882 ok( ret == SIMPLEREGION, "Expected SIMPLEREGION, got %d\n", ret);
5883 ok( r.left == 2 && r.top == 3 && r.right == 10 && r.bottom == 15,
5884 "Expected (2,3,10,15), got (%d,%d,%d,%d)\n", r.left, r.top,
5885 r.right, r.bottom);
5886 DeleteObject(hrgn);
5888 DestroyWindow(hwnd);
5891 START_TEST(win)
5893 HMODULE user32 = GetModuleHandleA( "user32.dll" );
5894 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
5895 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
5896 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
5897 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
5898 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
5899 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
5900 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
5901 pGetWindowRgnBox = (void *)GetProcAddress( user32, "GetWindowRgnBox" );
5902 pGetGUIThreadInfo = (void *)GetProcAddress( user32, "GetGUIThreadInfo" );
5904 if (!RegisterWindowClasses()) assert(0);
5906 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
5907 if (!hhook) win_skip( "Cannot set CBT hook, skipping some tests\n" );
5909 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
5910 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5911 WS_MAXIMIZEBOX | WS_POPUP,
5912 100, 100, 200, 200,
5913 0, 0, GetModuleHandle(0), NULL);
5914 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
5915 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5916 WS_MAXIMIZEBOX | WS_POPUP,
5917 100, 100, 200, 200,
5918 0, 0, GetModuleHandle(0), NULL);
5919 assert( hwndMain );
5920 assert( hwndMain2 );
5922 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
5924 /* Add the tests below this line */
5925 test_thick_child_size(hwndMain);
5926 test_fullscreen();
5927 test_hwnd_message();
5928 test_nonclient_area(hwndMain);
5929 test_params();
5930 test_GetWindowModuleFileName();
5931 test_capture_1();
5932 test_capture_2();
5933 test_capture_3(hwndMain, hwndMain2);
5934 test_capture_4();
5936 test_CreateWindow();
5937 test_parent_owner();
5938 test_SetParent();
5939 test_enum_thread_windows();
5941 test_mdi();
5942 test_icons();
5943 test_SetWindowPos(hwndMain);
5944 test_SetMenu(hwndMain);
5945 test_SetFocus(hwndMain);
5946 test_SetActiveWindow(hwndMain);
5947 test_NCRedraw();
5949 test_children_zorder(hwndMain);
5950 test_popup_zorder(hwndMain2, hwndMain);
5951 test_keyboard_input(hwndMain);
5952 test_mouse_input(hwndMain);
5953 test_validatergn(hwndMain);
5954 test_nccalcscroll( hwndMain);
5955 test_scrollwindow( hwndMain);
5956 test_scrollvalidate( hwndMain);
5957 test_scrolldc( hwndMain);
5958 test_scroll();
5959 test_IsWindowUnicode();
5960 test_vis_rgn(hwndMain);
5962 test_AdjustWindowRect();
5963 test_window_styles();
5964 test_redrawnow();
5965 test_csparentdc();
5966 test_SetWindowLong();
5967 test_ShowWindow();
5968 if (0) test_gettext(); /* crashes on NT4 */
5969 test_GetUpdateRect();
5970 test_Expose();
5971 test_layered_window();
5973 test_SetForegroundWindow(hwndMain);
5974 test_shell_window();
5975 test_handles( hwndMain );
5976 test_winregion();
5978 /* add the tests above this line */
5979 if (hhook) UnhookWindowsHookEx(hhook);
5981 DestroyWindow(hwndMain2);
5982 DestroyWindow(hwndMain);