deferwindowpos commit
[wine/wine64.git] / dlls / user32 / tests / win.c
blob8e833f8a22b6a373f746a3acdb84edd39872365d
1 /*
2 * Unit tests for window handling
4 * Copyright 2002 Bill Medland
5 * Copyright 2002 Alexandre Julliard
6 * Copyright 2003 Dmitry Timoshkov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 /* To get ICON_SMALL2 with the MSVC headers */
24 #define _WIN32_WINNT 0x0501
26 #include <assert.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <stdio.h>
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "winuser.h"
36 #include "wine/test.h"
38 #ifndef SPI_GETDESKWALLPAPER
39 #define SPI_GETDESKWALLPAPER 0x0073
40 #endif
42 #define LONG_PTR INT_PTR
43 #define ULONG_PTR UINT_PTR
45 void dump_region(HRGN hrgn);
47 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
48 static BOOL (WINAPI *pGetWindowInfo)(HWND,WINDOWINFO*);
49 static UINT (WINAPI *pGetWindowModuleFileNameA)(HWND,LPSTR,UINT);
50 static BOOL (WINAPI *pGetLayeredWindowAttributes)(HWND,COLORREF*,BYTE*,DWORD*);
51 static BOOL (WINAPI *pSetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD);
52 static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
53 static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
55 static BOOL test_lbuttondown_flag;
56 static HWND hwndMessage;
57 static HWND hwndMain, hwndMain2;
58 static HHOOK hhook;
60 static const char* szAWRClass = "Winsize";
61 static HMENU hmenu;
62 static DWORD our_pid;
64 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
66 static void dump_minmax_info( const MINMAXINFO *minmax )
68 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
69 minmax->ptReserved.x, minmax->ptReserved.y,
70 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
71 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
72 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
73 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
76 /* try to make sure pending X events have been processed before continuing */
77 static void flush_events( BOOL remove_messages )
79 MSG msg;
80 int diff = 200;
81 int min_timeout = 50;
82 DWORD time = GetTickCount() + diff;
84 while (diff > 0)
86 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
87 if (remove_messages)
88 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
89 diff = time - GetTickCount();
90 min_timeout = 10;
94 /* check the values returned by the various parent/owner functions on a given window */
95 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
96 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
98 HWND res;
100 if (pGetAncestor)
102 res = pGetAncestor( hwnd, GA_PARENT );
103 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
105 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
106 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
107 res = GetParent( hwnd );
108 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
109 res = GetWindow( hwnd, GW_OWNER );
110 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
111 if (pGetAncestor)
113 res = pGetAncestor( hwnd, GA_ROOT );
114 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
115 res = pGetAncestor( hwnd, GA_ROOTOWNER );
116 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
120 static BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
122 (*(LPINT)lParam)++;
123 trace("EnumChildProc on %p\n", hwndChild);
124 if (*(LPINT)lParam > 1) return FALSE;
125 return TRUE;
128 /* will search for the given window */
129 static BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
131 trace("EnumChildProc1 on %p\n", hwndChild);
132 if ((HWND)lParam == hwndChild) return FALSE;
133 return TRUE;
136 static HWND create_tool_window( LONG style, HWND parent )
138 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
139 0, 0, 100, 100, parent, 0, 0, NULL );
140 ok( ret != 0, "Creation failed\n" );
141 return ret;
144 /* test parent and owner values for various combinations */
145 static void test_parent_owner(void)
147 LONG style;
148 HWND test, owner, ret;
149 HWND desktop = GetDesktopWindow();
150 HWND child = create_tool_window( WS_CHILD, hwndMain );
151 INT numChildren;
153 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
155 /* child without parent, should fail */
156 SetLastError(0xdeadbeef);
157 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
158 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
159 ok( !test, "WS_CHILD without parent created\n" );
160 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD ||
161 broken(GetLastError() == 0xdeadbeef), /* win9x */
162 "CreateWindowExA error %u\n", GetLastError() );
164 /* desktop window */
165 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
166 style = GetWindowLongA( desktop, GWL_STYLE );
167 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
168 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
169 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
171 /* normal child window */
172 test = create_tool_window( WS_CHILD, hwndMain );
173 trace( "created child %p\n", test );
174 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
175 SetWindowLongA( test, GWL_STYLE, 0 );
176 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
177 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
178 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
179 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
180 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
181 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
182 DestroyWindow( test );
184 /* normal child window with WS_MAXIMIZE */
185 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
186 DestroyWindow( test );
188 /* normal child window with WS_THICKFRAME */
189 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
190 DestroyWindow( test );
192 /* popup window with WS_THICKFRAME */
193 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
194 DestroyWindow( test );
196 /* child of desktop */
197 test = create_tool_window( WS_CHILD, desktop );
198 trace( "created child of desktop %p\n", test );
199 check_parents( test, desktop, 0, desktop, 0, test, desktop );
200 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
201 check_parents( test, desktop, 0, 0, 0, test, test );
202 SetWindowLongA( test, GWL_STYLE, 0 );
203 check_parents( test, desktop, 0, 0, 0, test, test );
204 DestroyWindow( test );
206 /* child of desktop with WS_MAXIMIZE */
207 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
208 DestroyWindow( test );
210 /* child of desktop with WS_MINIMIZE */
211 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
212 DestroyWindow( test );
214 /* child of child */
215 test = create_tool_window( WS_CHILD, child );
216 trace( "created child of child %p\n", test );
217 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
218 SetWindowLongA( test, GWL_STYLE, 0 );
219 check_parents( test, child, child, 0, 0, hwndMain, test );
220 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
221 check_parents( test, child, child, 0, 0, hwndMain, test );
222 DestroyWindow( test );
224 /* child of child with WS_MAXIMIZE */
225 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
226 DestroyWindow( test );
228 /* child of child with WS_MINIMIZE */
229 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
230 DestroyWindow( test );
232 /* not owned top-level window */
233 test = create_tool_window( 0, 0 );
234 trace( "created top-level %p\n", test );
235 check_parents( test, desktop, 0, 0, 0, test, test );
236 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
237 check_parents( test, desktop, 0, 0, 0, test, test );
238 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
239 check_parents( test, desktop, 0, desktop, 0, test, desktop );
240 DestroyWindow( test );
242 /* not owned top-level window with WS_MAXIMIZE */
243 test = create_tool_window( WS_MAXIMIZE, 0 );
244 DestroyWindow( test );
246 /* owned top-level window */
247 test = create_tool_window( 0, hwndMain );
248 trace( "created owned top-level %p\n", test );
249 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
250 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
251 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
252 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
253 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
254 DestroyWindow( test );
256 /* owned top-level window with WS_MAXIMIZE */
257 test = create_tool_window( WS_MAXIMIZE, hwndMain );
258 DestroyWindow( test );
260 /* not owned popup */
261 test = create_tool_window( WS_POPUP, 0 );
262 trace( "created popup %p\n", test );
263 check_parents( test, desktop, 0, 0, 0, test, test );
264 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
265 check_parents( test, desktop, 0, desktop, 0, test, desktop );
266 SetWindowLongA( test, GWL_STYLE, 0 );
267 check_parents( test, desktop, 0, 0, 0, test, test );
268 DestroyWindow( test );
270 /* not owned popup with WS_MAXIMIZE */
271 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
272 DestroyWindow( test );
274 /* owned popup */
275 test = create_tool_window( WS_POPUP, hwndMain );
276 trace( "created owned popup %p\n", test );
277 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
278 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
279 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
280 SetWindowLongA( test, GWL_STYLE, 0 );
281 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
282 DestroyWindow( test );
284 /* owned popup with WS_MAXIMIZE */
285 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
286 DestroyWindow( test );
288 /* top-level window owned by child (same as owned by top-level) */
289 test = create_tool_window( 0, child );
290 trace( "created top-level owned by child %p\n", test );
291 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
292 DestroyWindow( test );
294 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
295 test = create_tool_window( WS_MAXIMIZE, child );
296 DestroyWindow( test );
298 /* popup owned by desktop (same as not owned) */
299 test = create_tool_window( WS_POPUP, desktop );
300 trace( "created popup owned by desktop %p\n", test );
301 check_parents( test, desktop, 0, 0, 0, test, test );
302 DestroyWindow( test );
304 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
305 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
306 DestroyWindow( test );
308 /* popup owned by child (same as owned by top-level) */
309 test = create_tool_window( WS_POPUP, child );
310 trace( "created popup owned by child %p\n", test );
311 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
312 DestroyWindow( test );
314 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
315 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
316 DestroyWindow( test );
318 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
319 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
320 trace( "created WS_CHILD popup %p\n", test );
321 check_parents( test, desktop, 0, 0, 0, test, test );
322 DestroyWindow( test );
324 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
325 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
326 DestroyWindow( test );
328 /* owned popup with WS_CHILD (same as WS_POPUP only) */
329 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
330 trace( "created owned WS_CHILD popup %p\n", test );
331 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
332 DestroyWindow( test );
334 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
335 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
336 DestroyWindow( test );
338 /******************** parent changes *************************/
339 trace( "testing parent changes\n" );
341 /* desktop window */
342 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
343 if (0)
345 /* this test succeeds on NT but crashes on win9x systems */
346 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
347 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
348 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
349 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
350 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
352 /* normal child window */
353 test = create_tool_window( WS_CHILD, hwndMain );
354 trace( "created child %p\n", test );
356 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
357 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
358 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
360 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
361 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
362 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
364 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
365 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
366 check_parents( test, desktop, 0, desktop, 0, test, desktop );
368 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
369 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
370 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
371 check_parents( test, desktop, child, desktop, child, test, desktop );
373 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
374 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
375 check_parents( test, desktop, 0, desktop, 0, test, desktop );
376 DestroyWindow( test );
378 /* not owned top-level window */
379 test = create_tool_window( 0, 0 );
380 trace( "created top-level %p\n", test );
382 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
383 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
384 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
386 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
387 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
388 check_parents( test, desktop, child, 0, child, test, test );
390 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
391 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
392 check_parents( test, desktop, 0, 0, 0, test, test );
393 DestroyWindow( test );
395 /* not owned popup */
396 test = create_tool_window( WS_POPUP, 0 );
397 trace( "created popup %p\n", test );
399 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
400 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
401 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
403 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
404 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
405 check_parents( test, desktop, child, child, child, test, hwndMain );
407 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
408 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
409 check_parents( test, desktop, 0, 0, 0, test, test );
410 DestroyWindow( test );
412 /* normal child window */
413 test = create_tool_window( WS_CHILD, hwndMain );
414 trace( "created child %p\n", test );
416 ret = SetParent( test, desktop );
417 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
418 check_parents( test, desktop, 0, desktop, 0, test, desktop );
420 ret = SetParent( test, child );
421 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
422 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
424 ret = SetParent( test, hwndMain2 );
425 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
426 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
427 DestroyWindow( test );
429 /* not owned top-level window */
430 test = create_tool_window( 0, 0 );
431 trace( "created top-level %p\n", test );
433 ret = SetParent( test, child );
434 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
435 check_parents( test, child, child, 0, 0, hwndMain, test );
436 DestroyWindow( test );
438 /* owned popup */
439 test = create_tool_window( WS_POPUP, hwndMain2 );
440 trace( "created owned popup %p\n", test );
442 ret = SetParent( test, child );
443 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
444 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
446 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
447 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
448 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
449 DestroyWindow( test );
451 /**************** test owner destruction *******************/
453 /* owned child popup */
454 owner = create_tool_window( 0, 0 );
455 test = create_tool_window( WS_POPUP, owner );
456 trace( "created owner %p and popup %p\n", owner, test );
457 ret = SetParent( test, child );
458 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
459 check_parents( test, child, child, owner, owner, hwndMain, owner );
460 /* window is now child of 'child' but owned by 'owner' */
461 DestroyWindow( owner );
462 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
463 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
464 * while Win95, Win2k, WinXP do.
466 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
467 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
468 DestroyWindow(test);
470 /* owned top-level popup */
471 owner = create_tool_window( 0, 0 );
472 test = create_tool_window( WS_POPUP, owner );
473 trace( "created owner %p and popup %p\n", owner, test );
474 check_parents( test, desktop, owner, owner, owner, test, owner );
475 DestroyWindow( owner );
476 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
478 /* top-level popup owned by child */
479 owner = create_tool_window( WS_CHILD, hwndMain2 );
480 test = create_tool_window( WS_POPUP, 0 );
481 trace( "created owner %p and popup %p\n", owner, test );
482 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
483 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
484 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
485 DestroyWindow( owner );
486 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
487 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
488 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
489 * while Win95, Win2k, WinXP do.
491 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
492 DestroyWindow(test);
494 /* final cleanup */
495 DestroyWindow(child);
498 owner = create_tool_window( WS_OVERLAPPED, 0 );
499 test = create_tool_window( WS_POPUP, desktop );
501 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
502 numChildren = 0;
503 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
504 "EnumChildWindows should have returned FALSE\n" );
505 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
507 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
508 ret = SetParent( test, owner );
509 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
511 numChildren = 0;
512 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
513 "EnumChildWindows should have returned TRUE\n" );
514 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
516 child = create_tool_window( WS_CHILD, owner );
517 numChildren = 0;
518 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
519 "EnumChildWindows should have returned FALSE\n" );
520 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
521 DestroyWindow( child );
523 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
524 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
525 numChildren = 0;
526 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
527 "EnumChildWindows should have returned TRUE\n" );
528 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
530 ret = SetParent( child, owner );
531 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
532 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
533 numChildren = 0;
534 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
535 "EnumChildWindows should have returned FALSE\n" );
536 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
538 ret = SetParent( child, NULL );
539 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
540 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
541 numChildren = 0;
542 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
543 "EnumChildWindows should have returned TRUE\n" );
544 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
546 /* even GW_OWNER == owner it's still a desktop's child */
547 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
548 "EnumChildWindows should have found %p and returned FALSE\n", child );
550 DestroyWindow( child );
551 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
553 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
554 "EnumChildWindows should have found %p and returned FALSE\n", child );
556 DestroyWindow( child );
557 DestroyWindow( test );
558 DestroyWindow( owner );
562 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
564 switch (msg)
566 case WM_GETMINMAXINFO:
568 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
570 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
571 dump_minmax_info( minmax );
572 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
573 break;
575 case WM_WINDOWPOSCHANGING:
577 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
578 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
579 trace("main: WM_WINDOWPOSCHANGING\n");
580 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
581 winpos->hwnd, winpos->hwndInsertAfter,
582 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
583 if (!(winpos->flags & SWP_NOMOVE))
585 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
586 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
588 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
589 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
591 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
592 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
594 break;
596 case WM_WINDOWPOSCHANGED:
598 RECT rc1, rc2;
599 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
600 trace("main: WM_WINDOWPOSCHANGED\n");
601 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
602 winpos->hwnd, winpos->hwndInsertAfter,
603 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
604 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
605 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
607 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
608 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
610 GetWindowRect(hwnd, &rc1);
611 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
612 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
613 /* note: winpos coordinates are relative to parent */
614 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
615 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
616 if (0)
618 /* Uncomment this once the test succeeds in all cases */
619 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
622 GetClientRect(hwnd, &rc2);
623 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
624 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
625 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
626 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
627 break;
629 case WM_NCCREATE:
631 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
632 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
634 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
635 if (got_getminmaxinfo)
636 trace("%p got WM_GETMINMAXINFO\n", hwnd);
638 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
639 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
640 else
641 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
642 break;
644 case WM_COMMAND:
645 if (test_lbuttondown_flag)
647 ShowWindow((HWND)wparam, SW_SHOW);
648 flush_events( FALSE );
650 break;
653 return DefWindowProcA(hwnd, msg, wparam, lparam);
656 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
658 switch (msg)
660 case WM_GETMINMAXINFO:
662 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
664 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
665 dump_minmax_info( minmax );
666 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
667 break;
669 case WM_NCCREATE:
671 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
672 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
674 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
675 if (got_getminmaxinfo)
676 trace("%p got WM_GETMINMAXINFO\n", hwnd);
678 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
679 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
680 else
681 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
682 break;
686 return DefWindowProcA(hwnd, msg, wparam, lparam);
689 static BOOL RegisterWindowClasses(void)
691 WNDCLASSA cls;
693 cls.style = CS_DBLCLKS;
694 cls.lpfnWndProc = main_window_procA;
695 cls.cbClsExtra = 0;
696 cls.cbWndExtra = 0;
697 cls.hInstance = GetModuleHandleA(0);
698 cls.hIcon = 0;
699 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
700 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
701 cls.lpszMenuName = NULL;
702 cls.lpszClassName = "MainWindowClass";
704 if(!RegisterClassA(&cls)) return FALSE;
706 cls.style = 0;
707 cls.lpfnWndProc = tool_window_procA;
708 cls.cbClsExtra = 0;
709 cls.cbWndExtra = 0;
710 cls.hInstance = GetModuleHandleA(0);
711 cls.hIcon = 0;
712 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
713 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
714 cls.lpszMenuName = NULL;
715 cls.lpszClassName = "ToolWindowClass";
717 if(!RegisterClassA(&cls)) return FALSE;
719 return TRUE;
722 static void verify_window_info(HWND hwnd, const WINDOWINFO *info)
724 RECT rcWindow, rcClient;
725 DWORD status;
727 ok(IsWindow(hwnd), "bad window handle\n");
729 GetWindowRect(hwnd, &rcWindow);
730 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow\n");
732 GetClientRect(hwnd, &rcClient);
733 /* translate to screen coordinates */
734 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
735 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient\n");
737 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
738 "wrong dwStyle: %08x != %08x\n", info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE));
739 /* Windows reports some undocumented exstyles in WINDOWINFO, but
740 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
742 ok((info->dwExStyle & ~0xe0000800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
743 "wrong dwExStyle: %08x != %08x\n", info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE));
744 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
745 if (GetForegroundWindow())
746 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x active %p fg %p\n",
747 info->dwWindowStatus, status, GetActiveWindow(), GetForegroundWindow());
749 /* win2k and XP return broken border info in GetWindowInfo most of
750 * the time, so there is no point in testing it.
752 #if 0
753 UINT border;
754 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
755 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
756 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
757 ok(info->cyWindowBorders == border,
758 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
759 #endif
760 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType\n");
761 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
762 info->wCreatorVersion == 0x0500 /* Vista */,
763 "wrong wCreatorVersion %04x\n", info->wCreatorVersion);
766 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
768 AdjustWindowRectEx(rc, style, menu, exstyle);
769 /* AdjustWindowRectEx does not include scroll bars */
770 if (style & WS_VSCROLL)
772 if(exstyle & WS_EX_LEFTSCROLLBAR)
773 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
774 else
775 rc->right += GetSystemMetrics(SM_CXVSCROLL);
777 if (style & WS_HSCROLL)
778 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
781 static void test_nonclient_area(HWND hwnd)
783 DWORD style, exstyle;
784 RECT rc_window, rc_client, rc;
785 BOOL menu;
786 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
787 LRESULT ret;
789 style = GetWindowLongA(hwnd, GWL_STYLE);
790 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
791 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
793 GetWindowRect(hwnd, &rc_window);
794 trace("window: (%d,%d)-(%d,%d)\n", rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
795 GetClientRect(hwnd, &rc_client);
796 trace("client: (%d,%d)-(%d,%d)\n", rc_client.left, rc_client.top, rc_client.right, rc_client.bottom);
798 /* avoid some cases when things go wrong */
799 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
800 rc_window.right > 32768 || rc_window.bottom > 32768) return;
802 CopyRect(&rc, &rc_client);
803 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
804 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
806 trace("calc window: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
807 ok(EqualRect(&rc, &rc_window), "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
810 CopyRect(&rc, &rc_window);
811 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
812 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
813 trace("calc client: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
814 ok(EqualRect(&rc, &rc_client), "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
816 /* NULL rectangle shouldn't crash */
817 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
818 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
820 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
821 if (is_win9x)
822 return;
824 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
825 SetRect(&rc_client, 0, 0, 250, 150);
826 CopyRect(&rc_window, &rc_client);
827 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
828 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
829 trace("calc window: (%d,%d)-(%d,%d)\n",
830 rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
832 CopyRect(&rc, &rc_window);
833 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
834 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
835 trace("calc client: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
836 ok(EqualRect(&rc, &rc_client), "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
839 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
841 static const char *CBT_code_name[10] = {
842 "HCBT_MOVESIZE",
843 "HCBT_MINMAX",
844 "HCBT_QS",
845 "HCBT_CREATEWND",
846 "HCBT_DESTROYWND",
847 "HCBT_ACTIVATE",
848 "HCBT_CLICKSKIPPED",
849 "HCBT_KEYSKIPPED",
850 "HCBT_SYSCOMMAND",
851 "HCBT_SETFOCUS" };
852 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
854 trace("CBT: %d (%s), %08lx, %08lx\n", nCode, code_name, wParam, lParam);
856 /* on HCBT_DESTROYWND window state is undefined */
857 if (nCode != HCBT_DESTROYWND && IsWindow((HWND)wParam))
859 if (pGetWindowInfo)
861 WINDOWINFO info;
863 /* Win98 actually does check the info.cbSize and doesn't allow
864 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
865 * WinXP do not check it at all.
867 info.cbSize = sizeof(WINDOWINFO);
868 ok(pGetWindowInfo((HWND)wParam, &info), "GetWindowInfo should not fail\n");
869 verify_window_info((HWND)wParam, &info);
873 switch (nCode)
875 case HCBT_CREATEWND:
877 static const RECT rc_null;
878 RECT rc;
879 LONG style;
880 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
881 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
882 (HWND)wParam, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
883 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
885 /* WS_VISIBLE should be turned off yet */
886 style = createwnd->lpcs->style & ~WS_VISIBLE;
887 ok(style == GetWindowLongA((HWND)wParam, GWL_STYLE),
888 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
889 GetWindowLongA((HWND)wParam, GWL_STYLE), style);
891 if (0)
893 /* Uncomment this once the test succeeds in all cases */
894 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
896 ok(GetParent((HWND)wParam) == hwndMessage,
897 "wrong result from GetParent %p: message window %p\n",
898 GetParent((HWND)wParam), hwndMessage);
900 else
901 ok(!GetParent((HWND)wParam), "GetParent should return 0 at this point\n");
903 ok(!GetWindow((HWND)wParam, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
905 if (0)
907 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
908 * Win9x still has them set to 0.
910 ok(GetWindow((HWND)wParam, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
911 ok(GetWindow((HWND)wParam, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
913 ok(!GetWindow((HWND)wParam, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
914 ok(!GetWindow((HWND)wParam, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
916 if (0)
918 /* Uncomment this once the test succeeds in all cases */
919 if (pGetAncestor)
921 ok(pGetAncestor((HWND)wParam, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
922 ok(pGetAncestor((HWND)wParam, GA_ROOT) == (HWND)wParam,
923 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOT), (HWND)wParam);
925 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
926 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == hwndMessage,
927 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
928 else
929 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == (HWND)wParam,
930 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOTOWNER), (HWND)wParam);
933 ok(GetWindowRect((HWND)wParam, &rc), "GetWindowRect failed\n");
934 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
935 ok(GetClientRect((HWND)wParam, &rc), "GetClientRect failed\n");
936 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
938 break;
942 return CallNextHookEx(hhook, nCode, wParam, lParam);
945 static void test_shell_window(void)
947 BOOL ret;
948 DWORD error;
949 HMODULE hinst, hUser32;
950 BOOL (WINAPI*SetShellWindow)(HWND);
951 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
952 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
953 HWND shellWindow, nextWnd;
955 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
957 trace("Skipping shell window test on Win9x\n");
958 return;
961 shellWindow = GetShellWindow();
962 hinst = GetModuleHandle(0);
963 hUser32 = GetModuleHandleA("user32");
965 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
966 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
968 trace("previous shell window: %p\n", shellWindow);
970 if (shellWindow) {
971 DWORD pid;
972 HANDLE hProcess;
974 SetLastError(0xdeadbeef);
975 ret = DestroyWindow(shellWindow);
976 error = GetLastError();
978 ok(!ret, "DestroyWindow(shellWindow)\n");
979 /* passes on Win XP, but not on Win98 */
980 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
981 "got %u after DestroyWindow(shellWindow)\n", error);
983 /* close old shell instance */
984 GetWindowThreadProcessId(shellWindow, &pid);
985 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
986 ret = TerminateProcess(hProcess, 0);
987 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
988 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
989 CloseHandle(hProcess);
992 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
993 trace("created window 1: %p\n", hwnd1);
995 ret = SetShellWindow(hwnd1);
996 ok(ret, "first call to SetShellWindow(hwnd1)\n");
997 shellWindow = GetShellWindow();
998 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
1000 ret = SetShellWindow(hwnd1);
1001 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1003 ret = SetShellWindow(0);
1004 error = GetLastError();
1005 /* passes on Win XP, but not on Win98
1006 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1007 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1009 ret = SetShellWindow(hwnd1);
1010 /* passes on Win XP, but not on Win98
1011 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1013 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1014 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
1015 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1017 ret = DestroyWindow(hwnd1);
1018 ok(ret, "DestroyWindow(hwnd1)\n");
1020 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1021 trace("created window 2: %p\n", hwnd2);
1022 ret = SetShellWindow(hwnd2);
1023 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1025 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1026 trace("created window 3: %p\n", hwnd3);
1028 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1029 trace("created window 4: %p\n", hwnd4);
1031 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1032 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1034 ret = SetShellWindow(hwnd4);
1035 ok(ret, "SetShellWindow(hwnd4)\n");
1036 shellWindow = GetShellWindow();
1037 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1039 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1040 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1042 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1043 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1045 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1046 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1048 ret = SetShellWindow(hwnd3);
1049 ok(!ret, "SetShellWindow(hwnd3)\n");
1050 shellWindow = GetShellWindow();
1051 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1053 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1054 trace("created window 5: %p\n", hwnd5);
1055 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1056 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1058 todo_wine
1060 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1061 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1064 /* destroy test windows */
1065 DestroyWindow(hwnd2);
1066 DestroyWindow(hwnd3);
1067 DestroyWindow(hwnd4);
1068 DestroyWindow(hwnd5);
1071 /************** MDI test ****************/
1073 static char mdi_lParam_test_message[] = "just a test string";
1075 static void test_MDI_create(HWND parent, HWND mdi_client, INT first_id)
1077 MDICREATESTRUCTA mdi_cs;
1078 HWND mdi_child;
1079 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1080 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1081 BOOL isWin9x = FALSE;
1083 mdi_cs.szClass = "MDI_child_Class_1";
1084 mdi_cs.szTitle = "MDI child";
1085 mdi_cs.hOwner = GetModuleHandle(0);
1086 mdi_cs.x = CW_USEDEFAULT;
1087 mdi_cs.y = CW_USEDEFAULT;
1088 mdi_cs.cx = CW_USEDEFAULT;
1089 mdi_cs.cy = CW_USEDEFAULT;
1090 mdi_cs.style = 0;
1091 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1092 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1093 ok(mdi_child != 0, "MDI child creation failed\n");
1094 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1095 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1096 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1098 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1099 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1100 ok(mdi_child != 0, "MDI child creation failed\n");
1101 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1102 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1103 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1105 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1106 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1107 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1109 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1111 else
1113 ok(mdi_child != 0, "MDI child creation failed\n");
1114 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1115 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1116 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1119 /* test MDICREATESTRUCT A<->W mapping */
1120 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1121 mdi_cs.style = 0;
1122 mdi_cs.szClass = (LPCSTR)classW;
1123 mdi_cs.szTitle = (LPCSTR)titleW;
1124 SetLastError(0xdeadbeef);
1125 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1126 if (!mdi_child)
1128 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1129 isWin9x = TRUE;
1130 else
1131 ok(mdi_child != 0, "MDI child creation failed\n");
1133 else
1135 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1136 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1137 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1140 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1142 CW_USEDEFAULT, CW_USEDEFAULT,
1143 CW_USEDEFAULT, CW_USEDEFAULT,
1144 mdi_client, GetModuleHandle(0),
1145 (LPARAM)mdi_lParam_test_message);
1146 ok(mdi_child != 0, "MDI child creation failed\n");
1147 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1148 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1149 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1151 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1152 0x7fffffff, /* without WS_POPUP */
1153 CW_USEDEFAULT, CW_USEDEFAULT,
1154 CW_USEDEFAULT, CW_USEDEFAULT,
1155 mdi_client, GetModuleHandle(0),
1156 (LPARAM)mdi_lParam_test_message);
1157 ok(mdi_child != 0, "MDI child creation failed\n");
1158 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1159 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1160 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1162 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1163 0xffffffff, /* with WS_POPUP */
1164 CW_USEDEFAULT, CW_USEDEFAULT,
1165 CW_USEDEFAULT, CW_USEDEFAULT,
1166 mdi_client, GetModuleHandle(0),
1167 (LPARAM)mdi_lParam_test_message);
1168 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1170 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1172 else
1174 ok(mdi_child != 0, "MDI child creation failed\n");
1175 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1176 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1177 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1180 /* test MDICREATESTRUCT A<->W mapping */
1181 SetLastError(0xdeadbeef);
1182 mdi_child = CreateMDIWindowW(classW, titleW,
1184 CW_USEDEFAULT, CW_USEDEFAULT,
1185 CW_USEDEFAULT, CW_USEDEFAULT,
1186 mdi_client, GetModuleHandle(0),
1187 (LPARAM)mdi_lParam_test_message);
1188 if (!mdi_child)
1190 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1191 isWin9x = TRUE;
1192 else
1193 ok(mdi_child != 0, "MDI child creation failed\n");
1195 else
1197 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1198 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1199 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1202 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1204 CW_USEDEFAULT, CW_USEDEFAULT,
1205 CW_USEDEFAULT, CW_USEDEFAULT,
1206 mdi_client, 0, GetModuleHandle(0),
1207 (LPVOID)mdi_lParam_test_message);
1208 ok(mdi_child != 0, "MDI child creation failed\n");
1209 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1210 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1211 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1213 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1214 0x7fffffff, /* without WS_POPUP */
1215 CW_USEDEFAULT, CW_USEDEFAULT,
1216 CW_USEDEFAULT, CW_USEDEFAULT,
1217 mdi_client, 0, GetModuleHandle(0),
1218 (LPVOID)mdi_lParam_test_message);
1219 ok(mdi_child != 0, "MDI child creation failed\n");
1220 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1221 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1222 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1224 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1225 0xffffffff, /* with WS_POPUP */
1226 CW_USEDEFAULT, CW_USEDEFAULT,
1227 CW_USEDEFAULT, CW_USEDEFAULT,
1228 mdi_client, 0, GetModuleHandle(0),
1229 (LPVOID)mdi_lParam_test_message);
1230 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1232 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1234 else
1236 ok(mdi_child != 0, "MDI child creation failed\n");
1237 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1238 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1239 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1242 /* test MDICREATESTRUCT A<->W mapping */
1243 SetLastError(0xdeadbeef);
1244 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1246 CW_USEDEFAULT, CW_USEDEFAULT,
1247 CW_USEDEFAULT, CW_USEDEFAULT,
1248 mdi_client, 0, GetModuleHandle(0),
1249 (LPVOID)mdi_lParam_test_message);
1250 if (!mdi_child)
1252 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1253 isWin9x = TRUE;
1254 else
1255 ok(mdi_child != 0, "MDI child creation failed\n");
1257 else
1259 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1260 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1261 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1264 /* This test fails on Win9x */
1265 if (!isWin9x)
1267 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1268 WS_CHILD,
1269 CW_USEDEFAULT, CW_USEDEFAULT,
1270 CW_USEDEFAULT, CW_USEDEFAULT,
1271 parent, 0, GetModuleHandle(0),
1272 (LPVOID)mdi_lParam_test_message);
1273 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1276 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1277 WS_CHILD, /* without WS_POPUP */
1278 CW_USEDEFAULT, CW_USEDEFAULT,
1279 CW_USEDEFAULT, CW_USEDEFAULT,
1280 mdi_client, 0, GetModuleHandle(0),
1281 (LPVOID)mdi_lParam_test_message);
1282 ok(mdi_child != 0, "MDI child creation failed\n");
1283 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1284 DestroyWindow(mdi_child);
1286 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1287 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1288 CW_USEDEFAULT, CW_USEDEFAULT,
1289 CW_USEDEFAULT, CW_USEDEFAULT,
1290 mdi_client, 0, GetModuleHandle(0),
1291 (LPVOID)mdi_lParam_test_message);
1292 ok(mdi_child != 0, "MDI child creation failed\n");
1293 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1294 DestroyWindow(mdi_child);
1296 /* maximized child */
1297 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1298 WS_CHILD | WS_MAXIMIZE,
1299 CW_USEDEFAULT, CW_USEDEFAULT,
1300 CW_USEDEFAULT, CW_USEDEFAULT,
1301 mdi_client, 0, GetModuleHandle(0),
1302 (LPVOID)mdi_lParam_test_message);
1303 ok(mdi_child != 0, "MDI child creation failed\n");
1304 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1305 DestroyWindow(mdi_child);
1307 trace("Creating maximized child with a caption\n");
1308 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1309 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1310 CW_USEDEFAULT, CW_USEDEFAULT,
1311 CW_USEDEFAULT, CW_USEDEFAULT,
1312 mdi_client, 0, GetModuleHandle(0),
1313 (LPVOID)mdi_lParam_test_message);
1314 ok(mdi_child != 0, "MDI child creation failed\n");
1315 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1316 DestroyWindow(mdi_child);
1318 trace("Creating maximized child with a caption and a thick frame\n");
1319 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1320 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1321 CW_USEDEFAULT, CW_USEDEFAULT,
1322 CW_USEDEFAULT, CW_USEDEFAULT,
1323 mdi_client, 0, GetModuleHandle(0),
1324 (LPVOID)mdi_lParam_test_message);
1325 ok(mdi_child != 0, "MDI child creation failed\n");
1326 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1327 DestroyWindow(mdi_child);
1330 /**********************************************************************
1331 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1333 * Note: The rule here is that client rect of the maximized MDI child
1334 * is equal to the client rect of the MDI client window.
1336 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1338 RECT rect;
1340 GetClientRect( client, &rect );
1341 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1342 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1344 rect.right -= rect.left;
1345 rect.bottom -= rect.top;
1346 lpMinMax->ptMaxSize.x = rect.right;
1347 lpMinMax->ptMaxSize.y = rect.bottom;
1349 lpMinMax->ptMaxPosition.x = rect.left;
1350 lpMinMax->ptMaxPosition.y = rect.top;
1352 trace("max rect (%d,%d - %d, %d)\n",
1353 rect.left, rect.top, rect.right, rect.bottom);
1356 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1358 switch (msg)
1360 case WM_NCCREATE:
1361 case WM_CREATE:
1363 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1364 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs->lpCreateParams;
1366 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1367 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1369 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1370 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1371 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1372 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1373 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1375 /* MDICREATESTRUCT should have original values */
1376 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1377 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1378 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1379 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1380 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1381 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1383 /* CREATESTRUCT should have fixed values */
1384 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1385 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1387 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1388 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1389 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1391 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1393 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1395 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1396 ok(cs->style == style,
1397 "cs->style does not match (%08x)\n", cs->style);
1399 else
1401 LONG style = mdi_cs->style;
1402 style &= ~WS_POPUP;
1403 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1404 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1405 ok(cs->style == style,
1406 "cs->style does not match (%08x)\n", cs->style);
1408 break;
1411 case WM_GETMINMAXINFO:
1413 HWND client = GetParent(hwnd);
1414 RECT rc;
1415 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1416 MINMAXINFO my_minmax;
1417 LONG style, exstyle;
1419 style = GetWindowLongA(hwnd, GWL_STYLE);
1420 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1422 GetWindowRect(client, &rc);
1423 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1424 GetClientRect(client, &rc);
1425 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1426 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1427 GetSystemMetrics(SM_CYSCREEN));
1429 GetClientRect(client, &rc);
1430 if ((style & WS_CAPTION) == WS_CAPTION)
1431 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1432 AdjustWindowRectEx(&rc, style, 0, exstyle);
1433 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1434 dump_minmax_info( minmax );
1436 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1437 minmax->ptMaxSize.x, rc.right - rc.left);
1438 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1439 minmax->ptMaxSize.y, rc.bottom - rc.top);
1441 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1443 trace("DefMDIChildProc returned:\n");
1444 dump_minmax_info( minmax );
1446 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1447 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1448 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1449 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1450 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1452 return 1;
1455 case WM_MDIACTIVATE:
1457 HWND active, client = GetParent(hwnd);
1458 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1459 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1460 if (hwnd == (HWND)lparam) /* if we are being activated */
1461 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1462 else
1463 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1464 break;
1467 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1470 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1472 switch (msg)
1474 case WM_NCCREATE:
1475 case WM_CREATE:
1477 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1479 trace("%s\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE");
1480 trace("x %d, y %d, cx %d, cy %d\n", cs->x, cs->y, cs->cx, cs->cy);
1482 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1483 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1485 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1486 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1488 /* CREATESTRUCT should have fixed values */
1489 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1490 while NT does. */
1491 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1492 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1494 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1495 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1496 while Win95, Win2k, WinXP do. */
1497 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1498 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1499 break;
1502 case WM_GETMINMAXINFO:
1504 HWND parent = GetParent(hwnd);
1505 RECT rc;
1506 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1507 LONG style, exstyle;
1509 trace("WM_GETMINMAXINFO\n");
1511 style = GetWindowLongA(hwnd, GWL_STYLE);
1512 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1514 GetClientRect(parent, &rc);
1515 trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1517 GetClientRect(parent, &rc);
1518 if ((style & WS_CAPTION) == WS_CAPTION)
1519 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1520 AdjustWindowRectEx(&rc, style, 0, exstyle);
1521 trace("calculated max child window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1522 dump_minmax_info( minmax );
1524 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1525 minmax->ptMaxSize.x, rc.right - rc.left);
1526 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1527 minmax->ptMaxSize.y, rc.bottom - rc.top);
1528 break;
1531 case WM_WINDOWPOSCHANGED:
1533 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1534 RECT rc1, rc2;
1536 GetWindowRect(hwnd, &rc1);
1537 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1538 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1539 /* note: winpos coordinates are relative to parent */
1540 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1541 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1542 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1544 GetWindowRect(hwnd, &rc1);
1545 GetClientRect(hwnd, &rc2);
1546 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1547 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1548 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1550 /* fall through */
1551 case WM_WINDOWPOSCHANGING:
1553 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1554 WINDOWPOS my_winpos = *winpos;
1556 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1557 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1558 winpos->hwnd, winpos->hwndInsertAfter,
1559 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1561 DefWindowProcA(hwnd, msg, wparam, lparam);
1563 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1564 winpos->hwnd, winpos->hwndInsertAfter,
1565 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1567 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1568 "DefWindowProc should not change WINDOWPOS values\n");
1570 return 1;
1573 return DefWindowProcA(hwnd, msg, wparam, lparam);
1576 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1578 static HWND mdi_client;
1580 switch (msg)
1582 case WM_CREATE:
1584 CLIENTCREATESTRUCT client_cs;
1585 RECT rc;
1587 GetClientRect(hwnd, &rc);
1589 client_cs.hWindowMenu = 0;
1590 client_cs.idFirstChild = 1;
1592 /* MDIClient without MDIS_ALLCHILDSTYLES */
1593 mdi_client = CreateWindowExA(0, "mdiclient",
1594 NULL,
1595 WS_CHILD /*| WS_VISIBLE*/,
1596 /* tests depend on a not zero MDIClient size */
1597 0, 0, rc.right, rc.bottom,
1598 hwnd, 0, GetModuleHandle(0),
1599 (LPVOID)&client_cs);
1600 assert(mdi_client);
1601 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1602 DestroyWindow(mdi_client);
1604 /* MDIClient with MDIS_ALLCHILDSTYLES */
1605 mdi_client = CreateWindowExA(0, "mdiclient",
1606 NULL,
1607 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1608 /* tests depend on a not zero MDIClient size */
1609 0, 0, rc.right, rc.bottom,
1610 hwnd, 0, GetModuleHandle(0),
1611 (LPVOID)&client_cs);
1612 assert(mdi_client);
1613 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1614 DestroyWindow(mdi_client);
1615 break;
1618 case WM_WINDOWPOSCHANGED:
1620 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1621 RECT rc1, rc2;
1623 GetWindowRect(hwnd, &rc1);
1624 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1625 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1626 /* note: winpos coordinates are relative to parent */
1627 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1628 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1629 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1631 GetWindowRect(hwnd, &rc1);
1632 GetClientRect(hwnd, &rc2);
1633 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1634 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1635 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1637 /* fall through */
1638 case WM_WINDOWPOSCHANGING:
1640 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1641 WINDOWPOS my_winpos = *winpos;
1643 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1644 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1645 winpos->hwnd, winpos->hwndInsertAfter,
1646 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1648 DefWindowProcA(hwnd, msg, wparam, lparam);
1650 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1651 winpos->hwnd, winpos->hwndInsertAfter,
1652 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1654 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1655 "DefWindowProc should not change WINDOWPOS values\n");
1657 return 1;
1660 case WM_CLOSE:
1661 PostQuitMessage(0);
1662 break;
1664 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1667 static BOOL mdi_RegisterWindowClasses(void)
1669 WNDCLASSA cls;
1671 cls.style = 0;
1672 cls.lpfnWndProc = mdi_main_wnd_procA;
1673 cls.cbClsExtra = 0;
1674 cls.cbWndExtra = 0;
1675 cls.hInstance = GetModuleHandleA(0);
1676 cls.hIcon = 0;
1677 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1678 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1679 cls.lpszMenuName = NULL;
1680 cls.lpszClassName = "MDI_parent_Class";
1681 if(!RegisterClassA(&cls)) return FALSE;
1683 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1684 cls.lpszClassName = "MDI_child_Class_1";
1685 if(!RegisterClassA(&cls)) return FALSE;
1687 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1688 cls.lpszClassName = "MDI_child_Class_2";
1689 if(!RegisterClassA(&cls)) return FALSE;
1691 return TRUE;
1694 static void test_mdi(void)
1696 HWND mdi_hwndMain;
1697 /*MSG msg;*/
1699 if (!mdi_RegisterWindowClasses()) assert(0);
1701 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1702 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1703 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1704 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1705 GetDesktopWindow(), 0,
1706 GetModuleHandle(0), NULL);
1707 assert(mdi_hwndMain);
1709 while(GetMessage(&msg, 0, 0, 0))
1711 TranslateMessage(&msg);
1712 DispatchMessage(&msg);
1715 DestroyWindow(mdi_hwndMain);
1718 static void test_icons(void)
1720 WNDCLASSEXA cls;
1721 HWND hwnd;
1722 HICON icon = LoadIconA(0, (LPSTR)IDI_APPLICATION);
1723 HICON icon2 = LoadIconA(0, (LPSTR)IDI_QUESTION);
1724 HICON small_icon = LoadImageA(0, (LPSTR)IDI_APPLICATION, IMAGE_ICON,
1725 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1726 HICON res;
1728 cls.cbSize = sizeof(cls);
1729 cls.style = 0;
1730 cls.lpfnWndProc = DefWindowProcA;
1731 cls.cbClsExtra = 0;
1732 cls.cbWndExtra = 0;
1733 cls.hInstance = 0;
1734 cls.hIcon = LoadIconA(0, (LPSTR)IDI_HAND);
1735 cls.hIconSm = small_icon;
1736 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1737 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1738 cls.lpszMenuName = NULL;
1739 cls.lpszClassName = "IconWindowClass";
1741 RegisterClassExA(&cls);
1743 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1744 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1745 assert( hwnd );
1747 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1748 ok( res == 0, "wrong big icon %p/0\n", res );
1749 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1750 ok( res == 0, "wrong previous big icon %p/0\n", res );
1751 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1752 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1753 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1754 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1755 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1756 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1758 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1759 ok( res == 0, "wrong small icon %p/0\n", res );
1760 /* this test is XP specific */
1761 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1762 ok( res != 0, "wrong small icon %p\n", res );*/
1763 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1764 ok( res == 0, "wrong previous small icon %p/0\n", res );
1765 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1766 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1767 /* this test is XP specific */
1768 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1769 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1770 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1771 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1772 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1773 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1774 /* this test is XP specific */
1775 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1776 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1778 /* make sure the big icon hasn't changed */
1779 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1780 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1782 DestroyWindow( hwnd );
1785 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1787 if (msg == WM_NCCALCSIZE)
1789 RECT *rect = (RECT *)lparam;
1790 /* first time around increase the rectangle, next time decrease it */
1791 if (rect->left == 100) InflateRect( rect, 10, 10 );
1792 else InflateRect( rect, -10, -10 );
1793 return 0;
1795 return DefWindowProc( hwnd, msg, wparam, lparam );
1798 static void test_SetWindowPos(HWND hwnd)
1800 RECT orig_win_rc, rect;
1801 LONG_PTR old_proc;
1802 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1804 SetRect(&rect, 111, 222, 333, 444);
1805 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1806 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1807 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1809 SetRect(&rect, 111, 222, 333, 444);
1810 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1811 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1812 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1814 GetWindowRect(hwnd, &orig_win_rc);
1816 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1817 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1818 GetWindowRect( hwnd, &rect );
1819 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1820 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1821 GetClientRect( hwnd, &rect );
1822 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1823 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1824 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1826 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1827 GetWindowRect( hwnd, &rect );
1828 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1829 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1830 GetClientRect( hwnd, &rect );
1831 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1832 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1833 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1835 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1836 orig_win_rc.right, orig_win_rc.bottom, 0);
1837 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1839 /* Win9x truncates coordinates to 16-bit irrespectively */
1840 if (!is_win9x)
1842 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1843 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1845 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1846 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1849 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1850 orig_win_rc.right, orig_win_rc.bottom, 0);
1852 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1853 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1854 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1855 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1856 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1857 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1858 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1861 static void test_SetMenu(HWND parent)
1863 HWND child;
1864 HMENU hMenu, ret;
1865 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1866 BOOL retok;
1867 DWORD style;
1869 hMenu = CreateMenu();
1870 assert(hMenu);
1872 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1873 if (0)
1875 /* fails on (at least) Wine, NT4, XP SP2 */
1876 test_nonclient_area(parent);
1878 ret = GetMenu(parent);
1879 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1880 /* test whether we can destroy a menu assigned to a window */
1881 retok = DestroyMenu(hMenu);
1882 ok( retok, "DestroyMenu error %d\n", GetLastError());
1883 retok = IsMenu(hMenu);
1884 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
1885 ret = GetMenu(parent);
1886 /* This test fails on Win9x */
1887 if (!is_win9x)
1888 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1889 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1890 test_nonclient_area(parent);
1892 hMenu = CreateMenu();
1893 assert(hMenu);
1895 /* parent */
1896 ret = GetMenu(parent);
1897 ok(ret == 0, "unexpected menu id %p\n", ret);
1899 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1900 test_nonclient_area(parent);
1901 ret = GetMenu(parent);
1902 ok(ret == 0, "unexpected menu id %p\n", ret);
1904 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1905 if (0)
1907 /* fails on (at least) Wine, NT4, XP SP2 */
1908 test_nonclient_area(parent);
1910 ret = GetMenu(parent);
1911 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1913 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1914 test_nonclient_area(parent);
1915 ret = GetMenu(parent);
1916 ok(ret == 0, "unexpected menu id %p\n", ret);
1918 /* child */
1919 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1920 assert(child);
1922 ret = GetMenu(child);
1923 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1925 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1926 test_nonclient_area(child);
1927 ret = GetMenu(child);
1928 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1930 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1931 test_nonclient_area(child);
1932 ret = GetMenu(child);
1933 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1935 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1936 test_nonclient_area(child);
1937 ret = GetMenu(child);
1938 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1940 style = GetWindowLong(child, GWL_STYLE);
1941 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
1942 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
1943 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
1944 SetWindowLong(child, GWL_STYLE, style);
1946 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
1947 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
1948 SetWindowLong(child, GWL_STYLE, style);
1950 DestroyWindow(child);
1951 DestroyMenu(hMenu);
1954 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1956 HWND child[5], hwnd;
1957 int i;
1959 assert(total <= 5);
1961 hwnd = GetWindow(parent, GW_CHILD);
1962 ok(!hwnd, "have to start without children to perform the test\n");
1964 for (i = 0; i < total; i++)
1966 if (style[i] & DS_CONTROL)
1968 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
1969 0,0,0,0, parent, (HMENU)i, 0, NULL);
1970 if (style[i] & WS_VISIBLE)
1971 ShowWindow(child[i], SW_SHOW);
1973 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
1975 else
1976 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
1977 parent, (HMENU)i, 0, NULL);
1978 trace("child[%d] = %p\n", i, child[i]);
1979 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
1982 hwnd = GetWindow(parent, GW_CHILD);
1983 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
1984 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
1985 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
1987 for (i = 0; i < total; i++)
1989 trace("hwnd[%d] = %p\n", i, hwnd);
1990 ok(child[order[i]] == hwnd, "Z order of child #%d is wrong\n", i);
1992 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1995 for (i = 0; i < total; i++)
1996 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
1999 static void test_children_zorder(HWND parent)
2001 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2002 WS_CHILD };
2003 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2005 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2006 WS_CHILD | WS_VISIBLE, WS_CHILD,
2007 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2008 const int complex_order_1[1] = { 0 };
2009 const int complex_order_2[2] = { 1, 0 };
2010 const int complex_order_3[3] = { 1, 0, 2 };
2011 const int complex_order_4[4] = { 1, 0, 2, 3 };
2012 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2013 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2014 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2015 WS_CHILD | WS_VISIBLE };
2016 const int complex_order_6[3] = { 0, 1, 2 };
2018 /* simple WS_CHILD */
2019 test_window_tree(parent, simple_style, simple_order, 5);
2021 /* complex children styles */
2022 test_window_tree(parent, complex_style, complex_order_1, 1);
2023 test_window_tree(parent, complex_style, complex_order_2, 2);
2024 test_window_tree(parent, complex_style, complex_order_3, 3);
2025 test_window_tree(parent, complex_style, complex_order_4, 4);
2026 test_window_tree(parent, complex_style, complex_order_5, 5);
2028 /* another set of complex children styles */
2029 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2032 #define check_z_order(hwnd, next, prev, owner, topmost) \
2033 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2034 __FILE__, __LINE__)
2036 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2037 BOOL topmost, const char *file, int line)
2039 HWND test;
2040 DWORD ex_style;
2042 test = GetWindow(hwnd, GW_HWNDNEXT);
2043 /* skip foreign windows */
2044 while (test && (GetWindowThreadProcessId(test, NULL) != our_pid ||
2045 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0)))
2047 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2048 test = GetWindow(test, GW_HWNDNEXT);
2050 ok_(file, line)(next == test, "expected next %p, got %p\n", next, test);
2052 test = GetWindow(hwnd, GW_HWNDPREV);
2053 /* skip foreign windows */
2054 while (test && (GetWindowThreadProcessId(test, NULL) != our_pid ||
2055 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0)))
2057 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2058 test = GetWindow(test, GW_HWNDPREV);
2060 ok_(file, line)(prev == test, "expected prev %p, got %p\n", prev, test);
2062 test = GetWindow(hwnd, GW_OWNER);
2063 ok_(file, line)(owner == test, "expected owner %p, got %p\n", owner, test);
2065 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2066 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "expected %stopmost\n", topmost ? "" : "NOT ");
2069 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E)
2071 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2073 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2075 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2077 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2078 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2080 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2081 WS_OVERLAPPED | WS_CAPTION,
2082 100, 100, 100, 100,
2083 0, 0, GetModuleHandle(0), NULL);
2084 trace("hwnd_F %p\n", hwnd_F);
2085 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2087 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2088 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2089 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2090 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2092 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2093 WS_POPUP,
2094 100, 100, 100, 100,
2095 hwnd_F, 0, GetModuleHandle(0), NULL);
2096 trace("hwnd_C %p\n", hwnd_C);
2097 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2098 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2099 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2100 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2102 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2103 WS_POPUP,
2104 100, 100, 100, 100,
2105 hwnd_F, 0, GetModuleHandle(0), NULL);
2106 trace("hwnd_B %p\n", hwnd_B);
2107 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2108 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2109 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2110 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2111 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2113 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2114 WS_POPUP,
2115 100, 100, 100, 100,
2116 0, 0, GetModuleHandle(0), NULL);
2117 trace("hwnd_A %p\n", hwnd_A);
2118 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2119 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2120 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2121 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2122 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2123 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2125 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);
2127 /* move hwnd_F and its popups up */
2128 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2129 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2130 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2131 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2132 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2133 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2134 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2136 /* move hwnd_F and its popups down */
2137 #if 0 /* enable once Wine is fixed to pass this test */
2138 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2139 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2140 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2141 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2142 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2143 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2144 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2145 #endif
2147 DestroyWindow(hwnd_A);
2148 DestroyWindow(hwnd_B);
2149 DestroyWindow(hwnd_C);
2150 DestroyWindow(hwnd_F);
2153 static void test_vis_rgn( HWND hwnd )
2155 RECT win_rect, rgn_rect;
2156 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2157 HDC hdc;
2159 ShowWindow(hwnd,SW_SHOW);
2160 hdc = GetDC( hwnd );
2161 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2162 GetWindowRect( hwnd, &win_rect );
2163 GetRgnBox( hrgn, &rgn_rect );
2164 if (GetVersion() & 0x80000000)
2166 trace("win9x, mapping to screen coords\n");
2167 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2169 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2170 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2171 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2172 rgn_rect.left, win_rect.left );
2173 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2174 rgn_rect.top, win_rect.top );
2175 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2176 rgn_rect.right, win_rect.right );
2177 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2178 rgn_rect.bottom, win_rect.bottom );
2179 ReleaseDC( hwnd, hdc );
2182 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2184 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2186 HWND child = GetWindow(hwnd, GW_CHILD);
2187 ok(child != 0, "couldn't find child window\n");
2188 SetFocus(child);
2189 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2190 return 0;
2192 return DefWindowProc(hwnd, msg, wp, lp);
2195 static void test_SetFocus(HWND hwnd)
2197 HWND child;
2198 WNDPROC old_wnd_proc;
2200 /* check if we can set focus to non-visible windows */
2202 ShowWindow(hwnd, SW_SHOW);
2203 SetFocus(0);
2204 SetFocus(hwnd);
2205 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2206 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2207 ShowWindow(hwnd, SW_HIDE);
2208 SetFocus(0);
2209 SetFocus(hwnd);
2210 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2211 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2212 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2213 assert(child);
2214 SetFocus(child);
2215 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2216 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2217 ShowWindow(child, SW_SHOW);
2218 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2219 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2220 ShowWindow(child, SW_HIDE);
2221 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2222 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2223 ShowWindow(child, SW_SHOW);
2224 SetFocus(child);
2225 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2226 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2227 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2229 ShowWindow(child, SW_HIDE);
2230 SetFocus(hwnd);
2231 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2232 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2233 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2234 ShowWindow(child, SW_HIDE);
2235 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2237 ShowWindow(hwnd, SW_SHOW);
2238 ShowWindow(child, SW_SHOW);
2239 SetFocus(child);
2240 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2241 EnableWindow(hwnd, FALSE);
2242 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2243 EnableWindow(hwnd, TRUE);
2245 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2246 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2247 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2248 todo_wine
2249 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2250 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2251 ShowWindow(hwnd, SW_RESTORE);
2252 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2253 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2254 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2255 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2256 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2257 todo_wine
2258 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2259 old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2260 ShowWindow(hwnd, SW_RESTORE);
2261 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2262 todo_wine
2263 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2265 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2267 DestroyWindow( child );
2270 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
2271 static void check_wnd_state_(const char *file, int line,
2272 HWND active, HWND foreground, HWND focus, HWND capture)
2274 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2275 if (foreground && GetForegroundWindow())
2276 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2277 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2278 ok_(file, line)(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2281 static void test_SetActiveWindow(HWND hwnd)
2283 HWND hwnd2;
2285 flush_events( TRUE );
2286 ShowWindow(hwnd, SW_HIDE);
2287 SetFocus(0);
2288 SetActiveWindow(0);
2289 check_wnd_state(0, 0, 0, 0);
2291 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2293 ShowWindow(hwnd, SW_SHOW);
2294 check_wnd_state(hwnd, hwnd, hwnd, 0);
2296 hwnd2 = SetActiveWindow(0);
2297 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2298 if (!GetActiveWindow()) /* doesn't always work on vista */
2300 check_wnd_state(0, 0, 0, 0);
2301 hwnd2 = SetActiveWindow(hwnd);
2302 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2304 check_wnd_state(hwnd, hwnd, hwnd, 0);
2306 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2307 check_wnd_state(hwnd, hwnd, hwnd, 0);
2309 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2310 check_wnd_state(hwnd, hwnd, hwnd, 0);
2312 ShowWindow(hwnd, SW_HIDE);
2313 check_wnd_state(0, 0, 0, 0);
2315 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2316 SetActiveWindow(hwnd);
2317 check_wnd_state(hwnd, hwnd, hwnd, 0);
2319 ShowWindow(hwnd, SW_SHOW);
2320 check_wnd_state(hwnd, hwnd, hwnd, 0);
2322 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2323 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2325 DestroyWindow(hwnd2);
2326 check_wnd_state(hwnd, hwnd, hwnd, 0);
2328 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2329 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2331 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2332 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2334 DestroyWindow(hwnd2);
2335 check_wnd_state(hwnd, hwnd, hwnd, 0);
2338 static void test_SetForegroundWindow(HWND hwnd)
2340 BOOL ret;
2341 HWND hwnd2;
2343 flush_events( TRUE );
2344 ShowWindow(hwnd, SW_HIDE);
2345 SetFocus(0);
2346 SetActiveWindow(0);
2347 check_wnd_state(0, 0, 0, 0);
2349 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2351 ShowWindow(hwnd, SW_SHOW);
2352 check_wnd_state(hwnd, hwnd, hwnd, 0);
2354 hwnd2 = SetActiveWindow(0);
2355 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2356 if (GetActiveWindow() == hwnd) /* doesn't always work on vista */
2357 check_wnd_state(hwnd, hwnd, hwnd, 0);
2358 else
2359 check_wnd_state(0, 0, 0, 0);
2361 ret = SetForegroundWindow(hwnd);
2362 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2363 check_wnd_state(hwnd, hwnd, hwnd, 0);
2365 SetLastError(0xdeadbeef);
2366 ret = SetForegroundWindow(0);
2367 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2368 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
2369 broken(GetLastError() == 0xdeadbeef), /* win9x */
2370 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2371 check_wnd_state(hwnd, hwnd, hwnd, 0);
2373 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2374 check_wnd_state(hwnd, hwnd, hwnd, 0);
2376 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2377 check_wnd_state(hwnd, hwnd, hwnd, 0);
2379 hwnd2 = GetForegroundWindow();
2380 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2381 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2382 hwnd2 = GetForegroundWindow();
2383 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2385 ShowWindow(hwnd, SW_HIDE);
2386 check_wnd_state(0, 0, 0, 0);
2388 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2389 ret = SetForegroundWindow(hwnd);
2390 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2391 check_wnd_state(hwnd, hwnd, hwnd, 0);
2393 ShowWindow(hwnd, SW_SHOW);
2394 check_wnd_state(hwnd, hwnd, hwnd, 0);
2396 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2397 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2399 DestroyWindow(hwnd2);
2400 check_wnd_state(hwnd, hwnd, hwnd, 0);
2402 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2403 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2405 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2406 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2408 DestroyWindow(hwnd2);
2409 check_wnd_state(hwnd, hwnd, hwnd, 0);
2412 static WNDPROC old_button_proc;
2414 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2416 LRESULT ret;
2417 USHORT key_state;
2419 key_state = GetKeyState(VK_LBUTTON);
2420 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2422 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2424 if (msg == WM_LBUTTONDOWN)
2426 HWND hwnd, capture;
2428 check_wnd_state(button, button, button, button);
2430 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2431 assert(hwnd);
2432 trace("hwnd %p\n", hwnd);
2434 check_wnd_state(button, button, button, button);
2436 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2438 check_wnd_state(button, button, button, button);
2440 DestroyWindow(hwnd);
2442 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2443 assert(hwnd);
2444 trace("hwnd %p\n", hwnd);
2446 check_wnd_state(button, button, button, button);
2448 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2449 * match internal button state.
2451 SendMessage(button, WM_KILLFOCUS, 0, 0);
2452 check_wnd_state(button, button, button, 0);
2454 ShowWindow(hwnd, SW_SHOW);
2455 check_wnd_state(hwnd, hwnd, hwnd, 0);
2457 capture = SetCapture(hwnd);
2458 ok(capture == 0, "SetCapture() = %p\n", capture);
2460 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2462 DestroyWindow(hwnd);
2464 check_wnd_state(button, 0, button, 0);
2467 return ret;
2470 static void test_capture_1(void)
2472 HWND button, capture, oldFocus, oldActive;
2474 oldFocus = GetFocus();
2475 oldActive = GetActiveWindow();
2477 capture = GetCapture();
2478 ok(capture == 0, "GetCapture() = %p\n", capture);
2480 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2481 assert(button);
2482 trace("button %p\n", button);
2484 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2486 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2488 capture = SetCapture(button);
2489 ok(capture == 0, "SetCapture() = %p\n", capture);
2490 check_wnd_state(button, 0, button, button);
2492 DestroyWindow(button);
2493 check_wnd_state(oldActive, 0, oldFocus, 0);
2496 static void test_capture_2(void)
2498 HWND button, hwnd, capture, oldFocus, oldActive;
2500 oldFocus = GetFocus();
2501 oldActive = GetActiveWindow();
2502 check_wnd_state(oldActive, 0, oldFocus, 0);
2504 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2505 assert(button);
2506 trace("button %p\n", button);
2508 check_wnd_state(button, button, button, 0);
2510 capture = SetCapture(button);
2511 ok(capture == 0, "SetCapture() = %p\n", capture);
2513 check_wnd_state(button, button, button, button);
2515 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2516 * internal button state.
2518 SendMessage(button, WM_KILLFOCUS, 0, 0);
2519 check_wnd_state(button, button, button, button);
2521 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2522 assert(hwnd);
2523 trace("hwnd %p\n", hwnd);
2525 check_wnd_state(button, button, button, button);
2527 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2529 check_wnd_state(button, button, button, button);
2531 DestroyWindow(hwnd);
2533 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2534 assert(hwnd);
2535 trace("hwnd %p\n", hwnd);
2537 check_wnd_state(button, button, button, button);
2539 ShowWindow(hwnd, SW_SHOW);
2541 check_wnd_state(hwnd, hwnd, hwnd, button);
2543 capture = SetCapture(hwnd);
2544 ok(capture == button, "SetCapture() = %p\n", capture);
2546 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2548 DestroyWindow(hwnd);
2549 check_wnd_state(button, button, button, 0);
2551 DestroyWindow(button);
2552 check_wnd_state(oldActive, 0, oldFocus, 0);
2555 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2557 BOOL ret;
2559 ShowWindow(hwnd1, SW_HIDE);
2560 ShowWindow(hwnd2, SW_HIDE);
2562 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2563 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2565 SetCapture(hwnd1);
2566 check_wnd_state(0, 0, 0, hwnd1);
2568 SetCapture(hwnd2);
2569 check_wnd_state(0, 0, 0, hwnd2);
2571 ShowWindow(hwnd1, SW_SHOW);
2572 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2574 ret = ReleaseCapture();
2575 ok (ret, "releasecapture did not return TRUE.\n");
2576 ret = ReleaseCapture();
2577 ok (ret, "releasecapture did not return TRUE after second try.\n");
2580 static void test_keyboard_input(HWND hwnd)
2582 MSG msg;
2583 BOOL ret;
2585 flush_events( TRUE );
2586 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
2587 UpdateWindow(hwnd);
2588 flush_events( TRUE );
2590 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2592 SetFocus(hwnd);
2593 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2595 flush_events( TRUE );
2597 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2598 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2599 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2600 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2601 ok( !ret, "message %04x available\n", msg.message);
2603 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2605 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2606 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2607 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2608 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2609 ok( !ret, "message %04x available\n", msg.message);
2611 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2613 keybd_event(VK_SPACE, 0, 0, 0);
2614 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2615 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2616 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2617 ok( !ret, "message %04x available\n", msg.message);
2619 SetFocus(0);
2620 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2622 flush_events( TRUE );
2624 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2625 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2626 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2627 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2628 ok( !ret, "message %04x available\n", msg.message);
2630 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2632 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2633 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2634 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2635 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2636 ok( !ret, "message %04x available\n", msg.message);
2638 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2640 keybd_event(VK_SPACE, 0, 0, 0);
2641 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2642 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2643 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2644 ok( !ret, "message %04x available\n", msg.message);
2647 static void test_mouse_input(HWND hwnd)
2649 RECT rc;
2650 POINT pt;
2651 int x, y;
2652 HWND popup;
2653 MSG msg;
2654 BOOL ret;
2655 LRESULT res;
2657 ShowWindow(hwnd, SW_SHOW);
2658 UpdateWindow(hwnd);
2660 GetWindowRect(hwnd, &rc);
2661 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2663 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2664 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2665 hwnd, 0, 0, NULL);
2666 assert(popup != 0);
2667 ShowWindow(popup, SW_SHOW);
2668 UpdateWindow(popup);
2670 GetWindowRect(popup, &rc);
2671 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2673 x = rc.left + (rc.right - rc.left) / 2;
2674 y = rc.top + (rc.bottom - rc.top) / 2;
2675 trace("setting cursor to (%d,%d)\n", x, y);
2677 SetCursorPos(x, y);
2678 GetCursorPos(&pt);
2679 ok(x == pt.x && y == pt.y, "wrong cursor pos (%d,%d), expected (%d,%d)\n", pt.x, pt.y, x, y);
2681 flush_events( TRUE );
2683 /* Check that setting the same position may generate WM_MOUSEMOVE */
2684 SetCursorPos(x, y);
2685 msg.message = 0;
2687 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2688 while (ret && msg.message >= 0xc000); /* skip registered messages */
2689 if (ret)
2691 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
2692 msg.hwnd, msg.message);
2693 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
2694 x, y, msg.pt.x, msg.pt.y);
2697 /* force the system to update its internal queue mouse position,
2698 * otherwise it won't generate relative mouse movements below.
2700 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2701 flush_events( TRUE );
2703 msg.message = 0;
2704 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2705 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2706 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2708 if (msg.message >= 0xc000) continue; /* skip registered messages */
2709 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
2710 "hwnd %p message %04x\n", msg.hwnd, msg.message);
2712 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2713 ok( !ret, "message %04x available\n", msg.message);
2715 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2716 ShowWindow(popup, SW_HIDE);
2718 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2719 while (msg.message >= 0xc000); /* skip registered messages */
2720 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2721 flush_events( TRUE );
2723 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2724 ShowWindow(hwnd, SW_HIDE);
2726 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2727 while (ret && msg.message >= 0xc000); /* skip registered messages */
2728 ok( !ret, "message %04x available\n", msg.message);
2729 flush_events( TRUE );
2731 /* test mouse clicks */
2733 ShowWindow(hwnd, SW_SHOW);
2734 flush_events( TRUE );
2735 ShowWindow(popup, SW_SHOW);
2736 flush_events( TRUE );
2738 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2739 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2740 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2741 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2743 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2744 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2745 msg.hwnd, popup, msg.message);
2746 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2747 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2748 msg.hwnd, popup, msg.message);
2750 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2751 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2752 msg.hwnd, popup, msg.message);
2753 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2754 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2755 msg.hwnd, popup, msg.message);
2757 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2758 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
2759 msg.hwnd, popup, msg.message);
2760 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2761 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
2762 msg.hwnd, popup, msg.message);
2764 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2765 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2766 msg.hwnd, popup, msg.message);
2767 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2768 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2769 msg.hwnd, popup, msg.message);
2771 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2772 ok(!ret, "message %04x available\n", msg.message);
2774 ShowWindow(popup, SW_HIDE);
2775 flush_events( TRUE );
2777 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2778 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2779 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2780 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2782 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2783 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2784 msg.hwnd, hwnd, msg.message);
2785 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2786 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2787 msg.hwnd, hwnd, msg.message);
2789 test_lbuttondown_flag = TRUE;
2790 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
2791 test_lbuttondown_flag = FALSE;
2794 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2795 while (msg.message >= 0xc000); /* skip registered messages */
2796 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2797 msg.hwnd, popup, msg.message);
2798 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2799 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2800 msg.hwnd, popup, msg.message);
2801 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2803 /* Test WM_MOUSEACTIVATE */
2804 #define TEST_MOUSEACTIVATE(A,B) \
2805 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2806 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2808 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
2809 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
2810 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
2811 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
2812 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
2813 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
2814 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
2815 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
2816 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
2817 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
2818 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
2819 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
2820 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
2821 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
2822 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
2823 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
2824 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
2825 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
2826 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
2827 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
2828 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
2829 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
2830 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
2831 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
2833 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2834 flush_events( TRUE );
2836 DestroyWindow(popup);
2839 static void test_validatergn(HWND hwnd)
2841 HWND child;
2842 RECT rc, rc2;
2843 HRGN rgn;
2844 int ret;
2845 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
2846 ShowWindow(hwnd, SW_SHOW);
2847 UpdateWindow( hwnd);
2848 /* test that ValidateRect validates children*/
2849 InvalidateRect( child, NULL, 1);
2850 GetWindowRect( child, &rc);
2851 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2852 ret = GetUpdateRect( child, &rc2, 0);
2853 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
2854 "Update rectangle is empty!\n");
2855 ValidateRect( hwnd, &rc);
2856 ret = GetUpdateRect( child, &rc2, 0);
2857 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2858 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2859 rc2.right, rc2.bottom);
2861 /* now test ValidateRgn */
2862 InvalidateRect( child, NULL, 1);
2863 GetWindowRect( child, &rc);
2864 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2865 rgn = CreateRectRgnIndirect( &rc);
2866 ValidateRgn( hwnd, rgn);
2867 ret = GetUpdateRect( child, &rc2, 0);
2868 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2869 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2870 rc2.right, rc2.bottom);
2872 DeleteObject( rgn);
2873 DestroyWindow( child );
2876 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
2878 MoveWindow( hwnd, 0, 0, x, y, 0);
2879 GetWindowRect( hwnd, prc);
2880 trace("window rect is %d,%d - %d,%d\n",
2881 prc->left,prc->top,prc->right,prc->bottom);
2882 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
2883 trace("nccalc rect is %d,%d - %d,%d\n",
2884 prc->left,prc->top,prc->right,prc->bottom);
2887 static void test_nccalcscroll(HWND parent)
2889 RECT rc1;
2890 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
2891 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
2892 HWND hwnd = CreateWindowExA(0, "static", NULL,
2893 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
2894 10, 10, 200, 200, parent, 0, 0, NULL);
2895 ShowWindow( parent, SW_SHOW);
2896 UpdateWindow( parent);
2898 /* test window too low for a horizontal scroll bar */
2899 nccalchelper( hwnd, 100, sbheight, &rc1);
2900 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
2901 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
2903 /* test window just high enough for a horizontal scroll bar */
2904 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
2905 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
2906 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2908 /* test window too narrow for a vertical scroll bar */
2909 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
2910 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
2911 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2913 /* test window just wide enough for a vertical scroll bar */
2914 nccalchelper( hwnd, sbwidth, 100, &rc1);
2915 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
2916 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
2918 /* same test, but with client edge: not enough width */
2919 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
2920 nccalchelper( hwnd, sbwidth, 100, &rc1);
2921 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
2922 "Width should be %d size is %d,%d - %d,%d\n",
2923 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
2925 DestroyWindow( hwnd);
2928 static void test_SetParent(void)
2930 BOOL ret;
2931 HWND desktop = GetDesktopWindow();
2932 HMENU hMenu;
2933 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
2934 HWND parent, child1, child2, child3, child4, sibling;
2936 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2937 100, 100, 200, 200, 0, 0, 0, NULL);
2938 assert(parent != 0);
2939 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2940 0, 0, 50, 50, parent, 0, 0, NULL);
2941 assert(child1 != 0);
2942 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2943 0, 0, 50, 50, child1, 0, 0, NULL);
2944 assert(child2 != 0);
2945 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2946 0, 0, 50, 50, child2, 0, 0, NULL);
2947 assert(child3 != 0);
2948 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2949 0, 0, 50, 50, child3, 0, 0, NULL);
2950 assert(child4 != 0);
2952 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2953 parent, child1, child2, child3, child4);
2955 check_parents(parent, desktop, 0, 0, 0, parent, parent);
2956 check_parents(child1, parent, parent, parent, 0, parent, parent);
2957 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2958 check_parents(child3, child2, child2, child2, 0, child2, parent);
2959 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2961 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
2962 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
2963 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2964 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
2965 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2967 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
2968 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2969 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
2970 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
2971 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
2972 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
2973 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
2974 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
2975 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2977 if (!is_win9x) /* Win9x doesn't survive this test */
2979 ok(!SetParent(parent, child1), "SetParent should fail\n");
2980 ok(!SetParent(child2, child3), "SetParent should fail\n");
2981 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
2982 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
2983 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
2984 ok(!SetParent(child2, parent), "SetParent should fail\n");
2985 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
2987 check_parents(parent, child4, child4, 0, 0, child4, parent);
2988 check_parents(child1, parent, parent, parent, 0, child4, parent);
2989 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2990 check_parents(child3, child2, child2, child2, 0, child2, parent);
2991 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2994 hMenu = CreateMenu();
2995 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2996 100, 100, 200, 200, 0, hMenu, 0, NULL);
2997 assert(sibling != 0);
2999 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
3000 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
3002 ret = DestroyWindow(parent);
3003 ok( ret, "DestroyWindow() error %d\n", GetLastError());
3005 ok(!IsWindow(parent), "parent still exists\n");
3006 ok(!IsWindow(sibling), "sibling still exists\n");
3007 ok(!IsWindow(child1), "child1 still exists\n");
3008 ok(!IsWindow(child2), "child2 still exists\n");
3009 ok(!IsWindow(child3), "child3 still exists\n");
3010 ok(!IsWindow(child4), "child4 still exists\n");
3013 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3015 LPCREATESTRUCT lpcs;
3016 LPSTYLESTRUCT lpss;
3018 switch (msg)
3020 case WM_NCCREATE:
3021 case WM_CREATE:
3022 lpcs = (LPCREATESTRUCT)lparam;
3023 lpss = (LPSTYLESTRUCT)lpcs->lpCreateParams;
3024 if (lpss)
3026 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
3027 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
3028 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
3029 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
3030 else
3031 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3033 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
3034 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
3035 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
3037 ok(lpss->styleNew == lpcs->style,
3038 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3039 lpss->styleNew, lpcs->style);
3041 break;
3043 return DefWindowProc(hwnd, msg, wparam, lparam);
3046 static ATOM atomStyleCheckClass;
3048 static void register_style_check_class(void)
3050 WNDCLASS wc =
3053 StyleCheckProc,
3056 GetModuleHandle(NULL),
3057 NULL,
3058 LoadCursor(NULL, IDC_ARROW),
3059 (HBRUSH)(COLOR_BTNFACE+1),
3060 NULL,
3061 TEXT("WineStyleCheck"),
3064 atomStyleCheckClass = RegisterClass(&wc);
3067 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3069 DWORD dwActualStyle;
3070 DWORD dwActualExStyle;
3071 STYLESTRUCT ss;
3072 HWND hwnd;
3073 HWND hwndParent = NULL;
3075 ss.styleNew = dwStyleIn;
3076 ss.styleOld = dwExStyleIn;
3078 if (dwStyleIn & WS_CHILD)
3080 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
3081 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3084 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
3085 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3086 assert(hwnd);
3088 flush_events( TRUE );
3090 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3091 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3092 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3093 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3094 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3096 DestroyWindow(hwnd);
3097 if (hwndParent) DestroyWindow(hwndParent);
3100 /* tests what window styles the window manager automatically adds */
3101 static void test_window_styles(void)
3103 register_style_check_class();
3105 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3106 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3107 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3108 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3109 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3110 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3111 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3112 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3113 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3114 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3115 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3118 static void test_scrollvalidate( HWND parent)
3120 HDC hdc;
3121 HRGN hrgn=CreateRectRgn(0,0,0,0);
3122 HRGN exprgn, tmprgn, clipping;
3123 RECT rc, rcu, cliprc;
3124 /* create two overlapping child windows. The visual region
3125 * of hwnd1 is clipped by the overlapping part of
3126 * hwnd2 because of the WS_CLIPSIBLING style */
3127 HWND hwnd1, hwnd2;
3129 clipping = CreateRectRgn(0,0,0,0);
3130 tmprgn = CreateRectRgn(0,0,0,0);
3131 exprgn = CreateRectRgn(0,0,0,0);
3132 hwnd2 = CreateWindowExA(0, "static", NULL,
3133 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3134 75, 30, 100, 100, parent, 0, 0, NULL);
3135 hwnd1 = CreateWindowExA(0, "static", NULL,
3136 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3137 25, 50, 100, 100, parent, 0, 0, NULL);
3138 ShowWindow( parent, SW_SHOW);
3139 UpdateWindow( parent);
3140 GetClientRect( hwnd1, &rc);
3141 cliprc=rc;
3142 SetRectRgn( clipping, 10, 10, 90, 90);
3143 hdc = GetDC( hwnd1);
3144 /* for a visual touch */
3145 TextOut( hdc, 0,10, "0123456789", 10);
3146 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3147 if (winetest_debug > 0) dump_region(hrgn);
3148 /* create a region with what is expected */
3149 SetRectRgn( exprgn, 39,0,49,74);
3150 SetRectRgn( tmprgn, 88,79,98,93);
3151 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3152 SetRectRgn( tmprgn, 0,93,98,98);
3153 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3154 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3155 trace("update rect is %d,%d - %d,%d\n",
3156 rcu.left,rcu.top,rcu.right,rcu.bottom);
3157 /* now with clipping region */
3158 SelectClipRgn( hdc, clipping);
3159 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3160 if (winetest_debug > 0) dump_region(hrgn);
3161 /* create a region with what is expected */
3162 SetRectRgn( exprgn, 39,10,49,74);
3163 SetRectRgn( tmprgn, 80,79,90,85);
3164 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3165 SetRectRgn( tmprgn, 10,85,90,90);
3166 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3167 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3168 trace("update rect is %d,%d - %d,%d\n",
3169 rcu.left,rcu.top,rcu.right,rcu.bottom);
3170 ReleaseDC( hwnd1, hdc);
3172 /* test scrolling a window with an update region */
3173 DestroyWindow( hwnd2);
3174 ValidateRect( hwnd1, NULL);
3175 SetRect( &rc, 40,40, 50,50);
3176 InvalidateRect( hwnd1, &rc, 1);
3177 GetClientRect( hwnd1, &rc);
3178 cliprc=rc;
3179 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
3180 SW_SCROLLCHILDREN | SW_INVALIDATE);
3181 if (winetest_debug > 0) dump_region(hrgn);
3182 SetRectRgn( exprgn, 88,0,98,98);
3183 SetRectRgn( tmprgn, 30, 40, 50, 50);
3184 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3185 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3187 /* clear an update region */
3188 UpdateWindow( hwnd1 );
3190 SetRect( &rc, 0,40, 100,60);
3191 SetRect( &cliprc, 0,0, 100,100);
3192 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3193 if (winetest_debug > 0) dump_region( hrgn );
3194 SetRectRgn( exprgn, 0, 40, 98, 60 );
3195 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
3197 /* now test ScrollWindowEx with a combination of
3198 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3199 /* make hwnd2 the child of hwnd1 */
3200 hwnd2 = CreateWindowExA(0, "static", NULL,
3201 WS_CHILD| WS_VISIBLE | WS_BORDER ,
3202 50, 50, 100, 100, hwnd1, 0, 0, NULL);
3203 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
3204 GetClientRect( hwnd1, &rc);
3205 cliprc=rc;
3207 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3208 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3209 ValidateRect( hwnd1, NULL);
3210 ValidateRect( hwnd2, NULL);
3211 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
3212 SW_SCROLLCHILDREN | SW_INVALIDATE);
3213 if (winetest_debug > 0) dump_region(hrgn);
3214 SetRectRgn( exprgn, 88,0,98,88);
3215 SetRectRgn( tmprgn, 0,88,98,98);
3216 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3217 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3219 /* SW_SCROLLCHILDREN */
3220 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3221 ValidateRect( hwnd1, NULL);
3222 ValidateRect( hwnd2, NULL);
3223 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3224 if (winetest_debug > 0) dump_region(hrgn);
3225 /* expected region is the same as in previous test */
3226 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3228 /* no SW_SCROLLCHILDREN */
3229 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3230 ValidateRect( hwnd1, NULL);
3231 ValidateRect( hwnd2, NULL);
3232 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3233 if (winetest_debug > 0) dump_region(hrgn);
3234 /* expected region is the same as in previous test */
3235 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3237 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3238 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3239 ValidateRect( hwnd1, NULL);
3240 ValidateRect( hwnd2, NULL);
3241 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3242 if (winetest_debug > 0) dump_region(hrgn);
3243 SetRectRgn( exprgn, 88,0,98,20);
3244 SetRectRgn( tmprgn, 20,20,98,30);
3245 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3246 SetRectRgn( tmprgn, 20,30,30,88);
3247 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3248 SetRectRgn( tmprgn, 0,88,30,98);
3249 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3250 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3252 /* clean up */
3253 DeleteObject( hrgn);
3254 DeleteObject( exprgn);
3255 DeleteObject( tmprgn);
3256 DestroyWindow( hwnd1);
3257 DestroyWindow( hwnd2);
3260 /* couple of tests of return values of scrollbar functions
3261 * called on a scrollbarless window */
3262 static void test_scroll(void)
3264 BOOL ret;
3265 INT min, max;
3266 SCROLLINFO si;
3267 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3268 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3269 100, 100, 200, 200, 0, 0, 0, NULL);
3270 /* horizontal */
3271 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3272 if (!ret) /* win9x */
3274 win_skip( "GetScrollRange doesn't work\n" );
3275 DestroyWindow( hwnd);
3276 return;
3278 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3279 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3280 si.cbSize = sizeof( si);
3281 si.fMask = SIF_PAGE;
3282 si.nPage = 0xdeadbeef;
3283 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3284 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3285 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3286 /* vertical */
3287 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3288 ok( ret, "GetScrollRange returns FALSE\n");
3289 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3290 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3291 si.cbSize = sizeof( si);
3292 si.fMask = SIF_PAGE;
3293 si.nPage = 0xdeadbeef;
3294 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3295 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3296 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3297 /* clean up */
3298 DestroyWindow( hwnd);
3301 static void test_scrolldc( HWND parent)
3303 HDC hdc;
3304 HRGN exprgn, tmprgn, hrgn;
3305 RECT rc, rc2, rcu, cliprc;
3306 HWND hwnd1;
3307 COLORREF colr;
3309 hrgn = CreateRectRgn(0,0,0,0);
3310 tmprgn = CreateRectRgn(0,0,0,0);
3311 exprgn = CreateRectRgn(0,0,0,0);
3313 hwnd1 = CreateWindowExA(0, "static", NULL,
3314 WS_CHILD| WS_VISIBLE,
3315 25, 50, 100, 100, parent, 0, 0, NULL);
3316 ShowWindow( parent, SW_SHOW);
3317 UpdateWindow( parent);
3318 flush_events( TRUE );
3319 GetClientRect( hwnd1, &rc);
3320 hdc = GetDC( hwnd1);
3321 /* paint the upper half of the window black */
3322 rc2 = rc;
3323 rc2.bottom = ( rc.top + rc.bottom) /2;
3324 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3325 /* clip region is the lower half */
3326 cliprc=rc;
3327 cliprc.top = (rc.top + rc.bottom) /2;
3328 /* test whether scrolled pixels are properly clipped */
3329 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3330 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3331 /* this scroll should not cause any visible changes */
3332 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3333 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3334 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3335 /* test with NULL clip rect */
3336 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3337 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3338 trace("update rect: %d,%d - %d,%d\n",
3339 rcu.left, rcu.top, rcu.right, rcu.bottom);
3340 if (winetest_debug > 0) dump_region(hrgn);
3341 SetRect(&rc2, 0, 0, 100, 100);
3342 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3343 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3345 SetRectRgn( exprgn, 0, 0, 20, 80);
3346 SetRectRgn( tmprgn, 0, 80, 100, 100);
3347 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3348 if (winetest_debug > 0) dump_region(exprgn);
3349 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3350 /* test clip rect > scroll rect */
3351 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3352 rc2=rc;
3353 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3354 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3355 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3356 SetRectRgn( exprgn, 25, 25, 75, 35);
3357 SetRectRgn( tmprgn, 25, 35, 35, 75);
3358 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3359 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3360 colr = GetPixel( hdc, 80, 80);
3361 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3362 trace("update rect: %d,%d - %d,%d\n",
3363 rcu.left, rcu.top, rcu.right, rcu.bottom);
3364 if (winetest_debug > 0) dump_region(hrgn);
3366 /* clean up */
3367 DeleteObject(hrgn);
3368 DeleteObject(exprgn);
3369 DeleteObject(tmprgn);
3370 DestroyWindow(hwnd1);
3373 static void test_params(void)
3375 HWND hwnd;
3376 INT rc;
3378 /* Just a param check */
3379 if (pGetMonitorInfoA)
3381 SetLastError(0xdeadbeef);
3382 rc = GetWindowText(hwndMain2, NULL, 1024);
3383 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
3385 else
3387 /* Skips actually on Win95 and NT4 */
3388 win_skip("Test would crash on Win95\n");
3391 SetLastError(0xdeadbeef);
3392 hwnd=CreateWindow("LISTBOX", "TestList",
3393 (LBS_STANDARD & ~LBS_SORT),
3394 0, 0, 100, 100,
3395 NULL, (HMENU)1, NULL, 0);
3397 ok(!hwnd, "CreateWindow with invalid menu handle should fail\n");
3398 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3399 GetLastError() == 0xdeadbeef, /* Win9x */
3400 "wrong last error value %d\n", GetLastError());
3403 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3405 HWND hwnd = 0;
3407 hwnd = CreateWindowEx(exStyle, class, class, style,
3408 110, 100,
3409 225, 200,
3411 menu ? hmenu : 0,
3412 0, 0);
3413 if (!hwnd) {
3414 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
3415 return;
3417 ShowWindow(hwnd, SW_SHOW);
3419 test_nonclient_area(hwnd);
3421 SetMenu(hwnd, 0);
3422 DestroyWindow(hwnd);
3425 static BOOL AWR_init(void)
3427 WNDCLASS class;
3429 class.style = CS_HREDRAW | CS_VREDRAW;
3430 class.lpfnWndProc = DefWindowProcA;
3431 class.cbClsExtra = 0;
3432 class.cbWndExtra = 0;
3433 class.hInstance = 0;
3434 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3435 class.hCursor = LoadCursor (0, IDC_ARROW);
3436 class.hbrBackground = 0;
3437 class.lpszMenuName = 0;
3438 class.lpszClassName = szAWRClass;
3440 if (!RegisterClass (&class)) {
3441 ok(FALSE, "RegisterClass failed\n");
3442 return FALSE;
3445 hmenu = CreateMenu();
3446 if (!hmenu)
3447 return FALSE;
3448 ok(hmenu != 0, "Failed to create menu\n");
3449 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3451 return TRUE;
3455 static void test_AWR_window_size(BOOL menu)
3457 LONG styles[] = {
3458 WS_POPUP,
3459 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3460 WS_SYSMENU,
3461 WS_THICKFRAME,
3462 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3463 WS_HSCROLL, WS_VSCROLL
3465 LONG exStyles[] = {
3466 WS_EX_CLIENTEDGE,
3467 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3468 WS_EX_APPWINDOW,
3469 #if 0
3470 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3471 WS_EX_DLGMODALFRAME,
3472 WS_EX_STATICEDGE,
3473 #endif
3476 int i;
3478 /* A exhaustive check of all the styles takes too long
3479 * so just do a (hopefully representative) sample
3481 for (i = 0; i < COUNTOF(styles); ++i)
3482 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3483 for (i = 0; i < COUNTOF(exStyles); ++i) {
3484 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3485 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3488 #undef COUNTOF
3490 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3492 static void test_AdjustWindowRect(void)
3494 if (!AWR_init())
3495 return;
3497 SHOWSYSMETRIC(SM_CYCAPTION);
3498 SHOWSYSMETRIC(SM_CYSMCAPTION);
3499 SHOWSYSMETRIC(SM_CYMENU);
3500 SHOWSYSMETRIC(SM_CXEDGE);
3501 SHOWSYSMETRIC(SM_CYEDGE);
3502 SHOWSYSMETRIC(SM_CXVSCROLL);
3503 SHOWSYSMETRIC(SM_CYHSCROLL);
3504 SHOWSYSMETRIC(SM_CXFRAME);
3505 SHOWSYSMETRIC(SM_CYFRAME);
3506 SHOWSYSMETRIC(SM_CXDLGFRAME);
3507 SHOWSYSMETRIC(SM_CYDLGFRAME);
3508 SHOWSYSMETRIC(SM_CXBORDER);
3509 SHOWSYSMETRIC(SM_CYBORDER);
3511 test_AWR_window_size(FALSE);
3512 test_AWR_window_size(TRUE);
3514 DestroyMenu(hmenu);
3516 #undef SHOWSYSMETRIC
3519 /* Global variables to trigger exit from loop */
3520 static int redrawComplete, WMPAINT_count;
3522 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3524 switch (msg)
3526 case WM_PAINT:
3527 trace("doing WM_PAINT %d\n", WMPAINT_count);
3528 WMPAINT_count++;
3529 if (WMPAINT_count > 10 && redrawComplete == 0) {
3530 PAINTSTRUCT ps;
3531 BeginPaint(hwnd, &ps);
3532 EndPaint(hwnd, &ps);
3533 return 1;
3535 return 0;
3537 return DefWindowProc(hwnd, msg, wparam, lparam);
3540 /* Ensure we exit from RedrawNow regardless of invalidated area */
3541 static void test_redrawnow(void)
3543 WNDCLASSA cls;
3544 HWND hwndMain;
3546 cls.style = CS_DBLCLKS;
3547 cls.lpfnWndProc = redraw_window_procA;
3548 cls.cbClsExtra = 0;
3549 cls.cbWndExtra = 0;
3550 cls.hInstance = GetModuleHandleA(0);
3551 cls.hIcon = 0;
3552 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3553 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3554 cls.lpszMenuName = NULL;
3555 cls.lpszClassName = "RedrawWindowClass";
3557 if(!RegisterClassA(&cls)) {
3558 trace("Register failed %d\n", GetLastError());
3559 return;
3562 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3563 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3565 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3566 ShowWindow(hwndMain, SW_SHOW);
3567 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3568 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3569 ok( WMPAINT_count == 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3570 redrawComplete = TRUE;
3571 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3573 /* clean up */
3574 DestroyWindow( hwndMain);
3577 struct parentdc_stat {
3578 RECT client;
3579 RECT clip;
3580 RECT paint;
3583 struct parentdc_test {
3584 struct parentdc_stat main, main_todo;
3585 struct parentdc_stat child1, child1_todo;
3586 struct parentdc_stat child2, child2_todo;
3589 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3591 RECT rc;
3592 PAINTSTRUCT ps;
3594 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3596 switch (msg)
3598 case WM_PAINT:
3599 trace("doing WM_PAINT on %p\n", hwnd);
3600 GetClientRect(hwnd, &rc);
3601 CopyRect(&t->client, &rc);
3602 trace("client rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3603 GetWindowRect(hwnd, &rc);
3604 trace("window rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3605 BeginPaint(hwnd, &ps);
3606 CopyRect(&t->paint, &ps.rcPaint);
3607 GetClipBox(ps.hdc, &rc);
3608 CopyRect(&t->clip, &rc);
3609 trace("clip rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3610 trace("paint rect (%d, %d)-(%d, %d)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3611 EndPaint(hwnd, &ps);
3612 return 0;
3614 return DefWindowProc(hwnd, msg, wparam, lparam);
3617 static void zero_parentdc_stat(struct parentdc_stat *t)
3619 SetRectEmpty(&t->client);
3620 SetRectEmpty(&t->clip);
3621 SetRectEmpty(&t->paint);
3624 static void zero_parentdc_test(struct parentdc_test *t)
3626 zero_parentdc_stat(&t->main);
3627 zero_parentdc_stat(&t->child1);
3628 zero_parentdc_stat(&t->child2);
3631 #define parentdc_field_ok(t, w, r, f, got) \
3632 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3633 ": expected %d, got %d\n", \
3634 t.w.r.f, got.w.r.f)
3636 #define parentdc_todo_field_ok(t, w, r, f, got) \
3637 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3638 else parentdc_field_ok(t, w, r, f, got)
3640 #define parentdc_rect_ok(t, w, r, got) \
3641 parentdc_todo_field_ok(t, w, r, left, got); \
3642 parentdc_todo_field_ok(t, w, r, top, got); \
3643 parentdc_todo_field_ok(t, w, r, right, got); \
3644 parentdc_todo_field_ok(t, w, r, bottom, got);
3646 #define parentdc_win_ok(t, w, got) \
3647 parentdc_rect_ok(t, w, client, got); \
3648 parentdc_rect_ok(t, w, clip, got); \
3649 parentdc_rect_ok(t, w, paint, got);
3651 #define parentdc_ok(t, got) \
3652 parentdc_win_ok(t, main, got); \
3653 parentdc_win_ok(t, child1, got); \
3654 parentdc_win_ok(t, child2, got);
3656 static void test_csparentdc(void)
3658 WNDCLASSA clsMain, cls;
3659 HWND hwndMain, hwnd1, hwnd2;
3660 RECT rc;
3662 struct parentdc_test test_answer;
3664 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3665 const struct parentdc_test test1 =
3667 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
3668 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3669 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3672 const struct parentdc_test test2 =
3674 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
3675 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3676 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3679 const struct parentdc_test test3 =
3681 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3682 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3683 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3686 const struct parentdc_test test4 =
3688 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
3689 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
3690 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3693 const struct parentdc_test test5 =
3695 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
3696 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3697 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3700 const struct parentdc_test test6 =
3702 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3703 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3704 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3707 const struct parentdc_test test7 =
3709 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3710 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3711 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3713 #undef nothing_todo
3715 clsMain.style = CS_DBLCLKS;
3716 clsMain.lpfnWndProc = parentdc_window_procA;
3717 clsMain.cbClsExtra = 0;
3718 clsMain.cbWndExtra = 0;
3719 clsMain.hInstance = GetModuleHandleA(0);
3720 clsMain.hIcon = 0;
3721 clsMain.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3722 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
3723 clsMain.lpszMenuName = NULL;
3724 clsMain.lpszClassName = "ParentDcMainWindowClass";
3726 if(!RegisterClassA(&clsMain)) {
3727 trace("Register failed %d\n", GetLastError());
3728 return;
3731 cls.style = CS_DBLCLKS | CS_PARENTDC;
3732 cls.lpfnWndProc = parentdc_window_procA;
3733 cls.cbClsExtra = 0;
3734 cls.cbWndExtra = 0;
3735 cls.hInstance = GetModuleHandleA(0);
3736 cls.hIcon = 0;
3737 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3738 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3739 cls.lpszMenuName = NULL;
3740 cls.lpszClassName = "ParentDcWindowClass";
3742 if(!RegisterClassA(&cls)) {
3743 trace("Register failed %d\n", GetLastError());
3744 return;
3747 SetRect(&rc, 0, 0, 150, 150);
3748 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
3749 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3750 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
3751 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
3752 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
3753 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
3754 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
3755 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
3756 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
3757 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
3758 ShowWindow(hwndMain, SW_SHOW);
3759 ShowWindow(hwnd1, SW_SHOW);
3760 ShowWindow(hwnd2, SW_SHOW);
3761 flush_events( TRUE );
3763 zero_parentdc_test(&test_answer);
3764 InvalidateRect(hwndMain, NULL, TRUE);
3765 flush_events( TRUE );
3766 parentdc_ok(test1, test_answer);
3768 zero_parentdc_test(&test_answer);
3769 SetRect(&rc, 0, 0, 50, 50);
3770 InvalidateRect(hwndMain, &rc, TRUE);
3771 flush_events( TRUE );
3772 parentdc_ok(test2, test_answer);
3774 zero_parentdc_test(&test_answer);
3775 SetRect(&rc, 0, 0, 10, 10);
3776 InvalidateRect(hwndMain, &rc, TRUE);
3777 flush_events( TRUE );
3778 parentdc_ok(test3, test_answer);
3780 zero_parentdc_test(&test_answer);
3781 SetRect(&rc, 40, 40, 50, 50);
3782 InvalidateRect(hwndMain, &rc, TRUE);
3783 flush_events( TRUE );
3784 parentdc_ok(test4, test_answer);
3786 zero_parentdc_test(&test_answer);
3787 SetRect(&rc, 20, 20, 60, 60);
3788 InvalidateRect(hwndMain, &rc, TRUE);
3789 flush_events( TRUE );
3790 parentdc_ok(test5, test_answer);
3792 zero_parentdc_test(&test_answer);
3793 SetRect(&rc, 0, 0, 10, 10);
3794 InvalidateRect(hwnd1, &rc, TRUE);
3795 flush_events( TRUE );
3796 parentdc_ok(test6, test_answer);
3798 zero_parentdc_test(&test_answer);
3799 SetRect(&rc, -5, -5, 65, 65);
3800 InvalidateRect(hwnd1, &rc, TRUE);
3801 flush_events( TRUE );
3802 parentdc_ok(test7, test_answer);
3804 DestroyWindow(hwndMain);
3805 DestroyWindow(hwnd1);
3806 DestroyWindow(hwnd2);
3809 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3811 return DefWindowProcA(hwnd, msg, wparam, lparam);
3814 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3816 return DefWindowProcW(hwnd, msg, wparam, lparam);
3819 static void test_IsWindowUnicode(void)
3821 static const char ansi_class_nameA[] = "ansi class name";
3822 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3823 static const char unicode_class_nameA[] = "unicode class name";
3824 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3825 WNDCLASSA classA;
3826 WNDCLASSW classW;
3827 HWND hwnd;
3829 memset(&classW, 0, sizeof(classW));
3830 classW.hInstance = GetModuleHandleA(0);
3831 classW.lpfnWndProc = def_window_procW;
3832 classW.lpszClassName = unicode_class_nameW;
3833 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
3835 memset(&classA, 0, sizeof(classA));
3836 classA.hInstance = GetModuleHandleA(0);
3837 classA.lpfnWndProc = def_window_procA;
3838 classA.lpszClassName = ansi_class_nameA;
3839 assert(RegisterClassA(&classA));
3841 /* unicode class: window proc */
3842 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3843 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3844 assert(hwnd);
3846 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3847 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3848 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3849 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3850 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3852 DestroyWindow(hwnd);
3854 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3855 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3856 assert(hwnd);
3858 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3859 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3860 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3861 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3862 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3864 DestroyWindow(hwnd);
3866 /* ansi class: window proc */
3867 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3868 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3869 assert(hwnd);
3871 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3872 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3873 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3874 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3875 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3877 DestroyWindow(hwnd);
3879 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3880 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3881 assert(hwnd);
3883 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3884 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3885 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3886 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3887 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3889 DestroyWindow(hwnd);
3891 /* unicode class: class proc */
3892 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3893 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3894 assert(hwnd);
3896 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3897 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3898 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3899 /* do not restore class window proc back to unicode */
3901 DestroyWindow(hwnd);
3903 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3904 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3905 assert(hwnd);
3907 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3908 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
3909 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3911 DestroyWindow(hwnd);
3913 /* ansi class: class proc */
3914 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3915 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3916 assert(hwnd);
3918 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3919 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
3920 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3921 /* do not restore class window proc back to ansi */
3923 DestroyWindow(hwnd);
3925 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3926 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3927 assert(hwnd);
3929 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3930 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3931 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3933 DestroyWindow(hwnd);
3936 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
3938 MINMAXINFO *minmax;
3940 if (msg != WM_GETMINMAXINFO)
3941 return DefWindowProc(hwnd, msg, wp, lp);
3943 minmax = (MINMAXINFO *)lp;
3945 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
3947 minmax->ptReserved.x = 0;
3948 minmax->ptReserved.y = 0;
3949 minmax->ptMaxSize.x = 400;
3950 minmax->ptMaxSize.y = 400;
3951 minmax->ptMaxPosition.x = 300;
3952 minmax->ptMaxPosition.y = 300;
3953 minmax->ptMaxTrackSize.x = 200;
3954 minmax->ptMaxTrackSize.y = 200;
3955 minmax->ptMinTrackSize.x = 100;
3956 minmax->ptMinTrackSize.y = 100;
3958 else
3959 DefWindowProc(hwnd, msg, wp, lp);
3960 return 1;
3963 static int expected_cx, expected_cy;
3964 static RECT expected_rect, broken_rect;
3966 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
3968 switch(msg)
3970 case WM_GETMINMAXINFO:
3972 RECT rect;
3973 GetWindowRect( hwnd, &rect );
3974 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
3975 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
3976 return DefWindowProc(hwnd, msg, wp, lp);
3978 case WM_NCCREATE:
3979 case WM_CREATE:
3981 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
3982 RECT rect;
3983 GetWindowRect( hwnd, &rect );
3984 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
3985 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
3986 ok( cs->cx == expected_cx || broken(cs->cx == (short)expected_cx),
3987 "wrong x size %d/%d\n", cs->cx, expected_cx );
3988 ok( cs->cy == expected_cy || broken(cs->cy == (short)expected_cy),
3989 "wrong y size %d/%d\n", cs->cy, expected_cy );
3990 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
3991 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
3992 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
3993 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top) ||
3994 broken( rect.right - rect.left == (short)broken_rect.right - (short)broken_rect.left &&
3995 rect.bottom - rect.top == (short)broken_rect.bottom - (short)broken_rect.top),
3996 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
3997 rect.left, rect.top, rect.right, rect.bottom,
3998 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
3999 return DefWindowProc(hwnd, msg, wp, lp);
4001 case WM_NCCALCSIZE:
4003 RECT rect, *r = (RECT *)lp;
4004 GetWindowRect( hwnd, &rect );
4005 ok( !memcmp( &rect, r, sizeof(rect) ),
4006 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
4007 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
4008 return DefWindowProc(hwnd, msg, wp, lp);
4010 default:
4011 return DefWindowProc(hwnd, msg, wp, lp);
4015 static void test_CreateWindow(void)
4017 WNDCLASS cls;
4018 HWND hwnd, parent;
4019 HMENU hmenu;
4020 RECT rc, rc_minmax;
4021 MINMAXINFO minmax;
4023 #define expect_menu(window, menu) \
4024 SetLastError(0xdeadbeef); \
4025 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
4027 #define expect_style(window, style)\
4028 ok(GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
4030 #define expect_ex_style(window, ex_style)\
4031 ok(GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
4033 #define expect_gle_broken_9x(gle)\
4034 ok(GetLastError() == gle ||\
4035 broken(GetLastError() == 0xdeadbeef),\
4036 "IsMenu set error %d\n", GetLastError())
4038 hmenu = CreateMenu();
4039 assert(hmenu != 0);
4040 parent = GetDesktopWindow();
4041 assert(parent != 0);
4043 SetLastError(0xdeadbeef);
4044 ok(IsMenu(hmenu), "IsMenu error %d\n", GetLastError());
4046 /* WS_CHILD */
4047 SetLastError(0xdeadbeef);
4048 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
4049 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4050 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4051 expect_menu(hwnd, 1);
4052 expect_style(hwnd, WS_CHILD);
4053 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4054 DestroyWindow(hwnd);
4056 SetLastError(0xdeadbeef);
4057 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
4058 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4059 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4060 expect_menu(hwnd, 1);
4061 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4062 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4063 DestroyWindow(hwnd);
4065 SetLastError(0xdeadbeef);
4066 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
4067 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4068 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4069 expect_menu(hwnd, 1);
4070 expect_style(hwnd, WS_CHILD);
4071 expect_ex_style(hwnd, 0);
4072 DestroyWindow(hwnd);
4074 SetLastError(0xdeadbeef);
4075 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
4076 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4077 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4078 expect_menu(hwnd, 1);
4079 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4080 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4081 DestroyWindow(hwnd);
4083 /* WS_POPUP */
4084 SetLastError(0xdeadbeef);
4085 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4086 0, 0, 100, 100, parent, hmenu, 0, NULL);
4087 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4088 expect_menu(hwnd, hmenu);
4089 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4090 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4091 DestroyWindow(hwnd);
4092 SetLastError(0xdeadbeef);
4093 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4094 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4096 hmenu = CreateMenu();
4097 assert(hmenu != 0);
4098 SetLastError(0xdeadbeef);
4099 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
4100 0, 0, 100, 100, parent, hmenu, 0, NULL);
4101 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4102 expect_menu(hwnd, hmenu);
4103 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4104 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4105 DestroyWindow(hwnd);
4106 SetLastError(0xdeadbeef);
4107 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4108 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4110 hmenu = CreateMenu();
4111 assert(hmenu != 0);
4112 SetLastError(0xdeadbeef);
4113 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
4114 0, 0, 100, 100, parent, hmenu, 0, NULL);
4115 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4116 expect_menu(hwnd, hmenu);
4117 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4118 expect_ex_style(hwnd, 0);
4119 DestroyWindow(hwnd);
4120 SetLastError(0xdeadbeef);
4121 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4122 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4124 hmenu = CreateMenu();
4125 assert(hmenu != 0);
4126 SetLastError(0xdeadbeef);
4127 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
4128 0, 0, 100, 100, parent, hmenu, 0, NULL);
4129 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4130 expect_menu(hwnd, hmenu);
4131 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4132 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4133 DestroyWindow(hwnd);
4134 SetLastError(0xdeadbeef);
4135 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4136 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4138 /* WS_CHILD | WS_POPUP */
4139 SetLastError(0xdeadbeef);
4140 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4141 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4142 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4143 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4144 if (hwnd)
4145 DestroyWindow(hwnd);
4147 hmenu = CreateMenu();
4148 assert(hmenu != 0);
4149 SetLastError(0xdeadbeef);
4150 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4151 0, 0, 100, 100, parent, hmenu, 0, NULL);
4152 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4153 expect_menu(hwnd, hmenu);
4154 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4155 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4156 DestroyWindow(hwnd);
4157 SetLastError(0xdeadbeef);
4158 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4159 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4161 SetLastError(0xdeadbeef);
4162 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4163 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4164 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4165 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4166 if (hwnd)
4167 DestroyWindow(hwnd);
4169 hmenu = CreateMenu();
4170 assert(hmenu != 0);
4171 SetLastError(0xdeadbeef);
4172 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4173 0, 0, 100, 100, parent, hmenu, 0, NULL);
4174 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4175 expect_menu(hwnd, hmenu);
4176 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4177 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4178 DestroyWindow(hwnd);
4179 SetLastError(0xdeadbeef);
4180 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4181 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4183 SetLastError(0xdeadbeef);
4184 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4185 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4186 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4187 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4188 if (hwnd)
4189 DestroyWindow(hwnd);
4191 hmenu = CreateMenu();
4192 assert(hmenu != 0);
4193 SetLastError(0xdeadbeef);
4194 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4195 0, 0, 100, 100, parent, hmenu, 0, NULL);
4196 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4197 expect_menu(hwnd, hmenu);
4198 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4199 expect_ex_style(hwnd, 0);
4200 DestroyWindow(hwnd);
4201 SetLastError(0xdeadbeef);
4202 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4203 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4205 SetLastError(0xdeadbeef);
4206 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4207 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4208 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4209 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4210 if (hwnd)
4211 DestroyWindow(hwnd);
4213 hmenu = CreateMenu();
4214 assert(hmenu != 0);
4215 SetLastError(0xdeadbeef);
4216 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4217 0, 0, 100, 100, parent, hmenu, 0, NULL);
4218 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4219 expect_menu(hwnd, hmenu);
4220 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4221 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4222 DestroyWindow(hwnd);
4223 SetLastError(0xdeadbeef);
4224 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4225 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4227 /* test child window sizing */
4228 cls.style = 0;
4229 cls.lpfnWndProc = minmax_wnd_proc;
4230 cls.cbClsExtra = 0;
4231 cls.cbWndExtra = 0;
4232 cls.hInstance = GetModuleHandle(0);
4233 cls.hIcon = 0;
4234 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
4235 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4236 cls.lpszMenuName = NULL;
4237 cls.lpszClassName = "MinMax_WndClass";
4238 RegisterClass(&cls);
4240 SetLastError(0xdeadbeef);
4241 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4242 0, 0, 100, 100, 0, 0, 0, NULL);
4243 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4244 expect_menu(parent, 0);
4245 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
4246 expect_ex_style(parent, WS_EX_WINDOWEDGE);
4248 memset(&minmax, 0, sizeof(minmax));
4249 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4250 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
4251 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
4252 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4253 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
4255 GetWindowRect(parent, &rc);
4256 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
4257 GetClientRect(parent, &rc);
4258 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
4260 InflateRect(&rc, 200, 200);
4261 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4263 SetLastError(0xdeadbeef);
4264 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4265 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
4266 parent, (HMENU)1, 0, NULL);
4267 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4268 expect_menu(hwnd, 1);
4269 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
4270 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4272 memset(&minmax, 0, sizeof(minmax));
4273 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4274 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4276 GetWindowRect(hwnd, &rc);
4277 OffsetRect(&rc, -rc.left, -rc.top);
4278 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4279 rc.left, rc.top, rc.right, rc.bottom,
4280 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
4281 DestroyWindow(hwnd);
4283 cls.lpfnWndProc = winsizes_wnd_proc;
4284 cls.lpszClassName = "Sizes_WndClass";
4285 RegisterClass(&cls);
4287 expected_cx = expected_cy = 200000;
4288 SetRect( &expected_rect, 0, 0, 200000, 200000 );
4289 broken_rect = expected_rect;
4290 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
4291 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4292 GetClientRect( hwnd, &rc );
4293 ok( rc.right == 200000 || broken(rc.right == (short)200000), "invalid rect right %u\n", rc.right );
4294 ok( rc.bottom == 200000 || broken(rc.bottom == (short)200000), "invalid rect bottom %u\n", rc.bottom );
4295 DestroyWindow(hwnd);
4297 expected_cx = expected_cy = -10;
4298 SetRect( &expected_rect, 0, 0, 0, 0 );
4299 SetRect( &broken_rect, 0, 0, -10, -10 );
4300 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
4301 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4302 GetClientRect( hwnd, &rc );
4303 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4304 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4305 DestroyWindow(hwnd);
4307 expected_cx = expected_cy = -200000;
4308 SetRect( &expected_rect, 0, 0, 0, 0 );
4309 SetRect( &broken_rect, 0, 0, -200000, -200000 );
4310 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
4311 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4312 GetClientRect( hwnd, &rc );
4313 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4314 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4315 DestroyWindow(hwnd);
4317 /* we need a parent at 0,0 so that child coordinates match */
4318 DestroyWindow(parent);
4319 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
4320 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4322 expected_cx = 100;
4323 expected_cy = 0x7fffffff;
4324 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
4325 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
4326 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
4327 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4328 GetClientRect( hwnd, &rc );
4329 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
4330 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4331 DestroyWindow(hwnd);
4333 expected_cx = 0x7fffffff;
4334 expected_cy = 0x7fffffff;
4335 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
4336 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
4337 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
4338 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4339 GetClientRect( hwnd, &rc );
4340 ok( rc.right == 0x7fffffff - 20 || broken(rc.right == 0), "invalid rect right %u\n", rc.right );
4341 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4342 DestroyWindow(hwnd);
4344 /* top level window */
4345 expected_cx = expected_cy = 200000;
4346 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
4347 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
4348 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4349 GetClientRect( hwnd, &rc );
4350 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
4351 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
4352 DestroyWindow(hwnd);
4354 DestroyWindow(parent);
4356 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4357 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4359 #undef expect_gle_broken_9x
4360 #undef expect_menu
4361 #undef expect_style
4362 #undef expect_ex_style
4365 /* function that remembers whether the system the test is running on sets the
4366 * last error for user32 functions to make the tests stricter */
4367 static int check_error(DWORD actual, DWORD expected)
4369 static int sets_last_error = -1;
4370 if (sets_last_error == -1)
4371 sets_last_error = (actual != 0xdeadbeef);
4372 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
4375 static void test_SetWindowLong(void)
4377 LONG_PTR retval;
4378 WNDPROC old_window_procW;
4380 SetLastError(0xdeadbeef);
4381 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
4382 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
4383 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
4384 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4386 SetLastError(0xdeadbeef);
4387 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
4388 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
4389 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
4390 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4392 SetLastError(0xdeadbeef);
4393 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4394 ok((WNDPROC)retval == main_window_procA || broken(!retval), /* win9x */
4395 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
4396 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4397 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
4398 ok((WNDPROC)retval == main_window_procA,
4399 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4400 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
4402 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
4403 SetLastError(0xdeadbeef);
4404 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
4405 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
4407 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4408 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
4409 ok((WNDPROC)retval == old_window_procW,
4410 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4411 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
4413 /* set it back to ANSI */
4414 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4418 static void test_ShowWindow(void)
4420 HWND hwnd;
4421 DWORD style;
4422 RECT rcMain, rc;
4423 LPARAM ret;
4425 SetRect(&rcMain, 120, 120, 210, 210);
4427 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
4428 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4429 WS_MAXIMIZEBOX | WS_POPUP,
4430 rcMain.left, rcMain.top,
4431 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
4432 0, 0, 0, NULL);
4433 assert(hwnd);
4435 style = GetWindowLong(hwnd, GWL_STYLE);
4436 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4437 ok(!(style & WS_VISIBLE), "window should not be visible\n");
4438 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4439 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4440 GetWindowRect(hwnd, &rc);
4441 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4442 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4443 rc.left, rc.top, rc.right, rc.bottom);
4445 ret = ShowWindow(hwnd, SW_SHOW);
4446 ok(!ret, "not expected ret: %lu\n", ret);
4447 style = GetWindowLong(hwnd, GWL_STYLE);
4448 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4449 ok(style & WS_VISIBLE, "window should be visible\n");
4450 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4451 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4452 GetWindowRect(hwnd, &rc);
4453 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4454 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4455 rc.left, rc.top, rc.right, rc.bottom);
4457 ret = ShowWindow(hwnd, SW_MINIMIZE);
4458 ok(ret, "not expected ret: %lu\n", ret);
4459 style = GetWindowLong(hwnd, GWL_STYLE);
4460 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4461 ok(style & WS_VISIBLE, "window should be visible\n");
4462 ok(style & WS_MINIMIZE, "window should be minimized\n");
4463 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4464 GetWindowRect(hwnd, &rc);
4465 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4467 ShowWindow(hwnd, SW_RESTORE);
4468 ok(ret, "not expected ret: %lu\n", ret);
4469 style = GetWindowLong(hwnd, GWL_STYLE);
4470 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4471 ok(style & WS_VISIBLE, "window should be visible\n");
4472 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4473 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4474 GetWindowRect(hwnd, &rc);
4475 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4476 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4477 rc.left, rc.top, rc.right, rc.bottom);
4479 ret = EnableWindow(hwnd, FALSE);
4480 ok(!ret, "not expected ret: %lu\n", ret);
4481 style = GetWindowLong(hwnd, GWL_STYLE);
4482 ok(style & WS_DISABLED, "window should be disabled\n");
4484 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
4485 ok(!ret, "not expected ret: %lu\n", ret);
4486 style = GetWindowLong(hwnd, GWL_STYLE);
4487 ok(style & WS_DISABLED, "window should be disabled\n");
4488 ok(style & WS_VISIBLE, "window should be visible\n");
4489 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4490 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4491 GetWindowRect(hwnd, &rc);
4492 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4493 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4494 rc.left, rc.top, rc.right, rc.bottom);
4496 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
4497 ok(!ret, "not expected ret: %lu\n", ret);
4498 style = GetWindowLong(hwnd, GWL_STYLE);
4499 ok(style & WS_DISABLED, "window should be disabled\n");
4500 ok(style & WS_VISIBLE, "window should be visible\n");
4501 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4502 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4503 GetWindowRect(hwnd, &rc);
4504 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4505 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4506 rc.left, rc.top, rc.right, rc.bottom);
4508 ret = ShowWindow(hwnd, SW_MINIMIZE);
4509 ok(ret, "not expected ret: %lu\n", ret);
4510 style = GetWindowLong(hwnd, GWL_STYLE);
4511 ok(style & WS_DISABLED, "window should be disabled\n");
4512 ok(style & WS_VISIBLE, "window should be visible\n");
4513 ok(style & WS_MINIMIZE, "window should be minimized\n");
4514 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4515 GetWindowRect(hwnd, &rc);
4516 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4518 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
4519 ok(!ret, "not expected ret: %lu\n", ret);
4520 style = GetWindowLong(hwnd, GWL_STYLE);
4521 ok(style & WS_DISABLED, "window should be disabled\n");
4522 ok(style & WS_VISIBLE, "window should be visible\n");
4523 ok(style & WS_MINIMIZE, "window should be minimized\n");
4524 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4525 GetWindowRect(hwnd, &rc);
4526 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4528 ret = ShowWindow(hwnd, SW_RESTORE);
4529 ok(ret, "not expected ret: %lu\n", ret);
4530 style = GetWindowLong(hwnd, GWL_STYLE);
4531 ok(style & WS_DISABLED, "window should be disabled\n");
4532 ok(style & WS_VISIBLE, "window should be visible\n");
4533 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4534 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4535 GetWindowRect(hwnd, &rc);
4536 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4537 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4538 rc.left, rc.top, rc.right, rc.bottom);
4540 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4541 ok(!ret, "not expected ret: %lu\n", ret);
4542 ok(IsWindow(hwnd), "window should exist\n");
4544 ret = EnableWindow(hwnd, TRUE);
4545 ok(ret, "not expected ret: %lu\n", ret);
4547 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4548 ok(!ret, "not expected ret: %lu\n", ret);
4549 ok(!IsWindow(hwnd), "window should not exist\n");
4552 static void test_gettext(void)
4554 WNDCLASS cls;
4555 LPCSTR clsname = "gettexttest";
4556 HWND hwnd;
4557 LRESULT r;
4559 memset( &cls, 0, sizeof cls );
4560 cls.lpfnWndProc = DefWindowProc;
4561 cls.lpszClassName = clsname;
4562 cls.hInstance = GetModuleHandle(NULL);
4564 if (!RegisterClass( &cls )) return;
4566 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
4567 ok( hwnd != NULL, "window was null\n");
4569 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
4570 ok( r == 0, "settext should return zero\n");
4572 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
4573 ok( r == 0, "settext should return zero (%ld)\n", r);
4575 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
4576 ok( r == 0, "settext should return zero (%ld)\n", r);
4578 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
4579 ok( r == 0, "settext should return zero (%ld)\n", r);
4581 DestroyWindow(hwnd);
4582 UnregisterClass( clsname, NULL );
4586 static void test_GetUpdateRect(void)
4588 MSG msg;
4589 BOOL ret, parent_wm_paint, grandparent_wm_paint;
4590 RECT rc1, rc2;
4591 HWND hgrandparent, hparent, hchild;
4592 WNDCLASSA cls;
4593 static const char classNameA[] = "GetUpdateRectClass";
4595 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
4596 0, 0, 100, 100, NULL, NULL, 0, NULL);
4598 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
4599 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4601 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
4602 10, 10, 30, 30, hparent, NULL, 0, NULL);
4604 ShowWindow(hgrandparent, SW_SHOW);
4605 UpdateWindow(hgrandparent);
4606 flush_events( TRUE );
4608 ShowWindow(hchild, SW_HIDE);
4609 SetRect(&rc2, 0, 0, 0, 0);
4610 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4611 ok(!ret, "GetUpdateRect returned not empty region\n");
4612 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4613 rc1.left, rc1.top, rc1.right, rc1.bottom,
4614 rc2.left, rc2.top, rc2.right, rc2.bottom);
4616 SetRect(&rc2, 10, 10, 40, 40);
4617 ret = GetUpdateRect(hparent, &rc1, FALSE);
4618 ok(ret, "GetUpdateRect returned empty region\n");
4619 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4620 rc1.left, rc1.top, rc1.right, rc1.bottom,
4621 rc2.left, rc2.top, rc2.right, rc2.bottom);
4623 parent_wm_paint = FALSE;
4624 grandparent_wm_paint = FALSE;
4625 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4627 if (msg.message == WM_PAINT)
4629 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4630 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4632 DispatchMessage(&msg);
4634 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4635 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4637 DestroyWindow(hgrandparent);
4639 cls.style = 0;
4640 cls.lpfnWndProc = DefWindowProcA;
4641 cls.cbClsExtra = 0;
4642 cls.cbWndExtra = 0;
4643 cls.hInstance = GetModuleHandleA(0);
4644 cls.hIcon = 0;
4645 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
4646 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4647 cls.lpszMenuName = NULL;
4648 cls.lpszClassName = classNameA;
4650 if(!RegisterClassA(&cls)) {
4651 trace("Register failed %d\n", GetLastError());
4652 return;
4655 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
4656 0, 0, 100, 100, NULL, NULL, 0, NULL);
4658 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
4659 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4661 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
4662 10, 10, 30, 30, hparent, NULL, 0, NULL);
4664 ShowWindow(hgrandparent, SW_SHOW);
4665 UpdateWindow(hgrandparent);
4666 flush_events( TRUE );
4668 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4669 ok(!ret, "GetUpdateRect returned not empty region\n");
4671 ShowWindow(hchild, SW_HIDE);
4673 SetRect(&rc2, 0, 0, 0, 0);
4674 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4675 ok(!ret, "GetUpdateRect returned not empty region\n");
4676 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4677 rc1.left, rc1.top, rc1.right, rc1.bottom,
4678 rc2.left, rc2.top, rc2.right, rc2.bottom);
4680 SetRect(&rc2, 10, 10, 40, 40);
4681 ret = GetUpdateRect(hparent, &rc1, FALSE);
4682 ok(ret, "GetUpdateRect returned empty region\n");
4683 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4684 rc1.left, rc1.top, rc1.right, rc1.bottom,
4685 rc2.left, rc2.top, rc2.right, rc2.bottom);
4687 parent_wm_paint = FALSE;
4688 grandparent_wm_paint = FALSE;
4689 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4691 if (msg.message == WM_PAINT)
4693 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4694 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4696 DispatchMessage(&msg);
4698 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4699 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4701 DestroyWindow(hgrandparent);
4705 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
4707 if(msg == WM_PAINT)
4709 PAINTSTRUCT ps;
4710 RECT updateRect;
4711 DWORD waitResult;
4712 HWND win;
4713 const int waitTime = 2000;
4715 BeginPaint(hwnd, &ps);
4717 /* create and destroy window to create an exposed region on this window */
4718 win = CreateWindowA("static", "win", WS_VISIBLE,
4719 10,10,50,50, NULL, NULL, 0, NULL);
4720 DestroyWindow(win);
4722 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
4724 ValidateRect(hwnd, NULL);
4725 EndPaint(hwnd, &ps);
4727 if(waitResult != WAIT_TIMEOUT)
4729 GetUpdateRect(hwnd, &updateRect, FALSE);
4730 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
4733 return 1;
4735 return DefWindowProc(hwnd, msg, wParam, lParam);
4738 static void test_Expose(void)
4740 ATOM atom;
4741 WNDCLASSA cls;
4742 HWND mw;
4743 memset(&cls, 0, sizeof(WNDCLASSA));
4744 cls.lpfnWndProc = TestExposedRegion_WndProc;
4745 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4746 cls.lpszClassName = "TestExposeClass";
4747 atom = RegisterClassA(&cls);
4749 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
4750 0, 0, 200, 100, NULL, NULL, 0, NULL);
4752 UpdateWindow(mw);
4753 DestroyWindow(mw);
4756 static void test_GetWindowModuleFileName(void)
4758 HWND hwnd;
4759 HINSTANCE hinst;
4760 UINT ret1, ret2;
4761 char buf1[MAX_PATH], buf2[MAX_PATH];
4763 if (!pGetWindowModuleFileNameA)
4765 skip("GetWindowModuleFileNameA is not available\n");
4766 return;
4769 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
4770 assert(hwnd);
4772 hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
4773 ok(hinst == 0 || broken(hinst == GetModuleHandle(0)), /* win9x */ "expected 0, got %p\n", hinst);
4775 buf1[0] = 0;
4776 SetLastError(0xdeadbeef);
4777 ret1 = GetModuleFileName(hinst, buf1, sizeof(buf1));
4778 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
4780 buf2[0] = 0;
4781 SetLastError(0xdeadbeef);
4782 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
4783 ok(ret2, "GetWindowModuleFileNameA error %u\n", GetLastError());
4785 ok(ret1 == ret2 || broken(ret2 == ret1 + 1), /* win98 */ "%u != %u\n", ret1, ret2);
4786 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
4788 hinst = GetModuleHandle(0);
4790 SetLastError(0xdeadbeef);
4791 ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
4792 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
4793 "expected %u, got %u\n", ret1 - 2, ret2);
4794 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4795 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4796 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4798 SetLastError(0xdeadbeef);
4799 ret2 = GetModuleFileName(hinst, buf2, 0);
4800 ok(!ret2, "GetModuleFileName should return 0\n");
4801 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4802 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4803 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4805 SetLastError(0xdeadbeef);
4806 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
4807 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
4808 "expected %u, got %u\n", ret1 - 2, ret2);
4809 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4810 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4811 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4813 SetLastError(0xdeadbeef);
4814 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
4815 ok(!ret2, "expected 0, got %u\n", ret2);
4816 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4817 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4818 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4820 DestroyWindow(hwnd);
4822 buf2[0] = 0;
4823 hwnd = (HWND)0xdeadbeef;
4824 SetLastError(0xdeadbeef);
4825 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4826 ok(!ret1, "expected 0, got %u\n", ret1);
4827 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef), /* win9x */
4828 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
4830 hwnd = FindWindow("Shell_TrayWnd", NULL);
4831 ok(IsWindow(hwnd), "got invalid tray window %p\n", hwnd);
4832 SetLastError(0xdeadbeef);
4833 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4834 ok(!ret1 || broken(ret1), /* win98 */ "expected 0, got %u\n", ret1);
4836 if (!ret1) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
4838 ret1 = GetModuleFileName(0, buf1, sizeof(buf1));
4839 hwnd = GetDesktopWindow();
4840 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
4841 SetLastError(0xdeadbeef);
4842 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
4843 ok(!ret2 || ret1 == ret2 /* vista */, "expected 0 or %u, got %u %s\n", ret1, ret2, buf2);
4847 static void test_hwnd_message(void)
4849 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
4850 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
4852 HWND parent = 0, hwnd, found;
4853 RECT rect;
4855 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
4856 on CreateWindowExA and crash later in the test.
4857 Use UNICODE here to fail on win9x */
4858 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
4859 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
4860 if (!hwnd)
4862 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
4863 return;
4866 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
4867 if (pGetAncestor)
4869 char buffer[100];
4870 HWND root, desktop = GetDesktopWindow();
4872 parent = pGetAncestor(hwnd, GA_PARENT);
4873 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
4874 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
4875 root = pGetAncestor(hwnd, GA_ROOT);
4876 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
4877 ok( !pGetAncestor(parent, GA_PARENT), "parent shouldn't have parent %p\n",
4878 pGetAncestor(parent, GA_PARENT) );
4879 trace("parent %p root %p desktop %p\n", parent, root, desktop);
4880 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
4881 ok( !lstrcmpi( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
4882 GetWindowRect( parent, &rect );
4883 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
4884 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4886 GetWindowRect( hwnd, &rect );
4887 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
4888 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4890 /* test FindWindow behavior */
4892 found = FindWindowExA( 0, 0, 0, "message window" );
4893 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
4894 SetLastError(0xdeadbeef);
4895 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
4896 ok( found == 0, "found message window %p/%p\n", found, hwnd );
4897 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
4898 if (parent)
4900 found = FindWindowExA( parent, 0, 0, "message window" );
4901 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
4904 /* test IsChild behavior */
4906 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
4908 /* test IsWindowVisible behavior */
4910 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
4911 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
4913 DestroyWindow(hwnd);
4916 static void test_layered_window(void)
4918 HWND hwnd;
4919 COLORREF key = 0;
4920 BYTE alpha = 0;
4921 DWORD flags = 0;
4922 BOOL ret;
4924 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes)
4926 win_skip( "layered windows not supported\n" );
4927 return;
4929 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
4930 100, 100, 200, 200, 0, 0, 0, NULL);
4931 assert( hwnd );
4932 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4933 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
4934 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
4935 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
4936 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
4937 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4938 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
4939 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
4940 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4941 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4942 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4943 ok( key == 0x123456, "wrong color key %x\n", key );
4944 ok( alpha == 44, "wrong alpha %u\n", alpha );
4945 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
4947 /* clearing WS_EX_LAYERED resets attributes */
4948 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
4949 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4950 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
4951 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
4952 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4953 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
4954 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
4955 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4956 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4957 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4958 ok( key == 0x654321, "wrong color key %x\n", key );
4959 ok( alpha == 22, "wrong alpha %u\n", alpha );
4960 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
4962 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
4963 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4964 alpha = 0;
4965 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4966 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4967 ok( key == 0x888888, "wrong color key %x\n", key );
4968 /* alpha not changed on vista if LWA_ALPHA is not set */
4969 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
4970 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
4972 /* color key always changed */
4973 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
4974 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4975 alpha = 0;
4976 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4977 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4978 ok( key == 0x999999, "wrong color key %x\n", key );
4979 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
4980 ok( flags == 0, "wrong flags %x\n", flags );
4982 /* default alpha is 0 */
4983 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
4984 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
4985 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
4986 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4987 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4988 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4989 ok( key == 0x222222, "wrong color key %x\n", key );
4990 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
4991 ok( flags == 0, "wrong flags %x\n", flags );
4993 DestroyWindow( hwnd );
4996 static MONITORINFO mi;
4998 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
5000 switch (msg)
5002 case WM_NCCREATE:
5004 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
5005 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs->x, cs->y, cs->cx, cs->cy);
5006 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
5007 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
5008 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
5009 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5010 cs->x, cs->y, cs->cx, cs->cy);
5011 break;
5013 case WM_GETMINMAXINFO:
5015 MINMAXINFO *minmax = (MINMAXINFO *)lp;
5016 dump_minmax_info(minmax);
5017 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
5018 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
5019 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
5020 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
5021 break;
5024 return DefWindowProc(hwnd, msg, wp, lp);
5027 static void test_fullscreen(void)
5029 static const DWORD t_style[] = {
5030 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
5032 static const DWORD t_ex_style[] = {
5033 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
5035 WNDCLASS cls;
5036 HWND hwnd;
5037 int i, j;
5038 POINT pt;
5039 RECT rc;
5040 HMONITOR hmon;
5041 LRESULT ret;
5043 if (!pGetMonitorInfoA || !pMonitorFromPoint)
5045 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
5046 return;
5049 pt.x = pt.y = 0;
5050 SetLastError(0xdeadbeef);
5051 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
5052 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
5054 mi.cbSize = sizeof(mi);
5055 SetLastError(0xdeadbeef);
5056 ret = pGetMonitorInfoA(hmon, &mi);
5057 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
5058 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
5059 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5060 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5062 cls.style = 0;
5063 cls.lpfnWndProc = fullscreen_wnd_proc;
5064 cls.cbClsExtra = 0;
5065 cls.cbWndExtra = 0;
5066 cls.hInstance = GetModuleHandle(0);
5067 cls.hIcon = 0;
5068 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
5069 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5070 cls.lpszMenuName = NULL;
5071 cls.lpszClassName = "fullscreen_class";
5072 RegisterClass(&cls);
5074 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
5076 DWORD style, ex_style;
5078 /* avoid a WM interaction */
5079 assert(!(t_style[i] & WS_VISIBLE));
5081 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
5083 int fixup;
5085 style = t_style[i];
5086 ex_style = t_ex_style[j];
5088 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5089 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5090 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5091 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5092 GetWindowRect(hwnd, &rc);
5093 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5094 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5095 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5096 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5097 DestroyWindow(hwnd);
5099 style = t_style[i] | WS_MAXIMIZE;
5100 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5101 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5102 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5103 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5104 GetWindowRect(hwnd, &rc);
5105 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5106 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5107 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5108 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5109 DestroyWindow(hwnd);
5111 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
5112 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5113 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5114 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5115 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5116 GetWindowRect(hwnd, &rc);
5117 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5118 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5119 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5120 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5121 DestroyWindow(hwnd);
5123 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
5124 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5125 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5126 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5127 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5128 GetWindowRect(hwnd, &rc);
5129 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5130 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5131 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5132 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5133 DestroyWindow(hwnd);
5135 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
5136 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5137 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5138 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5139 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5140 GetWindowRect(hwnd, &rc);
5141 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5142 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5143 fixup = min(abs(rc.left), abs(rc.top));
5144 InflateRect(&rc, -fixup, -fixup);
5145 /* FIXME: this doesn't work correctly in Wine for child windows yet */
5146 if (style & WS_CHILD)
5147 todo_wine
5148 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5149 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5150 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5151 else
5152 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5153 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5154 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5155 DestroyWindow(hwnd);
5157 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
5158 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5159 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5160 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5161 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5162 GetWindowRect(hwnd, &rc);
5163 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5164 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5165 fixup = min(abs(rc.left), abs(rc.top));
5166 InflateRect(&rc, -fixup, -fixup);
5167 if (style & (WS_CHILD | WS_POPUP))
5168 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5169 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5170 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5171 else
5172 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5173 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5174 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5175 DestroyWindow(hwnd);
5179 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5182 static BOOL test_thick_child_got_minmax;
5184 static int getExpectedThickChildInc(void)
5186 const int outer = 2;
5187 int resizeBorder = GetSystemMetrics(SM_CXFRAME) - GetSystemMetrics(SM_CXDLGFRAME);
5188 return (outer + resizeBorder);
5191 static LRESULT WINAPI test_thick_child_size_winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5193 MINMAXINFO* minmax;
5194 int expectedMinTrack;
5195 int actualMinTrackX;
5196 int actualMinTrackY;
5197 int expectedMaxTrackX;
5198 int expectedMaxTrackY;
5199 int actualMaxTrackX;
5200 int actualMaxTrackY;
5201 int expectedMaxSizeX;
5202 int expectedMaxSizeY;
5203 int actualMaxSizeX;
5204 int actualMaxSizeY;
5205 int expectedPosX;
5206 int expectedPosY;
5207 int actualPosX;
5208 int actualPosY;
5209 RECT rect;
5210 switch (msg)
5212 case WM_GETMINMAXINFO:
5214 minmax = (MINMAXINFO *)lparam;
5215 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
5216 dump_minmax_info( minmax );
5218 test_thick_child_got_minmax = TRUE;
5220 expectedMinTrack = 2* getExpectedThickChildInc();
5221 actualMinTrackX = minmax->ptMinTrackSize.x;
5222 actualMinTrackY = minmax->ptMinTrackSize.y;
5223 todo_wine
5224 ok(actualMinTrackX == expectedMinTrack && actualMinTrackY == expectedMinTrack,
5225 "expected minTrack %dx%d, actual minTrack %dx%d\n",
5226 expectedMinTrack, expectedMinTrack, actualMinTrackX, actualMinTrackY);
5228 actualMaxTrackX = minmax->ptMaxTrackSize.x;
5229 actualMaxTrackY = minmax->ptMaxTrackSize.y;
5230 expectedMaxTrackX = GetSystemMetrics(SM_CXMAXTRACK);
5231 expectedMaxTrackY = GetSystemMetrics(SM_CYMAXTRACK);
5232 ok(actualMaxTrackX == expectedMaxTrackX && actualMaxTrackY == expectedMaxTrackY,
5233 "expected maxTrack %dx%d, actual maxTrack %dx%d\n",
5234 expectedMaxTrackX, expectedMaxTrackY, actualMaxTrackX, actualMaxTrackY);
5236 GetClientRect(GetParent(hwnd), &rect);
5237 AdjustWindowRectEx(&rect, WS_CHILD | WS_VISIBLE | WS_THICKFRAME, FALSE, 0);
5238 expectedMaxSizeX = rect.right - rect.left;
5239 expectedMaxSizeY = rect.bottom - rect.top;
5240 actualMaxSizeX = minmax->ptMaxSize.x;
5241 actualMaxSizeY = minmax->ptMaxSize.y;
5242 ok(actualMaxSizeX == expectedMaxSizeX && actualMaxSizeY == expectedMaxSizeY,
5243 "expected maxTrack %dx%d, actual maxTrack %dx%d\n",
5244 expectedMaxSizeX, expectedMaxSizeY, actualMaxSizeX, actualMaxSizeY);
5246 expectedPosX = - getExpectedThickChildInc();
5247 expectedPosY = expectedPosX;
5248 actualPosX = minmax->ptMaxPosition.x;
5249 actualPosY = minmax->ptMaxPosition.y;
5250 todo_wine
5251 ok(actualPosX == expectedPosX && actualPosY == expectedPosY,
5252 "expected maxPosition (%d/%d), actual maxPosition (%d/%d)\n",
5253 expectedPosX, expectedPosY, actualPosX, actualPosY);
5254 break;
5258 return DefWindowProcA(hwnd, msg, wparam, lparam);
5261 static void test_thick_child_size(HWND parentWindow)
5263 BOOL success;
5264 RECT childRect;
5265 HWND childWindow;
5266 LONG childWidth;
5267 LONG childHeight;
5268 WNDCLASSA cls;
5269 LPCTSTR className = "THICK_CHILD_CLASS";
5270 LONG style = WS_CHILD | WS_VISIBLE | WS_THICKFRAME;
5271 LONG exStyle = 0;
5272 int expectedSize = 2*getExpectedThickChildInc();
5275 cls.style = 0;
5276 cls.lpfnWndProc = test_thick_child_size_winproc;
5277 cls.cbClsExtra = 0;
5278 cls.cbWndExtra = 0;
5279 cls.hInstance = GetModuleHandleA(0);
5280 cls.hIcon = 0;
5281 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
5282 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5283 cls.lpszMenuName = NULL;
5284 cls.lpszClassName = className;
5285 SetLastError(0xdeadbeef);
5286 ok(RegisterClassA(&cls),"RegisterClassA failed, error: %u\n", GetLastError());
5288 test_thick_child_got_minmax = FALSE;
5290 SetLastError(0xdeadbeef);
5291 childWindow = CreateWindowEx( exStyle, className, "", style, 0, 0, 0, 0, parentWindow, 0, GetModuleHandleA(0), NULL );
5292 ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
5294 ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
5296 SetLastError(0xdeadbeef);
5297 success = GetWindowRect(childWindow, &childRect);
5298 ok(success,"GetWindowRect call failed, error: %u\n", GetLastError());
5299 childWidth = childRect.right - childRect.left;
5300 childHeight = childRect.bottom - childRect.top;
5302 todo_wine
5303 ok( (childWidth == expectedSize) && (childHeight == expectedSize),
5304 "size of window with style WS_CHILD | WS_VISIBLE | WS_THICKFRAME is wrong: expected size %dx%d != actual size %dx%d\n",
5305 expectedSize, expectedSize, childWidth, childHeight);
5308 SetLastError(0xdeadbeef);
5309 success = DestroyWindow(childWindow);
5310 ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
5311 ok(UnregisterClass(className, GetModuleHandleA(0)),"UnregisterClass call failed\n");
5314 static void test_handles( HWND full_hwnd )
5316 HWND hwnd = full_hwnd;
5317 BOOL ret;
5318 RECT rect;
5320 SetLastError( 0xdeadbeef );
5321 ret = GetWindowRect( hwnd, &rect );
5322 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5324 #ifdef _WIN64
5325 if ((ULONG_PTR)full_hwnd >> 32)
5326 hwnd = (HWND)((ULONG_PTR)full_hwnd & ~0u);
5327 else
5328 hwnd = (HWND)((ULONG_PTR)full_hwnd | ((ULONG_PTR)~0u << 32));
5329 SetLastError( 0xdeadbeef );
5330 ret = GetWindowRect( hwnd, &rect );
5331 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5333 hwnd = (HWND)(((ULONG_PTR)full_hwnd & ~0u) | ((ULONG_PTR)0x1234 << 32));
5334 SetLastError( 0xdeadbeef );
5335 ret = GetWindowRect( hwnd, &rect );
5336 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5338 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x9876 << 16));
5339 SetLastError( 0xdeadbeef );
5340 ret = GetWindowRect( hwnd, &rect );
5341 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
5342 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
5344 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x12345678 << 16));
5345 SetLastError( 0xdeadbeef );
5346 ret = GetWindowRect( hwnd, &rect );
5347 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
5348 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
5349 #endif
5352 static void test_DeferWindowPos( HWND hwnd )
5354 HDWP hdwp;
5355 BOOL ret;
5357 SetLastError( 0xdeadbeef );
5358 hdwp = BeginDeferWindowPos( -1 );
5359 ok(!hdwp, "BeginDeferWindowPos(-1) succeeded\n");
5360 ok(GetLastError() == ERROR_INVALID_PARAMETER, "LastError is %u\n", GetLastError());
5362 if (hdwp) EndDeferWindowPos( hdwp );
5364 SetLastError( 0xdeadbeef );
5365 hdwp = BeginDeferWindowPos( 0 );
5366 ok(!hdwp, "BeginDeferWindowPos(0) failed\n");
5367 ok(GetLastError() == 0xdeadbeef, "LastError is %u\n", GetLastError());
5368 ok(HeapValidate( GetProcessHeap(), 0, hdwp ), "Cannot read from hdwp structure\n");
5369 trace("hdwp: %p\n", hdwp);
5371 if (hdwp)
5373 BOOL visible;
5375 SetLastError( 0xdeadbeef );
5376 hdwp = DeferWindowPos( hdwp, GetDesktopWindow(), NULL, 0, 0, 0, 0, SWP_SHOWWINDOW );
5377 ok(!hdwp, "DeferWindowPos(GetDesktopWindow()) succeeded\n");
5378 ok(GetLastError() == 0xdeadbeef, "LastError is %u\n", GetLastError());
5379 if (hdwp) EndDeferWindowPos( hdwp );
5381 SetLastError( 0xdeadbeef );
5382 hdwp = BeginDeferWindowPos( 1 );
5383 ok(!hdwp, "BeginDeferWindowPos(1) failed\n");
5384 ok(GetLastError() == 0xdeadbeef, "LastError is %u\n", GetLastError());
5386 visible = IsWindowVisible( hwnd );
5388 SetLastError( 0xdeadbeef );
5389 hdwp = DeferWindowPos( hdwp, hwnd, NULL, 0, 0, 0, 0, visible ? SWP_HIDEWINDOW : SWP_SHOWWINDOW );
5390 ok(!!hdwp, "DeferWindowPos(hwnd) failed\n");
5391 ok(GetLastError() == 0xdeadbeef, "LastError is %u\n", GetLastError());
5392 if (hdwp)
5394 BOOL nowvisible;
5396 SetLastError( 0xdeadbeef );
5397 ret = EndDeferWindowPos( hdwp );
5398 ok(ret, "EndDeferWindowPos failed\n");
5399 ok(GetLastError() == 0xdeadbeef, "LastError is %u\n", GetLastError());
5400 nowvisible = IsWindowVisible( hwnd );
5401 ok(nowvisible != visible, "Window visibility didn't change!\n");
5402 ShowWindow( hwnd, visible ? SWP_SHOWWINDOW : SWP_HIDEWINDOW );
5406 SetLastError( 0xdeadbeef );
5407 ret = EndDeferWindowPos( NULL );
5408 ok(!ret, "EndDeferWindowPos(NULL) succeeded\n");
5409 ok(GetLastError() == 0xdeadbeef, "LastError is %u\n", GetLastError());
5412 START_TEST(win)
5414 HMODULE user32 = GetModuleHandleA( "user32.dll" );
5415 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
5416 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
5417 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
5418 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
5419 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
5420 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
5421 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
5423 if (!RegisterWindowClasses()) assert(0);
5425 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
5426 assert(hhook);
5428 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
5429 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5430 WS_MAXIMIZEBOX | WS_POPUP,
5431 100, 100, 200, 200,
5432 0, 0, GetModuleHandle(0), NULL);
5433 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
5434 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5435 WS_MAXIMIZEBOX | WS_POPUP,
5436 100, 100, 200, 200,
5437 0, 0, GetModuleHandle(0), NULL);
5438 assert( hwndMain );
5439 assert( hwndMain2 );
5441 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
5443 /* Add the tests below this line */
5444 test_thick_child_size(hwndMain);
5445 test_fullscreen();
5446 test_hwnd_message();
5447 test_nonclient_area(hwndMain);
5448 test_params();
5449 test_GetWindowModuleFileName();
5450 test_capture_1();
5451 test_capture_2();
5452 test_capture_3(hwndMain, hwndMain2);
5454 test_CreateWindow();
5455 test_parent_owner();
5456 test_SetParent();
5458 test_mdi();
5459 test_icons();
5460 test_SetWindowPos(hwndMain);
5461 test_DeferWindowPos(hwndMain);
5462 test_SetMenu(hwndMain);
5463 test_SetFocus(hwndMain);
5464 test_SetActiveWindow(hwndMain);
5466 test_children_zorder(hwndMain);
5467 test_popup_zorder(hwndMain2, hwndMain);
5468 test_keyboard_input(hwndMain);
5469 test_mouse_input(hwndMain);
5470 test_validatergn(hwndMain);
5471 test_nccalcscroll( hwndMain);
5472 test_scrollvalidate( hwndMain);
5473 test_scrolldc( hwndMain);
5474 test_scroll();
5475 test_IsWindowUnicode();
5476 test_vis_rgn(hwndMain);
5478 test_AdjustWindowRect();
5479 test_window_styles();
5480 test_redrawnow();
5481 test_csparentdc();
5482 test_SetWindowLong();
5483 test_ShowWindow();
5484 if (0) test_gettext(); /* crashes on NT4 */
5485 test_GetUpdateRect();
5486 test_Expose();
5487 test_layered_window();
5489 test_SetForegroundWindow(hwndMain);
5490 test_shell_window();
5491 test_handles( hwndMain );
5493 /* add the tests above this line */
5494 UnhookWindowsHookEx(hhook);
5496 DestroyWindow(hwndMain2);
5497 DestroyWindow(hwndMain);