ntdll/tests: Add a FILE_APPEND_DATA test.
[wine.git] / dlls / user32 / tests / win.c
blobca55c80456a74fb20a726f96661e38bb1032b36d
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 *pUpdateLayeredWindow)(HWND,HDC,POINT*,SIZE*,HDC,POINT*,COLORREF,BLENDFUNCTION*,DWORD);
53 static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
54 static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
55 static int (WINAPI *pGetWindowRgnBox)(HWND,LPRECT);
56 static BOOL (WINAPI *pGetGUIThreadInfo)(DWORD, GUITHREADINFO*);
57 static BOOL (WINAPI *pGetProcessDefaultLayout)( DWORD *layout );
58 static BOOL (WINAPI *pSetProcessDefaultLayout)( DWORD layout );
59 static DWORD (WINAPI *pSetLayout)(HDC hdc, DWORD layout);
60 static DWORD (WINAPI *pGetLayout)(HDC hdc);
61 static BOOL (WINAPI *pMirrorRgn)(HWND hwnd, HRGN hrgn);
63 static BOOL test_lbuttondown_flag;
64 static HWND hwndMessage;
65 static HWND hwndMain, hwndMain2;
66 static HHOOK hhook;
68 static const char* szAWRClass = "Winsize";
69 static HMENU hmenu;
70 static DWORD our_pid;
72 static BOOL is_win9x = FALSE;
74 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
76 static void dump_minmax_info( const MINMAXINFO *minmax )
78 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
79 minmax->ptReserved.x, minmax->ptReserved.y,
80 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
81 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
82 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
83 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
86 /* try to make sure pending X events have been processed before continuing */
87 static void flush_events( BOOL remove_messages )
89 MSG msg;
90 int diff = 200;
91 int min_timeout = 100;
92 DWORD time = GetTickCount() + diff;
94 while (diff > 0)
96 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
97 if (remove_messages)
98 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
99 diff = time - GetTickCount();
100 min_timeout = 50;
104 /* check the values returned by the various parent/owner functions on a given window */
105 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
106 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
108 HWND res;
110 if (pGetAncestor)
112 res = pGetAncestor( hwnd, GA_PARENT );
113 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
115 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
116 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
117 res = GetParent( hwnd );
118 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
119 res = GetWindow( hwnd, GW_OWNER );
120 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
121 if (pGetAncestor)
123 res = pGetAncestor( hwnd, GA_ROOT );
124 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
125 res = pGetAncestor( hwnd, GA_ROOTOWNER );
126 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
130 static BOOL ignore_message( UINT message )
132 /* these are always ignored */
133 return (message >= 0xc000 ||
134 message == WM_GETICON ||
135 message == WM_GETOBJECT ||
136 message == WM_TIMECHANGE ||
137 message == WM_DEVICECHANGE);
140 static BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
142 (*(LPINT)lParam)++;
143 trace("EnumChildProc on %p\n", hwndChild);
144 if (*(LPINT)lParam > 1) return FALSE;
145 return TRUE;
148 /* will search for the given window */
149 static BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
151 trace("EnumChildProc1 on %p\n", hwndChild);
152 if ((HWND)lParam == hwndChild) return FALSE;
153 return TRUE;
156 static HWND create_tool_window( LONG style, HWND parent )
158 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
159 0, 0, 100, 100, parent, 0, 0, NULL );
160 ok( ret != 0, "Creation failed\n" );
161 return ret;
164 /* test parent and owner values for various combinations */
165 static void test_parent_owner(void)
167 LONG style;
168 HWND test, owner, ret;
169 HWND desktop = GetDesktopWindow();
170 HWND child = create_tool_window( WS_CHILD, hwndMain );
171 INT numChildren;
173 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
175 /* child without parent, should fail */
176 SetLastError(0xdeadbeef);
177 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
178 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
179 ok( !test, "WS_CHILD without parent created\n" );
180 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD ||
181 broken(GetLastError() == 0xdeadbeef), /* win9x */
182 "CreateWindowExA error %u\n", GetLastError() );
184 /* desktop window */
185 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
186 style = GetWindowLongA( desktop, GWL_STYLE );
187 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
188 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
189 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
191 /* normal child window */
192 test = create_tool_window( WS_CHILD, hwndMain );
193 trace( "created child %p\n", test );
194 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
195 SetWindowLongA( test, GWL_STYLE, 0 );
196 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
197 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
198 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
199 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
200 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
201 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
202 DestroyWindow( test );
204 /* normal child window with WS_MAXIMIZE */
205 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
206 DestroyWindow( test );
208 /* normal child window with WS_THICKFRAME */
209 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
210 DestroyWindow( test );
212 /* popup window with WS_THICKFRAME */
213 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
214 DestroyWindow( test );
216 /* child of desktop */
217 test = create_tool_window( WS_CHILD, desktop );
218 trace( "created child of desktop %p\n", test );
219 check_parents( test, desktop, 0, desktop, 0, test, desktop );
220 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
221 check_parents( test, desktop, 0, 0, 0, test, test );
222 SetWindowLongA( test, GWL_STYLE, 0 );
223 check_parents( test, desktop, 0, 0, 0, test, test );
224 DestroyWindow( test );
226 /* child of desktop with WS_MAXIMIZE */
227 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
228 DestroyWindow( test );
230 /* child of desktop with WS_MINIMIZE */
231 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
232 DestroyWindow( test );
234 /* child of child */
235 test = create_tool_window( WS_CHILD, child );
236 trace( "created child of child %p\n", test );
237 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
238 SetWindowLongA( test, GWL_STYLE, 0 );
239 check_parents( test, child, child, 0, 0, hwndMain, test );
240 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
241 check_parents( test, child, child, 0, 0, hwndMain, test );
242 DestroyWindow( test );
244 /* child of child with WS_MAXIMIZE */
245 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
246 DestroyWindow( test );
248 /* child of child with WS_MINIMIZE */
249 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
250 DestroyWindow( test );
252 /* not owned top-level window */
253 test = create_tool_window( 0, 0 );
254 trace( "created top-level %p\n", test );
255 check_parents( test, desktop, 0, 0, 0, test, test );
256 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
257 check_parents( test, desktop, 0, 0, 0, test, test );
258 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
259 check_parents( test, desktop, 0, desktop, 0, test, desktop );
260 DestroyWindow( test );
262 /* not owned top-level window with WS_MAXIMIZE */
263 test = create_tool_window( WS_MAXIMIZE, 0 );
264 DestroyWindow( test );
266 /* owned top-level window */
267 test = create_tool_window( 0, hwndMain );
268 trace( "created owned top-level %p\n", test );
269 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
270 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
271 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
272 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
273 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
274 DestroyWindow( test );
276 /* owned top-level window with WS_MAXIMIZE */
277 test = create_tool_window( WS_MAXIMIZE, hwndMain );
278 DestroyWindow( test );
280 /* not owned popup */
281 test = create_tool_window( WS_POPUP, 0 );
282 trace( "created popup %p\n", test );
283 check_parents( test, desktop, 0, 0, 0, test, test );
284 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
285 check_parents( test, desktop, 0, desktop, 0, test, desktop );
286 SetWindowLongA( test, GWL_STYLE, 0 );
287 check_parents( test, desktop, 0, 0, 0, test, test );
288 DestroyWindow( test );
290 /* not owned popup with WS_MAXIMIZE */
291 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
292 DestroyWindow( test );
294 /* owned popup */
295 test = create_tool_window( WS_POPUP, hwndMain );
296 trace( "created owned popup %p\n", test );
297 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
298 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
299 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
300 SetWindowLongA( test, GWL_STYLE, 0 );
301 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
302 DestroyWindow( test );
304 /* owned popup with WS_MAXIMIZE */
305 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
306 DestroyWindow( test );
308 /* top-level window owned by child (same as owned by top-level) */
309 test = create_tool_window( 0, child );
310 trace( "created top-level owned by child %p\n", test );
311 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
312 DestroyWindow( test );
314 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
315 test = create_tool_window( WS_MAXIMIZE, child );
316 DestroyWindow( test );
318 /* popup owned by desktop (same as not owned) */
319 test = create_tool_window( WS_POPUP, desktop );
320 trace( "created popup owned by desktop %p\n", test );
321 check_parents( test, desktop, 0, 0, 0, test, test );
322 DestroyWindow( test );
324 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
325 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
326 DestroyWindow( test );
328 /* popup owned by child (same as owned by top-level) */
329 test = create_tool_window( WS_POPUP, child );
330 trace( "created popup owned by child %p\n", test );
331 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
332 DestroyWindow( test );
334 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
335 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
336 DestroyWindow( test );
338 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
339 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
340 trace( "created WS_CHILD popup %p\n", test );
341 check_parents( test, desktop, 0, 0, 0, test, test );
342 DestroyWindow( test );
344 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
345 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
346 DestroyWindow( test );
348 /* owned popup with WS_CHILD (same as WS_POPUP only) */
349 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
350 trace( "created owned WS_CHILD popup %p\n", test );
351 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
352 DestroyWindow( test );
354 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
355 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
356 DestroyWindow( test );
358 /******************** parent changes *************************/
359 trace( "testing parent changes\n" );
361 /* desktop window */
362 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
363 if (0)
365 /* this test succeeds on NT but crashes on win9x systems */
366 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
367 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
368 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
369 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
370 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
372 /* normal child window */
373 test = create_tool_window( WS_CHILD, hwndMain );
374 trace( "created child %p\n", test );
376 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
377 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
378 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
380 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
381 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
382 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
384 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
385 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
386 check_parents( test, desktop, 0, desktop, 0, test, desktop );
388 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
389 if (!is_win9x)
391 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)test );
392 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
393 check_parents( test, desktop, 0, desktop, 0, test, desktop );
395 else
396 win_skip("Test creates circular window tree under Win9x/WinMe\n" );
398 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
399 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
400 check_parents( test, desktop, child, desktop, child, test, desktop );
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, desktop, 0, test, desktop );
405 DestroyWindow( test );
407 /* not owned top-level window */
408 test = create_tool_window( 0, 0 );
409 trace( "created top-level %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, 0, hwndMain2, test, test );
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, 0, child, test, test );
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 /* not owned popup */
425 test = create_tool_window( WS_POPUP, 0 );
426 trace( "created popup %p\n", test );
428 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
429 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
430 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
432 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
433 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
434 check_parents( test, desktop, child, child, child, test, hwndMain );
436 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
437 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
438 check_parents( test, desktop, 0, 0, 0, test, test );
439 DestroyWindow( test );
441 /* normal child window */
442 test = create_tool_window( WS_CHILD, hwndMain );
443 trace( "created child %p\n", test );
445 ret = SetParent( test, desktop );
446 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
447 check_parents( test, desktop, 0, desktop, 0, test, desktop );
449 ret = SetParent( test, child );
450 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
451 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
453 ret = SetParent( test, hwndMain2 );
454 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
455 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
456 DestroyWindow( test );
458 /* not owned top-level window */
459 test = create_tool_window( 0, 0 );
460 trace( "created top-level %p\n", test );
462 ret = SetParent( test, child );
463 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
464 check_parents( test, child, child, 0, 0, hwndMain, test );
466 if (!is_win9x)
468 ShowWindow( test, SW_SHOW );
469 ret = SetParent( test, test );
470 ok( ret == NULL, "SetParent return value %p expected %p\n", ret, NULL );
471 ok( GetWindowLongA( test, GWL_STYLE ) & WS_VISIBLE, "window is not visible after SetParent\n" );
472 check_parents( test, child, child, 0, 0, hwndMain, test );
474 else
475 win_skip( "Test crashes on Win9x/WinMe\n" );
476 DestroyWindow( test );
478 /* owned popup */
479 test = create_tool_window( WS_POPUP, hwndMain2 );
480 trace( "created owned popup %p\n", test );
482 ret = SetParent( test, child );
483 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
484 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
486 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
487 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
488 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
489 DestroyWindow( test );
491 /**************** test owner destruction *******************/
493 /* owned child popup */
494 owner = create_tool_window( 0, 0 );
495 test = create_tool_window( WS_POPUP, owner );
496 trace( "created owner %p and popup %p\n", owner, test );
497 ret = SetParent( test, child );
498 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
499 check_parents( test, child, child, owner, owner, hwndMain, owner );
500 /* window is now child of 'child' but owned by 'owner' */
501 DestroyWindow( owner );
502 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
503 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
504 * while Win95, Win2k, WinXP do.
506 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
507 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
508 DestroyWindow(test);
510 /* owned top-level popup */
511 owner = create_tool_window( 0, 0 );
512 test = create_tool_window( WS_POPUP, owner );
513 trace( "created owner %p and popup %p\n", owner, test );
514 check_parents( test, desktop, owner, owner, owner, test, owner );
515 DestroyWindow( owner );
516 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
518 /* top-level popup owned by child */
519 owner = create_tool_window( WS_CHILD, hwndMain2 );
520 test = create_tool_window( WS_POPUP, 0 );
521 trace( "created owner %p and popup %p\n", owner, test );
522 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
523 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
524 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
525 DestroyWindow( owner );
526 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
527 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
528 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
529 * while Win95, Win2k, WinXP do.
531 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
532 DestroyWindow(test);
534 /* final cleanup */
535 DestroyWindow(child);
538 owner = create_tool_window( WS_OVERLAPPED, 0 );
539 test = create_tool_window( WS_POPUP, desktop );
541 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
542 numChildren = 0;
543 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
544 "EnumChildWindows should have returned FALSE\n" );
545 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
547 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
548 ret = SetParent( test, owner );
549 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
551 numChildren = 0;
552 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
553 "EnumChildWindows should have returned TRUE\n" );
554 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
556 child = create_tool_window( WS_CHILD, owner );
557 numChildren = 0;
558 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
559 "EnumChildWindows should have returned FALSE\n" );
560 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
561 DestroyWindow( child );
563 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
564 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
565 numChildren = 0;
566 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
567 "EnumChildWindows should have returned TRUE\n" );
568 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
570 ret = SetParent( child, owner );
571 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
572 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
573 numChildren = 0;
574 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
575 "EnumChildWindows should have returned FALSE\n" );
576 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
578 ret = SetParent( child, NULL );
579 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
580 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
581 numChildren = 0;
582 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
583 "EnumChildWindows should have returned TRUE\n" );
584 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
586 /* even GW_OWNER == owner it's still a desktop's child */
587 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
588 "EnumChildWindows should have found %p and returned FALSE\n", child );
590 DestroyWindow( child );
591 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
593 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
594 "EnumChildWindows should have found %p and returned FALSE\n", child );
596 DestroyWindow( child );
597 DestroyWindow( test );
598 DestroyWindow( owner );
601 static BOOL CALLBACK enum_proc( HWND hwnd, LPARAM lParam)
603 (*(LPINT)lParam)++;
604 if (*(LPINT)lParam > 2) return FALSE;
605 return TRUE;
607 static DWORD CALLBACK enum_thread( void *arg )
609 INT count;
610 HWND hwnd[3];
611 BOOL ret;
612 MSG msg;
614 if (pGetGUIThreadInfo)
616 GUITHREADINFO info;
617 info.cbSize = sizeof(info);
618 ret = pGetGUIThreadInfo( GetCurrentThreadId(), &info );
619 ok( ret || broken(!ret), /* win9x */
620 "GetGUIThreadInfo failed without message queue\n" );
621 SetLastError( 0xdeadbeef );
622 info.cbSize = sizeof(info) + 1;
623 ret = pGetGUIThreadInfo( GetCurrentThreadId(), &info );
624 ok( !ret, "GetGUIThreadInfo succeeded with wrong size\n" );
625 ok( GetLastError() == ERROR_INVALID_PARAMETER ||
626 broken(GetLastError() == 0xdeadbeef), /* win9x */
627 "wrong error %u\n", GetLastError() );
630 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ); /* make sure we have a message queue */
632 count = 0;
633 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
634 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
635 ok( count == 0, "count should be 0 got %d\n", count );
637 hwnd[0] = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", WS_POPUP,
638 0, 0, 100, 100, 0, 0, 0, NULL );
639 count = 0;
640 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
641 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
642 if (count != 2) /* Vista gives us two windows for the price of one */
644 ok( count == 1, "count should be 1 got %d\n", count );
645 hwnd[2] = CreateWindowExA(0, "ToolWindowClass", "Tool window 2", WS_POPUP,
646 0, 0, 100, 100, 0, 0, 0, NULL );
648 else hwnd[2] = 0;
650 hwnd[1] = CreateWindowExA(0, "ToolWindowClass", "Tool window 3", WS_POPUP,
651 0, 0, 100, 100, 0, 0, 0, NULL );
652 count = 0;
653 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
654 ok( !ret, "EnumThreadWindows should have returned FALSE\n" );
655 ok( count == 3, "count should be 3 got %d\n", count );
657 if (hwnd[2]) DestroyWindow(hwnd[2]);
658 DestroyWindow(hwnd[1]);
659 DestroyWindow(hwnd[0]);
660 return 0;
663 /* test EnumThreadWindows in a separate thread */
664 static void test_enum_thread_windows(void)
666 DWORD id;
667 HANDLE handle = CreateThread( NULL, 0, enum_thread, 0, 0, &id );
668 ok( !WaitForSingleObject( handle, 10000 ), "wait failed\n" );
669 CloseHandle( handle );
672 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
674 switch (msg)
676 case WM_GETMINMAXINFO:
678 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
680 trace("WM_GETMINMAXINFO: hwnd %p, %08lx, %08lx\n", hwnd, wparam, lparam);
681 dump_minmax_info( minmax );
682 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
683 break;
685 case WM_WINDOWPOSCHANGING:
687 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
688 trace("main: WM_WINDOWPOSCHANGING %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
689 winpos->hwnd, winpos->hwndInsertAfter,
690 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
691 if (!(winpos->flags & SWP_NOMOVE))
693 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
694 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
696 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
697 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
699 ok((winpos->cx >= 0 && winpos->cx <= 32767) ||
700 winpos->cx == 32768, /* win7 doesn't truncate */
701 "bad winpos->cx %d\n", winpos->cx);
702 ok((winpos->cy >= 0 && winpos->cy <= 32767) ||
703 winpos->cy == 40000, /* win7 doesn't truncate */
704 "bad winpos->cy %d\n", winpos->cy);
706 break;
708 case WM_WINDOWPOSCHANGED:
710 RECT rc1, rc2;
711 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
712 trace("main: WM_WINDOWPOSCHANGED %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
713 winpos->hwnd, winpos->hwndInsertAfter,
714 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
715 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
716 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
718 ok((winpos->cx >= 0 && winpos->cx <= 32767) ||
719 winpos->cx == 32768, /* win7 doesn't truncate */
720 "bad winpos->cx %d\n", winpos->cx);
721 ok((winpos->cy >= 0 && winpos->cy <= 32767) ||
722 winpos->cy == 40000, /* win7 doesn't truncate */
723 "bad winpos->cy %d\n", winpos->cy);
725 GetWindowRect(hwnd, &rc1);
726 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
727 /* note: winpos coordinates are relative to parent */
728 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
729 if (0)
731 /* Uncomment this once the test succeeds in all cases */
732 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
733 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
735 GetClientRect(hwnd, &rc2);
736 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
737 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
738 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
739 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
741 break;
743 case WM_NCCREATE:
745 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
746 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
748 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
749 if (got_getminmaxinfo)
750 trace("%p got WM_GETMINMAXINFO\n", hwnd);
752 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
753 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
754 else
755 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
756 break;
758 case WM_COMMAND:
759 if (test_lbuttondown_flag)
761 ShowWindow((HWND)wparam, SW_SHOW);
762 flush_events( FALSE );
764 break;
767 return DefWindowProcA(hwnd, msg, wparam, lparam);
770 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
772 switch (msg)
774 case WM_GETMINMAXINFO:
776 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
778 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
779 dump_minmax_info( minmax );
780 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
781 break;
783 case WM_NCCREATE:
785 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
786 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
788 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
789 if (got_getminmaxinfo)
790 trace("%p got WM_GETMINMAXINFO\n", hwnd);
792 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
793 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
794 else
795 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
796 break;
800 return DefWindowProcA(hwnd, msg, wparam, lparam);
803 static BOOL RegisterWindowClasses(void)
805 WNDCLASSA cls;
807 cls.style = CS_DBLCLKS;
808 cls.lpfnWndProc = main_window_procA;
809 cls.cbClsExtra = 0;
810 cls.cbWndExtra = 0;
811 cls.hInstance = GetModuleHandleA(0);
812 cls.hIcon = 0;
813 cls.hCursor = LoadCursorA(0, IDC_ARROW);
814 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
815 cls.lpszMenuName = NULL;
816 cls.lpszClassName = "MainWindowClass";
818 if(!RegisterClassA(&cls)) return FALSE;
820 cls.style = 0;
821 cls.lpfnWndProc = tool_window_procA;
822 cls.cbClsExtra = 0;
823 cls.cbWndExtra = 0;
824 cls.hInstance = GetModuleHandleA(0);
825 cls.hIcon = 0;
826 cls.hCursor = LoadCursorA(0, IDC_ARROW);
827 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
828 cls.lpszMenuName = NULL;
829 cls.lpszClassName = "ToolWindowClass";
831 if(!RegisterClassA(&cls)) return FALSE;
833 return TRUE;
836 static void verify_window_info(const char *hook, HWND hwnd, const WINDOWINFO *info)
838 RECT rcWindow, rcClient;
839 DWORD status;
841 ok(IsWindow(hwnd), "bad window handle %p in hook %s\n", hwnd, hook);
843 GetWindowRect(hwnd, &rcWindow);
844 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow for %p in hook %s\n", hwnd, hook);
846 GetClientRect(hwnd, &rcClient);
847 /* translate to screen coordinates */
848 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
849 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient for %p in hook %s\n", hwnd, hook);
851 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
852 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
853 info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE), hwnd, hook);
854 /* Windows reports some undocumented exstyles in WINDOWINFO, but
855 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
857 ok((info->dwExStyle & ~0xe0000800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
858 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
859 info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE), hwnd, hook);
860 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
861 if (GetForegroundWindow())
862 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
863 info->dwWindowStatus, status, GetActiveWindow(), GetForegroundWindow(), hook);
865 /* win2k and XP return broken border info in GetWindowInfo most of
866 * the time, so there is no point in testing it.
868 #if 0
869 UINT border;
870 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
871 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
872 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
873 ok(info->cyWindowBorders == border,
874 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
875 #endif
876 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType for %p in hook %s\n",
877 hwnd, hook);
878 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
879 info->wCreatorVersion == 0x0500 /* Vista */,
880 "wrong wCreatorVersion %04x for %p in hook %s\n", info->wCreatorVersion, hwnd, hook);
883 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
885 AdjustWindowRectEx(rc, style, menu, exstyle);
886 /* AdjustWindowRectEx does not include scroll bars */
887 if (style & WS_VSCROLL)
889 if(exstyle & WS_EX_LEFTSCROLLBAR)
890 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
891 else
892 rc->right += GetSystemMetrics(SM_CXVSCROLL);
894 if (style & WS_HSCROLL)
895 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
898 static void test_nonclient_area(HWND hwnd)
900 DWORD style, exstyle;
901 RECT rc_window, rc_client, rc;
902 BOOL menu;
903 LRESULT ret;
905 style = GetWindowLongA(hwnd, GWL_STYLE);
906 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
907 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
909 GetWindowRect(hwnd, &rc_window);
910 GetClientRect(hwnd, &rc_client);
912 /* avoid some cases when things go wrong */
913 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
914 rc_window.right > 32768 || rc_window.bottom > 32768) return;
916 CopyRect(&rc, &rc_client);
917 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
918 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
920 ok(EqualRect(&rc, &rc_window),
921 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
922 style, exstyle, menu, rc_window.left, rc_window.top, rc_window.right, rc_window.bottom,
923 rc.left, rc.top, rc.right, rc.bottom);
926 CopyRect(&rc, &rc_window);
927 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
928 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
929 ok(EqualRect(&rc, &rc_client),
930 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
931 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
932 rc.left, rc.top, rc.right, rc.bottom);
934 /* NULL rectangle shouldn't crash */
935 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
936 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
938 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
939 if (is_win9x)
940 return;
942 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
943 SetRect(&rc_client, 0, 0, 250, 150);
944 CopyRect(&rc_window, &rc_client);
945 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
946 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
948 CopyRect(&rc, &rc_window);
949 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
950 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
951 ok(EqualRect(&rc, &rc_client),
952 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
953 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
954 rc.left, rc.top, rc.right, rc.bottom);
957 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
959 static const char *CBT_code_name[10] = {
960 "HCBT_MOVESIZE",
961 "HCBT_MINMAX",
962 "HCBT_QS",
963 "HCBT_CREATEWND",
964 "HCBT_DESTROYWND",
965 "HCBT_ACTIVATE",
966 "HCBT_CLICKSKIPPED",
967 "HCBT_KEYSKIPPED",
968 "HCBT_SYSCOMMAND",
969 "HCBT_SETFOCUS" };
970 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
971 HWND hwnd = (HWND)wParam;
973 switch (nCode)
975 case HCBT_CREATEWND:
977 static const RECT rc_null;
978 RECT rc;
979 LONG style;
980 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
981 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
983 if (pGetWindowInfo)
985 WINDOWINFO info;
986 info.cbSize = sizeof(WINDOWINFO);
987 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
988 verify_window_info(code_name, hwnd, &info);
991 /* WS_VISIBLE should be turned off yet */
992 style = createwnd->lpcs->style & ~WS_VISIBLE;
993 ok(style == GetWindowLongA(hwnd, GWL_STYLE),
994 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
995 GetWindowLongA(hwnd, GWL_STYLE), style);
997 if (0)
999 /* Uncomment this once the test succeeds in all cases */
1000 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
1002 ok(GetParent(hwnd) == hwndMessage,
1003 "wrong result from GetParent %p: message window %p\n",
1004 GetParent(hwnd), hwndMessage);
1006 else
1007 ok(!GetParent(hwnd), "GetParent should return 0 at this point\n");
1009 ok(!GetWindow(hwnd, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
1011 if (0)
1013 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
1014 * Win9x still has them set to 0.
1016 ok(GetWindow(hwnd, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
1017 ok(GetWindow(hwnd, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
1019 ok(!GetWindow(hwnd, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
1020 ok(!GetWindow(hwnd, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
1022 if (0)
1024 /* Uncomment this once the test succeeds in all cases */
1025 if (pGetAncestor)
1027 ok(pGetAncestor(hwnd, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
1028 ok(pGetAncestor(hwnd, GA_ROOT) == hwnd,
1029 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOT), hwnd);
1031 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
1032 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwndMessage,
1033 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
1034 else
1035 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwnd,
1036 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOTOWNER), hwnd);
1039 ok(GetWindowRect(hwnd, &rc), "GetWindowRect failed\n");
1040 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
1041 ok(GetClientRect(hwnd, &rc), "GetClientRect failed\n");
1042 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
1044 break;
1046 case HCBT_MOVESIZE:
1047 case HCBT_MINMAX:
1048 case HCBT_ACTIVATE:
1049 if (pGetWindowInfo && IsWindow(hwnd))
1051 WINDOWINFO info;
1053 /* Win98 actually does check the info.cbSize and doesn't allow
1054 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
1055 * WinXP do not check it at all.
1057 info.cbSize = sizeof(WINDOWINFO);
1058 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
1059 verify_window_info(code_name, hwnd, &info);
1061 break;
1062 /* window state is undefined */
1063 case HCBT_SETFOCUS:
1064 case HCBT_DESTROYWND:
1065 break;
1066 default:
1067 break;
1070 return CallNextHookEx(hhook, nCode, wParam, lParam);
1073 static void test_shell_window(void)
1075 BOOL ret;
1076 DWORD error;
1077 HMODULE hinst, hUser32;
1078 BOOL (WINAPI*SetShellWindow)(HWND);
1079 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
1080 HWND shellWindow, nextWnd;
1082 if (is_win9x)
1084 win_skip("Skipping shell window test on Win9x\n");
1085 return;
1088 shellWindow = GetShellWindow();
1089 hinst = GetModuleHandle(0);
1090 hUser32 = GetModuleHandleA("user32");
1092 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
1094 trace("previous shell window: %p\n", shellWindow);
1096 if (shellWindow) {
1097 DWORD pid;
1098 HANDLE hProcess;
1100 GetWindowThreadProcessId(shellWindow, &pid);
1101 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
1102 if (!hProcess)
1104 skip( "cannot get access to shell process\n" );
1105 return;
1108 SetLastError(0xdeadbeef);
1109 ret = DestroyWindow(shellWindow);
1110 error = GetLastError();
1112 ok(!ret, "DestroyWindow(shellWindow)\n");
1113 /* passes on Win XP, but not on Win98 */
1114 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
1115 "got %u after DestroyWindow(shellWindow)\n", error);
1117 /* close old shell instance */
1118 ret = TerminateProcess(hProcess, 0);
1119 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1120 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
1121 CloseHandle(hProcess);
1124 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
1125 trace("created window 1: %p\n", hwnd1);
1127 ret = SetShellWindow(hwnd1);
1128 ok(ret, "first call to SetShellWindow(hwnd1)\n");
1129 shellWindow = GetShellWindow();
1130 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
1132 ret = SetShellWindow(hwnd1);
1133 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1135 ret = SetShellWindow(0);
1136 error = GetLastError();
1137 /* passes on Win XP, but not on Win98
1138 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1139 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1141 ret = SetShellWindow(hwnd1);
1142 /* passes on Win XP, but not on Win98
1143 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1145 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1146 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
1147 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1149 ret = DestroyWindow(hwnd1);
1150 ok(ret, "DestroyWindow(hwnd1)\n");
1152 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1153 trace("created window 2: %p\n", hwnd2);
1154 ret = SetShellWindow(hwnd2);
1155 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1157 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1158 trace("created window 3: %p\n", hwnd3);
1160 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1161 trace("created window 4: %p\n", hwnd4);
1163 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1164 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1166 ret = SetShellWindow(hwnd4);
1167 ok(ret, "SetShellWindow(hwnd4)\n");
1168 shellWindow = GetShellWindow();
1169 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1171 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1172 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1174 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1175 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1177 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1178 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1180 ret = SetShellWindow(hwnd3);
1181 ok(!ret, "SetShellWindow(hwnd3)\n");
1182 shellWindow = GetShellWindow();
1183 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1185 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1186 trace("created window 5: %p\n", hwnd5);
1187 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1188 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1190 todo_wine
1192 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1193 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1196 /* destroy test windows */
1197 DestroyWindow(hwnd2);
1198 DestroyWindow(hwnd3);
1199 DestroyWindow(hwnd4);
1200 DestroyWindow(hwnd5);
1203 /************** MDI test ****************/
1205 static char mdi_lParam_test_message[] = "just a test string";
1207 static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
1209 MDICREATESTRUCTA mdi_cs;
1210 HWND mdi_child;
1211 INT_PTR id;
1212 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1213 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1214 BOOL isWin9x = FALSE;
1216 mdi_cs.szClass = "MDI_child_Class_1";
1217 mdi_cs.szTitle = "MDI child";
1218 mdi_cs.hOwner = GetModuleHandle(0);
1219 mdi_cs.x = CW_USEDEFAULT;
1220 mdi_cs.y = CW_USEDEFAULT;
1221 mdi_cs.cx = CW_USEDEFAULT;
1222 mdi_cs.cy = CW_USEDEFAULT;
1223 mdi_cs.style = 0;
1224 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1225 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1226 ok(mdi_child != 0, "MDI child creation failed\n");
1227 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1228 ok(id == first_id, "wrong child id %ld\n", id);
1229 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1230 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1232 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1233 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1234 ok(mdi_child != 0, "MDI child creation failed\n");
1235 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1236 ok(id == first_id, "wrong child id %ld\n", id);
1237 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1238 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1240 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1241 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1242 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1244 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1246 else
1248 ok(mdi_child != 0, "MDI child creation failed\n");
1249 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1250 ok(id == first_id, "wrong child id %ld\n", id);
1251 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1252 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1255 /* test MDICREATESTRUCT A<->W mapping */
1256 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1257 mdi_cs.style = 0;
1258 mdi_cs.szClass = (LPCSTR)classW;
1259 mdi_cs.szTitle = (LPCSTR)titleW;
1260 SetLastError(0xdeadbeef);
1261 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1262 if (!mdi_child)
1264 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1265 isWin9x = TRUE;
1266 else
1267 ok(mdi_child != 0, "MDI child creation failed\n");
1269 else
1271 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1272 ok(id == first_id, "wrong child id %ld\n", id);
1273 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1274 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1277 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1279 CW_USEDEFAULT, CW_USEDEFAULT,
1280 CW_USEDEFAULT, CW_USEDEFAULT,
1281 mdi_client, GetModuleHandle(0),
1282 (LPARAM)mdi_lParam_test_message);
1283 ok(mdi_child != 0, "MDI child creation failed\n");
1284 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1285 ok(id == first_id, "wrong child id %ld\n", id);
1286 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1287 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1289 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1290 0x7fffffff, /* without WS_POPUP */
1291 CW_USEDEFAULT, CW_USEDEFAULT,
1292 CW_USEDEFAULT, CW_USEDEFAULT,
1293 mdi_client, GetModuleHandle(0),
1294 (LPARAM)mdi_lParam_test_message);
1295 ok(mdi_child != 0, "MDI child creation failed\n");
1296 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1297 ok(id == first_id, "wrong child id %ld\n", id);
1298 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1299 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1301 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1302 0xffffffff, /* with WS_POPUP */
1303 CW_USEDEFAULT, CW_USEDEFAULT,
1304 CW_USEDEFAULT, CW_USEDEFAULT,
1305 mdi_client, GetModuleHandle(0),
1306 (LPARAM)mdi_lParam_test_message);
1307 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1309 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1311 else
1313 ok(mdi_child != 0, "MDI child creation failed\n");
1314 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1315 ok(id == first_id, "wrong child id %ld\n", id);
1316 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1317 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1320 /* test MDICREATESTRUCT A<->W mapping */
1321 SetLastError(0xdeadbeef);
1322 mdi_child = CreateMDIWindowW(classW, titleW,
1324 CW_USEDEFAULT, CW_USEDEFAULT,
1325 CW_USEDEFAULT, CW_USEDEFAULT,
1326 mdi_client, GetModuleHandle(0),
1327 (LPARAM)mdi_lParam_test_message);
1328 if (!mdi_child)
1330 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1331 isWin9x = TRUE;
1332 else
1333 ok(mdi_child != 0, "MDI child creation failed\n");
1335 else
1337 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1338 ok(id == first_id, "wrong child id %ld\n", id);
1339 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1340 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1343 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1345 CW_USEDEFAULT, CW_USEDEFAULT,
1346 CW_USEDEFAULT, CW_USEDEFAULT,
1347 mdi_client, 0, GetModuleHandle(0),
1348 mdi_lParam_test_message);
1349 ok(mdi_child != 0, "MDI child creation failed\n");
1350 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1351 ok(id == first_id, "wrong child id %ld\n", id);
1352 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1353 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1355 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1356 0x7fffffff, /* without WS_POPUP */
1357 CW_USEDEFAULT, CW_USEDEFAULT,
1358 CW_USEDEFAULT, CW_USEDEFAULT,
1359 mdi_client, 0, GetModuleHandle(0),
1360 mdi_lParam_test_message);
1361 ok(mdi_child != 0, "MDI child creation failed\n");
1362 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1363 ok(id == first_id, "wrong child id %ld\n", id);
1364 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1365 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1367 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1368 0xffffffff, /* with WS_POPUP */
1369 CW_USEDEFAULT, CW_USEDEFAULT,
1370 CW_USEDEFAULT, CW_USEDEFAULT,
1371 mdi_client, 0, GetModuleHandle(0),
1372 mdi_lParam_test_message);
1373 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1375 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1377 else
1379 ok(mdi_child != 0, "MDI child creation failed\n");
1380 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1381 ok(id == first_id, "wrong child id %ld\n", id);
1382 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1383 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1386 /* test MDICREATESTRUCT A<->W mapping */
1387 SetLastError(0xdeadbeef);
1388 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1390 CW_USEDEFAULT, CW_USEDEFAULT,
1391 CW_USEDEFAULT, CW_USEDEFAULT,
1392 mdi_client, 0, GetModuleHandle(0),
1393 mdi_lParam_test_message);
1394 if (!mdi_child)
1396 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1397 isWin9x = TRUE;
1398 else
1399 ok(mdi_child != 0, "MDI child creation failed\n");
1401 else
1403 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1404 ok(id == first_id, "wrong child id %ld\n", id);
1405 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1406 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1409 /* This test fails on Win9x */
1410 if (!isWin9x)
1412 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1413 WS_CHILD,
1414 CW_USEDEFAULT, CW_USEDEFAULT,
1415 CW_USEDEFAULT, CW_USEDEFAULT,
1416 parent, 0, GetModuleHandle(0),
1417 mdi_lParam_test_message);
1418 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1421 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1422 WS_CHILD, /* without WS_POPUP */
1423 CW_USEDEFAULT, CW_USEDEFAULT,
1424 CW_USEDEFAULT, CW_USEDEFAULT,
1425 mdi_client, 0, GetModuleHandle(0),
1426 mdi_lParam_test_message);
1427 ok(mdi_child != 0, "MDI child creation failed\n");
1428 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1429 ok(id == 0, "wrong child id %ld\n", id);
1430 DestroyWindow(mdi_child);
1432 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1433 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1434 CW_USEDEFAULT, CW_USEDEFAULT,
1435 CW_USEDEFAULT, CW_USEDEFAULT,
1436 mdi_client, 0, GetModuleHandle(0),
1437 mdi_lParam_test_message);
1438 ok(mdi_child != 0, "MDI child creation failed\n");
1439 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1440 ok(id == 0, "wrong child id %ld\n", id);
1441 DestroyWindow(mdi_child);
1443 /* maximized child */
1444 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1445 WS_CHILD | WS_MAXIMIZE,
1446 CW_USEDEFAULT, CW_USEDEFAULT,
1447 CW_USEDEFAULT, CW_USEDEFAULT,
1448 mdi_client, 0, GetModuleHandle(0),
1449 mdi_lParam_test_message);
1450 ok(mdi_child != 0, "MDI child creation failed\n");
1451 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1452 ok(id == 0, "wrong child id %ld\n", id);
1453 DestroyWindow(mdi_child);
1455 trace("Creating maximized child with a caption\n");
1456 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1457 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1458 CW_USEDEFAULT, CW_USEDEFAULT,
1459 CW_USEDEFAULT, CW_USEDEFAULT,
1460 mdi_client, 0, GetModuleHandle(0),
1461 mdi_lParam_test_message);
1462 ok(mdi_child != 0, "MDI child creation failed\n");
1463 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1464 ok(id == 0, "wrong child id %ld\n", id);
1465 DestroyWindow(mdi_child);
1467 trace("Creating maximized child with a caption and a thick frame\n");
1468 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1469 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1470 CW_USEDEFAULT, CW_USEDEFAULT,
1471 CW_USEDEFAULT, CW_USEDEFAULT,
1472 mdi_client, 0, GetModuleHandle(0),
1473 mdi_lParam_test_message);
1474 ok(mdi_child != 0, "MDI child creation failed\n");
1475 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1476 ok(id == 0, "wrong child id %ld\n", id);
1477 DestroyWindow(mdi_child);
1480 /**********************************************************************
1481 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1483 * Note: The rule here is that client rect of the maximized MDI child
1484 * is equal to the client rect of the MDI client window.
1486 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1488 RECT rect;
1490 GetClientRect( client, &rect );
1491 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1492 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1494 rect.right -= rect.left;
1495 rect.bottom -= rect.top;
1496 lpMinMax->ptMaxSize.x = rect.right;
1497 lpMinMax->ptMaxSize.y = rect.bottom;
1499 lpMinMax->ptMaxPosition.x = rect.left;
1500 lpMinMax->ptMaxPosition.y = rect.top;
1502 trace("max rect (%d,%d - %d, %d)\n",
1503 rect.left, rect.top, rect.right, rect.bottom);
1506 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1508 switch (msg)
1510 case WM_NCCREATE:
1511 case WM_CREATE:
1513 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1514 MDICREATESTRUCTA *mdi_cs = cs->lpCreateParams;
1516 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1517 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1519 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1520 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1521 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1522 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1523 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1525 /* MDICREATESTRUCT should have original values */
1526 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1527 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1528 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1529 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1530 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1531 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1533 /* CREATESTRUCT should have fixed values */
1534 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1535 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1537 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1538 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1539 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1541 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1543 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1545 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1546 ok(cs->style == style,
1547 "cs->style does not match (%08x)\n", cs->style);
1549 else
1551 LONG style = mdi_cs->style;
1552 style &= ~WS_POPUP;
1553 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1554 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1555 ok(cs->style == style,
1556 "cs->style does not match (%08x)\n", cs->style);
1558 break;
1561 case WM_GETMINMAXINFO:
1563 HWND client = GetParent(hwnd);
1564 RECT rc;
1565 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1566 MINMAXINFO my_minmax;
1567 LONG style, exstyle;
1569 style = GetWindowLongA(hwnd, GWL_STYLE);
1570 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1572 GetWindowRect(client, &rc);
1573 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1574 GetClientRect(client, &rc);
1575 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1576 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1577 GetSystemMetrics(SM_CYSCREEN));
1579 GetClientRect(client, &rc);
1580 if ((style & WS_CAPTION) == WS_CAPTION)
1581 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1582 AdjustWindowRectEx(&rc, style, 0, exstyle);
1583 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1584 dump_minmax_info( minmax );
1586 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1587 minmax->ptMaxSize.x, rc.right - rc.left);
1588 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1589 minmax->ptMaxSize.y, rc.bottom - rc.top);
1591 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1593 trace("DefMDIChildProc returned:\n");
1594 dump_minmax_info( minmax );
1596 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1597 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1598 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1599 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1600 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1602 return 1;
1605 case WM_MDIACTIVATE:
1607 HWND active, client = GetParent(hwnd);
1608 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1609 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1610 if (hwnd == (HWND)lparam) /* if we are being activated */
1611 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1612 else
1613 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1614 break;
1617 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1620 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1622 switch (msg)
1624 case WM_NCCREATE:
1625 case WM_CREATE:
1627 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1629 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE",
1630 cs->x, cs->y, cs->cx, cs->cy);
1632 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1633 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1635 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1636 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1638 /* CREATESTRUCT should have fixed values */
1639 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1640 while NT does. */
1641 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1642 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1644 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1645 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1646 while Win95, Win2k, WinXP do. */
1647 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1648 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1649 break;
1652 case WM_GETMINMAXINFO:
1654 HWND parent = GetParent(hwnd);
1655 RECT rc;
1656 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1657 LONG style, exstyle;
1659 style = GetWindowLongA(hwnd, GWL_STYLE);
1660 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1662 GetClientRect(parent, &rc);
1663 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1665 GetClientRect(parent, &rc);
1666 if ((style & WS_CAPTION) == WS_CAPTION)
1667 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1668 AdjustWindowRectEx(&rc, style, 0, exstyle);
1669 dump_minmax_info( minmax );
1671 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1672 minmax->ptMaxSize.x, rc.right - rc.left);
1673 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1674 minmax->ptMaxSize.y, rc.bottom - rc.top);
1675 break;
1678 case WM_WINDOWPOSCHANGED:
1680 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1681 RECT rc1, rc2;
1683 GetWindowRect(hwnd, &rc1);
1684 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1685 /* note: winpos coordinates are relative to parent */
1686 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1687 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) pos=(%d,%d)-(%d,%d)\n",
1688 rc1.left, rc1.top, rc1.right, rc1.bottom,
1689 rc2.left, rc2.top, rc2.right, rc2.bottom);
1690 GetWindowRect(hwnd, &rc1);
1691 GetClientRect(hwnd, &rc2);
1692 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1693 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1694 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1695 rc1.left, rc1.top, rc1.right, rc1.bottom,
1696 rc2.left, rc2.top, rc2.right, rc2.bottom);
1698 /* fall through */
1699 case WM_WINDOWPOSCHANGING:
1701 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1702 WINDOWPOS my_winpos = *winpos;
1704 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1705 (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
1706 winpos->hwnd, winpos->hwndInsertAfter,
1707 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1709 DefWindowProcA(hwnd, msg, wparam, lparam);
1711 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1712 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1713 winpos->hwnd, winpos->hwndInsertAfter,
1714 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1716 return 1;
1719 return DefWindowProcA(hwnd, msg, wparam, lparam);
1722 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1724 static HWND mdi_client;
1726 switch (msg)
1728 case WM_CREATE:
1730 CLIENTCREATESTRUCT client_cs;
1731 RECT rc;
1733 GetClientRect(hwnd, &rc);
1735 client_cs.hWindowMenu = 0;
1736 client_cs.idFirstChild = 1;
1738 /* MDIClient without MDIS_ALLCHILDSTYLES */
1739 mdi_client = CreateWindowExA(0, "mdiclient",
1740 NULL,
1741 WS_CHILD /*| WS_VISIBLE*/,
1742 /* tests depend on a not zero MDIClient size */
1743 0, 0, rc.right, rc.bottom,
1744 hwnd, 0, GetModuleHandle(0),
1745 &client_cs);
1746 assert(mdi_client);
1747 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1748 DestroyWindow(mdi_client);
1750 /* MDIClient with MDIS_ALLCHILDSTYLES */
1751 mdi_client = CreateWindowExA(0, "mdiclient",
1752 NULL,
1753 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1754 /* tests depend on a not zero MDIClient size */
1755 0, 0, rc.right, rc.bottom,
1756 hwnd, 0, GetModuleHandle(0),
1757 &client_cs);
1758 assert(mdi_client);
1759 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1760 DestroyWindow(mdi_client);
1761 break;
1764 case WM_WINDOWPOSCHANGED:
1766 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1767 RECT rc1, rc2;
1769 GetWindowRect(hwnd, &rc1);
1770 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1771 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1772 /* note: winpos coordinates are relative to parent */
1773 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1774 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1775 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1777 GetWindowRect(hwnd, &rc1);
1778 GetClientRect(hwnd, &rc2);
1779 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1780 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1781 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1783 /* fall through */
1784 case WM_WINDOWPOSCHANGING:
1786 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1787 WINDOWPOS my_winpos = *winpos;
1789 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1790 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1791 winpos->hwnd, winpos->hwndInsertAfter,
1792 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1794 DefWindowProcA(hwnd, msg, wparam, lparam);
1796 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1797 winpos->hwnd, winpos->hwndInsertAfter,
1798 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1800 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1801 "DefWindowProc should not change WINDOWPOS values\n");
1803 return 1;
1806 case WM_CLOSE:
1807 PostQuitMessage(0);
1808 break;
1810 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1813 static BOOL mdi_RegisterWindowClasses(void)
1815 WNDCLASSA cls;
1817 cls.style = 0;
1818 cls.lpfnWndProc = mdi_main_wnd_procA;
1819 cls.cbClsExtra = 0;
1820 cls.cbWndExtra = 0;
1821 cls.hInstance = GetModuleHandleA(0);
1822 cls.hIcon = 0;
1823 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1824 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1825 cls.lpszMenuName = NULL;
1826 cls.lpszClassName = "MDI_parent_Class";
1827 if(!RegisterClassA(&cls)) return FALSE;
1829 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1830 cls.lpszClassName = "MDI_child_Class_1";
1831 if(!RegisterClassA(&cls)) return FALSE;
1833 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1834 cls.lpszClassName = "MDI_child_Class_2";
1835 if(!RegisterClassA(&cls)) return FALSE;
1837 return TRUE;
1840 static void test_mdi(void)
1842 HWND mdi_hwndMain;
1843 /*MSG msg;*/
1845 if (!mdi_RegisterWindowClasses()) assert(0);
1847 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1848 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1849 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1850 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1851 GetDesktopWindow(), 0,
1852 GetModuleHandle(0), NULL);
1853 assert(mdi_hwndMain);
1855 while(GetMessage(&msg, 0, 0, 0))
1857 TranslateMessage(&msg);
1858 DispatchMessage(&msg);
1861 DestroyWindow(mdi_hwndMain);
1864 static void test_icons(void)
1866 WNDCLASSEXA cls;
1867 HWND hwnd;
1868 HICON icon = LoadIconA(0, IDI_APPLICATION);
1869 HICON icon2 = LoadIconA(0, IDI_QUESTION);
1870 HICON small_icon = LoadImageA(0, IDI_APPLICATION, IMAGE_ICON,
1871 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1872 HICON res;
1874 cls.cbSize = sizeof(cls);
1875 cls.style = 0;
1876 cls.lpfnWndProc = DefWindowProcA;
1877 cls.cbClsExtra = 0;
1878 cls.cbWndExtra = 0;
1879 cls.hInstance = 0;
1880 cls.hIcon = LoadIconA(0, IDI_HAND);
1881 cls.hIconSm = small_icon;
1882 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1883 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1884 cls.lpszMenuName = NULL;
1885 cls.lpszClassName = "IconWindowClass";
1887 RegisterClassExA(&cls);
1889 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1890 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1891 assert( hwnd );
1893 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1894 ok( res == 0, "wrong big icon %p/0\n", res );
1895 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1896 ok( res == 0, "wrong previous big icon %p/0\n", res );
1897 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1898 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1899 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1900 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1901 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1902 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1904 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1905 ok( res == 0, "wrong small icon %p/0\n", res );
1906 /* this test is XP specific */
1907 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1908 ok( res != 0, "wrong small icon %p\n", res );*/
1909 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1910 ok( res == 0, "wrong previous small icon %p/0\n", res );
1911 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1912 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1913 /* this test is XP specific */
1914 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1915 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1916 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1917 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1918 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1919 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1920 /* this test is XP specific */
1921 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1922 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1924 /* make sure the big icon hasn't changed */
1925 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1926 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1928 DestroyWindow( hwnd );
1931 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1933 if (msg == WM_NCCALCSIZE)
1935 RECT *rect = (RECT *)lparam;
1936 /* first time around increase the rectangle, next time decrease it */
1937 if (rect->left == 100) InflateRect( rect, 10, 10 );
1938 else InflateRect( rect, -10, -10 );
1939 return 0;
1941 return DefWindowProc( hwnd, msg, wparam, lparam );
1944 static void test_SetWindowPos(HWND hwnd)
1946 RECT orig_win_rc, rect;
1947 LONG_PTR old_proc;
1949 SetRect(&rect, 111, 222, 333, 444);
1950 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1951 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1952 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1954 SetRect(&rect, 111, 222, 333, 444);
1955 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1956 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1957 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1959 GetWindowRect(hwnd, &orig_win_rc);
1961 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1962 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1963 GetWindowRect( hwnd, &rect );
1964 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1965 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1966 GetClientRect( hwnd, &rect );
1967 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1968 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1969 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1971 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1972 GetWindowRect( hwnd, &rect );
1973 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1974 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1975 GetClientRect( hwnd, &rect );
1976 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1977 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1978 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1980 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1981 orig_win_rc.right, orig_win_rc.bottom, 0);
1982 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1984 /* Win9x truncates coordinates to 16-bit irrespectively */
1985 if (!is_win9x)
1987 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1988 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1990 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1991 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1994 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1995 orig_win_rc.right, orig_win_rc.bottom, 0);
1997 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1998 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1999 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
2000 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
2001 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
2002 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
2003 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
2006 static void test_SetMenu(HWND parent)
2008 HWND child;
2009 HMENU hMenu, ret;
2010 BOOL retok;
2011 DWORD style;
2013 hMenu = CreateMenu();
2014 assert(hMenu);
2016 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2017 if (0)
2019 /* fails on (at least) Wine, NT4, XP SP2 */
2020 test_nonclient_area(parent);
2022 ret = GetMenu(parent);
2023 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2024 /* test whether we can destroy a menu assigned to a window */
2025 retok = DestroyMenu(hMenu);
2026 ok( retok, "DestroyMenu error %d\n", GetLastError());
2027 retok = IsMenu(hMenu);
2028 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
2029 ret = GetMenu(parent);
2030 /* This test fails on Win9x */
2031 if (!is_win9x)
2032 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2033 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2034 test_nonclient_area(parent);
2036 hMenu = CreateMenu();
2037 assert(hMenu);
2039 /* parent */
2040 ret = GetMenu(parent);
2041 ok(ret == 0, "unexpected menu id %p\n", ret);
2043 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2044 test_nonclient_area(parent);
2045 ret = GetMenu(parent);
2046 ok(ret == 0, "unexpected menu id %p\n", ret);
2048 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2049 if (0)
2051 /* fails on (at least) Wine, NT4, XP SP2 */
2052 test_nonclient_area(parent);
2054 ret = GetMenu(parent);
2055 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2057 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2058 test_nonclient_area(parent);
2059 ret = GetMenu(parent);
2060 ok(ret == 0, "unexpected menu id %p\n", ret);
2062 /* child */
2063 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
2064 assert(child);
2066 ret = GetMenu(child);
2067 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2069 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2070 test_nonclient_area(child);
2071 ret = GetMenu(child);
2072 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2074 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
2075 test_nonclient_area(child);
2076 ret = GetMenu(child);
2077 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2079 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
2080 test_nonclient_area(child);
2081 ret = GetMenu(child);
2082 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2084 style = GetWindowLong(child, GWL_STYLE);
2085 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
2086 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
2087 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
2088 SetWindowLong(child, GWL_STYLE, style);
2090 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
2091 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
2092 SetWindowLong(child, GWL_STYLE, style);
2094 DestroyWindow(child);
2095 DestroyMenu(hMenu);
2098 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
2100 HWND child[5], hwnd;
2101 INT_PTR i;
2103 assert(total <= 5);
2105 hwnd = GetWindow(parent, GW_CHILD);
2106 ok(!hwnd, "have to start without children to perform the test\n");
2108 for (i = 0; i < total; i++)
2110 if (style[i] & DS_CONTROL)
2112 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
2113 0,0,0,0, parent, (HMENU)i, 0, NULL);
2114 if (style[i] & WS_VISIBLE)
2115 ShowWindow(child[i], SW_SHOW);
2117 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
2119 else
2120 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
2121 parent, (HMENU)i, 0, NULL);
2122 trace("child[%ld] = %p\n", i, child[i]);
2123 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
2126 hwnd = GetWindow(parent, GW_CHILD);
2127 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
2128 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
2129 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
2131 for (i = 0; i < total; i++)
2133 trace("hwnd[%ld] = %p\n", i, hwnd);
2134 ok(child[order[i]] == hwnd, "Z order of child #%ld is wrong\n", i);
2136 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
2139 for (i = 0; i < total; i++)
2140 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2143 static void test_children_zorder(HWND parent)
2145 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2146 WS_CHILD };
2147 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2149 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2150 WS_CHILD | WS_VISIBLE, WS_CHILD,
2151 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2152 const int complex_order_1[1] = { 0 };
2153 const int complex_order_2[2] = { 1, 0 };
2154 const int complex_order_3[3] = { 1, 0, 2 };
2155 const int complex_order_4[4] = { 1, 0, 2, 3 };
2156 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2157 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2158 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2159 WS_CHILD | WS_VISIBLE };
2160 const int complex_order_6[3] = { 0, 1, 2 };
2162 /* simple WS_CHILD */
2163 test_window_tree(parent, simple_style, simple_order, 5);
2165 /* complex children styles */
2166 test_window_tree(parent, complex_style, complex_order_1, 1);
2167 test_window_tree(parent, complex_style, complex_order_2, 2);
2168 test_window_tree(parent, complex_style, complex_order_3, 3);
2169 test_window_tree(parent, complex_style, complex_order_4, 4);
2170 test_window_tree(parent, complex_style, complex_order_5, 5);
2172 /* another set of complex children styles */
2173 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2176 #define check_z_order(hwnd, next, prev, owner, topmost) \
2177 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2178 __FILE__, __LINE__)
2180 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2181 BOOL topmost, const char *file, int line)
2183 HWND test;
2184 DWORD ex_style;
2186 test = GetWindow(hwnd, GW_HWNDNEXT);
2187 /* skip foreign windows */
2188 while (test && test != next &&
2189 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2190 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2191 GetWindow(test, GW_OWNER) == next))
2193 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2194 test = GetWindow(test, GW_HWNDNEXT);
2196 ok_(file, line)(next == test, "%p: expected next %p, got %p\n", hwnd, next, test);
2198 test = GetWindow(hwnd, GW_HWNDPREV);
2199 /* skip foreign windows */
2200 while (test && test != prev &&
2201 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2202 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2203 GetWindow(test, GW_OWNER) == hwnd))
2205 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2206 test = GetWindow(test, GW_HWNDPREV);
2208 ok_(file, line)(prev == test, "%p: expected prev %p, got %p\n", hwnd, prev, test);
2210 test = GetWindow(hwnd, GW_OWNER);
2211 ok_(file, line)(owner == test, "%p: expected owner %p, got %p\n", hwnd, owner, test);
2213 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2214 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "%p: expected %stopmost\n",
2215 hwnd, topmost ? "" : "NOT ");
2218 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E, DWORD style)
2220 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2222 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2224 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2226 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2227 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2229 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2230 WS_OVERLAPPED | WS_CAPTION,
2231 100, 100, 100, 100,
2232 0, 0, GetModuleHandle(0), NULL);
2233 trace("hwnd_F %p\n", hwnd_F);
2234 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2236 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2237 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2238 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2239 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2241 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2242 style,
2243 100, 100, 100, 100,
2244 hwnd_F, 0, GetModuleHandle(0), NULL);
2245 trace("hwnd_C %p\n", hwnd_C);
2246 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2247 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2248 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2249 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2251 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2252 style,
2253 100, 100, 100, 100,
2254 hwnd_F, 0, GetModuleHandle(0), NULL);
2255 trace("hwnd_B %p\n", hwnd_B);
2256 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2257 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2258 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2259 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2260 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2262 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2263 style,
2264 100, 100, 100, 100,
2265 0, 0, GetModuleHandle(0), NULL);
2266 trace("hwnd_A %p\n", hwnd_A);
2267 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2268 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2269 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2270 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2271 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2272 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2274 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);
2276 /* move hwnd_F and its popups up */
2277 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2278 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2279 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2280 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2281 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2282 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2283 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2285 /* move hwnd_F and its popups down */
2286 #if 0 /* enable once Wine is fixed to pass this test */
2287 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2288 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2289 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2290 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2291 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2292 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2293 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2294 #endif
2296 /* make hwnd_C owned by a topmost window */
2297 DestroyWindow( hwnd_C );
2298 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2299 style,
2300 100, 100, 100, 100,
2301 hwnd_A, 0, GetModuleHandle(0), NULL);
2302 trace("hwnd_C %p\n", hwnd_C);
2303 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2304 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2305 check_z_order(hwnd_F, hwnd_D, hwnd_B, 0, FALSE);
2306 check_z_order(hwnd_B, hwnd_F, hwnd_A, hwnd_F, TRUE);
2307 check_z_order(hwnd_A, hwnd_B, hwnd_C, 0, TRUE);
2308 check_z_order(hwnd_C, hwnd_A, 0, hwnd_A, TRUE);
2310 DestroyWindow(hwnd_A);
2311 DestroyWindow(hwnd_B);
2312 DestroyWindow(hwnd_C);
2313 DestroyWindow(hwnd_F);
2316 static void test_vis_rgn( HWND hwnd )
2318 RECT win_rect, rgn_rect;
2319 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2320 HDC hdc;
2322 ShowWindow(hwnd,SW_SHOW);
2323 hdc = GetDC( hwnd );
2324 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2325 GetWindowRect( hwnd, &win_rect );
2326 GetRgnBox( hrgn, &rgn_rect );
2327 if (is_win9x)
2329 trace("win9x, mapping to screen coords\n");
2330 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2332 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2333 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2334 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2335 rgn_rect.left, win_rect.left );
2336 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2337 rgn_rect.top, win_rect.top );
2338 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2339 rgn_rect.right, win_rect.right );
2340 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2341 rgn_rect.bottom, win_rect.bottom );
2342 ReleaseDC( hwnd, hdc );
2345 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2347 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2349 HWND child = GetWindow(hwnd, GW_CHILD);
2350 ok(child != 0, "couldn't find child window\n");
2351 SetFocus(child);
2352 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2353 return 0;
2355 return DefWindowProc(hwnd, msg, wp, lp);
2358 static void test_SetFocus(HWND hwnd)
2360 HWND child, child2;
2361 WNDPROC old_wnd_proc;
2363 /* check if we can set focus to non-visible windows */
2365 ShowWindow(hwnd, SW_SHOW);
2366 SetFocus(0);
2367 SetFocus(hwnd);
2368 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2369 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2370 ShowWindow(hwnd, SW_HIDE);
2371 SetFocus(0);
2372 SetFocus(hwnd);
2373 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2374 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2375 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2376 assert(child);
2377 SetFocus(child);
2378 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2379 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2380 ShowWindow(child, SW_SHOW);
2381 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2382 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2383 ShowWindow(child, SW_HIDE);
2384 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2385 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2386 ShowWindow(child, SW_SHOW);
2387 child2 = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, child, 0, 0, NULL);
2388 assert(child2);
2389 ShowWindow(child2, SW_SHOW);
2390 SetFocus(child2);
2391 ShowWindow(child, SW_HIDE);
2392 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2393 ok( GetFocus() == child2, "Focus should be on %p, not %p\n", child2, GetFocus() );
2394 ShowWindow(child, SW_SHOW);
2395 SetFocus(child);
2396 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2397 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2398 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2400 ShowWindow(child, SW_HIDE);
2401 SetFocus(hwnd);
2402 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2403 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2404 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2405 ShowWindow(child, SW_HIDE);
2406 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2408 ShowWindow(hwnd, SW_SHOW);
2409 ShowWindow(child, SW_SHOW);
2410 SetFocus(child);
2411 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2412 EnableWindow(hwnd, FALSE);
2413 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2414 EnableWindow(hwnd, TRUE);
2416 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2417 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2418 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2419 todo_wine
2420 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2421 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2422 ShowWindow(hwnd, SW_RESTORE);
2423 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2424 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2425 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2426 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2427 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2428 todo_wine
2429 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2430 old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2431 ShowWindow(hwnd, SW_RESTORE);
2432 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2433 todo_wine
2434 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2436 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2438 DestroyWindow( child2 );
2439 DestroyWindow( child );
2442 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
2443 static void check_wnd_state_(const char *file, int line,
2444 HWND active, HWND foreground, HWND focus, HWND capture)
2446 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2447 /* only check foreground if it belongs to the current thread */
2448 /* foreground can be moved to a different app pretty much at any time */
2449 if (foreground && GetForegroundWindow() &&
2450 GetWindowThreadProcessId(GetForegroundWindow(), NULL) == GetCurrentThreadId())
2451 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2452 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2453 ok_(file, line)(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2456 static void test_SetActiveWindow(HWND hwnd)
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 SetActiveWindow %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 returned %p instead of %p\n", hwnd2, hwnd);
2473 if (!GetActiveWindow()) /* doesn't always work on vista */
2475 check_wnd_state(0, 0, 0, 0);
2476 hwnd2 = SetActiveWindow(hwnd);
2477 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2479 check_wnd_state(hwnd, hwnd, hwnd, 0);
2481 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2482 check_wnd_state(hwnd, hwnd, hwnd, 0);
2484 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2485 check_wnd_state(hwnd, hwnd, hwnd, 0);
2487 ShowWindow(hwnd, SW_HIDE);
2488 check_wnd_state(0, 0, 0, 0);
2490 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2491 SetActiveWindow(hwnd);
2492 check_wnd_state(hwnd, hwnd, hwnd, 0);
2494 ShowWindow(hwnd, SW_SHOW);
2495 check_wnd_state(hwnd, hwnd, hwnd, 0);
2497 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2498 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2500 DestroyWindow(hwnd2);
2501 check_wnd_state(hwnd, hwnd, hwnd, 0);
2503 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2504 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2506 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2507 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2509 DestroyWindow(hwnd2);
2510 check_wnd_state(hwnd, hwnd, hwnd, 0);
2513 struct create_window_thread_params
2515 HWND window;
2516 HANDLE window_created;
2517 HANDLE test_finished;
2520 static DWORD WINAPI create_window_thread(void *param)
2522 struct create_window_thread_params *p = param;
2523 DWORD res;
2524 BOOL ret;
2526 p->window = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
2528 ret = SetEvent(p->window_created);
2529 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
2531 res = WaitForSingleObject(p->test_finished, INFINITE);
2532 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2534 DestroyWindow(p->window);
2535 return 0;
2538 static void test_SetForegroundWindow(HWND hwnd)
2540 struct create_window_thread_params thread_params;
2541 HANDLE thread;
2542 DWORD res, tid;
2543 BOOL ret;
2544 HWND hwnd2;
2545 MSG msg;
2547 flush_events( TRUE );
2548 ShowWindow(hwnd, SW_HIDE);
2549 SetFocus(0);
2550 SetActiveWindow(0);
2551 check_wnd_state(0, 0, 0, 0);
2553 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2555 ShowWindow(hwnd, SW_SHOW);
2556 check_wnd_state(hwnd, hwnd, hwnd, 0);
2558 hwnd2 = SetActiveWindow(0);
2559 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2560 if (GetActiveWindow() == hwnd) /* doesn't always work on vista */
2561 check_wnd_state(hwnd, hwnd, hwnd, 0);
2562 else
2563 check_wnd_state(0, 0, 0, 0);
2565 ret = SetForegroundWindow(hwnd);
2566 if (!ret)
2568 skip( "SetForegroundWindow not working\n" );
2569 return;
2571 check_wnd_state(hwnd, hwnd, hwnd, 0);
2573 SetLastError(0xdeadbeef);
2574 ret = SetForegroundWindow(0);
2575 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2576 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
2577 broken(GetLastError() == 0xdeadbeef), /* win9x */
2578 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2579 check_wnd_state(hwnd, hwnd, hwnd, 0);
2581 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2582 check_wnd_state(hwnd, hwnd, hwnd, 0);
2584 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2585 check_wnd_state(hwnd, hwnd, hwnd, 0);
2587 hwnd2 = GetForegroundWindow();
2588 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2589 ret = SetForegroundWindow( GetDesktopWindow() );
2590 ok(ret, "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2591 hwnd2 = GetForegroundWindow();
2592 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2594 ShowWindow(hwnd, SW_HIDE);
2595 check_wnd_state(0, 0, 0, 0);
2597 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2598 ret = SetForegroundWindow(hwnd);
2599 ok(ret || broken(!ret), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
2600 check_wnd_state(hwnd, hwnd, hwnd, 0);
2602 ShowWindow(hwnd, SW_SHOW);
2603 check_wnd_state(hwnd, hwnd, hwnd, 0);
2605 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2606 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2608 DestroyWindow(hwnd2);
2609 check_wnd_state(hwnd, hwnd, hwnd, 0);
2611 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2612 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2614 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2615 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2617 DestroyWindow(hwnd2);
2618 check_wnd_state(hwnd, hwnd, hwnd, 0);
2620 hwnd2 = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
2621 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2623 thread_params.window_created = CreateEvent(NULL, FALSE, FALSE, NULL);
2624 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
2625 thread_params.test_finished = CreateEvent(NULL, FALSE, FALSE, NULL);
2626 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
2627 thread = CreateThread(NULL, 0, create_window_thread, &thread_params, 0, &tid);
2628 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
2629 res = WaitForSingleObject(thread_params.window_created, INFINITE);
2630 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2631 check_wnd_state(hwnd2, thread_params.window, hwnd2, 0);
2633 SetForegroundWindow(hwnd2);
2634 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2636 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
2637 if (0) check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2638 todo_wine ok(GetActiveWindow() == hwnd2, "Expected active window %p, got %p.\n", hwnd2, GetActiveWindow());
2639 todo_wine ok(GetFocus() == hwnd2, "Expected focus window %p, got %p.\n", hwnd2, GetFocus());
2641 SetEvent(thread_params.test_finished);
2642 WaitForSingleObject(thread, INFINITE);
2643 CloseHandle(thread_params.test_finished);
2644 CloseHandle(thread_params.window_created);
2645 CloseHandle(thread);
2646 DestroyWindow(hwnd2);
2649 static WNDPROC old_button_proc;
2651 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2653 LRESULT ret;
2654 USHORT key_state;
2656 key_state = GetKeyState(VK_LBUTTON);
2657 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2659 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2661 if (msg == WM_LBUTTONDOWN)
2663 HWND hwnd, capture;
2665 check_wnd_state(button, button, button, button);
2667 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2668 assert(hwnd);
2669 trace("hwnd %p\n", hwnd);
2671 check_wnd_state(button, button, button, button);
2673 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2675 check_wnd_state(button, button, button, button);
2677 DestroyWindow(hwnd);
2679 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2680 assert(hwnd);
2681 trace("hwnd %p\n", hwnd);
2683 check_wnd_state(button, button, button, button);
2685 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2686 * match internal button state.
2688 SendMessage(button, WM_KILLFOCUS, 0, 0);
2689 check_wnd_state(button, button, button, 0);
2691 ShowWindow(hwnd, SW_SHOW);
2692 check_wnd_state(hwnd, hwnd, hwnd, 0);
2694 capture = SetCapture(hwnd);
2695 ok(capture == 0, "SetCapture() = %p\n", capture);
2697 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2699 DestroyWindow(hwnd);
2701 check_wnd_state(button, 0, button, 0);
2704 return ret;
2707 static void test_capture_1(void)
2709 HWND button, capture, oldFocus, oldActive;
2711 oldFocus = GetFocus();
2712 oldActive = GetActiveWindow();
2714 capture = GetCapture();
2715 ok(capture == 0, "GetCapture() = %p\n", capture);
2717 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2718 assert(button);
2719 trace("button %p\n", button);
2721 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2723 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2725 capture = SetCapture(button);
2726 ok(capture == 0, "SetCapture() = %p\n", capture);
2727 check_wnd_state(button, 0, button, button);
2729 DestroyWindow(button);
2730 check_wnd_state(oldActive, 0, oldFocus, 0);
2733 static void test_capture_2(void)
2735 HWND button, hwnd, capture, oldFocus, oldActive;
2737 oldFocus = GetFocus();
2738 oldActive = GetActiveWindow();
2739 check_wnd_state(oldActive, 0, oldFocus, 0);
2741 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2742 assert(button);
2743 trace("button %p\n", button);
2745 check_wnd_state(button, button, button, 0);
2747 capture = SetCapture(button);
2748 ok(capture == 0, "SetCapture() = %p\n", capture);
2750 check_wnd_state(button, button, button, button);
2752 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2753 * internal button state.
2755 SendMessage(button, WM_KILLFOCUS, 0, 0);
2756 check_wnd_state(button, button, button, button);
2758 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2759 assert(hwnd);
2760 trace("hwnd %p\n", hwnd);
2762 check_wnd_state(button, button, button, button);
2764 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2766 check_wnd_state(button, button, button, button);
2768 DestroyWindow(hwnd);
2770 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2771 assert(hwnd);
2772 trace("hwnd %p\n", hwnd);
2774 check_wnd_state(button, button, button, button);
2776 ShowWindow(hwnd, SW_SHOW);
2778 check_wnd_state(hwnd, hwnd, hwnd, button);
2780 capture = SetCapture(hwnd);
2781 ok(capture == button, "SetCapture() = %p\n", capture);
2783 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2785 DestroyWindow(hwnd);
2786 check_wnd_state(button, button, button, 0);
2788 DestroyWindow(button);
2789 check_wnd_state(oldActive, 0, oldFocus, 0);
2792 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2794 BOOL ret;
2796 ShowWindow(hwnd1, SW_HIDE);
2797 ShowWindow(hwnd2, SW_HIDE);
2799 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2800 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2802 SetCapture(hwnd1);
2803 check_wnd_state(0, 0, 0, hwnd1);
2805 SetCapture(hwnd2);
2806 check_wnd_state(0, 0, 0, hwnd2);
2808 ShowWindow(hwnd1, SW_SHOW);
2809 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2811 ret = ReleaseCapture();
2812 ok (ret, "releasecapture did not return TRUE.\n");
2813 ret = ReleaseCapture();
2814 ok (ret, "releasecapture did not return TRUE after second try.\n");
2817 static LRESULT CALLBACK test_capture_4_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2819 GUITHREADINFO gti;
2820 HWND cap_wnd, cap_wnd2, set_cap_wnd;
2821 BOOL status;
2822 switch (msg)
2824 case WM_CAPTURECHANGED:
2826 /* now try to release capture from menu. this should fail */
2827 if (pGetGUIThreadInfo)
2829 memset(&gti, 0, sizeof(GUITHREADINFO));
2830 gti.cbSize = sizeof(GUITHREADINFO);
2831 status = pGetGUIThreadInfo(GetCurrentThreadId(), &gti);
2832 ok(status, "GetGUIThreadInfo() failed!\n");
2833 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
2835 cap_wnd = GetCapture();
2837 /* check that re-setting the capture for the menu fails */
2838 set_cap_wnd = SetCapture(cap_wnd);
2839 ok(!set_cap_wnd || broken(set_cap_wnd == cap_wnd), /* nt4 */
2840 "SetCapture should have failed!\n");
2841 if (set_cap_wnd)
2843 DestroyWindow(hWnd);
2844 break;
2847 /* check that SetCapture fails for another window and that it does not touch the error code */
2848 set_cap_wnd = SetCapture(hWnd);
2849 ok(!set_cap_wnd, "SetCapture should have failed!\n");
2851 /* check that ReleaseCapture fails and does not touch the error code */
2852 status = ReleaseCapture();
2853 ok(!status, "ReleaseCapture should have failed!\n");
2855 /* check that thread info did not change */
2856 if (pGetGUIThreadInfo)
2858 memset(&gti, 0, sizeof(GUITHREADINFO));
2859 gti.cbSize = sizeof(GUITHREADINFO);
2860 status = pGetGUIThreadInfo(GetCurrentThreadId(), &gti);
2861 ok(status, "GetGUIThreadInfo() failed!\n");
2862 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
2865 /* verify that no capture change took place */
2866 cap_wnd2 = GetCapture();
2867 ok(cap_wnd2 == cap_wnd, "Capture changed!\n");
2869 /* we are done. kill the window */
2870 DestroyWindow(hWnd);
2871 break;
2873 default:
2874 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
2876 return 0;
2879 /* Test that no-one can mess around with the current capture while a menu is open */
2880 static void test_capture_4(void)
2882 BOOL ret;
2883 HMENU hmenu;
2884 HWND hwnd;
2885 WNDCLASSA wclass;
2886 HINSTANCE hInstance = GetModuleHandleA( NULL );
2888 if (!pGetGUIThreadInfo)
2890 win_skip("GetGUIThreadInfo is not available\n");
2891 return;
2893 wclass.lpszClassName = "TestCapture4Class";
2894 wclass.style = CS_HREDRAW | CS_VREDRAW;
2895 wclass.lpfnWndProc = test_capture_4_proc;
2896 wclass.hInstance = hInstance;
2897 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
2898 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
2899 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2900 wclass.lpszMenuName = 0;
2901 wclass.cbClsExtra = 0;
2902 wclass.cbWndExtra = 0;
2903 assert (RegisterClassA( &wclass ));
2904 assert (hwnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
2905 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2906 400, 200, NULL, NULL, hInstance, NULL) );
2907 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
2908 if (!hwnd) return;
2909 hmenu = CreatePopupMenu();
2911 ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest2");
2912 ok( ret, "AppendMenuA has failed!\n");
2914 /* set main window to have initial capture */
2915 SetCapture(hwnd);
2917 if (is_win9x)
2919 win_skip("TrackPopupMenu test crashes on Win9x/WinMe\n");
2921 else
2923 /* create popup (it will self-destruct) */
2924 ret = TrackPopupMenu(hmenu, TPM_RETURNCMD, 100, 100, 0, hwnd, NULL);
2925 ok( ret == 0, "TrackPopupMenu returned %d expected zero\n", ret);
2928 /* clean up */
2929 DestroyMenu(hmenu);
2930 DestroyWindow(hwnd);
2933 /* PeekMessage wrapper that ignores the messages we don't care about */
2934 static BOOL peek_message( MSG *msg )
2936 BOOL ret;
2939 ret = PeekMessageA(msg, 0, 0, 0, PM_REMOVE);
2940 } while (ret && (msg->message == WM_TIMER || ignore_message(msg->message)));
2941 return ret;
2944 static void test_keyboard_input(HWND hwnd)
2946 MSG msg;
2947 BOOL ret;
2949 flush_events( TRUE );
2950 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
2951 UpdateWindow(hwnd);
2952 flush_events( TRUE );
2954 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2956 SetFocus(hwnd);
2957 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2959 flush_events( TRUE );
2961 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2962 ret = peek_message(&msg);
2963 ok( ret, "no message available\n");
2964 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2965 ret = peek_message(&msg);
2966 ok( !ret, "message %04x available\n", msg.message);
2968 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2970 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2971 ret = peek_message(&msg);
2972 ok(ret, "no message available\n");
2973 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2974 ret = peek_message(&msg);
2975 ok( !ret, "message %04x available\n", msg.message);
2977 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2979 keybd_event(VK_SPACE, 0, 0, 0);
2980 if (!peek_message(&msg))
2982 skip( "keybd_event didn't work, skipping keyboard test\n" );
2983 return;
2985 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2986 ret = peek_message(&msg);
2987 ok( !ret, "message %04x available\n", msg.message);
2989 SetFocus(0);
2990 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2992 flush_events( TRUE );
2994 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2995 ret = peek_message(&msg);
2996 ok(ret, "no message available\n");
2997 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2998 ret = peek_message(&msg);
2999 ok( !ret, "message %04x available\n", msg.message);
3001 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3003 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
3004 ret = peek_message(&msg);
3005 ok(ret, "no message available\n");
3006 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3007 ret = peek_message(&msg);
3008 ok( !ret, "message %04x available\n", msg.message);
3010 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3012 keybd_event(VK_SPACE, 0, 0, 0);
3013 ret = peek_message(&msg);
3014 ok(ret, "no message available\n");
3015 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3016 ret = peek_message(&msg);
3017 ok( !ret, "message %04x available\n", msg.message);
3020 static BOOL wait_for_message( MSG *msg )
3022 BOOL ret;
3024 for (;;)
3026 ret = peek_message(msg);
3027 if (ret)
3029 if (msg->message == WM_PAINT) DispatchMessage(msg);
3030 else break;
3032 else if (MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
3034 if (!ret) msg->message = 0;
3035 return ret;
3038 static void test_mouse_input(HWND hwnd)
3040 RECT rc;
3041 POINT pt;
3042 int x, y;
3043 HWND popup;
3044 MSG msg;
3045 BOOL ret;
3046 LRESULT res;
3048 ShowWindow(hwnd, SW_SHOWNORMAL);
3049 UpdateWindow(hwnd);
3050 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3052 GetWindowRect(hwnd, &rc);
3053 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
3055 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
3056 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
3057 hwnd, 0, 0, NULL);
3058 assert(popup != 0);
3059 ShowWindow(popup, SW_SHOW);
3060 UpdateWindow(popup);
3061 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3063 GetWindowRect(popup, &rc);
3064 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
3066 x = rc.left + (rc.right - rc.left) / 2;
3067 y = rc.top + (rc.bottom - rc.top) / 2;
3068 trace("setting cursor to (%d,%d)\n", x, y);
3070 SetCursorPos(x, y);
3071 GetCursorPos(&pt);
3072 if (x != pt.x || y != pt.y)
3074 skip( "failed to set mouse position, skipping mouse input tests\n" );
3075 goto done;
3078 flush_events( TRUE );
3080 /* Check that setting the same position may generate WM_MOUSEMOVE */
3081 SetCursorPos(x, y);
3082 msg.message = 0;
3083 ret = peek_message(&msg);
3084 if (ret)
3086 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
3087 msg.hwnd, msg.message);
3088 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
3089 x, y, msg.pt.x, msg.pt.y);
3092 /* force the system to update its internal queue mouse position,
3093 * otherwise it won't generate relative mouse movements below.
3095 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3096 flush_events( TRUE );
3098 msg.message = 0;
3099 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3100 flush_events( FALSE );
3101 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
3102 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
3104 if (msg.message == WM_TIMER || ignore_message(msg.message)) continue;
3105 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
3106 "hwnd %p message %04x\n", msg.hwnd, msg.message);
3107 DispatchMessage(&msg);
3109 ret = peek_message(&msg);
3110 ok( !ret, "message %04x available\n", msg.message);
3112 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3113 ShowWindow(popup, SW_HIDE);
3114 ret = wait_for_message( &msg );
3115 if (ret)
3116 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3117 flush_events( TRUE );
3119 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3120 ShowWindow(hwnd, SW_HIDE);
3121 ret = wait_for_message( &msg );
3122 ok( !ret, "message %04x available\n", msg.message);
3123 flush_events( TRUE );
3125 /* test mouse clicks */
3127 ShowWindow(hwnd, SW_SHOW);
3128 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3129 flush_events( TRUE );
3130 ShowWindow(popup, SW_SHOW);
3131 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3132 flush_events( TRUE );
3134 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3135 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3136 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3137 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3139 ret = wait_for_message( &msg );
3140 if (!ret)
3142 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
3143 goto done;
3145 if (msg.message == WM_MOUSEMOVE) /* win2k has an extra WM_MOUSEMOVE here */
3147 ret = wait_for_message( &msg );
3148 ok(ret, "no message available\n");
3151 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3152 msg.hwnd, popup, msg.message);
3154 ret = wait_for_message( &msg );
3155 ok(ret, "no message available\n");
3156 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3157 msg.hwnd, popup, msg.message);
3159 ret = wait_for_message( &msg );
3160 ok(ret, "no message available\n");
3161 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
3162 msg.hwnd, popup, msg.message);
3164 ret = wait_for_message( &msg );
3165 ok(ret, "no message available\n");
3166 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3167 msg.hwnd, popup, msg.message);
3169 ret = peek_message(&msg);
3170 ok(!ret, "message %04x available\n", msg.message);
3172 ShowWindow(popup, SW_HIDE);
3173 flush_events( TRUE );
3175 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3176 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3177 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3178 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3180 ret = wait_for_message( &msg );
3181 ok(ret, "no message available\n");
3182 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3183 msg.hwnd, hwnd, msg.message);
3184 ret = wait_for_message( &msg );
3185 ok(ret, "no message available\n");
3186 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3187 msg.hwnd, hwnd, msg.message);
3189 test_lbuttondown_flag = TRUE;
3190 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
3191 test_lbuttondown_flag = FALSE;
3193 ret = wait_for_message( &msg );
3194 ok(ret, "no message available\n");
3195 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3196 msg.hwnd, popup, msg.message);
3197 ok(peek_message(&msg), "no message available\n");
3198 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3199 msg.hwnd, popup, msg.message);
3200 ok(peek_message(&msg), "no message available\n");
3202 /* Test WM_MOUSEACTIVATE */
3203 #define TEST_MOUSEACTIVATE(A,B) \
3204 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
3205 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
3207 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
3208 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
3209 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
3210 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
3211 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
3212 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
3213 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
3214 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
3215 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
3216 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
3217 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
3218 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
3219 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
3220 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
3221 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
3222 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
3223 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
3224 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
3225 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
3226 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
3227 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
3228 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
3229 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
3230 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
3232 done:
3233 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
3234 flush_events( TRUE );
3236 DestroyWindow(popup);
3239 static void test_validatergn(HWND hwnd)
3241 HWND child;
3242 RECT rc, rc2;
3243 HRGN rgn;
3244 int ret;
3245 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
3246 ShowWindow(hwnd, SW_SHOW);
3247 UpdateWindow( hwnd);
3248 /* test that ValidateRect validates children*/
3249 InvalidateRect( child, NULL, 1);
3250 GetWindowRect( child, &rc);
3251 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3252 ret = GetUpdateRect( child, &rc2, 0);
3253 ok( ret == 1, "Expected GetUpdateRect to return non-zero, got %d\n", ret);
3254 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
3255 "Update rectangle is empty!\n");
3256 ValidateRect( hwnd, &rc);
3257 ret = GetUpdateRect( child, &rc2, 0);
3258 ok( !ret, "Expected GetUpdateRect to return zero, got %d\n", ret);
3259 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3260 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3261 rc2.right, rc2.bottom);
3263 /* now test ValidateRgn */
3264 InvalidateRect( child, NULL, 1);
3265 GetWindowRect( child, &rc);
3266 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3267 rgn = CreateRectRgnIndirect( &rc);
3268 ValidateRgn( hwnd, rgn);
3269 ret = GetUpdateRect( child, &rc2, 0);
3270 ok( !ret, "Expected GetUpdateRect to return zero, got %d\n", ret);
3271 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3272 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3273 rc2.right, rc2.bottom);
3275 DeleteObject( rgn);
3276 DestroyWindow( child );
3279 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
3281 RECT rc;
3282 MoveWindow( hwnd, 0, 0, x, y, 0);
3283 GetWindowRect( hwnd, prc);
3284 rc = *prc;
3285 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
3286 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
3287 rc.left,rc.top,rc.right,rc.bottom, prc->left,prc->top,prc->right,prc->bottom);
3290 static void test_nccalcscroll(HWND parent)
3292 RECT rc1;
3293 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
3294 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
3295 HWND hwnd = CreateWindowExA(0, "static", NULL,
3296 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
3297 10, 10, 200, 200, parent, 0, 0, NULL);
3298 ShowWindow( parent, SW_SHOW);
3299 UpdateWindow( parent);
3301 /* test window too low for a horizontal scroll bar */
3302 nccalchelper( hwnd, 100, sbheight, &rc1);
3303 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
3304 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
3306 /* test window just high enough for a horizontal scroll bar */
3307 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
3308 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
3309 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3311 /* test window too narrow for a vertical scroll bar */
3312 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
3313 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
3314 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3316 /* test window just wide enough for a vertical scroll bar */
3317 nccalchelper( hwnd, sbwidth, 100, &rc1);
3318 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
3319 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
3321 /* same test, but with client edge: not enough width */
3322 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
3323 nccalchelper( hwnd, sbwidth, 100, &rc1);
3324 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
3325 "Width should be %d size is %d,%d - %d,%d\n",
3326 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
3328 DestroyWindow( hwnd);
3331 static void test_SetParent(void)
3333 BOOL ret;
3334 HWND desktop = GetDesktopWindow();
3335 HMENU hMenu;
3336 HWND parent, child1, child2, child3, child4, sibling;
3338 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3339 100, 100, 200, 200, 0, 0, 0, NULL);
3340 assert(parent != 0);
3341 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3342 0, 0, 50, 50, parent, 0, 0, NULL);
3343 assert(child1 != 0);
3344 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3345 0, 0, 50, 50, child1, 0, 0, NULL);
3346 assert(child2 != 0);
3347 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3348 0, 0, 50, 50, child2, 0, 0, NULL);
3349 assert(child3 != 0);
3350 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3351 0, 0, 50, 50, child3, 0, 0, NULL);
3352 assert(child4 != 0);
3354 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
3355 parent, child1, child2, child3, child4);
3357 check_parents(parent, desktop, 0, 0, 0, parent, parent);
3358 check_parents(child1, parent, parent, parent, 0, parent, parent);
3359 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3360 check_parents(child3, child2, child2, child2, 0, child2, parent);
3361 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3363 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
3364 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
3365 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3366 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
3367 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3369 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
3370 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3371 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
3372 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
3373 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
3374 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
3375 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
3376 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3377 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3379 if (!is_win9x) /* Win9x doesn't survive this test */
3381 HWND ret;
3383 ok(!SetParent(parent, child1), "SetParent should fail\n");
3384 ok(!SetParent(child2, child3), "SetParent should fail\n");
3385 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
3386 ret = SetParent(parent, child2);
3387 todo_wine ok( !ret || broken( ret != 0 ), "SetParent should fail\n");
3388 if (ret) /* nt4, win2k */
3390 ret = SetParent(parent, child3);
3391 ok(ret != 0, "SetParent should not fail\n");
3392 ret = SetParent(child2, parent);
3393 ok(!ret, "SetParent should fail\n");
3394 ret = SetParent(parent, child4);
3395 ok(ret != 0, "SetParent should not fail\n");
3396 check_parents(parent, child4, child4, 0, 0, child4, parent);
3397 check_parents(child1, parent, parent, parent, 0, child4, parent);
3398 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3399 check_parents(child3, child2, child2, child2, 0, child2, parent);
3400 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3402 else
3404 ret = SetParent(parent, child3);
3405 ok(ret != 0, "SetParent should not fail\n");
3406 ret = SetParent(child2, parent);
3407 ok(!ret, "SetParent should fail\n");
3408 ret = SetParent(parent, child4);
3409 ok(!ret, "SetParent should fail\n");
3410 check_parents(parent, child3, child3, 0, 0, child2, parent);
3411 check_parents(child1, parent, parent, parent, 0, child2, parent);
3412 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3413 check_parents(child3, child2, child2, child2, 0, child2, parent);
3414 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3417 else
3418 skip("Win9x/WinMe crash\n");
3420 hMenu = CreateMenu();
3421 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3422 100, 100, 200, 200, 0, hMenu, 0, NULL);
3423 assert(sibling != 0);
3425 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
3426 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
3428 ret = DestroyWindow(parent);
3429 ok( ret, "DestroyWindow() error %d\n", GetLastError());
3431 ok(!IsWindow(parent), "parent still exists\n");
3432 ok(!IsWindow(sibling), "sibling still exists\n");
3433 ok(!IsWindow(child1), "child1 still exists\n");
3434 ok(!IsWindow(child2), "child2 still exists\n");
3435 ok(!IsWindow(child3), "child3 still exists\n");
3436 ok(!IsWindow(child4), "child4 still exists\n");
3439 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3441 LPCREATESTRUCT lpcs;
3442 LPSTYLESTRUCT lpss;
3444 switch (msg)
3446 case WM_NCCREATE:
3447 case WM_CREATE:
3448 lpcs = (LPCREATESTRUCT)lparam;
3449 lpss = lpcs->lpCreateParams;
3450 if (lpss)
3452 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
3453 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
3454 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
3455 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
3456 else
3457 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3459 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
3460 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
3461 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
3463 ok(lpss->styleNew == lpcs->style,
3464 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3465 lpss->styleNew, lpcs->style);
3467 break;
3469 return DefWindowProc(hwnd, msg, wparam, lparam);
3472 static ATOM atomStyleCheckClass;
3474 static void register_style_check_class(void)
3476 WNDCLASS wc =
3479 StyleCheckProc,
3482 GetModuleHandle(NULL),
3483 NULL,
3484 LoadCursor(NULL, IDC_ARROW),
3485 (HBRUSH)(COLOR_BTNFACE+1),
3486 NULL,
3487 TEXT("WineStyleCheck"),
3490 atomStyleCheckClass = RegisterClass(&wc);
3493 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3495 DWORD dwActualStyle;
3496 DWORD dwActualExStyle;
3497 STYLESTRUCT ss;
3498 HWND hwnd;
3499 HWND hwndParent = NULL;
3501 ss.styleNew = dwStyleIn;
3502 ss.styleOld = dwExStyleIn;
3504 if (dwStyleIn & WS_CHILD)
3506 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
3507 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3510 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
3511 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3512 assert(hwnd);
3514 flush_events( TRUE );
3516 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3517 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3518 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3519 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3520 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3522 /* try setting the styles explicitly */
3523 SetWindowLong( hwnd, GWL_EXSTYLE, dwExStyleIn );
3524 SetWindowLong( hwnd, GWL_STYLE, dwStyleIn );
3525 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3526 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3527 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3528 if (dwStyleIn & WS_CHILD) dwStyleOut = dwStyleIn;
3529 else dwStyleOut = dwStyleIn | WS_CLIPSIBLINGS;
3530 /* WS_EX_WINDOWEDGE can't always be changed */
3531 if ((dwExStyleIn & WS_EX_DLGMODALFRAME) || (dwStyleIn & WS_THICKFRAME))
3532 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3533 else if (dwStyleIn & (WS_CHILD | WS_POPUP))
3534 dwExStyleOut = dwExStyleIn & ~WS_EX_WINDOWEDGE;
3535 else
3536 dwExStyleOut = dwExStyleIn;
3537 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3538 "%08x/%08x: Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3539 dwStyleIn, dwExStyleIn, dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3541 DestroyWindow(hwnd);
3542 if (hwndParent) DestroyWindow(hwndParent);
3545 /* tests what window styles the window manager automatically adds */
3546 static void test_window_styles(void)
3548 register_style_check_class();
3550 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3551 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3552 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3553 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3554 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3555 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3556 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3557 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3558 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3559 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3560 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3562 if (pGetLayeredWindowAttributes)
3564 check_window_style(0, WS_EX_LAYERED, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_WINDOWEDGE);
3565 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_WINDOWEDGE);
3566 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION,
3567 WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW|WS_EX_WINDOWEDGE);
3571 static void test_scrollwindow( HWND hwnd)
3573 HDC hdc;
3574 RECT rc, rc2, rc3;
3575 COLORREF colr;
3577 ShowWindow( hwnd, SW_SHOW);
3578 UpdateWindow( hwnd);
3579 flush_events( TRUE );
3580 GetClientRect( hwnd, &rc);
3581 hdc = GetDC( hwnd);
3582 /* test ScrollWindow(Ex) with no clip rectangle */
3583 /* paint the lower half of the window black */
3584 rc2 = rc;
3585 rc2.top = ( rc2.top + rc2.bottom) / 2;
3586 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3587 /* paint the upper half of the window white */
3588 rc2.bottom = rc2.top;
3589 rc2.top =0;
3590 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
3591 /* scroll lower half up */
3592 rc2 = rc;
3593 rc2.top = ( rc2.top + rc2.bottom) / 2;
3594 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, NULL, NULL, NULL, SW_ERASE);
3595 flush_events(FALSE);
3596 /* expected: black should have scrolled to the upper half */
3597 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
3598 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3599 /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
3600 /* paint the lower half of the window black */
3601 rc2 = rc;
3602 rc2.top = ( rc2.top + rc2.bottom) / 2;
3603 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3604 /* paint the upper half of the window white */
3605 rc2.bottom = rc2.top;
3606 rc2.top =0;
3607 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
3608 /* scroll lower half up */
3609 rc2 = rc;
3610 rc2.top = ( rc2.top + rc2.bottom) / 2;
3611 rc3 = rc;
3612 rc3.left = rc3.right / 4;
3613 rc3.right -= rc3.right / 4;
3614 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, &rc3, NULL, NULL, SW_ERASE);
3615 flush_events(FALSE);
3616 /* expected: black should have scrolled to the upper half */
3617 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
3618 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3620 /* clean up */
3621 ReleaseDC( hwnd, hdc);
3624 static void test_scrollvalidate( HWND parent)
3626 HDC hdc;
3627 HRGN hrgn=CreateRectRgn(0,0,0,0);
3628 HRGN exprgn, tmprgn, clipping;
3629 RECT rc, rcu, cliprc;
3630 /* create two overlapping child windows. The visual region
3631 * of hwnd1 is clipped by the overlapping part of
3632 * hwnd2 because of the WS_CLIPSIBLING style */
3633 HWND hwnd1, hwnd2;
3635 clipping = CreateRectRgn(0,0,0,0);
3636 tmprgn = CreateRectRgn(0,0,0,0);
3637 exprgn = CreateRectRgn(0,0,0,0);
3638 hwnd2 = CreateWindowExA(0, "static", NULL,
3639 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3640 75, 30, 100, 100, parent, 0, 0, NULL);
3641 hwnd1 = CreateWindowExA(0, "static", NULL,
3642 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3643 25, 50, 100, 100, parent, 0, 0, NULL);
3644 ShowWindow( parent, SW_SHOW);
3645 UpdateWindow( parent);
3646 GetClientRect( hwnd1, &rc);
3647 cliprc=rc;
3648 SetRectRgn( clipping, 10, 10, 90, 90);
3649 hdc = GetDC( hwnd1);
3650 /* for a visual touch */
3651 TextOut( hdc, 0,10, "0123456789", 10);
3652 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3653 if (winetest_debug > 0) dump_region(hrgn);
3654 /* create a region with what is expected */
3655 SetRectRgn( exprgn, 39,0,49,74);
3656 SetRectRgn( tmprgn, 88,79,98,93);
3657 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3658 SetRectRgn( tmprgn, 0,93,98,98);
3659 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3660 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3661 trace("update rect is %d,%d - %d,%d\n",
3662 rcu.left,rcu.top,rcu.right,rcu.bottom);
3663 /* now with clipping region */
3664 SelectClipRgn( hdc, clipping);
3665 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3666 if (winetest_debug > 0) dump_region(hrgn);
3667 /* create a region with what is expected */
3668 SetRectRgn( exprgn, 39,10,49,74);
3669 SetRectRgn( tmprgn, 80,79,90,85);
3670 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3671 SetRectRgn( tmprgn, 10,85,90,90);
3672 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3673 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3674 trace("update rect is %d,%d - %d,%d\n",
3675 rcu.left,rcu.top,rcu.right,rcu.bottom);
3676 ReleaseDC( hwnd1, hdc);
3678 /* test scrolling a window with an update region */
3679 DestroyWindow( hwnd2);
3680 ValidateRect( hwnd1, NULL);
3681 SetRect( &rc, 40,40, 50,50);
3682 InvalidateRect( hwnd1, &rc, 1);
3683 GetClientRect( hwnd1, &rc);
3684 cliprc=rc;
3685 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
3686 SW_SCROLLCHILDREN | SW_INVALIDATE);
3687 if (winetest_debug > 0) dump_region(hrgn);
3688 SetRectRgn( exprgn, 88,0,98,98);
3689 SetRectRgn( tmprgn, 30, 40, 50, 50);
3690 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3691 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3693 /* clear an update region */
3694 UpdateWindow( hwnd1 );
3696 SetRect( &rc, 0,40, 100,60);
3697 SetRect( &cliprc, 0,0, 100,100);
3698 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3699 if (winetest_debug > 0) dump_region( hrgn );
3700 SetRectRgn( exprgn, 0, 40, 98, 60 );
3701 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
3703 /* now test ScrollWindowEx with a combination of
3704 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3705 /* make hwnd2 the child of hwnd1 */
3706 hwnd2 = CreateWindowExA(0, "static", NULL,
3707 WS_CHILD| WS_VISIBLE | WS_BORDER ,
3708 50, 50, 100, 100, hwnd1, 0, 0, NULL);
3709 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
3710 GetClientRect( hwnd1, &rc);
3711 cliprc=rc;
3713 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3714 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3715 ValidateRect( hwnd1, NULL);
3716 ValidateRect( hwnd2, NULL);
3717 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
3718 SW_SCROLLCHILDREN | SW_INVALIDATE);
3719 if (winetest_debug > 0) dump_region(hrgn);
3720 SetRectRgn( exprgn, 88,0,98,88);
3721 SetRectRgn( tmprgn, 0,88,98,98);
3722 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3723 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3725 /* SW_SCROLLCHILDREN */
3726 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3727 ValidateRect( hwnd1, NULL);
3728 ValidateRect( hwnd2, NULL);
3729 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3730 if (winetest_debug > 0) dump_region(hrgn);
3731 /* expected region is the same as in previous test */
3732 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3734 /* no SW_SCROLLCHILDREN */
3735 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3736 ValidateRect( hwnd1, NULL);
3737 ValidateRect( hwnd2, NULL);
3738 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3739 if (winetest_debug > 0) dump_region(hrgn);
3740 /* expected region is the same as in previous test */
3741 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3743 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3744 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3745 ValidateRect( hwnd1, NULL);
3746 ValidateRect( hwnd2, NULL);
3747 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3748 if (winetest_debug > 0) dump_region(hrgn);
3749 SetRectRgn( exprgn, 88,0,98,20);
3750 SetRectRgn( tmprgn, 20,20,98,30);
3751 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3752 SetRectRgn( tmprgn, 20,30,30,88);
3753 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3754 SetRectRgn( tmprgn, 0,88,30,98);
3755 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3756 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3758 /* clean up */
3759 DeleteObject( hrgn);
3760 DeleteObject( exprgn);
3761 DeleteObject( tmprgn);
3762 DestroyWindow( hwnd1);
3763 DestroyWindow( hwnd2);
3766 /* couple of tests of return values of scrollbar functions
3767 * called on a scrollbarless window */
3768 static void test_scroll(void)
3770 BOOL ret;
3771 INT min, max;
3772 SCROLLINFO si;
3773 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3774 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3775 100, 100, 200, 200, 0, 0, 0, NULL);
3776 /* horizontal */
3777 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3778 if (!ret) /* win9x */
3780 win_skip( "GetScrollRange doesn't work\n" );
3781 DestroyWindow( hwnd);
3782 return;
3784 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3785 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3786 si.cbSize = sizeof( si);
3787 si.fMask = SIF_PAGE;
3788 si.nPage = 0xdeadbeef;
3789 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3790 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3791 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3792 /* vertical */
3793 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3794 ok( ret, "GetScrollRange returns FALSE\n");
3795 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3796 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3797 si.cbSize = sizeof( si);
3798 si.fMask = SIF_PAGE;
3799 si.nPage = 0xdeadbeef;
3800 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3801 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3802 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3803 /* clean up */
3804 DestroyWindow( hwnd);
3807 static void test_scrolldc( HWND parent)
3809 HDC hdc;
3810 HRGN exprgn, tmprgn, hrgn;
3811 RECT rc, rc2, rcu, cliprc;
3812 HWND hwnd1;
3813 COLORREF colr;
3815 hrgn = CreateRectRgn(0,0,0,0);
3816 tmprgn = CreateRectRgn(0,0,0,0);
3817 exprgn = CreateRectRgn(0,0,0,0);
3819 hwnd1 = CreateWindowExA(0, "static", NULL,
3820 WS_CHILD| WS_VISIBLE,
3821 25, 50, 100, 100, parent, 0, 0, NULL);
3822 ShowWindow( parent, SW_SHOW);
3823 UpdateWindow( parent);
3824 flush_events( TRUE );
3825 GetClientRect( hwnd1, &rc);
3826 hdc = GetDC( hwnd1);
3827 /* paint the upper half of the window black */
3828 rc2 = rc;
3829 rc2.bottom = ( rc.top + rc.bottom) /2;
3830 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3831 /* clip region is the lower half */
3832 cliprc=rc;
3833 cliprc.top = (rc.top + rc.bottom) /2;
3834 /* test whether scrolled pixels are properly clipped */
3835 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3836 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3837 /* this scroll should not cause any visible changes */
3838 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3839 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3840 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3841 /* test with NULL clip rect */
3842 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3843 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3844 trace("update rect: %d,%d - %d,%d\n",
3845 rcu.left, rcu.top, rcu.right, rcu.bottom);
3846 if (winetest_debug > 0) dump_region(hrgn);
3847 SetRect(&rc2, 0, 0, 100, 100);
3848 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3849 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3851 SetRectRgn( exprgn, 0, 0, 20, 80);
3852 SetRectRgn( tmprgn, 0, 80, 100, 100);
3853 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3854 if (winetest_debug > 0) dump_region(exprgn);
3855 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3856 /* test clip rect > scroll rect */
3857 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3858 rc2=rc;
3859 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3860 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3861 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3862 SetRectRgn( exprgn, 25, 25, 75, 35);
3863 SetRectRgn( tmprgn, 25, 35, 35, 75);
3864 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3865 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3866 trace("update rect: %d,%d - %d,%d\n",
3867 rcu.left, rcu.top, rcu.right, rcu.bottom);
3868 if (winetest_debug > 0) dump_region(hrgn);
3870 /* clean up */
3871 DeleteObject(hrgn);
3872 DeleteObject(exprgn);
3873 DeleteObject(tmprgn);
3874 DestroyWindow(hwnd1);
3877 static void test_params(void)
3879 HWND hwnd;
3880 INT rc;
3882 /* Just a param check */
3883 if (pGetMonitorInfoA)
3885 SetLastError(0xdeadbeef);
3886 rc = GetWindowText(hwndMain2, NULL, 1024);
3887 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
3889 else
3891 /* Skips actually on Win95 and NT4 */
3892 win_skip("Test would crash on Win95\n");
3895 SetLastError(0xdeadbeef);
3896 hwnd=CreateWindow("LISTBOX", "TestList",
3897 (LBS_STANDARD & ~LBS_SORT),
3898 0, 0, 100, 100,
3899 NULL, (HMENU)1, NULL, 0);
3901 ok(!hwnd || broken(hwnd != NULL), /* w2k3 sp2 */
3902 "CreateWindow with invalid menu handle should fail\n");
3903 if (!hwnd)
3904 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3905 GetLastError() == 0xdeadbeef, /* Win9x */
3906 "wrong last error value %d\n", GetLastError());
3909 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3911 HWND hwnd = 0;
3913 hwnd = CreateWindowEx(exStyle, class, class, style,
3914 110, 100,
3915 225, 200,
3917 menu ? hmenu : 0,
3918 0, 0);
3919 if (!hwnd) {
3920 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
3921 return;
3923 ShowWindow(hwnd, SW_SHOW);
3925 test_nonclient_area(hwnd);
3927 SetMenu(hwnd, 0);
3928 DestroyWindow(hwnd);
3931 static BOOL AWR_init(void)
3933 WNDCLASS class;
3935 class.style = CS_HREDRAW | CS_VREDRAW;
3936 class.lpfnWndProc = DefWindowProcA;
3937 class.cbClsExtra = 0;
3938 class.cbWndExtra = 0;
3939 class.hInstance = 0;
3940 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3941 class.hCursor = LoadCursor (0, IDC_ARROW);
3942 class.hbrBackground = 0;
3943 class.lpszMenuName = 0;
3944 class.lpszClassName = szAWRClass;
3946 if (!RegisterClass (&class)) {
3947 ok(FALSE, "RegisterClass failed\n");
3948 return FALSE;
3951 hmenu = CreateMenu();
3952 if (!hmenu)
3953 return FALSE;
3954 ok(hmenu != 0, "Failed to create menu\n");
3955 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3957 return TRUE;
3961 static void test_AWR_window_size(BOOL menu)
3963 LONG styles[] = {
3964 WS_POPUP,
3965 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3966 WS_SYSMENU,
3967 WS_THICKFRAME,
3968 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3969 WS_HSCROLL, WS_VSCROLL
3971 LONG exStyles[] = {
3972 WS_EX_CLIENTEDGE,
3973 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3974 WS_EX_APPWINDOW,
3975 #if 0
3976 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3977 WS_EX_DLGMODALFRAME,
3978 WS_EX_STATICEDGE,
3979 #endif
3982 int i;
3984 /* A exhaustive check of all the styles takes too long
3985 * so just do a (hopefully representative) sample
3987 for (i = 0; i < COUNTOF(styles); ++i)
3988 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3989 for (i = 0; i < COUNTOF(exStyles); ++i) {
3990 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3991 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3994 #undef COUNTOF
3996 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3998 static void test_AdjustWindowRect(void)
4000 if (!AWR_init())
4001 return;
4003 SHOWSYSMETRIC(SM_CYCAPTION);
4004 SHOWSYSMETRIC(SM_CYSMCAPTION);
4005 SHOWSYSMETRIC(SM_CYMENU);
4006 SHOWSYSMETRIC(SM_CXEDGE);
4007 SHOWSYSMETRIC(SM_CYEDGE);
4008 SHOWSYSMETRIC(SM_CXVSCROLL);
4009 SHOWSYSMETRIC(SM_CYHSCROLL);
4010 SHOWSYSMETRIC(SM_CXFRAME);
4011 SHOWSYSMETRIC(SM_CYFRAME);
4012 SHOWSYSMETRIC(SM_CXDLGFRAME);
4013 SHOWSYSMETRIC(SM_CYDLGFRAME);
4014 SHOWSYSMETRIC(SM_CXBORDER);
4015 SHOWSYSMETRIC(SM_CYBORDER);
4017 test_AWR_window_size(FALSE);
4018 test_AWR_window_size(TRUE);
4020 DestroyMenu(hmenu);
4022 #undef SHOWSYSMETRIC
4025 /* Global variables to trigger exit from loop */
4026 static int redrawComplete, WMPAINT_count;
4028 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4030 switch (msg)
4032 case WM_PAINT:
4033 trace("doing WM_PAINT %d\n", WMPAINT_count);
4034 WMPAINT_count++;
4035 if (WMPAINT_count > 10 && redrawComplete == 0) {
4036 PAINTSTRUCT ps;
4037 BeginPaint(hwnd, &ps);
4038 EndPaint(hwnd, &ps);
4039 return 1;
4041 return 0;
4043 return DefWindowProc(hwnd, msg, wparam, lparam);
4046 /* Ensure we exit from RedrawNow regardless of invalidated area */
4047 static void test_redrawnow(void)
4049 WNDCLASSA cls;
4050 HWND hwndMain;
4052 cls.style = CS_DBLCLKS;
4053 cls.lpfnWndProc = redraw_window_procA;
4054 cls.cbClsExtra = 0;
4055 cls.cbWndExtra = 0;
4056 cls.hInstance = GetModuleHandleA(0);
4057 cls.hIcon = 0;
4058 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4059 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4060 cls.lpszMenuName = NULL;
4061 cls.lpszClassName = "RedrawWindowClass";
4063 if(!RegisterClassA(&cls)) {
4064 trace("Register failed %d\n", GetLastError());
4065 return;
4068 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
4069 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
4071 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4072 ShowWindow(hwndMain, SW_SHOW);
4073 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4074 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
4075 ok( WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
4076 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4077 redrawComplete = TRUE;
4078 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
4080 /* clean up */
4081 DestroyWindow( hwndMain);
4084 struct parentdc_stat {
4085 RECT client;
4086 RECT clip;
4087 RECT paint;
4090 struct parentdc_test {
4091 struct parentdc_stat main, main_todo;
4092 struct parentdc_stat child1, child1_todo;
4093 struct parentdc_stat child2, child2_todo;
4096 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4098 RECT rc;
4099 PAINTSTRUCT ps;
4101 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
4103 switch (msg)
4105 case WM_PAINT:
4106 GetClientRect(hwnd, &rc);
4107 CopyRect(&t->client, &rc);
4108 GetWindowRect(hwnd, &rc);
4109 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd,
4110 t->client.left, t->client.top, t->client.right, t->client.bottom,
4111 rc.left, rc.top, rc.right, rc.bottom);
4112 BeginPaint(hwnd, &ps);
4113 CopyRect(&t->paint, &ps.rcPaint);
4114 GetClipBox(ps.hdc, &rc);
4115 CopyRect(&t->clip, &rc);
4116 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
4117 rc.left, rc.top, rc.right, rc.bottom,
4118 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
4119 EndPaint(hwnd, &ps);
4120 return 0;
4122 return DefWindowProc(hwnd, msg, wparam, lparam);
4125 static void zero_parentdc_stat(struct parentdc_stat *t)
4127 SetRectEmpty(&t->client);
4128 SetRectEmpty(&t->clip);
4129 SetRectEmpty(&t->paint);
4132 static void zero_parentdc_test(struct parentdc_test *t)
4134 zero_parentdc_stat(&t->main);
4135 zero_parentdc_stat(&t->child1);
4136 zero_parentdc_stat(&t->child2);
4139 #define parentdc_field_ok(t, w, r, f, got) \
4140 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
4141 ": expected %d, got %d\n", \
4142 t.w.r.f, got.w.r.f)
4144 #define parentdc_todo_field_ok(t, w, r, f, got) \
4145 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
4146 else parentdc_field_ok(t, w, r, f, got)
4148 #define parentdc_rect_ok(t, w, r, got) \
4149 parentdc_todo_field_ok(t, w, r, left, got); \
4150 parentdc_todo_field_ok(t, w, r, top, got); \
4151 parentdc_todo_field_ok(t, w, r, right, got); \
4152 parentdc_todo_field_ok(t, w, r, bottom, got);
4154 #define parentdc_win_ok(t, w, got) \
4155 parentdc_rect_ok(t, w, client, got); \
4156 parentdc_rect_ok(t, w, clip, got); \
4157 parentdc_rect_ok(t, w, paint, got);
4159 #define parentdc_ok(t, got) \
4160 parentdc_win_ok(t, main, got); \
4161 parentdc_win_ok(t, child1, got); \
4162 parentdc_win_ok(t, child2, got);
4164 static void test_csparentdc(void)
4166 WNDCLASSA clsMain, cls;
4167 HWND hwndMain, hwnd1, hwnd2;
4168 RECT rc;
4170 struct parentdc_test test_answer;
4172 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
4173 const struct parentdc_test test1 =
4175 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
4176 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4177 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4180 const struct parentdc_test test2 =
4182 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
4183 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4184 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4187 const struct parentdc_test test3 =
4189 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4190 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4191 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4194 const struct parentdc_test test4 =
4196 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
4197 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
4198 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4201 const struct parentdc_test test5 =
4203 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
4204 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4205 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4208 const struct parentdc_test test6 =
4210 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4211 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4212 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4215 const struct parentdc_test test7 =
4217 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4218 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4219 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4221 #undef nothing_todo
4223 clsMain.style = CS_DBLCLKS;
4224 clsMain.lpfnWndProc = parentdc_window_procA;
4225 clsMain.cbClsExtra = 0;
4226 clsMain.cbWndExtra = 0;
4227 clsMain.hInstance = GetModuleHandleA(0);
4228 clsMain.hIcon = 0;
4229 clsMain.hCursor = LoadCursorA(0, IDC_ARROW);
4230 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
4231 clsMain.lpszMenuName = NULL;
4232 clsMain.lpszClassName = "ParentDcMainWindowClass";
4234 if(!RegisterClassA(&clsMain)) {
4235 trace("Register failed %d\n", GetLastError());
4236 return;
4239 cls.style = CS_DBLCLKS | CS_PARENTDC;
4240 cls.lpfnWndProc = parentdc_window_procA;
4241 cls.cbClsExtra = 0;
4242 cls.cbWndExtra = 0;
4243 cls.hInstance = GetModuleHandleA(0);
4244 cls.hIcon = 0;
4245 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4246 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4247 cls.lpszMenuName = NULL;
4248 cls.lpszClassName = "ParentDcWindowClass";
4250 if(!RegisterClassA(&cls)) {
4251 trace("Register failed %d\n", GetLastError());
4252 return;
4255 SetRect(&rc, 0, 0, 150, 150);
4256 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
4257 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
4258 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
4259 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
4260 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
4261 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
4262 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
4263 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
4264 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
4265 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
4266 ShowWindow(hwndMain, SW_SHOW);
4267 ShowWindow(hwnd1, SW_SHOW);
4268 ShowWindow(hwnd2, SW_SHOW);
4269 SetWindowPos(hwndMain, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
4270 flush_events( TRUE );
4272 zero_parentdc_test(&test_answer);
4273 InvalidateRect(hwndMain, NULL, TRUE);
4274 flush_events( TRUE );
4275 parentdc_ok(test1, test_answer);
4277 zero_parentdc_test(&test_answer);
4278 SetRect(&rc, 0, 0, 50, 50);
4279 InvalidateRect(hwndMain, &rc, TRUE);
4280 flush_events( TRUE );
4281 parentdc_ok(test2, test_answer);
4283 zero_parentdc_test(&test_answer);
4284 SetRect(&rc, 0, 0, 10, 10);
4285 InvalidateRect(hwndMain, &rc, TRUE);
4286 flush_events( TRUE );
4287 parentdc_ok(test3, test_answer);
4289 zero_parentdc_test(&test_answer);
4290 SetRect(&rc, 40, 40, 50, 50);
4291 InvalidateRect(hwndMain, &rc, TRUE);
4292 flush_events( TRUE );
4293 parentdc_ok(test4, test_answer);
4295 zero_parentdc_test(&test_answer);
4296 SetRect(&rc, 20, 20, 60, 60);
4297 InvalidateRect(hwndMain, &rc, TRUE);
4298 flush_events( TRUE );
4299 parentdc_ok(test5, test_answer);
4301 zero_parentdc_test(&test_answer);
4302 SetRect(&rc, 0, 0, 10, 10);
4303 InvalidateRect(hwnd1, &rc, TRUE);
4304 flush_events( TRUE );
4305 parentdc_ok(test6, test_answer);
4307 zero_parentdc_test(&test_answer);
4308 SetRect(&rc, -5, -5, 65, 65);
4309 InvalidateRect(hwnd1, &rc, TRUE);
4310 flush_events( TRUE );
4311 parentdc_ok(test7, test_answer);
4313 DestroyWindow(hwndMain);
4314 DestroyWindow(hwnd1);
4315 DestroyWindow(hwnd2);
4318 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4320 return DefWindowProcA(hwnd, msg, wparam, lparam);
4323 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4325 return DefWindowProcW(hwnd, msg, wparam, lparam);
4328 static void test_IsWindowUnicode(void)
4330 static const char ansi_class_nameA[] = "ansi class name";
4331 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
4332 static const char unicode_class_nameA[] = "unicode class name";
4333 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
4334 WNDCLASSA classA;
4335 WNDCLASSW classW;
4336 HWND hwnd;
4338 memset(&classW, 0, sizeof(classW));
4339 classW.hInstance = GetModuleHandleA(0);
4340 classW.lpfnWndProc = def_window_procW;
4341 classW.lpszClassName = unicode_class_nameW;
4342 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
4344 memset(&classA, 0, sizeof(classA));
4345 classA.hInstance = GetModuleHandleA(0);
4346 classA.lpfnWndProc = def_window_procA;
4347 classA.lpszClassName = ansi_class_nameA;
4348 assert(RegisterClassA(&classA));
4350 /* unicode class: window proc */
4351 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4352 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4353 assert(hwnd);
4355 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4356 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4357 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4358 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4359 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4361 DestroyWindow(hwnd);
4363 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4364 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4365 assert(hwnd);
4367 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4368 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4369 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4370 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4371 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4373 DestroyWindow(hwnd);
4375 /* ansi class: window proc */
4376 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4377 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4378 assert(hwnd);
4380 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4381 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4382 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4383 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4384 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4386 DestroyWindow(hwnd);
4388 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4389 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4390 assert(hwnd);
4392 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4393 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4394 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4395 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4396 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4398 DestroyWindow(hwnd);
4400 /* unicode class: class proc */
4401 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4402 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4403 assert(hwnd);
4405 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4406 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4407 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4408 /* do not restore class window proc back to unicode */
4410 DestroyWindow(hwnd);
4412 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4413 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4414 assert(hwnd);
4416 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4417 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4418 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4420 DestroyWindow(hwnd);
4422 /* ansi class: class proc */
4423 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4424 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4425 assert(hwnd);
4427 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4428 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4429 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4430 /* do not restore class window proc back to ansi */
4432 DestroyWindow(hwnd);
4434 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4435 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4436 assert(hwnd);
4438 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4439 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4440 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4442 DestroyWindow(hwnd);
4445 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4447 MINMAXINFO *minmax;
4449 if (msg != WM_GETMINMAXINFO)
4450 return DefWindowProc(hwnd, msg, wp, lp);
4452 minmax = (MINMAXINFO *)lp;
4454 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
4456 minmax->ptReserved.x = 0;
4457 minmax->ptReserved.y = 0;
4458 minmax->ptMaxSize.x = 400;
4459 minmax->ptMaxSize.y = 400;
4460 minmax->ptMaxPosition.x = 300;
4461 minmax->ptMaxPosition.y = 300;
4462 minmax->ptMaxTrackSize.x = 200;
4463 minmax->ptMaxTrackSize.y = 200;
4464 minmax->ptMinTrackSize.x = 100;
4465 minmax->ptMinTrackSize.y = 100;
4467 else
4468 DefWindowProc(hwnd, msg, wp, lp);
4469 return 1;
4472 static int expected_cx, expected_cy;
4473 static RECT expected_rect, broken_rect;
4475 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4477 switch(msg)
4479 case WM_GETMINMAXINFO:
4481 RECT rect;
4482 GetWindowRect( hwnd, &rect );
4483 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
4484 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4485 return DefWindowProc(hwnd, msg, wp, lp);
4487 case WM_NCCREATE:
4488 case WM_CREATE:
4490 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
4491 RECT rect;
4492 GetWindowRect( hwnd, &rect );
4493 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
4494 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
4495 ok( cs->cx == expected_cx || broken(cs->cx == (short)expected_cx),
4496 "wrong x size %d/%d\n", cs->cx, expected_cx );
4497 ok( cs->cy == expected_cy || broken(cs->cy == (short)expected_cy),
4498 "wrong y size %d/%d\n", cs->cy, expected_cy );
4499 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
4500 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
4501 (rect.right - rect.left == min( 65535, expected_rect.right - expected_rect.left ) &&
4502 rect.bottom - rect.top == min( 65535, expected_rect.bottom - expected_rect.top )) ||
4503 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
4504 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top) ||
4505 broken( rect.right - rect.left == (short)broken_rect.right - (short)broken_rect.left &&
4506 rect.bottom - rect.top == (short)broken_rect.bottom - (short)broken_rect.top),
4507 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
4508 rect.left, rect.top, rect.right, rect.bottom,
4509 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
4510 return DefWindowProc(hwnd, msg, wp, lp);
4512 case WM_NCCALCSIZE:
4514 RECT rect, *r = (RECT *)lp;
4515 GetWindowRect( hwnd, &rect );
4516 ok( !memcmp( &rect, r, sizeof(rect) ),
4517 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
4518 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
4519 return DefWindowProc(hwnd, msg, wp, lp);
4521 default:
4522 return DefWindowProc(hwnd, msg, wp, lp);
4526 static void test_CreateWindow(void)
4528 WNDCLASS cls;
4529 HWND hwnd, parent;
4530 HMENU hmenu;
4531 RECT rc, rc_minmax;
4532 MINMAXINFO minmax;
4533 BOOL res;
4535 #define expect_menu(window, menu) \
4536 SetLastError(0xdeadbeef); \
4537 res = (GetMenu(window) == (HMENU)menu); \
4538 ok(res, "GetMenu error %d\n", GetLastError())
4540 #define expect_style(window, style)\
4541 ok((ULONG)GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
4543 #define expect_ex_style(window, ex_style)\
4544 ok((ULONG)GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
4546 #define expect_gle_broken_9x(gle)\
4547 ok(GetLastError() == gle ||\
4548 broken(GetLastError() == 0xdeadbeef),\
4549 "IsMenu set error %d\n", GetLastError())
4551 hmenu = CreateMenu();
4552 assert(hmenu != 0);
4553 parent = GetDesktopWindow();
4554 assert(parent != 0);
4556 SetLastError(0xdeadbeef);
4557 res = IsMenu(hmenu);
4558 ok(res, "IsMenu error %d\n", GetLastError());
4560 /* WS_CHILD */
4561 SetLastError(0xdeadbeef);
4562 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
4563 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4564 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4565 expect_menu(hwnd, 1);
4566 expect_style(hwnd, WS_CHILD);
4567 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4568 DestroyWindow(hwnd);
4570 SetLastError(0xdeadbeef);
4571 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
4572 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4573 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4574 expect_menu(hwnd, 1);
4575 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4576 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4577 DestroyWindow(hwnd);
4579 SetLastError(0xdeadbeef);
4580 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
4581 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4582 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4583 expect_menu(hwnd, 1);
4584 expect_style(hwnd, WS_CHILD);
4585 expect_ex_style(hwnd, 0);
4586 DestroyWindow(hwnd);
4588 SetLastError(0xdeadbeef);
4589 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
4590 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4591 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4592 expect_menu(hwnd, 1);
4593 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4594 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4595 DestroyWindow(hwnd);
4597 /* WS_POPUP */
4598 SetLastError(0xdeadbeef);
4599 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4600 0, 0, 100, 100, parent, hmenu, 0, NULL);
4601 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4602 expect_menu(hwnd, hmenu);
4603 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4604 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4605 DestroyWindow(hwnd);
4606 SetLastError(0xdeadbeef);
4607 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4608 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4610 hmenu = CreateMenu();
4611 assert(hmenu != 0);
4612 SetLastError(0xdeadbeef);
4613 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
4614 0, 0, 100, 100, parent, hmenu, 0, NULL);
4615 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4616 expect_menu(hwnd, hmenu);
4617 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4618 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4619 DestroyWindow(hwnd);
4620 SetLastError(0xdeadbeef);
4621 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4622 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4624 hmenu = CreateMenu();
4625 assert(hmenu != 0);
4626 SetLastError(0xdeadbeef);
4627 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
4628 0, 0, 100, 100, parent, hmenu, 0, NULL);
4629 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4630 expect_menu(hwnd, hmenu);
4631 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4632 expect_ex_style(hwnd, 0);
4633 DestroyWindow(hwnd);
4634 SetLastError(0xdeadbeef);
4635 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4636 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4638 hmenu = CreateMenu();
4639 assert(hmenu != 0);
4640 SetLastError(0xdeadbeef);
4641 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
4642 0, 0, 100, 100, parent, hmenu, 0, NULL);
4643 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4644 expect_menu(hwnd, hmenu);
4645 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4646 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4647 DestroyWindow(hwnd);
4648 SetLastError(0xdeadbeef);
4649 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4650 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4652 /* WS_CHILD | WS_POPUP */
4653 SetLastError(0xdeadbeef);
4654 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4655 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4656 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4657 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4658 if (hwnd)
4659 DestroyWindow(hwnd);
4661 hmenu = CreateMenu();
4662 assert(hmenu != 0);
4663 SetLastError(0xdeadbeef);
4664 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4665 0, 0, 100, 100, parent, hmenu, 0, NULL);
4666 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4667 expect_menu(hwnd, hmenu);
4668 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4669 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4670 DestroyWindow(hwnd);
4671 SetLastError(0xdeadbeef);
4672 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4673 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4675 SetLastError(0xdeadbeef);
4676 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4677 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4678 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4679 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4680 if (hwnd)
4681 DestroyWindow(hwnd);
4683 hmenu = CreateMenu();
4684 assert(hmenu != 0);
4685 SetLastError(0xdeadbeef);
4686 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4687 0, 0, 100, 100, parent, hmenu, 0, NULL);
4688 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4689 expect_menu(hwnd, hmenu);
4690 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4691 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4692 DestroyWindow(hwnd);
4693 SetLastError(0xdeadbeef);
4694 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4695 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4697 SetLastError(0xdeadbeef);
4698 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4699 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4700 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4701 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4702 if (hwnd)
4703 DestroyWindow(hwnd);
4705 hmenu = CreateMenu();
4706 assert(hmenu != 0);
4707 SetLastError(0xdeadbeef);
4708 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4709 0, 0, 100, 100, parent, hmenu, 0, NULL);
4710 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4711 expect_menu(hwnd, hmenu);
4712 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4713 expect_ex_style(hwnd, 0);
4714 DestroyWindow(hwnd);
4715 SetLastError(0xdeadbeef);
4716 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4717 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4719 SetLastError(0xdeadbeef);
4720 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4721 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4722 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4723 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4724 if (hwnd)
4725 DestroyWindow(hwnd);
4727 hmenu = CreateMenu();
4728 assert(hmenu != 0);
4729 SetLastError(0xdeadbeef);
4730 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4731 0, 0, 100, 100, parent, hmenu, 0, NULL);
4732 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4733 expect_menu(hwnd, hmenu);
4734 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4735 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4736 DestroyWindow(hwnd);
4737 SetLastError(0xdeadbeef);
4738 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4739 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4741 /* test child window sizing */
4742 cls.style = 0;
4743 cls.lpfnWndProc = minmax_wnd_proc;
4744 cls.cbClsExtra = 0;
4745 cls.cbWndExtra = 0;
4746 cls.hInstance = GetModuleHandle(0);
4747 cls.hIcon = 0;
4748 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4749 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4750 cls.lpszMenuName = NULL;
4751 cls.lpszClassName = "MinMax_WndClass";
4752 RegisterClass(&cls);
4754 SetLastError(0xdeadbeef);
4755 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4756 0, 0, 100, 100, 0, 0, 0, NULL);
4757 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4758 expect_menu(parent, 0);
4759 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
4760 expect_ex_style(parent, WS_EX_WINDOWEDGE);
4762 memset(&minmax, 0, sizeof(minmax));
4763 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4764 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
4765 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
4766 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4767 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
4769 GetWindowRect(parent, &rc);
4770 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
4771 GetClientRect(parent, &rc);
4772 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
4774 InflateRect(&rc, 200, 200);
4775 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4777 SetLastError(0xdeadbeef);
4778 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4779 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
4780 parent, (HMENU)1, 0, NULL);
4781 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4782 expect_menu(hwnd, 1);
4783 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
4784 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4786 memset(&minmax, 0, sizeof(minmax));
4787 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4788 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4790 GetWindowRect(hwnd, &rc);
4791 OffsetRect(&rc, -rc.left, -rc.top);
4792 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4793 rc.left, rc.top, rc.right, rc.bottom,
4794 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
4795 DestroyWindow(hwnd);
4797 cls.lpfnWndProc = winsizes_wnd_proc;
4798 cls.lpszClassName = "Sizes_WndClass";
4799 RegisterClass(&cls);
4801 expected_cx = expected_cy = 200000;
4802 SetRect( &expected_rect, 0, 0, 200000, 200000 );
4803 broken_rect = expected_rect;
4804 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
4805 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4806 GetClientRect( hwnd, &rc );
4807 ok( rc.right == 200000 || rc.right == 65535 || broken(rc.right == (short)200000),
4808 "invalid rect right %u\n", rc.right );
4809 ok( rc.bottom == 200000 || rc.bottom == 65535 || broken(rc.bottom == (short)200000),
4810 "invalid rect bottom %u\n", rc.bottom );
4811 DestroyWindow(hwnd);
4813 expected_cx = expected_cy = -10;
4814 SetRect( &expected_rect, 0, 0, 0, 0 );
4815 SetRect( &broken_rect, 0, 0, -10, -10 );
4816 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
4817 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4818 GetClientRect( hwnd, &rc );
4819 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4820 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4821 DestroyWindow(hwnd);
4823 expected_cx = expected_cy = -200000;
4824 SetRect( &expected_rect, 0, 0, 0, 0 );
4825 SetRect( &broken_rect, 0, 0, -200000, -200000 );
4826 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
4827 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4828 GetClientRect( hwnd, &rc );
4829 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4830 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4831 DestroyWindow(hwnd);
4833 /* we need a parent at 0,0 so that child coordinates match */
4834 DestroyWindow(parent);
4835 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
4836 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4838 expected_cx = 100;
4839 expected_cy = 0x7fffffff;
4840 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
4841 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
4842 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
4843 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4844 GetClientRect( hwnd, &rc );
4845 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
4846 ok( rc.bottom == 0x7fffffff - 10 || rc.bottom ==65535 || broken(rc.bottom == 0),
4847 "invalid rect bottom %u\n", rc.bottom );
4848 DestroyWindow(hwnd);
4850 expected_cx = 0x7fffffff;
4851 expected_cy = 0x7fffffff;
4852 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
4853 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
4854 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
4855 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4856 GetClientRect( hwnd, &rc );
4857 ok( rc.right == 0x7fffffff - 20 || rc.right == 65535 || broken(rc.right == 0),
4858 "invalid rect right %u\n", rc.right );
4859 ok( rc.bottom == 0x7fffffff - 10 || rc.right == 65535 || broken(rc.bottom == 0),
4860 "invalid rect bottom %u\n", rc.bottom );
4861 DestroyWindow(hwnd);
4863 /* top level window */
4864 expected_cx = expected_cy = 200000;
4865 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
4866 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
4867 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4868 GetClientRect( hwnd, &rc );
4869 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
4870 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
4871 DestroyWindow(hwnd);
4873 if (pGetLayout && pSetLayout)
4875 HDC hdc = GetDC( parent );
4876 pSetLayout( hdc, LAYOUT_RTL );
4877 if (pGetLayout( hdc ))
4879 ReleaseDC( parent, hdc );
4880 DestroyWindow( parent );
4881 SetLastError( 0xdeadbeef );
4882 parent = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_LAYOUTRTL, "static", NULL, WS_POPUP,
4883 0, 0, 100, 100, 0, 0, 0, NULL);
4884 ok( parent != 0, "creation failed err %u\n", GetLastError());
4885 expect_ex_style( parent, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
4886 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 20, 20, parent, 0, 0, NULL);
4887 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4888 expect_ex_style( hwnd, WS_EX_LAYOUTRTL );
4889 DestroyWindow( hwnd );
4890 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 20, 20, parent, 0, 0, NULL);
4891 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4892 expect_ex_style( hwnd, 0 );
4893 DestroyWindow( hwnd );
4894 SetWindowLongW( parent, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT );
4895 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 20, 20, parent, 0, 0, NULL);
4896 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4897 expect_ex_style( hwnd, 0 );
4898 DestroyWindow( hwnd );
4900 if (pGetProcessDefaultLayout && pSetProcessDefaultLayout)
4902 DWORD layout;
4904 SetLastError( 0xdeadbeef );
4905 ok( !pGetProcessDefaultLayout( NULL ), "GetProcessDefaultLayout succeeded\n" );
4906 ok( GetLastError() == ERROR_NOACCESS, "wrong error %u\n", GetLastError() );
4907 SetLastError( 0xdeadbeef );
4908 ok( pGetProcessDefaultLayout( &layout ),
4909 "GetProcessDefaultLayout failed err %u\n", GetLastError ());
4910 ok( layout == 0, "GetProcessDefaultLayout wrong layout %x\n", layout );
4911 SetLastError( 0xdeadbeef );
4912 ok( pSetProcessDefaultLayout( 7 ),
4913 "SetProcessDefaultLayout failed err %u\n", GetLastError ());
4914 ok( pGetProcessDefaultLayout( &layout ),
4915 "GetProcessDefaultLayout failed err %u\n", GetLastError ());
4916 ok( layout == 7, "GetProcessDefaultLayout wrong layout %x\n", layout );
4917 SetLastError( 0xdeadbeef );
4918 ok( pSetProcessDefaultLayout( LAYOUT_RTL ),
4919 "SetProcessDefaultLayout failed err %u\n", GetLastError ());
4920 ok( pGetProcessDefaultLayout( &layout ),
4921 "GetProcessDefaultLayout failed err %u\n", GetLastError ());
4922 ok( layout == LAYOUT_RTL, "GetProcessDefaultLayout wrong layout %x\n", layout );
4923 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4924 0, 0, 100, 100, 0, 0, 0, NULL);
4925 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4926 expect_ex_style( hwnd, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
4927 DestroyWindow( hwnd );
4928 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4929 0, 0, 100, 100, parent, 0, 0, NULL);
4930 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4931 expect_ex_style( hwnd, WS_EX_APPWINDOW );
4932 DestroyWindow( hwnd );
4933 pSetProcessDefaultLayout( 0 );
4935 else win_skip( "SetProcessDefaultLayout not supported\n" );
4937 else win_skip( "SetLayout not supported\n" );
4939 else win_skip( "SetLayout not available\n" );
4941 DestroyWindow(parent);
4943 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4944 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4946 #undef expect_gle_broken_9x
4947 #undef expect_menu
4948 #undef expect_style
4949 #undef expect_ex_style
4952 /* function that remembers whether the system the test is running on sets the
4953 * last error for user32 functions to make the tests stricter */
4954 static int check_error(DWORD actual, DWORD expected)
4956 static int sets_last_error = -1;
4957 if (sets_last_error == -1)
4958 sets_last_error = (actual != 0xdeadbeef);
4959 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
4962 static void test_SetWindowLong(void)
4964 LONG_PTR retval;
4965 WNDPROC old_window_procW;
4967 SetLastError(0xdeadbeef);
4968 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
4969 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
4970 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
4971 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4973 SetLastError(0xdeadbeef);
4974 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
4975 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
4976 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
4977 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4979 SetLastError(0xdeadbeef);
4980 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4981 ok((WNDPROC)retval == main_window_procA || broken(!retval), /* win9x */
4982 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
4983 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4984 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
4985 ok((WNDPROC)retval == main_window_procA,
4986 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4987 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
4989 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
4990 SetLastError(0xdeadbeef);
4991 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
4992 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
4994 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4995 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
4996 ok((WNDPROC)retval == old_window_procW,
4997 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4998 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
5000 /* set it back to ANSI */
5001 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
5005 static void test_ShowWindow(void)
5007 HWND hwnd;
5008 DWORD style;
5009 RECT rcMain, rc, rcMinimized;
5010 LPARAM ret;
5012 SetRect(&rcMain, 120, 120, 210, 210);
5014 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
5015 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5016 WS_MAXIMIZEBOX | WS_POPUP,
5017 rcMain.left, rcMain.top,
5018 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
5019 0, 0, 0, NULL);
5020 assert(hwnd);
5022 style = GetWindowLong(hwnd, GWL_STYLE);
5023 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5024 ok(!(style & WS_VISIBLE), "window should not be visible\n");
5025 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5026 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5027 GetWindowRect(hwnd, &rc);
5028 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5029 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5030 rc.left, rc.top, rc.right, rc.bottom);
5032 ret = ShowWindow(hwnd, SW_SHOW);
5033 ok(!ret, "not expected ret: %lu\n", ret);
5034 style = GetWindowLong(hwnd, GWL_STYLE);
5035 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5036 ok(style & WS_VISIBLE, "window should be visible\n");
5037 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5038 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5039 GetWindowRect(hwnd, &rc);
5040 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5041 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5042 rc.left, rc.top, rc.right, rc.bottom);
5044 ret = ShowWindow(hwnd, SW_MINIMIZE);
5045 ok(ret, "not expected ret: %lu\n", ret);
5046 style = GetWindowLong(hwnd, GWL_STYLE);
5047 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5048 ok(style & WS_VISIBLE, "window should be visible\n");
5049 ok(style & WS_MINIMIZE, "window should be minimized\n");
5050 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5051 GetWindowRect(hwnd, &rcMinimized);
5052 ok(!EqualRect(&rcMain, &rcMinimized), "rects shouldn't match\n");
5053 /* shouldn't be able to resize minized windows */
5054 ret = SetWindowPos(hwnd, 0, 0, 0,
5055 (rcMinimized.right - rcMinimized.left) * 2,
5056 (rcMinimized.bottom - rcMinimized.top) * 2,
5057 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
5058 ok(ret, "not expected ret: %lu\n", ret);
5059 GetWindowRect(hwnd, &rc);
5060 ok(EqualRect(&rc, &rcMinimized), "rects should match\n");
5062 ShowWindow(hwnd, SW_RESTORE);
5063 ok(ret, "not expected ret: %lu\n", ret);
5064 style = GetWindowLong(hwnd, GWL_STYLE);
5065 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5066 ok(style & WS_VISIBLE, "window should be visible\n");
5067 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5068 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5069 GetWindowRect(hwnd, &rc);
5070 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5071 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5072 rc.left, rc.top, rc.right, rc.bottom);
5074 ret = EnableWindow(hwnd, FALSE);
5075 ok(!ret, "not expected ret: %lu\n", ret);
5076 style = GetWindowLong(hwnd, GWL_STYLE);
5077 ok(style & WS_DISABLED, "window should be disabled\n");
5079 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
5080 ok(!ret, "not expected ret: %lu\n", ret);
5081 style = GetWindowLong(hwnd, GWL_STYLE);
5082 ok(style & WS_DISABLED, "window should be disabled\n");
5083 ok(style & WS_VISIBLE, "window should be visible\n");
5084 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5085 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5086 GetWindowRect(hwnd, &rc);
5087 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5088 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5089 rc.left, rc.top, rc.right, rc.bottom);
5091 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
5092 ok(!ret, "not expected ret: %lu\n", ret);
5093 style = GetWindowLong(hwnd, GWL_STYLE);
5094 ok(style & WS_DISABLED, "window should be disabled\n");
5095 ok(style & WS_VISIBLE, "window should be visible\n");
5096 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5097 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5098 GetWindowRect(hwnd, &rc);
5099 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5100 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5101 rc.left, rc.top, rc.right, rc.bottom);
5103 ret = ShowWindow(hwnd, SW_MINIMIZE);
5104 ok(ret, "not expected ret: %lu\n", ret);
5105 style = GetWindowLong(hwnd, GWL_STYLE);
5106 ok(style & WS_DISABLED, "window should be disabled\n");
5107 ok(style & WS_VISIBLE, "window should be visible\n");
5108 ok(style & WS_MINIMIZE, "window should be minimized\n");
5109 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5110 GetWindowRect(hwnd, &rc);
5111 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
5113 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
5114 ok(!ret, "not expected ret: %lu\n", ret);
5115 style = GetWindowLong(hwnd, GWL_STYLE);
5116 ok(style & WS_DISABLED, "window should be disabled\n");
5117 ok(style & WS_VISIBLE, "window should be visible\n");
5118 ok(style & WS_MINIMIZE, "window should be minimized\n");
5119 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5120 GetWindowRect(hwnd, &rc);
5121 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
5123 ret = ShowWindow(hwnd, SW_RESTORE);
5124 ok(ret, "not expected ret: %lu\n", ret);
5125 style = GetWindowLong(hwnd, GWL_STYLE);
5126 ok(style & WS_DISABLED, "window should be disabled\n");
5127 ok(style & WS_VISIBLE, "window should be visible\n");
5128 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5129 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5130 GetWindowRect(hwnd, &rc);
5131 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5132 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5133 rc.left, rc.top, rc.right, rc.bottom);
5135 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
5136 ok(!ret, "not expected ret: %lu\n", ret);
5137 ok(IsWindow(hwnd), "window should exist\n");
5139 ret = EnableWindow(hwnd, TRUE);
5140 ok(ret, "not expected ret: %lu\n", ret);
5142 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
5143 ok(!ret, "not expected ret: %lu\n", ret);
5144 ok(!IsWindow(hwnd), "window should not exist\n");
5147 static void test_gettext(void)
5149 WNDCLASS cls;
5150 LPCSTR clsname = "gettexttest";
5151 HWND hwnd;
5152 LRESULT r;
5154 memset( &cls, 0, sizeof cls );
5155 cls.lpfnWndProc = DefWindowProc;
5156 cls.lpszClassName = clsname;
5157 cls.hInstance = GetModuleHandle(NULL);
5159 if (!RegisterClass( &cls )) return;
5161 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
5162 ok( hwnd != NULL, "window was null\n");
5164 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
5165 ok( r == 0, "settext should return zero\n");
5167 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
5168 ok( r == 0, "settext should return zero (%ld)\n", r);
5170 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
5171 ok( r == 0, "settext should return zero (%ld)\n", r);
5173 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
5174 ok( r == 0, "settext should return zero (%ld)\n", r);
5176 DestroyWindow(hwnd);
5177 UnregisterClass( clsname, NULL );
5181 static void test_GetUpdateRect(void)
5183 MSG msg;
5184 BOOL ret, parent_wm_paint, grandparent_wm_paint;
5185 RECT rc1, rc2;
5186 HWND hgrandparent, hparent, hchild;
5187 WNDCLASSA cls;
5188 static const char classNameA[] = "GetUpdateRectClass";
5190 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
5191 0, 0, 100, 100, NULL, NULL, 0, NULL);
5193 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
5194 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
5196 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
5197 10, 10, 30, 30, hparent, NULL, 0, NULL);
5199 ShowWindow(hgrandparent, SW_SHOW);
5200 UpdateWindow(hgrandparent);
5201 flush_events( TRUE );
5203 ShowWindow(hchild, SW_HIDE);
5204 SetRect(&rc2, 0, 0, 0, 0);
5205 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5206 ok(!ret, "GetUpdateRect returned not empty region\n");
5207 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5208 rc1.left, rc1.top, rc1.right, rc1.bottom,
5209 rc2.left, rc2.top, rc2.right, rc2.bottom);
5211 SetRect(&rc2, 10, 10, 40, 40);
5212 ret = GetUpdateRect(hparent, &rc1, FALSE);
5213 ok(ret, "GetUpdateRect returned empty region\n");
5214 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5215 rc1.left, rc1.top, rc1.right, rc1.bottom,
5216 rc2.left, rc2.top, rc2.right, rc2.bottom);
5218 parent_wm_paint = FALSE;
5219 grandparent_wm_paint = FALSE;
5220 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
5222 if (msg.message == WM_PAINT)
5224 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
5225 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
5227 DispatchMessage(&msg);
5229 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
5230 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
5232 DestroyWindow(hgrandparent);
5234 cls.style = 0;
5235 cls.lpfnWndProc = DefWindowProcA;
5236 cls.cbClsExtra = 0;
5237 cls.cbWndExtra = 0;
5238 cls.hInstance = GetModuleHandleA(0);
5239 cls.hIcon = 0;
5240 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5241 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5242 cls.lpszMenuName = NULL;
5243 cls.lpszClassName = classNameA;
5245 if(!RegisterClassA(&cls)) {
5246 trace("Register failed %d\n", GetLastError());
5247 return;
5250 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
5251 0, 0, 100, 100, NULL, NULL, 0, NULL);
5253 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
5254 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
5256 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
5257 10, 10, 30, 30, hparent, NULL, 0, NULL);
5259 ShowWindow(hgrandparent, SW_SHOW);
5260 UpdateWindow(hgrandparent);
5261 flush_events( TRUE );
5263 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5264 ok(!ret, "GetUpdateRect returned not empty region\n");
5266 ShowWindow(hchild, SW_HIDE);
5268 SetRect(&rc2, 0, 0, 0, 0);
5269 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5270 ok(!ret, "GetUpdateRect returned not empty region\n");
5271 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5272 rc1.left, rc1.top, rc1.right, rc1.bottom,
5273 rc2.left, rc2.top, rc2.right, rc2.bottom);
5275 SetRect(&rc2, 10, 10, 40, 40);
5276 ret = GetUpdateRect(hparent, &rc1, FALSE);
5277 ok(ret, "GetUpdateRect returned empty region\n");
5278 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5279 rc1.left, rc1.top, rc1.right, rc1.bottom,
5280 rc2.left, rc2.top, rc2.right, rc2.bottom);
5282 parent_wm_paint = FALSE;
5283 grandparent_wm_paint = FALSE;
5284 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
5286 if (msg.message == WM_PAINT)
5288 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
5289 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
5291 DispatchMessage(&msg);
5293 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
5294 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
5296 DestroyWindow(hgrandparent);
5300 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5302 if(msg == WM_PAINT)
5304 PAINTSTRUCT ps;
5305 RECT updateRect;
5306 DWORD waitResult;
5307 HWND win;
5308 const int waitTime = 2000;
5310 BeginPaint(hwnd, &ps);
5312 /* create and destroy window to create an exposed region on this window */
5313 win = CreateWindowA("static", "win", WS_VISIBLE,
5314 10,10,50,50, NULL, NULL, 0, NULL);
5315 DestroyWindow(win);
5317 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
5319 ValidateRect(hwnd, NULL);
5320 EndPaint(hwnd, &ps);
5322 if(waitResult != WAIT_TIMEOUT)
5324 GetUpdateRect(hwnd, &updateRect, FALSE);
5325 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
5328 return 1;
5330 return DefWindowProc(hwnd, msg, wParam, lParam);
5333 static void test_Expose(void)
5335 WNDCLASSA cls;
5336 HWND mw;
5338 memset(&cls, 0, sizeof(WNDCLASSA));
5339 cls.lpfnWndProc = TestExposedRegion_WndProc;
5340 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5341 cls.lpszClassName = "TestExposeClass";
5342 RegisterClassA(&cls);
5344 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
5345 0, 0, 200, 100, NULL, NULL, 0, NULL);
5347 UpdateWindow(mw);
5348 DestroyWindow(mw);
5351 static LRESULT CALLBACK TestNCRedraw_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5353 static UINT ncredrawflags;
5354 PAINTSTRUCT ps;
5356 switch(msg)
5358 case WM_CREATE:
5359 ncredrawflags = *(UINT *) (((CREATESTRUCT *)lParam)->lpCreateParams);
5360 return 0;
5361 case WM_NCPAINT:
5362 RedrawWindow(hwnd, NULL, NULL, ncredrawflags);
5363 break;
5364 case WM_PAINT:
5365 BeginPaint(hwnd, &ps);
5366 EndPaint(hwnd, &ps);
5367 return 0;
5369 return DefWindowProc(hwnd, msg, wParam, lParam);
5372 static void run_NCRedrawLoop(UINT flags)
5374 HWND hwnd;
5375 MSG msg;
5377 UINT loopcount = 0;
5379 hwnd = CreateWindowA("TestNCRedrawClass", "MainWindow",
5380 WS_OVERLAPPEDWINDOW, 0, 0, 200, 100,
5381 NULL, NULL, 0, &flags);
5382 ShowWindow(hwnd, SW_SHOW);
5383 UpdateWindow(hwnd);
5384 flush_events( FALSE );
5385 while(PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE) != 0)
5387 if (msg.message == WM_PAINT) loopcount++;
5388 if (loopcount >= 100) break;
5389 TranslateMessage(&msg);
5390 DispatchMessage(&msg);
5391 MsgWaitForMultipleObjects(0, NULL, FALSE, 100, QS_ALLINPUT);
5393 if (flags == (RDW_INVALIDATE | RDW_FRAME))
5394 todo_wine ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
5395 else
5396 ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
5397 DestroyWindow(hwnd);
5400 static void test_NCRedraw(void)
5402 WNDCLASSA wndclass;
5404 wndclass.lpszClassName = "TestNCRedrawClass";
5405 wndclass.style = CS_HREDRAW | CS_VREDRAW;
5406 wndclass.lpfnWndProc = TestNCRedraw_WndProc;
5407 wndclass.cbClsExtra = 0;
5408 wndclass.cbWndExtra = 0;
5409 wndclass.hInstance = 0;
5410 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
5411 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
5412 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
5413 wndclass.lpszMenuName = NULL;
5415 RegisterClassA(&wndclass);
5417 run_NCRedrawLoop(RDW_INVALIDATE | RDW_FRAME);
5418 run_NCRedrawLoop(RDW_INVALIDATE);
5421 static void test_GetWindowModuleFileName(void)
5423 HWND hwnd;
5424 HINSTANCE hinst;
5425 UINT ret1, ret2;
5426 char buf1[MAX_PATH], buf2[MAX_PATH];
5428 if (!pGetWindowModuleFileNameA)
5430 win_skip("GetWindowModuleFileNameA is not available\n");
5431 return;
5434 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
5435 assert(hwnd);
5437 hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
5438 ok(hinst == 0 || broken(hinst == GetModuleHandle(0)), /* win9x */ "expected 0, got %p\n", hinst);
5440 buf1[0] = 0;
5441 SetLastError(0xdeadbeef);
5442 ret1 = GetModuleFileName(hinst, buf1, sizeof(buf1));
5443 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
5445 buf2[0] = 0;
5446 SetLastError(0xdeadbeef);
5447 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
5448 ok(ret2 || broken(!ret2), /* nt4 sp 3 */
5449 "GetWindowModuleFileNameA error %u\n", GetLastError());
5451 if (ret2)
5453 ok(ret1 == ret2 || broken(ret2 == ret1 + 1), /* win98 */ "%u != %u\n", ret1, ret2);
5454 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
5456 hinst = GetModuleHandle(0);
5458 SetLastError(0xdeadbeef);
5459 ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
5460 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
5461 "expected %u, got %u\n", ret1 - 2, ret2);
5462 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5463 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5464 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5466 SetLastError(0xdeadbeef);
5467 ret2 = GetModuleFileName(hinst, buf2, 0);
5468 ok(!ret2, "GetModuleFileName should return 0\n");
5469 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5470 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5471 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5473 SetLastError(0xdeadbeef);
5474 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
5475 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3) /* win98 */ || broken(!ret2), /* nt4 sp3 */
5476 "expected %u, got %u\n", ret1 - 2, ret2);
5477 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5478 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5479 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5481 SetLastError(0xdeadbeef);
5482 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
5483 ok(!ret2, "expected 0, got %u\n", ret2);
5484 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5485 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5486 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5488 DestroyWindow(hwnd);
5490 buf2[0] = 0;
5491 hwnd = (HWND)0xdeadbeef;
5492 SetLastError(0xdeadbeef);
5493 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
5494 ok(!ret1, "expected 0, got %u\n", ret1);
5495 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef), /* win9x */
5496 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
5498 hwnd = FindWindow("Shell_TrayWnd", NULL);
5499 ok(IsWindow(hwnd) || broken(!hwnd), "got invalid tray window %p\n", hwnd);
5500 SetLastError(0xdeadbeef);
5501 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
5502 ok(!ret1 || broken(ret1), /* win98 */ "expected 0, got %u\n", ret1);
5504 if (!ret1) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
5506 ret1 = GetModuleFileName(0, buf1, sizeof(buf1));
5507 hwnd = GetDesktopWindow();
5508 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
5509 SetLastError(0xdeadbeef);
5510 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
5511 ok(!ret2 ||
5512 ret1 == ret2 || /* vista */
5513 broken(ret2), /* some win98 return user.exe as file name */
5514 "expected 0 or %u, got %u %s\n", ret1, ret2, buf2);
5518 static void test_hwnd_message(void)
5520 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
5521 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
5523 HWND parent = 0, hwnd, found;
5524 RECT rect;
5526 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
5527 on CreateWindowExA and crash later in the test.
5528 Use UNICODE here to fail on win9x */
5529 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
5530 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
5531 if (!hwnd)
5533 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
5534 return;
5537 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
5538 if (pGetAncestor)
5540 char buffer[100];
5541 HWND root, desktop = GetDesktopWindow();
5543 parent = pGetAncestor(hwnd, GA_PARENT);
5544 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
5545 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
5546 root = pGetAncestor(hwnd, GA_ROOT);
5547 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
5548 ok( !pGetAncestor(parent, GA_PARENT) || broken(pGetAncestor(parent, GA_PARENT) != 0), /* win2k */
5549 "parent shouldn't have parent %p\n", pGetAncestor(parent, GA_PARENT) );
5550 trace("parent %p root %p desktop %p\n", parent, root, desktop);
5551 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
5552 ok( !lstrcmpi( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
5553 GetWindowRect( parent, &rect );
5554 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
5555 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
5557 GetWindowRect( hwnd, &rect );
5558 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
5559 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
5561 /* test FindWindow behavior */
5563 found = FindWindowExA( 0, 0, 0, "message window" );
5564 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
5565 SetLastError(0xdeadbeef);
5566 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
5567 ok( found == 0, "found message window %p/%p\n", found, hwnd );
5568 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
5569 if (parent)
5571 found = FindWindowExA( parent, 0, 0, "message window" );
5572 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
5575 /* test IsChild behavior */
5577 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
5579 /* test IsWindowVisible behavior */
5581 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
5582 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
5584 DestroyWindow(hwnd);
5587 static void test_layered_window(void)
5589 HWND hwnd;
5590 COLORREF key = 0;
5591 BYTE alpha = 0;
5592 DWORD flags = 0;
5593 POINT pt = { 0, 0 };
5594 SIZE sz = { 200, 200 };
5595 HDC hdc;
5596 HBITMAP hbm;
5597 BOOL ret;
5599 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes || !pUpdateLayeredWindow)
5601 win_skip( "layered windows not supported\n" );
5602 return;
5605 hdc = CreateCompatibleDC( 0 );
5606 hbm = CreateCompatibleBitmap( hdc, 200, 200 );
5607 SelectObject( hdc, hbm );
5609 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
5610 100, 100, 200, 200, 0, 0, 0, NULL);
5611 assert( hwnd );
5612 SetLastError( 0xdeadbeef );
5613 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
5614 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
5615 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
5616 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5617 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
5618 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
5619 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
5620 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5621 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5622 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5623 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
5624 ok( ret, "UpdateLayeredWindow should succeed on layered window\n" );
5625 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5626 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5627 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
5628 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5629 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5630 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5631 ok( key == 0x123456 || key == 0, "wrong color key %x\n", key );
5632 ok( alpha == 44, "wrong alpha %u\n", alpha );
5633 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
5634 SetLastError( 0xdeadbeef );
5635 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
5636 ok( !ret, "UpdateLayeredWindow should fail on layered but initialized window\n" );
5637 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
5639 /* clearing WS_EX_LAYERED resets attributes */
5640 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5641 SetLastError( 0xdeadbeef );
5642 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
5643 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
5644 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5645 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
5646 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5647 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5648 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5649 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
5650 ok( ret, "UpdateLayeredWindow should succeed on layered window\n" );
5651 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
5652 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5653 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5654 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5655 ok( key == 0x654321, "wrong color key %x\n", key );
5656 ok( alpha == 22, "wrong alpha %u\n", alpha );
5657 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
5658 SetLastError( 0xdeadbeef );
5659 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
5660 ok( !ret, "UpdateLayeredWindow should fail on layered but initialized window\n" );
5661 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
5663 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
5664 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5665 alpha = 0;
5666 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5667 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5668 ok( key == 0x888888, "wrong color key %x\n", key );
5669 /* alpha not changed on vista if LWA_ALPHA is not set */
5670 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
5671 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
5673 /* color key may or may not be changed without LWA_COLORKEY */
5674 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
5675 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5676 alpha = 0;
5677 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5678 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5679 ok( key == 0x888888 || key == 0x999999, "wrong color key %x\n", key );
5680 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
5681 ok( flags == 0, "wrong flags %x\n", flags );
5683 /* default alpha and color key is 0 */
5684 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5685 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5686 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
5687 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5688 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5689 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5690 ok( key == 0 || key == 0x222222, "wrong color key %x\n", key );
5691 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
5692 ok( flags == 0, "wrong flags %x\n", flags );
5694 DestroyWindow( hwnd );
5695 DeleteDC( hdc );
5696 DeleteObject( hbm );
5699 static MONITORINFO mi;
5701 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
5703 switch (msg)
5705 case WM_NCCREATE:
5707 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
5708 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs->x, cs->y, cs->cx, cs->cy);
5709 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
5710 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
5711 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
5712 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5713 cs->x, cs->y, cs->cx, cs->cy);
5714 break;
5716 case WM_GETMINMAXINFO:
5718 MINMAXINFO *minmax = (MINMAXINFO *)lp;
5719 dump_minmax_info(minmax);
5720 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
5721 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
5722 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
5723 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
5724 break;
5727 return DefWindowProc(hwnd, msg, wp, lp);
5730 static void test_fullscreen(void)
5732 static const DWORD t_style[] = {
5733 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
5735 static const DWORD t_ex_style[] = {
5736 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
5738 WNDCLASS cls;
5739 HWND hwnd;
5740 int i, j;
5741 POINT pt;
5742 RECT rc;
5743 HMONITOR hmon;
5744 LRESULT ret;
5746 if (!pGetMonitorInfoA || !pMonitorFromPoint)
5748 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
5749 return;
5752 pt.x = pt.y = 0;
5753 SetLastError(0xdeadbeef);
5754 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
5755 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
5757 mi.cbSize = sizeof(mi);
5758 SetLastError(0xdeadbeef);
5759 ret = pGetMonitorInfoA(hmon, &mi);
5760 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
5761 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
5762 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5763 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5765 cls.style = 0;
5766 cls.lpfnWndProc = fullscreen_wnd_proc;
5767 cls.cbClsExtra = 0;
5768 cls.cbWndExtra = 0;
5769 cls.hInstance = GetModuleHandle(0);
5770 cls.hIcon = 0;
5771 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5772 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5773 cls.lpszMenuName = NULL;
5774 cls.lpszClassName = "fullscreen_class";
5775 RegisterClass(&cls);
5777 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
5779 DWORD style, ex_style;
5781 /* avoid a WM interaction */
5782 assert(!(t_style[i] & WS_VISIBLE));
5784 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
5786 int fixup;
5788 style = t_style[i];
5789 ex_style = t_ex_style[j];
5791 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5792 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5793 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5794 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5795 GetWindowRect(hwnd, &rc);
5796 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5797 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5798 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5799 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5800 DestroyWindow(hwnd);
5802 style = t_style[i] | WS_MAXIMIZE;
5803 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5804 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5805 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5806 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5807 GetWindowRect(hwnd, &rc);
5808 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5809 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5810 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5811 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5812 DestroyWindow(hwnd);
5814 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
5815 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5816 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5817 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5818 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5819 GetWindowRect(hwnd, &rc);
5820 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5821 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5822 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5823 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5824 DestroyWindow(hwnd);
5826 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
5827 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5828 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5829 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5830 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5831 GetWindowRect(hwnd, &rc);
5832 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5833 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5834 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5835 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5836 DestroyWindow(hwnd);
5838 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
5839 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5840 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5841 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5842 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5843 GetWindowRect(hwnd, &rc);
5844 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5845 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5846 fixup = min(abs(rc.left), abs(rc.top));
5847 InflateRect(&rc, -fixup, -fixup);
5848 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5849 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5850 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
5851 ex_style, style, rc.left, rc.top, rc.right, rc.bottom,
5852 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5853 DestroyWindow(hwnd);
5855 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
5856 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5857 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5858 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5859 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5860 GetWindowRect(hwnd, &rc);
5861 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5862 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5863 fixup = min(abs(rc.left), abs(rc.top));
5864 InflateRect(&rc, -fixup, -fixup);
5865 if (style & (WS_CHILD | WS_POPUP))
5866 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5867 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5868 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5869 else
5870 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5871 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5872 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5873 DestroyWindow(hwnd);
5877 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5880 static BOOL test_thick_child_got_minmax;
5881 static const char * test_thick_child_name;
5882 static LONG test_thick_child_style;
5883 static LONG test_thick_child_exStyle;
5885 static LRESULT WINAPI test_thick_child_size_winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5887 MINMAXINFO* minmax;
5888 int expectedMinTrackX;
5889 int expectedMinTrackY;
5890 int actualMinTrackX;
5891 int actualMinTrackY;
5892 int expectedMaxTrackX;
5893 int expectedMaxTrackY;
5894 int actualMaxTrackX;
5895 int actualMaxTrackY;
5896 int expectedMaxSizeX;
5897 int expectedMaxSizeY;
5898 int actualMaxSizeX;
5899 int actualMaxSizeY;
5900 int expectedPosX;
5901 int expectedPosY;
5902 int actualPosX;
5903 int actualPosY;
5904 LONG adjustedStyle;
5905 RECT rect;
5906 switch (msg)
5908 case WM_GETMINMAXINFO:
5910 minmax = (MINMAXINFO *)lparam;
5911 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
5912 dump_minmax_info( minmax );
5914 test_thick_child_got_minmax = TRUE;
5917 adjustedStyle = test_thick_child_style;
5918 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
5919 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5920 GetClientRect(GetParent(hwnd), &rect);
5921 AdjustWindowRectEx(&rect, adjustedStyle, FALSE, test_thick_child_exStyle);
5923 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
5925 expectedMinTrackX = GetSystemMetrics(SM_CXMINTRACK);
5926 expectedMinTrackY = GetSystemMetrics(SM_CYMINTRACK);
5928 else
5930 expectedMinTrackX = -2 * rect.left;
5931 expectedMinTrackY = -2 * rect.top;
5933 actualMinTrackX = minmax->ptMinTrackSize.x;
5934 actualMinTrackY = minmax->ptMinTrackSize.y;
5936 ok(actualMinTrackX == expectedMinTrackX && actualMinTrackY == expectedMinTrackY,
5937 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
5938 expectedMinTrackX, expectedMinTrackY, actualMinTrackX, actualMinTrackY,
5939 test_thick_child_name);
5941 actualMaxTrackX = minmax->ptMaxTrackSize.x;
5942 actualMaxTrackY = minmax->ptMaxTrackSize.y;
5943 expectedMaxTrackX = GetSystemMetrics(SM_CXMAXTRACK);
5944 expectedMaxTrackY = GetSystemMetrics(SM_CYMAXTRACK);
5945 ok(actualMaxTrackX == expectedMaxTrackX && actualMaxTrackY == expectedMaxTrackY,
5946 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
5947 expectedMaxTrackX, expectedMaxTrackY, actualMaxTrackX, actualMaxTrackY,
5948 test_thick_child_name);
5950 expectedMaxSizeX = rect.right - rect.left;
5951 expectedMaxSizeY = rect.bottom - rect.top;
5952 actualMaxSizeX = minmax->ptMaxSize.x;
5953 actualMaxSizeY = minmax->ptMaxSize.y;
5955 ok(actualMaxSizeX == expectedMaxSizeX && actualMaxSizeY == expectedMaxSizeY,
5956 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
5957 expectedMaxSizeX, expectedMaxSizeY, actualMaxSizeX, actualMaxSizeY,
5958 test_thick_child_name);
5961 expectedPosX = rect.left;
5962 expectedPosY = rect.top;
5963 actualPosX = minmax->ptMaxPosition.x;
5964 actualPosY = minmax->ptMaxPosition.y;
5965 ok(actualPosX == expectedPosX && actualPosY == expectedPosY,
5966 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
5967 expectedPosX, expectedPosY, actualPosX, actualPosY, test_thick_child_name);
5969 break;
5973 return DefWindowProcA(hwnd, msg, wparam, lparam);
5976 #define NUMBER_OF_THICK_CHILD_TESTS 16
5977 static void test_thick_child_size(HWND parentWindow)
5979 BOOL success;
5980 RECT childRect;
5981 RECT adjustedParentRect;
5982 HWND childWindow;
5983 LONG childWidth;
5984 LONG childHeight;
5985 LONG expectedWidth;
5986 LONG expectedHeight;
5987 WNDCLASSA cls;
5988 LPCTSTR className = "THICK_CHILD_CLASS";
5989 int i;
5990 LONG adjustedStyle;
5991 static const LONG styles[NUMBER_OF_THICK_CHILD_TESTS] = {
5992 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5993 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5994 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5995 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5996 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5997 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5998 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5999 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6000 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6001 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6002 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6003 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6004 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6005 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6006 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6007 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6010 static const LONG exStyles[NUMBER_OF_THICK_CHILD_TESTS] = {
6015 WS_EX_DLGMODALFRAME,
6016 WS_EX_DLGMODALFRAME,
6017 WS_EX_DLGMODALFRAME,
6018 WS_EX_DLGMODALFRAME,
6019 WS_EX_STATICEDGE,
6020 WS_EX_STATICEDGE,
6021 WS_EX_STATICEDGE,
6022 WS_EX_STATICEDGE,
6023 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6024 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6025 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6026 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6028 static const char *styleName[NUMBER_OF_THICK_CHILD_TESTS] = {
6029 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
6030 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
6031 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
6032 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
6033 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
6034 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
6035 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
6036 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
6037 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
6038 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
6039 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
6040 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
6041 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6042 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6043 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6044 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6047 cls.style = 0;
6048 cls.lpfnWndProc = test_thick_child_size_winproc;
6049 cls.cbClsExtra = 0;
6050 cls.cbWndExtra = 0;
6051 cls.hInstance = GetModuleHandleA(0);
6052 cls.hIcon = 0;
6053 cls.hCursor = LoadCursorA(0, IDC_ARROW);
6054 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6055 cls.lpszMenuName = NULL;
6056 cls.lpszClassName = className;
6057 SetLastError(0xdeadbeef);
6058 success = RegisterClassA(&cls);
6059 ok(success,"RegisterClassA failed, error: %u\n", GetLastError());
6061 for(i = 0; i < NUMBER_OF_THICK_CHILD_TESTS; i++)
6063 test_thick_child_name = styleName[i];
6064 test_thick_child_style = styles[i];
6065 test_thick_child_exStyle = exStyles[i];
6066 test_thick_child_got_minmax = FALSE;
6068 SetLastError(0xdeadbeef);
6069 childWindow = CreateWindowEx( exStyles[i], className, "", styles[i], 0, 0, 0, 0, parentWindow, 0, GetModuleHandleA(0), NULL );
6070 ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
6072 ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
6074 SetLastError(0xdeadbeef);
6075 success = GetWindowRect(childWindow, &childRect);
6076 ok(success,"GetWindowRect call failed, error: %u\n", GetLastError());
6077 childWidth = childRect.right - childRect.left;
6078 childHeight = childRect.bottom - childRect.top;
6080 adjustedStyle = styles[i];
6081 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
6082 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
6083 GetClientRect(GetParent(childWindow), &adjustedParentRect);
6084 AdjustWindowRectEx(&adjustedParentRect, adjustedStyle, FALSE, test_thick_child_exStyle);
6087 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
6089 expectedWidth = GetSystemMetrics(SM_CXMINTRACK);
6090 expectedHeight = GetSystemMetrics(SM_CYMINTRACK);
6092 else
6094 expectedWidth = -2 * adjustedParentRect.left;
6095 expectedHeight = -2 * adjustedParentRect.top;
6098 ok((childWidth == expectedWidth) && (childHeight == expectedHeight),
6099 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
6100 test_thick_child_name, expectedWidth, expectedHeight, childWidth, childHeight);
6102 SetLastError(0xdeadbeef);
6103 success = DestroyWindow(childWindow);
6104 ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
6106 ok(UnregisterClass(className, GetModuleHandleA(0)),"UnregisterClass call failed\n");
6109 static void test_handles( HWND full_hwnd )
6111 HWND hwnd = full_hwnd;
6112 BOOL ret;
6113 RECT rect;
6115 SetLastError( 0xdeadbeef );
6116 ret = GetWindowRect( hwnd, &rect );
6117 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6119 #ifdef _WIN64
6120 if ((ULONG_PTR)full_hwnd >> 32)
6121 hwnd = (HWND)((ULONG_PTR)full_hwnd & ~0u);
6122 else
6123 hwnd = (HWND)((ULONG_PTR)full_hwnd | ((ULONG_PTR)~0u << 32));
6124 SetLastError( 0xdeadbeef );
6125 ret = GetWindowRect( hwnd, &rect );
6126 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6128 hwnd = (HWND)(((ULONG_PTR)full_hwnd & ~0u) | ((ULONG_PTR)0x1234 << 32));
6129 SetLastError( 0xdeadbeef );
6130 ret = GetWindowRect( hwnd, &rect );
6131 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6133 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x9876 << 16));
6134 SetLastError( 0xdeadbeef );
6135 ret = GetWindowRect( hwnd, &rect );
6136 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
6137 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
6139 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x12345678 << 16));
6140 SetLastError( 0xdeadbeef );
6141 ret = GetWindowRect( hwnd, &rect );
6142 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
6143 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
6144 #endif
6147 static void test_winregion(void)
6149 HWND hwnd;
6150 RECT r;
6151 int ret, width;
6152 HRGN hrgn;
6154 if (!pGetWindowRgnBox)
6156 win_skip("GetWindowRgnBox not supported\n");
6157 return;
6160 hwnd = CreateWindowExA(0, "static", NULL, WS_VISIBLE, 10, 10, 10, 10, NULL, 0, 0, NULL);
6161 /* NULL prect */
6162 SetLastError(0xdeadbeef);
6163 ret = pGetWindowRgnBox(hwnd, NULL);
6164 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
6165 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
6167 hrgn = CreateRectRgn(2, 3, 10, 15);
6168 ok( hrgn != NULL, "Region creation failed\n");
6169 if (hrgn)
6171 SetWindowRgn(hwnd, hrgn, FALSE);
6173 SetLastError(0xdeadbeef);
6174 ret = pGetWindowRgnBox(hwnd, NULL);
6175 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
6176 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
6178 r.left = r.top = r.right = r.bottom = 0;
6179 ret = pGetWindowRgnBox(hwnd, &r);
6180 ok( ret == SIMPLEREGION, "Expected SIMPLEREGION, got %d\n", ret);
6181 ok( r.left == 2 && r.top == 3 && r.right == 10 && r.bottom == 15,
6182 "Expected (2,3,10,15), got (%d,%d,%d,%d)\n", r.left, r.top,
6183 r.right, r.bottom);
6184 if (pMirrorRgn)
6186 hrgn = CreateRectRgn(2, 3, 10, 15);
6187 ret = pMirrorRgn( hwnd, hrgn );
6188 ok( ret == TRUE, "MirrorRgn failed %u\n", ret );
6189 r.left = r.top = r.right = r.bottom = 0;
6190 GetWindowRect( hwnd, &r );
6191 width = r.right - r.left;
6192 r.left = r.top = r.right = r.bottom = 0;
6193 ret = GetRgnBox( hrgn, &r );
6194 ok( ret == SIMPLEREGION, "GetRgnBox failed %u\n", ret );
6195 ok( r.left == width - 10 && r.top == 3 && r.right == width - 2 && r.bottom == 15,
6196 "Wrong rectangle (%d,%d,%d,%d) for width %d\n", r.left, r.top, r.right, r.bottom, width );
6198 else win_skip( "MirrorRgn not supported\n" );
6200 DestroyWindow(hwnd);
6203 static void test_rtl_layout(void)
6205 HWND parent, child;
6206 RECT r;
6207 POINT pt;
6209 if (!pSetProcessDefaultLayout)
6211 win_skip( "SetProcessDefaultLayout not supported\n" );
6212 return;
6215 parent = CreateWindowExA(WS_EX_LAYOUTRTL, "static", NULL, WS_POPUP, 100, 100, 300, 300, NULL, 0, 0, NULL);
6216 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 10, 10, 20, 20, parent, 0, 0, NULL);
6218 GetWindowRect( parent, &r );
6219 ok( r.left == 100 && r.right == 400, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6220 GetClientRect( parent, &r );
6221 ok( r.left == 0 && r.right == 300, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6222 GetClientRect( child, &r );
6223 ok( r.left == 0 && r.right == 20, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6224 MapWindowPoints( child, parent, (POINT *)&r, 2 );
6225 ok( r.left == 10 && r.right == 30, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6226 GetWindowRect( child, &r );
6227 ok( r.left == 370 && r.right == 390, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6228 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
6229 ok( r.left == 10 && r.right == 30, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6230 GetWindowRect( child, &r );
6231 MapWindowPoints( NULL, parent, (POINT *)&r, 1 );
6232 MapWindowPoints( NULL, parent, (POINT *)&r + 1, 1 );
6233 ok( r.left == 30 && r.right == 10, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6234 pt.x = pt.y = 12;
6235 MapWindowPoints( child, parent, &pt, 1 );
6236 ok( pt.x == 22 && pt.y == 22, "wrong point %d,%d\n", pt.x, pt.y );
6237 SetWindowPos( parent, 0, 0, 0, 250, 250, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
6238 GetWindowRect( parent, &r );
6239 ok( r.left == 100 && r.right == 350, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6240 GetWindowRect( child, &r );
6241 ok( r.left == 320 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6242 SetWindowLongW( parent, GWL_EXSTYLE, 0 );
6243 GetWindowRect( child, &r );
6244 ok( r.left == 320 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6245 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
6246 ok( r.left == 220 && r.right == 240, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6247 SetWindowLongW( parent, GWL_EXSTYLE, WS_EX_LAYOUTRTL );
6248 GetWindowRect( child, &r );
6249 ok( r.left == 320 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6250 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
6251 ok( r.left == 10 && r.right == 30, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6252 SetWindowPos( child, 0, 0, 0, 30, 30, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
6253 GetWindowRect( child, &r );
6254 ok( r.left == 310 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6255 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
6256 ok( r.left == 10 && r.right == 40, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6257 DestroyWindow( child );
6258 DestroyWindow( parent );
6261 static void test_FindWindowEx(void)
6263 HWND hwnd, found;
6264 CHAR title[1];
6266 hwnd = CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP, 0,0,0,0, 0, 0, 0, NULL );
6267 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
6269 title[0] = 0;
6271 found = FindWindowExA( 0, 0, "MainWindowClass", title );
6272 ok( found == NULL, "expected a NULL hwnd\n" );
6273 found = FindWindowExA( 0, 0, "MainWindowClass", NULL );
6274 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
6276 DestroyWindow( hwnd );
6278 hwnd = CreateWindowExA( 0, "MainWindowClass", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL );
6279 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
6281 found = FindWindowExA( 0, 0, "MainWindowClass", title );
6282 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
6283 found = FindWindowExA( 0, 0, "MainWindowClass", NULL );
6284 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
6286 DestroyWindow( hwnd );
6288 /* test behaviour with a window title that is an empty character */
6289 found = FindWindowExA( 0, 0, "Shell_TrayWnd", title );
6290 ok( found != NULL, "found is NULL, expected a valid hwnd\n" );
6291 found = FindWindowExA( 0, 0, "Shell_TrayWnd", NULL );
6292 ok( found != NULL, "found is NULL, expected a valid hwnd\n" );
6295 static void test_GetLastActivePopup(void)
6297 HWND hwndOwner, hwndPopup1, hwndPopup2;
6299 hwndOwner = CreateWindowExA(0, "MainWindowClass", NULL,
6300 WS_VISIBLE | WS_POPUPWINDOW,
6301 100, 100, 200, 200,
6302 NULL, 0, GetModuleHandle(0), NULL);
6303 hwndPopup1 = CreateWindowExA(0, "MainWindowClass", NULL,
6304 WS_VISIBLE | WS_POPUPWINDOW,
6305 100, 100, 200, 200,
6306 hwndOwner, 0, GetModuleHandle(0), NULL);
6307 hwndPopup2 = CreateWindowExA(0, "MainWindowClass", NULL,
6308 WS_VISIBLE | WS_POPUPWINDOW,
6309 100, 100, 200, 200,
6310 hwndPopup1, 0, GetModuleHandle(0), NULL);
6311 ok( GetLastActivePopup(hwndOwner) == hwndPopup2, "wrong last active popup\n" );
6312 DestroyWindow( hwndPopup2 );
6313 DestroyWindow( hwndPopup1 );
6314 DestroyWindow( hwndOwner );
6317 START_TEST(win)
6319 HMODULE user32 = GetModuleHandleA( "user32.dll" );
6320 HMODULE gdi32 = GetModuleHandleA("gdi32.dll");
6321 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
6322 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
6323 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
6324 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
6325 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
6326 pUpdateLayeredWindow = (void *)GetProcAddress( user32, "UpdateLayeredWindow" );
6327 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
6328 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
6329 pGetWindowRgnBox = (void *)GetProcAddress( user32, "GetWindowRgnBox" );
6330 pGetGUIThreadInfo = (void *)GetProcAddress( user32, "GetGUIThreadInfo" );
6331 pGetProcessDefaultLayout = (void *)GetProcAddress( user32, "GetProcessDefaultLayout" );
6332 pSetProcessDefaultLayout = (void *)GetProcAddress( user32, "SetProcessDefaultLayout" );
6333 pGetLayout = (void *)GetProcAddress( gdi32, "GetLayout" );
6334 pSetLayout = (void *)GetProcAddress( gdi32, "SetLayout" );
6335 pMirrorRgn = (void *)GetProcAddress( gdi32, "MirrorRgn" );
6337 if (!RegisterWindowClasses()) assert(0);
6339 SetLastError(0xdeafbeef);
6340 GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC);
6341 is_win9x = (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED);
6343 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
6344 if (!hhook) win_skip( "Cannot set CBT hook, skipping some tests\n" );
6346 /* make sure that FindWindow tests are executed first */
6347 test_FindWindowEx();
6349 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
6350 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
6351 WS_MAXIMIZEBOX | WS_POPUP,
6352 100, 100, 200, 200,
6353 0, 0, GetModuleHandle(0), NULL);
6354 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
6355 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
6356 WS_MAXIMIZEBOX | WS_POPUP,
6357 100, 100, 200, 200,
6358 0, 0, GetModuleHandle(0), NULL);
6359 assert( hwndMain );
6360 assert( hwndMain2 );
6362 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
6364 /* Add the tests below this line */
6365 test_thick_child_size(hwndMain);
6366 test_fullscreen();
6367 test_hwnd_message();
6368 test_nonclient_area(hwndMain);
6369 test_params();
6370 test_GetWindowModuleFileName();
6371 test_capture_1();
6372 test_capture_2();
6373 test_capture_3(hwndMain, hwndMain2);
6374 test_capture_4();
6375 test_rtl_layout();
6377 test_CreateWindow();
6378 test_parent_owner();
6379 test_SetParent();
6380 test_enum_thread_windows();
6382 test_mdi();
6383 test_icons();
6384 test_SetWindowPos(hwndMain);
6385 test_SetMenu(hwndMain);
6386 test_SetFocus(hwndMain);
6387 test_SetActiveWindow(hwndMain);
6388 test_NCRedraw();
6390 test_children_zorder(hwndMain);
6391 test_popup_zorder(hwndMain2, hwndMain, WS_POPUP);
6392 test_popup_zorder(hwndMain2, hwndMain, 0);
6393 test_GetLastActivePopup();
6394 test_keyboard_input(hwndMain);
6395 test_mouse_input(hwndMain);
6396 test_validatergn(hwndMain);
6397 test_nccalcscroll( hwndMain);
6398 test_scrollwindow( hwndMain);
6399 test_scrollvalidate( hwndMain);
6400 test_scrolldc( hwndMain);
6401 test_scroll();
6402 test_IsWindowUnicode();
6403 test_vis_rgn(hwndMain);
6405 test_AdjustWindowRect();
6406 test_window_styles();
6407 test_redrawnow();
6408 test_csparentdc();
6409 test_SetWindowLong();
6410 test_ShowWindow();
6411 if (0) test_gettext(); /* crashes on NT4 */
6412 test_GetUpdateRect();
6413 test_Expose();
6414 test_layered_window();
6416 test_SetForegroundWindow(hwndMain);
6417 test_shell_window();
6418 test_handles( hwndMain );
6419 test_winregion();
6421 /* add the tests above this line */
6422 if (hhook) UnhookWindowsHookEx(hhook);
6424 DestroyWindow(hwndMain2);
6425 DestroyWindow(hwndMain);