2 * Unit tests for window handling
4 * Copyright 2002 Bill Medland
5 * Copyright 2002 Alexandre Julliard
6 * Copyright 2003 Dmitry Timoshkov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 /* To get ICON_SMALL2 with the MSVC headers */
24 #define _WIN32_WINNT 0x0501
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
39 #include "wine/test.h"
41 #ifndef SPI_GETDESKWALLPAPER
42 #define SPI_GETDESKWALLPAPER 0x0073
45 #define LONG_PTR INT_PTR
46 #define ULONG_PTR UINT_PTR
48 void dump_region(HRGN hrgn);
50 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
51 static BOOL (WINAPI *pGetWindowInfo)(HWND,WINDOWINFO*);
53 static BOOL test_lbuttondown_flag;
54 static HWND hwndMessage;
55 static HWND hwndMain, hwndMain2;
58 static const char* szAWRClass = "Winsize";
61 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
63 /* check the values returned by the various parent/owner functions on a given window */
64 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
65 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
71 res = pGetAncestor( hwnd, GA_PARENT );
72 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
74 res = (HWND)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 );
82 res = pGetAncestor( hwnd, GA_ROOT );
83 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
84 res = pGetAncestor( hwnd, GA_ROOTOWNER );
85 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
90 static HWND create_tool_window( LONG style, HWND parent )
92 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
93 0, 0, 100, 100, parent, 0, 0, NULL );
94 ok( ret != 0, "Creation failed\n" );
98 /* test parent and owner values for various combinations */
99 static void test_parent_owner(void)
102 HWND test, owner, ret;
103 HWND desktop = GetDesktopWindow();
104 HWND child = create_tool_window( WS_CHILD, hwndMain );
106 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
108 /* child without parent, should fail */
109 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
110 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
111 ok( !test, "WS_CHILD without parent created\n" );
114 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
115 style = GetWindowLongA( desktop, GWL_STYLE );
116 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
117 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
118 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
120 /* normal child window */
121 test = create_tool_window( WS_CHILD, hwndMain );
122 trace( "created child %p\n", test );
123 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
124 SetWindowLongA( test, GWL_STYLE, 0 );
125 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
126 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
127 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
128 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
129 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
130 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
131 DestroyWindow( test );
133 /* normal child window with WS_MAXIMIZE */
134 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
135 DestroyWindow( test );
137 /* normal child window with WS_THICKFRAME */
138 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
139 DestroyWindow( test );
141 /* popup window with WS_THICKFRAME */
142 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
143 DestroyWindow( test );
145 /* child of desktop */
146 test = create_tool_window( WS_CHILD, desktop );
147 trace( "created child of desktop %p\n", test );
148 check_parents( test, desktop, 0, desktop, 0, test, desktop );
149 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
150 check_parents( test, desktop, 0, 0, 0, test, test );
151 SetWindowLongA( test, GWL_STYLE, 0 );
152 check_parents( test, desktop, 0, 0, 0, test, test );
153 DestroyWindow( test );
155 /* child of desktop with WS_MAXIMIZE */
156 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
157 DestroyWindow( test );
159 /* child of desktop with WS_MINIMIZE */
160 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
161 DestroyWindow( test );
164 test = create_tool_window( WS_CHILD, child );
165 trace( "created child of child %p\n", test );
166 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
167 SetWindowLongA( test, GWL_STYLE, 0 );
168 check_parents( test, child, child, 0, 0, hwndMain, test );
169 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
170 check_parents( test, child, child, 0, 0, hwndMain, test );
171 DestroyWindow( test );
173 /* child of child with WS_MAXIMIZE */
174 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
175 DestroyWindow( test );
177 /* child of child with WS_MINIMIZE */
178 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
179 DestroyWindow( test );
181 /* not owned top-level window */
182 test = create_tool_window( 0, 0 );
183 trace( "created top-level %p\n", test );
184 check_parents( test, desktop, 0, 0, 0, test, test );
185 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
186 check_parents( test, desktop, 0, 0, 0, test, test );
187 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
188 check_parents( test, desktop, 0, desktop, 0, test, desktop );
189 DestroyWindow( test );
191 /* not owned top-level window with WS_MAXIMIZE */
192 test = create_tool_window( WS_MAXIMIZE, 0 );
193 DestroyWindow( test );
195 /* owned top-level window */
196 test = create_tool_window( 0, hwndMain );
197 trace( "created owned top-level %p\n", test );
198 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
199 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
200 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
201 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
202 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
203 DestroyWindow( test );
205 /* owned top-level window with WS_MAXIMIZE */
206 test = create_tool_window( WS_MAXIMIZE, hwndMain );
207 DestroyWindow( test );
209 /* not owned popup */
210 test = create_tool_window( WS_POPUP, 0 );
211 trace( "created popup %p\n", test );
212 check_parents( test, desktop, 0, 0, 0, test, test );
213 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
214 check_parents( test, desktop, 0, desktop, 0, test, desktop );
215 SetWindowLongA( test, GWL_STYLE, 0 );
216 check_parents( test, desktop, 0, 0, 0, test, test );
217 DestroyWindow( test );
219 /* not owned popup with WS_MAXIMIZE */
220 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
221 DestroyWindow( test );
224 test = create_tool_window( WS_POPUP, hwndMain );
225 trace( "created owned popup %p\n", test );
226 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
227 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
228 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
229 SetWindowLongA( test, GWL_STYLE, 0 );
230 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
231 DestroyWindow( test );
233 /* owned popup with WS_MAXIMIZE */
234 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
235 DestroyWindow( test );
237 /* top-level window owned by child (same as owned by top-level) */
238 test = create_tool_window( 0, child );
239 trace( "created top-level owned by child %p\n", test );
240 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
241 DestroyWindow( test );
243 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
244 test = create_tool_window( WS_MAXIMIZE, child );
245 DestroyWindow( test );
247 /* popup owned by desktop (same as not owned) */
248 test = create_tool_window( WS_POPUP, desktop );
249 trace( "created popup owned by desktop %p\n", test );
250 check_parents( test, desktop, 0, 0, 0, test, test );
251 DestroyWindow( test );
253 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
254 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
255 DestroyWindow( test );
257 /* popup owned by child (same as owned by top-level) */
258 test = create_tool_window( WS_POPUP, child );
259 trace( "created popup owned by child %p\n", test );
260 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
261 DestroyWindow( test );
263 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
264 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
265 DestroyWindow( test );
267 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
268 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
269 trace( "created WS_CHILD popup %p\n", test );
270 check_parents( test, desktop, 0, 0, 0, test, test );
271 DestroyWindow( test );
273 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
274 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
275 DestroyWindow( test );
277 /* owned popup with WS_CHILD (same as WS_POPUP only) */
278 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
279 trace( "created owned WS_CHILD popup %p\n", test );
280 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
281 DestroyWindow( test );
283 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
284 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
285 DestroyWindow( test );
287 /******************** parent changes *************************/
288 trace( "testing parent changes\n" );
291 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
292 #if 0 /* this test succeeds on NT but crashes on win9x systems */
293 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
294 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
295 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
296 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
297 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
299 /* normal child window */
300 test = create_tool_window( WS_CHILD, hwndMain );
301 trace( "created child %p\n", test );
303 ret = (HWND)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 );
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 );
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 );*/
442 DestroyWindow(child);
446 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
450 case WM_GETMINMAXINFO:
452 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
454 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd, wparam, lparam);
455 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
456 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
457 minmax->ptReserved.x, minmax->ptReserved.y,
458 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
459 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
460 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
461 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
462 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
465 case WM_WINDOWPOSCHANGING:
467 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
468 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
469 trace("main: WM_WINDOWPOSCHANGING\n");
470 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
471 winpos->hwnd, winpos->hwndInsertAfter,
472 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
473 if (!(winpos->flags & SWP_NOMOVE))
475 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
476 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
478 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
479 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
481 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
482 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
486 case WM_WINDOWPOSCHANGED:
489 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
490 trace("main: WM_WINDOWPOSCHANGED\n");
491 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
492 winpos->hwnd, winpos->hwndInsertAfter,
493 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
494 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
495 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
497 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
498 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
500 GetWindowRect(hwnd, &rc1);
501 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
502 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
503 /* note: winpos coordinates are relative to parent */
504 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
505 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
506 #if 0 /* Uncomment this once the test succeeds in all cases */
507 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
510 GetClientRect(hwnd, &rc2);
511 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
512 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
513 ok(EqualRect(&rc1, &rc2), "rects do not match (%ld,%ld-%ld,%ld) / (%ld,%ld-%ld,%ld)\n",
514 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
519 BOOL got_getminmaxinfo = 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");
529 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
533 if (test_lbuttondown_flag)
534 ShowWindow((HWND)wparam, SW_SHOW);
538 return DefWindowProcA(hwnd, msg, wparam, lparam);
541 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
545 case WM_GETMINMAXINFO:
547 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
549 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd, wparam, lparam);
550 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
551 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
552 minmax->ptReserved.x, minmax->ptReserved.y,
553 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
554 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
555 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
556 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
557 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
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");
572 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
577 return DefWindowProcA(hwnd, msg, wparam, lparam);
580 static BOOL RegisterWindowClasses(void)
584 cls.style = CS_DBLCLKS;
585 cls.lpfnWndProc = main_window_procA;
588 cls.hInstance = GetModuleHandleA(0);
590 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
591 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
592 cls.lpszMenuName = NULL;
593 cls.lpszClassName = "MainWindowClass";
595 if(!RegisterClassA(&cls)) return FALSE;
598 cls.lpfnWndProc = tool_window_procA;
601 cls.hInstance = GetModuleHandleA(0);
603 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
604 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
605 cls.lpszMenuName = NULL;
606 cls.lpszClassName = "ToolWindowClass";
608 if(!RegisterClassA(&cls)) return FALSE;
613 static void verify_window_info(HWND hwnd, const WINDOWINFO *info, BOOL test_borders)
615 RECT rcWindow, rcClient;
619 ok(IsWindow(hwnd), "bad window handle\n");
621 GetWindowRect(hwnd, &rcWindow);
622 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow\n");
624 GetClientRect(hwnd, &rcClient);
625 /* translate to screen coordinates */
626 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
627 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient\n");
629 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
630 "wrong dwStyle: %08lx != %08lx\n", info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE));
631 ok(info->dwExStyle == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
632 "wrong dwExStyle: %08lx != %08lx\n", info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE));
633 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
634 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04lx != %04lx\n",
635 info->dwWindowStatus, status);
637 if (test_borders && !IsRectEmpty(&rcWindow))
639 trace("rcWindow: %ld,%ld - %ld,%ld\n", rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
640 trace("rcClient: %ld,%ld - %ld,%ld\n", rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
642 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
643 "wrong cxWindowBorders %d != %ld\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
644 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
645 ok(info->cyWindowBorders == border,
646 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
649 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType\n");
650 ok(info->wCreatorVersion == 0x0400, "wrong wCreatorVersion %04x\n", info->wCreatorVersion);
653 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
655 AdjustWindowRectEx(rc, style, menu, exstyle);
656 /* AdjustWindowRectEx does not include scroll bars */
657 if (style & WS_VSCROLL)
659 if(exstyle & WS_EX_LEFTSCROLLBAR)
660 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
662 rc->right += GetSystemMetrics(SM_CXVSCROLL);
664 if (style & WS_HSCROLL)
665 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
668 static void test_nonclient_area(HWND hwnd)
670 DWORD style, exstyle;
671 RECT rc_window, rc_client, rc;
673 BOOL is_win9x = 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 */;
706 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
707 SetRect(&rc_client, 0, 0, 250, 150);
708 CopyRect(&rc_window, &rc_client);
709 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
710 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
711 trace("calc window: (%ld,%ld)-(%ld,%ld)\n",
712 rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
714 CopyRect(&rc, &rc_window);
715 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
716 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
717 trace("calc client: (%ld,%ld)-(%ld,%ld)\n", rc.left, rc.top, rc.right, rc.bottom);
718 ok(EqualRect(&rc, &rc_client), "synthetic rect does not match: style:exstyle=0x%08lx:0x%08lx, menu=%d\n", style, exstyle, menu);
721 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
723 static const char *CBT_code_name[10] = {
734 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
736 trace("CBT: %d (%s), %08x, %08lx\n", nCode, code_name, wParam, lParam);
738 /* on HCBT_DESTROYWND window state is undefined */
739 if (nCode != HCBT_DESTROYWND && IsWindow((HWND)wParam))
745 /* Win98 actually does check the info.cbSize and doesn't allow
746 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
747 * WinXP do not check it at all.
749 info.cbSize = sizeof(WINDOWINFO);
750 ok(pGetWindowInfo((HWND)wParam, &info), "GetWindowInfo should not fail\n");
751 /* win2k SP4 returns broken border info if GetWindowInfo
752 * is being called from HCBT_DESTROYWND or HCBT_MINMAX hook proc.
754 verify_window_info((HWND)wParam, &info, nCode != HCBT_MINMAX);
762 #if 0 /* Uncomment this once the test succeeds in all cases */
763 static const RECT rc_null;
767 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
768 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08lx\n",
769 (HWND)wParam, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
770 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
772 /* WS_VISIBLE should be turned off yet */
773 style = createwnd->lpcs->style & ~WS_VISIBLE;
774 ok(style == GetWindowLongA((HWND)wParam, GWL_STYLE),
775 "style of hwnd and style in the CREATESTRUCT do not match: %08lx != %08lx\n",
776 GetWindowLongA((HWND)wParam, GWL_STYLE), style);
778 #if 0 /* Uncomment this once the test succeeds in all cases */
779 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
781 ok(GetParent((HWND)wParam) == hwndMessage,
782 "wrong result from GetParent %p: message window %p\n",
783 GetParent((HWND)wParam), hwndMessage);
786 ok(!GetParent((HWND)wParam), "GetParent should return 0 at this point\n");
788 ok(!GetWindow((HWND)wParam, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
790 #if 0 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
791 * Win9x still has them set to 0.
793 ok(GetWindow((HWND)wParam, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
794 ok(GetWindow((HWND)wParam, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
796 ok(!GetWindow((HWND)wParam, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
797 ok(!GetWindow((HWND)wParam, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
799 #if 0 /* Uncomment this once the test succeeds in all cases */
802 ok(pGetAncestor((HWND)wParam, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
803 ok(pGetAncestor((HWND)wParam, GA_ROOT) == (HWND)wParam,
804 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOT), (HWND)wParam);
806 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
807 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == hwndMessage,
808 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
810 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == (HWND)wParam,
811 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOTOWNER), (HWND)wParam);
814 ok(GetWindowRect((HWND)wParam, &rc), "GetWindowRect failed\n");
815 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
816 ok(GetClientRect((HWND)wParam, &rc), "GetClientRect failed\n");
817 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
823 return CallNextHookEx(hhook, nCode, wParam, lParam);
826 static void test_shell_window(void)
830 HMODULE hinst, hUser32;
831 BOOL (WINAPI*SetShellWindow)(HWND);
832 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
833 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
834 HWND shellWindow, nextWnd;
836 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
838 trace("Skipping shell window test on Win9x\n");
842 shellWindow = GetShellWindow();
843 hinst = GetModuleHandle(0);
844 hUser32 = GetModuleHandleA("user32");
846 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
847 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
849 trace("previous shell window: %p\n", shellWindow);
855 ret = DestroyWindow(shellWindow);
856 error = GetLastError();
858 ok(!ret, "DestroyWindow(shellWindow)\n");
859 /* passes on Win XP, but not on Win98 */
860 ok(error==ERROR_ACCESS_DENIED, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n");
862 /* close old shell instance */
863 GetWindowThreadProcessId(shellWindow, &pid);
864 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
865 ret = TerminateProcess(hProcess, 0);
866 ok(ret, "termination of previous shell process failed: GetLastError()=%ld\n", GetLastError());
867 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
868 CloseHandle(hProcess);
871 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
872 trace("created window 1: %p\n", hwnd1);
874 ret = SetShellWindow(hwnd1);
875 ok(ret, "first call to SetShellWindow(hwnd1)\n");
876 shellWindow = GetShellWindow();
877 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
879 ret = SetShellWindow(hwnd1);
880 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
882 ret = SetShellWindow(0);
883 error = GetLastError();
884 /* passes on Win XP, but not on Win98
885 ok(!ret, "reset shell window by SetShellWindow(0)\n");
886 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
888 ret = SetShellWindow(hwnd1);
889 /* passes on Win XP, but not on Win98
890 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
894 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
895 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
896 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
899 ret = DestroyWindow(hwnd1);
900 ok(ret, "DestroyWindow(hwnd1)\n");
902 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
903 trace("created window 2: %p\n", hwnd2);
904 ret = SetShellWindow(hwnd2);
905 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
907 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
908 trace("created window 3: %p\n", hwnd3);
910 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
911 trace("created window 4: %p\n", hwnd4);
913 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
914 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
916 ret = SetShellWindow(hwnd4);
917 ok(ret, "SetShellWindow(hwnd4)\n");
918 shellWindow = GetShellWindow();
919 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
921 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
922 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
924 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
925 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
927 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
928 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
930 ret = SetShellWindow(hwnd3);
931 ok(!ret, "SetShellWindow(hwnd3)\n");
932 shellWindow = GetShellWindow();
933 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
935 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
936 trace("created window 5: %p\n", hwnd5);
937 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
938 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
942 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
943 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
946 /* destroy test windows */
947 DestroyWindow(hwnd2);
948 DestroyWindow(hwnd3);
949 DestroyWindow(hwnd4);
950 DestroyWindow(hwnd5);
953 /************** MDI test ****************/
955 static const char mdi_lParam_test_message[] = "just a test string";
957 static void test_MDI_create(HWND parent, HWND mdi_client, INT first_id)
959 MDICREATESTRUCTA mdi_cs;
961 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
962 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
963 BOOL isWin9x = FALSE;
965 mdi_cs.szClass = "MDI_child_Class_1";
966 mdi_cs.szTitle = "MDI child";
967 mdi_cs.hOwner = GetModuleHandle(0);
968 mdi_cs.x = CW_USEDEFAULT;
969 mdi_cs.y = CW_USEDEFAULT;
970 mdi_cs.cx = CW_USEDEFAULT;
971 mdi_cs.cy = CW_USEDEFAULT;
973 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
974 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
975 ok(mdi_child != 0, "MDI child creation failed\n");
976 ok(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");
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 */
1004 mdi_cs.szClass = (LPCSTR)classW;
1005 mdi_cs.szTitle = (LPCSTR)titleW;
1006 SetLastError(0xdeadbeef);
1007 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1010 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1013 ok(mdi_child != 0, "MDI child creation failed\n");
1017 ok(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");
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);
1072 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1075 ok(mdi_child != 0, "MDI child creation failed\n");
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");
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);
1134 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1137 ok(mdi_child != 0, "MDI child creation failed\n");
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 */
1149 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1151 CW_USEDEFAULT, CW_USEDEFAULT,
1152 CW_USEDEFAULT, CW_USEDEFAULT,
1153 parent, 0, GetModuleHandle(0),
1154 (LPVOID)mdi_lParam_test_message);
1155 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1158 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1159 WS_CHILD, /* without WS_POPUP */
1160 CW_USEDEFAULT, CW_USEDEFAULT,
1161 CW_USEDEFAULT, CW_USEDEFAULT,
1162 mdi_client, 0, GetModuleHandle(0),
1163 (LPVOID)mdi_lParam_test_message);
1164 ok(mdi_child != 0, "MDI child creation failed\n");
1165 ok(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 )
1222 GetClientRect( client, &rect );
1223 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1224 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1226 rect.right -= rect.left;
1227 rect.bottom -= rect.top;
1228 lpMinMax->ptMaxSize.x = rect.right;
1229 lpMinMax->ptMaxSize.y = rect.bottom;
1231 lpMinMax->ptMaxPosition.x = rect.left;
1232 lpMinMax->ptMaxPosition.y = rect.top;
1234 trace("max rect (%ld,%ld - %ld, %ld)\n",
1235 rect.left, rect.top, rect.right, rect.bottom);
1238 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1245 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1246 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs->lpCreateParams;
1248 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1249 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1251 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1252 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1253 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1254 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1255 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1257 /* MDICREATESTRUCT should have original values */
1258 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1259 "mdi_cs->style does not match (%08lx)\n", mdi_cs->style);
1260 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1261 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1262 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1263 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1265 /* CREATESTRUCT should have fixed values */
1266 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1267 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1269 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1270 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1271 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1273 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1275 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1277 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1278 ok(cs->style == style,
1279 "cs->style does not match (%08lx)\n", cs->style);
1283 LONG style = mdi_cs->style;
1285 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1286 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1287 ok(cs->style == style,
1288 "cs->style does not match (%08lx)\n", cs->style);
1293 case WM_GETMINMAXINFO:
1295 HWND client = GetParent(hwnd);
1297 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1298 MINMAXINFO my_minmax;
1299 LONG style, exstyle;
1301 style = GetWindowLongA(hwnd, GWL_STYLE);
1302 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1304 GetWindowRect(client, &rc);
1305 trace("MDI client %p window size = (%ld x %ld)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1306 GetClientRect(client, &rc);
1307 trace("MDI client %p client size = (%ld x %ld)\n", client, rc.right, rc.bottom);
1308 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1309 GetSystemMetrics(SM_CYSCREEN));
1311 GetClientRect(client, &rc);
1312 if ((style & WS_CAPTION) == WS_CAPTION)
1313 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1314 AdjustWindowRectEx(&rc, style, 0, exstyle);
1315 trace("MDI child: calculated max window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1317 trace("ptReserved = (%ld,%ld)\n"
1318 "ptMaxSize = (%ld,%ld)\n"
1319 "ptMaxPosition = (%ld,%ld)\n"
1320 "ptMinTrackSize = (%ld,%ld)\n"
1321 "ptMaxTrackSize = (%ld,%ld)\n",
1322 minmax->ptReserved.x, minmax->ptReserved.y,
1323 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1324 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1325 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1326 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1328 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1329 minmax->ptMaxSize.x, rc.right - rc.left);
1330 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1331 minmax->ptMaxSize.y, rc.bottom - rc.top);
1333 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1335 trace("DefMDIChildProc returned:\n"
1336 "ptReserved = (%ld,%ld)\n"
1337 "ptMaxSize = (%ld,%ld)\n"
1338 "ptMaxPosition = (%ld,%ld)\n"
1339 "ptMinTrackSize = (%ld,%ld)\n"
1340 "ptMaxTrackSize = (%ld,%ld)\n",
1341 minmax->ptReserved.x, minmax->ptReserved.y,
1342 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1343 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1344 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1345 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1347 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1348 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %ld != %ld\n",
1349 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1350 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %ld != %ld\n",
1351 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1356 case WM_MDIACTIVATE:
1358 HWND active, client = GetParent(hwnd);
1359 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1360 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1361 if (hwnd == (HWND)lparam) /* if we are being activated */
1362 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1364 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1368 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1371 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1378 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1380 trace("%s\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE");
1381 trace("x %d, y %d, cx %d, cy %d\n", cs->x, cs->y, cs->cx, cs->cy);
1383 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1384 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1386 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1387 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1389 /* CREATESTRUCT should have fixed values */
1390 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1392 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1393 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1395 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1396 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1397 while Win95, Win2k, WinXP do. */
1398 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1399 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1403 case WM_GETMINMAXINFO:
1405 HWND parent = GetParent(hwnd);
1407 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1408 LONG style, exstyle;
1410 trace("WM_GETMINMAXINFO\n");
1412 style = GetWindowLongA(hwnd, GWL_STYLE);
1413 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1415 GetClientRect(parent, &rc);
1416 trace("parent %p client size = (%ld x %ld)\n", parent, rc.right, rc.bottom);
1418 GetClientRect(parent, &rc);
1419 if ((style & WS_CAPTION) == WS_CAPTION)
1420 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1421 AdjustWindowRectEx(&rc, style, 0, exstyle);
1422 trace("calculated max child window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1424 trace("ptReserved = (%ld,%ld)\n"
1425 "ptMaxSize = (%ld,%ld)\n"
1426 "ptMaxPosition = (%ld,%ld)\n"
1427 "ptMinTrackSize = (%ld,%ld)\n"
1428 "ptMaxTrackSize = (%ld,%ld)\n",
1429 minmax->ptReserved.x, minmax->ptReserved.y,
1430 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1431 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1432 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1433 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1435 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1436 minmax->ptMaxSize.x, rc.right - rc.left);
1437 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1438 minmax->ptMaxSize.y, rc.bottom - rc.top);
1442 case WM_WINDOWPOSCHANGED:
1444 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1447 GetWindowRect(hwnd, &rc1);
1448 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1449 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1450 /* note: winpos coordinates are relative to parent */
1451 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1452 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1453 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1455 GetWindowRect(hwnd, &rc1);
1456 GetClientRect(hwnd, &rc2);
1457 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1458 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1459 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1462 case WM_WINDOWPOSCHANGING:
1464 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1465 WINDOWPOS my_winpos = *winpos;
1467 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1468 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1469 winpos->hwnd, winpos->hwndInsertAfter,
1470 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1472 DefWindowProcA(hwnd, msg, wparam, lparam);
1474 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1475 winpos->hwnd, winpos->hwndInsertAfter,
1476 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1478 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1479 "DefWindowProc should not change WINDOWPOS values\n");
1484 return DefWindowProcA(hwnd, msg, wparam, lparam);
1487 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1489 static HWND mdi_client;
1495 CLIENTCREATESTRUCT client_cs;
1498 GetClientRect(hwnd, &rc);
1500 client_cs.hWindowMenu = 0;
1501 client_cs.idFirstChild = 1;
1503 /* MDIClient without MDIS_ALLCHILDSTYLES */
1504 mdi_client = CreateWindowExA(0, "mdiclient",
1506 WS_CHILD /*| WS_VISIBLE*/,
1507 /* tests depend on a not zero MDIClient size */
1508 0, 0, rc.right, rc.bottom,
1509 hwnd, 0, GetModuleHandle(0),
1510 (LPVOID)&client_cs);
1512 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1513 DestroyWindow(mdi_client);
1515 /* MDIClient with MDIS_ALLCHILDSTYLES */
1516 mdi_client = CreateWindowExA(0, "mdiclient",
1518 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1519 /* tests depend on a not zero MDIClient size */
1520 0, 0, rc.right, rc.bottom,
1521 hwnd, 0, GetModuleHandle(0),
1522 (LPVOID)&client_cs);
1524 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1525 DestroyWindow(mdi_client);
1529 case WM_WINDOWPOSCHANGED:
1531 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1534 GetWindowRect(hwnd, &rc1);
1535 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1536 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1537 /* note: winpos coordinates are relative to parent */
1538 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1539 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1540 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1542 GetWindowRect(hwnd, &rc1);
1543 GetClientRect(hwnd, &rc2);
1544 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1545 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1546 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1549 case WM_WINDOWPOSCHANGING:
1551 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1552 WINDOWPOS my_winpos = *winpos;
1554 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1555 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1556 winpos->hwnd, winpos->hwndInsertAfter,
1557 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1559 DefWindowProcA(hwnd, msg, wparam, lparam);
1561 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1562 winpos->hwnd, winpos->hwndInsertAfter,
1563 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1565 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1566 "DefWindowProc should not change WINDOWPOS values\n");
1575 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1578 static BOOL mdi_RegisterWindowClasses(void)
1583 cls.lpfnWndProc = mdi_main_wnd_procA;
1586 cls.hInstance = GetModuleHandleA(0);
1588 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1589 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1590 cls.lpszMenuName = NULL;
1591 cls.lpszClassName = "MDI_parent_Class";
1592 if(!RegisterClassA(&cls)) return FALSE;
1594 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1595 cls.lpszClassName = "MDI_child_Class_1";
1596 if(!RegisterClassA(&cls)) return FALSE;
1598 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1599 cls.lpszClassName = "MDI_child_Class_2";
1600 if(!RegisterClassA(&cls)) return FALSE;
1605 static void test_mdi(void)
1610 if (!mdi_RegisterWindowClasses()) assert(0);
1612 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1613 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1614 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1615 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1616 GetDesktopWindow(), 0,
1617 GetModuleHandle(0), NULL);
1618 assert(mdi_hwndMain);
1620 while(GetMessage(&msg, 0, 0, 0))
1622 TranslateMessage(&msg);
1623 DispatchMessage(&msg);
1628 static void test_icons(void)
1632 HICON icon = LoadIconA(0, (LPSTR)IDI_APPLICATION);
1633 HICON icon2 = LoadIconA(0, (LPSTR)IDI_QUESTION);
1634 HICON small_icon = LoadImageA(0, (LPSTR)IDI_APPLICATION, IMAGE_ICON,
1635 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1638 cls.cbSize = sizeof(cls);
1640 cls.lpfnWndProc = DefWindowProcA;
1644 cls.hIcon = LoadIconA(0, (LPSTR)IDI_HAND);
1645 cls.hIconSm = small_icon;
1646 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1647 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1648 cls.lpszMenuName = NULL;
1649 cls.lpszClassName = "IconWindowClass";
1651 RegisterClassExA(&cls);
1653 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1654 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1657 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1658 ok( res == 0, "wrong big icon %p/0\n", res );
1659 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1660 ok( res == 0, "wrong previous big icon %p/0\n", res );
1661 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1662 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1663 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1664 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1665 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1666 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1668 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1669 ok( res == 0, "wrong small icon %p/0\n", res );
1670 /* this test is XP specific */
1671 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1672 ok( res != 0, "wrong small icon %p\n", res );*/
1673 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1674 ok( res == 0, "wrong previous small icon %p/0\n", res );
1675 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1676 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1677 /* this test is XP specific */
1678 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1679 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1680 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1681 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1682 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1683 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1684 /* this test is XP specific */
1685 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1686 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1688 /* make sure the big icon hasn't changed */
1689 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1690 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1693 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1695 if (msg == WM_NCCALCSIZE)
1697 RECT *rect = (RECT *)lparam;
1698 /* first time around increase the rectangle, next time decrease it */
1699 if (rect->left == 100) InflateRect( rect, 10, 10 );
1700 else InflateRect( rect, -10, -10 );
1703 return DefWindowProc( hwnd, msg, wparam, lparam );
1706 static void test_SetWindowPos(HWND hwnd)
1708 RECT orig_win_rc, rect;
1710 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1712 SetRect(&rect, 111, 222, 333, 444);
1713 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1714 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1715 "wrong window rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1717 SetRect(&rect, 111, 222, 333, 444);
1718 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1719 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1720 "wrong window rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1722 GetWindowRect(hwnd, &orig_win_rc);
1724 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1725 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1726 GetWindowRect( hwnd, &rect );
1727 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1728 "invalid window rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1729 GetClientRect( hwnd, &rect );
1730 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1731 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1732 "invalid client rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1734 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1735 GetWindowRect( hwnd, &rect );
1736 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1737 "invalid window rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1738 GetClientRect( hwnd, &rect );
1739 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1740 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1741 "invalid client rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1743 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1744 orig_win_rc.right, orig_win_rc.bottom, 0);
1745 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1747 /* Win9x truncates coordinates to 16-bit irrespectively */
1750 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1751 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1753 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1754 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1757 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1758 orig_win_rc.right, orig_win_rc.bottom, 0);
1761 static void test_SetMenu(HWND parent)
1765 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1769 hMenu = CreateMenu();
1772 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1774 /* fails on (at least) Wine, NT4, XP SP2 */
1775 test_nonclient_area(parent);
1777 ret = GetMenu(parent);
1778 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1779 /* test whether we can destroy a menu assigned to a window */
1780 retok = DestroyMenu(hMenu);
1781 ok( retok, "DestroyMenu error %ld\n", GetLastError());
1782 ok(!IsMenu(hMenu), "menu handle should be not valid after DestroyMenu\n");
1783 ret = GetMenu(parent);
1784 /* This test fails on Win9x */
1786 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1787 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1788 test_nonclient_area(parent);
1790 hMenu = CreateMenu();
1794 ret = GetMenu(parent);
1795 ok(ret == 0, "unexpected menu id %p\n", ret);
1797 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1798 test_nonclient_area(parent);
1799 ret = GetMenu(parent);
1800 ok(ret == 0, "unexpected menu id %p\n", ret);
1802 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1804 /* fails on (at least) Wine, NT4, XP SP2 */
1805 test_nonclient_area(parent);
1807 ret = GetMenu(parent);
1808 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1810 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1811 test_nonclient_area(parent);
1812 ret = GetMenu(parent);
1813 ok(ret == 0, "unexpected menu id %p\n", ret);
1816 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1819 ret = GetMenu(child);
1820 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1822 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1823 test_nonclient_area(child);
1824 ret = GetMenu(child);
1825 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1827 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1828 test_nonclient_area(child);
1829 ret = GetMenu(child);
1830 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1832 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1833 test_nonclient_area(child);
1834 ret = GetMenu(child);
1835 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1837 style = GetWindowLong(child, GWL_STYLE);
1838 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
1839 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
1840 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
1841 SetWindowLong(child, GWL_STYLE, style);
1843 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
1844 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
1845 SetWindowLong(child, GWL_STYLE, style);
1847 DestroyWindow(child);
1851 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1853 HWND child[5], hwnd;
1858 hwnd = GetWindow(parent, GW_CHILD);
1859 ok(!hwnd, "have to start without children to perform the test\n");
1861 for (i = 0; i < total; i++)
1863 if (style[i] & DS_CONTROL)
1865 child[i] = CreateWindowExA(0, MAKEINTATOMA(32770), "", style[i] & ~WS_VISIBLE,
1866 0,0,0,0, parent, (HMENU)i, 0, NULL);
1867 if (style[i] & WS_VISIBLE)
1868 ShowWindow(child[i], SW_SHOW);
1870 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
1873 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
1874 parent, (HMENU)i, 0, NULL);
1875 trace("child[%d] = %p\n", i, child[i]);
1876 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
1879 hwnd = GetWindow(parent, GW_CHILD);
1880 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
1881 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
1882 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
1884 for (i = 0; i < total; i++)
1886 trace("hwnd[%d] = %p\n", i, hwnd);
1887 ok(child[order[i]] == hwnd, "Z order of child #%d is wrong\n", i);
1889 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1892 for (i = 0; i < total; i++)
1893 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
1896 static void test_children_zorder(HWND parent)
1898 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
1900 const int simple_order[5] = { 0, 1, 2, 3, 4 };
1902 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
1903 WS_CHILD | WS_VISIBLE, WS_CHILD,
1904 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
1905 const int complex_order_1[1] = { 0 };
1906 const int complex_order_2[2] = { 1, 0 };
1907 const int complex_order_3[3] = { 1, 0, 2 };
1908 const int complex_order_4[4] = { 1, 0, 2, 3 };
1909 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
1910 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
1911 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
1912 WS_CHILD | WS_VISIBLE };
1913 const int complex_order_6[3] = { 0, 1, 2 };
1915 /* simple WS_CHILD */
1916 test_window_tree(parent, simple_style, simple_order, 5);
1918 /* complex children styles */
1919 test_window_tree(parent, complex_style, complex_order_1, 1);
1920 test_window_tree(parent, complex_style, complex_order_2, 2);
1921 test_window_tree(parent, complex_style, complex_order_3, 3);
1922 test_window_tree(parent, complex_style, complex_order_4, 4);
1923 test_window_tree(parent, complex_style, complex_order_5, 5);
1925 /* another set of complex children styles */
1926 test_window_tree(parent, complex_style_6, complex_order_6, 3);
1929 static void test_vis_rgn( HWND hwnd )
1931 RECT win_rect, rgn_rect;
1932 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
1935 ShowWindow(hwnd,SW_SHOW);
1936 hdc = GetDC( hwnd );
1937 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
1938 GetWindowRect( hwnd, &win_rect );
1939 GetRgnBox( hrgn, &rgn_rect );
1940 if (GetVersion() & 0x80000000)
1942 trace("win9x, mapping to screen coords\n");
1943 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
1945 trace("win: %ld,%ld-%ld,%ld\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
1946 trace("rgn: %ld,%ld-%ld,%ld\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
1947 ok( win_rect.left <= rgn_rect.left, "rgn left %ld not inside win rect %ld\n",
1948 rgn_rect.left, win_rect.left );
1949 ok( win_rect.top <= rgn_rect.top, "rgn top %ld not inside win rect %ld\n",
1950 rgn_rect.top, win_rect.top );
1951 ok( win_rect.right >= rgn_rect.right, "rgn right %ld not inside win rect %ld\n",
1952 rgn_rect.right, win_rect.right );
1953 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %ld not inside win rect %ld\n",
1954 rgn_rect.bottom, win_rect.bottom );
1955 ReleaseDC( hwnd, hdc );
1958 static void test_SetFocus(HWND hwnd)
1962 /* check if we can set focus to non-visible windows */
1964 ShowWindow(hwnd, SW_SHOW);
1967 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
1968 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
1969 ShowWindow(hwnd, SW_HIDE);
1972 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
1973 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
1974 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
1977 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
1978 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
1979 ShowWindow(child, SW_SHOW);
1980 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
1981 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
1982 ShowWindow(child, SW_HIDE);
1983 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
1984 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
1985 ShowWindow(child, SW_SHOW);
1987 ok( GetFocus() == child, "Focus should be on child %p\n", child );
1988 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
1989 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
1991 ShowWindow(child, SW_HIDE);
1993 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
1994 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
1995 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
1996 ShowWindow(child, SW_HIDE);
1997 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
1999 ShowWindow(hwnd, SW_SHOW);
2000 ShowWindow(child, SW_SHOW);
2002 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2003 EnableWindow(hwnd, FALSE);
2004 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2005 EnableWindow(hwnd, TRUE);
2007 DestroyWindow( child );
2010 static void test_SetActiveWindow(HWND hwnd)
2014 ShowWindow(hwnd, SW_SHOW);
2016 SetActiveWindow(hwnd);
2017 ok( GetActiveWindow() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2018 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2019 ok( GetActiveWindow() == hwnd, "Window %p no longer active\n", hwnd );
2020 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2021 ShowWindow(hwnd, SW_HIDE);
2022 ok( GetActiveWindow() != hwnd, "Window %p is still active\n", hwnd );
2024 /* trace("**testing an invisible window now\n"); */
2025 SetActiveWindow(hwnd);
2026 ok( GetActiveWindow() == hwnd, "Window %p not active\n", hwnd );
2027 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p is visible\n", hwnd );
2029 ShowWindow(hwnd, SW_SHOW);
2031 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2032 ok( GetActiveWindow() == hwnd2, "Window %p is not active\n", hwnd2 );
2033 DestroyWindow(hwnd2);
2034 ok( GetActiveWindow() != hwnd2, "Window %p is still active\n", hwnd2 );
2036 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2037 ok( GetActiveWindow() == hwnd2, "Window %p is not active\n", hwnd2 );
2038 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2039 ok( GetActiveWindow() == hwnd2, "Window %p no longer active (%p)\n", hwnd2, GetActiveWindow() );
2040 DestroyWindow(hwnd2);
2041 ok( GetActiveWindow() != hwnd2, "Window %p is still active\n", hwnd2 );
2044 static void check_wnd_state(HWND active, HWND foreground, HWND focus, HWND capture)
2046 ok(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2048 ok(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2049 ok(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2050 ok(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2053 static WNDPROC old_button_proc;
2055 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2060 key_state = GetKeyState(VK_LBUTTON);
2061 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2063 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2065 if (msg == WM_LBUTTONDOWN)
2069 check_wnd_state(button, button, button, button);
2071 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2073 trace("hwnd %p\n", hwnd);
2075 check_wnd_state(button, button, button, button);
2077 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2079 check_wnd_state(button, button, button, button);
2081 DestroyWindow(hwnd);
2083 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2085 trace("hwnd %p\n", hwnd);
2087 check_wnd_state(button, button, button, button);
2089 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2090 * match internal button state.
2092 SendMessage(button, WM_KILLFOCUS, 0, 0);
2093 check_wnd_state(button, button, button, 0);
2095 ShowWindow(hwnd, SW_SHOW);
2096 check_wnd_state(hwnd, hwnd, hwnd, 0);
2098 capture = SetCapture(hwnd);
2099 ok(capture == 0, "SetCapture() = %p\n", capture);
2101 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2103 DestroyWindow(hwnd);
2105 check_wnd_state(button, 0, button, 0);
2111 static void test_capture_1(void)
2113 HWND button, capture;
2115 capture = GetCapture();
2116 ok(capture == 0, "GetCapture() = %p\n", capture);
2118 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2120 trace("button %p\n", button);
2122 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2124 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2126 capture = SetCapture(button);
2127 ok(capture == 0, "SetCapture() = %p\n", capture);
2128 check_wnd_state(button, 0, button, button);
2130 DestroyWindow(button);
2131 check_wnd_state(0, 0, 0, 0);
2134 static void test_capture_2(void)
2136 HWND button, hwnd, capture;
2138 check_wnd_state(0, 0, 0, 0);
2140 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2142 trace("button %p\n", button);
2144 check_wnd_state(button, button, button, 0);
2146 capture = SetCapture(button);
2147 ok(capture == 0, "SetCapture() = %p\n", capture);
2149 check_wnd_state(button, button, button, button);
2151 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2152 * internal button state.
2154 SendMessage(button, WM_KILLFOCUS, 0, 0);
2155 check_wnd_state(button, button, button, button);
2157 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2159 trace("hwnd %p\n", hwnd);
2161 check_wnd_state(button, button, button, button);
2163 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2165 check_wnd_state(button, button, button, button);
2167 DestroyWindow(hwnd);
2169 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2171 trace("hwnd %p\n", hwnd);
2173 check_wnd_state(button, button, button, button);
2175 ShowWindow(hwnd, SW_SHOW);
2177 check_wnd_state(hwnd, hwnd, hwnd, button);
2179 capture = SetCapture(hwnd);
2180 ok(capture == button, "SetCapture() = %p\n", capture);
2182 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2184 DestroyWindow(hwnd);
2185 check_wnd_state(button, button, button, 0);
2187 DestroyWindow(button);
2188 check_wnd_state(0, 0, 0, 0);
2191 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2195 ShowWindow(hwnd1, SW_HIDE);
2196 ShowWindow(hwnd2, SW_HIDE);
2198 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2199 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2202 check_wnd_state(0, 0, 0, hwnd1);
2205 check_wnd_state(0, 0, 0, hwnd2);
2207 ShowWindow(hwnd1, SW_SHOW);
2208 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2210 ret = ReleaseCapture();
2211 ok (ret, "releasecapture did not return TRUE.\n");
2212 ret = ReleaseCapture();
2213 ok (ret, "releasecapture did not return TRUE after second try.\n");
2216 static void test_keyboard_input(HWND hwnd)
2221 ShowWindow(hwnd, SW_SHOW);
2224 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2227 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2229 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2231 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2232 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2233 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2234 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2235 ok( !ret, "message %04x available\n", msg.message);
2237 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2239 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2240 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2241 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2242 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2243 ok( !ret, "message %04x available\n", msg.message);
2245 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2247 keybd_event(VK_SPACE, 0, 0, 0);
2248 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2249 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2250 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2251 ok( !ret, "message %04x available\n", msg.message);
2254 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2256 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
2258 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2259 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2260 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2261 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2262 ok( !ret, "message %04x available\n", msg.message);
2264 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2266 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2267 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2268 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2269 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2270 ok( !ret, "message %04x available\n", msg.message);
2272 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2274 keybd_event(VK_SPACE, 0, 0, 0);
2275 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2276 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2277 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2278 ok( !ret, "message %04x available\n", msg.message);
2281 static void test_mouse_input(HWND hwnd)
2291 ShowWindow(hwnd, SW_SHOW);
2294 GetWindowRect(hwnd, &rc);
2295 trace("main window %p: (%ld,%ld)-(%ld,%ld)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2297 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2298 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2301 ShowWindow(popup, SW_SHOW);
2302 UpdateWindow(popup);
2304 GetWindowRect(popup, &rc);
2305 trace("popup window %p: (%ld,%ld)-(%ld,%ld)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2307 x = rc.left + (rc.right - rc.left) / 2;
2308 y = rc.top + (rc.bottom - rc.top) / 2;
2309 trace("setting cursor to (%d,%d)\n", x, y);
2313 ok(x == pt.x && y == pt.y, "wrong cursor pos (%ld,%ld), expected (%d,%d)\n", pt.x, pt.y, x, y);
2315 /* force the system to update its internal queue mouse position,
2316 * otherwise it won't generate relative mouse movements below.
2318 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2319 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2322 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2323 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2324 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2325 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2326 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2327 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2328 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2329 ok( !ret, "message %04x available\n", msg.message);
2331 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2332 ShowWindow(popup, SW_HIDE);
2333 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2334 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2335 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2337 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2338 ShowWindow(hwnd, SW_HIDE);
2339 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2340 ok( !ret, "message %04x available\n", msg.message);
2342 /* test mouse clicks */
2344 ShowWindow(hwnd, SW_SHOW);
2345 ShowWindow(popup, SW_SHOW);
2347 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2349 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2350 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2351 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2352 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2354 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2355 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2356 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2357 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2359 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2360 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2361 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2362 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2364 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2365 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2366 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2367 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2369 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2370 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2371 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2372 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2374 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2375 ok(!ret, "message %04x available\n", msg.message);
2377 ShowWindow(popup, SW_HIDE);
2378 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2380 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2381 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2382 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2383 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2385 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2386 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2387 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2388 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2390 test_lbuttondown_flag = TRUE;
2391 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
2392 test_lbuttondown_flag = FALSE;
2394 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2395 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2396 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2397 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2398 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2400 /* Test WM_MOUSEACTIVATE */
2401 #define TEST_MOUSEACTIVATE(A,B) \
2402 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2403 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2405 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
2406 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
2407 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
2408 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
2409 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
2410 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
2411 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
2412 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
2413 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
2414 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
2415 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
2416 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
2417 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
2418 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
2419 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
2420 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
2421 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
2422 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
2423 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
2424 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
2425 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
2426 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
2427 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
2428 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
2430 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2431 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2433 DestroyWindow(popup);
2436 static void test_validatergn(HWND hwnd)
2442 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
2443 ShowWindow(hwnd, SW_SHOW);
2444 UpdateWindow( hwnd);
2445 /* test that ValidateRect validates children*/
2446 InvalidateRect( child, NULL, 1);
2447 GetWindowRect( child, &rc);
2448 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2449 ret = GetUpdateRect( child, &rc2, 0);
2450 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
2451 "Update rectangle is empty!\n");
2452 ValidateRect( hwnd, &rc);
2453 ret = GetUpdateRect( child, &rc2, 0);
2454 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2455 "Update rectangle %ld,%ld-%ld,%ld is not empty!\n", rc2.left, rc2.top,
2456 rc2.right, rc2.bottom);
2458 /* now test ValidateRgn */
2459 InvalidateRect( child, NULL, 1);
2460 GetWindowRect( child, &rc);
2461 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2462 rgn = CreateRectRgnIndirect( &rc);
2463 ValidateRgn( hwnd, rgn);
2464 ret = GetUpdateRect( child, &rc2, 0);
2465 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2466 "Update rectangle %ld,%ld-%ld,%ld is not empty!\n", rc2.left, rc2.top,
2467 rc2.right, rc2.bottom);
2470 DestroyWindow( child );
2473 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
2475 MoveWindow( hwnd, 0, 0, x, y, 0);
2476 GetWindowRect( hwnd, prc);
2477 trace("window rect is %ld,%ld - %ld,%ld\n",
2478 prc->left,prc->top,prc->right,prc->bottom);
2479 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
2480 trace("nccalc rect is %ld,%ld - %ld,%ld\n",
2481 prc->left,prc->top,prc->right,prc->bottom);
2484 static void test_nccalcscroll(HWND parent)
2487 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
2488 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
2489 HWND hwnd = CreateWindowExA(0, "static", NULL,
2490 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
2491 10, 10, 200, 200, parent, 0, 0, NULL);
2492 ShowWindow( parent, SW_SHOW);
2493 UpdateWindow( parent);
2495 /* test window too low for a horizontal scroll bar */
2496 nccalchelper( hwnd, 100, sbheight, &rc1);
2497 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %ld,%ld - %ld,%ld\n",
2498 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
2500 /* test window just high enough for a horizontal scroll bar */
2501 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
2502 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %ld,%ld - %ld,%ld\n",
2503 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2505 /* test window too narrow for a vertical scroll bar */
2506 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
2507 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %ld,%ld - %ld,%ld\n",
2508 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2510 /* test window just wide enough for a vertical scroll bar */
2511 nccalchelper( hwnd, sbwidth, 100, &rc1);
2512 ok( rc1.right - rc1.left == 0, "Width should be %d size is %ld,%ld - %ld,%ld\n",
2513 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
2515 /* same test, but with client edge: not enough width */
2516 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
2517 nccalchelper( hwnd, sbwidth, 100, &rc1);
2518 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
2519 "Width should be %d size is %ld,%ld - %ld,%ld\n",
2520 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
2522 DestroyWindow( hwnd);
2525 static void test_SetParent(void)
2528 HWND desktop = GetDesktopWindow();
2530 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
2531 HWND parent, child1, child2, child3, child4, sibling;
2533 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2534 100, 100, 200, 200, 0, 0, 0, NULL);
2535 assert(parent != 0);
2536 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2537 0, 0, 50, 50, parent, 0, 0, NULL);
2538 assert(child1 != 0);
2539 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2540 0, 0, 50, 50, child1, 0, 0, NULL);
2541 assert(child2 != 0);
2542 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2543 0, 0, 50, 50, child2, 0, 0, NULL);
2544 assert(child3 != 0);
2545 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2546 0, 0, 50, 50, child3, 0, 0, NULL);
2547 assert(child4 != 0);
2549 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2550 parent, child1, child2, child3, child4);
2552 check_parents(parent, desktop, 0, 0, 0, parent, parent);
2553 check_parents(child1, parent, parent, parent, 0, parent, parent);
2554 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2555 check_parents(child3, child2, child2, child2, 0, child2, parent);
2556 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2559 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
2560 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
2561 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2562 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
2563 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2566 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
2568 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2570 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
2571 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
2572 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
2573 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
2574 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
2575 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
2577 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2580 if (!is_win9x) /* Win9x doesn't survive this test */
2582 ok(!SetParent(parent, child1), "SetParent should fail\n");
2583 ok(!SetParent(child2, child3), "SetParent should fail\n");
2584 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
2585 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
2586 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
2587 ok(!SetParent(child2, parent), "SetParent should fail\n");
2588 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
2590 check_parents(parent, child4, child4, 0, 0, child4, parent);
2591 check_parents(child1, parent, parent, parent, 0, child4, parent);
2592 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2593 check_parents(child3, child2, child2, child2, 0, child2, parent);
2594 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2597 hMenu = CreateMenu();
2598 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2599 100, 100, 200, 200, 0, hMenu, 0, NULL);
2600 assert(sibling != 0);
2602 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
2603 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
2605 ret = DestroyWindow(parent);
2606 ok( ret, "DestroyWindow() error %ld\n", GetLastError());
2608 ok(!IsWindow(parent), "parent still exists\n");
2609 ok(!IsWindow(sibling), "sibling still exists\n");
2610 ok(!IsWindow(child1), "child1 still exists\n");
2611 ok(!IsWindow(child2), "child2 still exists\n");
2612 ok(!IsWindow(child3), "child3 still exists\n");
2613 ok(!IsWindow(child4), "child4 still exists\n");
2616 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2618 LPCREATESTRUCT lpcs;
2625 lpcs = (LPCREATESTRUCT)lparam;
2626 lpss = (LPSTYLESTRUCT)lpcs->lpCreateParams;
2629 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
2630 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
2631 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
2632 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
2634 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
2636 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
2637 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2638 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
2640 ok(lpss->styleNew == lpcs->style,
2641 "Style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2642 lpss->styleNew, lpcs->style);
2646 return DefWindowProc(hwnd, msg, wparam, lparam);
2649 static ATOM atomStyleCheckClass;
2651 static void register_style_check_class(void)
2659 GetModuleHandle(NULL),
2661 LoadCursor(NULL, IDC_ARROW),
2662 (HBRUSH)(COLOR_BTNFACE+1),
2664 TEXT("WineStyleCheck"),
2667 atomStyleCheckClass = RegisterClass(&wc);
2670 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
2672 DWORD dwActualStyle;
2673 DWORD dwActualExStyle;
2676 HWND hwndParent = NULL;
2679 ss.styleNew = dwStyleIn;
2680 ss.styleOld = dwExStyleIn;
2682 if (dwStyleIn & WS_CHILD)
2684 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
2685 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
2688 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
2689 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
2692 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2694 TranslateMessage(&msg);
2695 DispatchMessage(&msg);
2698 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
2699 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
2700 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
2701 "Style (0x%08lx) should really be 0x%08lx and/or Ex style (0x%08lx) should really be 0x%08lx\n",
2702 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
2704 DestroyWindow(hwnd);
2705 if (hwndParent) DestroyWindow(hwndParent);
2708 /* tests what window styles the window manager automatically adds */
2709 static void test_window_styles(void)
2711 register_style_check_class();
2713 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
2714 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
2715 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
2716 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
2717 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
2718 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
2719 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
2720 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
2721 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
2722 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
2723 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
2726 static void test_scrollvalidate( HWND parent)
2729 HRGN hrgn=CreateRectRgn(0,0,0,0);
2730 HRGN exprgn, tmprgn, clipping;
2731 RECT rc, rcu, cliprc;
2732 /* create two overlapping child windows. The visual region
2733 * of hwnd1 is clipped by the overlapping part of
2734 * hwnd2 because of the WS_CLIPSIBLING style */
2737 hwnd2 = CreateWindowExA(0, "static", NULL,
2738 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
2739 75, 30, 100, 100, parent, 0, 0, NULL);
2740 hwnd1 = CreateWindowExA(0, "static", NULL,
2741 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
2742 25, 50, 100, 100, parent, 0, 0, NULL);
2743 ShowWindow( parent, SW_SHOW);
2744 UpdateWindow( parent);
2745 GetClientRect( hwnd1, &rc);
2747 clipping = CreateRectRgn( 10, 10, 90, 90);
2748 hdc = GetDC( hwnd1);
2749 /* for a visual touch */
2750 TextOut( hdc, 0,10, "0123456789", 10);
2751 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
2752 if (winetest_debug > 0) dump_region(hrgn);
2753 /* create a region with what is expected */
2754 exprgn = CreateRectRgn( 39,0,49,74);
2755 tmprgn = CreateRectRgn( 88,79,98,93);
2756 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2757 tmprgn = CreateRectRgn( 0,93,98,98);
2758 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2759 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2760 trace("update rect is %ld,%ld - %ld,%ld\n",
2761 rcu.left,rcu.top,rcu.right,rcu.bottom);
2762 /* now with clipping region */
2763 SelectClipRgn( hdc, clipping);
2764 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
2765 if (winetest_debug > 0) dump_region(hrgn);
2766 /* create a region with what is expected */
2767 exprgn = CreateRectRgn( 39,10,49,74);
2768 tmprgn = CreateRectRgn( 80,79,90,85);
2769 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2770 tmprgn = CreateRectRgn( 10,85,90,90);
2771 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2772 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2773 trace("update rect is %ld,%ld - %ld,%ld\n",
2774 rcu.left,rcu.top,rcu.right,rcu.bottom);
2775 ReleaseDC( hwnd1, hdc);
2777 /* test scrolling a window with an update region */
2778 DestroyWindow( hwnd2);
2779 ValidateRect( hwnd1, NULL);
2780 SetRect( &rc, 40,40, 50,50);
2781 InvalidateRect( hwnd1, &rc, 1);
2782 GetClientRect( hwnd1, &rc);
2784 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
2785 SW_SCROLLCHILDREN | SW_INVALIDATE);
2786 if (winetest_debug > 0) dump_region(hrgn);
2787 exprgn = CreateRectRgn( 88,0,98,98);
2788 tmprgn = CreateRectRgn( 30, 40, 50, 50);
2789 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2790 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2792 /* now test ScrollWindowEx with a combination of
2793 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
2794 /* make hwnd2 the child of hwnd1 */
2795 hwnd2 = CreateWindowExA(0, "static", NULL,
2796 WS_CHILD| WS_VISIBLE | WS_BORDER ,
2797 50, 50, 100, 100, hwnd1, 0, 0, NULL);
2798 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
2799 GetClientRect( hwnd1, &rc);
2802 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
2803 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
2804 ValidateRect( hwnd1, NULL);
2805 ValidateRect( hwnd2, NULL);
2806 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
2807 SW_SCROLLCHILDREN | SW_INVALIDATE);
2808 if (winetest_debug > 0) dump_region(hrgn);
2809 exprgn = CreateRectRgn( 88,0,98,88);
2810 tmprgn = CreateRectRgn( 0,88,98,98);
2811 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2812 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2814 /* SW_SCROLLCHILDREN */
2815 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
2816 ValidateRect( hwnd1, NULL);
2817 ValidateRect( hwnd2, NULL);
2818 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
2819 if (winetest_debug > 0) dump_region(hrgn);
2820 /* expected region is the same as in previous test */
2821 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2823 /* no SW_SCROLLCHILDREN */
2824 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
2825 ValidateRect( hwnd1, NULL);
2826 ValidateRect( hwnd2, NULL);
2827 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
2828 if (winetest_debug > 0) dump_region(hrgn);
2829 /* expected region is the same as in previous test */
2830 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2832 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
2833 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
2834 ValidateRect( hwnd1, NULL);
2835 ValidateRect( hwnd2, NULL);
2836 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
2837 if (winetest_debug > 0) dump_region(hrgn);
2838 exprgn = CreateRectRgn( 88,0,98,20);
2839 tmprgn = CreateRectRgn( 20,20,98,30);
2840 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2841 tmprgn = CreateRectRgn( 20,30,30,88);
2842 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2843 tmprgn = CreateRectRgn( 0,88,30,98);
2844 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2845 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2848 DeleteObject( hrgn);
2849 DeleteObject( exprgn);
2850 DeleteObject( tmprgn);
2851 DestroyWindow( hwnd1);
2852 DestroyWindow( hwnd2);
2855 /* couple of tests of return values of scrollbar functions
2856 * called on a scrollbarless window */
2857 static void test_scroll(void)
2862 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
2863 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
2864 100, 100, 200, 200, 0, 0, 0, NULL);
2866 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
2867 ok( ret, "GetScrollRange returns FALSE\n");
2868 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
2869 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
2870 si.cbSize = sizeof( si);
2871 si.fMask = SIF_PAGE;
2872 si.nPage = 0xdeadbeef;
2873 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
2874 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
2875 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
2877 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
2878 ok( ret, "GetScrollRange returns FALSE\n");
2879 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
2880 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
2881 si.cbSize = sizeof( si);
2882 si.fMask = SIF_PAGE;
2883 si.nPage = 0xdeadbeef;
2884 ret = GetScrollInfo( hwnd, SB_VERT, &si);
2885 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
2886 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
2888 DestroyWindow( hwnd);
2891 static void test_params(void)
2896 /* Just a param check */
2897 SetLastError(0xdeadbeef);
2898 rc = GetWindowText(hwndMain2, NULL, 1024);
2899 ok( rc==0, "GetWindowText: rc=%d err=%ld\n",rc,GetLastError());
2901 SetLastError(0xdeadbeef);
2902 hwnd=CreateWindow("LISTBOX", "TestList",
2903 (LBS_STANDARD & ~LBS_SORT),
2905 NULL, (HMENU)1, NULL, 0);
2907 ok(!hwnd, "CreateWindow with invalid menu handle should fail\n");
2908 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
2909 GetLastError() == 0xdeadbeef, /* Win9x */
2910 "wrong last error value %ld\n", GetLastError());
2913 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
2917 hwnd = CreateWindowEx(exStyle, class, class, style,
2924 trace("Failed to create window class=%s, style=0x%08lx, exStyle=0x%08lx\n", class, style, exStyle);
2927 ShowWindow(hwnd, SW_SHOW);
2929 test_nonclient_area(hwnd);
2932 DestroyWindow(hwnd);
2935 static BOOL AWR_init(void)
2939 class.style = CS_HREDRAW | CS_VREDRAW;
2940 class.lpfnWndProc = DefWindowProcA;
2941 class.cbClsExtra = 0;
2942 class.cbWndExtra = 0;
2943 class.hInstance = 0;
2944 class.hIcon = LoadIcon (0, IDI_APPLICATION);
2945 class.hCursor = LoadCursor (0, IDC_ARROW);
2946 class.hbrBackground = 0;
2947 class.lpszMenuName = 0;
2948 class.lpszClassName = szAWRClass;
2950 if (!RegisterClass (&class)) {
2951 ok(FALSE, "RegisterClass failed\n");
2955 hmenu = CreateMenu();
2958 ok(hmenu != 0, "Failed to create menu\n");
2959 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
2965 static void test_AWR_window_size(BOOL menu)
2969 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
2972 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
2973 WS_HSCROLL, WS_VSCROLL
2977 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
2980 /* These styles have problems on (at least) WinXP (SP2) and Wine */
2981 WS_EX_DLGMODALFRAME,
2988 /* A exhaustive check of all the styles takes too long
2989 * so just do a (hopefully representative) sample
2991 for (i = 0; i < COUNTOF(styles); ++i)
2992 test_AWRwindow(szAWRClass, styles[i], 0, menu);
2993 for (i = 0; i < COUNTOF(exStyles); ++i) {
2994 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
2995 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3000 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3002 static void test_AdjustWindowRect(void)
3007 SHOWSYSMETRIC(SM_CYCAPTION);
3008 SHOWSYSMETRIC(SM_CYSMCAPTION);
3009 SHOWSYSMETRIC(SM_CYMENU);
3010 SHOWSYSMETRIC(SM_CXEDGE);
3011 SHOWSYSMETRIC(SM_CYEDGE);
3012 SHOWSYSMETRIC(SM_CXVSCROLL);
3013 SHOWSYSMETRIC(SM_CYHSCROLL);
3014 SHOWSYSMETRIC(SM_CXFRAME);
3015 SHOWSYSMETRIC(SM_CYFRAME);
3016 SHOWSYSMETRIC(SM_CXDLGFRAME);
3017 SHOWSYSMETRIC(SM_CYDLGFRAME);
3018 SHOWSYSMETRIC(SM_CXBORDER);
3019 SHOWSYSMETRIC(SM_CYBORDER);
3021 test_AWR_window_size(FALSE);
3022 test_AWR_window_size(TRUE);
3026 #undef SHOWSYSMETRIC
3029 /* Global variables to trigger exit from loop */
3030 static int redrawComplete, WMPAINT_count;
3032 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3037 trace("doing WM_PAINT %d\n", WMPAINT_count);
3039 if (WMPAINT_count > 10 && redrawComplete == 0) {
3041 BeginPaint(hwnd, &ps);
3042 EndPaint(hwnd, &ps);
3048 return DefWindowProc(hwnd, msg, wparam, lparam);
3051 /* Ensure we exit from RedrawNow regardless of invalidated area */
3052 static void test_redrawnow(void)
3057 cls.style = CS_DBLCLKS;
3058 cls.lpfnWndProc = redraw_window_procA;
3061 cls.hInstance = GetModuleHandleA(0);
3063 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3064 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3065 cls.lpszMenuName = NULL;
3066 cls.lpszClassName = "RedrawWindowClass";
3068 if(!RegisterClassA(&cls)) {
3069 trace("Register failed %ld\n", GetLastError());
3073 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3074 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3076 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3077 ShowWindow(hwndMain, SW_SHOW);
3078 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3079 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3080 ok( WMPAINT_count == 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3081 redrawComplete = TRUE;
3082 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3085 DestroyWindow( hwndMain);
3088 struct parentdc_stat {
3094 struct parentdc_test {
3095 struct parentdc_stat main, main_todo;
3096 struct parentdc_stat child1, child1_todo;
3097 struct parentdc_stat child2, child2_todo;
3100 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3105 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3110 trace("doing WM_PAINT on %p\n", hwnd);
3111 GetClientRect(hwnd, &rc);
3112 CopyRect(&t->client, &rc);
3113 trace("client rect (%ld, %ld)-(%ld, %ld)\n", rc.left, rc.top, rc.right, rc.bottom);
3114 GetWindowRect(hwnd, &rc);
3115 trace("window rect (%ld, %ld)-(%ld, %ld)\n", rc.left, rc.top, rc.right, rc.bottom);
3116 BeginPaint(hwnd, &ps);
3117 CopyRect(&t->paint, &ps.rcPaint);
3118 GetClipBox(ps.hdc, &rc);
3119 CopyRect(&t->clip, &rc);
3120 trace("clip rect (%ld, %ld)-(%ld, %ld)\n", rc.left, rc.top, rc.right, rc.bottom);
3121 trace("paint rect (%ld, %ld)-(%ld, %ld)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3122 EndPaint(hwnd, &ps);
3125 return DefWindowProc(hwnd, msg, wparam, lparam);
3128 static void zero_parentdc_stat(struct parentdc_stat *t)
3130 SetRectEmpty(&t->client);
3131 SetRectEmpty(&t->clip);
3132 SetRectEmpty(&t->paint);
3135 static void zero_parentdc_test(struct parentdc_test *t)
3137 zero_parentdc_stat(&t->main);
3138 zero_parentdc_stat(&t->child1);
3139 zero_parentdc_stat(&t->child2);
3142 #define parentdc_field_ok(t, w, r, f, got) \
3143 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3144 ": expected %ld, got %ld\n", \
3147 #define parentdc_todo_field_ok(t, w, r, f, got) \
3148 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3149 else parentdc_field_ok(t, w, r, f, got)
3151 #define parentdc_rect_ok(t, w, r, got) \
3152 parentdc_todo_field_ok(t, w, r, left, got); \
3153 parentdc_todo_field_ok(t, w, r, top, got); \
3154 parentdc_todo_field_ok(t, w, r, right, got); \
3155 parentdc_todo_field_ok(t, w, r, bottom, got);
3157 #define parentdc_win_ok(t, w, got) \
3158 parentdc_rect_ok(t, w, client, got); \
3159 parentdc_rect_ok(t, w, clip, got); \
3160 parentdc_rect_ok(t, w, paint, got);
3162 #define parentdc_ok(t, got) \
3163 parentdc_win_ok(t, main, got); \
3164 parentdc_win_ok(t, child1, got); \
3165 parentdc_win_ok(t, child2, got);
3167 static void test_csparentdc(void)
3169 WNDCLASSA clsMain, cls;
3170 HWND hwndMain, hwnd1, hwnd2;
3174 struct parentdc_test test_answer;
3176 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3177 const struct parentdc_test test1 =
3179 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
3180 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3181 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3184 const struct parentdc_test test2 =
3186 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
3187 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3188 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3191 const struct parentdc_test test3 =
3193 {{0, 0, 150, 150}, {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,
3195 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3198 const struct parentdc_test test4 =
3200 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
3201 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
3202 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3205 const struct parentdc_test test5 =
3207 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
3208 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3209 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3212 const struct parentdc_test test6 =
3214 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3215 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3216 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3219 const struct parentdc_test test7 =
3221 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3222 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3223 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3227 clsMain.style = CS_DBLCLKS;
3228 clsMain.lpfnWndProc = parentdc_window_procA;
3229 clsMain.cbClsExtra = 0;
3230 clsMain.cbWndExtra = 0;
3231 clsMain.hInstance = GetModuleHandleA(0);
3233 clsMain.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3234 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
3235 clsMain.lpszMenuName = NULL;
3236 clsMain.lpszClassName = "ParentDcMainWindowClass";
3238 if(!RegisterClassA(&clsMain)) {
3239 trace("Register failed %ld\n", GetLastError());
3243 cls.style = CS_DBLCLKS | CS_PARENTDC;
3244 cls.lpfnWndProc = parentdc_window_procA;
3247 cls.hInstance = GetModuleHandleA(0);
3249 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3250 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3251 cls.lpszMenuName = NULL;
3252 cls.lpszClassName = "ParentDcWindowClass";
3254 if(!RegisterClassA(&cls)) {
3255 trace("Register failed %ld\n", GetLastError());
3259 SetRect(&rc, 0, 0, 150, 150);
3260 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
3261 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3262 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
3263 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
3264 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
3265 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
3266 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
3267 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
3268 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
3269 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
3270 ShowWindow(hwndMain, SW_SHOW);
3271 ShowWindow(hwnd1, SW_SHOW);
3272 ShowWindow(hwnd2, SW_SHOW);
3274 zero_parentdc_test(&test_answer);
3275 InvalidateRect(hwndMain, NULL, TRUE);
3276 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3277 parentdc_ok(test1, test_answer);
3279 zero_parentdc_test(&test_answer);
3280 SetRect(&rc, 0, 0, 50, 50);
3281 InvalidateRect(hwndMain, &rc, TRUE);
3282 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3283 parentdc_ok(test2, test_answer);
3285 zero_parentdc_test(&test_answer);
3286 SetRect(&rc, 0, 0, 10, 10);
3287 InvalidateRect(hwndMain, &rc, TRUE);
3288 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3289 parentdc_ok(test3, test_answer);
3291 zero_parentdc_test(&test_answer);
3292 SetRect(&rc, 40, 40, 50, 50);
3293 InvalidateRect(hwndMain, &rc, TRUE);
3294 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3295 parentdc_ok(test4, test_answer);
3297 zero_parentdc_test(&test_answer);
3298 SetRect(&rc, 20, 20, 60, 60);
3299 InvalidateRect(hwndMain, &rc, TRUE);
3300 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3301 parentdc_ok(test5, test_answer);
3303 zero_parentdc_test(&test_answer);
3304 SetRect(&rc, 0, 0, 10, 10);
3305 InvalidateRect(hwnd1, &rc, TRUE);
3306 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3307 parentdc_ok(test6, test_answer);
3309 zero_parentdc_test(&test_answer);
3310 SetRect(&rc, -5, -5, 65, 65);
3311 InvalidateRect(hwnd1, &rc, TRUE);
3312 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3313 parentdc_ok(test7, test_answer);
3315 DestroyWindow(hwndMain);
3316 DestroyWindow(hwnd1);
3317 DestroyWindow(hwnd2);
3320 static void test_IsWindowUnicode(void)
3322 static const char ansi_class_nameA[] = "ansi class name";
3323 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3324 static const char unicode_class_nameA[] = "unicode class name";
3325 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3330 memset(&classW, 0, sizeof(classW));
3331 classW.hInstance = GetModuleHandleA(0);
3332 classW.lpfnWndProc = DefWindowProcW;
3333 classW.lpszClassName = unicode_class_nameW;
3334 if (!RegisterClassW(&classW)) return;
3336 memset(&classA, 0, sizeof(classA));
3337 classA.hInstance = GetModuleHandleA(0);
3338 classA.lpfnWndProc = DefWindowProcA;
3339 classA.lpszClassName = ansi_class_nameA;
3340 assert(RegisterClassA(&classA));
3342 /* unicode class: window proc */
3343 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3344 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3347 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3348 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3349 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3350 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3351 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3353 DestroyWindow(hwnd);
3355 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3356 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3359 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3360 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3361 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3362 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3363 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3365 DestroyWindow(hwnd);
3367 /* ansi class: window proc */
3368 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3369 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3372 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3373 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3374 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3375 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3376 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3378 DestroyWindow(hwnd);
3380 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3381 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3384 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3385 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3386 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3387 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3388 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3390 DestroyWindow(hwnd);
3392 /* unicode class: class proc */
3393 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3394 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3397 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3398 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3399 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3400 /* do not restore class window proc back to unicode */
3402 DestroyWindow(hwnd);
3404 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3405 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3408 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3409 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3410 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3412 DestroyWindow(hwnd);
3414 /* ansi class: class proc */
3415 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3416 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3419 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3420 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3421 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3422 /* do not restore class window proc back to ansi */
3424 DestroyWindow(hwnd);
3426 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3427 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3430 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3431 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3432 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3434 DestroyWindow(hwnd);
3439 pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
3440 pGetWindowInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
3442 hwndMain = CreateWindowExA(0, "static", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, NULL);
3445 ok(!GetParent(hwndMain), "GetParent should return 0 for message only windows\n");
3448 hwndMessage = pGetAncestor(hwndMain, GA_PARENT);
3449 ok(hwndMessage != 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
3450 trace("hwndMessage %p\n", hwndMessage);
3452 DestroyWindow(hwndMain);
3455 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
3457 if (!RegisterWindowClasses()) assert(0);
3459 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
3462 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
3463 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3464 WS_MAXIMIZEBOX | WS_POPUP,
3467 test_nonclient_area(hwndMain);
3469 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
3470 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3471 WS_MAXIMIZEBOX | WS_POPUP,
3475 assert( hwndMain2 );
3477 /* Add the tests below this line */
3482 test_capture_3(hwndMain, hwndMain2);
3484 test_parent_owner();
3486 test_shell_window();
3490 test_SetWindowPos(hwndMain);
3491 test_SetMenu(hwndMain);
3492 test_SetFocus(hwndMain);
3493 test_SetActiveWindow(hwndMain);
3495 test_children_zorder(hwndMain);
3496 test_keyboard_input(hwndMain);
3497 test_mouse_input(hwndMain);
3498 test_validatergn(hwndMain);
3499 test_nccalcscroll( hwndMain);
3500 test_scrollvalidate( hwndMain);
3502 test_IsWindowUnicode();
3503 test_vis_rgn(hwndMain);
3505 test_AdjustWindowRect();
3506 test_window_styles();
3510 /* add the tests above this line */
3511 UnhookWindowsHookEx(hhook);