user32/tests: Avoid crash on win9x.
[wine/hacks.git] / dlls / user32 / tests / win.c
blob6e411003706d69f62656920b7e412f737661c7f3
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( GetLastError() == ERROR_TLW_WITH_WSCHILD, "CreateWindowExA should call SetLastError\n" );
160 ok( !test, "WS_CHILD without parent created\n" );
162 /* desktop window */
163 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
164 style = GetWindowLongA( desktop, GWL_STYLE );
165 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
166 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
167 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
169 /* normal child window */
170 test = create_tool_window( WS_CHILD, hwndMain );
171 trace( "created child %p\n", test );
172 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
173 SetWindowLongA( test, GWL_STYLE, 0 );
174 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
175 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
176 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
177 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
178 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
179 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
180 DestroyWindow( test );
182 /* normal child window with WS_MAXIMIZE */
183 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
184 DestroyWindow( test );
186 /* normal child window with WS_THICKFRAME */
187 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
188 DestroyWindow( test );
190 /* popup window with WS_THICKFRAME */
191 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
192 DestroyWindow( test );
194 /* child of desktop */
195 test = create_tool_window( WS_CHILD, desktop );
196 trace( "created child of desktop %p\n", test );
197 check_parents( test, desktop, 0, desktop, 0, test, desktop );
198 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
199 check_parents( test, desktop, 0, 0, 0, test, test );
200 SetWindowLongA( test, GWL_STYLE, 0 );
201 check_parents( test, desktop, 0, 0, 0, test, test );
202 DestroyWindow( test );
204 /* child of desktop with WS_MAXIMIZE */
205 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
206 DestroyWindow( test );
208 /* child of desktop with WS_MINIMIZE */
209 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
210 DestroyWindow( test );
212 /* child of child */
213 test = create_tool_window( WS_CHILD, child );
214 trace( "created child of child %p\n", test );
215 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
216 SetWindowLongA( test, GWL_STYLE, 0 );
217 check_parents( test, child, child, 0, 0, hwndMain, test );
218 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
219 check_parents( test, child, child, 0, 0, hwndMain, test );
220 DestroyWindow( test );
222 /* child of child with WS_MAXIMIZE */
223 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
224 DestroyWindow( test );
226 /* child of child with WS_MINIMIZE */
227 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
228 DestroyWindow( test );
230 /* not owned top-level window */
231 test = create_tool_window( 0, 0 );
232 trace( "created top-level %p\n", test );
233 check_parents( test, desktop, 0, 0, 0, test, test );
234 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
235 check_parents( test, desktop, 0, 0, 0, test, test );
236 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
237 check_parents( test, desktop, 0, desktop, 0, test, desktop );
238 DestroyWindow( test );
240 /* not owned top-level window with WS_MAXIMIZE */
241 test = create_tool_window( WS_MAXIMIZE, 0 );
242 DestroyWindow( test );
244 /* owned top-level window */
245 test = create_tool_window( 0, hwndMain );
246 trace( "created owned top-level %p\n", test );
247 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
248 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
249 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
250 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
251 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
252 DestroyWindow( test );
254 /* owned top-level window with WS_MAXIMIZE */
255 test = create_tool_window( WS_MAXIMIZE, hwndMain );
256 DestroyWindow( test );
258 /* not owned popup */
259 test = create_tool_window( WS_POPUP, 0 );
260 trace( "created popup %p\n", test );
261 check_parents( test, desktop, 0, 0, 0, test, test );
262 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
263 check_parents( test, desktop, 0, desktop, 0, test, desktop );
264 SetWindowLongA( test, GWL_STYLE, 0 );
265 check_parents( test, desktop, 0, 0, 0, test, test );
266 DestroyWindow( test );
268 /* not owned popup with WS_MAXIMIZE */
269 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
270 DestroyWindow( test );
272 /* owned popup */
273 test = create_tool_window( WS_POPUP, hwndMain );
274 trace( "created owned popup %p\n", test );
275 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
276 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
277 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
278 SetWindowLongA( test, GWL_STYLE, 0 );
279 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
280 DestroyWindow( test );
282 /* owned popup with WS_MAXIMIZE */
283 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
284 DestroyWindow( test );
286 /* top-level window owned by child (same as owned by top-level) */
287 test = create_tool_window( 0, child );
288 trace( "created top-level owned by child %p\n", test );
289 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
290 DestroyWindow( test );
292 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
293 test = create_tool_window( WS_MAXIMIZE, child );
294 DestroyWindow( test );
296 /* popup owned by desktop (same as not owned) */
297 test = create_tool_window( WS_POPUP, desktop );
298 trace( "created popup owned by desktop %p\n", test );
299 check_parents( test, desktop, 0, 0, 0, test, test );
300 DestroyWindow( test );
302 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
303 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
304 DestroyWindow( test );
306 /* popup owned by child (same as owned by top-level) */
307 test = create_tool_window( WS_POPUP, child );
308 trace( "created popup owned by child %p\n", test );
309 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
310 DestroyWindow( test );
312 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
313 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
314 DestroyWindow( test );
316 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
317 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
318 trace( "created WS_CHILD popup %p\n", test );
319 check_parents( test, desktop, 0, 0, 0, test, test );
320 DestroyWindow( test );
322 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
323 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
324 DestroyWindow( test );
326 /* owned popup with WS_CHILD (same as WS_POPUP only) */
327 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
328 trace( "created owned WS_CHILD popup %p\n", test );
329 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
330 DestroyWindow( test );
332 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
333 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
334 DestroyWindow( test );
336 /******************** parent changes *************************/
337 trace( "testing parent changes\n" );
339 /* desktop window */
340 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
341 if (0)
343 /* this test succeeds on NT but crashes on win9x systems */
344 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
345 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
346 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
347 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
348 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
350 /* normal child window */
351 test = create_tool_window( WS_CHILD, hwndMain );
352 trace( "created child %p\n", test );
354 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
355 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
356 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
358 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
359 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
360 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
362 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
363 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
364 check_parents( test, desktop, 0, desktop, 0, test, desktop );
366 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
367 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
368 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
369 check_parents( test, desktop, child, desktop, child, test, desktop );
371 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
372 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
373 check_parents( test, desktop, 0, desktop, 0, test, desktop );
374 DestroyWindow( test );
376 /* not owned top-level window */
377 test = create_tool_window( 0, 0 );
378 trace( "created top-level %p\n", test );
380 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
381 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
382 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
384 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
385 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
386 check_parents( test, desktop, child, 0, child, test, test );
388 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
389 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
390 check_parents( test, desktop, 0, 0, 0, test, test );
391 DestroyWindow( test );
393 /* not owned popup */
394 test = create_tool_window( WS_POPUP, 0 );
395 trace( "created popup %p\n", test );
397 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
398 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
399 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
401 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
402 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
403 check_parents( test, desktop, child, child, child, test, hwndMain );
405 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
406 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
407 check_parents( test, desktop, 0, 0, 0, test, test );
408 DestroyWindow( test );
410 /* normal child window */
411 test = create_tool_window( WS_CHILD, hwndMain );
412 trace( "created child %p\n", test );
414 ret = SetParent( test, desktop );
415 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
416 check_parents( test, desktop, 0, desktop, 0, test, desktop );
418 ret = SetParent( test, child );
419 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
420 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
422 ret = SetParent( test, hwndMain2 );
423 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
424 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
425 DestroyWindow( test );
427 /* not owned top-level window */
428 test = create_tool_window( 0, 0 );
429 trace( "created top-level %p\n", test );
431 ret = SetParent( test, child );
432 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
433 check_parents( test, child, child, 0, 0, hwndMain, test );
434 DestroyWindow( test );
436 /* owned popup */
437 test = create_tool_window( WS_POPUP, hwndMain2 );
438 trace( "created owned popup %p\n", test );
440 ret = SetParent( test, child );
441 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
442 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
444 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
445 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
446 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
447 DestroyWindow( test );
449 /**************** test owner destruction *******************/
451 /* owned child popup */
452 owner = create_tool_window( 0, 0 );
453 test = create_tool_window( WS_POPUP, owner );
454 trace( "created owner %p and popup %p\n", owner, test );
455 ret = SetParent( test, child );
456 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
457 check_parents( test, child, child, owner, owner, hwndMain, owner );
458 /* window is now child of 'child' but owned by 'owner' */
459 DestroyWindow( owner );
460 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
461 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
462 * while Win95, Win2k, WinXP do.
464 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
465 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
466 DestroyWindow(test);
468 /* owned top-level popup */
469 owner = create_tool_window( 0, 0 );
470 test = create_tool_window( WS_POPUP, owner );
471 trace( "created owner %p and popup %p\n", owner, test );
472 check_parents( test, desktop, owner, owner, owner, test, owner );
473 DestroyWindow( owner );
474 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
476 /* top-level popup owned by child */
477 owner = create_tool_window( WS_CHILD, hwndMain2 );
478 test = create_tool_window( WS_POPUP, 0 );
479 trace( "created owner %p and popup %p\n", owner, test );
480 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
481 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
482 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
483 DestroyWindow( owner );
484 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
485 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
486 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
487 * while Win95, Win2k, WinXP do.
489 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
490 DestroyWindow(test);
492 /* final cleanup */
493 DestroyWindow(child);
496 owner = create_tool_window( WS_OVERLAPPED, 0 );
497 test = create_tool_window( WS_POPUP, desktop );
499 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
500 numChildren = 0;
501 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
502 "EnumChildWindows should have returned FALSE\n" );
503 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
505 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
506 ret = SetParent( test, owner );
507 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
509 numChildren = 0;
510 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
511 "EnumChildWindows should have returned TRUE\n" );
512 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
514 child = create_tool_window( WS_CHILD, owner );
515 numChildren = 0;
516 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
517 "EnumChildWindows should have returned FALSE\n" );
518 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
519 DestroyWindow( child );
521 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
522 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
523 numChildren = 0;
524 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
525 "EnumChildWindows should have returned TRUE\n" );
526 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
528 ret = SetParent( child, owner );
529 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
530 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
531 numChildren = 0;
532 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
533 "EnumChildWindows should have returned FALSE\n" );
534 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
536 ret = SetParent( child, NULL );
537 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
538 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
539 numChildren = 0;
540 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
541 "EnumChildWindows should have returned TRUE\n" );
542 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
544 /* even GW_OWNER == owner it's still a desktop's child */
545 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
546 "EnumChildWindows should have found %p and returned FALSE\n", child );
548 DestroyWindow( child );
549 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
551 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
552 "EnumChildWindows should have found %p and returned FALSE\n", child );
554 DestroyWindow( child );
555 DestroyWindow( test );
556 DestroyWindow( owner );
560 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
562 switch (msg)
564 case WM_GETMINMAXINFO:
566 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
568 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
569 dump_minmax_info( minmax );
570 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
571 break;
573 case WM_WINDOWPOSCHANGING:
575 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
576 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
577 trace("main: WM_WINDOWPOSCHANGING\n");
578 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
579 winpos->hwnd, winpos->hwndInsertAfter,
580 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
581 if (!(winpos->flags & SWP_NOMOVE))
583 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
584 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
586 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
587 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
589 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
590 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
592 break;
594 case WM_WINDOWPOSCHANGED:
596 RECT rc1, rc2;
597 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
598 trace("main: WM_WINDOWPOSCHANGED\n");
599 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
600 winpos->hwnd, winpos->hwndInsertAfter,
601 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
602 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
603 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
605 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
606 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
608 GetWindowRect(hwnd, &rc1);
609 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
610 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
611 /* note: winpos coordinates are relative to parent */
612 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
613 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
614 if (0)
616 /* Uncomment this once the test succeeds in all cases */
617 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
620 GetClientRect(hwnd, &rc2);
621 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
622 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
623 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
624 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
625 break;
627 case WM_NCCREATE:
629 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
630 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
632 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
633 if (got_getminmaxinfo)
634 trace("%p got WM_GETMINMAXINFO\n", hwnd);
636 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
637 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
638 else
639 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
640 break;
642 case WM_COMMAND:
643 if (test_lbuttondown_flag)
645 ShowWindow((HWND)wparam, SW_SHOW);
646 flush_events( FALSE );
648 break;
651 return DefWindowProcA(hwnd, msg, wparam, lparam);
654 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
656 switch (msg)
658 case WM_GETMINMAXINFO:
660 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
662 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
663 dump_minmax_info( minmax );
664 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
665 break;
667 case WM_NCCREATE:
669 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
670 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
672 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
673 if (got_getminmaxinfo)
674 trace("%p got WM_GETMINMAXINFO\n", hwnd);
676 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
677 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
678 else
679 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
680 break;
684 return DefWindowProcA(hwnd, msg, wparam, lparam);
687 static BOOL RegisterWindowClasses(void)
689 WNDCLASSA cls;
691 cls.style = CS_DBLCLKS;
692 cls.lpfnWndProc = main_window_procA;
693 cls.cbClsExtra = 0;
694 cls.cbWndExtra = 0;
695 cls.hInstance = GetModuleHandleA(0);
696 cls.hIcon = 0;
697 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
698 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
699 cls.lpszMenuName = NULL;
700 cls.lpszClassName = "MainWindowClass";
702 if(!RegisterClassA(&cls)) return FALSE;
704 cls.style = 0;
705 cls.lpfnWndProc = tool_window_procA;
706 cls.cbClsExtra = 0;
707 cls.cbWndExtra = 0;
708 cls.hInstance = GetModuleHandleA(0);
709 cls.hIcon = 0;
710 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
711 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
712 cls.lpszMenuName = NULL;
713 cls.lpszClassName = "ToolWindowClass";
715 if(!RegisterClassA(&cls)) return FALSE;
717 return TRUE;
720 static void verify_window_info(HWND hwnd, const WINDOWINFO *info)
722 RECT rcWindow, rcClient;
723 DWORD status;
725 ok(IsWindow(hwnd), "bad window handle\n");
727 GetWindowRect(hwnd, &rcWindow);
728 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow\n");
730 GetClientRect(hwnd, &rcClient);
731 /* translate to screen coordinates */
732 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
733 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient\n");
735 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
736 "wrong dwStyle: %08x != %08x\n", info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE));
737 /* Windows reports some undocumented exstyles in WINDOWINFO, but
738 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
740 ok((info->dwExStyle & ~0xe0000800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
741 "wrong dwExStyle: %08x != %08x\n", info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE));
742 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
743 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x\n",
744 info->dwWindowStatus, status);
746 /* win2k and XP return broken border info in GetWindowInfo most of
747 * the time, so there is no point in testing it.
749 #if 0
750 UINT border;
751 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
752 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
753 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
754 ok(info->cyWindowBorders == border,
755 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
756 #endif
757 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType\n");
758 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
759 info->wCreatorVersion == 0x0500 /* Vista */,
760 "wrong wCreatorVersion %04x\n", info->wCreatorVersion);
763 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
765 AdjustWindowRectEx(rc, style, menu, exstyle);
766 /* AdjustWindowRectEx does not include scroll bars */
767 if (style & WS_VSCROLL)
769 if(exstyle & WS_EX_LEFTSCROLLBAR)
770 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
771 else
772 rc->right += GetSystemMetrics(SM_CXVSCROLL);
774 if (style & WS_HSCROLL)
775 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
778 static void test_nonclient_area(HWND hwnd)
780 DWORD style, exstyle;
781 RECT rc_window, rc_client, rc;
782 BOOL menu;
783 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
785 style = GetWindowLongA(hwnd, GWL_STYLE);
786 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
787 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
789 GetWindowRect(hwnd, &rc_window);
790 trace("window: (%d,%d)-(%d,%d)\n", rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
791 GetClientRect(hwnd, &rc_client);
792 trace("client: (%d,%d)-(%d,%d)\n", rc_client.left, rc_client.top, rc_client.right, rc_client.bottom);
794 /* avoid some cases when things go wrong */
795 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
796 rc_window.right > 32768 || rc_window.bottom > 32768) return;
798 CopyRect(&rc, &rc_client);
799 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
800 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
802 trace("calc window: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
803 ok(EqualRect(&rc, &rc_window), "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
806 CopyRect(&rc, &rc_window);
807 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
808 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
809 trace("calc client: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
810 ok(EqualRect(&rc, &rc_client), "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
812 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
813 if (is_win9x)
814 return;
816 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
817 SetRect(&rc_client, 0, 0, 250, 150);
818 CopyRect(&rc_window, &rc_client);
819 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
820 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
821 trace("calc window: (%d,%d)-(%d,%d)\n",
822 rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
824 CopyRect(&rc, &rc_window);
825 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
826 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
827 trace("calc client: (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
828 ok(EqualRect(&rc, &rc_client), "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style, exstyle, menu);
831 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
833 static const char *CBT_code_name[10] = {
834 "HCBT_MOVESIZE",
835 "HCBT_MINMAX",
836 "HCBT_QS",
837 "HCBT_CREATEWND",
838 "HCBT_DESTROYWND",
839 "HCBT_ACTIVATE",
840 "HCBT_CLICKSKIPPED",
841 "HCBT_KEYSKIPPED",
842 "HCBT_SYSCOMMAND",
843 "HCBT_SETFOCUS" };
844 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
846 trace("CBT: %d (%s), %08lx, %08lx\n", nCode, code_name, wParam, lParam);
848 /* on HCBT_DESTROYWND window state is undefined */
849 if (nCode != HCBT_DESTROYWND && IsWindow((HWND)wParam))
851 if (pGetWindowInfo)
853 WINDOWINFO info;
855 /* Win98 actually does check the info.cbSize and doesn't allow
856 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
857 * WinXP do not check it at all.
859 info.cbSize = sizeof(WINDOWINFO);
860 ok(pGetWindowInfo((HWND)wParam, &info), "GetWindowInfo should not fail\n");
861 verify_window_info((HWND)wParam, &info);
865 switch (nCode)
867 case HCBT_CREATEWND:
869 static const RECT rc_null;
870 RECT rc;
871 LONG style;
872 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
873 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
874 (HWND)wParam, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
875 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
877 /* WS_VISIBLE should be turned off yet */
878 style = createwnd->lpcs->style & ~WS_VISIBLE;
879 ok(style == GetWindowLongA((HWND)wParam, GWL_STYLE),
880 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
881 GetWindowLongA((HWND)wParam, GWL_STYLE), style);
883 if (0)
885 /* Uncomment this once the test succeeds in all cases */
886 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
888 ok(GetParent((HWND)wParam) == hwndMessage,
889 "wrong result from GetParent %p: message window %p\n",
890 GetParent((HWND)wParam), hwndMessage);
892 else
893 ok(!GetParent((HWND)wParam), "GetParent should return 0 at this point\n");
895 ok(!GetWindow((HWND)wParam, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
897 if (0)
899 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
900 * Win9x still has them set to 0.
902 ok(GetWindow((HWND)wParam, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
903 ok(GetWindow((HWND)wParam, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
905 ok(!GetWindow((HWND)wParam, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
906 ok(!GetWindow((HWND)wParam, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
908 if (0)
910 /* Uncomment this once the test succeeds in all cases */
911 if (pGetAncestor)
913 ok(pGetAncestor((HWND)wParam, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
914 ok(pGetAncestor((HWND)wParam, GA_ROOT) == (HWND)wParam,
915 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOT), (HWND)wParam);
917 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
918 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == hwndMessage,
919 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
920 else
921 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == (HWND)wParam,
922 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOTOWNER), (HWND)wParam);
925 ok(GetWindowRect((HWND)wParam, &rc), "GetWindowRect failed\n");
926 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
927 ok(GetClientRect((HWND)wParam, &rc), "GetClientRect failed\n");
928 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
930 break;
934 return CallNextHookEx(hhook, nCode, wParam, lParam);
937 static void test_shell_window(void)
939 BOOL ret;
940 DWORD error;
941 HMODULE hinst, hUser32;
942 BOOL (WINAPI*SetShellWindow)(HWND);
943 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
944 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
945 HWND shellWindow, nextWnd;
947 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
949 trace("Skipping shell window test on Win9x\n");
950 return;
953 shellWindow = GetShellWindow();
954 hinst = GetModuleHandle(0);
955 hUser32 = GetModuleHandleA("user32");
957 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
958 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
960 trace("previous shell window: %p\n", shellWindow);
962 if (shellWindow) {
963 DWORD pid;
964 HANDLE hProcess;
966 ret = DestroyWindow(shellWindow);
967 error = GetLastError();
969 ok(!ret, "DestroyWindow(shellWindow)\n");
970 /* passes on Win XP, but not on Win98 */
971 ok(error==ERROR_ACCESS_DENIED, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n");
973 /* close old shell instance */
974 GetWindowThreadProcessId(shellWindow, &pid);
975 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
976 ret = TerminateProcess(hProcess, 0);
977 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
978 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
979 CloseHandle(hProcess);
982 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
983 trace("created window 1: %p\n", hwnd1);
985 ret = SetShellWindow(hwnd1);
986 ok(ret, "first call to SetShellWindow(hwnd1)\n");
987 shellWindow = GetShellWindow();
988 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
990 ret = SetShellWindow(hwnd1);
991 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
993 ret = SetShellWindow(0);
994 error = GetLastError();
995 /* passes on Win XP, but not on Win98
996 ok(!ret, "reset shell window by SetShellWindow(0)\n");
997 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
999 ret = SetShellWindow(hwnd1);
1000 /* passes on Win XP, but not on Win98
1001 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1003 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1004 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
1005 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1007 ret = DestroyWindow(hwnd1);
1008 ok(ret, "DestroyWindow(hwnd1)\n");
1010 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1011 trace("created window 2: %p\n", hwnd2);
1012 ret = SetShellWindow(hwnd2);
1013 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1015 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1016 trace("created window 3: %p\n", hwnd3);
1018 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1019 trace("created window 4: %p\n", hwnd4);
1021 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1022 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1024 ret = SetShellWindow(hwnd4);
1025 ok(ret, "SetShellWindow(hwnd4)\n");
1026 shellWindow = GetShellWindow();
1027 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1029 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1030 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1032 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1033 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1035 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1036 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1038 ret = SetShellWindow(hwnd3);
1039 ok(!ret, "SetShellWindow(hwnd3)\n");
1040 shellWindow = GetShellWindow();
1041 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1043 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1044 trace("created window 5: %p\n", hwnd5);
1045 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1046 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1048 todo_wine
1050 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1051 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1054 /* destroy test windows */
1055 DestroyWindow(hwnd2);
1056 DestroyWindow(hwnd3);
1057 DestroyWindow(hwnd4);
1058 DestroyWindow(hwnd5);
1061 /************** MDI test ****************/
1063 static char mdi_lParam_test_message[] = "just a test string";
1065 static void test_MDI_create(HWND parent, HWND mdi_client, INT first_id)
1067 MDICREATESTRUCTA mdi_cs;
1068 HWND mdi_child;
1069 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1070 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1071 BOOL isWin9x = FALSE;
1073 mdi_cs.szClass = "MDI_child_Class_1";
1074 mdi_cs.szTitle = "MDI child";
1075 mdi_cs.hOwner = GetModuleHandle(0);
1076 mdi_cs.x = CW_USEDEFAULT;
1077 mdi_cs.y = CW_USEDEFAULT;
1078 mdi_cs.cx = CW_USEDEFAULT;
1079 mdi_cs.cy = CW_USEDEFAULT;
1080 mdi_cs.style = 0;
1081 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1082 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1083 ok(mdi_child != 0, "MDI child creation failed\n");
1084 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1085 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1086 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1088 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1089 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1090 ok(mdi_child != 0, "MDI child creation failed\n");
1091 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1092 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1093 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1095 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1096 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1097 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1099 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1101 else
1103 ok(mdi_child != 0, "MDI child creation failed\n");
1104 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1105 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1106 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1109 /* test MDICREATESTRUCT A<->W mapping */
1110 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1111 mdi_cs.style = 0;
1112 mdi_cs.szClass = (LPCSTR)classW;
1113 mdi_cs.szTitle = (LPCSTR)titleW;
1114 SetLastError(0xdeadbeef);
1115 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1116 if (!mdi_child)
1118 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1119 isWin9x = TRUE;
1120 else
1121 ok(mdi_child != 0, "MDI child creation failed\n");
1123 else
1125 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1126 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1127 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1130 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1132 CW_USEDEFAULT, CW_USEDEFAULT,
1133 CW_USEDEFAULT, CW_USEDEFAULT,
1134 mdi_client, GetModuleHandle(0),
1135 (LPARAM)mdi_lParam_test_message);
1136 ok(mdi_child != 0, "MDI child creation failed\n");
1137 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1138 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1139 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1141 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1142 0x7fffffff, /* without WS_POPUP */
1143 CW_USEDEFAULT, CW_USEDEFAULT,
1144 CW_USEDEFAULT, CW_USEDEFAULT,
1145 mdi_client, GetModuleHandle(0),
1146 (LPARAM)mdi_lParam_test_message);
1147 ok(mdi_child != 0, "MDI child creation failed\n");
1148 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1149 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1150 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1152 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1153 0xffffffff, /* with WS_POPUP */
1154 CW_USEDEFAULT, CW_USEDEFAULT,
1155 CW_USEDEFAULT, CW_USEDEFAULT,
1156 mdi_client, GetModuleHandle(0),
1157 (LPARAM)mdi_lParam_test_message);
1158 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1160 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1162 else
1164 ok(mdi_child != 0, "MDI child creation failed\n");
1165 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1166 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1167 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1170 /* test MDICREATESTRUCT A<->W mapping */
1171 SetLastError(0xdeadbeef);
1172 mdi_child = CreateMDIWindowW(classW, titleW,
1174 CW_USEDEFAULT, CW_USEDEFAULT,
1175 CW_USEDEFAULT, CW_USEDEFAULT,
1176 mdi_client, GetModuleHandle(0),
1177 (LPARAM)mdi_lParam_test_message);
1178 if (!mdi_child)
1180 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1181 isWin9x = TRUE;
1182 else
1183 ok(mdi_child != 0, "MDI child creation failed\n");
1185 else
1187 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1188 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1189 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1192 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1194 CW_USEDEFAULT, CW_USEDEFAULT,
1195 CW_USEDEFAULT, CW_USEDEFAULT,
1196 mdi_client, 0, GetModuleHandle(0),
1197 (LPVOID)mdi_lParam_test_message);
1198 ok(mdi_child != 0, "MDI child creation failed\n");
1199 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1200 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1201 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1203 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1204 0x7fffffff, /* without WS_POPUP */
1205 CW_USEDEFAULT, CW_USEDEFAULT,
1206 CW_USEDEFAULT, CW_USEDEFAULT,
1207 mdi_client, 0, GetModuleHandle(0),
1208 (LPVOID)mdi_lParam_test_message);
1209 ok(mdi_child != 0, "MDI child creation failed\n");
1210 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1211 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1212 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1214 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1215 0xffffffff, /* with WS_POPUP */
1216 CW_USEDEFAULT, CW_USEDEFAULT,
1217 CW_USEDEFAULT, CW_USEDEFAULT,
1218 mdi_client, 0, GetModuleHandle(0),
1219 (LPVOID)mdi_lParam_test_message);
1220 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1222 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1224 else
1226 ok(mdi_child != 0, "MDI child creation failed\n");
1227 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1228 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1229 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1232 /* test MDICREATESTRUCT A<->W mapping */
1233 SetLastError(0xdeadbeef);
1234 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1236 CW_USEDEFAULT, CW_USEDEFAULT,
1237 CW_USEDEFAULT, CW_USEDEFAULT,
1238 mdi_client, 0, GetModuleHandle(0),
1239 (LPVOID)mdi_lParam_test_message);
1240 if (!mdi_child)
1242 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1243 isWin9x = TRUE;
1244 else
1245 ok(mdi_child != 0, "MDI child creation failed\n");
1247 else
1249 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1250 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1251 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1254 /* This test fails on Win9x */
1255 if (!isWin9x)
1257 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1258 WS_CHILD,
1259 CW_USEDEFAULT, CW_USEDEFAULT,
1260 CW_USEDEFAULT, CW_USEDEFAULT,
1261 parent, 0, GetModuleHandle(0),
1262 (LPVOID)mdi_lParam_test_message);
1263 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1266 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1267 WS_CHILD, /* without WS_POPUP */
1268 CW_USEDEFAULT, CW_USEDEFAULT,
1269 CW_USEDEFAULT, CW_USEDEFAULT,
1270 mdi_client, 0, GetModuleHandle(0),
1271 (LPVOID)mdi_lParam_test_message);
1272 ok(mdi_child != 0, "MDI child creation failed\n");
1273 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1274 DestroyWindow(mdi_child);
1276 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1277 WS_CHILD | WS_POPUP, /* with 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 /* maximized child */
1287 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1288 WS_CHILD | WS_MAXIMIZE,
1289 CW_USEDEFAULT, CW_USEDEFAULT,
1290 CW_USEDEFAULT, CW_USEDEFAULT,
1291 mdi_client, 0, GetModuleHandle(0),
1292 (LPVOID)mdi_lParam_test_message);
1293 ok(mdi_child != 0, "MDI child creation failed\n");
1294 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1295 DestroyWindow(mdi_child);
1297 trace("Creating maximized child with a caption\n");
1298 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1299 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1300 CW_USEDEFAULT, CW_USEDEFAULT,
1301 CW_USEDEFAULT, CW_USEDEFAULT,
1302 mdi_client, 0, GetModuleHandle(0),
1303 (LPVOID)mdi_lParam_test_message);
1304 ok(mdi_child != 0, "MDI child creation failed\n");
1305 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1306 DestroyWindow(mdi_child);
1308 trace("Creating maximized child with a caption and a thick frame\n");
1309 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1310 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1311 CW_USEDEFAULT, CW_USEDEFAULT,
1312 CW_USEDEFAULT, CW_USEDEFAULT,
1313 mdi_client, 0, GetModuleHandle(0),
1314 (LPVOID)mdi_lParam_test_message);
1315 ok(mdi_child != 0, "MDI child creation failed\n");
1316 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1317 DestroyWindow(mdi_child);
1320 /**********************************************************************
1321 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1323 * Note: The rule here is that client rect of the maximized MDI child
1324 * is equal to the client rect of the MDI client window.
1326 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1328 RECT rect;
1330 GetClientRect( client, &rect );
1331 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1332 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1334 rect.right -= rect.left;
1335 rect.bottom -= rect.top;
1336 lpMinMax->ptMaxSize.x = rect.right;
1337 lpMinMax->ptMaxSize.y = rect.bottom;
1339 lpMinMax->ptMaxPosition.x = rect.left;
1340 lpMinMax->ptMaxPosition.y = rect.top;
1342 trace("max rect (%d,%d - %d, %d)\n",
1343 rect.left, rect.top, rect.right, rect.bottom);
1346 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1348 switch (msg)
1350 case WM_NCCREATE:
1351 case WM_CREATE:
1353 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1354 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs->lpCreateParams;
1356 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1357 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1359 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1360 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1361 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1362 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1363 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1365 /* MDICREATESTRUCT should have original values */
1366 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1367 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1368 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1369 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1370 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1371 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1373 /* CREATESTRUCT should have fixed values */
1374 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1375 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1377 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1378 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1379 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1381 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1383 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1385 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1386 ok(cs->style == style,
1387 "cs->style does not match (%08x)\n", cs->style);
1389 else
1391 LONG style = mdi_cs->style;
1392 style &= ~WS_POPUP;
1393 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1394 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1395 ok(cs->style == style,
1396 "cs->style does not match (%08x)\n", cs->style);
1398 break;
1401 case WM_GETMINMAXINFO:
1403 HWND client = GetParent(hwnd);
1404 RECT rc;
1405 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1406 MINMAXINFO my_minmax;
1407 LONG style, exstyle;
1409 style = GetWindowLongA(hwnd, GWL_STYLE);
1410 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1412 GetWindowRect(client, &rc);
1413 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1414 GetClientRect(client, &rc);
1415 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1416 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1417 GetSystemMetrics(SM_CYSCREEN));
1419 GetClientRect(client, &rc);
1420 if ((style & WS_CAPTION) == WS_CAPTION)
1421 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1422 AdjustWindowRectEx(&rc, style, 0, exstyle);
1423 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1424 dump_minmax_info( minmax );
1426 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1427 minmax->ptMaxSize.x, rc.right - rc.left);
1428 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1429 minmax->ptMaxSize.y, rc.bottom - rc.top);
1431 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1433 trace("DefMDIChildProc returned:\n");
1434 dump_minmax_info( minmax );
1436 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1437 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1438 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1439 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1440 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1442 return 1;
1445 case WM_MDIACTIVATE:
1447 HWND active, client = GetParent(hwnd);
1448 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1449 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1450 if (hwnd == (HWND)lparam) /* if we are being activated */
1451 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1452 else
1453 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1454 break;
1457 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1460 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1462 switch (msg)
1464 case WM_NCCREATE:
1465 case WM_CREATE:
1467 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1469 trace("%s\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE");
1470 trace("x %d, y %d, cx %d, cy %d\n", cs->x, cs->y, cs->cx, cs->cy);
1472 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1473 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1475 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1476 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1478 /* CREATESTRUCT should have fixed values */
1479 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1480 while NT does. */
1481 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1482 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1484 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1485 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1486 while Win95, Win2k, WinXP do. */
1487 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1488 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1489 break;
1492 case WM_GETMINMAXINFO:
1494 HWND parent = GetParent(hwnd);
1495 RECT rc;
1496 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1497 LONG style, exstyle;
1499 trace("WM_GETMINMAXINFO\n");
1501 style = GetWindowLongA(hwnd, GWL_STYLE);
1502 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1504 GetClientRect(parent, &rc);
1505 trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1507 GetClientRect(parent, &rc);
1508 if ((style & WS_CAPTION) == WS_CAPTION)
1509 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1510 AdjustWindowRectEx(&rc, style, 0, exstyle);
1511 trace("calculated max child window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1512 dump_minmax_info( minmax );
1514 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1515 minmax->ptMaxSize.x, rc.right - rc.left);
1516 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1517 minmax->ptMaxSize.y, rc.bottom - rc.top);
1518 break;
1521 case WM_WINDOWPOSCHANGED:
1523 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1524 RECT rc1, rc2;
1526 GetWindowRect(hwnd, &rc1);
1527 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1528 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1529 /* note: winpos coordinates are relative to parent */
1530 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1531 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1532 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1534 GetWindowRect(hwnd, &rc1);
1535 GetClientRect(hwnd, &rc2);
1536 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1537 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1538 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1540 /* fall through */
1541 case WM_WINDOWPOSCHANGING:
1543 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1544 WINDOWPOS my_winpos = *winpos;
1546 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1547 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1548 winpos->hwnd, winpos->hwndInsertAfter,
1549 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1551 DefWindowProcA(hwnd, msg, wparam, lparam);
1553 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1554 winpos->hwnd, winpos->hwndInsertAfter,
1555 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1557 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1558 "DefWindowProc should not change WINDOWPOS values\n");
1560 return 1;
1563 return DefWindowProcA(hwnd, msg, wparam, lparam);
1566 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1568 static HWND mdi_client;
1570 switch (msg)
1572 case WM_CREATE:
1574 CLIENTCREATESTRUCT client_cs;
1575 RECT rc;
1577 GetClientRect(hwnd, &rc);
1579 client_cs.hWindowMenu = 0;
1580 client_cs.idFirstChild = 1;
1582 /* MDIClient without MDIS_ALLCHILDSTYLES */
1583 mdi_client = CreateWindowExA(0, "mdiclient",
1584 NULL,
1585 WS_CHILD /*| WS_VISIBLE*/,
1586 /* tests depend on a not zero MDIClient size */
1587 0, 0, rc.right, rc.bottom,
1588 hwnd, 0, GetModuleHandle(0),
1589 (LPVOID)&client_cs);
1590 assert(mdi_client);
1591 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1592 DestroyWindow(mdi_client);
1594 /* MDIClient with MDIS_ALLCHILDSTYLES */
1595 mdi_client = CreateWindowExA(0, "mdiclient",
1596 NULL,
1597 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1598 /* tests depend on a not zero MDIClient size */
1599 0, 0, rc.right, rc.bottom,
1600 hwnd, 0, GetModuleHandle(0),
1601 (LPVOID)&client_cs);
1602 assert(mdi_client);
1603 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1604 DestroyWindow(mdi_client);
1605 break;
1608 case WM_WINDOWPOSCHANGED:
1610 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1611 RECT rc1, rc2;
1613 GetWindowRect(hwnd, &rc1);
1614 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1615 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1616 /* note: winpos coordinates are relative to parent */
1617 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1618 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1619 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1621 GetWindowRect(hwnd, &rc1);
1622 GetClientRect(hwnd, &rc2);
1623 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1624 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1625 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1627 /* fall through */
1628 case WM_WINDOWPOSCHANGING:
1630 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1631 WINDOWPOS my_winpos = *winpos;
1633 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1634 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1635 winpos->hwnd, winpos->hwndInsertAfter,
1636 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1638 DefWindowProcA(hwnd, msg, wparam, lparam);
1640 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1641 winpos->hwnd, winpos->hwndInsertAfter,
1642 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1644 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1645 "DefWindowProc should not change WINDOWPOS values\n");
1647 return 1;
1650 case WM_CLOSE:
1651 PostQuitMessage(0);
1652 break;
1654 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1657 static BOOL mdi_RegisterWindowClasses(void)
1659 WNDCLASSA cls;
1661 cls.style = 0;
1662 cls.lpfnWndProc = mdi_main_wnd_procA;
1663 cls.cbClsExtra = 0;
1664 cls.cbWndExtra = 0;
1665 cls.hInstance = GetModuleHandleA(0);
1666 cls.hIcon = 0;
1667 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1668 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1669 cls.lpszMenuName = NULL;
1670 cls.lpszClassName = "MDI_parent_Class";
1671 if(!RegisterClassA(&cls)) return FALSE;
1673 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1674 cls.lpszClassName = "MDI_child_Class_1";
1675 if(!RegisterClassA(&cls)) return FALSE;
1677 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1678 cls.lpszClassName = "MDI_child_Class_2";
1679 if(!RegisterClassA(&cls)) return FALSE;
1681 return TRUE;
1684 static void test_mdi(void)
1686 HWND mdi_hwndMain;
1687 /*MSG msg;*/
1689 if (!mdi_RegisterWindowClasses()) assert(0);
1691 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1692 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1693 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1694 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1695 GetDesktopWindow(), 0,
1696 GetModuleHandle(0), NULL);
1697 assert(mdi_hwndMain);
1699 while(GetMessage(&msg, 0, 0, 0))
1701 TranslateMessage(&msg);
1702 DispatchMessage(&msg);
1705 DestroyWindow(mdi_hwndMain);
1708 static void test_icons(void)
1710 WNDCLASSEXA cls;
1711 HWND hwnd;
1712 HICON icon = LoadIconA(0, (LPSTR)IDI_APPLICATION);
1713 HICON icon2 = LoadIconA(0, (LPSTR)IDI_QUESTION);
1714 HICON small_icon = LoadImageA(0, (LPSTR)IDI_APPLICATION, IMAGE_ICON,
1715 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1716 HICON res;
1718 cls.cbSize = sizeof(cls);
1719 cls.style = 0;
1720 cls.lpfnWndProc = DefWindowProcA;
1721 cls.cbClsExtra = 0;
1722 cls.cbWndExtra = 0;
1723 cls.hInstance = 0;
1724 cls.hIcon = LoadIconA(0, (LPSTR)IDI_HAND);
1725 cls.hIconSm = small_icon;
1726 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1727 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1728 cls.lpszMenuName = NULL;
1729 cls.lpszClassName = "IconWindowClass";
1731 RegisterClassExA(&cls);
1733 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1734 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1735 assert( hwnd );
1737 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1738 ok( res == 0, "wrong big icon %p/0\n", res );
1739 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1740 ok( res == 0, "wrong previous big icon %p/0\n", res );
1741 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1742 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1743 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1744 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1745 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1746 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1748 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1749 ok( res == 0, "wrong small icon %p/0\n", res );
1750 /* this test is XP specific */
1751 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1752 ok( res != 0, "wrong small icon %p\n", res );*/
1753 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1754 ok( res == 0, "wrong previous small icon %p/0\n", res );
1755 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1756 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1757 /* this test is XP specific */
1758 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1759 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1760 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1761 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1762 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1763 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1764 /* this test is XP specific */
1765 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1766 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1768 /* make sure the big icon hasn't changed */
1769 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1770 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1772 DestroyWindow( hwnd );
1775 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1777 if (msg == WM_NCCALCSIZE)
1779 RECT *rect = (RECT *)lparam;
1780 /* first time around increase the rectangle, next time decrease it */
1781 if (rect->left == 100) InflateRect( rect, 10, 10 );
1782 else InflateRect( rect, -10, -10 );
1783 return 0;
1785 return DefWindowProc( hwnd, msg, wparam, lparam );
1788 static void test_SetWindowPos(HWND hwnd)
1790 RECT orig_win_rc, rect;
1791 LONG_PTR old_proc;
1792 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1794 SetRect(&rect, 111, 222, 333, 444);
1795 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1796 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1797 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1799 SetRect(&rect, 111, 222, 333, 444);
1800 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1801 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1802 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1804 GetWindowRect(hwnd, &orig_win_rc);
1806 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1807 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1808 GetWindowRect( hwnd, &rect );
1809 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1810 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1811 GetClientRect( hwnd, &rect );
1812 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1813 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1814 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1816 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1817 GetWindowRect( hwnd, &rect );
1818 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1819 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1820 GetClientRect( hwnd, &rect );
1821 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1822 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1823 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1825 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1826 orig_win_rc.right, orig_win_rc.bottom, 0);
1827 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1829 /* Win9x truncates coordinates to 16-bit irrespectively */
1830 if (!is_win9x)
1832 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1833 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1835 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1836 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1839 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1840 orig_win_rc.right, orig_win_rc.bottom, 0);
1842 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1843 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1844 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1845 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1846 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1847 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1848 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1851 static void test_SetMenu(HWND parent)
1853 HWND child;
1854 HMENU hMenu, ret;
1855 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1856 BOOL retok;
1857 DWORD style;
1859 hMenu = CreateMenu();
1860 assert(hMenu);
1862 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1863 if (0)
1865 /* fails on (at least) Wine, NT4, XP SP2 */
1866 test_nonclient_area(parent);
1868 ret = GetMenu(parent);
1869 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1870 /* test whether we can destroy a menu assigned to a window */
1871 retok = DestroyMenu(hMenu);
1872 ok( retok, "DestroyMenu error %d\n", GetLastError());
1873 ok(!IsMenu(hMenu), "menu handle should be not valid after DestroyMenu\n");
1874 ret = GetMenu(parent);
1875 /* This test fails on Win9x */
1876 if (!is_win9x)
1877 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1878 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1879 test_nonclient_area(parent);
1881 hMenu = CreateMenu();
1882 assert(hMenu);
1884 /* parent */
1885 ret = GetMenu(parent);
1886 ok(ret == 0, "unexpected menu id %p\n", ret);
1888 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1889 test_nonclient_area(parent);
1890 ret = GetMenu(parent);
1891 ok(ret == 0, "unexpected menu id %p\n", ret);
1893 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1894 if (0)
1896 /* fails on (at least) Wine, NT4, XP SP2 */
1897 test_nonclient_area(parent);
1899 ret = GetMenu(parent);
1900 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1902 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1903 test_nonclient_area(parent);
1904 ret = GetMenu(parent);
1905 ok(ret == 0, "unexpected menu id %p\n", ret);
1907 /* child */
1908 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1909 assert(child);
1911 ret = GetMenu(child);
1912 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1914 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1915 test_nonclient_area(child);
1916 ret = GetMenu(child);
1917 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1919 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1920 test_nonclient_area(child);
1921 ret = GetMenu(child);
1922 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1924 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1925 test_nonclient_area(child);
1926 ret = GetMenu(child);
1927 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1929 style = GetWindowLong(child, GWL_STYLE);
1930 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
1931 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
1932 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
1933 SetWindowLong(child, GWL_STYLE, style);
1935 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
1936 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
1937 SetWindowLong(child, GWL_STYLE, style);
1939 DestroyWindow(child);
1940 DestroyMenu(hMenu);
1943 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1945 HWND child[5], hwnd;
1946 int i;
1948 assert(total <= 5);
1950 hwnd = GetWindow(parent, GW_CHILD);
1951 ok(!hwnd, "have to start without children to perform the test\n");
1953 for (i = 0; i < total; i++)
1955 if (style[i] & DS_CONTROL)
1957 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
1958 0,0,0,0, parent, (HMENU)i, 0, NULL);
1959 if (style[i] & WS_VISIBLE)
1960 ShowWindow(child[i], SW_SHOW);
1962 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
1964 else
1965 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
1966 parent, (HMENU)i, 0, NULL);
1967 trace("child[%d] = %p\n", i, child[i]);
1968 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
1971 hwnd = GetWindow(parent, GW_CHILD);
1972 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
1973 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
1974 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
1976 for (i = 0; i < total; i++)
1978 trace("hwnd[%d] = %p\n", i, hwnd);
1979 ok(child[order[i]] == hwnd, "Z order of child #%d is wrong\n", i);
1981 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1984 for (i = 0; i < total; i++)
1985 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
1988 static void test_children_zorder(HWND parent)
1990 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
1991 WS_CHILD };
1992 const int simple_order[5] = { 0, 1, 2, 3, 4 };
1994 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
1995 WS_CHILD | WS_VISIBLE, WS_CHILD,
1996 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
1997 const int complex_order_1[1] = { 0 };
1998 const int complex_order_2[2] = { 1, 0 };
1999 const int complex_order_3[3] = { 1, 0, 2 };
2000 const int complex_order_4[4] = { 1, 0, 2, 3 };
2001 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2002 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2003 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2004 WS_CHILD | WS_VISIBLE };
2005 const int complex_order_6[3] = { 0, 1, 2 };
2007 /* simple WS_CHILD */
2008 test_window_tree(parent, simple_style, simple_order, 5);
2010 /* complex children styles */
2011 test_window_tree(parent, complex_style, complex_order_1, 1);
2012 test_window_tree(parent, complex_style, complex_order_2, 2);
2013 test_window_tree(parent, complex_style, complex_order_3, 3);
2014 test_window_tree(parent, complex_style, complex_order_4, 4);
2015 test_window_tree(parent, complex_style, complex_order_5, 5);
2017 /* another set of complex children styles */
2018 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2021 #define check_z_order(hwnd, next, prev, owner, topmost) \
2022 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2023 __FILE__, __LINE__)
2025 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2026 BOOL topmost, const char *file, int line)
2028 HWND test;
2029 DWORD ex_style;
2031 test = GetWindow(hwnd, GW_HWNDNEXT);
2032 /* skip foreign windows */
2033 while (test && (GetWindowThreadProcessId(test, NULL) != our_pid ||
2034 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0)))
2036 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2037 test = GetWindow(test, GW_HWNDNEXT);
2039 ok_(file, line)(next == test, "expected next %p, got %p\n", next, test);
2041 test = GetWindow(hwnd, GW_HWNDPREV);
2042 /* skip foreign windows */
2043 while (test && (GetWindowThreadProcessId(test, NULL) != our_pid ||
2044 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0)))
2046 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2047 test = GetWindow(test, GW_HWNDPREV);
2049 ok_(file, line)(prev == test, "expected prev %p, got %p\n", prev, test);
2051 test = GetWindow(hwnd, GW_OWNER);
2052 ok_(file, line)(owner == test, "expected owner %p, got %p\n", owner, test);
2054 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2055 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "expected %stopmost\n", topmost ? "" : "NOT ");
2058 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E)
2060 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2062 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2064 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2066 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2067 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2069 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2070 WS_OVERLAPPED | WS_CAPTION,
2071 100, 100, 100, 100,
2072 0, 0, GetModuleHandle(0), NULL);
2073 trace("hwnd_F %p\n", hwnd_F);
2074 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2076 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2077 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2078 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2079 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2081 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2082 WS_POPUP,
2083 100, 100, 100, 100,
2084 hwnd_F, 0, GetModuleHandle(0), NULL);
2085 trace("hwnd_C %p\n", hwnd_C);
2086 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2087 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2088 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2089 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2091 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2092 WS_POPUP,
2093 100, 100, 100, 100,
2094 hwnd_F, 0, GetModuleHandle(0), NULL);
2095 trace("hwnd_B %p\n", hwnd_B);
2096 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2097 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2098 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2099 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2100 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2102 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2103 WS_POPUP,
2104 100, 100, 100, 100,
2105 0, 0, GetModuleHandle(0), NULL);
2106 trace("hwnd_A %p\n", hwnd_A);
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, hwnd_A, hwnd_F, TRUE);
2112 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2114 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);
2116 /* move hwnd_F and its popups up */
2117 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2118 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2119 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2120 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2121 check_z_order(hwnd_C, hwnd_F, 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 /* move hwnd_F and its popups down */
2126 #if 0 /* enable once Wine is fixed to pass this test */
2127 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2128 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2129 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2130 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2131 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2132 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2133 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2134 #endif
2136 DestroyWindow(hwnd_A);
2137 DestroyWindow(hwnd_B);
2138 DestroyWindow(hwnd_C);
2139 DestroyWindow(hwnd_F);
2142 static void test_vis_rgn( HWND hwnd )
2144 RECT win_rect, rgn_rect;
2145 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2146 HDC hdc;
2148 ShowWindow(hwnd,SW_SHOW);
2149 hdc = GetDC( hwnd );
2150 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2151 GetWindowRect( hwnd, &win_rect );
2152 GetRgnBox( hrgn, &rgn_rect );
2153 if (GetVersion() & 0x80000000)
2155 trace("win9x, mapping to screen coords\n");
2156 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2158 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2159 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2160 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2161 rgn_rect.left, win_rect.left );
2162 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2163 rgn_rect.top, win_rect.top );
2164 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2165 rgn_rect.right, win_rect.right );
2166 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2167 rgn_rect.bottom, win_rect.bottom );
2168 ReleaseDC( hwnd, hdc );
2171 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2173 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2175 HWND child = GetWindow(hwnd, GW_CHILD);
2176 ok(child != 0, "couldn't find child window\n");
2177 SetFocus(child);
2178 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2179 return 0;
2181 return DefWindowProc(hwnd, msg, wp, lp);
2184 static void test_SetFocus(HWND hwnd)
2186 HWND child;
2187 WNDPROC old_wnd_proc;
2189 /* check if we can set focus to non-visible windows */
2191 ShowWindow(hwnd, SW_SHOW);
2192 SetFocus(0);
2193 SetFocus(hwnd);
2194 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2195 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2196 ShowWindow(hwnd, SW_HIDE);
2197 SetFocus(0);
2198 SetFocus(hwnd);
2199 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2200 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2201 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2202 assert(child);
2203 SetFocus(child);
2204 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2205 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2206 ShowWindow(child, SW_SHOW);
2207 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2208 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2209 ShowWindow(child, SW_HIDE);
2210 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2211 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2212 ShowWindow(child, SW_SHOW);
2213 SetFocus(child);
2214 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2215 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2216 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2218 ShowWindow(child, SW_HIDE);
2219 SetFocus(hwnd);
2220 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2221 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2222 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2223 ShowWindow(child, SW_HIDE);
2224 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2226 ShowWindow(hwnd, SW_SHOW);
2227 ShowWindow(child, SW_SHOW);
2228 SetFocus(child);
2229 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2230 EnableWindow(hwnd, FALSE);
2231 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2232 EnableWindow(hwnd, TRUE);
2234 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2235 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2236 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2237 todo_wine
2238 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2239 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2240 ShowWindow(hwnd, SW_RESTORE);
2241 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2242 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2243 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2244 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2245 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2246 todo_wine
2247 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2248 old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2249 ShowWindow(hwnd, SW_RESTORE);
2250 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2251 todo_wine
2252 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2254 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2256 DestroyWindow( child );
2259 static void check_wnd_state(HWND active, HWND foreground, HWND focus, HWND capture)
2261 ok(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2262 if (foreground)
2263 ok(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2264 ok(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2265 ok(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2268 static void test_SetActiveWindow(HWND hwnd)
2270 HWND hwnd2;
2272 flush_events( TRUE );
2273 ShowWindow(hwnd, SW_HIDE);
2274 SetFocus(0);
2275 SetActiveWindow(0);
2276 check_wnd_state(0, 0, 0, 0);
2278 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2280 ShowWindow(hwnd, SW_SHOW);
2281 check_wnd_state(hwnd, hwnd, hwnd, 0);
2283 hwnd2 = SetActiveWindow(0);
2284 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2285 check_wnd_state(0, 0, 0, 0);
2287 hwnd2 = SetActiveWindow(hwnd);
2288 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2289 check_wnd_state(hwnd, hwnd, hwnd, 0);
2291 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2292 check_wnd_state(hwnd, hwnd, hwnd, 0);
2294 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2295 check_wnd_state(hwnd, hwnd, hwnd, 0);
2297 ShowWindow(hwnd, SW_HIDE);
2298 check_wnd_state(0, 0, 0, 0);
2300 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2301 SetActiveWindow(hwnd);
2302 check_wnd_state(hwnd, hwnd, hwnd, 0);
2304 ShowWindow(hwnd, SW_SHOW);
2305 check_wnd_state(hwnd, hwnd, hwnd, 0);
2307 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2308 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2310 DestroyWindow(hwnd2);
2311 check_wnd_state(hwnd, hwnd, hwnd, 0);
2313 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2314 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2316 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2317 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2319 DestroyWindow(hwnd2);
2320 check_wnd_state(hwnd, hwnd, hwnd, 0);
2323 static void test_SetForegroundWindow(HWND hwnd)
2325 BOOL ret;
2326 HWND hwnd2;
2328 flush_events( TRUE );
2329 ShowWindow(hwnd, SW_HIDE);
2330 SetFocus(0);
2331 SetActiveWindow(0);
2332 check_wnd_state(0, 0, 0, 0);
2334 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2336 ShowWindow(hwnd, SW_SHOW);
2337 check_wnd_state(hwnd, hwnd, hwnd, 0);
2339 hwnd2 = SetActiveWindow(0);
2340 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2341 check_wnd_state(0, 0, 0, 0);
2343 ret = SetForegroundWindow(hwnd);
2344 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2345 check_wnd_state(hwnd, hwnd, hwnd, 0);
2347 SetLastError(0xdeadbeef);
2348 ret = SetForegroundWindow(0);
2349 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2350 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2351 check_wnd_state(hwnd, hwnd, hwnd, 0);
2353 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2354 check_wnd_state(hwnd, hwnd, hwnd, 0);
2356 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2357 check_wnd_state(hwnd, hwnd, hwnd, 0);
2359 hwnd2 = GetForegroundWindow();
2360 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2361 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2362 hwnd2 = GetForegroundWindow();
2363 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2365 ShowWindow(hwnd, SW_HIDE);
2366 check_wnd_state(0, 0, 0, 0);
2368 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2369 ret = SetForegroundWindow(hwnd);
2370 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2371 check_wnd_state(hwnd, hwnd, hwnd, 0);
2373 ShowWindow(hwnd, SW_SHOW);
2374 check_wnd_state(hwnd, hwnd, hwnd, 0);
2376 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2377 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2379 DestroyWindow(hwnd2);
2380 check_wnd_state(hwnd, hwnd, hwnd, 0);
2382 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2383 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2385 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2386 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2388 DestroyWindow(hwnd2);
2389 check_wnd_state(hwnd, hwnd, hwnd, 0);
2392 static WNDPROC old_button_proc;
2394 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2396 LRESULT ret;
2397 USHORT key_state;
2399 key_state = GetKeyState(VK_LBUTTON);
2400 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2402 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2404 if (msg == WM_LBUTTONDOWN)
2406 HWND hwnd, capture;
2408 check_wnd_state(button, button, button, button);
2410 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2411 assert(hwnd);
2412 trace("hwnd %p\n", hwnd);
2414 check_wnd_state(button, button, button, button);
2416 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2418 check_wnd_state(button, button, button, button);
2420 DestroyWindow(hwnd);
2422 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2423 assert(hwnd);
2424 trace("hwnd %p\n", hwnd);
2426 check_wnd_state(button, button, button, button);
2428 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2429 * match internal button state.
2431 SendMessage(button, WM_KILLFOCUS, 0, 0);
2432 check_wnd_state(button, button, button, 0);
2434 ShowWindow(hwnd, SW_SHOW);
2435 check_wnd_state(hwnd, hwnd, hwnd, 0);
2437 capture = SetCapture(hwnd);
2438 ok(capture == 0, "SetCapture() = %p\n", capture);
2440 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2442 DestroyWindow(hwnd);
2444 check_wnd_state(button, 0, button, 0);
2447 return ret;
2450 static void test_capture_1(void)
2452 HWND button, capture;
2454 capture = GetCapture();
2455 ok(capture == 0, "GetCapture() = %p\n", capture);
2457 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2458 assert(button);
2459 trace("button %p\n", button);
2461 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2463 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2465 capture = SetCapture(button);
2466 ok(capture == 0, "SetCapture() = %p\n", capture);
2467 check_wnd_state(button, 0, button, button);
2469 DestroyWindow(button);
2470 check_wnd_state(0, 0, 0, 0);
2473 static void test_capture_2(void)
2475 HWND button, hwnd, capture;
2477 check_wnd_state(0, 0, 0, 0);
2479 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2480 assert(button);
2481 trace("button %p\n", button);
2483 check_wnd_state(button, button, button, 0);
2485 capture = SetCapture(button);
2486 ok(capture == 0, "SetCapture() = %p\n", capture);
2488 check_wnd_state(button, button, button, button);
2490 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2491 * internal button state.
2493 SendMessage(button, WM_KILLFOCUS, 0, 0);
2494 check_wnd_state(button, button, button, button);
2496 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2497 assert(hwnd);
2498 trace("hwnd %p\n", hwnd);
2500 check_wnd_state(button, button, button, button);
2502 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2504 check_wnd_state(button, button, button, button);
2506 DestroyWindow(hwnd);
2508 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2509 assert(hwnd);
2510 trace("hwnd %p\n", hwnd);
2512 check_wnd_state(button, button, button, button);
2514 ShowWindow(hwnd, SW_SHOW);
2516 check_wnd_state(hwnd, hwnd, hwnd, button);
2518 capture = SetCapture(hwnd);
2519 ok(capture == button, "SetCapture() = %p\n", capture);
2521 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2523 DestroyWindow(hwnd);
2524 check_wnd_state(button, button, button, 0);
2526 DestroyWindow(button);
2527 check_wnd_state(0, 0, 0, 0);
2530 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2532 BOOL ret;
2534 ShowWindow(hwnd1, SW_HIDE);
2535 ShowWindow(hwnd2, SW_HIDE);
2537 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2538 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2540 SetCapture(hwnd1);
2541 check_wnd_state(0, 0, 0, hwnd1);
2543 SetCapture(hwnd2);
2544 check_wnd_state(0, 0, 0, hwnd2);
2546 ShowWindow(hwnd1, SW_SHOW);
2547 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2549 ret = ReleaseCapture();
2550 ok (ret, "releasecapture did not return TRUE.\n");
2551 ret = ReleaseCapture();
2552 ok (ret, "releasecapture did not return TRUE after second try.\n");
2555 static void test_keyboard_input(HWND hwnd)
2557 MSG msg;
2558 BOOL ret;
2560 flush_events( TRUE );
2561 ShowWindow(hwnd, SW_SHOW);
2562 UpdateWindow(hwnd);
2563 flush_events( TRUE );
2565 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2567 SetFocus(hwnd);
2568 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2570 flush_events( TRUE );
2572 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2573 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2574 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2575 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2576 ok( !ret, "message %04x available\n", msg.message);
2578 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2580 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2581 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2582 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2583 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2584 ok( !ret, "message %04x available\n", msg.message);
2586 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2588 keybd_event(VK_SPACE, 0, 0, 0);
2589 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2590 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2591 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2592 ok( !ret, "message %04x available\n", msg.message);
2594 SetFocus(0);
2595 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2597 flush_events( TRUE );
2599 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2600 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2601 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2602 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2603 ok( !ret, "message %04x available\n", msg.message);
2605 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2607 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2608 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2609 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2610 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2611 ok( !ret, "message %04x available\n", msg.message);
2613 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2615 keybd_event(VK_SPACE, 0, 0, 0);
2616 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2617 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2618 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2619 ok( !ret, "message %04x available\n", msg.message);
2622 static void test_mouse_input(HWND hwnd)
2624 RECT rc;
2625 POINT pt;
2626 int x, y;
2627 HWND popup;
2628 MSG msg;
2629 BOOL ret;
2630 LRESULT res;
2632 ShowWindow(hwnd, SW_SHOW);
2633 UpdateWindow(hwnd);
2635 GetWindowRect(hwnd, &rc);
2636 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2638 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2639 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2640 hwnd, 0, 0, NULL);
2641 assert(popup != 0);
2642 ShowWindow(popup, SW_SHOW);
2643 UpdateWindow(popup);
2645 GetWindowRect(popup, &rc);
2646 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2648 x = rc.left + (rc.right - rc.left) / 2;
2649 y = rc.top + (rc.bottom - rc.top) / 2;
2650 trace("setting cursor to (%d,%d)\n", x, y);
2652 SetCursorPos(x, y);
2653 GetCursorPos(&pt);
2654 ok(x == pt.x && y == pt.y, "wrong cursor pos (%d,%d), expected (%d,%d)\n", pt.x, pt.y, x, y);
2656 flush_events( TRUE );
2658 /* Check that setting the same position will generate WM_MOUSEMOVE */
2659 SetCursorPos(x, y);
2660 msg.message = 0;
2661 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2662 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2663 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n", x, y, msg.pt.x, msg.pt.y);
2665 /* force the system to update its internal queue mouse position,
2666 * otherwise it won't generate relative mouse movements below.
2668 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2669 flush_events( TRUE );
2671 msg.message = 0;
2672 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2673 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2674 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2675 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2676 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2677 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2678 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2679 ok( !ret, "message %04x available\n", msg.message);
2681 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2682 ShowWindow(popup, SW_HIDE);
2683 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2684 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2685 flush_events( TRUE );
2687 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2688 ShowWindow(hwnd, SW_HIDE);
2689 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2690 ok( !ret, "message %04x available\n", msg.message);
2691 flush_events( TRUE );
2693 /* test mouse clicks */
2695 ShowWindow(hwnd, SW_SHOW);
2696 flush_events( TRUE );
2697 ShowWindow(popup, SW_SHOW);
2698 flush_events( TRUE );
2700 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2701 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2702 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2703 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2705 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2706 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2707 msg.hwnd, popup, msg.message);
2708 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2709 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2710 msg.hwnd, popup, msg.message);
2712 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2713 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2714 msg.hwnd, popup, msg.message);
2715 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2716 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2717 msg.hwnd, popup, msg.message);
2719 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2720 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
2721 msg.hwnd, popup, msg.message);
2722 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2723 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
2724 msg.hwnd, popup, msg.message);
2726 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2727 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2728 msg.hwnd, popup, msg.message);
2729 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2730 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2731 msg.hwnd, popup, msg.message);
2733 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2734 ok(!ret, "message %04x available\n", msg.message);
2736 ShowWindow(popup, SW_HIDE);
2737 flush_events( TRUE );
2739 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2740 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2741 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2742 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2744 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2745 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2746 msg.hwnd, hwnd, msg.message);
2747 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2748 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2749 msg.hwnd, hwnd, msg.message);
2751 test_lbuttondown_flag = TRUE;
2752 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
2753 test_lbuttondown_flag = FALSE;
2755 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2756 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2757 msg.hwnd, popup, msg.message);
2758 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2759 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2760 msg.hwnd, popup, msg.message);
2761 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2763 /* Test WM_MOUSEACTIVATE */
2764 #define TEST_MOUSEACTIVATE(A,B) \
2765 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2766 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2768 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
2769 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
2770 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
2771 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
2772 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
2773 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
2774 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
2775 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
2776 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
2777 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
2778 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
2779 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
2780 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
2781 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
2782 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
2783 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
2784 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
2785 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
2786 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
2787 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
2788 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
2789 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
2790 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
2791 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
2793 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2794 flush_events( TRUE );
2796 DestroyWindow(popup);
2799 static void test_validatergn(HWND hwnd)
2801 HWND child;
2802 RECT rc, rc2;
2803 HRGN rgn;
2804 int ret;
2805 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
2806 ShowWindow(hwnd, SW_SHOW);
2807 UpdateWindow( hwnd);
2808 /* test that ValidateRect validates children*/
2809 InvalidateRect( child, NULL, 1);
2810 GetWindowRect( child, &rc);
2811 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2812 ret = GetUpdateRect( child, &rc2, 0);
2813 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
2814 "Update rectangle is empty!\n");
2815 ValidateRect( hwnd, &rc);
2816 ret = GetUpdateRect( child, &rc2, 0);
2817 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2818 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2819 rc2.right, rc2.bottom);
2821 /* now test ValidateRgn */
2822 InvalidateRect( child, NULL, 1);
2823 GetWindowRect( child, &rc);
2824 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2825 rgn = CreateRectRgnIndirect( &rc);
2826 ValidateRgn( hwnd, rgn);
2827 ret = GetUpdateRect( child, &rc2, 0);
2828 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2829 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2830 rc2.right, rc2.bottom);
2832 DeleteObject( rgn);
2833 DestroyWindow( child );
2836 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
2838 MoveWindow( hwnd, 0, 0, x, y, 0);
2839 GetWindowRect( hwnd, prc);
2840 trace("window rect is %d,%d - %d,%d\n",
2841 prc->left,prc->top,prc->right,prc->bottom);
2842 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
2843 trace("nccalc rect is %d,%d - %d,%d\n",
2844 prc->left,prc->top,prc->right,prc->bottom);
2847 static void test_nccalcscroll(HWND parent)
2849 RECT rc1;
2850 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
2851 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
2852 HWND hwnd = CreateWindowExA(0, "static", NULL,
2853 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
2854 10, 10, 200, 200, parent, 0, 0, NULL);
2855 ShowWindow( parent, SW_SHOW);
2856 UpdateWindow( parent);
2858 /* test window too low for a horizontal scroll bar */
2859 nccalchelper( hwnd, 100, sbheight, &rc1);
2860 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
2861 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
2863 /* test window just high enough for a horizontal scroll bar */
2864 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
2865 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
2866 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2868 /* test window too narrow for a vertical scroll bar */
2869 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
2870 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
2871 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2873 /* test window just wide enough for a vertical scroll bar */
2874 nccalchelper( hwnd, sbwidth, 100, &rc1);
2875 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
2876 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
2878 /* same test, but with client edge: not enough width */
2879 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
2880 nccalchelper( hwnd, sbwidth, 100, &rc1);
2881 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
2882 "Width should be %d size is %d,%d - %d,%d\n",
2883 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
2885 DestroyWindow( hwnd);
2888 static void test_SetParent(void)
2890 BOOL ret;
2891 HWND desktop = GetDesktopWindow();
2892 HMENU hMenu;
2893 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
2894 HWND parent, child1, child2, child3, child4, sibling;
2896 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2897 100, 100, 200, 200, 0, 0, 0, NULL);
2898 assert(parent != 0);
2899 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2900 0, 0, 50, 50, parent, 0, 0, NULL);
2901 assert(child1 != 0);
2902 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2903 0, 0, 50, 50, child1, 0, 0, NULL);
2904 assert(child2 != 0);
2905 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2906 0, 0, 50, 50, child2, 0, 0, NULL);
2907 assert(child3 != 0);
2908 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2909 0, 0, 50, 50, child3, 0, 0, NULL);
2910 assert(child4 != 0);
2912 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2913 parent, child1, child2, child3, child4);
2915 check_parents(parent, desktop, 0, 0, 0, parent, parent);
2916 check_parents(child1, parent, parent, parent, 0, parent, parent);
2917 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2918 check_parents(child3, child2, child2, child2, 0, child2, parent);
2919 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2921 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
2922 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
2923 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2924 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
2925 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2927 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
2928 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2929 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
2930 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
2931 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
2932 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
2933 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
2934 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
2935 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2937 if (!is_win9x) /* Win9x doesn't survive this test */
2939 ok(!SetParent(parent, child1), "SetParent should fail\n");
2940 ok(!SetParent(child2, child3), "SetParent should fail\n");
2941 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
2942 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
2943 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
2944 ok(!SetParent(child2, parent), "SetParent should fail\n");
2945 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
2947 check_parents(parent, child4, child4, 0, 0, child4, parent);
2948 check_parents(child1, parent, parent, parent, 0, child4, parent);
2949 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2950 check_parents(child3, child2, child2, child2, 0, child2, parent);
2951 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2954 hMenu = CreateMenu();
2955 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2956 100, 100, 200, 200, 0, hMenu, 0, NULL);
2957 assert(sibling != 0);
2959 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
2960 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
2962 ret = DestroyWindow(parent);
2963 ok( ret, "DestroyWindow() error %d\n", GetLastError());
2965 ok(!IsWindow(parent), "parent still exists\n");
2966 ok(!IsWindow(sibling), "sibling still exists\n");
2967 ok(!IsWindow(child1), "child1 still exists\n");
2968 ok(!IsWindow(child2), "child2 still exists\n");
2969 ok(!IsWindow(child3), "child3 still exists\n");
2970 ok(!IsWindow(child4), "child4 still exists\n");
2973 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2975 LPCREATESTRUCT lpcs;
2976 LPSTYLESTRUCT lpss;
2978 switch (msg)
2980 case WM_NCCREATE:
2981 case WM_CREATE:
2982 lpcs = (LPCREATESTRUCT)lparam;
2983 lpss = (LPSTYLESTRUCT)lpcs->lpCreateParams;
2984 if (lpss)
2986 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
2987 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
2988 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
2989 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
2990 else
2991 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
2993 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
2994 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2995 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
2997 ok(lpss->styleNew == lpcs->style,
2998 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
2999 lpss->styleNew, lpcs->style);
3001 break;
3003 return DefWindowProc(hwnd, msg, wparam, lparam);
3006 static ATOM atomStyleCheckClass;
3008 static void register_style_check_class(void)
3010 WNDCLASS wc =
3013 StyleCheckProc,
3016 GetModuleHandle(NULL),
3017 NULL,
3018 LoadCursor(NULL, IDC_ARROW),
3019 (HBRUSH)(COLOR_BTNFACE+1),
3020 NULL,
3021 TEXT("WineStyleCheck"),
3024 atomStyleCheckClass = RegisterClass(&wc);
3027 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3029 DWORD dwActualStyle;
3030 DWORD dwActualExStyle;
3031 STYLESTRUCT ss;
3032 HWND hwnd;
3033 HWND hwndParent = NULL;
3035 ss.styleNew = dwStyleIn;
3036 ss.styleOld = dwExStyleIn;
3038 if (dwStyleIn & WS_CHILD)
3040 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
3041 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3044 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
3045 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3046 assert(hwnd);
3048 flush_events( TRUE );
3050 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3051 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3052 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3053 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3054 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3056 DestroyWindow(hwnd);
3057 if (hwndParent) DestroyWindow(hwndParent);
3060 /* tests what window styles the window manager automatically adds */
3061 static void test_window_styles(void)
3063 register_style_check_class();
3065 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3066 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3067 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3068 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3069 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3070 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3071 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3072 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3073 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3074 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3075 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3078 static void test_scrollvalidate( HWND parent)
3080 HDC hdc;
3081 HRGN hrgn=CreateRectRgn(0,0,0,0);
3082 HRGN exprgn, tmprgn, clipping;
3083 RECT rc, rcu, cliprc;
3084 /* create two overlapping child windows. The visual region
3085 * of hwnd1 is clipped by the overlapping part of
3086 * hwnd2 because of the WS_CLIPSIBLING style */
3087 HWND hwnd1, hwnd2;
3089 clipping = CreateRectRgn(0,0,0,0);
3090 tmprgn = CreateRectRgn(0,0,0,0);
3091 exprgn = CreateRectRgn(0,0,0,0);
3092 hwnd2 = CreateWindowExA(0, "static", NULL,
3093 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3094 75, 30, 100, 100, parent, 0, 0, NULL);
3095 hwnd1 = CreateWindowExA(0, "static", NULL,
3096 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3097 25, 50, 100, 100, parent, 0, 0, NULL);
3098 ShowWindow( parent, SW_SHOW);
3099 UpdateWindow( parent);
3100 GetClientRect( hwnd1, &rc);
3101 cliprc=rc;
3102 SetRectRgn( clipping, 10, 10, 90, 90);
3103 hdc = GetDC( hwnd1);
3104 /* for a visual touch */
3105 TextOut( hdc, 0,10, "0123456789", 10);
3106 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3107 if (winetest_debug > 0) dump_region(hrgn);
3108 /* create a region with what is expected */
3109 SetRectRgn( exprgn, 39,0,49,74);
3110 SetRectRgn( tmprgn, 88,79,98,93);
3111 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3112 SetRectRgn( tmprgn, 0,93,98,98);
3113 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3114 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3115 trace("update rect is %d,%d - %d,%d\n",
3116 rcu.left,rcu.top,rcu.right,rcu.bottom);
3117 /* now with clipping region */
3118 SelectClipRgn( hdc, clipping);
3119 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3120 if (winetest_debug > 0) dump_region(hrgn);
3121 /* create a region with what is expected */
3122 SetRectRgn( exprgn, 39,10,49,74);
3123 SetRectRgn( tmprgn, 80,79,90,85);
3124 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3125 SetRectRgn( tmprgn, 10,85,90,90);
3126 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3127 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3128 trace("update rect is %d,%d - %d,%d\n",
3129 rcu.left,rcu.top,rcu.right,rcu.bottom);
3130 ReleaseDC( hwnd1, hdc);
3132 /* test scrolling a window with an update region */
3133 DestroyWindow( hwnd2);
3134 ValidateRect( hwnd1, NULL);
3135 SetRect( &rc, 40,40, 50,50);
3136 InvalidateRect( hwnd1, &rc, 1);
3137 GetClientRect( hwnd1, &rc);
3138 cliprc=rc;
3139 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
3140 SW_SCROLLCHILDREN | SW_INVALIDATE);
3141 if (winetest_debug > 0) dump_region(hrgn);
3142 SetRectRgn( exprgn, 88,0,98,98);
3143 SetRectRgn( tmprgn, 30, 40, 50, 50);
3144 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3145 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3147 /* clear an update region */
3148 UpdateWindow( hwnd1 );
3150 SetRect( &rc, 0,40, 100,60);
3151 SetRect( &cliprc, 0,0, 100,100);
3152 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3153 if (winetest_debug > 0) dump_region( hrgn );
3154 SetRectRgn( exprgn, 0, 40, 98, 60 );
3155 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
3157 /* now test ScrollWindowEx with a combination of
3158 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3159 /* make hwnd2 the child of hwnd1 */
3160 hwnd2 = CreateWindowExA(0, "static", NULL,
3161 WS_CHILD| WS_VISIBLE | WS_BORDER ,
3162 50, 50, 100, 100, hwnd1, 0, 0, NULL);
3163 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
3164 GetClientRect( hwnd1, &rc);
3165 cliprc=rc;
3167 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3168 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3169 ValidateRect( hwnd1, NULL);
3170 ValidateRect( hwnd2, NULL);
3171 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
3172 SW_SCROLLCHILDREN | SW_INVALIDATE);
3173 if (winetest_debug > 0) dump_region(hrgn);
3174 SetRectRgn( exprgn, 88,0,98,88);
3175 SetRectRgn( tmprgn, 0,88,98,98);
3176 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3177 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3179 /* SW_SCROLLCHILDREN */
3180 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3181 ValidateRect( hwnd1, NULL);
3182 ValidateRect( hwnd2, NULL);
3183 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3184 if (winetest_debug > 0) dump_region(hrgn);
3185 /* expected region is the same as in previous test */
3186 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3188 /* no SW_SCROLLCHILDREN */
3189 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3190 ValidateRect( hwnd1, NULL);
3191 ValidateRect( hwnd2, NULL);
3192 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3193 if (winetest_debug > 0) dump_region(hrgn);
3194 /* expected region is the same as in previous test */
3195 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3197 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3198 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3199 ValidateRect( hwnd1, NULL);
3200 ValidateRect( hwnd2, NULL);
3201 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3202 if (winetest_debug > 0) dump_region(hrgn);
3203 SetRectRgn( exprgn, 88,0,98,20);
3204 SetRectRgn( tmprgn, 20,20,98,30);
3205 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3206 SetRectRgn( tmprgn, 20,30,30,88);
3207 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3208 SetRectRgn( tmprgn, 0,88,30,98);
3209 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3210 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3212 /* clean up */
3213 DeleteObject( hrgn);
3214 DeleteObject( exprgn);
3215 DeleteObject( tmprgn);
3216 DestroyWindow( hwnd1);
3217 DestroyWindow( hwnd2);
3220 /* couple of tests of return values of scrollbar functions
3221 * called on a scrollbarless window */
3222 static void test_scroll(void)
3224 BOOL ret;
3225 INT min, max;
3226 SCROLLINFO si;
3227 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3228 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3229 100, 100, 200, 200, 0, 0, 0, NULL);
3230 /* horizontal */
3231 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3232 ok( ret, "GetScrollRange returns FALSE\n");
3233 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3234 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3235 si.cbSize = sizeof( si);
3236 si.fMask = SIF_PAGE;
3237 si.nPage = 0xdeadbeef;
3238 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3239 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3240 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3241 /* vertical */
3242 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3243 ok( ret, "GetScrollRange returns FALSE\n");
3244 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3245 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3246 si.cbSize = sizeof( si);
3247 si.fMask = SIF_PAGE;
3248 si.nPage = 0xdeadbeef;
3249 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3250 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3251 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3252 /* clean up */
3253 DestroyWindow( hwnd);
3256 static void test_scrolldc( HWND parent)
3258 HDC hdc;
3259 HRGN exprgn, tmprgn, hrgn;
3260 RECT rc, rc2, rcu, cliprc;
3261 HWND hwnd1;
3262 COLORREF colr;
3264 hrgn = CreateRectRgn(0,0,0,0);
3265 tmprgn = CreateRectRgn(0,0,0,0);
3266 exprgn = CreateRectRgn(0,0,0,0);
3268 hwnd1 = CreateWindowExA(0, "static", NULL,
3269 WS_CHILD| WS_VISIBLE,
3270 25, 50, 100, 100, parent, 0, 0, NULL);
3271 ShowWindow( parent, SW_SHOW);
3272 UpdateWindow( parent);
3273 flush_events( TRUE );
3274 GetClientRect( hwnd1, &rc);
3275 hdc = GetDC( hwnd1);
3276 /* paint the upper half of the window black */
3277 rc2 = rc;
3278 rc2.bottom = ( rc.top + rc.bottom) /2;
3279 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3280 /* clip region is the lower half */
3281 cliprc=rc;
3282 cliprc.top = (rc.top + rc.bottom) /2;
3283 /* test whether scrolled pixels are properly clipped */
3284 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3285 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3286 /* this scroll should not cause any visible changes */
3287 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3288 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3289 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3290 /* test with NULL clip rect */
3291 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3292 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3293 trace("update rect: %d,%d - %d,%d\n",
3294 rcu.left, rcu.top, rcu.right, rcu.bottom);
3295 if (winetest_debug > 0) dump_region(hrgn);
3296 SetRect(&rc2, 0, 0, 100, 100);
3297 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3298 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3300 SetRectRgn( exprgn, 0, 0, 20, 80);
3301 SetRectRgn( tmprgn, 0, 80, 100, 100);
3302 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3303 if (winetest_debug > 0) dump_region(exprgn);
3304 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3305 /* test clip rect > scroll rect */
3306 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3307 rc2=rc;
3308 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3309 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3310 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3311 SetRectRgn( exprgn, 25, 25, 75, 35);
3312 SetRectRgn( tmprgn, 25, 35, 35, 75);
3313 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3314 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3315 colr = GetPixel( hdc, 80, 80);
3316 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3317 trace("update rect: %d,%d - %d,%d\n",
3318 rcu.left, rcu.top, rcu.right, rcu.bottom);
3319 if (winetest_debug > 0) dump_region(hrgn);
3321 /* clean up */
3322 DeleteObject(hrgn);
3323 DeleteObject(exprgn);
3324 DeleteObject(tmprgn);
3325 DestroyWindow(hwnd1);
3328 static void test_params(void)
3330 HWND hwnd;
3331 INT rc;
3333 /* Just a param check */
3334 SetLastError(0xdeadbeef);
3335 rc = GetWindowText(hwndMain2, NULL, 1024);
3336 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
3338 SetLastError(0xdeadbeef);
3339 hwnd=CreateWindow("LISTBOX", "TestList",
3340 (LBS_STANDARD & ~LBS_SORT),
3341 0, 0, 100, 100,
3342 NULL, (HMENU)1, NULL, 0);
3344 ok(!hwnd, "CreateWindow with invalid menu handle should fail\n");
3345 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3346 GetLastError() == 0xdeadbeef, /* Win9x */
3347 "wrong last error value %d\n", GetLastError());
3350 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3352 HWND hwnd = 0;
3354 hwnd = CreateWindowEx(exStyle, class, class, style,
3355 110, 100,
3356 225, 200,
3358 menu ? hmenu : 0,
3359 0, 0);
3360 if (!hwnd) {
3361 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
3362 return;
3364 ShowWindow(hwnd, SW_SHOW);
3366 test_nonclient_area(hwnd);
3368 SetMenu(hwnd, 0);
3369 DestroyWindow(hwnd);
3372 static BOOL AWR_init(void)
3374 WNDCLASS class;
3376 class.style = CS_HREDRAW | CS_VREDRAW;
3377 class.lpfnWndProc = DefWindowProcA;
3378 class.cbClsExtra = 0;
3379 class.cbWndExtra = 0;
3380 class.hInstance = 0;
3381 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3382 class.hCursor = LoadCursor (0, IDC_ARROW);
3383 class.hbrBackground = 0;
3384 class.lpszMenuName = 0;
3385 class.lpszClassName = szAWRClass;
3387 if (!RegisterClass (&class)) {
3388 ok(FALSE, "RegisterClass failed\n");
3389 return FALSE;
3392 hmenu = CreateMenu();
3393 if (!hmenu)
3394 return FALSE;
3395 ok(hmenu != 0, "Failed to create menu\n");
3396 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3398 return TRUE;
3402 static void test_AWR_window_size(BOOL menu)
3404 LONG styles[] = {
3405 WS_POPUP,
3406 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3407 WS_SYSMENU,
3408 WS_THICKFRAME,
3409 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3410 WS_HSCROLL, WS_VSCROLL
3412 LONG exStyles[] = {
3413 WS_EX_CLIENTEDGE,
3414 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3415 WS_EX_APPWINDOW,
3416 #if 0
3417 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3418 WS_EX_DLGMODALFRAME,
3419 WS_EX_STATICEDGE,
3420 #endif
3423 int i;
3425 /* A exhaustive check of all the styles takes too long
3426 * so just do a (hopefully representative) sample
3428 for (i = 0; i < COUNTOF(styles); ++i)
3429 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3430 for (i = 0; i < COUNTOF(exStyles); ++i) {
3431 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3432 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3435 #undef COUNTOF
3437 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3439 static void test_AdjustWindowRect(void)
3441 if (!AWR_init())
3442 return;
3444 SHOWSYSMETRIC(SM_CYCAPTION);
3445 SHOWSYSMETRIC(SM_CYSMCAPTION);
3446 SHOWSYSMETRIC(SM_CYMENU);
3447 SHOWSYSMETRIC(SM_CXEDGE);
3448 SHOWSYSMETRIC(SM_CYEDGE);
3449 SHOWSYSMETRIC(SM_CXVSCROLL);
3450 SHOWSYSMETRIC(SM_CYHSCROLL);
3451 SHOWSYSMETRIC(SM_CXFRAME);
3452 SHOWSYSMETRIC(SM_CYFRAME);
3453 SHOWSYSMETRIC(SM_CXDLGFRAME);
3454 SHOWSYSMETRIC(SM_CYDLGFRAME);
3455 SHOWSYSMETRIC(SM_CXBORDER);
3456 SHOWSYSMETRIC(SM_CYBORDER);
3458 test_AWR_window_size(FALSE);
3459 test_AWR_window_size(TRUE);
3461 DestroyMenu(hmenu);
3463 #undef SHOWSYSMETRIC
3466 /* Global variables to trigger exit from loop */
3467 static int redrawComplete, WMPAINT_count;
3469 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3471 switch (msg)
3473 case WM_PAINT:
3474 trace("doing WM_PAINT %d\n", WMPAINT_count);
3475 WMPAINT_count++;
3476 if (WMPAINT_count > 10 && redrawComplete == 0) {
3477 PAINTSTRUCT ps;
3478 BeginPaint(hwnd, &ps);
3479 EndPaint(hwnd, &ps);
3480 return 1;
3482 return 0;
3484 return DefWindowProc(hwnd, msg, wparam, lparam);
3487 /* Ensure we exit from RedrawNow regardless of invalidated area */
3488 static void test_redrawnow(void)
3490 WNDCLASSA cls;
3491 HWND hwndMain;
3493 cls.style = CS_DBLCLKS;
3494 cls.lpfnWndProc = redraw_window_procA;
3495 cls.cbClsExtra = 0;
3496 cls.cbWndExtra = 0;
3497 cls.hInstance = GetModuleHandleA(0);
3498 cls.hIcon = 0;
3499 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3500 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3501 cls.lpszMenuName = NULL;
3502 cls.lpszClassName = "RedrawWindowClass";
3504 if(!RegisterClassA(&cls)) {
3505 trace("Register failed %d\n", GetLastError());
3506 return;
3509 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3510 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3512 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3513 ShowWindow(hwndMain, SW_SHOW);
3514 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3515 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3516 ok( WMPAINT_count == 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3517 redrawComplete = TRUE;
3518 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3520 /* clean up */
3521 DestroyWindow( hwndMain);
3524 struct parentdc_stat {
3525 RECT client;
3526 RECT clip;
3527 RECT paint;
3530 struct parentdc_test {
3531 struct parentdc_stat main, main_todo;
3532 struct parentdc_stat child1, child1_todo;
3533 struct parentdc_stat child2, child2_todo;
3536 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3538 RECT rc;
3539 PAINTSTRUCT ps;
3541 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3543 switch (msg)
3545 case WM_PAINT:
3546 trace("doing WM_PAINT on %p\n", hwnd);
3547 GetClientRect(hwnd, &rc);
3548 CopyRect(&t->client, &rc);
3549 trace("client rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3550 GetWindowRect(hwnd, &rc);
3551 trace("window rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3552 BeginPaint(hwnd, &ps);
3553 CopyRect(&t->paint, &ps.rcPaint);
3554 GetClipBox(ps.hdc, &rc);
3555 CopyRect(&t->clip, &rc);
3556 trace("clip rect (%d, %d)-(%d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
3557 trace("paint rect (%d, %d)-(%d, %d)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3558 EndPaint(hwnd, &ps);
3559 return 0;
3561 return DefWindowProc(hwnd, msg, wparam, lparam);
3564 static void zero_parentdc_stat(struct parentdc_stat *t)
3566 SetRectEmpty(&t->client);
3567 SetRectEmpty(&t->clip);
3568 SetRectEmpty(&t->paint);
3571 static void zero_parentdc_test(struct parentdc_test *t)
3573 zero_parentdc_stat(&t->main);
3574 zero_parentdc_stat(&t->child1);
3575 zero_parentdc_stat(&t->child2);
3578 #define parentdc_field_ok(t, w, r, f, got) \
3579 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3580 ": expected %d, got %d\n", \
3581 t.w.r.f, got.w.r.f)
3583 #define parentdc_todo_field_ok(t, w, r, f, got) \
3584 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3585 else parentdc_field_ok(t, w, r, f, got)
3587 #define parentdc_rect_ok(t, w, r, got) \
3588 parentdc_todo_field_ok(t, w, r, left, got); \
3589 parentdc_todo_field_ok(t, w, r, top, got); \
3590 parentdc_todo_field_ok(t, w, r, right, got); \
3591 parentdc_todo_field_ok(t, w, r, bottom, got);
3593 #define parentdc_win_ok(t, w, got) \
3594 parentdc_rect_ok(t, w, client, got); \
3595 parentdc_rect_ok(t, w, clip, got); \
3596 parentdc_rect_ok(t, w, paint, got);
3598 #define parentdc_ok(t, got) \
3599 parentdc_win_ok(t, main, got); \
3600 parentdc_win_ok(t, child1, got); \
3601 parentdc_win_ok(t, child2, got);
3603 static void test_csparentdc(void)
3605 WNDCLASSA clsMain, cls;
3606 HWND hwndMain, hwnd1, hwnd2;
3607 RECT rc;
3609 struct parentdc_test test_answer;
3611 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3612 const struct parentdc_test test1 =
3614 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
3615 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3616 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3619 const struct parentdc_test test2 =
3621 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
3622 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3623 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3626 const struct parentdc_test test3 =
3628 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3629 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3630 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3633 const struct parentdc_test test4 =
3635 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
3636 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
3637 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3640 const struct parentdc_test test5 =
3642 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
3643 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3644 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3647 const struct parentdc_test test6 =
3649 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3650 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3651 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3654 const struct parentdc_test test7 =
3656 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3657 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3658 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3660 #undef nothing_todo
3662 clsMain.style = CS_DBLCLKS;
3663 clsMain.lpfnWndProc = parentdc_window_procA;
3664 clsMain.cbClsExtra = 0;
3665 clsMain.cbWndExtra = 0;
3666 clsMain.hInstance = GetModuleHandleA(0);
3667 clsMain.hIcon = 0;
3668 clsMain.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3669 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
3670 clsMain.lpszMenuName = NULL;
3671 clsMain.lpszClassName = "ParentDcMainWindowClass";
3673 if(!RegisterClassA(&clsMain)) {
3674 trace("Register failed %d\n", GetLastError());
3675 return;
3678 cls.style = CS_DBLCLKS | CS_PARENTDC;
3679 cls.lpfnWndProc = parentdc_window_procA;
3680 cls.cbClsExtra = 0;
3681 cls.cbWndExtra = 0;
3682 cls.hInstance = GetModuleHandleA(0);
3683 cls.hIcon = 0;
3684 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3685 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3686 cls.lpszMenuName = NULL;
3687 cls.lpszClassName = "ParentDcWindowClass";
3689 if(!RegisterClassA(&cls)) {
3690 trace("Register failed %d\n", GetLastError());
3691 return;
3694 SetRect(&rc, 0, 0, 150, 150);
3695 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
3696 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3697 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
3698 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
3699 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
3700 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
3701 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
3702 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
3703 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
3704 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
3705 ShowWindow(hwndMain, SW_SHOW);
3706 ShowWindow(hwnd1, SW_SHOW);
3707 ShowWindow(hwnd2, SW_SHOW);
3708 flush_events( TRUE );
3710 zero_parentdc_test(&test_answer);
3711 InvalidateRect(hwndMain, NULL, TRUE);
3712 flush_events( TRUE );
3713 parentdc_ok(test1, test_answer);
3715 zero_parentdc_test(&test_answer);
3716 SetRect(&rc, 0, 0, 50, 50);
3717 InvalidateRect(hwndMain, &rc, TRUE);
3718 flush_events( TRUE );
3719 parentdc_ok(test2, test_answer);
3721 zero_parentdc_test(&test_answer);
3722 SetRect(&rc, 0, 0, 10, 10);
3723 InvalidateRect(hwndMain, &rc, TRUE);
3724 flush_events( TRUE );
3725 parentdc_ok(test3, test_answer);
3727 zero_parentdc_test(&test_answer);
3728 SetRect(&rc, 40, 40, 50, 50);
3729 InvalidateRect(hwndMain, &rc, TRUE);
3730 flush_events( TRUE );
3731 parentdc_ok(test4, test_answer);
3733 zero_parentdc_test(&test_answer);
3734 SetRect(&rc, 20, 20, 60, 60);
3735 InvalidateRect(hwndMain, &rc, TRUE);
3736 flush_events( TRUE );
3737 parentdc_ok(test5, test_answer);
3739 zero_parentdc_test(&test_answer);
3740 SetRect(&rc, 0, 0, 10, 10);
3741 InvalidateRect(hwnd1, &rc, TRUE);
3742 flush_events( TRUE );
3743 parentdc_ok(test6, test_answer);
3745 zero_parentdc_test(&test_answer);
3746 SetRect(&rc, -5, -5, 65, 65);
3747 InvalidateRect(hwnd1, &rc, TRUE);
3748 flush_events( TRUE );
3749 parentdc_ok(test7, test_answer);
3751 DestroyWindow(hwndMain);
3752 DestroyWindow(hwnd1);
3753 DestroyWindow(hwnd2);
3756 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3758 return DefWindowProcA(hwnd, msg, wparam, lparam);
3761 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3763 return DefWindowProcW(hwnd, msg, wparam, lparam);
3766 static void test_IsWindowUnicode(void)
3768 static const char ansi_class_nameA[] = "ansi class name";
3769 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3770 static const char unicode_class_nameA[] = "unicode class name";
3771 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3772 WNDCLASSA classA;
3773 WNDCLASSW classW;
3774 HWND hwnd;
3776 memset(&classW, 0, sizeof(classW));
3777 classW.hInstance = GetModuleHandleA(0);
3778 classW.lpfnWndProc = def_window_procW;
3779 classW.lpszClassName = unicode_class_nameW;
3780 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
3782 memset(&classA, 0, sizeof(classA));
3783 classA.hInstance = GetModuleHandleA(0);
3784 classA.lpfnWndProc = def_window_procA;
3785 classA.lpszClassName = ansi_class_nameA;
3786 assert(RegisterClassA(&classA));
3788 /* unicode class: window proc */
3789 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3790 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3791 assert(hwnd);
3793 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3794 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3795 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3796 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3797 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3799 DestroyWindow(hwnd);
3801 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3802 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3803 assert(hwnd);
3805 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3806 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3807 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3808 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3809 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3811 DestroyWindow(hwnd);
3813 /* ansi class: window proc */
3814 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3815 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3816 assert(hwnd);
3818 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3819 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3820 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3821 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3822 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3824 DestroyWindow(hwnd);
3826 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3827 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3828 assert(hwnd);
3830 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3831 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3832 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3833 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3834 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3836 DestroyWindow(hwnd);
3838 /* unicode class: class proc */
3839 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3840 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3841 assert(hwnd);
3843 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3844 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3845 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3846 /* do not restore class window proc back to unicode */
3848 DestroyWindow(hwnd);
3850 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3851 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3852 assert(hwnd);
3854 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3855 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
3856 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3858 DestroyWindow(hwnd);
3860 /* ansi class: class proc */
3861 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3862 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3863 assert(hwnd);
3865 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3866 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
3867 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3868 /* do not restore class window proc back to ansi */
3870 DestroyWindow(hwnd);
3872 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3873 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3874 assert(hwnd);
3876 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3877 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3878 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3880 DestroyWindow(hwnd);
3883 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
3885 MINMAXINFO *minmax;
3887 if (msg != WM_GETMINMAXINFO)
3888 return DefWindowProc(hwnd, msg, wp, lp);
3890 minmax = (MINMAXINFO *)lp;
3892 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
3894 minmax->ptReserved.x = 0;
3895 minmax->ptReserved.y = 0;
3896 minmax->ptMaxSize.x = 400;
3897 minmax->ptMaxSize.y = 400;
3898 minmax->ptMaxPosition.x = 300;
3899 minmax->ptMaxPosition.y = 300;
3900 minmax->ptMaxTrackSize.x = 200;
3901 minmax->ptMaxTrackSize.y = 200;
3902 minmax->ptMinTrackSize.x = 100;
3903 minmax->ptMinTrackSize.y = 100;
3905 else
3906 DefWindowProc(hwnd, msg, wp, lp);
3907 return 1;
3910 static int expected_cx, expected_cy;
3911 static RECT expected_rect, broken_rect;
3913 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
3915 switch(msg)
3917 case WM_GETMINMAXINFO:
3919 RECT rect;
3920 GetWindowRect( hwnd, &rect );
3921 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
3922 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
3923 return DefWindowProc(hwnd, msg, wp, lp);
3925 case WM_NCCREATE:
3926 case WM_CREATE:
3928 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
3929 RECT rect;
3930 GetWindowRect( hwnd, &rect );
3931 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
3932 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
3933 ok( cs->cx == expected_cx, "wrong x size %d/%d\n", cs->cx, expected_cx );
3934 ok( cs->cy == expected_cy, "wrong y size %d/%d\n", cs->cy, expected_cy );
3935 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
3936 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
3937 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
3938 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top),
3939 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
3940 rect.left, rect.top, rect.right, rect.bottom,
3941 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
3942 return DefWindowProc(hwnd, msg, wp, lp);
3944 case WM_NCCALCSIZE:
3946 RECT rect, *r = (RECT *)lp;
3947 GetWindowRect( hwnd, &rect );
3948 ok( !memcmp( &rect, r, sizeof(rect) ),
3949 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
3950 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
3951 return DefWindowProc(hwnd, msg, wp, lp);
3953 default:
3954 return DefWindowProc(hwnd, msg, wp, lp);
3958 static void test_CreateWindow(void)
3960 WNDCLASS cls;
3961 HWND hwnd, parent;
3962 HMENU hmenu;
3963 RECT rc, rc_minmax;
3964 MINMAXINFO minmax;
3966 #define expect_menu(window, menu) \
3967 SetLastError(0xdeadbeef); \
3968 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
3970 #define expect_style(window, style)\
3971 ok(GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
3973 #define expect_ex_style(window, ex_style)\
3974 ok(GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
3976 hmenu = CreateMenu();
3977 assert(hmenu != 0);
3978 parent = GetDesktopWindow();
3979 assert(parent != 0);
3981 SetLastError(0xdeadbeef);
3982 ok(IsMenu(hmenu), "IsMenu error %d\n", GetLastError());
3984 /* WS_CHILD */
3985 SetLastError(0xdeadbeef);
3986 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
3987 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3988 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3989 expect_menu(hwnd, 1);
3990 expect_style(hwnd, WS_CHILD);
3991 expect_ex_style(hwnd, WS_EX_APPWINDOW);
3992 DestroyWindow(hwnd);
3994 SetLastError(0xdeadbeef);
3995 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
3996 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3997 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
3998 expect_menu(hwnd, 1);
3999 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4000 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4001 DestroyWindow(hwnd);
4003 SetLastError(0xdeadbeef);
4004 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
4005 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4006 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4007 expect_menu(hwnd, 1);
4008 expect_style(hwnd, WS_CHILD);
4009 expect_ex_style(hwnd, 0);
4010 DestroyWindow(hwnd);
4012 SetLastError(0xdeadbeef);
4013 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
4014 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4015 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4016 expect_menu(hwnd, 1);
4017 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4018 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4019 DestroyWindow(hwnd);
4021 /* WS_POPUP */
4022 SetLastError(0xdeadbeef);
4023 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4024 0, 0, 100, 100, parent, hmenu, 0, NULL);
4025 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4026 expect_menu(hwnd, hmenu);
4027 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4028 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4029 DestroyWindow(hwnd);
4030 SetLastError(0xdeadbeef);
4031 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4032 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4034 hmenu = CreateMenu();
4035 assert(hmenu != 0);
4036 SetLastError(0xdeadbeef);
4037 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
4038 0, 0, 100, 100, parent, hmenu, 0, NULL);
4039 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4040 expect_menu(hwnd, hmenu);
4041 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4042 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4043 DestroyWindow(hwnd);
4044 SetLastError(0xdeadbeef);
4045 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4046 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4048 hmenu = CreateMenu();
4049 assert(hmenu != 0);
4050 SetLastError(0xdeadbeef);
4051 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
4052 0, 0, 100, 100, parent, hmenu, 0, NULL);
4053 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4054 expect_menu(hwnd, hmenu);
4055 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4056 expect_ex_style(hwnd, 0);
4057 DestroyWindow(hwnd);
4058 SetLastError(0xdeadbeef);
4059 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4060 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4062 hmenu = CreateMenu();
4063 assert(hmenu != 0);
4064 SetLastError(0xdeadbeef);
4065 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
4066 0, 0, 100, 100, parent, hmenu, 0, NULL);
4067 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4068 expect_menu(hwnd, hmenu);
4069 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4070 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4071 DestroyWindow(hwnd);
4072 SetLastError(0xdeadbeef);
4073 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4074 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4076 /* WS_CHILD | WS_POPUP */
4077 SetLastError(0xdeadbeef);
4078 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4079 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4080 ok(!hwnd, "CreateWindowEx should fail\n");
4081 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4083 hmenu = CreateMenu();
4084 assert(hmenu != 0);
4085 SetLastError(0xdeadbeef);
4086 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4087 0, 0, 100, 100, parent, hmenu, 0, NULL);
4088 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4089 expect_menu(hwnd, hmenu);
4090 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4091 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4092 DestroyWindow(hwnd);
4093 SetLastError(0xdeadbeef);
4094 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4095 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4097 SetLastError(0xdeadbeef);
4098 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4099 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4100 ok(!hwnd, "CreateWindowEx should fail\n");
4101 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4103 hmenu = CreateMenu();
4104 assert(hmenu != 0);
4105 SetLastError(0xdeadbeef);
4106 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4107 0, 0, 100, 100, parent, hmenu, 0, NULL);
4108 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4109 expect_menu(hwnd, hmenu);
4110 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4111 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4112 DestroyWindow(hwnd);
4113 SetLastError(0xdeadbeef);
4114 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4115 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4117 SetLastError(0xdeadbeef);
4118 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4119 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4120 ok(!hwnd, "CreateWindowEx should fail\n");
4121 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4123 hmenu = CreateMenu();
4124 assert(hmenu != 0);
4125 SetLastError(0xdeadbeef);
4126 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4127 0, 0, 100, 100, parent, hmenu, 0, NULL);
4128 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4129 expect_menu(hwnd, hmenu);
4130 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4131 expect_ex_style(hwnd, 0);
4132 DestroyWindow(hwnd);
4133 SetLastError(0xdeadbeef);
4134 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4135 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4137 SetLastError(0xdeadbeef);
4138 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4139 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4140 ok(!hwnd, "CreateWindowEx should fail\n");
4141 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4143 hmenu = CreateMenu();
4144 assert(hmenu != 0);
4145 SetLastError(0xdeadbeef);
4146 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4147 0, 0, 100, 100, parent, hmenu, 0, NULL);
4148 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4149 expect_menu(hwnd, hmenu);
4150 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4151 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4152 DestroyWindow(hwnd);
4153 SetLastError(0xdeadbeef);
4154 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4155 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %d\n", GetLastError());
4157 /* test child window sizing */
4158 cls.style = 0;
4159 cls.lpfnWndProc = minmax_wnd_proc;
4160 cls.cbClsExtra = 0;
4161 cls.cbWndExtra = 0;
4162 cls.hInstance = GetModuleHandle(0);
4163 cls.hIcon = 0;
4164 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
4165 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4166 cls.lpszMenuName = NULL;
4167 cls.lpszClassName = "MinMax_WndClass";
4168 RegisterClass(&cls);
4170 SetLastError(0xdeadbeef);
4171 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4172 0, 0, 100, 100, 0, 0, 0, NULL);
4173 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4174 expect_menu(parent, 0);
4175 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
4176 expect_ex_style(parent, WS_EX_WINDOWEDGE);
4178 memset(&minmax, 0, sizeof(minmax));
4179 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4180 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
4181 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
4182 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4183 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
4185 GetWindowRect(parent, &rc);
4186 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
4187 GetClientRect(parent, &rc);
4188 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
4190 InflateRect(&rc, 200, 200);
4191 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4193 SetLastError(0xdeadbeef);
4194 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4195 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
4196 parent, (HMENU)1, 0, NULL);
4197 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4198 expect_menu(hwnd, 1);
4199 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
4200 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4202 memset(&minmax, 0, sizeof(minmax));
4203 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4204 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4206 GetWindowRect(hwnd, &rc);
4207 OffsetRect(&rc, -rc.left, -rc.top);
4208 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4209 rc.left, rc.top, rc.right, rc.bottom,
4210 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
4211 DestroyWindow(hwnd);
4213 cls.lpfnWndProc = winsizes_wnd_proc;
4214 cls.lpszClassName = "Sizes_WndClass";
4215 RegisterClass(&cls);
4217 expected_cx = expected_cy = 200000;
4218 SetRect( &expected_rect, 0, 0, 200000, 200000 );
4219 broken_rect = expected_rect;
4220 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
4221 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4222 GetClientRect( hwnd, &rc );
4223 ok( rc.right == 200000, "invalid rect right %u\n", rc.right );
4224 ok( rc.bottom == 200000, "invalid rect bottom %u\n", rc.bottom );
4225 DestroyWindow(hwnd);
4227 expected_cx = expected_cy = -10;
4228 SetRect( &expected_rect, 0, 0, 0, 0 );
4229 broken_rect = expected_rect;
4230 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
4231 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4232 GetClientRect( hwnd, &rc );
4233 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4234 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4235 DestroyWindow(hwnd);
4237 expected_cx = expected_cy = -200000;
4238 SetRect( &expected_rect, 0, 0, 0, 0 );
4239 broken_rect = expected_rect;
4240 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
4241 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4242 GetClientRect( hwnd, &rc );
4243 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4244 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4245 DestroyWindow(hwnd);
4247 /* we need a parent at 0,0 so that child coordinates match */
4248 DestroyWindow(parent);
4249 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
4250 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4252 expected_cx = 100;
4253 expected_cy = 0x7fffffff;
4254 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
4255 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
4256 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
4257 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4258 GetClientRect( hwnd, &rc );
4259 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
4260 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4261 DestroyWindow(hwnd);
4263 expected_cx = 0x7fffffff;
4264 expected_cy = 0x7fffffff;
4265 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
4266 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
4267 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
4268 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4269 GetClientRect( hwnd, &rc );
4270 ok( rc.right == 0x7fffffff - 20 || broken(rc.right == 0), "invalid rect right %u\n", rc.right );
4271 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4272 DestroyWindow(hwnd);
4274 /* top level window */
4275 expected_cx = expected_cy = 200000;
4276 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
4277 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
4278 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4279 GetClientRect( hwnd, &rc );
4280 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
4281 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
4282 DestroyWindow(hwnd);
4284 DestroyWindow(parent);
4286 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4287 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4289 #undef expect_menu
4290 #undef expect_style
4291 #undef expect_ex_style
4294 /* function that remembers whether the system the test is running on sets the
4295 * last error for user32 functions to make the tests stricter */
4296 static int check_error(DWORD actual, DWORD expected)
4298 static int sets_last_error = -1;
4299 if (sets_last_error == -1)
4300 sets_last_error = (actual != 0xdeadbeef);
4301 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
4304 static void test_SetWindowLong(void)
4306 LONG_PTR retval;
4307 WNDPROC old_window_procW;
4309 SetLastError(0xdeadbeef);
4310 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
4311 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
4312 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
4313 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4315 SetLastError(0xdeadbeef);
4316 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
4317 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
4318 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
4319 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4321 SetLastError(0xdeadbeef);
4322 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4323 ok((WNDPROC)retval == main_window_procA,
4324 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
4325 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4326 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
4327 ok((WNDPROC)retval == main_window_procA,
4328 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4329 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
4331 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
4332 SetLastError(0xdeadbeef);
4333 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
4334 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
4336 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4337 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
4338 ok((WNDPROC)retval == old_window_procW,
4339 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4340 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
4342 /* set it back to ANSI */
4343 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4347 static void test_ShowWindow(void)
4349 HWND hwnd;
4350 DWORD style;
4351 RECT rcMain, rc;
4352 LPARAM ret;
4354 SetRect(&rcMain, 120, 120, 210, 210);
4356 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
4357 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4358 WS_MAXIMIZEBOX | WS_POPUP,
4359 rcMain.left, rcMain.top,
4360 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
4361 0, 0, 0, NULL);
4362 assert(hwnd);
4364 style = GetWindowLong(hwnd, GWL_STYLE);
4365 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4366 ok(!(style & WS_VISIBLE), "window should not be visible\n");
4367 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4368 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4369 GetWindowRect(hwnd, &rc);
4370 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4371 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4372 rc.left, rc.top, rc.right, rc.bottom);
4374 ret = ShowWindow(hwnd, SW_SHOW);
4375 ok(!ret, "not expected ret: %lu\n", ret);
4376 style = GetWindowLong(hwnd, GWL_STYLE);
4377 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4378 ok(style & WS_VISIBLE, "window should be visible\n");
4379 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4380 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4381 GetWindowRect(hwnd, &rc);
4382 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4383 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4384 rc.left, rc.top, rc.right, rc.bottom);
4386 ret = ShowWindow(hwnd, SW_MINIMIZE);
4387 ok(ret, "not expected ret: %lu\n", ret);
4388 style = GetWindowLong(hwnd, GWL_STYLE);
4389 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4390 ok(style & WS_VISIBLE, "window should be visible\n");
4391 ok(style & WS_MINIMIZE, "window should be minimized\n");
4392 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4393 GetWindowRect(hwnd, &rc);
4394 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4396 ShowWindow(hwnd, SW_RESTORE);
4397 ok(ret, "not expected ret: %lu\n", ret);
4398 style = GetWindowLong(hwnd, GWL_STYLE);
4399 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4400 ok(style & WS_VISIBLE, "window should be visible\n");
4401 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4402 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4403 GetWindowRect(hwnd, &rc);
4404 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4405 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4406 rc.left, rc.top, rc.right, rc.bottom);
4408 ret = EnableWindow(hwnd, FALSE);
4409 ok(!ret, "not expected ret: %lu\n", ret);
4410 style = GetWindowLong(hwnd, GWL_STYLE);
4411 ok(style & WS_DISABLED, "window should be disabled\n");
4413 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
4414 ok(!ret, "not expected ret: %lu\n", ret);
4415 style = GetWindowLong(hwnd, GWL_STYLE);
4416 ok(style & WS_DISABLED, "window should be disabled\n");
4417 ok(style & WS_VISIBLE, "window should be visible\n");
4418 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4419 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4420 GetWindowRect(hwnd, &rc);
4421 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4422 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4423 rc.left, rc.top, rc.right, rc.bottom);
4425 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
4426 ok(!ret, "not expected ret: %lu\n", ret);
4427 style = GetWindowLong(hwnd, GWL_STYLE);
4428 ok(style & WS_DISABLED, "window should be disabled\n");
4429 ok(style & WS_VISIBLE, "window should be visible\n");
4430 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4431 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4432 GetWindowRect(hwnd, &rc);
4433 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4434 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4435 rc.left, rc.top, rc.right, rc.bottom);
4437 ret = ShowWindow(hwnd, SW_MINIMIZE);
4438 ok(ret, "not expected ret: %lu\n", ret);
4439 style = GetWindowLong(hwnd, GWL_STYLE);
4440 ok(style & WS_DISABLED, "window should be disabled\n");
4441 ok(style & WS_VISIBLE, "window should be visible\n");
4442 ok(style & WS_MINIMIZE, "window should be minimized\n");
4443 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4444 GetWindowRect(hwnd, &rc);
4445 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4447 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
4448 ok(!ret, "not expected ret: %lu\n", ret);
4449 style = GetWindowLong(hwnd, GWL_STYLE);
4450 ok(style & WS_DISABLED, "window should be disabled\n");
4451 ok(style & WS_VISIBLE, "window should be visible\n");
4452 ok(style & WS_MINIMIZE, "window should be minimized\n");
4453 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4454 GetWindowRect(hwnd, &rc);
4455 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4457 ret = ShowWindow(hwnd, SW_RESTORE);
4458 ok(ret, "not expected ret: %lu\n", ret);
4459 style = GetWindowLong(hwnd, GWL_STYLE);
4460 ok(style & WS_DISABLED, "window should be disabled\n");
4461 ok(style & WS_VISIBLE, "window should be visible\n");
4462 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4463 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4464 GetWindowRect(hwnd, &rc);
4465 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4466 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4467 rc.left, rc.top, rc.right, rc.bottom);
4469 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4470 ok(!ret, "not expected ret: %lu\n", ret);
4471 ok(IsWindow(hwnd), "window should exist\n");
4473 ret = EnableWindow(hwnd, TRUE);
4474 ok(ret, "not expected ret: %lu\n", ret);
4476 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4477 ok(!ret, "not expected ret: %lu\n", ret);
4478 ok(!IsWindow(hwnd), "window should not exist\n");
4481 static void test_gettext(void)
4483 WNDCLASS cls;
4484 LPCSTR clsname = "gettexttest";
4485 HWND hwnd;
4486 LRESULT r;
4488 memset( &cls, 0, sizeof cls );
4489 cls.lpfnWndProc = DefWindowProc;
4490 cls.lpszClassName = clsname;
4491 cls.hInstance = GetModuleHandle(NULL);
4493 if (!RegisterClass( &cls )) return;
4495 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
4496 ok( hwnd != NULL, "window was null\n");
4498 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
4499 ok( r == 0, "settext should return zero\n");
4501 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
4502 ok( r == 0, "settext should return zero (%ld)\n", r);
4504 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
4505 ok( r == 0, "settext should return zero (%ld)\n", r);
4507 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
4508 ok( r == 0, "settext should return zero (%ld)\n", r);
4510 DestroyWindow(hwnd);
4511 UnregisterClass( clsname, NULL );
4515 static void test_GetUpdateRect(void)
4517 MSG msg;
4518 BOOL ret, parent_wm_paint, grandparent_wm_paint;
4519 RECT rc1, rc2;
4520 HWND hgrandparent, hparent, hchild;
4521 WNDCLASSA cls;
4522 static const char classNameA[] = "GetUpdateRectClass";
4524 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
4525 0, 0, 100, 100, NULL, NULL, 0, NULL);
4527 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
4528 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4530 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
4531 10, 10, 30, 30, hparent, NULL, 0, NULL);
4533 ShowWindow(hgrandparent, SW_SHOW);
4534 UpdateWindow(hgrandparent);
4535 flush_events( TRUE );
4537 ShowWindow(hchild, SW_HIDE);
4538 SetRect(&rc2, 0, 0, 0, 0);
4539 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4540 ok(!ret, "GetUpdateRect returned not empty region\n");
4541 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4542 rc1.left, rc1.top, rc1.right, rc1.bottom,
4543 rc2.left, rc2.top, rc2.right, rc2.bottom);
4545 SetRect(&rc2, 10, 10, 40, 40);
4546 ret = GetUpdateRect(hparent, &rc1, FALSE);
4547 ok(ret, "GetUpdateRect returned empty region\n");
4548 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4549 rc1.left, rc1.top, rc1.right, rc1.bottom,
4550 rc2.left, rc2.top, rc2.right, rc2.bottom);
4552 parent_wm_paint = FALSE;
4553 grandparent_wm_paint = FALSE;
4554 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4556 if (msg.message == WM_PAINT)
4558 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4559 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4561 DispatchMessage(&msg);
4563 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4564 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4566 DestroyWindow(hgrandparent);
4568 cls.style = 0;
4569 cls.lpfnWndProc = DefWindowProcA;
4570 cls.cbClsExtra = 0;
4571 cls.cbWndExtra = 0;
4572 cls.hInstance = GetModuleHandleA(0);
4573 cls.hIcon = 0;
4574 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
4575 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4576 cls.lpszMenuName = NULL;
4577 cls.lpszClassName = classNameA;
4579 if(!RegisterClassA(&cls)) {
4580 trace("Register failed %d\n", GetLastError());
4581 return;
4584 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
4585 0, 0, 100, 100, NULL, NULL, 0, NULL);
4587 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
4588 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4590 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
4591 10, 10, 30, 30, hparent, NULL, 0, NULL);
4593 ShowWindow(hgrandparent, SW_SHOW);
4594 UpdateWindow(hgrandparent);
4595 flush_events( TRUE );
4597 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4598 ok(!ret, "GetUpdateRect returned not empty region\n");
4600 ShowWindow(hchild, SW_HIDE);
4602 SetRect(&rc2, 0, 0, 0, 0);
4603 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4604 ok(!ret, "GetUpdateRect returned not empty region\n");
4605 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4606 rc1.left, rc1.top, rc1.right, rc1.bottom,
4607 rc2.left, rc2.top, rc2.right, rc2.bottom);
4609 SetRect(&rc2, 10, 10, 40, 40);
4610 ret = GetUpdateRect(hparent, &rc1, FALSE);
4611 ok(ret, "GetUpdateRect returned 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 parent_wm_paint = FALSE;
4617 grandparent_wm_paint = FALSE;
4618 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4620 if (msg.message == WM_PAINT)
4622 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4623 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4625 DispatchMessage(&msg);
4627 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4628 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4630 DestroyWindow(hgrandparent);
4634 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
4636 if(msg == WM_PAINT)
4638 PAINTSTRUCT ps;
4639 RECT updateRect;
4640 DWORD waitResult;
4641 HWND win;
4642 const int waitTime = 2000;
4644 BeginPaint(hwnd, &ps);
4646 /* create and destroy window to create an exposed region on this window */
4647 win = CreateWindowA("static", "win", WS_VISIBLE,
4648 10,10,50,50, NULL, NULL, 0, NULL);
4649 DestroyWindow(win);
4651 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
4653 ValidateRect(hwnd, NULL);
4654 EndPaint(hwnd, &ps);
4656 if(waitResult != WAIT_TIMEOUT)
4658 GetUpdateRect(hwnd, &updateRect, FALSE);
4659 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
4662 return 1;
4664 return DefWindowProc(hwnd, msg, wParam, lParam);
4667 static void test_Expose(void)
4669 ATOM atom;
4670 WNDCLASSA cls;
4671 HWND mw;
4672 memset(&cls, 0, sizeof(WNDCLASSA));
4673 cls.lpfnWndProc = TestExposedRegion_WndProc;
4674 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4675 cls.lpszClassName = "TestExposeClass";
4676 atom = RegisterClassA(&cls);
4678 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
4679 0, 0, 200, 100, NULL, NULL, 0, NULL);
4681 UpdateWindow(mw);
4682 DestroyWindow(mw);
4685 static void test_GetWindowModuleFileName(void)
4687 HWND hwnd;
4688 HINSTANCE hinst;
4689 UINT ret1, ret2;
4690 char buf1[MAX_PATH], buf2[MAX_PATH];
4692 if (!pGetWindowModuleFileNameA)
4694 skip("GetWindowModuleFileNameA is not available\n");
4695 return;
4698 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
4699 assert(hwnd);
4701 hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
4702 ok(hinst == 0, "expected 0, got %p\n", hinst);
4704 buf1[0] = 0;
4705 SetLastError(0xdeadbeef);
4706 ret1 = GetModuleFileName(hinst, buf1, sizeof(buf1));
4707 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
4709 buf2[0] = 0;
4710 SetLastError(0xdeadbeef);
4711 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
4712 ok(ret2, "GetWindowModuleFileNameA error %u\n", GetLastError());
4714 ok(ret1 == ret2, "%u != %u\n", ret1, ret2);
4715 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
4717 hinst = GetModuleHandle(0);
4719 SetLastError(0xdeadbeef);
4720 ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
4721 ok(ret2 == ret1 - 2, "expected %u, got %u\n", ret1 - 2, ret2);
4722 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4723 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4724 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4726 SetLastError(0xdeadbeef);
4727 ret2 = GetModuleFileName(hinst, buf2, 0);
4728 ok(!ret2, "GetModuleFileName should return 0\n");
4729 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4730 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4731 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4733 SetLastError(0xdeadbeef);
4734 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
4735 ok(ret2 == ret1 - 2, "expected %u, got %u\n", ret1 - 2, ret2);
4736 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4737 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4738 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4740 SetLastError(0xdeadbeef);
4741 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
4742 ok(!ret2, "expected 0, got %u\n", ret2);
4743 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4744 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4745 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4747 DestroyWindow(hwnd);
4749 buf2[0] = 0;
4750 hwnd = (HWND)0xdeadbeef;
4751 SetLastError(0xdeadbeef);
4752 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4753 ok(!ret1, "expected 0, got %u\n", ret1);
4754 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
4756 hwnd = GetDesktopWindow();
4757 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
4758 SetLastError(0xdeadbeef);
4759 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4760 ok(!ret1, "expected 0, got %u\n", ret1);
4762 hwnd = FindWindow("Shell_TrayWnd", NULL);
4763 ok(IsWindow(hwnd), "got invalid tray window %p\n", hwnd);
4764 SetLastError(0xdeadbeef);
4765 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4766 ok(!ret1, "expected 0, got %u\n", ret1);
4769 static void test_hwnd_message(void)
4771 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
4772 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
4774 HWND parent = 0, hwnd, found;
4775 RECT rect;
4777 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
4778 on CreateWindowExA and crash later in the test.
4779 Use UNICODE here to fail on win9x */
4780 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
4781 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
4782 if (!hwnd)
4784 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
4785 return;
4788 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
4789 if (pGetAncestor)
4791 char buffer[100];
4792 HWND root, desktop = GetDesktopWindow();
4794 parent = pGetAncestor(hwnd, GA_PARENT);
4795 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
4796 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
4797 root = pGetAncestor(hwnd, GA_ROOT);
4798 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
4799 ok( !pGetAncestor(parent, GA_PARENT), "parent shouldn't have a parent\n" );
4800 trace("parent %p root %p desktop %p\n", parent, root, desktop);
4801 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
4802 ok( !lstrcmpi( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
4803 GetWindowRect( parent, &rect );
4804 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
4805 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4807 GetWindowRect( hwnd, &rect );
4808 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
4809 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4811 /* test FindWindow behavior */
4813 found = FindWindowExA( 0, 0, 0, "message window" );
4814 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
4815 SetLastError(0xdeadbeef);
4816 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
4817 ok( found == 0, "found message window %p/%p\n", found, hwnd );
4818 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
4819 if (parent)
4821 found = FindWindowExA( parent, 0, 0, "message window" );
4822 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
4825 /* test IsChild behavior */
4827 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
4829 /* test IsWindowVisible behavior */
4831 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
4832 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
4834 DestroyWindow(hwnd);
4837 static void test_layered_window(void)
4839 HWND hwnd;
4840 COLORREF key = 0;
4841 BYTE alpha = 0;
4842 DWORD flags = 0;
4843 BOOL ret;
4845 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes)
4847 win_skip( "layered windows not supported\n" );
4848 return;
4850 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
4851 100, 100, 200, 200, 0, 0, 0, NULL);
4852 assert( hwnd );
4853 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4854 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
4855 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
4856 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
4857 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
4858 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4859 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
4860 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
4861 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4862 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4863 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4864 ok( key == 0x123456, "wrong color key %x\n", key );
4865 ok( alpha == 44, "wrong alpha %u\n", alpha );
4866 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
4868 /* clearing WS_EX_LAYERED resets attributes */
4869 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
4870 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4871 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
4872 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
4873 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4874 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
4875 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
4876 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4877 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4878 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4879 ok( key == 0x654321, "wrong color key %x\n", key );
4880 ok( alpha == 22, "wrong alpha %u\n", alpha );
4881 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
4883 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
4884 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4885 alpha = 0;
4886 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4887 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4888 ok( key == 0x888888, "wrong color key %x\n", key );
4889 /* alpha not changed on vista if LWA_ALPHA is not set */
4890 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
4891 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
4893 /* color key always changed */
4894 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
4895 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4896 alpha = 0;
4897 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4898 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4899 ok( key == 0x999999, "wrong color key %x\n", key );
4900 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
4901 ok( flags == 0, "wrong flags %x\n", flags );
4903 /* default alpha is 0 */
4904 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
4905 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
4906 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
4907 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
4908 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
4909 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
4910 ok( key == 0x222222, "wrong color key %x\n", key );
4911 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
4912 ok( flags == 0, "wrong flags %x\n", flags );
4914 DestroyWindow( hwnd );
4917 static MONITORINFO mi;
4919 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4921 switch (msg)
4923 case WM_NCCREATE:
4925 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
4926 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs->x, cs->y, cs->cx, cs->cy);
4927 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
4928 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
4929 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
4930 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
4931 cs->x, cs->y, cs->cx, cs->cy);
4932 break;
4934 case WM_GETMINMAXINFO:
4936 MINMAXINFO *minmax = (MINMAXINFO *)lp;
4937 dump_minmax_info(minmax);
4938 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
4939 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
4940 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
4941 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
4942 break;
4945 return DefWindowProc(hwnd, msg, wp, lp);
4948 static void test_fullscreen(void)
4950 static const DWORD t_style[] = {
4951 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
4953 static const DWORD t_ex_style[] = {
4954 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
4956 WNDCLASS cls;
4957 HWND hwnd;
4958 int i, j;
4959 POINT pt;
4960 RECT rc;
4961 HMONITOR hmon;
4962 LRESULT ret;
4964 if (!pGetMonitorInfoA || !pMonitorFromPoint)
4966 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
4967 return;
4970 pt.x = pt.y = 0;
4971 SetLastError(0xdeadbeef);
4972 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
4973 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
4975 mi.cbSize = sizeof(mi);
4976 SetLastError(0xdeadbeef);
4977 ret = pGetMonitorInfoA(hmon, &mi);
4978 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
4979 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
4980 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
4981 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
4983 cls.style = 0;
4984 cls.lpfnWndProc = fullscreen_wnd_proc;
4985 cls.cbClsExtra = 0;
4986 cls.cbWndExtra = 0;
4987 cls.hInstance = GetModuleHandle(0);
4988 cls.hIcon = 0;
4989 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
4990 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4991 cls.lpszMenuName = NULL;
4992 cls.lpszClassName = "fullscreen_class";
4993 RegisterClass(&cls);
4995 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
4997 DWORD style, ex_style;
4999 /* avoid a WM interaction */
5000 assert(!(t_style[i] & WS_VISIBLE));
5002 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
5004 int fixup;
5006 style = t_style[i];
5007 ex_style = t_ex_style[j];
5009 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5010 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5011 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5012 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5013 GetWindowRect(hwnd, &rc);
5014 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5015 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5016 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5017 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5018 DestroyWindow(hwnd);
5020 style = t_style[i] | WS_MAXIMIZE;
5021 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5022 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5023 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5024 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5025 GetWindowRect(hwnd, &rc);
5026 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5027 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5028 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5029 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5030 DestroyWindow(hwnd);
5032 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
5033 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5034 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5035 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5036 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5037 GetWindowRect(hwnd, &rc);
5038 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5039 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5040 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5041 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5042 DestroyWindow(hwnd);
5044 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
5045 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5046 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5047 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5048 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5049 GetWindowRect(hwnd, &rc);
5050 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5051 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5052 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5053 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5054 DestroyWindow(hwnd);
5056 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
5057 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5058 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5059 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5060 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5061 GetWindowRect(hwnd, &rc);
5062 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5063 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5064 fixup = min(abs(rc.left), abs(rc.top));
5065 InflateRect(&rc, -fixup, -fixup);
5066 /* FIXME: this doesn't work correctly in Wine for child windows yet */
5067 if (style & WS_CHILD)
5068 todo_wine
5069 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5070 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5071 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5072 else
5073 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5074 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5075 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5076 DestroyWindow(hwnd);
5078 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
5079 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5080 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5081 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5082 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5083 GetWindowRect(hwnd, &rc);
5084 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5085 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5086 fixup = min(abs(rc.left), abs(rc.top));
5087 InflateRect(&rc, -fixup, -fixup);
5088 if (style & (WS_CHILD | WS_POPUP))
5089 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5090 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5091 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5092 else
5093 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5094 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5095 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5096 DestroyWindow(hwnd);
5100 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5103 START_TEST(win)
5105 HMODULE user32 = GetModuleHandleA( "user32.dll" );
5106 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
5107 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
5108 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
5109 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
5110 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
5111 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
5112 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
5114 if (!RegisterWindowClasses()) assert(0);
5116 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
5117 assert(hhook);
5119 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
5120 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5121 WS_MAXIMIZEBOX | WS_POPUP,
5122 100, 100, 200, 200,
5123 0, 0, GetModuleHandle(0), NULL);
5124 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
5125 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5126 WS_MAXIMIZEBOX | WS_POPUP,
5127 100, 100, 200, 200,
5128 0, 0, GetModuleHandle(0), NULL);
5129 assert( hwndMain );
5130 assert( hwndMain2 );
5132 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
5134 /* Add the tests below this line */
5135 test_fullscreen();
5136 test_hwnd_message();
5137 test_nonclient_area(hwndMain);
5138 test_params();
5139 test_GetWindowModuleFileName();
5140 test_capture_1();
5141 test_capture_2();
5142 test_capture_3(hwndMain, hwndMain2);
5144 test_CreateWindow();
5145 test_parent_owner();
5146 test_SetParent();
5148 test_mdi();
5149 test_icons();
5150 test_SetWindowPos(hwndMain);
5151 test_SetMenu(hwndMain);
5152 test_SetFocus(hwndMain);
5153 test_SetActiveWindow(hwndMain);
5154 test_SetForegroundWindow(hwndMain);
5156 test_children_zorder(hwndMain);
5157 test_popup_zorder(hwndMain2, hwndMain);
5158 test_keyboard_input(hwndMain);
5159 test_mouse_input(hwndMain);
5160 test_validatergn(hwndMain);
5161 test_nccalcscroll( hwndMain);
5162 test_scrollvalidate( hwndMain);
5163 test_scrolldc( hwndMain);
5164 test_scroll();
5165 test_IsWindowUnicode();
5166 test_vis_rgn(hwndMain);
5168 test_AdjustWindowRect();
5169 test_window_styles();
5170 test_redrawnow();
5171 test_csparentdc();
5172 test_SetWindowLong();
5173 test_ShowWindow();
5174 test_gettext();
5175 test_GetUpdateRect();
5176 test_Expose();
5177 test_layered_window();
5179 test_shell_window();
5181 /* add the tests above this line */
5182 UnhookWindowsHookEx(hhook);