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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 /* To get ICON_SMALL2 with the MSVC headers */
24 #define _WIN32_WINNT 0x0501
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
39 #include "wine/test.h"
41 #ifndef SPI_GETDESKWALLPAPER
42 #define SPI_GETDESKWALLPAPER 0x0073
45 #define LONG_PTR INT_PTR
46 #define ULONG_PTR UINT_PTR
48 void dump_region(HRGN hrgn);
50 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
51 static BOOL (WINAPI *pGetWindowInfo)(HWND,WINDOWINFO*);
53 static BOOL test_lbuttondown_flag;
54 static HWND hwndMessage;
55 static HWND hwndMain, hwndMain2;
58 static const char* szAWRClass = "Winsize";
61 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
63 /* check the values returned by the various parent/owner functions on a given window */
64 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
65 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
71 res = pGetAncestor( hwnd, GA_PARENT );
72 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
74 res = (HWND)GetWindowLongA( hwnd, GWL_HWNDPARENT );
75 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
76 res = GetParent( hwnd );
77 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
78 res = GetWindow( hwnd, GW_OWNER );
79 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
82 res = pGetAncestor( hwnd, GA_ROOT );
83 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
84 res = pGetAncestor( hwnd, GA_ROOTOWNER );
85 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
90 static HWND create_tool_window( LONG style, HWND parent )
92 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
93 0, 0, 100, 100, parent, 0, 0, NULL );
94 ok( ret != 0, "Creation failed\n" );
98 /* test parent and owner values for various combinations */
99 static void test_parent_owner(void)
102 HWND test, owner, ret;
103 HWND desktop = GetDesktopWindow();
104 HWND child = create_tool_window( WS_CHILD, hwndMain );
106 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
108 /* child without parent, should fail */
109 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
110 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
111 ok( !test, "WS_CHILD without parent created\n" );
114 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
115 style = GetWindowLongA( desktop, GWL_STYLE );
116 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
117 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
118 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
120 /* normal child window */
121 test = create_tool_window( WS_CHILD, hwndMain );
122 trace( "created child %p\n", test );
123 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
124 SetWindowLongA( test, GWL_STYLE, 0 );
125 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
126 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
127 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
128 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
129 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
130 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
131 DestroyWindow( test );
133 /* normal child window with WS_MAXIMIZE */
134 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
135 DestroyWindow( test );
137 /* normal child window with WS_THICKFRAME */
138 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
139 DestroyWindow( test );
141 /* popup window with WS_THICKFRAME */
142 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
143 DestroyWindow( test );
145 /* child of desktop */
146 test = create_tool_window( WS_CHILD, desktop );
147 trace( "created child of desktop %p\n", test );
148 check_parents( test, desktop, 0, desktop, 0, test, desktop );
149 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
150 check_parents( test, desktop, 0, 0, 0, test, test );
151 SetWindowLongA( test, GWL_STYLE, 0 );
152 check_parents( test, desktop, 0, 0, 0, test, test );
153 DestroyWindow( test );
155 /* child of desktop with WS_MAXIMIZE */
156 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
157 DestroyWindow( test );
159 /* child of desktop with WS_MINIMIZE */
160 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
161 DestroyWindow( test );
164 test = create_tool_window( WS_CHILD, child );
165 trace( "created child of child %p\n", test );
166 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
167 SetWindowLongA( test, GWL_STYLE, 0 );
168 check_parents( test, child, child, 0, 0, hwndMain, test );
169 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
170 check_parents( test, child, child, 0, 0, hwndMain, test );
171 DestroyWindow( test );
173 /* child of child with WS_MAXIMIZE */
174 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
175 DestroyWindow( test );
177 /* child of child with WS_MINIMIZE */
178 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
179 DestroyWindow( test );
181 /* not owned top-level window */
182 test = create_tool_window( 0, 0 );
183 trace( "created top-level %p\n", test );
184 check_parents( test, desktop, 0, 0, 0, test, test );
185 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
186 check_parents( test, desktop, 0, 0, 0, test, test );
187 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
188 check_parents( test, desktop, 0, desktop, 0, test, desktop );
189 DestroyWindow( test );
191 /* not owned top-level window with WS_MAXIMIZE */
192 test = create_tool_window( WS_MAXIMIZE, 0 );
193 DestroyWindow( test );
195 /* owned top-level window */
196 test = create_tool_window( 0, hwndMain );
197 trace( "created owned top-level %p\n", test );
198 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
199 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
200 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
201 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
202 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
203 DestroyWindow( test );
205 /* owned top-level window with WS_MAXIMIZE */
206 test = create_tool_window( WS_MAXIMIZE, hwndMain );
207 DestroyWindow( test );
209 /* not owned popup */
210 test = create_tool_window( WS_POPUP, 0 );
211 trace( "created popup %p\n", test );
212 check_parents( test, desktop, 0, 0, 0, test, test );
213 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
214 check_parents( test, desktop, 0, desktop, 0, test, desktop );
215 SetWindowLongA( test, GWL_STYLE, 0 );
216 check_parents( test, desktop, 0, 0, 0, test, test );
217 DestroyWindow( test );
219 /* not owned popup with WS_MAXIMIZE */
220 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
221 DestroyWindow( test );
224 test = create_tool_window( WS_POPUP, hwndMain );
225 trace( "created owned popup %p\n", test );
226 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
227 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
228 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
229 SetWindowLongA( test, GWL_STYLE, 0 );
230 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
231 DestroyWindow( test );
233 /* owned popup with WS_MAXIMIZE */
234 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
235 DestroyWindow( test );
237 /* top-level window owned by child (same as owned by top-level) */
238 test = create_tool_window( 0, child );
239 trace( "created top-level owned by child %p\n", test );
240 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
241 DestroyWindow( test );
243 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
244 test = create_tool_window( WS_MAXIMIZE, child );
245 DestroyWindow( test );
247 /* popup owned by desktop (same as not owned) */
248 test = create_tool_window( WS_POPUP, desktop );
249 trace( "created popup owned by desktop %p\n", test );
250 check_parents( test, desktop, 0, 0, 0, test, test );
251 DestroyWindow( test );
253 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
254 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
255 DestroyWindow( test );
257 /* popup owned by child (same as owned by top-level) */
258 test = create_tool_window( WS_POPUP, child );
259 trace( "created popup owned by child %p\n", test );
260 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
261 DestroyWindow( test );
263 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
264 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
265 DestroyWindow( test );
267 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
268 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
269 trace( "created WS_CHILD popup %p\n", test );
270 check_parents( test, desktop, 0, 0, 0, test, test );
271 DestroyWindow( test );
273 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
274 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
275 DestroyWindow( test );
277 /* owned popup with WS_CHILD (same as WS_POPUP only) */
278 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
279 trace( "created owned WS_CHILD popup %p\n", test );
280 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
281 DestroyWindow( test );
283 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
284 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
285 DestroyWindow( test );
287 /******************** parent changes *************************/
288 trace( "testing parent changes\n" );
291 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
292 #if 0 /* this test succeeds on NT but crashes on win9x systems */
293 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
294 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
295 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
296 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
297 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
299 /* normal child window */
300 test = create_tool_window( WS_CHILD, hwndMain );
301 trace( "created child %p\n", test );
303 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
304 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
305 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
307 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)child );
308 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
309 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
311 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)desktop );
312 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
313 check_parents( test, desktop, 0, desktop, 0, test, desktop );
315 /* window is now child of desktop so GWL_HWNDPARENT changes owner from now on */
316 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)child );
317 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
318 check_parents( test, desktop, child, desktop, child, test, desktop );
320 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, 0 );
321 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
322 check_parents( test, desktop, 0, desktop, 0, test, desktop );
323 DestroyWindow( test );
325 /* not owned top-level window */
326 test = create_tool_window( 0, 0 );
327 trace( "created top-level %p\n", test );
329 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
330 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
331 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
333 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)child );
334 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
335 check_parents( test, desktop, child, 0, child, test, test );
337 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, 0 );
338 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
339 check_parents( test, desktop, 0, 0, 0, test, test );
340 DestroyWindow( test );
342 /* not owned popup */
343 test = create_tool_window( WS_POPUP, 0 );
344 trace( "created popup %p\n", test );
346 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
347 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
348 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
350 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)child );
351 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
352 check_parents( test, desktop, child, child, child, test, hwndMain );
354 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, 0 );
355 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
356 check_parents( test, desktop, 0, 0, 0, test, test );
357 DestroyWindow( test );
359 /* normal child window */
360 test = create_tool_window( WS_CHILD, hwndMain );
361 trace( "created child %p\n", test );
363 ret = SetParent( test, desktop );
364 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
365 check_parents( test, desktop, 0, desktop, 0, test, desktop );
367 ret = SetParent( test, child );
368 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
369 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
371 ret = SetParent( test, hwndMain2 );
372 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
373 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
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 = SetParent( test, child );
381 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
382 check_parents( test, child, child, 0, 0, hwndMain, test );
383 DestroyWindow( test );
386 test = create_tool_window( WS_POPUP, hwndMain2 );
387 trace( "created owned popup %p\n", test );
389 ret = SetParent( test, child );
390 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
391 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
393 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (ULONG_PTR)hwndMain );
394 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
395 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
396 DestroyWindow( test );
398 /**************** test owner destruction *******************/
400 /* owned child popup */
401 owner = create_tool_window( 0, 0 );
402 test = create_tool_window( WS_POPUP, owner );
403 trace( "created owner %p and popup %p\n", owner, test );
404 ret = SetParent( test, child );
405 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
406 check_parents( test, child, child, owner, owner, hwndMain, owner );
407 /* window is now child of 'child' but owned by 'owner' */
408 DestroyWindow( owner );
409 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
410 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
411 * while Win95, Win2k, WinXP do.
413 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
414 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
417 /* owned top-level popup */
418 owner = create_tool_window( 0, 0 );
419 test = create_tool_window( WS_POPUP, owner );
420 trace( "created owner %p and popup %p\n", owner, test );
421 check_parents( test, desktop, owner, owner, owner, test, owner );
422 DestroyWindow( owner );
423 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
425 /* top-level popup owned by child */
426 owner = create_tool_window( WS_CHILD, hwndMain2 );
427 test = create_tool_window( WS_POPUP, 0 );
428 trace( "created owner %p and popup %p\n", owner, test );
429 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (ULONG_PTR)owner );
430 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
431 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
432 DestroyWindow( owner );
433 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
434 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
435 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
436 * while Win95, Win2k, WinXP do.
438 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
442 DestroyWindow(child);
446 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
450 case WM_GETMINMAXINFO:
452 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
454 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd, wparam, lparam);
455 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
456 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
457 minmax->ptReserved.x, minmax->ptReserved.y,
458 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
459 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
460 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
461 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
462 SetWindowLongA(hwnd, GWL_USERDATA, 0x20031021);
465 case WM_WINDOWPOSCHANGING:
467 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
468 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
469 trace("main: WM_WINDOWPOSCHANGING\n");
470 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
471 winpos->hwnd, winpos->hwndInsertAfter,
472 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
473 if (!(winpos->flags & SWP_NOMOVE))
475 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
476 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
478 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
479 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
481 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
482 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
486 case WM_WINDOWPOSCHANGED:
489 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
490 trace("main: WM_WINDOWPOSCHANGED\n");
491 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
492 winpos->hwnd, winpos->hwndInsertAfter,
493 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
494 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
495 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
497 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
498 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
500 GetWindowRect(hwnd, &rc1);
501 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
502 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
503 /* note: winpos coordinates are relative to parent */
504 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
505 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
506 #if 0 /* Uncomment this once the test succeeds in all cases */
507 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
510 GetClientRect(hwnd, &rc2);
511 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
512 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
513 ok(EqualRect(&rc1, &rc2), "rects do not match (%ld,%ld-%ld,%ld) / (%ld,%ld-%ld,%ld)\n",
514 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
519 BOOL got_getminmaxinfo = GetWindowLongA(hwnd, GWL_USERDATA) == 0x20031021;
520 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
522 trace("WM_NCCREATE: hwnd %p, parent %p, style %08lx\n", hwnd, cs->hwndParent, cs->style);
523 if (got_getminmaxinfo)
524 trace("%p got WM_GETMINMAXINFO\n", hwnd);
526 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
527 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
529 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
533 if (test_lbuttondown_flag)
534 ShowWindow((HWND)wparam, SW_SHOW);
538 return DefWindowProcA(hwnd, msg, wparam, lparam);
541 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
545 case WM_GETMINMAXINFO:
547 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
549 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd, wparam, lparam);
550 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
551 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
552 minmax->ptReserved.x, minmax->ptReserved.y,
553 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
554 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
555 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
556 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
557 SetWindowLongA(hwnd, GWL_USERDATA, 0x20031021);
562 BOOL got_getminmaxinfo = GetWindowLongA(hwnd, GWL_USERDATA) == 0x20031021;
563 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
565 trace("WM_NCCREATE: hwnd %p, parent %p, style %08lx\n", hwnd, cs->hwndParent, cs->style);
566 if (got_getminmaxinfo)
567 trace("%p got WM_GETMINMAXINFO\n", hwnd);
569 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
570 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
572 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
577 return DefWindowProcA(hwnd, msg, wparam, lparam);
580 static BOOL RegisterWindowClasses(void)
584 cls.style = CS_DBLCLKS;
585 cls.lpfnWndProc = main_window_procA;
588 cls.hInstance = GetModuleHandleA(0);
590 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
591 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
592 cls.lpszMenuName = NULL;
593 cls.lpszClassName = "MainWindowClass";
595 if(!RegisterClassA(&cls)) return FALSE;
598 cls.lpfnWndProc = tool_window_procA;
601 cls.hInstance = GetModuleHandleA(0);
603 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
604 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
605 cls.lpszMenuName = NULL;
606 cls.lpszClassName = "ToolWindowClass";
608 if(!RegisterClassA(&cls)) return FALSE;
613 static void verify_window_info(HWND hwnd, const WINDOWINFO *info, BOOL test_borders)
615 RECT rcWindow, rcClient;
619 ok(IsWindow(hwnd), "bad window handle\n");
621 GetWindowRect(hwnd, &rcWindow);
622 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow\n");
624 GetClientRect(hwnd, &rcClient);
625 /* translate to screen coordinates */
626 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
627 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient\n");
629 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
630 "wrong dwStyle: %08lx != %08lx\n", info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE));
631 ok(info->dwExStyle == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
632 "wrong dwExStyle: %08lx != %08lx\n", info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE));
633 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
634 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04lx != %04lx\n",
635 info->dwWindowStatus, status);
637 if (test_borders && !IsRectEmpty(&rcWindow))
639 trace("rcWindow: %ld,%ld - %ld,%ld\n", rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
640 trace("rcClient: %ld,%ld - %ld,%ld\n", rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
642 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
643 "wrong cxWindowBorders %d != %ld\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
644 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
645 ok(info->cyWindowBorders == border,
646 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
649 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType\n");
650 ok(info->wCreatorVersion == 0x0400, "wrong wCreatorVersion %04x\n", info->wCreatorVersion);
653 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
655 AdjustWindowRectEx(rc, style, menu, exstyle);
656 /* AdjustWindowRectEx does not include scroll bars */
657 if (style & WS_VSCROLL)
659 if(exstyle & WS_EX_LEFTSCROLLBAR)
660 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
662 rc->right += GetSystemMetrics(SM_CXVSCROLL);
664 if (style & WS_HSCROLL)
665 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
668 static void test_nonclient_area(HWND hwnd)
670 DWORD style, exstyle;
671 RECT rc_window, rc_client, rc;
673 BOOL is_win9x = GetWindowLongW(hwnd, GWL_WNDPROC) == 0;
675 style = GetWindowLongA(hwnd, GWL_STYLE);
676 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
677 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
679 GetWindowRect(hwnd, &rc_window);
680 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
681 GetClientRect(hwnd, &rc_client);
682 trace("client: (%ld,%ld)-(%ld,%ld)\n", rc_client.left, rc_client.top, rc_client.right, rc_client.bottom);
684 /* avoid some cases when things go wrong */
685 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
686 rc_window.right > 32768 || rc_window.bottom > 32768) return;
688 CopyRect(&rc, &rc_client);
689 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
690 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
692 trace("calc window: (%ld,%ld)-(%ld,%ld)\n", rc.left, rc.top, rc.right, rc.bottom);
693 ok(EqualRect(&rc, &rc_window), "window rect does not match: style:exstyle=0x%08lx:0x%08lx, menu=%d\n", style, exstyle, menu);
696 CopyRect(&rc, &rc_window);
697 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
698 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
699 trace("calc client: (%ld,%ld)-(%ld,%ld)\n", rc.left, rc.top, rc.right, rc.bottom);
700 ok(EqualRect(&rc, &rc_client), "client rect does not match: style:exstyle=0x%08lx:0x%08lx, menu=%d\n", style, exstyle, menu);
702 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
706 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
707 SetRect(&rc_client, 0, 0, 250, 150);
708 CopyRect(&rc_window, &rc_client);
709 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
710 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
711 trace("calc window: (%ld,%ld)-(%ld,%ld)\n",
712 rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
714 CopyRect(&rc, &rc_window);
715 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
716 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
717 trace("calc client: (%ld,%ld)-(%ld,%ld)\n", rc.left, rc.top, rc.right, rc.bottom);
718 ok(EqualRect(&rc, &rc_client), "synthetic rect does not match: style:exstyle=0x%08lx:0x%08lx, menu=%d\n", style, exstyle, menu);
721 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
723 static const char *CBT_code_name[10] = {
734 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
736 trace("CBT: %d (%s), %08x, %08lx\n", nCode, code_name, wParam, lParam);
738 /* on HCBT_DESTROYWND window state is undefined */
739 if (nCode != HCBT_DESTROYWND && IsWindow((HWND)wParam))
745 /* Win98 actually does check the info.cbSize and doesn't allow
746 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
747 * WinXP do not check it at all.
749 info.cbSize = sizeof(WINDOWINFO);
750 ok(pGetWindowInfo((HWND)wParam, &info), "GetWindowInfo should not fail\n");
751 /* win2k SP4 returns broken border info if GetWindowInfo
752 * is being called from HCBT_DESTROYWND or HCBT_MINMAX hook proc.
754 verify_window_info((HWND)wParam, &info, nCode != HCBT_MINMAX);
762 #if 0 /* Uncomment this once the test succeeds in all cases */
763 static const RECT rc_null;
767 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
768 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08lx\n",
769 (HWND)wParam, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
770 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
772 /* WS_VISIBLE should be turned off yet */
773 style = createwnd->lpcs->style & ~WS_VISIBLE;
774 ok(style == GetWindowLongA((HWND)wParam, GWL_STYLE),
775 "style of hwnd and style in the CREATESTRUCT do not match: %08lx != %08lx\n",
776 GetWindowLongA((HWND)wParam, GWL_STYLE), style);
778 #if 0 /* Uncomment this once the test succeeds in all cases */
779 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
781 ok(GetParent((HWND)wParam) == hwndMessage,
782 "wrong result from GetParent %p: message window %p\n",
783 GetParent((HWND)wParam), hwndMessage);
786 ok(!GetParent((HWND)wParam), "GetParent should return 0 at this point\n");
788 ok(!GetWindow((HWND)wParam, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
790 #if 0 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
791 * Win9x still has them set to 0.
793 ok(GetWindow((HWND)wParam, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
794 ok(GetWindow((HWND)wParam, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
796 ok(!GetWindow((HWND)wParam, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
797 ok(!GetWindow((HWND)wParam, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
799 #if 0 /* Uncomment this once the test succeeds in all cases */
802 ok(pGetAncestor((HWND)wParam, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
803 ok(pGetAncestor((HWND)wParam, GA_ROOT) == (HWND)wParam,
804 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOT), (HWND)wParam);
806 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
807 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == hwndMessage,
808 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
810 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == (HWND)wParam,
811 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOTOWNER), (HWND)wParam);
814 ok(GetWindowRect((HWND)wParam, &rc), "GetWindowRect failed\n");
815 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
816 ok(GetClientRect((HWND)wParam, &rc), "GetClientRect failed\n");
817 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
823 return CallNextHookEx(hhook, nCode, wParam, lParam);
826 static void test_shell_window(void)
830 HMODULE hinst, hUser32;
831 BOOL (WINAPI*SetShellWindow)(HWND);
832 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
833 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
834 HWND shellWindow, nextWnd;
836 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
838 trace("Skipping shell window test on Win9x\n");
842 shellWindow = GetShellWindow();
843 hinst = GetModuleHandle(0);
844 hUser32 = GetModuleHandleA("user32");
846 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
847 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
849 trace("previous shell window: %p\n", shellWindow);
855 ret = DestroyWindow(shellWindow);
856 error = GetLastError();
858 ok(!ret, "DestroyWindow(shellWindow)\n");
859 /* passes on Win XP, but not on Win98 */
860 ok(error==ERROR_ACCESS_DENIED, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n");
862 /* close old shell instance */
863 GetWindowThreadProcessId(shellWindow, &pid);
864 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
865 ret = TerminateProcess(hProcess, 0);
866 ok(ret, "termination of previous shell process failed: GetLastError()=%ld\n", GetLastError());
867 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
868 CloseHandle(hProcess);
871 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
872 trace("created window 1: %p\n", hwnd1);
874 ret = SetShellWindow(hwnd1);
875 ok(ret, "first call to SetShellWindow(hwnd1)\n");
876 shellWindow = GetShellWindow();
877 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
879 ret = SetShellWindow(hwnd1);
880 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
882 ret = SetShellWindow(0);
883 error = GetLastError();
884 /* passes on Win XP, but not on Win98
885 ok(!ret, "reset shell window by SetShellWindow(0)\n");
886 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
888 ret = SetShellWindow(hwnd1);
889 /* passes on Win XP, but not on Win98
890 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
894 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
895 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
896 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
899 ret = DestroyWindow(hwnd1);
900 ok(ret, "DestroyWindow(hwnd1)\n");
902 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
903 trace("created window 2: %p\n", hwnd2);
904 ret = SetShellWindow(hwnd2);
905 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
907 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
908 trace("created window 3: %p\n", hwnd3);
910 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
911 trace("created window 4: %p\n", hwnd4);
913 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
914 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
916 ret = SetShellWindow(hwnd4);
917 ok(ret, "SetShellWindow(hwnd4)\n");
918 shellWindow = GetShellWindow();
919 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
921 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
922 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
924 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
925 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
927 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
928 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
930 ret = SetShellWindow(hwnd3);
931 ok(!ret, "SetShellWindow(hwnd3)\n");
932 shellWindow = GetShellWindow();
933 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
935 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
936 trace("created window 5: %p\n", hwnd5);
937 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
938 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
942 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
943 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
946 /* destroy test windows */
947 DestroyWindow(hwnd2);
948 DestroyWindow(hwnd3);
949 DestroyWindow(hwnd4);
950 DestroyWindow(hwnd5);
953 /************** MDI test ****************/
955 static const char mdi_lParam_test_message[] = "just a test string";
957 static void test_MDI_create(HWND parent, HWND mdi_client, INT first_id)
959 MDICREATESTRUCTA mdi_cs;
961 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
962 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
963 BOOL isWin9x = FALSE;
965 mdi_cs.szClass = "MDI_child_Class_1";
966 mdi_cs.szTitle = "MDI child";
967 mdi_cs.hOwner = GetModuleHandle(0);
968 mdi_cs.x = CW_USEDEFAULT;
969 mdi_cs.y = CW_USEDEFAULT;
970 mdi_cs.cx = CW_USEDEFAULT;
971 mdi_cs.cy = CW_USEDEFAULT;
973 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
974 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
975 ok(mdi_child != 0, "MDI child creation failed\n");
976 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
977 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
978 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
980 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
981 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
982 ok(mdi_child != 0, "MDI child creation failed\n");
983 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
984 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
985 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
987 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
988 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
989 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
991 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
995 ok(mdi_child != 0, "MDI child creation failed\n");
996 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
997 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
998 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1001 /* test MDICREATESTRUCT A<->W mapping */
1002 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1004 mdi_cs.szClass = (LPCSTR)classW;
1005 mdi_cs.szTitle = (LPCSTR)titleW;
1006 SetLastError(0xdeadbeef);
1007 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1010 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1013 ok(mdi_child != 0, "MDI child creation failed\n");
1017 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1018 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1019 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1022 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1024 CW_USEDEFAULT, CW_USEDEFAULT,
1025 CW_USEDEFAULT, CW_USEDEFAULT,
1026 mdi_client, GetModuleHandle(0),
1027 (LPARAM)mdi_lParam_test_message);
1028 ok(mdi_child != 0, "MDI child creation failed\n");
1029 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1030 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1031 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1033 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1034 0x7fffffff, /* without WS_POPUP */
1035 CW_USEDEFAULT, CW_USEDEFAULT,
1036 CW_USEDEFAULT, CW_USEDEFAULT,
1037 mdi_client, GetModuleHandle(0),
1038 (LPARAM)mdi_lParam_test_message);
1039 ok(mdi_child != 0, "MDI child creation failed\n");
1040 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1041 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1042 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1044 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1045 0xffffffff, /* with WS_POPUP */
1046 CW_USEDEFAULT, CW_USEDEFAULT,
1047 CW_USEDEFAULT, CW_USEDEFAULT,
1048 mdi_client, GetModuleHandle(0),
1049 (LPARAM)mdi_lParam_test_message);
1050 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1052 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1056 ok(mdi_child != 0, "MDI child creation failed\n");
1057 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1058 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1059 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1062 /* test MDICREATESTRUCT A<->W mapping */
1063 SetLastError(0xdeadbeef);
1064 mdi_child = CreateMDIWindowW(classW, titleW,
1066 CW_USEDEFAULT, CW_USEDEFAULT,
1067 CW_USEDEFAULT, CW_USEDEFAULT,
1068 mdi_client, GetModuleHandle(0),
1069 (LPARAM)mdi_lParam_test_message);
1072 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1075 ok(mdi_child != 0, "MDI child creation failed\n");
1079 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1080 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1081 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1084 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1086 CW_USEDEFAULT, CW_USEDEFAULT,
1087 CW_USEDEFAULT, CW_USEDEFAULT,
1088 mdi_client, 0, GetModuleHandle(0),
1089 (LPVOID)mdi_lParam_test_message);
1090 ok(mdi_child != 0, "MDI child creation failed\n");
1091 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1092 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1093 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1095 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1096 0x7fffffff, /* without WS_POPUP */
1097 CW_USEDEFAULT, CW_USEDEFAULT,
1098 CW_USEDEFAULT, CW_USEDEFAULT,
1099 mdi_client, 0, GetModuleHandle(0),
1100 (LPVOID)mdi_lParam_test_message);
1101 ok(mdi_child != 0, "MDI child creation failed\n");
1102 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1103 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1104 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1106 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1107 0xffffffff, /* with WS_POPUP */
1108 CW_USEDEFAULT, CW_USEDEFAULT,
1109 CW_USEDEFAULT, CW_USEDEFAULT,
1110 mdi_client, 0, GetModuleHandle(0),
1111 (LPVOID)mdi_lParam_test_message);
1112 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1114 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1118 ok(mdi_child != 0, "MDI child creation failed\n");
1119 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1120 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1121 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1124 /* test MDICREATESTRUCT A<->W mapping */
1125 SetLastError(0xdeadbeef);
1126 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1128 CW_USEDEFAULT, CW_USEDEFAULT,
1129 CW_USEDEFAULT, CW_USEDEFAULT,
1130 mdi_client, 0, GetModuleHandle(0),
1131 (LPVOID)mdi_lParam_test_message);
1134 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1137 ok(mdi_child != 0, "MDI child creation failed\n");
1141 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1142 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1143 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1146 /* This test fails on Win9x */
1149 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1151 CW_USEDEFAULT, CW_USEDEFAULT,
1152 CW_USEDEFAULT, CW_USEDEFAULT,
1153 parent, 0, GetModuleHandle(0),
1154 (LPVOID)mdi_lParam_test_message);
1155 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1158 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1159 WS_CHILD, /* without WS_POPUP */
1160 CW_USEDEFAULT, CW_USEDEFAULT,
1161 CW_USEDEFAULT, CW_USEDEFAULT,
1162 mdi_client, 0, GetModuleHandle(0),
1163 (LPVOID)mdi_lParam_test_message);
1164 ok(mdi_child != 0, "MDI child creation failed\n");
1165 ok(GetWindowLongA(mdi_child, GWL_ID) == 0, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1166 DestroyWindow(mdi_child);
1168 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1169 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1170 CW_USEDEFAULT, CW_USEDEFAULT,
1171 CW_USEDEFAULT, CW_USEDEFAULT,
1172 mdi_client, 0, GetModuleHandle(0),
1173 (LPVOID)mdi_lParam_test_message);
1174 ok(mdi_child != 0, "MDI child creation failed\n");
1175 ok(GetWindowLongA(mdi_child, GWL_ID) == 0, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1176 DestroyWindow(mdi_child);
1178 /* maximized child */
1179 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1180 WS_CHILD | WS_MAXIMIZE,
1181 CW_USEDEFAULT, CW_USEDEFAULT,
1182 CW_USEDEFAULT, CW_USEDEFAULT,
1183 mdi_client, 0, GetModuleHandle(0),
1184 (LPVOID)mdi_lParam_test_message);
1185 ok(mdi_child != 0, "MDI child creation failed\n");
1186 ok(GetWindowLongA(mdi_child, GWL_ID) == 0, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1187 DestroyWindow(mdi_child);
1189 trace("Creating maximized child with a caption\n");
1190 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1191 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1192 CW_USEDEFAULT, CW_USEDEFAULT,
1193 CW_USEDEFAULT, CW_USEDEFAULT,
1194 mdi_client, 0, GetModuleHandle(0),
1195 (LPVOID)mdi_lParam_test_message);
1196 ok(mdi_child != 0, "MDI child creation failed\n");
1197 ok(GetWindowLongA(mdi_child, GWL_ID) == 0, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1198 DestroyWindow(mdi_child);
1200 trace("Creating maximized child with a caption and a thick frame\n");
1201 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1202 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1203 CW_USEDEFAULT, CW_USEDEFAULT,
1204 CW_USEDEFAULT, CW_USEDEFAULT,
1205 mdi_client, 0, GetModuleHandle(0),
1206 (LPVOID)mdi_lParam_test_message);
1207 ok(mdi_child != 0, "MDI child creation failed\n");
1208 ok(GetWindowLongA(mdi_child, GWL_ID) == 0, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1209 DestroyWindow(mdi_child);
1212 /**********************************************************************
1213 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1215 * Note: The rule here is that client rect of the maximized MDI child
1216 * is equal to the client rect of the MDI client window.
1218 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1222 GetClientRect( client, &rect );
1223 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1224 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1226 rect.right -= rect.left;
1227 rect.bottom -= rect.top;
1228 lpMinMax->ptMaxSize.x = rect.right;
1229 lpMinMax->ptMaxSize.y = rect.bottom;
1231 lpMinMax->ptMaxPosition.x = rect.left;
1232 lpMinMax->ptMaxPosition.y = rect.top;
1234 trace("max rect (%ld,%ld - %ld, %ld)\n",
1235 rect.left, rect.top, rect.right, rect.bottom);
1238 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1245 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1246 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs->lpCreateParams;
1248 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1249 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1251 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1252 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1253 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1254 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1255 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1257 /* MDICREATESTRUCT should have original values */
1258 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1259 "mdi_cs->style does not match (%08lx)\n", mdi_cs->style);
1260 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1261 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1262 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1263 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1265 /* CREATESTRUCT should have fixed values */
1266 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1267 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1269 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1270 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1271 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1273 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1275 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1277 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1278 ok(cs->style == style,
1279 "cs->style does not match (%08lx)\n", cs->style);
1283 LONG style = mdi_cs->style;
1285 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1286 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1287 ok(cs->style == style,
1288 "cs->style does not match (%08lx)\n", cs->style);
1293 case WM_GETMINMAXINFO:
1295 HWND client = GetParent(hwnd);
1297 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1298 MINMAXINFO my_minmax;
1299 LONG style, exstyle;
1301 style = GetWindowLongA(hwnd, GWL_STYLE);
1302 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1304 GetWindowRect(client, &rc);
1305 trace("MDI client %p window size = (%ld x %ld)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1306 GetClientRect(client, &rc);
1307 trace("MDI client %p client size = (%ld x %ld)\n", client, rc.right, rc.bottom);
1308 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1309 GetSystemMetrics(SM_CYSCREEN));
1311 GetClientRect(client, &rc);
1312 if ((style & WS_CAPTION) == WS_CAPTION)
1313 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1314 AdjustWindowRectEx(&rc, style, 0, exstyle);
1315 trace("MDI child: calculated max window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1317 trace("ptReserved = (%ld,%ld)\n"
1318 "ptMaxSize = (%ld,%ld)\n"
1319 "ptMaxPosition = (%ld,%ld)\n"
1320 "ptMinTrackSize = (%ld,%ld)\n"
1321 "ptMaxTrackSize = (%ld,%ld)\n",
1322 minmax->ptReserved.x, minmax->ptReserved.y,
1323 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1324 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1325 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1326 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1328 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1329 minmax->ptMaxSize.x, rc.right - rc.left);
1330 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1331 minmax->ptMaxSize.y, rc.bottom - rc.top);
1333 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1335 trace("DefMDIChildProc returned:\n"
1336 "ptReserved = (%ld,%ld)\n"
1337 "ptMaxSize = (%ld,%ld)\n"
1338 "ptMaxPosition = (%ld,%ld)\n"
1339 "ptMinTrackSize = (%ld,%ld)\n"
1340 "ptMaxTrackSize = (%ld,%ld)\n",
1341 minmax->ptReserved.x, minmax->ptReserved.y,
1342 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1343 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1344 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1345 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1347 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1348 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %ld != %ld\n",
1349 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1350 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %ld != %ld\n",
1351 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1356 case WM_MDIACTIVATE:
1358 HWND active, client = GetParent(hwnd);
1359 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1360 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1361 if (hwnd == (HWND)lparam) /* if we are being activated */
1362 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1364 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1368 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1371 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1378 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1380 trace("%s\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE");
1381 trace("x %d, y %d, cx %d, cy %d\n", cs->x, cs->y, cs->cx, cs->cy);
1383 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1384 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1386 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1387 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1389 /* CREATESTRUCT should have fixed values */
1390 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1392 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1393 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1395 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1396 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1397 while Win95, Win2k, WinXP do. */
1398 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1399 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1403 case WM_GETMINMAXINFO:
1405 HWND parent = GetParent(hwnd);
1407 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1408 LONG style, exstyle;
1410 trace("WM_GETMINMAXINFO\n");
1412 style = GetWindowLongA(hwnd, GWL_STYLE);
1413 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1415 GetClientRect(parent, &rc);
1416 trace("parent %p client size = (%ld x %ld)\n", parent, rc.right, rc.bottom);
1418 GetClientRect(parent, &rc);
1419 if ((style & WS_CAPTION) == WS_CAPTION)
1420 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1421 AdjustWindowRectEx(&rc, style, 0, exstyle);
1422 trace("calculated max child window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1424 trace("ptReserved = (%ld,%ld)\n"
1425 "ptMaxSize = (%ld,%ld)\n"
1426 "ptMaxPosition = (%ld,%ld)\n"
1427 "ptMinTrackSize = (%ld,%ld)\n"
1428 "ptMaxTrackSize = (%ld,%ld)\n",
1429 minmax->ptReserved.x, minmax->ptReserved.y,
1430 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1431 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1432 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1433 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1435 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1436 minmax->ptMaxSize.x, rc.right - rc.left);
1437 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1438 minmax->ptMaxSize.y, rc.bottom - rc.top);
1442 case WM_WINDOWPOSCHANGED:
1444 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1447 GetWindowRect(hwnd, &rc1);
1448 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1449 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1450 /* note: winpos coordinates are relative to parent */
1451 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1452 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1453 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1455 GetWindowRect(hwnd, &rc1);
1456 GetClientRect(hwnd, &rc2);
1457 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1458 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1459 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1462 case WM_WINDOWPOSCHANGING:
1464 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1465 WINDOWPOS my_winpos = *winpos;
1467 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1468 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1469 winpos->hwnd, winpos->hwndInsertAfter,
1470 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1472 DefWindowProcA(hwnd, msg, wparam, lparam);
1474 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1475 winpos->hwnd, winpos->hwndInsertAfter,
1476 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1478 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1479 "DefWindowProc should not change WINDOWPOS values\n");
1484 return DefWindowProcA(hwnd, msg, wparam, lparam);
1487 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1489 static HWND mdi_client;
1495 CLIENTCREATESTRUCT client_cs;
1498 GetClientRect(hwnd, &rc);
1500 client_cs.hWindowMenu = 0;
1501 client_cs.idFirstChild = 1;
1503 /* MDIClient without MDIS_ALLCHILDSTYLES */
1504 mdi_client = CreateWindowExA(0, "mdiclient",
1506 WS_CHILD /*| WS_VISIBLE*/,
1507 /* tests depend on a not zero MDIClient size */
1508 0, 0, rc.right, rc.bottom,
1509 hwnd, 0, GetModuleHandle(0),
1510 (LPVOID)&client_cs);
1512 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1513 DestroyWindow(mdi_client);
1515 /* MDIClient with MDIS_ALLCHILDSTYLES */
1516 mdi_client = CreateWindowExA(0, "mdiclient",
1518 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1519 /* tests depend on a not zero MDIClient size */
1520 0, 0, rc.right, rc.bottom,
1521 hwnd, 0, GetModuleHandle(0),
1522 (LPVOID)&client_cs);
1524 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1525 DestroyWindow(mdi_client);
1529 case WM_WINDOWPOSCHANGED:
1531 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1534 GetWindowRect(hwnd, &rc1);
1535 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1536 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1537 /* note: winpos coordinates are relative to parent */
1538 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1539 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1540 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1542 GetWindowRect(hwnd, &rc1);
1543 GetClientRect(hwnd, &rc2);
1544 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1545 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1546 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1549 case WM_WINDOWPOSCHANGING:
1551 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1552 WINDOWPOS my_winpos = *winpos;
1554 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1555 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1556 winpos->hwnd, winpos->hwndInsertAfter,
1557 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1559 DefWindowProcA(hwnd, msg, wparam, lparam);
1561 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1562 winpos->hwnd, winpos->hwndInsertAfter,
1563 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1565 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1566 "DefWindowProc should not change WINDOWPOS values\n");
1575 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1578 static BOOL mdi_RegisterWindowClasses(void)
1583 cls.lpfnWndProc = mdi_main_wnd_procA;
1586 cls.hInstance = GetModuleHandleA(0);
1588 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1589 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1590 cls.lpszMenuName = NULL;
1591 cls.lpszClassName = "MDI_parent_Class";
1592 if(!RegisterClassA(&cls)) return FALSE;
1594 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1595 cls.lpszClassName = "MDI_child_Class_1";
1596 if(!RegisterClassA(&cls)) return FALSE;
1598 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1599 cls.lpszClassName = "MDI_child_Class_2";
1600 if(!RegisterClassA(&cls)) return FALSE;
1605 static void test_mdi(void)
1610 if (!mdi_RegisterWindowClasses()) assert(0);
1612 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1613 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1614 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1615 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1616 GetDesktopWindow(), 0,
1617 GetModuleHandle(0), NULL);
1618 assert(mdi_hwndMain);
1620 while(GetMessage(&msg, 0, 0, 0))
1622 TranslateMessage(&msg);
1623 DispatchMessage(&msg);
1628 static void test_icons(void)
1632 HICON icon = LoadIconA(0, (LPSTR)IDI_APPLICATION);
1633 HICON icon2 = LoadIconA(0, (LPSTR)IDI_QUESTION);
1634 HICON small_icon = LoadImageA(0, (LPSTR)IDI_APPLICATION, IMAGE_ICON,
1635 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1638 cls.cbSize = sizeof(cls);
1640 cls.lpfnWndProc = DefWindowProcA;
1644 cls.hIcon = LoadIconA(0, (LPSTR)IDI_HAND);
1645 cls.hIconSm = small_icon;
1646 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1647 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1648 cls.lpszMenuName = NULL;
1649 cls.lpszClassName = "IconWindowClass";
1651 RegisterClassExA(&cls);
1653 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1654 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1657 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1658 ok( res == 0, "wrong big icon %p/0\n", res );
1659 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1660 ok( res == 0, "wrong previous big icon %p/0\n", res );
1661 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1662 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1663 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1664 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1665 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1666 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1668 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1669 ok( res == 0, "wrong small icon %p/0\n", res );
1670 /* this test is XP specific */
1671 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1672 ok( res != 0, "wrong small icon %p\n", res );*/
1673 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1674 ok( res == 0, "wrong previous small icon %p/0\n", res );
1675 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1676 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1677 /* this test is XP specific */
1678 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1679 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1680 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1681 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1682 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1683 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1684 /* this test is XP specific */
1685 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1686 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1688 /* make sure the big icon hasn't changed */
1689 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1690 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1693 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1695 if (msg == WM_NCCALCSIZE)
1697 RECT *rect = (RECT *)lparam;
1698 /* first time around increase the rectangle, next time decrease it */
1699 if (rect->left == 100) InflateRect( rect, 10, 10 );
1700 else InflateRect( rect, -10, -10 );
1703 return DefWindowProc( hwnd, msg, wparam, lparam );
1706 static void test_SetWindowPos(HWND hwnd)
1708 RECT orig_win_rc, rect;
1710 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1712 SetRect(&rect, 111, 222, 333, 444);
1713 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1714 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1715 "wrong window rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1717 SetRect(&rect, 111, 222, 333, 444);
1718 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1719 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1720 "wrong window rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1722 GetWindowRect(hwnd, &orig_win_rc);
1724 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1725 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1726 GetWindowRect( hwnd, &rect );
1727 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1728 "invalid window rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1729 GetClientRect( hwnd, &rect );
1730 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1731 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1732 "invalid client rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1734 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1735 GetWindowRect( hwnd, &rect );
1736 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1737 "invalid window rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1738 GetClientRect( hwnd, &rect );
1739 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1740 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1741 "invalid client rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1743 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1744 orig_win_rc.right, orig_win_rc.bottom, 0);
1745 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1747 /* Win9x truncates coordinates to 16-bit irrespectively */
1750 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1751 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1753 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1754 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1757 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1758 orig_win_rc.right, orig_win_rc.bottom, 0);
1761 static void test_SetMenu(HWND parent)
1765 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1769 hMenu = CreateMenu();
1772 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1774 /* fails on (at least) Wine, NT4, XP SP2 */
1775 test_nonclient_area(parent);
1777 ret = GetMenu(parent);
1778 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1779 /* test whether we can destroy a menu assigned to a window */
1780 retok = DestroyMenu(hMenu);
1781 ok( retok, "DestroyMenu error %ld\n", GetLastError());
1782 ok(!IsMenu(hMenu), "menu handle should be not valid after DestroyMenu\n");
1783 ret = GetMenu(parent);
1784 /* This test fails on Win9x */
1786 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1787 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1788 test_nonclient_area(parent);
1790 hMenu = CreateMenu();
1794 ret = GetMenu(parent);
1795 ok(ret == 0, "unexpected menu id %p\n", ret);
1797 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1798 test_nonclient_area(parent);
1799 ret = GetMenu(parent);
1800 ok(ret == 0, "unexpected menu id %p\n", ret);
1802 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1804 /* fails on (at least) Wine, NT4, XP SP2 */
1805 test_nonclient_area(parent);
1807 ret = GetMenu(parent);
1808 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1810 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1811 test_nonclient_area(parent);
1812 ret = GetMenu(parent);
1813 ok(ret == 0, "unexpected menu id %p\n", ret);
1816 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1819 ret = GetMenu(child);
1820 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1822 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1823 test_nonclient_area(child);
1824 ret = GetMenu(child);
1825 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1827 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1828 test_nonclient_area(child);
1829 ret = GetMenu(child);
1830 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1832 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1833 test_nonclient_area(child);
1834 ret = GetMenu(child);
1835 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1837 style = GetWindowLong(child, GWL_STYLE);
1838 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
1839 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
1840 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
1841 SetWindowLong(child, GWL_STYLE, style);
1843 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
1844 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
1845 SetWindowLong(child, GWL_STYLE, style);
1847 DestroyWindow(child);
1851 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1853 HWND child[5], hwnd;
1858 hwnd = GetWindow(parent, GW_CHILD);
1859 ok(!hwnd, "have to start without children to perform the test\n");
1861 for (i = 0; i < total; i++)
1863 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
1864 parent, 0, 0, NULL);
1865 trace("child[%d] = %p\n", i, child[i]);
1866 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
1869 hwnd = GetWindow(parent, GW_CHILD);
1870 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
1871 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
1872 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
1874 for (i = 0; i < total; i++)
1876 trace("hwnd[%d] = %p\n", i, hwnd);
1877 ok(child[order[i]] == hwnd, "Z order of child #%d is wrong\n", i);
1879 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1882 for (i = 0; i < total; i++)
1883 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
1886 static void test_children_zorder(HWND parent)
1888 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
1890 const int simple_order[5] = { 0, 1, 2, 3, 4 };
1892 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
1893 WS_CHILD | WS_VISIBLE, WS_CHILD,
1894 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
1895 const int complex_order_1[1] = { 0 };
1896 const int complex_order_2[2] = { 1, 0 };
1897 const int complex_order_3[3] = { 1, 0, 2 };
1898 const int complex_order_4[4] = { 1, 0, 2, 3 };
1899 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
1901 /* simple WS_CHILD */
1902 test_window_tree(parent, simple_style, simple_order, 5);
1904 /* complex children styles */
1905 test_window_tree(parent, complex_style, complex_order_1, 1);
1906 test_window_tree(parent, complex_style, complex_order_2, 2);
1907 test_window_tree(parent, complex_style, complex_order_3, 3);
1908 test_window_tree(parent, complex_style, complex_order_4, 4);
1909 test_window_tree(parent, complex_style, complex_order_5, 5);
1912 static void test_SetFocus(HWND hwnd)
1916 /* check if we can set focus to non-visible windows */
1918 ShowWindow(hwnd, SW_SHOW);
1921 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
1922 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
1923 ShowWindow(hwnd, SW_HIDE);
1926 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
1927 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
1928 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
1931 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
1932 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
1933 ShowWindow(child, SW_SHOW);
1934 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
1935 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
1936 ShowWindow(child, SW_HIDE);
1937 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
1938 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
1939 ShowWindow(child, SW_SHOW);
1941 ok( GetFocus() == child, "Focus should be on child %p\n", child );
1942 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
1943 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
1945 ShowWindow(child, SW_HIDE);
1947 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
1948 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
1949 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
1950 ShowWindow(child, SW_HIDE);
1951 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
1953 ShowWindow(hwnd, SW_SHOW);
1954 ShowWindow(child, SW_SHOW);
1956 ok( GetFocus() == child, "Focus should be on child %p\n", child );
1957 EnableWindow(hwnd, FALSE);
1958 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
1959 EnableWindow(hwnd, TRUE);
1961 DestroyWindow( child );
1964 static void test_SetActiveWindow(HWND hwnd)
1968 ShowWindow(hwnd, SW_SHOW);
1970 SetActiveWindow(hwnd);
1971 ok( GetActiveWindow() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
1972 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
1973 ok( GetActiveWindow() == hwnd, "Window %p no longer active\n", hwnd );
1974 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
1975 ShowWindow(hwnd, SW_HIDE);
1976 ok( GetActiveWindow() != hwnd, "Window %p is still active\n", hwnd );
1978 /* trace("**testing an invisible window now\n"); */
1979 SetActiveWindow(hwnd);
1980 ok( GetActiveWindow() == hwnd, "Window %p not active\n", hwnd );
1981 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p is visible\n", hwnd );
1983 ShowWindow(hwnd, SW_SHOW);
1985 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
1986 ok( GetActiveWindow() == hwnd2, "Window %p is not active\n", hwnd2 );
1987 DestroyWindow(hwnd2);
1988 ok( GetActiveWindow() != hwnd2, "Window %p is still active\n", hwnd2 );
1990 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
1991 ok( GetActiveWindow() == hwnd2, "Window %p is not active\n", hwnd2 );
1992 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
1993 ok( GetActiveWindow() == hwnd2, "Window %p no longer active (%p)\n", hwnd2, GetActiveWindow() );
1994 DestroyWindow(hwnd2);
1995 ok( GetActiveWindow() != hwnd2, "Window %p is still active\n", hwnd2 );
1998 static void check_wnd_state(HWND active, HWND foreground, HWND focus, HWND capture)
2000 ok(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2002 ok(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2003 ok(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2004 ok(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2007 static WNDPROC old_button_proc;
2009 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2014 key_state = GetKeyState(VK_LBUTTON);
2015 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2017 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2019 if (msg == WM_LBUTTONDOWN)
2023 check_wnd_state(button, button, button, button);
2025 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2027 trace("hwnd %p\n", hwnd);
2029 check_wnd_state(button, button, button, button);
2031 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2033 check_wnd_state(button, button, button, button);
2035 DestroyWindow(hwnd);
2037 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2039 trace("hwnd %p\n", hwnd);
2041 check_wnd_state(button, button, button, button);
2043 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2044 * match internal button state.
2046 SendMessage(button, WM_KILLFOCUS, 0, 0);
2047 check_wnd_state(button, button, button, 0);
2049 ShowWindow(hwnd, SW_SHOW);
2050 check_wnd_state(hwnd, hwnd, hwnd, 0);
2052 capture = SetCapture(hwnd);
2053 ok(capture == 0, "SetCapture() = %p\n", capture);
2055 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2057 DestroyWindow(hwnd);
2059 check_wnd_state(button, 0, button, 0);
2065 static void test_capture_1(void)
2067 HWND button, capture;
2069 capture = GetCapture();
2070 ok(capture == 0, "GetCapture() = %p\n", capture);
2072 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2074 trace("button %p\n", button);
2076 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2078 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2080 capture = SetCapture(button);
2081 ok(capture == 0, "SetCapture() = %p\n", capture);
2082 check_wnd_state(button, 0, button, button);
2084 DestroyWindow(button);
2085 check_wnd_state(0, 0, 0, 0);
2088 static void test_capture_2(void)
2090 HWND button, hwnd, capture;
2092 check_wnd_state(0, 0, 0, 0);
2094 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2096 trace("button %p\n", button);
2098 check_wnd_state(button, button, button, 0);
2100 capture = SetCapture(button);
2101 ok(capture == 0, "SetCapture() = %p\n", capture);
2103 check_wnd_state(button, button, button, button);
2105 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2106 * internal button state.
2108 SendMessage(button, WM_KILLFOCUS, 0, 0);
2109 check_wnd_state(button, button, button, button);
2111 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2113 trace("hwnd %p\n", hwnd);
2115 check_wnd_state(button, button, button, button);
2117 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2119 check_wnd_state(button, button, button, button);
2121 DestroyWindow(hwnd);
2123 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2125 trace("hwnd %p\n", hwnd);
2127 check_wnd_state(button, button, button, button);
2129 ShowWindow(hwnd, SW_SHOW);
2131 check_wnd_state(hwnd, hwnd, hwnd, button);
2133 capture = SetCapture(hwnd);
2134 ok(capture == button, "SetCapture() = %p\n", capture);
2136 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2138 DestroyWindow(hwnd);
2139 check_wnd_state(button, button, button, 0);
2141 DestroyWindow(button);
2142 check_wnd_state(0, 0, 0, 0);
2145 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2147 ShowWindow(hwnd1, SW_HIDE);
2148 ShowWindow(hwnd2, SW_HIDE);
2150 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2151 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2154 check_wnd_state(0, 0, 0, hwnd1);
2157 check_wnd_state(0, 0, 0, hwnd2);
2159 ShowWindow(hwnd1, SW_SHOW);
2160 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2165 static void test_keyboard_input(HWND hwnd)
2170 ShowWindow(hwnd, SW_SHOW);
2173 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2176 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2178 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2180 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2181 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2182 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2183 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2184 ok( !ret, "message %04x available\n", msg.message);
2186 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2188 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2189 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2190 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2191 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2192 ok( !ret, "message %04x available\n", msg.message);
2194 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2196 keybd_event(VK_SPACE, 0, 0, 0);
2197 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2198 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2199 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2200 ok( !ret, "message %04x available\n", msg.message);
2203 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2205 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
2207 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2208 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2209 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2210 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2211 ok( !ret, "message %04x available\n", msg.message);
2213 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2215 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2216 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2217 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2218 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2219 ok( !ret, "message %04x available\n", msg.message);
2221 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2223 keybd_event(VK_SPACE, 0, 0, 0);
2224 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2225 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2226 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2227 ok( !ret, "message %04x available\n", msg.message);
2230 static void test_mouse_input(HWND hwnd)
2239 ShowWindow(hwnd, SW_SHOW);
2242 GetWindowRect(hwnd, &rc);
2243 trace("main window %p: (%ld,%ld)-(%ld,%ld)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2245 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2246 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2249 ShowWindow(popup, SW_SHOW);
2250 UpdateWindow(popup);
2252 GetWindowRect(popup, &rc);
2253 trace("popup window %p: (%ld,%ld)-(%ld,%ld)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2255 x = rc.left + (rc.right - rc.left) / 2;
2256 y = rc.top + (rc.bottom - rc.top) / 2;
2257 trace("setting cursor to (%d,%d)\n", x, y);
2261 ok(x == pt.x && y == pt.y, "wrong cursor pos (%ld,%ld), expected (%d,%d)\n", pt.x, pt.y, x, y);
2263 /* force the system to update its internal queue mouse position,
2264 * otherwise it won't generate relative mouse movements below.
2266 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2267 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2270 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2271 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2272 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2273 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2274 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2275 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2276 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2277 ok( !ret, "message %04x available\n", msg.message);
2279 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2280 ShowWindow(popup, SW_HIDE);
2281 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2282 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2283 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2285 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2286 ShowWindow(hwnd, SW_HIDE);
2287 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2288 ok( !ret, "message %04x available\n", msg.message);
2290 /* test mouse clicks */
2292 ShowWindow(hwnd, SW_SHOW);
2293 ShowWindow(popup, SW_SHOW);
2295 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2297 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2298 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2299 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2300 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2302 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2303 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2304 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2305 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2307 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2308 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2309 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2310 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2312 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2313 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2314 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2315 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2317 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2318 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2319 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2320 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2322 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2323 ok(!ret, "message %04x available\n", msg.message);
2325 ShowWindow(popup, SW_HIDE);
2326 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2328 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2329 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2330 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2331 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2333 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2334 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2335 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2336 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2338 test_lbuttondown_flag = TRUE;
2339 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
2340 test_lbuttondown_flag = FALSE;
2342 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2343 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2344 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2345 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2346 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2348 DestroyWindow(popup);
2351 static void test_validatergn(HWND hwnd)
2357 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
2358 ShowWindow(hwnd, SW_SHOW);
2359 UpdateWindow( hwnd);
2360 /* test that ValidateRect validates children*/
2361 InvalidateRect( child, NULL, 1);
2362 GetWindowRect( child, &rc);
2363 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2364 ret = GetUpdateRect( child, &rc2, 0);
2365 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
2366 "Update rectangle is empty!\n");
2367 ValidateRect( hwnd, &rc);
2368 ret = GetUpdateRect( child, &rc2, 0);
2369 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2370 "Update rectangle %ld,%ld-%ld,%ld is not empty!\n", rc2.left, rc2.top,
2371 rc2.right, rc2.bottom);
2373 /* now test ValidateRgn */
2374 InvalidateRect( child, NULL, 1);
2375 GetWindowRect( child, &rc);
2376 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2377 rgn = CreateRectRgnIndirect( &rc);
2378 ValidateRgn( hwnd, rgn);
2379 ret = GetUpdateRect( child, &rc2, 0);
2380 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2381 "Update rectangle %ld,%ld-%ld,%ld is not empty!\n", rc2.left, rc2.top,
2382 rc2.right, rc2.bottom);
2385 DestroyWindow( child );
2388 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
2390 MoveWindow( hwnd, 0, 0, x, y, 0);
2391 GetWindowRect( hwnd, prc);
2392 trace("window rect is %ld,%ld - %ld,%ld\n",
2393 prc->left,prc->top,prc->right,prc->bottom);
2394 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
2395 trace("nccalc rect is %ld,%ld - %ld,%ld\n",
2396 prc->left,prc->top,prc->right,prc->bottom);
2399 static void test_nccalcscroll(HWND parent)
2402 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
2403 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
2404 HWND hwnd = CreateWindowExA(0, "static", NULL,
2405 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
2406 10, 10, 200, 200, parent, 0, 0, NULL);
2407 ShowWindow( parent, SW_SHOW);
2408 UpdateWindow( parent);
2410 /* test window too low for a horizontal scroll bar */
2411 nccalchelper( hwnd, 100, sbheight, &rc1);
2412 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %ld,%ld - %ld,%ld\n",
2413 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
2415 /* test window just high enough for a horizontal scroll bar */
2416 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
2417 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %ld,%ld - %ld,%ld\n",
2418 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2420 /* test window too narrow for a vertical scroll bar */
2421 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
2422 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %ld,%ld - %ld,%ld\n",
2423 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2425 /* test window just wide enough for a vertical scroll bar */
2426 nccalchelper( hwnd, sbwidth, 100, &rc1);
2427 ok( rc1.right - rc1.left == 0, "Width should be %d size is %ld,%ld - %ld,%ld\n",
2428 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
2430 /* same test, but with client edge: not enough width */
2431 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
2432 nccalchelper( hwnd, sbwidth, 100, &rc1);
2433 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
2434 "Width should be %d size is %ld,%ld - %ld,%ld\n",
2435 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
2437 DestroyWindow( hwnd);
2440 static void test_SetParent(void)
2443 HWND desktop = GetDesktopWindow();
2445 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
2446 HWND parent, child1, child2, child3, child4, sibling;
2448 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2449 100, 100, 200, 200, 0, 0, 0, NULL);
2450 assert(parent != 0);
2451 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2452 0, 0, 50, 50, parent, 0, 0, NULL);
2453 assert(child1 != 0);
2454 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2455 0, 0, 50, 50, child1, 0, 0, NULL);
2456 assert(child2 != 0);
2457 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2458 0, 0, 50, 50, child2, 0, 0, NULL);
2459 assert(child3 != 0);
2460 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2461 0, 0, 50, 50, child3, 0, 0, NULL);
2462 assert(child4 != 0);
2464 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2465 parent, child1, child2, child3, child4);
2467 check_parents(parent, desktop, 0, 0, 0, parent, parent);
2468 check_parents(child1, parent, parent, parent, 0, parent, parent);
2469 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2470 check_parents(child3, child2, child2, child2, 0, child2, parent);
2471 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2474 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
2475 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
2476 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2477 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
2478 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2481 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
2483 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2485 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
2486 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
2487 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
2488 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
2489 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
2490 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
2492 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2495 if (!is_win9x) /* Win9x doesn't survive this test */
2497 ok(!SetParent(parent, child1), "SetParent should fail\n");
2498 ok(!SetParent(child2, child3), "SetParent should fail\n");
2499 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
2500 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
2501 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
2502 ok(!SetParent(child2, parent), "SetParent should fail\n");
2503 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
2505 check_parents(parent, child4, child4, 0, 0, child4, parent);
2506 check_parents(child1, parent, parent, parent, 0, child4, parent);
2507 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2508 check_parents(child3, child2, child2, child2, 0, child2, parent);
2509 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2512 hMenu = CreateMenu();
2513 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2514 100, 100, 200, 200, 0, hMenu, 0, NULL);
2515 assert(sibling != 0);
2517 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
2518 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
2520 ret = DestroyWindow(parent);
2521 ok( ret, "DestroyWindow() error %ld\n", GetLastError());
2523 ok(!IsWindow(parent), "parent still exists\n");
2524 ok(!IsWindow(sibling), "sibling still exists\n");
2525 ok(!IsWindow(child1), "child1 still exists\n");
2526 ok(!IsWindow(child2), "child2 still exists\n");
2527 ok(!IsWindow(child3), "child3 still exists\n");
2528 ok(!IsWindow(child4), "child4 still exists\n");
2531 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2533 LPCREATESTRUCT lpcs;
2540 lpcs = (LPCREATESTRUCT)lparam;
2541 lpss = (LPSTYLESTRUCT)lpcs->lpCreateParams;
2544 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
2545 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
2546 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
2547 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
2549 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
2551 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
2552 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2553 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
2555 ok(lpss->styleNew == lpcs->style,
2556 "Style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2557 lpss->styleNew, lpcs->style);
2561 return DefWindowProc(hwnd, msg, wparam, lparam);
2564 static ATOM atomStyleCheckClass;
2566 static void register_style_check_class(void)
2574 GetModuleHandle(NULL),
2576 LoadCursor(NULL, IDC_ARROW),
2577 (HBRUSH)(COLOR_BTNFACE+1),
2579 TEXT("WineStyleCheck"),
2582 atomStyleCheckClass = RegisterClass(&wc);
2585 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
2587 DWORD dwActualStyle;
2588 DWORD dwActualExStyle;
2591 HWND hwndParent = NULL;
2594 ss.styleNew = dwStyleIn;
2595 ss.styleOld = dwExStyleIn;
2597 if (dwStyleIn & WS_CHILD)
2599 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
2600 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
2603 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
2604 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
2607 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2609 TranslateMessage(&msg);
2610 DispatchMessage(&msg);
2613 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
2614 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
2615 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
2616 "Style (0x%08lx) should really be 0x%08lx and/or Ex style (0x%08lx) should really be 0x%08lx\n",
2617 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
2619 DestroyWindow(hwnd);
2620 if (hwndParent) DestroyWindow(hwndParent);
2623 /* tests what window styles the window manager automatically adds */
2624 static void test_window_styles(void)
2626 register_style_check_class();
2628 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
2629 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
2630 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
2631 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
2632 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
2633 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
2634 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
2635 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
2636 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
2637 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
2638 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
2641 static void test_scrollvalidate( HWND parent)
2644 HRGN hrgn=CreateRectRgn(0,0,0,0);
2645 HRGN exprgn, tmprgn, clipping;
2646 RECT rc, rcu, cliprc;
2647 /* create two overlapping child windows. The visual region
2648 * of hwnd1 is clipped by the overlapping part of
2649 * hwnd2 because of the WS_CLIPSIBLING style */
2652 hwnd2 = CreateWindowExA(0, "static", NULL,
2653 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
2654 75, 30, 100, 100, parent, 0, 0, NULL);
2655 hwnd1 = CreateWindowExA(0, "static", NULL,
2656 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
2657 25, 50, 100, 100, parent, 0, 0, NULL);
2658 ShowWindow( parent, SW_SHOW);
2659 UpdateWindow( parent);
2660 GetClientRect( hwnd1, &rc);
2662 clipping = CreateRectRgn( 10, 10, 90, 90);
2663 hdc = GetDC( hwnd1);
2664 /* for a visual touch */
2665 TextOut( hdc, 0,10, "0123456789", 10);
2666 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
2667 if (winetest_debug > 0) dump_region(hrgn);
2668 /* create a region with what is expected */
2669 exprgn = CreateRectRgn( 39,0,49,74);
2670 tmprgn = CreateRectRgn( 88,79,98,93);
2671 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2672 tmprgn = CreateRectRgn( 0,93,98,98);
2673 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2674 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2675 trace("update rect is %ld,%ld - %ld,%ld\n",
2676 rcu.left,rcu.top,rcu.right,rcu.bottom);
2677 /* now with clipping region */
2678 SelectClipRgn( hdc, clipping);
2679 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
2680 if (winetest_debug > 0) dump_region(hrgn);
2681 /* create a region with what is expected */
2682 exprgn = CreateRectRgn( 39,10,49,74);
2683 tmprgn = CreateRectRgn( 80,79,90,85);
2684 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2685 tmprgn = CreateRectRgn( 10,85,90,90);
2686 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2687 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2688 trace("update rect is %ld,%ld - %ld,%ld\n",
2689 rcu.left,rcu.top,rcu.right,rcu.bottom);
2690 ReleaseDC( hwnd1, hdc);
2692 /* test scrolling a window with an update region */
2693 DestroyWindow( hwnd2);
2694 ValidateRect( hwnd1, NULL);
2695 SetRect( &rc, 40,40, 50,50);
2696 InvalidateRect( hwnd1, &rc, 1);
2697 GetClientRect( hwnd1, &rc);
2699 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
2700 SW_SCROLLCHILDREN | SW_INVALIDATE);
2701 if (winetest_debug > 0) dump_region(hrgn);
2702 exprgn = CreateRectRgn( 88,0,98,98);
2703 tmprgn = CreateRectRgn( 30, 40, 50, 50);
2704 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2705 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2707 /* now test ScrollWindowEx with a combination of
2708 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
2709 /* make hwnd2 the child of hwnd1 */
2710 hwnd2 = CreateWindowExA(0, "static", NULL,
2711 WS_CHILD| WS_VISIBLE | WS_BORDER ,
2712 50, 50, 100, 100, hwnd1, 0, 0, NULL);
2713 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
2714 GetClientRect( hwnd1, &rc);
2717 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
2718 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
2719 ValidateRect( hwnd1, NULL);
2720 ValidateRect( hwnd2, NULL);
2721 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
2722 SW_SCROLLCHILDREN | SW_INVALIDATE);
2723 if (winetest_debug > 0) dump_region(hrgn);
2724 exprgn = CreateRectRgn( 88,0,98,88);
2725 tmprgn = CreateRectRgn( 0,88,98,98);
2726 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2727 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2729 /* SW_SCROLLCHILDREN */
2730 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
2731 ValidateRect( hwnd1, NULL);
2732 ValidateRect( hwnd2, NULL);
2733 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
2734 if (winetest_debug > 0) dump_region(hrgn);
2735 /* expected region is the same as in previous test */
2736 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2738 /* no SW_SCROLLCHILDREN */
2739 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
2740 ValidateRect( hwnd1, NULL);
2741 ValidateRect( hwnd2, NULL);
2742 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
2743 if (winetest_debug > 0) dump_region(hrgn);
2744 /* expected region is the same as in previous test */
2745 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2747 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
2748 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
2749 ValidateRect( hwnd1, NULL);
2750 ValidateRect( hwnd2, NULL);
2751 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
2752 if (winetest_debug > 0) dump_region(hrgn);
2753 exprgn = CreateRectRgn( 88,0,98,20);
2754 tmprgn = CreateRectRgn( 20,20,98,30);
2755 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2756 tmprgn = CreateRectRgn( 20,30,30,88);
2757 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2758 tmprgn = CreateRectRgn( 0,88,30,98);
2759 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2760 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2763 DeleteObject( hrgn);
2764 DeleteObject( exprgn);
2765 DeleteObject( tmprgn);
2766 DestroyWindow( hwnd1);
2767 DestroyWindow( hwnd2);
2770 /* couple of tests of return values of scrollbar functions
2771 * called on a scrollbarless window */
2772 static void test_scroll(void)
2777 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
2778 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
2779 100, 100, 200, 200, 0, 0, 0, NULL);
2781 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
2782 ok( ret, "GetScrollRange returns FALSE\n");
2783 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
2784 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
2785 si.cbSize = sizeof( si);
2786 si.fMask = SIF_PAGE;
2787 si.nPage = 0xdeadbeef;
2788 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
2789 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
2790 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
2792 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
2793 ok( ret, "GetScrollRange returns FALSE\n");
2794 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
2795 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
2796 si.cbSize = sizeof( si);
2797 si.fMask = SIF_PAGE;
2798 si.nPage = 0xdeadbeef;
2799 ret = GetScrollInfo( hwnd, SB_VERT, &si);
2800 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
2801 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
2803 DestroyWindow( hwnd);
2806 static void test_params(void)
2810 /* Just a param check */
2811 SetLastError(0xdeadbeef);
2812 rc = GetWindowText(hwndMain2, NULL, 1024);
2813 ok( rc==0, "GetWindowText: rc=%d err=%ld\n",rc,GetLastError());
2816 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
2820 hwnd = CreateWindowEx(exStyle, class, class, style,
2827 trace("Failed to create window class=%s, style=0x%08lx, exStyle=0x%08lx\n", class, style, exStyle);
2830 ShowWindow(hwnd, SW_SHOW);
2832 test_nonclient_area(hwnd);
2835 DestroyWindow(hwnd);
2838 static BOOL AWR_init(void)
2842 class.style = CS_HREDRAW | CS_VREDRAW;
2843 class.lpfnWndProc = DefWindowProcA;
2844 class.cbClsExtra = 0;
2845 class.cbWndExtra = 0;
2846 class.hInstance = 0;
2847 class.hIcon = LoadIcon (0, IDI_APPLICATION);
2848 class.hCursor = LoadCursor (0, IDC_ARROW);
2849 class.hbrBackground = 0;
2850 class.lpszMenuName = 0;
2851 class.lpszClassName = szAWRClass;
2853 if (!RegisterClass (&class)) {
2854 ok(FALSE, "RegisterClass failed\n");
2858 hmenu = CreateMenu();
2861 ok(hmenu != 0, "Failed to create menu\n");
2862 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
2868 static void test_AWR_window_size(BOOL menu)
2872 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
2875 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
2876 WS_HSCROLL, WS_VSCROLL
2880 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
2883 /* These styles have problems on (at least) WinXP (SP2) and Wine */
2884 WS_EX_DLGMODALFRAME,
2891 /* A exhaustive check of all the styles takes too long
2892 * so just do a (hopefully representative) sample
2894 for (i = 0; i < COUNTOF(styles); ++i)
2895 test_AWRwindow(szAWRClass, styles[i], 0, menu);
2896 for (i = 0; i < COUNTOF(exStyles); ++i) {
2897 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
2898 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
2903 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
2905 static void test_AdjustWindowRect(void)
2910 SHOWSYSMETRIC(SM_CYCAPTION);
2911 SHOWSYSMETRIC(SM_CYSMCAPTION);
2912 SHOWSYSMETRIC(SM_CYMENU);
2913 SHOWSYSMETRIC(SM_CXEDGE);
2914 SHOWSYSMETRIC(SM_CYEDGE);
2915 SHOWSYSMETRIC(SM_CXVSCROLL);
2916 SHOWSYSMETRIC(SM_CYHSCROLL);
2917 SHOWSYSMETRIC(SM_CXFRAME);
2918 SHOWSYSMETRIC(SM_CYFRAME);
2919 SHOWSYSMETRIC(SM_CXDLGFRAME);
2920 SHOWSYSMETRIC(SM_CYDLGFRAME);
2921 SHOWSYSMETRIC(SM_CXBORDER);
2922 SHOWSYSMETRIC(SM_CYBORDER);
2924 test_AWR_window_size(FALSE);
2925 test_AWR_window_size(TRUE);
2929 #undef SHOWSYSMETRIC
2932 /* Global variables to trigger exit from loop */
2933 static int redrawComplete, WMPAINT_count;
2935 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2940 trace("doing WM_PAINT %d\n", WMPAINT_count);
2942 if (WMPAINT_count > 10 && redrawComplete == 0) {
2944 BeginPaint(hwnd, &ps);
2945 EndPaint(hwnd, &ps);
2951 return DefWindowProc(hwnd, msg, wparam, lparam);
2954 /* Ensure we exit from RedrawNow regardless of invalidated area */
2955 static void test_redrawnow(void)
2960 cls.style = CS_DBLCLKS;
2961 cls.lpfnWndProc = redraw_window_procA;
2964 cls.hInstance = GetModuleHandleA(0);
2966 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
2967 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
2968 cls.lpszMenuName = NULL;
2969 cls.lpszClassName = "RedrawWindowClass";
2971 if(!RegisterClassA(&cls)) {
2972 trace("Register failed %ld\n", GetLastError());
2976 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
2977 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
2979 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
2980 ShowWindow(hwndMain, SW_SHOW);
2981 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
2982 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
2983 ok( WMPAINT_count == 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
2984 redrawComplete = TRUE;
2985 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
2988 DestroyWindow( hwndMain);
2991 static void test_IsWindowUnicode(void)
2993 static const char ansi_class_nameA[] = "ansi class name";
2994 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
2995 static const char unicode_class_nameA[] = "unicode class name";
2996 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3001 memset(&classW, 0, sizeof(classW));
3002 classW.hInstance = GetModuleHandleA(0);
3003 classW.lpfnWndProc = DefWindowProcW;
3004 classW.lpszClassName = unicode_class_nameW;
3005 if (!RegisterClassW(&classW)) return;
3007 memset(&classA, 0, sizeof(classA));
3008 classA.hInstance = GetModuleHandleA(0);
3009 classA.lpfnWndProc = DefWindowProcA;
3010 classA.lpszClassName = ansi_class_nameA;
3011 assert(RegisterClassA(&classA));
3013 /* unicode class: window proc */
3014 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3015 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3018 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3019 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3020 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3021 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3022 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3024 DestroyWindow(hwnd);
3026 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3027 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3030 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3031 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3032 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3033 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3034 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3036 DestroyWindow(hwnd);
3038 /* ansi class: window proc */
3039 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3040 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3043 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3044 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3045 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3046 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3047 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3049 DestroyWindow(hwnd);
3051 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3052 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3055 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3056 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3057 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3058 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3059 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3061 DestroyWindow(hwnd);
3063 /* unicode class: class proc */
3064 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3065 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3068 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3069 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3070 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3071 /* do not restore class window proc back to unicode */
3073 DestroyWindow(hwnd);
3075 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3076 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3079 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3080 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3081 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE");
3083 DestroyWindow(hwnd);
3085 /* ansi class: class proc */
3086 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3087 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3090 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3091 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3092 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3093 /* do not restore class window proc back to ansi */
3095 DestroyWindow(hwnd);
3097 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3098 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3101 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3102 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3103 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3105 DestroyWindow(hwnd);
3110 pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
3111 pGetWindowInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
3113 hwndMain = CreateWindowExA(0, "static", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, NULL);
3116 ok(!GetParent(hwndMain), "GetParent should return 0 for message only windows\n");
3119 hwndMessage = pGetAncestor(hwndMain, GA_PARENT);
3120 ok(hwndMessage != 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
3121 trace("hwndMessage %p\n", hwndMessage);
3123 DestroyWindow(hwndMain);
3126 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
3128 if (!RegisterWindowClasses()) assert(0);
3130 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
3133 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
3134 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3135 WS_MAXIMIZEBOX | WS_POPUP,
3138 test_nonclient_area(hwndMain);
3140 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
3141 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3142 WS_MAXIMIZEBOX | WS_POPUP,
3146 assert( hwndMain2 );
3152 test_capture_3(hwndMain, hwndMain2);
3154 test_parent_owner();
3156 test_shell_window();
3160 test_SetWindowPos(hwndMain);
3161 test_SetMenu(hwndMain);
3162 test_SetFocus(hwndMain);
3163 test_SetActiveWindow(hwndMain);
3165 test_children_zorder(hwndMain);
3166 test_keyboard_input(hwndMain);
3167 test_mouse_input(hwndMain);
3168 test_validatergn(hwndMain);
3169 test_nccalcscroll( hwndMain);
3170 test_scrollvalidate( hwndMain);
3172 test_IsWindowUnicode();
3174 UnhookWindowsHookEx(hhook);
3176 test_AdjustWindowRect();
3177 test_window_styles();