Release 20050930.
[wine/gsoc-2012-control.git] / dlls / user / tests / win.c
blob658baeb311f293611cf52aadc296a529683f4752
1 /*
2 * Unit tests for window handling
4 * Copyright 2002 Bill Medland
5 * Copyright 2002 Alexandre Julliard
6 * Copyright 2003 Dmitry Timoshkov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 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
29 #include <assert.h>
30 #include <stdlib.h>
31 #include <stdarg.h>
32 #include <stdio.h>
34 #include "windef.h"
35 #include "winbase.h"
36 #include "wingdi.h"
37 #include "winuser.h"
39 #include "wine/test.h"
41 #ifndef SPI_GETDESKWALLPAPER
42 #define SPI_GETDESKWALLPAPER 0x0073
43 #endif
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;
56 static HHOOK hhook;
58 static const char* szAWRClass = "Winsize";
59 static HMENU hmenu;
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 )
67 HWND res;
69 if (pGetAncestor)
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)GetWindowLongPtrA( hwnd, GWLP_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 );
80 if (pGetAncestor)
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" );
95 return ret;
98 /* test parent and owner values for various combinations */
99 static void test_parent_owner(void)
101 LONG style;
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" );
113 /* desktop window */
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 );
163 /* child of child */
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 );
223 /* owned popup */
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" );
290 /* desktop window */
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 );
298 #endif
299 /* normal child window */
300 test = create_tool_window( WS_CHILD, hwndMain );
301 trace( "created child %p\n", test );
303 ret = (HWND)SetWindowLongPtrA( test, GWLP_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)SetWindowLongPtrA( test, GWLP_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)SetWindowLongPtrA( test, GWLP_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 GWLP_HWNDPARENT changes owner from now on */
316 ret = (HWND)SetWindowLongPtrA( test, GWLP_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)SetWindowLongPtrA( test, GWLP_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)SetWindowLongPtrA( test, GWLP_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)SetWindowLongPtrA( test, GWLP_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)SetWindowLongPtrA( test, GWLP_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)SetWindowLongPtrA( test, GWLP_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)SetWindowLongPtrA( test, GWLP_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)SetWindowLongPtrA( test, GWLP_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 );
385 /* owned popup */
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)SetWindowLongPtrA( test, GWLP_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 );
415 DestroyWindow(test);
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)SetWindowLongPtrA( test, GWLP_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 );*/
439 DestroyWindow(test);
441 /* final cleanup */
442 DestroyWindow(child);
446 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
448 switch (msg)
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 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
463 break;
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);
484 break;
486 case WM_WINDOWPOSCHANGED:
488 RECT rc1, rc2;
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");
508 #endif
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 );
515 break;
517 case WM_NCCREATE:
519 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_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");
528 else
529 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
530 break;
532 case WM_COMMAND:
533 if (test_lbuttondown_flag)
534 ShowWindow((HWND)wparam, SW_SHOW);
535 break;
538 return DefWindowProcA(hwnd, msg, wparam, lparam);
541 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
543 switch (msg)
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 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
558 break;
560 case WM_NCCREATE:
562 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_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");
571 else
572 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
573 break;
577 return DefWindowProcA(hwnd, msg, wparam, lparam);
580 static BOOL RegisterWindowClasses(void)
582 WNDCLASSA cls;
584 cls.style = CS_DBLCLKS;
585 cls.lpfnWndProc = main_window_procA;
586 cls.cbClsExtra = 0;
587 cls.cbWndExtra = 0;
588 cls.hInstance = GetModuleHandleA(0);
589 cls.hIcon = 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;
597 cls.style = 0;
598 cls.lpfnWndProc = tool_window_procA;
599 cls.cbClsExtra = 0;
600 cls.cbWndExtra = 0;
601 cls.hInstance = GetModuleHandleA(0);
602 cls.hIcon = 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;
610 return TRUE;
613 static void verify_window_info(HWND hwnd, const WINDOWINFO *info, BOOL test_borders)
615 RECT rcWindow, rcClient;
616 UINT border;
617 DWORD status;
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);
661 else
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;
672 BOOL menu;
673 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_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 */;
703 if (is_win9x)
704 return;
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] = {
724 "HCBT_MOVESIZE",
725 "HCBT_MINMAX",
726 "HCBT_QS",
727 "HCBT_CREATEWND",
728 "HCBT_DESTROYWND",
729 "HCBT_ACTIVATE",
730 "HCBT_CLICKSKIPPED",
731 "HCBT_KEYSKIPPED",
732 "HCBT_SYSCOMMAND",
733 "HCBT_SETFOCUS" };
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))
741 if (pGetWindowInfo)
743 WINDOWINFO info;
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);
758 switch (nCode)
760 case HCBT_CREATEWND:
762 #if 0 /* Uncomment this once the test succeeds in all cases */
763 static const RECT rc_null;
764 RECT rc;
765 #endif
766 LONG style;
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);
785 else
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");
789 #endif
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");
795 #endif
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 */
800 if (pGetAncestor)
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");
809 else
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");
818 #endif
819 break;
823 return CallNextHookEx(hhook, nCode, wParam, lParam);
826 static void test_shell_window(void)
828 BOOL ret;
829 DWORD error;
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");
839 return;
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);
851 if (shellWindow) {
852 DWORD pid;
853 HANDLE hProcess;
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"); */
892 todo_wine
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");
940 todo_wine
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;
960 HWND mdi_child;
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;
972 mdi_cs.style = 0;
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(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_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(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_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");
993 else
995 ok(mdi_child != 0, "MDI child creation failed\n");
996 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_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 */
1003 mdi_cs.style = 0;
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);
1008 if (!mdi_child)
1010 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1011 isWin9x = TRUE;
1012 else
1013 ok(mdi_child != 0, "MDI child creation failed\n");
1015 else
1017 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_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(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_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(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_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");
1054 else
1056 ok(mdi_child != 0, "MDI child creation failed\n");
1057 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_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);
1070 if (!mdi_child)
1072 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1073 isWin9x = TRUE;
1074 else
1075 ok(mdi_child != 0, "MDI child creation failed\n");
1077 else
1079 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_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(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1092 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1093 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1095 mdi_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(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_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");
1116 else
1118 ok(mdi_child != 0, "MDI child creation failed\n");
1119 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_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);
1132 if (!mdi_child)
1134 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1135 isWin9x = TRUE;
1136 else
1137 ok(mdi_child != 0, "MDI child creation failed\n");
1139 else
1141 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_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 */
1147 if (!isWin9x)
1149 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1150 WS_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(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_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(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_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(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_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(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_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(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_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 )
1220 RECT rect;
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)
1240 switch (msg)
1242 case WM_NCCREATE:
1243 case WM_CREATE:
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);
1281 else
1283 LONG style = mdi_cs->style;
1284 style &= ~WS_POPUP;
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);
1290 break;
1293 case WM_GETMINMAXINFO:
1295 HWND client = GetParent(hwnd);
1296 RECT rc;
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);
1353 return 1;
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);
1363 else
1364 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1365 break;
1368 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1371 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1373 switch (msg)
1375 case WM_NCCREATE:
1376 case WM_CREATE:
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,
1391 while NT does. */
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);
1400 break;
1403 case WM_GETMINMAXINFO:
1405 HWND parent = GetParent(hwnd);
1406 RECT rc;
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);
1439 break;
1442 case WM_WINDOWPOSCHANGED:
1444 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1445 RECT rc1, rc2;
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");
1461 /* fall through */
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");
1481 return 1;
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;
1491 switch (msg)
1493 case WM_CREATE:
1495 CLIENTCREATESTRUCT client_cs;
1496 RECT rc;
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",
1505 NULL,
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);
1511 assert(mdi_client);
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",
1517 NULL,
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);
1523 assert(mdi_client);
1524 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1525 DestroyWindow(mdi_client);
1526 break;
1529 case WM_WINDOWPOSCHANGED:
1531 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1532 RECT rc1, rc2;
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");
1548 /* fall through */
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");
1568 return 1;
1571 case WM_CLOSE:
1572 PostQuitMessage(0);
1573 break;
1575 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1578 static BOOL mdi_RegisterWindowClasses(void)
1580 WNDCLASSA cls;
1582 cls.style = 0;
1583 cls.lpfnWndProc = mdi_main_wnd_procA;
1584 cls.cbClsExtra = 0;
1585 cls.cbWndExtra = 0;
1586 cls.hInstance = GetModuleHandleA(0);
1587 cls.hIcon = 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;
1602 return TRUE;
1605 static void test_mdi(void)
1607 HWND mdi_hwndMain;
1608 /*MSG msg;*/
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)
1630 WNDCLASSEXA cls;
1631 HWND hwnd;
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 );
1636 HICON res;
1638 cls.cbSize = sizeof(cls);
1639 cls.style = 0;
1640 cls.lpfnWndProc = DefWindowProcA;
1641 cls.cbClsExtra = 0;
1642 cls.cbWndExtra = 0;
1643 cls.hInstance = 0;
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);
1655 assert( hwnd );
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 );
1701 return 0;
1703 return DefWindowProc( hwnd, msg, wparam, lparam );
1706 static void test_SetWindowPos(HWND hwnd)
1708 RECT orig_win_rc, rect;
1709 LONG_PTR old_proc;
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 */
1748 if (!is_win9x)
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)
1763 HWND child;
1764 HMENU hMenu, ret;
1765 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1766 BOOL retok;
1767 DWORD style;
1769 hMenu = CreateMenu();
1770 assert(hMenu);
1772 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1773 #if 0
1774 /* fails on (at least) Wine, NT4, XP SP2 */
1775 test_nonclient_area(parent);
1776 #endif
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 */
1785 if (!is_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();
1791 assert(hMenu);
1793 /* parent */
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");
1803 #if 0
1804 /* fails on (at least) Wine, NT4, XP SP2 */
1805 test_nonclient_area(parent);
1806 #endif
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);
1815 /* child */
1816 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1817 assert(child);
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);
1848 DestroyMenu(hMenu);
1851 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1853 HWND child[5], hwnd;
1854 int i;
1856 assert(total <= 5);
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,
1889 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_vis_rgn( HWND hwnd )
1914 RECT win_rect, rgn_rect;
1915 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
1916 HDC hdc;
1918 ShowWindow(hwnd,SW_SHOW);
1919 hdc = GetDC( hwnd );
1920 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
1921 GetWindowRect( hwnd, &win_rect );
1922 GetRgnBox( hrgn, &rgn_rect );
1923 if (GetVersion() & 0x80000000)
1925 trace("win9x, mapping to screen coords\n");
1926 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
1928 trace("win: %ld,%ld-%ld,%ld\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
1929 trace("rgn: %ld,%ld-%ld,%ld\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
1930 ok( win_rect.left <= rgn_rect.left, "rgn left %ld not inside win rect %ld\n",
1931 rgn_rect.left, win_rect.left );
1932 ok( win_rect.top <= rgn_rect.top, "rgn top %ld not inside win rect %ld\n",
1933 rgn_rect.top, win_rect.top );
1934 ok( win_rect.right >= rgn_rect.right, "rgn right %ld not inside win rect %ld\n",
1935 rgn_rect.right, win_rect.right );
1936 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %ld not inside win rect %ld\n",
1937 rgn_rect.bottom, win_rect.bottom );
1938 ReleaseDC( hwnd, hdc );
1941 static void test_SetFocus(HWND hwnd)
1943 HWND child;
1945 /* check if we can set focus to non-visible windows */
1947 ShowWindow(hwnd, SW_SHOW);
1948 SetFocus(0);
1949 SetFocus(hwnd);
1950 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
1951 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
1952 ShowWindow(hwnd, SW_HIDE);
1953 SetFocus(0);
1954 SetFocus(hwnd);
1955 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
1956 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
1957 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
1958 assert(child);
1959 SetFocus(child);
1960 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
1961 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
1962 ShowWindow(child, SW_SHOW);
1963 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
1964 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
1965 ShowWindow(child, SW_HIDE);
1966 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
1967 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
1968 ShowWindow(child, SW_SHOW);
1969 SetFocus(child);
1970 ok( GetFocus() == child, "Focus should be on child %p\n", child );
1971 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
1972 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
1974 ShowWindow(child, SW_HIDE);
1975 SetFocus(hwnd);
1976 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
1977 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
1978 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
1979 ShowWindow(child, SW_HIDE);
1980 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
1982 ShowWindow(hwnd, SW_SHOW);
1983 ShowWindow(child, SW_SHOW);
1984 SetFocus(child);
1985 ok( GetFocus() == child, "Focus should be on child %p\n", child );
1986 EnableWindow(hwnd, FALSE);
1987 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
1988 EnableWindow(hwnd, TRUE);
1990 DestroyWindow( child );
1993 static void test_SetActiveWindow(HWND hwnd)
1995 HWND hwnd2;
1997 ShowWindow(hwnd, SW_SHOW);
1998 SetActiveWindow(0);
1999 SetActiveWindow(hwnd);
2000 ok( GetActiveWindow() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2001 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2002 ok( GetActiveWindow() == hwnd, "Window %p no longer active\n", hwnd );
2003 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2004 ShowWindow(hwnd, SW_HIDE);
2005 ok( GetActiveWindow() != hwnd, "Window %p is still active\n", hwnd );
2007 /* trace("**testing an invisible window now\n"); */
2008 SetActiveWindow(hwnd);
2009 ok( GetActiveWindow() == hwnd, "Window %p not active\n", hwnd );
2010 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p is visible\n", hwnd );
2012 ShowWindow(hwnd, SW_SHOW);
2014 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2015 ok( GetActiveWindow() == hwnd2, "Window %p is not active\n", hwnd2 );
2016 DestroyWindow(hwnd2);
2017 ok( GetActiveWindow() != hwnd2, "Window %p is still active\n", hwnd2 );
2019 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2020 ok( GetActiveWindow() == hwnd2, "Window %p is not active\n", hwnd2 );
2021 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2022 ok( GetActiveWindow() == hwnd2, "Window %p no longer active (%p)\n", hwnd2, GetActiveWindow() );
2023 DestroyWindow(hwnd2);
2024 ok( GetActiveWindow() != hwnd2, "Window %p is still active\n", hwnd2 );
2027 static void check_wnd_state(HWND active, HWND foreground, HWND focus, HWND capture)
2029 ok(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2030 if (foreground)
2031 ok(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2032 ok(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2033 ok(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2036 static WNDPROC old_button_proc;
2038 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2040 LRESULT ret;
2041 USHORT key_state;
2043 key_state = GetKeyState(VK_LBUTTON);
2044 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2046 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2048 if (msg == WM_LBUTTONDOWN)
2050 HWND hwnd, capture;
2052 check_wnd_state(button, button, button, button);
2054 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2055 assert(hwnd);
2056 trace("hwnd %p\n", hwnd);
2058 check_wnd_state(button, button, button, button);
2060 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2062 check_wnd_state(button, button, button, button);
2064 DestroyWindow(hwnd);
2066 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2067 assert(hwnd);
2068 trace("hwnd %p\n", hwnd);
2070 check_wnd_state(button, button, button, button);
2072 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2073 * match internal button state.
2075 SendMessage(button, WM_KILLFOCUS, 0, 0);
2076 check_wnd_state(button, button, button, 0);
2078 ShowWindow(hwnd, SW_SHOW);
2079 check_wnd_state(hwnd, hwnd, hwnd, 0);
2081 capture = SetCapture(hwnd);
2082 ok(capture == 0, "SetCapture() = %p\n", capture);
2084 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2086 DestroyWindow(hwnd);
2088 check_wnd_state(button, 0, button, 0);
2091 return ret;
2094 static void test_capture_1(void)
2096 HWND button, capture;
2098 capture = GetCapture();
2099 ok(capture == 0, "GetCapture() = %p\n", capture);
2101 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2102 assert(button);
2103 trace("button %p\n", button);
2105 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2107 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2109 capture = SetCapture(button);
2110 ok(capture == 0, "SetCapture() = %p\n", capture);
2111 check_wnd_state(button, 0, button, button);
2113 DestroyWindow(button);
2114 check_wnd_state(0, 0, 0, 0);
2117 static void test_capture_2(void)
2119 HWND button, hwnd, capture;
2121 check_wnd_state(0, 0, 0, 0);
2123 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2124 assert(button);
2125 trace("button %p\n", button);
2127 check_wnd_state(button, button, button, 0);
2129 capture = SetCapture(button);
2130 ok(capture == 0, "SetCapture() = %p\n", capture);
2132 check_wnd_state(button, button, button, button);
2134 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2135 * internal button state.
2137 SendMessage(button, WM_KILLFOCUS, 0, 0);
2138 check_wnd_state(button, button, button, button);
2140 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2141 assert(hwnd);
2142 trace("hwnd %p\n", hwnd);
2144 check_wnd_state(button, button, button, button);
2146 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2148 check_wnd_state(button, button, button, button);
2150 DestroyWindow(hwnd);
2152 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2153 assert(hwnd);
2154 trace("hwnd %p\n", hwnd);
2156 check_wnd_state(button, button, button, button);
2158 ShowWindow(hwnd, SW_SHOW);
2160 check_wnd_state(hwnd, hwnd, hwnd, button);
2162 capture = SetCapture(hwnd);
2163 ok(capture == button, "SetCapture() = %p\n", capture);
2165 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2167 DestroyWindow(hwnd);
2168 check_wnd_state(button, button, button, 0);
2170 DestroyWindow(button);
2171 check_wnd_state(0, 0, 0, 0);
2174 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2176 ShowWindow(hwnd1, SW_HIDE);
2177 ShowWindow(hwnd2, SW_HIDE);
2179 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2180 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2182 SetCapture(hwnd1);
2183 check_wnd_state(0, 0, 0, hwnd1);
2185 SetCapture(hwnd2);
2186 check_wnd_state(0, 0, 0, hwnd2);
2188 ShowWindow(hwnd1, SW_SHOW);
2189 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2191 ReleaseCapture();
2194 static void test_keyboard_input(HWND hwnd)
2196 MSG msg;
2197 BOOL ret;
2199 ShowWindow(hwnd, SW_SHOW);
2200 UpdateWindow(hwnd);
2202 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2204 SetFocus(hwnd);
2205 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2207 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2209 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2210 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2211 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2212 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2213 ok( !ret, "message %04x available\n", msg.message);
2215 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2217 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2218 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2219 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2220 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2221 ok( !ret, "message %04x available\n", msg.message);
2223 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2225 keybd_event(VK_SPACE, 0, 0, 0);
2226 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2227 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2228 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2229 ok( !ret, "message %04x available\n", msg.message);
2231 SetFocus(0);
2232 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2234 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
2236 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2237 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2238 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2239 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2240 ok( !ret, "message %04x available\n", msg.message);
2242 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2244 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2245 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2246 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2247 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2248 ok( !ret, "message %04x available\n", msg.message);
2250 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2252 keybd_event(VK_SPACE, 0, 0, 0);
2253 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2254 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2255 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2256 ok( !ret, "message %04x available\n", msg.message);
2259 static void test_mouse_input(HWND hwnd)
2261 RECT rc;
2262 POINT pt;
2263 int x, y;
2264 HWND popup;
2265 MSG msg;
2266 BOOL ret;
2267 LRESULT res;
2269 ShowWindow(hwnd, SW_SHOW);
2270 UpdateWindow(hwnd);
2272 GetWindowRect(hwnd, &rc);
2273 trace("main window %p: (%ld,%ld)-(%ld,%ld)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2275 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2276 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2277 hwnd, 0, 0, NULL);
2278 assert(popup != 0);
2279 ShowWindow(popup, SW_SHOW);
2280 UpdateWindow(popup);
2282 GetWindowRect(popup, &rc);
2283 trace("popup window %p: (%ld,%ld)-(%ld,%ld)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2285 x = rc.left + (rc.right - rc.left) / 2;
2286 y = rc.top + (rc.bottom - rc.top) / 2;
2287 trace("setting cursor to (%d,%d)\n", x, y);
2289 SetCursorPos(x, y);
2290 GetCursorPos(&pt);
2291 ok(x == pt.x && y == pt.y, "wrong cursor pos (%ld,%ld), expected (%d,%d)\n", pt.x, pt.y, x, y);
2293 /* force the system to update its internal queue mouse position,
2294 * otherwise it won't generate relative mouse movements below.
2296 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2297 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2299 msg.message = 0;
2300 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2301 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2302 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2303 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2304 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2305 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2306 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2307 ok( !ret, "message %04x available\n", msg.message);
2309 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2310 ShowWindow(popup, SW_HIDE);
2311 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2312 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2313 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2315 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2316 ShowWindow(hwnd, SW_HIDE);
2317 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2318 ok( !ret, "message %04x available\n", msg.message);
2320 /* test mouse clicks */
2322 ShowWindow(hwnd, SW_SHOW);
2323 ShowWindow(popup, SW_SHOW);
2325 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2327 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2328 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2329 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2330 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2332 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2333 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2334 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2335 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2337 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2338 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2339 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2340 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2342 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2343 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "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_LBUTTONDBLCLK, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2347 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2348 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2349 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2350 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2352 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2353 ok(!ret, "message %04x available\n", msg.message);
2355 ShowWindow(popup, SW_HIDE);
2356 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2358 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2359 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2360 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2361 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2363 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2364 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2365 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2366 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2368 test_lbuttondown_flag = TRUE;
2369 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
2370 test_lbuttondown_flag = FALSE;
2372 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2373 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2374 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2375 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2376 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2378 /* Test WM_MOUSEACTIVATE */
2379 #define TEST_MOUSEACTIVATE(A,B) \
2380 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2381 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2383 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
2384 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
2385 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
2386 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
2387 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
2388 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
2389 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
2390 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
2391 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
2392 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
2393 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
2394 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
2395 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
2396 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
2397 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
2398 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
2399 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
2400 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
2401 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
2402 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
2403 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
2404 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
2405 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
2406 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
2408 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2409 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2411 DestroyWindow(popup);
2414 static void test_validatergn(HWND hwnd)
2416 HWND child;
2417 RECT rc, rc2;
2418 HRGN rgn;
2419 int ret;
2420 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
2421 ShowWindow(hwnd, SW_SHOW);
2422 UpdateWindow( hwnd);
2423 /* test that ValidateRect validates children*/
2424 InvalidateRect( child, NULL, 1);
2425 GetWindowRect( child, &rc);
2426 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2427 ret = GetUpdateRect( child, &rc2, 0);
2428 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
2429 "Update rectangle is empty!\n");
2430 ValidateRect( hwnd, &rc);
2431 ret = GetUpdateRect( child, &rc2, 0);
2432 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2433 "Update rectangle %ld,%ld-%ld,%ld is not empty!\n", rc2.left, rc2.top,
2434 rc2.right, rc2.bottom);
2436 /* now test ValidateRgn */
2437 InvalidateRect( child, NULL, 1);
2438 GetWindowRect( child, &rc);
2439 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2440 rgn = CreateRectRgnIndirect( &rc);
2441 ValidateRgn( hwnd, rgn);
2442 ret = GetUpdateRect( child, &rc2, 0);
2443 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2444 "Update rectangle %ld,%ld-%ld,%ld is not empty!\n", rc2.left, rc2.top,
2445 rc2.right, rc2.bottom);
2447 DeleteObject( rgn);
2448 DestroyWindow( child );
2451 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
2453 MoveWindow( hwnd, 0, 0, x, y, 0);
2454 GetWindowRect( hwnd, prc);
2455 trace("window rect is %ld,%ld - %ld,%ld\n",
2456 prc->left,prc->top,prc->right,prc->bottom);
2457 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
2458 trace("nccalc rect is %ld,%ld - %ld,%ld\n",
2459 prc->left,prc->top,prc->right,prc->bottom);
2462 static void test_nccalcscroll(HWND parent)
2464 RECT rc1;
2465 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
2466 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
2467 HWND hwnd = CreateWindowExA(0, "static", NULL,
2468 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
2469 10, 10, 200, 200, parent, 0, 0, NULL);
2470 ShowWindow( parent, SW_SHOW);
2471 UpdateWindow( parent);
2473 /* test window too low for a horizontal scroll bar */
2474 nccalchelper( hwnd, 100, sbheight, &rc1);
2475 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %ld,%ld - %ld,%ld\n",
2476 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
2478 /* test window just high enough for a horizontal scroll bar */
2479 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
2480 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %ld,%ld - %ld,%ld\n",
2481 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2483 /* test window too narrow for a vertical scroll bar */
2484 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
2485 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %ld,%ld - %ld,%ld\n",
2486 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2488 /* test window just wide enough for a vertical scroll bar */
2489 nccalchelper( hwnd, sbwidth, 100, &rc1);
2490 ok( rc1.right - rc1.left == 0, "Width should be %d size is %ld,%ld - %ld,%ld\n",
2491 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
2493 /* same test, but with client edge: not enough width */
2494 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
2495 nccalchelper( hwnd, sbwidth, 100, &rc1);
2496 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
2497 "Width should be %d size is %ld,%ld - %ld,%ld\n",
2498 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
2500 DestroyWindow( hwnd);
2503 static void test_SetParent(void)
2505 BOOL ret;
2506 HWND desktop = GetDesktopWindow();
2507 HMENU hMenu;
2508 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
2509 HWND parent, child1, child2, child3, child4, sibling;
2511 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2512 100, 100, 200, 200, 0, 0, 0, NULL);
2513 assert(parent != 0);
2514 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2515 0, 0, 50, 50, parent, 0, 0, NULL);
2516 assert(child1 != 0);
2517 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2518 0, 0, 50, 50, child1, 0, 0, NULL);
2519 assert(child2 != 0);
2520 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2521 0, 0, 50, 50, child2, 0, 0, NULL);
2522 assert(child3 != 0);
2523 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2524 0, 0, 50, 50, child3, 0, 0, NULL);
2525 assert(child4 != 0);
2527 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2528 parent, child1, child2, child3, child4);
2530 check_parents(parent, desktop, 0, 0, 0, parent, parent);
2531 check_parents(child1, parent, parent, parent, 0, parent, parent);
2532 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2533 check_parents(child3, child2, child2, child2, 0, child2, parent);
2534 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2536 todo_wine {
2537 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
2538 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
2539 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2540 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
2541 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2544 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
2545 todo_wine {
2546 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2548 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
2549 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
2550 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
2551 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
2552 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
2553 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
2554 todo_wine {
2555 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2558 if (!is_win9x) /* Win9x doesn't survive this test */
2560 ok(!SetParent(parent, child1), "SetParent should fail\n");
2561 ok(!SetParent(child2, child3), "SetParent should fail\n");
2562 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
2563 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
2564 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
2565 ok(!SetParent(child2, parent), "SetParent should fail\n");
2566 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
2568 check_parents(parent, child4, child4, 0, 0, child4, parent);
2569 check_parents(child1, parent, parent, parent, 0, child4, parent);
2570 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2571 check_parents(child3, child2, child2, child2, 0, child2, parent);
2572 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2575 hMenu = CreateMenu();
2576 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2577 100, 100, 200, 200, 0, hMenu, 0, NULL);
2578 assert(sibling != 0);
2580 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
2581 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
2583 ret = DestroyWindow(parent);
2584 ok( ret, "DestroyWindow() error %ld\n", GetLastError());
2586 ok(!IsWindow(parent), "parent still exists\n");
2587 ok(!IsWindow(sibling), "sibling still exists\n");
2588 ok(!IsWindow(child1), "child1 still exists\n");
2589 ok(!IsWindow(child2), "child2 still exists\n");
2590 ok(!IsWindow(child3), "child3 still exists\n");
2591 ok(!IsWindow(child4), "child4 still exists\n");
2594 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2596 LPCREATESTRUCT lpcs;
2597 LPSTYLESTRUCT lpss;
2599 switch (msg)
2601 case WM_NCCREATE:
2602 case WM_CREATE:
2603 lpcs = (LPCREATESTRUCT)lparam;
2604 lpss = (LPSTYLESTRUCT)lpcs->lpCreateParams;
2605 if (lpss)
2607 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
2608 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
2609 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
2610 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
2611 else
2612 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
2614 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
2615 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2616 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
2618 ok(lpss->styleNew == lpcs->style,
2619 "Style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2620 lpss->styleNew, lpcs->style);
2622 break;
2624 return DefWindowProc(hwnd, msg, wparam, lparam);
2627 static ATOM atomStyleCheckClass;
2629 static void register_style_check_class(void)
2631 WNDCLASS wc =
2634 StyleCheckProc,
2637 GetModuleHandle(NULL),
2638 NULL,
2639 LoadCursor(NULL, IDC_ARROW),
2640 (HBRUSH)(COLOR_BTNFACE+1),
2641 NULL,
2642 TEXT("WineStyleCheck"),
2645 atomStyleCheckClass = RegisterClass(&wc);
2648 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
2650 DWORD dwActualStyle;
2651 DWORD dwActualExStyle;
2652 STYLESTRUCT ss;
2653 HWND hwnd;
2654 HWND hwndParent = NULL;
2655 MSG msg;
2657 ss.styleNew = dwStyleIn;
2658 ss.styleOld = dwExStyleIn;
2660 if (dwStyleIn & WS_CHILD)
2662 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
2663 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
2666 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
2667 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
2668 assert(hwnd);
2670 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2672 TranslateMessage(&msg);
2673 DispatchMessage(&msg);
2676 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
2677 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
2678 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
2679 "Style (0x%08lx) should really be 0x%08lx and/or Ex style (0x%08lx) should really be 0x%08lx\n",
2680 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
2682 DestroyWindow(hwnd);
2683 if (hwndParent) DestroyWindow(hwndParent);
2686 /* tests what window styles the window manager automatically adds */
2687 static void test_window_styles(void)
2689 register_style_check_class();
2691 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
2692 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
2693 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
2694 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
2695 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
2696 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
2697 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
2698 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
2699 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
2700 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
2701 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
2704 static void test_scrollvalidate( HWND parent)
2706 HDC hdc;
2707 HRGN hrgn=CreateRectRgn(0,0,0,0);
2708 HRGN exprgn, tmprgn, clipping;
2709 RECT rc, rcu, cliprc;
2710 /* create two overlapping child windows. The visual region
2711 * of hwnd1 is clipped by the overlapping part of
2712 * hwnd2 because of the WS_CLIPSIBLING style */
2713 HWND hwnd1, hwnd2;
2715 hwnd2 = CreateWindowExA(0, "static", NULL,
2716 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
2717 75, 30, 100, 100, parent, 0, 0, NULL);
2718 hwnd1 = CreateWindowExA(0, "static", NULL,
2719 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
2720 25, 50, 100, 100, parent, 0, 0, NULL);
2721 ShowWindow( parent, SW_SHOW);
2722 UpdateWindow( parent);
2723 GetClientRect( hwnd1, &rc);
2724 cliprc=rc;
2725 clipping = CreateRectRgn( 10, 10, 90, 90);
2726 hdc = GetDC( hwnd1);
2727 /* for a visual touch */
2728 TextOut( hdc, 0,10, "0123456789", 10);
2729 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
2730 if (winetest_debug > 0) dump_region(hrgn);
2731 /* create a region with what is expected */
2732 exprgn = CreateRectRgn( 39,0,49,74);
2733 tmprgn = CreateRectRgn( 88,79,98,93);
2734 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2735 tmprgn = CreateRectRgn( 0,93,98,98);
2736 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2737 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2738 trace("update rect is %ld,%ld - %ld,%ld\n",
2739 rcu.left,rcu.top,rcu.right,rcu.bottom);
2740 /* now with clipping region */
2741 SelectClipRgn( hdc, clipping);
2742 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
2743 if (winetest_debug > 0) dump_region(hrgn);
2744 /* create a region with what is expected */
2745 exprgn = CreateRectRgn( 39,10,49,74);
2746 tmprgn = CreateRectRgn( 80,79,90,85);
2747 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2748 tmprgn = CreateRectRgn( 10,85,90,90);
2749 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2750 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2751 trace("update rect is %ld,%ld - %ld,%ld\n",
2752 rcu.left,rcu.top,rcu.right,rcu.bottom);
2753 ReleaseDC( hwnd1, hdc);
2755 /* test scrolling a window with an update region */
2756 DestroyWindow( hwnd2);
2757 ValidateRect( hwnd1, NULL);
2758 SetRect( &rc, 40,40, 50,50);
2759 InvalidateRect( hwnd1, &rc, 1);
2760 GetClientRect( hwnd1, &rc);
2761 cliprc=rc;
2762 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
2763 SW_SCROLLCHILDREN | SW_INVALIDATE);
2764 if (winetest_debug > 0) dump_region(hrgn);
2765 exprgn = CreateRectRgn( 88,0,98,98);
2766 tmprgn = CreateRectRgn( 30, 40, 50, 50);
2767 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2768 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2770 /* now test ScrollWindowEx with a combination of
2771 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
2772 /* make hwnd2 the child of hwnd1 */
2773 hwnd2 = CreateWindowExA(0, "static", NULL,
2774 WS_CHILD| WS_VISIBLE | WS_BORDER ,
2775 50, 50, 100, 100, hwnd1, 0, 0, NULL);
2776 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
2777 GetClientRect( hwnd1, &rc);
2778 cliprc=rc;
2780 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
2781 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
2782 ValidateRect( hwnd1, NULL);
2783 ValidateRect( hwnd2, NULL);
2784 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
2785 SW_SCROLLCHILDREN | SW_INVALIDATE);
2786 if (winetest_debug > 0) dump_region(hrgn);
2787 exprgn = CreateRectRgn( 88,0,98,88);
2788 tmprgn = CreateRectRgn( 0,88,98,98);
2789 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2790 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2792 /* SW_SCROLLCHILDREN */
2793 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
2794 ValidateRect( hwnd1, NULL);
2795 ValidateRect( hwnd2, NULL);
2796 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
2797 if (winetest_debug > 0) dump_region(hrgn);
2798 /* expected region is the same as in previous test */
2799 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2801 /* no SW_SCROLLCHILDREN */
2802 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
2803 ValidateRect( hwnd1, NULL);
2804 ValidateRect( hwnd2, NULL);
2805 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
2806 if (winetest_debug > 0) dump_region(hrgn);
2807 /* expected region is the same as in previous test */
2808 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2810 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
2811 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
2812 ValidateRect( hwnd1, NULL);
2813 ValidateRect( hwnd2, NULL);
2814 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
2815 if (winetest_debug > 0) dump_region(hrgn);
2816 exprgn = CreateRectRgn( 88,0,98,20);
2817 tmprgn = CreateRectRgn( 20,20,98,30);
2818 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2819 tmprgn = CreateRectRgn( 20,30,30,88);
2820 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2821 tmprgn = CreateRectRgn( 0,88,30,98);
2822 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2823 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2825 /* clean up */
2826 DeleteObject( hrgn);
2827 DeleteObject( exprgn);
2828 DeleteObject( tmprgn);
2829 DestroyWindow( hwnd1);
2830 DestroyWindow( hwnd2);
2833 /* couple of tests of return values of scrollbar functions
2834 * called on a scrollbarless window */
2835 static void test_scroll(void)
2837 BOOL ret;
2838 INT min, max;
2839 SCROLLINFO si;
2840 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
2841 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
2842 100, 100, 200, 200, 0, 0, 0, NULL);
2843 /* horizontal */
2844 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
2845 ok( ret, "GetScrollRange returns FALSE\n");
2846 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
2847 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
2848 si.cbSize = sizeof( si);
2849 si.fMask = SIF_PAGE;
2850 si.nPage = 0xdeadbeef;
2851 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
2852 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
2853 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
2854 /* vertical */
2855 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
2856 ok( ret, "GetScrollRange returns FALSE\n");
2857 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
2858 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
2859 si.cbSize = sizeof( si);
2860 si.fMask = SIF_PAGE;
2861 si.nPage = 0xdeadbeef;
2862 ret = GetScrollInfo( hwnd, SB_VERT, &si);
2863 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
2864 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
2865 /* clean up */
2866 DestroyWindow( hwnd);
2869 static void test_params(void)
2871 HWND hwnd;
2872 INT rc;
2874 /* Just a param check */
2875 SetLastError(0xdeadbeef);
2876 rc = GetWindowText(hwndMain2, NULL, 1024);
2877 ok( rc==0, "GetWindowText: rc=%d err=%ld\n",rc,GetLastError());
2879 SetLastError(0xdeadbeef);
2880 hwnd=CreateWindow("LISTBOX", "TestList",
2881 (LBS_STANDARD & ~LBS_SORT),
2882 0, 0, 100, 100,
2883 NULL, (HMENU)1, NULL, 0);
2885 ok(!hwnd, "CreateWindow with invalid menu handle should fail\n");
2886 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
2887 GetLastError() == 0xdeadbeef, /* Win9x */
2888 "wrong last error value %ld\n", GetLastError());
2891 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
2893 HWND hwnd = 0;
2895 hwnd = CreateWindowEx(exStyle, class, class, style,
2896 110, 100,
2897 225, 200,
2899 menu ? hmenu : 0,
2900 0, 0);
2901 if (!hwnd) {
2902 trace("Failed to create window class=%s, style=0x%08lx, exStyle=0x%08lx\n", class, style, exStyle);
2903 return;
2905 ShowWindow(hwnd, SW_SHOW);
2907 test_nonclient_area(hwnd);
2909 SetMenu(hwnd, 0);
2910 DestroyWindow(hwnd);
2913 static BOOL AWR_init(void)
2915 WNDCLASS class;
2917 class.style = CS_HREDRAW | CS_VREDRAW;
2918 class.lpfnWndProc = DefWindowProcA;
2919 class.cbClsExtra = 0;
2920 class.cbWndExtra = 0;
2921 class.hInstance = 0;
2922 class.hIcon = LoadIcon (0, IDI_APPLICATION);
2923 class.hCursor = LoadCursor (0, IDC_ARROW);
2924 class.hbrBackground = 0;
2925 class.lpszMenuName = 0;
2926 class.lpszClassName = szAWRClass;
2928 if (!RegisterClass (&class)) {
2929 ok(FALSE, "RegisterClass failed\n");
2930 return FALSE;
2933 hmenu = CreateMenu();
2934 if (!hmenu)
2935 return FALSE;
2936 ok(hmenu != 0, "Failed to create menu\n");
2937 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
2939 return TRUE;
2943 static void test_AWR_window_size(BOOL menu)
2945 LONG styles[] = {
2946 WS_POPUP,
2947 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
2948 WS_SYSMENU,
2949 WS_THICKFRAME,
2950 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
2951 WS_HSCROLL, WS_VSCROLL
2953 LONG exStyles[] = {
2954 WS_EX_CLIENTEDGE,
2955 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
2956 WS_EX_APPWINDOW,
2957 #if 0
2958 /* These styles have problems on (at least) WinXP (SP2) and Wine */
2959 WS_EX_DLGMODALFRAME,
2960 WS_EX_STATICEDGE,
2961 #endif
2964 int i;
2966 /* A exhaustive check of all the styles takes too long
2967 * so just do a (hopefully representative) sample
2969 for (i = 0; i < COUNTOF(styles); ++i)
2970 test_AWRwindow(szAWRClass, styles[i], 0, menu);
2971 for (i = 0; i < COUNTOF(exStyles); ++i) {
2972 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
2973 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
2976 #undef COUNTOF
2978 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
2980 static void test_AdjustWindowRect(void)
2982 if (!AWR_init())
2983 return;
2985 SHOWSYSMETRIC(SM_CYCAPTION);
2986 SHOWSYSMETRIC(SM_CYSMCAPTION);
2987 SHOWSYSMETRIC(SM_CYMENU);
2988 SHOWSYSMETRIC(SM_CXEDGE);
2989 SHOWSYSMETRIC(SM_CYEDGE);
2990 SHOWSYSMETRIC(SM_CXVSCROLL);
2991 SHOWSYSMETRIC(SM_CYHSCROLL);
2992 SHOWSYSMETRIC(SM_CXFRAME);
2993 SHOWSYSMETRIC(SM_CYFRAME);
2994 SHOWSYSMETRIC(SM_CXDLGFRAME);
2995 SHOWSYSMETRIC(SM_CYDLGFRAME);
2996 SHOWSYSMETRIC(SM_CXBORDER);
2997 SHOWSYSMETRIC(SM_CYBORDER);
2999 test_AWR_window_size(FALSE);
3000 test_AWR_window_size(TRUE);
3002 DestroyMenu(hmenu);
3004 #undef SHOWSYSMETRIC
3007 /* Global variables to trigger exit from loop */
3008 static int redrawComplete, WMPAINT_count;
3010 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3012 switch (msg)
3014 case WM_PAINT:
3015 trace("doing WM_PAINT %d\n", WMPAINT_count);
3016 WMPAINT_count++;
3017 if (WMPAINT_count > 10 && redrawComplete == 0) {
3018 PAINTSTRUCT ps;
3019 BeginPaint(hwnd, &ps);
3020 EndPaint(hwnd, &ps);
3021 return 1;
3023 return 0;
3024 break;
3026 return DefWindowProc(hwnd, msg, wparam, lparam);
3029 /* Ensure we exit from RedrawNow regardless of invalidated area */
3030 static void test_redrawnow(void)
3032 WNDCLASSA cls;
3033 HWND hwndMain;
3035 cls.style = CS_DBLCLKS;
3036 cls.lpfnWndProc = redraw_window_procA;
3037 cls.cbClsExtra = 0;
3038 cls.cbWndExtra = 0;
3039 cls.hInstance = GetModuleHandleA(0);
3040 cls.hIcon = 0;
3041 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3042 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3043 cls.lpszMenuName = NULL;
3044 cls.lpszClassName = "RedrawWindowClass";
3046 if(!RegisterClassA(&cls)) {
3047 trace("Register failed %ld\n", GetLastError());
3048 return;
3051 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3052 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3054 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3055 ShowWindow(hwndMain, SW_SHOW);
3056 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3057 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3058 ok( WMPAINT_count == 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3059 redrawComplete = TRUE;
3060 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3062 /* clean up */
3063 DestroyWindow( hwndMain);
3066 struct parentdc_stat {
3067 RECT client;
3068 RECT clip;
3069 RECT paint;
3072 struct parentdc_test {
3073 struct parentdc_stat main, main_todo;
3074 struct parentdc_stat child1, child1_todo;
3075 struct parentdc_stat child2, child2_todo;
3078 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3080 RECT rc;
3081 PAINTSTRUCT ps;
3083 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3085 switch (msg)
3087 case WM_PAINT:
3088 trace("doing WM_PAINT on %p\n", hwnd);
3089 GetClientRect(hwnd, &rc);
3090 CopyRect(&t->client, &rc);
3091 trace("client rect (%ld, %ld)-(%ld, %ld)\n", rc.left, rc.top, rc.right, rc.bottom);
3092 GetWindowRect(hwnd, &rc);
3093 trace("window rect (%ld, %ld)-(%ld, %ld)\n", rc.left, rc.top, rc.right, rc.bottom);
3094 BeginPaint(hwnd, &ps);
3095 CopyRect(&t->paint, &ps.rcPaint);
3096 GetClipBox(ps.hdc, &rc);
3097 CopyRect(&t->clip, &rc);
3098 trace("clip rect (%ld, %ld)-(%ld, %ld)\n", rc.left, rc.top, rc.right, rc.bottom);
3099 trace("paint rect (%ld, %ld)-(%ld, %ld)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3100 EndPaint(hwnd, &ps);
3101 return 0;
3103 return DefWindowProc(hwnd, msg, wparam, lparam);
3106 static void zero_parentdc_stat(struct parentdc_stat *t)
3108 SetRectEmpty(&t->client);
3109 SetRectEmpty(&t->clip);
3110 SetRectEmpty(&t->paint);
3113 static void zero_parentdc_test(struct parentdc_test *t)
3115 zero_parentdc_stat(&t->main);
3116 zero_parentdc_stat(&t->child1);
3117 zero_parentdc_stat(&t->child2);
3120 #define parentdc_field_ok(t, w, r, f, got) \
3121 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3122 ": expected %ld, got %ld\n", \
3123 t.w.r.f, got.w.r.f)
3125 #define parentdc_todo_field_ok(t, w, r, f, got) \
3126 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3127 else parentdc_field_ok(t, w, r, f, got)
3129 #define parentdc_rect_ok(t, w, r, got) \
3130 parentdc_todo_field_ok(t, w, r, left, got); \
3131 parentdc_todo_field_ok(t, w, r, top, got); \
3132 parentdc_todo_field_ok(t, w, r, right, got); \
3133 parentdc_todo_field_ok(t, w, r, bottom, got);
3135 #define parentdc_win_ok(t, w, got) \
3136 parentdc_rect_ok(t, w, client, got); \
3137 parentdc_rect_ok(t, w, clip, got); \
3138 parentdc_rect_ok(t, w, paint, got);
3140 #define parentdc_ok(t, got) \
3141 parentdc_win_ok(t, main, got); \
3142 parentdc_win_ok(t, child1, got); \
3143 parentdc_win_ok(t, child2, got);
3145 static void test_csparentdc(void)
3147 WNDCLASSA clsMain, cls;
3148 HWND hwndMain, hwnd1, hwnd2;
3149 MSG msg;
3150 RECT rc;
3152 struct parentdc_test test_answer;
3154 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3155 const struct parentdc_test test1 =
3157 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
3158 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3159 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3162 const struct parentdc_test test2 =
3164 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
3165 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3166 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3169 const struct parentdc_test test3 =
3171 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3172 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3173 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3176 const struct parentdc_test test4 =
3178 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
3179 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
3180 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3183 const struct parentdc_test test5 =
3185 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
3186 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3187 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3190 const struct parentdc_test test6 =
3192 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3193 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3194 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3197 const struct parentdc_test test7 =
3199 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3200 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3201 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3203 #undef nothing_todo
3205 clsMain.style = CS_DBLCLKS;
3206 clsMain.lpfnWndProc = parentdc_window_procA;
3207 clsMain.cbClsExtra = 0;
3208 clsMain.cbWndExtra = 0;
3209 clsMain.hInstance = GetModuleHandleA(0);
3210 clsMain.hIcon = 0;
3211 clsMain.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3212 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
3213 clsMain.lpszMenuName = NULL;
3214 clsMain.lpszClassName = "ParentDcMainWindowClass";
3216 if(!RegisterClassA(&clsMain)) {
3217 trace("Register failed %ld\n", GetLastError());
3218 return;
3221 cls.style = CS_DBLCLKS | CS_PARENTDC;
3222 cls.lpfnWndProc = parentdc_window_procA;
3223 cls.cbClsExtra = 0;
3224 cls.cbWndExtra = 0;
3225 cls.hInstance = GetModuleHandleA(0);
3226 cls.hIcon = 0;
3227 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3228 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3229 cls.lpszMenuName = NULL;
3230 cls.lpszClassName = "ParentDcWindowClass";
3232 if(!RegisterClassA(&cls)) {
3233 trace("Register failed %ld\n", GetLastError());
3234 return;
3237 SetRect(&rc, 0, 0, 150, 150);
3238 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
3239 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3240 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
3241 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
3242 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
3243 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
3244 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
3245 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
3246 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
3247 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
3248 ShowWindow(hwndMain, SW_SHOW);
3249 ShowWindow(hwnd1, SW_SHOW);
3250 ShowWindow(hwnd2, SW_SHOW);
3252 zero_parentdc_test(&test_answer);
3253 InvalidateRect(hwndMain, NULL, TRUE);
3254 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3255 parentdc_ok(test1, test_answer);
3257 zero_parentdc_test(&test_answer);
3258 SetRect(&rc, 0, 0, 50, 50);
3259 InvalidateRect(hwndMain, &rc, TRUE);
3260 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3261 parentdc_ok(test2, test_answer);
3263 zero_parentdc_test(&test_answer);
3264 SetRect(&rc, 0, 0, 10, 10);
3265 InvalidateRect(hwndMain, &rc, TRUE);
3266 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3267 parentdc_ok(test3, test_answer);
3269 zero_parentdc_test(&test_answer);
3270 SetRect(&rc, 40, 40, 50, 50);
3271 InvalidateRect(hwndMain, &rc, TRUE);
3272 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3273 parentdc_ok(test4, test_answer);
3275 zero_parentdc_test(&test_answer);
3276 SetRect(&rc, 20, 20, 60, 60);
3277 InvalidateRect(hwndMain, &rc, TRUE);
3278 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3279 parentdc_ok(test5, test_answer);
3281 zero_parentdc_test(&test_answer);
3282 SetRect(&rc, 0, 0, 10, 10);
3283 InvalidateRect(hwnd1, &rc, TRUE);
3284 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3285 parentdc_ok(test6, test_answer);
3287 zero_parentdc_test(&test_answer);
3288 SetRect(&rc, -5, -5, 65, 65);
3289 InvalidateRect(hwnd1, &rc, TRUE);
3290 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3291 parentdc_ok(test7, test_answer);
3293 DestroyWindow(hwndMain);
3294 DestroyWindow(hwnd1);
3295 DestroyWindow(hwnd2);
3298 static void test_IsWindowUnicode(void)
3300 static const char ansi_class_nameA[] = "ansi class name";
3301 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3302 static const char unicode_class_nameA[] = "unicode class name";
3303 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3304 WNDCLASSA classA;
3305 WNDCLASSW classW;
3306 HWND hwnd;
3308 memset(&classW, 0, sizeof(classW));
3309 classW.hInstance = GetModuleHandleA(0);
3310 classW.lpfnWndProc = DefWindowProcW;
3311 classW.lpszClassName = unicode_class_nameW;
3312 if (!RegisterClassW(&classW)) return;
3314 memset(&classA, 0, sizeof(classA));
3315 classA.hInstance = GetModuleHandleA(0);
3316 classA.lpfnWndProc = DefWindowProcA;
3317 classA.lpszClassName = ansi_class_nameA;
3318 assert(RegisterClassA(&classA));
3320 /* unicode class: window proc */
3321 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3322 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3323 assert(hwnd);
3325 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3326 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3327 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3328 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3329 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3331 DestroyWindow(hwnd);
3333 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3334 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3335 assert(hwnd);
3337 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3338 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3339 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3340 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3341 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3343 DestroyWindow(hwnd);
3345 /* ansi class: window proc */
3346 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3347 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3348 assert(hwnd);
3350 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3351 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3352 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3353 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3354 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3356 DestroyWindow(hwnd);
3358 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3359 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3360 assert(hwnd);
3362 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3363 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3364 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3365 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3366 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3368 DestroyWindow(hwnd);
3370 /* unicode class: class proc */
3371 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3372 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3373 assert(hwnd);
3375 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3376 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3377 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3378 /* do not restore class window proc back to unicode */
3380 DestroyWindow(hwnd);
3382 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3383 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3384 assert(hwnd);
3386 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3387 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3388 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3390 DestroyWindow(hwnd);
3392 /* ansi class: class proc */
3393 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3394 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3395 assert(hwnd);
3397 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3398 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3399 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3400 /* do not restore class window proc back to ansi */
3402 DestroyWindow(hwnd);
3404 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3405 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3406 assert(hwnd);
3408 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3409 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3410 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3412 DestroyWindow(hwnd);
3415 START_TEST(win)
3417 pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
3418 pGetWindowInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
3420 hwndMain = CreateWindowExA(0, "static", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, NULL);
3421 if (hwndMain)
3423 ok(!GetParent(hwndMain), "GetParent should return 0 for message only windows\n");
3424 if (pGetAncestor)
3426 hwndMessage = pGetAncestor(hwndMain, GA_PARENT);
3427 ok(hwndMessage != 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
3428 trace("hwndMessage %p\n", hwndMessage);
3430 DestroyWindow(hwndMain);
3432 else
3433 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
3435 if (!RegisterWindowClasses()) assert(0);
3437 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
3438 assert(hhook);
3440 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
3441 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3442 WS_MAXIMIZEBOX | WS_POPUP,
3443 100, 100, 200, 200,
3444 0, 0, 0, NULL);
3445 test_nonclient_area(hwndMain);
3447 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
3448 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3449 WS_MAXIMIZEBOX | WS_POPUP,
3450 100, 100, 200, 200,
3451 0, 0, 0, NULL);
3452 assert( hwndMain );
3453 assert( hwndMain2 );
3455 test_params();
3457 test_capture_1();
3458 test_capture_2();
3459 test_capture_3(hwndMain, hwndMain2);
3461 test_parent_owner();
3462 test_SetParent();
3463 test_shell_window();
3465 test_mdi();
3466 test_icons();
3467 test_SetWindowPos(hwndMain);
3468 test_SetMenu(hwndMain);
3469 test_SetFocus(hwndMain);
3470 test_SetActiveWindow(hwndMain);
3472 test_children_zorder(hwndMain);
3473 test_keyboard_input(hwndMain);
3474 test_mouse_input(hwndMain);
3475 test_validatergn(hwndMain);
3476 test_nccalcscroll( hwndMain);
3477 test_scrollvalidate( hwndMain);
3478 test_scroll();
3479 test_IsWindowUnicode();
3480 test_vis_rgn(hwndMain);
3482 UnhookWindowsHookEx(hhook);
3484 test_AdjustWindowRect();
3485 test_window_styles();
3486 test_redrawnow();
3487 test_csparentdc();